relentless.model.potential.DihedralSpline#
- class relentless.model.potential.DihedralSpline(types, num_knots, mode='diff', name=None)#
Spline dihedral potentials.
The dihedral spline potential is defined by interpolation through a set of knot points. The interpolation scheme uses Akima splines.
- 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.
Examples
The spline potential is setup from a tabulated potential instead of specifying knot parameters directly:
spline = relentless.potential.dihedral.DihedralSpline( types=("dihedralA",), num_knots=3, ) spline.from_array(("dihedralA"),[0,1,2],[4,2,0])
However, the knot variables can be iterated over and manipulated directly:
for r,k in spline.knots("dihedralA"): k.value = 1.0
Methods
derivative(type_, var, phi)Evaluate derivative with respect to a variable.
energy(type_, phi)Evaluate potential energy.
force(type_, phi)Evaluate force magnitude.
from_array(types, phi, 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, phi)#
Evaluate derivative with respect to a variable.
The derivative is evaluated using the
_derivative()function for all \(u_{0,\lambda}(phi)\).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 dihedral derivative evaluated at
phi. The return type is consistent withphi.- Return type:
- Raises:
ValueError – If any value in
phiis not between -pi and pi.TypeError – If the parameter with respect to which to take the derivative is not a
Variable.
- energy(type_, phi)#
Evaluate potential energy.
- Parameters:
- Returns:
The pair energy evaluated at
phi. The return type is consistent withphi.- Return type:
- Raises:
ValueError – If any value in
phiis outside of -pi to pi.
- force(type_, phi)#
Evaluate force magnitude.
The force is the (negative) magnitude of the
phigradient.- Parameters:
- Returns:
The force evaluated at
phi. The return type is consistent withphi.- Return type:
- Raises:
ValueError – If any value in
phiis outside of -pi to pi.
- from_array(types, phi, u)#
Set up the potential from knot points.
- Parameters:
- Raises:
ValueError – If the number of
phivalues 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.