File: alloys.py

package info (click to toggle)
python-emmet-core 0.84.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 77,220 kB
  • sloc: python: 16,355; makefile: 30
file content (37 lines) | stat: -rw-r--r-- 946 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from emmet.core.base import EmmetBaseModel
from typing import Dict

try:
    from pymatgen.analysis.alloys.core import (
        AlloyPair,
        AlloySystem,
    )
except ImportError:
    raise ImportError(
        "Install pymatgen-analysis-alloys to use AlloyPairDoc or AlloySystemDoc"
    )


class AlloyPairDoc(EmmetBaseModel):
    alloy_pair: AlloyPair

    pair_id: str

    # fields useful for building search indices
    _search: Dict

    @classmethod
    def from_pair(cls, pair: AlloyPair):
        return cls(alloy_pair=pair, pair_id=pair.pair_id, _search=pair.search_dict())


class AlloySystemDoc(EmmetBaseModel):
    alloy_system: AlloySystem

    alloy_id: str

    @classmethod
    def from_pair(cls, alloy_system: AlloySystem):
        # Too large to duplicate alloy pairs here.
        alloy_system.alloy_pairs = None  # type: ignore[assignment]
        return cls(alloy_system=alloy_system, alloy_id=alloy_system.alloy_id)