# script.sh for computing phonons and band gap renormalization in diamond

cd $PWD
QE=path_to_qe_bin

wget http://www.pseudo-dojo.org/pseudos/nc-sr-04_pbesol_standard/C.upf.gz
gunzip C.upf.gz
 cp ../inputs/* .
# calculate the phonons 
 ibrun -np 4 $QE/pw.x -nk 4 < scf.in > scf.out
 cp ../inputs/ph.in .
 ibrun -np 4 $QE/ph.x -nk 4 < ph.in > ph.out
 cp ../inputs/q2r.in .
 ibrun -np 1 $QE/q2r.x < q2r.in > q2r.out
 ibrun -np 1 $QE/matdyn.x < matdyn.in > matdyn.out
 rm -rf _ph0
#
# band strcture for unit cell
 ibrun -np 4 $QE/pw.x -nk 4 < bands.in > bands.out
#
# generate ZG configurations for multiple temperatures
 ibrun -np 4 $QE/ZG.x -nk 4 < ZG_444_multi_T.in > ZG_444_multi_T.out
# 
# run scf calculations for equilibrium and ZG structures
 ibrun -np 54 $QE/pw.x -nk 3 < equil-scf_444.in > equil-scf_444.out
 declare -i j
 array=(0 50 100 150 200 250 300 350 400 600 800 1000)
 for j in ${array[@]}
 do
   ibrun -n 48 $QE/pw.x -nk 8 < ZG-scf_444_"$j".00K.in > ZG-scf_444_"$j".00K.out
 done

# prepare nscf files
 ./com.sh
 
# run nscf calculations for equilibrium and ZG structures
 ibrun -n 48 $QE/pw.x < equil-nscf_444.in > equil-nscf_444.out
#
 declare -i j
 array=(0 50 100 150 200 250 300 350 400 600 800 1000)
 for j in ${array[@]}
 do
   ibrun -n 48 $QE/pw.x < ZG-nscf_444_"$j".00K.in > ZG-nscf_444_"$j".00K.out
   rm *wfc* *.save/*wfc*
 done

# calculate the band gap
./com_av_gap.sh

#com.sh
#------
##!/bin/bash
## 
#cp equil-scf_444.in equil-nscf_444.in
#sed -i 's/scf/nscf/g' equil-nscf_444.in
#sed -i 's/-nscf/-scf/g' equil-nscf_444.in
#sed -i 's/ecutwfc/nosym = .true., nbnd = 320, ecutwfc/g' equil-nscf_444.in
#sed -i '/K_P/d' equil-nscf_444.in
#sed -i '/2   2   2/d' equil-nscf_444.in
##
#cat equil-nscf_444.in Kpoints.txt > tmp
#mv tmp equil-nscf_444.in
##
#declare -i i
#array=(0 50 100 150 200 250 300 400 600 800 1000)
#for i in ${array[@]}
#do
#  cp ZG-scf_444_"$i".00K.in ZG-nscf_444_"$i".00K.in
#done
##
#sed -i 's/scf/nscf/g' ZG-nscf_444_*
#sed -i 's/-nscf/-scf/g' ZG-nscf_444_*
#sed -i 's/ecutwfc/nosym = .true., nbnd = 320, ecutwfc/g' ZG-nscf_444_*
#sed -i '/K_P/d' ZG-nscf_444_*
#sed -i '/2   2   2/d' ZG-nscf_444_*
##
## Add k-point for the direct gap of diamond
#for i in ${array[@]}
#do
#  cat ZG-nscf_444_"$i".00K.in Kpoints.txt > tmp
#  mv tmp ZG-nscf_444_"$i".00K.in
#done

#com_av_gap.sh
#-------------
##!/bin/bash
## 
#cp equil-scf_444.in equil-nscf_444.in
#sed -i 's/scf/nscf/g' equil-nscf_444.in
#sed -i 's/-nscf/-scf/g' equil-nscf_444.in
#sed -i 's/ecutwfc/nosym = .true., nbnd = 320, ecutwfc/g' equil-nscf_444.in
#sed -i '/K_P/d' equil-nscf_444.in
#sed -i '/2   2   2/d' equil-nscf_444.in
##
#cat equil-nscf_444.in Kpoints.txt > tmp
#mv tmp equil-nscf_444.in
##
#declare -i i
#array=(0 50 100 150 200 250 300 400 600 800 1000)
#for i in ${array[@]}
#do
#  cp ZG-scf_444_"$i".00K.in ZG-nscf_444_"$i".00K.in
#done
##
#sed -i 's/scf/nscf/g' ZG-nscf_444_*
#sed -i 's/-nscf/-scf/g' ZG-nscf_444_*
#sed -i 's/ecutwfc/nosym = .true., nbnd = 320, ecutwfc/g' ZG-nscf_444_*
#sed -i '/K_P/d' ZG-nscf_444_*
#sed -i '/2   2   2/d' ZG-nscf_444_*
##
## Add k-point for the direct gap of diamond
#for i in ${array[@]}
#do
#  cat ZG-nscf_444_"$i".00K.in Kpoints.txt > tmp
#  mv tmp ZG-nscf_444_"$i".00K.in
#done

