OpenMM

This class implements complex, multiple stage nonbonded interactions between particles. More...
#include <CustomGBForce.h>
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...  
enum  ComputationType { SingleParticle = 0, ParticlePair = 1, ParticlePairNoExclusions = 2 } 
This is an enumeration of the different ways in which a computed value or energy term can be calculated. More...  
Public Member Functions  
CustomGBForce ()  
Create a CustomGBForce. More...  
~CustomGBForce ()  
int  getNumParticles () const 
Get the number of particles for which force field parameters have been defined. More...  
int  getNumExclusions () const 
Get the number of particle pairs whose interactions should be excluded. More...  
int  getNumPerParticleParameters () const 
Get the number of perparticle parameters that the interaction depends on. More...  
int  getNumGlobalParameters () const 
Get the number of global parameters that the interaction depends on. More...  
int  getNumTabulatedFunctions () const 
Get the number of tabulated functions that have been defined. More...  
int  getNumFunctions () const 
Get the number of tabulated functions that have been defined. More...  
int  getNumComputedValues () const 
Get the number of perparticle computed values the interaction depends on. More...  
int  getNumEnergyTerms () const 
Get the number of terms in the energy computation. 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 for nonbonded interactions. More...  
void  setCutoffDistance (double distance) 
Set the cutoff distance (in nm) being used for nonbonded interactions. More...  
int  addPerParticleParameter (const std::string &name) 
Add a new perparticle parameter that the interaction may depend on. More...  
const std::string &  getPerParticleParameterName (int index) const 
Get the name of a perparticle parameter. More...  
void  setPerParticleParameterName (int index, const std::string &name) 
Set the name of a perparticle 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  addParticle (const std::vector< double > ¶meters) 
Add the nonbonded force parameters for a particle. More...  
void  getParticleParameters (int index, std::vector< double > ¶meters) const 
Get the nonbonded force parameters for a particle. More...  
void  setParticleParameters (int index, const std::vector< double > ¶meters) 
Set the nonbonded force parameters for a particle. More...  
int  addComputedValue (const std::string &name, const std::string &expression, ComputationType type) 
Add a computed value to calculate for each particle. More...  
void  getComputedValueParameters (int index, std::string &name, std::string &expression, ComputationType &type) const 
Get the properties of a computed value. More...  
void  setComputedValueParameters (int index, const std::string &name, const std::string &expression, ComputationType type) 
Set the properties of a computed value. More...  
int  addEnergyTerm (const std::string &expression, ComputationType type) 
Add a term to the energy computation. More...  
void  getEnergyTermParameters (int index, std::string &expression, ComputationType &type) const 
Get the properties of a term to the energy computation. More...  
void  setEnergyTermParameters (int index, const std::string &expression, ComputationType type) 
Set the properties of a term to the energy computation. More...  
int  addExclusion (int particle1, int particle2) 
Add a particle pair to the list of interactions that should be excluded. More...  
void  getExclusionParticles (int index, int &particle1, int &particle2) const 
Get the particles in a pair whose interaction should be excluded. More...  
void  setExclusionParticles (int index, int particle1, int particle2) 
Set the particles in a pair whose interaction should be excluded. More...  
int  addTabulatedFunction (const std::string &name, TabulatedFunction *function) 
Add a tabulated function that may appear in expressions. More...  
const TabulatedFunction &  getTabulatedFunction (int index) const 
Get a const reference to a tabulated function that may appear in expressions. More...  
TabulatedFunction &  getTabulatedFunction (int index) 
Get a reference to a tabulated function that may appear in expressions. More...  
const std::string &  getTabulatedFunctionName (int index) const 
Get the name of a tabulated function that may appear in expressions. More...  
int  addFunction (const std::string &name, const std::vector< double > &values, double min, double max) 
Add a tabulated function that may appear in expressions. 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 expressions. 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 expressions. More...  
void  updateParametersInContext (Context &context) 
Update the perparticle 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  
ForceImpl *  createImpl () const 
When a Context is created, it invokes this method on each Force in the System. More...  
Protected Member Functions inherited from Force  
ForceImpl &  getImplInContext (Context &context) 
Get the ForceImpl corresponding to this Force in a Context. More...  
ContextImpl &  getContextImpl (Context &context) 
Get the ContextImpl corresponding to a Context. More...  
This class implements complex, multiple stage nonbonded interactions between particles.
It is designed primarily for implementing Generalized Born implicit solvation models, although it is not strictly limited to that purpose. The interaction is specified as a series of computations, each defined by an arbitrary algebraic expression. It also allows tabulated functions to be defined and used with the computations. It optionally supports periodic boundary conditions and cutoffs for long range interactions.
The computation consists of calculating some number of perparticle computed values, followed by one or more energy terms. A computed value is a scalar value that is computed for each particle in the system. It may depend on an arbitrary set of global and perparticle parameters, and well as on other computed values that have been calculated before it. Once all computed values have been calculated, the energy terms and their derivatives are evaluated to determine the system energy and particle forces. The energy terms may depend on global parameters, perparticle parameters, and perparticle computed values.
When specifying a computed value or energy term, you provide an algebraic expression to evaluate and a computation type describing how the expression is to be evaluated. There are two main types of computations:
Be aware that, although this class is extremely general in the computations it can define, particular Platforms may only support more restricted types of computations. In particular, all currently existing Platforms require that the first computed value must be a particle pair computation, and all computed values after the first must be single particle computations. This is sufficient for most Generalized Born models, but might not permit some other types of calculations to be implemented.
This is a complicated class to use, and an example may help to clarify it. The following code implements the OBC variant of the GB/SA solvation model, using the ACE approximation to estimate surface area:
CustomGBForce* custom = new CustomGBForce();
custom>addPerParticleParameter("q");
custom>addPerParticleParameter("radius");
custom>addPerParticleParameter("scale");
custom>addGlobalParameter("solventDielectric", obc>getSolventDielectric());
custom>addGlobalParameter("soluteDielectric", obc>getSoluteDielectric());
custom>addComputedValue("I", "step(r+sr2or1)*0.5*(1/L1/U+0.25*(1/U^21/L^2)*(rsr2*sr2/r)+0.5*log(L/U)/r+C);"
"U=r+sr2;"
"C=2*(1/or11/L)*step(sr2ror1);"
"L=max(or1, D);"
"D=abs(rsr2);"
"sr2 = scale2*or2;"
"or1 = radius10.009; or2 = radius20.009", CustomGBForce::ParticlePairNoExclusions);
custom>addComputedValue("B", "1/(1/ortanh(1*psi0.8*psi^2+4.85*psi^3)/radius);"
"psi=I*or; or=radius0.009", CustomGBForce::SingleParticle);
custom>addEnergyTerm("28.3919551*(radius+0.14)^2*(radius/B)^60.5*138.935456*(1/soluteDielectric1/solventDielectric)*q^2/B",
CustomGBForce::SingleParticle);
custom>addEnergyTerm("138.935456*(1/soluteDielectric1/solventDielectric)*q1*q2/f;"
"f=sqrt(r^2+B1*B2*exp(r^2/(4*B1*B2)))", CustomGBForce::ParticlePair);
It begins by defining three perparticle parameters (charge, atomic radius, and scale factor) and two global parameters (the dielectric constants for the solute and solvent). It then defines a computed value "I" of type ParticlePair. The expression for evaluating it is a complicated function of the distance between each pair of particles (r), their atomic radii (radius1 and radius2), and their scale factors (scale1 and scale2). Very roughly speaking, it is a measure of the distance between each particle and other nearby particles.
Next a computation is defined for the Born Radius (B). It is computed independently for each particle, and is a function of that particle's atomic radius and the intermediate value I defined above.
Finally, two energy terms are defined. The first one is computed for each particle and represents the surface area term, as well as the self interaction part of the polarization energy. The second term is calculated for each pair of particles, and represents the screening of electrostatic interactions by the solvent.
After defining the force as shown above, you should then call addParticle() once for each particle in the System to set the values of its perparticle parameters (q, radius, and scale). 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().
CustomGBForce also lets you specify "exclusions", particular pairs of particles whose interactions should be omitted from calculations. This is most often used for particles that are bonded to each other. Even if you specify exclusions, however, you can use the computation type ParticlePairNoExclusions to indicate that exclusions should not be applied to a particular piece of the computation.
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 expressions for particle pair calculations, the names of perparticle parameters and computed values have the suffix "1" or "2" appended to them to indicate the values for the two interacting particles. As seen in the above example, an expression may also involve intermediate quantities that are defined following the main expression, using ";" as a separator.
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 expressions.
enum ComputationType 
This is an enumeration of the different ways in which a computed value or energy term can be calculated.
enum NonbondedMethod 
This is an enumeration of the different methods that may be used for handling long range nonbonded forces.
CustomGBForce  (  ) 
Create a CustomGBForce.
~CustomGBForce  (  ) 
int addComputedValue  (  const std::string &  name, 
const std::string &  expression,  
ComputationType  type  
) 
Add a computed value to calculate for each particle.
name  the name of the value 
expression  an algebraic expression to evaluate when calculating the computed value. If the ComputationType is SingleParticle, the expression is evaluated independently for each particle, and may depend on its x, y, and z coordinates, as well as the perparticle parameters and previous computed values for that particle. If the ComputationType is ParticlePair or ParticlePairNoExclusions, the expression is evaluated once for every other particle in the system and summed to get the final value. In the latter case, the expression may depend on the distance r between the two particles, and on the perparticle parameters and previous computed values for each of them. Append "1" to a variable name to indicate the parameter for the particle whose value is being calculated, and "2" to indicate the particle it is interacting with. 
type  the method to use for computing this value 
int addEnergyTerm  (  const std::string &  expression, 
ComputationType  type  
) 
Add a term to the energy computation.
expression  an algebraic expression to evaluate when calculating the energy. If the ComputationType is SingleParticle, the expression is evaluated once for each particle, and may depend on its x, y, and z coordinates, as well as the perparticle parameters and computed values for that particle. If the ComputationType is ParticlePair or ParticlePairNoExclusions, the expression is evaluated once for every pair of particles in the system. In the latter case, the expression may depend on the distance r between the two particles, and on the perparticle parameters and computed values for each of them. Append "1" to a variable name to indicate the parameter for the first particle in the pair and "2" to indicate the second particle in the pair. 
type  the method to use for computing this value 
int addExclusion  (  int  particle1, 
int  particle2  
) 
Add a particle pair to the list of interactions that should be excluded.
particle1  the index of the first particle in the pair 
particle2  the index of the second particle in the pair 
int addFunction  (  const std::string &  name, 
const std::vector< double > &  values,  
double  min,  
double  max  
) 
Add a tabulated function that may appear in expressions.
int addGlobalParameter  (  const std::string &  name, 
double  defaultValue  
) 
Add a new global parameter that the interaction may depend on.
name  the name of the parameter 
defaultValue  the default value of the parameter 
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  the list of parameters for the new particle 
int addPerParticleParameter  (  const std::string &  name  ) 
Add a new perparticle parameter that the interaction may depend on.
name  the name of the parameter 
int addTabulatedFunction  (  const std::string &  name, 
TabulatedFunction *  function  
) 
Add a tabulated function that may appear in expressions.
name  the name of the function as it appears in expressions 
function  a TabulatedFunction object defining the function. The TabulatedFunction should have been created on the heap with the "new" operator. The Force takes over ownership of it, and deletes it when the Force itself is deleted. 

