openmmtools.forces.HarmonicRestraintForce

class openmmtools.forces.HarmonicRestraintForce(spring_constant, *args, **kwargs)[source]

Impose a single harmonic restraint between the centroids of two groups of atoms.

This can be used to prevent the ligand from drifting too far from the protein in implicit solvent calculations or to keep the ligand close to the binding pocket in the decoupled states to increase mixing.

The restraint is applied between the centroids of two groups of atoms that belong to the receptor and the ligand respectively. The centroids are determined by a mass-weighted average of the group particles positions.

The energy expression of the restraint is given by

E = controlling_parameter * (K/2)*r^2

where K is the spring constant, r is the distance between the two group centroids, and controlling_parameter is a scale factor that can be used to control the strength of the restraint.

With OpenCL, only on 64bit platforms are supported.

Parameters:
spring_constant : simtk.unit.Quantity

The spring constant K (see energy expression above) in units compatible with joule/nanometer**2/mole.

restrained_atom_indices1 : iterable of int

The indices of the first group of atoms to restrain.

restrained_atom_indices2 : iterable of int

The indices of the second group of atoms to restrain.

controlling_parameter_name : str, optional

The name of the global parameter controlling the energy function. The default value is ‘lambda_restraints’.

Attributes:
spring_constant

unit.simtk.Quantity: The spring constant K (units of energy/mole/distance^2).

restrained_atom_indices1

The indices of the first group of restrained atoms.

restrained_atom_indices2

The indices of the first group of restrained atoms.

restraint_parameters

OrderedDict: The restraint parameters in dictionary form.

controlling_parameter_name

str: The name of the global parameter controlling the energy function (read-only).

Methods

addBond(self, groups, parameters) addBond(self, groups) -> int
addEnergyParameterDerivative(self, name) Request that this Force compute the derivative of its energy with respect to a global parameter.
addGlobalParameter(self, name, defaultValue) Add a new global parameter that the interaction may depend on.
addGroup(self, particles, weights) addGroup(self, particles) -> int
addPerBondParameter(self, name) Add a new per-bond parameter that the interaction may depend on.
addTabulatedFunction(self, name, function) Add a tabulated function that may appear in the energy expression.
compute_standard_state_correction(…[, …]) Return the standard state correction of the restraint.
deserialize_xml(xml_serialization) Shortcut to deserialize the XML representation and the restore interface.
distance_at_energy(potential_energy) Compute the distance at which the potential energy is potential_energy.
getBondParameters(self, index) Get the properties of a bond.
getEnergyFunction(self) Get the algebraic expression that gives the interaction energy of each bond
getEnergyParameterDerivativeName(self, index) Get the name of a global parameter with respect to which this Force should compute the derivative of the energy.
getForceGroup(self) Get the force group this Force belongs to.
getGlobalParameterDefaultValue(self, index) Get the default value of a global parameter.
getGlobalParameterName(self, index) Get the name of a global parameter.
getGroupParameters(self, index) Get the properties of a group.
getNumBonds(self) Get the number of bonds for which force field parameters have been defined.
getNumEnergyParameterDerivatives(self) Get the number of global parameters with respect to which the derivative of the energy should be computed.
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.
getNumGroups(self) Get the number of particle groups that have been defined.
getNumGroupsPerBond(self) Get the number of groups used to define each bond.
getNumPerBondParameters(self) Get the number of per-bond parameters that the interaction depends on.
getNumTabulatedFunctions(self) Get the number of tabulated functions that have been defined.
getPerBondParameterName(self, index) Get the name of a per-bond parameter.
getTabulatedFunction(self, index) getTabulatedFunction(self, index) -> TabulatedFunction
getTabulatedFunctionName(self, index) Get the name of a tabulated function that may appear in the energy expression.
is_restorable(openmm_object) Check if the custom integrator or force has a restorable interface.
restore_interface(openmm_object) Restore the original interface of an OpenMM custom force or integrator.
setBondParameters(self, index, groups, …) Set the properties of a bond.
setEnergyFunction(self, energy) Set the algebraic expression that gives the interaction energy of each bond
setForceGroup(self, group) Set the force group this Force belongs to.
setGlobalParameterDefaultValue(self, index, …) Set the default value of a global parameter.
setGlobalParameterName(self, index, name) Set the name of a global parameter.
setGroupParameters(self, index, particles, …) Set the properties of a group.
setPerBondParameterName(self, index, name) Set the name of a per-bond parameter.
setUsesPeriodicBoundaryConditions(self, periodic) Set whether this force should apply periodic boundary conditions when calculating displacements.
updateParametersInContext(self, context) Update the per-bond 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.
__init__(spring_constant, *args, **kwargs)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(spring_constant, *args, **kwargs) Initialize self.
addBond(self, groups, parameters) addBond(self, groups) -> int
addEnergyParameterDerivative(self, name) Request that this Force compute the derivative of its energy with respect to a global parameter.
addGlobalParameter(self, name, defaultValue) Add a new global parameter that the interaction may depend on.
addGroup(self, particles, weights) addGroup(self, particles) -> int
addPerBondParameter(self, name) Add a new per-bond parameter that the interaction may depend on.
addTabulatedFunction(self, name, function) Add a tabulated function that may appear in the energy expression.
compute_standard_state_correction(…[, …]) Return the standard state correction of the restraint.
deserialize_xml(xml_serialization) Shortcut to deserialize the XML representation and the restore interface.
distance_at_energy(potential_energy) Compute the distance at which the potential energy is potential_energy.
getBondParameters(self, index) Get the properties of a bond.
getEnergyFunction(self) Get the algebraic expression that gives the interaction energy of each bond
getEnergyParameterDerivativeName(self, index) Get the name of a global parameter with respect to which this Force should compute the derivative of the energy.
getForceGroup(self) Get the force group this Force belongs to.
getGlobalParameterDefaultValue(self, index) Get the default value of a global parameter.
getGlobalParameterName(self, index) Get the name of a global parameter.
getGroupParameters(self, index) Get the properties of a group.
getNumBonds(self) Get the number of bonds for which force field parameters have been defined.
getNumEnergyParameterDerivatives(self) Get the number of global parameters with respect to which the derivative of the energy should be computed.
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.
getNumGroups(self) Get the number of particle groups that have been defined.
getNumGroupsPerBond(self) Get the number of groups used to define each bond.
getNumPerBondParameters(self) Get the number of per-bond parameters that the interaction depends on.
getNumTabulatedFunctions(self) Get the number of tabulated functions that have been defined.
getPerBondParameterName(self, index) Get the name of a per-bond parameter.
getTabulatedFunction(self, index) getTabulatedFunction(self, index) -> TabulatedFunction
getTabulatedFunctionName(self, index) Get the name of a tabulated function that may appear in the energy expression.
is_restorable(openmm_object) Check if the custom integrator or force has a restorable interface.
restore_interface(openmm_object) Restore the original interface of an OpenMM custom force or integrator.
setBondParameters(self, index, groups, …) Set the properties of a bond.
setEnergyFunction(self, energy) Set the algebraic expression that gives the interaction energy of each bond
setForceGroup(self, group) Set the force group this Force belongs to.
setGlobalParameterDefaultValue(self, index, …) Set the default value of a global parameter.
setGlobalParameterName(self, index, name) Set the name of a global parameter.
setGroupParameters(self, index, particles, …) Set the properties of a group.
setPerBondParameterName(self, index, name) Set the name of a per-bond parameter.
setUsesPeriodicBoundaryConditions(self, periodic) Set whether this force should apply periodic boundary conditions when calculating displacements.
updateParametersInContext(self, context) Update the per-bond 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

