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