|
2 | 2 |
|
3 | 3 | import logging |
4 | 4 | from collections import defaultdict |
| 5 | +from copy import deepcopy |
5 | 6 | from typing import TYPE_CHECKING |
6 | 7 |
|
7 | 8 | import numpy as np |
8 | 9 | from pydantic import Field |
9 | 10 | from pymatgen.analysis.bond_valence import BVAnalyzer |
10 | | -from pymatgen.core import Structure |
11 | 11 | from pymatgen.core.periodic_table import Specie |
12 | 12 |
|
13 | 13 | from emmet.core.material_property import PropertyDoc |
@@ -49,9 +49,11 @@ class OxidationStateDoc(PropertyDoc): |
49 | 49 |
|
50 | 50 | @classmethod |
51 | 51 | def from_structure( |
52 | | - cls, structure: Structure, material_id: IdentifierType | None = None, **kwargs |
| 52 | + cls, |
| 53 | + structure: StructureType, |
| 54 | + material_id: IdentifierType | None = None, |
| 55 | + **kwargs, |
53 | 56 | ): |
54 | | - |
55 | 57 | # Check if structure already has oxidation states, |
56 | 58 | # if so pass this along unchanged with "method" == "manualx" |
57 | 59 | struct_valences: list[float | None] = [] |
@@ -101,6 +103,15 @@ def from_structure( |
101 | 103 | } |
102 | 104 |
|
103 | 105 | if d["method"] == OxiStateAssigner.BVA: |
| 106 | + # BVAnalyzer (through SpaceGroupAnalyzer) is sensitive to magnetic configuration |
| 107 | + # -> magmoms can be removed for improved reliablity during oxi state analysis, |
| 108 | + # but original structure should be passed as meta_structure to preserve data |
| 109 | + if "magmom" in structure.site_properties: |
| 110 | + meta_structure = deepcopy(structure) |
| 111 | + structure.remove_site_property("magmom") |
| 112 | + else: |
| 113 | + meta_structure = structure |
| 114 | + |
104 | 115 | try: |
105 | 116 | bva = BVAnalyzer() |
106 | 117 | valences = bva.get_valences(structure) |
@@ -166,7 +177,7 @@ def from_structure( |
166 | 177 | d["method"] = None |
167 | 178 |
|
168 | 179 | return super().from_structure( |
169 | | - meta_structure=structure, |
| 180 | + meta_structure=meta_structure, |
170 | 181 | **d, |
171 | 182 | **kwargs, |
172 | 183 | ) |
0 commit comments