ExtendedSpaceSimulation

class openxps.ExtendedSpaceSimulation(topology, system, integrator, platform=None, platformProperties=None, state=None)[source]

A openmm.Simulation object that uses an ExtendedSpaceContext to enable extended phase-space (XPS) simulations with dynamical variables.

This class extends openmm.Simulation to seamlessly integrate extended phase-space capabilities by creating an ExtendedSpaceContext instead of a standard openmm.Context. All other functionality is inherited from the base class.

Note: The system and integrator provided as arguments are modified in place.

Parameters:
  • topology (Topology) – The openmm.Topology describing the system to be simulated.

  • system (ExtendedSpaceSystem) – The ExtendedSpaceSystem object to simulate.

  • integrator (ExtendedSpaceIntegrator) – An ExtendedSpaceIntegrator object to be used for advancing the XPS simulation. Available implementations include LockstepIntegrator for systems where both integrators use the same step size, and SplitIntegrator for systems with different step sizes related by an even integer ratio.

  • platform (Platform | None) – The openmm.Platform to use for calculations. If None, the default Platform will be used.

  • platformProperties (dict | None) – A dictionary of platform-specific properties. If None, the default properties will be used.

  • state (State | str | PathLike | None) – If specified, either an openmm.State object or the name or path of a file written by saveState(), from which the simulation state is set after initialization.

Example

>>> import openxps as xps
>>> from math import pi
>>> import cvpack
>>> import openmm
>>> 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.kilojoules_per_mole / unit.radian**2
>>> harmonic_force = xps.HarmonicCoupling(phi, phi0, kappa)
>>> integrator = openmm.LangevinMiddleIntegrator(
...     300 * unit.kelvin, 1 / unit.picosecond, 4 * unit.femtosecond
... )
>>> integrator.setRandomNumberSeed(1234)
>>> simulation = xps.ExtendedSpaceSimulation(
...     model.topology,
...     xps.ExtendedSpaceSystem(model.system, harmonic_force),
...     xps.LockstepIntegrator(integrator),
...     openmm.Platform.getPlatformByName("Reference"),
... )
>>> simulation.context.setPositions(model.positions)
>>> simulation.context.setVelocitiesToTemperature(300 * unit.kelvin, 1234)
>>> simulation.context.setDynamicalVariableValues([180 * unit.degree])
>>> simulation.context.setDynamicalVariableVelocitiesToTemperature(
...     300 * unit.kelvin, 1234
... )
>>> simulation.step(100)
>>> print("phi0 =", *simulation.context.getDynamicalVariableValues())
phi0 = ... rad

Methods

loadState(file)[source]

Load the states written by saveState() and synchronize the contexts.

Parameters:

file (str | PathLike | IO) – A file name or path, or a file object open in text or binary mode.

minimizeEnergy(*args, **kwargs)[source]

Minimize the energy of the physical system and synchronize the extension context. Arguments are those of openmm.Simulation.

saveState(file)[source]

Save the states of the physical and extension contexts to a file.

Parameters:

file (str | PathLike | IO) – A file name or path, or a file object open in text or binary mode.