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

cd completed

rm -rf grofiles

mkdir grofiles
cp ../align_assembly.tcl grofiles

#IMPORTANT! When aligning  to center of mass, selecting POPC does not always work since sometimes the water is in the middle and POPC is at the outside, therefore the aligning to COM does not fix this. Therefore better to choose one atom of a lipid close to the center of the bilayer as reference point
make_ndx -f 00/assemble.gro -o grofiles/index.ndx <<EOL
a C5B & r20
q
EOL

for i in {00..99}
do

trjconv -s $i/assemble.tpr -f $i/assemble.gro -o grofiles/assemble_${i}.gro -center -pbc nojump <<EOL
1
0
EOL

trjconv -s $i/assemble.tpr -f grofiles/assemble_${i}.gro -o grofiles/assemble_${i}.pdb -center -pbc mol -n grofiles/index.ndx <<EOL
16
0
EOL

done

cd grofiles

j=1;
for i in *.pdb
do

printf "TITLE     Protein in a POPC bilayer t=   ${j}.00000\n" >> ${i}_out.pdb
printf "CRYST1   72.000   72.000   72.000  90.00  90.00  90.00 P 1           1\n" >> ${i}_out.pdb
printf "MODEL %4d\n" $j >> ${i}_out.pdb
grep ATOM $i >> ${i}_out.pdb
printf "ENDMDL\n" >> ${i}_out.pdb
j=`expr $j + 1`

done

cat *out.pdb > all.pdb
rm *out.pdb
rm *.gro

/net/orinoco/hkh041/vmd_latest_for_annesc/vmd -dispdev text -e align_assembly.tcl


