-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenmm_minim.py
More file actions
executable file
·145 lines (130 loc) · 5.62 KB
/
Copy pathopenmm_minim.py
File metadata and controls
executable file
·145 lines (130 loc) · 5.62 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#!/usr/bin/python
from simtk.openmm.app import *
from simtk.openmm import *
from simtk.unit import *
from sys import stdout
class files():
inpdb = sys.argv[1]
minimize = 'minimize.pdb'
traj = 'traj.pdb'
mdlog = 'md.log'
lastframe = 'finished.pdb'
restart = 'checkpoint.restart'
error = 'error_save.pdb'
F = files()
class parameters():
box_buffer = 1.0*nanometer # when there is no box information in PDB file, the script will generate one ,here the buffer size
nsteps = 500 * 1000
stepsize = 0.002*picoseconds
nsavetraj = 100
ndatareprot = 100
T = 300*kelvin
P = 1*bar
forcefield = 'amber99sb.xml' # 'amber99sb.xml' #'amber99sb.xml'
watermodel = 'tip3p.xml' #None #'tip3p.xml'
nonbondedMethod = PME
nonbondedCutoff = 1*nanometer
constraints = HBonds
rigidWater = True
removeCMMotion = True
frictionCoeff = 1/picosecond
platform = 'CUDA'
FLAG_PRESSURE_COUPLING = True
FLAG_POSRES_HEAVY = True
FLAG_MINIM = True
FLAG_MD = False
P = parameters()
class global_variable():
pdb = None
system = None
integrator = None
forcefield = None
simulation = None
G = global_variable()
########################################################
#### Input pdb ####
########################################################
G.pdb = PDBFile(F.inpdb)
###### If pdb file do not contain a vector of box parameters
if G.pdb.topology.getUnitCellDimensions() == None:
xmin = min([x[0] for x in G.pdb.positions])
xmax = max([x[0] for x in G.pdb.positions])
ymin = min([x[1] for x in G.pdb.positions])
ymax = max([x[1] for x in G.pdb.positions])
zmin = min([x[2] for x in G.pdb.positions])
zmax = max([x[2] for x in G.pdb.positions])
a = xmax - xmin + 2 * P.box_buffer
b = ymax - ymin + 2 * P.box_buffer
c = zmax - zmin + 2 * P.box_buffer
dimension = Quantity( (a,b,c) )
G.pdb.topology.setUnitCellDimensions( dimension )
else:
pass
########################################################
#### Intergrator ####
########################################################
if True:
G.integrator = LangevinIntegrator(P.T, P.frictionCoeff, P.stepsize)
########################################################
#### System and force field ####
########################################################
if True:
####### System and Force field
if P.watermodel != None:
G.forcefield = ForceField(P.forcefield,P.watermodel)
else:
G.forcefield = ForceField(P.forcefield)
G.system = G.forcefield.createSystem(G.pdb.topology,
nonbondedMethod = P.nonbondedMethod,
nonbondedCutoff = P.nonbondedCutoff,
constraints = P.constraints,
rigidWater = P.rigidWater ,
removeCMMotion = P.removeCMMotion )
####### Position Restraint
if P.FLAG_POSRES_HEAVY :
harmonic_force_str = '1000.0*( (x-x0)*(x-x0) + (y-y0)*(y-y0) + (z-z0)*(z-z0) )'
restr_force = CustomExternalForce(harmonic_force_str)
restr_force.addPerParticleParameter('x0')
restr_force.addPerParticleParameter('y0')
restr_force.addPerParticleParameter('z0')
atoms = G.pdb.topology.atoms()
restr_list = [ x.index for x in atoms
if x.residue.name not in ('HOH','SOL','WAT')
and x.element.symbol!='H' ]
for i in restr_list:
restr_force.addParticle(i,G.pdb.positions[i])
G.system.addForce(restr_force)
####### pressure coupling
if P.FLAG_PRESSURE_COUPLING :
G.system.addForce(MonteCarloBarostat(P.P, P.T))
########################################################
#### Simulation ####
########################################################
if True :
platform = Platform.getPlatformByName(P.platform)
G.simulation = Simulation(G.pdb.topology, G.system, G.integrator, platform)
G.simulation.context.setPositions(G.pdb.positions)
####### Minimization
if P.FLAG_MINIM :
G.simulation.minimizeEnergy()
positions = G.simulation.context.getState(getPositions=True).getPositions()
PDBFile.writeFile(G.simulation.topology, positions, open(F.minimize, 'w'))
####### Molecular dynamics
elif P.FLAG_MD :
pdbreporter = PDBReporter(F.traj,P.nsavetraj)
G.simulation.reporters.append(pdbreporter)
statedatareporter = StateDataReporter(F.mdlog, P.ndatareprot, step=True, time =True, potentialEnergy=True,
kineticEnergy=True, totalEnergy=True, temperature =True,
volume=True, density =True, speed =True,
separator= ',', systemMass =None, totalSteps =None )
G.simulation.reporters.append(statedatareporter)
try:
G.simulation.step(P.nsteps)
except:
f = open(F.restart,'w')
f.write(G.simulation.context.createCheckpoint())
positions = G.simulation.context.getState(getPositions=True).getPositions()
PDBFile.writeFile(G.simulation.topology, positions, open(F.error, 'w'))
positions = G.simulation.context.getState(getPositions=True).getPositions()
PDBFile.writeFile(G.simulation.topology, positions, open(F.lastframe, 'w'))
print('Done')