Skip to content

Commit

Permalink
Make species hash and coord hash optional in MoleculeMetadata
Browse files Browse the repository at this point in the history
This PR closes #1149 by making the species hash and coord hash fields optional in `MoleculeMetadata`, only generating them if OpenBabel is installed. In return, it is possible to generate `MoleculeMetadata` without relying on OpenBabel.
  • Loading branch information
Andrew-S-Rosen authored Nov 29, 2024
1 parent a705a61 commit cbcb044
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions emmet-core/emmet/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
T = TypeVar("T", bound="StructureMetadata")
S = TypeVar("S", bound="MoleculeMetadata")

try:
from openbabel import openbabel
except Exception:
openbabel = None

class StructureMetadata(EmmetBaseModel):
"""Mix-in class for structure metadata."""
Expand Down Expand Up @@ -313,8 +317,9 @@ def from_molecule(
"formula_anonymous": comp.anonymized_formula,
"chemsys": "-".join(elsyms),
"symmetry": symmetry,
"species_hash": get_graph_hash(meta_molecule, "specie"),
"coord_hash": get_graph_hash(meta_molecule, "coords"),
}
if openbabel:
data["species_hash"] = get_graph_hash(meta_molecule, "specie")
data["coord_hash"] = get_graph_hash(meta_molecule, "coords")

return cls(**{k: v for k, v in data.items() if k in fields}, **kwargs)

0 comments on commit cbcb044

Please sign in to comment.