relentless.model.potential.Potential#
- class relentless.model.potential.Potential(keys, params, container=None, name=None)#
Abstract base class for interaction potential.
A Potential defines the potential energy abstractly, which can be parametrized on a
key(like a type) and that is a function of an arbitrary scalar coordinatex. Concreteenergy(),force(), andderivative()methods must be implemented to define the potential energy (and its derivatives).- Parameters:
keys (list) – Keys for parametrizing the potential.
params (list) – Parameters of the potential.
container (object) – Container for storing coefficients. By default,
Parametersis used. The constructor of thecontainermust accept two arguments:keysandparams.name (str) – Unique name of the potential. Defaults to
__u[id], whereidis the unique integer ID of the potential.
Methods
derivative(key, var, x)Evaluate potential parameter derivative.
energy(key, x)Evaluate potential energy.
force(key, x)Evaluate force magnitude.
from_file(filename[, name])Create potential from a JSON file.
from_json(data[, name])Create potential from JSON data.
save(filename)Save the potential to file as JSON data.
to_json()Export potential to a JSON-compatible dictionary.
Attributes
countnames- abstract derivative(key, var, x)#
Evaluate potential parameter derivative.
- Parameters:
- Returns:
The potential parameter derivative evaluated at
x. The return type is consistent withx.- Return type:
- abstract energy(key, x)#
Evaluate potential energy.
- Parameters:
- Returns:
The pair energy evaluated at
x. The return type is consistent withx.- Return type:
- abstract force(key, x)#
Evaluate force magnitude.
The force is the (negative) magnitude of the
xgradient.- Parameters:
- Returns:
The force evaluated at
x. The return type is consistent withx.- Return type:
- classmethod from_file(filename, name=None)#
Create potential from a JSON file.
It is assumed that the JSON file is compatible with the potential type.
- Parameters:
filename (str) – JSON file to load.
name (str or bool or None) – Name of the potential. If a
str,nameoverrides the value in the file. IfTrue, the name in the file is always preserved. IfFalse, the name in the file is always ignored, and a default name is created. IfNone, the value in the file is used if it is not taken and does not match the default name pattern; otherwise, a new default name is generated.
- classmethod from_json(data, name=None)#
Create potential from JSON data.
It is assumed that the data is compatible with the pair potential.
- Parameters:
data (dict) – JSON data for potential.
name (str or bool or None) – Name of the potential. If a
str,nameoverrides the value in the JSON data. IfTrue, the name in the JSON data is always preserved. IfFalse, the name in the JSON data is always ignored, and a default name is created. IfNone, the value in the JSON data is used if it is not taken and does not match the default name pattern; otherwise, a new default name is generated.