Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Castep ase323 update #330

Merged
merged 9 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions tests/calculators/test_castep.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ def test_castep_calculation(tmp_path):
)

atoms.calc = calc
assert atoms.get_potential_energy() == approx(-217.2263559019)
assert atoms.get_forces() == approx(np.array([[-0., -0., 0.], [ 0., 0., -0.]]))
assert atoms.get_stress() == approx(np.array([ 0.06361731, 0.06361731, 0.06361731,-0., 0., 0.]))
assert atoms.get_potential_energy() == approx(-217.2263559019, 2e-3)
assert atoms.get_forces() == approx(np.array([[-0., -0., 0.], [ 0., 0., -0.]]), abs=1e-4)
assert atoms.get_stress() == approx(np.array([ 0.06361731, 0.06361731, 0.06361731,-0., 0., 0.]), abs=1e-5)


def test_castep_calc_via_generic(tmp_path):
Expand Down
16 changes: 12 additions & 4 deletions wfl/calculators/castep.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

from copy import deepcopy

from packaging.version import Version

import ase
from ase.calculators.calculator import all_changes
from ase.calculators.castep import Castep as ASE_Castep

Expand Down Expand Up @@ -51,6 +54,10 @@ def __init__(self, keep_files="default", rundir_prefix="run_CASTEP_",
workdir=None, scratchdir=None,
calculator_exec=None, **kwargs):

if Version(ase.__version__) < Version("3.23"):
raise ImportError(f"The wfl CASTEP calculator is only compatible with ASE v3.23 and higher, "
f"but your ASE version is v{ase.__version__}. Please upgrade")

kwargs = deepcopy(kwargs)
if calculator_exec is not None:
if "castep_command" in kwargs:
Expand Down Expand Up @@ -83,7 +90,7 @@ def calculate(self, atoms=None, properties=_default_properties, system_changes=a

orig_pbc = self.atoms.pbc.copy()
try:
super().calculate(atoms=atoms)
super().calculate(atoms=atoms, properties=properties, system_changes=system_changes)
bernstei marked this conversation as resolved.
Show resolved Hide resolved
calculation_succeeded = True
if 'DFT_FAILED_CASTEP' in atoms.info:
del atoms.info['DFT_FAILED_CASTEP']
Expand All @@ -95,17 +102,18 @@ def calculate(self, atoms=None, properties=_default_properties, system_changes=a
# ASE castep calculator does not ever raise an exception when
# it fails. Instead, you get things like stress being None,
# which lead to TypeError when save_calc_results calls get_stress().
for property in properties:
result = self.get_property(property)
for prop in properties:
result = self.get_property(prop, allow_calculation=False)
bernstei marked this conversation as resolved.
Show resolved Hide resolved
if result is None:
calculation_succeeded = False
atoms.info["DFT_FAILED_CASTEP"] = True
break

# from WFLFileIOCalculator
self.clean_rundir(_default_keep_files, calculation_succeeded)

# reset pbc because Castep overwrites it to True
self.atoms.pbc = orig_pbc(False)
self.atoms.pbc = orig_pbc


def setup_calc_params(self, properties):
Expand Down
Loading