#
# This is a command file.
#
# The contents of this file will be used to create a Bash shell script
# so any legal shell commands can go in this file.
# Or comments like this one, for that matter.
#
# Variable substiution is done using Python's printf format,
# meaning you need a percent sign, the variable name in parentheses,
# and the letter 's' (for 'string').
#
# Available variables include:
#   workdir     the directory where test input files have been copied,
#               and where test output files should end up.
#   minidir     the base directory where Mini lives
#   database    where the Mini database lives
#   bin         where the Mini binaries live
#   binext      the extension on binary files, like ".linuxgccrelease"
#
# The most important thing is that the test execute in the right directory.
# This is especially true when we're using SSH to execute on other hosts.
# All command files should start with this line:
#
# This command files is used for two cluster scripts: submit and analyze
# 'submit' script should prepare all input files and submit them to a condor.
#          After execution of 'submit' is finished root level script will wait until condor queue is
#          empty and create and call 'analyze' script.
#
# 'analyze' script should assume that all condor jobs are finished and can perform all post process
#           calculations thats are necessary. The end result of analyze script is at least two
#           files: results.log and results.yaml. In addition to that all files that was left in
#           output/ directory will be also saved by root script for future references.

cd %(workdir)s

# Removing old files from previous run
rm .results.log  .results.yaml

work_dir="input"
compiler=%(bin)s/docking_protocol.%(binext)s
[ -x $compiler ] || exit 1
prefix=XT
Njobs=20
database="%(database)s"

exec < flags
protocol=""
while read line
do
	#echo $line
	protocol=$protocol" "$line
done
protocol="'"$protocol"'"

cd $work_dir

rm protocol.config
#cp ../scripts/protocol.config .
cp ../scripts/crun_sci_test.bash .
echo "compiler=$compiler" >> protocol.config
echo "prefix=$prefix" >> protocol.config
echo "protocol_flags=$protocol" >> protocol.config
echo "Njobs=$Njobs" >> protocol.config
echo "database=$database" >> protocol.config

LIST=$(ls *.pdb | cut -c 1-4)
for pdb in $LIST
do
echo $pdb
rm -rf $pdb
./crun_sci_test.bash $pdb protocol
done

#rm protocol.config

