Running a PyRETIS simulation with OpenMM

In this example we will show the interface between OpenMM and PyRETIS.

First we will have to generate an file with a OpenMM Simulation object. We use the online tool OpenMM Script Builder to generate the example with this pdb of 2 water molecules.

from openmm import app
import openmm as mm
from openmm import unit

pdb = app.PDBFile('input.pdb')
forcefield = app.ForceField('amber99sbildn.xml', 'tip3p.xml')

system = forcefield.createSystem(pdb.topology, nonbondedMethod=app.PME,
                                 nonbondedCutoff=1.0*unit.nanometers,
                                 constraints=app.HBonds, rigidWater=True,
                                 ewaldErrorTolerance=0.0005)
integrator = mm.LangevinIntegrator(300*unit.kelvin,
                                   1.0/unit.picoseconds,
                                   2.0*unit.femtoseconds)
integrator.setConstraintTolerance(0.00001)

# Check with "python -m simtk.testInstallation" which platforms are available
# Here I use CUDA, but CPU is more commonly available
# platform = mm.Platform.getPlatformByName('CPU')
platform = mm.Platform.getPlatformByName('CUDA')
simulation = app.Simulation(pdb.topology, system, integrator, platform)
simulation.context.setPositions(pdb.positions)

With this simulation object we can now construct the needed rst options in the engine section:

Engine
------
type = openmm
class = openmm
openmm_simulation = simulation
openmm_module = openmm_sim.py
subcycles = 10
Here we say that:
  • The engine type is openmm, to tell PyRETIS it is has a special system representation.
  • The engine class is also openmm to tell PyRETIS we want to use the OpenMM engine.
  • The openmm_module where we want to load the simulation from, here it is openmm_sim.py.
  • And the name of the openmm_simulation object in that file, in this case simulation.

Finally we give the number of subcycles, which indicates how many MD-steps OpenMM does before we ask for another frame. This should be relatively high when using GPUs, as it dictates how often we have to communicate with the GPU. However, keep in mind that this also lowers the time-resolution of your PyRETIS simulation.

After this, it is run as a regular PyRETIS simulation, using pyretisrun

pyretisrun -i openmm_retis.rst -p