-
Notifications
You must be signed in to change notification settings - Fork 4
/
get_properties_functions.py
1401 lines (1237 loc) · 75.5 KB
/
get_properties_functions.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
#code written by Brittany C. Haas and Melissa A. Hardy (adapted from David B. Vogt's get_properties_pandas.py, adapted from Tobias Gensch)
import pandas as pd
import numpy as np
import re
import math
from morfeus import Sterimol
from morfeus import BuriedVolume
from morfeus import Pyramidalization
from morfeus import SASA
import goodvibes.GoodVibes as gv
import goodvibes.thermo as thermo
import goodvibes.io as io
import dbstep.Dbstep as db
homo_pattern = re.compile("Alpha occ. eigenvalues")
npa_pattern = re.compile("Summary of Natural Population Analysis:")
nbo_os_pattern = re.compile("beta spin orbitals")
nmrstart_pattern = " SCF GIAO Magnetic shielding tensor (ppm):\n"
nmrend_pattern = re.compile("End of Minotr F.D.")
nmrend_pattern_os = re.compile("g value of the free electron")
zero_pattern = re.compile("zero-point Energies")
cputime_pattern = re.compile("Job cpu time:")
walltime_pattern = re.compile("Elapsed time:")
volume_pattern = re.compile("Molar volume =")
polarizability_pattern = re.compile("Dipole polarizability, Alpha")
dipole_pattern = "Dipole moment (field-independent basis, Debye)"
frqs_pattern = re.compile("Red. masses")
frqsend_pattern = re.compile("Thermochemistry")
chelpg1_pattern = re.compile("(CHELPG)")
chelpg2_pattern = re.compile("Charges from ESP fit")
hirshfeld_pattern = re.compile("Hirshfeld charges, spin densities, dipoles, and CM5 charges")
def get_geom(streams): #extracts the geometry from the compressed stream
geom = []
for item in streams[-1][16:]:
if item == "":
break
geom.append([item.split(",")[0],float(item.split(",")[-3]),float(item.split(",")[-2]),float(item.split(",")[-1])])
return(geom)
def get_outstreams(log): #gets the compressed stream information at the end of a Gaussian job
streams = []
starts,ends = [],[]
error = ""
an_error = True
try:
with open(log+".log") as f:
loglines = f.readlines()
except:
with open(log+".LOG") as f:
loglines = f.readlines()
for line in loglines[::-1]:
if "Normal termination" in line:
an_error = False
if an_error:
error = "****Failed or incomplete jobs for " + log + ".log"
for i in range(len(loglines)):
if "1\\1\\" in loglines[i]:
starts.append(i)
if "@" in loglines[i]:
ends.append(i)
if len(starts) != len(ends) or len(starts) == 0: #probably redundant
error = "****Failed or incomplete jobs for " + log + ".log"
return(streams,error)
for i in range(len(starts)):
tmp = ""
for j in range(starts[i],ends[i]+1,1):
tmp = tmp + loglines[j][1:-1]
streams.append(tmp.split("\\"))
return(streams,error)
def get_filecont(log): #gets the entire job output
error = "" #default unless "normal termination" is in file
an_error = True
with open(log+".log") as f:
loglines = f.readlines()
for line in loglines[::-1]:
if "Normal termination" in line:
an_error = False
if an_error:
error = "****Failed or incomplete jobs for " + log + ".log"
return(loglines, error)
def get_sterimol_morfeus(dataframe, sterimol_list): #uses morfeus to calculate sterimol L, B1, B5 for two input atoms for every entry in df
sterimol_dataframe = pd.DataFrame(columns=[])
for index, row in dataframe.iterrows():
try:
#parsing the Sterimol axis defined in the list from input line
sterimolnums_list = []
for sterimol in sterimol_list:
atomnum_list = [] #the atom numbers used to collect sterimol values (e.g., [18 16 17 15]) are collected from the df using the input list (e.g., [["O2", "C1"], ["O3", "H5"]])
for atom in sterimol:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
sterimolnums_list.append(atomnum_list) #append atomnum_list for each sterimol axis defined in the input to make a list of the form [['18', '16'], ['16', '15']]
#this makes column headers based on Sterimol axis defined in the input line
sterimoltitle_list = []
for sterimol in sterimol_list:
sterimoltitle = str(sterimol[0]) + "_" + str(sterimol[1])
sterimoltitle_list.append(sterimoltitle)
log_file = row['log_name']
streams, error = get_outstreams(log_file) #need to add file path if you're running from a different directory than file
if error != "":
print(error)
row_i = {}
for a in range(0, len(sterimolnums_list)):
entry = {'Sterimol_L_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': "no data",
'Sterimol_B1_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': "no data",
'Sterimol_B5_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': "no data"}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
continue
geom = get_geom(streams)
#checks for if the wrong number of atoms are input, input is not of the correct form, or calls atom numbers that do not exist in the molecule
error = ""
for sterimol in sterimolnums_list:
if len(sterimol)%2 != 0:
error = "Number of atom inputs given for Sterimol is not divisible by two. " + str(len(sterimol)) + " atoms were given. "
for atom in sterimol:
if not atom.isdigit():
error += " " + atom + ": Only numbers accepted as input for Sterimol"
if int(atom) > len(geom):
error += " " + atom + " is out of range. Maximum valid atom number: " + str(len(geom)+1) + " "
if error != "": print(error)
elements = np.array([geom[i][0] for i in range(len(geom))])
coordinates = np.array([np.array(geom[i][1:]) for i in range(len(geom))])
#this collects Sterimol values for each pair of inputs
sterimolout = []
for sterimol in sterimolnums_list:
sterimol_values = Sterimol(elements, coordinates, int(sterimol[0]), int(sterimol[1])) #calls morfeus
sterimolout.append(sterimol_values)
#this adds the data from sterimolout into the new property df
row_i = {}
for a in range(0, len(sterimolnums_list)):
entry = {'Sterimol_L_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': sterimolout[a].L_value,
'Sterimol_B1_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': sterimolout[a].B_1_value,
'Sterimol_B5_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': sterimolout[a].B_5_value}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire Morfeus Sterimol parameters for:', row['log_name'], ".log")
row_i = {}
try:
for a in range(0, len(sterimolnums_list)):
entry = {'Sterimol_L_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': "no data",
'Sterimol_B1_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': "no data",
'Sterimol_B5_' + str(sterimoltitle_list[a]) + '(Å)_morfeus': "no data"}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
except:
print("****Ope, there's a problem with your atom inputs.")
print("Morfeus Sterimol function has completed for", sterimol_list)
return(pd.concat([dataframe, sterimol_dataframe], axis = 1))
def get_sterimol_dbstep(dataframe, sterimol_list): #uses DBSTEP to calculate sterimol L, B1, B5 for two input atoms for every entry in df
sterimol_dataframe = pd.DataFrame(columns=[])
for index, row in dataframe.iterrows():
try:
log_file = row['log_name']
#parsing the Sterimol axis defined in the list from input line
sterimolnums_list = []
for sterimol in sterimol_list:
atomnum_list = [] #the atom numbers used to collect sterimol values (e.g., [18 16 17 15]) are collected from the df using the input list (e.g., [["O2", "C1"], ["O3", "H5"]])
for atom in sterimol:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
sterimolnums_list.append(atomnum_list) #append atomnum_list for each sterimol axis defined in the input to make a list of the form [['18', '16'], ['16', '15']]
#checks for if the wrong number of atoms are input or input is not of the correct form
error = ""
for sterimol in sterimolnums_list:
if len(sterimol)%2 != 0:
error = "****Number of atom inputs given for Sterimol is not divisible by two. " + str(len(sterimol)) + " atoms were given. "
for atom in sterimol:
if not atom.isdigit():
error += "**** " + atom + ": Only numbers accepted as input for Sterimol"
if error != "": print(error)
#this collects Sterimol values for each pair of inputs
sterimol_out = []
fp = log_file + str(".log")
for sterimol in sterimolnums_list:
sterimol_values = db.dbstep(fp,atom1=int(sterimol[0]),atom2=int(sterimol[1]),commandline=True,verbose=False,sterimol=True,measure='grid')
sterimol_out.append(sterimol_values)
#this makes column headers based on Sterimol axis defined in the input line
sterimoltitle_list = []
for sterimol in sterimol_list:
sterimoltitle = str(sterimol[0]) + "_" + str(sterimol[1])
sterimoltitle_list.append(sterimoltitle)
#this adds the data from sterimolout into the new property df
row_i = {}
for a in range(0, len(sterimolnums_list)):
entry = {'Sterimol_B1_' + str(sterimoltitle_list[a]) + "(Å)_dbstep": sterimol_out[a].Bmin,
'Sterimol_B5_' + str(sterimoltitle_list[a]) + "(Å)_dbstep": sterimol_out[a].Bmax,
'Sterimol_L_' + str(sterimoltitle_list[a]) + "(Å)_dbstep": sterimol_out[a].L}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire DSBTEP Sterimol parameters for:', row['log_name'], ".log")
row_i = {}
try:
for a in range(0, len(sterimolnums_list)):
entry = {'Sterimol_L_' + str(sterimoltitle_list[a]) + '(Å)_dbstep': "no data",
'Sterimol_B1_' + str(sterimoltitle_list[a]) + '(Å)_dbstep': "no data",
'Sterimol_B5_' + str(sterimoltitle_list[a]) + '(Å)_dbstep': "no data"}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
except:
print("****Ope, there's a problem with your atom inputs.")
print("DBSTEP Sterimol function has completed for", sterimol_list)
return(pd.concat([dataframe, sterimol_dataframe], axis = 1))
def get_sterimol2vec(dataframe, sterimol_list, end_r, step_size): #uses DBSTEP to calculate sterimol Bmin and Bmax for two input atoms at intervals from 0 to end_r at step_size
sterimol_dataframe = pd.DataFrame(columns=[])
num_steps = int((end_r)/step_size + 1)
radii_list = [0 + step_size*i for i in range(num_steps)]
for index, row in dataframe.iterrows():
try:
log_file = row['log_name']
#parsing the Sterimol axis defined in the list from input line
sterimolnums_list = []
for sterimol in sterimol_list:
atomnum_list = [] #the atom numbers used to collect sterimol values (e.g., [18 16 17 15]) are collected from the df using the input list (e.g., [["O2", "C1"], ["O3", "H5"]])
for atom in sterimol:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
sterimolnums_list.append(atomnum_list) #append atomnum_list for each sterimol axis defined in the input to make a list of the form [['18', '16'], ['16', '15']]
#checks for if the wrong number of atoms are input or input is not of the correct form
error = ""
for sterimol in sterimolnums_list:
if len(sterimol)%2 != 0:
error = "Number of atom inputs given for Sterimol is not divisible by two. " + str(len(sterimol)) + " atoms were given. "
for atom in sterimol:
if not atom.isdigit():
error += " " + atom + ": Only numbers accepted as input for Sterimol"
if error != "": print(error)
#this collects Sterimol values for each pair of inputs
sterimol2vec_out = []
fp = log_file + str(".log")
for sterimol in sterimolnums_list:
sterimol2vec_values = db.dbstep(fp,atom1=int(sterimol[0]),atom2=int(sterimol[1]),scan='0.0:{}:{}'.format(end_r,step_size),commandline=True,verbose=False,sterimol=True,measure='grid')
sterimol2vec_out.append(sterimol2vec_values)
#this makes column headers based on Sterimol axis defined in the input line
sterimoltitle_list = []
for sterimol in sterimol_list:
sterimoltitle = str(sterimol[0]) + "_" + str(sterimol[1])
sterimoltitle_list.append(sterimoltitle)
scans = radii_list
#this adds the data from sterimolout into the new property df
row_i = {}
for a in range(0, len(sterimolnums_list)):
for i in range(0, len(scans)):
entry = {'Sterimol_Bmin_' + str(sterimoltitle_list[a]) + "_" + str(scans[i]) + "Å(Å)": sterimol2vec_out[a].Bmin[i],
'Sterimol_Bmax_' + str(sterimoltitle_list[a]) + "_" + str(scans[i]) + "Å(Å)": sterimol2vec_out[a].Bmax[i]}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire DSBTEP Sterimol2Vec parameters for:', row['log_name'], ".log")
row_i = {}
try:
for a in range(0, len(sterimolnums_list)):
for i in range(0, len(scans)):
entry = {'Sterimol_Bmin_' + str(sterimoltitle_list[a]) + "_" + str(scans[i]) + "Å(Å)": "no data",
'Sterimol_Bmax_' + str(sterimoltitle_list[a]) + "_" + str(scans[i]) + "Å(Å)": "no data"}
row_i.update(entry)
sterimol_dataframe = sterimol_dataframe.append(row_i, ignore_index=True)
except:
print("****Ope, there's a problem with your atom inputs.")
print("DBSTEP Sterimol2Vec function has completed for", sterimol_list)
return(pd.concat([dataframe, sterimol_dataframe], axis = 1))
def get_vbur_one_radius(dataframe, a1, radius): #uses morfeus to calculate vbur at a single radius for an atom (a1) in df
atom = str(a1)
vbur_dataframe = pd.DataFrame(columns=[])
for index, row in dataframe.iterrows():
try:
log_file = row['log_name']
atom1 = row[str(a1)] #gets numerical value (e.g. 16) for a1 (e.g. C1)
streams, error = get_outstreams(log_file) #need to add file path if you're running from a different directory than file
if error != "":
print(error)
row_i = {'%Vbur_'+str(atom)+"_"+str(radius)+"Å": "no data"}
vbur_dataframe = vbur_dataframe.append(row_i, ignore_index=True)
continue
log_coordinates = get_geom(streams)
elements = np.array([log_coordinates[i][0] for i in range(len(log_coordinates))])
coordinates = np.array([np.array(log_coordinates[i][1:]) for i in range(len(log_coordinates))])
vbur = BuriedVolume(elements, coordinates, int(atom1), include_hs=True, radius=radius) #calls morfeus
row_i = {'%Vbur_'+str(atom)+"_"+str(radius)+"Å": vbur.percent_buried_volume * 100}
vbur_dataframe = vbur_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire Vbur parameters for:', row['log_name'], ".log")
row_i = {'%Vbur_'+str(atom)+"_"+str(radius)+"Å": "no data"}
vbur_dataframe = vbur_dataframe.append(row_i, ignore_index=True)
return(vbur_dataframe)
def get_vbur_scan(dataframe, a_list, start_r, end_r, step_size): #uses morfeus via get_vbur_one_radius to scan vbur across a range of radii
num_steps = int((end_r-start_r)/step_size + 1)
radii = [start_r + step_size*i for i in range(num_steps)]
frames = []
for radius in radii:
for a in a_list:
frames.append(get_vbur_one_radius(dataframe, a, radius))
vbur_scan_dataframe = pd.concat(frames, axis = 1)
print("Vbur scan function has completed for", a_list, "from", start_r, " to ", end_r)
return(pd.concat([dataframe, vbur_scan_dataframe], axis = 1))
def get_pyramidalization(dataframe, a_list): #uses morfeus to calculate pyramidalization (based on the 3 atoms in closest proximity to the defined atom) for for all atoms (a_list, of form ["C1", "C4", "O2"]) in a dataframe that contains file name and atom number
pyr_dataframe = pd.DataFrame(columns=[])
for index, row in dataframe.iterrows():
try:
atom_list = []
for label in a_list:
atom = row[str(label)] #the atom number (e.g., 16) to add to the list is the df entry of this row for the labeled atom (e.g., "C1")
atom_list.append(str(atom)) #append that to atom_list to make a list of the form [16, 17, 29]
log_file = row['log_name']
streams, error = get_outstreams(log_file) #need to add file path if you're running from a different directory than file
if error != "":
print(error)
row_i = {}
for a in range(0, len(atom_list)):
entry = {'pyramidalization_Gavrish_' + str(a_list[a]) + '(°)': "no data",
'pyramidalization_Agranat-Radhakrishnan_' + str(a_list[a]): "no data"} #details on these values can be found here: https://kjelljorner.github.io/morfeus/pyramidalization.html
row_i.update(entry)
pyr_dataframe = pyr_dataframe.append(row_i, ignore_index=True)
continue
log_coordinates = get_geom(streams)
elements = np.array([log_coordinates[i][0] for i in range(len(log_coordinates))])
coordinates = np.array([np.array(log_coordinates[i][1:]) for i in range(len(log_coordinates))])
pyrout = []
for atom in atom_list:
pyr = Pyramidalization(coordinates, int(atom)) #calls morfeus
pyrout.append(pyr)
row_i = {}
for a in range(0, len(atom_list)):
entry = {'pyramidalization_Gavrish_' + str(a_list[a]) + '(°)': pyrout[a].P_angle,
'pyramidalization_Agranat-Radhakrishnan_' + str(a_list[a]): pyrout[a].P} #details on these values can be found here: https://kjelljorner.github.io/morfeus/pyramidalization.html
row_i.update(entry)
pyr_dataframe = pyr_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire pyramidalizataion parameters for:', row['log_name'], ".log")
row_i = {}
for a in range(0, len(atom_list)):
entry = {'pyramidalization_Gavrish_' + str(a_list[a]) + '(°)': "no data",
'pyramidalization_Agranat-Radhakrishnan_' + str(a_list[a]): "no data"} #details on these values can be found here: https://kjelljorner.github.io/morfeus/pyramidalization.html
row_i.update(entry)
pyr_dataframe = pyr_dataframe.append(row_i, ignore_index=True)
print("Pyramidalization function has completed for", a_list)
return(pd.concat([dataframe, pyr_dataframe], axis = 1))
def get_specdata(atoms,prop): #input a list of atom numbers and a list of pairs of all atom numbers and property of interest for use with NMR, NBO, etc.
propout = []
for atom in atoms:
if atom.isdigit():
a = int(atom)-1
if a <= len(prop):
propout.append(float(prop[a][1]))
else: continue
else: continue
return(propout)
def get_nbo(dataframe, a_list): #a function to get the nbo npa partial charge for all atoms (a_list, form ["C1", "C4", "O2"]) in a dataframe that contains file name and atom number
nbo_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
atomnum_list = []
for atom in a_list:
atomnum = row[str(atom)] #the atom number (e.g., 16) to add to the list is the df entry of this row for the labeled atom (e.g., "C1")
atomnum_list.append(str(atomnum)) #append that to atomnum_list to make a list of the form [16, 17, 29]
log_file = row['log_name'] #read file name from df
filecont, error = get_filecont(log_file) #read the contents of the log file
if error != "":
print(error)
row_i = {}
for a in range(0, len(a_list)):
entry = {'NBO_charge_'+str(a_list[a]): "no data"}
row_i.update(entry)
nbo_dataframe = nbo_dataframe.append(row_i, ignore_index=True)
continue
nbo,nbostart,nboout,skip = [],0,"",0
#this section finds the line (nbostart) where the nbo data is located
for i in range(len(filecont)-1,0,-1): #search the file contents for the phrase "beta spin orbitals" to check for open shell molecules
if re.search(nbo_os_pattern,filecont[i]) and skip == 0:
skip = 2 # retrieve only combined orbitals NPA in open shell molecules
if npa_pattern.search(filecont[i]): #search the file content for the phrase which indicates the start of the NBO section
if skip != 0:
skip = skip-1
continue
nbostart = i + 6 #skips the set number of lines between the search key and the start of the table
break
if nbostart == 0:
error = "****no Natural Population Analysis found in: " + str(row['log_name']) + ".log"
print(error)
row_i = {}
for a in range(0, len(a_list)):
entry = {'NBO_charge_'+str(a_list[a]): "no data"}
row_i.update(entry)
nbo_dataframe = nbo_dataframe.append(row_i, ignore_index=True)
continue
#this section splits the table where nbo data is located into just the atom number and charge to generate a list of lists (nbo)
ls = []
for line in filecont[nbostart:]:
if "==" in line: break
ls = [str.split(line)[1],str.split(line)[2]]
nbo.append(ls)
#this uses the nbo list to return only the charges for only the atoms of interest as a list (nboout)
nboout = get_specdata(atomnum_list,nbo)
#this adds the data from the nboout into the new property df
row_i = {}
for a in range(0, len(a_list)):
entry = {'NBO_charge_'+str(a_list[a]): nboout[a]}
row_i.update(entry)
nbo_dataframe = nbo_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire NBO charges for:', row['log_name'], ".log")
row_i = {}
for a in range(0, len(a_list)):
entry = {'NBO_charge_'+str(a_list[a]): "no data"}
row_i.update(entry)
nbo_dataframe = nbo_dataframe.append(row_i, ignore_index=True)
print("NBO function has completed for", a_list)
return(pd.concat([dataframe, nbo_dataframe], axis = 1))
def get_nmr(dataframe, a_list): # a function to get the nbo for all atoms (a_list, form ["C1", "C4", "O2"]) in a dataframe that contains file name and atom number
nmr_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
atom_list = []
for new_a in a_list:
new_atom = row[str(new_a)] #the atom number (e.g., 16) to add to the list is the df entry of this row for the labeled atom (e.g., "C1")
atom_list.append(str(new_atom)) #append that to atom_list to make a list of the form [16, 17, 29]
log_file = row['log_name'] #read file name from df
filecont, error = get_filecont(log_file) #read the contents of the log file
if error != "":
print(error)
row_i = {}
for a in range(0, len(a_list)):
entry = {'NMR_shift_'+str(a_list[a]): "no data"}
row_i.update(entry)
nmr_dataframe = nmr_dataframe.append(row_i, ignore_index=True)
continue
#determining the locations/values for start and end of NMR section
start,end,i = 0,0,0
if nmrstart_pattern in filecont:
start = filecont.index(nmrstart_pattern)+1
for i in range(start,len(filecont),1):
if nmrend_pattern.search(filecont[i]) or nmrend_pattern_os.search(filecont[i]):
end = i
break
if start == 0:
error = "****no NMR data found in file: " + str(row['log_name']) + ".log"
print(error)
row_i = {}
for a in range(0, len(a_list)):
entry = {'NMR_shift_'+str(a_list[a]): "no data"}
row_i.update(entry)
nmr_dataframe = nmr_dataframe.append(row_i, ignore_index=True)
continue
atoms = int((end - start)/5) #total number of atoms in molecule (there are 5 lines generated per atom)
nmr = []
for atom in range(atoms):
element = str.split(filecont[start+5*atom])[1]
shift_s = str.split(filecont[start+5*atom])[4]
nmr.append([element,shift_s])
#atom_list = ["1", "2", "3"]
nmrout = get_specdata(atom_list,nmr) #revisit
#print(nmrout)
#this adds the data from the nboout into the new property df
row_i = {}
for a in range(0, len(a_list)):
entry = {'NMR_shift_'+str(a_list[a]): nmrout[a]}
row_i.update(entry)
nmr_dataframe = nmr_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire NMR shifts for:', row['log_name'], ".log")
row_i = {}
for a in range(0, len(a_list)):
entry = {'NMR_shift_'+str(a_list[a]): "no data"}
row_i.update(entry)
nmr_dataframe = nmr_dataframe.append(row_i, ignore_index=True)
print("NMR function has completed for", a_list)
return(pd.concat([dataframe, nmr_dataframe], axis = 1))
def get_angles(dataframe,angle_list): # a function to get the angles for all atoms (angle_list, form [[O3, C1, O2], [C4, C1, O3]]) in a dataframe that contains file name and atom number
angle_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try:
#parsing the angle list from input line
anglenums_list = []
for angle in angle_list:
atomnum_list = [] #the atom numbers for an angle (e.g., 17 16 18) are collected from the df using the input list (e.g., ["O3", "C1", "O2"])
for atom in angle:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
anglenums_list.append(atomnum_list) #append atomnum_list for each angle to make a list of the form [['17', '16', '18'], ['15', '16', '17']]
angletitle_list = []
for angle in angle_list:
angletitle = str(angle[0]) + "_" + str(angle[1]) + "_" + str(angle[2])
angletitle_list.append(angletitle)
log_file = row['log_name'] #read file name from df
streams, error = get_outstreams(log_file)
if error != "":
print(error)
row_i = {}
for a in range(0, len(anglenums_list)):
entry = {'angle_'+str(angletitle_list[a]) + '(°)': "no data"}
row_i.update(entry)
angle_dataframe = angle_dataframe.append(row_i, ignore_index=True)
continue
geom = get_geom(streams)
#checks for if the wrong number of atoms are input, input is not of the correct form, or calls atom numbers that do not exist in the molecule.
error = ""
for angle in anglenums_list:
if len(angle)%3 != 0:
error = "****Number of atom inputs given for angle is not divisible by three. " + str(len(angle)) + " atoms were given. "
for atom in angle:
if not atom.isdigit():
error += "**** " + atom + ": Only numbers accepted as input for angles"
if int(atom) > len(geom):
error += "**** " + atom + " is out of range. Maximum valid atom number: " + str(len(geom)+1) + " "
if error != "": print(error)
anglesout = []
for angle in anglenums_list:
a = geom[int(angle[0])-1][:4] # atom coords
b = geom[int(angle[1])-1][:4]
c = geom[int(angle[2])-1][:4]
ba = np.array(a[1:]) - np.array(b[1:])
bc = np.array(c[1:]) - np.array(b[1:])
cosine_angle = np.dot(ba, bc) / (np.linalg.norm(ba) * np.linalg.norm(bc))
anglevalue = np.arccos(cosine_angle)
anglesout.append(float(round(np.degrees(anglevalue),3)))
#this adds the data from the anglesout into the new property df
row_i = {}
for a in range(0, len(anglenums_list)):
entry = {'angle_'+str(angletitle_list[a]) + '(°)': anglesout[a]}
row_i.update(entry)
angle_dataframe = angle_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire angles for:', row['log_name'], ".log")
row_i = {}
try:
for a in range(0, len(anglenums_list)):
entry = {'angle_'+str(angletitle_list[a]) + '(°)': "no data"}
row_i.update(entry)
angle_dataframe = angle_dataframe.append(row_i, ignore_index=True)
except:
print("****Ope, there's a problem with your atom inputs.")
print("Angles function has completed for", angle_list)
return(pd.concat([dataframe, angle_dataframe], axis = 1))
def get_dihedral(dataframe,dihedral_list): # a function to get the dihedrals for all atoms (dihederal_list, form [[O2, C1, O3, H5], [C4, C1, O3, H5]]) in a dataframe that contains file name and atom number
dihedral_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try:
#parsing the dihedral list from input line
dihedralnums_list = []
for dihedral in dihedral_list:
atomnum_list = [] #the atom numbers for a dihedral (e.g., 18 16 17 50) are collected from the df using the input list (e.g., ["O2", "C1", "O3", "H5"])
for atom in dihedral:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
dihedralnums_list.append(atomnum_list) #append atomnum_list for each dihedral to make a list of the form [['18', '16', '17', '50'], ['18', '16', '17', '50']]
dihedraltitle_list = []
for dihedral in dihedral_list:
dihedraltitle = str(dihedral[0]) + "_" + str(dihedral[1]) + "_" + str(dihedral[2]) + "_" +str(dihedral[3])
dihedraltitle_list.append(dihedraltitle)
log_file = row['log_name'] #read file name from df
streams, error = get_outstreams(log_file)
if error != "":
print(error)
row_i = {}
for a in range(0, len(dihedralnums_list)):
entry = {'dihedral_'+str(dihedraltitle_list[a]) + '(°)': "no data"}
row_i.update(entry)
dihedral_dataframe = dihedral_dataframe.append(row_i, ignore_index=True)
continue
geom = get_geom(streams)
#checks for if the wrong number of atoms are input, input is not of the correct form, or calls atom numbers that do not exist in the molecule.
error = ""
for dihedral in dihedralnums_list:
if len(dihedral)%4 != 0:
error = "****Number of atom inputs given for dihedral angle is not divisible by four. " + str(len(dihedral)) + " atoms were given. "
for atom in dihedral:
if not atom.isdigit():
error += "**** " + atom + ": Only numbers accepted as input for dihedral angles"
if int(atom) > len(geom):
error += "**** " + atom + " is out of range. Maximum valid atom number: " + str(len(geom)+1) + " "
if error != "": print(error)
dihedralsout = []
for dihedral in dihedralnums_list:
a = geom[int(dihedral[0])-1][:4] # atom coords
b = geom[int(dihedral[1])-1][:4]
c = geom[int(dihedral[2])-1][:4]
d = geom[int(dihedral[3])-1][:4]
ab = np.array([a[1]-b[1],a[2]-b[2],a[3]-b[3]]) # vectors
bc = np.array([b[1]-c[1],b[2]-c[2],b[3]-c[3]])
cd = np.array([c[1]-d[1],c[2]-d[2],c[3]-d[3]])
n1 = np.cross(ab,bc) # normal vectors
n2 = np.cross(bc,cd)
dihedral = round(np.degrees(np.arccos(np.dot(n1,n2) / (np.linalg.norm(n1)*np.linalg.norm(n2)))),3)
dihedralsout.append(float(dihedral))
#this adds the data from the dihedralsout into the new property df
row_i = {}
for a in range(0, len(dihedralnums_list)):
entry = {'dihedral_'+str(dihedraltitle_list[a]) + '(°)': dihedralsout[a]}
row_i.update(entry)
dihedral_dataframe = dihedral_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire dihedral angles for:', row['log_name'], ".log")
row_i = {}
try:
for a in range(0, len(dihedralnums_list)):
entry = {'dihedral_'+str(dihedraltitle_list[a]) + '(°)': "no data"}
row_i.update(entry)
dihedral_dataframe = dihedral_dataframe.append(row_i, ignore_index=True)
except:
print("****Ope, there's a problem with your atom inputs.")
print("Dihedral function has completed for", dihedral_list)
return(pd.concat([dataframe, dihedral_dataframe], axis = 1))
def get_distance(dataframe,dist_list): # a function to get the distances for all atoms (dist_list, form [[C1, O2], [C4, C1]]) in a dataframe that contains file name and atom number
dist_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try:
#parsing the distances list from input line
distnums_list = []
for dist in dist_list:
atomnum_list = [] #the atom numbers for a distance (e.g., 18 16 16 15) are collected from the df using the input list (e.g., ["O2", "C1", "O3", "H5"])
for atom in dist:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
distnums_list.append(atomnum_list) #append atomnum_list for each distance to make a list of the form [['18', '16'], ['16', '15']]
disttitle_list = []
for dist in dist_list:
disttitle = str(dist[0]) + "_" + str(dist[1])
disttitle_list.append(disttitle)
log_file = row['log_name'] #read file name from df
streams, error = get_outstreams(log_file)
if error != "":
print(error)
row_i = {}
for a in range(0, len(distnums_list)):
entry = {'distance_' + str(disttitle_list[a]) + '(Å)': "no data"}
row_i.update(entry)
dist_dataframe = dist_dataframe.append(row_i, ignore_index=True)
continue
geom = get_geom(streams)
#checks for if the wrong number of atoms are input, input is not of the correct form, or calls atom numbers that do not exist in the molecule.
error = ""
for dist in distnums_list:
if len(dist)%2 != 0:
error = "****Number of atom inputs given for distance is not divisible by two. " + str(len(dist)) + " atoms were given. "
for atom in dist:
if not atom.isdigit():
error += "**** " + atom + ": Only numbers accepted as input for distances"
if int(atom) > len(geom):
error += "**** " + atom + " is out of range. Maximum valid atom number: " + str(len(geom)+1) + " "
if error != "": print(error)
distout = []
for dist in distnums_list:
a = geom[int(dist[0])-1][:4] # atom coords
b = geom[int(dist[1])-1][:4]
ba = np.array(a[1:]) - np.array(b[1:])
dist = round(np.linalg.norm(ba),5)
distout.append(float(dist))
#this adds the data from the distout into the new property df
row_i = {}
for a in range(0, len(distnums_list)):
entry = {'distance_' + str(disttitle_list[a]) + '(Å)': distout[a]}
row_i.update(entry)
dist_dataframe = dist_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire distance for:', row['log_name'], ".log")
row_i = {}
try:
for a in range(0, len(distnums_list)):
entry = {'distance_' + str(disttitle_list[a]) + '(Å)': "no data"}
row_i.update(entry)
dist_dataframe = dist_dataframe.append(row_i, ignore_index=True)
except:
print("****Ope, there's a problem with your atom inputs.")
print("Distance function has completed for", dist_list)
return(pd.concat([dataframe, dist_dataframe], axis = 1))
def get_enthalpies(dataframe): # gets thermochemical data from freq jobs
enthalpy_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
log_file = row['log_name'] #read file name from df
filecont = get_filecont(log_file) #read the contents of the log file
evals = []
error = "no thermochemical data found;;"
e_hf,ezpe,h,g = 0,0,0,0
for i in range(len(filecont)-1): #uses the zero_pattern that denotes this section to gather relevant energy terms
if zero_pattern.search(filecont[i]):
e_hf = round(-eval(str.split(filecont[i-4])[-2]) + ezpe,6)
evals.append(e_hf)
ezpe = eval(str.split(filecont[i])[-1])
evals.append(ezpe)
h = eval(str.split(filecont[i+2])[-1])
evals.append(h)
g = eval(str.split(filecont[i+3])[-1])
evals.append(g)
error = ""
#this adds the data from the energy_values list (evals) into the new property df
row_i = {'ZP_correction(Hartree)': evals[0], 'E_ZPE(Hartree)': evals[1], 'H(Hartree)': evals[2], 'G(Hartree)': evals[3]}
#print(row_i)
enthalpy_dataframe = enthalpy_dataframe.append(row_i, ignore_index=True)
except:
print('Unable to acquire enthalpies for:', row['log_name'], ".log")
print("Enthalpies function has completed")
return(pd.concat([dataframe, enthalpy_dataframe], axis = 1))
def get_time(dataframe): # gets wall time and CPU for all jobs
time_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
log_file = row['log_name'] #read file name from df
filecont, error = get_filecont(log_file) #read the contents of the log file
if error != "":
print(error)
row_i = {'CPU_time_total(hours)': "no data", 'Wall_time_total(hours)': "no data"}
time_dataframe = time_dataframe.append(row_i, ignore_index=True)
continue
cputime,walltime = 0,0
timeout = []
for line in filecont:
if cputime_pattern.search(line):
lsplt = str.split(line)
cputime = float(lsplt[-2])/3600 + float(lsplt[-4])/60 + float(lsplt[-6]) + float(lsplt[-8])*24
timeout.append(round(cputime,5))
if walltime_pattern.search(line):
lsplt = str.split(line)
walltime = float(lsplt[-2])/3600 + float(lsplt[-4])/60 + float(lsplt[-6]) + float(lsplt[-8])*24
timeout.append(walltime)
CPU_time = 0
Wall_time = 0
for i in range(len(timeout)):
if i%2 == 0:
CPU_time += timeout[i]
if i%2 != 0:
Wall_time += timeout[i]
#this adds the data from the CPU_time and Wall_time into the property df
row_i = {'CPU_time_total(hours)': CPU_time, 'Wall_time_total(hours)': Wall_time}
time_dataframe = time_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire CPU time and wall time for:', row['log_name'], ".log")
row_i = {'CPU_time_total(hours)': "no data", 'Wall_time_total(hours)': "no data"}
time_dataframe = time_dataframe.append(row_i, ignore_index=True)
print("Time function has completed")
return(pd.concat([dataframe, time_dataframe], axis = 1))
def get_frontierorbs(dataframe): # homo,lumo energies and derived values of last job in file
frontierorbs_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
log_file = row['log_name'] #read file name from df
filecont, error = get_filecont(log_file) #read the contents of the log file
if error != "":
print(error)
row_i = {'HOMO': "no data", 'LUMO': "no data", "μ": "no data", "η": "no data", "ω": "no data"}
frontierorbs_dataframe = frontierorbs_dataframe.append(row_i, ignore_index=True)
continue
frontierout = []
index = 0
for line in filecont[::-1]:
if homo_pattern.search(line):
index += 1 #index ensures only the first entry is included
if index == 1:
homo = float(str.split(line)[-1])
lumo = float(str.split(filecont[filecont.index(line)+1])[4])
mu = (homo+lumo)/2 # chemical potential or negative of molecular electronegativity
eta = lumo-homo # hardness/softness
omega = round(mu**2/(2*eta),5) # electrophilicity index
frontierout.append(homo)
frontierout.append(lumo)
frontierout.append(mu)
frontierout.append(eta)
frontierout.append(omega)
#this adds the data from the frontierout into the new property df
row_i = {'HOMO': frontierout[0], 'LUMO': frontierout[1], "μ": frontierout[2], "η": frontierout[3], "ω": frontierout[4]}
frontierorbs_dataframe = frontierorbs_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire frontier orbitals for:', row['log_name'], ".log")
row_i = {'HOMO': "no data", 'LUMO': "no data", "μ": "no data", "η": "no data", "ω": "no data"}
frontierorbs_dataframe = frontierorbs_dataframe.append(row_i, ignore_index=True)
print("Frontier orbitals function has completed")
return(pd.concat([dataframe, frontierorbs_dataframe], axis = 1))
def get_volume(dataframe): #gets the molar volume of the molecule
volume_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
log_file = row['log_name'] #read file name from df
filecont, error = get_filecont(log_file) #read the contents of the log file
if error != "":
print(error)
row_i = {'volume(Bohr_radius³/mol)': "no data"}
volume_dataframe = volume_dataframe.append(row_i, ignore_index=True)
continue
volume = []
for line in filecont:
if volume_pattern.search(line):
volume.append(line.split()[3])
#this adds the data into the new property df
row_i = {'volume(Bohr_radius³/mol)': float(volume[0])}
volume_dataframe = volume_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire volume for:', row['log_name'], ".log")
row_i = {'volume(Bohr_radius³/mol)': "no data"}
volume_dataframe = volume_dataframe.append(row_i, ignore_index=True)
print("Volume function has completed")
return(pd.concat([dataframe, volume_dataframe], axis = 1))
def get_polarizability(dataframe): # polarizability isotropic and anisotropic
polarizability_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try: #try to get the data
log_file = row['log_name'] #read file name from df
filecont, error = get_filecont(log_file) #read the contents of the log file
if error != "":
print(error)
row_i = {'polar_iso(au)': "no data", 'polar_aniso(au)': "no data"}
polarizability_dataframe = polarizability_dataframe.append(row_i, ignore_index=True)
continue
polarout = []
for i in range(len(filecont)-1,1,-1):
if polarizability_pattern.search(filecont[i]):
alpha_iso = float(filecont[i+4].split()[1].replace("D","E"))
alpha_aniso = float(filecont[i+5].split()[1].replace("D","E"))
polarout.append(alpha_iso)
polarout.append(alpha_aniso)
#this adds the data from the polarout into the new property df
row_i = {'polar_iso(au)': polarout[0], 'polar_aniso(au)': polarout[1]}
polarizability_dataframe = polarizability_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire polarizability for:', row['log_name'], ".log")
row_i = {'polar_iso(au)': "no data", 'polar_aniso(au)': "no data"}
polarizability_dataframe = polarizability_dataframe.append(row_i, ignore_index=True)
print("Polarizability function has completed")
return(pd.concat([dataframe, polarizability_dataframe], axis = 1))
def get_planeangle(dataframe,planeangle_list): # a function to get the plane angles for all atoms (dihederal_list, form [[O2, C1, O3, H5], [C4, C1, O3, H5]]) in a dataframe that contains file name and atom number
planeangle_dataframe = pd.DataFrame(columns=[]) #define an empty df to place results in
for index, row in dataframe.iterrows(): #iterate over the dataframe
try:
#parsing the plane angle list from input line
planeanglenums_list = []
for planeangle in planeangle_list:
atomnum_list = [] #the atom numbers for a plane angle (e.g., 18 16 17 50) are collected from the df using the input list (e.g., ["O2", "C1", "O3", "H5"])
for atom in planeangle:
atomnum = row[str(atom)]
atomnum_list.append(str(atomnum))
planeanglenums_list.append(atomnum_list) #append atomnum_list for each plane angle to make a list of the form [['18', '16', '17', '50'], ['18', '16', '17', '50']]
planeangletitle_list = []
for planeangle in planeangle_list:
planeangletitle = str(planeangle[0]) + "_" + str(planeangle[1]) + "_" + str(planeangle[2]) + "_&_" +str(planeangle[3])+ "_" + str(planeangle[4]) + "_" +str(planeangle[5])
planeangletitle_list.append(planeangletitle)
log_file = row['log_name'] #read file name from df
streams, error = get_outstreams(log_file)
if error != "":
print(error)
row_i = {}
for a in range(0, len(planeanglenums_list)):
entry = {'planeangle_'+str(planeangletitle_list[a]) + '(°)': "no data"}
row_i.update(entry)
planeangle_dataframe = planeangle_dataframe.append(row_i, ignore_index=True)
continue
geom = get_geom(streams)
#checks for if the wrong number of atoms are input, input is not of the correct form, or calls atom numbers that do not exist in the molecule.
error = ""
for planeangle in planeanglenums_list:
if len(planeangle)%6 != 0:
error = "****Number of atom inputs given for plane angle is not divisible by six. " + str(len(planeangle)) + " atoms were given. "
for atom in planeangle:
if not atom.isdigit():
error += "**** " + atom + ": Only numbers accepted as input for plane angles"
if int(atom) > len(geom):
error += "**** " + atom + " is out of range. Maximum valid atom number: " + str(len(geom)+1) + " "
if error != "": print(error)
planeanglesout = []
for planeangle in planeanglenums_list:
a = geom[int(planeangle[0])-1][:4]
b = geom[int(planeangle[1])-1][:4]
c = geom[int(planeangle[2])-1][:4]
d = geom[int(planeangle[3])-1][:4]
e = geom[int(planeangle[4])-1][:4]
f = geom[int(planeangle[5])-1][:4]
ab = np.array([a[1]-b[1],a[2]-b[2],a[3]-b[3]]) # vectors
bc = np.array([b[1]-c[1],b[2]-c[2],b[3]-c[3]])
de = np.array([d[1]-e[1],d[2]-e[2],d[3]-e[3]])
ef = np.array([e[1]-f[1],e[2]-f[2],e[3]-f[3]])
n1 = np.cross(ab,bc) # Normal vectors
n2 = np.cross(de,ef)
planeangle_value = round(np.degrees(np.arccos(np.dot(n1,n2) / (np.linalg.norm(n1)*np.linalg.norm(n2)))),3)
planeangle_value = min(abs(planeangle_value),abs(180-planeangle_value))
planeanglesout.append(planeangle_value)
#this adds the data from the planeanglesout into the new property df
row_i = {}
for a in range(0, len(planeanglenums_list)):
entry = {'planeangle_'+str(planeangletitle_list[a]) + '(°)': planeanglesout[a]}
row_i.update(entry)
planeangle_dataframe = planeangle_dataframe.append(row_i, ignore_index=True)
except:
print('****Unable to acquire plane angle for:', row['log_name'], ".log")