Spaces:
Sleeping
Sleeping
Download modules/materials_adapter.py from chemenovausa/orbitchem-api: direct link, hf CLI and curl.
- Browser
- Download file 2.06 kB
-
https://huggingface.co/spaces/chemenovausa/orbitchem-api/resolve/main/modules/materials_adapter.py
- Command line
-
hf download hf://spaces/chemenovausa/orbitchem-api/modules/materials_adapter.py
-
curl -L -o materials_adapter.py https://huggingface.co/spaces/chemenovausa/orbitchem-api/resolve/main/modules/materials_adapter.py
2.06 kB
| """ | |
| modules/materials_adapter.py | |
| Pymatgen + matminer execution hooks for IntelliForm Enterprise. | |
| """ | |
| from __future__ import annotations | |
| from dataclasses import asdict, dataclass | |
| from typing import List | |
| try: | |
| from pymatgen.core import Composition | |
| PYMATGEN_OK = True | |
| except ImportError: | |
| Composition = None | |
| PYMATGEN_OK = False | |
| try: | |
| from matminer.featurizers.composition import ElementProperty | |
| MATMINER_OK = True | |
| except ImportError: | |
| ElementProperty = None | |
| MATMINER_OK = False | |
| class MaterialsSummary: | |
| active: bool | |
| composition_count: int | |
| feature_columns: int | |
| example_formula: str | |
| notes: List[str] | |
| def to_dict(self) -> dict: | |
| return asdict(self) | |
| def analyze_compositions(formulas: List[str]) -> MaterialsSummary: | |
| if not PYMATGEN_OK: | |
| return MaterialsSummary( | |
| active=False, | |
| composition_count=0, | |
| feature_columns=0, | |
| example_formula="", | |
| notes=["pymatgen is not installed in the current runtime."], | |
| ) | |
| usable = [f for f in formulas if f] | |
| if not usable: | |
| return MaterialsSummary( | |
| active=True, | |
| composition_count=0, | |
| feature_columns=0, | |
| example_formula="", | |
| notes=["No molecular formulas were available for composition analysis."], | |
| ) | |
| comps = [Composition(f) for f in usable] | |
| feature_columns = 0 | |
| notes = ["pymatgen composition parsing is active."] | |
| if MATMINER_OK: | |
| featurizer = ElementProperty.from_preset("magpie") | |
| labels = featurizer.feature_labels() | |
| feature_columns = len(labels) | |
| notes.append("matminer Magpie composition featurization is active for OrbitChem-style materials descriptors.") | |
| else: | |
| notes.append("matminer is not installed, so only composition parsing is active.") | |
| return MaterialsSummary( | |
| active=True, | |
| composition_count=len(comps), | |
| feature_columns=feature_columns, | |
| example_formula=usable[0], | |
| notes=notes, | |
| ) | |