relentless.model.potential.PairSpline#
- class relentless.model.potential.PairSpline(types, num_knots, mode='diff', name=None)#
Spline pair potential.
The pair 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.pair.Spline(types=('A',), num_knots=3) spline.from_array(('A','A'),[0,1,2],[4,2,0])
However, the knot variables can be iterated over and manipulated directly:
for r,k in spline.knots(('A','A')): k.value = 1.0
Methods
derivative(pair, var, r)Evaluate pair derivative with respect to a variable.
energy(pair, r)Evaluate pair energy.
force(pair, r)Evaluate pair force.
from_array(pair, r, 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(pair)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(pair, var, r)#
Evaluate pair derivative with respect to a variable.
The derivative is evaluated using the
_derivative()function for all \(u_{0,\lambda}(r)\). The truncation and shifting scheme is applied.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 pair derivative evaluated at
r. The return type is consistent withr.- Return type:
- Raises:
ValueError – If any value in
ris negative.TypeError – If the parameter with respect to which to take the derivative is not a
Variable.ValueError – If the potential is shifted without setting
rmax.
- energy(pair, r)#
Evaluate pair energy.
The energy is evaluated using the
_energy()function for \(u_0(r)\). The truncation and shifting scheme is applied.- Parameters:
- Returns:
The pair energy evaluated at
r. The return type is consistent withr.- Return type:
- Raises:
ValueError – If any value in
ris negative.ValueError – If the potential is shifted without setting
rmax.
- force(pair, r)#
Evaluate pair force.
The force is evaluated using the
_force()function for \(f_0(r)\). The truncation and shifting scheme is applied.- Parameters:
- Returns:
The pair force evaluated at
r. The return type is consistent withr.- Return type:
- Raises:
ValueError – If any value in
ris negative.
- from_array(pair, r, u)#
Set up the potential from knot points.
Each knot will be converted into two
Variableobjects consistent with the storagemode.- Parameters:
- Raises:
ValueError – If the number of
rvalues 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(pair)#
Generator for knot points.