diff --git a/tests/forcefields/test_utils.py b/tests/forcefields/test_utils.py index f2fe64eaf..2d91ac638 100644 --- a/tests/forcefields/test_utils.py +++ b/tests/forcefields/test_utils.py @@ -1,3 +1,4 @@ +import numpy as np import pytest from atomate2.forcefields import MLFF @@ -11,6 +12,8 @@ def test_mlff(mlff: MLFF): @pytest.mark.parametrize("mlff", ["CHGNet", "MACE", MLFF.MatterSim, MLFF.SevenNet]) def test_ext_load(mlff: str): + from ase.build import bulk + decode_dict = { "CHGNet": {"@module": "chgnet.model.dynamics", "@callable": "CHGNetCalculator"}, "MACE": {"@module": "mace.calculators", "@callable": "mace_mp"}, @@ -29,6 +32,17 @@ def test_ext_load(mlff: str): assert calc_from_decode.name == calc_from_preset.name assert calc_from_decode.parameters == calc_from_preset.parameters == {} + atoms = bulk("Si", "diamond", a=5.43) + + atoms.calc = calc_from_preset + energy = atoms.get_potential_energy() + forces = atoms.get_forces() + + assert isinstance(energy, float | np.floating) + assert energy < 0 + assert forces.shape == (2, 3) + assert abs(forces.sum()) < 1e-6, f"unexpectedly large net {forces=}" + def test_raises_error(): with pytest.raises(ValueError, match="Could not create"):