# CustomManyParticleForce Class Reference

This class supports a wide variety of nonbonded N-particle interactions, where N is user specified. More...

Inheritance diagram for CustomManyParticleForce:

List of all members.

## Public Member Functions

def | __del__
| __del__(OpenMM.CustomManyParticleForce self)
def | getNumParticlesPerSet
| getNumParticlesPerSet(CustomManyParticleForce self) -> int
def | getNumParticles
| getNumParticles(CustomManyParticleForce self) -> int
def | getNumExclusions
| getNumExclusions(CustomManyParticleForce self) -> int
def | getNumPerParticleParameters
| getNumPerParticleParameters(CustomManyParticleForce self) -> int
def | getNumGlobalParameters
| getNumGlobalParameters(CustomManyParticleForce self) -> int
def | getNumTabulatedFunctions
| getNumTabulatedFunctions(CustomManyParticleForce self) -> int
def | getEnergyFunction
| getEnergyFunction(CustomManyParticleForce self) -> std.string const &
def | setEnergyFunction
| setEnergyFunction(CustomManyParticleForce self, std.string const & energy)
def | getNonbondedMethod
| getNonbondedMethod(CustomManyParticleForce self) -> OpenMM.CustomManyParticleForce.NonbondedMethod
def | setNonbondedMethod
| setNonbondedMethod(CustomManyParticleForce self, OpenMM.CustomManyParticleForce.NonbondedMethod method)
def | getPermutationMode
| getPermutationMode(CustomManyParticleForce self) -> OpenMM.CustomManyParticleForce.PermutationMode
def | setPermutationMode
| setPermutationMode(CustomManyParticleForce self, OpenMM.CustomManyParticleForce.PermutationMode mode)
def | getCutoffDistance
| getCutoffDistance(CustomManyParticleForce self) -> double
def | setCutoffDistance
| setCutoffDistance(CustomManyParticleForce self, double distance)
def | addPerParticleParameter
| addPerParticleParameter(CustomManyParticleForce self, std.string const & name) -> int
def | getPerParticleParameterName
| getPerParticleParameterName(CustomManyParticleForce self, int index) -> std.string const &
def | setPerParticleParameterName
| setPerParticleParameterName(CustomManyParticleForce self, int index, std.string const & name)
def | addGlobalParameter
| addGlobalParameter(CustomManyParticleForce self, std.string const & name, double defaultValue) -> int
def | getGlobalParameterName
| getGlobalParameterName(CustomManyParticleForce self, int index) -> std.string const &
def | setGlobalParameterName
| setGlobalParameterName(CustomManyParticleForce self, int index, std.string const & name)
def | getGlobalParameterDefaultValue
| getGlobalParameterDefaultValue(CustomManyParticleForce self, int index) -> double
def | setGlobalParameterDefaultValue
| setGlobalParameterDefaultValue(CustomManyParticleForce self, int index, double defaultValue)
def | addParticle
| addParticle(CustomManyParticleForce self, vectord parameters, int type=0) -> int addParticle(CustomManyParticleForce self, vectord parameters) -> int
def | getParticleParameters
| getParticleParameters(CustomManyParticleForce self, int index)
def | setParticleParameters
| setParticleParameters(CustomManyParticleForce self, int index, vectord parameters, int type)
def | addExclusion
| addExclusion(CustomManyParticleForce self, int particle1, int particle2) -> int
def | getExclusionParticles
| getExclusionParticles(CustomManyParticleForce self, int index)
def | setExclusionParticles
| setExclusionParticles(CustomManyParticleForce self, int index, int particle1, int particle2)
def | createExclusionsFromBonds
| createExclusionsFromBonds(CustomManyParticleForce self, vectorpairii bonds, int bondCutoff)
def | getTypeFilter
| getTypeFilter(CustomManyParticleForce self, int index)
def | setTypeFilter
| setTypeFilter(CustomManyParticleForce self, int index, seti types)
def | addTabulatedFunction
| addTabulatedFunction(CustomManyParticleForce self, std.string const & name, TabulatedFunction function) -> int
def | getTabulatedFunction
| getTabulatedFunction(CustomManyParticleForce self, int index) -> TabulatedFunction getTabulatedFunction(CustomManyParticleForce self, int index) -> TabulatedFunction
def | getTabulatedFunctionName
| getTabulatedFunctionName(CustomManyParticleForce self, int index) -> std.string const &
def | updateParametersInContext
| updateParametersInContext(CustomManyParticleForce self, Context context)
def | __init__
| __init__(OpenMM.CustomManyParticleForce self, int particlesPerSet, std.string const & energy) -> CustomManyParticleForce __init__(OpenMM.CustomManyParticleForce self, CustomManyParticleForce other) -> CustomManyParticleForce

