Skip to content

Commit

Permalink
return computed Phonopy object along with thermal properties
Browse files Browse the repository at this point in the history
  • Loading branch information
PROA200 committed Oct 20, 2023
1 parent 2ec983a commit cf6251f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
17 changes: 11 additions & 6 deletions matcalc/phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@ def calc(self, structure: Structure) -> dict:
Args:
structure: Pymatgen structure.
Returns: {
temperatures: list of temperatures in Kelvin,
free_energy: list of Helmholtz free energies at corresponding temperatures in eV,
entropy: list of entropies at corresponding temperatures in eV/K,
heat_capacity: list of heat capacities at constant volume at corresponding temperatures in eV/K^2,
Returns:
{
phonon: Phonopy object with force constants produced
thermal_properties:
{
temperatures: list of temperatures in Kelvin,
free_energy: list of Helmholtz free energies at corresponding temperatures in eV,
entropy: list of entropies at corresponding temperatures in eV/K,
heat_capacity: list of heat capacities at constant volume at corresponding temperatures in eV/K^2,
}
}
"""
if self.relax_structure:
Expand All @@ -80,7 +85,7 @@ def calc(self, structure: Structure) -> dict:
phonon.produce_force_constants()
phonon.run_mesh()
phonon.run_thermal_properties(t_step=self.t_step, t_max=self.t_max, t_min=self.t_min)
return phonon.get_thermal_properties_dict()
return {"phonon": phonon, "thermal_properties": phonon.get_thermal_properties_dict()}


def _calc_forces(calculator: Calculator, supercell: PhonopyAtoms) -> ArrayLike:
Expand Down
10 changes: 5 additions & 5 deletions tests/test_phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def test_phonon_calc(Li2O, LiFePO4, M3GNetCalc):
results = pcalc.calc(Li2O)

# Test values at 100 K
ind = results["temperatures"].tolist().index(300)
assert results["heat_capacity"][ind] == pytest.approx(59.91894069664282, rel=1e-2)
assert results["entropy"][ind] == pytest.approx(51.9081928335805, rel=1e-2)
assert results["free_energy"][ind] == pytest.approx(11.892105644441045, rel=1e-2)
ind = results["thermal_properties"]["temperatures"].tolist().index(300)
assert results["thermal_properties"]["heat_capacity"][ind] == pytest.approx(59.91894069664282, rel=1e-2)
assert results["thermal_properties"]["entropy"][ind] == pytest.approx(51.9081928335805, rel=1e-2)
assert results["thermal_properties"]["free_energy"][ind] == pytest.approx(11.892105644441045, rel=1e-2)

results = list(pcalc.calc_many([Li2O, LiFePO4]))
assert len(results) == 2
assert results[-1]["heat_capacity"][ind] == pytest.approx(550.6419940551511, rel=1e-2)
assert results[-1]["thermal_properties"]["heat_capacity"][ind] == pytest.approx(550.6419940551511, rel=1e-2)

0 comments on commit cf6251f

Please sign in to comment.