#!/bin/bash
# simple analysis script for PG-titration into POPC assay 
# focus on the effect of the AMC peptidomimetic
#
# tool fatslim required


for f in pg*.tpr
do
  deffnm=${f%.tpr}
  [ ! -s ${deffnm}_boxx.xvg ]      && echo box-x | gmx energy -f ${deffnm}.edr -o ${deffnm}_boxx.xvg
  [ ! -s ${deffnm}_sk10_pbc.xtc ]  && echo Peptidomimetics+membrane | gmx trjconv -f ${deffnm}.xtc -s ${deffnm}.tpr -o ${deffnm}_sk10_pbc -pbc whole -skip 10 -n index.ndx 

  [ ! -s ${deffnm}_cpt.gro ]       &&  echo Peptidomimetics+membrane | gmx trjconv -f ${deffnm}.cpt -s ${deffnm}.tpr -o ${deffnm}_cpt.gro -pbc whole  -n index.ndx 
  [ ! -s ${deffnm}_numcont.xvg ]   && tsp -L ${deffnm}_mindist bash -c "echo Membrane Peptidomimetics | gmx mindist -f ${deffnm}_sk10_pbc.xtc -s ${deffnm}.tpr -n index.ndx -od ${deffnm}_mindist -on ${deffnm}_numcont -d 0.5 -group"

  # Fatslim
  [ ! -s ${deffnm}_thickness.xvg ] && tsp -L ${deffnm}_thickness fatslim thickness -c ${deffnm}_cpt.gro -n lipidator.ndx -t ${deffnm}_sk10_pbc.xtc --hg-group POPC --thickness-cutoff 20.0 --plot-thickness ${deffnm}_thickness.xvg 
  [ ! -s ${deffnm}_apl.xvg ] && tsp -L ${deffnm}_apl fatslim apl -c ${deffnm}_cpt.gro -n lipidator.ndx -t ${deffnm}_sk10_pbc.xtc --hg-group POPC --apl-cutoff 20.0 --plot-area ${deffnm}_apl.xvg 
  # Calc-order-parameters using the modified adapted calcOrderParameter.py from NMRlipids
  [ ! -s ${deffnm}_ordpars.out ] && tsp -L ${deffnm}_ordpars ../../../scripts/calcOP-py3-modif-martini.py -i martini_op.def -t ${deffnm}_cpt.gro  -x ${deffnm}_sk10_pbc.xtc -o ${deffnm}_ordpars.out 
done
