-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpes2mp.py
3124 lines (2712 loc) · 157 KB
/
pes2mp.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
main file for PES2MP package (to debug/modify --> refer manual)
This program:
(*) imports necessary libraries
(*) creates required folders
(*) PESGen:
(*) calculates and moves respective Rigid Rotor(s) (RR) to COM.
(*) generates PES using Psi4 internally (for rough estimation)
(*) generates input files by transforming Jacobi coordinates (R, θ_n) to XYZ
(*) auxillary scripts are provided for external calculations (Molpro/Gaussian) and collecting results
(*) PESPlot:
(*) Plots 1D/2D and 4D PES using (a) R vs E plots and (b) polar plots
(*) NNGen:
(*) Can generate NN model for augmenting PES2MP
(*) Can handle N inputs and M outputs with PES and non-PES data
(*) MPExp:
(*) Does Multipole expansion of 2D and 4D PES
(*) 2D PES is expanded using Legendre polynomials and 4D using Spherical Harmonics
(*) Also performs inverse fitting after analytical fitting to print residual errors.
(*) AnaFit:
(*) Uses analytical expressions for fitting either PES or V Lambda terms.
"""
# general libraries
import numpy as np
import pandas as pd
# importing driver.py
import pes2mp_driver as driver
import os
from tqdm import tqdm
import shutil
import sys
import importlib
# uncomment the fllowing two linesto catch segmentation error!!
# import faulthandler
# faulthandler.enable()
# defining current directory for creating new directories
input_dir = os.getcwd()+'/'
# the fllowing two lines define input file for pes2mp
inputfile = sys.argv[1]
sys.path.append(input_dir)
inp = importlib.import_module(inputfile)
# original_stdout = sys.stdout # Save a reference to the original standard output
driver.varerr(inp, inp.Proj_name)
Proj_name = inp.Proj_name
out_data = input_dir + 'Projects/' + Proj_name + '/' # directory for psi4 data
if not os.path.exists(out_data):
os.makedirs(out_data)
input_files_data = out_data + 'input_files/' # directory for Gaussian/Molpro input files
if not os.path.exists(input_files_data):
os.makedirs(input_files_data)
log_filex = inp.Proj_name + '.log' # Set a project name (Important)
f = open(out_data+log_filex, 'a+')
print('Necessary files Created')
f.write("##################################################################")
f.write("\n#################### PES2MP Initiated ######################")
f.write("\n##################################################################")
f.write('\n \n /data and /project folders created.')
# with open(out_data+log_filex, 'w+') as f:
# sys.stdout = f # Change the standard output to the file we created.
# print('/data/ ; /psi4_PES_data/ ; /scratch/ folders created.')
# sys.stdout = original_stdout # Reset the standard output to its original value
# The program checks for job type in the input file uses series of if-else
# commands to execute the task inside the jobtype.
try:
inp.Create_PES_input
except:
print("Create_PES_input not provided! Skipping PESGen module!")
PESGen =False
direct_plot = False
else:
PESGen = inp.Create_PES_input
###############################################################################
###############################################################################
########################## PES Generation #####################################
###############################################################################
###############################################################################
if PESGen == True:
print("Using PESGen module!")
import psi4
coll_1D = False
coll_2D = False
coll_4D = False
# determining nature of collision (1D/2D/4D)
f.write("\nIdentifying collision type !!!: ")
if (len(inp.RR1_atoms) == 1 and len(inp.RR2_atoms) == 1):
coll_1D = True
print("\n \t atom-atom collision: Using 1D template for PES")
f.write("\n \t atom-atom collision: Using 1D template for PES")
driver.PES_handler(inp, 1)
elif (len(inp.RR1_atoms) > 1 and len(inp.RR2_atoms) == 1):
coll_2D = True
print("\n \t RR1 has >1 atoms and RR2 has 1 atom: Using 2D Template for PES")
f.write("\n \t RR1 has >1 atoms and RR2 has 1 atom: Using 2D Template for PES")
driver.PES_handler(inp, 2)
elif (len(inp.RR1_atoms) > 1 and len(inp.RR2_atoms) > 1):
coll_4D = True
print("\n \t Both RR1 and RR2 have >1 atoms: Using 4D Template for PES")
f.write("\n \t Both RR1 and RR2 have >1 atoms: Using 4D Template for PES")
driver.PES_handler(inp, 4)
else:
print("\n Something wrong with the input atoms.\n")
print("\n For 1D collision, make sure that the num of atoms in the lists: RR1 = 1 and RR2 = 1")
print("\n For 2D collision, make sure that the num of atoms in the lists: RR1 > 1 and RR2 = 1")
print("\n For 2D collision, make sure that the num of atoms in the lists: RR1 > 1 and RR2 > 1")
f.write("\n Something wrong with the input atoms.\n")
f.write("\n For 1D collision, make sure that the num of atoms in the lists: RR1 = 1 and RR2 = 1")
f.write("\n For 2D collision, make sure that the num of atoms in the lists: RR1 > 1 and RR2 = 1")
f.write("\n For 2D collision, make sure that the num of atoms in the lists: RR1 > 1 and RR2 > 1")
driver.exit_program()
R = np.empty(0)
for i in range (len(inp.R_i)):
R_1 = np.arange(inp.R_i[i], inp.R_f[i], inp.R_stp[i]) # R_1 from R_i to R_f Ang with step size R_stp Ang
R = np.concatenate((R,R_1),axis=None) # merging R columns
r_n = len(R) # saving number of R data points
print("\n The R coodinates are: \n", R)
print("\n Total number of data points in R coordinates are: ", r_n)
r4 = np.atleast_2d(R).T # Converting R from row to column vector
f.write("\n \n The R coodinates are: \n")
f.write(str(R))
f.write("\n\n Total number of data points in R coordinates are: {} \n\n".format (r_n))
# saving and printing coordinates
print("Saving input coordinates in 'data/proj_name'")
if coll_1D:
np.savetxt(out_data + "1D_input_coordinates.dat", R,fmt='%.2f')
elif coll_2D:
# creating matrix for 2D collision coordinates
ang_i= inp.theta
A_nr = np.ndarray(shape=(1,2)) # R, theta array initialization
for i_gamma in tqdm(range (ang_i[0], ang_i[1], ang_i[2])):
b = np.array([i_gamma]) # defining array with angle
c = np.tile(b,(r_n,1)) # creating angles as columns
d = np.c_[ r4, c ] # joining r and columns
A_nr = np.vstack([A_nr, d]) # repeating for different geoms and joining
A_nr = np.delete(A_nr, 0, 0) # deleting first row (empty)
# sorting coordinates by theta and then R
keys = (A_nr[:, 1], A_nr[:, 0])
# creating matrix for 2D collision coordinates
sorted_indices = np.lexsort(keys)
A = A_nr[sorted_indices]
# creating matrix for 4D collision coordinates
elif coll_4D:
phi= inp.phi
th2= inp.theta2
th1 = inp.theta1
A_nr = np.ndarray(shape=(1,4)) # internal coordinates array initialization
# to include final value in python, step size is added to it.
for i_phi in tqdm(range (phi[0],phi[1],phi[2])):
for j_theta2 in range (th2[0],th2[1],th2[2]):
for k_theta1 in range (th1[0],th1[1],th1[2]):
b = np.array([i_phi,j_theta2,k_theta1]) # defining array with angle
c = np.tile(b,(r_n,1)) # creating angles as columns
d = np.c_[ r4, c ] # joining r and columns
A_nr = np.vstack([A_nr, d]) # repeating for different geoms and joining
A_nr = np.delete(A_nr, 0, 0) # deleting first row (empty)
# sorting coordinates by phi, th2, th1 and then R
keys = (A_nr[:, 3], A_nr[:, 2], A_nr[:, 1], A_nr[:, 0])
# creating matrix for 4D collision coordinates
sorted_indices = np.lexsort(keys)
A = A_nr[sorted_indices]
else:
# this condition is non viable
pass
# checking if isotopic substitution is requested!
try:
inp.Use_isotope
except:
Use_isotope = False
print('\n Not using isotopic substitution! \n')
else:
Use_isotope = inp.Use_isotope
if Use_isotope:
print('\n Using isotopic substitution! \n')
f.write('\n Using isotopic substitution! \n')
RR1_isotope_mass = inp.RR1_isotope_mass
RR2_isotope_mass = inp.RR2_isotope_mass
#RR1_isotope_G = inp.RR1_isotope_G
#RR2_isotope_G = inp.RR2_isotope_G
else:
RR1_isotope_mass = [0] * len(inp.RR1_atoms)
RR2_isotope_mass = [0] * len(inp.RR2_atoms)
#RR1_isotope_G = [0] * len(inp.RR1_atoms)
#RR2_isotope_G = [0] * len(inp.RR1_atoms)
# Printing coordinates for 2D/4D rigid rotors and extracting COM coordinates
if coll_1D:
pass
else:
# if 2D/4D collision
print('\n Input coordinates (first 5, mid and last 5)\n')
print(A[:5]) # prints first 5 coordinates of R, gamma
print('---')
half_c = int(len(A)/2)
print(A[half_c-3:half_c+2]) # prints mid coordinates of R, gamma
print('---')
print(A[-5:]) # prints last 5 coordinates of R, gamma
print("\nTotal number of input coordinates : ",len(A))
f.write('\n Input coordinates (first 5, mid and last 5)\n')
f.write('\n' + str(A[:5]) + '\n') # prints first 5 coordinates of R, gamma
f.write('---')
f.write('\n' + str(A[half_c-3:half_c+2]) + '\n' ) # prints mid coordinates of R, gamma
f.write('---')
f.write('\n' + str(A[-5:]) + '\n' ) # prints last 5 coordinates of R, gamma
f.write("\nTotal number of input coordinates : {}".format(len(A)))
# Creating rigid rotor 1 (RR1) coordinates below and extracting COM coordinates
RR1_psi4, RR1_COM_len = driver.RR_com(f, inp.RR1_atoms, inp.RR1_bond_len,
inp.Charge[0], inp.Multiplicity[0],
RR1_isotope_mass)
if coll_2D:
np.savetxt(out_data + "2D_input_coordinates.dat", A,fmt='%.2f\t%d')
elif coll_4D:
np.savetxt(out_data + "4D_input_coordinates.dat", A,fmt='%.2f\t%d\t%d\t%d')
# Creating RR2 input file with XYZ coordinates below and extracting COM coordinates
RR2_psi4, RR2_COM_len = driver.RR_com(f, inp.RR2_atoms, inp.RR2_bond_len,
inp.Charge[1], inp.Multiplicity[1],
RR2_isotope_mass)
else:
pass
###############################################################################
#-----------------------Gaussian Input Parameters-----------------------------#
###############################################################################
try:
inp.Create_GAUSSIAN_input_files
except:
Create_GAUSSIAN_input_files = False
else:
Create_GAUSSIAN_input_files = inp.Create_GAUSSIAN_input_files
print("\nCreating Gaussian Input files!\n")
# creating input files for Gaussian (CP corrected) ########################
if Create_GAUSSIAN_input_files:
gaussian_data = input_files_data + 'Gaussian_CP/' # directory for psi4 data
# creating gaussian directory
if not os.path.exists(gaussian_data):
os.makedirs(gaussian_data)
# appending gaussian template with charge spin and other info!
Gaussian_input_template = "%nprocshared={}".format(inp.proc_g)
Gaussian_input_template += "\n%mem={}".format(inp.mem_g)
Gaussian_input_template += "\n%chk={}.chk\n".format(inp.chk_g)
Gaussian_input_template += inp.cmd_g
# Creating input files by calling appropriate function in driver file.
#-------------------------------# Gaussian 1D #-------------------------------#
if coll_1D:
FxD_geom_G = driver.gaussian_files_1D(f, Gaussian_input_template,
inp.RR1_atoms, inp.RR2_atoms,
inp.Charge, inp.Multiplicity,
R, gaussian_data)
#-------------------------------# Gaussian 2D #-------------------------------#
elif coll_2D :
FxD_geom_G = driver.gaussian_files_2D(f, Gaussian_input_template,
inp.RR1_atoms, inp.RR2_atoms,
inp.Charge, inp.Multiplicity,
R, gaussian_data, RR1_COM_len,A)
#-------------------------------# Gaussian 4D #-------------------------------#
elif coll_4D:
FxD_geom_G = driver.gaussian_files_4D(f, Gaussian_input_template,
inp.RR1_atoms, inp.RR2_atoms,
inp.Charge, inp.Multiplicity,
R, gaussian_data, RR1_COM_len,
RR2_COM_len, A)
else:
print('ID: 260 --> All coll_1D, coll_2D and coll_4D are False. Check for error!')
f.write("\n---- Gaussian input file template : see Template_Gaussian_CP.dat .")
template_filex = 'Template_Gaussian_CP.log'
f2 = open(input_files_data+template_filex, 'a+')
f2.write(str(FxD_geom_G))
f2.close()
print(" \n Gaussian (CP) Input files Created! \n")
f.write('\n Gaussian (CP) Input files Created! \n ')
else:
print(" \n Create_GAUSSIAN_input_files = False : Skipping Gaussian (CP) Input! \n")
f.write('\n Create_GAUSSIAN_input_files = False : Skipping Gaussian (CP) Input! \n ')
###############################################################################
#-----------------------Molpro Input Parameters (CP)--------------------------#
###############################################################################
try:
inp.Create_MOLPRO_CP_input_files
except:
Create_MOLPRO_CP_input_files = False
else:
Create_MOLPRO_CP_input_files = inp.Create_MOLPRO_CP_input_files
print("\nCreating molpro (CP) Input files!\n")
# creating input files for Molpro (CP corrected) ########################
if Create_MOLPRO_CP_input_files:
molpro_data = input_files_data + 'Molpro_CP/' # directory for psi4 data
if not os.path.exists(molpro_data):
os.makedirs(molpro_data)
Molpro_input_template = "***,single point energies \n"
Molpro_input_template += "memory,{}\n".format(inp.mem_m)
Molpro_input_template += "basis= {}\n".format(inp.basis_cp)
Molpro_input_template += "run_method={}\n".format(inp.run_method)
# converting RR atoms with label eg. C1, C2, etc.
RR1_name = [f'{name}{ii}' for ii, name in enumerate(inp.RR1_atoms, 1)]
RR2_name = [f'{name}{iii}' for iii, name in enumerate(inp.RR2_atoms, len(inp.RR1_atoms)+1)]
#print(psi4.core.Molecule.mass(RR1_psi4))
#-----------------------------# Molpro 1D (CP) #------------------------------#
if coll_1D:
FxD_geom_M = driver.molpro_files_CP_1D(f, Molpro_input_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_data)
#-------------------------------# Molpro 2D #-------------------------------#
elif coll_2D :
FxD_geom_M = driver.molpro_files_CP_2D(f, Molpro_input_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_data,
RR1_COM_len, A)
#-------------------------------# Molpro 4D #-------------------------------#
elif coll_4D:
FxD_geom_M = driver.molpro_files_CP_4D(f, Molpro_input_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_data,
RR1_COM_len, RR2_COM_len, A)
else:
print('ID: 317 --> All coll_1D, coll_2D and coll_4D are False. Check for error!')
f.write("\n---- Molpro input file template : see Template_Molpro_CP.dat.")
template_filex = 'Template_Molpro_CP.log'
f3 = open(input_files_data+template_filex, 'a+')
f3.write(str(FxD_geom_M))
f3.close()
print(" \n Molpro (CP) Input files Created! \n")
f.write('\n Molpro (CP) Input files Created! \n ')
else:
print(" \n Create_MOLPRO_input_files = False : Skipping Molpro (CP) Input! \n")
f.write('\n Create_MOLPRO_input_files = False : Skipping Molpro (CP) Input! \n ')
###############################################################################
#----------------------Molpro Input Parameters (CBS)--------------------------#
###############################################################################
try:
inp.Create_MOLPRO_CBS_input_files
except:
Create_MOLPRO_CBS_input_files = False
else:
Create_MOLPRO_CBS_input_files = inp.Create_MOLPRO_CBS_input_files
print("\nCreating molpro (CBS) Input files!\n")
# creating input files for Molpro (CBS extrapolated energies) #############
if Create_MOLPRO_CBS_input_files:
molpro_cbs_data = input_files_data + 'Molpro_CBS/' # directory for psi4 data
if not os.path.exists(molpro_cbs_data):
os.makedirs(molpro_cbs_data)
Molpro_cbs_template = "***,single point energies \n"
Molpro_cbs_template += "memory,{} \n".format(inp.mem_m)
Molpro_cbs_template += "run_method={} \n".format(inp.run_method)
# converting RR atoms with label eg. C1, C2, etc.
RR1_name = [f'{name}{ii}' for ii, name in enumerate(inp.RR1_atoms, 1)]
RR2_name = [f'{name}{iii}' for iii, name in enumerate(inp.RR2_atoms, len(inp.RR1_atoms)+1)]
#-----------------------------# Molpro 1D (CBS) #------------------------------#
if coll_1D:
FxD_geom_M_cbs = driver.molpro_files_CBS_1D(f, Molpro_cbs_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_cbs_data,
inp.basis_ref,inp.basis_cbs)
#-------------------------------# Molpro 2D #-------------------------------#
elif coll_2D :
FxD_geom_M_cbs = driver.molpro_files_CBS_2D(f, Molpro_cbs_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_cbs_data,
RR1_COM_len, A, inp.basis_ref,inp.basis_cbs)
#-------------------------------# Molpro 4D #-------------------------------#
elif coll_4D:
FxD_geom_M_cbs = driver.molpro_files_CBS_4D(f, Molpro_cbs_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_cbs_data,
RR1_COM_len, RR2_COM_len, A,
inp.basis_ref,inp.basis_cbs)
else:
print('ID: 375 --> All coll_1D, coll_2D and coll_4D are False. Check for error!')
f.write("\n---- Molpro input file template : see Template_Molpro_CBS.dat.")
template_filex = 'Template_Molpro_CBS.log'
f4 = open(input_files_data+template_filex, 'a+')
f4.write(str(FxD_geom_M_cbs))
f4.close()
print(" \n Molpro (CBS) Input files Created! \n")
f.write('\n Molpro (CBS) Input files Created! \n ')
else:
print(" \n Create_MOLPRO_CBS_input_files = False : Skipping Molpro (CBS) Input! \n")
f.write('\n Create_MOLPRO_CBS_input_files = False : Skipping Molpro (CBS) Input! \n ')
###############################################################################
#----------------------Molpro Input Parameters (Custom)-----------------------#
###############################################################################
try:
inp.Create_MOLPRO_custom_input_files
except:
Create_MOLPRO_custom_input_files = False
else:
Create_MOLPRO_custom_input_files = inp.Create_MOLPRO_custom_input_files
print("\nCreating molpro (custom) Input files!\n")
# creating input files for Molpro (custom input) #############
if Create_MOLPRO_custom_input_files:
molpro_custom_data = input_files_data + 'Molpro_custom/' # directory for psi4 data
if not os.path.exists(molpro_custom_data):
os.makedirs(molpro_custom_data)
Molpro_custom_template = "***,single point energies \n"
Molpro_custom_template += "memory,{} \n".format(inp.mem_m)
# converting RR atoms with label eg. C1, C2, etc.
RR1_name = [f'{name}{ii}' for ii, name in enumerate(inp.RR1_atoms, 1)]
RR2_name = [f'{name}{iii}' for iii, name in enumerate(inp.RR2_atoms, len(inp.RR1_atoms)+1)]
#-----------------------------# Molpro 1D (CBS) #------------------------------#
if coll_1D:
FxD_geom_M_ext = driver.molpro_files_custom_1D(f, Molpro_custom_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_custom_data,
inp.molpro_ext)
#-------------------------------# Molpro 2D #-------------------------------#
elif coll_2D :
FxD_geom_M_ext = driver.molpro_files_custom_2D(f, Molpro_custom_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_custom_data,
RR1_COM_len, A, inp.molpro_ext)
#-------------------------------# Molpro 4D #-------------------------------#
elif coll_4D:
FxD_geom_M_ext = driver.molpro_files_custom_4D(f, Molpro_custom_template, RR1_name, RR2_name,
inp.Charge, inp.Multiplicity, R, molpro_custom_data,
RR1_COM_len, RR2_COM_len, A, inp.molpro_ext)
else:
print('ID: 428 --> All coll_1D, coll_2D and coll_4D are False. Check for error!')
f.write("\n---- Molpro input file template : see Template_Molpro_custom.dat.")
template_filex = 'Template_Molpro_custom.log'
f5 = open(input_files_data+template_filex, 'a+')
f5.write(str(FxD_geom_M_ext))
f5.close()
print(" \n Molpro (custom) Input files Created! \n")
f.write('\n Molpro (custom) Input files Created! \n ')
else:
print(" \n Create_MOLPRO_custom_input_files = False : Skipping Molpro (custom) Input! \n")
f.write('\n Create_MOLPRO_custom_input_files = False : Skipping Molpro (custom) Input! \n ')
###############################################################################
#--------- Psi4 Input Parameters (Custom for external calculation) -----------#
###############################################################################
try:
inp.Create_Psi4_custom_input_files
except:
Create_Psi4_custom_input_files = False
else:
Create_Psi4_custom_input_files = inp.Create_Psi4_custom_input_files
print("\nCreating Psi4 (custom) Input files!\n")
# creating input files for Molpro (CBS extrapolated energies) #############
if Create_Psi4_custom_input_files:
psi4_custom_data = input_files_data + 'psi4_custom/' # directory for psi4 data
if not os.path.exists(psi4_custom_data):
os.makedirs(psi4_custom_data)
Psi4_custom_template = 'molecule {{'
#-----------------------------# Molpro 1D (CBS) #------------------------------#
if coll_1D:
FxD_geom_psi4 = driver.psi4_input_1D(inp)
Psi4_custom_template += FxD_geom_psi4
Psi4_custom_template += '}}'
Psi4_custom_template += '\nR = {:.4f}\n'
Psi4_custom_template += inp.psi4_ext
for j in tqdm(range (len(R))): # python loop to generate PES
R_ii = R[j] # radial coordinate
inp_file = open(psi4_custom_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(Psi4_custom_template.format(R_ii,R_ii)) # write string to file
inp_file.close() # close file
#-------------------------------# Molpro 2D #-------------------------------#
elif coll_2D :
FxD_geom_psi4 = driver.psi4_input_2D(inp,RR1_psi4)
Psi4_custom_template += FxD_geom_psi4
Psi4_custom_template += '}}'
Psi4_custom_template += '\nR = {:.4f} \nTheta = {:.4f}\n'
Psi4_custom_template += inp.psi4_ext
for j in tqdm(range (len(A))): # python loop to generate PES
R = A[j,0] # radial coordinate
gamma = A[j,1] # angular coordinate
# Rigid rotor (RR) lies on Z axis (no rotation of RR : no projection)
R_x, R_z = driver.proj2D (R, gamma)
inp_file = open(psi4_custom_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(Psi4_custom_template.format(R_x, R_z,R, gamma))
inp_file.close() # close file
#-------------------------------# Molpro 4D #-------------------------------#
elif coll_4D:
FxD_geom_psi4 = driver.psi4_input_4D(inp,RR1_COM_len,RR2_COM_len)
Psi4_custom_template += FxD_geom_psi4
Psi4_custom_template += '}}'
Psi4_custom_template += '\nR = {:.4f} \nPhi = {:.4f} \nTheta2 = {:.4f} \nTheta1 = {:.4f}'
Psi4_custom_template += inp.psi4_ext
for j in tqdm(range (len(A))): # python loop to generate PES
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 = driver.proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len) # calling 4D projection function
inp_file = open(psi4_custom_data + '{:d}.inp'.format(int(j)), "w") # open input file
inp_file.write(Psi4_custom_template.format(*RR_mat,R, phi, theta2, theta1))
inp_file.close() # close file
else:
print('ID: 475 --> All coll_1D, coll_2D and coll_4D are False. Check for error!')
template_filex = 'Template_psi4_custom.log'
f5 = open(input_files_data+template_filex, 'a+')
f5.write(str(Psi4_custom_template))
f5.close()
print(" \n Psi4 (custom) Input files Created! \n")
f.write('\n Psi4 (custom) Input files Created! \n ')
else:
print(" \n Create_MOLPRO_custom_input_files = False : Skipping Psi4 (custom) Input! \n")
f.write('\n Create_MOLPRO_custom_input_files = False : Skipping Psi4 (custom) Input! \n ')
################################################################################
#----------------- Running Psi4 calculations internally------------------------#
################################################################################
#Important:
#Try/Except/Finally block (in Psi4 - for rough PES calculation):
#Use 'pass' to ignore failed calculations (only store data points that converge)
#Use 'raise' to show error ! --> to debug code
################################################################################
try:
inp.Run_psi4
except:
Run_psi4 = False
else:
Run_psi4 = inp.Run_psi4
if Run_psi4:
direct_plot = True
psi4_int = out_data + 'psi4_PES_data/' # directory for psi4 data
psi4_data = psi4_int + 'data/' # directory for psi4 data
if not os.path.exists(psi4_data):
os.makedirs(psi4_data)
scratch_dir = psi4_int + 'scratch/' # scratch directory for Psi4
if not os.path.exists(scratch_dir):
os.makedirs(scratch_dir)
f1 = open(psi4_int+'psi4_failed_coordinates', 'a+')
psi4_io = psi4.core.IOManager.shared_object()
psi4_io.set_default_path(scratch_dir)
psi4.set_memory(inp.psi4_mem)
psi4.set_num_threads(inp.psi4_proc)
print("Generating Psi4 PES!")
# 1D PES calculation using psi4
if coll_1D:
# geometry specifications
ecp = {} # dictionary for energies
F1D_geom = driver.psi4_input_1D(inp)
# print(" \n Psi4 Input : \n ")
# print(F1D_geom)
f.write(" \n Psi4 Input : \n ")
f.write('-x'*30 + '\n')
f.write(str(F1D_geom))
f.write('-x'*30 + '\n')
print(F1D_geom)
for fx in os.listdir(scratch_dir): # removing any previous scratch files
os.remove(os.path.join(scratch_dir, fx))
for j in tqdm(range (len(R))): # python loop to generate PES (using try and except to suppress error)
try:
R_ii = R[j] # radial coordinate
# Rigid rotor (RR) lies on Z axis (no rotation of RR : no projection)
psi4.core.set_output_file(psi4_data+'{:.2f}.out'.format(R_ii), False) # sets output file location
F1D_mol = psi4.geometry(F1D_geom.format(R_ii))
psi4_inp = psi4.core.Molecule.create_psi4_string_from_molecule(F1D_mol)
psi4.set_options({'reference': inp.psi4_reference,'freeze_core': inp.psi4_Frozen_Core})
if inp.psi4_bsse == None:
ecp[j] = psi4.energy(inp.psi4_method_basis, molecule=F1D_mol)
else:
ecp[j] = psi4.energy(inp.psi4_method_basis, bsse_type= inp.psi4_bsse,
return_total_data=True, molecule=F1D_mol)
except:
print("\n\n")
print ("Failed coordinate : (R = %.2f) \n" % (R_ii) )
f1.write("Failed coordinate : (R = %.2f) \n" % (R_ii) )
# replace 'pass' with 'raise' to show error ! to debug code
pass
finally:
psi4.core.close_outfile()
try:
os.remove(psi4_data+'{:.2f}.log'.format(R_ii)) # removing log file (too large)
except:
pass
psi4.core.clean()
psi4.core.clean_variables()
psi4.core.clean_options()
psi4.core.clean_timers()
for fx in os.listdir(scratch_dir): # removing remaining files after psi4 clean()
os.remove(os.path.join(scratch_dir, fx))
#####################################################################################################################
# coordinates for calculating E_inf ( to convert energies to cm-1 )
R_inf = inp.R_inf
#####################################################################################################################
# Section 4.0.2 : Calculating E infinity (200 Angstroms) at 90 degrees (BSSE approx. 0 at infinity)
# print("\n Geometry at infinity: \n ", F1D_geom.format(R_inf))
f.write("\n Geometry at infinity: \n ")
f.write("R = {}".format(R_inf))
psi4.core.set_output_file(psi4_data+'E_Inf.out',False) # sets output file location
F1D_mol_inf = psi4.geometry(F1D_geom.format(R_inf))
psi4.set_options({'reference': inp.psi4_reference,'freeze_core': inp.psi4_Frozen_Core})
try:
if inp.psi4_bsse == None:
ecp_inf = psi4.energy(inp.psi4_method_basis, molecule=F1D_mol_inf)
else:
ecp_inf = psi4.energy(inp.psi4_method_basis, bsse_type= inp.psi4_bsse,
return_total_data=True, molecule=F1D_mol_inf)
#os.remove(psi4_data+'E_Inf.log') # removing log file
psi4.core.clean()
except:
print('E infinity convergence failed! using last converged energy')
f.write('E infinity convergence failed! using last converged energy \n')
ecp_inf = list(ecp.values())[-1]
print(list(ecp.values())[-1])
pass
print("\n Energy at inifinity (Hartree): ", ecp_inf)
f.write("\n Energy at inifinity (Hartree): {}" .format(ecp_inf) )
# converting ecp diectionary into dataframe
df_ecp = pd.DataFrame.from_dict([ecp]).T
df_ecp.columns = ['E'] # giving suitable name for header
# converting coordinates to dataframe with suitable names
df_A = pd.DataFrame({'R': R })
# merging coordinate and energy dataframes
# The coordinates for which calculations have failed are dropped automatically
merged_df = pd.merge(df_A, df_ecp, left_index=True, right_index=True)
# set precision of each column
merged_df['R'] = merged_df['R'].apply(lambda x: format(x,".2f"))
merged_df['E'] = merged_df['E'].apply(lambda x: round(x,12))
# saving csv file
merged_df.to_csv(psi4_int + inp.PES_filename, index=None, header=True,sep='\t')
# converting energies in cm-1 and saving file
merged_df['E'] = (merged_df['E']-ecp_inf)*219474.6
merged_df['E'] = merged_df['E'].apply(lambda x: round(x,6))
merged_df.to_csv(out_data + inp.PES_filename_cm, index=None, header=True,sep='\t')
print("All required files are saved ! Check folder --> ", out_data)
try:
shutil.rmtree(scratch_dir) # removing scratch directory (residual files)
print("Scratch Directory Removed!")
except:
print("Most probably the scratch directory is already deleted! \n To see error replace 'pass' with 'raise' in the code.")
pass
# 2D PES calculation using psi4
elif coll_2D:
# geometry specifications
ecp = {} # dictionary for energies
F2D_geom = driver.psi4_input_2D(inp, RR1_psi4)
# print(" \n Psi4 Input : \n ")
#print(F2D_geom)
f.write(" \n Psi4 Input : \n ")
f.write(str(F2D_geom))
for fx in os.listdir(scratch_dir): # removing any previous scratch files
os.remove(os.path.join(scratch_dir, fx))
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress error)
try:
R = A[j,0] # radial coordinate
gamma = A[j,1] # angular coordinate
# Rigid rotor (RR) lies on Z axis (no rotation of RR : no projection)
R_x, R_z = driver.proj2D (R, gamma)
psi4.core.set_output_file(psi4_data+'{:.2f}_{:d}.out'.format(R,int(gamma)), False) # sets output file location
F2D_mol = psi4.geometry(F2D_geom.format(R_x, R_z))
psi4.set_options({'reference': inp.psi4_reference,'freeze_core': inp.psi4_Frozen_Core})
if inp.psi4_bsse == None:
ecp[j] = psi4.energy(inp.psi4_method_basis, molecule=F2D_mol)
else:
ecp[j] = psi4.energy(inp.psi4_method_basis, bsse_type= inp.psi4_bsse,
return_total_data=True, molecule=F2D_mol)
except:
print ("Failed coordinate : (R = %.2f, theta = %d ) \n" % (A[j,0], A[j,1]) )
f1.write("Failed coordinate : (R = %.2f, theta = %d ) \n" % (A[j,0], A[j,1]) )
# replace 'pass' with 'raise' to show error ! to debug code
pass
finally:
psi4.core.close_outfile()
try:
os.remove(psi4_data+'{:.2f}_{:d}.log'.format(R,int(gamma))) # removing log file
except:
pass
psi4.core.clean()
psi4.core.clean_variables()
psi4.core.clean_options()
psi4.core.clean_timers()
for fx in os.listdir(scratch_dir): # removing remaining files after psi4 clean()
os.remove(os.path.join(scratch_dir, fx))
#####################################################################################################################
# coordinates for calculating E_inf ( to convert energies to cm-1 )
R_inf = inp.R_inf
ang_inf = inp.theta_2D_inf
#####################################################################################################################
# Section 4.0.2 : Calculating E infinity (200 Angstroms) at 90 degrees (BSSE approx. 0 at infinity)
R_x_inf, R_z_inf = driver.proj2D (R_inf, ang_inf)
# print("\n Geometry at infinity: \n ", F2D_geom.format(R_x_inf, R_z_inf))
f.write("\n Geometry at infinity: \n ")
f.write("R = {}\n Theta = {}\n".format(R_inf,ang_inf))
psi4.core.set_output_file(psi4_data+'E_Inf.out',False) # sets output file location
F2D_mol_inf = psi4.geometry(F2D_geom.format(R_x, R_z))
psi4.set_options({'reference': inp.psi4_reference,'freeze_core': inp.psi4_Frozen_Core})
try:
if inp.psi4_bsse == None:
ecp_inf = psi4.energy(inp.psi4_method_basis, molecule=F2D_mol_inf)
else:
ecp_inf = psi4.energy(inp.psi4_method_basis, bsse_type= inp.psi4_bsse,
return_total_data=True, molecule=F2D_mol_inf)
#os.remove(psi4_data+'E_Inf.log') # removing log file
psi4.core.clean()
except:
print('E infinity convergence failed! using last converged energy')
f.write('E infinity convergence failed! using last converged energy \n ')
ecp_inf = list(ecp.values())[-1]
print(list(ecp.values())[-1])
pass
print("\n Energy at inifinity (Hartree): ", ecp_inf)
f.write("\n Energy at inifinity (Hartree): " )
f.write(str(ecp_inf))
# converting ecp diectionary into dataframe
df_ecp = pd.DataFrame.from_dict([ecp]).T
df_ecp.columns = ['E'] # giving suitable name for header
# converting coordinates to dataframe with suitable names
df_A = pd.DataFrame({'R': A[:, 0], 'Gamma': A[:, 1]})
# merging coordinate and energy dataframes
# The coordinates for which calculations have failed are dropped automatically
merged_df = pd.merge(df_A, df_ecp, left_index=True, right_index=True)
# set precision of each column
merged_df['R'] = merged_df['R'].apply(lambda x: format(x,".2f"))
merged_df['Gamma'] = merged_df['Gamma'].apply(lambda x: format(x,".0f"))
merged_df['E'] = merged_df['E'].apply(lambda x: round(x,12))
# saving csv file
merged_df.to_csv(psi4_int + inp.PES_filename, index=None, header=True,sep='\t')
# converting energies in cm-1 and saving file
merged_df['E'] = (merged_df['E']-ecp_inf)*219474.6
merged_df['E'] = merged_df['E'].apply(lambda x: round(x,6))
merged_df.to_csv(out_data + inp.PES_filename_cm, index=None, header=True,sep='\t')
print("All required files are saved ! Check folder --> ", out_data)
try:
shutil.rmtree(scratch_dir) # removing scratch directory (residual files)
print("Scratch Directory Removed!")
except:
print("Most probably the scratch directory is already deleted! \n To see error replace 'pass' with 'raise' in the code.")
pass
# 4D PES calculation using psi4
elif coll_4D:
ecp = {} # dictionary for energies
F4D_geom = driver.psi4_input_4D(inp,RR1_COM_len,RR2_COM_len)
# print(" \n Psi4 Input : \n ")
# print(F4D_geom)
f.write(" \n Psi4 Input : \n ")
f.write(str(F4D_geom))
for fx in os.listdir(scratch_dir): # removing any previous scratch files
os.remove(os.path.join(scratch_dir, fx))
for j in tqdm(range (len(A))): # python loop to generate PES (using try and except to suppress convergence error)
try:
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 = driver.proj4D (R, phi, theta2, theta1, RR1_COM_len, RR2_COM_len) # calling 4D projection function
psi4.core.set_output_file(psi4_data+'{:.2f}_{:d}_{:d}_{:d}.out'.format(R,int(phi),int(theta2),int(theta1)),
False) # sets output file location
F4D_mol = psi4.geometry(F4D_geom.format(*RR_mat))
psi4.set_options({'reference': inp.psi4_reference,'freeze_core': inp.psi4_Frozen_Core})
if inp.psi4_bsse == None:
ecp[j] = psi4.energy(inp.psi4_method_basis, molecule=F4D_mol)
else:
ecp[j] = psi4.energy(inp.psi4_method_basis, bsse_type= inp.psi4_bsse,
return_total_data=True, molecule=F4D_mol)
except:
print ("Failed coordinate : (R = %.2f, phi = %d, theta2= %d, theta1= %d ) \n" % (A[j,0], A[j,1], A[j,2], A[j,3]) )
f1.write("Failed coordinate : (R = %.2f, phi = %d, theta2= %d, theta1= %d ) \n" % (A[j,0], A[j,1], A[j,2], A[j,3]) )
# replace 'pass' with 'raise' to show error ! to debug code
pass
finally:
psi4.core.close_outfile()
try:
os.remove(psi4_data+'{:.2f}_{:d}_{:d}_{:d}.log'.format(R,int(phi),int(theta2),int(theta1))) # removing log file
except:
pass
psi4.core.clean()
psi4.core.clean_variables()
psi4.core.clean_options()
psi4.core.clean_timers()
for fx in os.listdir(scratch_dir): # removing remaining files after psi4 clean()
os.remove(os.path.join(scratch_dir, fx))
#####################################################################################################################
# coordinates for calculating E_inf ( to convert energies to cm-1 )
R_inf = inp.R_inf
phi_inf = inp.phi_4D_inf
theta2_inf = inp.theta2_4D_inf
theta1_inf = inp.theta1_4D_inf
#####################################################################################################################
# Section 4.0.2 : Calculating E infinity (200 Angstroms) at 90 degrees (BSSE approx. 0 at infinity)
RR_mat_inf = driver.proj4D ( R_inf, phi_inf, theta2_inf, theta1_inf, RR1_COM_len, RR2_COM_len) # calling 4D projection function
F4D_mol_inf = psi4.geometry(F4D_geom.format(*RR_mat_inf))
# print("\n Geometry at infinity: \n ", F4D_geom.format(*RR_mat_inf))
f.write("\n Geometry at infinity: \n ")
f.write(" R = {}\n Phi = {}\n Theta 2 = {}\n Theta 1 = {}\n".format(R_inf,phi_inf, theta2_inf, theta1_inf))
psi4.core.set_output_file(psi4_data+'E_Inf.out',False) # sets output file location
psi4.set_options({'reference': inp.psi4_reference,'freeze_core': inp.psi4_Frozen_Core})
try:
if inp.psi4_bsse == None:
ecp_inf = psi4.energy(inp.psi4_method_basis, molecule=F4D_mol_inf)
else:
ecp_inf = psi4.energy(inp.psi4_method_basis, bsse_type= inp.psi4_bsse,
return_total_data=True, molecule=F4D_mol_inf)
#os.remove(psi4_data+'E_Inf.log') # removing log file
psi4.core.clean()
except:
print('E infinity convergence failed! using last converged energy')
f.write('E infinity convergence failed! using last converged energy \n')
ecp_inf = list(ecp.values())[-1]
print(list(ecp.values())[-1])
pass
print("\n Energy at inifinity (Hartree): ", ecp_inf)
f.write("\n Energy at inifinity (Hartree): ")
f.write(str(ecp_inf))
#####################################################################################################################
# converting ecp diectionary into dataframe
df_ecp = pd.DataFrame.from_dict([ecp]).T
df_ecp.columns = ['E'] # giving suitable name for header
# converting coordinates to dataframe with suitable names
df_A = pd.DataFrame({'R': A[:, 0], 'phi': A[:, 1], 'theta2': A[:, 2], 'theta1': A[:, 3]})
# merging coordinate and energy dataframes
# The coordinates for which calculations have failed are dropped automatically
merged_df = pd.merge(df_A, df_ecp, left_index=True, right_index=True)
# set precision of each column
merged_df['R'] = merged_df['R'].apply(lambda x: format(x,".2f"))
merged_df['phi'] = merged_df['phi'].apply(lambda x: format(x,".0f"))
merged_df['theta2'] = merged_df['theta2'].apply(lambda x: format(x,".0f"))
merged_df['theta1'] = merged_df['theta1'].apply(lambda x: format(x,".0f"))
merged_df['E'] = merged_df['E'].apply(lambda x: round(x,12))
# saving csv file
merged_df.to_csv(psi4_int + inp.PES_filename, index=None, header=True,sep='\t')
# converting energies in cm-1 and saving file
merged_df['E'] = (merged_df['E']-ecp_inf)*219474.6
merged_df['E'] = merged_df['E'].apply(lambda x: round(x,6))
merged_df.to_csv(out_data + inp.PES_filename_cm, index=None, header=True,sep='\t')
print("All required files are saved ! \n Check folder : \n ", out_data)
try:
shutil.rmtree(scratch_dir) # removing scratch directory (along with residual files)
print("Scratch Directory Removed!")
except:
print("Most probably the scratch directory is already deleted! \n To see error replace 'pass' with 'raise' in the code.")
else:
print('ID: 235 --> All coll_1D, coll_2D and coll_4D are False. Check for error!')
print(" \n Psi4 calculations finished! \n")
f.write('\n Psi4 calculations finished! \n ')
f1.close()
else:
direct_plot = False
print(" \n Create_PES_input = False : Skipping Psi4 calculations! \n")
f.write('\n Run_psi4 = False : Skipping Psi4 calculations! \n ')
else:
print(" \n Create_PES_input = False : Checking input for external Plots \n")
f.write('\n Create_PES_input = False : Checking input for external Plots! \n ')
###############################################################################
###############################################################################
############################# PES Plot ########################################
###############################################################################
###############################################################################
try:
inp.Plot_PES
except:
print("Plot_PES not defined! Skipping PES plots!")
Plot_PES =False
else:
Plot_PES = inp.Plot_PES
# plotting psi4 or any other dataframe in required format
if (direct_plot == True or Plot_PES == True):
print("Using Plot module!")
if direct_plot:
print('\nPlotting PES from Psi4 output.')
f.write('\nPlotting PES from Psi4 output.')
print("The energies at very small R distance don't usually converge (may give : -inf ) and ruin the plots !")
print("Check and remove unconverged coordinates/energies in !",out_data+inp.PES_filename_cm)
input("Satisfied! Press Enter to continue...")
df_out1 = pd.read_csv(out_data+inp.PES_filename_cm,sep='\s+')
else:
print('\nPlotting PES from external output. ')
f.write('\nPlotting PES from external output. ')
try:
Plot_folder = inp.Plot_folder
except:
print('\nUsing default path and project name')
f.write('\nUsing default path and project name')
Plot_folder = out_data + 'input_files/'
else:
print('\nExternal folder path provided!')
f.write('\nExternal folder path provided!')
df_out1 = pd.read_csv(Plot_folder+inp.PES_filename_cm,sep=inp.sep,header=None)
df_out1 = df_out1.apply(pd.to_numeric, errors='coerce')
print(df_out1.head(5))
print("\n If your input dataframe contain 'HEADER' like R, theta, E, etc, it should be visible on 1st row and must be removed. \n")
df_choice2 = int(input("\n Do you want to remove 1st row ! (0= No, 1= Yes) : "))
if (df_choice2 == 1):
df_out1.drop(index=df_out1.index[0], axis=0, inplace=True)
print("Header column removed! The new dataframe is: \n")
print(df_out1.head(5))
else:
print("No header input. The dataframe remains same: \n ")
try:
inp.E_inf
except:
E_Hartree = False
E_inf = 0.00
else:
E_Hartree = True
E_inf = inp.E_inf
coll_1D = False
coll_2D = False
coll_4D = False
print(len(df_out1.axes[1]))
if len(df_out1.axes[1]) == 2:
print('\n 1D coll. Columns must be in order: R and E')
coll_1D = True
if E_Hartree == True:
df_out1[1] = (df_out1[1] - E_inf)*219474.63 # convert to cm-1
df_out1.to_csv(out_data+'pes_cm_1D.dat', index=None, header=None,sep=',') # save V_lam coefficients to file separated by comma
df_out1.columns = ['R', 'E']
elif len(df_out1.axes[1]) == 3:
print('\n 2D coll. Columns must be in order: R, theta and E')
coll_2D = True
if E_Hartree == True:
df_out1[2] = (df_out1[2] - E_inf)*219474.63 # convert to cm-1
df_out1.to_csv(out_data+'pes_cm_2D.dat', index=None, header=None,sep=',') # save V_lam coefficients to file separated by comma