#!/bin/bash
#SBATCH -A workshop
#SBATCH --time=00:30:00
#SBATCH -N 1
#SBATCH -n 36
#SBATCH -p long
#SBATCH --qos normal

module load intel/PSXE2017 
module load mvapich2/2.1-intel 
module load Quantum_ESPRESSO/5.4

export OCEAN_BIN=/hpcgpfs01/work/workshop/ocean_tutorial/bin

mkdir -p CONV
cd CONV

rm -f k.txt
touch k.txt

# Loop over 2, 3, 4, 6, and 8
for k in  2 3 4 6 8
do
cp ../DFT/scf.in .
echo $k

# Replace the k-point settings in scf.in with the current loop
sed -i "s/3  3  3/$k  $k  $k/" scf.in


# The 2x2x2 grid only has 2 k-points, so I need to set npool down to 2
srun -n 32 $OCEAN_BIN/pw.x -npool 2 -inp scf.in > scf.k${k}.out

grep '!' scf.k${k}.out | awk "{print $k, \$5*13.605 }" >> k.txt

done


rm -f e.txt
touch e.txt

# now we loop over energy cutoff
for e in 40 60 80 100 120
do
cp ../DFT/scf.in .
echo $e
sed -i "s/ecutwfc = 100/ecutwfc = $e/" scf.in

# I know that a 3x3x3 gives 6 k-points, by looking at the scf.out from the ocean run
# Therefore I change the pools to 6 and the number of processors down to the 
# largest even multipule
srun -n 30 $OCEAN_BIN/pw.x -npool 6 -inp scf.in > scf.e${e}.out

grep '!' scf.e${e}.out | awk "{print $e, \$5*13.605 }" >> e.txt

done
