ExtendedSpaceContext¶
- class openxps.ExtendedSpaceContext(system, integrator, platform=None, properties=None)[source]¶
An openmm.Context object that includes extra dynamical variables (DVs) and allows for extended phase-space (XPS) simulations.
- Parameters:
system (ExtendedSpaceSystem) – The
ExtendedSpaceSystemto be used in the XPS simulation.integrator (ExtendedSpaceIntegrator) – An
ExtendedSpaceIntegratorobject to be used for advancing the XPS simulation. Available implementations includeLockstepIntegratorfor systems where both integrators use the same step size, andSplitIntegratorfor systems with different step sizes related by an even integer ratio.platform (Platform | None) – The openmm.Platform to use for calculations.
properties (dict | None) – A dictionary of values for platform-specific properties.
Example
>>> import openxps as xps >>> from math import pi >>> import openmm >>> import cvpack >>> from openmm import unit >>> from openmmtools import testsystems >>> model = testsystems.AlanineDipeptideVacuum() >>> mass = 3 * unit.dalton*(unit.nanometer/unit.radian)**2 >>> phi0 = xps.DynamicalVariable("phi0", unit.radian, mass, xps.CircularBounds()) >>> phi = cvpack.Torsion(6, 8, 14, 16, name="phi") >>> kappa = 1000 * unit.kilojoule_per_mole / unit.radian**2 >>> harmonic_force = xps.HarmonicCoupling(phi, phi0, kappa) >>> temp = 300 * unit.kelvin >>> integrator = openmm.LangevinMiddleIntegrator( ... temp, 1 / unit.picosecond, 4 * unit.femtosecond ... ) >>> integrator.setRandomNumberSeed(1234) >>> platform = openmm.Platform.getPlatformByName("Reference") >>> context = xps.ExtendedSpaceContext( ... xps.ExtendedSpaceSystem(model.system, harmonic_force), ... xps.LockstepIntegrator(integrator), ... platform, ... ) >>> context.setPositions(model.positions) >>> context.setVelocitiesToTemperature(temp, 1234) >>> context.setDynamicalVariableValues([180 * unit.degree]) >>> context.setDynamicalVariableVelocitiesToTemperature(temp, 1234) >>> context.getIntegrator().step(100) >>> print("phi0 =", *context.getDynamicalVariableValues()) phi0 = ... rad >>> state = context.getExtensionContext().getState(getEnergy=True) >>> print("U =", state.getPotentialEnergy(), "K =", state.getKineticEnergy()) U = ... kJ/mol K = ... kJ/mol
Methods
- createCheckpoint()[source]¶
Create a checkpoint recording the current state of the Context.
This should be treated as an opaque block of binary data. See
loadCheckpoint()for more details.- Returns:
The checkpoint data
- Return type:
bytes
- getDynamicalVariableValues()[source]¶
Get the values of the dynamical variables, wrapped into their bounds.
- Returns:
The values of the dynamical variables, in the order of
ExtendedSpaceSystem.getDynamicalVariables(). They are given in MD units, whatever unit each dynamical variable was declared in.- Return type:
t.Tuple[mmunit.Quantity]
- getDynamicalVariableVelocities()[source]¶
Get the velocities of the dynamical variables.
- Returns:
The velocities of the dynamical variables, in the order of
ExtendedSpaceSystem.getDynamicalVariables(). They are given in MD units, whatever unit each dynamical variable was declared in.- Return type:
t.Tuple[mmunit.Quantity]
- getExtensionContext()[source]¶
Get a reference to the OpenMM context containing the extension system.
- Returns:
The context containing the extension system.
- Return type:
mm.Context
- getIntegrator()[source]¶
Get the integrator included in the extended phase-space context.
- Returns:
The integrator.
- Return type:
ExtendedSpaceIntegrator
- getParameter(name)[source]¶
Get the value of a global parameter of the physical or extension system.
- Parameters:
name (str) – The name of the parameter. A parameter that exists only in the extension system (e.g. a parameter of a coupling function) is read from the extension context.
- Returns:
The value of the parameter.
- Return type:
float
- getSystem()[source]¶
Get the system included in the extended phase-space context.
- Returns:
The system.
- Return type:
- loadCheckpoint(checkpoint)[source]¶
Load a checkpoint that was written by
createCheckpoint().See openmm.Context for more details.
- Parameters:
checkpoint (bytes) – The checkpoint data to load.
- reinitialize(preserveState=False)[source]¶
Reinitialize the physical context and restore the dynamical variable parameters from the extension context, whose state is always preserved.
Parameters shared by both contexts take their values from the physical context, so they are reset to their defaults when the physical state is not preserved.
- Parameters:
preserveState (bool) – Whether to preserve the state of the physical context.
- setDynamicalVariableValues(values)[source]¶
Set the values of the dynamical variables.
- Parameters:
values (Iterable[Quantity]) – The values of all dynamical variables, in the order of
ExtendedSpaceSystem.getDynamicalVariables(). As in OpenMM, a value given without units is taken in MD units (e.g. radians for angles, even if the dynamical variable was declared in degrees).
- setDynamicalVariableVelocities(velocities)[source]¶
Set the velocities of the dynamical variables.
- Parameters:
velocities (Iterable[Quantity]) – The velocities of all dynamical variables, in the order of
ExtendedSpaceSystem.getDynamicalVariables(). As in OpenMM, a velocity given without units is taken in MD units (e.g. radians per picosecond for angles).
- setDynamicalVariableVelocitiesToTemperature(temperature, seed=None)[source]¶
Set the velocities of the dynamical variables to a temperature.
- Parameters:
temperature (Quantity) – The temperature to set the velocities to.
- setParameter(name, value)[source]¶
Set the value of a global parameter defined by a Force object in the System.
Notes
Parameters that represent dynamical variables are protected and cannot be set through this method; use
setDynamicalVariableValues()instead. A parameter that exists in both systems (e.g. a coupling constant) is updated in both contexts, and one that exists only in the extension system (e.g. a parameter of a coupling function) is updated in the extension context. Both contexts are then synchronized.- Parameters:
name (str) – The name of the parameter to set.
value (Quantity) – The value of the parameter.
- setPositions(positions)[source]¶
Sets the positions of all particles in the physical system.
- Parameters:
positions (Quantity) – The positions for each particle in the system.
- setState(state)[source]¶
Set the state of the physical context and synchronize both contexts.
Parameters restored from the state that also exist in the extension system (e.g. a coupling constant) are copied to the extension context.
- Parameters:
state (State) – The openmm.State to apply to the physical context.
- synchronize()[source]¶
Push the dynamical variable values to the physical context and the collective variable values to the extension context.
Call this after changing the physical state through a channel that bypasses this class, such as an openmm.LocalEnergyMinimizer.