Base Calculators¶
This module provides calculator classes which serve as abstract base
classes for other types for calculators. Note that calculators defined
here do not act as direct base classes for calculators which are used
by users. The ususal inheritance scheme is Calculator
is
subclassed by CalculatorType
which is subclassed by
UserCalculatorType
. For example, Calculator
is
subclassed by Optimizer
and Optimizer
is
subclassed by ETKDG
. Only ETKDG
is instantiated
and used by the user. Note that Optimizer
does not
subclass Calculator
directly, it is subclassed via
MolecularCalculator
, this is an implementation detail of the
Optimizer
class.
Calculator
simply serves as a common abstract base class
for every other stk
calculator. The direct subclass of
Calculator
is an abstract base class which defines a new
type of calculator for stk
, for example Optimizer
or EnergyCalculator
. These define an interface for the new
type of calculation. Finally the subclasses of Optimizer
or
EnergyCalculator
implement the calculation. For example
ETKDG
or :class:`.MMFF``or different implementations of an
optimization, which the user can use.
For some of the abstract base classes provided here, an implementation is also provided. If the implementation is inherited, the abstract base class it implements should also be inherited, explicitly and directly. This is because inheriting the implementation class is purely an implementation detail that should be treated as invisible to the user of the class.
-
class
Calculator
¶ Bases:
object
Abstract base class for all calculators.
-
__init__
(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
-
class
EAOperation
¶ Bases:
stk.calculators.base_calculators.Calculator
Abstract base class for operations such as mutation or crossover.
Methods
set_cache_use
(self, use_cache)Set use of the molecular cache on or off.
-
__init__
(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
set_cache_use
(self, use_cache)¶ Set use of the molecular cache on or off.
- Parameters
use_cache (
bool
) –True
if the molecular cache is to be used.- Returns
The calculator.
- Return type
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-
-
class
MoleculeCalculator
¶ Bases:
stk.calculators.base_calculators.Calculator
Abstract base class for calculators used on single molecules.
Methods
add_to_cache
(self, mol[, value])Add a molecule to the cache.
get_cached_value
(self, mol)Return the value stored in the cache for mol.
is_caching
(self)True
if the calculator has caching turned on.is_in_cache
(self, mol)Return
True
if mol is cached.set_cache_use
(self, use_cache)Set cache use on or off.
-
__init__
(self, /, *args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
add_to_cache
(self, mol, value=None)¶ Add a molecule to the cache.
- Parameters
mol (
Molecule
) – The molecule to be added to the cache.value (class:object, optional) – The cached value associated with the molecule.
- Returns
The calculator.
- Return type
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-
get_cached_value
(self, mol)¶ Return the value stored in the cache for mol.
- Parameters
mol (
Molecule
) – The molecule whose cached value is to be returned.- Returns
The cached value.
- Return type
object
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-
is_caching
(self)¶ True
if the calculator has caching turned on.- Returns
True
if the calculator has caching turned on.- Return type
bool
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-
is_in_cache
(self, mol)¶ Return
True
if mol is cached.- Parameters
mol (
Molecule
) – The molecule being checked.- Returns
True
if mol is cached.- Return type
bool
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-
set_cache_use
(self, use_cache)¶ Set cache use on or off.
- Parameters
use_cache (
bool
) –True
if the cache is to be used.- Returns
The calculator.
- Return type
- Raises
NotImplementedError – This is a virtual method and needs to be implemented in a subclass.
-