View difference between Paste ID: VNQHjKeL and rFvmymSx
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
# This shell script plots electron density of states from ORCA output file into txt data usable for plotting. It should work for any single-point calculation, but do not try using it for geometry jobs (i.e. where orbital energies are printed more than once)
3
#There are no comments in code because I'm a bit lazy to write them, sorry :-)
4
# (c) 2013 Evgeny Tikhonov; mail: lumbrius at gmail dot com
5
6
Nel=`grep "Number of Electrons" $1 | awk '{print $6}'`
7
8
IsOdd=`echo ${Nel}%2 | bc`
9
10
if [ $IsOdd == 1 ];
11
then
12
13-
Norb=`grep "Number of basis functions" $1 | awk '{print $6}'`
13+
Norb=`grep "Basis Dimension" $1 | awk '{print $5}'`
14
Norb0=`echo ${Norb}-1 | bc`
15
Norb0_2=`echo ${Norb0}+2 | bc`
16
17
echo "function gauss(a,b,c,x){" > gauss_uks_o.awk
18
echo "  return a*exp(-(x-b)**2/(2*c))/sqrt(3.1415926535897932*2*c)" >> gauss_uks_o.awk
19
echo "}" >> gauss_uks_o.awk
20
echo "{" >> gauss_uks_o.awk
21
echo "          for (i=x0;i<=x1;i+=0.01)" >> gauss_uks_o.awk
22
echo "                  print i\"    \"gauss(\$1,\$2,w,i)" >> gauss_uks_o.awk
23
echo "}" >> gauss_uks_o.awk
24
25
echo "Give me threshold for electron energy in valence orbitals region [eV] (usually about -30eV is more than enough) and press [ENTER]:"
26
read Emin
27
28
grep -A${Norb0_2} "SPIN UP ORBITALS" $1 | tail -n${Norb} | awk -v nl=${Emin} '{if (($4 >= nl) && ($2 > 0) ) print $2" "$4}' > ./$1_list_a.tmp
29
grep -A${Norb0_2} "SPIN DOWN ORBITALS" $1 | tail -n${Norb} | awk -v nl=${Emin} '{if (($4 >= nl) && ($2 > 0) ) print $2" "$4}' > ./$1_list_b.tmp
30
31
echo "Give me gaussian broadening [eV] and press [ENTER]:"
32
read Width
33
34
X0=`echo \(${Emin}-$Width*5\)/1-1 | bc`
35
X1=`tail -n1 ./$1_list_a.tmp | awk '{print $2}'`
36
X2=`tail -n1 ./$1_list_b.tmp | awk '{print $2}'`
37
[[ `echo ${X1}\>${X2}| bc` == 1 ]] && X1=$X1 || X1=$X2
38
X1=`echo ${X1}/1+1 | bc`
39
40
echo Occupied region start point X0=$X0
41
echo Occupied region end point X1=$X1
42
43
awk -f gauss_uks_o.awk -v w=${Width} x0=${X0} x1=${X1} ./$1_list_a.tmp > ./$1_unsorted_a.tmp 2>/dev/null
44
awk -f gauss_uks_o.awk -v w=${Width} x0=${X0} x1=${X1} ./$1_list_b.tmp > ./$1_unsorted_b.tmp 2>/dev/null
45
awk '{a[$1]+=$2}; END{for (i in a) print i"    "a[i]}' ./$1_unsorted_a.tmp | LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 sort -g > ./$1.occ_a.txt
46
awk '{a[$1]+=$2}; END{for (i in a) print i"    "a[i]}' ./$1_unsorted_b.tmp | LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 sort -g > ./$1.occ_b.txt
47
echo "Results for occupied states (spin up) should be in file $1.occ_a.txt"
48
echo "Results for occupied states (spin down) should be in file $1.occ_b.txt"
49
join ./$1.occ_a.txt ./$1.occ_b.txt | awk '{print $1"    "$2+$3}' > ./$1.occ.txt
50
echo "Results for occupied states (both spin channels) should be in file $1.occ.txt"
51
52
echo "Give me threshhold for electron energy in free orbitals region [eV] (usually about 5eV is more than enough) and press [ENTER]:"
53
read Emax
54
55
grep -A${Norb0_2} "SPIN UP ORBITALS" $1 | tail -n${Norb} | awk -v nl=${Emax} '{if (($4 <= nl) && ( $2 < 1)) print $2" "$4}' > ./$1_list_a.tmp
56
grep -A${Norb0_2} "SPIN DOWN ORBITALS" $1 | tail -n${Norb} | awk -v nl=${Emax} '{if (($4 <= nl) && ( $2 < 1)) print $2" "$4}' > ./$1_list_b.tmp
57
58
cp gauss_uks_o.awk gauss_uks_f.awk
59
sed -i 's/\$1/1/g' gauss_uks_f.awk
60
61
X0=`head -n1 ./$1_list_a.tmp | awk '{print $2}'`
62
X2=`head -n1 ./$1_list_b.tmp | awk '{print $2}'`
63
[[ `echo ${X0}\<${X2}| bc` == 1 ]] && X0=$X0 || X0=$X2
64
X0=`echo ${X0}/1-2 | bc`
65
X1=`echo ${Emax}/1+1 | bc`
66
echo Free region start point X0=$X0
67
echo Free region end point X1=$X1
68
69
awk -f gauss_uks_f.awk -v w=${Width} x0=${X0} x1=${X1} ./$1_list_a.tmp > ./$1_unsorted_a.tmp 2>/dev/null
70
awk -f gauss_uks_f.awk -v w=${Width} x0=${X0} x1=${X1} ./$1_list_b.tmp > ./$1_unsorted_b.tmp 2>/dev/null
71
awk '{a[$1]+=$2}; END{for (i in a) print i"    "a[i]}' ./$1_unsorted_a.tmp | LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 sort -g > ./$1.free_a.txt
72
awk '{a[$1]+=$2}; END{for (i in a) print i"    "a[i]}' ./$1_unsorted_b.tmp | LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 sort -g > ./$1.free_b.txt
73
echo "Results for occupied states (spin up) should be in file $1.free_a.txt"
74
echo "Results for occupied states (spin down) should be in file $1.free_b.txt"
75
join ./$1.free_a.txt ./$1.free_b.txt | awk '{print $1"    "$2+$3}' > ./$1.free.txt
76
echo "Results for occupied states should be in file $1.free.txt"
77
78
rm ./$1_list_a.tmp
79
rm ./$1_list_b.tmp
80
rm ./$1_unsorted_a.tmp
81
rm ./$1_unsorted_b.tmp
82
83
else
84
echo Even number of electrons found, going restricted Kohm-Sham mode
85
86-
Norb=`grep "Number of basis functions" $1 | awk '{print $6}'`
86+
Norb=`grep "Basis Dimension" $1 | awk '{print $5}'`
87
Norb0=`echo ${Norb}-1 | bc`
88
Norb0_4=`echo ${Norb0}+4 | bc`
89
90
echo "function gauss(a,b,c,x){" > gauss_rks_o.awk
91
echo "	return a*exp(-(x-b)**2/(2*c))/sqrt(3.1415926535897932*2*c)" >> gauss_rks_o.awk
92
echo "}" >> gauss_rks_o.awk
93
echo "{" >> gauss_rks_o.awk
94
echo "		for (i=x0;i<=x1;i+=0.01)" >> gauss_rks_o.awk
95
echo "			print i\"    \"gauss(\$1,\$2,w,i)" >> gauss_rks_o.awk
96
echo "}" >> gauss_rks_o.awk
97
98
echo "Give me threshold for electron energy in valence orbitals region [eV] (usually about -30eV is more than enough) and press [ENTER]:"
99
read Emin
100
101
grep -A${Norb0_4} "ORBITAL ENERGIES" $1 | tail -n${Norb} | awk -v nl=${Emin} '{if (($4 >= nl) && ($2 > 0) ) print $2" "$4}' > ./$1_list.tmp
102
103
echo "Give me gaussian broadening [eV] and press [ENTER]:"
104
read Width
105
106
X0=`echo \(${Emin}-$Width*5\)/1-1 | bc`
107
X1=`tail -n1 ./$1_list.tmp | awk '{print $2}'`
108
X1=`echo ${X1}/1+1 | bc`
109
110
echo Occupied region start point X0=$X0
111
echo Occupied region end point X1=$X1
112
113
awk -f gauss_rks_o.awk -v w=${Width} x0=${X0} x1=${X1} ./$1_list.tmp > ./$1_unsorted.tmp 2>/dev/null
114
awk '{a[$1]+=$2}; END{for (i in a) print i"    "a[i]}' ./$1_unsorted.tmp | LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 sort -g > ./$1.occ.txt
115
echo "Results for occupied states should be in file $1.occ.txt"
116
117
echo "Give me threshhold for electron energy in free orbitals region [eV] (usually about 5eV is more than enough) and press [ENTER]:"
118
read Emax
119
120
grep -A${Norb0_4} "ORBITAL ENERGIES" $1 | tail -n${Norb} | awk -v nl=${Emax} '{if (($4 <= nl) && ( $2 < 1)) print $2" "$4}' > ./$1_list.tmp
121
122
cp gauss_rks_o.awk gauss_rks_f.awk
123
sed -i 's/\$1/2/g' gauss_rks_f.awk
124
125
X0=`head -n1 ./$1_list.tmp | awk '{print $2}'`
126
X0=`echo ${X0}/1-2 | bc`
127
X1=`echo ${Emax}/1+1 | bc`
128
echo Free region start point X0=$X0
129
echo Free region end point X1=$X1
130
131
awk -f gauss_rks_f.awk -v w=${Width} x0=${X0} x1=${X1} ./$1_list.tmp > ./$1_unsorted.tmp 2>/dev/null
132
awk '{a[$1]+=$2}; END{for (i in a) print i"    "a[i]}' ./$1_unsorted.tmp | LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 sort -g > ./$1.free.txt
133
echo "Results for occupied states should be in file $1.free.txt"
134
135
rm ./$1_list.tmp
136
rm ./$1_unsorted.tmp
137
fi