diff --git a/include/tadah/mlip/structure.h b/include/tadah/mlip/structure.h index 306ca2c7e87695b5041881c41795e5e066fb48ea..c36baf27fe3f215e0729e0c3be97f30ed420792c 100644 --- a/include/tadah/mlip/structure.h +++ b/include/tadah/mlip/structure.h @@ -137,6 +137,9 @@ struct Structure { /** @return volume of this structure. */ double get_volume() const; + /** @return density of this structure in g/cm^3 */ + double get_density() const; + /** @return virial pressure calculated from the stress tensor. * * Units: energy/distance^3 diff --git a/src/structure.cpp b/src/structure.cpp index 2d870bbecdacab8f4fd35779ef42c9f6cc111174..9db209cc995becbf1129f55c268cbda00b286aed 100644 --- a/src/structure.cpp +++ b/src/structure.cpp @@ -173,6 +173,14 @@ size_t Structure::get_nn_iindex(const size_t i, const size_t j, const size_t jj) double Structure::get_volume() const { return cell.row(0)*(cell.row(1).cross(cell.row(2))); } +double Structure::get_density() const { + double V = cell.row(0)*(cell.row(1).cross(cell.row(2))); + V*=1e-24; // convert to cm^3 + double amu = 1.66053906660e-24; // g + double mass = 0; + for (const auto& a:atoms) mass += PeriodicTable::get_mass(a.Z); + return amu*mass/V; +} double Structure::get_virial_pressure() const { return stress.trace()/get_volume()/3;