# script_anh.sh for computing the band gap at 300 K, 500 K and 700 K using anharmonic phonons
cd $PWD
QE=path_to_qe_bin

# set array with temperatures
array=(300 500 700)
for j in ${array[@]}
do
  # run ZG for each temperature using the corresponding T.00K_iter_01.fc file
  ibrun -n 1 $QE/ZG.x < ZG_"$j"K.in > ZG_"$j"K.out
  # run scf
  ibrun -n 48 $QE/pw.x -nk 8 < ZG-scf_222_"$j".00K.in > ZG-scf_222_"$j".00K.out
  # prepare nscf file
  file=ZG-nscf_222_"$j".00K
  cp ZG-scf_222_"$j".00K.in "$file".in
  sed -i 's/scf/nscf/g' "$file".in
  sed -i 's/-nscf/-scf/g' "$file".in
  sed -i 's/ecutwfc/nosym = .true., nbnd = 140, ecutwfc/g' "$file".in
  sed -i '/K_P/d' "$file".in
  sed -i '/3   3   3/d' "$file".in
  cat "$file".in Kpoints.txt > tmp
  mv tmp "$file".in
  # run nscf
  ibrun -n 48 $QE/pw.x < "$file".in > "$file".out
  rm *wfc* *.save/*wfc*
done
