#!/bin/bash
#SBATCH -J c17_scf
#SBATCH --nodes=1 --ntasks-per-node=40
#SBATCH -t 288:00:00
#SBATCH --mail-user=euanbassey@ucsb.edu
#SBATCH --mail-type=start,end

export JOB=c17_scf
cd $SLURM_SUBMIT_DIR

#   unlimit the stack size
ulimit -s unlimited

#   What node are we running on?
echo $SLURM_JOB_NODELIST

#   Directory stuff- may be useful if we have to use /scratch
export DIR=$SLURM_SUBMIT_DIR
echo "submit directory: "
echo $SLURM_SUBMIT_DIR

#   Load the relevant modules
module purge
module load intel/18
module load openmpi/2.1.0
module load crystal17

echo "{\"status\": \"started spin-flip\"}" > status.json

#   Run the spin-locked job
mpirun -np $SLURM_NTASKS Pcrystal < INPUT >& out

#   Remove the unwanted files
rm fort.*.pe* dffit* diis* fort.79

# Copy useful files
cp fort.9 fort.20
cp INPUT spinflip_hyperfine.input
cp out spinflip_hyperfine.out

echo "{\"status\": \"completed spin-flip\"}" > status.json

# Transfer the properties.input script to INPUT
cp properties.input INPUT

echo "{\"status\": \"completed properties\"}" > status.json

# Run the properties extraction job
mpirun -np $SLURM_NTASKS Pproperties < INPUT >& out
