#!/bin/csh
#

# Generated by CHARMM-GUI (http://www.charmm-gui.org) v3.7
#
# All input files were optimized for AMBER16 or above, so lower version of AMBER can cause some errors.
# In this script, the parallel (MPI) version is commented out. Use this line for parallel execution instead
# (adjust for your MPI and the number of CPUs you want to use). Alternatively, if you have access to
# pmemd.cuda or are willing to use sander, you can replace "pmemd" with pmemd.cuda or sander and "pmemd.MPI"
# with pmemd.cuda.MPI or sander.MPI
#
# There is a known issue in current CHARMM-GUI AMBER inputs with "sander".
# If you are willing to use "sander" for your simulation, please remove "&end" line in all minimization / equilibration
# inputs.

set amber = sander
# set amber = "mpirun -np 4 pmemd.MPI"

set init = step3_input
set mini_prefix = step4.0_minimization
set equi_prefix = step4.1_equilibration
set prod_prefix = step5_production
set prod_step   = step5
set cur_folder = $PWD


# Minimization
# In the case that there is a problem during minimization using a pmemd.cuda, please try to use pmemd only for
# the minimization step.
if (-e "dihe.restraint") sed -e "s/FC/1.0/g" dihe.restraint > ${mini_prefix}.rest
${amber} -O -i ${mini_prefix}.mdin -p ${init}.parm7 -c ${init}.rst7 -o ${mini_prefix}.mdout -r ${mini_prefix}.rst7 -inf ${mini_prefix}.mdinfo -ref ${init}.rst7


# Equilibration
if (-e "dihe.restraint") sed -e "s/FC/1.0/g" dihe.restraint > ${equi_prefix}.rest
${amber} -O -i ${equi_prefix}.mdin -p ${init}.parm7 -c ${mini_prefix}.rst7 -o ${equi_prefix}.mdout -r ${equi_prefix}.rst7 -inf ${equi_prefix}.mdinfo -ref ${init}.rst7 -x ${equi_prefix}.nc


# Production
set cnt    = 1
set cntmax = 10

sed -i "s|\#cur_folder|${cur_folder}|" step5_production.mdin

while ( ${cnt} <= ${cntmax} )
    @ pcnt = ${cnt} - 1
    set istep = ${prod_step}_${cnt}
    set pstep = ${prod_step}_${pcnt}
    if ( ${cnt} == 1 ) set pstep = ${equi_prefix}

    ${amber} -O -i ${prod_prefix}.mdin -p ${init}.parm7 -c ${pstep}.rst7 -o ${istep}.mdout -r ${istep}.rst7 -inf ${istep}.mdinfo -x ${istep}.nc
    @ cnt += 1
end


