# Path: src/python/pipelines/rdkit/sanify_utils.py
# def enumerateStereoIsomers(mol):
#     out = []
#     chiralCentres = Chem.FindMolChiralCenters(mol, includeUnassigned=True)
#     #return the molecule object when no chiral centres where identified
#     if chiralCentres == []:
#         return [mol]
# 
#     #All bit permutations with number of bits equals number of chiralCentres
#     elements = _spam(len(chiralCentres))
# 
#     for isoId,element in enumerate(elements):
#         for centreId,i in enumerate(element):
#             atomId = chiralCentres[centreId][0]
#             if i == 0:
#                 mol.GetAtomWithIdx(atomId).SetChiralTag(Chem.rdchem.ChiralType.CHI_TETRAHEDRAL_CW)
#             elif i == 1:
#                 mol.GetAtomWithIdx(atomId).SetChiralTag(Chem.rdchem.ChiralType.CHI_TETRAHEDRAL_CCW)
#         outmol = copy(mol)
#         utils.log("Enumerated ", Chem.MolToSmiles(mol, isomericSmiles=True))
#         out.append(outmol)
#     return out
# 
# def enumerateTautomers(mol):
#     """
#     Get all of the Tautomers of a given molecule
#     :param mol: the input molecule
#     :return: a list of Tautomers
#     """
#     smiles = Chem.MolToSmiles(mol,isomericSmiles=True)
#     tauts = enumerate_tautomers_smiles(smiles)
#     ##TODO Append Parent molecule name
#     return  [Chem.MolFromSmiles(x) for x in tauts]
# 
# STANDARD_MOL_METHODS = {"molvs": molVsStandardizer, "flatkinson": flatkinsonStandardizer}


import sys, argparse
from pipelines_utils import parameter_utils, utils
from pipelines_utils_rdkit import rdkit_utils
from rdkit import Chem
from rdkit.Chem import AllChem
from .sanify_utils import enumerateStereoIsomers,enumerateTautomers,STANDARD_MOL_METHODS
                else:
                    std.SetProp("Standardized", "True")
            except:
                errors += 1
                utils.log("Error standardizing", sys.exc_info()[0])
                std = mol
                std.SetProp("Standardized", "Error")

            count = write_out([std],count,writer,args.mol_format,args.outformat)
        else:
            # we want a new UUID generating as we are generating new molecules
            if mol.HasProp('uuid'):
                parentUuid = mol.GetProp("uuid")
            else:
                parentUuid = None

            results = []


            if args.enumerate_tauts:
                utils.log("Enumerating tautomers")
                results = enumerateTautomers(mol)
            else:
                results.append(mol)

            if args.enumerate_stereo:
                utils.log("Enumerating steroisomers")
                mols = results
                results = []
                for m in mols:

# Path: src/python/pipelines/rdkit/sanify_utils.py
# def enumerateStereoIsomers(mol):
#     out = []
#     chiralCentres = Chem.FindMolChiralCenters(mol, includeUnassigned=True)
#     #return the molecule object when no chiral centres where identified
#     if chiralCentres == []:
#         return [mol]
# 
#     #All bit permutations with number of bits equals number of chiralCentres
#     elements = _spam(len(chiralCentres))
# 
#     for isoId,element in enumerate(elements):
#         for centreId,i in enumerate(element):
#             atomId = chiralCentres[centreId][0]
#             if i == 0:
#                 mol.GetAtomWithIdx(atomId).SetChiralTag(Chem.rdchem.ChiralType.CHI_TETRAHEDRAL_CW)
#             elif i == 1:
#                 mol.GetAtomWithIdx(atomId).SetChiralTag(Chem.rdchem.ChiralType.CHI_TETRAHEDRAL_CCW)
#         outmol = copy(mol)
#         utils.log("Enumerated ", Chem.MolToSmiles(mol, isomericSmiles=True))
#         out.append(outmol)
#     return out
# 
# def enumerateTautomers(mol):
#     """
#     Get all of the Tautomers of a given molecule
#     :param mol: the input molecule
#     :return: a list of Tautomers
#     """
#     smiles = Chem.MolToSmiles(mol,isomericSmiles=True)
#     tauts = enumerate_tautomers_smiles(smiles)
#     ##TODO Append Parent molecule name
#     return  [Chem.MolFromSmiles(x) for x in tauts]
# 
# STANDARD_MOL_METHODS = {"molvs": molVsStandardizer, "flatkinson": flatkinsonStandardizer}


# Path: src/python/pipelines/rdkit/sanifier.py
import sys, argparse
from pipelines_utils import parameter_utils, utils
from pipelines_utils_rdkit import rdkit_utils
from rdkit import Chem
from rdkit.Chem import AllChem
from .sanify_utils import enumerateStereoIsomers,enumerateTautomers,STANDARD_MOL_METHODS

                else:
                    std.SetProp("Standardized", "True")
            except:
                errors += 1
                utils.log("Error standardizing", sys.exc_info()[0])
                std = mol
                std.SetProp("Standardized", "Error")

            count = write_out([std],count,writer,args.mol_format,args.outformat)
        else:
            # we want a new UUID generating as we are generating new molecules
            if mol.HasProp('uuid'):
                parentUuid = mol.GetProp("uuid")
            else:
                parentUuid = None

            results = []


            if args.enumerate_tauts:
                utils.log("Enumerating tautomers")
                results = enumerateTautomers(mol)
            else:
                results.append(mol)

            if args.enumerate_stereo:
                utils.log("Enumerating steroisomers")
                mols = results
                results = []
                for m in mols:

                    enumerated = enumerateStereoIsomers(m)