fix(gromacs): preserve first-seen element order#1031
Conversation
Infer GROMACS atom types in first-seen order when no type_map is supplied. Add a regression fixture matching issue deepmodeling#740 so both atom names and type IDs are checked instead of membership alone. Coding-Agent: Codex Codex-Version: codex-cli 0.144.4 Model: gpt-5.6-sol Reasoning-Effort: xhigh
|
Warning Review limit reached
Next review available in: 58 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe GROMACS reader preserves the first-seen order of unique atom names when inferring types. A ChangesGROMACS atom ordering
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 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 |
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 #1031 +/- ##
=======================================
Coverage 87.01% 87.01%
=======================================
Files 90 90
Lines 8330 8330
=======================================
Hits 7248 7248
Misses 1082 1082 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
wanghan-iapcm
left a comment
There was a problem hiding this comment.
Approving: correct fix for #740. Replacing list(set(names)) with list(dict.fromkeys(names)) makes the inferred atom-name/type order deterministic (first-seen), and atom_types/atom_numbs derive from the same list so they stay consistent; the type_map-given path is unaffected. This intentionally makes first-seen order a contract when no type_map is provided -- accepted as the right direction, consistent with the order-preservation fixes in #1007/#1010. Build and codecov/patch green (docs/readthedocs red is the unrelated emscripten-forge outage, #1035).
Two non-blocking notes: (1) the regression test is a ~95% probabilistic guard -- with PYTHONHASHSEED randomization the old set() coincidentally yields insertion order in ~5% of runs, so it does not deterministically fail on pre-fix code; a fixture with more atom types (coincidence ~1/N!) would make it a guaranteed catch. (2) The bug was actually introduced when a deliberate .sort() was dropped in 223ec89 (2021); first-seen order differs from that pre-2021 alphabetical order, worth noting since the comment frames set-hash-order as the sole prior behavior.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
tests/gromacs/type_order.gro (1)
7-8: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick winRemove the extra blank line after the box record.
The GROMACS reader treats a non-EOF blank line as another frame header, then attempts to parse EOF as an atom count. This fixture will therefore fail with
ValueErrorinstead of loading one frame.Proposed fix
7 1.01400 1.01400 1.01400 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 -8🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/gromacs/type_order.gro` around lines 7 - 8, Remove the extra blank line immediately following the box record in the type_order fixture, ensuring the file ends directly after the box data so the GROMACS reader loads exactly one frame without interpreting EOF as another frame header.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@tests/gromacs/type_order.gro`:
- Around line 7-8: Remove the extra blank line immediately following the box
record in the type_order fixture, ensuring the file ends directly after the box
data so the GROMACS reader loads exactly one frame without interpreting EOF as
another frame header.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 62dddc44-309d-4bd0-9c51-7e7dfe199c51
📒 Files selected for processing (3)
dpdata/formats/gromacs/gro.pytests/gromacs/type_order.grotests/test_gromacs_gro.py
Coding-Agent: Codex Codex-Version: codex-cli 0.144.4 Model: gpt-5.6-sol Reasoning-Effort: xhigh
Fixes #740.
Use stable first-seen element ordering when no GROMACS type_map is supplied.
Tests:
cd tests && python -m unittest test_gromacs_groWhy existing tests missed it: Most tests supplied type_map or asserted only set membership, not atom-name/type ordering.
Coding agent: Codex
Codex version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning effort: xhigh
Summary by CodeRabbit
.grofiles..grofixture and a unit test to verify atom type inference follows the order atom names first appear.