Skip to content

fix(gromacs): preserve first-seen element order#1031

Open
njzjz-bot wants to merge 3 commits into
deepmodeling:masterfrom
njzjz-bot:fix/issue-740
Open

fix(gromacs): preserve first-seen element order#1031
njzjz-bot wants to merge 3 commits into
deepmodeling:masterfrom
njzjz-bot:fix/issue-740

Conversation

@njzjz-bot

@njzjz-bot njzjz-bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #740.

Use stable first-seen element ordering when no GROMACS type_map is supplied.

Tests: cd tests && python -m unittest test_gromacs_gro

Why 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

  • Bug Fixes
    • Preserved the first-seen order of atom names when importing GROMACS .gro files.
    • Ensured inferred atom counts and type IDs remain stable and consistent across conversions.
  • Tests
    • Added a new .gro fixture and a unit test to verify atom type inference follows the order atom names first appear.

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
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. dpdata labels Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@njzjz, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ae8a457-4fd6-4c9c-a9ab-bcf212c0462a

📥 Commits

Reviewing files that changed from the base of the PR and between 18a2dd6 and d2e8956.

📒 Files selected for processing (3)
  • dpdata/formats/gromacs/gro.py
  • tests/gromacs/type_order.gro
  • tests/test_gromacs_gro.py
📝 Walkthrough

Walkthrough

The GROMACS reader preserves the first-seen order of unique atom names when inferring types. A .gro fixture and unit test verify the resulting atom names, counts, and type IDs without an explicit type map.

Changes

GROMACS atom ordering

Layer / File(s) Summary
Ordered atom inference and regression coverage
dpdata/formats/gromacs/gro.py, tests/gromacs/type_order.gro, tests/test_gromacs_gro.py
Atom names are deduplicated while preserving input order, and the new fixture-based test verifies the inferred names, counts, and type IDs.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: preserving first-seen ordering for GROMACS element names.
Linked Issues check ✅ Passed The code and test changes address #740 by keeping atom names and type IDs in first-seen order without a type_map.
Out of Scope Changes check ✅ Passed The added fixture and test directly support the ordering fix and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codspeed-hq

codspeed-hq Bot commented Jul 16, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

✅ 2 untouched benchmarks


Comparing njzjz-bot:fix/issue-740 (d2e8956) with master (b3c88c6)

Open in CodSpeed

@codecov

codecov Bot commented Jul 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.01%. Comparing base (b3c88c6) to head (d2e8956).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@wanghan-iapcm wanghan-iapcm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 18, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Remove 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 ValueError instead 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

📥 Commits

Reviewing files that changed from the base of the PR and between b3c88c6 and c0e379e.

📒 Files selected for processing (3)
  • dpdata/formats/gromacs/gro.py
  • tests/gromacs/type_order.gro
  • tests/test_gromacs_gro.py

Coding-Agent: Codex
Codex-Version: codex-cli 0.144.4
Model: gpt-5.6-sol
Reasoning-Effort: xhigh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dpdata lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Unexpected element order from gro to lammps data file

2 participants