-
Notifications
You must be signed in to change notification settings - Fork 868
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
Fix floating point imprecision error in ordering property of CollinearMagneticStructureAnalyzer #3574
Conversation
…ccount for floating point imprecision, added test for that.
…lose in favor abs(tot_mag) > 1e-8
There was a problem hiding this 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.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!
…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>
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
withif 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
abs_tol=1e-8
a reasonable choice for "being close to zero" here?