Skip to content

Commit b88b34d

Browse files
committed
test_phonon_maker_initialization_with_all_mlff
1 parent 7d2655b commit b88b34d

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

tests/common/jobs/test_phonon.py

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1-
from jobflow import run_locally
1+
from jobflow import Flow, run_locally
22
from numpy.testing import assert_allclose
3-
from pymatgen.core.structure import Structure
3+
from pymatgen.core import Structure
44

55
from atomate2.common.jobs.phonons import get_supercell_size
6+
from atomate2.forcefields.flows.phonons import PhononMaker
7+
from atomate2.forcefields.jobs import ForceFieldRelaxMaker, ForceFieldStaticMaker
8+
from atomate2.forcefields.utils import MLFF
69

710

811
def test_phonon_get_supercell_size(clean_dir, si_structure: Structure):
@@ -12,3 +15,40 @@ def test_phonon_get_supercell_size(clean_dir, si_structure: Structure):
1215
responses = run_locally(job, create_folders=True, ensure_success=True)
1316

1417
assert_allclose(responses[job.uuid][1].output, [[6, -2, 0], [0, 6, 0], [-3, -2, 5]])
18+
19+
20+
def test_phonon_maker_initialization_with_all_mlff(si_structure):
21+
"""Test PhononMaker can be initialized with all MLFF static and relax makers."""
22+
23+
for mlff in MLFF:
24+
static_maker = ForceFieldStaticMaker(
25+
name=f"{mlff} static",
26+
force_field_name=str(mlff),
27+
)
28+
relax_maker = ForceFieldRelaxMaker(
29+
name=f"{mlff} relax",
30+
force_field_name=str(mlff),
31+
relax_kwargs={"fmax": 0.00001},
32+
)
33+
34+
try:
35+
phonon_maker = PhononMaker(
36+
bulk_relax_maker=relax_maker,
37+
static_energy_maker=static_maker,
38+
phonon_displacement_maker=static_maker,
39+
use_symmetrized_structure="conventional",
40+
create_thermal_displacements=False,
41+
store_force_constants=False,
42+
)
43+
44+
flow = phonon_maker.make(si_structure)
45+
assert isinstance(flow, Flow)
46+
assert len(flow) == 7, f"{len(flow)=}"
47+
assert flow[1].name == f"{mlff} relax", f"{flow[1].name=}"
48+
assert flow[3].name == f"{mlff} static", f"{flow[3].name=}"
49+
assert flow[4].name == "generate_phonon_displacements", f"{flow[4].name=}"
50+
assert flow[5].name == "run_phonon_displacements", f"{flow[5].name=}"
51+
52+
except Exception as exc:
53+
exc.add_note(f"Failed to initialize PhononMaker with {mlff=} makers")
54+
raise

0 commit comments

Comments
 (0)