-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckGau
executable file
·420 lines (371 loc) · 13.6 KB
/
checkGau
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
#!/bin/bash
#############################################################################
# Program : #
# Check the status of G16 output file. #
# - classification: SP, MIN, Saddle and IRC #
# - it has single job version and benchmark version #
# #
# Input : #
# single job verion : $1 = test.log #
# benchmark version : $1 = all #
# #
# Output : #
# 1. Std-out #
# 2. (SP.dat, MIN.dat, Saddle.dat and IRC.dat) depend on systems #
# #
# History : #
# 2016/11/03, Grace, 1st. ver. merge the function of checkGauOPT and #
# checkGauPES and getGauEandZPE. #
# 2018/08/24, Grace, fix the bug of extracting many imaginary frequency #
# 2019/08/07, Grace, modify the structure of code; move main program in the #
# front and also remove redundant part. #
# 2020/09/22, Grace, change structure and also change g09 to g16. #
# 2020/09/23, Grace, add output as documents to save energy curve. #
# 2020/10/05, Grace, changeFormatSaddle(): change the format of std-out in #
# Saddle.dat. #
# 2020/10/06, Grace, change name of IRC() to extractIRC() because of #
# duplicate cause bug. #
# #
#############################################################################
function main(){
# 1. print out purpose
stdoutPurpose $1
# 2. check input argument $1
getNumJobs $1 #output: list.dat and $NumJobs=$?
NumJobs=$?
# check the job is sucessful of fail; remove list.dat
checkJobs $NumJobs list.dat # output : statistic.dat
# 3. classify jobs into four categries: SP, MIN, Saddle or IRC
classifyJobs statistic.dat
# exit
# output : class.dat and (SP.dat, MIN.dat, Saddle.dat, IRC.dat)
# 4. alalyse the result of jobs
# sub-functions in classifyJobs(); countIF(), extractE(), extractZPE() and IRC()
analyseJobs statistic.dat class.dat SP.dat MIN.dat Saddle.dat IRC.dat
}
function stdoutPurpose(){
cat << EOF
#############################################################################
Program $0 checks and alanyses Gaussian output files
Current working directory: $(pwd)
The extension of output file is : .log
1. Analyse all the gaussian output file
>> checkGau all
2. Analyse only one gaussian output file
>> checkGau \$(name).log
#############################################################################
EOF
[ "$1" == "" ] && \
echo 'No argument, please key-in "all" or the name o ouftput file (*.log)' \
&& exit
}
function getNumJobs(){
# $1 = input argument
# output: list.dat
case $1 in
"all") # benchmark mode
ls | grep .log | sed 's/.log//g' > list.dat
NumJobs=$(wc -l list.dat | awk '{print $1}')
return $NumJobs
;;
*) # single job mode
echo $1 | sed 's/.log//g' > list.dat
return 1
;;
esac
}
function checkJobs(){
# $1 = $NumJobs
# $2 = list.dat
# output: statistic.dat
NumJobs=$1
ListFile=$2
rm -f statistic.dat
for (( i=1; i<=$NumJobs; i++ ))
do
name=$(sed -n "$i,$i p" $ListFile)
# check the existence of argument
test -e $name.log || echo "file $name.log is not exist" | exit
End=$(grep -c 'Normal termination' $name.log)
if [ "$End" == "0" ]
then
# Error termination
stat=$(echo Fail)
else
# Normal termination
stat=$(echo Success)
fi
echo $name $stat >> statistic.dat
done
rm -f $ListFile
}
function classifyJobs(){
# $1 = statistic.dat
# output : class.dat (SP.dat, MIN.dat, Saddle.dat, IRC.dat)
StatFile=$1
rm -f class.dat SP.dat MIN.dat Saddle.dat IRC.dat
grep Success $StatFile | awk '{print $1} '> NameList.dat
for name in `cat NameList.dat`
do
echo $name > name.dat
# check it is IRC or not
numIRC=$(grep -c 'Summary of reaction path following' $name.log)
if [ "$numIRC" == "0" ]
then
# check it is Saddle or MIN or SP
countIF $name.log
# extract the energy
extractE $name.log
NumIF=$(head -n 1 IF.dat | awk '{print $1}')
if [ "$NumIF" == "0" ]
then
# IF is not exist
SP=$(grep 'Frequencies' $name.log)
if [ "$SP" == "" ]
then
status=$(echo SP)
paste name.dat E.dat >> SP.dat
else
extractZPE $name.log
status=$(echo MIN)
paste name.dat E.dat ZPE.dat >> MIN.dat
fi
else
# IF is exist
extractZPE $name.log
status=$(echo Saddle)
paste name.dat E.dat ZPE.dat IF.dat >> Saddle.dat
fi
else
# this is IRC result
status=$(echo IRC)
extractIRC $name.log #output: extractIRC.dat
paste name.dat extractIRC.dat >> IRC.dat
fi
echo $name $status >> class.dat
rm -f name.dat extractIRC.dat IF.dat E.dat ZPE.dat
done
rm -f NameList.dat
}
function changeFormatSaddle(){
# $1 = Saddle.dat
awk '{print $4}' `echo $1`| awk 'NF > 0' > NumIF.dat
nline=0
rm -f saddle.tmp
for IF in `cat NumIF.dat`
do
nline=$(( $nline + 1 ))
if [ "$IF" == 1 ]
then
printf '%10s\t %16.10f\t %16.10f\t %2i\t %10.4f\n' $(sed -n "$nline,$nline p " `echo $1` ) >> saddle.tmp
else
saddlename=$(sed -n "$nline,$nline p" `echo $1`| awk '{print $1}')
saddleE=$(sed -n "$nline,$nline p" `echo $1`| awk '{print $2}')
saddleZPE=$(sed -n "$nline,$nline p" `echo $1`| awk '{print $3}')
for ((s=1;s<=$IF;s++))
do
if [ "$s" == 1 ]
then
saddleEig=$(sed -n "$nline,$nline p" `echo $1`| awk '{print $5}')
else
nline=$(( $nline + 1 ))
saddleEig=$(sed -n "$nline,$nline p" `echo $1` )
fi
printf '%10s\t %16.10f\t %16.10f\t %2i\t %10.4f\n' "$saddlename" "$saddleE" "$saddleZPE" "$s" "$saddleEig" >> saddle.tmp
done
fi
done
mv -f saddle.tmp Saddle.dat
rm -f NumIF.dat
}
# sub-functions in classifyJobs(); countIF(), extractE(), extractZPE() and extractIRC()
function countIF(){
# input : test.log; gaussian output file
# output : IF.dat
# extract all frequency
# 2020/10/05, Grace, add constraints of counting normal modes
NAtoms=$(grep 'NAtoms' $1 | tail -n 1 | awk '{print $2}')
NumNM=$(( 3*NAtoms-6 )) # assume it is a nonlinear molecule
NumNMRemainder=$(( $NumNM%3 ))
NumNMRow=$(( $NumNM/3 ))
[ "$NumNMRemainder" != 0 ] && NumNMRow=$(( $NumNMRow + 1 ))
grep -w 'Frequencies --' $1 | grep -v 'Frequencies ---' \
|awk '{print $3,$4,$5}' | tail -n $NumNMRow > FreqList
awk '{print $1}' FreqList > FreqListColumn
awk '{print $2}' FreqList >> FreqListColumn
awk '{print $3}' FreqList >> FreqListColumn
# count the amount of IF
NumIF=$(grep -c '-' FreqList)
echo $NumIF > tmp0.dat
if [ "$NumIF" == "0" ]
then
# SP or MIN
touch tmp1.dat
else
# Saddle point, extract the IF
rm -f tmp1.dat
for (( i=1; i<=$NumIF; i++ ))
do
head -n $i FreqListColumn | tail -n 1 >> tmp1.dat
done
fi
paste tmp0.dat tmp1.dat > IF.dat
rm -f FreqList FreqListColumn tmp0.dat tmp1.dat
}
# 2.3 extract the energy
function extractE(){
# input : test.log; gaussian output file
# output : E.dat
#The keyword for MP2 is 'EUMP2',and for CCSD is 'CORR'. Others
#are 'SCF Done'.
method=$(grep ' CORR ' $1|tail -n 1)
[ "$method" == '' ] && method=$(grep 'EUMP2' $1|tail -n 1) \
|| method='CORR'
if [ "$method" != 'CORR' ]; then
[ "$method" == '' ] && method='SCF Done' || method='EUMP2'
fi
rowE=$(grep "$method" $1 | tail -n 1)
case $method in
"CORR")
E=$(echo $rowE | awk '{print $4}')
;;
"EUMP2")
E=$(echo $rowE | awk '{print $6}' | sed 's/D/E/g' )
;;
"SCF Done")
E=$(echo $rowE | awk '{print $5}')
;;
esac
echo $E >> E.dat
}
# 2.4 extract zero point energy
function extractZPE(){
# input : test.log; gaussian output file
# output : ZPE.dat
method=$(grep ' CORR ' $1|tail -n 1)
[ "$method" == '' ] && method=$(grep 'EUMP2' $1|tail -n 1) \
|| method='CORR'
if [ "$method" != 'CORR' ]; then
[ "$method" == '' ] && method='SCF Done' || method='EUMP2'
fi
ZPE=$(grep 'Zero-point correction' $1|tail -n 1| awk '{print $3}')
if [ "$method" == "CORR" ]; then
ZPE=0
fi
echo $ZPE >> ZPE.dat
}
# 2.5 extract the IRC information
function extractIRC(){
# input : test.log; gaussian output file
# output : extractIRC.dat
tmp=$(grep '# OF POINTS ALONG THE PATH =' $1 | tail -n 1 \
|awk '{print $8}')
pts=$(($tmp+1))
TS=$(grep 'Energies reported relative to the TS energy of' $1 \
| awk '{print $9}' )
R=$(grep -A 3 'Summary of reaction path following' $1 | tail -n 1 \
| awk '{print $2}')
P=$(grep -A $(($pts+2)) 'Summary of reaction path following' $1 | \
tail -n 1 | awk '{print $2}')
echo $pts $R $TS $P > extractIRC.dat
}
function analyseJobs(){
# $1 = statistic.dat
# $2 = class.dat
# $3 = SP.dat
# $4 = MIN.dat
# $5 = Saddle.dat
# $6 = IRC.dat
StatFile=$1
ClassFile=$2
SPFile=$3
MinFile=$4
SaddleFile=$5
IRCFile=$6
# analyse the amount of jobs ###################################################
Total=$(wc -l $StatFile |awk '{print $1}')
Success=$(grep -c Success $StatFile)
Fail=$(grep -c Fail $StatFile)
SP=$(grep -c SP $ClassFile)
MIN=$(grep -c MIN $ClassFile)
Saddle=$(grep -c Saddle $ClassFile)
IRC=$(grep -c IRC $ClassFile)
grep Fail statistic.dat | sed 's/Fail//g' > Fail.dat
stdoutStatResult $Total $Success $Fail
if [ -f $ClassFile ]
then
stdoutClassResult $SP $MIN $Saddle $IRC
if [ -f SP.dat ]
then
echo ""
echo '----- SP -----'
printf '%10s\t %16s\t \n' $(echo Name E\(hartree\))
printf '%10s\t %16.10f\t \n' $(cat SP.dat)
fi
if [ -f MIN.dat ]
then
echo ""
echo '----- MIN -----'
printf '%10s\t %16s\t %16s\t \n' $(echo Name E\(hartree\) ZPE\(hartree\))
printf '%10s\t %16.10f\t %16.10f\t \n' $(cat MIN.dat)
fi
if [ -f Saddle.dat ]
then
echo ""
echo '----- Saddle -----'
printf '%10s\t %16s\t %16s\t %3s\t %10s\t \n' \
$(echo Name E\(hartree\) ZPE\(hartree\) \#IF IF\(cm^1\))
# 2020/10/05, Grace, separate higher-order saddle points
changeFormatSaddle Saddle.dat
###
printf '%10s\t %16.10f\t %16.10f\t %2i\t %10.4f\n' $(cat Saddle.dat)
fi
if [ -f IRC.dat ]
then
echo ""
echo '----- IRC -----'
printf '%10s\t %4s\t %16s\t %16s\t %16s\t \n' \
$(echo Name \#IRC rel_R\(hartree\) TS\(hartree\) rel_P\(hartree\))
printf '%10s\t %4i\t %16.10f\t %16.10f\t %16.10f\n' \
$(cat IRC.dat)
fi
rm -f $StatFile $ClassFile # $SPFile $MINFile $SaddleFile $IRCFile Fail.dat
fi
}
function stdoutStatResult(){
# $1 = $Total
# $2 = $Success
# $3 = $Fail
cat << EOF
#############################################################################
Std-out the information of rawdata
Count the amount of jobs:
`printf '%8s\t %5i\t \n' $(echo Total: $1)`
`printf '%8s\t %5i\t \n' $(echo Success: $2)`
`printf '%8s\t %5i\t \n' $(echo Fail: $3)`
EOF
}
function stdoutClassResult(){
# $1 = $SP
# $2 = $MIN
# $3 = $Saddle
# $4 = $IRC
[ `wc -l Fail.dat | awk '{print $1}' ` = 0 ] && FailFile='' || FailFile='Fail.dat'
[ $1 = 0 ] && SPFile='' || SPFile='SP.dat'
[ $2 = 0 ] && MINFile='' || MINFile='MIN.dat'
[ $3 = 0 ] && SaddleFile='' || SaddleFile='Saddle.dat'
[ $4 = 0 ] && IRCFile='' || IRCFile='IRC.dat'
cat << EOF
Classification of the successful jobs:
`printf '%8s\t %5i\t \n' $(echo SP: $1)`
`printf '%8s\t %5i\t \n' $(echo MIN: $2)`
`printf '%8s\t %5i\t \n' $(echo Saddle: $3)`
`printf '%8s\t %5i\t \n' $(echo IRC: $4)`
------------------------------------------------------------
Output files: $FailFile $SPFile $MINFile $SaddleFile $IRCFile
------------------------------------------------------------
#############################################################################
Detail of output:
EOF
}
main $@