relentless.model.potential.BondSpline#

class relentless.model.potential.BondSpline(types, num_knots, mode='diff', name=None)#

Spline bond potentials.

The bonded spline potential is defined by interpolation through a set of knot points. The interpolation scheme uses Akima splines.

Parameters:
  • types (tuple[str]) – Types.

  • num_knots (int) – Number of knots.

  • mode (str) – Mode for storing the values of the knots in Variable that can be optimized. If mode='value', the knot amplitudes are manipulated directly. If mode='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], where id is 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.bond.BondSpline(types=("bondA",), num_knots=3)
spline.from_array(("bondA"),[0,1,2],[4,2,0])

However, the knot variables can be iterated over and manipulated directly:

for r,k in spline.knots("bondA"):
    k.value = 1.0

Methods

derivative(type_, var, r)

Evaluate bond derivative with respect to a variable.

energy(type_, r)

Evaluate potential energy.

force(type_, r)

Evaluate force magnitude.

from_array(types, 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(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

count

design_variables

Designable variables of the spline.

mode

Spline construction mode.

names

num_knots

Number of knots.

valid_modes

derivative(type_, var, r)#

Evaluate bond derivative with respect to a variable.

The derivative is evaluated using the _derivative() function for all \(u_{0,\lambda}(r)\).

The derivative will be carried out with respect to var for all Variable parameters. The appropriate chain rules are handled automatically. If the potential does not depend on var, the derivative will be zero by definition.

Parameters:
  • _type (tuple[str]) – The type for which to calculate the derivative.

  • var (Variable) – The variable with respect to which the derivative is calculated.

  • r (float or list) – The bond distance(s) at which to evaluate the derivative.

Returns:

The bond derivative evaluated at r. The return type is consistent with r.

Return type:

float or numpy.ndarray

Raises:
  • ValueError – If any value in r is negative.

  • TypeError – If the parameter with respect to which to take the derivative is not a Variable.

property design_variables#

Designable variables of the spline.

Type:

tuple

energy(type_, r)#

Evaluate potential energy.

Parameters:
  • type – Type parametrizing the potential in coeff.

  • r (float or list) – Potential energy coordinate.

Returns:

The pair energy evaluated at r. The return type is consistent with r.

Return type:

float or numpy.ndarray

Raises:

ValueError – If any value in r is negative.

force(type_, r)#

Evaluate force magnitude.

The force is the (negative) magnitude of the x gradient.

Parameters:
  • type – Type parametrizing the potential in coeff.

  • x (float or list) – Potential energy coordinate.

Returns:

The force evaluated at r. The return type is consistent with r.

Return type:

float or numpy.ndarray

Raises:

ValueError – If any value in r is negative.

from_array(types, r, u)#

Set up the potential from knot points.

Parameters:
  • types (tuple[str]) – The type for which to set up the potential.

  • r (list) – Position of each knot.

  • u (list) – Potential energy of each knot.

Raises:
  • ValueError – If the number of r values is not the same as the number of knots.

  • ValueError – If the number of u values 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, name overrides the value in the file. If True, the name in the file is always preserved. If False, the name in the file is always ignored, and a default name is created. If None, 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, name overrides the value in the JSON data. If True, the name in the JSON data is always preserved. If False, the name in the JSON data is always ignored, and a default name is created. If None, 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.

Parameters:

i (int) – Key for the knot variable.

Returns:

  • str – The parameter name of the \(x\) value.

  • str – The parameter name of the knot value.

Raises:

TypeError – If the knot key is not an integer.

knots(types)#

Generator for knot points.

Parameters:

types (tuple[str]) – The types for which to retrieve the knot points.

Yields:
  • Variable – The next \(dr\) variable in the parameters.

  • Variable – The next knot variable in the parameters.

property mode#

Spline construction mode.

Type:

str

property num_knots#

Number of knots.

Type:

int

save(filename)#

Save the potential to file as JSON data.

Parameters:

filename (str) – The name of the file to which to save the data.

to_json()#

Export potential to a JSON-compatible dictionary.

The JSON dictionary will contain the id and name of the potential, along with the JSON representation of its coefficients.

Returns:

Potential.

Return type:

dict