forked from stfc/janus-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test and document external calculators (stfc#383)
* Add docs for external calculators * Test Lennard Jones calculator
- Loading branch information
1 parent
d4d4b32
commit 4e0d1cd
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Test external ASE calculators.""" | ||
|
||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
|
||
from ase.calculators.lj import LennardJones | ||
from ase.io import read | ||
import numpy as np | ||
import pytest | ||
|
||
from janus_core.calculations.geom_opt import GeomOpt | ||
from janus_core.calculations.single_point import SinglePoint | ||
|
||
DATA_PATH = Path(__file__).parent / "data" | ||
|
||
|
||
def test_single_point(): | ||
"""Test single point calculation using LJ calculator.""" | ||
struct = read(DATA_PATH / "NaCl.cif") | ||
struct.calc = LennardJones() | ||
single_point = SinglePoint(struct=struct, properties="energy") | ||
results = single_point.run() | ||
|
||
assert isinstance(struct.calc, LennardJones) | ||
assert results["energy"] == pytest.approx(-0.05900093815771919) | ||
|
||
|
||
def test_geom_opt(): | ||
"""Test geometry optimisation using LJ calculator.""" | ||
struct = read(DATA_PATH / "NaCl-deformed.cif") | ||
struct.calc = LennardJones() | ||
geom_opt = GeomOpt(struct=struct, fmax=0.01) | ||
geom_opt.run() | ||
|
||
assert isinstance(geom_opt.struct.calc, LennardJones) | ||
assert struct.get_forces() == pytest.approx(np.zeros((8, 3))) |