#!/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

# not possible to automatically create TM19 containing protonated aspartate using martinize.py, so manual procedure needed
# starting from TM19 -> convert into TM19_C14 using moe (parameters of cys are quite close to asp0)
# then sed chain name in pymol using 
#		alter (all),chain='A'
#		sort 
# then make martini topology: 
./martinize.py -f TM19_C14_sed.pdb -o system_vaccum.top -x TM19_C14_pol_CG.pdb -dssp /Applications/DSSP_MAC.EXE -p backbone -ff martini22p

#manually adapt TM19_C14_pol_CG.pdb into TM19_D0.pdb and change Protein_A.itp!

#editconf -f TM19_D0.pdb -o editconf.pdb -bt cubic -d 1 -c

#change martini.itp to #include "martini_v2.2.itp" in system_vaccum.top
#grompp -f minimization_vaccum.mdp -p system_vaccum.top -c editconf.pdb -o minimization_vaccum.tpr -maxwarn 1
#mdrun -deffnm minimization_vaccum -v

editconf -f TM19_D0.pdb -o editconf.gro -box 9 9 9
genbox -cp editconf.gro -ci popc_single.gro -nmol 128 -try 500 -o genbox.gro

grompp -f minimization.mdp -c genbox.gro -p system.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

#due to protonated asp, neutralization needed!!
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
#add #include "martini_v2.0_ions.itp" to system.top!

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

make_ndx -f system_neutral.gro -o index.ndx <<EOL
1 | 18
name 22 Protein
del 1
19 | 20
q
EOL

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

rm \#*
