-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhartree2kcal
executable file
·68 lines (65 loc) · 1.94 KB
/
hartree2kcal
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
#!/bin/bash
#####################################################################
# Program : #
# Change the energy unit from Hartree to kcal/mol #
# Input : #
# $1 = * #
# Output : #
# * (User defined) #
#####################################################################
# 2016/09/15, Grace, 1st. ver.
# 2016/11/16, Grace, 2nd. ver.
# 2017/04/28, Grace, 3rd. ver.
# 2017/12/28, Grace, tmp. ver. close stdin
# Step 0. Check the existance of input file
[ "$1" == "" ] && echo 'No 1st. input argument, stop the program.' && exit
[ -f "$1" ] || echo "$1 is not exist"
[ -f "$1" ] || exit
[ "$2" == "" ] && echo 'No 2nd. input argument, stop the program.' && exit
# Step 1. Get the number of grid points
# Get the number of state
num_pts=$(wc $1|awk '{print $1}')
num_column=$(cat $1 | sort -n -k 2 | head -n 1 | awk '{FS = " "} ; {print NF}')
# fix bug, 2017/11/27, Grace. remove fail jobs
num_state=$(($num_column-1))
# Step 2. Decide the energy reference, and then change the energy unit
# from Hartree to kcal/mol
read -p 'Use the smallest energy as the reference (yes/no): ' judge
#judge='yes'
case $judge in
"yes") # smallest one as ref.
ref=$(awk '{print $2}' $1|sed '/^$/d' | sort -nr | tail -n 1)
;;
"no")
read -p 'Key-in the energy of reference: ' ref
;;
"*")
echo "Wrong type! exit"
exit
esac
rm -f tmp*.txt
for (( i=2; i<=$num_column; i++))
do
awk "{print \$$i}" $1 > list.txt
line=$(wc list.txt | awk '{print $1}')
for (( j=1;j<=$line;j++))
do
energy=$(head -n $j list.txt | tail -n 1)
if [ "$energy" == "" ]
then
echo "" >> tmp$i.txt
else
echo "( $energy - $ref ) * 627.5095" | bc >> tmp$i.txt
fi
done
done
# Step 3. Store all information into file $2
echo "output file : $2"
awk '{print $1}' $1 > x.txt
line=$(echo x.txt)
for (( i=2; i<=$num_column; i++))
do
line=$(echo "$line tmp$i.txt")
done
paste `echo $line` > $2
rm -f x.txt list.txt tmp*.txt