#!/bin/bash

for i in `ls mdp | sed 's/\.mdp//'`; do

mkdir ${i}

grompp -f mdp/${i}.mdp -c et.gro -p et.top -o ${i}/et_${i}.tpr
mdrun_d -deffnm ${i}/et_${i} -v -nt 1

trjconv -f ${i}/et_${i}.trr -s ${i}/et_${i}.tpr -o ${i}/et_${i}.pdb

echo -e "Bond\nKinetic-En.\n0" | g_energy -f ${i}/et_${i}.edr -o ${i}/et_${i}_en.xvg > ${i}/et_${i}.txt


echo "set datafile commentschars '#@&' 
set term 'png'
set output '${i}/en_${i}.png'
set pointsize 0.5
plot '${i}/et_${i}_en.xvg' using 1:2,  '${i}/et_${i}_en.xvg' using 1:3
" > ${i}/gnu_${i}.gnu

cat ${i}/gnu_${i}.gnu | gnuplot

g_bond -f ${i}/et_${i}.trr -s ${i}/et_${i}.tpr -o ${i}/bond_${i}.xvg -n b.ndx 

echo "set datafile commentschars '#@&' 
set term 'png'
set output '${i}/bond_${i}.png'
plot '${i}/bond_${i}.xvg'with boxes
" > ${i}/gnu_bond_${i}.gnu

cat ${i}/gnu_bond_${i}.gnu | gnuplot

ls -r ${i}/*.png >> image.list

done

montage +frame +shadow +label -tile 2x5 -geometry 640x480 `cat image.list` images.png