Skip to content

support to read coord/cell from STRU_ION*_D in abacus/relax#957

Merged
wanghan-iapcm merged 13 commits intodeepmodeling:masterfrom
pxlxingliang:abacus-relax
Mar 23, 2026
Merged

support to read coord/cell from STRU_ION*_D in abacus/relax#957
wanghan-iapcm merged 13 commits intodeepmodeling:masterfrom
pxlxingliang:abacus-relax

Conversation

@pxlxingliang
Copy link
Copy Markdown
Contributor

@pxlxingliang pxlxingliang commented Mar 18, 2026

fix #951

Summary by CodeRabbit

  • New Features

    • Enhanced ABACUS relaxation structure parsing with improved coordinate and lattice vector unit conversion during parsing.
    • Added fallback logic to recover missing structure data from alternate sources in relaxation workflows.
  • Tests

    • Added comprehensive test coverage for relaxation data reading scenarios.
  • Chores

    • Updated dependency management with Python version-gated requirements.

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 18, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 18, 2026

Merging this PR will degrade performance by 14.24%

⚠️ 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.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 1 untouched benchmark

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
WallTime test_import 9.8 ms 11.4 ms -14.24%

Comparing pxlxingliang:abacus-relax (d3f5707) with master (80abfc5)

Open in CodSpeed

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 133be322-d70b-4bf0-8f4b-4ce38ac7bf68

📥 Commits

Reviewing files that changed from the base of the PR and between d0f691e and 082a7e0.

