Skip to content

Commit cb2f490

Browse files
kaueltzenjanosh
andauthored
Added threshold_ordering parameter to CollinearMagneticStructureAnalyzer in addition to PR #3574 (#3577)
* Modified ordering property of CollinearMagneticStructureAnalyzer to account for floating point imprecision, added test for that. * improve CollinearMagneticStructureAnalyzer.ordering doc str, drop isclose in favor abs(tot_mag) > 1e-8 * compress tests/files/magnetic.example.CuO.mcif * add comment with source DOI for mcif file * link PR that added CuO AFM test * Added treshold_ordering for determination of magnetic ordering in CollinearMagneticStructureAnalyzer. * Added test case that demonstrates different ordering values dependent on threshold_ordering parameter. * document default threshold_ordering, refactor test --------- Co-authored-by: kueltzen <kueltzen@sv2218.zit.bam.de> Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
1 parent 0b8be98 commit cb2f490

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

pymatgen/analysis/magnetism/analyzer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def __init__(
8585
set_net_positive: bool = True,
8686
threshold: float = 0,
8787
threshold_nonmag: float = 0.1,
88+
threshold_ordering: float = 1e-8,
8889
):
8990
"""
9091
If magnetic moments are not defined, moments will be
@@ -132,6 +133,9 @@ def __init__(
132133
threshold_nonmag: number (in Bohr magneton)
133134
below which nonmagnetic ions (with no magmom specified
134135
in default_magmoms) will be rounded to zero
136+
threshold_ordering: number (absolute of sum of all magmoms,
137+
in Bohr magneton) below which total magnetization is treated as zero
138+
when defining magnetic ordering. Defaults to 1e-8.
135139
"""
136140
if default_magmoms:
137141
self.default_magmoms = default_magmoms
@@ -289,6 +293,7 @@ def __init__(
289293
structure = structure.get_primitive_structure(use_site_props=True)
290294

291295
self.structure = structure
296+
self.threshold_ordering = threshold_ordering
292297

293298
@no_type_check # ignore seemingly false mypy errors
294299
@staticmethod
@@ -483,7 +488,7 @@ def ordering(self) -> Ordering:
483488
"""Applies heuristics to return a magnetic ordering for a collinear
484489
magnetic structure. Result is not guaranteed to be correct, just a best
485490
guess. Tolerance for minimum total magnetization to be considered
486-
ferro/ferrimagnetic is 1e-8.
491+
ferro/ferrimagnetic is self.threshold_ordering and defaults to 1e-8.
487492
488493
Returns:
489494
Ordering: Enum with values FM: ferromagnetic, FiM: ferrimagnetic,
@@ -508,9 +513,9 @@ def ordering(self) -> Ordering:
508513

509514
is_potentially_ferromagnetic = np.all(magmoms >= 0) or np.all(magmoms <= 0)
510515

511-
if abs(total_magnetization) > 1e-8 and is_potentially_ferromagnetic:
516+
if abs(total_magnetization) > self.threshold_ordering and is_potentially_ferromagnetic:
512517
return Ordering.FM
513-
if abs(total_magnetization) > 1e-8:
518+
if abs(total_magnetization) > self.threshold_ordering:
514519
return Ordering.FiM
515520
if max_magmom > 0:
516521
return Ordering.AFM

tests/analysis/magnetism/test_analyzer.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,9 @@ def test_magnetic_properties(self):
189189
assert mag_struct_analyzer.get_exchange_group_info() == ("Fm-3m", 225)
190190

191191
# https://github.com/materialsproject/pymatgen/pull/3574
192-
mag_struct_analyzer = CollinearMagneticStructureAnalyzer(self.CuO_expt)
193-
assert mag_struct_analyzer.ordering == Ordering.AFM
192+
for threshold, expected in [(1e-8, Ordering.AFM), (1e-20, Ordering.FiM)]:
193+
mag_struct_analyzer = CollinearMagneticStructureAnalyzer(self.CuO_expt, threshold_ordering=threshold)
194+
assert mag_struct_analyzer.ordering == expected
194195

195196
def test_str(self):
196197
msa = CollinearMagneticStructureAnalyzer(self.NiO_AFM_001)

0 commit comments

Comments
 (0)