#!/bin/csh
#$ -S /bin/csh
#$ -cwd
#$ -o /nfs/exa/work/stefan/Anions/MWT-300-400/Each-pattern/Enamine-300-400-filtered-xaaqa/CovEnamine-300-400-filtered-xaaqa-eachpattern.out
#$ -e /nfs/exa/work/stefan/Anions/MWT-300-400/Each-pattern/Enamine-300-400-filtered-xaaqa/CovEnamine-300-400-filtered-xaaqa-eachpattern.err 
#$ -t 1-1
hostname
date
cd /scratch
mkdir -p /scratch/stefan/CovEnamine-300-400-filtered-xaaqa-eachpattern
cd /scratch/stefan/CovEnamine-300-400-filtered-xaaqa-eachpattern
cp /nfs/exa/work/stefan/Anions/MWT-300-400/Each-pattern/Enamine-300-400-filtered-xaaqa/Enamine-300-400-filtered-xaaqa.smi ./
set name=Enamine-300-400-filtered-xaaqa
cp /nfs/exa/work/stefan/Anions/MWT-300-400/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-300-400-filtered-xaaqa-eachpattern/$subdir
        cd  /scratch/stefan/CovEnamine-300-400-filtered-xaaqa-eachpattern/$subdir
        awk "NR==$i" /scratch/stefan/CovEnamine-300-400-filtered-xaaqa-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-300-400-filtered-xaaqa-eachpattern/Enamine-300-400-filtered-xaaqa.smi out.$subdir.smi
        set num2=`cat /scratch/stefan/CovEnamine-300-400-filtered-xaaqa-eachpattern/$subdir/out.$subdir.smi | wc -l`
        echo check$i $num2
        cp -rf /scratch/stefan/CovEnamine-300-400-filtered-xaaqa-eachpattern/$subdir/ /nfs/exa/work/stefan/Anions/MWT-300-400/Each-pattern/Enamine-300-400-filtered-xaaqa\/
   @ i++
end
cd /scratch/stefan/
date
rm -rf CovEnamine-300-400-filtered-xaaqa-eachpattern
