Skip to content

Commit

Permalink
Add tests for writing singlepoint results
Browse files Browse the repository at this point in the history
  • Loading branch information
ElliottKasoar committed Mar 5, 2024
1 parent a4fc101 commit 6b7a13f
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_single_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from pathlib import Path

from ase.io import read
import pytest

from janus_core.single_point import SinglePoint
Expand Down Expand Up @@ -78,3 +79,35 @@ def test_single_point_traj():
results = single_point.run_single_point("energy")
assert results["energy"][0] == pytest.approx(-76.0605725422795)
assert results["energy"][1] == pytest.approx(-74.80419118083256)


def test_single_point_write(tmp_path):
"""Test writing singlepoint results."""
data_path = DATA_PATH / "NaCl.cif"
model_path = MODEL_PATH
results_path = tmp_path / "NaCl.xyz"
single_point = SinglePoint(
system=data_path,
architecture="mace",
model_paths=model_path,
)

assert "forces" not in single_point.sys.arrays
single_point.run_single_point(write_kwargs={"filename": results_path})

atoms = read(results_path)
assert atoms.get_potential_energy() is not None
assert "forces" in atoms.arrays


def test_single_point_write_missing():
"""Test writing singlepoint results."""
data_path = DATA_PATH / "NaCl.cif"
model_path = MODEL_PATH
single_point = SinglePoint(
system=data_path,
architecture="mace",
model_paths=model_path,
)
with pytest.raises(ValueError):
single_point.run_single_point(write_kwargs={"file": "file.xyz"})

0 comments on commit 6b7a13f

Please sign in to comment.