protectedvirtual 
void getComputedValueParameters  (  int  index, 
std::string &  name,  
std::string &  expression,  
ComputationType &  type  
)  const 
Get the properties of a computed value.
index  the index of the computed value for which to get parameters 
name  the name of the value 
expression  an algebraic expression to evaluate when calculating the computed value. If the ComputationType is SingleParticle, the expression is evaluated independently for each particle, and may depend on its x, y, and z coordinates, as well as the perparticle parameters and previous computed values for that particle. If the ComputationType is ParticlePair or ParticlePairNoExclusions, the expression is evaluated once for every other particle in the system and summed to get the final value. In the latter case, the expression may depend on the distance r between the two particles, and on the perparticle parameters and previous computed values for each of them. Append "1" to a variable name to indicate the parameter for the particle whose value is being calculated, and "2" to indicate the particle it is interacting with. 
type  the method to use for computing this value 
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.
void getEnergyTermParameters  (  int  index, 
std::string &  expression,  
ComputationType &  type  
)  const 
Get the properties of a term to the energy computation.
index  the index of the term for which to get parameters 
expression  an algebraic expression to evaluate when calculating the energy. If the ComputationType is SingleParticle, the expression is evaluated once for each particle, and may depend on its x, y, and z coordinates, as well as the perparticle parameters and computed values for that particle. If the ComputationType is ParticlePair or ParticlePairNoExclusions, the expression is evaluated once for every pair of particles in the system. In the latter case, the expression may depend on the distance r between the two particles, and on the perparticle parameters and computed values for each of them. Append "1" to a variable name to indicate the parameter for the first particle in the pair and "2" to indicate the second particle in the pair. 
type  the method to use for computing this value 
void getExclusionParticles  (  int  index, 
int &  particle1,  
int &  particle2  
)  const 
Get the particles in a pair whose interaction should be excluded.
index  the index of the exclusion for which to get particle indices 
particle1  the index of the first particle in the pair 
particle2  the 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 expressions.
double getGlobalParameterDefaultValue  (  int  index  )  const 
Get the default value of a global parameter.
index  the index of the parameter for which to get the default value 
const std::string& getGlobalParameterName  (  int  index  )  const 
Get the name of a global parameter.
index  the index of the parameter for which to get the name 
NonbondedMethod getNonbondedMethod  (  )  const 
Get the method used for handling long range nonbonded interactions.

