From a9b9a95431dc942af606480d458280c2ba041a55 Mon Sep 17 00:00:00 2001 From: Timotej Bernat Date: Fri, 3 Jan 2025 16:06:42 -0700 Subject: [PATCH] Added dependency prechecks for cirpy and pubchempy packages to smileslib.chemdbqueries --- polymerist/smileslib/chemdbqueries.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/polymerist/smileslib/chemdbqueries.py b/polymerist/smileslib/chemdbqueries.py index 936f331..5631408 100644 --- a/polymerist/smileslib/chemdbqueries.py +++ b/polymerist/smileslib/chemdbqueries.py @@ -6,9 +6,29 @@ import logging LOGGER = logging.getLogger(__name__) +from typing import Optional + +from ..genutils.importutils.dependencies import modules_installed, MissingPrerequisitePackage +if not modules_installed('cirpy'): + raise MissingPrerequisitePackage( + importing_package_name=__spec__.name, + use_case='Querying the NIH CACTUS Chemical Identifier Resolver (CIR)', + install_link='https://cirpy.readthedocs.io/en/latest/guide/install.html', + dependency_name='cirpy', + dependency_name_formal='CIRpy', + ) import cirpy + +from ..genutils.importutils.dependencies import modules_installed, MissingPrerequisitePackage +if not modules_installed('pubchempy'): + raise MissingPrerequisitePackage( + importing_package_name=__spec__.name, + use_case='Querying the PubChem Compound database', + install_link='https://pubchempy.readthedocs.io/en/latest/guide/install.html', + dependency_name='pubchempy', + dependency_name_formal='PubChemPy', + ) import pubchempy as pcp -from typing import Optional def get_property_from_smiles(smiles : str, prop_name : str='iupac_name') -> Optional[str]: # TODO: abstract each query method via Strategy pattern