# script_mono_gap.sh for computing band gap renormalization of monomorphous CsPbBr3 
 
cd $PWD 
QE=/path_to/q-e/

# generate ZG configurations of the monomorphous structure for multiple temperatures 
# using anharmonic phonons at 450 K
ibrun -np 4 $QE/ZG.x -nk 4 < ZG_multi_T.in > ZG_multi_T.out

# static-equilibrium and ZG configurations of the monomorphous structure
# scf calculations 
ibrun -np 48 $QE/pw.x -nk 8 < equil-scf_222.in > equil-scf_222.out
rm *save/*wfc*
array=(430 450 470 500)
for j in ${array[@]}
do
  ibrun -np 48 $QE/pw.x -nk 8 < ZG-scf_222_"$j".00K.in > ZG-scf_222_"$j".00K.out
  rm ZG-"$j".00K-scf.save/*wfc*
  rm ZG-"$j".00K-scf.save/*upf
done
#
# copy inputs and prepare ncsf files 
cp ../inputs/Kpoints.txt .
cp ../inputs/mono.sh .
./mono.sh

# nscf calculations
ibrun -np 48 $QE/pw.x < equil-nscf_222.in > equil-nscf_222.out
rm *save/*wfc*
mono_gap=$(grep highest equil-nscf_222.out | awk '{print $8-$7}')
echo $mono_gap > mono_gap.dat
#
array=(430 450 470 500)
for j in ${array[@]}
do
  ibrun -np 48 $QE/pw.x  < ZG-nscf_222_"$j".00K.in > ZG-nscf_222_"$j".00K.out
  rm ZG-"$j".00K-scf.save/*wfc*
  rm ZG-"$j".00K-scf.save/*upf
  rm *wfc*
done
# calculate the band gap renormalization from nscf files
grep highest ZG-nscf_222_*.out > tmp
awk '{print $1, $8, $9, $9-$8-'$mono_gap'}' tmp | sed 's/ZG-nscf_222_//g' | sed 's/K.out://g' > Renorm_mono_T.dat

exit