inline 
Get the number of perparticle computed values the interaction depends on.

inline 
Get the number of terms in the energy computation.

inline 
Get the number of particle pairs whose interactions should be excluded.

inline 
Get the number of tabulated functions that have been defined.

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

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

inline 
Get the number of perparticle parameters that the interaction depends on.

inline 
Get the number of tabulated functions that have been defined.
void getParticleParameters  (  int  index, 
std::vector< double > &  parameters  
)  const 
Get the nonbonded force parameters for a particle.
index  the index of the particle for which to get parameters 
parameters  the list of parameters for the specified particle 
const std::string& getPerParticleParameterName  (  int  index  )  const 
Get the name of a perparticle parameter.
index  the index of the parameter for which to get the name 
const TabulatedFunction& getTabulatedFunction  (  int  index  )  const 
Get a const reference to a tabulated function that may appear in expressions.
index  the index of the function to get 
TabulatedFunction& getTabulatedFunction  (  int  index  ) 
Get a reference to a tabulated function that may appear in expressions.
index  the index of the function to get 
const std::string& getTabulatedFunctionName  (  int  index  )  const 
Get the name of a tabulated function that may appear in expressions.
index  the index of the function to get 
void setComputedValueParameters  (  int  index, 
const std::string &  name,  
const std::string &  expression,  
ComputationType  type  
) 
Set the properties of a computed value.
index  the index of the computed value for which to set parameters 
name  the name of the value 
expression  an algebraic expression to evaluate when calculating the computed value. If the ComputationType is SingleParticle, the expression is evaluated independently for each particle, and may depend on its x, y, and z coordinates, as well as the perparticle parameters and previous computed values for that particle. If the ComputationType is ParticlePair or ParticlePairNoExclusions, the expression is evaluated once for every other particle in the system and summed to get the final value. In the latter case, the expression may depend on the distance r between the two particles, and on the perparticle parameters and previous computed values for each of them. Append "1" to a variable name to indicate the parameter for the particle whose value is being calculated, and "2" to indicate the particle it is interacting with. 
type  the method to use for computing this value 
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.
distance  the cutoff distance, measured in nm 
void setEnergyTermParameters  (  int  index, 
const std::string &  expression,  
ComputationType  type  
) 
Set the properties of a term to the energy computation.
index  the index of the term for which to set parameters 
expression  an algebraic expression to evaluate when calculating the energy. If the ComputationType is SingleParticle, the expression is evaluated once for each particle, and may depend on its x, y, and z coordinates, as well as the perparticle parameters and computed values for that particle. If the ComputationType is ParticlePair or ParticlePairNoExclusions, the expression is evaluated once for every pair of particles in the system. In the latter case, the expression may depend on the distance r between the two particles, and on the perparticle parameters and computed values for each of them. Append "1" to a variable name to indicate the parameter for the first particle in the pair and "2" to indicate the second particle in the pair. 
type  the method to use for computing this value 
void setExclusionParticles  (  int  index, 
int  particle1,  
int  particle2  
) 
Set the particles in a pair whose interaction should be excluded.
index  the index of the exclusion for which to set particle indices 
particle1  the index of the first particle in the pair 
particle2  the 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 expressions.
void setGlobalParameterDefaultValue  (  int  index, 
double  defaultValue  
) 
Set the default value of a global parameter.
index  the index of the parameter for which to set the default value 
name  the default value of the parameter 
void setGlobalParameterName  (  int  index, 
const std::string &  name  
) 
Set the name of a global parameter.
index  the index of the parameter for which to set the name 
name  the 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.
index  the index of the particle for which to set parameters 
parameters  the list of parameters for the specified particle 
void setPerParticleParameterName  (  int  index, 
const std::string &  name  
) 
Set the name of a perparticle parameter.
index  the index of the parameter for which to set the name 
name  the name of the parameter 
void updateParametersInContext  (  Context &  context  ) 
Update the perparticle 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 perparticle parameters. All other aspects of the Force (such as the energy function) 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.