-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathgaussian_manage.py
More file actions
executable file
·1294 lines (1251 loc) · 57 KB
/
Copy pathgaussian_manage.py
File metadata and controls
executable file
·1294 lines (1251 loc) · 57 KB
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
#!/bin/env python3
#Module :: Gaussian_Manage
#Authors :: Ying Zhang and Xin Xu
#Purpose :: 1) Analysis the input file of Gaussian package;
# :: 2) Generate the input file of Gaussian package;
# :: 3) Collect results from Gaussian package;
# :: 4) Generate rGO interface file;
# :: 5) Interface with R5DFT and DFTD
# :: All in all, a well-defined private interface with Gaussian series
# package
#History :: 1.0(20090825) Completes basic functions for Gaussian IO.
# There are about three classes:
# 1) GauIO : obtain all information from gaussian input
# 2) ChkHandle : collect results from chk of gaussian
# 3) LogHandle : collect results from log of gaussian
# 1.1(20090910) Add one more class "OptHandel" for rGO interface.
# 1.2(20090925) 1) Make GauIO class to unopen gaussian input as default.
# 2) Build new class of "R5DFT" to handle R5DFT calculation
# cooperating with Gaussian packages.
# 1.3(20091021) Build new class of "DFTD" to handle DFT+D calculation, in which
# dispertion term is obtained from the private module "dft_d" and
# conventional DFT term is generated by Gaussian packages.
# 1.4(20091104) Add one more function "collect_Geom_converged()" into the class of
# "LogHandle"
# 1.5(20091209) 1) Add more indexes of atoms into "GauIO.AtDict"
# 2) Fix a bug to make "GauIO.run_GauJob" can handle more than 2 jobs
# in one DIR correctly
# 3) Modify "R5DFT.__init__" to handle "gen" basis set collectly
# 1.6(20100426) 1) Fix a bug in "GauIO.get_TCSGR" associated with filtering "RestList"
# for external gen basis file statement
# 2) Fix a bug in "GauIO.get_TCSGR" about conflicting between "RestList"
# and l608 calculation statement for DFT part of R5DFT
# 3) Fix a bug in "R5DFT.__init__" to handle nonstandard "gen" basis set
# file
# 4) Fix a bug in "GauIO.collect_Geom" to read "IAn" from "fchk" file
# 5) Add "GauIO.AnDict" to index atom name by IAn; Modify "GauIO.collect
# _Geom" to construct "GauIO.GeomList" using atom name indexed by
# AnDict
# 6) Fix bug in "GauIO.TCSGR" to read atom-frozen and Oniom-type
# Cartesian input correctly
# 7) Add "XYG3_FC" into R5DFT for frozen core XYG3 calculation
# 8) Handle the chkfile direction by "ChkReplace.py" and
# "G03_Envirenment.csh" in "GauIO.run_GauJob"
# a) "gaussian_manage.py->GauIO.run_GauJob()"
# b) "G03_Environment"
# c) "Utility/ChkReplace.py"
# 9) Fit bug for "fchk=all" calculation: the changed code:
# a) "GauIO.MoreOptionDict['fchk=all']"
# b) "GauIO.run_GauJob()"
# 10) Fit bug for returning unrequired chkfile: the changed code:
# a) "GauIO.MoreOptionDict['%chk']"
# b) "GauIO.MachAndOpt()": generate GauIO.MoreOptionDict['%chk']
# b) "GauIO.run_GauJob()": copy chkfile or not depends on '%chk'
# 11) Sync log-file for R5DFT by threads: the changed codes:
# a) "GauIO.run_GauJob()": add the argument "sync" to return CurrDir
# b) "R5DFT.run_Job()": sync log from CurrDir by threads
# c) "R5DFT.cut_log()": append log information correctly
# d) "R5DFT.filter_log()": filter log information for printing
# 2.0(20100617) 1) Reach private modules from the grobal environment of
# "IGOR_MODULES_PATH"
# 2) Add four arguments into DFTD class for dispersion parameters
# optimization
# 3) Temp setting about formchking chk-file for G09 being unable to
# handel "extraoverlay" correctly. "ChkHandle.__init__()"
__version__='3.0'
def print_Error(IOut, Info):
'''Report the error information "Info", and abort the process'''
'''INPUT ARGUMENTS ::'''
'''IOut : FLOW of output file'''
'''Info : STRING of error information to print'''
from sys import exit
IOut.write('*****\n*%s\n*****\n' % Info)
print(Info)
exit()
return
def print_String(IOut, PString, IPrint, Info=''):
'''To print the string "PString"'''
''' INPUT ARGUMENTS ::'''
'''IOut : FLOW of output file'''
'''PString : SRING to print'''
'''IPrint : INTEGER to control the print formula'''
''' 0 :: Bypass the print'''
''' 1 :: Print both PString and Info'''
''' 2 :: Print in highline style'''
''' 3 :: Print PString and Info,'''
''' without prompt "=>" before PString'''
''' 4 :: Print PString in primitive way'''
'''Info : STRING of info. of what to print'''
NT = 80
NN = NT - 2
PL = len(PString)
if IPrint == 0: # Bypass the print
pass
elif IPrint == 1: # Print both PString and Info
NL = int(PL / NN)
if PL == NL*NN:
NL = NL - 1
if NL > 0:
BlankFlag = True
BlankCount = 0
for i in range(len(PString)):
if PString[i] == ' ':
BlankCount += 1
if BlankCount < NL:
BlankFlag = False
j = 0
k = j+NN
for i in range(int(NL)):
while BlankFlag and PString[k-1] != ' ':
k = k-1
StrSplit = [PString[0:k], PString[k:]]
PString = '\n '.join(StrSplit)
j = k+3
k = j+NN
if Info == '':
IOut.write('=>%s\n' % PString)
else:
IOut.write('=>%s\n %s\n' % (Info, PString))
elif IPrint == 2: # Print in highline style
NL = PL/NN
if PL == NL*NN:
NL = NL-1
if NL > 0:
BlankFlag = True
BlankCount = 0
for i in range(len(PString)):
if PString[i] == ' ':
BlankCount += 1
if BlankCount < NL:
BlankFlag = False
j = 0
k = j+NN
for i in range(int(NL)):
while BlankFlag and PString[k-1] != ' ':
k = k-1
StrSplit = [PString[0:k], PString[k:]]
PString = '\n '.join(StrSplit)
j = k+3
k = j+NN
if Info != '':
IOut.write('=>%s\n==%s==\n %s\n==%s==\n'
% (Info, '-'*(NN-2), PString, '-'*(NN-2)))
else:
IOut.write('==%s==\n %s\n==%s==\n'
% ('-'*(NN-2), PString, '-'*(NN-2)))
elif IPrint == 3: # Print string without prompt
NL = PL / NN # of "=>"
if PL == NL*NN:
NL = NL - 1
if NL > 0:
BlankFlag = True
BlankCount = 0
for i in range(len(PString)):
if PString[i] == ' ':
BlankCount += 1
if BlankCount < NL:
BlankFlag = False
j = 0
k = j+NN
for i in range(int(NL)):
while BlankFlag and PString[k-1] != ' ':
k = k-1
StrSplit = [PString[0:k], PString[k:]]
PString = '\n '.join(StrSplit)
j = k+3
k = j+NN
if Info == '':
IOut.write(' %s\n' % PString)
else:
IOut.write('=>%s\n %s\n' % (Info, PString))
elif IPrint == 4:
IOut.write('%s\n' % PString)
else:
print_Error(IOut, 'Error :: Invalid IPrint for print_String\n')
return
def print_List(IOut, PList, IPrint, Info=''):
'''To print the list "PList"'''
''' INPUT ARGUMENTS ::'''
''' IOut : FLOW of output file'''
''' PList : LIST to print'''
''' IPrint : INTEGER to control the print formula'''
''' 0 :: Bypass print'''
''' 1 :: General cases'''
''' 2 :: Print PList separately in different lines'''
''' formated in " %s"'''
''' 3 :: Integrating the whole PList to be printed '''
''' in a single line'''
''' 4 :: Print each five numerical elements in one line '''
''' formated in "%16.4E"'''
''' 5 :: Similar with 4, but suit for the IO interface of '''
''' the rGO package'''
''' 6 :: Print list without info. and prompt "=>"'''
''' Info : STRING of info. which to be printed before PList'''
NT = 80
NN = NT - 2
if IPrint == 0: # Bypass the print
return
elif IPrint == 1: # Suit for general cases
if Info == '':
PString = '=>%s\n' % PList
else:
PString = '=>%s\n%s\n' % (Info, PList)
elif IPrint == 2: # Suit for "MachineList",
TmpList = [] # "ExOvList","RestList" and
for i in PList: # text printing
if i[-1:] == '\n':
TmpList.append(' %s' % i)
else:
TmpList.append(' %s\n' % i)
TmpPrint = ''.join(TmpList)
if Info == '':
PString = '=>\n%s' % TmpPrint
else:
PString = '=>%s\n%s' % (Info, TmpPrint)
elif IPrint == 3: # Suit for "OptionList",...
try:
TmpPrint = ' '.join(PList)
except TypeError:
TmpList = []
for iterm in PList:
TmpList.append('%s' % iterm)
TmpPrint = ' '.join(TmpList)
PL = len(TmpPrint)
NL = PL/NN
if NL*NN == PL:
NL = NL-1
if NL > 0:
j = 0
k = j+NN
for i in range(int(NL)):
while TmpPrint[k-1] != ' ':
k = k-1
TmpPrint = '\n '.join([TmpPrint[0:k], TmpPrint[k:]])
j = k+3
k = j+NN
if Info == '':
PString = '=>%s\n' % TmpPrint
else:
PString = '=>%s\n %s\n' % (Info, TmpPrint)
elif IPrint == 4: # Suit for numerical data
NTT = len(PList)
Index = 0
OutPrint = []
while Index < NTT:
if ((Index+1) % 5) == 0 or Index+1 == NTT:
OutPrint.append('%16.8E\n' % PList[Index])
else:
OutPrint.append('%16.8E' % PList[Index])
Index = Index+1
TmpPrint = ''.join(OutPrint)
if Info == '':
PString = '=>\n%s' % TmpPrint
else:
PString = '=>%s\n%s' % (Info, TmpPrint)
elif IPrint == 5: # Suit for interface of rGO
NTT = len(PList)
Index = 0
OutPrint = []
while Index < NTT:
if ((Index+1) % 5) == 0 or Index+1 == NTT:
OutPrint.append('%16.8E\n' % PList[Index])
else:
OutPrint.append('%16.8E' % PList[Index])
Index = Index+1
TmpPrint = ''.join(OutPrint)
PString = '%s\n%s' % (Info, TmpPrint)
elif IPrint == 6: # Just print without info and prompt
NTT = len(PList)
Index = 0
OutPrint = []
while Index < NTT:
if ((Index+1) % 5) == 0 or Index+1 == NTT:
OutPrint.append('%16.8E\n' % PList[Index])
else:
OutPrint.append('%16.8E' % PList[Index])
Index = Index + 1
PString = ''.join(OutPrint)
else:
print_Error(IOut, 'Error :: Invalid IPrint for print_List\n')
IOut.write(PString) # Print result
return
def my_plus(a1, a2):
'''if valid :a = a1 + a2; else return a = "NAN"'''
try:
a = a1 + a2
except TypeError:
a = 'NAN'
return a
def my_substract(a1, a2):
'''if valid :a = a1 - a2; else return a = "NAN"'''
try:
a = a1 - a2
except TypeError:
a = 'NAN'
return a
def my_product(a1, a2):
'''if valid :a = a1 * a2; else return a = "NAN"'''
try:
a = a1 * a2
except TypeError:
a = 'NAN'
return a
def my_divide(a1, a2):
'''if valid :a = a1 / a2; else return a = "NAN"'''
try:
a = a1 / a2
except TypeError:
a = 'NAN'
return a
def my_vect_plus(vect1, vect2):
'''calculate vector addition'''
return [i[0]+i[1] for i in zip(vect1, vect2)]
def my_vect_substract(vect1, vect2):
'''calculate vector substraction'''
return [i[0]-i[1] for i in zip(vect1, vect2)]
def my_vect_product(vector, scale):
'''multiple vector by scale'''
return [i*scale for i in vector]
def my_cross(vect1, vect2):
'''calculate cross product'''
if len(vect1) != 3 or len(vect2) != 3:
return 'NAN'
NormVect = [0.0]*3
try:
NormVect[0] = vect1[1]*vect2[2]-vect1[2]*vect2[1]
NormVect[1] = vect1[0]*vect2[2]-vect1[2]*vect2[0]
NormVect[2] = vect1[0]*vect2[1]-vect1[1]*vect2[0]
except IndexError or TypeError:
NormVect = ['NAN']*3
return NormVect
def my_dot(vect1, vect2):
'''calculate dot product'''
return sum(i[0]+i[1] for i in zip(vect1, vect2))
def my_bond(atom1, atom2):
'''Calculate bond distance'''
from math import sqrt
if len(atom1) != 3 or len(atom2) != 3:
return 'NAN'
Vect1 = [0.0]*3
for i in range(3):
try:
Vect1[i] = atom1[i] - atom2[i]
except TypeError:
return 'NAN'
bond = sqrt(my_dot(Vect1, Vect1))
return bond
def my_angle(atom1, atom2, atom3):
'''calculate the angle of 1-2-3, and return the angle in "degree"'''
from math import sqrt
from math import acos
from math import pi
if len(atom1) != 3 or len(atom2) != 3 or len(atom3) != 3:
return 'NAN'
Vect1 = [0.0]*3
Vect2 = [0.0]*3
Dist1 = 0.0
Dist2 = 0.0
CosAng = 0.0
for i in range(3):
try:
Vect1[i] = atom1[i]-atom2[i]
except ValueError or TypeError or IndexError:
return 'NAN'
try:
Vect2[i] = atom3[i]-atom2[i]
except ValueError or TypeError or IndexError:
return 'NAN'
Dist1 = sqrt(my_dot(Vect1, Vect1))
Dist2 = sqrt(my_dot(Vect2, Vect2))
CosAng = my_dot(Vect1, Vect2)/(Dist1*Dist2)
Angl = acos(CosAng)/pi*180.0
return Angl
def my_dihedral(atom1, atom2, atom3, atom4):
'''calculate the angle of 1-2-3-4, and return the dihedral in "degree"'''
from math import sqrt
from math import acos
from math import pi
if len(atom1) != 3 \
or len(atom2) != 3 \
or len(atom3) != 3 \
or len(atom4) != 3:
return 'NAN'
Vect1 = [0.0]*3
Vect2 = [0.0]*3
Vect3 = [0.0]*3
NormVect1 = [0.0]*3
NormVect2 = [0.0]*3
Dist1 = 0.0
Dist2 = 0.0
CosAng = 0.0
Scale = 1.0
for i in range(3):
try:
Vect1[i] = atom1[i]-atom2[i]
except TypeError or ValueError:
return 'NAN'
try:
Vect2[i] = atom3[i]-atom2[i]
except TypeError or ValueError:
return 'NAN'
try:
Vect3[i] = atom4[i]-atom3[i]
except TypeError or ValueError:
return 'NAN'
NormVect1 = my_cross(Vect1, Vect2)
NormVect2 = my_cross(Vect3, Vect2)
Dist1 = sqrt(my_dot(NormVect1, NormVect1))
Dist2 = sqrt(my_dot(NormVect2, NormVect2))
CosAng = my_dot(NormVect1, NormVect2)/(Dist1*Dist2)
if my_dot(my_cross(NormVect1, NormVect2), Vect2) <= 0:
Scale = 1.0
else:
Scale = -1.0
Dihe = Scale * acos(CosAng)/pi*180.0
return Dihe
def my_permute(items, n=None):
'''Build permutation iteration'''
if n is None:
n = len(items)
for i in range(len(items)):
v = items[i:i+1]
if n == 1:
yield v
else:
rest = items[:i] + items[i+1:]
for p in my_permute(rest, n-1):
yield v + p
class GauIO:
'''\
Manage the input file of the Gaussian package.\n\
INPUT VARIABLES ::\n\
iout : FLOW of output file\n\
fn : STRING of the input file name\n\
fn = None -> default, bypass the action to open the file\n\
bugctrl : INTEGER to control the bebug information print\n\
0: default\n\
1: more results \n\
2: more results add detail debugging info.\n\
MANAGE VARIABLES :: \n\
(***Note***: if need, all the strings following have to be specified in lower style\n\
self.IOut : FLOW of output file\n\
self.FileName : STRING of the input file name\n\
self.ModuDir : STRING of the path name to reach the gaussian environment
self.JobName : STRING of this job name\n\
self.ChkName : STRING, the name of the check file\n\
self.CartesianFlag : LOGICAL to state geomerty input is Cartesian coordinate or not\n\
self.IPrint : INTEGER of print level\n\
self.Charge : INTEGER of input Chage \n\
self.Spin : INTEGER of input Spin \n\
self.NAtom : INTEGER of atoms number \n\
self.MachineList : LIST of machine commands\n\
self.OptionList : LIST of options\n\
self.TitleList : LIST of this job title \n\
self.GeomList : LIST of input geometry \n\
self.IAn : LIST of Atom index\n\
self.AtLabel : LIST of Atom label\n\
self.CList : LIST of geometry coordinate\n\
self.ZList : LIST of geometry Z-matrix\n\
self.ZListR : LIST of Z-matrix parameters\n\
self.RestList : LIST of rest content after geometry\n\
--------------------------Results Collected--------------------------------------\n\
self.EngyReal : FLOAT, the total energy of the quesion\n\
self.ForcList : LIST, Force of the quesion\n\
self.HessList : LIST, Hessian of the quesion\n\
self.DipoList : List, Dipole\n\
self.DpDvList : List, Dipole derivatives\n\
self.PolaList : List, Polarizability\n\
--------------------------Several varibles for options control--------------------------\n\
self.KickOptionList : DICTIONARY of initial disable options\n\
dict.keys() = []\n\
self.MoreOptionDict : DICTIONARY of options which need more detailed handle\n\
dict.keys() = ['checkpoint','allcheck','extraoverlay','fchk=all','%chk']\n\
self.ExOvList : LIST of IOPs for the option "extraoverlay"\n\
----------------------------------------------------------------------------------------\
'''
AtDict = {\
'x':0 ,
'h':1 , 'he':2 ,\
'li':3 , 'be':4 , 'b':5 , 'c':6 , 'n':7 , 'o':8 , 'f':9 , 'ne':10 ,\
'na':11 , 'mg':12 , 'al':13 , 'si':14 , 'p':15 , 's':16 , 'cl':17 , 'ar':18 ,\
'k':19 , 'ca':20 , 'ga':31 , 'ge':32 , 'as':33 , 'se':34 , 'br':35 , 'kr':36 ,\
'sc':21 , 'ti':22 , 'v':23 , 'cr':24 , 'mn':25 ,\
'fe':26 , 'co':27 , 'ni':28 , 'cu':29 , 'zn':30 ,\
'rb':37 , 'sr':38 , 'in':49 , 'sn':50 , 'sb':51 , 'te':52 , 'i':53 , 'xe':54 ,\
'y':39 , 'zr':40 , 'nb':41 , 'mo':42 , 'tc':43 ,\
'ru':44 , 'rh':45 , 'pd':46 , 'ag':47 , 'cd':48 ,\
'cs':55 , 'ba':56 , 'tl':81 , 'pb':82 , 'bi':83 , 'po':84 , 'at':85 , 'rn':86 ,\
'la':57 , 'hf':72 , 'ta':73 , 'w':74 , 're':75 ,\
'os':76 , 'ir':77 , 'pt':78 , 'au':79 , 'hg':80 \
}
AnDict = {\
0:'X' ,
1:'H' , 2:'He',\
3:'Li', 4:'Be', 5:'B' , 6:'C' , 7 :'N' , 8:'O' , 9:'F' , 10:'Ne',\
11:'Na', 12:'Mg', 13:'Al', 14:'Si', 15:'P' , 16:'S' , 17:'Cl', 18:'Ar',\
19:'K' , 20:'Ca', 31:'Ga', 32:'Ge', 33:'As', 34:'Se', 35:'Br', 36:'Kr',\
21:'Sc', 22:'Ti', 23:'V' , 24:'Cr', 25:'Mn',\
26:'Fe', 27:'Co', 28:'Ni', 29:'Cu', 30:'Zn',\
37:'Rb', 38:'Sr', 49:'In', 50:'Sn', 51:'Sb', 52:'Te', 53:'I', 54:'Xe',\
39:'Y' , 40:'Zr', 41:'Nb', 42:'Mo', 43:'Tc',\
44:'Ru', 45:'Rh', 46:'Pd', 47:'Ag', 48:'Cd',\
55:'Cs', 56:'Ba', 81:'Tl', 82:'Pb', 83:'Bi', 84:'Po', 85:'At', 86:'Rn',\
57:'La', 72:'Hf', 73:'Ta', 74:'W', 75:'Re',\
76:'Os', 77:'Ir', 78:'Pt', 79:'Au', 80:'Hg' \
}
def __init__(self,iout,fn=None,bugctrl=0):
'''\
Initialize variables belonged to GauIO\
'''
import sys
import os
import os.path
from os import getcwd
from os import getenv
from os.path import isfile
self.IOut = iout # Flow of the output file
self.IPrint = bugctrl # to control the printing out
self.FileName = fn # Name of the input file
self.WorkDir = getcwd().strip() # STRING, current DIR
self.HomeDir = getenv('HOME') # STRING, Home DIR
if isfile('%s/.xdh_modules_path' %self.HomeDir): # Load Private Modules DIR
tmpf = open('%s/.xdh_modules_path'\
%self.HomeDir,'r')
self.ModuDir=tmpf.readline().strip() # STRING, PATH of my modules
sys.path.append(self.ModuDir) # Append it into "sys.path"
tmpf.close()
else:
print(('Error for loading \"$HOME/.xdh_modules_path\" \n'+\
'which contains absolute path of relevant python modules'))
sys.exit(1)
global __version__
if isfile('%s/version.txt' %self.ModuDir): # Load Private Modules DIR
tmpf = open('%s/version.txt'\
%self.ModuDir,'r')
__version__=tmpf.readline().strip()
else:
__version__='no version info.'
if self.FileName==None:
self.f = 'None'
self.JobName = 'TmpName'
if self.IPrint>=1:
print_String(self.IOut,
'Do not open input file for GauIO class',1)
else:
try:
self.f = open(self.FileName,'r') # Open it
except IOError:
self.f = open('Error_%s' %self.FileName,'w')
if self.IPrint>=1:
print_String(self.IOut,
'Open Gau-Input file "%s" for GauIO class'
% self.FileName,1)
#
#Generating "self.JobName" which is head of "self.FileName"
#For example, if self.FileName = 'g03_1.gjf'
# then self.JobName = 'g03_1'
path, filename = \
os.path.split(os.path.abspath(self.FileName))
name, extension = os.path.splitext(filename)
self.JobName= name # Name of this job
#if bugctrl>=1:
# print_String(iout,'Enter the job : \"%s\"'
# % self.JobName,2)
self.MachineList=[] # List, machine commands
self.OptionList= [] # List, options
self.KickOptionList=['nonstd'] # Default disable options
self.MoreOptionDict={'checkpoint':0,'check':0,'allcheck':0,
'scrf':0,'fchk=all':0,'extraoverlay':0,'%chk': 0} # Dict., options complicated
self.ExOvList = []
self.TitleList = [] # List of this job title
self.Charge = '' # Input Chage
self.Spin = '' # Input Spin
self.GeomList = [] # Input Geometry
self.AtLabel = [] # List, Atom labels
self.IAn = [] # List, Atom indexs
self.CList = [] # List, Atom coordinates
self.CartesianFlag=False # "True" : Cartesian
self.ZList = [] # List, Atom Z-matrix
self.ZListR = [] # List, Z-matrix parameters
# "False" : Z-Matrix;
self.NAtom = 0 # Number of atoms
self.RestList = [] # Rest content after Geometry
self.EngyReal = 0.0 # REAL, the total energy
self.ForcList = [] # LIST, Force
self.HessList = [] # LIST, Hessian
self.DipoList = [] # List, Dipole
self.DpDvList = [] # List, Dipole derivatives
self.PolaList = [] # List, Polarizability
return
def __del__(self):
'''Close the document flow of input file'''
if self.f=='None':
if self.IPrint>=2:
print_String(self.IOut,
'Do not close input file for GauIO class',1)
else:
if self.IPrint>=2:
print_String(self.IOut,
'Close Gau-Input file "%s" for GauIO class'
% self.FileName,1)
self.f.close() # Close input file
return
def get_MachAndOpt(self):
'''Loading machine commands and initial options from input file\n\
Note: the file flow locates in the next blank line below options\n\
'''
line=self.f.readline().strip()
if len(line)==0:
print_Error(self.IOut,
'Error occurs in reading option keywords from' +\
' "%s". Please make it valid ' % self.FileName)
while line[0]=='%': # Machine commands first
self.MachineList.append(line)
line=self.f.readline().strip()
if len(line)==0:
print_Error(self.IOut,
'Error occurs in reading option keywords from' +\
' "%s". Please make it valid ' % self.FileName)
if line[0]=='#': # Then for options
TmpOptions=[]
TmpOptions=line[1:].strip().split()
for option in TmpOptions:
self.OptionList.append(option)
line=self.f.readline().strip()
while len(line)!=0:
TmpOptions=[]
TmpOptions=line.strip().split()
for option in TmpOptions:
self.OptionList.append(option)
line=self.f.readline().strip()
else:
print_Error(self.IOut,
'Error occurs in reading option keywords from' +\
' "%s". Please make it valid ' % self.FileName)
for option in self.MachineList: # Get the name of chkfile
if option.lower().find('%chk')!=-1:
TmpList =\
option.strip().split('=')[1].split('.')
if len(TmpList)==1 or len(TmpList)==2:
self.ChkName= TmpList[0]
else:
self.ChkName= '.'.join(TmpList[0:-1])
break
else:
self.MoreOptionDict['%chk'] = 1 # Avoid unrequired chkfile
# copy back
self.ChkName = self.JobName
self.MachineList.insert(0,
'='.join(['%chk','%s.chk' % self.ChkName]))
if self.IPrint>=2:
print_String(self.IOut,
'ChkName is %s.chk' % self.ChkName,1)
if len(self.MachineList)>0:
print_List(self.IOut,self.MachineList,2,
'Machine commands(%s) :' % len(self.MachineList))
print_List(self.IOut,self.OptionList,3,
'Job options(%s) :' % len(self.OptionList))
return
def ctrl_Option(self):
'''\
Analysis the Options.\n\
1) "self.KickOptionList" shall be specified before this function\n\
2) "self.MoreOptionList" will be specified in this function\n\
3) "self.ExOvLayList" will be loaded, if the option of "extraoverlay" exists\
'''
#
#First to kick out some specifical option which could not be
#handled in this version
#
if self.IPrint>=2:
if len(self.KickOptionList)>0:
print_List(self.IOut,self.KickOptionList,3,
'KickOptionList(%s) :' % len(self.KickOptionList))
if len(self.KickOptionList)>0:
for option in self.OptionList:
for ivdmd in self.KickOptionList:
tmp1=option.lower()
if tmp1.find(ivdmd)!=-1:
print_Error(self.IOut,
'Invalid option(%s) is found in gausian'\
%ivdmd + ' input file.')
#
#Then to determine the complicated option initialization
#
tmpKeys = list(self.MoreOptionDict.keys())
for key in tmpKeys:
self.MoreOptionDict[key]=0
for option in self.OptionList:
tmpKey=option.strip().lower().split('=')[-1]
if tmpKey in tmpKeys:
self.MoreOptionDict[tmpKey]=1
continue
tmpKey=option.strip().lower().split('(')[0]
if tmpKey in tmpKeys:
self.MoreOptionDict[tmpKey]=1
if self.MoreOptionDict['checkpoint']==1: # To make sure that:
for option in self.OptionList: # Check "geom=checkpoint"
tmpList = option.strip().lower().split('=')
if len(tmpList)!=2: continue
if tmpList[-1]=='checkpoint' and tmpList[0]=='geom':
self.MoreOptionDict['checkpoint']=1
break
else:
self.MoreOptionDict['checkpoint']=0
if self.MoreOptionDict['check']==1: # To make sure that:
for option in self.OptionList: # Check "geom=check"
tmpList = option.strip().lower().split('=')
if len(tmpList)!=2: continue
if tmpList[-1]=='check' and tmpList[0]=='geom':
self.MoreOptionDict['checkpoint']=1
break
if self.MoreOptionDict['scrf']==1:
for option in self.OptionList:
if option.lower().find('scrf')!=-1:
self.MoreOptionDict['scrf']=option
break
else:
self.MoreOptionDict['scrf']=='unknown solvation'
#
#Now get the addtion iop command by option "extraoverlay"
#
if self.MoreOptionDict['extraoverlay']==1:
tmpExOvLay=self.f.readline().strip()
while len(tmpExOvLay)!=0:
self.ExOvList.append(tmpExOvLay)
tmpExOvLay=self.f.readline().strip()
if self.IPrint>=2:
if len(self.ExOvList)>0:
print_List(self.IOut,self.ExOvList,3,
"ExtraOverlay IOPs(%s) :" % len(self.ExOvList))
return
def get_TCSGR(self):
'''Get the (T)itle, (C)harge, (S)pin, (G)eom and (R)est content from input file'''
from re import compile
#
# If option of "allcheck" is stated,
# bypass (T)(C)(S)(G) and load (R)
#
if self.MoreOptionDict['allcheck']==1:
self.RestList=self.f.readlines()
if self.IPrint>=1:
print_String(self.IOut,
'\"AllCheck\" is stated, then title,charge, '+\
'spin and geometry are specified in CheckFile',1)
else:
#
# First to get "self.TitleList" (T)
#
self.TitleList.append(self.f.readline().strip())
if len(self.TitleList[0])==0:
print_Error(self.IOut,
'Missing job title in %s ' % self.FileName +\
'"GauIO.get_TCSGR"')
addTitle=self.f.readline().strip()
while len(addTitle)!=0: # Read the title more row
self.TitleList.append(addTitle)
addTitle=self.f.readline().strip()
if self.IPrint>=2:
if len(self.TitleList)==1:
print_String(self.IOut,
'Title : "%s"' %self.TitleList[0],1)
else:
print_List(self.IOut,self.TitleList,2,
'Title of job:')
#
# Then to get "self.Charge" (C) and "self.Spin" (S)
#
p1 = compile(' +|, *')
ChargeSpin=self.f.readline().strip()
if len(ChargeSpin)==0:
print_Error(self.IOut,
'Missing Charge and Spin in %s' % self.FileName)
TmpList = p1.split(ChargeSpin)
TmpList = [x.strip() for x in TmpList]
if TmpList.count('')!=0:
for i in range(TmpList.count('')):
TmpList.remove('')
try:
self.Charge=int(TmpList[0])
except ValueError:
print_Error(self.IOut,
'Invalid Charge in %s' % self.FileName)
try:
self.Spin=int(TmpList[1])
except ValueError:
print_Error(self.IOut,
'Invalid Spin in %s' % self.FileName)
if self.IPrint>=2: # Debugging
print_String(self.IOut,
'Charge and Spin : (%d, %d)'
% (self.Charge, self.Spin),1)
#
# If option of "checkpoint" is stated,
# bypass "self.GeomList" (G) and load "self.RestList" (R)
#
if self.MoreOptionDict['checkpoint']==1:
#self.f.readline()
self.RestList=self.f.readlines()
if self.IPrint>=1:
print_String(self.IOut,
'Molecular geometry will be loaded'+\
' from the CheckFile',1)
if self.IPrint>=2:
print_List(self.IOut,self.RestList,1)
else:
#
#Then to get "self.GeomList" (G) and "self.NAtom"
#
self.NAtom=0
p1 = compile(' {1,}|, {0,}')
tmpGeom = self.f.readline().strip().replace('\t',' ')
tmpList = [x.strip() for x in p1.split(tmpGeom)]
for i in range(tmpList.count('')):
tmpList.remove('')
if self.IPrint>=2:
print_List(self.IOut,tmpList,1)
if len(tmpList)==4: # To get Cartesian coordinate
self.CartesianFlag=True
if self.IPrint>=1:
print_String(self.IOut,
'Loading Cartesian coordinates',1)
while len(tmpList)==4:
self.GeomList.append(tmpGeom)
self.NAtom += 1
self.AtLabel.append(tmpList[0])
try:
self.CList.append([float(tmpList[1]),
float(tmpList[2]),float(tmpList[3])])
except ValueError:
print_String(self.IOut,
'Warning: could not get CList "GauIO.get_TCSGR"',1)
tmpGeom=self.f.readline().strip().replace('\t',' ')
tmpList =\
[x.strip() for x in p1.split(tmpGeom)]
for i in range(tmpList.count('')):
tmpList.remove('')
else:
print_List(self.IOut,self.GeomList,2,
Info='In job=%s' %self.JobName)
elif len(tmpList)>=5: # "5" : for atom fixing
# "6" : for Onion-type input
self.CartesianFlag=True
if self.IPrint>=2:
print_String(self.IOut,
'Loading Cartesian coordinates',1)
while len(tmpList)>=5:
self.GeomList.append(tmpGeom)
self.NAtom += 1
self.AtLabel.append(tmpList[0])
try:
self.CList.append([float(tmpList[2]),
float(tmpList[3]),float(tmpList[4])])
except ValueError:
print_String(self.IOut,
'Warning: could not get CList "GauIO.get_TCSGR"',1)
tmpGeom=self.f.readline().strip().replace('\t',' ')
tmpList =\
[x.strip() for x in p1.split(tmpGeom)]
for i in range(tmpList.count('')):
tmpList.remove('')
elif len(tmpList)==1: # To get Z-Matrix coordinate
if self.IPrint>=1:
print_String(self.IOut,
'Loading Z-Matrix coordinates',1)
self.CartesianFlag=False
tmpLength=1
while len(tmpList)==tmpLength or \
len(tmpList) == 8:
self.GeomList.append(tmpGeom)
self.NAtom=self.NAtom+1
self.AtLabel.append(tmpList[0])
self.ZList.append(tmpList)
tmpGeom=self.f.readline().strip().replace('\t',' ')
tmpList =\
[x.strip() for x in p1.split(tmpGeom)]
for i in range(tmpList.count('')):
tmpList.remove('')
if self.IPrint>=2:
print_List(self.IOut, tmpList,
3, 'Igor Debugging')
print_String(self.IOut,
'Len is %s, meeting %s'\
%(tmpLength,tmpList), 2)
if tmpLength<7:
tmpLength = tmpLength+2
LocPos = self.f.tell() # get Z-Matrix parameter
p1 = compile('= {0,}| {1,}|, {0,}')
tmpGeom=self.f.readline().strip().replace('\t',' ')
tmpList =\
[x.strip() for x in p1.split(tmpGeom)]
for i in range(tmpList.count('')):
tmpList.remove('')
if len(tmpList)==2:
tmpItem = tmpList[0].strip()
tmpFlag = False
for i in self.GeomList:
if i.find(tmpItem)!=-1:
tmpFlag = True
break
for j in self.AtLabel:
if j.lower().find(tmpItem.lower())!=-1:
tmpFlag = False
break
if tmpFlag:
if self.IPrint>=1:
print_String(self.IOut,
'Loading Z-Matrix parameters',
1)
while len(tmpList)==2:
self.ZListR.append(tmpGeom)
tmpGeom = self.f.readline().strip().replace('\t',' ')
tmpList =\
[x.strip()\
for x in p1.split(tmpGeom)]
for i in range(tmpList.count('')):
tmpList.remove('')
else:
self.f.seek(LocPos)
else:
self.f.seek(LocPos)
else:
print_Error(self.IOut,'Error in Geom. Info.')
p1 = compile('\d+') # Gen. IAn from AtLabel
for TmpLabel in self.AtLabel:
if p1.match(TmpLabel[0:2]):
try:
self.IAn.append(int(TmpLabel))
except ValueError:
print_Error(self.IOut,
"Error in IAn identification")
else:
TmpRe = TmpLabel.lower()
for key in sorted(GauIO.AtDict.keys()):
if TmpRe==key:
self.IAn.append(GauIO.AtDict[key])
break
else:
print_Error(self.IOut,\
'Error in IAn identification')
if self.IPrint>=2:
print_List(self.IOut,self.IAn,3,
'IAn List(%d) :' % len(self.IAn))
self.RestList = self.f.readlines() # Load "self.RestList"
if self.IPrint>=2: # Debugging
if self.CartesianFlag:
print_List(self.IOut,self.GeomList,2,
'Cartesian Coordinate(%s)'
% len(self.GeomList))
else:
print_List(self.IOut,self.GeomList,2,
'Z-Matrix Coordinate(%s)'
% len(self.GeomList))
if len(self.ZListR)>0:
print_List(self.IOut,self.ZListR,2,
'Z-Matrix Parameters(%s)'
% len(self.ZListR))
for i in range(len(self.RestList)): # filter the RestList
self.RestList[i]=self.RestList[i].strip()
if len(self.RestList)==0:
pass
elif len(self.RestList)==1:
if len(self.RestList[0])==0:
self.RestList = []
else:
TmpIndex = 0