Skip to content

Commit

Permalink
add molecule test for forcefield
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoyi92 committed Feb 18, 2025
1 parent e41ecd1 commit 1e8c488
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from jobflow.settings import JobflowSettings
from maggma.stores import MemoryStore
from monty.serialization import loadfn
from pymatgen.core import Structure
from pymatgen.core import Molecule, Structure

from atomate2.utils.log import initialize_logger

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


@pytest.fixture
def water_molecule(test_dir):
return Molecule.from_file(test_dir / "molecules" / "water.xyz")


@pytest.fixture(autouse=True)
def mock_jobflow_settings(memory_jobstore):
"""Mock the jobflow settings to use our specific jobstore (with data store)."""
Expand Down
21 changes: 17 additions & 4 deletions tests/forcefields/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from jobflow import run_locally
from pymatgen.core import Structure
from pymatgen.core import Molecule, Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pytest import approx, importorskip

Expand Down Expand Up @@ -319,9 +319,7 @@ def test_mace_relax_maker(
assert output1.output.n_steps == 7


def test_mace_mpa_0_relax_maker(
si_structure: Structure,
):
def test_mace_mpa_0_relax_maker(si_structure: Structure, water_molecule: Molecule):
job = ForceFieldRelaxMaker(
force_field_name="MACE_MPA_0",
steps=25,
Expand All @@ -333,12 +331,27 @@ def test_mace_mpa_0_relax_maker(
# validating the outputs of the job
output = responses[job.uuid][1].output

job_mol = ForceFieldRelaxMaker(
force_field_name="MACE_MPA_0",
steps=25,
relax_kwargs={"fmax": 0.005},
).make(water_molecule)
# run the flow or job and ensure that it finished running successfully
responses_mol = run_locally(job_mol, ensure_success=True)

# validating the outputs of the job
output_mol = responses_mol[job_mol.uuid][1].output

assert output.ase_calculator_name == "MLFF.MACE_MPA_0"
assert output.output.energy == pytest.approx(-10.829493522644043)
assert output.output.structure.volume == pytest.approx(40.87471552602735)
assert len(output.output.ionic_steps) == 4
assert output.structure.volume == output.output.structure.volume

assert output_mol.ase_calculator_name == "MLFF.MACE_MPA_0"
assert output_mol.output.energy == pytest.approx(-13.786081314086914)
assert len(output_mol.output.ionic_steps) == 20


def test_gap_static_maker(si_structure: Structure, test_dir):
importorskip("quippy")
Expand Down
5 changes: 5 additions & 0 deletions tests/test_data/molecules/water.xyz
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
3
Water molecule
O 0.00000 0.00000 0.11779
H 0.00000 0.75545 -0.47116
H 0.00000 -0.75545 -0.47116

0 comments on commit 1e8c488

Please sign in to comment.