#!/usr/bin/env bash

# set threads to 1 to avoid some numerical unstability
export OMP_NUM_THREADS=1

export TESTDIR=$CONDA_PREFIX/share/cmip/tests
export RESULTS=$TESTDIR/results
mkdir $RESULTS 2> /dev/null
export REF=$TESTDIR/reference
export CMIP=cmip
export VDW=$CONDA_PREFIX/share/cmip/dat/vdwprm

cd $RESULTS
rm *out *grd *cube *rst 2> /dev/null
echo "1/5 Testing: MIP O-"
$CMIP -i $TESTDIR/mipn.in -hs $TESTDIR/1kim_h.pdb -grdout 1kim_mipn.grd -cube 1kim_mipn.cube -o 1kim.mipn.out -vdw $VDW
diff -I '#T' 1kim.mipn.out $REF/1kim.mipn.out.0 > 1kim.mipn.out.diff
echo "Test done"
echo ""
echo "2/5 Testing: Docking without using restart data"
$CMIP -i $TESTDIR/dock.in -rst 1kim.rst -hs $TESTDIR/1kim_h.pdb  -pr $TESTDIR/1kim_l.pdb -outpdb 1kim_h_1kim_l.dock -grdout 1kim.dock.grd -o 1kim.dock.out -vdw $VDW
diff 1kim_h_1kim_l.dock.pdb $REF/1kim_h_1kim_l.dock.pdb.0 > 1kim_h_1kim_l.dock.pdb.diff
diff -I '#T' 1kim.dock.out $REF/1kim.dock.out.0 > 1kim.dock.out.diff
echo "Test done"
echo ""
echo "3/5 Testing: Docking using restart data"
$CMIP -i $TESTDIR/dockrst.in -rst 1kim.rst  -pr $TESTDIR/1kim_l.pdb -outpdb 1kim_h_1kim_l.dockrst -grdout 1kim.dockrst.grd -o 1kim.dockrst.out -vdw $VDW
diff 1kim_h_1kim_l.dockrst.pdb $REF/1kim_h_1kim_l.dockrst.pdb.0 > 1kim_h_1kim_l.dockrst.pdb.diff
diff -I '#T' 1kim.dockrst.out $REF/1kim.dockrst.out.0 > 1kim.dockrst.out.diff
echo "Test done"
echo ""
echo "4/5 Testing: Interaction energy"
$CMIP -i $TESTDIR/energy.in -hs $TESTDIR/1kim_h.pdb  -pr $TESTDIR/1kim_l.pdb -o 1kim.energy.out -vdw $VDW -byat 1kim_l.byatom.out
diff -I '#T' 1kim.energy.out $REF/1kim.energy.out.0 > 1kim.energy.out.diff
diff 1kim_l.byatom.out $REF/1kim_l.byatom.out.0 > 1kim_l.byatom.out.diff
echo "Test done"
echo ""
echo "5/5 Testing: PB Solvation"
$CMIP -i $TESTDIR/solv.in -hs $TESTDIR/1kim_l.pdb  -o 1kim_l.solv.out -vdw $VDW -grdout 1kim_l.mep.grd -cube 1kim_l.mep.cube
diff -I '#T' 1kim_l.solv.out $REF/1kim_l.solv.out.0 > 1kim_l.solv.out.diff
echo "Test done"
echo ""
echo ""
echo "If there is no other output than the test start and test end messages, the tests have successfully passed"
echo ""

