OpenMM
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CustomHbondForce Class Reference

This class supports a wide variety of energy functions used to represent hydrogen bonding. More...

#include <CustomHbondForce.h>

+ Inheritance diagram for CustomHbondForce:

Public Types

enum  NonbondedMethod { NoCutoff = 0, CutoffNonPeriodic = 1, CutoffPeriodic = 2 }
 This is an enumeration of the different methods that may be used for handling long range nonbonded forces. More...
 

Public Member Functions

 CustomHbondForce (const std::string &energy)
 Create a CustomHbondForce. More...
 
int getNumDonors () const
 Get the number of donors for which force field parameters have been defined. More...
 
int getNumAcceptors () const
 Get the number of acceptors for which force field parameters have been defined. More...
 
int getNumExclusions () const
 Get the number of donor-acceptor pairs whose interactions should be excluded. More...
 
int getNumPerDonorParameters () const
 Get the number of per-donor parameters that the interaction depends on. More...
 
int getNumPerAcceptorParameters () const
 Get the number of per-acceptor parameters that the interaction depends on. More...
 
int getNumGlobalParameters () const
 Get the number of global parameters that the interaction depends on. More...
 
int getNumFunctions () const
 Get the number of tabulated functions that have been defined. More...
 
const std::string & getEnergyFunction () const
 Get the algebraic expression that gives the interaction energy between a donor and an acceptor. More...
 
void setEnergyFunction (const std::string &energy)
 Set the algebraic expression that gives the interaction energy between a donor and an acceptor. More...
 
NonbondedMethod getNonbondedMethod () const
 Get the method used for handling long range nonbonded interactions. More...
 
void setNonbondedMethod (NonbondedMethod method)
 Set the method used for handling long range nonbonded interactions. More...
 
double getCutoffDistance () const
 Get the cutoff distance (in nm) being used. More...
 
void setCutoffDistance (double distance)
 Set the cutoff distance (in nm) being used. More...
 
int addPerDonorParameter (const std::string &name)
 Add a new per-donor parameter that the interaction may depend on. More...
 
const std::string & getPerDonorParameterName (int index) const
 Get the name of a per-donor parameter. More...
 
void setPerDonorParameterName (int index, const std::string &name)
 Set the name of a per-donor parameter. More...
 
int addPerAcceptorParameter (const std::string &name)
 Add a new per-acceptor parameter that the interaction may depend on. More...
 
const std::string & getPerAcceptorParameterName (int index) const
 Get the name of a per-acceptor parameter. More...
 
void setPerAcceptorParameterName (int index, const std::string &name)
 Set the name of a per-acceptor parameter. More...
 
int addGlobalParameter (const std::string &name, double defaultValue)
 Add a new global parameter that the interaction may depend on. More...
 
const std::string & getGlobalParameterName (int index) const
 Get the name of a global parameter. More...
 
void setGlobalParameterName (int index, const std::string &name)
 Set the name of a global parameter. More...
 
double getGlobalParameterDefaultValue (int index) const
 Get the default value of a global parameter. More...
 
void setGlobalParameterDefaultValue (int index, double defaultValue)
 Set the default value of a global parameter. More...
 
int addDonor (int d1, int d2, int d3, const std::vector< double > &parameters)
 Add a donor group to the force. More...
 
void getDonorParameters (int index, int &d1, int &d2, int &d3, std::vector< double > &parameters) const
 Get the properties of a donor group. More...
 
void setDonorParameters (int index, int d1, int d2, int d3, const std::vector< double > &parameters)
 Set the properties of a donor group. More...
 
int addAcceptor (int a1, int a2, int a3, const std::vector< double > &parameters)
 Add an acceptor group to the force. More...
 
void getAcceptorParameters (int index, int &a1, int &a2, int &a3, std::vector< double > &parameters) const
 Get the properties of an acceptor group. More...
 
void setAcceptorParameters (int index, int a1, int a2, int a3, const std::vector< double > &parameters)
 Set the properties of an acceptor group. More...
 
int addExclusion (int donor, int acceptor)
 Add a donor-acceptor pair to the list of interactions that should be excluded. More...
 
void getExclusionParticles (int index, int &donor, int &acceptor) const
 Get the donor and acceptor in a pair whose interaction should be excluded. More...
 
void setExclusionParticles (int index, int donor, int acceptor)
 Get the donor and acceptor in a pair whose interaction should be excluded. More...
 
int addFunction (const std::string &name, const std::vector< double > &values, double min, double max)
 Add a tabulated function that may appear in the energy expression. More...
 
void getFunctionParameters (int index, std::string &name, std::vector< double > &values, double &min, double &max) const
 Get the parameters for a tabulated function that may appear in the energy expression. More...
 
void setFunctionParameters (int index, const std::string &name, const std::vector< double > &values, double min, double max)
 Set the parameters for a tabulated function that may appear in algebraic expressions. More...
 
