-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpes2mp_driver.py
2117 lines (1836 loc) · 99 KB
/
pes2mp_driver.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/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 14 15:28:43 2023
@author: Apoorv Kushwaha, Pooja Chahal, Habit Tatin & Prof. T. J. Dhilip Kumar
This is the driver file for PES2MP containing most of the functions.
The changes to PES tamplate can be done directly here.
"""
###############################################################################
#--------------------------- Input Sanity Check! -----------------------------#
###############################################################################
#-----------------------------------------------------------------------------#
def exit_program():
import sys
print("\n Error in input file. Exiting the program...")
sys.exit(0)
def lenerr(var, lenx):
print("\n List Size Error! length of {} must be {}".format(var, lenx))
exit_program()
def varerr(inp, var):
try:
var
except NameError:
print("\n variable not found! ")
print("\n Provide {} in {}.py".format(var, inp))
exit_program()
else:
pass
#-----------------------------------------------------------------------------#
def PES_handler(inp,coll_typ):
print('\n Checking input file parameters! \n ')
if len (inp.Charge) !=3:
print("\n Invalid Charge list")
lenerr('Charge', 3)
if len (inp.Multiplicity) !=3:
print("\n Multiplicity Charge list")
lenerr('Multiplicity', 3)
print("Checking Radial coordinates (R_i, R_f & R_stp) ")
varerr(inp, inp.R_i)
varerr(inp, inp.R_f)
varerr(inp, inp.R_stp)
if (inp.R_i != inp.R_i != inp.R_i):
print("Inconsistent length of R_i, R_f, R_stp. \n Lists must be of equal length. ")
else:
print("Passed! Radial coordinates")
try:
inp.Use_isotope
except:
print('Not using Isotopes for COM')
else:
if len(inp.RR1_isotope_G) != len(inp.RR1_atoms):
lenerr('RR1_isotope_G', 'equal to RR1_atoms')
if len(inp.RR2_isotope_G) != len(inp.RR2_atoms):
lenerr('RR2_isotope_G', 'equal to RR2_atoms')
if len(inp.RR1_isotope_mass) != len(inp.RR1_atoms):
lenerr('RR1_isotope_mass', 'equal to RR1_atoms')
if len(inp.RR2_isotope_mass) != len(inp.RR2_atoms):
lenerr('RR2_isotope_mass', 'equal to RR2_atoms')
else:
print("\n List length of isotopes passed!: ")
if coll_typ == 1:
print("\n Requred parameters for 1D collision --> Passed! ")
elif (coll_typ == 2):
varerr(inp, inp.theta)
varerr(inp, inp.RR1_bond_len)
if len(inp.theta) != 3:
print("Invalid angular coordinates for collision type")
lenerr('theta', 3)
if len(inp.RR1_bond_len) != (len(inp.RR1_atoms)-1):
print("Invalid RR1_bond_length")
lenerr('RR1_bond_length', 'equal to RR1_atoms - 1 ')
print("\n Requred parameters for 2D collision --> Passed! ")
elif(coll_typ == 4):
varerr(inp, inp.phi)
varerr(inp, inp.theta2)
varerr(inp, inp.theta1)
varerr(inp, inp.RR1_bond_len)
varerr(inp, inp.RR2_bond_len)
if len(inp.phi) != 3:
print("Invalid angular coordinates for collision type")
lenerr('phi', 3)
if len(inp.theta2) != 3:
print("Invalid angular coordinates for collision type")
lenerr('theta2', 3)
if len(inp.theta1) != 3:
print("Invalid angular coordinates for collision type")
lenerr('theta1', 3)
if len(inp.RR1_bond_len) != (len(inp.RR1_atoms)-1):
print("Invalid RR1_bond_length")
lenerr('RR1_bond_length', 'equal to RR1_atoms - 1 ')
if len(inp.RR2_bond_len) != (len(inp.RR2_atoms)-1):
print("Invalid RR2_bond_length")
lenerr('RR2_bond_length', 'equal to RR2_atoms - 1 ')
print("\n Requred parameters for 4D collision --> Passed! ")
else :
print("Unrecognised collision type ↓ ")
print("Check PES2MP.py --> driver.file_handler(args*, x) !! ")
###############################################################################
def delete_files_in_directory(directory_path):
import os
import glob
try:
files = glob.glob(os.path.join(directory_path, '*'))
for file in files:
if os.path.isfile(file):
os.remove(file)
print("All files deleted successfully.")
except OSError:
print("Error occurred while deleting files.")
###############################################################################
#------------------------- Get COM for Rigid Rotor! --------------------------#
###############################################################################
def RR_com(f,RR_atoms, RR_bond_len,Charge, Multiplicity,RR_isotope_mass):
import psi4
# Creating rigid rotor (RR) coordinates below
RR_geom_x = RR_goem_iso(RR_atoms, RR_bond_len, RR_isotope_mass)
print("\n\nOriginal Geometry without charge and multiplicity!\n")
print('-x'*30)
print(RR_geom_x)
f.write("\n\n Original Geometry without charge and multiplicity!\n")
f.write('-x'*30)
f.write(str(RR_geom_x))
f.write('-x'*30)
f.write('\n')
RR_psi4 = psi4.geometry(RR_geom_x.format(Charge,Multiplicity)) # passing geometry in Psi4
psi4.core.Molecule.move_to_com(RR_psi4) # moving RR to COM
print('-x'*30)
print("\n\n Geometry after moving molecule to COM \n")
molvec = psi4.core.Molecule.save_string_xyz(RR_psi4) # printing new coorddinates
print(molvec) # printing molecule after moving to com
print('-x'*30)
print("\n The estimated rotational constant [x y z] by Psi4 in cm-1 : \n")
rtvec = psi4.core.Molecule.rotational_constants(RR_psi4)
print(str(rtvec.to_array())) # printing rotational constant (estimate)
f.write("\n\n Geometry after moving molecule to COM \n")
f.write('-x'*30)
f.write(str(psi4.core.Molecule.save_string_xyz(RR_psi4))) # saving new coorddinates
f.write('-x'*30)
f.write("\n The estimated rotational constant [x y z] by Psi4 in cm-1 : \n")
f.write(str(rtvec.to_array())) # printing rotational constant (estimate)
RR_COM_len = RR_com_extract(RR_psi4)
print('\nExtracted COM coordinates : \n ')
print(RR_atoms)
print(RR_COM_len)
f.write('\nExtracted COM coordinates for RR : \n ')
f.write(str(RR_atoms)+'\n')
f.write(str(RR_COM_len)+'\n')
return RR_psi4, RR_COM_len
#-----------------------------------------------------------------------------#
def RR_goem_iso(RR_atoms, RR_bond_len, RR_isotope_mass):
if RR_isotope_mass[0] == 0 :
RR_geom_x = """
{{}} {{}}
{} 0.000000 0.000000 0.000000
""".format(RR_atoms[0])
else:
RR_geom_x = """
{{}} {{}}
{}@{} 0.000000 0.000000 0.000000
""".format(RR_atoms[0], RR_isotope_mass[0])
R_tot = 0.000000
for i in range (len(RR_bond_len)):
R_tot += RR_bond_len[i]
if RR_isotope_mass[i+1] == 0 :
RR_geom_x += '''{} 0.000000 0.000000 {}\n'''.format(RR_atoms[i+1],R_tot)
else:
RR_geom_x += '''{}@{} 0.000000 0.000000 {}\n'''.format(RR_atoms[i+1],
RR_isotope_mass[i+1],
R_tot)
return RR_geom_x
#-----------------------------------------------------------------------------#
# extract coordinates after moving molecule to COM
def RR_com_extract(RR_psi4):
import psi4
RR_COM_str = psi4.core.Molecule.save_string_xyz(RR_psi4) # convert psi4 input to string
pattern = ''.join((x if x in '0123456789.-' else ' ') for x in RR_COM_str) # pattern to extract all numbers in string
rr_all_num = [float(i) for i in pattern.split()] # split numbers into list
RR_COM_len = rr_all_num[4::3] # [start: end : step] drops unnecessary terms
return RR_COM_len
###############################################################################
###############################################################################
#-------------------- Get 2D and 4D projected Coordinates! -------------------#
###############################################################################
#-----------------------------------------------------------------------------#
def proj2D (R, gamma):
from math import sin, cos, radians
# Rigid rotor (RR) lies on Z axis (no rotation of RR : no projection)
R_x = sin(radians(gamma))*R # projection of He on X axis
R_z = cos(radians(gamma))*R # projection of He on Z axis
return R_x, R_z
###############################################################################
#-----------------------------------------------------------------------------#
def proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len):
from math import sin, cos, radians
# Rigid rotor (RR) lies on Z axis (no rotation of RR : no projection)
# 3D projection for RR1
a1=sin(radians(theta1))*sin(radians(phi)) # projection on X axis
a2=sin(radians(theta1))*cos(radians(phi)) # projection on Y axis
a3=cos(radians(theta1)) # projection on Z axis
# 2D projection for RR2 (No Dihedral: No X axis projection)
b1=sin(radians(theta2)) # projection on Y axis
b2=cos(radians(theta2)) # projection on Z axis
RR_mat = [0] * (len(RR1_COM_len)*3 + len(RR2_COM_len)*2)
ct1=0
for i in range (0,len(RR1_COM_len)):
RR_mat[ct1] = RR1_COM_len[i] * a1
RR_mat[ct1+1] = RR1_COM_len[i] * a2
RR_mat[ct1+2] = RR1_COM_len[i] * a3
ct1+=3
for i in range (0,len(RR2_COM_len)):
RR_mat[ct1] = RR2_COM_len[i] *b1
RR_mat[ct1+1] = R + RR2_COM_len[i] *b2
ct1+=2
return RR_mat
###############################################################################
###############################################################################
#---------------- Create Gaussian Input Files (CP corrected) -----------------#
###############################################################################
#-----------------------------------------------------------------------------#
def gaussian_auxcm(Charge,Multiplicity):
FxD_geom_G = '{},{} {},{} {},{}\n'.format(Charge[2], Multiplicity[2], Charge[0],
Multiplicity[0], Charge[1], Multiplicity[1])
return FxD_geom_G
def gaussian_files_1D(f,Gaussian_input_template,RR1_atoms,RR2_atoms, Charge,Multiplicity,R,gaussian_data):
from tqdm import tqdm
# create 1D gaussian input Files (CP corrected)
F1D_geom_G = Gaussian_input_template + '\n\nR = {:.4f}\n\n'
F1D_geom_G += gaussian_auxcm(Charge, Multiplicity)
F1D_geom_G += '''{}(Fragment=1) 0.000000 0.000000 0.000000\n'''.format(RR1_atoms[0])
F1D_geom_G += '''{}(Fragment=2) 0.000000 0.000000 {{:.6f}}\n\n\n'''.format(RR2_atoms[0])
for j in tqdm(range (len(R))): # python loop to generate PES (using try and except to suppress error)
R_ii = R[j] # radial coordinate
inp_file = open(gaussian_data + '{:d}.gjf'.format(int(j)), "w") # open input file
inp_file.write(F1D_geom_G.format(R_ii, R_ii)) # write string to file
inp_file.close() # close file
return F1D_geom_G
###############################################################################
#-----------------------------------------------------------------------------#
def gaussian_files_2D(f,Gaussian_input_template,RR1_atoms,RR2_atoms,
Charge,Multiplicity,R,gaussian_data,RR1_COM_len,A):
from tqdm import tqdm
# create 2D gaussian input Files
F2D_geom_G = Gaussian_input_template + '\n\nR = {:.4f}, Theta={:.2f}\n\n'
F2D_geom_G += gaussian_auxcm(Charge,Multiplicity)
# appending gaussian template with RR atoms
for i in range (len(RR1_COM_len)):
F2D_geom_G += '''{}(Fragment=1) 0.000000 0.000000 {:.6f}\n'''.format(RR1_atoms[i],RR1_COM_len[i])
# appending gaussian template with collider atom and two blank lines
F2D_geom_G += '''{}(Fragment=2) {{:.6f}} 0.000000 {{:.6f}}\n\n\n'''.format(RR2_atoms[0])
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
gamma = A[j,1] # angular coordinate
R_x, R_z = proj2D (R, gamma) # calling 2D projection function
inp_file = open(gaussian_data + '{:d}.gjf'.format(int(j)), "w") # open input file
inp_file.write(F2D_geom_G.format(R, gamma, R_x, R_z)) # write string to file
inp_file.close() # close file
return F2D_geom_G
###############################################################################
#-----------------------------------------------------------------------------#
def gaussian_files_4D(f,Gaussian_input_template,RR1_atoms,RR2_atoms,
Charge,Multiplicity,R,gaussian_data,RR1_COM_len,RR2_COM_len,A):
from tqdm import tqdm
F4D_geom_G = Gaussian_input_template + '\n\nR = {:.4f}, Phi={:.2f}, Theta2={:.2f}, Theta1={:.2f}\n\n'
F4D_geom_G += gaussian_auxcm(Charge,Multiplicity)
# appending gaussian template with RR atoms
for i in range (len(RR1_COM_len)):
F4D_geom_G += '''{}(Fragment=1) {{:.6f}} {{:.6f}} {{:.6f}}\n'''.format(RR1_atoms[i])
# appending gaussian template with collider atom
for i in range (len(RR2_COM_len)):
F4D_geom_G += '''{}(Fragment=1) 0.000000 {{:.6f}} {{:.6f}}\n'''.format(RR2_atoms[i])
F4D_geom_G += '\n\n'
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
phi = A[j,1] # angular coordinate phi
theta2 = A[j,2] # angular coordinate theta2
theta1 = A[j,3] # angular coordinate theta1
RR_mat = proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len) # calling 4D projection function
inp_file = open(gaussian_data + '{:d}.gjf'.format(int(j)), "w") # open input file
inp_file.write(F4D_geom_G.format(R, phi, theta2, theta1, *RR_mat)) # write string to file
inp_file.close() # close file
return F4D_geom_G
###############################################################################
###############################################################################
#------------------ Create Molpro Input Files (CP corrected) -----------------#
###############################################################################
#-----------------------------------------------------------------------------#
def molpro_files_f1(Molpro_input_template):
FxD_geom_M = Molpro_input_template + """
Angstrom
!****************************************************************
! Energy of Complex !
!****************************************************************
text, complex
geometry={{{{
""".format()
return FxD_geom_M
#-----------------------------------------------------------------------------#
def molpro_files_CP_f2_1(Charge, Multiplicity):
FxD_geom_M = """}}}}
set, charge={}, spin={}
run_method
E_complex = energy
!****************************************************************
! Energy by ghosting other fragment !
!****************************************************************
""".format(Charge[2],Multiplicity[2]-1)
return FxD_geom_M
def molpro_files_CP_f2_2():
FxD_geom_M = """
text, cp for RR{}
dummy, {}
set, charge={}, spin={}
run_method
E_RR{} = energy
!**************************************************************** """
return FxD_geom_M
def molpro_files_CP_f2_3():
FxD_geom_M = """
! Energy of fragments at Infinity !
!****************************************************************
text, inf E for RR1
Angstrom
geometry={{{{
""".format()
return FxD_geom_M
#-----------------------------------------------------------------------------#
def molpro_files_CP_f3(Charge, Multiplicity):
FxD_geom_M = """}}}}
set, charge={}, spin={}
run_method
E_RR1_inf = energy
!****************************************************************
text, inf E for RR2
Angstrom
geometry={{{{
""".format(Charge[0],Multiplicity[0]-1)
return FxD_geom_M
#-----------------------------------------------------------------------------#
def molpro_files_CP_f4(Charge, Multiplicity):
FxD_geom_M = """}}}}
set, charge={}, spin={}
run_method
E_RR2_inf = energy
!****************************************************************
!****************************************************************
BSSE_RR1 = (E_RR1 - E_RR1_inf) !BSSE for RR
BSSE_RR2 = (E_RR2 - E_RR2_inf) !BSSE for Atom
bsse_tot = BSSE_RR1 + BSSE_RR2 !total BSSE
E_CP = E_complex - bsse_tot !CP correced E
""".format(Charge[1],Multiplicity[1]-1) # Molpro multiplicity = 2*S not 2S+1
return FxD_geom_M
#-----------------------------------------------------------------------------#
def molpro_files_CP_1D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_data):
from tqdm import tqdm
# appending molpro template for E_complex energy
F1D_geom_M = molpro_files_f1(Molpro_input_template)
F1D_geom_M += '''{} 0.000000 0.000000 0.000000\n'''.format(RR1_atoms[0])
F1D_geom_M += '''{} 0.000000 0.000000 {{:.6f}}\n'''.format(RR2_atoms[0])
# appending molpro template for bsse for each (using dummy)
F1D_geom_M += molpro_files_CP_f2_1(Charge, Multiplicity)
dumm1 = molpro_files_CP_f2_2()
F1D_geom_M += dumm1.format(1, RR2_atoms[0], Charge[0], Multiplicity[0]-1, 1)
dumm2 = molpro_files_CP_f2_2()
F1D_geom_M += dumm2.format(2, RR1_atoms[0], Charge[1], Multiplicity[1]-1, 2)
F1D_geom_M += molpro_files_CP_f2_3()
# appending molpro template for E_inf
F1D_geom_M += '''{} 0.000000 0.000000 0.000000\n'''.format(RR1_atoms[0])
F1D_geom_M += molpro_files_CP_f3(Charge, Multiplicity)
F1D_geom_M += '''{} 0.000000 0.000000 {{:.6f}}\n'''.format(RR2_atoms[0])
F1D_geom_M += molpro_files_CP_f4(Charge, Multiplicity)
# table
F1D_geom_M += """
R = {{:.4f}}
table,R,E_CP
digits, 4, 12
""".format()
for j in tqdm(range (len(R))): # python loop to generate PES (using try and except to suppress error)
R_ii = R[j] # radial coordinate
inp_file = open(molpro_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F1D_geom_M.format(R_ii, R_ii, R_ii)) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F1D_geom_M
#--------------------------------------------------------------------------------------#
def molpro_files_CP_2D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_data, RR1_COM_len, A):
from tqdm import tqdm
# appending molpro template for E_complex energy
F2D_geom_M = molpro_files_f1(Molpro_input_template)
for i in range (len(RR1_COM_len)):
F2D_geom_M += '''{} 0.000000 0.000000 {}\n'''.format(RR1_atoms[i], RR1_COM_len[i])
F2D_geom_M += '''{} {{:.6f}} 0.000000 {{:.6f}}\n'''.format(RR2_atoms[0])
F2D_geom_M += molpro_files_CP_f2_1(Charge, Multiplicity)
# appending molpro template for bsse for each (using dummy)
dumm1 = molpro_files_CP_f2_2()
F2D_geom_M += dumm1.format(1, RR2_atoms[0], Charge[0], Multiplicity[0]-1, 1)
dumm2 = molpro_files_CP_f2_2()
F2D_geom_M += dumm2.format(2, ', '.join(map(str, RR1_atoms)), Charge[1], Multiplicity[1]-1, 2)
F2D_geom_M += molpro_files_CP_f2_3()
# appending molpro template for E_inf
for i in range (len(RR1_COM_len)):
F2D_geom_M += '''{} 0.000000 0.000000 {:.6f}\n'''.format(RR1_atoms[i],RR1_COM_len[i])
F2D_geom_M += molpro_files_CP_f3(Charge, Multiplicity)
F2D_geom_M += '''{} {{:.6f}} 0.000000 {{:.6f}}\n'''.format(RR2_atoms[0])
F2D_geom_M += molpro_files_CP_f4(Charge, Multiplicity)
# table
F2D_geom_M += """
R = {{:.4f}}
Theta={{:.4f}}
table,R,Theta,E_CP
digits, 4, 4, 12
""".format()
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
gamma = A[j,1] # angular coordinate
R_x, R_z = proj2D (R, gamma) # calling 2D projection function
inp_file = open(molpro_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F2D_geom_M.format(R_x, R_z, R_x, R_z, R, gamma)) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F2D_geom_M
def molpro_files_CP_4D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_data, RR1_COM_len, RR2_COM_len, A):
from tqdm import tqdm
# appending molpro template for E_complex energy
F4D_geom_M = molpro_files_f1(Molpro_input_template)
for i in range (len(RR1_COM_len)):
F4D_geom_M += '''{} {{:.6f}} {{:.6f}} {{:.6f}} \n'''.format(RR1_atoms[i])
for i in range (len(RR2_COM_len)):
F4D_geom_M += '''{} 0.000000 {{:.6f}} {{:.6f}} \n'''.format(RR2_atoms[i])
F4D_geom_M += molpro_files_CP_f2_1(Charge, Multiplicity)
# appending molpro template for bsse for each (using dummy)
dumm1 = molpro_files_CP_f2_2()
F4D_geom_M += dumm1.format(1, ', '.join(map(str, RR2_atoms)), Charge[0], Multiplicity[0]-1, 1)
dumm2 = molpro_files_CP_f2_2()
F4D_geom_M += dumm2.format(2, ', '.join(map(str, RR1_atoms)), Charge[1], Multiplicity[1]-1, 2)
F4D_geom_M += molpro_files_CP_f2_3()
# appending molpro template for E_inf
for i in range (len(RR1_COM_len)):
F4D_geom_M += '''{} {{:.6f}} {{:.6f}} {{:.6f}} \n'''.format(RR1_atoms[i])
F4D_geom_M += molpro_files_CP_f3(Charge, Multiplicity)
for i in range (len(RR2_COM_len)):
F4D_geom_M += '''{} 0.000000 {{:.6f}} {{:.6f}} \n'''.format(RR2_atoms[i])
F4D_geom_M += molpro_files_CP_f4(Charge, Multiplicity)
# table
F4D_geom_M += """
R = {{:.4f}}
Phi={{:.4f}}
Theta2={{:.4f}}
Theta1={{:.4f}}
table,R,Phi,Theta2,Theta1,E_CP
digits, 4, 4, 4, 4, 12
""".format()
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
phi = A[j,1] # angular coordinate phi
theta2 = A[j,2] # angular coordinate theta2
theta1 = A[j,3] # angular coordinate theta1
RR_mat = proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len) # calling 4D projection function
inp_file = open(molpro_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F4D_geom_M.format(*RR_mat, *RR_mat, R, phi, theta2, theta1 )) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F4D_geom_M
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
###############################################################################
#---------------- Create Molpro Input Files (CBS extrapolated) ---------------#
###############################################################################
#-----------------------------------------------------------------------------#
def molpro_files_CBS_f2(basis_ref, basis):
F1D_geom_M_cbs = """
basis= {}
run_method
E_ref=energy
text,compute energies, extrapolate reference energy using EX1 and correlation energy using L3
extrapolate,basis={}:{}:{},method_c=l3,method_r=ex1,npc=2
{}=energy(1)
{}=energy(2)
{}=energy(3)
e_cbs=energy(4)
""".format(basis_ref,*basis,*basis)
return F1D_geom_M_cbs
#-----------------------------------------------------------------------------#
def molpro_files_CBS_1D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_cbs_data,
basis_ref,basis):
from tqdm import tqdm
# appending molpro template for E_complex energy
F1D_geom_M_cbs = molpro_files_f1(Molpro_input_template)
F1D_geom_M_cbs += '''{} 0.000000 0.000000 0.000000\n'''.format(RR1_atoms[0])
F1D_geom_M_cbs += '''{} 0.000000 0.000000 {{:.6f}}\n'''.format(RR2_atoms[0])
F1D_geom_M_cbs += """}}}}
set, charge={}, spin={}
""".format(Charge[2],Multiplicity[2]-1)
F1D_geom_M_cbs += molpro_files_CBS_f2(basis_ref, basis)
F1D_geom_M_cbs += """
!****************************************************************
R = {{:.4f}}
!****************************************************************
table,$R,${},${},${},$e_cbs
digits,2,10,10,10,10
""".format(*basis)
for j in tqdm(range (len(R))): # python loop to generate PES (using try and except to suppress error)
R_ii = R[j] # radial coordinate
inp_file = open(molpro_cbs_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F1D_geom_M_cbs.format(R_ii, R_ii, R_ii)) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F1D_geom_M_cbs
###############################################################################
#-----------------------------------------------------------------------------#
def molpro_files_CBS_2D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_cbs_data, RR1_COM_len,
A,basis_ref,basis):
from tqdm import tqdm
# appending molpro template for E_complex energy
F2D_geom_M_cbs = molpro_files_f1(Molpro_input_template)
for i in range (len(RR1_COM_len)):
F2D_geom_M_cbs += '''{} 0.000000 0.000000 {}\n'''.format(RR1_atoms[i],RR1_COM_len[i])
F2D_geom_M_cbs += '''{} {{:.6f}} 0.000000 {{:.6f}}\n'''.format(RR2_atoms[0])
F2D_geom_M_cbs += """}}}}
set, charge={}, spin={}
""".format(Charge[2],Multiplicity[2]-1)
F2D_geom_M_cbs += molpro_files_CBS_f2(basis_ref,basis)
F2D_geom_M_cbs += """
!****************************************************************
R = {{:.4f}}
Theta={{:.4f}}
!****************************************************************
table,$R,$Theta,${},${},${},$e_cbs
digits,2,2,10,10,10,10
""".format(*basis)
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
gamma = A[j,1] # angular coordinate
R_x, R_z = proj2D (R, gamma) # calling 2D projection function
inp_file = open(molpro_cbs_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F2D_geom_M_cbs.format(R_x, R_z, R, gamma)) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F2D_geom_M_cbs
###############################################################################
#-----------------------------------------------------------------------------#
def molpro_files_CBS_4D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_cbs_data, RR1_COM_len,
RR2_COM_len, A, basis_ref, basis):
from tqdm import tqdm
# appending molpro template for E_complex energy
F4D_geom_M_cbs = molpro_files_f1(Molpro_input_template)
for i in range (len(RR1_COM_len)):
F4D_geom_M_cbs += '''{} {{:.6f}} {{:.6f}} {{:.6f}}\n'''.format(RR1_atoms[i])
for i in range (len(RR2_COM_len)):
F4D_geom_M_cbs += '''{} 0.000000 {{:.6f}} {{:.6f}}\n'''.format(RR2_atoms[i])
F4D_geom_M_cbs += """}}}}
set, charge={}, spin={}
""".format(Charge[2],Multiplicity[2]-1)
F4D_geom_M_cbs += molpro_files_CBS_f2(basis_ref,basis)
F4D_geom_M_cbs += """
!****************************************************************
R = {{:.4f}}
Phi = {{:.4f}}
Theta2 = {{:.4f}}
Theta1 = {{:.4f}}
!****************************************************************
table,R,Phi,Theta2,Theta1,${},${},${},$e_cbs
digits,2,2,2,2,10,10,10,10
""".format(*basis)
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
phi = A[j,1] # angular coordinate phi
theta2 = A[j,2] # angular coordinate theta2
theta1 = A[j,3] # angular coordinate theta1
RR_mat = proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len) # calling 4D projection function
inp_file = open(molpro_cbs_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F4D_geom_M_cbs.format(*RR_mat, R, phi, theta2, theta1 )) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F4D_geom_M_cbs
#-----------------------------------------------------------------------------#
###############################################################################
#----------- Create Molpro Input Files (Custom for SAPT/MRCI etc.) -----------#
###############################################################################
def molpro_files_custom_1D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_ext_data,molpro_ext):
from tqdm import tqdm
# appending molpro template for E_complex energy
F1D_geom_M_ext = Molpro_input_template + '''
!****************************************************************
! Molpro custom calculations !
!****************************************************************
'''
F1D_geom_M_ext += "R = {:.6f}"
F1D_geom_M_ext += '''
Angstrom
geometry={{{{
'''.format()
F1D_geom_M_ext += '''{} 0.000000 0.000000 0.000000\n'''.format(RR1_atoms[0])
F1D_geom_M_ext += '''{} 0.000000 0.000000 R\n'''.format(RR2_atoms[0])
F1D_geom_M_ext += """}}}}
set, charge={}, spin={}
""".format(Charge[2],Multiplicity[2]-1)
F1D_geom_M_ext += molpro_ext
for j in tqdm(range (len(R))): # python loop to generate PES (using try and except to suppress error)
R_ii = R[j] # radial coordinate
inp_file = open(molpro_ext_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F1D_geom_M_ext.format(R_ii,R_ii)) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F1D_geom_M_ext
###############################################################################
#-----------------------------------------------------------------------------#
def molpro_files_custom_2D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_ext_data,
RR1_COM_len, A, molpro_ext):
from tqdm import tqdm
# appending molpro template for E_complex energy
print(Molpro_input_template)
F2D_geom_M_ext = Molpro_input_template + '''
!****************************************************************
! Molpro custom calculations !
!****************************************************************
'''
print(F2D_geom_M_ext)
for ii in range (len(RR1_COM_len)): # variables are declaired separately
F2D_geom_M_ext += "R{} = {} \n".format(ii+1, RR1_COM_len[ii])
F2D_geom_M_ext += "R{} = {{:.6f}} \nR{} = {{:.6f}} \n".format(ii+2, ii+3)
F2D_geom_M_ext += '''
Angstrom
geometry={{{{
'''.format()
for i in range (len(RR1_COM_len)):
F2D_geom_M_ext += '''{} 0.000000 0.000000 R{}\n'''.format(RR1_atoms[i],i+1)
F2D_geom_M_ext += '''{} R{} 0.000000 R{}\n'''.format(RR2_atoms[0], i+2, i+3)
F2D_geom_M_ext += """}}}}
set, charge={}, spin={}
""".format(Charge[2],Multiplicity[2]-1)
F2D_geom_M_ext += '''
R = {:.4f}
Theta = {:.4f}
'''
F2D_geom_M_ext += molpro_ext
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
gamma = A[j,1] # angular coordinate
R_x, R_z = proj2D (R, gamma) # calling 2D projection function
inp_file = open(molpro_ext_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F2D_geom_M_ext.format(R_x, R_z, R, gamma)) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F2D_geom_M_ext
###############################################################################
#-----------------------------------------------------------------------------#
def molpro_files_custom_4D(f,Molpro_input_template,RR1_atoms,RR2_atoms,Charge,Multiplicity,R,molpro_ext_data,
RR1_COM_len, RR2_COM_len, A, molpro_ext):
from tqdm import tqdm
# appending molpro template for E_complex energy
F4D_geom_M_ext = Molpro_input_template + '''
!****************************************************************
! Molpro custom calculations !
!****************************************************************
'''
for ii in range (len(RR1_COM_len)): # variables are declaired separately
F4D_geom_M_ext += "R{} = {{:.6f}} \nR{} = {{:.6f}} \nR{} = {{:.6f}} \n".format(ii*3+1,ii*3+2,ii*3+3)
for jj in range (len(RR2_COM_len)): # variables are declaired separately
F4D_geom_M_ext += "R{} = {{:.6f}} \nR{} = {{:.6f}} \n".format((ii+1)*3+(jj*2)+1,(ii+1)*3+(jj*2)+2)
F4D_geom_M_ext += '''
Angstrom
geometry={{{{
'''.format()
for i in range (len(RR1_COM_len)):
F4D_geom_M_ext += '''{} R{} R{} R{}\n'''.format(RR1_atoms[i], i*3+1,i*3+2,i*3+3)
for j in range (len(RR2_COM_len)):
F4D_geom_M_ext += '''{} 0.000000 R{} R{}\n'''.format(RR2_atoms[j],(i+1)*3+(j*2)+1,(i+1)*3+(j*2)+2)
F4D_geom_M_ext += """}}}}
set, charge={}, spin={}
""".format(Charge[2],Multiplicity[2]-1)
F4D_geom_M_ext += '''
R = {:.4f}
Phi = {:.4f}
Theta2 = {:.4f}
Theta1 = {:.4f}
'''
F4D_geom_M_ext += molpro_ext
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
R = A[j,0] # radial coordinate
phi = A[j,1] # angular coordinate phi
theta2 = A[j,2] # angular coordinate theta2
theta1 = A[j,3] # angular coordinate theta1
RR_mat = proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len) # calling 4D projection function
inp_file = open(molpro_ext_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(F4D_geom_M_ext.format(*RR_mat, R, phi, theta2, theta1 )) # write string to file
inp_file.close() # close file
#print("\n Molpro files created! \n")
return F4D_geom_M_ext
###############################################################################
#-------------------- Create Psi4 Input Files with coordinates ---------------#
###############################################################################
def psi4_input_1D(inp):
F1D_geom = ''
if inp.psi4_bsse == None:
F1D_geom += " {} {} \n".format(inp.Charge[2],inp.Multiplicity[2])
F1D_geom += '''{} 0.000000 0.000000 0.000000 \n'''.format(inp.RR1_atoms[0])
F1D_geom += '''{} 0.000000 0.000000 {{:.6f}}\n'''.format(inp.RR2_atoms[0])
else:
F1D_geom += "{} {} \n-- \n".format(inp.Charge[2],inp.Multiplicity[2])
F1D_geom += ' {} {} \n'.format(inp.Charge[0],inp.Multiplicity[0])
F1D_geom += '''{} 0.000000 0.000000 0.000000 \n'''.format(inp.RR1_atoms[0])
F1D_geom += "-- \n {} {} \n".format(inp.Charge[1],inp.Multiplicity[1])
F1D_geom += '''{} 0.000000 0.000000 {{:.6f}}\n'''.format(inp.RR2_atoms[0])
F1D_geom += "\n no_com \n no_reorient \n "
return F1D_geom
#-----------------------------------------------------------------------------#
def psi4_input_2D(inp,RR1_psi4):
import psi4
F2D_geom = ''
if inp.psi4_bsse == None:
#F2D_geom += " {} {} \n".format(inp.Charge[2],inp.Multiplicity[2])
RR1_psi4_xyz = psi4.core.Molecule.save_string_xyz(RR1_psi4)
F2D_geom += RR1_psi4_xyz
F2D_geom += '''{} {{:.6f}} 0.000000 {{:.6f}}'''.format(inp.RR2_atoms[0])
else:
F2D_geom += "{} {} \n-- \n".format(inp.Charge[2],inp.Multiplicity[2])
#F2D_geom += " {} {} \n".format(inp.Charge[0],inp.Multiplicity[0])
RR1_psi4_xyz = psi4.core.Molecule.save_string_xyz(RR1_psi4)
F2D_geom += RR1_psi4_xyz
F2D_geom += "-- \n {} {} \n".format(inp.Charge[1],inp.Multiplicity[1])
F2D_geom += '''{} {{:.6f}} 0.000000 {{:.6f}}'''.format(inp.RR2_atoms[0])
F2D_geom += "\n no_com \n no_reorient \n"
return F2D_geom
#-----------------------------------------------------------------------------#
def psi4_input_4D(inp,RR1_COM_len,RR2_COM_len):
F4D_geom = ''
if inp.psi4_bsse == None:
F4D_geom += " {} {} \n".format(inp.Charge[2],inp.Multiplicity[2])
for i in range (len(RR1_COM_len)):
F4D_geom += '''{} {{:.6f}} {{:.4f}} {{:.6f}}\n'''.format(inp.RR1_atoms[i])
for i in range (len(RR2_COM_len)):
F4D_geom += '''{} 0.000000 {{:.6f}} {{:.6f}}\n'''.format(inp.RR2_atoms[i])
else:
F4D_geom += "{} {} \n-- \n".format(inp.Charge[2],inp.Multiplicity[2])
F4D_geom += " {} {} \n".format(inp.Charge[0],inp.Multiplicity[0])
for i in range (len(RR1_COM_len)):
F4D_geom += '''{} {{:.6f}} {{:.4f}} {{:.6f}}\n'''.format(inp.RR1_atoms[i])
F4D_geom += "-- \n {} {} \n".format(inp.Charge[1],inp.Multiplicity[1])
for i in range (len(RR2_COM_len)):
F4D_geom += '''{} 0.000000 {{:.6f}} {{:.6f}}\n'''.format(inp.RR2_atoms[i])
F4D_geom += "\n no_com \n no_reorient \n symmetry c1 \n"
return F4D_geom
#-----------------------------------------------------------------------------#
#-----------------------------------------------------------------------------#
###############################################################################
#-------------------------------- Various Plots ------------------------------#
###############################################################################
def mirror(df_out1,header_keep,z1_3d):
import pandas as pd
max_theta = max(df_out1[header_keep].unique())
if (max_theta == 90):
print('Max angle is 90 mirroring to 180')
z1_3d_mir90 = z1_3d.iloc[:,::-1] # new df mirror
z1_3d_mir90 = z1_3d_mir90.drop(90,axis=1) # dropping 90
z1_3d_mir90.columns = list(map(lambda x: 180-x , z1_3d_mir90.columns)) # renaming columns (angles)
lst = [z1_3d, z1_3d_mir90] # List of two dataframes
z1_3d = pd.concat(lst, axis =1) # combining dataframes
max_theta = 180
if (max_theta == 180):
print('Max angle is 180 mirroring to 360')
z1_3d_mir180 = z1_3d.iloc[:,::-1] # new df mirror
z1_3d_mir180 = z1_3d_mir180.drop(180,axis=1) # dropping 180
z1_3d_mir180.columns = list(map(lambda x: 360-x , z1_3d_mir180.columns)) # renaming columns (angles)
#z1_3d_mir180 = z1_3d_mir180.drop(360,axis=1) # dropping 360
lst = [z1_3d, z1_3d_mir180] # List of two dataframes
z1_3d = pd.concat(lst, axis =1) # combining dataframes
print("New dataframe till 360 degrees!")
return z1_3d
###############################################################################
#-----------------------------------------------------------------------------#
def plot_4D_proj(df_out1, header_keep, header_drop1, header_drop1_val, header_drop2,
header_drop2_val, out_data_plots, out_plots, inp):
import numpy as np
import matplotlib.pyplot as plt
df_res = df_out1.loc[(df_out1[header_drop1]==header_drop1_val) &
(df_out1[header_drop2]==header_drop2_val)]
df_res = df_res.drop([header_drop1, header_drop2], axis=1)
df_res.reset_index(drop=True, inplace=True)
df_res.to_csv(out_data_plots + "data_df_%s_%s_%d_%d.dat"
%(header_drop1,header_drop2, header_drop1_val,header_drop2_val),
index=None,columns =['R',header_keep,'E'],sep=',')
z1_3d = df_res.pivot(index=df_res.columns[0], columns=df_res.columns[1],
values=df_res.columns[2])
z1_3d.to_csv(out_data_plots + "data_mat_%s_%s_%d_%d.dat"
%(header_drop1,header_drop2, header_drop1_val,header_drop2_val),
header=True,sep='\t')
z1_3d = mirror(df_res,header_keep,z1_3d) # mirroring to 360 degrees
plt.figure(figsize=(20,8)) # plot size
theta = np.radians(z1_3d.columns) # theta converted to radians
r = df_res[df_out1.columns[0]].unique() # extracting R values
try:
inp.E_lim
inp.E_stp
except:
min_E = int(min(z1_3d.min()))-1
levels_min = np.arange(min_E,0,0.1) # levels for energies minima
levels_max = np.arange(0,-min_E+1,0.1) # levels for energies maxima
else:
levels_min = np.arange(inp.E_lim[0],0,inp.E_stp) # levels for energies minima
levels_max = np.arange(0,inp.E_lim[1] + inp.E_stp,inp.E_stp) # levels for energies maxima
levels = np.append(levels_min, levels_max) # combined levels
ax = plt.axes(projection="polar") # polar plot initialization
[X, Y] = np.meshgrid(theta, r) # 2D mesh creation
cp = plt.contourf(X, Y, z1_3d,levels,cmap='seismic', extend="both") # contour plot
plt.colorbar(cp, pad = 0.12) # colorbar position
ax.set_facecolor("maroon") # set background color
plt.grid(True,linestyle=':') # grid on
plt.minorticks_on() # minor ticks are on
plt.title("Polar Plot of {} vs R at ({} = {} and {} = {})".format (header_keep,header_drop1,
header_drop1_val, header_drop2,
header_drop2_val)) # title of plot
try:
inp.plt_x_axis
except:
print('No x lebel provided. Using Default!')
plt.xlabel(r'R $\mathrm{(\AA)}$') # X label (written in latex $...$ format)
else:
plt.xlabel(inp.plt_x_axis)
ax.xaxis.set_label_coords(1.07, 0.745) # position of label R
plt.ylim(0,inp.R_lim[1]) # y limit
#plt.xlim(0, 2*np.pi) # x limit (not needed)
# Use polar_plot_%s_%s_%d_%d.eps and format='eps to save polar contour in eps format
plt.savefig(out_plots+'polar_plot_%s_%s_%d_%d.'
%(header_drop1,header_drop2,int(header_drop1_val),int(header_drop2_val)) + inp.fmt,
format=inp.fmt,bbox_inches='tight') # save polar contour in pdf (tight layout)
#plt.show() # preview for jupyter notebook only
plt.close()
###############################################################################
#-----------------------------------------------------------------------------#
def plot_2D_proj(df_out1, z1_3d, out_data, out_plots, inp):
import numpy as np
import matplotlib.pyplot as plt
plt.figure(figsize=(20,8)) # figure size
theta = np.radians(z1_3d.columns) # theta converted to radians
r = df_out1[df_out1.columns[0]].unique() # extracting R values
try:
inp.E_lim
inp.E_stp
except:
min_E = int(min(z1_3d.min()))-1
levels_min = np.arange(min_E,0,0.1) # levels for energies minima
levels_max = np.arange(0,-min_E+1,0.1) # levels for energies maxima
else:
levels_min = np.arange(inp.E_lim[0],0,inp.E_stp) # levels for energies minima
levels_max = np.arange(0,inp.E_lim[1] + inp.E_stp,inp.E_stp) # levels for energies maxima
levels = np.append(levels_min, levels_max) # combined levels
#print('Energy levels are : ', levels)
ax = plt.axes(projection="polar") # polar plot initialization
[X, Y] = np.meshgrid(theta, r) # 2D mesh creation
cp = plt.contourf(X, Y, z1_3d,levels,cmap='seismic', extend="both") # contour plot
plt.colorbar(cp, pad = 0.12) # colorbar position
ax.set_facecolor("maroon") # set background color
plt.grid(True,linestyle=':') # grid on
plt.minorticks_on() # minor ticks are on
try:
inp.plt_title
except:
print('No plot title provided. Using Default!')
plt.title("Polar Plot") # title of plot