Using ParmEd with MDAnalysis and OpenMM to simulate a selection of atoms¶
Here we use MDAnalysis to convert a ParmEd structure to an MDAnalysis Universe, select a subset of atoms, and convert it back to ParmEd to simulate with OpenMM.
Last executed: Dec 27, 2020 with MDAnalysis 1.0.0
Last updated: January 2020
Minimum version of MDAnalysis: 1.0.0
Packages required:
[1]:
import parmed as pmd
import MDAnalysis as mda
from MDAnalysis.tests.datafiles import PRM7_ala2, RST7_ala2
Loading files: the difference between ParmEd and MDAnalysis¶
Both ParmEd and MDAnalysis read a number of file formats. However, while MDAnalysis is typically used to analyse simulations, ParmEd is often used to set them up. This requires ParmEd to read topology parameter information that MDAnalysis typically ignores, such as the equilibrium length and force constants of bonds in the system. For example, the ParmEd structure below.
[2]:
pprm = pmd.load_file(PRM7_ala2, RST7_ala2)
pprm
[2]:
<AmberParm 3026 atoms; 1003 residues; 3025 bonds; PBC (orthogonal); parametrized>
[3]:
pprm.bonds[0]
[3]:
<Bond <Atom C [10]; In ALA 0>--<Atom O [11]; In ALA 0>; type=<BondType; k=570.000, req=1.229>>
When MDAnalysis reads these files in, it does not include that information.
[4]:
mprm = mda.Universe(PRM7_ala2, RST7_ala2, format='RESTRT')
mprm
[4]:
<Universe with 3026 atoms>
The bond type simply shows the atom types involved in the connection.
[5]:
mprm.atoms.bonds[0].type
[5]:
('N3', 'H')
If you then convert this Universe to ParmEd, you can see that the resulting Structure is not parametrized
.
[6]:
mprm_converted = mprm.atoms.convert_to('PARMED')
mprm_converted
[6]:
<Structure 3026 atoms; 1003 residues; 3025 bonds; PBC (triclinic); NOT parametrized>
While the bonds are present, there is no type
information associated.
[7]:
mprm_converted.bonds[0]
[7]:
<Bond <Atom N [0]; In ALA 0>--<Atom H1 [1]; In ALA 0>; type=None>
Therefore, if you wish to use ParmEd functionality that requires parametrization on a MDAnalysis Universe, you need to create that Universe from a ParmEd structure in order to convert it back to something useable in ParmEd.
[8]:
mprm_from_parmed = mda.Universe(pprm)
mprm_from_parmed
[8]:
<Universe with 3026 atoms>
Now the bond type is actually a ParmEd Bond object.
[9]:
mprm_from_parmed.bonds[0].type
[9]:
<Bond <Atom N [0]; In ALA 0>--<Atom H1 [1]; In ALA 0>; type=<BondType; k=434.000, req=1.010>>
Using MDAnalysis to select atoms¶
One reason we might want to convert a ParmEd structure into MDAnalysis is to use its sophisticated atom selection syntax. While ParmEd has its own ways to select atoms, MDAnalysis allows you to select atoms based on geometric distance.
[10]:
water = mprm_from_parmed.select_atoms('around 5 protein').residues.atoms
protein_shell = mprm_from_parmed.select_atoms('protein') + water
prm_protein_shell = protein_shell.convert_to('PARMED')
[11]:
prm_protein_shell
[11]:
<Structure 155 atoms; 46 residues; 154 bonds; PBC (orthogonal); parametrized>
Using ParmEd and OpenMM to create a simulation system¶
[12]:
import sys
import simtk.openmm as mm
import simtk.openmm.app as app
from parmed import unit as u
from parmed.openmm import StateDataReporter, MdcrdReporter
You can create an OpenMM simulation system directly from a ParmEd structure, providing that it is parametrized.
[13]:
system = prm_protein_shell.createSystem(nonbondedMethod=app.NoCutoff,
constraints=app.HBonds,
implicitSolvent=app.GBn2)
Here we set the integrator to do Langevin dynamics.
[14]:
integrator = mm.LangevinIntegrator(
300*u.kelvin, # Temperature of heat bath
1.0/u.picoseconds, # Friction coefficient
2.0*u.femtoseconds, # Time step
)
We create the Simulation object and set particle positions.
[15]:
sim = app.Simulation(prm_protein_shell.topology, system, integrator)
sim.context.setPositions(prm_protein_shell.positions)
We now minimise the energy.
[16]:
sim.minimizeEnergy(maxIterations=500)
The reporter below reports energies and coordinates every 100 steps to stdout, but every 10 steps to the ala2_shell.nc
file.
[17]:
sim.reporters.append(
StateDataReporter(sys.stdout, 100, step=True, potentialEnergy=True,
kineticEnergy=True, temperature=True, volume=True,
density=True)
)
sim.reporters.append(MdcrdReporter('ala2_shell.trj', 10, crds=True))
We can run dynamics for 500 steps (1 picosecond).
[18]:
sim.step(500)
#"Step","Time (ps)","Potential Energy (kilocalorie/mole)","Kinetic Energy (kilocalorie/mole)","Total Energy (kilocalorie/mole)","Temperature (K)","Box Volume (angstrom**3)","Density (gram/(item*milliliter))"
100,0.20000000000000015,-623.3492499327796,19.803327793076484,-603.5459221397031,62.675606124245874,45325.80641910621,0.03490935070036196
200,0.4000000000000003,-611.0055606178298,33.20984569525998,-577.7957149225698,105.10593118449512,45325.80641910621,0.03490935070036196
300,0.6000000000000004,-606.1388529965344,51.26908103744882,-554.8697719590856,162.26165435582024,45325.80641910621,0.03490935070036196
400,0.8000000000000006,-601.3819619756812,56.01401743345518,-545.3679445422259,177.27891649217017,45325.80641910621,0.03490935070036196
500,1.0000000000000007,-606.1466720318475,76.01105805061736,-530.1356139812301,240.56760486150492,45325.80641910621,0.03490935070036196
If we write a topology file out from our former protein_shell
atomgroup, we can load the trajectory in for further analysis.
[19]:
protein_shell.write('ala2_shell.pdb')
u = mda.Universe('ala2_shell.pdb', 'ala2_shell.trj')
u.trajectory
[19]:
<TRJReader ala2_shell.trj with 50 frames of 155 atoms>
[1] R. J. Gowers, M. Linke, J. Barnoud, T. J. E. Reddy, M. N. Melo, S. L. Seyler, D. L. Dotson, J. Domanski, S. Buchoux, I. M. Kenney, and O. Beckstein. MDAnalysis: A Python package for the rapid analysis of molecular dynamics simulations. In S. Benthall and S. Rostrup, editors, Proceedings of the 15th Python in Science Conference, pages 98-105, Austin, TX, 2016. SciPy, doi: 10.25080/majora-629e541a-00e.
[2] N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein. MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. J. Comput. Chem. 32 (2011), 2319-2327, doi:10.1002/jcc.21787. PMCID:PMC3144279
[3] Peter Eastman, Jason Swails, John D. Chodera, Robert T. McGibbon, Yutong Zhao, Kyle A. Beauchamp, Lee-Ping Wang, Andrew C. Simmonett, Matthew P. Harrigan, Chaya D. Stern, Rafal P. Wiewiora, Bernard R. Brooks, Vijay S. Pande. OpenMM 7: Rapid Development of High Performance Algorithms for Molecular Dynamics. PLoS Comput. Biol. 13:e1005659, 2017.
[4] Hai Nguyen, David A Case, Alexander S Rose. NGLview - Interactive molecular graphics for Jupyter notebooks. Bioinformatics. 34 (2018), 1241–1242, doi:10.1093/bioinformatics/btx789