#! /bin/bash
# This scripts take all SMILES files in the folder, that are supposed to
# contain compounds with chiral moieties containing more than one chiral
# mark crystallised in non-chiral space groups, hence forming racemic crystals.
# The enantiomer of the input is created and both enantiomers are written to
# the output. The output file replaces the original one, which is removed.

for i in `ls *.smi` ; do
   tmp=`cat $i | cut -f1`
   tmp0=`cat $i | cut -f1`
   key=`cat $i | cut -f2`
   while echo $tmp | grep @@ > /dev/null; do   
      tmp=`echo $tmp | sed -e s/@@/xxx/`
   done
   while echo $tmp | grep @ > /dev/null; do   
      tmp=`echo $tmp | sed -e s/@/yyy/`
   done
   while echo $tmp | grep yyy > /dev/null; do   
      tmp=`echo $tmp | sed -e s/yyy/@@/`
   done
   while echo $tmp | grep xxx > /dev/null; do   
      tmp=`echo $tmp | sed -e s/xxx/@/`
   done
   rm -f $i
   echo -n $tmp0 > $i
   echo -n .$tmp >> $i
   echo -e "\t"$key >> $i
done
