Running a simulation in OpenMMΒΆ

simulation-with-openmm_evaluated
In [1]:
# In this example, we'e going to actually run a short simulation with OpenMM
# saving the results to disk with MDTraj's HDF5 reporter

# Obviously, running this example calculation on your machine requires
# having OpenMM installed. OpenMM can be downloaded and installed from
# https://simtk.org/home/openmm.
In [2]:
# Lets import some things we're going to need from mdtraj

import os
import mdtraj
import mdtraj.reporters

# And a few things froms OpenMM

from simtk import unit
import simtk.openmm as mm
from simtk.openmm import app
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-2-24d2e9abdc06> in <module>()
      8 
      9 from simtk import unit
---> 10 import simtk.openmm as mm
     11 from simtk.openmm import app

/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/__init__.py in <module>()
     11 
     12 import os, os.path
---> 13 from simtk.openmm.openmm import *
     14 from simtk.openmm.vec3 import Vec3
     15 from simtk.openmm import version

/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/openmm.py in <module>()
     38                 fp.close()
     39             return _mod
---> 40     _openmm = swig_import_helper()
     41     del swig_import_helper
     42 else:

/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/openmm.py in swig_import_helper()
     34         if fp is not None:
     35             try:
---> 36                 _mod = imp.load_module('_openmm', fp, pathname, description)
     37             finally:
     38                 fp.close()

ImportError: dlopen(/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/_openmm.so, 2): Library not loaded: @rpath/libOpenMM.dylib
  Referenced from: /Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/_openmm.so
  Reason: image not found
In [3]:
# First, lets find a PDB for alanine dipeptide, the system we'll
# be simulating. We happen to have one inlcuded in the mdtraj
# package for testing named "native.pdb". Under normal circumstances
# circumstances, you shouldn't have much need for mdtraj.testing.get_fn
# (unless you're contributing tests to mdtraj!)

import mdtraj.testing
pdb = mdtraj.load(mdtraj.testing.get_fn('native.pdb'))
topology = pdb.topology.to_openmm()

# Lets use the amber99sb-ildn forcefield with implicit solvent
# and a langevin integrator. This is relatively "standard" OpenMM
# code for setting up a system.

forcefield = app.ForceField('amber99sbildn.xml', 'amber99_obc.xml')
system = forcefield.createSystem(topology, nonbondedMethod=app.CutoffNonPeriodic)
integrator = mm.LangevinIntegrator(330*unit.kelvin, 1.0/unit.picoseconds, 2.0*unit.femtoseconds)
simulation = app.Simulation(topology, system, integrator)

# Set the initial positions to the "first frame" of the PDB
# file (it only has one frame). Note that pdb is an mdtraj trajectory
# pass in its positions to OpenMM just fine though.

simulation.context.setPositions(pdb.xyz[0])
simulation.context.setVelocitiesToTemperature(330*unit.kelvin)

##################################################################################

The code at topology.py:261 requires the simtk.openmm.app module, which is
the python OpenMM application layer. OpenMM is a toolkit for molecular simulation
using high performance GPU code.

simtk.openmm.app is installed with OpenMM, which is available at http://openmm.org

##################################################################################

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-3-39910b10e34a> in <module>()
      7 import mdtraj.testing
      8 pdb = mdtraj.load(mdtraj.testing.get_fn('native.pdb'))
----> 9 topology = pdb.topology.to_openmm()
     10 
     11 # Lets use the amber99sb-ildn forcefield with implicit solvent

/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/mdtraj-0.8.0-py2.7-macosx-10.5-x86_64.egg/mdtraj/core/topology.pyc in to_openmm(self)
    259            This topology, as an OpenMM topology
    260         """
--> 261         app = import_('simtk.openmm.app')
    262 
    263         out = app.Topology()

/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/mdtraj-0.8.0-py2.7-macosx-10.5-x86_64.egg/mdtraj/utils/delay_import.pyc in import_(module)
    191         print(m, file=sys.stderr)
    192         print(bar, file=sys.stderr)
--> 193         raise e

ImportError: dlopen(/Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/_openmm.so, 2): Library not loaded: @rpath/libOpenMM.dylib
  Referenced from: /Users/rmcgibbo/miniconda/envs/2.7.9/lib/python2.7/site-packages/simtk/openmm/_openmm.so
  Reason: image not found
In [4]:
# Let's use one of the OpenMM reporters that mdtraj provides. This is
# the hdf5 reporter, which saves all kinds of information, including
# the topology, positions, energies, etc to disk. To visualize the h5
# trajectory with a non-hdf5 enabled app like PyMol or VMD, you can
# use mdconvert on the command line to easily transform it to NetCDF, DCD,
# or any other format of your preference.

if not os.path.exists('ala2.h5'):
    simulation.reporters.append(mdtraj.reporters.HDF5Reporter('ala2.h5', 1000))
    simulation.step(100000)
In [5]:
 

(simulation-with-openmm.ipynb; simulation-with-openmm_evaluated.ipynb; simulation-with-openmm.py)

Versions