⛔ Files ignored due to path filters (1)
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/running_cell-relax.log is excluded by !**/*.log
📒 Files selected for processing (12)
  • pyproject.toml
  • tests/abacus.relax.readFromSTRUIOND/INPUT
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION1_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION2_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION3_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION_D
  • tests/abacus.relax.readFromSTRUIOND/cells.npy
  • tests/abacus.relax.readFromSTRUIOND/coords.npy
  • tests/abacus.relax.readFromSTRUIOND/energies.npy
  • tests/abacus.relax.readFromSTRUIOND/forces.npy
  • tests/abacus.relax.readFromSTRUIOND/stress.npy
  • tests/abacus.relax.readFromSTRUIOND/virials.npy
✅ Files skipped from review due to trivial changes (5)
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION2_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION1_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION3_D
  • tests/abacus.relax.readFromSTRUIOND/INPUT
🚧 Files skipped from review as they are similar to previous changes (1)
  • pyproject.toml

📝 Walkthrough

Walkthrough

This PR fixes the issue where only the first frame was read from ABACUS relaxation trajectories. It adds discovery of STRU_ION*_D intermediate structure files, implements fallback logic to populate missing coordinates from these files, and applies unit conversions earlier in the parsing pipeline with enhanced NaN-based structure validation.

Changes

Cohort / File(s) Summary
ABACUS relax trajectory parsing
dpdata/abacus/relax.py
Added get_relax_stru_files() function to discover STRU_ION*_D files; updated get_coords_from_log() signature to accept optional stru_files parameter; moved bohr→angstrom scaling earlier in parsing (both coordinates and cells); added fallback logic to fill missing frames from individual STRU files when log contains energy but not coordinates; enhanced pruning to remove structures with NaN in energy, coords, or cells; updated get_frame() to locate and pass STRU files into coordinate parsing.
ABACUS relax test fixture files
tests/abacus.relax.readFromSTRUIOND/INPUT, tests/abacus.relax.readFromSTRUIOND/STRU, tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION*_D
Added test configuration and structure definition files (INPUT, initial STRU, and three intermediate frame files STRU_ION1_D through STRU_ION3_D) for validating multi-frame trajectory reading.
Test class for STRU reading
tests/test_abacus_relax.py
Added TestABACUSRelaxReadFromSTRUIOND class with setUp and test_results methods to verify energies, cells, coords, forces, stress, and virials are correctly read from ABACUS relaxation outputs.
Dependency configuration
pyproject.toml
Modified lmdb dependency to use Python version gating: pins >=0.98,<1 for Python <3.9 and unpinned for Python ≥3.9.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • wanghan-iapcm
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The pyproject.toml change (lmdb version gating) appears unrelated to the stated objective of reading STRU_ION*_D files in abacus/relax. Remove the pyproject.toml lmdb version gating changes or justify their necessity in relation to the STRU_ION*_D reading functionality.
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support to read coordinates and cell data from STRU_ION*_D files in the abacus/relax module.
Linked Issues check ✅ Passed The PR implements the core requirement from issue #951: correctly parsing all frames in relaxation trajectories by reading coordinates/cells from STRU_ION*_D files instead of only the first frame.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/test_abacus_relax.py (1)

198-200: Please remove commented-out artifact generation code.

This is test-debug residue and can be dropped to keep the suite clean.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/test_abacus_relax.py` around lines 198 - 200, Remove the commented-out
test artifact generation block (the np.save loop) so the test no longer contains
leftover debug code; specifically delete the commented lines that iterate over
the keys list ["energies", "cells", "coords", "forces", "stress", "virials"] and
call np.save with self.system.data (the commented np.save(...) lines), leaving
only the functional test code intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@dpdata/abacus/relax.py`:
- Around line 134-138: get_frame_from_stru returns coordinates/cells in Angstrom
but later code multiplies all frames by bohr2ang, causing STRU-derived frames to
be double-scaled; modify the block that assigns stru-derived data (where
coords[iframe] and cells[iframe] are set from get_frame_from_stru) to normalize
those values back to Bohr (divide by bohr2ang) so the later common conversion is
correct; reference get_frame_from_stru, coords, cells, bohr2ang, stru_files,
stru_file_name, and iframe when locating the change.
- Line 51: Replace the mutable default argument in get_coords_from_log: change
the signature from stru_files=[] to stru_files=None and inside the function set
stru_files = [] if stru_files is None; update any downstream logic that assumes
stru_files is a list to use the initialized local list to avoid shared-state
bugs caused by the original mutable default.

---

Nitpick comments:
In `@tests/test_abacus_relax.py`:
- Around line 198-200: Remove the commented-out test artifact generation block
(the np.save loop) so the test no longer contains leftover debug code;
specifically delete the commented lines that iterate over the keys list
["energies", "cells", "coords", "forces", "stress", "virials"] and call np.save
with self.system.data (the commented np.save(...) lines), leaving only the
functional test code intact.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3ee3a62b-cd30-4386-a867-f3e832e6c647

📥 Commits

Reviewing files that changed from the base of the PR and between 26171f2 and bf5cf3e.

⛔ Files ignored due to path filters (1)
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/running_cell-relax.log is excluded by !**/*.log
📒 Files selected for processing (17)
  • dpdata/abacus/relax.py
  • tests/abacus.relax.readFromSTRUIOND/INPUT
  • tests/abacus.relax.readFromSTRUIOND/KPT
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION1_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION2_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION3_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION4_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION5_D
  • tests/abacus.relax.readFromSTRUIOND/OUT.ABACUS/STRU_ION_D
  • tests/abacus.relax.readFromSTRUIOND/STRU
  • tests/abacus.relax.readFromSTRUIOND/cells.npy
  • tests/abacus.relax.readFromSTRUIOND/coords.npy
  • tests/abacus.relax.readFromSTRUIOND/energies.npy
  • tests/abacus.relax.readFromSTRUIOND/forces.npy
  • tests/abacus.relax.readFromSTRUIOND/stress.npy
  • tests/abacus.relax.readFromSTRUIOND/virials.npy
  • tests/test_abacus_relax.py

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 23, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.65%. Comparing base (80abfc5) to head (d3f5707).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #957      +/-   ##
==========================================
+ Coverage   86.63%   86.65%   +0.02%     
==========================================
  Files          86       86              
  Lines        8006     8019      +13     
==========================================
+ Hits         6936     6949      +13     
  Misses       1070     1070              

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@pyproject.toml`:
- Around line 27-28: The conditional lmdb dependency lines ('lmdb>=0.98,<1;
python_version < "3.9"' and 'lmdb; python_version >= "3.9"') are unrelated to
this PR’s purpose—either revert this change so the pyproject.toml keeps the
original lmdb spec, or move the version-constraint change into its own PR with a
short rationale; if you intentionally changed it here, add a brief comment in
the PR description explaining why Python <3.9 must be pinned to <1 while >=3.9
is unpinned, referencing the lmdb lines so reviewers can find them easily.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6086c0a3-1217-4e32-8508-a21f99233351

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4745c and d0f691e.

📒 Files selected for processing (2)
  • dpdata/abacus/relax.py
  • pyproject.toml

@wanghan-iapcm wanghan-iapcm merged commit 0b6bf2f into deepmodeling:master Mar 23, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

abacus dpdata lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Only the first frame is read using abacus/lcao/relax

2 participants