Skip to content

Commit bfbb00f

Browse files
committed
add molecule test for forcefield
1 parent b01ded5 commit bfbb00f

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

tests/conftest.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from jobflow.settings import JobflowSettings
1313
from maggma.stores import MemoryStore
1414
from monty.serialization import loadfn
15-
from pymatgen.core import Structure
15+
from pymatgen.core import Molecule, Structure
1616

1717
from atomate2.utils.log import initialize_logger
1818

@@ -117,6 +117,11 @@ def ba_ti_o3_structure(test_dir):
117117
return Structure.from_file(test_dir / "structures" / "BaTiO3.cif")
118118

119119

120+
@pytest.fixture
121+
def water_molecule(test_dir):
122+
return Molecule.from_file(test_dir / "molecules" / "water.xyz")
123+
124+
120125
@pytest.fixture(autouse=True)
121126
def mock_jobflow_settings(memory_jobstore):
122127
"""Mock the jobflow settings to use our specific jobstore (with data store)."""

tests/forcefields/test_jobs.py

+17-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import pytest
55
from jobflow import run_locally
6-
from pymatgen.core import Structure
6+
from pymatgen.core import Molecule, Structure
77
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
88
from pytest import approx, importorskip
99

@@ -319,9 +319,7 @@ def test_mace_relax_maker(
319319
assert output1.output.n_steps == 7
320320

321321

322-
def test_mace_mpa_0_relax_maker(
323-
si_structure: Structure,
324-
):
322+
def test_mace_mpa_0_relax_maker(si_structure: Structure, water_molecule: Molecule):
325323
job = ForceFieldRelaxMaker(
326324
force_field_name="MACE_MPA_0",
327325
steps=25,
@@ -333,12 +331,27 @@ def test_mace_mpa_0_relax_maker(
333331
# validating the outputs of the job
334332
output = responses[job.uuid][1].output
335333

334+
job_mol = ForceFieldRelaxMaker(
335+
force_field_name="MACE_MPA_0",
336+
steps=25,
337+
relax_kwargs={"fmax": 0.005},
338+
).make(water_molecule)
339+
# run the flow or job and ensure that it finished running successfully
340+
responses_mol = run_locally(job_mol, ensure_success=True)
341+
342+
# validating the outputs of the job
343+
output_mol = responses_mol[job_mol.uuid][1].output
344+
336345
assert output.ase_calculator_name == "MLFF.MACE_MPA_0"
337346
assert output.output.energy == pytest.approx(-10.829493522644043)
338347
assert output.output.structure.volume == pytest.approx(40.87471552602735)
339348
assert len(output.output.ionic_steps) == 4
340349
assert output.structure.volume == output.output.structure.volume
341350

351+
assert output_mol.ase_calculator_name == "MLFF.MACE_MPA_0"
352+
assert output_mol.output.energy == pytest.approx(-13.786081314086914)
353+
assert len(output_mol.output.ionic_steps) == 20
354+
342355

343356
def test_gap_static_maker(si_structure: Structure, test_dir):
344357
importorskip("quippy")

tests/test_data/molecules/water.xyz

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
3
2+
Water molecule
3+
O 0.00000 0.00000 0.11779
4+
H 0.00000 0.75545 -0.47116
5+
H 0.00000 -0.75545 -0.47116

0 commit comments

Comments
 (0)