Skip to content

Commit

Permalink
Add nicer error message when trying to use wfl.generate.smiles if rdk…
Browse files Browse the repository at this point in the history
…it isn't installed
  • Loading branch information
bernstei committed Jun 6, 2024
1 parent caa239d commit 02ba42e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wfl/generate/smiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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")

0 comments on commit 02ba42e

Please sign in to comment.