]> www.hackdaworld.org Git - physik/posic.git/blob - vasp_tools/get_ks_levels
deleted config file (as a test)
[physik/posic.git] / vasp_tools / get_ks_levels
1 #!/bin/bash
2
3 # get the kohn sham levels (plotted nicely)
4
5 # spin component 1
6
7 file=$1/OUTCAR
8
9 WUP=1.2
10 WDOWN=1.8
11 PS=2
12 OPT=7
13 UPT=4
14
15 if [ ! -f $file ]; then
16         echo "no OUTCAR file found ..."
17         exit
18 fi
19
20 rm -f $1/ks_levels_*
21
22 center="0"
23
24 cntup=0
25 echo $cntup > $1/temp_cu
26 fup=0
27 echo $fup > $1/temp_fu
28 cntdown=0
29 echo $cntdown > $1/temp_cd
30 fdown=0
31 echo $fdown > $1/temp_fd
32
33 # spin component 1
34 startline=`grep -n spin\ component\ 1 $file | tail -1 | awk -F: '{ print $1 }'`
35 echo -en "spin component 1 ($startline)... "
36 sed -n "$startline,/spin component 2/p" $file | grep ^' '*[0-9] | \
37         while read number energy occu; do
38                 if [ "$occu" = "1.00000" ]; then
39                 echo "0.18 $energy 0.1" >> $1/ks_levels_o
40                 cntup=`cat $1/temp_cu`
41                 ((cntup+=1))
42                 echo $cntup > $1/temp_cu
43                 elif [ "$occu" = "0.00000" ]; then
44                 echo "0.18 $energy 0.1" >> $1/ks_levels_u
45                 else
46                 echo "0.18 $energy 0.1" >> $1/ks_levels_p
47                 fup=`cat $1/temp_fu`
48                 fup=`echo $fup $occu | awk '{ print $1+$2 }'`
49                 echo $fup > $1/temp_fu
50                 fi
51         done
52 echo "done"
53
54 # spin component 2
55 startline=`grep -n spin\ component\ 2 $file | tail -1 | awk -F: '{ print $1 }'`
56 echo -en "spin component 2 ($startline) ... "
57 sed -n "$startline,/---/p" $file | grep ^' '*[0-9] | \
58         while read number energy occu; do
59                 if [ "$occu" = "1.00000" ]; then
60                 echo "0.42 $energy 0.1" >> $1/ks_levels_o
61                 cntdown=`cat $1/temp_cd`
62                 ((cntdown+=1))
63                 echo $cntdown > $1/temp_cd
64                 elif [ "$occu" = "0.00000" ]; then
65                         if [ "$center" = "0" ]; then
66                                 echo -en "setting mid value -> $energy ... "
67                                 center=$energy
68                                 echo "$energy" > $1/temp_e
69                         fi
70                 echo "0.42 $energy 0.1" >> $1/ks_levels_u
71                 else
72                 echo "0.42 $energy 0.1" >> $1/ks_levels_p
73                 fdown=`cat $1/temp_fd`
74                 fdown=`echo $fdown $occu | awk '{ print $1+$2 }'`
75                 echo $fdown > $1/temp_fd
76                 fi
77         done
78 echo "done"
79
80 cntup=`cat $1/temp_cu`
81 fup=`cat $1/temp_fu`
82 cntdown=`cat $1/temp_cd`
83 fdown=`cat $1/temp_fd`
84 center=`cat $1/temp_e`
85 yl=`echo $center $WDOWN | awk '{ print $1-$2 }'`
86 yh=`echo $center $WUP | awk '{ print $1+$2 }'`
87 fup=`awk -v var=$fup 'BEGIN{ printf"%0.f\n", var }'`
88 fdown=`awk -v var=$fdown 'BEGIN{ printf"%0.f\n", var }'`
89 ((cntup+=fup))
90 ((cntdown+=fdown))
91 ((difference=cntup-cntdown))
92 echo "generating gnuplot file ($center, $yl, $yh, $ly) ..."
93 cat > $1/ksl_plot.gpi <<!
94 plot "ks_levels_o" w xerrorbars pt $OPT ps $PS t "", "ks_levels_u" w xerrorbars pt $UPT ps $PS t "", "ks_levels_p" w xerrorbars pt $OPT ps $PS t ""
95 unset bars
96 set ylabel "Kohn-Sham levels [eV]"
97 set xrange [0:0.6]
98 set yrange [$yl:$yh]
99 set xlabel "Spin up / down"
100 set format x ""
101 set x2label "$cntup / $cntdown (Delta: $difference)"
102 unset xtics
103 set mytics 5
104 set size ratio 3.0
105 replot
106 set term epslatex standalone color solid size 3.5,7
107 set out "ksl.tex"
108 replot
109 !
110
111 cd $1
112
113 echo "running gnuplot and latex ..."
114 gnuplot ksl_plot.gpi
115 latex ksl
116 dvips ksl
117 gv ksl
118
119 cd ../..
120
121 echo "done"
122 echo "file: $1/ksl.ps"
123 echo