This repository has been archived by the owner on Nov 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
FMTools.py
executable file
·1917 lines (1621 loc) · 83.8 KB
/
FMTools.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
#!/usr/bin/python
### ### ### ### ###
### ### ### ### ###
#####b. ####b. ###### .d##b. #####b. ### ####b. #####b. ###
### ### "##b "##b ### d##""##b ### "##b ### "##b ### "##b ###
### ### ### .d###### ### ### ### ### ### ### .d###### ### ###
### ### d##P ### ### Y##b. Y##..##P ### ### ### ### ### ### d##P ###
### #####P" "Y###### "Y### "Y##P" ### ### ### "Y###### #####P" ###
###
###
# THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
# Comments and/or additions are welcome (send e-mail to:
###############################################################
# FMTools.py #
# Libraries and methods for Full Monte Carlo #
###############################################################
####### Written by: Rob Paton ###############################
####### Last modified: Mar 20, 2013 #########################
###############################################################
# Python Libraries ############################################
import subprocess, sys, os, commands, math, time, tarfile, random
###############################################################
# EXECECTUBALE ################################################
G09_EXEC = 'g09sub'
MOPAC_EXEC = '/u/rsp/rpaton/mopac/MOPAC2012.exe'
###############################################################
# The time elapsed between two specified Y/M/D 24H/M/S format #
def RealTime(time1, time2):
timeTuple1 = time.strptime(time1, "%Y/%m/%d %H:%M:%S")
timeTuple2 = time.strptime(time2, "%Y/%m/%d %H:%M:%S")
time_difference = time.mktime(timeTuple2) - time.mktime(timeTuple1)
realdays=int(time_difference/(60.0*60*24))
realhours=int(time_difference/(60.0*60))-realdays*24
realmins=int(time_difference/60.0)-realdays*24-realhours*60
realsecs=int(time_difference)-realdays*24*60*60-realhours*60*60-realmins*60
timediff=[realdays,realhours,realmins,realsecs]
return timediff
###############################################################
# Tidies up times in [D,H,M,S] format #########################
def CPUTime(CSearch):
totalcpu = [0,0,0,0]
for cpu in CSearch.ALLCPU:
for i in range(0,4): totalcpu[i] = totalcpu[i] + cpu[i]
totalcpu[2] = totalcpu[2]+int(totalcpu[3]/60.0)
totalcpu[3] = totalcpu[3]-60*int(totalcpu[3]/60.0)
totalcpu[1] = totalcpu[1] + int(totalcpu[2]/60.0)
totalcpu[2] = totalcpu[2] - 60*int(totalcpu[2]/60.0)
totalcpu[0] = totalcpu[0] + int(totalcpu[1]/24.0)
totalcpu[1] = totalcpu[1] - 24*int(totalcpu[1]/24.0)
return totalcpu
###############################################################
# Define Job type #############################################
class JobSpec:
def __init__(self, software):
self.PROGRAM = software
self.CONSTRAINED = []
if software == "Mopac":
self.EXEC = MOPAC_EXEC
self.INPUT = ".mop"
self.ARGS = "&"
if software == "Gaussian":
self.EXEC = G09_EXEC
self.INPUT = " "
self.ARGS = " "
###############################################################
# Submits a computational chemistry job #######################
def submitJob(JobSpec,MolSpec,log):
if not os.path.exists(MolSpec.NAME+".log"):command = JobSpec.EXEC+" "+MolSpec.NAME+JobSpec.INPUT+" "+JobSpec.ARGS+" > /dev/null"
else: command = ""
try:
#print "deactivated submission"
retcode = subprocess.call(command, shell=True)
if retcode != 0:
print >>sys.stderr, log.Write("\nERROR: Submission of "+MolSpec.NAME+" failed")
return -1
else: return 1
except OSError, e:
print >>sys.stderr, log.Write("\nERROR: Submission of "+MolSpec.NAME+" failed")
return -1
###############################################################
# Check that a computational chemistry job has finished #######
def isJobFinished(JobSpec, MolSpec):
if JobSpec.PROGRAM == "Mopac":
if not os.path.exists(MolSpec.NAME+".out"): return 0
else:
outfile = open(MolSpec.NAME+".out","r")
jobdone=0; normal=0
for line in outfile.readlines():
if JobSpec.PROGRAM == "Mopac":
if line.find("== MOPAC DONE ==") > -1:
jobdone = jobdone+1
normal=normal+1
if line.find("EXCESS NUMBER OF OPTIMIZATION CYCLES") > -1:
jobdone = jobdone+1
normal=normal-1
outfile.close()
if JobSpec.PROGRAM == "Gaussian":
if os.path.exists(MolSpec.NAME+".out"):
outfile = open(MolSpec.NAME+".out","r")
if os.path.exists(MolSpec.NAME+".log"):
outfile = open(MolSpec.NAME+".log","r");
jobdone=0; normal=0
for line in outfile.readlines():
if line.find("Normal termination") > -1:
jobdone = jobdone+1
normal=normal+1
outfile.close()
if jobdone>0 and normal>0: return 1
if jobdone>0 and normal==0: return 2
else:
if JobSpec.PROGRAM == "Mopac": modtime=commands.getoutput("ls -l -t "+MolSpec.NAME+".out")
if JobSpec.PROGRAM == "Gaussian":
if os.path.exists(MolSpec.NAME+".log"):modtime=commands.getoutput("ls -l -t "+MolSpec.NAME+".log")
if os.path.exists(MolSpec.NAME+".out"):modtime=commands.getoutput("ls -l -t "+MolSpec.NAME+".out")
#print modtime
for mod in modtime.split():
if mod.find(":") > -1: timeofday = mod
Elapsed = RealTime(time.strftime("%Y/%m/%d" , time.localtime())+" "+modtime.split()[7]+":00", time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()))
ElapsedMins = Elapsed[0]*24*60+Elapsed[1]*60+Elapsed[2]
if JobSpec.PROGRAM == "Mopac":
if ElapsedMins < 5: return 0
else: return -1
###############################################################
# Filter prior to optimization - if there are any very close nonbonded contacts, a non-zero value is returned
def checkDists(MolSpec, SearchParams):
checkval = 0
for i in range(0,len(MolSpec.CARTESIANS)):
bondedatomlist = []
for partners in MolSpec.CONNECTIVITY[i]: bondedatomlist.append(int(partners.split("__")[0])-1)
for j in range(i+1,len(MolSpec.CARTESIANS)):
bond = 0
for bondedatom in bondedatomlist:
if j == bondedatom: bond = bond + bond + 1
if bond == 0:
totdist = abs(calcdist(i, j, MolSpec.CARTESIANS))
bump = SearchParams.RJCT*(bondiRadius(atomicnumber(MolSpec.ATOMTYPES[i]))+bondiRadius(atomicnumber(MolSpec.ATOMTYPES[j])))
# If heteroatom - hydrogen bonds are not specified as fixed...
if SearchParams.HSWAP != 0:
if MolSpec.ATOMTYPES[i]=="N" or MolSpec.ATOMTYPES[i]=="O" or MolSpec.ATOMTYPES[i]=="S":
if MolSpec.ATOMTYPES[j]=="H": bump=0.75*bump
if MolSpec.ATOMTYPES[j]=="N" or MolSpec.ATOMTYPES[j]=="O" or MolSpec.ATOMTYPES[j]=="S":
if MolSpec.ATOMTYPES[i]=="H": bump=0.75*bump
if totdist<bump:
checkval = checkval+1
#print " PREOPT: Rejecting structure!",MolSpec.ATOMTYPES[i],(i+1),MolSpec.ATOMTYPES[j],(j+1),"distance =", totdist,"Ang"
return checkval
###############################################################
# Some useful arrays ##########################################
periodictable = ["","H","He","Li","Be","B","C","N","O","F","Ne","Na","Mg","Al","Si","P","S","Cl","Ar","K","Ca","Sc","Ti","V","Cr","Mn","Fe","Co","Ni","Cu","Zn","Ga","Ge","As","Se","Br","Kr","Rb","Sr","Y","Zr",
"Nb","Mo","Tc","Ru","Rh","Pd","Ag","Cd","In","Sn","Sb","Te","I","Xe","Cs","Ba","La","Ce","Pr","Nd","Pm","Sm","Eu","Gd","Tb","Dy","Ho","Er","Tm","Yb","Lu","Hf","Ta","W","Re","Os","Ir","Pt","Au","Hg","Tl",
"Pb","Bi","Po","At","Rn","Fr","Ra","Ac","Th","Pa","U","Np","Pu","Am","Cm","Bk","Cf","Es","Fm","Md","No","Lr","Rf","Db","Sg","Bh","Hs","Mt","Ds","Rg","Uub","Uut","Uuq","Uup","Uuh","Uus","Uuo"]
atomicmass = [0.0,1.008, 4.003, 6.941, 9.012, 10.81, 12.01, 14.01, 16.00, 19.00, 20.18, 22.99, 24.31, 26.98, 28.09, 30.97, 32.07, 35.45, 39.95, 39.10, 40.08, 44.96, 47.87, 50.94, 52.00, 54.94, 55.84, 58.93, 58.69,
63.55, 65.39, 69.72, 72.61, 74.92, 78.96, 79.90, 83.80, 85.47, 87.62, 88.91, 91.22, 92.91, 95.94, 99.0, 101.07, 102.91, 106.42, 107.87, 112.41, 114.82, 118.71, 121.76, 127.60, 126.90, 131.29]
calendar=["","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"]
def digitalMonth(month):
digital = 0
for i in range(0,len(calendar)):
if calendar[i] in month.lower(): digital = i
return digital
def elementID(massno):
if massno < len(periodictable): return periodictable[massno]
else: return "XX"
def atomicnumber(element):
atomicno = 0
for i in range(0,len(periodictable)):
if element == periodictable[i]: atomicno = i
return atomicno
def bondiRadius(massno):
#Bondi van der Waals radii for all atoms from: Bondi, A. J. Phys. Chem. 1964, 68, 441-452, except hydrogen, which is taken from Rowland, R. S.; Taylor, R. J. Phys. Chem. 1996, 100, 7384-7391
#Radii that are not available in either of these publications have RvdW = 2.00 Angstrom
bondi = [0.0,1.09, 1.40, 1.82,2.00,2.00,1.70,1.55,1.52,1.47,1.54,2.27,1.73,2.00,2.10,1.80,1.80,1.75,1.88,2.75,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,1.63,1.40,1.39,1.87,2.00,1.85,1.90,
1.85,2.02,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,1.63,1.72,1.58,1.93,2.17,2.00,2.06,1.98,2.16,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,1.72,1.66,1.55,1.96,2.02,2.00,2.00,2.00,
2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,2.00,1.86]
if massno<len(bondi): radius = bondi[massno]
else: radius = 2.0
return radius
###############################################################
#Geometric calculations #######################################
def calcdist(atoma,atomb,coords):
x1=coords[atoma][0]
y1=coords[atoma][1]
z1=coords[atoma][2]
x2=coords[atomb][0]
y2=coords[atomb][1]
z2=coords[atomb][2]
ba = [x1-x2, y1-y2, z1-z2]
dist = math.sqrt(ba[0]*ba[0]+ba[1]*ba[1]+ba[2]*ba[2])
return dist
def calcangle(atoma,atomb,atomc,coords):
x1=coords[atoma][0]
y1=coords[atoma][1]
z1=coords[atoma][2]
x2=coords[atomb][0]
y2=coords[atomb][1]
z2=coords[atomb][2]
x3=coords[atomc][0]
y3=coords[atomc][1]
z3=coords[atomc][2]
ba = [x1-x2, y1-y2, z1-z2]
bc = [x3-x2, y3-y2, z3-z2]
angle = 180.0/math.pi*math.acos((ba[0]*bc[0]+ba[1]*bc[1]+ba[2]*bc[2])/(math.sqrt(ba[0]*ba[0]+ba[1]*ba[1]+ba[2]*ba[2])*math.sqrt(bc[0]*bc[0]+bc[1]*bc[1]+bc[2]*bc[2])))
return angle
def calcdihedral(atoma,atomb,atomc,atomd,coords):
x1=coords[atoma][0]
y1=coords[atoma][1]
z1=coords[atoma][2]
x2=coords[atomb][0]
y2=coords[atomb][1]
z2=coords[atomb][2]
x3=coords[atomc][0]
y3=coords[atomc][1]
z3=coords[atomc][2]
x4=coords[atomd][0]
y4=coords[atomd][1]
z4=coords[atomd][2]
ax= (y2-y1)*(z2-z3)-(z2-z1)*(y2-y3)
ay= (z2-z1)*(x2-x3)-(x2-x1)*(z2-z3)
az= (x2-x1)*(y2-y3)-(y2-y1)*(x2-x3)
bx= (y3-y2)*(z3-z4)-(z3-z2)*(y3-y4)
by= (z3-z2)*(x3-x4)-(x3-x2)*(z3-z4)
bz= (x3-x2)*(y3-y4)-(y3-y2)*(x3-x4)
nbx= (y2-y3)*(z4-z3)-(z2-z3)*(y4-y3)
nby= (z2-z3)*(x4-x3)-(x2-x3)*(z4-z3)
nbz= (x2-x3)*(y4-y3)-(y2-y3)*(x4-x3)
torsion=180.0/math.pi*math.acos((ax*bx+ay*by+az*bz)/(math.sqrt(ax*ax+ay*ay+az*az)*math.sqrt(bx*bx+by*by+bz*bz)))
sign=180.0/math.pi*math.acos((nbx*(x2-x1)+nby*(y2-y1)+nbz*(z2-z1))/(math.sqrt(nbx*nbx+nby*nby+nbz*nbz)*math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)+(z2-z1)*(z2-z1))))
if sign<90.0: torsion=torsion*-1.0
return torsion
###############################################################
# Filter post optimization - checks whether two conformers are identical on the basis of non-bonded distances and energy. Needs to consider equivalent coordinate descriptions
# also do enantiomers here
def checkSame(ConfSpec, CSearch, SearchParams, savedconf):
if not hasattr(ConfSpec, "CARTESIANS"): return 1
tordiff=0.0; besttordiff=180.0; sameval=0
if len(SearchParams.EQUI)==0:
#print "No equivalent coordinate descriptions"
torval1=getTorsion(ConfSpec)
#print ConfSpec.NAME
#print ConfSpec.CARTESIANS
#print torval1
#print CSearch.NAME[savedconf]
#print CSearch.CARTESIANS[savedconf]
#print CSearch.TORVAL[savedconf]
for x in range(0,len(torval1)):
difftor=math.sqrt((torval1[x]-CSearch.TORVAL[savedconf][x])*(torval1[x]-CSearch.TORVAL[savedconf][x]))
if difftor>180.0:
difftor=360.0-difftor
tordiff=tordiff + difftor*difftor
# print torval1[x], CSearch.TORVAL[savedconf][x], difftor
if len(torval1)!=0:
besttordiff=math.sqrt(tordiff/len(torval1))
#print "----------"
#print besttordiff
#print "----------"
else:
tempcart=[]
for i in range(0,len(ConfSpec.CARTESIANS)): tempcart.append(ConfSpec.CARTESIANS[i])
allposscoords=[tempcart]
#print len(allposscoords)
#print SearchParams.EQUI
equilist=[]
for i in range(0,len(SearchParams.EQUI)): equilist.append(SearchParams.EQUI[i])
for equivcoords in equilist:
equivstring=equivcoords.split(" ")
if len(equivstring)==3:
equilist.append(equivstring[0]+" "+equivstring[1])
equilist.append(equivstring[0]+" "+equivstring[2])
equilist.append(equivstring[1]+" "+equivstring[2])
#print equilist
for equivcoords in equilist:
#print equivcoords
equivstring=equivcoords.split(" ")
nequiv=len(equivstring)
if nequiv == 2:
equivloop=[]
for item in equivstring:
equivloop.append(int(item)-1)
for item in equivstring:
equivloop.append(int(item)-1)
for l in range(0,len(allposscoords)):
for i in range(1, nequiv):
orig=[]
swap=[]
for j in range(0,nequiv):
orig.append(equivloop[j])
swap.append(equivloop[i+j])
swappedcoords=[0]*len(ConfSpec.CARTESIANS)
for j in range(0,len(ConfSpec.CARTESIANS)):
swappedcoords[j]=allposscoords[l][j]
for k in range(0,nequiv):
if j == orig[k]:
#print "Interchanging coordinates",j, swap[k]
swappedcoords[j]=allposscoords[l][swap[k]]
#print swappedcoords[j]
#PossSpec = ConfSpec
#PossSpec.CARTESIANS = swappedcoords
#torval1=getTorsion(PossSpec)
#print torval1
allposscoords.append(swappedcoords)
#print "appending"
#print swappedcoords
#print len(allposscoords)
originaltorval=getTorsion(ConfSpec)
originalsum = 0.0
alteredsum = 0.0
for x in range(0,len(originaltorval)):
originalsum = originalsum + math.pow(originaltorval[x],2.0)
for poss in allposscoords:
#print "poss"
#for i in range(0,len(poss)):
# print ConfSpec.ATOMTYPES[i], poss[i][0], poss[i][1], poss[i][2]
PossSpec = ConfSpec
PossSpec.CARTESIANS = poss
torval1=getTorsion(PossSpec)
tordiff=0.0
alteredsum = 0.0
for y in range(0,len(torval1)):
alteredsum = alteredsum + math.pow(torval1[y],2.0)
if math.pow((originalsum-alteredsum),2.0) < 0.1:
print originalsum, alteredsum
print "comparing torsions"
for z in range(0,len(torval1)):
#print savedconf, "-", x, torval1[x], CSearch.TORVAL[savedconf][x]
difftor=math.sqrt((torval1[z]-CSearch.TORVAL[savedconf][z])*(torval1[z]-CSearch.TORVAL[savedconf][z]))
if difftor>180.0:
difftor=360.0-difftor
tordiff=tordiff + difftor*difftor
#print torval1[z], CSearch.TORVAL[savedconf][z], difftor
if len(torval1)!=0:
tordiff=math.sqrt(tordiff/len(torval1))
print tordiff
if tordiff<besttordiff:
besttordiff=tordiff
#this is a horrible hack which returns the cartesians back to before equivalent coordinate systems were considered....
ConfSpec.CARTESIANS = tempcart
#print " ----------"
#print " "+str(besttordiff)
#print " ----------"
#print ConfSpec.NAME, CSearch.NAME[savedconf], besttordiff
if besttordiff<SearchParams.COMP: sameval=sameval+1
return sameval
#Check the stereochemistry has not been changed
def checkchir(ConfSpec, MolSpec, CSearch, SearchParams):
epimerized = 0; epimatom = 0
for i in range(0,len(ConfSpec.CARTESIANS)):
if MolSpec.ATOMTYPES[i] == "C":
if len(MolSpec.CONNECTIVITY[i]) == 4:
#print "\nATOM", MolSpec.ATOMTYPES[i], (i),
abcd = []; types = []
for partners in MolSpec.CONNECTIVITY[i]:
abcd.append(int(partners.split("__")[0])-1)
types.append(MolSpec.ATOMTYPES[int(partners.split("__")[0])-1])
numh = 0
for type in types:
if type == "H": numh = numh + 1
if numh <= 1:
#print " Computing dihedral angle between", abcd
if math.fabs(calcdihedral(abcd[0],abcd[1],abcd[2],abcd[3],ConfSpec.CARTESIANS) - calcdihedral(abcd[0],abcd[1],abcd[2],abcd[3],MolSpec.CARTESIANS)) > 10.0:
print " POSSIBLY EPIMERIZED!",i, abcd, types
print calcdihedral(abcd[0],abcd[1],abcd[2],abcd[3],ConfSpec.CARTESIANS), calcdihedral(abcd[0],abcd[1],abcd[2],abcd[3],MolSpec.CARTESIANS)
epimerized = 1; epimatom = (i+1)
return [epimerized,epimatom]
#Check the connectivity and compare to the starting structure
def checkconn(ConfSpec, MolSpec, CSearch, SearchParams):
checkval=0
a = "X"; b = 0; c = "X"; d = 0
for i in range(0,len(ConfSpec.CARTESIANS)):
bondedatomlist=[]
for partners in MolSpec.CONNECTIVITY[i]: bondedatomlist.append(int(partners.split("__")[0])-1)
nonbondedlist=[]
for j in range(i+1,len(ConfSpec.CARTESIANS)):
bond=0
nonbondedlist.append(j)
for bondedatom in bondedatomlist:
#This deals with breaking existing bonds
if j==bondedatom:
#print (i+1), (j+1)
nonbondedlist.pop()
xdist=float(ConfSpec.CARTESIANS[i][0])-float(ConfSpec.CARTESIANS[j][0])
ydist=float(ConfSpec.CARTESIANS[i][1])-float(ConfSpec.CARTESIANS[j][1])
zdist=float(ConfSpec.CARTESIANS[i][2])-float(ConfSpec.CARTESIANS[j][2])
totdist=math.sqrt(xdist*xdist+ydist*ydist+zdist*zdist)
#print totdist
origxdist=float(CSearch.CARTESIANS[0][i][0])-float(CSearch.CARTESIANS[0][j][0])
origydist=float(CSearch.CARTESIANS[0][i][1])-float(CSearch.CARTESIANS[0][j][1])
origzdist=float(CSearch.CARTESIANS[0][i][2])-float(CSearch.CARTESIANS[0][j][2])
origdist=math.sqrt(origxdist*origxdist+origydist*origydist+origzdist*origzdist)
#print origdist
if (totdist-origdist)>0.5*origdist:
#print "Looks like ",MolSpec.ATOMTYPES[i],(i+1)," has broken from ",MolSpec.ATOMTYPES[j],(j+1)
a = MolSpec.ATOMTYPES[i]; b = (i+1); c = MolSpec.ATOMTYPES[j]; d = (j+1)
checkval=checkval+1
#if HSWAP!=0:
# if MolSpec.ATOMTYPES[i]=="N" or MolSpec.ATOMTYPES[i]=="O" or MolSpec.ATOMTYPES[i]=="S":
# if MolSpec.ATOMTYPES[j]=="H":
#Has an acidic proton swapped positions?
#for k in range(0,len(ConfSpec.CARTESIANS)):
#if k!=i and k!=j:
#hxdist=float(ConfSpec.CARTESIANS[k][0])-float(ConfSpec.CARTESIANS[j][0])
#hydist=float(ConfSpec.CARTESIANS[k][1])-float(ConfSpec.CARTESIANS[j][1])
#hzdist=float(ConfSpec.CARTESIANS[k][2])-float(ConfSpec.CARTESIANS[j][2])
#htotdist=math.sqrt(hxdist*hxdist+hydist*hydist+hzdist*hzdist)
#print htotdist
#if htotdist<0.5*(bondiradius(atomicnumber(MolSpec.ATOMTYPES[i]))+bondiradius(atomicnumber(MolSpec.ATOMTYPES[j]))):
#print "Looks like ",MolSpec.ATOMTYPES[i],(i+1)," has broken from ",MolSpec.ATOMTYPES[j],(j+1)
# breakbond.append([i+1,j+1])
# checkval=checkval-1
# if MolSpec.ATOMTYPES[j]=="N" or MolSpec.ATOMTYPES[j]=="O" or MolSpec.ATOMTYPES[j]=="S":
# if MolSpec.ATOMTYPES[i]=="H":
#Has an acidic proton swapped positions?
#for k in range(0,len(ConfSpec.CARTESIANS)):
#if k!=j and k!=i:
#hxdist=float(ConfSpec.CARTESIANS[k][0])-float(ConfSpec.CARTESIANS[i][0])
#hydist=float(ConfSpec.CARTESIANS[k][1])-float(ConfSpec.CARTESIANS[i][1])
#hzdist=float(ConfSpec.CARTESIANS[k][2])-float(ConfSpec.CARTESIANS[i][2])
#htotdist=math.sqrt(hxdist*hxdist+hydist*hydist+hzdist*hzdist)
#if htotdist<0.5*(bondiradius(atomicnumber(MolSpec.ATOMTYPES[i]))+bondiradius(atomicnumber(MolSpec.ATOMTYPES[k]))):
#print "Looks like ",MolSpec.ATOMTYPES[i],(i+1)," has broken from ",MolSpec.ATOMTYPES[j],(j+1)
#breakbond.append([i+1,j+1])
#checkval=checkval-1
#This deals with forming new bonds
for j in nonbondedlist:
xdist=float(ConfSpec.CARTESIANS[i][0])-float(ConfSpec.CARTESIANS[j][0])
ydist=float(ConfSpec.CARTESIANS[i][1])-float(ConfSpec.CARTESIANS[j][1])
zdist=float(ConfSpec.CARTESIANS[i][2])-float(ConfSpec.CARTESIANS[j][2])
totdist=math.sqrt(xdist*xdist+ydist*ydist+zdist*zdist)
if totdist<0.5*(bondiRadius(atomicnumber(MolSpec.ATOMTYPES[i]))+bondiRadius(atomicnumber(MolSpec.ATOMTYPES[j]))):
print "Looks like ",MolSpec.ATOMTYPES[i],(i+1),":",MolSpec.ATOMTYPES[j],(j+1),"have formed a new bond"
checkval=checkval+1
if SearchParams.NNBO == 0:
if MolSpec.ATOMTYPES[i]=="N" or MolSpec.ATOMTYPES[i]=="O" or MolSpec.ATOMTYPES[i]=="S":
if MolSpec.ATOMTYPES[j]=="H": checkval=checkval-1
if MolSpec.ATOMTYPES[j]=="N" or MolSpec.ATOMTYPES[j]=="O" or MolSpec.ATOMTYPES[j]=="S":
if MolSpec.ATOMTYPES[i]=="H": checkval=checkval-1
return [checkval, str(a), str(b),str(c),str(d)]
# Returns a matrix of dihedral angles (with sign) given connecitivty and coordinates in numerical order. Only between heavy atoms and NH,OH and SH protons
def getTorsion(MolSpec):
torval=[]
for atoma in range(0,len(MolSpec.CARTESIANS)):
for partner1 in MolSpec.CONNECTIVITY[atoma]:
atomb = int(partner1.split("__")[0])-1
for partner2 in MolSpec.CONNECTIVITY[atomb]:
atomc = int(partner2.split("__")[0])-1
if atomc!=atoma:
for partner3 in MolSpec.CONNECTIVITY[atomc]:
atomd = int(partner3.split("__")[0])-1
if atomd>atoma and atomd!=atomb:
if MolSpec.ATOMTYPES[atoma]=="H" and MolSpec.ATOMTYPES[atomb]=="C": ignore=1
elif MolSpec.ATOMTYPES[atomd]=="H" and MolSpec.ATOMTYPES[atomc]=="C": ignore=1
else:
endA=""
endD=""
for endAatom in MolSpec.CONNECTIVITY[atomb]:
if (int(endAatom.split("__")[0])-1)!=atomc:
endA = endA+MolSpec.ATOMTYPES[int(endAatom.split("__")[0])-1]
for endDatom in MolSpec.CONNECTIVITY[atomc]:
if (int(endDatom.split("__")[0])-1)!=atomb:endD = endD+MolSpec.ATOMTYPES[int(endDatom.split("__")[0])-1]
if endA!="HHH" and endD!="HHH":
torsion=calcdihedral(atoma,atomb,atomc,atomd,MolSpec.CARTESIANS)
#print (MolSpec.ATOMTYPES[atoma],atoma, MolSpec.ATOMTYPES[atomb],atomb, MolSpec.ATOMTYPES[atomc],atomc, MolSpec.ATOMTYPES[atomd],atomd, torsion)
torval.append(torsion)
return torval
# Find how many separate molecules there are
def howmanyMol(bondmatrix,startatom):
molecule1=[]
count = 1
stop=0
currentatom=[]
nextlot=[]
currentatom.append([-1])
currentatom.append([startatom])
while count<100 and stop==0:
nextlot=[]
for onecurrentatom in currentatom[count]:
for partners in bondmatrix[onecurrentatom]:
inf = partners.split("__")
for n in range(0,len(inf)/2):
noback=0
for onepreviousatom in currentatom[count-1]:
if (int(inf[2*n])-1)==onepreviousatom: # Can't go back - make sure atom isn't in previous currentatom
noback=noback+1
if noback==0:
nextlot.append(int(inf[2*n])-1)
count=count+1
if len(nextlot)==0:
stop=stop+1
currentatom.append(nextlot)
for i in range(0,len(bondmatrix)):
for j in range(0,len(currentatom)):
for atom in currentatom[j]:
if atom==i:
same = 0
for alreadyfound in molecule1:
if atom == alreadyfound: same = same + 1
if same ==0: molecule1.append(atom)
return molecule1
#Repeat for all starting atoms. How may different molecules are there?
# Looks for rotatable single bonds. Requires connectivity information. Uninteresting torsions (e.g. methyl groups) are excluded
class Assign_Variables:
def __init__(self, MolSpec, Params, log):
# Find out if there are separate molecules
self.MOLATOMS = [howmanyMol(MolSpec.CONNECTIVITY,0)]
for i in range(1,MolSpec.NATOMS):
k=0
for j in range(0,len(self.MOLATOMS)):
if howmanyMol(MolSpec.CONNECTIVITY,i)[0] == self.MOLATOMS[j][0]:
k=k+1
if k == 0: self.MOLATOMS.append(howmanyMol(MolSpec.CONNECTIVITY,i))
self.NMOLS = len(self.MOLATOMS)
# Find rotatable bonds
self.ETOZ = []
if len(Params.ETOZ) > 0:
self.ETOZ.append([int(Params.ETOZ[0].split()[0]), int(Params.ETOZ[0].split()[1])])
self.TORSION = []
for i in range(0, MolSpec.NATOMS):
for partner in MolSpec.CONNECTIVITY[i]:
nextatom = int(partner.split("__")[0])-1
bondorder = float(partner.split("__")[1])
if nextatom>i: # Avoid duplication
fixed=0
for fix in Params.FIXT:
fixA=int(fix.split(" ")[0])
fixB=int(fix.split(" ")[1])
if fixA == i+1 and fixB == nextatom+1: fixed=fixed+1
if fixB == i+1 and fixA == nextatom+1: fixed=fixed+1
# Must be single bonds not specified as fixed
if bondorder == 1.0 and fixed == 0:
terminal = 0
CX3 = 0
nextCX3 = 0
for member in [i, nextatom]:
nextatomstring = ""
nextnextatomstring = ""
nextnumh = 0
templist1 = []
# Each atom must have other atoms attached
if len(MolSpec.CONNECTIVITY[member])>1:
terminal = terminal + 1
for nextpartner in MolSpec.CONNECTIVITY[member]:
for z in range(0,len(nextpartner.split("__"))/2):
nextnextatom = int(nextpartner.split("__")[2*z])-1
if nextnextatom != i and nextnextatom != nextatom:
nextatomstring=nextatomstring+MolSpec.ATOMTYPES[nextnextatom]
templist1.append(nextnextatom)
for nextnextpartner in MolSpec.CONNECTIVITY[nextnextatom]:
for v in range(0,len(nextnextpartner.split("__"))/2):
nextnextnextatom = int(nextnextpartner.split("__")[2*v])-1
if nextnextnextatom!=member:
nextnextatomstring=nextnextatomstring+MolSpec.ATOMTYPES[nextnextnextatom]
#Checks if either of two connected atoms are CX3 groups
if nextatomstring.find("HHH") > -1 or nextatomstring.find("FFF") > -1 or nextatomstring.find("ClClCl") >- 1 or nextatomstring.find("III")>-1: CX3 = CX3 + 1
#Checks if either of two connected atoms are bonded to three identical CX3 or NX3 or PX3 or SiX3 groups
if nextatomstring.find("CCC")>-1 or nextatomstring.find("NNN")>-1 or nextatomstring.find("PPP")>-1 or nextatomstring.find("SiSiSi")>-1:
if nextnextatomstring.find("HHHHHHHHH")>-1 or nextnextatomstring.find("FFFFFFFFF")>-1 or nextnextatomstring.find("ClClClClClClClClCl")>-1 or nextnextatomstring.find("IIIIIIIII")>-1: nextCX3=nextCX3+1
# Given the above criteria are satisfied, we also need to make sure the torsion isn't part of a ring, as they must be dealt with differently
if CX3 == 0 and nextCX3 == 0 and terminal == 2:
count = 1
mem = 0
currentatom=[[i],[nextatom]]
nextlot=[]
while count<1000 and mem==0:
nextlot=[]
for onecurrentatom in currentatom[count]:
for partners in MolSpec.CONNECTIVITY[onecurrentatom]:
inf = partners.split("__")
for n in range(0,len(inf)/2):
noback=0
for onepreviousatom in currentatom[count-1]:
if (int(inf[2*n])-1) == onepreviousatom: noback = noback + 1
if (int(inf[2*n])-1) == nextatom: noback = noback + 1
if noback == 0:
if (int(inf[2*n])-1) == i: mem = count+1
nextlot.append(int(inf[2*n])-1)
count=count+1
currentatom.append(nextlot)
if mem == 0: self.TORSION.append([i,nextatom])
#if mem>5: #Only larger than 5mem rings are interesting conformationally!
#ring.append([x,nextatom])
self.MCNV = len(self.TORSION)
#A random number of changes are made to generate each new structure. Chang, Guida and Still found between 2 and ntors-1 to work well
self.MCNVmin = 2
self.MCNVmax = self.MCNV - 1
#However if there is only one or two rotatable bonds, adjust the upper limit to ntors
if self.MCNVmin > self.MCNV: self.MCNVmin = self.MCNV
if self.MCNVmax < self.MCNVmin: self.MCNVmax = self.MCNVmin
#Ring variables - not coded yet
self.RING = []
self.MCRI = 0
#If there is nothing to vary then exit
if self.MCNV == 0 and self.MCRI == 0 and self.NMOLS == 1: print ("\nFATAL ERROR: Found zero rotatable torsions and only one molecule in %s \n"%MolSpec.NAME); sys.exit()
#Translate a random number of molecules by a given vector
def translateMol(FMVAR, ConfSpec):
newcoord=[]
for i in range(0,len(ConfSpec.CARTESIANS)): newcoord.append(ConfSpec.CARTESIANS[i])
#Random intermolecular vectors are altered
nrand = random.randint(1, FMVAR.NMOLS-1)
movemol = random.sample(xrange(0,FMVAR.NMOLS), nrand)
for mol in movemol:
trans = [random.uniform(-1.0,1.0), random.uniform(-1.0,1.0), random.uniform(-1.0,1.0)]
for atom in FMVAR.MOLATOMS[mol]:
newcoord[atom]=[newcoord[atom][0]+trans[0],newcoord[atom][1]+trans[1],newcoord[atom][2]+trans[2]]
return newcoord
#Rotate a molecule about its centre of mass
def rotateMol(FMVAR, ConfSpec):
newcoord=[]
for i in range(0,len(ConfSpec.CARTESIANS)): newcoord.append(ConfSpec.CARTESIANS[i])
#Random molecules are spun about their centre of mass
nrand = random.randint(1, FMVAR.NMOLS-1)
movemol = random.sample(xrange(0,FMVAR.NMOLS), nrand)
for mol in movemol:
rot = [random.randint(90,180), random.randint(90,180), random.randint(90,180)]
coords1 = []
types1 = []
mass1 = 0.0
#print "Spinning molecule",(k+1),"in",savedname[startgeom],"about its centre of mass by",xrot,yrot,zrot
for atom in FMVAR.MOLATOMS[mol]:
coords1.append(newcoord[atom])
types1.append(ConfSpec.ATOMTYPES[atom])
#print ConfSpec.ATOMTYPES[atom]
#print atomicnumber(ConfSpec.ATOMTYPES[atom])
#print atomicmass[atomicnumber(ConfSpec.ATOMTYPES[atom])]
mass1 = mass1 + atomicmass[atomicnumber(ConfSpec.ATOMTYPES[atom])]
#print mass1
com1x=0.0
com1y=0.0
com1z=0.0
for i in range(0,len(coords1)):
com1x=com1x+coords1[i][0]*atomicmass[atomicnumber(types1[i])]
com1y=com1y+coords1[i][1]*atomicmass[atomicnumber(types1[i])]
com1z=com1z+coords1[i][2]*atomicmass[atomicnumber(types1[i])]
c_o_mass = [com1x/mass1, com1y/mass1, com1z/mass1]
xvector=[c_o_mass[0]+1.0, c_o_mass[1], c_o_mass[2], rot[0]]
yvector=[c_o_mass[0], c_o_mass[1]+1.0, c_o_mass[2], rot[1]]
zvector=[c_o_mass[0], c_o_mass[1], c_o_mass[2]+1.0, rot[2]]
rotvector=[xvector,yvector,zvector]
for vector in rotvector:
magvector=math.sqrt(vector[0]*vector[0]+vector[1]*vector[1]+vector[2]*vector[2])
unitvector=[vector[0]/magvector,vector[1]/magvector,vector[2]/magvector]
theta=vector[3]/180.0*math.pi
for atom in FMVAR.MOLATOMS[mol]:
dotproduct=unitvector[0]*(float(newcoord[atom][0])-float(c_o_mass[0]))+unitvector[1]*(float(newcoord[atom][1])-float(c_o_mass[1]))+unitvector[2]*(float(newcoord[atom][2])-float(c_o_mass[2]))
centre=[float(c_o_mass[0])+dotproduct*unitvector[0],float(c_o_mass[1])+dotproduct*unitvector[1],float(c_o_mass[2])+dotproduct*unitvector[2]]
v=[float(newcoord[atom][0])-centre[0],float(newcoord[atom][1])-centre[1],float(newcoord[atom][2])-centre[2]]
d=math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])
px=v[0]*math.cos(theta)+v[1]*math.sin(theta)*unitvector[2]-v[2]*math.sin(theta)*unitvector[1]
py=v[1]*math.cos(theta)+v[2]*math.sin(theta)*unitvector[0]-v[0]*math.sin(theta)*unitvector[2]
pz=v[2]*math.cos(theta)+v[0]*math.sin(theta)*unitvector[1]-v[1]*math.sin(theta)*unitvector[0]
newv=[px+centre[0],py+centre[1],pz+centre[2]]
newdist=math.sqrt(px*px+py*py+pz*pz)
newcoord[atom]=newv
return newcoord
#Rotates specified single bond through a specified angle, returning the modified coordinates
def AtomRot(MolSpec, torsion, geometry):
atomA = geometry[torsion[0]-1]
atomB = geometry[torsion[1]-1]
theta = float(torsion[2])/180.0*math.pi
cyclic = 0
newcoord=[]
if cyclic == 0:
vectorAB = [float(atomB[0])-float(atomA[0]),float(atomB[1])-float(atomA[1]),float(atomB[2])-float(atomA[2])]
distAB = math.sqrt(vectorAB[0]*vectorAB[0]+vectorAB[1]*vectorAB[1]+vectorAB[2]*vectorAB[2])
unitAB = [vectorAB[0]/distAB,vectorAB[1]/distAB,vectorAB[2]/distAB]
count = 1
stop=0
currentatom=[]
nextlot=[]
currentatom.append([torsion[0]-1])
currentatom.append([torsion[1]-1])
while count<100 and stop==0:
nextlot=[]
for onecurrentatom in currentatom[count]:
for partners in MolSpec.CONNECTIVITY[onecurrentatom]:
inf = partners.split("__")
for n in range(0,len(inf)/2):
noback=0
for onepreviousatom in currentatom[count-1]:
if (int(inf[2*n])-1)==onepreviousatom: noback=noback+1
for onepreviousatom in currentatom[count]:
if (int(inf[2*n])-1)==onepreviousatom: noback=noback+1
if noback==0: nextlot.append(int(inf[2*n])-1)
count=count+1
#print count
if len(nextlot) == 0:stop=stop+1
currentatom.append(nextlot)
#print currentatom
for i in range(0,len(geometry)):
#print i,geometry[i]
newcoord.append(geometry[i])
for i in range(2,len(currentatom)-1):
for atom in currentatom[i]:
dotproduct = unitAB[0]*(float(geometry[atom][0]) - float(atomA[0])) + unitAB[1]*(float(geometry[atom][1]) - float(atomA[1])) + unitAB[2]*(float(geometry[atom][2]) - float(atomA[2]))
centre = [float(atomA[0]) + dotproduct*unitAB[0], float(atomA[1]) + dotproduct*unitAB[1], float(atomA[2]) + dotproduct*unitAB[2]]
v = [float(geometry[atom][0]) - centre[0], float(geometry[atom][1]) - centre[1], float(geometry[atom][2]) - centre[2]]
d = math.sqrt(v[0]*v[0]+v[1]*v[1]+v[2]*v[2])
px = v[0]*math.cos(theta) + v[1]*math.sin(theta)*unitAB[2] - v[2]*math.sin(theta)*unitAB[1]
py = v[1]*math.cos(theta) + v[2]*math.sin(theta)*unitAB[0] - v[0]*math.sin(theta)*unitAB[2]
pz = v[2]*math.cos(theta) + v[0]*math.sin(theta)*unitAB[1] - v[1]*math.sin(theta)*unitAB[0]
newv = [px + centre[0], py + centre[1], pz + centre[2]]
newdist = math.sqrt(px*px + py*py + pz*pz)
newcoord[int(atom)]=newv
if len(newcoord) !=0 : return newcoord
else:
print "didn't do anything!!!"
for i in range(0,len(geometry)): newcoord.append([0.0,0.0,0.0])
return newcoord
class makemirror:
def __init__(self, CONFSPEC):
self.CARTESIANS = []
for cart in CONFSPEC.CARTESIANS:
self.CARTESIANS.append([-1.0*cart[0], cart[1], cart[2]])
self.ATOMTYPES = CONFSPEC.ATOMTYPES
self.CONNECTIVITY = CONFSPEC.CONNECTIVITY
self.NAME = CONFSPEC.NAME
class OrderConfs:
def __init__(self, CSEARCH, SEARCHPARAMS, start, log):
#Order the low energy conformers by energy
self.CARTESIANS = []
self.NAME = []
self.TIMESFOUND = []
self.USED = []
self.CPU = []
self.TORVAL =[]
self.MATCHEDALREADY = []
for j in range(0, CSEARCH.NSAVED): self.MATCHEDALREADY.append(0)
self.ENERGY = sorted(CSEARCH.ENERGY)
for j in range(0, CSEARCH.NSAVED):
for i in range(0, CSEARCH.NSAVED):
if CSEARCH.ENERGY[i] == self.ENERGY[j] and self.MATCHEDALREADY[i] == 0:
match = i
self.MATCHEDALREADY[match] = 1
self.CARTESIANS.append(CSEARCH.CARTESIANS[match])
self.NAME.append(CSEARCH.NAME[match])
self.TIMESFOUND.append(CSEARCH.TIMESFOUND[match])
self.USED.append(CSEARCH.USED[match])
self.CPU.append(CSEARCH.CPU[match])
self.TORVAL.append(CSEARCH.TORVAL[match])
CSEARCH.CARTESIANS = self.CARTESIANS
CSEARCH.NAME = self.NAME
CSEARCH.ENERGY = self.ENERGY
CSEARCH.TIMESFOUND = self.TIMESFOUND
CSEARCH.USED = self.USED
CSEARCH.CPU = self.CPU
CSEARCH.TORVAL = self.TORVAL
class AddConformer:
def __init__(self, CSEARCH, CONFSPEC):
CSEARCH.NAME.append(CONFSPEC.NAME)
CSEARCH.ENERGY.append(CONFSPEC.ENERGY)
CSEARCH.CARTESIANS.append(CONFSPEC.CARTESIANS)
CSEARCH.CONNECTIVITY.append(CONFSPEC.CONNECTIVITY)
CSEARCH.TIMESFOUND.append(1)
CSEARCH.USED.append(0)
CSEARCH.CPU.append(CONFSPEC.CPU)
CSEARCH.TORVAL.append(getTorsion(CONFSPEC))
CSEARCH.NSAVED = CSEARCH.NSAVED + 1
class RemoveConformer:
def __init__(self, CSEARCH, todel):
j=0
for i in range(0,len(CSEARCH.NAME)): print CSEARCH.NAME[i], CSEARCH.ENERGY[i]
print todel, len(todel),
cutoff = (len(CSEARCH.NAME)-len(todel))
print cutoff
#print len(CSEARCH.NAME)-len(todel)
newtodel=[]
for i in range(len(todel)-1, -1, -1): newtodel.append(todel[i])
#print newtodel
#print len(CSEARCH.NAME), CSEARCH.NAME
print CSEARCH.NAME[cutoff:]
print CSEARCH.NAME[:cutoff]
for i in range(0,len(todel)):
#print i, todel[i], CSEARCH.TIMESFOUND[todel[i]]
CSEARCH.NREJECT = CSEARCH.NREJECT + CSEARCH.TIMESFOUND[todel[i]]
del CSEARCH.NAME[cutoff:]
#print len(CSEARCH.NAME), CSEARCH.NAME
del CSEARCH.ENERGY[cutoff:]
#print len(CSEARCH.ENERGY), CSEARCH.ENERGY
del CSEARCH.CARTESIANS[cutoff:]
del CSEARCH.CONNECTIVITY[cutoff:]
del CSEARCH.USED[cutoff:]
del CSEARCH.CPU[cutoff:]
del CSEARCH.TIMESFOUND[cutoff:]
del CSEARCH.TORVAL[cutoff:]
print "AFTER REMOVAL"
for i in range(0,len(CSEARCH.NAME)): print CSEARCH.NAME[i], CSEARCH.ENERGY[i]
#print len(CSEARCH.CONNECTIVITY),len(CSEARCH.USED), len(CSEARCH.CPU), len(CSEARCH.TIMESFOUND), len(CSEARCH.TORVAL)
CSEARCH.NSAVED = len(CSEARCH.NAME)
class CleanAfterJob:
def __init__(self, Job, Confspec, samecheck, toohigh, isomerize):
try:
for suffix in [".com", ".mop", ".arc", ".temp", ".end", ".chk", ".joblog", ".csh", ".errlog"]:
if os.path.exists(Confspec.NAME+suffix): os.remove(Confspec.NAME+suffix)
# If discarded remove the outfile as well
if isJobFinished(Job, Confspec) != 1 or samecheck > 0 or toohigh == 1 or isomerize == 1:
if os.path.exists(Confspec.NAME+".out"): os.remove(Confspec.NAME+".out")
except: pass
class CleanUp:
def __init__(self, CSearch, SearchParams, filein, log):
# Create a tarball of low energy outfiles
try:
# First open previous incarnation of the tarfile
if os.path.isfile(filein+"_fm.tgz") == 1:
tar = tarfile.open(filein+"_fm.tgz", "r:gz")
prevfiles = tar.getnames()
for prev in prevfiles: tar.extract(prev, path="")
os.remove(filein+"_fm.tgz")
# Now create and write
tar = tarfile.open(filein+"_fm.tgz", "w|gz")
for saved in CSEARCH.NAME:
#print "TARRING", saved+".out"
if os.path.isfile(saved+".out") == 1: tar.add(saved+".out")
#print "found and zipping", saved+".out"
#print commands.getoutput("ls -l -t "+filein+"_fm.tgz")
if os.path.isfile(saved+".log") == 1: tar.add(saved+".log")
#print "found and zipping", saved+".out"
#print commands.getoutput("ls -l -t "+filein+"_fm.tgz")
time.sleep(0.1)
tar.close()
for i in range(0,CSearch.STEP*SearchParams.POOL+1):
if os.path.isfile(filein+"_step_"+str(i)+".out") == 1: os.remove(filein+"_step_"+str(i)+".out")
#print "found and deleting", filein+"_step_"+str(i)+".out"
if os.path.isfile(filein+"_step_"+str(i)+".log") == 1: os.remove(filein+"_step_"+str(i)+".log")
except: print "ERROR IN ZIPPING!!!"
def reName(dir, oldname, newname):
files=commands.getstatusoutput("ls "+dir+"/*"+oldname+"*")
if files[0] == 0:
for file in string.split(files[1],'\n'):
newfile = file.replace(oldname, newname)
print "Renaming",file,"to",newfile
commands.getoutput("mv "+file+" "+newfile)
else:
print "No files Found"
# Set an executable
class SETUPEXE:
def __init__(self, executable):
modify = "false"
if os.path.exists(executable):
var = raw_input("\no Path to Mopac executable seem to be ok, do you really want to change this? ... ")
if var.lower() == "y" or var.lower() == "": modify = "true"
else: print "\nExiting"; sys.exit(1)
else: modify = "true"
if modify == "true":
executable = ''
enter_values = "true"
while enter_values == "true":
fmlocation = raw_input("\no Enter location of FullMonte ($FULL_MONTE_DIR), including full path ... ")
if os.path.exists(fmlocation):
enter_values = "false"
else: print "\no Wrong path, please repeat the procedure"
enter_values = "true"
while enter_values == "true":
executable = raw_input("\no Enter filename of mopac executable, including full path ... ")
if os.path.exists(executable):