void updateParametersInContext (Context &context)
 Update the per-donor and per-acceptor parameters in a Context to match those stored in this Force object. More...
 
- Public Member Functions inherited from Force
 Force ()
 
virtual ~Force ()
 
int getForceGroup () const
 Get the force group this Force belongs to. More...
 
void setForceGroup (int group)
 Set the force group this Force belongs to. More...
 

Protected Member Functions

ForceImplcreateImpl () const
 When a Context is created, it invokes this method on each Force in the System. More...
 
- Protected Member Functions inherited from Force
ForceImplgetImplInContext (Context &context)
 Get the ForceImpl corresponding to this Force in a Context. More...
 
ContextImplgetContextImpl (Context &context)
 Get the ContextImpl corresponding to a Context. More...
 

Detailed Description

This class supports a wide variety of energy functions used to represent hydrogen bonding.

It computes interactions between "donor" particle groups and "acceptor" particle groups, where each group may include up to three particles. Typically a donor group consists of a hydrogen atom and the atoms it is bonded to, and an acceptor group consists of a negatively charged atom and the atoms it is bonded to.

We refer to the particles in a donor group as d1, d2 and d3, and the particles in an acceptor group as a1, a2, and a3. For each donor and each acceptor, CustomHbondForce evaluates a user supplied algebraic expression to determine the interaction energy. The expression may depend on arbitrary distances, angles, and dihedral angles defined by any of the six particles involved. The function distance(p1, p2) is the distance between the particles p1 and p2 (where "p1" and "p2" should be replaced by the names of the actual particles to calculate the distance between), angle(p1, p2, p3) is the angle formed by the three specified particles, and dihedral(p1, p2, p3, p4) is the dihedral angle formed by the four specified particles.

The expression also may involve tabulated functions, and may depend on arbitrary global, per-donor, and per-acceptor parameters. It also optionally supports periodic boundary conditions and cutoffs for long range interactions.

To use this class, create a CustomHbondForce object, passing an algebraic expression to the constructor that defines the interaction energy between each donor and acceptor. Then call addPerDonorParameter() to define per-donor parameters, addPerAcceptorParameter() to define per-acceptor parameters, and addGlobalParameter() to define global parameters. The values of per-donor and per-acceptor 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 addDonor() and addAcceptor() to define donors and acceptors and specify their parameter values. After a donor or acceptor has been added, you can modify its parameters by calling setDonorParameters() or setAcceptorParameters(). This will have no effect on Contexts that already exist unless you call updateParametersInContext().

CustomHbondForce also lets you specify "exclusions", particular combinations of donors and acceptors whose interactions should be omitted from force and energy calculations. This is most often used for particles that are bonded to each other.

As an example, the following code creates a CustomHbondForce that implements a simple harmonic potential to keep the distance between a1 and d1, and the angle formed by a1-d1-d2, near ideal values:

CustomHbondForce* force = new CustomHbondForce("k*(distance(a1,d1)-r0)^2*(angle(a1,d1,d2)-theta0)^2");

This force depends on three parameters: k, r0, and theta0. The following code defines these as per-donor parameters:

force->addPerDonorParameter("k");
force->addPerDonorParameter("r0");
force->addPerDonorParameter("theta0");

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, sinh, cosh, tanh, erf, erfc, min, max, abs, step, delta. 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.

In addition, you can call addFunction() to define a new function based on tabulated values. You specify a vector of values, and a natural spline is created from them. That function can then appear in the expression.

Member Enumeration Documentation

This is an enumeration of the different methods that may be used for handling long range nonbonded forces.

Enumerator
NoCutoff 

No cutoff is applied to nonbonded interactions.

The full set of N^2 interactions is computed exactly. This necessarily means that periodic boundary conditions cannot be used. This is the default.

CutoffNonPeriodic 

Interactions beyond the cutoff distance are ignored.

CutoffPeriodic 

Periodic boundary conditions are used, so that each particle interacts only with the nearest periodic copy of each other particle.

Interactions beyond the cutoff distance are ignored.

Constructor & Destructor Documentation

CustomHbondForce ( const std::string &  energy)
explicit

Create a CustomHbondForce.

Parameters
energyan algebraic expression giving the interaction energy between a donor and an acceptor as a function of inter-particle distances, angles, and dihedrals, as well as any global, per-donor, and per-acceptor parameters

Member Function Documentation

int addAcceptor ( int  a1,
int  a2,
int  a3,
const std::vector< double > &  parameters 
)

Add an acceptor group to the force.

Parameters
a1the index of the first particle for this acceptor group
a2the index of the second particle for this acceptor group. If the group only includes one particle, this must be -1.
a3the index of the third particle for this acceptor group. If the group includes less than three particles, this must be -1.
parametersthe list of per-acceptor parameter values for the new acceptor
Returns
the index of the acceptor that was added
int addDonor ( int  d1,
int  d2,
int  d3,
const std::vector< double > &  parameters 
)

