Skip to content

Commit 4bebe12

Browse files
committed
Updated tests for new matpes model.
1 parent c84aa9c commit 4bebe12

13 files changed

Lines changed: 465 additions & 132 deletions

examples/Running the MatCalc-Benchmark.ipynb

Lines changed: 346 additions & 37 deletions
Large diffs are not rendered by default.

src/matcalc/benchmark.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
from ._stability import EnergeticsCalc
3535
from .backend import run_pes_calc
3636
from .config import BENCHMARK_DATA_DIR, BENCHMARK_HF_REPO_ID
37-
from .units import eVA3ToGPa
3837

3938
logger = logging.getLogger(__name__)
4039

@@ -549,6 +548,7 @@ def get_prop_calc(self, calculator: str | Calculator, **kwargs: Any) -> PropCalc
549548
Configured ``ElasticityCalc``.
550549
"""
551550
kwargs.setdefault("fmax", 0.05)
551+
kwargs.setdefault("units_GPa", True)
552552
return ElasticityCalc(calculator, **kwargs)
553553

554554
def process_result(self, result: dict | None, model_name: str) -> dict:
@@ -566,12 +566,8 @@ def process_result(self, result: dict | None, model_name: str) -> dict:
566566
K and G in GPa as ``bulk_modulus_vrh_{model}``, ``shear_modulus_vrh_{model}``.
567567
"""
568568
return {
569-
f"bulk_modulus_vrh_{model_name}": (
570-
result["bulk_modulus_vrh"] * eVA3ToGPa if result is not None else float("nan")
571-
),
572-
f"shear_modulus_vrh_{model_name}": (
573-
result["shear_modulus_vrh"] * eVA3ToGPa if result is not None else float("nan")
574-
),
569+
f"bulk_modulus_vrh_{model_name}": (result["bulk_modulus_vrh"] if result is not None else float("nan")),
570+
f"shear_modulus_vrh_{model_name}": (result["shear_modulus_vrh"] if result is not None else float("nan")),
575571
}
576572

577573

tests/test_benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def test_equilibrium_benchmark(matpes_calculator: PESCalculator) -> None:
3939
benchmark = EquilibriumBenchmark(seed=1, n_samples=2)
4040
results = benchmark.run(matpes_calculator, "toy")
4141
assert len(results) == 2
42-
assert results["d_toy"].mean() == pytest.approx(0.12305854320340562, abs=1e-1)
43-
assert np.abs(results["Eform_toy"] - results["Eform_DFT"]).mean() == pytest.approx(0.0703378673539001, abs=1e-2)
42+
assert results["d_toy"].mean() == pytest.approx(0.3577008030046791, abs=1e-1)
43+
assert np.abs(results["Eform_toy"] - results["Eform_DFT"]).mean() == pytest.approx(0.05689055202524909, abs=1e-2)
4444

4545

4646
def test_elasticity_benchmark(matpes_calculator: PESCalculator) -> None:
@@ -55,7 +55,7 @@ def test_elasticity_benchmark(matpes_calculator: PESCalculator) -> None:
5555
assert not os.path.exists(chkpt_file)
5656
assert len(results) == 3
5757
# Compute MAE
58-
assert np.abs(results["K_vrh_toy"] - results["K_vrh_DFT"]).mean() == pytest.approx(2.9499577941620814, rel=1e-1)
58+
assert np.abs(results["K_vrh_toy"] - results["K_vrh_DFT"]).mean() == pytest.approx(24.956482656725004, rel=1e-1)
5959

6060
benchmark = ElasticityBenchmark(benchmark_name="mp-pbe-elasticity-2025.3.json.gz", seed=0, n_samples=3)
6161

@@ -82,7 +82,7 @@ def test_phonon_benchmark(matpes_calculator: PESCalculator) -> None:
8282
benchmark = PhononBenchmark(seed=0, n_samples=3)
8383
results = benchmark.run(matpes_calculator, "toy")
8484
assert len(results) == 3
85-
assert np.abs(results["CV_toy"] - results["CV_DFT"]).mean() == pytest.approx(13.510378078609543, abs=3e-1)
85+
assert np.abs(results["CV_toy"] - results["CV_DFT"]).mean() == pytest.approx(3.172300846568419, abs=3e-1)
8686

8787

8888
def test_softening_benchmark(matpes_calculator: PESCalculator) -> None:

tests/test_elasticity.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ def test_elastic_calc(
3636
assert results["elastic_tensor"].shape == (3, 3, 3, 3)
3737
assert results["structure"].lattice.a == pytest.approx(3.291071792359756, rel=1e-1)
3838

39-
assert results["elastic_tensor"][0][1][1][0] == pytest.approx(0.40202637537731767, rel=1e-1)
40-
assert results["bulk_modulus_vrh"] == pytest.approx(0.41534028838780773, rel=1e-1)
41-
assert results["shear_modulus_vrh"] == pytest.approx(0.25912319676768314, rel=1e-1)
42-
assert results["youngs_modulus"] == pytest.approx(643538946.776407, rel=1e-1)
43-
assert results["residuals_sum"] == pytest.approx(1.7357497032219036e-08, rel=1e-1)
39+
assert results["elastic_tensor"][0][1][1][0] == pytest.approx(0.4616500809788702, rel=1e-1)
40+
assert results["bulk_modulus_vrh"] == pytest.approx(0.45903962068080767, rel=1e-1)
41+
assert results["shear_modulus_vrh"] == pytest.approx(0.40219758881584616, rel=1e-1)
42+
assert results["youngs_modulus"] == pytest.approx(933853928.3876991, rel=1e-1)
43+
assert results["residuals_sum"] == pytest.approx(3.581519020751326e-08, rel=1e-1)
4444

4545
# Test Li2O without the equilibrium structure
4646
elast_calc = ElasticityCalc(
@@ -53,7 +53,7 @@ def test_elastic_calc(
5353
)
5454

5555
results = elast_calc.calc(Li2O)
56-
assert results["residuals_sum"] == pytest.approx(1.3195273228222949e-08, rel=1e-1)
56+
assert results["residuals_sum"] == pytest.approx(2.736990723556343e-08, rel=1e-1)
5757

5858
# Test Li2O with float
5959
elast_calc = ElasticityCalc(
@@ -67,7 +67,7 @@ def test_elastic_calc(
6767

6868
results = elast_calc.calc(Li2O)
6969
assert results["residuals_sum"] == 0.0
70-
assert results["bulk_modulus_vrh"] == pytest.approx(0.40877813076228825, rel=1e-1)
70+
assert results["bulk_modulus_vrh"] == pytest.approx(0.4507664949851733, rel=1e-1)
7171

7272

7373
def test_elastic_calc_atoms(

tests/test_eos.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ def test_eos_calc(
4545
)
4646
assert result["eos"]["energies"] == pytest.approx(
4747
[
48-
-13.237542152404785,
49-
-13.61134147644043,
50-
-13.849345207214355,
51-
-13.988920211791992,
52-
-14.05781078338623,
53-
-14.077228546142578,
54-
-14.057827949523926,
55-
-14.006065368652344,
56-
-13.925064086914062,
57-
-13.817656517028809,
58-
-13.688666343688965,
48+
-13.577718734741211,
49+
-13.87842845916748,
50+
-14.080720901489258,
51+
-14.209554672241211,
52+
-14.278072357177734,
53+
-14.29671573638916,
54+
-14.274452209472656,
55+
-14.218313217163086,
56+
-14.133645057678223,
57+
-14.024273872375488,
58+
-13.892631530761719,
5959
],
6060
rel=1e-3,
6161
)
@@ -74,4 +74,4 @@ def test_eos_calc_atoms(
7474
eos_calc = EOSCalc(matpes_calculator, fmax=0.1, relax_structure=False)
7575
result = eos_calc.calc(Si_atoms)
7676

77-
assert result["bulk_modulus_bm"] == pytest.approx(87.31159138735727, rel=1e-1)
77+
assert result["bulk_modulus_bm"] == pytest.approx(76.57813407426684, rel=1e-1)

tests/test_interface.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,4 @@ def test_interface_calc_basic(Si: Structure, SiO2: Structure, matpes_calculator:
4343

4444
assert interface_res["film_energy_per_atom"] == pytest.approx(-7.881573994954427, rel=1e-1)
4545
assert interface_res["substrate_energy_per_atom"] == pytest.approx(-5.419038772583008, rel=1e-1)
46-
assert interface_res["interfacial_energy"] == pytest.approx(0.15930456535294427, rel=1e-1)
46+
assert interface_res["interfacial_energy"] == pytest.approx(0.19152603543013672, rel=1e-1)

tests/test_md.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@ def _set_seed() -> None:
2727
@pytest.mark.parametrize(
2828
("ensemble", "expected_energy"),
2929
[
30-
("nve", -10.441453988814853),
31-
("nvt", -10.429515745917376),
32-
("nvt_berendsen", -10.442275652025423),
33-
("nvt_langevin", -10.3960898598168),
34-
("nvt_andersen", -10.449911725549356),
35-
("nvt_bussi", -10.394832352314676),
36-
("npt_inhomogeneous", -10.444233085819286),
37-
("npt_berendsen", -10.423091635481624),
38-
("npt_nose_hoover", -10.39898962348729),
39-
("npt_isotropic_mtk", -10.42449303041493),
40-
("npt_mtk", -10.45577119876975),
30+
("nve", -10.585068948632792),
31+
("nvt", -10.573131415356976),
32+
("nvt_berendsen", -10.585859430696043),
33+
("nvt_langevin", -10.539638997522172),
34+
("nvt_andersen", -10.593524902060441),
35+
("nvt_bussi", -10.538497767305778),
36+
("npt_inhomogeneous", -10.587772892938327),
37+
("npt_berendsen", -10.566610902894368),
38+
("npt_nose_hoover", -10.542476644421331),
39+
("npt_isotropic_mtk", -10.567787082355974),
40+
("npt_mtk", -10.59909077098931),
4141
],
4242
)
4343
def test_md_calc(
@@ -141,7 +141,7 @@ def test_md_relax_cell(
141141
initial_vol = Si.lattice.volume
142142
results = md_calc.calc(Si)
143143
volume_after_relax = np.linalg.det(results["trajectory"][0].get_cell())
144-
assert abs(volume_after_relax - initial_vol) > 0.1
144+
assert abs(volume_after_relax - initial_vol) > 1e-4
145145

146146

147147
def test_stationary(Si_atoms: Atoms, matpes_calculator: PESCalculator, tmp_path: Path) -> None:

tests/test_neb.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test_neb_calc(LiFePO4: Structure, matpes_calculator: PESCalculator, tmp_path
2525
image_end = relax.calc(image_end)["final_structure"]
2626
neb_calc = NEBCalc(matpes_calculator, traj_folder=tmp_path, fmax=0.5, method="aseneb")
2727
barriers = neb_calc.calc_images(image_start, image_end, n_images=5)
28-
assert barriers["barrier"] == pytest.approx(0.17913818359375044, rel=0.005)
29-
assert barriers["force"] == pytest.approx(-0.0042724609375, abs=1e-4)
28+
assert barriers["barrier"] == pytest.approx(0.23047832627218945, rel=0.005)
29+
assert barriers["force"] == pytest.approx(0.0008544921875, abs=1e-4)
3030
assert isinstance(barriers["mep"], MEP), "barriers['mep'] should be an MEP instance"
3131
mep = barriers["mep"]
3232
assert len(mep.labels) > 0, "MEP should have labels"

tests/test_phonon.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,14 @@ def test_phonon_calc(
6161
# Test values at 100 K
6262
thermal_props = result["thermal_properties"]
6363
ind = thermal_props["temperatures"].tolist().index(300)
64-
assert thermal_props["heat_capacity"][ind] == pytest.approx(58.42898, rel=1e-1)
65-
assert thermal_props["entropy"][ind] == pytest.approx(49.37746, rel=1e-1)
66-
assert thermal_props["free_energy"][ind] == pytest.approx(13.24547, rel=1e-1)
67-
assert_allclose(result["final_structure"].lattice.abc, (3.291071792359756, 3.291071792359756, 3.291071792359756))
64+
assert thermal_props["heat_capacity"][ind] == pytest.approx(56.618323353498866, rel=1e-1)
65+
assert thermal_props["entropy"][ind] == pytest.approx(43.70960755706888, rel=1e-1)
66+
assert thermal_props["free_energy"][ind] == pytest.approx(15.620299826689202, rel=1e-1)
67+
assert_allclose(
68+
result["final_structure"].lattice.abc,
69+
(3.276385084722167, 3.276385084722167, 3.276385084722167),
70+
rtol=1e-4,
71+
)
6872
assert_allclose(
6973
result["disp_supercells"][0].lattice.abc,
7074
(

tests/test_phonon3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_phonon3_calc(
5151

5252
result = phonon3_calc.calc(Si)
5353
ind = result["temperatures"].tolist().index(300)
54-
assert result["thermal_conductivity"][ind] == pytest.approx(76.02046300874582, rel=1e-1)
54+
assert result["thermal_conductivity"][ind] == pytest.approx(107.54778638875011, rel=1e-1)
5555

5656
if write_phonon3_path:
5757
assert os.path.isfile(str(write_phonon3_path))
@@ -85,4 +85,4 @@ def test_phonon3_calc_atoms(
8585

8686
result = phonon3_calc.calc(Si_atoms)
8787
ind = result["temperatures"].tolist().index(300)
88-
assert result["thermal_conductivity"][ind] == pytest.approx(76.02046300874582, rel=1e-1)
88+
assert result["thermal_conductivity"][ind] == pytest.approx(107.54778638875011, rel=1e-1)

0 commit comments

Comments
 (0)