relentless.model.potential.BondedSpline#
- class relentless.model.potential.BondedSpline(types, num_knots, mode='diff', name=None)#
Base class for bonded spline potentials.
The bonded spline potential is defined by interpolation through a set of knot points. The interpolation scheme uses Akima splines.
This class should not be instantiated directly. Instead, use the appropriate spline type, i.e.,
BondSplineorAngleSpline.- Parameters:
num_knots (int) – Number of knots.
mode (str) – Mode for storing the values of the knots in
Variablethat can be optimized. Ifmode='value', the knot amplitudes are manipulated directly. Ifmode='diff', the amplitude of the last knot is fixed, and differences between neighboring knots are manipulated for all other knots. Defaults to'diff'.name (str) – Unique name of the potential. Defaults to
__u[id], whereidis the unique integer ID of the potential.
Methods
derivative(type_, var, x)Evaluate bond derivative with respect to a variable.
energy(type_, x)Evaluate potential energy.
force(type_, x)Evaluate force magnitude.
from_array(types, x, u)Set up the potential from knot points.
from_file(filename[, name])Create potential from a JSON file.
from_json(data[, name])Create potential from JSON data.
knot_params(i)Get the parameter names for a given knot.
knots(types)Generator for knot points.
save(filename)Save the potential to file as JSON data.
to_json()Export potential to a JSON-compatible dictionary.
Attributes
countDesignable variables of the spline.
Spline construction mode.
namesNumber of knots.
valid_modes- derivative(type_, var, x)#
Evaluate bond derivative with respect to a variable.
The derivative is evaluated using the
_derivative()function for all \(u_{0,\lambda}(x)\).The derivative will be carried out with respect to
varfor allVariableparameters. The appropriate chain rules are handled automatically. If the potential does not depend onvar, the derivative will be zero by definition.- Parameters:
- Returns:
The bond derivative evaluated at
x. The return type is consistent withx.- Return type:
- Raises:
ValueError – If any value in
xis negative.TypeError – If the parameter with respect to which to take the derivative is not a
Variable.
- energy(type_, x)#
Evaluate potential energy.
- Parameters:
- Returns:
The pair energy evaluated at
x. The return type is consistent withx.- Return type:
- force(type_, 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:
- from_array(types, x, u)#
Set up the potential from knot points.
- Parameters:
- Raises:
ValueError – If the number of
xvalues is not the same as the number of knots.ValueError – If the number of
uvalues is not the same as the number of knots.
- 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.
- knot_params(i)#
Get the parameter names for a given knot.
- knots(types)#
Generator for knot points.