#!/bin/csh
#$ -S /bin/csh
#$ -cwd
#$ -o /nfs/exa/work/stefan/Anions/MWT-250-300/Each-pattern/Enamine-250-300-filtered-xaacu/CovEnamine-250-300-filtered-xaacu-eachpattern.out
#$ -e /nfs/exa/work/stefan/Anions/MWT-250-300/Each-pattern/Enamine-250-300-filtered-xaacu/CovEnamine-250-300-filtered-xaacu-eachpattern.err 
#$ -t 1-1
hostname
date
cd /scratch
mkdir -p /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern
cd /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern
cp /nfs/exa/work/stefan/Anions/MWT-250-300/Each-pattern/Enamine-250-300-filtered-xaacu/Enamine-250-300-filtered-xaacu.smi ./
set name=Enamine-250-300-filtered-xaacu
cp /nfs/exa/work/stefan/Anions/MWT-250-300/Each-pattern/2019-11-9-xiaobo_combine_version.txt ./
set num=`cat 2019-11-9-xiaobo_combine_version.txt | wc -l`
set i = 1
while ($i <= $num)
        set subdir=check$i
        mkdir -p /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern/$subdir
        cd  /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern/$subdir
        awk "NR==$i" /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern/2019-11-9-xiaobo_combine_version.txt | awk '{print $1}'>$subdir.txt
         source /nfs/soft/www/apps/zinc15/envs/production/env.csh
        /nfs/soft/tools/apps/molgrep/molgrep.py smarts -f $subdir.txt /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern/Enamine-250-300-filtered-xaacu.smi out.$subdir.smi
        set num2=`cat /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern/$subdir/out.$subdir.smi | wc -l`
        echo check$i $num2
        cp -rf /scratch/stefan/CovEnamine-250-300-filtered-xaacu-eachpattern/$subdir/ /nfs/exa/work/stefan/Anions/MWT-250-300/Each-pattern/Enamine-250-300-filtered-xaacu\/
   @ i++
end
cd /scratch/stefan/
date
rm -rf CovEnamine-250-300-filtered-xaacu-eachpattern
