OpenMM
 All Classes Namespaces Functions Variables Enumerations Enumerator Friends
CustomNonbondedForce Class Reference

This class implements nonbonded interactions between particles. More...

#include <CustomNonbondedForce.h>

+ Inheritance diagram for CustomNonbondedForce:

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

 CustomNonbondedForce (const std::string &energy)
 Create a CustomNonbondedForce.
 
int getNumParticles () const
 Get the number of particles for which force field parameters have been defined.
 
int getNumExclusions () const
 Get the number of particle pairs whose interactions should be excluded.
 
int getNumPerParticleParameters () const
 Get the number of per-particle parameters that the interaction depends on.
 
int getNumGlobalParameters () const
 Get the number of global parameters that the interaction depends on.
 
int getNumFunctions () const
 Get the number of tabulated functions that have been defined.
 
const std::string & getEnergyFunction () const
 Get the algebraic expression that gives the interaction energy between two particles.
 
void setEnergyFunction (const std::string &energy)
 Set the algebraic expression that gives the interaction energy between two particles.
 
NonbondedMethod getNonbondedMethod () const
 Get the method used for handling long range nonbonded interactions.
 
void setNonbondedMethod (NonbondedMethod method)
 Set the method used for handling long range nonbonded interactions.
 
double getCutoffDistance () const
 Get the cutoff distance (in nm) being used for nonbonded interactions.
 
void setCutoffDistance (double distance)
 Set the cutoff distance (in nm) being used for nonbonded interactions.
 
int addPerParticleParameter (const std::string &name)
 Add a new per-particle parameter that the interaction may depend on.
 
const std::string & getPerParticleParameterName (int index) const
 Get the name of a per-particle parameter.
 
void setPerParticleParameterName (int index, const std::string &name)
 Set the name of a per-particle parameter.
 
int addGlobalParameter (const std::string &name, double defaultValue)
 Add a new global parameter that the interaction may depend on.
 
const std::string & getGlobalParameterName (int index) const
 Get the name of a global parameter.
 
void setGlobalParameterName (int index, const std::string &name)
 Set the name of a global parameter.
 
double getGlobalParameterDefaultValue (int index) const
 Get the default value of a global parameter.
 
void setGlobalParameterDefaultValue (int index, double defaultValue)
 Set the default value of a global parameter.
 
int addParticle (const std::vector< double > &parameters)
 Add the nonbonded force parameters for a particle.
 
void getParticleParameters (int index, std::vector< double > &parameters) const
 Get the nonbonded force parameters for a particle.
 
void setParticleParameters (int index, const std::vector< double > &parameters)
 Set the nonbonded force parameters for a particle.
 
int addExclusion (int particle1, int particle2)
 Add a particle pair to the list of interactions that should be excluded.
 
void getExclusionParticles (int index, int &particle1, int &particle2) const
 Get the particles in a pair whose interaction should be excluded.
 
void setExclusionParticles (int index, int particle1, int particle2)
 Set the particles in a pair whose interaction should be excluded.
 
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.
 
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.
 
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.
 
void updateParametersInContext (Context &context)
 Update the per-particle parameters in a Context to match those stored in this Force object.
 
- Public Member Functions inherited from Force
 Force ()
 
virtual ~Force ()
 
int getForceGroup () const
 Get the force group this Force belongs to.
 
void setForceGroup (int group)
 Set the force group this Force belongs to.
 

Protected Member Functions

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

Detailed Description

This class implements nonbonded interactions between particles.

Unlike NonbondedForce, the functional form of the interaction is completely customizable, and may involve arbitrary algebraic expressions and tabulated functions. It may depend on the distance between particles, as well as on arbitrary global and per-particle parameters. It also optionally supports periodic boundary conditions and cutoffs for long range interactions.

To use this class, create a CustomNonbondedForce object, passing an algebraic expression to the constructor that defines the interaction energy between each pair of particles. The expression may depend on r, the distance between the particles, as well as on any parameters you choose. Then call addPerParticleParameter() to define per-particle parameters, and addGlobalParameter() to define global parameters. The values of per-particle 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 addParticle() once for each particle in the System to set the values of its per-particle parameters. The number of particles for which you set parameters must be exactly equal to the number of particles in the System, or else an exception will be thrown when you try to create a Context. After a particle has been added, you can modify its parameters by calling setParticleParameters(). This will have no effect on Contexts that already exist unless you call updateParametersInContext().

