Skip to content

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

Open
pxlxingliang wants to merge 6 commits intodeepmodeling:masterfrom
pxlxingliang:abacus-relax
Open

support to read coord/cell from STRU_ION*_D in abacus/relax#957
pxlxingliang wants to merge 6 commits intodeepmodeling:masterfrom
pxlxingliang:abacus-relax

Conversation

@pxlxingliang
Copy link
Contributor

@pxlxingliang pxlxingliang commented Mar 18, 2026

fix #951

Summary by CodeRabbit

  • New Features

    • Improved relaxation handling to ingest missing structure data from generated structure outputs and ensure coordinates/cells are populated and correctly scaled.
    • Coordinate/lattice scaling applied earlier in processing to produce consistent Å units.
  • Bug Fixes

    • Extended cleanup to drop entries with NaN in energies, coordinates, or cell data.
  • Tests

    • Added end-to-end tests and supporting fixture data for relaxation workflows.

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

codspeed-hq bot commented Mar 18, 2026

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 pxlxingliang:abacus-relax (5f4745c) with master (26171f2)

Open in CodSpeed

@coderabbitai
Copy link

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: 62bbe1c5-f6a6-4c2f-9b92-18a9f5fc298d

📥 Commits

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

📒 Files selected for processing (2)
  • dpdata/abacus/relax.py
  • tests/abacus.relax.readFromSTRUIOND/coords.npy

📝 Walkthrough

Walkthrough

Adds STRU_ION*_D discovery and parsing to the ABACUS relax reader so intermediate relaxation snapshots (coordinates/cells) are incorporated into frames; updates coordinate conversion to angstroms, expands NaN pruning, and adds a test fixture and unit test validating multi-frame reads.

Changes

Cohort / File(s) Summary
Core ABACUS relax code
dpdata/abacus/relax.py
Added get_relax_stru_files(output_dir); extended get_coords_from_log(loglines, natoms, stru_files=None) to accept STRU files and fill missing coords/cells from STRU_ION*_D; applied bohr→Å conversions earlier; broadened NaN pruning; updated get_frame() to call get_relax_stru_files() and thread STRU files into parsing; added glob import.
Test fixtures: ABACUS outputs
tests/abacus.relax.readFromSTRUIOND/INPUT, .../KPT, .../OUT.ABACUS/STRU_ION*_D, tests/abacus.relax.readFromSTRUIOND/STRU
Added a complete set of ABACUS relaxation output fixtures including multiple STRU_ION*_D snapshot files and final STRU_ION_D to exercise STRU-derived coordinate/cell extraction.
Tests
tests/test_abacus_relax.py
Added TestABACUSRelaxReadFromSTRUIOND with setUp() and test_results() that assert energies, cells, coords, forces, stress, and virials against saved arrays (8-decimal precision).

Sequence Diagram(s)

sequenceDiagram
    participant Reader as LabeledSystem.get_frame
    participant LogParser as get_coords_from_log
    participant FS as Filesystem
    participant STRUParser as STRU reader (get_relax_stru_files / STRU_ION*_D)

    Reader->>FS: locate ABACUS output dir
    Reader->>STRUParser: get_relax_stru_files(output_dir)
    STRUParser-->>Reader: list of STRU_ION*_D paths
    Reader->>FS: read log file lines
    Reader->>LogParser: get_coords_from_log(loglines, natoms, stru_files)
    LogParser->>STRUParser: open STRU_ION*_D as needed
    STRUParser-->>LogParser: coordinates / cells for missing frames
    LogParser-->>Reader: frames with energies, coords, cells, forces, stress (with bohr→Å applied)
    Reader->>Reader: prune NaN frames and assemble LabeledSystem
Loading

(Note: colored rectangles not required for simple flow.)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • wanghan-iapcm
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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 (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding support to read coordinates and cells from STRU_ION*_D files in the abacus/relax module.
Linked Issues check ✅ Passed The PR successfully addresses issue #951 by implementing support to read all frames from STRU_ION*_D files, enabling complete relaxation trajectories to be parsed rather than just the first frame.
Out of Scope Changes check ✅ Passed All changes are focused on the objective of reading coordinates and cells from STRU_ION*_D files in abacus/relax; test files and fixtures are appropriately scoped.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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

@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

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

Labels

abacus dpdata 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

1 participant