Skip to content

Commit

Permalink
Ensure openbabel can stay an optional dep (#760)
Browse files Browse the repository at this point in the history
  • Loading branch information
munrojm committed Jun 22, 2023
1 parent 8de3751 commit edb9806
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions emmet-core/emmet/core/qchem/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from pydantic import Field

from openbabel import openbabel as ob

from pymatgen.core.structure import Molecule
from pymatgen.analysis.molecule_matcher import MoleculeMatcher
from pymatgen.io.babel import BabelMolAdaptor
Expand All @@ -16,6 +14,11 @@
from emmet.core.qchem.calc_types import CalcType, LevelOfTheory, TaskType
from emmet.core.qchem.task import TaskDocument

try:
import openbabel
except ImportError:
openbabel = None


__author__ = "Evan Spotte-Smith <ewcspottesmith@lbl.gov>"

Expand Down Expand Up @@ -252,6 +255,12 @@ def from_tasks(
Args:
task_group: List of task document
"""

if openbabel is None:
raise ModuleNotFoundError(
"openbabel must be installed to instantiate a MoleculeDoc from tasks"
)

if len(task_group) == 0:
raise Exception("Must have more than one task in the group.")

Expand Down Expand Up @@ -394,7 +403,7 @@ def from_tasks(
coord_hash = get_graph_hash(molecule, "coords")

ad = BabelMolAdaptor(molecule)
ob.StereoFrom3D(ad.openbabel_mol)
openbabel.StereoFrom3D(ad.openbabel_mol)

inchi = ad.pybel_mol.write("inchi").strip()
inchikey = ad.pybel_mol.write("inchikey").strip()
Expand Down Expand Up @@ -473,7 +482,7 @@ def construct_deprecated_molecule(
coord_hash = get_graph_hash(molecule, "coords")

ad = BabelMolAdaptor(molecule)
ob.StereoFrom3D(ad.openbabel_mol)
openbabel.StereoFrom3D(ad.openbabel_mol)

inchi = ad.pybel_mol.write("inchi").strip()
inchikey = ad.pybel_mol.write("inchikey").strip()
Expand Down

0 comments on commit edb9806

Please sign in to comment.