## Public Attributes

| this

## Static Public Attributes

| NoCutoff = _openmm.CustomManyParticleForce_NoCutoff
| CutoffNonPeriodic = _openmm.CustomManyParticleForce_CutoffNonPeriodic
| CutoffPeriodic = _openmm.CustomManyParticleForce_CutoffPeriodic
| SinglePermutation = _openmm.CustomManyParticleForce_SinglePermutation
| UniqueCentralParticle = _openmm.CustomManyParticleForce_UniqueCentralParticle

## Detailed Description

This class supports a wide variety of nonbonded N-particle interactions, where N is user specified.

The interaction energy is determined by an arbitrary, user specified algebraic expression that is evaluated for every possible set of N particles in the system. It may depend on the positions of the individual particles, the distances between pairs of particles, the angles formed by sets of three particles, and the dihedral angles formed by sets of four particles.

Be aware that the cost of evaluating an N-particle interaction increases very rapidly with N. Values larger than N=3 are rarely used.

We refer to a set of particles for which the energy is being evaluated as p1, p2, p3, etc. The energy expression may depend on the following variables and functions:

- x1, y1, z1, x2, y2, z2, etc.: The x, y, and z coordinates of the particle positions. For example, x1 is the x coordinate of particle p1, and y3 is the y coordinate of particle p3.

- distance(p1, p2): the distance between particles p1 and p2 (where "p1" and "p2" may be replaced by the names of whichever particles you want to calculate the distance between).

- angle(p1, p2, p3): the angle formed by the three specified particles.

- dihedral(p1, p2, p3, p4): the dihedral angle formed by the four specified particles.

- arbitrary global and per-particle parameters that you define.

To use this class, create a CustomManyParticleForce object, passing an algebraic expression to the constructor that defines the interaction energy of each set of particles. 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().

Multi-particle interactions can be very expensive to evaluate, so they are usually used with a cutoff distance. The exact interpretation of the cutoff depends on the permutation mode, as discussed below.

CustomManyParticleForce 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. If you specify a pair of particles as an exclusion, all sets that include those two particles will be omitted.

As an example, the following code creates a CustomManyParticleForce that implements an Axilrod-Teller potential. This is an interaction between three particles that depends on all three distances and angles formed by the particles.

