CustomGBForce

class simtk.openmm.openmm.CustomGBForce(*args)

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 per-particle _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 per-particle 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, per-particle parameters, and per-particle 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:

  • Single Particle: The expression is evaluated once for each particle in the System. In the case of a computed value, this means the value for a particle depends only on other properties of that particle (its position, parameters, and other computed values). In the case of an energy term, it means each particle makes an independent contribution to the System energy.
  • Particle Pairs: The expression is evaluated for every pair of particles in the system. In the case of a computed value, the value for a particular particle is calculated by pairing it with every other particle in the system, evaluating the expression for each pair, and summing them. For an energy term, each particle pair makes an independent contribution to the System energy. (Note that energy terms are assumed to be symmetric with respect to the two interacting particles, and therefore are evaluated only once per pair. In contrast, expressions for computed values need not be symmetric and therefore are calculated twice for each pair: once when calculating the value for the first particle, and again when calculating the value for the second particle.)

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+sr2-or1)*0.5*(1/L-1/U+0.25*(1/U^2-1/L^2)*(r-sr2*sr2/r)+0.5*log(L/U)/r+C);"
                              "U=r+sr2;"
                              "C=2*(1/or1-1/L)*step(sr2-r-or1);"
                              "L=max(or1, D);"
                              "D=abs(r-sr2);"
                              "sr2 = scale2*or2;"
                              "or1 = radius1-0.009; or2 = radius2-0.009", CustomGBForce::ParticlePairNoExclusions);
custom->addComputedValue("B", "1/(1/or-tanh(1*psi-0.8*psi^2+4.85*psi^3)/radius);"
                              "psi=I*or; or=radius-0.009", CustomGBForce::SingleParticle);
custom->addEnergyTerm("28.3919551*(radius+0.14)^2*(radius/B)^6-0.5*138.935456*(1/soluteDielectric-1/solventDielectric)*q^2/B",
                      CustomGBForce::SingleParticle);
custom->addEnergyTerm("-138.935456*(1/soluteDielectric-1/solventDielectric)*q1*q2/f;"
                      "f=sqrt(r^2+B1*B2*exp(-r^2/(4*B1*B2)))", CustomGBForce::ParticlePair);

It begins by defining three per-particle 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 per-particle 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.

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. In expressions for particle pair calculations, the names of per-particle 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.

__init__(self) → CustomGBForce

__init__(self, other) -> CustomGBForce

Create a CustomGBForce.

Methods

__init__(self) __init__(self, other) -> CustomGBForce
addComputedValue(self, name, expression, type) Add a computed value to calculate for each particle.
addEnergyParameterDerivative(self, name) Request that this Force compute the derivative of its energy with respect to a global parameter.
addEnergyTerm(self, expression, type) Add a term to the energy computation.
addExclusion(self, particle1, particle2) Add a particle pair to the list of interactions that should be excluded.
addFunction(self, name, values, min, max) Add a tabulated function that may appear in expressions.
addGlobalParameter(self, name, defaultValue) Add a new global parameter that the interaction may depend on.
addParticle(self, parameters) addParticle(self) -> int
addPerParticleParameter(self, name) Add a new per-particle parameter that the interaction may depend on.
addTabulatedFunction(self, name, function) Add a tabulated function that may appear in expressions.
getComputedValueParameters(self, index) Get the properties of a computed value.
getCutoffDistance(self) Get the cutoff distance (in nm) being used for nonbonded interactions.
getEnergyParameterDerivativeName(self, index) Get the name of a global parameter with respect to which this Force should compute the derivative of the energy.
getEnergyTermParameters(self, index) Get the properties of a term to the energy computation.
getExclusionParticles(self, index) Get the particles in a pair whose interaction should be excluded.
getForceGroup(self) Get the force group this Force belongs to.
getFunctionParameters(self, index) Get the parameters for a tabulated function that may appear in expressions.
getGlobalParameterDefaultValue(self, index) Get the default value of a global parameter.
getGlobalParameterName(self, index) Get the name of a global parameter.
getNonbondedMethod(self) Get the method used for handling long range nonbonded interactions.
getNumComputedValues(self) Get the number of per-particle computed values the interaction depends on.
getNumEnergyParameterDerivatives(self) Get the number of global parameters with respect to which the derivative of the energy should be computed.
getNumEnergyTerms(self) Get the number of terms in the energy computation.
getNumExclusions(self) Get the number of particle pairs whose interactions should be excluded.
getNumFunctions(self) Get the number of tabulated functions that have been defined.
getNumGlobalParameters(self) Get the number of global parameters that the interaction depends on.
getNumParticles(self) Get the number of particles for which force field parameters have been defined.
getNumPerParticleParameters(self) Get the number of per-particle parameters that the interaction depends on.
getNumTabulatedFunctions(self) Get the number of tabulated functions that have been defined.
getParticleParameters(self, index) Get the nonbonded force parameters for a particle.
getPerParticleParameterName(self, index) Get the name of a per-particle parameter.
getTabulatedFunction(self, index) getTabulatedFunction(self, index) -> TabulatedFunction
getTabulatedFunctionName(self, index) Get the name of a tabulated function that may appear in expressions.
setComputedValueParameters(self, index, …) Set the properties of a computed value.
setCutoffDistance(self, distance) Set the cutoff distance (in nm) being used for nonbonded interactions.
setEnergyTermParameters(self, index, …) Set the properties of a term to the energy computation.
setExclusionParticles(self, index, …) Set the particles in a pair whose interaction should be excluded.
setForceGroup(self, group) Set the force group this Force belongs to.
setFunctionParameters(self, index, name, …) Set the parameters for a tabulated function that may appear in expressions.
setGlobalParameterDefaultValue(self, index, …) Set the default value of a global parameter.
setGlobalParameterName(self, index, name) Set the name of a global parameter.
setNonbondedMethod(self, method) Set the method used for handling long range nonbonded interactions.
setParticleParameters(self, index, parameters) Set the nonbonded force parameters for a particle.
setPerParticleParameterName(self, index, name) Set the name of a per-particle parameter.
updateParametersInContext(self, context) Update the per-particle parameters in a Context to match those stored in this Force object.
usesPeriodicBoundaryConditions(self) Returns whether or not this force makes use of periodic boundary conditions.

