Skip to content

Commit

Permalink
test energy and forces produced by MLFFs in test_ext_load
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Dec 7, 2024
1 parent e07e855 commit 461c528
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/forcefields/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import numpy as np
import pytest

from atomate2.forcefields import MLFF
Expand All @@ -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"},
Expand All @@ -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"):
Expand Down

0 comments on commit 461c528

Please sign in to comment.