###############################################################################
# Help                                                                         #
################################################################################
Help()
{
   # Display Help
   echo "Carry out all atom refinement using Xplor"
   echo "regularizes bond, angle and improper terms, not allowing significant motion of the P atoms"
   echo
   echo "Usage: "
   echo "      bash master_refine.sh pdb_list"
   echo 
   echo "      pdb_list          list of all atom PDBs with full path"
   echo "                        example at scripts_path/analysis/aaPDBlist.txt"
   echo "                        The refined PDB files have extension _ref.pdb"
   echo
}
# Get the options
while getopts ":h" option; do
   case $option in
      h) # display Help
         Help
         exit;;
   esac
done
# While no arguments
if [[ $# -eq 0 ]] ; then
    Help
    exit 0
fi

module load python/2.7
module load Xplor-NIH/3.3

PDBlist_file=$1
#echo $bpl_basename

## parse/process the list of pdb files 
count=1
while IFS= read -r line
do
  pdb_basename=`basename $line`
  pdb_path=`readlink -f $line`
  #echo $pdb_path
  #cp $pdb_path ./
  #echo $pdb_basename
  ######## glob to all atom conversion
  #echo "****** now carrying out refinement on $pdb_basename  ********"
 
  ##### Xplor refinement/batch job submission
  cp $pdb_path ./
  cp $analysisPath"/analysis/regularize.py" ./
  echo "******* now submitting job for all atom refinement on $pdb_basename *********"
  slurmXplor  -to-sbatch  --partition=norm,ccr --time=0-01:00:00 -o $pdb_basename".log" regularize.py $pdb_basename 

  ## get out into the top level directory

done <$PDBlist_file

