Skip to content

Commit

Permalink
Merge pull request #1 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Added name and configuration to the calculator to keep track of different instances.
  • Loading branch information
seamm authored Aug 17, 2024
2 parents 3eca65f + 4fefc31 commit 65b4815
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions seamm_ase/seamm_ase.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

__all__ = ["SEAMM_Calculator"]

import logging

from ase.calculators.calculator import (
Calculator as ASE_Calculator,
all_changes as ASE_all_changes,
register_calculator_class,
)

logger = logging.getLogger(__name__)


class SEAMM_Calculator(ASE_Calculator):
"""Generic ASE calculator for SEAMM.
Expand Down Expand Up @@ -60,7 +65,7 @@ def calculator(
implemented_properties = ["energy", "forces"]
nolabel = True

def __init__(self, step, **kwargs):
def __init__(self, step, calculator=None, name=None, configuration=None, **kwargs):
"""
Parameters
----------
Expand All @@ -71,8 +76,26 @@ def __init__(self, step, **kwargs):
The keyword arguments are passed to the parent class.
"""
self.step = step
self.calculator = calculator # Method or function to call
self._name = name
self._configuration = configuration

super().__init__(**kwargs)

@property
def configuration(self):
"""The configuration this calculator represents."""
return self._configuration

@property
def name(self):
"""A name for this calculator."""
if self._name is None and self.configuration is not None:
name = self.configuration.system.name + "/" + self.configuration.name
return name
else:
return self._name

def calculate(
self,
atoms=None,
Expand All @@ -97,4 +120,25 @@ def calculate(
"""
super().calculate(atoms, properties, system_changes)

self.step.calculator(self, properties, system_changes)
logger.debug(f"SEAMM_Calculator.calculate {self.name} {properties=}")
logger.debug(f" {system_changes=}")
logger.debug(f" {atoms is None=}")

if self.calculator is None:
self.step.calculate(self, properties, system_changes)
else:
self.calculator(self, properties, system_changes)

def check_state(self, atoms, tol=1e-10):
"""Check for any system changes since last calculation."""
return super().check_state(atoms, tol=tol)

def get_property(self, name, atoms=None, allow_calculation=True):
logger.debug(f"SEAMM_Calculator.get_property {self.name} {name=}")

return super().get_property(
name, atoms=atoms, allow_calculation=allow_calculation
)


register_calculator_class("seamm", SEAMM_Calculator)

0 comments on commit 65b4815

Please sign in to comment.