1#!/bin/sh
2
3# run from directory where this script is
4cd `echo $0 | sed 's/\(.*\)\/.*/\1/'` # extract pathname
5EXAMPLE_DIR=`pwd`
6
7# check whether ECHO has the -e option
8if test "`echo -e`" = "-e" ; then ECHO=echo ; else ECHO="echo -e" ; fi
9
10$ECHO
11$ECHO "$EXAMPLE_DIR : starting"
12$ECHO
13$ECHO "This example shows how to use the recover feature of ph.x for el-ph"
14
15# set the needed environment variables
16. ../../../environment_variables
17
18# required executables and pseudopotentials
19BIN_LIST="pw.x ph.x q2r.x matdyn.x"
20PSEUDO_LIST="Al.pz-vbc.UPF"
21
22$ECHO
23$ECHO "  executables directory: $BIN_DIR"
24$ECHO "  pseudo directory:      $PSEUDO_DIR"
25$ECHO "  temporary directory:   $TMP_DIR"
26$ECHO
27$ECHO "  checking that needed directories and files exist...\c"
28
29# check for gnuplot
30GP_COMMAND=`which gnuplot 2>/dev/null`
31if [ "$GP_COMMAND" = "" ]; then
32        $ECHO
33        $ECHO "gnuplot not in PATH"
34        $ECHO "Results will not be plotted"
35fi
36
37
38# check for directories
39for DIR in "$BIN_DIR" "$PSEUDO_DIR" ; do
40    if test ! -d $DIR ; then
41        $ECHO
42        $ECHO "ERROR: $DIR not existent or not a directory"
43        $ECHO "Aborting"
44        exit 1
45    fi
46done
47for DIR in "$TMP_DIR" "$EXAMPLE_DIR/results_1" ; do
48    if test ! -d $DIR ; then
49        mkdir $DIR
50    fi
51done
52cd $EXAMPLE_DIR/results_1
53
54# check for executables
55for FILE in $BIN_LIST ; do
56    if test ! -x $BIN_DIR/$FILE ; then
57        $ECHO
58        $ECHO "ERROR: $BIN_DIR/$FILE not existent or not executable"
59        $ECHO "Aborting"
60        exit 1
61    fi
62done
63
64# check for pseudopotentials
65for FILE in $PSEUDO_LIST ; do
66    if test ! -r $PSEUDO_DIR/$FILE ; then
67       $ECHO
68       $ECHO "Downloading $FILE to $PSEUDO_DIR...\c"
69            $WGET $PSEUDO_DIR/$FILE $NETWORK_PSEUDO/$FILE 2> /dev/null
70    fi
71    if test $? != 0; then
72        $ECHO
73        $ECHO "ERROR: $PSEUDO_DIR/$FILE not existent or not readable"
74        $ECHO "Aborting"
75        exit 1
76    fi
77done
78$ECHO " done"
79
80# how to run executables
81PW_COMMAND="$PARA_PREFIX $BIN_DIR/pw.x $PARA_POSTFIX"
82PH_COMMAND="$PARA_PREFIX $BIN_DIR/ph.x $PARA_POSTFIX"
83Q2R_COMMAND="$PARA_PREFIX $BIN_DIR/q2r.x $PARA_POSTFIX"
84MATDYN_COMMAND="$PARA_PREFIX $BIN_DIR/matdyn.x $PARA_POSTFIX"
85$ECHO
86$ECHO "  running pw.x as:     $PW_COMMAND"
87$ECHO "  running ph.x as:     $PH_COMMAND"
88$ECHO "  running q2r.x as:    $Q2R_COMMAND"
89$ECHO "  running matdyn.x as: $MATDYN_COMMAND"
90$ECHO
91
92
93# clean TMP_DIR
94$ECHO "  cleaning $TMP_DIR...\c"
95rm -rf $TMP_DIR/aluminum*
96rm -rf $TMP_DIR/_ph0/aluminum*
97$ECHO " done"
98$ECHO
99
100#
101# SCF at dense k-mesh, good enough for electronic DOS
102#
103PREFIX='aluminum'
104cat > al.scf.fit.in << EOF
105 &control
106    calculation='scf'
107    restart_mode='from_scratch',
108    prefix='$PREFIX',
109    pseudo_dir = '$PSEUDO_DIR/',
110    outdir='$TMP_DIR/'
111 /
112 &system
113    ibrav=  2, celldm(1) =7.5, nat= 1, ntyp= 1,
114    ecutwfc =15.0,
115    occupations='smearing', smearing='mv', degauss=0.05,
116    la2F = .true.,
117 /
118 &electrons
119    conv_thr =  1.0d-8
120    mixing_beta = 0.7
121 /
122ATOMIC_SPECIES
123 Al  26.98 Al.pz-vbc.UPF
124ATOMIC_POSITIONS alat
125 Al 0.00 0.00 0.00
126K_POINTS {automatic}
127 16 16 16  0 0 0
128EOF
129$ECHO "  running the scf calculation with dense k-point grid...\c"
130$PW_COMMAND  < al.scf.fit.in > al.scf.fit.out
131check_failure $?
132$ECHO "  done"
133#
134#  SCF at k-mesh good enough for phonons
135#
136cat > al.scf.in << EOF
137 &control
138    calculation='scf'
139    restart_mode='from_scratch',
140    prefix='$PREFIX',
141    pseudo_dir = '$PSEUDO_DIR/',
142    outdir='$TMP_DIR/'
143 /
144 &system
145    ibrav=  2, celldm(1) =7.5, nat= 1, ntyp= 1,
146    ecutwfc =15.0,
147    occupations='smearing', smearing='mv', degauss=0.05
148 /
149 &electrons
150    conv_thr =  1.0d-8
151    mixing_beta = 0.7
152 /
153ATOMIC_SPECIES
154 Al  26.98 Al.pz-vbc.UPF
155ATOMIC_POSITIONS alat
156 Al 0.00 0.00 0.00
157K_POINTS {automatic}
158 8 8 8  0 0 0
159EOF
160$ECHO "  running the scf calculation...\c"
161$PW_COMMAND < al.scf.in > al.scf.out
162check_failure $?
163$ECHO "  done"
164
165cat > al.elph.in << EOF
166Electron-phonon coefficients for Al
167 &inputph
168  tr2_ph=1.0d-10,
169  prefix='$PREFIX',
170  fildvscf='aldv',
171  amass(1)=26.98,
172  outdir='$TMP_DIR/',
173  fildyn='al.dyn',
174  electron_phonon='interpolated',
175  max_seconds=3,
176  el_ph_sigma=0.005, 
177  el_ph_nsigma=10,
178  trans=.true.,
179  ldisp=.true.
180  nq1=4, nq2=4, nq3=4
181 /
182EOF
183$ECHO "  running the electron-phonon calculation ...\c"
184$PH_COMMAND < al.elph.in > al.elph.out
185#
186cat > al.elph.in1 << EOF
187Electron-phonon coefficients for Al
188 &inputph
189  tr2_ph=1.0d-10,
190  prefix='$PREFIX',
191  fildvscf='aldv',
192  amass(1)=26.98,
193  outdir='$TMP_DIR/',
194  fildyn='al.dyn',
195  electron_phonon='interpolated',
196  el_ph_sigma=0.005, 
197  el_ph_nsigma=10,
198  recover=.true.,
199  trans=.true.,
200  ldisp=.true.
201  nq1=4, nq2=4, nq3=4
202 /
203EOF
204$ECHO "  recovering the electron phonon calculation ...\c"
205$PH_COMMAND < al.elph.in1 > al.elph.out1
206check_failure $?
207$ECHO "  done"
208#
209
210cat > q2r.in << EOF
211 &input
212  zasr='simple',  fildyn='al.dyn', flfrc='Al444.fc', la2F=.true.
213 /
214EOF
215$ECHO "  running q2r...\c"
216$Q2R_COMMAND < q2r.in > q2r.out
217check_failure $?
218$ECHO "  done"
219#
220cat > matdyn.in.dos << EOF
221 &input
222    asr='simple',  amass(1)=26.98,
223    flfrc='Al444.fc', flfrq='Al444.freq', la2F=.true., dos=.true.
224    fldos='phonon.dos', nk1=10, nk2=10, nk3=10, ndos=50
225 /
226EOF
227$ECHO "  running matdyn for a2F(omega) calculation...\c"
228$MATDYN_COMMAND < matdyn.in.dos > matdyn.out.dos
229check_failure $?
230$ECHO "  done"
231
232$ECHO
233$ECHO "$EXAMPLE_DIR: done"
234
235