forked from rmcgibbo/openmm-pulling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenmm.py
83 lines (56 loc) · 2.46 KB
/
openmm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
##########################################################################
# this script was generated by openmm-builder. to customize it further,
# you can save the file to disk and edit it with your favorite editor.
##########################################################################
#from __future__ import print_function
from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *
from sys import stdout
from openmmtools.elongationreporter import ElongationReporter
from openmmtools.pullingforcewrapper import PullingForceWrapper
from openmmtools.chacoreporter import ChacoReporter
import threading
import numpy as np
import IPython as ip
##############################################################################
timestep = 2.0*femtoseconds
elongation_factor = 8.0
n_steps = 500000
n_intervals = 25
class AwesomeReporter(ChacoReporter, ElongationReporter):
pass
##############################################################################
pdb = PDBFile('input.pdb')
forcefield = ForceField('amber99sb.xml')
system = forcefield.createSystem(pdb.topology, nonbondedMethod=CutoffNonPeriodic,
constraints=HBonds, rigidWater=True, nonbondedCutoff=1.0*nanometers)
integrator = LangevinIntegrator(300*kelvin, 91.0/picoseconds, timestep)
integrator.setConstraintTolerance(0.0001)
pullingforce = PullingForceWrapper(pdb=pdb)
pullingforce.add_to_system(system)
platform = Platform.getPlatformByName('Reference')
simulation = Simulation(pdb.topology, system, integrator, platform)
simulation.context.setPositions(pdb.positions)
print 'Minimizing...'
simulation.minimizeEnergy()
simulation.context.setVelocitiesToTemperature(300*kelvin)
print 'Equilibrating...'
simulation.step(100)
simulation.reporters.append(DCDReporter('pulling.dcd', 100))
reporter = AwesomeReporter(stdout, 500, pullingforce.atom1, pullingforce.atom2,
temperature=True, time=True, totalEnergy=True)
simulation.reporters.append(reporter)
total_time = n_steps * timestep
print 'Going for', total_time.in_units_of(picoseconds)
initial_r0 = pullingforce.get_r0()
final_r0 = elongation_factor * pullingforce.get_r0()
print 'PULLING RATE', ((final_r0 - initial_r0) / total_time).in_units_of(nanometer/nanosecond)
def run():
for i, r0 in enumerate(np.linspace(initial_r0, final_r0, n_intervals)):
pullingforce.set_r0(r0, simulation.context)
simulation.step(n_steps / n_intervals)
t = threading.Thread(target=run)
t.daemon = True
t.start()
reporter.configure_traits()