#!/bin/sh

. ../../../../environment_5

rm -f $TMP_DIR/*

cat > Si.scf.in << EOF
Rubdium
Rb
&control
    calculation='scf'
    restart_mode='from_scratch',
    pseudo_dir = '$PSEUDO_DIR/',
    prefix='Si',
    outdir='$TMP_DIR/',
    tstress=.true.,
    tprnfor=.true.
/
&system
    ibrav= 4, celldm(1) =4.7599,celldm(3)=0.9365
    nat=  1, ntyp= 1,
    ecutwfc =45.0,ecutrho=600.,
    occupations='smearing', smearing='methfessel-paxton', degauss=0.05
/
&electrons
    conv_thr =  1.0d-9
    mixing_beta= 0.7
/
ATOMIC_SPECIES
Si 28.0855 Si.vbc.UPF
ATOMIC_POSITIONS
Si 0.00 0.00 0.00
K_POINTS {automatic}
16 16 16    0 0 0
EOF

$PARA_PREFIX $PW_ROOT/bin/pw.x $PARA_POSTFIX < Si.scf.in > Si.scf.out

ic=0

for qvec in \
     '0.49999999     0.28868359     0.00000000' ;
do

ic=`expr $ic + 1`


#
# non self-consistent calculation
#


{
cat << EOF
CsI
CsI_cmca
&control
    calculation='phonon'
    restart_mode='from_scratch',
    pseudo_dir = '$PSEUDO_DIR',
    outdir='$TMP_DIR/',
    prefix='Si'
/
&system
    ibrav= 4, celldm(1) =4.7599,celldm(3)=0.9365
    nat=  1, ntyp= 1,
    ecutwfc =45.0,ecutrho=600.,
    occupations='smearing', smearing='methfessel-paxton', degauss=0.05
/
&electrons
    conv_thr =  1.0d-9
    mixing_beta= 0.7
/
&phonon
EOF
echo "$qvec" | tr -s ' ' | tr ' ' '\12' | awk '{ printf "xqq(%d)=%s", NR, $1 
; if (NR<3) { printf ", " ; } } END { printf "\n" ; }'
cat <<EOF
/
ATOMIC_SPECIES
Si 28.0855 Si.vbc.UPF
ATOMIC_POSITIONS
Si 0.00 0.00 0.00
K_POINTS {automatic}
16 16 16    0 0 0
EOF
} > Si.nscf.in

$PARA_PREFIX $PW_ROOT/bin/pw.x $PARA_POSTFIX < Si.nscf.in > Si.nscf.out

#
# phonon calculation at X
#
cat > Si.ph.in << EOF
phonons of CsI
&inputph
  tr2_ph=1.0d-14,
  prefix='Si',
  amass(1)=28.0855,
  outdir='$TMP_DIR/',
  fildyn='Si_${ic}.dyn'
/
$qvec
EOF

$PARA_PREFIX $PW_ROOT/bin/ph.x $PARA_POSTFIX < Si.ph.in > Si.ph.out

done

exit 0

