shell之提取Gaussian输出文件中的能量数据

本文基于shell语言编写了提取Gaussian计算输出文件中的能量数据的脚本。

文件格式要求

  1. 在当前文件夹下需有四个文件夹./opt/ ./freq/ ./hbs/ ./solv/
  2. 四个文件夹下对应的文件名命名要求 *-opt.log *-freq.log *-hbs.log *-solv.log
output

脚本内容

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
#! /usr/bin/sh
############################################################################
#### This script is writen by Yafei Jiang, Dec 18,2019 @Jonyafei ####
#### Find all .log files and print corresponding energy ####
#### current dir: ./opt/ ./freq/ ./hbs/ ./solv/ ####
#### file name: *-opt.log *-freq.log *-hbs.log *-solv.log ####
############################################################################

cd ./opt/
files=(`ls *.log`)
names=()
Eopt=()
for i in ${!files[@]}
do
names[i]=`echo ${files[$i]} | sed 's/-opt.log//'`
Eopt[i]=`grep "SCF Done" ${files[$i]} | tail -1 | awk '{printf "%.6f\n",$5}'`
done

Ehbs=()
Ezpe=()
Gcorr=()
Esolv=()
for i in ${!names[@]}
do
cd ../hbs/
if [ ! -f ${names[$i]}-hbs.log ];then
Ehbs[i]=None
else
Ehbs[i]=`grep "SCF Done" ${names[$i]}-hbs.log | tail -1 | awk '{printf "%.6f\n",$5}'`
fi

cd ../freq/
if [ ! -f ${names[$i]}-freq.log ];then
Ezpe[i]=None
Gcorr[i]=None
else
Ezpe[i]=`grep "Zero-point correction" ${names[$i]}-freq.log | awk '{printf "%.6f\n",$3}'`
Gcorr[i]=`grep "Thermal correction to Gibbs Free Energy" ${names[$i]}-freq.log | awk '{printf "%.6f\n",$7}'`
fi

cd ../solv/
if [ ! -f ${names[$i]}-solv.log ];then
Esolv[i]=None
else
Esolv[i]=`grep "SCF Done" ${names[$i]}-solv.log | tail -1 | awk '{printf "%.6f\n",$5}'`
fi
done

cd ..
for i in ${!files[@]}
do
echo ${names[$i]} ${Eopt[$i]} ${Ezpe[$i]} ${Gcorr[$i]} ${Ehbs[$i]} ${Esolv[$i]} >> data.out
done

index="names\tE0\tEzpe\tGcorr\tEhbs\tEsolv"
sed -r "1i$index" data.out | column -t -R1,2,3,4,5,6 > energy.out
rm data.out

点击下载代码