openmmtools.mcmc.MetropolizedMove¶
-
class
openmmtools.mcmc.MetropolizedMove(atom_subset=None, context_cache=None)[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_subset : slice 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).
- context_cache : openmmtools.cache.ContextCache, optional
The ContextCache to use for Context creation. If None, the global cache openmmtools.cache.global_context_cache is used (default is None).
Examples
>>> from simtk 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) Propose new positions >>> move.n_accepted 1 >>> move.n_proposed 1
Attributes: - n_accepted : int
The number of proposals accepted.
- n_proposed : int
The total number of attempted moves.
- atom_subset
- context_cache
Methods
apply(thermodynamic_state, sampler_state)Apply a metropolized move to the sampler state. -
__init__(atom_subset=None, context_cache=None)[source]¶ x.__init__(…) initializes x; see help(type(x)) for signature
Methods
__init__([atom_subset, context_cache])x.__init__(…) initializes x; see help(type(x)) for signature apply(thermodynamic_state, sampler_state)Apply a metropolized move to the sampler state. Attributes
statisticsThe acceptance statistics as a dictionary. -
apply(thermodynamic_state, sampler_state)[source]¶ Apply a metropolized move to the sampler state.
Total number of acceptances and proposed move are updated.
Parameters: - thermodynamic_state : openmmtools.states.ThermodynamicState
The thermodynamic state to use to apply the move.
- sampler_state : openmmtools.states.SamplerState
The initial sampler state to apply the move to. This is modified.
-
statistics¶ The acceptance statistics as a dictionary.