Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix floating point imprecision error in ordering property of CollinearMagneticStructureAnalyzer #3574

Merged
merged 6 commits into from
Jan 23, 2024

Conversation

kaueltzen
Copy link
Contributor

Summary

The ordering property of the CollinearMagneticStructureAnalyzer class is set depending on the total_magnetization = abs(sum(magmoms)). Due to floating point imprecision, the sum of magmoms can adapt values close to zero instead of zero. This can, for example, lead to collinear AFM structures being misclassified as FiM.

This was resolved by replacing if total_magnetization > 0 with if not isclose(total_magnetization, 0, abs_tol=1e-8).
A test to determine the magnetic ordering of MAGNDATA entry 1.62 (CuO) which would have failed with the previous code was added.

Source mcif:
https://www.cryst.ehu.es/magndata/index.php?index=1.62
doi: 10.1088/0022-3719/21/15/023

Open questions

@janosh

  1. Is an absolute tolerance of abs_tol=1e-8 a reasonable choice for "being close to zero" here?
  2. I included a test file (tests/files/magnetic.example.CuO.mcif) from MAGNDATA because this was also done for magnetic.example.NiO.mcif - hope this is okay?

@janosh janosh added fix Bug fix PRs magmoms Magnetism related labels Jan 23, 2024
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @kaueltzen, esp. for adding a test right away! 👍 this looks great.

@janosh janosh merged commit f392c8d into materialsproject:master Jan 23, 2024
17 of 22 checks passed
magnetic structure. Result is not guaranteed for correctness.
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we should make this adaptable when defining the instance the class if we are not sure about the tolerance yet.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, wanted to add that but forgot. PRs welcome!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaueltzen will hopefully open another PR as it was one of the questions in the PR!

janosh added a commit that referenced this pull request Jan 25, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PRs magmoms Magnetism related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants