forked from sanha0213/VRAI-selectivity
-
Notifications
You must be signed in to change notification settings - Fork 1
/
VRAI-selectivity_v4.py
1666 lines (1275 loc) · 61.5 KB
/
VRAI-selectivity_v4.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
'''
Filename: VRAI-selectivity.py
Description:
- Predicts Major and Minor products from two transition states in reaction involving valley ridge inflections
- In order for this code to work the Gaussian frequency calculation must be run with freq=hpmodes keyword. This will ask Gaussian to print the eigenvectors to 5 significant figures.
Usage:
Algorithm Summary:
1. Import TS1 and TS2 structures
2. Align TS1 and TS2 to minimise RMSD
3. Extract TS1 and TS2 imaginary eigenvectors
4. Translate TS2 eigenvector according to the aligned TS2 geometry
5. Find u
6. Perform QRC from g+ub (i.e. TS2 structure displaced by u in the direction of imag freq vector)
@Sanha Lee
Dec 2018
'''
############################################################
# Import Modules
############################################################
import numpy as np
import argparse
import os
import math
import sys
from rdkit import Chem
import bisect
import logging
from datetime import datetime
import itertools
############################################################
# Main Code
############################################################
def main1(filename1, filename2, filename3, filename4, filename5, filename6, filename7, filename8, intermediate_option, weight_option):
code_name = 'VRAI-selectivity_v3_'
logging.basicConfig(filename=code_name+filename1[:-4]+'.log', level=logging.DEBUG, format='%(message)s', filemode='w')
datetime_now = datetime.now()
formatted_datetime = datetime_now.strftime("%Y %b %d %H:%M:%S")
print ''
print '***********************************'
print ''
print code_name
print ''
print 'Python code to predict selectivity'
print '@author: Sanha Lee'
print 'Run date: '+formatted_datetime
print ''
print 'Created: '+code_name+filename1[:-4]+'.log'
print ''
print '***********************************'
print ''
logging.info('\n')
logging.info('***********************************\n')
logging.info(code_name+'\n')
logging.info('Python code to predict selectivity')
logging.info('@author: Sanha Lee')
logging.info('University of Cambridge')
logging.info('Run date: '+formatted_datetime+'\n')
logging.info('***********************************\n')
logging.info('Reading TS1: '+filename1)
logging.info('Reading INT: '+filename2)
logging.info('Reading P1: '+filename3)
logging.info('Reading P2: '+filename4)
logging.info('Reading TS1 freq: '+filename5)
logging.info('Reading INT freq: '+filename6+'\n')
if filename7 == None and filename8 == None:
logging.info('')
logging.info('No file detected as TS2A and TS2B inputs')
else:
logging.info('')
logging.info('Inputs detected for TS2A and TS2B')
logging.info('Reading TS2A freq: '+filename7)
logging.info('Reading TS2B freq: '+filename8)
logging.info('')
atoms1, geometries1 = ReadGeometries(filename1)
atoms2, geometries2 = ReadGeometries(filename2)
atoms3, geometries3 = ReadGeometries(filename3)
atoms4, geometries4 = ReadGeometries(filename4)
logging.info('No. of Atoms: '+str(len(atoms1))+'\n')
equalweightslist = SetEqualWeights(atoms1)
trueweightslist = []
WeightsToUse = equalweightslist[:]
TempToUse = 298.0
# -- Change weights for alignment if necessary
if weight_option == True:
logging.info('Alignment weight option is set to atomic weights')
for atom in atoms1:
trueweightslist += [GetAtomNum(atom)]
WeightsToUse = trueweightslist[:]
else:
logging.info('Alignment weight option is set equal for all atoms')
rdkitmolTS1 = Chem.MolFromMolFile(filename1, removeHs=False, strictParsing=False)
if not rdkitmolTS1:
logging.error("Could not create RDKIT mol for: ",filename1)
logging.error('Terminating Program')
sys.exit()
else:
logging.info('RDKIT Mol object successfully created for: '+filename1)
logging.info(rdkitmolTS1)
rdkitmolTS2 = Chem.MolFromMolFile(filename2, removeHs=False, strictParsing=False)
if not rdkitmolTS2:
logging.error("Could not create mol for: ",filename2)
logging.error('Terminating Program')
sys.exit()
else:
logging.info('Mol object successfully created for: '+filename2)
logging.info(rdkitmolTS2)
rdkitmolP1 = Chem.MolFromMolFile(filename3, removeHs=False, strictParsing=False)
if not rdkitmolP1:
logging.error("Could not create mol for: "+filename3)
logging.error('Terminating Program')
sys.exit()
else:
logging.info('Mol object successfully created for: '+filename3)
logging.info(rdkitmolP1)
rdkitmolP2 = Chem.MolFromMolFile(filename4, removeHs=False, strictParsing=False)
if not rdkitmolP2:
logging.error("Could not create mol for: "+filename4)
logging.error('Terminating Program')
sys.exit()
else:
logging.info('Mol object successfully created for: '+filename4)
logging.info(rdkitmolP2)
# -- Identify Orthogonal Bonds
P1bonds = ExtractBonds(rdkitmolP1, atoms1)
P2bonds = ExtractBonds(rdkitmolP2, atoms1)
TS1bonds = ExtractBonds(rdkitmolTS1, atoms1)
logging.info('')
logging.info('P1bonds:')
for item in P1bonds:
logging.info(str(item[0])+'-'+str(item[1]))
logging.info('')
logging.info('P2bonds:')
for item in P2bonds:
logging.info(str(item[0])+'-'+str(item[1]))
unidenticalP1P2, unidenticalP2P1 = IdentifyChangedBonds(P1bonds, P2bonds)
unidenticalTS1P1, unidenticalP1TS1 = IdentifyChangedBonds(TS1bonds, P1bonds)
unidenticalTS1P2, unidenticalP2TS1 = IdentifyChangedBonds(TS1bonds, P2bonds)
# changed_bonds1 = bonds in bondlist1 which does not exist in bondlist2
# changed_bonds2 = bonds in bondlist2 which does not exist in bondlist1
logging.info('')
logging.info('unidenticalP1P2: '+str(unidenticalP1P2))
logging.info('unidenticalP2P1: '+str(unidenticalP2P1))
logging.info('unidenticalTS1P1: '+str(unidenticalTS1P1))
logging.info('unidenticalTS1P2: '+str(unidenticalTS1P2))
logging.info('unidenticalP1TS1: '+str(unidenticalP1TS1))
logging.info('unidenticalP2TS1: '+str(unidenticalP2TS1))
orthbond1list = []
orthbond2list = []
newunidenticalP1TS1 = []
newunidenticalTS1P1 = []
newunidenticalP2TS1 = []
newunidenticalTS1P2 = []
# -- Remove Duplicated bonds in all lists
for item in unidenticalP1TS1:
if item in unidenticalP1P2:
pass
else:
newunidenticalP1TS1 += [item]
for item in unidenticalTS1P1:
if item in unidenticalP1P2 or item in unidenticalP1TS1:
pass
else:
newunidenticalTS1P1 += [item]
for item in unidenticalP2TS1:
if item in unidenticalP2P1:
pass
else:
newunidenticalP2TS1 += [item]
for item in unidenticalTS1P2:
if item in unidenticalP2P1 or item in unidenticalP2TS1:
pass
else:
newunidenticalTS1P2 += [item]
# -- Rank the bond differences found
BondrankP1 = []
BondrankP2 = []
if intermediate_option == True:
logging.info('')
logging.info('Intermediate option activated:')
logging.info('Combining unidentical P1/P2 bonds with unidentical P1/TS1 and P2/TS1 then ranking')
P1combinations = unidenticalP1P2 + unidenticalP1TS1
P2combinations = unidenticalP2P1 + unidenticalP2TS1
permutations_P1combrank, permutations_P2combrank = RankBonds(P1combinations, P2combinations, geometries1, geometries2, geometries3, geometries4)
BondrankP1 = BondrankP1 + permutations_P1combrank
BondrankP2 = BondrankP2 + permutations_P2combrank
else:
logging.info('')
logging.info('Intermediate option unactivated:')
logging.info('Unidentical P1/P2 bonds takes highest priority followed by TS1 unidentical bonds')
# CaseA: When the length of B(P1|P2) >= 1 or B(P2|P1) >= 1
logging.info('')
logging.info('Case when B(P1|P2) >= 1 or B(P2|P1) >= 1')
permutationsP1P2rank, permutationsP2P1rank = RankBonds(unidenticalP1P2, unidenticalP2P1, geometries1, geometries2, geometries3, geometries4)
BondrankP1 = BondrankP1 + permutationsP1P2rank
BondrankP2 = BondrankP2 + permutationsP2P1rank
# CaseB: When the length of B(P1|P2) = 0 or B(P2|P1) = 0
# CaseC: both B(P1|P2) >= 1 or B(P2|P1) >= 1 but needs more B(|) tests
logging.info('')
logging.info('Replace B(P1|P2) with B(TS1|P1)')
permutationsTS1P1P2P1, permutationsP2P1TS1P1 = RankBonds(unidenticalTS1P1, unidenticalP2P1, geometries1, geometries2, geometries3, geometries4)
BondrankP1 = BondrankP1 + permutationsTS1P1P2P1
BondrankP2 = BondrankP2 + permutationsP2P1TS1P1
logging.info('')
logging.info('Replace B(P2|P1) with B(TS1|P2)')
permutationsP1P2TS1P2, permutationsTS1P2P1P2 = RankBonds(unidenticalP1P2, unidenticalTS1P2, geometries1, geometries2, geometries3, geometries4)
BondrankP1 = BondrankP1 + permutationsP1P2TS1P2
BondrankP2 = BondrankP2 + permutationsTS1P2P1P2
logging.info('')
logging.info('Replace B(P1|P2) with B(P1|TS1)')
permutationsP1TS1P2P1, permutationsP2P1P1TS1 = RankBonds(unidenticalP1TS1, unidenticalP2P1, geometries1, geometries2, geometries3, geometries4)
BondrankP1 = BondrankP1 + permutationsP1TS1P2P1
BondrankP2 = BondrankP2 + permutationsP2P1P1TS1
logging.info('')
logging.info('Replace B(P2|P1) with B(P2|TS1)')
permutationsP1P2P2TS1, permutationsP2TS1P1P2 = RankBonds(unidenticalP1P2, unidenticalP2TS1, geometries1, geometries2, geometries3, geometries4)
BondrankP1 = BondrankP1 + permutationsP1P2P2TS1
BondrankP2 = BondrankP2 + permutationsP2TS1P1P2
# test whether the algorithm is using bond1 to loop or bond2 to loop
logging.info('')
logging.info('BondrankP1: '+str(BondrankP1))
logging.info('BondrankP2: '+str(BondrankP2))
testlength = 0
if len(BondrankP1) >= len(BondrankP2):
testlength = len(BondrankP2)
if len(BondrankP2) >= len(BondrankP1):
testlength = len(BondrankP1)
testidx = 0
while testidx < testlength:
orthbond1list = BondrankP1[testidx]
orthbond2list = BondrankP2[testidx]
logging.info('')
logging.info('The algorithm is current using the following bonds for the major product analysis:')
logging.info('orthbond1list: '+str(orthbond1list))
logging.info('orthbond1list: '+str(orthbond2list))
orthbond1list = [(int(i)-1) for i in orthbond1list]
orthbond2list = [(int(i)-1) for i in orthbond2list]
# -- Major Product Analysis
eigenvectors1, imag_eigenvector1, real_eigenvectors1 = ReadEigenVec(filename5) # RealEigenVec format: [[vector1],[vector2],...]
eigenvectors2, imag_eigenvector2, real_eigenvectors2 = ReadEigenVec(filename6)
forceconstants1, frequencies1 = ExtractForceConsts(filename5) # Note: This function does not return the force constant corresponding to the imaginary frequency
imag_eigenvector1 = [float(i) for i in imag_eigenvector1]
real_xyzeigenvectors = []
real_floateigenvectors = []
for eigenvector in real_eigenvectors1:
real_floateigenvectors.append([])
floateigenlist = [float(item) for item in eigenvector]
real_floateigenvectors[-1] = floateigenlist
for eigenvector in real_eigenvectors1:
real_lineigenvectorcomp = [float(item) for item in eigenvector]
real_xyzeigenvectorcomp = ConvertLineartoXYZ(real_lineigenvectorcomp)
real_xyzeigenvectors.append([])
real_xyzeigenvectors[-1] = real_xyzeigenvectorcomp
logging.info('')
logging.info('-- Starting Vector Analysis --')
logging.info('')
logging.info('coord1-1: '+str(geometries1[orthbond1list[0]]))
logging.info('coord1-2: '+str(geometries1[orthbond1list[1]]))
logging.info('coord2-1: '+str(geometries1[orthbond2list[0]]))
logging.info('coord2-2: '+str(geometries1[orthbond2list[1]]))
logging.info('TS1_bond1: '+str(GetBondLength(geometries1, orthbond1list[0], orthbond1list[1])))
logging.info('TS1_bond2: '+str(GetBondLength(geometries1, orthbond2list[0], orthbond2list[1])))
# Stretch the molecule along the imaginary eigenvector and find the difference with the original atom position to find the imaginary eigenvector
lingeometries1 = ConvertXYZtoLinear(geometries1)
lindispTS1 = list(np.array(lingeometries1) + np.array(imag_eigenvector1))
dispTS1 = ConvertLineartoXYZ(lindispTS1)
dispcomp1 = GetBondLength(dispTS1, orthbond1list[0], orthbond1list[1]) - GetBondLength(geometries1, orthbond1list[0], orthbond1list[1])
dispcomp2 = GetBondLength(dispTS1, orthbond2list[0], orthbond2list[1]) - GetBondLength(geometries1, orthbond2list[0], orthbond2list[1])
Redimag_eigenvector1 = [dispcomp1,dispcomp2]
logging.info('')
logging.info('Bond Imaginary Eigenvector: '+str(Redimag_eigenvector1))
Redgeometry1 = [GetBondLength(geometries1, orthbond1list[0], orthbond1list[1]),GetBondLength(geometries1, orthbond2list[0], orthbond2list[1])]
Redgeometry2 = [GetBondLength(geometries2, orthbond1list[0], orthbond1list[1]),GetBondLength(geometries2, orthbond2list[0], orthbond2list[1])]
Redgeometry3 = [GetBondLength(geometries3, orthbond1list[0], orthbond1list[1]),GetBondLength(geometries3, orthbond2list[0], orthbond2list[1])]
Redgeometry4 = [GetBondLength(geometries4, orthbond1list[0], orthbond1list[1]),GetBondLength(geometries4, orthbond2list[0], orthbond2list[1])]
p1_ = list(np.array(Redgeometry3)-np.array(Redgeometry2))
p2_ = list(np.array(Redgeometry4)-np.array(Redgeometry2))
g_ = list(np.array(Redgeometry2)-np.array(Redgeometry1))
logging.info('')
logging.info('p1_: ')
for item in ConvertLineartoXYZ(p1_):
logging.info(str(item).strip('[]'))
logging.info('')
logging.info('p2_: ')
for item in ConvertLineartoXYZ(p2_):
logging.info(str(item).strip('[]'))
logging.info('')
logging.info('imag_eigenvector:')
for item in ConvertLineartoXYZ(imag_eigenvector1):
logging.info(str(item).strip('[]'))
logging.info('')
logging.info('g_:')
for item in ConvertLineartoXYZ(g_):
logging.info(str(item).strip('[]'))
logging.info('')
# -- Test whether the TS1 eigenvector needs to be inverted
angle_phi = abs(angle(Redimag_eigenvector1,g_))
if angle_phi > (math.pi/2):
logging.info('phi is '+str((180/math.pi)*angle_phi)+' vector a_ will be inverted.\n')
Redimag_eigenvector1 = InvertVec(Redimag_eigenvector1)
angle_phi = abs(angle(Redimag_eigenvector1,g_))
logging.info('new phi is '+str((180/math.pi)*abs(angle(Redimag_eigenvector1,g_))))
else:
logging.info('phi is '+str((180/math.pi)*angle_phi)+' vector a_ will not be inverted.\n')
angle_p1p2 = abs(angle(p1_,p2_))
mu1_ = Findmu_(Redimag_eigenvector1, p1_, g_)
mu2_ = Findmu_(Redimag_eigenvector1, p2_, g_)
lambda1_ = Findlambda_(Redimag_eigenvector1, p1_, g_)
lambda2_ = Findlambda_(Redimag_eigenvector1, p2_, g_)
if np.sign(mu1_) != np.sign(mu2_) and lambda1_ > 0 and lambda2_ > 0:
if (180/math.pi)*angle_phi < 0.1:
logging.info('The angle phi is less than 0.1 degs. The algorithm will try different sent of bonds')
testidx += 1
else:
logging.info('+mu_, -mu_, +lambda_, +lambda_ combination found. The algorithm wil continue.')
break
else:
logging.info('')
logging.info('The sign test did not find +mu_, -mu_, +lambda_, +lambda_ combination. The algorithm will try different set of bonds')
testidx += 1
neg_g_ = list(np.array(Redgeometry1)-np.array(Redgeometry2))
theta1 = angle(neg_g_, p1_)
theta2 = angle(neg_g_, p2_)
logging.info('')
logging.info('angle(p1,p1): '+str((180/math.pi)*angle_p1p2))
logging.info('|p1|: '+str(length(p1_)))
logging.info('|p2|: '+str(length(p2_)))
logging.info('|a|: '+str(length(imag_eigenvector1)))
logging.info('|b|: '+str(length(imag_eigenvector2)))
logging.info('|g|: '+str(length(g_)))
logging.info('theta1: '+str((180/math.pi)*theta1))
logging.info('theta2: '+str((180/math.pi)*theta2))
logging.info('')
logging.info('phi:')
logging.info(angle(Redimag_eigenvector1,g_)*(180/math.pi))
# -- Result Analysis --
# Test whether TST will give better answer
TST_valid = False
if intermediate_option == True:
TS1_G = ReadFreeEnergy(filename5)
INT_G = ReadFreeEnergy(filename6)
TS2A_G = ReadFreeEnergy(filename7)
TS2B_G = ReadFreeEnergy(filename8)
TS2_maxbarrier = max(TS2A_G, TS2B_G)
TS1INT_DeltaG = INT_G - TS1_G
TS2AINT_DeltaG = INT_G - TS2A_G
TS2BINT_DeltaG = INT_G - TS2B_G
ddG_test = TS2B_G - TS2A_G
TS_energydiff = TS1_G - TS2_maxbarrier
logging.info('')
logging.info('Delta_G(INT-TS1) = '+str(round(TS1INT_DeltaG,1))+' kJ/mol')
logging.info('Delta_G(INT-TS2A) = '+str(round(TS2AINT_DeltaG,1))+' kJ/mol')
logging.info('Delta_G(INT-TS2B) = '+str(round(TS2BINT_DeltaG,1))+' kJ/mol')
logging.info('DeltaDelta_G = '+str(round(ddG_test,1))+' kJ/mol')
logging.info('')
if TS_energydiff < 5.0:
logging.info('The TS2 free energy is higher than -5 kJ/mol from TS1. The algorithm will use TST to predict the selectivity')
logging.info('')
TST_valid = True
else:
logging.info('The TS2 free energy is lower than -5 kJ/mol from TS1. The algorithm will not use TST to predict the selectivity')
logging.info('')
# TST analysis
if TST_valid == True:
if TS2A_G < TS2B_G:
ddG = TS2B_G - TS2A_G
AB_ratio = math.exp((ddG * 1000)/(8.314*298))
major_perc = (AB_ratio / (AB_ratio + 1))*100.0
minor_perc = 100.0 - major_perc
logging.info('')
logging.info('**** Analysis Completed ****')
logging.info('')
logging.info('The difference in free energy between TS1 and TS2 is found to be less than 5 kJ/mol. The algorithm will use TST to predict the product ratios')
logging.info('')
logging.info('Delta_G(INT-TS1) = '+str(round(TS1INT_DeltaG,1))+' kJ/mol')
logging.info('Delta_G(INT-TS2A) = '+str(round(TS2AINT_DeltaG,1))+' kJ/mol')
logging.info('Delta_G(INT-TS2B) = '+str(round(TS2BINT_DeltaG,1))+' kJ/mol')
logging.info('DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol')
logging.info('')
logging.info('Major product is '+str(filename3))
logging.info('Minor product is '+str(filename4))
logging.info('')
logging.info('TST Major product percentage is '+str(round(major_perc,1)))
logging.info('TST Minor product percentage is '+str(round(minor_perc,1)))
logging.info('')
logging.info('****************************')
logging.info('')
print ''
print '**** Analysis Completed ****'
print ''
print 'The difference in free energy between TS1 and TS2 is found to be less than 5 kJ/mol. The algorithm will use TST to predict the product ratios'
print ''
print 'Delta_G(INT-TS1) = '+str(round(TS1INT_DeltaG,1))+' kJ/mol'
print 'Delta_G(INT-TS2A) = '+str(round(TS2AINT_DeltaG,1))+' kJ/mol'
print 'Delta_G(INT-TS2B) = '+str(round(TS2BINT_DeltaG,1))+' kJ/mol'
print 'DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol'
print ''
print 'Major product is '+str(filename3)
print 'Minor product is '+str(filename4)
print ''
print 'TST Major product percentage is '+str(round(major_perc,1))
print 'TST Minor product percentage is '+str(round(minor_perc,1))
print ''
print '****************************'
if TS2B_G < TS2A_G:
ddG = TS2A_G - TS2B_G
AB_ratio = math.exp((ddG * 1000)/(8.314*298))
major_perc = AB_ratio / (AB_ratio + 1)
minor_perc = 1 - major_perc
logging.info('')
logging.info('**** Analysis Completed ****')
logging.info('')
logging.info('The difference in free energy between TS1 and TS2 is found to be less than 5 kJ/mol. The algorithm will use TST to predict the product ratios')
logging.info('')
logging.info('Delta_G(INT-TS1) = '+str(round(TS1INT_DeltaG,1))+' kJ/mol')
logging.info('Delta_G(INT-TS2A) = '+str(round(TS2AINT_DeltaG,1))+' kJ/mol')
logging.info('Delta_G(INT-TS2B) = '+str(round(TS2BINT_DeltaG,1))+' kJ/mol')
logging.info('DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol')
logging.info('')
logging.info('Major product is '+str(filename4))
logging.info('Minor product is '+str(filename3))
logging.info('')
logging.info('TST Major product percentage is '+str(round(major_perc,1)))
logging.info('TST Minor product percentage is '+str(round(minor_perc,1)))
logging.info('')
logging.info('****************************')
logging.info('')
print ''
print '**** Analysis Completed ****'
print ''
print 'The difference in free energy between TS1 and TS2 is found to be less than 5 kJ/mol. The algorithm will use TST to predict the product ratios'
print ''
print 'Delta_G(INT-TS1) = '+str(round(TS1INT_DeltaG,1))+' kJ/mol'
print 'Delta_G(INT-TS2A) = '+str(round(TS2AINT_DeltaG,1))+' kJ/mol'
print 'Delta_G(INT-TS2B) = '+str(round(TS2BINT_DeltaG,1))+' kJ/mol'
print 'DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol'
print ''
print 'Major product is '+str(filename4)
print 'Minor product is '+str(filename3)
print ''
print 'TST Major product percentage is '+str(round(major_perc,1))
print 'TST Minor product percentage is '+str(round(minor_perc,1))
print ''
print '****************************'
# Dynamics analysis
if TST_valid == False:
if np.sign(mu1_) != np.sign(mu2_) and lambda1_ > 0 and lambda2_ > 0:
# -- Real Eigenvector Proudct Ratio Analysis
BondRealEigenvectors = ProjectEigenToBond(real_floateigenvectors, orthbond1list, orthbond2list, geometries1)
logging.info('')
logging.info('BondRealEigenVectors')
for item in BondRealEigenvectors:
logging.info(item)
BondRealEigenvectorLengths = [] # Find the length of the real eigenvectors projected to the two key bonds
for vector in BondRealEigenvectors:
BondRealEigenvectorLengths += [length(vector)]
TempToUse = 298.0
HalfWellWidths = CalcXs(forceconstants1, TempToUse, frequencies1)
logging.info('')
logging.info('HalfWellWidths: ')
for item in HalfWellWidths:
logging.info(item)
logging.info('')
logging.info('BondRealEigenvectorLengths:')
for item in BondRealEigenvectorLengths:
logging.info(item)
constantAs = []
for index in range(len(BondRealEigenvectors)):
const_A = HalfWellWidths[index]/BondRealEigenvectorLengths[index]
constantAs += [const_A]
logging.info('')
logging.info('const_As: ')
for item in constantAs:
logging.info(item)
m_list = ImagOrthogonalProj(BondRealEigenvectors,constantAs,Redimag_eigenvector1,g_)
ConstBs = FindConstantB(m_list,Redimag_eigenvector1,g_)
logging.info('')
logging.info('ConstBs')
for item in ConstBs:
logging.info(item)
major_length, minor_length = FindProdRatio(m_list, ConstBs, Redimag_eigenvector1)
major_ratio = major_length/(major_length + minor_length)
minor_ratio = minor_length/(major_length + minor_length)
if length(g_) < 0.5 and (180/math.pi)*angle_phi > 20 and (180/math.pi)*angle_phi < 50 and intermediate_option == False:
logging.info('')
logging.info('current major ratio:'+str(major_ratio))
logging.info('current minor ratio:'+str(minor_ratio))
logging.info('|g| < 0.5 and 20 < phi < 50 degs, the algorithm will change the major:minor product ratio')
major_ratio = (major_ratio - 0.58369)/0.4029
if major_ratio > 1:
major_ratio = 1
minor_ratio = 1 - major_ratio
if intermediate_option == True:
if mu1_ > 0 and mu2_ < 0:
correction_factor = ((180/math.pi)*angle_phi + (180 - (180/math.pi)*theta2))*0.01
logging.info('')
logging.info('current major ratio:'+str(major_ratio))
logging.info('current minor ratio:'+str(minor_ratio))
logging.info('the algorithm will change the major:minor product ratio for positive mu1_ (intermediate activation)')
major_ratio = major_ratio - (correction_factor * 0.6306 - 0.62707)
minor_ratio = 1 - major_ratio
if major_ratio > 1:
major_ratio = 1
if mu1_ < 0 and mu2_ > 0:
correction_factor = ((180/math.pi)*angle_phi + (180 - (180/math.pi)*theta1))*0.01
logging.info('')
logging.info('current major ratio:'+str(major_ratio))
logging.info('current minor ratio:'+str(minor_ratio))
logging.info('the algorithm will change the major:minor product ratio for positive mu1_ (intermediate activation)')
major_ratio = major_ratio - (correction_factor * 0.6306 - 0.62707)
minor_ratio = 1 - major_ratio
if major_ratio > 1:
major_ratio = 1
if mu1_ > 0 and mu2_ < 0:
logging.info('')
logging.info('**** Analysis Completed ****')
logging.info('Major product is '+str(filename3))
logging.info('Minor product is '+str(filename4))
print ''
print '**** Analysis Completed ****'
print 'Major product is '+str(filename3)
print 'Minor product is '+str(filename4)
elif mu2_ > 0 and mu1_ < 0:
logging.info('')
logging.info('**** Analysis Completed ****')
logging.info('Major product is '+str(filename4))
logging.info('Minor product is '+str(filename3))
print ''
print '**** Analysis Completed ****'
print 'Major product is '+str(filename4)
print 'Minor product is '+str(filename3)
logging.info('')
logging.info('mu1_ = '+str(mu1_))
logging.info('mu2_ = '+str(mu2_))
logging.info('lambda1_ = '+str(lambda1_))
logging.info('lambda2_ = '+str(lambda2_))
logging.info('|g_| = '+str(length(g_)))
if length(g_) > 1.0:
logging.info('WARNING: |g_| is large (|g_| > 1)')
logging.info('phi = '+str((180/math.pi)*angle_phi))
logging.info('')
logging.info('The algorith will now proceed to estimate the major and minor product ratios')
logging.info('')
logging.info('Product Ratio Calculation Completed:')
logging.info('Major Product : Minor Product ratio')
logging.info(str(round(major_ratio*100, 1))+' : '+str(round(minor_ratio*100, 1))+'\n')
if round(major_ratio*100, 1) < 60.0:
logging.info('WARNING: the predicted ratio is close to 50:50')
logging.info('****************************')
logging.info('')
print ''
print 'mu1_ = '+str(mu1_)
print 'mu2_ = '+str(mu2_)
print 'lambda1_ = '+str(lambda1_)
print 'lambda2_ = '+str(lambda2_)
print '|g_| = '+str(length(g_))
if length(g_) > 1.0:
print 'WARNING: |g_| is large (|g_| > 1)'
print 'phi = '+str((180/math.pi)*angle_phi)
print ''
print 'Product Ratio Calculation Completed:'
print 'Major Product : Minor Product ratio'
print str(round(major_ratio*100, 1))+' : '+str(round(minor_ratio*100, 1))
if round(major_ratio*100, 1) < 60.0:
print 'WARNING: the predicted ratio is close to 50:50'
print ''
print '****************************'
print ''
else:
logging.error('')
logging.error('**** Analysis Completed ****')
logging.error('+mu_, -mu_, +lambda_, +lambda_ combination not found')
logging.error('ERROR: Unable to predict the major product')
logging.error('')
logging.error('mu1_ = '+str(mu1_))
logging.error('mu2_ = '+str(mu2_))
logging.error('lambda1_ = '+str(lambda1_))
logging.error('lambda2_ = '+str(lambda2_))
logging.info('|g_| = '+str(length(g_)))
logging.info('phi = '+str((180/math.pi)*angle_phi))
logging.error('')
logging.error('The algorith will not proceed to estimate the major and minor product ratios')
logging.error('****************************')
print ''
print '**** Analysis Completed ****'
print '+mu_, -mu_, +lambda_, +lambda_ combination not found'
print 'ERROR: Unable to predict the major product'
print ''
print 'mu1_ = '+str(mu1_)
print 'mu2_ = '+str(mu2_)
print 'lambda1_ = '+str(lambda1_)
print 'lambda2_ = '+str(lambda2_)
print '|g_| = '+str(length(g_))
print 'phi = '+str((180/math.pi)*angle_phi)
print ''
print 'The algorith will not proceed to estimate the major and minor product ratios'
print '****************************'
print ''
def main2(filename1, filename2):
code_name = 'VRAI-selectivity_v3_'
logging.basicConfig(filename=code_name+filename1[:-4]+'_TST.log', level=logging.DEBUG, format='%(message)s', filemode='w')
datetime_now = datetime.now()
formatted_datetime = datetime_now.strftime("%Y %b %d %H:%M:%S")
print ''
print '***********************************'
print ''
print code_name
print ''
print 'Python code to predict selectivity'
print '@author: Sanha Lee'
print 'Run date: '+formatted_datetime
print ''
print 'Created: '+code_name+filename1[:-4]+'.log'
print ''
print '***********************************'
print ''
logging.info('\n')
logging.info('***********************************\n')
logging.info(code_name+'\n')
logging.info('Python code to predict selectivity')
logging.info('@author: Sanha Lee')
logging.info('University of Cambridge')
logging.info('Run date: '+formatted_datetime+'\n')
logging.info('***********************************\n')
logging.info('Reading TS2A: '+filename1)
logging.info('Reading TS2B: '+filename2)
logging.info('')
logging.info('-S activation: VRAI-selectivity is performing TST analysis')
logging.info('Reading TS2A freq: '+filename1)
logging.info('Reading TS2B freq: '+filename2)
logging.info('')
TS2A_G = ReadFreeEnergy(filename1)
TS2B_G = ReadFreeEnergy(filename2)
TS2_maxbarrier = max(TS2A_G, TS2B_G)
ddG_test = TS2B_G - TS2A_G
logging.info('')
logging.info('DeltaDelta_G = '+str(round(ddG_test,1))+' kJ/mol')
logging.info('')
if TS2A_G < TS2B_G:
ddG = TS2B_G - TS2A_G
AB_ratio = math.exp((ddG * 1000)/(8.314*298))
major_perc = (AB_ratio / (AB_ratio + 1))*100.0
minor_perc = 100.0 - major_perc
logging.info('')
logging.info('**** Analysis Completed ****')
logging.info('')
logging.info('-S activation, VRAI-selectivity is predicting selectivity using TST')
logging.info('')
logging.info('DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol')
logging.info('')
logging.info('Major product is '+str(filename1))
logging.info('Minor product is '+str(filename2))
logging.info('')
logging.info('TST Major product percentage is '+str(round(major_perc,1)))
logging.info('TST Minor product percentage is '+str(round(minor_perc,1)))
logging.info('')
logging.info('****************************')
logging.info('')
print ''
print '**** Analysis Completed ****'
print ''
print '-S activation, VRAI-selectivity is predicting selectivity using TST'
print ''
print 'DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol'
print ''
print 'Major product is '+str(filename1)
print 'Minor product is '+str(filename2)
print ''
print 'TST Major product percentage is '+str(round(major_perc,1))
print 'TST Minor product percentage is '+str(round(minor_perc,1))
print ''
print '****************************'
if TS2B_G < TS2A_G:
ddG = TS2A_G - TS2B_G
AB_ratio = math.exp((ddG * 1000)/(8.314*298))
major_perc = AB_ratio / (AB_ratio + 1)
minor_perc = 1 - major_perc
logging.info('')
logging.info('**** Analysis Completed ****')
logging.info('')
logging.info('-S activation, VRAI-selectivity is predicting selectivity using TST')
logging.info('')
logging.info('DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol')
logging.info('')
logging.info('Major product is '+str(filename2))
logging.info('Minor product is '+str(filename1))
logging.info('')
logging.info('TST Major product percentage is '+str(round(major_perc,1)))
logging.info('TST Minor product percentage is '+str(round(minor_perc,1)))
logging.info('')
logging.info('****************************')
logging.info('')
print ''
print '**** Analysis Completed ****'
print ''
print '-S activation, VRAI-selectivity is predicting selectivity using TST'
print ''
print 'DeltaDelta_G = '+str(round(ddG,1))+' kJ/mol'
print ''
print 'Major product is '+str(filename2)
print 'Minor product is '+str(filename1)
print ''
print 'TST Major product percentage is '+str(round(major_perc,1))
print 'TST Minor product percentage is '+str(round(minor_perc,1))
print ''
print '****************************'
############################################################
# Functions
############################################################
def SetEqualWeights(atom_list):
'''
Sets weightings used for geometry alignments
'''
weights = []
for item in atom_list:
weights += [1]
return weights
def InvertVec(vector):
InvertedVector = [(-1)*i for i in vector]
return InvertedVector
def ConvertLineartoXYZ(LinearList):
'''
Convert [x1,y1,z1,x2,y2,z2,...] format to [[x1,y1,z1],[x2,y2,z2],...]
'''
XYZlist = []
i = 0
while i < len(LinearList):
XYZlist.append(LinearList[i:i+3])
i+=3
return XYZlist
def VectorAddition(vec1,vec2):
addedvector = []
for i in range(len(vec1)):
addition = float(vec1[i]) + float(vec2[i])
addedvector += [addition]
return addedvector
def ConvertXYZtoLinear(XYZlist):
'''
Covert geometry list in [[x1,y1,z1],[x2,y2,z2],...] format to [x1,y1,z1,x2,y2,z2,...] format
'''
linearlist = []
for i in range(len(XYZlist)):
for j in range(3):
linearlist.append(XYZlist[i][j])
return linearlist
def Findmu_(vec_a, vec_b, vec_g):
'''
Finds u in point of closest approach analysis
'''
nominator = dotproduct(vec_a,vec_g)*dotproduct(vec_a,vec_b) - dotproduct(vec_b,vec_g)*dotproduct(vec_a,vec_a)
denominator = dotproduct(vec_a,vec_a)*dotproduct(vec_b,vec_b)-(dotproduct(vec_a,vec_b)**2)
return (nominator/denominator)
def Findlambda_(vec_a, vec_b, vec_g):
'''
Finds lambda in point of closest approach analysis
'''
nominator = dotproduct(vec_a,vec_g)*dotproduct(vec_b,vec_b) - dotproduct(vec_b,vec_g)*dotproduct(vec_a,vec_b)
denominator = dotproduct(vec_a,vec_a)*dotproduct(vec_b,vec_b)-(dotproduct(vec_a,vec_b)**2)
return (nominator/denominator)
def dotproduct(v1, v2):
'''
Returns dot product of vectors v1 and v2
'''
return sum((float(a)*float(b)) for a, b in zip(v1, v2))
def length(v):
'''
Returns magnitude of vector v
'''
return math.sqrt(dotproduct(v, v))
def angle(v1, v2):
'''
Returns angle between vectors v1 and v2
'''
return math.acos(round(dotproduct(v1, v2) / (length(v1) * length(v2)),5))
def FindUnitVector(vector):
'''
Returns the unit vector
'''
unit_vector = []
magnitude = length(vector)
for item in vector:
unit_vector += [item/magnitude]
return unit_vector
def ReadGeometries(GMolFile):
'''
Finds optimisation steps in the Gaussian output file and extracts the coordinates for each step.
If the output file is a frequency calculation only one geometry exists.