#!/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=`POPCd`

#Config
NPROCS=2

#reduce trajectory size a bit for VMD (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
# see analysis_rdf.sh
#sh analysis_rdf.sh

#calculate minimal distance of water 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_POPC.xvg -av mindistres_POPC_av.xvg
g_analyze -f mindistres_POPC.xvg -dist mindistres_POPC_distr.xvg -bw 0.01

make_ndx -f equilibration.gro -o index_aa.ndx <<EOL
splitres 1
q
EOL

for i in {1..19}
do
j=$(($i + 14))
echo $j

g_rdf -s dynamic.tpr -f dynamic.xtc -o rdf_r${i}-POPC.xvg -n index_aa.ndx <<EOL
$j
13
EOL

done

rm \#*

rm \#*