Attributes

CutoffNonPeriodic
CutoffPeriodic
NoCutoff
ParticlePair
ParticlePairNoExclusions
SingleParticle
getNumParticles(self) → int

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

getNumExclusions(self) → int

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

getNumPerParticleParameters(self) → int

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

getNumGlobalParameters(self) → int

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

getNumEnergyParameterDerivatives(self) → int

Get the number of global parameters with respect to which the derivative of the energy should be computed.

getNumTabulatedFunctions(self) → int

Get the number of tabulated functions that have been defined.

getNumFunctions(self) → int

Get the number of tabulated functions that have been defined.

Deprecated

This method exists only for backward compatibility. Use getNumTabulatedFunctions() instead.
getNumComputedValues(self) → int

Get the number of per-particle computed values the interaction depends on.

getNumEnergyTerms(self) → int

Get the number of terms in the energy computation.

getNonbondedMethod(self) → OpenMM::CustomGBForce::NonbondedMethod

Get the method used for handling long range nonbonded interactions.

setNonbondedMethod(self, method)

Set the method used for handling long range nonbonded interactions.

getCutoffDistance(self) → double

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
Return type:double
setCutoffDistance(self, 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:distance (double) – the cutoff distance, measured in nm
addPerParticleParameter(self, name) → int

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

Parameters:name (string) – the name of the parameter
Returns:the index of the parameter that was added
Return type:int
getPerParticleParameterName(self, index) → std::string const &

Get the name of a per-particle parameter.

Parameters:index (int) – the index of the parameter for which to get the name
Returns:the parameter name
Return type:string
setPerParticleParameterName(self, index, name)

Set the name of a per-particle parameter.

Parameters:
  • index (int) – the index of the parameter for which to set the name
  • name (string) – the name of the parameter
addGlobalParameter(self, name, defaultValue) → int

Add a new global parameter that the interaction may depend on. The default value provided to this method is the initial value of the parameter in newly created Contexts. You can change the value at any time by calling setParameter() on the Context.

Parameters:
  • name (string) – the name of the parameter
  • defaultValue (double) – the default value of the parameter
Returns:

the index of the parameter that was added

Return type:

int

getGlobalParameterName(self, index) → std::string const &

Get the name of a global parameter.

Parameters:index (int) – the index of the parameter for which to get the name
Returns:the parameter name
Return type:string
setGlobalParameterName(self, index, name)

Set the name of a global parameter.

Parameters:
  • index (int) – the index of the parameter for which to set the name
  • name (string) – the name of the parameter
getGlobalParameterDefaultValue(self, index) → double

Get the default value of a global parameter.

Parameters:index (int) – the index of the parameter for which to get the default value
Returns:the parameter default value
Return type:double
setGlobalParameterDefaultValue(self, index, defaultValue)

Set the default value of a global parameter.

Parameters:
  • index (int) – the index of the parameter for which to set the default value
  • defaultValue (double) – the default value of the parameter
addEnergyParameterDerivative(self, name)

Request that this Force compute the derivative of its energy with respect to a global parameter. The parameter must have already been added with addGlobalParameter().

Parameters:name (string) – the name of the parameter
getEnergyParameterDerivativeName(self, index) → std::string const &

Get the name of a global parameter with respect to which this Force should compute the derivative of the energy.

Parameters:index (int) – the index of the parameter derivative, between 0 and getNumEnergyParameterDerivatives()
Returns:the parameter name
Return type:string
addParticle(self, parameters) → int

addParticle(self) -> int

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:parameters (vector< double >) – the list of parameters for the new particle
Returns:the index of the particle that was added
Return type:int
getParticleParameters(self, index)

Get the nonbonded force parameters for a particle.

Parameters:index (int) – the index of the particle for which to get parameters
Returns:parameters – the list of parameters for the specified particle
Return type:vector< double >
setParticleParameters(self, index, parameters)

Set the nonbonded force parameters for a particle.

Parameters:
  • index (int) – the index of the particle for which to set parameters
  • parameters (vector< double >) – the list of parameters for the specified particle
addComputedValue(self, name, expression, type) → int

Add a computed value to calculate for each particle.

Parameters:
  • name (string) – the name of the value
  • expression (string) – 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 per-particle 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 per-particle 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 (ComputationType) – the method to use for computing this value
getComputedValueParameters(self, index)

Get the properties of a computed value.

Parameters:index (int) – the index of the computed value for which to get parameters
Returns:
  • name (string) – the name of the value
  • expression (string) – 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 per-particle 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 per-particle 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 (ComputationType) – the method to use for computing this value
setComputedValueParameters(self, index, name, expression, type)

Set the properties of a computed value.

Parameters:
  • index (int) – the index of the computed value for which to set parameters
  • name (string) – the name of the value
  • expression (string) – 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 per-particle 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 per-particle 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 (ComputationType) – the method to use for computing this value
addEnergyTerm(self, expression, type) → int

Add a term to the energy computation.

Parameters:
  • expression (string) – 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 per-particle 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 per-particle 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 (ComputationType) – the method to use for computing this value
getEnergyTermParameters(self, index)

Get the properties of a term to the energy computation.

Parameters:index (int) – the index of the term for which to get parameters
Returns:
  • expression (string) – 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 per-particle 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 per-particle 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 (ComputationType) – the method to use for computing this value
setEnergyTermParameters(self, index, expression, type)

Set the properties of a term to the energy computation.

Parameters:
  • index (int) – the index of the term for which to set parameters
  • expression (string) – 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 per-particle 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 per-particle 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 (ComputationType) – the method to use for computing this value
addExclusion(self, particle1, particle2) → int

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

Parameters:
  • particle1 (int) – the index of the first particle in the pair
  • particle2 (int) – the index of the second particle in the pair
Returns:

the index of the exclusion that was added

Return type:

int

getExclusionParticles(self, index)

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

Parameters:index (int) – the index of the exclusion for which to get particle indices
Returns:
  • particle1 (int) – the index of the first particle in the pair
  • particle2 (int) – the index of the second particle in the pair
setExclusionParticles(self, index, particle1, particle2)

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

Parameters:
  • index (int) – the index of the exclusion for which to set particle indices
  • particle1 (int) – the index of the first particle in the pair
  • particle2 (int) – the index of the second particle in the pair
addTabulatedFunction(self, name, function) → int

Add a tabulated function that may appear in expressions.

Parameters:
  • name (string) – the name of the function as it appears in expressions
  • function (TabulatedFunction *) – 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.
Returns:

the index of the function that was added

Return type:

int

getTabulatedFunction(self, index) → TabulatedFunction

getTabulatedFunction(self, index) -> TabulatedFunction

Get a reference to a tabulated function that may appear in expressions.

Parameters:index (int) – the index of the function to get
Returns:the TabulatedFunction object defining the function
Return type:TabulatedFunction
getTabulatedFunctionName(self, index) → std::string const &

Get the name of a tabulated function that may appear in expressions.

Parameters:index (int) – the index of the function to get
Returns:the name of the function as it appears in expressions
Return type:string
addFunction(self, name, values, min, max) → int

Add a tabulated function that may appear in expressions.

Deprecated

This method exists only for backward compatibility. Use addTabulatedFunction() instead.
getFunctionParameters(self, index)

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

Deprecated

This method exists only for backward compatibility. Use getTabulatedFunctionParameters() instead. If the specified function is not a Continuous1DFunction, this throws an exception.
setFunctionParameters(self, index, name, values, min, max)

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

Deprecated

This method exists only for backward compatibility. Use setTabulatedFunctionParameters() instead. If the specified function is not a Continuous1DFunction, this throws an exception.
updateParametersInContext(self, 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 updateParametersInContext() 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 (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.

usesPeriodicBoundaryConditions(self) → bool

Returns whether or not this force makes use of periodic boundary conditions.

Returns:true if force uses PBC and false otherwise
Return type:bool
__copy__(self) → Force
getForceGroup(self) → int

Get the force group this Force belongs to.

setForceGroup(self, group)

Set the force group this Force belongs to.

Parameters:group (int) – the group index. Legal values are between 0 and 31 (inclusive).