Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions src/material_hasher/hasher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Copyright 2025 Entalpic
import warnings

from material_hasher.hasher.bawl import BAWLHasher, ShortBAWLHasher
from material_hasher.hasher.pdd import PointwiseDistanceDistributionHasher

warnings.filterwarnings("always")

__all__ = ["BAWLHasher"]

HASHERS = {
Expand All @@ -16,11 +12,12 @@


try:
from material_hasher.hasher.slices import SLICESHasher
import warnings

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=ImportWarning)
from material_hasher.hasher.slices import SLICESHasher

HASHERS.update({"SLICES": SLICESHasher})
except ImportError:
warnings.warn(
"Failed to import SLICES. If you would like to use this module, please consider running uv pip install -r requirements_slices.txt",
ImportWarning,
)
pass
10 changes: 8 additions & 2 deletions src/material_hasher/hasher/slices.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@


from pymatgen.core.structure import Structure
from slices.core import SLICES

try:
from slices.core import SLICES
except ImportError:
raise ImportError(
"Failed to import SLICES. If you would like to use this module, please consider running uv pip install -r requirements_slices.txt"
)


from material_hasher.hasher.base import HasherBase

Expand All @@ -32,4 +39,3 @@ def get_material_hash(self, structure: Structure) -> str:
The SLICES string representation of the structure.
"""
return self.backend.structure2SLICES(structure)

22 changes: 9 additions & 13 deletions src/material_hasher/similarity/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# Copyright 2025 Entalpic
import logging

from .structure_matchers import PymatgenStructureSimilarity

__all__ = ["PymatgenStructureSimilarity"]
Expand All @@ -10,15 +8,13 @@
}

try:
from .eqv2 import EquiformerV2Similarity
import warnings

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=ImportWarning)
from .eqv2 import EquiformerV2Similarity

__all__.append("EquiformerV2Similarity")
SIMILARITY_MATCHERS["eqv2"] = EquiformerV2Similarity # type: ignore
except ImportError as e:
logging.warning(
"EquiformerV2Similarity is not available. You need to install fairchem-core and its dependencies. "
"This issue is known to affect MacOS systems. "
"If you're not using MacOS, please ensure the optional dependencies required for this feature are installed. uv sync --extra fairchem and uv sync --extra geometric"
"For more information, refer to issue #4: https://github.com/Entalpic/material-hasher/issues/4",
f"Error: {e}",
)
__all__.append("EquiformerV2Similarity")
SIMILARITY_MATCHERS["eqv2"] = EquiformerV2Similarity # type: ignore
except ImportError:
pass
13 changes: 12 additions & 1 deletion src/material_hasher/similarity/eqv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
import yaml
from ase.filters import FrechetCellFilter
from ase.optimize import FIRE
from fairchem.core import OCPCalculator

# fmt: off
try:
from fairchem.core import OCPCalculator
except ImportError:
raise ImportError(
"EquiformerV2Similarity is not available. You need to install fairchem-core and its dependencies. "
"Please ensure the optional dependencies required for this feature are installed. uv sync --extra fairchem and uv sync --extra geometric"
"For more information, refer to issue #4: https://github.com/Entalpic/material-hasher/issues/4",
)
# fmt: on

from huggingface_hub import hf_hub_download
from pymatgen.core import Structure
from pymatgen.io.ase import AseAtomsAdaptor
Expand Down