fix: skip zero-force fabrication when ABACUS MD dump lacks FORCE columns#1008
fix: skip zero-force fabrication when ABACUS MD dump lacks FORCE columns#1008abhi-0203 wants to merge 3 commits into
Conversation
When an ABACUS MD dump file does not contain FORCE columns (i.e., dump_force=0), the parser previously initialized forces as a zero array and always assigned it to the output data dict. This fabricated misleading zero forces instead of correctly omitting the forces key. Now get_coords_from_dump() returns None for forces when calc_force is False, and get_frame() only includes 'forces' in the data dict when actual force data was parsed. Closes deepmodeling#1000
for more information, see https://pre-commit.ci
📝 WalkthroughWalkthroughThe ABACUS MD dump parser now treats forces as optional, allocating ChangesABACUS MD no-force handling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 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
|
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/abacus.md.noforce/OUT.autotest/MD_dump (1)
1-23: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick winAdd
tests/abacus.md.noforce/OUT.autotest/running_md.log
dpdata/formats/abacus/md.py:get_framestill unconditionally opensrunning_md.log, so this fixture will hitFileNotFoundErrorbeforetest_no_force_columnsreaches the no-force path. Add a 2-frame log with matching energies.🤖 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/abacus.md.noforce/OUT.autotest/MD_dump` around lines 1 - 23, The abacus MD fixture is missing the running_md.log file that dpdata/formats/abacus/md.py:get_frame always opens, so the no-force test cannot proceed. Add a matching 2-frame running_md.log fixture alongside MD_dump, and make sure its frame count and energies align with the existing MDSTEP entries so test_no_force_columns can exercise the no-force path without FileNotFoundError.
🧹 Nitpick comments (1)
dpdata/formats/abacus/md.py (1)
118-124: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueRedundant
forces is not Nonecheck.Since
forcesis allocated exactly whencalc_forceisTrue(Line 75) and never reassigned toNoneafterwards,forces is not Noneis always true whenevercalc_forceis true. The extra check adds no protection and slightly obscures intent.♻️ Simplify condition
- if calc_force and forces is not None: + if calc_force:🤖 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 `@dpdata/formats/abacus/md.py` around lines 118 - 124, Simplify the force parsing condition in the ABACUS MD reader by removing the redundant `forces is not None` check. In `dpdata.formats.abacus.md`, the `forces` array is already created in the `calc_force` path and is not reassigned, so update the condition around the force assignment in the parsing loop to rely on `calc_force` alone and keep the intent clear.
🤖 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/abacus.md.noforce/OUT.autotest/MD_dump`:
- Around line 1-23: The abacus MD fixture is missing the running_md.log file
that dpdata/formats/abacus/md.py:get_frame always opens, so the no-force test
cannot proceed. Add a matching 2-frame running_md.log fixture alongside MD_dump,
and make sure its frame count and energies align with the existing MDSTEP
entries so test_no_force_columns can exercise the no-force path without
FileNotFoundError.
---
Nitpick comments:
In `@dpdata/formats/abacus/md.py`:
- Around line 118-124: Simplify the force parsing condition in the ABACUS MD
reader by removing the redundant `forces is not None` check. In
`dpdata.formats.abacus.md`, the `forces` array is already created in the
`calc_force` path and is not reassigned, so update the condition around the
force assignment in the parsing loop to rely on `calc_force` alone and keep the
intent clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cd5c5adc-e4d6-42ad-87f0-2e6a86ce7e66
📒 Files selected for processing (5)
dpdata/formats/abacus/md.pytests/abacus.md.noforce/INPUTtests/abacus.md.noforce/OUT.autotest/MD_dumptests/abacus.md.noforce/STRUtests/test_abacus_md.py
The test fixture at tests/abacus.md.noforce/ was missing running_md.log, which dpdata/formats/abacus/md.py:get_frame unconditionally opens. This caused FileNotFoundError when running test_no_force_columns. Add a minimal 2-frame running_md.log with matching energies to fix the test. Addresses CodeRabbit review comment on PR deepmodeling#1008
|
Addressed CodeRabbit review comments:
All 10 ABACUS MD tests pass. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1008 +/- ##
=======================================
Coverage 86.87% 86.88%
=======================================
Files 89 89
Lines 8268 8270 +2
=======================================
+ Hits 7183 7185 +2
Misses 1085 1085 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
When an ABACUS MD dump file does not contain FORCE columns (i.e., ), the parser previously initialized forces as a zero array and always assigned it to the output data dict. This fabricated misleading zero forces instead of correctly omitting the forces key.
Now returns for forces when is , and only includes in the data dict when actual force data was parsed.
Changes
Test Plan
Closes #1000
Summary by CodeRabbit
Bug Fixes
Tests