# 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
            writer.write(mol, format=fmt)

    return count

def main():

    ### command line args defintions #########################################

    parser = argparse.ArgumentParser(description='RDKit molecule standardizer / enumerator')
    parameter_utils.add_default_io_args(parser)
    parser.add_argument('-et', '--enumerate_tauts', action='store_true', help='Enumerate all tautomers')
    parser.add_argument('-es', '--enumerate_stereo', action='store_true', help='Enumerate all stereoisomers')
    parser.add_argument('-st', '--standardize', action='store_true', help='Standardize molecules. Cannot  be true if enumerate is on.')
    parser.add_argument('-stm','--standardize_method', default="molvs",choices=STANDARD_MOL_METHODS.keys(),help="Choose the method to standardize.")
    parser.add_argument('-mf','--mol_format' ,choices=['smiles', 'mol_2d', 'mol_3d'],help="Format for molecules.")

    args = parser.parse_args()

    utils.log("Sanifier Args: ", args)

    if args.standardize and args.enumerate_tauts:
        raise ValueError("Cannot Enumerate Tautomers and Standardize")

    if args.standardize and args.enumerate_stereo:
        raise ValueError("Cannot Enumerate Stereo and Standardize")

    if args.outformat == 'sdf' and args.mol_format == 'smiles':
        raise ValueError("Smiles cannot be used when outputting as SDF")

    if args.standardize:

# 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

            writer.write(mol, format=fmt)

    return count

def main():

    ### command line args defintions #########################################

    parser = argparse.ArgumentParser(description='RDKit molecule standardizer / enumerator')
    parameter_utils.add_default_io_args(parser)
    parser.add_argument('-et', '--enumerate_tauts', action='store_true', help='Enumerate all tautomers')
    parser.add_argument('-es', '--enumerate_stereo', action='store_true', help='Enumerate all stereoisomers')
    parser.add_argument('-st', '--standardize', action='store_true', help='Standardize molecules. Cannot  be true if enumerate is on.')
    parser.add_argument('-stm','--standardize_method', default="molvs",choices=STANDARD_MOL_METHODS.keys(),help="Choose the method to standardize.")
    parser.add_argument('-mf','--mol_format' ,choices=['smiles', 'mol_2d', 'mol_3d'],help="Format for molecules.")

    args = parser.parse_args()

    utils.log("Sanifier Args: ", args)

    if args.standardize and args.enumerate_tauts:
        raise ValueError("Cannot Enumerate Tautomers and Standardize")

    if args.standardize and args.enumerate_stereo:
        raise ValueError("Cannot Enumerate Stereo and Standardize")

    if args.outformat == 'sdf' and args.mol_format == 'smiles':
        raise ValueError("Smiles cannot be used when outputting as SDF")

    if args.standardize:

        getStandardMolecule = STANDARD_MOL_METHODS[args.standardize_method]