Class CompoundIntegrator
CompoundIntegrator compoundIntegrator = new CompoundIntegrator(); compoundIntegrator.addIntegrator(new VerletIntegrator(0.001)); compoundIntegrator.addIntegrator(new LangevinIntegrator(300.0, 1.0, 0.001));
Next create a Context, specifying the CompoundIntegrator as the Integrator to use for the Context:
Context context = new Context(system, compoundIntegrator);
Finally, call setCurrentIntegrator() to set which Integrator is active. That one will be used for all calls to step() until the next time you change it.
compoundIntegrator.setCurrentIntegrator(0); compoundIntegrator.step(1000); // Take 1000 steps of Verlet dynamics compoundIntegrator.setCurrentIntegrator(1); compoundIntegrator.step(1000); // Take 1000 steps of Langevin dynamics
When switching between integrators, it is important to make sure they are compatible with each other, and that they will interpret the positions and velocities in the same way. Remember that leapfrog style integrators assume the positions and velocities are offset from each other by half a time step. When switching between a leapfrog and non-leapfrog integrator, you must first adjust the velocities to avoid introducing error. This is also true when switching between two leapfrog integrators that use different step sizes, since they will interpret the velocities as corresponding to different times.
-
Field Summary
Fields inherited from class ffx.openmm.Integrator
pointer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
addIntegrator
(Integrator integrator) Add an Integrator to this CompoundIntegrator.void
destroy()
Destroy the integrator.double
Get the distance tolerance within which constraints are maintained, as a fraction of the constrained distance.int
Get the index of the current Integrator.int
Get which force groups to use for integration.com.sun.jna.ptr.PointerByReference
getIntegrator
(int index) Get a reference to one of the Integrators that have been added to this CompoundIntegrator.int
Get the number of Integrators that have been added to this CompoundIntegrator.double
Get the size of each time step, in picoseconds.void
setConstraintTolerance
(double tol) Set the distance tolerance within which constraints are maintained, as a fraction of the constrained distance.void
setCurrentIntegrator
(int index) Set the current Integrator.void
setIntegrationForceGroups
(int groups) Set which force groups to use for integration.void
setStepSize
(double size) Set the size of each time step, in picoseconds.void
step
(int steps) Advance a simulation through time by taking a series of time steps.Methods inherited from class ffx.openmm.Integrator
getPointer, setPointer
-
Constructor Details
-
CompoundIntegrator
public CompoundIntegrator()Create a CompoundIntegrator.
-
-
Method Details
-
addIntegrator
Add an Integrator to this CompoundIntegrator. The Integrator object should have been created on the heap with the "new" operator. The CompoundIntegrator takes over ownership of it, and deletes it when the CompoundIntegrator itself is deleted. All Integrators must be added before the Context is created.- Parameters:
integrator
- the Integrator to add- Returns:
- the index of the Integrator that was added
-
destroy
public void destroy()Destroy the integrator.- Specified by:
destroy
in classIntegrator
-
getConstraintTolerance
public double getConstraintTolerance()Get the distance tolerance within which constraints are maintained, as a fraction of the constrained distance. This method calls getConstraintTolerance() on whichever Integrator has been set as current.- Overrides:
getConstraintTolerance
in classIntegrator
- Returns:
- The constraint tolerance in nm.
-
getCurrentIntegrator
public int getCurrentIntegrator()Get the index of the current Integrator. -
getIntegrationForceGroups
public int getIntegrationForceGroups()Get which force groups to use for integration. By default, all force groups are included. This is interpreted as a set of bit flags: the forces from group i will be included if (groups&(1<<i)) != 0.This method returns the integration force groups for the current Integrator.
- Overrides:
getIntegrationForceGroups
in classIntegrator
- Returns:
- The bit flags indicating which force groups this integrator acts on.
-
getIntegrator
public com.sun.jna.ptr.PointerByReference getIntegrator(int index) Get a reference to one of the Integrators that have been added to this CompoundIntegrator.- Parameters:
index
- the index of the Integrator to get
-
getNumIntegrators
public int getNumIntegrators()Get the number of Integrators that have been added to this CompoundIntegrator. -
getStepSize
public double getStepSize()Get the size of each time step, in picoseconds. This method calls getStepSize() on whichever Integrator has been set as current.- Overrides:
getStepSize
in classIntegrator
- Returns:
- the step size, measured in ps
-
setConstraintTolerance
public void setConstraintTolerance(double tol) Set the distance tolerance within which constraints are maintained, as a fraction of the constrained distance. This method calls setConstraintTolerance() on whichever Integrator has been set as current.- Overrides:
setConstraintTolerance
in classIntegrator
- Parameters:
tol
- The tolerance within which constraints must be satisfied.
-
setCurrentIntegrator
public void setCurrentIntegrator(int index) Set the current Integrator.- Parameters:
index
- the index of the Integrator to use
-
setIntegrationForceGroups
public void setIntegrationForceGroups(int groups) Set which force groups to use for integration. By default, all force groups are included. This is interpreted as a set of bit flags: the forces from group i will be included if (groups&(1<<i)) != 0.Calling this method sets the integration force groups for all Integrators contained in this CompoundIntegrator.
- Overrides:
setIntegrationForceGroups
in classIntegrator
- Parameters:
groups
- The bit flags indicating which force groups this integrator acts on.
-
setStepSize
public void setStepSize(double size) Set the size of each time step, in picoseconds. This method calls setStepSize() on whichever Integrator has been set as current.- Overrides:
setStepSize
in classIntegrator
- Parameters:
size
- the step size, measured in ps
-
step
public void step(int steps) Advance a simulation through time by taking a series of time steps. This method calls step() on whichever Integrator has been set as current.- Overrides:
step
in classIntegrator
- Parameters:
steps
- the number of time steps to take
-