Add a donor group to the force.

Parameters
d1the index of the first particle for this donor group
d2the index of the second particle for this donor group. If the group only includes one particle, this must be -1.
d3the index of the third particle for this donor group. If the group includes less than three particles, this must be -1.
parametersthe list of per-donor parameter values for the new donor
Returns
the index of the donor that was added
int addExclusion ( int  donor,
int  acceptor 
)

Add a donor-acceptor pair to the list of interactions that should be excluded.

Parameters
donorthe index of the donor to exclude
acceptorthe index of the acceptor to exclude
Returns
the index of the exclusion that was added
int addFunction ( const std::string &  name,
const std::vector< double > &  values,
double  min,
double  max 
)

Add a tabulated function that may appear in the energy expression.

Parameters
namethe name of the function as it appears in expressions
valuesthe tabulated values of the function f(x) at uniformly spaced values of x between min and max. The function is assumed to be zero for x < min or x > max.
minthe value of the independent variable corresponding to the first element of values
maxthe value of the independent variable corresponding to the last element of values
Returns
the index of the function that was added
int addGlobalParameter ( const std::string &  name,
double  defaultValue 
)

Add a new global parameter that the interaction may depend on.

Parameters
namethe name of the parameter
defaultValuethe default value of the parameter
Returns
the index of the parameter that was added
int addPerAcceptorParameter ( const std::string &  name)

Add a new per-acceptor parameter that the interaction may depend on.

Parameters
namethe name of the parameter
Returns
the index of the parameter that was added
int addPerDonorParameter ( const std::string &  name)

Add a new per-donor parameter that the interaction may depend on.

Parameters
namethe name of the parameter
Returns
the index of the parameter that was added
ForceImpl* createImpl ( ) const
protectedvirtual

When a Context is created, it invokes this method on each Force in the System.

It should create a new ForceImpl object which can be used by the context for calculating forces. The ForceImpl will be deleted automatically when the Context is deleted.

Implements Force.

void getAcceptorParameters ( int  index,
int &  a1,
int &  a2,
int &  a3,
std::vector< double > &  parameters 
) const

Get the properties of an acceptor group.

Parameters
indexthe index of the acceptor group to get
a1the index of the first particle for this acceptor group
a2the index of the second particle for this acceptor group. If the group only includes one particle, this will be -1.
a3the index of the third particle for this acceptor group. If the group includes less than three particles, this will be -1.
parametersthe list of per-acceptor parameter values for the acceptor
double getCutoffDistance ( ) const

Get the cutoff distance (in nm) being used.

All interactions for which the distance between d1 and a1 is greater than the cutoff will be ignored. If the NonbondedMethod in use is NoCutoff, this value will have no effect.

Returns
the cutoff distance, measured in nm
void getDonorParameters ( int  index,
int &  d1,
int &  d2,
int &  d3,
std::vector< double > &  parameters 
) const

Get the properties of a donor group.

Parameters
indexthe index of the donor group to get
d1the index of the first particle for this donor group
d2the index of the second particle for this donor group. If the group only includes one particle, this will be -1.
d3the index of the third particle for this donor group. If the group includes less than three particles, this will be -1.
parametersthe list of per-donor parameter values for the donor
const std::string& getEnergyFunction ( ) const

Get the algebraic expression that gives the interaction energy between a donor and an acceptor.

void getExclusionParticles ( int  index,
int &  donor,
int &  acceptor 
) const

Get the donor and acceptor in a pair whose interaction should be excluded.

Parameters
indexthe index of the exclusion for which to get donor and acceptor indices
particle1the index of the donor
particle2the index of the acceptor
void getFunctionParameters ( int  index,
std::string &  name,
std::vector< double > &  values,
double &  min,
double &  max 
) const

Get the parameters for a tabulated function that may appear in the energy expression.

Parameters
indexthe index of the function for which to get parameters
namethe name of the function as it appears in expressions
valuesthe tabulated values of the function f(x) at uniformly spaced values of x between min and max. The function is assumed to be zero for x < min or x > max.
minthe value of the independent variable corresponding to the first element of values
maxthe value of the independent variable corresponding to the last element of values
double getGlobalParameterDefaultValue ( int  index) const

Get the default value of a global parameter.

Parameters
indexthe index of the parameter for which to get the default value
Returns
the parameter default value
const std::string& getGlobalParameterName ( int  index) const

Get the name of a global parameter.

Parameters
indexthe index of the parameter for which to get the name
Returns
the parameter name
NonbondedMethod getNonbondedMethod ( ) const

Get the method used for handling long range nonbonded interactions.