``

    CustomManyParticleForce* force = new CustomManyParticleForce(3,
    "C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
    "theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
    "r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
    force->setPermutationMode(CustomManyParticleForce.SinglePermutation);

This force depends on one parameter, C. The following code defines it as a global parameter:

``

    force->addGlobalParameter("C", 1.0);

Notice that the expression is symmetric with respect to the particles. It only depends on the products cos(theta1)*cos(theta2)*cos(theta3) and r12*r13*r23, both of which are unchanged if the labels p1, p2, and p3 are permuted. This is required because we specified SinglePermutation as the permutation mode. (This is the default, so we did not really need to set it, but doing so makes the example clearer.) In this mode, the expression is only evaluated once for each set of particles. No guarantee is made about which particle will be identified as p1, p2, etc. Therefore, the energy must be symmetric with respect to exchange of particles. Otherwise, the results would be undefined because permuting the labels would change the energy.

Not all many-particle interactions work this way. Another common pattern is for the expression to describe an interaction between one central particle and other nearby particles. An example of this is the 3-particle piece of the Stillinger-Weber potential:

``

    CustomManyParticleForce* force = new CustomManyParticleForce(3,
    "L*eps*(cos(theta1)+1/3)^2*exp(sigma*gamma/(r12-a*sigma))*exp(sigma*gamma/(r13-a*sigma));"
    "r12 = distance(p1,p2); r13 = distance(p1,p3); theta1 = angle(p3,p1,p2)");
    force->setPermutationMode(CustomManyParticleForce.UniqueCentralParticle);

When the permutation mode is set to UniqueCentralParticle, particle p1 is treated as the central particle. For a set of N particles, the expression is evaluated N times, once with each particle as p1. The expression can therefore treat p1 differently from the other particles. Notice that it is still symmetric with respect to p2 and p3, however. There is no guarantee about how those labels will be assigned to particles.

Distance cutoffs are applied in different ways depending on the permutation mode. In SinglePermutation mode, every particle in the set must be within the cutoff distance of every other particle. If any two particles are further apart than the cutoff distance, the interaction is skipped. In UniqueCentralParticle mode, each particle must be within the cutoff distance of the central particle, but not necessarily of all the other particles. The cutoff may therefore exclude a subset of the permutations of a set of particles.

Another common situation is that some particles are fundamentally different from others, causing the expression to be inherently non-symmetric. An example would be a water model that involves three particles, two of which must be hydrogen and one of which must be oxygen. Cases like this can be implemented using particle types.

A particle type is an integer that you specify when you call addParticle(). (If you omit the argument, it defaults to 0.) For the water model, you could specify 0 for all oxygen atoms and 1 for all hydrogen atoms. You can then call setTypeFilter() to specify the list of allowed types for each of the N particles involved in an interaction:

``

    set<int> oxygenTypes, hydrogenTypes;
    oxygenTypes.insert(0);
    hydrogenTypes.insert(1);
    force->setTypeFilter(0, oxygenTypes);
    force->setTypeFilter(1, hydrogenTypes);
    force->setTypeFilter(2, hydrogenTypes);

This specifies that of the three particles in an interaction, p1 must be oxygen while p2 and p3 must be hydrogen. The energy expression will only be evaluated for triplets of particles that satisfy those requirements. It will still only be evaluated once for each triplet, so it must still be symmetric with respect to p2 and p3.

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", "2", etc. appended to them to indicate the values for the multiple interacting particles. For example, if you define a per-particle parameter called "charge", then the variable "charge2" is the charge of particle p2. As seen above, the 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 the expression.

## Member Function Documentation

def __del__ | ( |  | self | ) |

__del__(OpenMM.CustomManyParticleForce self)

Reimplemented from Force.

def __init__ | ( |  | self,
|  |  | args |
| ) |  |  |

__init__(OpenMM.CustomManyParticleForce self, int particlesPerSet, std.string const & energy) -> CustomManyParticleForce __init__(OpenMM.CustomManyParticleForce self, CustomManyParticleForce other) -> CustomManyParticleForce

Create a CustomManyParticleForce.

Parameters:

  | particlesPerSet | the number of particles in each set for which the energy is evaluated
  | energy | an algebraic expression giving the interaction energy of each triplet as a function of particle positions, inter-particle distances, angles, and any global and per-particle parameters

def addExclusion | ( |  | self,
|  |  | args |
| ) |  |  |

addExclusion(CustomManyParticleForce self, int particle1, int particle2) -> int

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

In many cases, you can use createExclusionsFromBonds() rather than adding each exclusion explicitly.

Parameters:

  | particle1 | the index of the first particle in the pair
  | particle2 | the index of the second particle in the pair

def addGlobalParameter | ( |  | self,
|  |  | args |
| ) |  |  |

addGlobalParameter(CustomManyParticleForce self, std.string const & name, double defaultValue) -> int

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

Parameters:

  | name | the name of the parameter
  | defaultValue | the default value of the parameter

def addParticle | ( |  | self,
|  |  | args |
| ) |  |  |

addParticle(CustomManyParticleForce self, vectord parameters, int type=0) -> int addParticle(CustomManyParticleForce self, vectord parameters) -> 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 | the list of parameters for the new particle
  | type | the type of the new particle

def addPerParticleParameter | ( |  | self,
|  |  | args |
| ) |  |  |

addPerParticleParameter(CustomManyParticleForce self, std.string const & name) -> int

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

Parameters:

  | name | the name of the parameter

def addTabulatedFunction | ( |  | self,
|  |  | args |
| ) |  |  |

addTabulatedFunction(CustomManyParticleForce self, std.string const & name, TabulatedFunction function) -> int

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

Parameters:

  | name | the name of the function as it appears in expressions
  | function | a TabulatedFunction object defining the function. 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.

def createExclusionsFromBonds | ( |  | self,
|  |  | args |
| ) |  |  |

createExclusionsFromBonds(CustomManyParticleForce self, vectorpairii bonds, int bondCutoff)

Identify exclusions based on the molecular topology. Particles which are separated by up to a specified number of bonds are added as exclusions.

Parameters:

  | bonds | the set of bonds based on which to construct exclusions. Each element specifies the indices of two particles that are bonded to each other.
  | bondCutoff | pairs of particles that are separated by this many bonds or fewer are added to the list of exclusions

def getCutoffDistance | ( |  | self | ) |

getCutoffDistance(CustomManyParticleForce 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.

def getEnergyFunction | ( |  | self | ) |

getEnergyFunction(CustomManyParticleForce self) -> std.string const &

Get the algebraic expression that gives the interaction energy of each bond

def getExclusionParticles | ( |  | self,
|  |  | args |
| ) |  |  |

getExclusionParticles(CustomManyParticleForce self, int index)

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

Parameters:

  | 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

def getGlobalParameterDefaultValue | ( |  | self,
|  |  | args |
| ) |  |  |

getGlobalParameterDefaultValue(CustomManyParticleForce self, int index) -> double

Get the default value of a global parameter.

Parameters:

  | index | the index of the parameter for which to get the default value

def getGlobalParameterName | ( |  | self,
|  |  | args |
| ) |  |  |

getGlobalParameterName(CustomManyParticleForce self, int index) -> std.string const &

Get the name of a global parameter.

Parameters:

  | index | the index of the parameter for which to get the name

def getNonbondedMethod | ( |  | self | ) |

getNonbondedMethod(CustomManyParticleForce self) -> OpenMM.CustomManyParticleForce.NonbondedMethod

Get the method used for handling long range nonbonded interactions.

def getNumExclusions | ( |  | self | ) |

getNumExclusions(CustomManyParticleForce self) -> int

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

def getNumGlobalParameters | ( |  | self | ) |

getNumGlobalParameters(CustomManyParticleForce self) -> int

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

def getNumParticles | ( |  | self | ) |

getNumParticles(CustomManyParticleForce self) -> int

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

def getNumParticlesPerSet | ( |  | self | ) |

getNumParticlesPerSet(CustomManyParticleForce self) -> int

Get the number of particles in each set for which the energy is evaluated

def getNumPerParticleParameters | ( |  | self | ) |

getNumPerParticleParameters(CustomManyParticleForce self) -> int

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

def getNumTabulatedFunctions | ( |  | self | ) |

getNumTabulatedFunctions(CustomManyParticleForce self) -> int

Get the number of tabulated functions that have been defined.

def getParticleParameters | ( |  | self,
|  |  | args |
| ) |  |  |

getParticleParameters(CustomManyParticleForce self, int index)

Get the nonbonded force parameters for a particle.

Parameters:

  | index | the index of the particle for which to get parameters
  | parameters | the list of parameters for the specified particle
  | type | the type of the specified particle

def getPermutationMode | ( |  | self | ) |

getPermutationMode(CustomManyParticleForce self) -> OpenMM.CustomManyParticleForce.PermutationMode

Get the mode that selects which permutations of a set of particles to evaluate the interaction for.

def getPerParticleParameterName | ( |  | self,
|  |  | args |
| ) |  |  |

getPerParticleParameterName(CustomManyParticleForce self, int index) -> std.string const &

Get the name of a per-particle parameter.

Parameters:

  | index | the index of the parameter for which to get the name

def getTabulatedFunction | ( |  | self,
|  |  | args |
| ) |  |  |

getTabulatedFunction(CustomManyParticleForce self, int index) -> TabulatedFunction getTabulatedFunction(CustomManyParticleForce self, int index) -> TabulatedFunction

Get a reference to a tabulated function that may appear in the energy expression.

Parameters:

  | index | the index of the function to get

def getTabulatedFunctionName | ( |  | self,
|  |  | args |
| ) |  |  |

getTabulatedFunctionName(CustomManyParticleForce self, int index) -> std.string const &

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

Parameters:

  | index | the index of the function to get

def getTypeFilter | ( |  | self,
|  |  | args |
| ) |  |  |

getTypeFilter(CustomManyParticleForce self, int index)

Get the allowed particle types for one of the particles involved in the interaction. If this an empty set (the default), no filter is applied and all interactions are evaluated regardless of the type of the specified particle.

Parameters:

  | index | the index of the particle within the interaction (between 0 and getNumParticlesPerSet())
  | types | the allowed types for the specified particle

def setCutoffDistance | ( |  | self,
|  |  | args |
| ) |  |  |

setCutoffDistance(CustomManyParticleForce self, 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:

  | distance | the cutoff distance, measured in nm

def setEnergyFunction | ( |  | self,
|  |  | args |
| ) |  |  |

setEnergyFunction(CustomManyParticleForce self, std.string const & energy)

Set the algebraic expression that gives the interaction energy of each bond

def setExclusionParticles | ( |  | self,
|  |  | args |
| ) |  |  |

setExclusionParticles(CustomManyParticleForce self, int index, int particle1, int particle2)

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

Parameters:

  | 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

def setGlobalParameterDefaultValue | ( |  | self,
|  |  | args |
| ) |  |  |

setGlobalParameterDefaultValue(CustomManyParticleForce self, int index, double defaultValue)

Set the default value of a global parameter.

Parameters:

  | index | the index of the parameter for which to set the default value
  | name | the default value of the parameter

def setGlobalParameterName | ( |  | self,
|  |  | args |
| ) |  |  |

setGlobalParameterName(CustomManyParticleForce self, int index, std.string const & name)

Set the name of a global parameter.

Parameters:

  | index | the index of the parameter for which to set the name
  | name | the name of the parameter

def setNonbondedMethod | ( |  | self,
|  |  | args |
| ) |  |  |

setNonbondedMethod(CustomManyParticleForce self, OpenMM.CustomManyParticleForce.NonbondedMethod method)

Set the method used for handling long range nonbonded interactions.

def setParticleParameters | ( |  | self,
|  |  | args |
| ) |  |  |

setParticleParameters(CustomManyParticleForce self, int index, vectord parameters, int type)

Set the nonbonded force parameters for a particle.

Parameters:

  | index | the index of the particle for which to set parameters
  | parameters | the list of parameters for the specified particle
  | type | the type of the specified particle

def setPermutationMode | ( |  | self,
|  |  | args |
| ) |  |  |

setPermutationMode(CustomManyParticleForce self, OpenMM.CustomManyParticleForce.PermutationMode mode)

Set the mode that selects which permutations of a set of particles to evaluate the interaction for.

def setPerParticleParameterName | ( |  | self,
|  |  | args |
| ) |  |  |

setPerParticleParameterName(CustomManyParticleForce self, int index, std.string const & name)

Set the name of a per-particle parameter.

Parameters:

  | index | the index of the parameter for which to set the name
  | name | the name of the parameter

def setTypeFilter | ( |  | self,
|  |  | args |
| ) |  |  |

setTypeFilter(CustomManyParticleForce self, int index, seti types)

Set the allowed particle types for one of the particles involved in the interaction. If this an empty set (the default), no filter is applied and all interactions are evaluated regardless of the type of the specified particle.

Parameters:

  | index | the index of the particle within the interaction (between 0 and getNumParticlesPerSet())
  | types | the allowed types for the specified particle

def updateParametersInContext | ( |  | self,
|  |  | args |
| ) |  |  |

updateParametersInContext(CustomManyParticleForce self, 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 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 (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.

## Member Data Documentation

CutoffNonPeriodic = _openmm.CustomManyParticleForce_CutoffNonPeriodic`[static]`

CutoffPeriodic = _openmm.CustomManyParticleForce_CutoffPeriodic`[static]`

NoCutoff = _openmm.CustomManyParticleForce_NoCutoff`[static]`

SinglePermutation = _openmm.CustomManyParticleForce_SinglePermutation`[static]`

this

UniqueCentralParticle = _openmm.CustomManyParticleForce_UniqueCentralParticle`[static]`

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

- openmm.py