# script_ASDM.sh for computing anharmonic phonons in PbTe
cd $PWD

QE=path_to_qe_bin


# Repeat the process for different temperature
# set temperature
T=500
cp ../inputs/ZG*in . 
cp ../inputs/matdyn*in . 
sed -i 's/AAA/'$T'/g' ZG*in
sed -i 's/AAA/'$T'/g' matdyn_*in

# first iteration only
ibrun -np 1 $QE/ZG.x < ZG_1.in > ZG_1.out

file=ZG-scf_"$T".00K_iter_01
mkdir fd_forces/
for i in {0001..0096}; do
  mkdir $i
  cd $i
  cp ../Pb.upf .
  cp ../Te.upf .
  mv ../"$file"_"$i".in .
## We have copied the "fd_forces" folder from inputs which includes all ASDM calculations.
## This is done for spead up purposes. Otherwise, calculate and copy forces files by 
## uncommenting the two lines below.
#  ibrun -np 56 $QE/pw.x -nk 14 < "$file"_"$i".in > "$file"_"$i".out
#  mv "$file"_"$i".out ../fd_forces/.
  rm Pb.upf Te.upf
  cd ../
done

ibrun -np 1 $QE/ZG.x < ZG_2.in > ZG_2.out
ibrun -np 1 $QE/matdyn.x < matdyn_01.in > matdyn_01.out
