-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathorcajobcheck.py
More file actions
1490 lines (1446 loc) · 79.3 KB
/
orcajobcheck.py
File metadata and controls
1490 lines (1446 loc) · 79.3 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
debug="no"
scriptversion=3.0
# All dependencies (also matplotlib and subprocess for special cases)
import numpy
import math
import sys
import os
import re
import time
start_time = time.time()
# Reverse read function.
# Default buffersize was 4096. 20480 works better
def reverse_lines(filename, BUFSIZE=20480):
#f = open(filename, "r")
filename.seek(0, 2)
p = filename.tell()
remainder = ""
while True:
sz = min(BUFSIZE, p)
p -= sz
filename.seek(p)
buf = filename.read(sz) + remainder
if '\n' not in buf:
remainder = buf
else:
i = buf.index('\n')
for L in buf[i+1:].split("\n")[::-1]:
yield L
remainder = buf[:i]
if p == 0:
break
yield remainder
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
#Conversion factors
#hartree to kcal/mol
harkcal = 627.50946900
##########################################
# Getting user arguments first
#########################################
# Read in filename or dir as argument
filelist=[]
try:
if sys.argv[1]==".":
dirmode="on"
for file in sorted(os.listdir(sys.argv[1])):
if file.endswith(".out"):
filelist.append(file)
#If using full or relative path for file or dir
elif "/" in sys.argv[1]:
#Checking if a single file with path
if ".out" in sys.argv[1]:
dirmode="off"
filename=sys.argv[1]
filelist.append(filename)
print("filename is", filename)
#Or a directory
else:
dirmode="on"
for file in os.listdir(sys.argv[1]):
if file.endswith(".out"):
filelist.append(sys.argv[1]+"/"+file)
#If parent folder
elif sys.argv[1]=="..":
dirmode="on"
for file in sorted(os.listdir(sys.argv[1])):
if file.endswith(".out"):
filelist.append(sys.argv[1]+"/"+file)
else:
dirmode="off"
filename=sys.argv[1]
if '.out' in filename == None :
print("Not an ORCA outputfile?")
exit()
filelist.append(filename)
except IndexError:
print(bcolors.OKBLUE +"ORCA JobCheck Utility version", scriptversion, "(Python version)", bcolors.ENDC)
print("---------------------------------")
print("Script usage:")
print("On single file: porcajobcheck.sh orcafile.out")
print("On directory: porcajobcheck.sh .")
print("Short printing mode: porcajobcheck.sh . -short")
quit()
shortmode="unset"
try:
if sys.argv[2]=="-short" :
shortmode="yes"
except IndexError:
pass
####################################################################
#Here begins jobspecific section
####################################################################
if debug=="yes":
if dirmode=="on":
print("filelist is", filelist)
print("Exiting dirmode")
#print('Here1. Script took %s' % (time.time() - start_time))
for filename in filelist:
if debug=="yes":
print("filename is", filename)
earlycrash="unset"
xyzfileerror="unset"
runcomplete="unset"
orcacrash="unset"
conbf="unset"
cpscferror="unset"
scferrorgeneral="unset"
scfstillrunning="unset"
scfalmostconv="unset"
parproc="unset"
jobtype="unset"
scfmethod="unset"
dft="unset"
optrunconverged="unset"
linearcheck="unset"
optenergy="unset"
finaltopenergy="unset"
opterror="unset"
optnotconv="unset"
optcycle="unset"
intelectrons="unset"
freqjob="unset"
freqsection="unset"
freqsearch="unset"
hessfail="unset"
optjob="unset"
scfconv="unset"
noiter="unset"
moread="unset"
autostart="unset"
postHFmethod="unset"
postHF="unset"
frozel="unset"
correl="unset"
refenergy="unset"
correnergy="unset"
caseinputline="unset"
inputline="unset"
nofrozencore="unset"
casscf="unset"
lastmacroiter="unset"
casscfconv="unset"
nevpt2correnergy="unset"
version="unset"
semiempirical="unset"
functional="unknown"
engrad="unset"
freqinrun="unset"
charge="unset"
endofinput="unset"
numatoms="unset"
spin="unset"
actualelec="unset"
temprcount="unset"
diagerror="unset"
brokensym="unset"
flipspin="unset"
errormult="unset"
scfcycleslist=[]
#errormessage="unset"
errormessage=[]
s2value="unset"
ideals2value="unset"
scftype="unset"
occorbsgrab="unset"
virtorbsgrab="unset"
orbs=[]
lastvirt_a="unset"
lastocc_a="unset"
gap_a="unset"
#spsection used to stop when SP output is done from bottom
spsection="unset"
#optsection used to stop when output found
optsection="unset"
finalgeo="unset"
coord="unset"
geomconvtable="unset"
geomconvgrab="unset"
lastgeomark="unset"
numatomcountstart="unset"
scantest="unset"
findenergy="unset"
scanenergies=[]
scanoptcycle=[]
lastscanoptcycle="unset"
lastenergy="unset"
allscanstepnums=[]
bsenergies=[]
rctype="unset"
scanatomA="unset"
scanatomB="unset"
scanatomC="unset"
scanatomD="unset"
extrapolate="unset"
extrapscfenergy="unset"
extrapcorrenergy="unset"
basissets=[]
newjob="unset"
finalsingleline="unset"
#
imaginmodes=[]
atomcoord=[]
optgeo=[]
lastgeo=[]
inputgeo=[]
geomconv=[]
count=0
rmsgradlist=[]
#funcional list
funclist=["b3lyp", "bp", "pbe", "tpss", "tpssh", "pbe0", "bp86", "blyp", "LDA", "BHLYP", "B2PLYP", "cam-b3lyp", "m06-2x", "pw6b95"]
grabsimpleinput=False
case=''
#Reading first lines of file normally until "Nuclear Repulsion ENuc"
#utf-8 has been used. errors=ignore seems to work for encoding issues
#with open(filename, encoding='utf-8') as bfile:
with open(filename, errors='ignore') as bfile:
for line in bfile:
count=count+1
if version =="unset":
if 'Program Version' in line:
version=line.split()[2]
if caseinputline=="unset" and version !="unset":
if 'WARNING: The NDO methods cannot have' in line:
semiempirical="yes"
#Grabbing simpleinputline
if caseinputline=="unset" and version !="unset":
if grabsimpleinput == True:
if '!' in line and not '#' in line:
var1=line.lower().split()[2:]
var2= ' '.join(var1)
var2=var2.replace("!","")
case=case+var2
else:
if grabsimpleinput==False and 'INPUT FILE' in line:
grabsimpleinput=True
#Here checking for stuff in listed inputfile until 'END OF INPUT'
if 'INPUT LINE' != "unset" and endofinput=="unset":
if 'END OF INPUT' in line:
endofinput="yes"
grabsimpleinput=False
caseinputline=case
#Now going through simple-input keywords here to determine job-type
if caseinputline!="unset":
#Checking for functional
for i in funclist:
if i in caseinputline:
functional=i
#Checking for noiter
if "noiter" in caseinputline:
noiter="yes"
#Checking for moread
if "moread" in caseinputline:
moread="yes"
#Checking for nofrozencore
if "nofrozencore" in caseinputline:
nofrozencore="yes"
#Checking for post-HF keywords
#print("caseinputline is", caseinputline)
if "ccsd" in caseinputline or "mp2" in caseinputline or "qcisd" in caseinputline:
postHF="yes"
if "ccsd" in caseinputline:
postHFmethod="CC"
if "qcisd" in caseinputline:
postHFmethod="QCI"
if "mp2" in caseinputline:
postHFmethod="MP2"
if "extrapolate" in caseinputline:
extrapolate="yes"
# Checking for opt or freq here
if " optts " in caseinputline or " optts\n" in caseinputline:
jobtype="optts"
if " freq " in caseinputline or " numfreq " in caseinputline or " freq" in caseinputline or " numfreq" in caseinputline:
jobtype="opttsfreq"; freqsection="notyetdone"
elif " opt" in caseinputline or " tightopt" in caseinputline or "copt" in caseinputline:
jobtype="opt"
#print("jobtype is", jobtype)
if " freq" in caseinputline or " numfreq" in caseinputline:
jobtype="optfreq"; freqsection="notyetdone"
elif " md " in caseinputline:
jobtype="md"
elif " freq " in caseinputline:
jobtype="freqsp"; freqsection="notyetdone"
elif " engrad " in caseinputline:
jobtype="sp"
engrad="yes"
else:
jobtype="sp"
#Going through block input
if casscf=="unset":
if '%casscf' in line:
casscf="yes"
if "$new_job" in line and newjob == "unset":
newjob="yes"
print(bcolors.WARNING +"New_job feature detected! Script will probably not deal with multi-job outputfiles correctly! Complain to RB.",bcolors.ENDC)
#Checking if brokensym job
if 'flipspin' in line.lower():
flipspin="yes"
if 'finalms' in line.lower():
bsms=float(line.split()[-1])
if 'brokensym' in line.lower():
brokensym="yes"
if endofinput=="yes":
if scantest=="unset":
temp=next(bfile);temp=next(bfile);temp=next(bfile);temp=next(bfile);
if "Relaxed" in temp:
scantest="over"
jobtype="scan"
temp=next(bfile);temp=next(bfile);temp=next(bfile)
rctype=temp.split()[0]
scansteps=temp.split()[-1]
if rctype=="Bond":
scanatomA=temp.split()[2][:-1]
scanatomB=temp.split()[3][:-2]
elif rctype=="Angle":
scanatomA=temp.split()[2][:-1]
scanatomB=temp.split()[3][:-1]
scanatomC=temp.split()[4][:-2]
elif rctype=="Dihedral":
scanatomA=temp.split()[2][:-1]
scanatomB=temp.split()[3][:-1]
scanatomC=temp.split()[4][:-1]
scanatomD=temp.split()[5][:-2]
scanvalA=temp.split()[-6]
scanvalB=temp.split()[-4]
scanchange=(float(scanvalB) - float(scanvalA)) / (float(scansteps) - 1)
else:
scantest="over"
if autostart=="unset" and conbf=="unset":
if 'Checking for AutoStart:' in line:
autostart="yes"
if conbf=="unset" and semiempirical=="unset":
if '# of contracted basis functions' in line:
conbf=line.split()[-1]
if 'Number of basis functions' in line:
conbf=line.split()[5]
if casscf=="yes":
if 'Number of basis functions' in line:
conbf=line.split()[5]
# #Counting atoms and getting inputgeo
if numatomcountstart=="unset" and scantest=="over":
if 'CARTESIAN COORDINATES (ANGSTROEM)' in line:
numatomcountstart="on"
numatomcount=0
if numatomcountstart=="on":
numatomcount += 1
inputgeo.append(line.strip())
if 'CARTESIAN COORDINATES (A.U.)' in line and numatomcountstart=="on" and numatoms=="unset":
numatomcountstart="off"
inputgeo.pop(0);inputgeo.pop(0);inputgeo.pop();inputgeo.pop();inputgeo.pop()
numatoms=numatomcount-5
if numatoms > 3:
pausecount=int((numatoms*3)-6+10+((numatoms*3)/6)*(numatoms*3)+20+numatoms*3-20)
if debug=="yes":
print("pausecount is", pausecount)
else:
pausecount=33
#Finding parallel and SCF output after basis output
if conbf !="unset" or semiempirical=="yes":
if parproc =="unset":
if 'parallel MPI-processes' in line:
parproc=line.split()[4]
# SCF method #NOTE. MULTIPLE OCCURENCE
if 'SCF SETTINGS' in line:
temp=next(bfile);temp=next(bfile);temp=next(bfile)
scftemp=temp.split()
if scftemp[0]=="ZDO-Hamiltonian":
semiempirical="yes"
scfmethod=scftemp[3]
else:
scfmethod=scftemp[4]
if 'DFT' in scfmethod:
dft="yes"
#Charge and spin
if scfmethod!="unset":
if ' Hartree-Fock type HFTyp' in line:
scftype=line.split()[4]
if ' Total Charge Charge' in line:
charge=line.split()[4]
if charge !="unset":
if ' Multiplicity Mult ....' in line:
mult=int(line.split()[3])
spin=(mult-1)/2.0
if 'Number of Electrons NEL ....' in line:
actualelec=line.split()[5]
if 'Nuclear Repulsion ENuc' in line:
nucrepuls=line.split()[5]
break
#Now we have read through the first few hundred lines (until nuc repulsion) of file that determines the jobtype and basic molecule info.
#If the ORCA job died prematurely (before nuc repulsion was printed) then that is fine (reversed read below will find the error)
if debug=="yes":
print('First read complete. Read', count, 'lines. Script took %s' % (time.time() - start_time))
print("Last line was", line)
#Now Reading lines of file backwards. This should detect errors immediately etc. or find where job died.
rcount=0
with open(filename, errors='ignore') as file:
for line in reverse_lines(file):
rcount=rcount+1
#Error messages. Only last 50 lines checked
if rcount < 60:
#If copy lines from suborca present at bottom of outputfile. Do not count
if '->' in line:
rcount=rcount-1
if 'ERROR: Unknown identifier' in line:
earlycrash="yes"; orcacrash="yes"; errormessage.append(line)
if 'Error (ORCA/TRAFO/RI-GIAO):' in line:
orcacrash="yes"; errormessage.append(line)
if 'Zero distance between atoms' in line:
orcacrash="yes";earlycrash="yes"
if 'Cannot open input file:' in line:
orcacrash="yes";earlycrash="yes"
if 'You must have a' in line:
orcacrash="yes";earlycrash="yes"
if 'INPUT ERROR' in line:
inputerror="yes";orcacrash="yes";earlycrash="yes"
if 'ERROR CODE RETURNED FROM CP-SCF PROGRAM' in line:
cpscferror="yes";orcacrash="yes"
if 'ABORTING THE RUN' in line:
abortcode="yes";orcacrash="yes";earlycrash="yes"
if 'Invalid assignment in' in line:
abortcode="yes";orcacrash="yes";earlycrash="yes"
if 'Aborting the run' in line:
abortcode2="yes";orcacrash="yes"
if 'Skipping actual calculation' in line:
abortcode3="yes";orcacrash="yes";earlycrash="yes"
if 'Error : multiplicity' in line:
errormult="yes";orcacrash="yes";earlycrash="yes"
if 'Unrecognized symbol in' in line:
orcacrash="yes";earlycrash="yes"
errormessage.append(line)
if 'Basis not recognized' in line:
orcacrash="yes";earlycrash="yes"
errormessage.append(line)
if 'Requested ECP not available' in line:
orcacrash="yes";earlycrash="yes"
errormessage.append(line)
if 'Element name/number, dummy atom or point charge expected in COORDS' in line:
coorderror="yes";orcacrash="yes";earlycrash="yes"
if 'FATAL ERROR ENCOUNTERED' in line:
fatalerrorcode="yes";orcacrash="yes";earlycrash="yes"
if 'There is no basis function on atom' in line:
basiserror="yes";orcacrash="yes";earlycrash="yes"
if 'ORCA finished by error termination' in line:
errortermin="yes";orcacrash="yes";errormessage.append(line)
if 'An error has occured in the SCF module' in line:
scferrorgeneral="yes";orcacrash="yes"
if 'An error has occured in the CASSCF module' in line:
casscferrorgeneral="yes";orcacrash="yes"
errormessage.append("CASSCF module failed")
if 'ORCA finished by error termination in CASSCF' in line:
casscferrorgeneral="yes";orcacrash="yes"
errormessage.append("CASSCF module failed")
if 'mpirun has exited due to process' in line:
mpiruncode="yes";orcacrash="yes"
if 'mpirun noticed that process rank 0' in line:
mpiruncode2="yes";orcacrash="yes"
if 'Job terminated from outer' in line:
jobtermin="yes";orcacrash="yes"
if 'CANNOT OPEN FILE' in line:
cannotopenfile="yes";orcacrash="yes";earlycrash="yes"
if 'Error: XYZ File reading requested' in line:
xyzfileerror="yes";orcacrash="yes";earlycrash="yes"
errormessage.append("XYZ file error problem")
if '!!! Filename:' in line:
xyzfileerror="yes";orcacrash="yes";earlycrash="yes"
errormessage.append("XYZ file error problem")
if 'Unknown identifier in' in line:
unknownidentifier="yes";orcacrash="yes";earlycrash="yes"
if 'ERROR: expect a' in line:
commanderror="yes";orcacrash="yes";earlycrash="yes"
if 'Error: Number of NGauss expected' in line:
orcacrash="yes";earlycrash="yes";errormessage.append(line)
if 'ERROR: found a coordinate defintion' in line:
coordinateerror="yes";orcacrash="yes";earlycrash="yes"
if 'Diagonalization failure because of NANs in input matrix' in line:
diagerror="yes"; orcacrash="yes"
if 'ERROR : GSTEP Program returns an error' in line:
gsteperror="yes";orcacrash="yes"
if 'ORCA TERMINATED NORMALLY' in line:
runcomplete="yes"
if 'TOTAL RUN TIME:' in line:
runtime=line.split()[3:]
if 'This wavefunction IS NOT CONVERGED!' in line:
scfconv="no";orcacrash="yes"
errormessage.append("SCF did not converge")
if 'The optimization did not converge but reach' in line:
optnotconv="yes"
if 'Error (ORCA_SCFGRAD): cannot find the xc-energy file:' in line:
scfconv="no";orcacrash="yes"
errormessage.append("SCF did not converge")
if 'Error: XYZ File reading requested but the structur' in line:
xyzfileerror="yes";orcacrash="yes";earlycrash="yes"
errormessage.append("XYZ file error problem")
# Here need to add some kind of break so that we stop if errors above are encountered
#if orcacrash="yes":
# break
if rcount==50:
if debug=="yes":
print('Here,rcount50. Script took %s' % (time.time() - start_time))
#Relaxed surface scan section
if jobtype=="scan":
if 'RELAXED SURFACE SCAN STEP' in line:
scanstep=line.split()[5]
allscanstepnums.append(scanstep)
if '* GEOMETRY OPTIMIZATION CYCLE' in line:
scanoptcycle.append(line.split()[4])
if lastgeomark=="unset":
if 'CARTESIAN COORDINATES (A.U.)' in line and lastgeomark=="unset" :
coord="active"
if debug=="yes":
print('Here. Starting coord grab Read', rcount, 'lines. %s' % (time.time() - start_time))
if coord=="active":
lastgeo.append(line.strip())
if 'CARTESIAN COORDINATES (ANGSTROEM)' in line:
coord="inactive"
lastgeomark="done"
lastgeo.pop(0);lastgeo.pop(0);lastgeo.pop(0);lastgeo.pop();lastgeo.pop()
if lastenergy =="unset":
if 'FINAL SINGLE POINT ENERGY' in line:
lastenergy=line.split()[4]
if 'OPTIMIZATION RUN DONE' in line:
findenergy="yes"
if findenergy=="yes":
if 'FINAL SINGLE POINT ENERGY' in line:
scanenergies.append(line.split()[4])
findenergy="no"
#Single-point section
if jobtype == "sp" or jobtype == "freqsp":
#If brokensymm job
if brokensym=="yes" or flipspin=="yes":
sdfds="sdf"
if 'E(BrokenSym)' in line:
bsenergy=line.split()[2]
if 'E(High-Spin) =' in line:
hsenergy=line.split()[2]
if 'DFT' in scfmethod and intelectrons=="unset":
if 'N(Total)' in line:
intelectrons=line.split()[2]
if runcomplete=="yes":
sdf="ds"
#Grabbing HOMO-LUMO gap
#if 'NO OCC E(Eh) E(eV)' in line:
if scftype=="UHF":
if 'SPIN DOWN ORBITALS' in line:
occorbsgrab="yes"
if scftype=="RHF":
if ' * MULLIKEN POPULATION ANALYSIS *' in line:
occorbsgrab="yes"
if occorbsgrab=="yes":
#print("line is", line); print("line.split is", len(line.split()))
if len(line) > 1 and len(line.split())==4 and '*' not in line:
endocc=line.split()[1]
if endocc == "0.0000":
#print(line)
lastvirt_a=float(line.split()[-1])
#print("last virt energy is", lastvirt)
#occorbsgrab="no"
#virtorbsgrab="yes"
elif endocc == "1.0000":
lastocc_a=float(line.split()[-1])
gap_a=lastvirt_a-lastocc_a
occorbsgrab="no"
#orbs.append(float(line.split()[-1]))
elif endocc == "2.0000":
lastocc_a=float(line.split()[-1])
gap_a=lastvirt_a-lastocc_a
occorbsgrab="no"
#orbs.append(float(line.split()[-1]))
if 'SPIN UP ORBITALS' in line:
occorbsgrab=="no"
if ' NO OCC E(Eh) E(eV)' in line:
occorbsgrab=="no"
#if virtorbsgrab=="yes":
# if line == '\n':
# virtorbsgrab="no"
# virtbands.append(float(line.split()[3]))
# endvirt=line.split()[1]
#print("orbs is", orbs)
#Grabbing S**2 value
if 'Expectation value of' in line:
s2value=line.split()[-1]
if 'Ideal value' in line:
ideals2value=line.split()[-1]
if postHF=="yes":
if extrapolate=="yes":
if "Extrapolated CBS SCF energy" in line:
extrapscfenergy=line.split()[-2]
if "Extrapolated CBS correlation energy" in line:
extrapcorrenergy=line.split()[-2]
if "Cardinal #:" in line:
basissets.append(line.split()[-1])
elif 'SCF energy with basis' in line:
basissets.append(line.split()[4][:-1])
if postHFmethod=="CC":
if 'Number of correlated electrons' in line:
correl=line.split()[5]
frozel=int(actualelec)-int(correl)
if noiter=="yes":
break
if 'Reference energy' in line:
refenergy=line.split()[3]
if 'Final correlation energy' in line:
correnergy=line.split()[4]
if 'E(CORR)(total)' in line:
correnergy=line.split()[2]
if 'E(CORR)(corrected)' in line:
correnergy=line.split()[2]
if 'E(CORR)' in line:
correnergy=line.split()[2]
if postHFmethod=="QCI":
if 'Number of correlated electrons' in line:
correl=line.split()[5]
frozel=int(actualelec)-int(correl)
if noiter=="yes":
break
if 'Reference energy' in line:
refenergy=line.split()[3]
if 'E(CORR)(corrected)' in line:
correnergy=line.split()[2]
if 'E(CORR)' in line:
correnergy=line.split()[2]
if postHFmethod=="MP2":
if 'CORRELATION ENERGY' in line:
correnergy=line.split()[3]
if 'chemical core electrons' in line:
frozel=line.split()[1].lstrip('NCore=')
if nofrozencore=="yes":
frozel="0"
if 'FINAL SINGLE POINT ENERGY' in line:
scfenergy=line.split()[4]
finalsingleline=True
if postHF=="unset" and noiter=="yes":
break
if 'SCF CONVERGED AFTER' in line:
scfconv="yes"
scfcycles=line.split()[4]
#if brokensym=="yes" or flipspin=="yes":
# scfcycleslist.append(scfcycles)
# print("scfcycleslist is", scfcycleslist)
spsection="done"
if 'The wavefunction IS NOT YET CONVERGED! It shows however signs of' in line:
scfalmostconv="yes"
if 'SCF NOT CONVERGED AFTER' in line:
scfconv="no"
unfinscfcycles=line.split()[5]
spsection="done"
#If runcomplete not true. Like if SCF is still running or if FREQ-sp job and something happened during freq run.
else:
if 'FINAL SINGLE POINT ENERGY' in line:
scfenergy=line.split()[4]
if postHF=="unset" and noiter=="yes":
break
if 'SCF CONVERGED AFTER' in line:
scfconv="yes"
scfcycles=line.split()[4]
spsection="done"
if 'Total Energy :' in line:
purescfenergy=line.split()[3]
if 'The wavefunction IS NOT YET CONVERGED! It shows however signs of' in line:
scfalmostconv="yes"
if 'SCF NOT CONVERGED AFTER' in line:
scfconv="no"
unfinscfcycles=line.split()[5]
spsection="done"
if 'ERROR (ORCA_CASSCF): Convergence Failure.' in line:
scfconv="no"; spsection="done";casscfconv="no"
if 'Warning: Active Space composition changed by more than' in line:
scfconv="no"; spsection="done";casscfconv="no"
if 'SCF ITERATIONS' in line:
if scfconv=="unset":
scfstillrunning="yes"
spsection="done"
########
if casscf=="yes":
if 'Total Energy Correction :' in line:
nevpt2correnergy=line.split()[6]
if lastmacroiter=="unset" and 'MACRO-ITERATION' in line:
lastmacroiter=line.split()[1].rstrip(':')
if 'THE CAS-SCF GRADIENT HAS CONVERGED' in line:
casscfconv="yes"
if 'THE CAS-SCF ENERGY HAS CONVERGED' in line:
casscfconv="yes"
if 'CAS-SCF ITERATIONS' in line:
break
#if 'SCF ITERATIONS' in line:
# scfstillrunning="yes"
# spsection="done"
if spsection == "done":
break
#FREQSECTION
#print("freqsection is", freqsection)
#Will analyze the last freq output encountered in outputfile. But will only print it if optjob converged
if freqsection=="notyetdone":
if runcomplete=="yes":
freqjob="yes"
#print("freqjob is", freqjob)
#Once Temperature has been found, try to skip all Normal mode output without re.search lines.
#Until NORMAL MODES
if freqsearch!="on":
if 'Temperature ...' in line:
temperature=line.split()[2]
temprcount=rcount
freqsearch="on"
if debug=="yes":
print('Here. Temperature line. rcount is:', rcount, 'Script took %s' % (time.time() - start_time))
if temprcount!="unset" and rcount-temprcount > pausecount :
#print("rcount is", rcount); print("line is", line)
if 'imaginary' in line:
freqimagtest="yes"
imaginmodes.append(line.split()[1])
if linearcheck=="yes":
if '5:' in line:
lowestvib=line.split()[1]
else:
if '6:' in line:
lowestvib=line.split()[1]
#Here we have reached the beginning of FREQ section, from bottom, hence freqsection is done
if 'VIBRATIONAL FREQUENCIES' in line:
freqsearch="off"
if debug=="yes":
print('Here. FREQdone. rcount is:', rcount, 'Script took %s' % (time.time() - start_time))
freqsection="done"
#Therm stuff
if freqsearch!="on":
#print('bla Script took %s' % (time.time() - start_time))
if 'The molecule is recognized as being linear' in line:
linearcheck="yes"
if 'G-E(el)' in line:
if "nan" in line.split()[2]:
hessfail=True
freqsection="done"
else:
gthermcorr=float(line.split()[2])
if 'Zero point' in line:
zeropointcorr=float(line.split()[4])
enthalpycorr=totthermcorr+zeropointcorr+enthalpyterm
if 'Final entropy term' in line:
entropycorr=float(line.split()[4])
if 'Total thermal correction' in line:
totthermcorr=float(line.split()[3])
if 'Thermal Enthalpy correction' in line:
enthalpyterm=float(line.split()[4])
#If freqjob but runcomplete is unset.
elif rcount > 50 and runcomplete=="unset":
#print("Here. freqsection is:", freqsection)
freqsection="notpresent"
#print("fresection not present")
#OPT job settings
if freqsection=="done" or freqsection=="unset" or freqsection=="notpresent":
if jobtype == "opt" or jobtype == "optts" or jobtype == "optfreq" or jobtype == "opttsfreq":
optjob="yes"
#if 'Analytical frequency calculation' in line:
#freqinrun="yes"
#numatoms
#print("optrunconverged is", optrunconverged)
#print("optnotconv is", optnotconv)
if optrunconverged=="unset" or optnotconv=="unset":
if 'OPTIMIZATION RUN DONE' in line:
optrunconverged="yes"
if 'The optimization did not converge but' in line:
optnotconv="yes"
if runcomplete=="yes":
if optrunconverged=="unset":
if 'OPTIMIZATION RUN DONE' in line:
if debug=="yes":
print("we are here Script took %s" % (time.time() - start_time))
optrunconverged="yes"
if optenergy=="unset":
if 'FINAL SINGLE POINT ENERGY' in line:
#print("line is", line)
optenergy=float(line.split()[4])
if optrunconverged=="yes":
finaloptenergy=optenergy
#print("this optenergy is", optenergy)
if debug=="yes":
print(line)
print('In optsection. FINAL S P E line. Read', rcount, 'lines. Script took %s' % (time.time() - start_time))
if lastgeomark=="done":
#print('lastgeomark is done. Script took %s' % (time.time() - start_time))
if optrunconverged=="unset":
if 'FINAL ENERGY EVALUATION AT THE STATIONARY POINT' in line:
optrunconverged="yes"
if debug=="yes":
print('Here. OPT HAS CONVERGED. ', rcount, 'lines. Script took %s' % (time.time() - start_time))
# Only Slow line maybe. Necessary??? Maybe
#Using rcount >15015 time reduces barely. Maybe this is not the bottleneck?
#if rcount >15015:
# #print("line is", line)
if 'CARTESIAN COORDINATES (A.U.)' in line and lastgeomark=="unset" :
coord="active"
if debug=="yes":
print('Here. Starting coord grab Read', rcount, 'lines. %s' % (time.time() - start_time))
if coord=="active":
lastgeo.append(line.strip())
if 'CARTESIAN COORDINATES (ANGSTROEM)' in line:
coord="inactive"
lastgeomark="done"
lastgeo.pop(0);lastgeo.pop(0);lastgeo.pop(0);lastgeo.pop();lastgeo.pop()
#Finds optcycle number if optimization converged
#if re.search('*** (AFTER', line):
if runcomplete=="yes" and optrunconverged=="yes" and lastgeomark=="done":
if '*** (AFTER' in line:
optcycle=int(line.split()[2])
# Signals that optsection is over for a converged done. Breaks later if optsection is set
if optcycle!="unset":
if 'FINAL ENERGY EVALUATION AT THE STATIONARY POINT' in line:
#print("Optsection is now done")
optsection="done"
#ONly search for opt not conv in last 100 lines
if rcount < 100:
if 'The optimization did not converge but reached the maximum number of' in line:
optnotconv="yes"
#This finds optcycle number if optimization did not converge. Should break at some point though
#Previously slow LINE. Hopefully fixed now.
if lastgeomark=="done":
if 'GEOMETRY OPTIMIZATION CYCLE' in line and optcycle=="unset":
optcycle=int(line.split()[4])
prevoptcycle=optcycle-1
#3jan. Disabling optsection here and putting in geomconvtable section instead
#optsection="done"
#print("runcomplete is", runcomplete)
#print("optnotconv is", optnotconv)
if optnotconv=="yes" or runcomplete=="unset":
if optcycle!="unset":
if 'The optimization has not yet converged - more geometry cycles are needed' in line:
geomconvtable="active"
#print("geomconvtable ACTIVE")
if geomconvtable=="active":
#if 'RMS gradient' in line:
# print("RMS line is", line)
# rmsgradlist.append(line.strip()[2])
geomconv.append(line.strip())
if '|Geometry convergence|' in line:
#print("line is", line)
geomconv.pop(0);geomconv.pop(0)
geomconvtable="inactive"
geomconvgrab="done"
#optsection="done"
if geomconvgrab=="done":
if 'FINAL SINGLE POINT ENERGY' in line:
optenergy=float(line.split()[4])
optsection="done"
if 'DFT' in scfmethod and optrunconverged=="yes" and intelectrons=="unset":
if 'N(Total)' in line:
intelectrons=line.split()[2]
if optsection=="done":
if debug=="yes":
print('Optsection done, breaking. Script took %s' % (time.time() - start_time))
break
#Integration of electrons. Only necessary for DFT.
#NOTE. MULTIPLE OCCURENCE
#Jess example: Can save 0.062 seconds here
if debug=="yes":
print('Here. End of reverse loop. Script took %s' % (time.time() - start_time))
#print("Last line is", line)
# Here begins printing
#print("runcomplete is", runcomplete)
#print("optnotconv is", optnotconv)
########################
# Now all read through file done. Printing below.
########################
#################
#SHORT PRINTING MODE
if shortmode=="yes":
#print("--------------")
#print("filename is", filename)
#print("jobtype is", jobtype)
if runcomplete=="yes":
#print("jobtype is", jobtype)
if jobtype=="sp" or jobtype=="freqsp" and postHF=="unset":
if jobtype=="freqsp":
if len(imaginmodes)==0:
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + scfenergy), bcolors.ENDC)
else:
print('{0:40} {1:10} {2:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + scfenergy, bcolors.FAIL + "Imaginary modes"), bcolors.ENDC)
if jobtype=="sp":
if scfconv=="yes" or casscfconv=="yes":
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + scfenergy), bcolors.ENDC)
else:
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.FAIL + "Not converged!"), bcolors.ENDC)
elif jobtype=="sp" and postHF!="unset":
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + scfenergy), bcolors.ENDC)
elif optjob=="yes" or jobtype=="optfreq" or jobtype=="opttsfreq":
if optrunconverged=="yes":
#print("optenergy is", optenergy)
if hessfail==True:
print('{0:40} {1:10} {2:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + str(optenergy), bcolors.FAIL + "Hessian incomplete"), bcolors.ENDC)
continue
if len(imaginmodes)==0:
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + str(optenergy)), bcolors.ENDC)
else:
print('{0:40} {1:10} {2:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + str(optenergy), bcolors.FAIL + "Imaginary modes"), bcolors.ENDC)
else:
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.FAIL + "Optimization failed!"), bcolors.ENDC)
elif jobtype=="scan":
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.OKGREEN + 'Scan'), bcolors.ENDC)
elif optnotconv=="yes":
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.FAIL + "Optimization failed!"), bcolors.ENDC)
elif orcacrash=="yes":
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.FAIL + "ORCA Crash!"), bcolors.ENDC)
else:
print('{0:40} {1:40}'.format(bcolors.HEADER + filename+":", bcolors.WARNING + "Running?"), bcolors.ENDC)
# LONG PRINTING MODE
else:
print("")
print(bcolors.OKBLUE +"ORCA JobCheck Utility version", scriptversion, "(Python3 version)", bcolors.ENDC)
print("-----------------------------------------------------------------------")
print(bcolors.HEADER +"File:", filename, bcolors.ENDC)
if parproc!="unset":
print("ORCA version", version, "ran", parproc,"MPI-process job.")
else:
print("ORCA version", version, "ran serial job")
if runcomplete=="yes":
print(bcolors.OKGREEN +"ORCA terminated normally (",' '.join(runtime),")", bcolors.ENDC)
elif optnotconv=="yes":
print(bcolors.FAIL +"ORCA Optimization failed to converge!", bcolors.ENDC)
elif orcacrash=="yes":
if optrunconverged=="yes":
print(bcolors.OKGREEN +"Optimization converged! in (", optcycle, "iterations). YAY!", bcolors.ENDC)
print(bcolors.OKBLUE + "FINAL OPTIMIZED ENERGY:", finaloptenergy, bcolors.ENDC)
print(bcolors.FAIL +"ORCA JOB Crashed!", bcolors.ENDC)
print("Error message:")
for emes in errormessage:
print(bcolors.FAIL+emes,bcolors.ENDC)
#print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
#with open(filename, errors='ignore') as cfile:
# scount=0
# bla=[]
# nlines=5
# for dline in reverse_lines(cfile):
# scount += 1
# bla.append(dline.strip('\n'))
# if scount==nlines:
# break
# for bline in reversed(bla):
# print(bcolors.FAIL +bline, bcolors.ENDC),
# break
#Will now allow last geometry printout as well
try:
if optjob=="yes":
if optrunconverged=="unset" and sys.argv[2]=="-p":
print("Cycle", optcycle, "Cartesian coordinates (", numatoms, "atoms) in Angstrom:")
for atom in reversed(lastgeo):
print(*atom, sep='')
if sys.argv[2]=="-plotgrad":
print(bcolors.OKBLUE +"Plotting Gradient in Matplotlib...", bcolors.ENDC)
allcycles=list(range(1, optcycle+1))
import subprocess
import matplotlib.pyplot as plt
proc = subprocess.Popen(['grep', " RMS grad", filename],stdout=subprocess.PIPE)
proc2 = subprocess.Popen(['grep', " MAX grad", filename],stdout=subprocess.PIPE)
all_rmsgrad=[]
for line in proc.stdout.readlines():
string=line.decode("utf-8").strip().split()
val_rmsg=float(string[2])
target_rmsg=float(string[3])
all_rmsgrad.append(val_rmsg)
all_maxgrad=[]
for line in proc2.stdout.readlines():
string=line.decode("utf-8").strip().split()
val_maxg=float(string[2])
target_maxg=float(string[3])
all_maxgrad.append(val_maxg)
plt.plot(allcycles, all_rmsgrad, linestyle='-', color='red', linewidth=2, label="RMS grad")
plt.plot(cycles, [target_rmsg] * len(cycles), linestyle='-', color='red', linewidth=1)
plt.plot(allcycles, all_maxgrad, linestyle='-', color='blue', linewidth=2, label="Max grad")