-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScript_run_c2.py
More file actions
429 lines (350 loc) · 11.4 KB
/
Script_run_c2.py
File metadata and controls
429 lines (350 loc) · 11.4 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# Test Script to import PhysNet as energy function in CHARMM via PyCHARMM
# Basics
import os
import sys
import ctypes
import pandas
import numpy as np
# ASE
from ase import Atoms
from ase import io
import ase.units as units
# PyCHARMM
import pycharmm
import pycharmm.generate as gen
import pycharmm.ic as ic
import pycharmm.coor as coor
import pycharmm.energy as energy
import pycharmm.dynamics as dyn
import pycharmm.nbonds as nbonds
import pycharmm.minimize as minimize
import pycharmm.crystal as crystal
import pycharmm.image as image
import pycharmm.psf as psf
import pycharmm.read as read
import pycharmm.write as write
import pycharmm.settings as settings
import pycharmm.lingo as stream
import pycharmm.select as select
import pycharmm.shake as shake
import pycharmm.cons_fix as cons_fix
import pycharmm.cons_harm as cons_harm
from pycharmm.lib import charmm as libcharmm
import pycharmm.lib as lib
# Step 0: Load parameter files
#-----------------------------------------------------------
# Residue and classical force field parameter
rtf_fn = "top_all22_prot_c2.inp"
read.rtf(rtf_fn)
prm_fn = "par_all22_prot_c2.inp"
read.prm(prm_fn)
settings.set_bomb_level(-2)
settings.set_warn_level(-1)
# Step 1: Read System
#-----------------------------------------------------------
stream.charmm_script('set name bulk_c2')
name = 'bulk_c2'
stream.charmm_script('set num 1')
num = '1'
psf_fn = "bulk_c2.psf"
read.psf_card(psf_fn)
coor_fn = "bulk_c2.cor"
read.coor_card(coor_fn, flex=True)
# Save system pdb files
write.coor_pdb("init_bulk_c2.pdb")
# Step 2: Set CHARMM Properties
#-----------------------------------------------------------
# Non-bonding parameter
dict_nbonds = {
'atom': True,
'vdw': True,
'vswitch': True,
'cutnb': 14,
'ctofnb': 12,
'ctonnb': 10,
'cutim': 14,
'lrc': True,
'inbfrq': -1,
'imgfrq': -1
}
nbond = pycharmm.NonBondedScript(**dict_nbonds)
nbond.run()
# Custom energy
energy.show()
# PBC box
stats = coor.stat()
size = ( stats['xmax'] - stats['xmin']\
+ stats['ymax'] - stats['ymin']\
+ stats['zmax'] - stats['zmin'] ) / 3
crystal.define_cubic(length=(size + 1.0))
crystal.build(cutoff=14.0)
stream.charmm_script('image byres xcen 0.0 ycen 0.0 zcen 0.0 sele all end')
#constraints
#shake.on(bonh=True, tol=1e-7)
stream.charmm_script('wkky sele bynu 9:6008 end')
#stream.charmm_script('cons hmcm force 1.0 refx 0.0 refy 0.0 refz 0.0 sele .not. ((segid WAT)) end')
# Deactivate CMAP correction for peptides
stream.charmm_script("skip cmap")
# Energy
energy.show()
# Step 3: Define PhysNet energy function
#-----------------------------------------------------------
# Prepare PhysNet input parameter
selection = pycharmm.SelectAtoms(seg_id='CH3C')
# Atomic numbers
ase_pept = io.read("init_bulk_c2.pdb", format="proteindatabank")
Z = ase_pept.get_atomic_numbers()[:8]
print(Z)
# Checkpoint files
checkpoint = "../physnet-criegee/criegee-103635_b"
# PhysNet config file
config = "../physnet-criegee/config"
# Model units are eV and Angstrom
econv = 1./(units.kcal/units.mol)
fconv = 1./(units.kcal/units.mol)
charge = 0
# Initialize PhysNet calculator
pycharmm.MLpot(
selection,
fq=True,
Z=Z,
checkpoint=checkpoint,
config=config,
charge=charge,
econv=econv,
fconv=fconv,
v1=True) # Model is trained by PhysNet using tensorflow 1.x
# Custom energy
energy.show()
stream.charmm_script('cons fix sele segid CH3C end')
stream.charmm_script('cons fix sele none end')
energy.show()
# Step 5: MINI - CHARMM, PhysNet
#-----------------------------------------------------------
# Do minimization or read result from last run
if True:
stream.charmm_script('cons fix sele segid CH3C end')
# Optimization with PhysNet parameter
minimize.run_sd(**{
'nstep': 1000,
'tolenr': 1e-5,
'tolgrd': 1e-5})
stream.charmm_script('cons fix sele none end')
# Optimization with PhysNet parameter
dcd_file = pycharmm.CharmmFile(
file_name="mini_c2.dcd", file_unit=1, formatted=False, read_only=False)
minimize.run_sd(**{
'nstep': 1000,
'tolenr': 1e-5,
'tolgrd': 1e-5,
'iuncrd': 1,
'nsavc': 1,
'step': 0.001})
dcd_file.close()
# Write pdb file
write.coor_pdb("mini_c2.pdb", title="PhysNet Tripeptide in water - Minimized")
write.coor_card("mini_c2.cor", title="PhysNet Tripeptide in water - Minimized")
else:
# Read minimized coordinates and check energy
read.coor_card("mini_c2.cor")
energy.show()
# Step 4: Heating - CHARMM, PhysNet
#-----------------------------------------------------------
if True:
stream.charmm_script('cons hmcm force 1.0 refx 0.0 refy 0.0 refz 0.0 sele .not. ((segid WAT)) end')
timestep = 0.001 # 0.5 fs
tottime = 5.0 # 10 ps
savetime = 0.10 # 100 fs
res_file = pycharmm.CharmmFile(
file_name="heat_c2.res", file_unit=2, formatted=True, read_only=False)
dcd_file = pycharmm.CharmmFile(
file_name="heat_c2.dcd", file_unit=1, formatted=False, read_only=False)
# Run some dynamics
dynamics_dict = {
'leap': False,
'verlet': True,
'cpt': False,
'new': False,
'langevin': False,
'timestep': timestep,
'start': True,
'nstep': 2000,
'nsavc': 100,
'nsavv': 0,
'inbfrq':-1,
'ihbfrq': 50,
'ilbfrq': 50,
'imgfrq': 50,
'ixtfrq': 1000,
'iunrea':-1,
'iunwri': res_file.file_unit,
'iuncrd': dcd_file.file_unit,
'nsavl': 0, # frequency for saving lambda values in lamda-dynamics
'iunldm':-1,
'ilap': -1,
'ilaf': -1,
'nprint': 100, # Frequency to write to output
'iprfrq': 500, # Frequency to calculate averages
'isvfrq': 1000, # Frequency to save restart file
'ntrfrq': 1000,
'ihtfrq': 0, # 200
'ieqfrq': 1000,
'firstt': 300,
'finalt': 300,
'tbath': 300,
'iasors': 0,
'iasvel': 1,
'ichecw': 0,
'iscale': 0, # scale velocities on a restart
'scale': 1, # scaling factor for velocity scaling
'echeck':-1}
dyn_heat = pycharmm.DynamicsScript(**dynamics_dict)
dyn_heat.run()
res_file.close()
dcd_file.close()
# Step 5: Equilibration - CHARMM, PhysNet
#-----------------------------------------------------------
if True:
timestep = 0.001 # 0.2 fs
tottime = 5.0 # 50 ps
savetime = 0.01 # 10 fs
pmass = int(np.sum(select.get_property('mass'))/50.0)
tmass = int(pmass*10)
str_file = pycharmm.CharmmFile(
file_name='heat_c2.res', file_unit=3, formatted=True, read_only=False)
res_file = pycharmm.CharmmFile(
file_name='eqb_c2.res', file_unit=2, formatted=True, read_only=False)
dcd_file = pycharmm.CharmmFile(
file_name='eqb_c2.dcd', file_unit=1, formatted=False, read_only=False)
# Run some dynamics
dynamics_dict = {
'leap': True,
'verlet': False,
'cpt': True,
'new': False,
'langevin': False,
'timestep': timestep,
'start': False,
'restart': True,
'nstep': 5000,
'nsavc': 100,
'nsavv': 0,
'inbfrq':-1,
'ihbfrq': 50,
'ilbfrq': 50,
'imgfrq': 50,
'ixtfrq': 1000,
'iunrea': str_file.file_unit,
'iunwri': res_file.file_unit,
'iuncrd': dcd_file.file_unit,
'nsavl': 0, # frequency for saving lambda values in lamda-dynamics
'iunldm':-1,
'ilap': -1,
'ilaf': -1,
'nprint': 1000, # Frequency to write to output
'iprfrq': 1000, # Frequency to calculate averages
'isvfrq': 1000, # Frequency to save restart file
'ntrfrq': 500,
'ihtfrq': 200,
'ieqfrq': 0,
'firstt': 300,
'finalt': 300,
'tbath': 300,
'pint pconst pref': 1,
'pgamma': 5,
'pmass': pmass,
'hoover reft': 300,
'tmass': tmass,
'iasors': 0,
'iasvel': 1,
'ichecw': 0,
'iscale': 0, # scale velocities on a restart
'scale': 1, # scaling factor for velocity scaling
'echeck':-1}
dyn_equi = pycharmm.DynamicsScript(**dynamics_dict)
dyn_equi.run()
str_file.close()
res_file.close()
dcd_file.close()
write.coor_pdb("eqb_c2.pdb")
write.coor_card("eqb_c2.cor")
# Step 6: Production - CHARMM, PhysNet
#-----------------------------------------------------------
if True:
timestep = 0.0001 # 0.2 fs
pmass = int(np.sum(select.get_property('mass'))/50.0)
tmass = int(pmass*10)
for ii in range(0, 10):
if ii==0:
str_file = pycharmm.CharmmFile(
file_name='eqb_c2.res',
file_unit=3, formatted=True, read_only=False)
res_file = pycharmm.CharmmFile(
file_name='dyna_c2_{:d}.res'.format(ii),
file_unit=2, formatted=True, read_only=False)
dcd_file = pycharmm.CharmmFile(
file_name='/data/yinc/ir/bulk_physnet_kky/dyna_c2_{:d}.dcd'.format(ii),
file_unit=1, formatted=False, read_only=False)
else:
str_file = pycharmm.CharmmFile(
file_name='dyna_c2_{:d}.res'.format(ii - 1),
file_unit=3, formatted=True, read_only=False)
res_file = pycharmm.CharmmFile(
file_name='dyna_c2_{:d}.res'.format(ii),
file_unit=2, formatted=True, read_only=False)
dcd_file = pycharmm.CharmmFile(
file_name='/data/yinc/ir/bulk_physnet_kky/dyna_c2_{:d}.dcd'.format(ii),
file_unit=1, formatted=False, read_only=False)
# Run some dynamics
dynamics_dict = {
'leap': True,
'verlet': False,
'cpt': True,
'new': False,
'langevin': False,
'timestep': timestep,
'start': False,
'restart': True,
# 'nstep': 100.0*1./timestep,
'nstep': 2000000,
'nsavc': 10,
'nsavv': 0,
'inbfrq':-1,
'ihbfrq': 50,
'ilbfrq': 50,
'imgfrq': 50,
'ixtfrq': 1000,
'iunrea': str_file.file_unit,
'iunwri': res_file.file_unit,
'iuncrd': dcd_file.file_unit,
'nsavl': 0, # frequency for saving lambda values in lamda-dynamics
'iunldm':-1,
'ilap': -1,
'ilaf': -1,
'nprint': 100, # Frequency to write to output
'iprfrq': 500, # Frequency to calculate averages
'isvfrq': 1000, # Frequency to save restart file
'ntrfrq': 1000,
'ihtfrq': 0,
'ieqfrq': 0,
'firstt': 300,
'finalt': 300,
'tbath': 300,
'pint pconst pref': 1,
'pgamma': 5,
'pmass': pmass,
'hoover reft': 300,
'tmass': tmass,
'iasors': 0,
'iasvel': 1,
'ichecw': 0,
'iscale': 0, # scale velocities on a restart
'scale': 1, # scaling factor for velocity scaling
'echeck':-1}
dyn_prod = pycharmm.DynamicsScript(**dynamics_dict)
dyn_prod.run()
str_file.close()
res_file.close()
dcd_file.close()
write.coor_pdb("dyna_c2.pdb")
write.coor_card("dyna_c2.cor")