First SimulationΒΆ

This is a good starting point for learning how to use OpenMM.

It loads a PDB file villin.pdb, which is the villin headpiece protein in a box of water. In then parameterizes it using the Amber14 forcefield and TIP3P-FB water model, energy minimizes it, and simulates it for 1000 steps with a langevin intergator.

[1]:
from openmm.app import *
from openmm import *
from openmm.unit import *
from sys import stdout

# Load in the PDB strucure
pdb = PDBFile('villin.pdb')

# Specifiy the forcefield
forcefield = ForceField('amber14-all.xml', 'amber14/tip3pfb.xml')


# Combine the molecular topology and the forcefield
system = forcefield.createSystem(pdb.topology, nonbondedMethod=PME,
        nonbondedCutoff=1*nanometer, constraints=HBonds)

# Create the integrator to use for advacing the equations of motion.
# It specifies a Langevin integrator.
# The paramters set are temperature, friction coefficient, and timestep.
integrator = LangevinMiddleIntegrator(300*kelvin, 1/picosecond, 0.004*picoseconds)

# Combines the molecular topology, system, and integrator
# to begin a new simulation.
simulation = Simulation(pdb.topology, system, integrator)
simulation.context.setPositions(pdb.positions)

# Perform local energy minimization
print("Minimizing energy...")
simulation.minimizeEnergy(maxIterations=100)

# Write the trajectory to a file called "output.pdb"
simulation.reporters.append(PDBReporter('output.pdb', 1000))

# Report infomation to the screen as the simulation runs
simulation.reporters.append(StateDataReporter(stdout, 100, step=True,
        potentialEnergy=True, temperature=True))

#Run the simulation for 1000 timsteps
print("Running simulation...")
simulation.step(1000)
Minimizing energy...
Running simulation...
#"Step","Potential Energy (kJ/mole)","Temperature (K)"
100,-156926.17192414246,118.95764338112916
200,-152650.6469013507,179.8978827093201
300,-149589.12979993055,216.99795705038375
400,-147402.24444647052,242.4199092247939
500,-145719.9528352572,259.215780352194
600,-144685.58211562768,277.43997170424495
700,-143709.29306082262,280.8265423867712
800,-143446.90564952893,286.3067441412862
900,-142652.03878155095,288.4469241321636
1000,-142684.37538255044,289.89366667741996