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

#For TM31C_cholpopc2, let's move the peptide a bit up, to see if the C-terminus stays in the membrane, in contrast to TM31C_cholpopc!

#We made the previous system using this:
#./insane.py -f minimization_vaccum_rotate.gro -o system.gro -pbc optimal -box 6.6,6.6,11 -l POPC:7 -l CHOL:3 -u POPC:7 -u CHOL:3 -center -sol PW
# but this puts the peptide simply in the center of the box

#therefore first make the first make tpr file of our previous system
grompp -f minimization.mdp -c system.gro -p system.top -o minimization.tpr
#and then write out peptide conformation (gives error but writes out file anyway !)
trjconv -s minimization.tpr -f system.gro -o system_peptide.gro
#translate ze peptide
editconf -f system_peptide.gro -translate 0 0 2 -noc -o system_peptide_new.gro
#et voila, make new file (system_new.gro) using new coordinates for ze peptide in system_peptide_new.gro

#et do ze grompp again for minimization
grompp -f minimization.mdp -c system_new.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 \#*
