Skip to content

Commit

Permalink
pysisyphus: fix ase test
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepforce committed Sep 9, 2024
1 parent 96b9ca9 commit 6cf5da6
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
48 changes: 48 additions & 0 deletions pkgs/python-by-name/pysisyphus/ase.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
diff --git a/pysisyphus/calculators/FakeASE.py b/pysisyphus/calculators/FakeASE.py
index 913b40567..0ef644b81 100644
--- a/pysisyphus/calculators/FakeASE.py
+++ b/pysisyphus/calculators/FakeASE.py
@@ -1,6 +1,13 @@
+import warnings
+
from pysisyphus.constants import BOHR2ANG

+
class FakeASE:
+ """Pysisyphus calculator mimicing an ASE calculator.
+
+ Instances of this class can be set as calculators on ASE Atoms
+ objects."""

def __init__(self, calc):
self.calc = calc
@@ -8,12 +15,15 @@ def __init__(self, calc):
self.results = dict()

def get_atoms_coords(self, atoms):
- return (atoms.get_chemical_symbols(),
- # Convert ASE Angstrom to Bohr for pysisyphus
- atoms.get_positions().flatten() / BOHR2ANG
+ return (
+ atoms.get_chemical_symbols(),
+ # Convert ASE Angstrom to Bohr for pysisyphus
+ atoms.get_positions().flatten() / BOHR2ANG,
)

- def get_potential_energy(self, atoms=None):
+ def get_potential_energy(self, atoms=None, force_consistent=True):
+ if not force_consistent:
+ warnings.warn("force_consistent=False is ignored by FakeASE!")
atoms, coords = self.get_atoms_coords(atoms)
results = self.calc.get_energy(atoms, coords)

diff --git a/tests/test_fake_ase/test_fake_ase.py b/tests/test_fake_ase/test_fake_ase.py
index 06c80aa8e..5a578628b 100644
--- a/tests/test_fake_ase/test_fake_ase.py
+++ b/tests/test_fake_ase/test_fake_ase.py
@@ -34,4 +34,4 @@ def test_fake_ase_opt():

assert dyn.converged()
assert dyn.get_number_of_steps() == 14
- assert np.linalg.norm(dyn.f0) == pytest.approx(0.0041871980)
+ assert np.linalg.norm(dyn.forces0) == pytest.approx(0.0041871980)
5 changes: 5 additions & 0 deletions pkgs/python-by-name/pysisyphus/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ buildPythonPackage rec {
hash = "sha256-PBccu+Vx2knzms8ezlWPUBFh3iNr32/tF9E7c3woKzI=";
};

patches = [
# Fixes test failing by changed ASE API. Remove with next update
./ase.patch
];

format = "pyproject";

preBuild = "export SETUPTOOLS_SCM_PRETEND_VERSION=0.8.0b1";
Expand Down

0 comments on commit 6cf5da6

Please sign in to comment.