-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplot_dosband.sh
401 lines (344 loc) · 11.1 KB
/
plot_dosband.sh
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
#!/bin/bash
#################################################################################################################################################
# Band Structure and DOS plotter. #
# Author: Ahmad Abdolmaleki #
# Email: ahmadubuntu at gmail #
# web: https://github.com/ahmadubuntu/aims_DosBand #
# This shell script is provided to plot Density Of States (DOS) and Band Structure of materials from outputfiles of FHI-aims code. #
# #
# For this purpes you shuld use at list one line of "output band <start> <end> <npoints> <starting_point_name> <ending_point_name> " #
# or "output dos ..." or some of them in "control.in" input file of FHItaims. After running FHI-aims on this input file it gives #
# one band structructure file as "bandXXXX.out" for each "output band ..." line and two DOS file as "KS_DOS_total.dat" and #
# "KS_DOS_total_raw.dat" which we use "KS_DOS_total.dat" for DOS but for band structure, we use "aims_band_ploting.pl" in FHI-aims #
# utilities to merge those band files. Then, use this script to plot DOS and Band structure via xmgrace and save picture as "DosBand.png" #
# #
# #
# usage: #
# ./plot_dosband.sh [options] #
# #
# which options can be: #
# -jb =====> just plot band structure #
# -jd =====> just plot DOS #
# -bfile BANDFILE #
# -dfile DOSFILE #
# -erange EMIN EMAX #
# -t NUMBER =====> the ticks multiples #
# -s =====> spin
# -h =====> print this message #
# #
# for example: #
# ./plot_dosband.sh [-bfile band_structure.dat] [-dfile KS_DOS_total.dat] [-erange -10 10] [-t 5] #
# These are default options. #
# #
# #
#################################################################################################################################################
## default setting
bandfile="band_structure.dat"
bandupfile="band_structure_spin_up.dat"
banddownfile="band_structure_spin_down.dat"
dosfile="KS_DOS_total.dat"
emin="-10"
emax="10"
etick=$[(emax-emin)/5]
band="true"
dos="true"
spn="false"
################################################################################################################ FUNCTIONS
##################################################
function usage (){
echo "usage:" ;
echo " ./plot_dosband.sh [options]";
echo "";
echo "which options can be:" ;
echo " -jb =====> just plot band structure" ;
echo " -jd =====> just plot DOS";
echo " -bfile BANDFILE" ;
echo " -dfile DOSFILE" ;
echo " -erange EMIN EMAX" ;
echo " -t NUMBER" ;
echo " -s ====> if spin != none";
echo " -h ====> print this message" ;
echo "" ;
echo "for example:" ;
echo "./plot_dosband.sh [-bfile band_structure.dat] [-dfile KS_DOS_total.dat] [-erange -10 10] [-t 5]" ;
echo "These are default options."; exit ;
}
##################################################
function ghsnb (){
if [[ "$spn" == "false" ]]
then
## grep number of high symmetry points
nhsp=`grep "point for band" $bandfile | awk '{print $19}' | wc -l `
hs=`grep "point for band" $bandfile | awk '{print $19}'| head -1`
# find kPoint name
kname=`grep "point for band" $bandfile | awk '{print $7}' | sed -n "1p" `
elif [[ "$spn" == "true" ]]
then
## grep number of high symmetry points
nhsp=`grep "point for band" $bandupfile | awk '{print $19}' | wc -l `
hs=`grep "point for band" $bandupfile | awk '{print $19}'| head -1`
# find kPoint name
kname=`grep "point for band" $bandupfile | awk '{print $7}' | sed -n "1p" `
fi
rm -f hyskp.dat
cat > hyskp.dat<<EOF
${hs} -2000
${hs} 2000
EOF
echo "" >> hyskp.dat
echo $hs $kname > kp.dat
for i in `seq 2 2 $nhsp`
do
if [[ "$spn" == "false" ]]
then
hs=`grep "point for band" $bandfile | awk '{print $19}' | sed -n "${i}p" `
kname=`grep "point for band" $bandfile | awk '{print $7}' | sed -n "${i}p" `
elif [[ "$spn" == "true" ]]
then
hs=`grep "point for band" $bandupfile | awk '{print $19}' | sed -n "${i}p" `
kname=`grep "point for band" $bandupfile | awk '{print $7}' | sed -n "${i}p" `
fi
echo $hs $kname >> kp.dat
cat >> hyskp.dat<<EOF
${hs} -2000
${hs} 2000
EOF
echo "" >> hyskp.dat
done
#cat hyskp.dat
## find min and max in k_points
ki=`cat kp.dat | sort -n -k1 | head -1 | awk '{print $1}' `
kf=`cat kp.dat | sort -nr -k1 | head -1 | awk '{print $1}'`
## find number of bands
if [[ "$spn" == "false" ]]
then
nbands=`tail -n 1 $bandfile | awk '{print NF}'`
nbands=$[nbands-1]
elif [[ "$spn" == "true" ]]
then
nbands=`tail -n 1 $bandupfile | awk '{print NF}'`
nbands=$[nbands-1]
fi
## create Fermi level data
cat > ferb.dat <<EOF
$ki 0
$kf 0
EOF
}
##################################################
## check if BAND files exist
function chband (){
if [[ ! -f $bandfile ]] && [[ ! -f $bandupfile ]]
then
echo "ERROR:"
echo " $bandfile does not exist!"
echo ""
echo "Maybe you need to insert 'output band <start> <end> <npoints> <starting_point_name> <ending_point_name>' line in your control.in file and run FHI-aims again."
echo "for example:"
echo "output band 0.0 0.0 0.0 0.5 0.0 0.0 100 Gamma X"
exit
fi
}
##################################################
## check if DOS files exist
function chdos (){
if [[ ! -f $dosfile ]]
then
echo "ERROR:"
echo " $dosfile does not exist!"
echo ""
echo "Maybe you need to insert 'output dos ...' line in your control.in file and run FHI-aims again."
echo "for example:"
echo "output dos -20 10 400 0.05"
exit
fi
}
##################################################
function bandscript (){
cat > script.bat <<EOF
default linewidth 2.0
with g0
default linewidth 2.0
title size 1.500000
## title "BAND STRUCTURE "
xaxis label "K-points directions"
yaxis label "Energy (eV)"
world $ki, $emin, $kf, $emax
yaxis tick major $etick
frame linewidth 2.0
xaxis label char size 1.220000
yaxis label char size 1.220000
xaxis tick major linewidth 2.0
yaxis tick major linewidth 2.0
xaxis tick major grid on
xaxis tick minor linewidth 2.0
xaxis tick major linestyle 1
xaxis tick minor grid off
s0 line linestyle 3
s0 legend "Fermi level"
EOF
if [[ "$spn" == "true" ]]
then
echo 's1 legend "Up"' >> script.bat
echo 's2 legend "Down"' >> script.bat
fi
nkp=`cat kp.dat | wc -l`
echo " xaxis tick spec type both" >> script.bat
echo " xaxis tick spec $nkp" >> script.bat
for i in `seq 1 $nkp`
do
j=$[i-1]
hs=`cat kp.dat | sed -n "${i}p" | awk '{print $1}' `
kname=`cat kp.dat | sed -n "${i}p" | awk '{print $2}' `
echo " xaxis tick major $j, $hs " >> script.bat
if [[ $kname == "Gamma" ]]
then
echo " xaxis ticklabel $j, \"\xG\f{}\" " >> script.bat
else
echo " xaxis ticklabel $j, \"$kname\" " >> script.bat
fi
done
bb=$[nbands-1]
for i in `seq 0 $bb`
do
echo " s$i line linewidth 2.0 " >> script.bat
done
if [[ "$spn" == "false" ]]
then
for i in `seq 0 $bb`
do
echo " s$i line color 2 " >> script.bat
done
for i in `seq $[bb+1] $[bb*2]`
do
echo " s$i line color 4 " >> script.bat
done
else
for i in `seq 1 $[bb*4]`
do
if [ $[i%2] == 0 ]; then
echo " s$i line color 2 " >> script.bat
else
echo " s$i line color 4 " >> script.bat
fi
done
fi
}
##################################################
function dosscript (){
cat >> script.bat <<EOF
with g1
## title "Density Of State"
xaxis label "DOS"
world 0, $emin, $dmax, $emax
xaxis tick major 1
yaxis tick major $etick
yaxis ticklabel off
frame linewidth 2.0
xaxis label char size 1.220000
yaxis label char size 1.220000
s0 line linestyle 3
s1 line linewidth 2.0
EOF
cat >> ferd.dat <<EOF
0 0
$dmax 0
EOF
}
##################################################
function jdoscript (){
cat >> script.bat <<EOF
with g0
title "Density Of State"
yaxis label "DOS"
world $emin, 0, $emax, $dmax
xaxis tick major $etick
yaxis tick major 1
yaxis ticklabel on
frame linewidth 2.0
xaxis label char size 1.220000
yaxis label char size 1.220000
s0 line linestyle 3
s1 line linewidth 2.0
EOF
cat >> ferd.dat <<EOF
0 0
0 $dmax
EOF
}
##################################################
function xmprint (){
cat >> script.bat <<EOF
HARDCOPY DEVICE "PNG"
DEVICE "PNG" DPI 600
PAGE SIZE 1200,800
DEVICE "PNG" FONT ANTIALIASING on
##Make white background transparent
##DEVICE "PNG" OP "transparent:on"
##DEVICE "PNG" OP "compression:9"
PRINT TO "DosBand.png"
PRINT
EOF
}
##################################################
######################################################### main part
no=$#
i=1
while [[ $i -le $no ]]
do
# echo "optin $i = " ${!i}
case ${!i} in
"-jb" ) dos="false"; i=$[i+1] ;;
"-jd" ) band="false"; i=$[i+1] ;;
"-bfile" ) j=$[i+1]; bandfile=${!j} ; i=$[i+2] ;;
"-dfile" ) j=$[i+1]; dosfile=${!j} ; i=$[i+2] ;;
"-erange" ) j=$[i+1]; l=$[i+2]; emin=${!j} ; emax=${!l} ; i=$[i+3] ;;
"-t" ) j=$[i+1]; etick=${!j} ; i=$[i+2] ;;
"-s" ) spn="true"; i=$[i+1] ;;
"-d" ) debg="true"; i=$[i+1] ;;
"-h" ) usage ;;
* )
echo "ERROR: Wrong Optin!!! There is no '${!i}' in the options" ; usage ;;
esac
done
if [[ "$band" == "true" ]] && [[ "$spn" == "false" ]]
then
chband
ghsnb
bandscript
bp="-graph 0 -viewport 0.15 0.15 1.15 0.85 ferb.dat -nxy $bandfile"
elif [[ "$band" == "true" ]] && [[ "$spn" == "true" ]]
then
chband
ghsnb
bandscript
bp="-graph 0 -viewport 0.15 0.15 1.15 0.85 ferb.dat -nxy $bandupfile -nxy $banddownfile"
fi
if [[ "$dos" == "true" ]] && [[ "$spn" == "false" ]]
then
chdos
dmax=`sort -n -k2 $dosfile | tail -1 | awk '{print $2}'`
if [[ "$band" == "true" ]]
then
dosscript
dp="-graph 1 -viewport 1.2 0.15 1.4 0.85 ferd.dat -block $dosfile -bxy 2:1"
else
jdoscript
dp="-graph 0 -viewport 0.15 0.15 1.15 0.85 ferd.dat -block $dosfile -bxy 1:2"
fi
elif [[ "$dos" == "true" ]] && [[ "$spn" == "true" ]]
then
chdos
dmax=`sort -n -k2 $dosfile | tail -1 | awk '{print $2}'`
if [[ "$band" == "true" ]]
then
dosscript
dp="-graph 1 -viewport 1.2 0.15 1.4 0.85 ferd.dat -block $dosfile -bxy 2:1 -bxy 3:1"
else
jdoscript
dp="-graph 0 -viewport 0.15 0.15 1.15 0.85 ferd.dat -block $dosfile -bxy 1:2 -bxy 1:3"
fi
fi
xmprint
xmgrace -nosafe $bp $dp -batch script.bat
rm -f kp.dat script.bat hyskp.dat ferb.dat ferd.dat