fix: build pymatgen Molecule species from atom_types order (#994)#1010
Conversation
…ing#994) PyMatgenMoleculeFormat.to_system() built the species list by expanding grouped atom_names/atom_numbs, but passed coords in atom_types order. When atoms are not grouped by type, species were assigned to the wrong coordinates. Build species per-atom from atom_types, matching the coord order and the sibling Structure exporter (line 37). Adds a regression test that fails on master (['H','H','O'] vs ['H','O','H']) and passes with this change.
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1010 +/- ##
==========================================
- Coverage 86.87% 86.87% -0.01%
==========================================
Files 89 89
Lines 8266 8264 -2
==========================================
- Hits 7181 7179 -2
Misses 1085 1085 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR fixes a bug in ChangesSpecies ordering fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Sequence Diagram(s)Not applicable; the change is a localized bug fix without multi-component interaction flow. Suggested labels: bug, tests Suggested reviewers: none identified from the provided context Poem: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #994.
Summary
PyMatgenMoleculeFormat.to_system()built thespecieslist by expanding groupedatom_names/atom_numbs(e.g.H, H, O), but passedcoordsin theiratom_typesorder (e.g.H, O, H). When atoms are not grouped by type, the resultingpymatgen.core.Moleculeassigns species to the wrong coordinates.Change
Build
speciesper-atom fromatom_types, matching the coordinate order — the same construction the sibling Structure exporter already uses in this file:This is the fix suggested in the issue.
Testing
test_ungrouped_atom_types_species_match_coords) using the reporter's reproducer: species now follow the coordinate order (H, O, H) and each site sits on its original coordinate. It fails on master and passes with this change.ruff checkandruff format --checkclean.Disclosure: authored with AI assistance (Claude Code); reviewed by me and I'll shepherd it through review.
Summary by CodeRabbit
Bug Fixes
Tests