#!/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 <<EOL
1
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
16
15
EOL
#15: r14
#14: PW

#calculate minimal distance of CHOL molecules near all protein residues
g_mindist -s dynamic.tpr -f dynamic_pbc.xtc -od mindist_CHOL.xvg -on mindistnum_CHOL.xvg -or mindistres_CHOL.xvg -printresname -respertime -tu us <<EOL
1
14 
EOL

#calculate minimal distance of POPC molecules near all protein residues
g_mindist -s dynamic.tpr -f dynamic_pbc.xtc -od mindist_POPC.xvg -on mindistnum_POPC.xvg -or mindistres_POPC.xvg -printresname -respertime -tu us <<EOL
1
13 
EOL

g_analyze -f mindistres_CHOL.xvg -dist mindistres_CHOL_distr.xvg -bw 0.01
g_analyze -f mindistres_POPC.xvg -dist mindistres_POPC_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 -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.1 -dist bundle_distr.xvg


rm \#*
