#! /bin/bash
# Moves to another directory all SMILES containing a nitrogen atom which
# appears not to be trivalent. These SMILES should be checked, 
# in many cases, they are coordination compounds with correct brackets around
# the nitrogen.

[ -d ../working ] || mkdir ../working
for i in `ls *.smi` ; do
   radical=no
   dato=`cat $i | grep [[]N[]]`
   if [ "$dato" != "" ]; then
     radical=si
   else  
     dato=`cat $i | grep [[]NH[]]`
     if [ "$dato" != "" ]; then
       radical=si
     else
       dato=`cat $i | grep [[]NH2[]]`
       if [ "$dato" != "" ]; then
         radical=si
       else
         dato=`cat $i | grep [[]NH3[]]`
         if [ "$dato" != "" ]; then
           radical=si
         fi
       fi
     fi
   fi
   if [ "$radical" == "si" ]; then
     mv $i ../working       
   fi
done
