narupa.openmm.runner module

Facilities to run an OpenMM simulation.

class narupa.openmm.runner.OpenMMRunner(simulation: pretends.Simulation, name: Optional[str] = None, address: Optional[str] = None, port: Optional[int] = None)

Bases: narupa.app.runner.NarupaRunner

Convenience class to run an OpenMM simulation.

A Runner object wraps an OpenMM simulation. The app.Simulation instance is accessible via the simulation attribute.

Actually starting the simulation is done with the run() method. The method takes an number of steps to run as an argument; by default, the simulation runs indefinitely.

By default, one frame is sent to clients every 5 MD steps. This rate can be changed by setting the frame_interval attribute. By default, as well, the dynamics is throttled to send 30 frames per seconds (therefore running 150 MD steps per second). This rate can be changed by setting the target interval between frames in seconds with the dynamics_interval attribute. Setting the interval to 0 causes the dynamics to not be throttled.

The verbosity can be adjusted by setting the verbose attribute, or by using the make_verbose() and make_quiet() methods.

Parameters:
app
app_server

Get the underlying app of the runner.

cancel_run(wait: bool = False) → None

Cancel molecular dynamics that is running on a background thread.

Parameters:wait – Whether to block and wait for the molecular dynamics to halt before returning.
close()

Closes the connection and stops the dynamics.

dynamics_interval

Minimum interval, in seconds, between frames sent to the frame publisher.

force_interval

Update iMD interactions every N steps.

frame_interval

Send a frame every N steps.

classmethod from_xml_input(input_xml: Union[str, bytes, os.PathLike], name: Optional[str] = None, address: Optional[str] = None, port: Optional[int] = None) → RunnerClass

Create a runner from a serialized simulation.

Parameters:
  • input_xml – Path to an XML serialised OpenMM simulation.
  • name – A friendly name for the runner. It will be displayed by ESSD.
  • address – The IP address the server binds to.
  • port – The port the server listens to.
Returns:

An instance of the class.

See also

The XML serialized simulation can be produced by narupa.openmm.serializer.serialize_simulation().

is_running

Whether or not the molecular dynamics is currently running on a background thread or not. :return: True, if molecular dynamics is running, False otherwise.

make_quiet() → None

Detach the verbosity reporter if it is attached.

See also

make_verbose()

make_verbose() → None

Attach a verbosity reporter if it is not already attached.

The verbosity reporter reports the step number, the potential energy in kJ/mol, and the simulation speed in ns/day. This report is displayed every 10 simulation steps.

See also

The make_quiet() method removes the verbosity reporter.

pause()

Pause the simulation, by cancelling any current run.

This method is called whenever a client runs the pause command, described in :mod:narupa.trajectory.frame_server.

play()

Run the simulation indefinitely

Cancels any current run and then begins running the simulation on a background thread.

This method is called whenever a client runs the play command, described in :mod:narupa.trajectory.frame_server.

reset()
run(steps: Optional[int] = None, block: Optional[bool] = None) → None

Runs the molecular dynamics.

Parameters:
  • steps – If passed, will run the given number of steps, otherwise will run forever on a background thread and immediately return.
  • block – If False, run in a separate thread. By default, “block” is None, which means it is automatically set to True if a number of steps is provided and to False otherwise.
step()

Take a single step of the simulation and stop.

This method is called whenever a client runs the step command, described in :mod:narupa.trajectory.frame_server.

verbose

Returns True if the verbosity reporter is attached.

verbosity_interval

Display the verbosity report every N steps.

If the runner is not verbose, then the verbosity interval is 0. Same wise, if this interval is set to 0, then the runner is made quiet.