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 calculate the phonon dispersion on a GRID"
14$ECHO "for AlAs in zincblende structure. Both q-points and irreps are split."
15
16# set the needed environment variables
17. ../../../environment_variables
18
19# required executables and pseudopotentials
20BIN_LIST="pw.x ph.x q2r.x matdyn.x plotband.x"
21PSEUDO_LIST="Al.pz-vbc.UPF As.pz-bhs.UPF"
22
23$ECHO
24$ECHO "  executables directory: $BIN_DIR"
25$ECHO "  pseudo directory:      $PSEUDO_DIR"
26$ECHO "  temporary directory:   $TMP_DIR"
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# check for directories
38for DIR in "$BIN_DIR" "$PSEUDO_DIR" ; do
39    if test ! -d $DIR ; then
40        $ECHO
41        $ECHO "ERROR: $DIR not existent or not a directory"
42        $ECHO "Aborting"
43        exit 1
44    fi
45done
46for DIR in "$TMP_DIR" "$EXAMPLE_DIR/results_3" ; do
47    if test ! -d $DIR ; then
48        mkdir $DIR
49    fi
50done
51cd $EXAMPLE_DIR/results_3
52
53# check for executables
54for FILE in $BIN_LIST ; do
55    if test ! -x $BIN_DIR/$FILE ; then
56        $ECHO
57        $ECHO "ERROR: $BIN_DIR/$FILE not existent or not executable"
58        $ECHO "Aborting"
59        exit 1
60    fi
61done
62
63# check for pseudopotentials
64for FILE in $PSEUDO_LIST ; do
65    if test ! -r $PSEUDO_DIR/$FILE ; then
66       $ECHO
67       $ECHO "Downloading $FILE to $PSEUDO_DIR...\c"
68            $WGET $PSEUDO_DIR/$FILE $NETWORK_PSEUDO/$FILE 2> /dev/null
69    fi
70    if test $? != 0; then
71        $ECHO
72        $ECHO "ERROR: $PSEUDO_DIR/$FILE not existent or not readable"
73        $ECHO "Aborting"
74        exit 1
75    fi
76done
77$ECHO " done"
78
79# how to run executables
80PW_COMMAND="$PARA_PREFIX $BIN_DIR/pw.x $PARA_POSTFIX"
81PH_COMMAND="$PARA_PREFIX $BIN_DIR/ph.x $PARA_POSTFIX"
82Q2R_COMMAND="$PARA_PREFIX $BIN_DIR/q2r.x $PARA_POSTFIX"
83MATDYN_COMMAND="$PARA_PREFIX $BIN_DIR/matdyn.x $PARA_POSTFIX"
84PLOTBAND_COMMAND="$BIN_DIR/plotband.x"
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 "  running plotband.x as: $PLOTBAND_COMMAND"
91$ECHO "  running gnuplot as: $GP_COMMAND"
92$ECHO
93
94# clean TMP_DIR
95$ECHO "  cleaning $TMP_DIR...\c"
96rm -rf $TMP_DIR/alas*
97rm -rf $TMP_DIR/_ph0/alas*
98for q in `seq 1 8 ` ; do
99for irr in `seq 1 6` ; do
100rm -rf $TMP_DIR/$q.$irr
101done
102done
103$ECHO " done"
104
105PREFIX='alas'
106
107# self-consistent calculation
108cat > alas.scf.in << EOF
109 &control
110    calculation='scf'
111    restart_mode='from_scratch',
112    tstress = .true.
113    tprnfor = .true.
114    prefix='$PREFIX',
115    pseudo_dir = '$PSEUDO_DIR/',
116    outdir='$TMP_DIR/'
117    wf_collect=.true.
118 /
119 &system
120    ibrav=  2, celldm(1) =10.50, nat=  2, ntyp= 2,
121    ecutwfc =16.0
122 /
123 &electrons
124    conv_thr =  1.0d-8
125    mixing_beta = 0.7
126 /
127ATOMIC_SPECIES
128 Al  26.98  Al.pz-vbc.UPF
129 As  74.92  As.pz-bhs.UPF
130ATOMIC_POSITIONS (alat)
131 Al 0.00 0.00 0.00
132 As 0.25 0.25 0.25
133K_POINTS
134 2
135 0.25 0.25 0.25 1.0
136 0.25 0.25 0.75 3.0
137EOF
138$ECHO "  running the scf calculation...\c"
139$PW_COMMAND < alas.scf.in > alas.scf.out
140check_failure $?
141$ECHO " done"
142#
143# Initial calculation, only band structure. Note that here and in pw.x
144# you can use a different number of processors with respect to the
145# phonon calculation using the wf_collect=.true. flag.
146#
147cat > alas.ph.wfc.in << EOF
148phonons of AlAs
149 &inputph
150  tr2_ph=1.0d-12,
151  prefix='$PREFIX',
152  ldisp=.true.,
153  nq1=4, nq2=4, nq3=4
154  only_wfc=.true.,
155  lqdir=.true.,
156  outdir='$TMP_DIR/',
157  fildyn='$PREFIX.dyn.xml',
158 /
159EOF
160$ECHO "  running the band structure calculation ...\c"
161$PH_COMMAND < alas.ph.wfc.in > alas.ph.wfc.out
162check_failure $?
163$ECHO " done"
164#
165# Initial calculation, initial part of the dynamical matrix
166#
167cat > alas.ph.in0 << EOF
168phonons of AlAs
169 &inputph
170  tr2_ph=1.0d-12,
171  prefix='$PREFIX',
172  ldisp=.true.,
173  nq1=4, nq2=4, nq3=4
174  only_init=.true.,
175  recover=.true.
176  lqdir=.true.,
177  outdir='$TMP_DIR/',
178  fildyn='$PREFIX.dyn.xml',
179 /
180EOF
181$ECHO "  running the initialization phonon calculation ...\c"
182$PH_COMMAND < alas.ph.in0 > alas.ph.out0
183check_failure $?
184$ECHO " done"
185
186
187for q in `seq 1 8 ` ; do
188
189for irr in `seq 1 6` ; do
190
191cat > input.$q.$irr << EOF
192phonons of AlAs
193 &inputph
194  tr2_ph=1.0d-12,
195  prefix='$PREFIX',
196  ldisp=.true.,
197  lqdir=.true.,
198  nq1=4, nq2=4, nq3=4
199  start_q=$q
200  last_q=$q
201  start_irr=$irr
202  last_irr=$irr
203  recover=.true.,
204  low_directory_check=.true.
205  outdir="$TMP_DIR/$q.$irr",
206  fildyn='$PREFIX.dyn.xml',
207 /
208EOF
209
210mkdir -p $TMP_DIR/$q.$irr/_ph0/$PREFIX.q_$q
211mkdir -p $TMP_DIR/$q.$irr/_ph0/$PREFIX.phsave
212cp -r $TMP_DIR/$PREFIX.* $TMP_DIR/$q.$irr
213cp $TMP_DIR/_ph0/$PREFIX.phsave/* $TMP_DIR/$q.$irr/_ph0/$PREFIX.phsave
214if [ "$q" != "1" ]; then
215cp -r $TMP_DIR/_ph0/$PREFIX.q_$q/* $TMP_DIR/$q.$irr/_ph0/$PREFIX.q_$q
216fi
217
218$ECHO "  running the phonon calculation for q= " $q " irr=" $irr "...\c"
219$PH_COMMAND < input.$q.$irr > output.$q.$irr
220$ECHO " done"
221
222done
223done
224#
225#  Collecting all results in a single directory:
226#
227for q in `seq 1 8 ` ; do
228
229for irr in `seq 1 6` ; do
230
231\cp -f $TMP_DIR/$q.$irr/_ph0/$PREFIX.phsave/dynmat.$q.$irr.xml $TMP_DIR/_ph0/$PREFIX.phsave 2> /dev/null
232
233done
234#
235#  collect also the representation 0 (contribution to the dynamical
236#  matrix independent from the induced charge).
237#
238\cp -f $TMP_DIR/$q.1/_ph0/$PREFIX.phsave/dynmat.$q.0.xml $TMP_DIR/_ph0/$PREFIX.phsave 2> /dev/null
239
240done
241#
242# cp electric field part
243#
244\cp -f $TMP_DIR/1.1/_ph0/$PREFIX.phsave/tensors.xml $TMP_DIR/_ph0/$PREFIX.phsave
245#
246cat > alas.ph.in << EOF
247phonons of AlAs
248 &inputph
249  tr2_ph=1.0d-12,
250  prefix='$PREFIX',
251  ldisp=.true.,
252  nq1=4, nq2=4, nq3=4
253  recover=.true.,
254  outdir='$TMP_DIR/',
255  fildyn='$PREFIX.dyn.xml',
256 /
257EOF
258$ECHO "  running the phonon calculation to collect the results...\c"
259$PH_COMMAND < alas.ph.in > alas.ph.out
260check_failure $?
261$ECHO " done"
262
263cat > q2r.in <<EOF
264 &input
265   fildyn='$PREFIX.dyn.xml', zasr='simple', flfrc='$PREFIX.444.fc'
266 /
267EOF
268
269$ECHO "  transforming C(q) => C(R)...\c"
270mv $PREFIX.dyn0 $PREFIX.dyn0.xml
271$Q2R_COMMAND < q2r.in > q2r.out
272check_failure $?
273$ECHO " done"
274
275cat > matdyn.in <<EOF
276 &input
277    asr='simple',  amass(1)=26.98, amass(2)=74.922,
278    flfrc='$PREFIX.444.fc.xml', flfrq='$PREFIX.freq', q_in_band_form=.true.,
279 /
280 6
281  0.000 0.0 0.0   40
282  1.0   0.0 0.0   20
283  1.0   0.5 0.0   20
284  1.0   1.0 0.0   40
285  0.00  0.0 0.0   40
286  0.5   0.5 0.5    1
287EOF
288
289$ECHO "  recalculating omega(q) from C(R)...\c"
290$MATDYN_COMMAND < matdyn.in > matdyn.out
291check_failure $?
292$ECHO " done"
293
294cat > plotband.in <<EOF
295alas.freq
2960 600
297freq.plot
298freq.ps
2990.0
30050.0 0.1
301EOF
302
303$ECHO "  writing the phonon dispersions in freq.plot...\c"
304$PLOTBAND_COMMAND < plotband.in > /dev/null
305check_failure $?
306$ECHO " done"
307
308if [ "$GP_COMMAND" = "" ]; then
309    break
310else
311cat > gnuplot.tmp <<EOF
312set encoding iso_8859_15
313set terminal postscript enhanced solid color "Helvetica" 20
314set output "alas.dispersions.ps"
315#
316set key off
317
318set xrange [0:4.280239]
319dim=450
320set border front
321set yrange [0:dim]
322set arrow from 1,0. to 1,dim nohead  lw 2  front
323set arrow from 2,0. to 2,dim nohead  lw 2  front
324set arrow from 1.5,0. to 1.5,dim nohead  lw 2 front
325set arrow from 3.4142,0. to 3.4142,dim nohead  lw 2 front
326set ylabel "frequency (cm^{-1})"
327unset xtics
328lpos=-15
329set label "{/Symbol G}" at -0.05,lpos
330set label "X" at 0.95,lpos
331set label "W" at 1.45,lpos
332set label "X" at 1.95,lpos
333set label "{/Symbol G}" at 3.37,lpos
334set label "L" at 4.1897,lpos
335
336plot "freq.plot.1.1" u 1:2 w l lw 3 lt 1, \
337     "freq.plot.1.3" u 1:2 w l lw 3 lt 2, \
338     "freq.plot.2.1" u 1:2 w l lw 3 lt 1, \
339     "freq.plot.2.2" u 1:2 w l lw 3 lt 2, \
340     "freq.plot.3.1" u 1:2 w l lw 3 lt 1, \
341     "freq.plot.3.2" u 1:2 w l lw 3 lt 2, \
342     "freq.plot.4.1" u 1:2 w l lw 3 lt 1, \
343     "freq.plot.4.2" u 1:2 w l lw 3 lt 2, \
344     "freq.plot.5.1" u 1:2 w l lw 3 lt 1, \
345     "freq.plot.5.3" u 1:2 w l lw 3 lt 2
346EOF
347$ECHO "  creating the postscript file alas.dispersion.ps...\c"
348$GP_COMMAND gnuplot.tmp
349check_failure $?
350$ECHO " done"
351fi
352
353cat > phdos.in <<EOF
354 &input
355    asr='simple',  dos=.true. amass(1)=26.98, amass(2)=74.922,
356    flfrc='$PREFIX.444.fc.xml', fldos='$PREFIX.phdos', nk1=6,nk2=6,nk3=6
357 /
358EOF
359
360$ECHO "  calculating phonon DOS ...\c"
361$MATDYN_COMMAND < phdos.in > phdos.out
362check_failure $?
363$ECHO " done"
364
365if [ "$GP_COMMAND" = "" ]; then
366    break
367else
368cat > gnuplot1.tmp <<EOF
369set encoding iso_8859_15
370set terminal postscript enhanced solid color "Helvetica" 20
371set output "alas.phdos.ps"
372#
373set key off
374set xrange [0:450]
375set xlabel "frequency (cm^{-1})"
376set ylabel "DOS"
377plot 'alas.phdos' u 1:2 w l lw 3 
378EOF
379$ECHO "  generating plot of phonon_dos in the file alas.phdos.ps...\c"
380$GP_COMMAND  gnuplot1.tmp
381check_failure $?
382$ECHO " done"
383fi
384
385$ECHO
386$ECHO "$EXAMPLE_DIR: done"
387
388