ExtensionWriter

class openxps.ExtensionWriter(*, kinetic=False, temperature=False, dynamical_variables=False, forces=False, collective_variables=False, effective_masses=False, coupling_functions=False)[source]

A custom writer for reporting state data from an extension context.

This writer can be used with cvpack.reporting.StateDataReporter to report various properties of the extension context in an extended phase-space simulation. The extension context contains the dynamical variables and their associated properties.

Parameters:
  • kinetic (bool, optional, default=False) – If True, the kinetic energy of the dynamical variables will be reported in units of kJ/mol. If the extension integrator is a RegulatedNHLIntegrator, its regulated kinetic energy is reported instead, so that equipartition holds for the reported temperature.

  • temperature (bool, optional, default=False) – If True, the temperature of the dynamical variables, with one degree of freedom per variable, will be reported in units of Kelvin.

  • dynamical_variables (bool, optional, default=False) – If True, the current values of all dynamical variables will be reported. Each variable will be reported with its name and unit.

  • forces (bool, optional, default=False) – If True, the forces acting on each dynamical variable will be reported in units of kJ/(mol*unit), where unit is the unit of the corresponding dynamical variable.

  • collective_variables (bool, optional, default=False) – If True, the current values of collective variables that are part of collective variable couplings will be reported.

  • effective_masses (bool, optional, default=False) – If True, the effective masses of collective variables from coupling forces will be reported in units of dalton*(nanometer/unit)^2, where unit is the unit of the corresponding collective variable.

  • coupling_functions (bool, optional, default=False) – If True, the current values of functions in inner product couplings will be reported.

Example

>>> import openxps as xps
>>> from sys import stdout
>>> 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.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)
>>> platform = openmm.Platform.getPlatformByName("Reference")
>>> simulation = xps.ExtendedSpaceSimulation(
...     model.topology,
...     xps.ExtendedSpaceSystem(model.system, harmonic_force),
...     xps.LockstepIntegrator(integrator),
...     platform
... )
>>> 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
... )
>>> reporter = cvpack.reporting.StateDataReporter(
...     stdout,
...     10,
...     step=True,
...     kineticEnergy=True,
...     writers=[xps.ExtensionWriter(
...         kinetic=True,
...         temperature=True,
...         dynamical_variables=True
...     )],
... )
>>> simulation.reporters.append(reporter)
>>> simulation.step(100)
#"Step","Kinetic Energy (kJ/mole)","Extension Kinetic Energy (kJ/mole)",    "Extension Temperature (K)","phi0 (rad)"
10,60.512...,1.7013...,123.456...,3.1415...

Methods

getCollectiveVariableHeaders()[source]

Get the headers for all collective variables.

Returns:

The headers for all collective variables.

Return type:

list[str]

getDynamicalVariableHeaders()[source]

Get the headers for all dynamical variables.

Returns:

The headers for all dynamical variables.

Return type:

list[str]

getEffectiveMassHeaders()[source]

Get the headers for all effective masses.

Returns:

The headers for all effective masses.

Return type:

list[str]

getForceHeaders()[source]

Get the header for the force on a dynamical variable.

Returns:

The headers for all forces.

Return type:

list[str]

getHeaders()[source]

Gets a list of strigs containing the headers to be added to the report.

Return type:

list[str]

getValues(simulation)[source]

Gets a list of floats containing the values to be added to the report.

Parameters:

simulation (ExtendedSpaceSimulation) – The simulation object.

Return type:

list[float]

initialize(simulation)[source]

Initializes the writer. This method is called before the first report and can be used to perform any necessary setup.

Parameters:

simulation (ExtendedSpaceSimulation) – The simulation object.