Skip to content

Commit cbe4cbc

Browse files
committed
remove influence from magnetic configuration on BVAnalyzer for oxi states builder
1 parent a0b409b commit cbe4cbc

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

emmet-core/emmet/core/oxidation_states.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import logging
44
from collections import defaultdict
5+
from copy import deepcopy
56
from typing import TYPE_CHECKING
67

78
import numpy as np
89
from pydantic import Field
910
from pymatgen.analysis.bond_valence import BVAnalyzer
10-
from pymatgen.core import Structure
1111
from pymatgen.core.periodic_table import Specie
1212

1313
from emmet.core.material_property import PropertyDoc
@@ -49,9 +49,11 @@ class OxidationStateDoc(PropertyDoc):
4949

5050
@classmethod
5151
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,
5356
):
54-
5557
# Check if structure already has oxidation states,
5658
# if so pass this along unchanged with "method" == "manualx"
5759
struct_valences: list[float | None] = []
@@ -101,6 +103,15 @@ def from_structure(
101103
}
102104

103105
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+
104115
try:
105116
bva = BVAnalyzer()
106117
valences = bva.get_valences(structure)
@@ -166,7 +177,7 @@ def from_structure(
166177
d["method"] = None
167178

168179
return super().from_structure(
169-
meta_structure=structure,
180+
meta_structure=meta_structure,
170181
**d,
171182
**kwargs,
172183
)

0 commit comments

Comments
 (0)