openmmtools.mcmc.BaseIntegratorMove

class openmmtools.mcmc.BaseIntegratorMove(n_steps, reassign_velocities=False, n_restart_attempts=4, **kwargs)[source]

A general MCMC move that applies an integrator.

This class is intended to be inherited by MCMCMoves that need to integrate the system. The child class has to implement the _get_integrator method.

You can decide to override _before_integration() and _after_integration() to execute some code at specific points of the workflow, for example to read data from the Context before the it is destroyed.

Parameters:
n_stepsint

The number of integration steps to take each time the move is applied.

reassign_velocitiesbool, optional

If True, the velocities will be reassigned from the Maxwell-Boltzmann distribution at the beginning of the move (default is False).

n_restart_attemptsint, optional

When greater than 0, if after the integration there are NaNs in energies, the move will restart. When the integrator has a random component, this may help recovering. On the last attempt, the Context is re-initialized in a slower process, but better than the simulation crashing. An IntegratorMoveError is raised after the given number of attempts if there are still NaNs.

Examples

Create a VerletIntegratorMove class.

>>> from openmmtools import testsystems, states
>>> from openmm import VerletIntegrator
>>> class VerletMove(BaseIntegratorMove):
...     def __init__(self, timestep, n_steps, **kwargs):
...         super(VerletMove, self).__init__(n_steps, **kwargs)
...         self.timestep = timestep
...     def _get_integrator(self, thermodynamic_state):
...         return VerletIntegrator(self.timestep)
...     def _before_integration(self, context, thermodynamic_state):
...         print('Setting velocities')
...         context.setVelocitiesToTemperature(thermodynamic_state.temperature)
...     def _after_integration(self, context, thermodynamic_state):
...         print('Reading statistics')
...
>>> alanine = testsystems.AlanineDipeptideVacuum()
>>> sampler_state = states.SamplerState(alanine.positions)
>>> thermodynamic_state = states.ThermodynamicState(alanine.system, 300*unit.kelvin)
>>> move = VerletMove(timestep=1.0*unit.femtosecond, n_steps=2)
>>> move.apply(thermodynamic_state,sampler_state,context_cache=context_cache)
Setting velocities
Reading statistics
Attributes:
n_stepsint
reassign_velocitiesbool
n_restart_attemptsint or None

Methods

apply(thermodynamic_state, sampler_state[, ...])

Propagate the state through the integrator.

__init__(n_steps, reassign_velocities=False, n_restart_attempts=4, **kwargs)[source]

Methods

__init__(n_steps[, reassign_velocities, ...])

apply(thermodynamic_state, sampler_state[, ...])

Propagate the state through the integrator.

Attributes

context_cache