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 bc4b1ac commit 6de2b19
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 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 @@ -73,3 +74,33 @@ 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"
results_path = tmp_path / "NaCl.xyz"
single_point = SinglePoint(
structure=data_path,
architecture="mace",
calc_kwargs={"model_paths": MODEL_PATH},
)

assert "forces" not in single_point.struct.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"
single_point = SinglePoint(
structure=data_path,
architecture="mace",
calc_kwargs={"model_paths": MODEL_PATH},
)
with pytest.raises(ValueError):
single_point.run_single_point(write_kwargs={"file": "file.xyz"})

0 comments on commit 6de2b19

Please sign in to comment.