controlling_parameter_name str: The name of the global parameter controlling the energy function (read-only).
restrained_atom_indices1 The indices of the first group of restrained atoms.
restrained_atom_indices2 The indices of the first group of restrained atoms.
restraint_parameters OrderedDict: The restraint parameters in dictionary form.
spring_constant unit.simtk.Quantity: The spring constant K (units of energy/mole/distance^2).
addBond(self, groups, parameters) → int

addBond(self, groups) -> int

Add a bond to the force

Parameters:
groups : vector< int >

the indices of the groups the bond depends on

parameters : vector< double >

the list of per-bond parameter values for the new bond

Returns:
int

the index of the bond that was added

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

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:
int

the index of the parameter that was added

addGroup(self, particles, weights) → int

addGroup(self, particles) -> int

Add a particle group.

Parameters:
particles : vector< int >

the indices of the particles to include in the group

weights : vector< double >

the weight to use for each particle when computing the center position. If this is omitted, then particle masses will be used as weights.

Returns:
int

the index of the group that was added

addPerBondParameter(self, name) → int

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

Parameters:
name : string

the name of the parameter

Returns:
int

the index of the parameter that was added

addTabulatedFunction(self, name, function) → int

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

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:
int

the index of the function that was added

compute_standard_state_correction(thermodynamic_state, square_well=False, radius_cutoff=None, energy_cutoff=None, max_volume=None)

Return the standard state correction of the restraint.

The standard state correction is computed as

  • log(V_standard / V_restraint)

where V_standard is the volume at standard state concentration and V_restraint is the restraint volume. V_restraint is bounded by the volume of the periodic box.

The square_well parameter, can be used to re-compute the standard state correction when removing the bias introduced by the restraint.

Parameters:
thermodynamic_state : states.ThermodynamicState

The thermodynamic state at which to compute the standard state correction.

square_well : bool, optional

If True, this computes the standard state correction assuming the restraint to obey a square well potential. The energy cutoff is still applied to the original energy potential.

radius_cutoff : simtk.unit.Quantity, optional

The maximum distance achievable by the restraint (units compatible with nanometers). This is equivalent to placing a hard wall potential at this distance.

energy_cutoff : float, optional

The maximum potential energy achievable by the restraint in kT. This is equivalent to placing a hard wall potential at a distance such that potential_energy(distance) == energy_cutoff.

max_volume : simtk.unit.Quantity or ‘system’, optional

