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

#reduce trajectory size a bit (dt of 1000 -> 1 ns, equals 5000 frames)
trjconv -s dynamic.tpr -f dynamic.xtc -pbc mol -ur compact -o dynamic_pbc.xtc -dt 1000 -center -n index.ndx <<EOL
21
0
EOL

#create index file for Asp residue
#make_ndx -f equilibration.gro -o index.ndx <<EOL
#r14
#q
#EOL

#calculate rdf profile of water molecules near the Asp residue
g_rdf -s dynamic.tpr -f dynamic_pbc.xtc -o rdf.xvg -n index.ndx <<EOL
13
15
EOL
#15: r14
#14: PW

#calculate minimal distance of water molecules near all protein residues
g_mindist -s dynamic.tpr -f dynamic_pbc.xtc -od mindist_PW.xvg -on mindistnum_PW.xvg -or mindistres_PW.xvg -printresname -respertime -tu us -n index.ndx <<EOL
21
14 
EOL
#14 = PW
#printresname?

g_analyze -f mindistres_PW.xvg -av
g_analyze -f mindistres_PW.xvg -dist mindistres_PW_distr.xvg -bw 0.01

#xmgrace -nxy 

#create index file to calculate the tilt of the peptide in the membrane
make_ndx -f equilibration.gro -n index.ndx -o index_bundle.ndx <<EOL
r1-4
r16-19
q
EOL

#and then calculate the tilt using g_bundle
g_bundle -s equilibration.gro -f dynamic_pbc.xtc -z -na 1 -n index_bundle.ndx -ot bundle.xvg <<EOL
r_1-4
r_16-19
EOL

g_analyze -f bundle.xvg -bw 0.2 -dist bundle_distr.xvg


rm \#*
