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 MagOrderingTransformation by enforcing implicit-zero magnetic moments in SpaceGroupAnalyzer #3070

Merged
merged 7 commits into from
Jul 14, 2023

Conversation

mattmcdermott
Copy link
Member

@mattmcdermott mattmcdermott commented Jun 15, 2023

This PR addresses the bugs described in #3006. To summarize: changes to default magnetic moments introduced in #2727 now mean that structures with only partially defined magnetic moments (e.g., on half the sites) cannot be successfully analyzed by SpaceGroupAnalyzer. This was encountered when performing magnetic ordering enumeration, as the previous default behavior for MagOrderingTransformation does not implicitly yield spins of 0 on the nonmagnetic sites. Altogether this has been fixed with two edits:

  • Fix 1: Introduce logic in SpaceGroupAnalyzer. If any site in the structure has magnetic moments defined, then assume that any undefined ones are implicitly zero.
  • Fix 2: Change the default behavior of MagOrderingTransformation to ensure that all the sites in the transformed structure have labeled spins (this means explicitly defining spin=0), per recommendation by @mkhorton

Todos

  • Still need to write tests!

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • All tests and linting pass.

@mattmcdermott
Copy link
Member Author

mattmcdermott commented Jul 13, 2023

This PR has been open for a while and fixed some of the previous magnetic moment problems. I apologize for not adding tests yet to get it merged.

However, with the recent changes in Species properties (related to spin), theMagOrderingTransformation code is again broken. I don't really understand what happened/changed, and now I am not sure I have the bandwidth to try fixing this again.

Does anyone with more knowledge of this situation able to address? @janosh @shyuep @mkhorton

@janosh
Copy link
Member

janosh commented Jul 13, 2023

Just for clarity, this PR still addresses a relevant bug and is just missing tests? Sounds like the MagOrderingTransformation breaking again is a different problem?

@janosh janosh changed the title [WIP] Bug fix: enforcing implicit-zero magnetic moments in SpaceGroupAnalyzer and MagOrderingTransformation Fix MagOrderingTransformation by enforcing implicit-zero magnetic moments in SpaceGroupAnalyzer Jul 13, 2023
@janosh janosh added fix Bug fix PRs analysis Concerning pymatgen.analysis magmoms Magnetism related labels Jul 13, 2023
@mattmcdermott
Copy link
Member Author

mattmcdermott commented Jul 13, 2023

The original problem this PR addressed is still "fixed"(i.e., enforcing implicit-zero magnetic moments) but the implementation here will need to be reworked to account for the new defaults in how spin is handled.

I am just somewhat confused about specifically why it's broken now and what is the right thing to do... I think @shyuep also expressed that sentiment: 9d0461f

@janosh
Copy link
Member

janosh commented Jul 13, 2023

I am just somewhat confused about specifically why it's broken now and what is the right thing to do... I think @shyuep also expressed that sentiment: 9d0461f

Lol! 😄

Well, I'm happy to merge as is if this is at least a step towards improvement.

@mkhorton
Copy link
Member

mkhorton commented Jul 13, 2023 via email

@shyuep
Copy link
Member

shyuep commented Jul 14, 2023

This fix actually works. I am merging.

@shyuep shyuep merged commit 86bdbdb into materialsproject:master Jul 14, 2023
41 checks passed
@shyuep
Copy link
Member

shyuep commented Jul 14, 2023

I should add that my changes to Specie does not do anything backward incompatible. I was deliberate in making sure all existing code still works. @mattmcdermott 's solution works since it is based on existing ways of determining spin.

@shyuep
Copy link
Member

shyuep commented Jul 14, 2023

Also, no tests are necessary. There is an existing test in MagTransformation. The tests fail previously. Not sure why the Github actions is not detecting it. But I confirm the tests pass now.

@mattmcdermott
Copy link
Member Author

Oh, that is great to hear! Glad you were able to pull this in, @shyuep. Thank you for investigating :)

I should have spent some more time digging yesterday before I brought up that it was broken; it is actually a different section of code that is broken now -- specifically CollinearMagneticStructureAnalyzer. This seems only to be the case when a structure is provided that has a defined spin property but not defined magmoms. Seems to be something that is missed by our current tests.

I just found a simple one-line fix for that, so I will open up a new PR :) thanks again everyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis Concerning pymatgen.analysis fix Bug fix PRs magmoms Magnetism related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants