forked from egallicc/bedam_workflow
-
Notifications
You must be signed in to change notification settings - Fork 2
/
bedam.py
1521 lines (1340 loc) · 50 KB
/
bedam.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
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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# bedam python class
__doc__="""
$Revision: 0.1 $
A class to prepare and analyze BEDAM jobs
"""
# Contributors: Emilio Gallicchio, Junchao Xia
import os, sys, time, re, glob
from operator import itemgetter, attrgetter
from schrodinger import structure, structureutil
from schrodinger.application import inputconfig
from schrodinger.utils.fileutils import get_structure_file_format, splitext, is_poseviewer_file, get_next_filename
from schrodinger.utils import cmdline
import schrodinger.utils.log
import shutil
import signal
import glob
import time
import sqlite3 as lite
from math import *
from numpy import * # numerical array library
#sys.path.append('/home/tuf29141/software/bedam_workflow/pymbar-2.0beta/pymbar')
#import MBAR
#sys.path.append('/home/tuf29141/software/bedam_workflow/pymbar-1.0d/pymbar')
#import MBAR
# Setup the logger
logger = schrodinger.utils.log.get_output_logger("bedam_prep")
class bedam_job:
"""
Class to set up BEDAM calculations
"""
def __init__(self, command_file, options):
self.command_file = command_file
self.jobname = os.path.splitext( os.path.basename(command_file) )[0]
self.impact = os.path.join(os.environ['SCHRODINGER'],'impact')
self.parseInputFile()
self.printStatus() #debug: write out the parameters, etc.
def error(self, text):
""" Print an error line to the log file """
logger.error(text)
sys.stdout.flush()
def exit(self, text):
""" Print an error and exit """
self.error(text)
print 'exiting...'
sys.exit(1)
def parseInputFile(self):
"""
Read keywords from BEDAM input file
"""
config = inputconfig.InputConfig(self.command_file)
self.keywords = dict(config)
def printStatus(self):
print 'command_file=', self.command_file
print 'jobname=', self.jobname
for k, v in self.keywords.iteritems():
print k, v
#
# Impact input file templates for commerical impact
#
def setupTemplates(self):
""" Setup templates for input files for commerical impact"""
self.input_idx = """
write file -
"%s" -
title -
"%s" *
CREATE
build primary name species1 type auto read maestro file -
"%s"
build primary name species2 type auto read maestro file -
"%s"
build types name species1
build types name species2
QUIT
SETMODEL
setpotential
mmechanics consolv agbnp2
quit
read parm file -
"paramstd.dat" -
noprint
energy parm dielectric 1 nodist -
listupdate 10 -
cutoff 12 hmass 5
energy rescutoff byatom all
zonecons auto
energy constraints bonds hydrogens
QUIT
MINIMIZE
input cntl mxcyc 0 rmscut 0.05 deltae 1.0e-05
conjugate dx0 0.05 dxm 1.0
run
write maestro name species1 file "%s"
write maestro name species2 file "%s"
QUIT
END
"""
self.input_mintherm = """
write file -
"%s" -
title -
"%s" *
CREATE
build primary name species1 type auto read maestro file -
"%s"
build primary name species2 type auto read maestro file -
"%s"
build types name species1
build types name species2
QUIT
SETMODEL
setpotential
mmechanics consolv agbnp2
quit
read parm file -
"paramstd.dat" -
noprint
energy rest domain cmdist kdist %s dist0 %s toldist %s -
read file "%s"
energy parm dielectric 1 nodist -
listupdate 10 -
cutoff 12 hmass 5
energy rescutoff byatom all
zonecons auto
energy constraints bonds hydrogens
QUIT
MINIMIZE
conjugate dx0 5.000000e-02 dxm 1.000000e+00
input cntl mxcyc 200 rmscut 1.000000e-02 deltae 1.000000e-07
run
QUIT
put 100 into 'temp0'
put %s into 'tempt'
put 10 into 'n'
put 'tempt'- 'temp0' into 'dtemp'
put 'dtemp' / 'n' into 'dt'
put 0 into 'i'
while 'i' lt 'n'
DYNAMICS
input cntl nstep 1000 delt 0.0005
input cntl constant totalenergy
input cntl initialize temperature at 'temp0'
input cntl nprnt 100
input cntl tol 1.00000e-07
input cntl stop rotations
input cntl statistics off
run rrespa fast 8
QUIT
put 'temp0' + 'dt' into 'temp0'
put 'i' + 1 into 'i'
endwhile
DYNAMICS
write restart coordinates formatted file "%s"
write maestro file "%s"
QUIT
END
"""
self.input_remd = """
write file -
"%s" -
title -
"%s" *
CREATE
build primary name species1 type auto read maestro file -
"%s"
build primary name species2 type auto read maestro file -
"%s"
build types name species1
build types name species2
QUIT
SETMODEL
setpotential
mmechanics nb12softcore umax %s %s consolv agbnp2
weight constraints buffer %s
weight bind rxid 0 nrep %d %s
%s
quit
read parm file -
"paramstd.dat" -
noprint
energy rest domain cmdist kdist %s dist0 %s toldist %s -
read file "%s"
energy parm dielectric 1 nodist -
listupdate 10 -
cutoff 12 hmass 5
energy rescutoff byatom all
zonecons auto
energy constraints bonds hydrogens
QUIT
MINI
read restart coordinates formatted file "%s"
QUIT
DYNAMICS
input cntl nstep %s delt 0.001
input cntl constant temperature langevin relax 10.0 -
rxmd nwalkers %d nstepexch %s -
hamiltonian
input target temperature %s
input cntl initialize temperature at %s
input cntl nprnt %s
input cntl tol 1.00000e-07
input cntl statistics off
run rrespa fast 4
QUIT
DYNAMICS
input cntl nstep %s delt 0.001
input cntl constant temperature langevin relax 1.0
input cntl rxmd nwalkers %d nstepexch 200 -
hamiltonian %s
input target temperature %s
input cntl initialize temperature at %s
input cntl nprnt %s
input cntl tol 1.00000e-07
input cntl statistics off
write trajectory coordinates rxid every %s -
external file "%s"
run rrespa fast 4
write restart coordinates rxid formatted file "%s"
write maestro file -
"%s"
QUIT
END
"""
self.input_remd_restart = """
write file -
"%s" -
title -
"%s" *
CREATE
build primary name species1 type auto read maestro file -
"%s"
build primary name species2 type auto read maestro file -
"%s"
build types name species1
build types name species2
QUIT
SETMODEL
setpotential
mmechanics nb12softcore umax %s %s consolv agbnp2
weight constraints buffer %s
weight bind rxid 0 nrep %d %s
%s
quit
read parm file -
"paramstd.dat" -
noprint
energy rest domain cmdist kdist %s dist0 %s toldist %s -
read file "%s"
energy parm dielectric 1 nodist -
listupdate 10 -
cutoff 12 hmass 5
energy rescutoff byatom all
zonecons auto
energy constraints bonds hydrogens
QUIT
DYNAMICS
input cntl nstep %s delt 0.001
input cntl constant temperature langevin relax 1.0
input cntl rxmd nwalkers %d nstepexch 200 -
hamiltonian %s
input target temperature %s
input cntl initialize temperature at %s
input cntl nprnt %s
input cntl tol 1.00000e-07
input cntl statistics off
read restart coordinates rxid formatted file "%s"
write trajectory coordinates rxid every %s -
external file "%s"
run rrespa fast 4
write restart coordinates rxid formatted file "%s"
write maestro file -
"%s"
QUIT
END
"""
self.input_reservoir = """ -
l0reservoir nreservoir %s resvrxid 0 -
traj nfile 2 maxrec %s nskip 1 delt 0.001 -
coordinates temperature every 1 -
traj fnames external file "%s" -
file "%s" -
cmrestraints """
self.input_trj = """
write file -
"%s" -
title -
"%s" *
CREATE
build primary name species1 type auto read maestro file -
"%s"
build primary name species2 type auto read maestro file -
"%s"
build types name species1
build types name species2
QUIT
SETMODEL
setpotential
mmechanics nb12softcore umax %s consolv agbnp2
weight constraints buffer %s
weight bind rxid 0 nrep %d %s
quit
read parm file -
"paramstd.dat" -
noprint
energy parm dielectric 1 nodist -
listupdate 10 -
cutoff 12 hmass 5
energy rescutoff byatom all
zonecons auto
energy constraints bonds hydrogens
QUIT
put 0 into 'repl'
while 'repl' lt %d
put $q$ concat (char 'repl') into 'bs3'
put 'bs3' concat $.trj$ into 'trjname'
show 'trjname'
TABLE
traj nfile 1 maxrec 50000000 nskip 1 delt 0.001 -
coordinates rxid every 1 -
traj fnames external file -
'trjname'
starttrack
QUIT
reset 'current.rxid'
show 'repl'
show 'current.rxid'
put $q$ concat (char 'current.rxid') into 'ms3'
put 'ms3' concat $.maegz$ into 'maename'
MINIMIZE
conjugate dx0 5.000000e-02 dxm 1.000000e+00
input cntl mxcyc 0 rmscut 1.000000e-02 deltae 1.000000e-07
run
write maestro file 'maename' append
QUIT
TABLE
stoptrack
QUIT
put 'repl' + 1 into 'repl'
endwhile
END
"""
self.input_trj_rescore = """
write file -
"%s" verbose 1 -
title -
"%s" *
CREATE
build primary name species1 type auto read maestro file -
"%s"
build primary name species2 type auto read maestro file -
"%s"
build types name species1
build types name species2
QUIT
SETMODEL
setpotential
mmechanics nb12softcore umax %s consolv agbnp2
weight constraints buffer %s
weight bind rxid 0 nrep %d %s
quit
read parm file -
"paramstd.dat" -
noprint
energy parm dielectric 1 nodist -
listupdate 10 -
cutoff 12 hmass 5
energy rescutoff byatom all
zonecons auto
energy constraints bonds hydrogens
QUIT
put 0 into 'repl'
while 'repl' lt %d
put $q$ concat (char 'repl') into 'bs3'
put 'bs3' concat $.trj$ into 'trjname'
show 'trjname'
TABLE
traj nfile 1 maxrec 50000000 nskip 1 delt 0.001 -
coordinates rxid every 1 -
traj fnames external file -
'trjname'
starttrack
QUIT
reset 'current.rxid'
show 'repl'
show 'current.rxid'
if 'current.rxid' eq %d
MINIMIZE
conjugate dx0 5.000000e-02 dxm 1.000000e+00
input cntl mxcyc 0 rmscut 1.000000e-02 deltae 1.000000e-07
run
QUIT
endif
TABLE
stoptrack
QUIT
put 'repl' + 1 into 'repl'
endwhile
END
"""
#
# runs Impact on the input mae files to get versions with internal
# atom indexes
#
def getImpactMaeFiles(self):
receptor_file = self.keywords.get('RECEPTOR_FILE')
if not receptor_file:
msg = "bedam_prep: No receptor file specified in the input file"
self.exit(msg)
if not os.path.exists(receptor_file):
msg = 'File does not exist: %s' % receptor_file
self.exit(msg)
ligand_file = self.keywords.get('LIGAND_FILE')
if not ligand_file:
msg = "bedam_prep: No ligand file specified in the input file"
self.exit(msg)
if not os.path.exists(ligand_file):
msg = 'File does not exist: %s' % ligand_file
self.exit(msg)
impact_input_file = self.jobname + '_idx' + '.inp'
impact_output_file = self.jobname + '_idx' + '.out'
impact_jobtitle = self.jobname + '_idx'
out_receptor_file = self.jobname + '_rcpt_idx' + '.maegz'
out_ligand_file = self.jobname + '_lig_idx' + '.maegz'
f = open(impact_input_file, 'w')
input = self.input_idx % (impact_output_file, impact_jobtitle, receptor_file, ligand_file, out_receptor_file, out_ligand_file )
f.write(input)
f.close()
cmd = self.impact + " -i " + impact_input_file + " -LOCAL -WAIT"
os.system(cmd)
if not os.path.exists(out_receptor_file) or not os.path.exists(out_ligand_file):
print " failed"
msg = "Impact job to analyze structure files failed"
self.exit(msg)
self.recidxfile = out_receptor_file
self.ligidxfile = out_ligand_file
#
# write the binding site restraint file *_cmrestraint.dat
#
def writeRestraintFile(self):
# check that structure files with internal indexes have been generated
if self.recidxfile is None or self.ligidxfile is None:
msg = "writeRestraintFile: Internal error: structure files not found"
self.exit(msg)
receptor_asl = self.keywords.get('REST_LIGAND_CMRECASL')
if not receptor_asl:
msg = "bedam_prep: No ASL specified for receptor site center"
self.exit(msg)
ligand_asl = self.keywords.get('REST_LIGAND_CMLIGASL')
if not ligand_asl:
ligand_asl = '( all)'
try:
st = structure.StructureReader(self.recidxfile).next()
except:
print "Cannot open Maestro structure file %s" % self.recidxfile
sys.exit(-1)
nrecatoms = len(st.atom)
atoms = structureutil.evaluate_asl(st, receptor_asl)
rec_atoms = [];
for iat in atoms:
rec_atoms.append(st.atom[iat].property['i_i_internal_atom_index'])
#computes receptor CM
cmrx = cmry = cmrz = 0.
for iat in atoms:
cmrx += st.atom[iat].x
cmry += st.atom[iat].y
cmrz += st.atom[iat].z
n = len(atoms)
cmrx /= float(n)
cmry /= float(n)
cmrz /= float(n)
try:
st = structure.StructureReader(self.ligidxfile).next()
except:
print "Cannot open Maestro structure file %s" % self.ligidxfile
sys.exit(-1)
nligatoms = len(st.atom)
atoms = structureutil.evaluate_asl(st, ligand_asl)
lig_atoms = [];
for iat in atoms:
lig_atoms.append(st.atom[iat].property['i_i_internal_atom_index']-nrecatoms)
#computes ligand CM
cmlx = cmly = cmlz = 0.
for iat in atoms:
cmlx += st.atom[iat].x
cmly += st.atom[iat].y
cmlz += st.atom[iat].z
n = len(atoms)
cmlx /= float(n)
cmly /= float(n)
cmlz /= float(n)
#computes and reports the distance btw CM's
d = sqrt((cmlx - cmrx)*(cmlx - cmrx) + (cmly - cmry)*(cmly - cmry) + (cmlz - cmrz)*(cmlz - cmrz))
print "CM-CM distance = %f" % d
self.restraint_file = self.jobname + '_cmrestraint.dat'
f = open(self.restraint_file,"w")
f.write("Receptor\n")
f.write("%d\n" % 1)
f.write("%d\n" % len(rec_atoms) )
for i in rec_atoms:
f.write("%d\n" % i)
f.write("Ligand\n")
f.write("%d\n" % 2)
f.write("%d\n" % len(lig_atoms) )
for i in lig_atoms:
f.write("%d\n" % i)
f.close()
#
# writes receptor mae file with restraints
#
def writeRecStructureFile(self):
receptor_file = self.keywords.get('RECEPTOR_FILE')
if not receptor_file:
msg = "bedam_prep: No receptor file specified in the input file"
self.exit(msg)
if not os.path.exists(receptor_file):
msg = 'File does not exist: %s' % receptor_file
self.exit(msg)
receptor_asl = self.keywords.get('REST_RECEPTOR_ASL')
try:
st = structure.StructureReader(receptor_file).next()
except:
print "Cannot open Maestro structure file %s" % receptor_file
sys.exit(-1)
atoms = []
if receptor_asl:
atoms = structureutil.evaluate_asl(st, receptor_asl)
# all atoms free
for atom in st.atom:
atom.property['i_i_constraint'] = 0
# buffer the ones in ASL
for iat in atoms:
st.atom[iat].property['i_i_constraint'] = 2
receptor_file_restr = self.jobname + '_rcpt_restr' + '.maegz'
st.write(receptor_file_restr)
self.receptor_file_restr = receptor_file_restr
self.ligand_file_restr = self.ligidxfile
#
# writes the Impact input file for minimization/thermalization
#
def writeThermInputFile(self):
if self.receptor_file_restr is None:
msg = "writeThermInputFile: Internal error: receptor structure file not found"
self.exit(msg)
if not os.path.exists(self.receptor_file_restr):
msg = 'File does not exist: %s' % self.receptor_file_restr
self.exit(msg)
if self.ligand_file_restr is None:
msg = "writeThermInputFile: No ligand file specified in the input file"
self.exit(msg)
if not os.path.exists(self.ligand_file_restr):
msg = 'File does not exist: %s' % self.ligand_file_restr
self.exit(msg)
kfcm = self.keywords.get('REST_LIGAND_CMKF')
if not kfcm:
kfcm = '3.0'
d0cm = self.keywords.get('REST_LIGAND_CMDIST0')
if not d0cm:
msg = "bedam_prep: No receptor-ligand reference distance specified"
self.exit(msg)
tolcm = self.keywords.get('REST_LIGAND_CMTOL')
if not tolcm:
msg = "bedam_prep: No receptor-ligand distance tolerance specified"
self.exit(msg)
if self.restraint_file is None:
msg = "writeThermInputFile: Internal error: restraint file not found"
self.exit(msg)
if not os.path.exists(self.restraint_file):
msg = 'File does not exist: %s' % self.restraint_file
self.exit(msg)
temperature = self.keywords.get('TEMPERATURE')
if not temperature:
temperature = '300.0'
impact_input_file = self.jobname + '_mintherm' + '.inp'
impact_output_file = self.jobname + '_mintherm' + '.out'
impact_jobtitle = self.jobname + '_mintherm'
out_restart_file = self.jobname + '_mintherm' + '.rst'
self.mintherm_out_restart_file = out_restart_file
out_structure_file = self.jobname + '_mintherm' + '.maegz'
input = self.input_mintherm % (impact_output_file, impact_jobtitle, self.receptor_file_restr,self.ligand_file_restr, kfcm, d0cm, tolcm, self.restraint_file, temperature, out_restart_file, out_structure_file)
f = open(impact_input_file, "w")
f.write(input)
f.close()
def mkAuxParams(self):
lambda_string = self.keywords.get('LAMBDAS')
if not lambda_string:
msg = "bedam_prep: No lambda schedule specified"
self.exit(msg)
lambdas = lambda_string.split(',')
nlambdas = len(lambdas)
qb_fcs_string = self.keywords.get('QB_FORCECONSTANT')
if not qb_fcs_string:
msg = "bedam_prep: No quadbias force constants specified"
self.exit(msg)
self.qb_fcs = qb_fcs_string.split(',')
if not (len(self.qb_fcs) == nlambdas):
msg = "bedam_prep: Number of quadbias force constants does not match the number of lambdas."
self.exit(msg)
qb_bepos_string = self.keywords.get('QB_BEPOS')
if not qb_bepos_string:
msg = "bedam_prep: No quadbias binding energy positions specified"
self.exit(msg)
self.qb_bepos = qb_bepos_string.split(',')
if not (len(self.qb_bepos) == nlambdas):
msg = "bedam_prep: Number of quadbias binding energy positions does not match the number of lambdas."
self.exit(msg)
#
# writes the Impact input file for remd production
#
def writeRemdInputFile(self):
if self.receptor_file_restr is None:
msg = "writeRemdInputFile: Internal error: receptor structure file not found"
self.exit(msg)
if not os.path.exists(self.receptor_file_restr):
msg = 'File does not exist: %s' % self.receptor_file_restr
self.exit(msg)
if self.ligand_file_restr is None:
msg = "writeRemdInputFile: No ligand file specified in the input file"
self.exit(msg)
if not os.path.exists(self.ligand_file_restr):
msg = 'File does not exist: %s' % self.ligand_file_restr
self.exit(msg)
umax = self.keywords.get('UMAX')
if not umax:
umax = '1000.0'
kfcm = self.keywords.get('REST_LIGAND_CMKF')
if not kfcm:
kfcm = '3.0'
d0cm = self.keywords.get('REST_LIGAND_CMDIST0')
if not d0cm:
msg = "bedam_prep: No receptor-ligand reference distance specified"
self.exit(msg)
tolcm = self.keywords.get('REST_LIGAND_CMTOL')
if not tolcm:
msg = "bedam_prep: No receptor-ligand distance tolerance specified"
self.exit(msg)
if self.restraint_file is None:
msg = "writeRemdInputFile: Internal error: restraint file not found"
self.exit(msg)
if not os.path.exists(self.restraint_file):
msg = 'File does not exist: %s' % self.restraint_file
self.exit(msg)
temperature = self.keywords.get('TEMPERATURE')
if not temperature:
msg = "bedam_prep: no temperature speciefied"
self.exit(msg)
lambda_string = self.keywords.get('LAMBDAS')
if not lambda_string:
msg = "bedam_prep: No lambda schedule specified"
self.exit(msg)
lambdas = lambda_string.split(',')
nlambdas = len(lambdas)
# constructs list of lambdas in input file
lambda_list = ''
for l in lambdas:
lambda_list = lambda_list + "-\n lambda %s " % l
rest_kf = self.keywords.get('REST_RECEPTOR_KF')
if not rest_kf:
rest_kf = '0.6'
if self.mintherm_out_restart_file is None:
msg = "writeRemdInputFile: Internal error: min/therm restart file not found"
self.exit(msg)
basename = os.path.splitext( os.path.basename(self.mintherm_out_restart_file) )[0]
suffix = os.path.splitext( os.path.basename(self.mintherm_out_restart_file) )[1]
for i in range(0,nlambdas):
os.system("ln -s %s %s_%d%s" % (self.mintherm_out_restart_file, basename, i, suffix))
nmd_eq = self.keywords.get('EQUILIBRATION_STEPS')
if not nmd_eq:
msg = "bedam_prep: Number of equilibration steps not specified"
self.exit(msg)
nmd_prod = self.keywords.get('PRODUCTION_STEPS')
if not nmd_prod:
msg = "bedam_prep: Number of production steps not specified"
self.exit(msg)
nprnt = self.keywords.get('PRNT_FREQUENCY')
if not nprnt:
msg = "Number of printing frequency not specified"
self.exit(msg)
ntrj = self.keywords.get('TRJ_FREQUENCY')
if not ntrj:
msg = "Number of trajectory writing frequency not specified"
self.exit(msg)
rcpt_rsvr = self.keywords.get('RCPT_RESERVOIR_TRJFILE')
lig_rsvr = self.keywords.get('LIG_RESERVOIR_TRJFILE')
nrsvr = self.keywords.get('RESERVOIR_SIZE')
if rcpt_rsvr and lig_rsvr and nrsvr:
if not os.path.exists(rcpt_rsvr):
msg = 'File does not exist: %s' % rcpt_rsvr
self.exit(msg)
if not os.path.exists(rcpt_rsvr):
msg = 'File does not exist: %s' % lig_rsvr
self.exit(msg)
rsvr_command = self.input_reservoir % (nrsvr, nrsvr, rcpt_rsvr, lig_rsvr)
else:
rsvr_command = ""
restart_file = self.keywords.get('RESTART_FILE')
#Bias potentials settings
bias_flag = ""
bias_parameters = "! "
qb_k = self.keywords.get('QUADBIAS')
if qb_k:
if qb_k == "yes":
bias_flag = "quadbias"
self.mkAuxParams() #creates self.qb_fcs and self.qb_bepos
# constructs list of auxiliary bedam parameters in input file
n_aux_parameters = 2 # force constant + binding energy position
bias_parameters = " weight auxbind naux %d " % n_aux_parameters
for i in range(0,nlambdas):
bias_parameters = bias_parameters + "-\n auxp1 %s auxp2 %s " % (self.qb_fcs[i],self.qb_bepos[i])
impact_input_file = self.jobname + '_remd' + '.inp'
impact_output_file = self.jobname + '_remd' + '.out'
impact_jobtitle = self.jobname + '_remd'
out_trajectory_file = self.jobname + '_remd' + '.trj'
out_restart_file = self.jobname + '_remd' + '.rst'
out_structure_file = self.jobname + '_remd' + '.maegz'
if not restart_file:
input = self.input_remd % (impact_output_file, impact_jobtitle,
self.receptor_file_restr , self.ligand_file_restr,
umax, bias_flag,
rest_kf, nlambdas, lambda_list,
bias_parameters,
kfcm, d0cm, tolcm, self.restraint_file,
self.mintherm_out_restart_file,
nmd_eq, nlambdas, nmd_eq, temperature, temperature, nprnt,
nmd_prod, nlambdas, rsvr_command,
temperature, temperature, nprnt,
ntrj, out_trajectory_file, out_restart_file, out_structure_file)
else:
input = self.input_remd_restart % (impact_output_file, impact_jobtitle,
self.receptor_file_restr , self.ligand_file_restr,
umax, bias_flag,
rest_kf, nlambdas, lambda_list,
bias_parameters,
kfcm, d0cm, tolcm, self.restraint_file,
nmd_prod, nlambdas, rsvr_command,
temperature, temperature, nprnt,
restart_file,
ntrj, out_trajectory_file,
out_restart_file, out_structure_file)
f = open(impact_input_file, "w")
f.write(input)
f.close
#
# writes the Impact input file to construct .maegz trajectories by lambda
#
def writeReadTrajInputFile(self):
if self.receptor_file_restr is None:
msg = "writeReadTrajInputFile: Internal error: receptor structure file not found"
self.exit(msg)
if not os.path.exists(self.receptor_file_restr):
msg = 'File does not exist: %s' % self.receptor_file_restr
self.exit(msg)
if self.ligand_file_restr is None:
msg = "writeReadTrajInputFile: No ligand file specified in the input file"
self.exit(msg)
if not os.path.exists(self.ligand_file_restr):
msg = 'File does not exist: %s' % self.ligand_file_restr
self.exit(msg)
umax = self.keywords.get('UMAX')
if not umax:
umax = '1000.0'
lambda_string = self.keywords.get('LAMBDAS')
if not lambda_string:
msg = "bedam_prep: No lambda schedule specified"
self.exit(msg)
lambdas = lambda_string.split(',')
nlambdas = len(lambdas)
# constructs list of lambdas in input file
lambda_list = ''
for l in lambdas:
lambda_list = lambda_list + "-\nlambda %s " % l
rest_kf = self.keywords.get('REST_RECEPTOR_KF')
if not rest_kf:
rest_kf = '0.6'
impact_input_file = self.jobname + '_readtraj' + '.inp'
impact_output_file = self.jobname + '_readtraj' + '.out'
impact_jobtitle = self.jobname + '_readtraj'
# creates short-named versions of trj and maegz files
for i in range(nlambdas):
long_trjfile = self.jobname + "_remd_%d.trj" % i
short_trjfile = "q%d.trj" % i
os.system("ln -s -f %s %s" % (long_trjfile, short_trjfile))
i = 0
for l in lambdas:
long_maefile = self.jobname + "_remd_trj_%s.maegz" % l
short_maefile = "q%d.maegz" % i
os.system("ln -s -f %s %s" % (short_maefile, long_maefile))
i += 1
input = self.input_trj % (impact_output_file, impact_jobtitle,
self.receptor_file_restr , self.ligand_file_restr,
umax,
rest_kf, nlambdas, lambda_list,
nlambdas)
f = open(impact_input_file, "w")
f.write(input)
f.close
#writes readtraj for surface rescoring
impact_input_file = self.jobname + '_readtraj_rescore' + '.inp'
impact_output_file = self.jobname + '_readtraj_rescore' + '.out'
impact_jobtitle = self.jobname + '_readtraj_rescore'
input = self.input_trj_rescore % (impact_output_file, impact_jobtitle,
self.receptor_file_restr , self.ligand_file_restr,
umax,
rest_kf, nlambdas, lambda_list,
nlambdas,nlambdas-1)
f = open(impact_input_file, "w")
f.write(input)
f.close
#
# Reads all of the simulation data values temperature, energies, etc.
# at each time step and puts into a big table
#
def getImpactData(self,file):
if not os.path.exists(file):
msg = 'File does not exist: %s' % file
self.exit(msg)
step_line = re.compile("^ Step number:")
number_line = re.compile("(\s+-*\d\.\d+E[\+-]\d+\s*)+")
temperature_line = re.compile("^\s*input target temperature\s+(\d*\.*\d*)")
have_trgtemperature = 0
nsamples = 0
data = []
f = open(file ,"r")
line = f.readline()
while line:
# fast forward until we get to the line:
# "Step number: ... ", grab target temperature along the way
# if it's in the input file
while line and not re.match(step_line, line):
if re.match(temperature_line, line):
words = line.split()
temperature = words[3]
have_trgtemperature = 1
line = f.readline()
# read the step number
if re.match(step_line, line):
words = line.split()
step = words[2]
datablock = [int(step)]
if have_trgtemperature == 1:
datablock.append(float(temperature))
#now read up to 3 lines of numbers
ln = 0
while ln < 3:
line = f.readline()
if not line:
msg = "Unexpected end of file"
self.exit(msg)
if re.match(number_line, line):
for word in line.split():
datablock.append(float(word))
ln += 1
data.append(datablock)
line = f.readline()
f.close()
return data
"""
#read up to 3 lines of numbers
ln = 0
datablock = []
while ln < 3:
line = f.readline()
if re.match(number_line,line):
print line
ln += 1
line = f.readline()
"""
"""
# fast forward until we get to the line:
# "Step number: ... "
for line in f:
# fast forward until we get to the line:
# "Step number: ... "
if not in_block:
if not (line.find("Step number:") == -1):
in_block = 1
words = line.split()
line = f.readline()
while(line.find('Step number:') == -1):
"""