File: magnetism.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 (103 lines) | stat: -rw-r--r-- 3,172 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
from typing import List, Optional

from pydantic import Field
from pymatgen.core import Structure
from pymatgen.analysis.magnetism import CollinearMagneticStructureAnalyzer

from emmet.core.material_property import PropertyDoc
from emmet.core.mpid import MPID


class MagnetismDoc(PropertyDoc):
    """
    Magnetic data obtain from the calculated structure
    """

    property_name: str = "magnetism"

    ordering: Optional[str] = Field(
        None,
        description="Magnetic ordering.",
    )

    is_magnetic: Optional[bool] = Field(
        None,
        description="Whether the material is magnetic.",
    )

    exchange_symmetry: Optional[int] = Field(
        None,
        description="Exchange symmetry.",
    )

    num_magnetic_sites: Optional[int] = Field(
        None,
        description="The number of magnetic sites.",
    )

    num_unique_magnetic_sites: Optional[int] = Field(
        None,
        description="The number of unique magnetic sites.",
    )

    types_of_magnetic_species: Optional[List[str]] = Field(
        None,
        description="Magnetic specie elements.",
    )

    magmoms: Optional[List[float]] = Field(
        None,
        description="Magnetic moments for each site.",
    )

    total_magnetization: Optional[float] = Field(
        None,
        description="Total magnetization in μB.",
    )

    total_magnetization_normalized_vol: Optional[float] = Field(
        None,
        description="Total magnetization normalized by volume in μB/ų.",
    )

    total_magnetization_normalized_formula_units: Optional[float] = Field(
        None,
        description="Total magnetization normalized by formula unit in μB/f.u. .",
    )

    @classmethod
    def from_structure(
        cls,
        structure: Structure,
        total_magnetization: float,
        material_id: MPID,
        **kwargs
    ):  # noqa: E501
        struct_has_magmoms = "magmom" in structure.site_properties
        total_magnetization = abs(
            total_magnetization
        )  # not necessarily == sum(magmoms)
        msa = CollinearMagneticStructureAnalyzer(
            structure, round_magmoms=True, threshold_nonmag=0.2, threshold=0
        )

        magmoms = msa.magmoms.tolist()

        d = {
            "ordering": msa.ordering.value if struct_has_magmoms else "Unknown",
            "is_magnetic": msa.is_magnetic,
            "exchange_symmetry": msa.get_exchange_group_info()[1],
            "num_magnetic_sites": msa.number_of_magnetic_sites,
            "num_unique_magnetic_sites": msa.number_of_unique_magnetic_sites(),
            "types_of_magnetic_species": [str(t) for t in msa.types_of_magnetic_specie],
            "magmoms": magmoms,
            "total_magnetization": total_magnetization,
            "total_magnetization_normalized_vol": total_magnetization
            / structure.volume,
            "total_magnetization_normalized_formula_units": total_magnetization
            / (structure.composition.get_reduced_composition_and_factor()[1]),
        }

        return super().from_structure(
            meta_structure=structure, material_id=material_id, **d, **kwargs
        )