#!/bin/bash
#
# Code by  venkentom@gmail.com
#
# Licenced by the GPL General Public License
# Have a look at:
# http://www.gnu.org/copyleft/gpl.html
# For more information about the GPL License
#
# I am not responsible for what this code does to your hw/sw/mind
# Use at your own risk
# 

#Put gromacs commands after this line

DIR=`pwd`

#Config
NPROCS=2

source /Home/ii/venken/.bashrc

for i in {100..100}
do

mkdir $i
cp system.top $i
cp *.itp $i
cp minimization.mdp $i
cp assemble.mdp $i #has been set to 100 ns!
cp genion.mdp $i
cp submit* $i #has been set to 100 ns!

genconf -f Tubby_CG.pdb -rot -o $i/genconf_${i}.gro

j=$[ RANDOM % 9 ]
k=$[ RANDOM % 9 ]
l=$[ RANDOM % 9 ]

cd $i
editconf -f genconf_${i}.gro -o editconf.gro -box 9 9 9 -translate $j $k $l -noc
genbox -cp editconf.gro -ci ../popc_single.gro -nmol 128 -try 500 -o genbox.gro

grompp -f minimization.mdp -c genbox.gro -p ../system_noW.top -maxwarn 10 -o min-init.tpr
mdrun -deffnm min-init -v 

genbox -cp min-init.gro -cs ../polarize-water.gro -o waterbox.gro -maxsol 1500 -vdwd 0.21

grompp -f genion.mdp -c waterbox.gro -p system.top -o system_neutral.tpr
genion -s system_neutral.tpr -o system_neutral.gro -p system.top -pname NA+ -nname CL- -neutral -conc 0.000001 << EOL
PW
EOL

make_ndx -f system_neutral.gro -o index.ndx <<EOL
18 | 19
q
EOL

grompp -f minimization.mdp -c system_neutral.gro -p system.top -maxwarn 10 -o min-solvent.tpr 
mdrun -deffnm min-solvent -v 

#grompp -f assemble.mdp -c min-solvent.gro -p system.top -maxwarn 10 -o assemble.tpr -n index.ndx 
#mdrun -deffnm assemble -v

rm \#*

cd ..

done


