diff --git a/datamol/data/__init__.py b/datamol/data/__init__.py index 04cbbb37..a13718e3 100644 --- a/datamol/data/__init__.py +++ b/datamol/data/__init__.py @@ -13,6 +13,7 @@ import sys import io +import functools try: import importlib.resources as importlib_resources @@ -27,6 +28,17 @@ from ..convert import render_mol_df +@functools.lru_cache() +def datamol_data_file_path(filename: str, dm_module: str = "datamol.data") -> str: + if sys.version_info < (3, 9, 0): + with importlib_resources.path(dm_module, filename) as p: + data_path = p + else: + data_path = importlib_resources.files(dm_module).joinpath(filename) + + return str(data_path) + + def open_datamol_data_file( filename: str, open_binary: bool = False, diff --git a/datamol/mol.py b/datamol/mol.py index e31f1ac4..e0cf6cab 100644 --- a/datamol/mol.py +++ b/datamol/mol.py @@ -45,7 +45,7 @@ AROMATIC_BOND = Chem.rdchem.BondType.AROMATIC DATIVE_BOND = Chem.rdchem.BondType.DATIVE UNSPECIFIED_BOND = Chem.rdchem.BondType.UNSPECIFIED -SALT_SOLVENT_PATH = datamol.data.open_datamol_data_file("salts_solvents.smi").name +SALT_SOLVENT_PATH = datamol.data.datamol_data_file_path("salts_solvents.smi") SALT_SOLVENT_REMOVER = SaltRemover(defnFilename=SALT_SOLVENT_PATH)