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, andshiftwill automatically be included incoeffwith initial values ofFalse, which indicate that the potential should not be truncated or shifted.- Parameters:
- coeff#
Parameters of the potential for each pair.
- Type:
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
countnames- 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.
- 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.