1#!/bin/sh
2
3###############################################################################
4##
5##  HIGH VERBOSITY EXAMPLE
6##
7###############################################################################
8
9# run from directory where this script is
10cd `echo $0 | sed 's/\(.*\)\/.*/\1/'` # extract pathname
11EXAMPLE_DIR=`pwd`
12
13# check whether echo has the -e option
14if test "`echo -e`" = "-e" ; then ECHO=echo ; else ECHO="echo -e" ; fi
15
16$ECHO
17$ECHO "$EXAMPLE_DIR : starting"
18$ECHO
19$ECHO "This example calculates the band structure of ferromagnetic bcc-Fe."
20$ECHO "in the noncollinear spin-orbit case."
21$ECHO
22
23# set the needed environment variables
24. ../../../environment_variables
25
26# required executables and pseudopotentials
27BIN_LIST="pw.x bands.x plotband.x"
28PSEUDO_LIST="Fe.rel-pbe-kjpaw.UPF"
29
30$ECHO
31$ECHO "  executables directory: $BIN_DIR"
32$ECHO "  pseudo directory:      $PSEUDO_DIR"
33$ECHO "  temporary directory:   $TMP_DIR"
34$ECHO "  checking that needed directories and files exist...\c"
35
36# check for directories
37for DIR in "$BIN_DIR" "$PSEUDO_DIR" ; do
38    if test ! -d $DIR ; then
39        $ECHO
40        $ECHO "ERROR: $DIR not existent or not a directory"
41        $ECHO "Aborting"
42        exit 1
43    fi
44done
45for DIR in "$TMP_DIR" "$EXAMPLE_DIR/results" ; do
46    if test ! -d $DIR ; then
47        mkdir $DIR
48    fi
49done
50cd $EXAMPLE_DIR/results
51
52# check for executables
53for FILE in $BIN_LIST ; do
54    if test ! -x $BIN_DIR/$FILE ; then
55        $ECHO
56        $ECHO "ERROR: $BIN_DIR/$FILE not existent or not executable"
57        $ECHO "Aborting"
58        exit 1
59    fi
60done
61
62# check for gnuplot
63GP_COMMAND=`which gnuplot 2>/dev/null`
64if [ "$GP_COMMAND" = "" ]; then
65        $ECHO
66        $ECHO "gnuplot not in PATH"
67        $ECHO "Results will not be plotted"
68fi
69
70
71# check for pseudopotentials
72for FILE in $PSEUDO_LIST ; do
73    if test ! -r $PSEUDO_DIR/$FILE ; then
74       $ECHO
75       $ECHO "Downloading $FILE to $PSEUDO_DIR...\c"
76            $WGET $PSEUDO_DIR/$FILE $NETWORK_PSEUDO/$FILE 2> /dev/null
77    fi
78    if test $? != 0; then
79        $ECHO
80        $ECHO "ERROR: $PSEUDO_DIR/$FILE not existent or not readable"
81        $ECHO "Aborting"
82        exit 1
83    fi
84done
85$ECHO " done"
86
87# how to run executables
88PW_COMMAND="$PARA_PREFIX $BIN_DIR/pw.x $PARA_POSTFIX"
89BAND_COMMAND="$PARA_PREFIX $BIN_DIR/bands.x $PARA_POSTFIX"
90PLOTBAND_COMMAND="$BIN_DIR/plotband.x"
91$ECHO
92$ECHO "  running pw.x     as: $PW_COMMAND"
93$ECHO "  running bands.x  as: $BAND_COMMAND"
94$ECHO "  running plotband.x  as: $PLOTBAND_COMMAND"
95$ECHO
96
97# self-consistent calculation for bcc-Fe with fully relativistic PAW-PP
98cat > Fe.scf_pbe.in << EOF
99 &control
100    calculation = 'scf'
101    prefix='Fe',
102    pseudo_dir = '$PSEUDO_DIR/',
103    outdir='$TMP_DIR/'
104 /
105 &system    
106    ibrav=  3, 
107    celldm(1) =5.42, 
108    nat=  1, 
109    ntyp= 1,
110    nr1=27,
111    nr2=27,
112    nr3=27,
113    noncolin=.true.
114    lspinorb=.true.
115    starting_magnetization(1)=0.5,
116    occupations='smearing',
117    smearing='mv',
118    degauss=0.04,
119    ecutwfc =45.0, 
120    ecutrho =300.0
121 /
122 &electrons
123    conv_thr =  1.0d-10
124 /
125ATOMIC_SPECIES
126Fe  0.0    Fe.rel-pbe-kjpaw.UPF
127ATOMIC_POSITIONS alat
128Fe  0.0000000   0.00000000   0.0  
129K_POINTS AUTOMATIC
1308 8 8 1 1 1 
131EOF
132$ECHO "  running the scf calculation for Fe with PAW spin-orbit...\c"
133$PW_COMMAND < Fe.scf_pbe.in > Fe.scf_pbe.out
134check_failure $?
135$ECHO " done"
136
137# self-consistent calculation for bcc-Fe with fully relativistic PAW-PP
138cat > Fe.band_pbe.in << EOF
139 &control
140    calculation = 'bands'
141    prefix='Fe',
142    point_label_type='BI'
143    pseudo_dir = '$PSEUDO_DIR/',
144    outdir='$TMP_DIR/'
145 /
146 &system    
147    ibrav=  3, 
148    celldm(1) =5.42, 
149    nat=  1, 
150    ntyp= 1,
151    nr1=27,
152    nr2=27,
153    nr3=27,
154    noncolin=.true.
155    lspinorb=.true.
156    starting_magnetization(1)=0.5,
157    occupations='smearing',
158    smearing='mv',
159    degauss=0.04,
160    ecutwfc =45.0, 
161    ecutrho =300.0
162 /
163 &electrons
164    conv_thr =  1.0d-10
165    diagonalization = 'cg'
166 /
167ATOMIC_SPECIES
168Fe  0.0    Fe.rel-pbe-kjpaw.UPF
169ATOMIC_POSITIONS alat
170Fe  0.0000000   0.00000000   0.0  
171K_POINTS tpiba_b
1723
173H1  40
174gG  40
1750.0 0.0 1.0 1
176EOF
177$ECHO "  running the band calculation for Fe with PAW and spin-orbit...\c"
178$PW_COMMAND < Fe.band_pbe.in > Fe.band_pbe.out
179check_failure $?
180$ECHO " done"
181
182# self-consistent calculation for bcc-Fe with fully relativistic PAW-PP
183cat > Fe.bands.in << EOF
184 &bands
185    prefix='Fe',
186    outdir='$TMP_DIR/'
187    filband='fe.band'
188    lsym=.true.,
189 /
190EOF
191$ECHO "  checking band symmetry of bcc-Fe with PAW and spin-orbit...\c"
192$BAND_COMMAND < Fe.bands.in > Fe.bands.out
193check_failure $?
194$ECHO " done"
195
196cat > plotband.in << EOF
197fe.band
1980 50
199ciao
200EOF
201$ECHO "  Plotting the bands...\c"
202$PLOTBAND_COMMAND < plotband.in > plotband.out
203check_failure $?
204$ECHO " done"
205
206#
207#  if gnuplot was found, the results are plotted
208#
209if [ "$GP_COMMAND" = "" ]; then
210    break
211else
212cat > plot.gnu << EOF
213set encoding iso_8859_15
214set terminal postscript enhanced color "Helvetica" 24
215set output "fe.bands.ps"
216#
217set key off
218
219set xrange [0:2]
220set yrange [-.5:0.5]
221set arrow from 1,-0.5 to 1,0.5 nohead lw 2 lt -1 front
222set xzeroaxis lw 2 lt -1
223set border lw 2
224unset xtics
225set size 0.85,1.0
226set ylabel "Energy (eV)"
227set label "{/Symbol G}" at -.02,-0.535
228set label "{/Symbol G}" at 1.97,-0.535
229set label "(1,0,0) H (0,0,1)" at 1.0,-0.535 center
230set label " M//(0,0,1) " at 1.47,0.43
231set label " D_{4h} [C_{4h}] " at -0.12,0.535 font ",16"
232set label " D_{4h} [C_{4h}] " at  0.90,0.535 font ",16"
233set label " D_{4h} [C_{4h}] " at  1.82,0.535 font ",16"
234set label " C_{2v} [C_{s}] " at  0.4,0.535 font ",16"
235set label " D_{4} [C_{4}] " at  1.4,0.535 font ",16"
236set label " {/Symbol G}_4 " at 0.55,-0.45 font ",16" tc rgb "blue"
237set label " {/Symbol G}_3 " at 0.24,-0.45 font ",16" tc rgb "red"
238set label " {/Symbol G}_6 " at 1.08,-0.45 font ",16" tc rgb "black"
239set label " {/Symbol G}_7 " at 1.32,-0.45 font ",16" tc rgb "green"
240set label " {/Symbol G}_8 " at 1.2,-0.45 font ",16" tc rgb "blue"
241set label " {/Symbol G}_5 " at 1.62,-0.45 font ",16" tc rgb "red"
242ef=12.5628
243plot 'ciao.1.1' u (1.-\$1):(\$2-ef) w l lw 3   lt 1 lc rgb "red", 'ciao.1.2' u (1.-\$1):(\$2-ef) w l lw 3 lt 5 lc rgb "blue", 'ciao.2.1' u (3.-\$1):(\$2-ef) w l lw 3 lt 1 lc rgb "red", 'ciao.2.2' u (3.-\$1):(\$2-ef) w l lw 3 lt 4 lc rgb "black", 'ciao.2.3' u (3.-\$1):(\$2-ef) w l lw 3 lt 1 lc rgb "green", 'ciao.2.4' u (3.-\$1):(\$2-ef) w l lw 3 lt 5 lc rgb "blue"
244EOF
245$ECHO "  Writing the bands on file fe.bands.ps...\c"
246gnuplot plot.gnu
247check_failure $?
248$ECHO " done"
249fi
250
251$ECHO "  cleaning $TMP_DIR...\c"
252rm -rf $TMP_DIR/Fe.*
253$ECHO
254$ECHO "$EXAMPLE_DIR: done"
255