## Process the pdbs to produce the afm image data
## Usage: pdb2cafeimage.sh cafe_input_file pdb_path
## First argument is the cafemol input file, 
## second argument is pdb folder path

module load R/4.0
module load python/3.5
path_input=`readlink -f $1`
cafe_input=`basename $path_input`
#echo $cafe_input
pdb_path=$2
cd $pdb_path
FileList=`ls *.pdb`

## correct the format in each pdb
for name in $FileList
do
  echo $name
  Rscript --vanilla $analysisPath"/analysis/format_pdb_cg.R" $name
done
temp_dir="temp_pseudo"
mkdir -p $temp_dir && cp $path_input $_

## run the cafemol to procuce the output image
for name in $FileList
do
  python $analysisPath"/analysis/edit_input_munit.py" $temp_dir/$cafe_input $name $temp_dir ./
  ## edit_input_unit.py will produce a cafemol input file called format.inp
  format_input="format.inp"
  ## run the cafemol to procuce the output image
  echo "********** Running cafemol for image generation **************"
  $cafemolImageout $format_input
  echo "cafemol run is completed successfully"
  Rscript --vanilla $analysisPath"/analysis/read_image_data.R" image_info_cafe.txt $format_input $name
  rm "image_info_cafe.txt" 
done