The volume of the periodic box (units compatible with nanometer**3). This must be provided the thermodynamic state is in NPT. If the string ‘system’ is passed, the maximum volume is computed from the system box vectors (this has no effect if the system is not periodic).

Returns:
correction : float

The unit-less standard state correction in kT at the given thermodynamic state.

Raises:
TypeError

If the thermodynamic state is in the NPT ensemble, and max_volume is not provided, or if the system is non-periodic and no cutoff is given.

controlling_parameter_name

str: The name of the global parameter controlling the energy function (read-only).

classmethod deserialize_xml(xml_serialization)

Shortcut to deserialize the XML representation and the restore interface.

Parameters:
xml_serialization : str

The XML representation of the OpenMM custom force/integrator.

Returns:
openmm_object

The deserialized OpenMM force/integrator with the original interface restored (if restorable).

distance_at_energy(potential_energy)

Compute the distance at which the potential energy is potential_energy.

Parameters:
potential_energy : simtk.unit.Quantity

The potential energy of the restraint (units of energy/mole).

Returns:
distance : simtk.unit.Quantity

The distance at which the potential energy is potential_energy (units of length).

getBondParameters(self, index)

Get the properties of a bond.

Parameters:
index : int

the index of the bond to get

Returns:
groups : vector< int >

the indices of the groups in the bond

parameters : vector< double >

the list of per-bond parameter values for the bond

getEnergyFunction(self) → std::string const &

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

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:
string

the parameter name

getForceGroup(self) → int

Get the force group this Force belongs to.

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:
double

the parameter default value

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:
string

the parameter name

getGroupParameters(self, index)

Get the properties of a group.

Parameters:
index : int

the index of the group to get

Returns:
particles : vector< int >

the indices of the particles in the group

weights : vector< double >

the weight used for each particle when computing the center position. If no weights were specified, this vector will be empty indicating that particle masses should be used as weights.

getNumBonds(self) → int

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

getNumEnergyParameterDerivatives(self) → int

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

getNumFunctions(self) → int

Get the number of tabulated functions that have been defined.

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

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

getNumGroups(self) → int

Get the number of particle groups that have been defined.

getNumGroupsPerBond(self) → int

Get the number of groups used to define each bond.

getNumPerBondParameters(self) → int

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

getNumTabulatedFunctions(self) → int

Get the number of tabulated functions that have been defined.

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

Get the name of a per-bond parameter.

Parameters:
index : int

the index of the parameter for which to get the name

Returns:
string

the parameter name

getTabulatedFunction(self, index) → TabulatedFunction

getTabulatedFunction(self, index) -> TabulatedFunction

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

Parameters:
index : int

the index of the function to get

Returns:
TabulatedFunction

the TabulatedFunction object defining the function

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

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

Parameters:
index : int

the index of the function to get

Returns:
string

the name of the function as it appears in expressions

classmethod is_restorable(openmm_object)

Check if the custom integrator or force has a restorable interface.

Parameters:
openmm_object : object

The custom integrator or force to check.

Returns:
True if the object has a restorable interface, False otherwise.
classmethod restore_interface(openmm_object)

Restore the original interface of an OpenMM custom force or integrator.

The function restore the methods of the original class that inherited from RestorableOpenMMObject. Return False if the interface could not be restored.

Parameters:
openmm_object : object

The object to restore.

Returns:
True if the original class interface could be restored, False otherwise.
restrained_atom_indices1

The indices of the first group of restrained atoms.

restrained_atom_indices2

The indices of the first group of restrained atoms.

restraint_parameters

OrderedDict: The restraint parameters in dictionary form.

setBondParameters(self, index, groups, parameters) setBondParameters(self, index, groups)

Set the properties of a bond.

Parameters:
index : int

the index of the bond to set

groups : vector< int >

the indices of the groups in the bond

parameters : vector< double >

the list of per-bond parameter values for the bond

setEnergyFunction(self, energy)

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

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).

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

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

setGroupParameters(self, index, particles, weights) setGroupParameters(self, index, particles)

Set the properties of a group.

Parameters:
index : int

the index of the group to set

particles : vector< int >

the indices of the particles in the group

weights : vector< double >

the weight to use for each particle when computing the center position. If this is omitted, then particle masses will be used as weights.

setPerBondParameterName(self, index, name)

Set the name of a per-bond parameter.

Parameters:
index : int

the index of the parameter for which to set the name

name : string

the name of the parameter

setUsesPeriodicBoundaryConditions(self, periodic)

Set whether this force should apply periodic boundary conditions when calculating displacements. Usually this is not appropriate for bonded forces, but there are situations when it can be useful.

spring_constant

unit.simtk.Quantity: The spring constant K (units of energy/mole/distance^2).

updateParametersInContext(self, context)

Update the per-bond 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 setBondParameters() 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-bond parameters. All other aspects of the Force (such as the energy function) are unaffected and can only be changed by reinitializing the Context. Neither the definitions of groups nor the set of groups involved in a bond can be changed, nor can new bonds be added.

usesPeriodicBoundaryConditions(self) → bool

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

Returns:
bool

true if force uses PBC and false otherwise