# Path: src/python/pipelines/dimorphite/dimorphite_dl.py
# def run_with_mol_list(mol_lst, **kwargs):
#     """A helpful, importable function for those who want to call Dimorphite-DL
#     from another Python script rather than the command line. Note that this
#     function is for passing Dimorphite-DL a list of RDKit Mol objects, together
#     with command-line parameters. If you want to use only the same parameters
#     that you would use from the command line, import run() instead.
# 
#     :param mol_lst: A list of rdkit.Chem.rdchem.Mol objects.
#     :type mol_lst: list
#     :raises Exception: If the **kwargs includes "smiles", "smiles_file",
#                        "output_file", or "test" parameters.
#     :return: A list of properly protonated rdkit.Chem.rdchem.Mol objects.
#     :rtype: list
#     """
# 
#     # Do a quick check to make sure the user input makes sense.
#     for bad_arg in ["smiles", "smiles_file", "output_file", "test"]:
#         if bad_arg in kwargs:
#             msg = "You're using Dimorphite-DL's run_with_mol_list(mol_lst, " + \
#                    "**kwargs) function, but you also passed the \"" + \
#                    bad_arg + "\" argument. Did you mean to use the " + \
#                    "run(**kwargs) function instead?"
#             print(msg)
#             raise Exception(msg)
# 
#     # Set the return_as_list flag so main() will return the protonated smiles
#     # as a list.
#     kwargs["return_as_list"] = True
# 
#     # Having reviewed the code, it will be very difficult to rewrite it so
#     # that a list of Mol objects can be used directly. Intead, convert this
#     # list of mols to smiles and pass that. Not efficient, but it will work.
#     protonated_smiles_and_props = []
#     for m in mol_lst:
#         props = m.GetPropsAsDict()
#         kwargs["smiles"] = Chem.MolToSmiles(m, isomericSmiles=True)
#         protonated_smiles_and_props.extend(
#             [(s.split("\t")[0], props) for s in main(kwargs)]
#         )
# 
#     # Now convert the list of protonated smiles strings back to RDKit Mol
#     # objects. Also, add back in the properties from the original mol objects.
#     mols = []
#     for s, props in protonated_smiles_and_props:
#         m = Chem.MolFromSmiles(s)
#         if m:
#             for prop, val in props.items():
#                 if type(val) is int:
#                     m.SetIntProp(prop, val)
#                 elif type(val) is float:
#                     m.SetDoubleProp(prop, val)
#                 elif type(val) is bool:
#                     m.SetBoolProp(prop, val)
#                 else:
#                     m.SetProp(prop, str(val))
#             mols.append(m)
#         else:
#             UtilFuncs.eprint("WARNING: Could not process molecule with SMILES string " + s + " and properties " + str(props))
# 
#     return mols


import argparse, sys
from pipelines_utils import parameter_utils, utils
from pipelines_utils_rdkit import rdkit_utils, mol_utils
from .dimorphite_dl import run_with_mol_list



def enumerateMol(mol, fragment):
    """
    Enumerate a single molecule
    :param mol:
    :param fragment The fragmentation method, 'hac' or 'mw'. If not specified the whole molecules is passed to Dimorphite
    :return:
    """

    if fragment:
        mol = mol_utils.fragment(mol, fragment)

    inputmol = []
    inputmol.append(mol)


# Path: src/python/pipelines/dimorphite/dimorphite_dl.py
# def run_with_mol_list(mol_lst, **kwargs):
#     """A helpful, importable function for those who want to call Dimorphite-DL
#     from another Python script rather than the command line. Note that this
#     function is for passing Dimorphite-DL a list of RDKit Mol objects, together
#     with command-line parameters. If you want to use only the same parameters
#     that you would use from the command line, import run() instead.
# 
#     :param mol_lst: A list of rdkit.Chem.rdchem.Mol objects.
#     :type mol_lst: list
#     :raises Exception: If the **kwargs includes "smiles", "smiles_file",
#                        "output_file", or "test" parameters.
#     :return: A list of properly protonated rdkit.Chem.rdchem.Mol objects.
#     :rtype: list
#     """
# 
#     # Do a quick check to make sure the user input makes sense.
#     for bad_arg in ["smiles", "smiles_file", "output_file", "test"]:
#         if bad_arg in kwargs:
#             msg = "You're using Dimorphite-DL's run_with_mol_list(mol_lst, " + \
#                    "**kwargs) function, but you also passed the \"" + \
#                    bad_arg + "\" argument. Did you mean to use the " + \
#                    "run(**kwargs) function instead?"
#             print(msg)
#             raise Exception(msg)
# 
#     # Set the return_as_list flag so main() will return the protonated smiles
#     # as a list.
#     kwargs["return_as_list"] = True
# 
#     # Having reviewed the code, it will be very difficult to rewrite it so
#     # that a list of Mol objects can be used directly. Intead, convert this
#     # list of mols to smiles and pass that. Not efficient, but it will work.
#     protonated_smiles_and_props = []
#     for m in mol_lst:
#         props = m.GetPropsAsDict()
#         kwargs["smiles"] = Chem.MolToSmiles(m, isomericSmiles=True)
#         protonated_smiles_and_props.extend(
#             [(s.split("\t")[0], props) for s in main(kwargs)]
#         )
# 
#     # Now convert the list of protonated smiles strings back to RDKit Mol
#     # objects. Also, add back in the properties from the original mol objects.
#     mols = []
#     for s, props in protonated_smiles_and_props:
#         m = Chem.MolFromSmiles(s)
#         if m:
#             for prop, val in props.items():
#                 if type(val) is int:
#                     m.SetIntProp(prop, val)
#                 elif type(val) is float:
#                     m.SetDoubleProp(prop, val)
#                 elif type(val) is bool:
#                     m.SetBoolProp(prop, val)
#                 else:
#                     m.SetProp(prop, str(val))
#             mols.append(m)
#         else:
#             UtilFuncs.eprint("WARNING: Could not process molecule with SMILES string " + s + " and properties " + str(props))
# 
#     return mols


# Path: src/python/pipelines/dimorphite/enumerate_charges.py
import argparse, sys
from pipelines_utils import parameter_utils, utils
from pipelines_utils_rdkit import rdkit_utils, mol_utils
from .dimorphite_dl import run_with_mol_list




def enumerateMol(mol, fragment):
    """
    Enumerate a single molecule
    :param mol:
    :param fragment The fragmentation method, 'hac' or 'mw'. If not specified the whole molecules is passed to Dimorphite
    :return:
    """

    if fragment:
        mol = mol_utils.fragment(mol, fragment)

    inputmol = []
    inputmol.append(mol)


    protonated_mols = run_with_mol_list(inputmol)