Skip to content

Commit

Permalink
Added threshold_ordering parameter to CollinearMagneticStructureAnaly…
Browse files Browse the repository at this point in the history
…zer 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>
  • Loading branch information
3 people authored Jan 25, 2024
1 parent 0b8be98 commit cb2f490
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
11 changes: 8 additions & 3 deletions pymatgen/analysis/magnetism/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(
set_net_positive: bool = True,
threshold: float = 0,
threshold_nonmag: float = 0.1,
threshold_ordering: float = 1e-8,
):
"""
If magnetic moments are not defined, moments will be
Expand Down Expand Up @@ -132,6 +133,9 @@ def __init__(
threshold_nonmag: number (in Bohr magneton)
below which nonmagnetic ions (with no magmom specified
in default_magmoms) will be rounded to zero
threshold_ordering: number (absolute of sum of all magmoms,
in Bohr magneton) below which total magnetization is treated as zero
when defining magnetic ordering. Defaults to 1e-8.
"""
if default_magmoms:
self.default_magmoms = default_magmoms
Expand Down Expand Up @@ -289,6 +293,7 @@ def __init__(
structure = structure.get_primitive_structure(use_site_props=True)

self.structure = structure
self.threshold_ordering = threshold_ordering

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

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

if abs(total_magnetization) > 1e-8 and is_potentially_ferromagnetic:
if abs(total_magnetization) > self.threshold_ordering and is_potentially_ferromagnetic:
return Ordering.FM
if abs(total_magnetization) > 1e-8:
if abs(total_magnetization) > self.threshold_ordering:
return Ordering.FiM
if max_magmom > 0:
return Ordering.AFM
Expand Down
5 changes: 3 additions & 2 deletions tests/analysis/magnetism/test_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ def test_magnetic_properties(self):
assert mag_struct_analyzer.get_exchange_group_info() == ("Fm-3m", 225)

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

def test_str(self):
msa = CollinearMagneticStructureAnalyzer(self.NiO_AFM_001)
Expand Down

0 comments on commit cb2f490

Please sign in to comment.