From 02ba42eb86dd21144d3e468bc46d160d71daca66 Mon Sep 17 00:00:00 2001 From: Noam Bernstein Date: Thu, 6 Jun 2024 08:27:48 -0400 Subject: [PATCH] Add nicer error message when trying to use wfl.generate.smiles if rdkit isn't installed --- wfl/generate/smiles.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wfl/generate/smiles.py b/wfl/generate/smiles.py index 0d3ab6a7..8b8c1184 100644 --- a/wfl/generate/smiles.py +++ b/wfl/generate/smiles.py @@ -5,13 +5,15 @@ from rdkit import Chem from rdkit.Chem import AllChem except ModuleNotFoundError: - pass + Chem = None from wfl.autoparallelize import autoparallelize, autoparallelize_docstring def smi_to_atoms(smi, useBasicKnowledge=True, useExpTorsionAnglePrefs=True, randomSeed=-1): """Converts smiles to 3D Atoms object""" + if Chem is None: + raise RuntimeError("rdkit must be installed for SMILES support") mol = Chem.MolFromSmiles(smi) mol = Chem.AddHs(mol) @@ -72,5 +74,7 @@ def _run_autopara_wrappable(smiles, useBasicKnowledge=True, useExpTorsionAnglePr def smiles(*args, **kwargs): + if Chem is None: + raise RuntimeError("rdkit must be installed for SMILES support") return autoparallelize(_run_autopara_wrappable, *args, **kwargs) autoparallelize_docstring(smiles, _run_autopara_wrappable, "SMILES string")