Skip to content

Commit e2968b0

Browse files
authored
add file output xyz file including final atoms object to ase and forcefield jobs (#1206)
* add file output to ase and forcefield jobs * remove useless file
1 parent 0e50e07 commit e2968b0

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/atomate2/ase/utils.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from ase.constraints import FixSymmetry
1717
from ase.filters import FrechetCellFilter
1818
from ase.io import Trajectory as AseTrajectory
19+
from ase.io import write
1920
from ase.optimize import BFGS, FIRE, LBFGS, BFGSLineSearch, LBFGSLineSearch, MDMin
2021
from ase.optimize.sciopt import SciPyFminBFGS, SciPyFminCG
2122
from monty.serialization import dumpfn
@@ -328,6 +329,7 @@ def relax(
328329
fmax: float = 0.1,
329330
steps: int = 500,
330331
traj_file: str = None,
332+
final_atoms_object_file: str = "final_atoms_object.xyz",
331333
interval: int = 1,
332334
verbose: bool = False,
333335
cell_filter: Filter = FrechetCellFilter,
@@ -346,6 +348,8 @@ def relax(
346348
Max number of steps for relaxation.
347349
traj_file : str
348350
The trajectory file for saving.
351+
final_atoms_object_file: str
352+
The final atoms object file for saving.
349353
interval : int
350354
The step interval for saving the trajectories.
351355
verbose : bool
@@ -389,6 +393,9 @@ def relax(
389393
np.linalg.norm(traj.frame_properties[-1]["forces"][idx]) < abs(fmax)
390394
for idx in range(len(struct))
391395
)
396+
if final_atoms_object_file is not None:
397+
write(final_atoms_object_file, atoms, format="extxyz", append=True)
398+
392399
return AseResult(
393400
final_mol_or_struct=struct,
394401
trajectory=traj,

tests/forcefields/test_jobs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def test_m3gnet_relax_maker(si_structure):
193193

194194

195195
@mace_paths
196-
def test_mace_static_maker(si_structure: Structure, test_dir: Path, model):
196+
def test_mace_static_maker(si_structure: Structure, clean_dir, model):
197197
# generate job
198198
# NOTE the test model is not trained on Si, so the energy is not accurate
199199
job = ForceFieldStaticMaker(
@@ -212,6 +212,8 @@ def test_mace_static_maker(si_structure: Structure, test_dir: Path, model):
212212
assert output1.output.n_steps == 1
213213
assert output1.forcefield_version == get_imported_version("mace-torch")
214214

215+
assert Path("final_atoms_object.xyz").exists()
216+
215217
with pytest.warns(FutureWarning):
216218
MACEStaticMaker()
217219

0 commit comments

Comments
 (0)