-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
85 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
"""Tests for PhononCalc class""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from matcalc.eos import EOSCalc | ||
|
||
if TYPE_CHECKING: | ||
from matgl.ext.ase import M3GNetCalculator | ||
from pymatgen.core import Structure | ||
|
||
|
||
def test_eos_calc(Li2O, LiFePO4, M3GNetCalc): | ||
def test_eos_calc( | ||
Li2O: Structure, | ||
LiFePO4: Structure, | ||
M3GNetCalc: M3GNetCalculator, | ||
) -> None: | ||
"""Tests for EOSCalc class""" | ||
# Note that the fmax is probably too high. This is for testing purposes only. | ||
pcalc = EOSCalc(M3GNetCalc, fmax=0.1) | ||
results = pcalc.calc(Li2O) | ||
eos_calc = EOSCalc(M3GNetCalc, fmax=0.1) | ||
result = eos_calc.calc(Li2O) | ||
|
||
assert {*results} == {"eos", "r2_score_bm", "bulk_modulus_bm"} | ||
assert results["bulk_modulus_bm"] == pytest.approx(65.57980045603279, rel=1e-2) | ||
assert {*results["eos"]} == {"volumes", "energies"} | ||
assert results["eos"]["volumes"] == pytest.approx( | ||
assert {*result} == {"eos", "r2_score_bm", "bulk_modulus_bm"} | ||
assert result["bulk_modulus_bm"] == pytest.approx(65.57980045603279, rel=1e-2) | ||
assert {*result["eos"]} == {"volumes", "energies"} | ||
assert result["eos"]["volumes"] == pytest.approx( | ||
[18.38, 19.63, 20.94, 22.3, 23.73, 25.21, 26.75, 28.36, 30.02, 31.76, 33.55], | ||
rel=1e-3, | ||
) | ||
assert results["eos"]["energies"] == pytest.approx( | ||
assert result["eos"]["energies"] == pytest.approx( | ||
[-13.52, -13.77, -13.94, -14.08, -14.15, -14.18, -14.16, -14.11, -14.03, -13.94, -13.83], | ||
rel=1e-3, | ||
) | ||
pcalc = EOSCalc(M3GNetCalc, relax_structure=False) | ||
results = list(pcalc.calc_many([Li2O, LiFePO4])) | ||
eos_calc = EOSCalc(M3GNetCalc, relax_structure=False) | ||
results = list(eos_calc.calc_many([Li2O, LiFePO4])) | ||
assert len(results) == 2 | ||
assert results[1]["bulk_modulus_bm"] == pytest.approx(54.5953851822073, rel=1e-2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
"""Tests for PhononCalc class""" | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
import pytest | ||
|
||
from matcalc.phonon import PhononCalc | ||
|
||
if TYPE_CHECKING: | ||
from matgl.ext.ase import M3GNetCalculator | ||
from pymatgen.core import Structure | ||
|
||
|
||
def test_phonon_calc(Li2O, M3GNetCalc): | ||
def test_phonon_calc(Li2O: Structure, M3GNetCalc: M3GNetCalculator) -> None: | ||
"""Tests for PhononCalc class""" | ||
# Note that the fmax is probably too high. This is for testing purposes only. | ||
pcalc = PhononCalc(M3GNetCalc, supercell_matrix=((2, 0, 0), (0, 2, 0), (0, 0, 2)), fmax=0.1, t_step=50, t_max=1000) | ||
results = pcalc.calc(Li2O) | ||
phonon_calc = PhononCalc( | ||
M3GNetCalc, supercell_matrix=((2, 0, 0), (0, 2, 0), (0, 0, 2)), fmax=0.1, t_step=50, t_max=1000 | ||
) | ||
result = phonon_calc.calc(Li2O) | ||
|
||
# Test values at 100 K | ||
ind = results["thermal_properties"]["temperatures"].tolist().index(300) | ||
assert results["thermal_properties"]["heat_capacity"][ind] == pytest.approx(58.42898370395005, rel=1e-2) | ||
assert results["thermal_properties"]["entropy"][ind] == pytest.approx(49.3774618162247, rel=1e-2) | ||
assert results["thermal_properties"]["free_energy"][ind] == pytest.approx(13.245478097108784, rel=1e-2) | ||
ind = result["thermal_properties"]["temperatures"].tolist().index(300) | ||
assert result["thermal_properties"]["heat_capacity"][ind] == pytest.approx(58.42898370395005, rel=1e-2) | ||
assert result["thermal_properties"]["entropy"][ind] == pytest.approx(49.3774618162247, rel=1e-2) | ||
assert result["thermal_properties"]["free_energy"][ind] == pytest.approx(13.245478097108784, rel=1e-2) | ||
|
||
results = list(pcalc.calc_many([Li2O, Li2O])) | ||
results = list(phonon_calc.calc_many([Li2O, Li2O])) | ||
assert len(results) == 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters