#!/bin/bash

#PBS -N Sim2_88810
#PBS -q simulationq
#PBS -P external
#PBS -l select=1:ncpus=12:ngpus=1
#PBS -l walltime=96:00:00
#PBS -o process_out.txt
#PBS -e process_out.err
#PBS -joe

cd $PBS_O_WORKDIR

module load gromacs/gpu/2022.3

## Minimization
gmx grompp -f step4.0_minimization.mdp -o step4.0_minimization.tpr -c step3_input.gro -r step3_input.gro -p topol.top -maxwarn 1
gmx mdrun -v -deffnm step4.0_minimization 


# Equilibration
# step4.1
gmx grompp -f step4.1_equilibration.mdp -o step4.1_equilibration.tpr -c step4.0_minimization.gro -r step3_input.gro -p topol.top -maxwarn 1
gmx mdrun -v -deffnm step4.1_equilibration


# Production
cnt=1
cntmax=10

while [ ${cnt} -le ${cntmax} ]; do
    if [ ${cnt} -eq 1 ]; then
        gmx grompp -f step5_production.mdp -o step5_${cnt}.tpr -c step4.1_equilibration.gro -p topol.top -maxwarn 1
        
        gmx mdrun -v -deffnm step5_${cnt} -nb gpu -pme gpu -bonded gpu
    else
        pcnt=$((cnt - 1))
        
        gmx grompp -f step5_production.mdp -o step5_${cnt}.tpr -c step5_${pcnt}.gro -t step5_${pcnt}.cpt -p topol.top -maxwarn 1
        
        gmx mdrun -v -deffnm step5_${cnt} -nb gpu -pme gpu -bonded gpu
    fi
    cnt=$((cnt + 1))
done



