/group/ag_cmb/software
on the local machines, cuda01, and allegro
/import/ag_cmb/software
on cuda02, cuda03, and allegro
module load compiler/4.6.3 openmm/5.1
or
module load compiler/4.6.3 openmm/gitPlease not that the compiler/4.6.3 module is mandatory since CUDA requires a gcc compiler version <= 4.6.x!
The general idea is to tie one simulation object to one GPU and wrap calls to simulation.step in separate threads.
state = simulation.context.getState(getPositions=True, getVelocities=True) n_forces = len(system.getForces()) # assume that the Barostat was last force that I added system.removeForce(n_forces-1) simulation.context.reinitialize() simulation.context.setState(state)
import MDAnalysis from simtk.unit import *Next you have to subclass the Timestep class of MDAnalysis. This class will act as a hinge between MDAnalysis and OpenMM. Each instance of Timestep must provide the properties numatoms, frame, _unitcell and _pos. For every frame that we want to save, a new instance of Timestep will be generated (see below) so we can just pass in all the data via init.
class MyTimestep(MDAnalysis.coordinates.base.Timestep): def __init__(self,numatoms,frame_number,positions,boxvectors): self.numatoms = numatoms self.frame = frame_number boxvectors /= angstroms self._unitcell = (boxvectors[0,0],90.0,boxvectors[1,1],90.0,90.0,boxvectors[2,2]) positions /= angstroms self._pos = positions.astype(numpy.float32)The actual writing is done by the MDAnalysis.Writer class. Before we can write any frames, we need to make an instance of it. The only parameter is the output file name.
writer = MDAnalysis.Writer('trajectory.xtc')When you have set your OpenMM simulation, you can read the current frame with the getState method. Then it is easy to write this frame to the xtc file. Just extract all the data from OpenMM's state object, make an instance of MyTimestep thats holds the data and instruct the writer class to write this frame to disk.
state = simulation.context.getState(getPositions=True,enforcePeriodicBox=True) x = state.getPositions(asNumpy=True) box = state.getPeriodicBoxVectors(asNumpy=True) natoms = x.shape[0] step = MyTimestep(natoms,simulation.currentStep,x,box) writer.write(step)