relentless.model.potential.PairPotential#

class relentless.model.potential.PairPotential(types, params, name=None)#

Abstract base class for a pair potential.

This class can be extended to evaluate the energy, force, and parameter derivatives of a pair potential with a given functional form. _energy() specifies the potential energy \(u_0(r)\), _force() specifies the force \(f_0(r) = -\partial u_0/\partial r\), and _derivative() specifies the derivative \(u_{0,\lambda} = \partial u_0/\partial \lambda\) with respect to parameter \(\lambda\).

Truncation and shifting

The underlying pair potential can be truncated at a minimum distance \(r_{\rm min}\) and maximum distance \(r_{\rm max}\). The truncation scheme is based on that used in molecular dynamics simulations, where the force is discontinuous and the pair potential is continuous.

This makes the effective pair potential

\[\begin{split}u(r) = \begin{cases} u_0(r_{\rm min}),& r < r_{\rm min} \\ u_0(r),& r_{\rm min} \le r \le r_{\rm max} \\ u_0(r_{\rm max}),& r > r_{\rm max} \end{cases},\end{split}\]

the effective pair force

\[\begin{split}f(r) = \begin{cases} 0,& r < r_{\rm min} \\ f_0(r),& r_{\rm min} \le r \le r_{\rm max} \\ 0,& r > r_{\rm max} \end{cases},\end{split}\]

and the effective pair derivative

\[\begin{split}u_\lambda(r) = \begin{cases} u_{0,\lambda}(r_{\rm min}),& r < r_{\rm min} \\ u_{0,\lambda}(r),& r_{\rm min} \le r \le r_{\rm max} \\ u_{0,\lambda}(r_{\rm max}),& r > r_{\rm max} \end{cases}.\end{split}\]

Two special cases are the derivative with respect to \(r_{\rm min}\)

\[\begin{split}u_{r_{\rm min}}(r) = \begin{cases} -f_0(r_{\rm min}),& r < r_{\rm min} \\ 0,& \textrm{otherwise} \end{cases}\end{split}\]

and with respect to \(r_{\rm max}\):

\[\begin{split}u_{r_{\rm max}}(r) = \begin{cases} -f_0(r_{\rm max}),& r > r_{\rm max} \\ 0,& \textrm{otherwise} \end{cases}.\end{split}\]

The pair potential can also be shifted to zero at \(r_{\rm max}\). Shifting subtracts \(u_0(r_{\rm max})\) from all pieces of \(u(r)\) and \(-f_0(r_{\rm max})\) from all parameter derivatives. The force is unaffected by shifting the pair potential.

The parameters rmin, rmax, and shift will automatically be included in coeff with initial values of False, which indicate that the potential should not be truncated or shifted.

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

  • params (tuple[str]) – Required parameters.

  • name (str) – Unique name of the potential. Defaults to __u[id], where id is the unique integer ID of the potential.

coeff#

Parameters of the potential for each pair.

Type:

PairParameters

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_file(filename)

Create potential from a JSON file.

from_json(data)

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

count

names

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 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:
  • pair (tuple[str]) – The pair for which to calculate the derivative.

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

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

Returns:

The pair 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.

  • 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:
  • pair (tuple[str]) – The pair for which to calculate the energy.

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

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.

  • 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:
  • pair (tuple[str]) – The pair for which to calculate the force.

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

Returns:

The pair 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.

classmethod from_file(filename)#

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.

classmethod from_json(data)#

Create potential from JSON data.

It is assumed that the data is compatible with the pair potential.

Parameters:

data (dict) – JSON data for potential.

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