44import numpy as np
55import pytest
66from jobflow import run_locally
7- from pymatgen .core import Structure
7+ from pymatgen .core import Molecule , Structure
88from pymatgen .symmetry .analyzer import SpacegroupAnalyzer
99from pytest import approx , importorskip
1010
1111from atomate2 .forcefields .jobs import ForceFieldRelaxMaker , ForceFieldStaticMaker
12- from atomate2 .forcefields .schemas import ForceFieldTaskDocument
12+ from atomate2 .forcefields .schemas import (
13+ ForceFieldMoleculeTaskDocument ,
14+ ForceFieldTaskDocument ,
15+ )
1316
1417
1518def test_maker_initialization ():
@@ -299,9 +302,7 @@ def test_mace_relax_maker(
299302 assert output1 .output .n_steps == 7
300303
301304
302- def test_mace_mpa_0_relax_maker (
303- si_structure : Structure ,
304- ):
305+ def test_mace_mpa_0_relax_maker (si_structure : Structure , test_dir : Path , tmp_dir ):
305306 job = ForceFieldRelaxMaker (
306307 force_field_name = "MACE_MPA_0" ,
307308 steps = 25 ,
@@ -313,12 +314,29 @@ def test_mace_mpa_0_relax_maker(
313314 # validating the outputs of the job
314315 output = responses [job .uuid ][1 ].output
315316
317+ water_molecule = Molecule .from_file (test_dir / "molecules" / "water.xyz.gz" )
318+ job_mol = ForceFieldRelaxMaker (
319+ force_field_name = "MACE_MPA_0" ,
320+ steps = 25 ,
321+ relax_kwargs = {"fmax" : 0.005 },
322+ ).make (water_molecule )
323+ # run the flow or job and ensure that it finished running successfully
324+ responses_mol = run_locally (job_mol , ensure_success = True )
325+
326+ # validating the outputs of the job
327+ output_mol = responses_mol [job_mol .uuid ][1 ].output
328+ assert isinstance (output_mol , ForceFieldMoleculeTaskDocument )
329+
316330 assert output .ase_calculator_name == "MLFF.MACE_MPA_0"
317331 assert output .output .energy == pytest .approx (- 10.829493522644043 )
318332 assert output .output .structure .volume == pytest .approx (40.87471552602735 )
319333 assert len (output .output .ionic_steps ) == 4
320334 assert output .structure .volume == output .output .structure .volume
321335
336+ assert output_mol .ase_calculator_name == "MLFF.MACE_MPA_0"
337+ assert output_mol .output .energy == pytest .approx (- 13.786081314086914 )
338+ assert len (output_mol .output .ionic_steps ) == 20
339+
322340
323341def test_gap_static_maker (si_structure : Structure , test_dir ):
324342 importorskip ("quippy" )
@@ -522,14 +540,16 @@ def test_nequip_relax_maker(
522540 assert final_spg_num == 99
523541
524542
525- def test_deepmd_static_maker (sr_ti_o3_structure : Structure , test_dir : Path ):
543+ def test_deepmd_static_maker (
544+ sr_ti_o3_structure : Structure , test_dir : Path , get_deepmd_pretrained_model_path
545+ ):
526546 importorskip ("deepmd" )
527547
528548 # generate job
529549 job = ForceFieldStaticMaker (
530550 force_field_name = "DeepMD" ,
531551 ionic_step_data = ("structure" , "energy" ),
532- calculator_kwargs = {"model" : test_dir / "forcefields" / "deepmd_graph.pb" },
552+ calculator_kwargs = {"model" : get_deepmd_pretrained_model_path },
533553 ).make (sr_ti_o3_structure )
534554
535555 # run the flow or job and ensure that it finished running successfully
@@ -552,6 +572,7 @@ def test_deepmd_relax_maker(
552572 test_dir : Path ,
553573 relax_cell : bool ,
554574 fix_symmetry : bool ,
575+ get_deepmd_pretrained_model_path : Path ,
555576):
556577 importorskip ("deepmd" )
557578 # translate one atom to ensure a small number of relaxation steps are taken
@@ -563,7 +584,7 @@ def test_deepmd_relax_maker(
563584 optimizer_kwargs = {"optimizer" : "BFGSLineSearch" },
564585 relax_cell = relax_cell ,
565586 fix_symmetry = fix_symmetry ,
566- calculator_kwargs = {"model" : test_dir / "forcefields" / "deepmd_graph.pb" },
587+ calculator_kwargs = {"model" : get_deepmd_pretrained_model_path },
567588 ).make (sr_ti_o3_structure )
568589
569590 # run the flow or job and ensure that it finished running successfully
0 commit comments