#!/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 {2..200}
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 TM31C_CG.pdb -rot -o $i/genconf_${i}.gro

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

cd $i
editconf -f genconf_${i}.gro -o editconf.gro -box 10 10 10 -translate $j $k $l -noc
genbox -cp editconf.gro -ci ../popc_single.gro -nmol 134 -try 500 -o genbox_popc.gro
genbox -cp genbox_popc.gro -ci ../chol_single.gro -nmol 58 -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 ../water.gro -o waterbox.gro -maxsol 2250 -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
W
EOL

make_ndx -f system_neutral.gro -o index.ndx <<EOL
13 | 14
15 | 16
name 22 Membrane
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 -rdd 2

rm \#*

cd ..

done