int getNumAcceptors ( ) const
inline

Get the number of acceptors for which force field parameters have been defined.

int getNumDonors ( ) const
inline

Get the number of donors for which force field parameters have been defined.

int getNumExclusions ( ) const
inline

Get the number of donor-acceptor pairs whose interactions should be excluded.

int getNumFunctions ( ) const
inline

Get the number of tabulated functions that have been defined.

int getNumGlobalParameters ( ) const
inline

Get the number of global parameters that the interaction depends on.

int getNumPerAcceptorParameters ( ) const
inline

Get the number of per-acceptor parameters that the interaction depends on.

int getNumPerDonorParameters ( ) const
inline

Get the number of per-donor parameters that the interaction depends on.

const std::string& getPerAcceptorParameterName ( int  index) const

Get the name of a per-acceptor parameter.

Parameters
indexthe index of the parameter for which to get the name
Returns
the parameter name
const std::string& getPerDonorParameterName ( int  index) const

Get the name of a per-donor parameter.

Parameters
indexthe index of the parameter for which to get the name
Returns
the parameter name
void setAcceptorParameters ( int  index,
int  a1,
int  a2,
int  a3,
const std::vector< double > &  parameters 
)

Set the properties of an acceptor group.

Parameters
indexthe index of the acceptor group to set
a1the index of the first particle for this acceptor group
a2the index of the second particle for this acceptor group. If the group only includes one particle, this must be -1.
a3the index of the third particle for this acceptor group. If the group includes less than three particles, this must be -1.
parametersthe list of per-acceptor parameter values for the acceptor
void setCutoffDistance ( double  distance)

Set the cutoff distance (in nm) being used.

All interactions for which the distance between d1 and a1 is greater than the cutoff will be ignored. If the NonbondedMethod in use is NoCutoff, this value will have no effect.

Parameters
distancethe cutoff distance, measured in nm
void setDonorParameters ( int  index,
int  d1,
int  d2,
int  d3,
const std::vector< double > &  parameters 
)

Set the properties of a donor group.

Parameters
indexthe index of the donor group to set
d1the index of the first particle for this donor group
d2the index of the second particle for this donor group. If the group only includes one particle, this must be -1.
d3the index of the third particle for this donor group. If the group includes less than three particles, this must be -1.
parametersthe list of per-donor parameter values for the donor
void setEnergyFunction ( const std::string &  energy)

Set the algebraic expression that gives the interaction energy between a donor and an acceptor.

void setExclusionParticles ( int  index,
int  donor,
int  acceptor 
)

Get the donor and acceptor in a pair whose interaction should be excluded.

Parameters
indexthe index of the exclusion for which to get donor and acceptor indices
particle1the index of the donor
particle2the index of the acceptor
void setFunctionParameters ( int  index,
const std::string &  name,
const std::vector< double > &  values,
double  min,
double  max 
)

Set the parameters for a tabulated function that may appear in algebraic expressions.

Parameters
indexthe index of the function for which to set parameters
namethe name of the function as it appears in expressions
valuesthe tabulated values of the function f(x) at uniformly spaced values of x between min and max. The function is assumed to be zero for x < min or x > max.
minthe value of the independent variable corresponding to the first element of values
maxthe value of the independent variable corresponding to the last element of values
void setGlobalParameterDefaultValue ( int  index,
double  defaultValue 
)

Set the default value of a global parameter.

Parameters
indexthe index of the parameter for which to set the default value
namethe default value of the parameter
void setGlobalParameterName ( int  index,
const std::string &  name 
)

Set the name of a global parameter.

Parameters
indexthe index of the parameter for which to set the name
namethe name of the parameter
void setNonbondedMethod ( NonbondedMethod  method)

Set the method used for handling long range nonbonded interactions.

void setPerAcceptorParameterName ( int  index,
const std::string &  name 
)

Set the name of a per-acceptor parameter.

Parameters
indexthe index of the parameter for which to set the name
namethe name of the parameter
void setPerDonorParameterName ( int  index,
const std::string &  name 
)

Set the name of a per-donor parameter.

Parameters
indexthe index of the parameter for which to set the name
namethe name of the parameter
void updateParametersInContext ( Context context)

Update the per-donor and per-acceptor parameters in a Context to match those stored in this Force object.

This method provides an efficient method to update certain parameters in an existing Context without needing to reinitialize it. Simply call setDonorParameters() and setAcceptorParameters() to modify this object's parameters, then call updateParametersInState() to copy them over to the Context.

This method has several limitations. The only information it updates is the values of per-donor and per-acceptor parameters. All other aspects of the Force (the energy function, nonbonded method, cutoff distance, etc.) are unaffected and can only be changed by reinitializing the Context. The set of particles involved in a donor or acceptor cannot be changed, nor can new donors or acceptors be added.


The documentation for this class was generated from the following file: