receptor_pdbqt=$1
receptor_pdbqt_modified=$2
receptor_pdbqt_modified2=$3
ligand_pdbqt=$4
size_x=$5
out=$6
log=$7
receptor_name=$8
ligand_name=$9
# This one is to extract the protein code and to check whether the fillouts have already been done
# This is for the parallel version, ignore
receptor_file=${10}
receptorTypes=${11}
toolsDirectory=${12}

# Configuration variables // This is not really necessary anymore
MYRAND=$(( ( RANDOM % 10000000 )  + 1 ))
RANDDIR=${MYRAND}





mkdir $RANDDIR


cp -r ${toolsDirectory}/scripts/* $RANDDIR
echo "$toolsDirectory"

cp $receptorTypes $RANDDIR
NOMBRERECEPTOR=$(basename $receptorTypes)
mv $RANDDIR/$NOMBRERECEPTOR $RANDDIR/receptor_atm_types.txt

MYPWD=$PWD


cd $RANDDIR

source ADT_VENV/bin/activate

#echo "[RUNNING] - (Rscript pdbcenter_npts_finder.R $receptor_pdbqt_modified $RANDDIR) &>/dev/null"
Rscript pdbcenter_npts_finder.R $receptor_pdbqt_modified2 $MYPWD/$RANDDIR

#echo "[RUNNING] - (Rscript gpffilemaker.R $receptor_pdbqt $RANDDIR) "
Rscript gpffilemaker.R $receptor_pdbqt_modified2 $MYPWD/$RANDDIR

#echo "[RUNNING] - (Rscript glgfilemaker.R $receptor_pdbqt $RANDDIR) "
Rscript glgfilemaker.R $receptor_pdbqt_modified2 $MYPWD/$RANDDIR

#echo "[RUNNING] - (Rscript envelopesmaker.R $receptor_pdbqt $RANDDIR) "
#(Rscript envelopesmaker.R $receptor_pdbqt $RANDDIR) &>/dev/null
pathLigand=$(which AutoLigand.py)
Rscript envelopesmaker.R $receptor_pdbqt_modified2 $MYPWD/$RANDDIR $pathLigand

#cp ~/proteindb/2E9U_PH7/FILL* .

#echo "[RUNNING] - (Rscript envelopesmaker.R $receptor_pdbqt $RANDDIR) "
#(Rscript envelopesmaker.R $receptor_pdbqt $RANDDIR) &>/dev/null


#echo "[RUNNING] - (Rscript clusterfilemaker.R $RANDDIR) "
Rscript clusterfilemaker.R $MYPWD/$RANDDIR


#echo "[RUNNING] - (Rscript clusterfinder_Auto.R $RANDDIR) "
Rscript clusterfinder_Auto.R $MYPWD/$RANDDIR


#echo "[RUNNING] - (Rscript cluster_to_vina_cluster.R $receptor_pdbqt_modified2 $ligand_pdbqt $out $log $size_x $RANDDIR $receptor_name $ligand_name) "
Rscript cluster_to_vina_cluster.R $receptor_pdbqt_modified2 $ligand_pdbqt $out $log $size_x $MYPWD/$RANDDIR $receptor_name $ligand_name


cd $MYPWD


deactivate
