#!/bin/bash
if [ -z "$OSTYPE" ]; then
      if which cygpath 1>/dev/null 2>/dev/null; then
              OSTYPE=cygwin
      fi
fi
mypath=$0
while [ -h "$mypath" ]; do  # Resolve symlinks
        ls=`ls -ld "$mypath"`
        link=`expr "$ls" : '.*-> \(.*\)$'`
        if expr "$link" : '\/' > /dev/null; then
                mypath="$link"
        else
                mypath=`dirname "$mypath"`/"$link"
        fi
done

if expr "$mypath" : '[^\/]' > /dev/null; then
	mypath="`pwd`/$mypath"
fi

case "$OSTYPE" in
cygwin*)
	dir="`dirname $mypath`"
	dir="`cygpath -w $dir`"
        JCHEMHOME="$dir\\..\\.."
        ;;
*)
        dir=`dirname $mypath`
        JCHEMHOME="$dir/../.."
        ;;
esac

cd $JCHEMHOME

echo
echo "In this example the pharmacophoric point types of 1000 compounds "
echo "(taken from the NCI database) are perceived."
echo 
echo "These structures are retrieved from an SDfile (molecules/nci1000.sdf)"
echo "and results are stored in nci1000-FRAG.sdf. This output file contais all "
echo "original structures along with their pharmacophore point map "
echo "(in the PMAP-FRAG tag) data. Pharmacophoric point perception uses a simple"
echo "rule-base comprising 21 small molecular fragments."
echo

read -p "Press any key to continue (or Ctrl-C to abort) " -n 1 key
echo

bin/pmapper -c examples/config/pharma-frag.xml -o examples/output/nci1000-FRAG.sdf \
-S -t PMAP-FRAG examples/molecules/nci1000.sdf

echo
echo "Now the the same input file is used, but this time pharmacophore points "
echo "are identified by ion charge calculations. This takes a bit longer, though "
echo "it achieves higher accuracy."
echo "These pharmacophore maps are stored as PMAP-CALC and the output is"
echo "nci1000-CALC.sdf."
echo

read -p "Press any key to continue (or Ctrl-C to abort) " -n 1 key
echo

bin/pmapper -c examples/config/pharma-calc.xml -o examples/output/nci1000-CALC.sdf \
-S -t PMAP-CALC examples/molecules/nci1000.sdf

echo 
echo "Now the structures will be displayed in MarvinView. Structures are"
echo "colored according to their pharmacophore point types. The coloring"
echo "schema is defined in file config/PF.colors. For the sake of easy"
echo "comparison of the two pharmacophore perception methods MarvinView is"
echo "launched in two instances: the first displays fragment based PMAP-FRAG data,"
echo "and the second shows calculation based PMAP-CALC."
echo 
echo 

bin/mview -t PMAP-FRAG -p examples/config/PF.colors examples/output/nci1000-FRAG.sdf &
bin/mview -t PMAP-CALC -p examples/config/PF.colors examples/output/nci1000-CALC.sdf &

echo 
echo 
echo 


