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

mkdir depth

#make index file
make_ndx -f system.pdb -o index_aa_upper.ndx <<EOL
splitres 3
ri 20-72 & a P
q
EOL

#loop over all residues
for i in {01..19}
do
k=`echo $i|sed 's/^0*//'`
j=$(($k + 17))

echo $j

g_dist -s system.tpr -f prod_time.xtc -dt 0.001 -o dist_${j}.xvg -xvg none -n index_aa_upper.ndx <<EOL 
$j
r_20-72
EOL

done

pr -m -t -s\  dist_*.xvg | gawk '{print $1,$5,$10,$15,$20,$25,$30,$35,$40,$45,$50,$55,$60,$65,$70,$75,$80,$85,$90,$95}' > dist_all.xvg

g_analyze -f dist_all.xvg > dist_all_avg.txt

mv dist* depth
rm \#*


