This enables OPS to use any testsystem from openmmtools to be used as well as add ANY possible OpenMM setup, not just the ones that we provided before. The old OpenMMEngine has been rename intp SimpleOpenMMEngine
In [1]:
from __future__ import print_function
import openpathsampling as paths
import openmmtools as omt
import simtk.openmm as omm
import simtk.unit as u
import mdtraj as md
import openpathsampling.engines.openmm as eng
Create Alanine in Vacuum and run it using OPS.
In [2]:
testsystem = omt.testsystems.AlanineDipeptideVacuum()
Let's have a look at the content
In [3]:
#! skip
{ key: type(value) for key, value in testsystem.__dict__.items()}
Out[3]:
An OpenMM
simulation in OPS needs 3 ingredients to function
In the following we will get these parts.
The information for the template is contained in the _topology
and the _positions
object.
In [4]:
template = eng.snapshot_from_testsystem(testsystem)
This is easy since we directly get it from the testsytem objects
In [5]:
system = testsystem.system
The openmmtools system is (almost) independent of the integrator and openmm
provides us with lots of options. For now we pick something simple.
In [6]:
integrator = omm.VerletIntegrator(
0.002 * u.picoseconds
)
build the engine
In [7]:
engine = eng.Engine(
template.topology,
system,
integrator)
Let's run a simulation of 10 steps.
In [8]:
traj = engine.generate(template, [paths.LengthEnsemble(10).can_append])
In [9]:
assert len(traj) == 10
In [10]:
#! skip
print(traj[5].coordinates)
In [11]:
psi = md.compute_psi(traj.to_mdtraj())
In [12]:
#! ignore
psi[1][3:8]
Out[12]:
In [13]:
st = paths.Storage('engine_store_test.nc', mode='w')
In [14]:
st.engines.save(engine);
st.tag['template'] = template
The engine is stored by using the XML serialization of OpenMM and put this into the storage.
In [15]:
#! skip
st.variables['engines_json'][0][0:256] + '...'
Out[15]:
In [16]:
st.save(traj);
In [17]:
st.close()
In [18]:
st = paths.AnalysisStorage('engine_store_test.nc')
In [19]:
engine = st.engines[0]
Run another 10 steps to test
In [20]:
template = st.tag['template']
In [21]:
traj = engine.generate(template, [paths.LengthEnsemble(10).can_append])
In [22]:
print(traj)
In [23]:
st.close()
And save the trajectory for future use (other tests)
In [24]:
st = paths.Storage('engine_store_test.nc', "a")
st.save(traj)
st.close()
In [ ]: