openmmtools.mcmc.MetropolizedMove

class openmmtools.mcmc.MetropolizedMove(atom_subset=None, **kwargs)[source]

A base class for metropolized moves.

This class is intended to be inherited by MCMCMoves that needs to accept or reject a proposed move with a Metropolis criterion. Only the proposal needs to be specified by subclasses through the method _propose_positions().

Parameters:
atom_subsetslice or list of int, optional

If specified, the move is applied only to those atoms specified by these indices. If None, the move is applied to all atoms (default is None).

Examples

>>> from openmm import unit
>>> from openmmtools import testsystems, states
>>> class AddOneVector(MetropolizedMove):
...     def __init__(self, **kwargs):
...         super(AddOneVector, self).__init__(**kwargs)
...     def _propose_positions(self, initial_positions):
...         print('Propose new positions')
...         displacement = unit.Quantity(np.array([1.0, 1.0, 1.0]), initial_positions.unit)
...         return initial_positions + displacement
...
>>> alanine = testsystems.AlanineDipeptideVacuum()
>>> sampler_state = states.SamplerState(alanine.positions)
>>> thermodynamic_state = states.ThermodynamicState(alanine.system, 300*unit.kelvin)
>>> move = AddOneVector(atom_subset=list(range(sampler_state.n_particles)))
>>> move.apply(thermodynamic_state,sampler_state,context_cache=context_cache)
Propose new positions
>>> move.n_accepted
1
>>> move.n_proposed
1
Attributes:
n_acceptedint

The number of proposals accepted.

n_proposedint

The total number of attempted moves.

atom_subset

Methods

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

Apply a metropolized move to the sampler state.

__init__(atom_subset=None, **kwargs)[source]

Methods

__init__([atom_subset])

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

Apply a metropolized move to the sampler state.

Attributes

context_cache

statistics

The acceptance statistics as a dictionary.