CustomNonbondedForce also lets you specify "exclusions", particular pairs of particles 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 CustomNonbondedForce that implements a 12-6 Lennard-Jones potential:

CustomNonbondedForce* force = new CustomNonbondedForce("4*epsilon*((sigma/r)^12-(sigma/r)^6); sigma=0.5*(sigma1*sigma2); epsilon=sqrt(epsilon1*epsilon2)");

This force depends on two parameters: sigma and epsilon. The following code defines these as per-particle parameters:

force->addPerParticleParameter("sigma");
force->addPerParticleParameter("epsilon");

The expression must be symmetric with respect to the two particles. It typically will only be evaluated once for each pair of particles, and no guarantee is made about which particle will be identified as "particle 1". In the above example, the energy only depends on the products sigma1*sigma2 and epsilon1*epsilon2, both of which are unchanged if the labels 1 and 2 are reversed. In contrast, if it depended on the difference sigma1-sigma2, the results would be undefined, because reversing the labels 1 and 2 would change the energy.

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. The names of per-particle parameters have the suffix "1" or "2" appended to them to indicate the values for the two interacting particles. As seen in the above example, the expression may also involve intermediate quantities that are defined following the main expression, using ";" as a separator.

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

CustomNonbondedForce ( const std::string &  energy)
explicit

Create a CustomNonbondedForce.

Parameters
energyan algebraic expression giving the interaction energy between two particles as a function of r, the distance between them, as well as any global and per-particle parameters

Member Function Documentation

int addExclusion ( int  particle1,
int  particle2 
)

Add a particle pair to the list of interactions that should be excluded.

Parameters
particle1the index of the first particle in the pair
particle2the index of the second particle in the pair
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 addParticle ( const std::vector< double > &  parameters)

Add the nonbonded force parameters for a particle.

This should be called once for each particle in the System. When it is called for the i'th time, it specifies the parameters for the i'th particle.

Parameters
parametersthe list of parameters for the new particle
Returns
the index of the particle that was added
int addPerParticleParameter ( const std::string &  name)

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

Parameters
namethe name of the parameter
Returns
the index of the parameter that was added
ForceImpl* createImpl ( )
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.

double getCutoffDistance ( ) const

Get the cutoff distance (in nm) being used for nonbonded interactions.

If the NonbondedMethod in use is NoCutoff, this value will have no effect.

Returns
the cutoff distance, measured in nm
const std::string& getEnergyFunction ( ) const

Get the algebraic expression that gives the interaction energy between two particles.

void getExclusionParticles ( int  index,
int &  particle1,
int &  particle2 
) const

Get the particles in a pair whose interaction should be excluded.

Parameters
indexthe index of the exclusion for which to get particle indices
particle1the index of the first particle in the pair
particle2the index of the second particle in the pair
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 getNumExclusions ( ) const
inline

Get the number of particle 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 getNumParticles ( ) const
inline

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

int getNumPerParticleParameters ( ) const
inline

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

void getParticleParameters ( int  index,
std::vector< double > &  parameters 
) const

Get the nonbonded force parameters for a particle.

Parameters
indexthe index of the particle for which to get parameters
parametersthe list of parameters for the specified particle
const std::string& getPerParticleParameterName ( int  index) const

Get the name of a per-particle parameter.

Parameters
indexthe index of the parameter for which to get the name
Returns
the parameter name
void setCutoffDistance ( double  distance)

Set the cutoff distance (in nm) being used for nonbonded interactions.

If the NonbondedMethod in use is NoCutoff, this value will have no effect.

Parameters
distancethe cutoff distance, measured in nm
void setEnergyFunction ( const std::string &  energy)

Set the algebraic expression that gives the interaction energy between two particles.

void setExclusionParticles ( int  index,
int  particle1,
int  particle2 
)

Set the particles in a pair whose interaction should be excluded.

Parameters
indexthe index of the exclusion for which to set particle indices
particle1the index of the first particle in the pair
particle2the index of the second particle in the pair
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 setParticleParameters ( int  index,
const std::vector< double > &  parameters 
)

Set the nonbonded force parameters for a particle.

Parameters
indexthe index of the particle for which to set parameters
parametersthe list of parameters for the specified particle
void setPerParticleParameterName ( int  index,
const std::string &  name 
)

Set the name of a per-particle 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-particle 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 setParticleParameters() 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-particle 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. Also, this method cannot be used to add new particles, only to change the parameters of existing ones.


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