Skip to content

Commit 461c528

Browse files
committed
test energy and forces produced by MLFFs in test_ext_load
1 parent e07e855 commit 461c528

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/forcefields/test_utils.py

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import numpy as np
12
import pytest
23

34
from atomate2.forcefields import MLFF
@@ -11,6 +12,8 @@ def test_mlff(mlff: MLFF):
1112

1213
@pytest.mark.parametrize("mlff", ["CHGNet", "MACE", MLFF.MatterSim, MLFF.SevenNet])
1314
def test_ext_load(mlff: str):
15+
from ase.build import bulk
16+
1417
decode_dict = {
1518
"CHGNet": {"@module": "chgnet.model.dynamics", "@callable": "CHGNetCalculator"},
1619
"MACE": {"@module": "mace.calculators", "@callable": "mace_mp"},
@@ -29,6 +32,17 @@ def test_ext_load(mlff: str):
2932
assert calc_from_decode.name == calc_from_preset.name
3033
assert calc_from_decode.parameters == calc_from_preset.parameters == {}
3134

35+
atoms = bulk("Si", "diamond", a=5.43)
36+
37+
atoms.calc = calc_from_preset
38+
energy = atoms.get_potential_energy()
39+
forces = atoms.get_forces()
40+
41+
assert isinstance(energy, float | np.floating)
42+
assert energy < 0
43+
assert forces.shape == (2, 3)
44+
assert abs(forces.sum()) < 1e-6, f"unexpectedly large net {forces=}"
45+
3246

3347
def test_raises_error():
3448
with pytest.raises(ValueError, match="Could not create"):

0 commit comments

Comments
 (0)