CustomVolumeForce

class CustomVolumeForce : public OpenMM::Force

This class computes an energy that depends only on the volume of the periodic box, or more generally on the box shape as specified by the elements of the box vectors. Because the energy does not depend on particle positions, it does not apply any forces to particles. It is primarily useful for constant pressure simulations, where the volume-dependent energy can influence the behavior of the barostat. Energy terms of this sort are often used for pressure matching in coarse grained force fields.

To use this class, create a CustomVolumeForce object, passing an algebraic expression to the constructor that defines the energy. The expression may depend on the following variables.

  • v: The volume of the periodic box in nm^3.

  • ax: The x component of the first box vector in nm. (The y and z components are always zero.)

  • bx, by: The x and y components of the second box vector in nm. (The z component is always zero.)

  • cx, cy, cz: The x, y and z components of the third box vector in nm.

  • Global parameters that you define by calling addGlobalParameter().

The initial value of a global parameter is specified in the call to addGlobalParameter(). Theire values can be modified during a simulation by calling Context::setParameter().

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.

Public Functions

explicit CustomVolumeForce(const std::string &energy)

Create a CustomVolumeForce.

Parameters

energy – an algebraic expression giving the energy as a function of the box shape

inline int getNumGlobalParameters() const

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

const std::string &getEnergyFunction() const

Get the algebraic expression that defines the energy.

void setEnergyFunction(const std::string &energy)

Set the algebraic expression that defines the energy.

int addGlobalParameter(const std::string &name, double defaultValue)

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 – the name of the parameter

  • defaultValue – the default value of the parameter

Returns

the index of the parameter that was added

const std::string &getGlobalParameterName(int index) const

Get the name of a global parameter.

Parameters

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

Returns

the parameter name

void setGlobalParameterName(int index, const std::string &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

double getGlobalParameterDefaultValue(int index) const

Get the default value of a global parameter.

Parameters

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

Returns

the parameter default value

void setGlobalParameterDefaultValue(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

  • defaultValue – the default value of the parameter

inline virtual bool usesPeriodicBoundaryConditions() const

Returns whether or not this force makes use of periodic boundary conditions. Because this class is only applicable to periodic systems, this always returns true.