Skip to content

Fix default_magmoms type hint in MagneticOrderingsMaker - #1650

Open
computron wants to merge 2 commits into
materialsproject:mainfrom
computron:fix/magnetic-orderings-default-magmoms-type
Open

computron wants to merge 2 commits into
materialsproject:mainfrom
computron:fix/magnetic-orderings-default-magmoms-type

Conversation

@computron

Copy link
Copy Markdown
Member

Problem. MagneticOrderingsMaker.default_magmoms is annotated dict[Element, float], but enumerate_magnetic_orderings takes dict[str, float] and pymatgen looks moments up by site.species_string. Element keys never match ("Fe" in {Element("Fe"): 1} is False), so a user who follows the type hint gets ValueError: Not detected as magnetic from the enumerator.

Credit to @Luguza, who found this while porting the exchange workflow in #1528 (comment).

Fix. Annotate dict[str, float] and state in the docstring that keys are element symbols.

Tested. Ran MagneticStructureEnumerator on a rock-salt FeO cell: {Element("Fe"): 1.0} raises the error above, {"Fe": 1.0} gets past it. The module imports with the new annotation. This changes only the annotation and docstring, so no new test.

🤖 Generated with Claude Code

computron and others added 2 commits November 12, 2026 10:10
The field was annotated dict[Element, float], but enumerate_magnetic_orderings
takes dict[str, float] and pymatgen looks moments up by species string, so
Element keys never match. Spotted by @Luguza in materialsproject#1528.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@computron

Copy link
Copy Markdown
Member Author

I think this is ready to merge. Unsure who is the correct reviewer - @esoteric-ephemera ?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant