Class CustomCompoundBondForce
- Direct Known Subclasses:
AngleTorsionForce
,InPlaneAngleForce
,OutOfPlaneBendForce
,PiOrbitalTorsionForce
,StretchBendForce
,StretchTorsionForce
We refer to the particles in a bond as p1, p2, p3, etc. For each bond, CustomCompoundBondForce evaluates a user supplied algebraic expression to determine the interaction energy. The expression may depend on the following variables and functions:
- x1, y1, z1, x2, y2, z2, etc.: The x, y, and z coordinates of the particle positions. For example, x1 is the x coordinate of particle p1, and y3 is the y coordinate of particle p3.
- distance(p1, p2): the distance between particles p1 and p2 (where "p1" and "p2" may be replaced by the names of whichever particles you want to calculate the distance between).
- angle(p1, p2, p3): the angle formed by the three specified particles.
- dihedral(p1, p2, p3, p4): the dihedral angle formed by the four specified particles, guaranteed to be in the range [-pi,+pi].
The expression also may involve tabulated functions, and may depend on arbitrary global and per-bond parameters.
To use this class, create a CustomCompoundBondForce object, passing an algebraic expression to the constructor that defines the interaction energy of each bond. Then call addPerBondParameter() to define per-bond parameters and addGlobalParameter() to define global parameters. The values of per-bond parameters are specified as part of the system definition, while values of global parameters may be modified during a simulation by calling Context::setParameter().
Next, call addBond() to define bonds and specify their parameter values. After a bond has been added, you can modify its parameters by calling setBondParameters(). This will have no effect on Contexts that already exist unless you call updateParametersInContext().
As an example, the following code creates a CustomCompoundBondForce that implements a Urey-Bradley potential. This is an interaction between three particles that depends on the angle formed by p1-p2-p3, and on the distance between p1 and p3.
CustomCompoundBondForce* force = new CustomCompoundBondForce(3, "0.5*(kangle*(angle(p1,p2,p3)-theta0)^2+kbond*(distance(p1,p3)-r0)^2)");
This force depends on four parameters: kangle, kbond, theta0, and r0. The following code defines these as per-bond parameters:
force->addPerBondParameter("kangle");
force->addPerBondParameter("kbond");
force->addPerBondParameter("theta0");
force->addPerBondParameter("r0");
This class also has the ability to compute derivatives of the potential energy with respect to global parameters. Call addEnergyParameterDerivative() to request that the derivative with respect to a particular parameter be computed. You can then query its value in a Context by calling getState() on it.
Expressions may involve the operators + (add), - (subtract), * (multiply), / (divide), and ˆ (power), and the following functions: sqrt, exp, log, sin, cos, sec, csc, tan, cot, asin, acos, atan, atan2, sinh, cosh, tanh, erf, erfc, min, max, abs, floor, ceil, step, delta, select. All trigonometric functions are defined in radians, and log is the natural logarithm. step(x) = 0 if x is less than 0, 1 otherwise. delta(x) = 1 if x is 0, 0 otherwise. select(x,y,z) = z if x = 0, y otherwise.
This class also supports the functions pointdistance(x1, y1, z1, x2, y2, z2), pointangle(x1, y1, z1, x2, y2, z2, x3, y3, z3), and pointdihedral(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4). These functions are similar to distance(), angle(), and dihedral(), but the arguments are the coordinates of points to perform the calculation based on rather than the names of particles. This enables more flexible geometric calculations. For example, the following computes the distance from particle p1 to the midpoint between particles p2 and p3.
CustomCompoundBondForce* force = new CustomCompoundBondForce(3, "pointdistance(x1, y1, z1, (x2+x3)/2, (y2+y3)/2, (z2+z3)/2)");
In addition, you can call addTabulatedFunction() to define a new function based on tabulated values. You specify the function by creating a TabulatedFunction object. That function can then appear in the expression.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionCustomCompoundBondForce
(int numParticles, String energy) Create a CustomCompoundBondForce. -
Method Summary
Modifier and TypeMethodDescriptionint
addBond
(IntArray particles, DoubleArray parameters) Add a bond to the force.void
Request that this Force compute the derivative of its energy with respect to a global parameter.int
addFunction
(String name, com.sun.jna.ptr.PointerByReference values, double min, double max) Deprecated.This method exists only for backward compatibility.int
addGlobalParameter
(String name, double defaultValue) Add a global parameter that the interaction may depend on.int
addPerBondParameter
(String name) Add a per-bond parameter that the interaction may depend on.int
addTabulatedFunction
(String name, com.sun.jna.ptr.PointerByReference function) Add a tabulated function that may appear in the energy expression.void
destroy()
Destroy the force.void
getBondParameters
(int index, IntArray particles, DoubleArray parameters) Get the parameters for a bond.Get the energy expression for the force.getEnergyParameterDerivativeName
(int index) Get the name of a parameter with respect to which the derivative of the energy should be computed.void
getFunctionParameters
(int index, com.sun.jna.ptr.PointerByReference name, com.sun.jna.ptr.PointerByReference values, com.sun.jna.ptr.DoubleByReference min, com.sun.jna.ptr.DoubleByReference max) Get the parameters for a tabulated function.void
getFunctionParameters
(int index, com.sun.jna.ptr.PointerByReference name, com.sun.jna.ptr.PointerByReference values, DoubleBuffer min, DoubleBuffer max) Get the parameters for a tabulated function.double
getGlobalParameterDefaultValue
(int index) Get the default value of a global parameter.getGlobalParameterName
(int index) Get the name of a global parameter.int
Get the number of bonds.int
Get the number of parameters with respect to which the derivative of the energy should be computed.int
Deprecated.This method exists only for backward compatibility.int
Get the number of global parameters.int
Get the number of particles per bond.int
Get the number of per-bond parameters.int
Get the number of tabulated functions.getPerBondParameterName
(int index) Get the name of a per-bond parameter.com.sun.jna.ptr.PointerByReference
getTabulatedFunction
(int index) Get a reference to a tabulated function.getTabulatedFunctionName
(int index) Get the name of a tabulated function.void
setBondParameters
(int index, IntArray particles, DoubleArray parameters) Set the parameters for a bond.void
setEnergyFunction
(String energy) Set the energy expression for the force.void
setFunctionParameters
(int index, String name, com.sun.jna.ptr.PointerByReference values, double min, double max) Set the parameters for a tabulated function.void
setGlobalParameterDefaultValue
(int index, double defaultValue) Set the default value of a global parameter.void
setGlobalParameterName
(int index, String name) Set the name of a global parameter.void
setPerBondParameterName
(int index, String name) Set the name of a per-bond parameter.void
setUsesPeriodicBoundaryConditions
(boolean periodic) Set whether this force should apply periodic boundary conditions when calculating displacements.void
updateParametersInContext
(Context context) Update the parameters in the context.boolean
Check if the force uses periodic boundary conditions.Methods inherited from class ffx.openmm.Force
getForceGroup, getForceIndex, getName, getPointer, setForceGroup, setForceIndex, setName
-
Constructor Details
-
CustomCompoundBondForce
Create a CustomCompoundBondForce.- Parameters:
numParticles
- The number of particles per bond.energy
- The energy expression for the force.
-
-
Method Details
-
addBond
Add a bond to the force.- Parameters:
particles
- The indices of the particles in the bond.parameters
- The bond parameters.- Returns:
- The index of the bond that was added.
-
addEnergyParameterDerivative
Request that this Force compute the derivative of its energy with respect to a global parameter.- Parameters:
name
- The name of the parameter to compute the derivative of the energy with respect to.
-
addFunction
@Deprecated public int addFunction(String name, com.sun.jna.ptr.PointerByReference values, double min, double max) Deprecated.This method exists only for backward compatibility. Use addTabulatedFunction() instead.Add a tabulated function that may appear in the energy expression.- Parameters:
name
- The name of the function as it appears in expressions.values
- The tabulated values of the function.min
- The minimum value of the independent variable for which the function is defined.max
- The maximum value of the independent variable for which the function is defined.- Returns:
- The index of the function that was added.
-
addGlobalParameter
Add a global parameter that the interaction may depend on.- Parameters:
name
- The name of the parameter.defaultValue
- The default value of the parameter.- Returns:
- The index of the parameter that was added.
-
addPerBondParameter
Add a per-bond parameter that the interaction may depend on.- Parameters:
name
- The name of the parameter.- Returns:
- The index of the parameter that was added.
-
addTabulatedFunction
Add a tabulated function that may appear in the energy expression.- Parameters:
name
- The name of the function as it appears in expressions.function
- A TabulatedFunction object defining the function.- Returns:
- The index of the function that was added.
-
destroy
public void destroy()Destroy the force. -
getBondParameters
Get the parameters for a bond.- Parameters:
index
- The index of the bond.particles
- The indices of the particles in the bond.parameters
- The bond parameters.
-
getEnergyFunction
Get the energy expression for the force.- Returns:
- The energy expression for the force.
-
getEnergyParameterDerivativeName
Get the name of a parameter with respect to which the derivative of the energy should be computed.- Parameters:
index
- The index of the parameter derivative.- Returns:
- The name of the parameter.
-
getFunctionParameters
public void getFunctionParameters(int index, com.sun.jna.ptr.PointerByReference name, com.sun.jna.ptr.PointerByReference values, DoubleBuffer min, DoubleBuffer max) Get the parameters for a tabulated function.- Parameters:
index
- The index of the function.name
- The name of the function.values
- The tabulated values.min
- The minimum value of the independent variable.max
- The maximum value of the independent variable.
-
getFunctionParameters
public void getFunctionParameters(int index, com.sun.jna.ptr.PointerByReference name, com.sun.jna.ptr.PointerByReference values, com.sun.jna.ptr.DoubleByReference min, com.sun.jna.ptr.DoubleByReference max) Get the parameters for a tabulated function.- Parameters:
index
- The index of the function.name
- The name of the function.values
- The tabulated values.min
- The minimum value of the independent variable.max
- The maximum value of the independent variable.
-
getGlobalParameterDefaultValue
public double getGlobalParameterDefaultValue(int index) Get the default value of a global parameter.- Parameters:
index
- The index of the parameter.- Returns:
- The default value of the parameter.
-
getGlobalParameterName
Get the name of a global parameter.- Parameters:
index
- The index of the parameter.- Returns:
- The name of the parameter.
-
getNumBonds
public int getNumBonds()Get the number of bonds.- Returns:
- The number of bonds.
-
getNumEnergyParameterDerivatives
public int getNumEnergyParameterDerivatives()Get the number of parameters with respect to which the derivative of the energy should be computed.- Returns:
- The number of parameters.
-
getNumFunctions
Deprecated.This method exists only for backward compatibility. Use getNumTabulatedFunctions() instead.Get the number of tabulated functions.- Returns:
- The number of tabulated functions.
-
getNumGlobalParameters
public int getNumGlobalParameters()Get the number of global parameters.- Returns:
- The number of global parameters.
-
getNumParticlesPerBond
public int getNumParticlesPerBond()Get the number of particles per bond.- Returns:
- The number of particles per bond.
-
getNumPerBondParameters
public int getNumPerBondParameters()Get the number of per-bond parameters.- Returns:
- The number of per-bond parameters.
-
getNumTabulatedFunctions
public int getNumTabulatedFunctions()Get the number of tabulated functions.- Returns:
- The number of tabulated functions.
-
getPerBondParameterName
Get the name of a per-bond parameter.- Parameters:
index
- The index of the parameter.- Returns:
- The name of the parameter.
-
getTabulatedFunction
public com.sun.jna.ptr.PointerByReference getTabulatedFunction(int index) Get a reference to a tabulated function.- Parameters:
index
- The index of the function.- Returns:
- A reference to the function.
-
getTabulatedFunctionName
Get the name of a tabulated function.- Parameters:
index
- The index of the function.- Returns:
- The name of the function.
-
setBondParameters
Set the parameters for a bond.- Parameters:
index
- The index of the bond.particles
- The indices of the particles in the bond.parameters
- The bond parameters.
-
setEnergyFunction
Set the energy expression for the force.- Parameters:
energy
- The energy expression for the force.
-
setFunctionParameters
public void setFunctionParameters(int index, String name, com.sun.jna.ptr.PointerByReference values, double min, double max) Set the parameters for a tabulated function.- Parameters:
index
- The index of the function.name
- The name of the function.values
- The tabulated values.min
- The minimum value of the independent variable.max
- The maximum value of the independent variable.
-
setGlobalParameterDefaultValue
public void setGlobalParameterDefaultValue(int index, double defaultValue) Set the default value of a global parameter.- Parameters:
index
- The index of the parameter.defaultValue
- The default value of the parameter.
-
setGlobalParameterName
Set the name of a global parameter.- Parameters:
index
- The index of the parameter.name
- The name of the parameter.
-
setPerBondParameterName
Set the name of a per-bond parameter.- Parameters:
index
- The index of the parameter.name
- The name of the parameter.
-
setUsesPeriodicBoundaryConditions
public void setUsesPeriodicBoundaryConditions(boolean periodic) Set whether this force should apply periodic boundary conditions when calculating displacements.- Parameters:
periodic
- If true, periodic boundary conditions will be used.
-
updateParametersInContext
Update the parameters in the context.- Parameters:
context
- The context to update.
-
usesPeriodicBoundaryConditions
public boolean usesPeriodicBoundaryConditions()Check if the force uses periodic boundary conditions.- Overrides:
usesPeriodicBoundaryConditions
in classForce
- Returns:
- True if the force uses periodic boundary conditions.
-