Skip to content

Commit

Permalink
Fix writing xyz files (stfc#449)
Browse files Browse the repository at this point in the history
* Test writing xyz file

* Fix writing xyz files
  • Loading branch information
ElliottKasoar authored Feb 26, 2025
1 parent 43fdec7 commit 80882e8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion janus_core/helpers/struct_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def output_structs(
)

# write_results is only a valid kwarg for extxyz
if write_format in ("extxyz"):
if write_format == "extxyz":
write_kwargs.setdefault("write_results", not invalidate_calc)
else:
write_kwargs.pop("write_results", None)
Expand Down
16 changes: 14 additions & 2 deletions tests/test_geom_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,18 @@ def test_traj_reformat(tmp_path):
)

traj_path_binary = tmp_path / "NaCl.traj"
traj_path_xyz = tmp_path / "NaCl-traj.extxyz"
traj_path_xyz = tmp_path / "NaCl-traj.xyz"

optimizer = GeomOpt(
single_point.struct,
opt_kwargs={"trajectory": str(traj_path_binary)},
traj_kwargs={"filename": traj_path_xyz},
traj_kwargs={"filename": traj_path_xyz, "format": "xyz"},
)
optimizer.run()
traj = read(traj_path_xyz, index=":")

assert len(traj) == 3
assert traj[0].info == {}


def test_missing_traj_kwarg(tmp_path):
Expand Down Expand Up @@ -357,3 +358,14 @@ def test_logging(tmp_path):
assert log_file.exists()
assert "emissions" in single_point.struct.info
assert single_point.struct.info["emissions"] > 0


def test_write_xyz(tmp_path):
"""Test writing a non-extended xyz file."""
optimizer = GeomOpt(
struct=DATA_PATH / "NaCl-deformed.cif",
arch="mace_mp",
calc_kwargs={"model": MODEL_PATH},
fmax=0.1,
)
optimizer.run()

0 comments on commit 80882e8

Please sign in to comment.