Skip to content

Commit

Permalink
Rewrite tests without LiFePO4
Browse files Browse the repository at this point in the history
  • Loading branch information
PROA200 committed Nov 29, 2023
1 parent 8ea9a86 commit 4e3ad4a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions tests/test_phonon.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from matcalc.phonon import PhononCalc


def test_phonon_calc(Li2O, LiFePO4, M3GNetCalc):
def test_phonon_calc(Li2O, M3GNetCalc):
"""Tests for PhononCalc class"""
calculator = M3GNetCalc
# Note that the fmax is probably too high. This is for testing purposes only.
Expand All @@ -15,10 +15,9 @@ def test_phonon_calc(Li2O, LiFePO4, M3GNetCalc):

# Test values at 100 K
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)
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)

results = list(pcalc.calc_many([Li2O, LiFePO4]))
results = list(pcalc.calc_many([Li2O, Li2O]))
assert len(results) == 2
assert results[-1]["thermal_properties"]["heat_capacity"][ind] == pytest.approx(550.6419940551511, rel=1e-2)
24 changes: 12 additions & 12 deletions tests/test_relaxation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
from matcalc.relaxation import RelaxCalc


def test_relax_calc(LiFePO4, M3GNetCalc, tmp_path):
pcalc = RelaxCalc(M3GNetCalc, traj_file=f"{tmp_path}/lfp_relax.txt", optimizer="FIRE")
results = pcalc.calc(LiFePO4)
assert results["a"] == pytest.approx(4.75571137)
assert results["b"] == pytest.approx(6.13161423)
assert results["c"] == pytest.approx(10.4385933)
assert results["alpha"] == pytest.approx(90, abs=1)
assert results["beta"] == pytest.approx(90, abs=1)
assert results["gamma"] == pytest.approx(90, abs=1)
assert results["volume"] == pytest.approx(results["a"] * results["b"] * results["c"], abs=0.1)
def test_relax_calc(Li2O, M3GNetCalc, tmp_path):
pcalc = RelaxCalc(M3GNetCalc, traj_file=f"{tmp_path}/li2o_relax.txt", optimizer="FIRE")
results = pcalc.calc(Li2O)
assert results["a"] == pytest.approx(3.291071792359756, rel=0.002)
assert results["b"] == pytest.approx(3.291071899625086, rel=0.002)
assert results["c"] == pytest.approx(3.291072056855788, rel=0.002)
assert results["alpha"] == pytest.approx(60, abs=1)
assert results["beta"] == pytest.approx(60, abs=1)
assert results["gamma"] == pytest.approx(60, abs=1)
assert results["volume"] == pytest.approx(results["a"] * results["b"] * results["c"]/2**0.5, abs=0.1)

results = list(pcalc.calc_many([LiFePO4] * 2))
results = list(pcalc.calc_many([Li2O] * 2))
assert len(results) == 2
assert results[-1]["a"] == pytest.approx(4.7557113)
assert results[-1]["a"] == pytest.approx(3.291071792359756, rel=0.002)

with pytest.raises(ValueError, match="Unknown optimizer='invalid', must be one of "):
RelaxCalc(M3GNetCalc, optimizer="invalid")

0 comments on commit 4e3ad4a

Please sign in to comment.