# Path: e3fp_paper/sea_utils/util.py
# def lists_dicts_to_molecules(molecules_file, smiles_dict, mol_lists_dict,
#                              fp_type):
#     """Write dict of mol names to list of native tuples to a molecules file."""
#     with smart_open(molecules_file, "wb") as f:
#         writer = csv.writer(f)
#         fp_type.write(writer)
#         writer.writerow(("molecule id", "smiles", "fingerprint"))
#         for mol_name in sorted(smiles_dict.keys()):
#             smiles = smiles_dict[mol_name]
#             fp_list = mol_lists_dict.get(mol_name, [])
#             for fp_native, fp_name in fp_list:
#                 writer.writerow((fp_name, smiles, fp_native))
# 
# def fprint_params_to_fptype(bits=None, radius_multiplier=None,
#                             level=None, stereo=None,
#                             include_disconnected=None, **kwargs):
#     """Make SEA ``FingerprintType`` from fingerprint parameters."""
#     if len(kwargs) > 0:
#         logging.warning(
#             "Ignoring fingerprint params {!r} for fp_type".format(kwargs))
#     fp_type = FingerprintType()
#     fp_type.data[fp_type.KEYS[0]] = 'e3fp'
#     fp_type.data[fp_type.KEYS[1]] = 'sea_native'
#     fp_type.data[fp_type.KEYS[2]] = bits
#     fp_params = {'radius_multiplier': "%.4g" % radius_multiplier,
#                  'level': str(level), 'stereo': str(stereo),
#                  'include_disconnected': str(include_disconnected)}
#     fp_type.data[fp_type.KEYS[3]] = str(sorted(fp_params.items()))
#     return fp_type
# 
# Path: e3fp_paper/pipeline.py
# def native_tuples_from_sdf(sdf_file, fprint_params={}, save=False):
#     """Fingerprint conformers from SDF file and convert to native_tuples."""
#     fprints_list = fprints_from_sdf(sdf_file, fprint_params=fprint_params,
#                                     save=save)
#     native_tuples = list(map(fprint_to_native_tuple, fprints_list))
#     return native_tuples
# 
# def native_tuples_from_smiles(smiles, name, confgen_params={},
#                               fprint_params={}, save=False):
#     """Generate conformers, fprints, and native encoding from SMILES string."""
#     fprints_list = fprints_from_smiles(smiles, name,
#                                        confgen_params=confgen_params,
#                                        fprint_params=fprint_params, save=save)
#     native_tuples = list(map(fprint_to_native_tuple, fprints_list))
#     return native_tuples


import glob
import os
import logging
import argparse
from python_utilities.parallel import Parallelizer, make_data_iterator, \
                                      ALL_PARALLEL_MODES
from python_utilities.scripting import setup_logging
from e3fp.conformer.util import smiles_to_dict
from e3fp.pipeline import params_to_dicts
from e3fp_paper.sea_utils.util import lists_dicts_to_molecules, \
                                      fprint_params_to_fptype
from e3fp_paper.pipeline import native_tuples_from_sdf, \
                                native_tuples_from_smiles
"""Generate E3FP fingerprints and save to SEA molecules file.

Author: Seth Axen
E-mail: seth.axen@gmail.com"""



def name_from_sdf_filename(fn):
    return os.path.basename(fn).split('.')[0]



# Path: e3fp_paper/sea_utils/util.py
# def lists_dicts_to_molecules(molecules_file, smiles_dict, mol_lists_dict,
#                              fp_type):
#     """Write dict of mol names to list of native tuples to a molecules file."""
#     with smart_open(molecules_file, "wb") as f:
#         writer = csv.writer(f)
#         fp_type.write(writer)
#         writer.writerow(("molecule id", "smiles", "fingerprint"))
#         for mol_name in sorted(smiles_dict.keys()):
#             smiles = smiles_dict[mol_name]
#             fp_list = mol_lists_dict.get(mol_name, [])
#             for fp_native, fp_name in fp_list:
#                 writer.writerow((fp_name, smiles, fp_native))
# 
# def fprint_params_to_fptype(bits=None, radius_multiplier=None,
#                             level=None, stereo=None,
#                             include_disconnected=None, **kwargs):
#     """Make SEA ``FingerprintType`` from fingerprint parameters."""
#     if len(kwargs) > 0:
#         logging.warning(
#             "Ignoring fingerprint params {!r} for fp_type".format(kwargs))
#     fp_type = FingerprintType()
#     fp_type.data[fp_type.KEYS[0]] = 'e3fp'
#     fp_type.data[fp_type.KEYS[1]] = 'sea_native'
#     fp_type.data[fp_type.KEYS[2]] = bits
#     fp_params = {'radius_multiplier': "%.4g" % radius_multiplier,
#                  'level': str(level), 'stereo': str(stereo),
#                  'include_disconnected': str(include_disconnected)}
#     fp_type.data[fp_type.KEYS[3]] = str(sorted(fp_params.items()))
#     return fp_type
# 
# Path: e3fp_paper/pipeline.py
# def native_tuples_from_sdf(sdf_file, fprint_params={}, save=False):
#     """Fingerprint conformers from SDF file and convert to native_tuples."""
#     fprints_list = fprints_from_sdf(sdf_file, fprint_params=fprint_params,
#                                     save=save)
#     native_tuples = list(map(fprint_to_native_tuple, fprints_list))
#     return native_tuples
# 
# def native_tuples_from_smiles(smiles, name, confgen_params={},
#                               fprint_params={}, save=False):
#     """Generate conformers, fprints, and native encoding from SMILES string."""
#     fprints_list = fprints_from_smiles(smiles, name,
#                                        confgen_params=confgen_params,
#                                        fprint_params=fprint_params, save=save)
#     native_tuples = list(map(fprint_to_native_tuple, fprints_list))
#     return native_tuples


# Path: project/scripts/generate_e3fp_fprints.py
import glob
import os
import logging
import argparse
from python_utilities.parallel import Parallelizer, make_data_iterator, \
                                      ALL_PARALLEL_MODES
from python_utilities.scripting import setup_logging
from e3fp.conformer.util import smiles_to_dict
from e3fp.pipeline import params_to_dicts
from e3fp_paper.sea_utils.util import lists_dicts_to_molecules, \
                                      fprint_params_to_fptype
from e3fp_paper.pipeline import native_tuples_from_sdf, \
                                native_tuples_from_smiles

"""Generate E3FP fingerprints and save to SEA molecules file.

Author: Seth Axen
E-mail: seth.axen@gmail.com"""



def name_from_sdf_filename(fn):
    return os.path.basename(fn).split('.')[0]



def main(smiles_file, params_file, sdf_dir=None, out_file="molecules.csv.bz2",