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

# !! *** same procedure as in TM19_sol, now with polarized ff *** !!

# used TM19 created in moe, then sed chain name in pymol using 
#		alter (all),chain='A'
#		sort 
# then make martini topology: 
# ./martinize.py -f TM19_sed.pdb -o system_vaccum.top -x TM19_pol_CG.pdb -dssp /Applications/DSSP_MAC.EXE -p backbone -ff martini22p

# editconf -f TM19_pol_CG.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

#after minimization, rotate to align with z-axis membrane
editconf -f minimization_vaccum.gro -princ -o minimization_vaccum_rotate.gro -rotate 0 90 0 <<EOL
1
EOL

#and put into membrane
./insane.py -f minimization_vaccum_rotate.gro -o system.gro -pbc cubic -box 6.6,6.6,11 -l POPC:7 -l CHOL:3 -u POPC:7 -u CHOL:3 -center -sol PW

grompp -f minimization.mdp -c system.gro -p system.top -o minimization.tpr
mdrun -deffnm minimization -v -nt 4

#index file necessary to use as input with grompp, POPC_CHOL needs to be specified as one temperature coupling group, mdp files were modified accordingly
make_ndx -f system.gro -o index.ndx <<EOL
13 | 14
q
EOL

grompp -f equilibration.mdp -c minimization.gro -p system.top -o equilibration.tpr -n index.ndx -maxwarn 1
mdrun -deffnm equilibration -v -nt 4

grompp -f dynamic.mdp -c equilibration.gro -p system.top -o dynamic.tpr  -t equilibration.trr -n  index.ndx
mdrun -deffnm dynamic -v -nt 4


rm \#*
