#!/bin/sh
# Run scripts with Python (and modpy.sh if needed) if possible, rather
# than the modXXX script (which only works correctly if Python 2.3 is installed)
modpy="../../bin/modpy.sh"
# If modpy.sh doesn't exist, assume we have Python set up correctly already
# (e.g. Mac or RPM install, or PYTHONPATH and LD_LIBRARY_PATH set):
if test "${PYTHON}x" != "x"; then
  pyint="${PYTHON}"
else
  pyint="python"
fi
if test ! -f ${modpy}; then
  modpy="${pyint}"
else
  modpy="${modpy} ${pyint}"
fi
# Only use Modeller through Python if 1) an import succeeds, 2) the 'modeller'
# module imported is really Modeller (not a spurious modeller.py in the path
# somewhere) and 3) the version matches that these examples were built with
run_version=`${modpy} - 2>/dev/null <<END
import sys
from modeller import *
v = info.version_info
if isinstance(v, tuple):
    v = ".".join([str(i) for i in v])
sys.stdout.write(v + '\n')
END
`
build_version="9.20"

run_script() {
  pyscript="$1.py"
  if test "${run_version}" = "${build_version}"; then
    log="$1.log"
    cmd="${modpy} ${pyscript} > ${log}"
  else
    cmd="mod9.20 ${pyscript}"
  fi
  echo "$cmd"
  eval "$cmd"
}

run_script salign_align2d
run_script salign_profile_profile
run_script salign_external_matrix
run_script salign_fix_positions
run_script salign_multiple_seq
run_script salign_multiple_struc
run_script salign_subopt
run_script salign_iterative
