Skip to content

fix: raise runtime error when the vasp long ions per type bug is triggered#861

Merged
wanghan-iapcm merged 1 commit intodeepmodeling:develfrom
wanghan-iapcm:fix-long-ions-per-type
Aug 6, 2025
Merged

fix: raise runtime error when the vasp long ions per type bug is triggered#861
wanghan-iapcm merged 1 commit intodeepmodeling:develfrom
wanghan-iapcm:fix-long-ions-per-type

Conversation

@wanghan-iapcm
Copy link
Contributor

@wanghan-iapcm wanghan-iapcm commented Aug 6, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling to detect and alert users when there is a mismatch between atom counts and types in VASP OUTCAR files, preventing silent data inconsistencies.
  • Refactor

    • Enhanced file handling for frame extraction to ensure files are properly closed and code is more maintainable.
  • Tests

    • Added a new test to verify correct error reporting for OUTCAR files with more than 10 atom types.

@wanghan-iapcm wanghan-iapcm requested a review from njzjz August 6, 2025 08:48
@codecov
Copy link

codecov bot commented Aug 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.43%. Comparing base (c129cc3) to head (f0ab50f).
⚠️ Report is 33 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #861      +/-   ##
==========================================
+ Coverage   85.41%   85.43%   +0.01%     
==========================================
  Files          82       82              
  Lines        7577     7580       +3     
==========================================
+ Hits         6472     6476       +4     
+ Misses       1105     1104       -1     

☔ 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.

@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

📝 Walkthrough

Walkthrough

A runtime check was introduced in the VASP OUTCAR parser to detect mismatches between atom type names and counts, raising a descriptive error if found. The frame extraction logic was refactored for improved file handling. A new test ensures the error is raised for files with more than 10 atom types, confirming correct bug detection.

Changes

Cohort / File(s) Change Summary
VASP OUTCAR Parsing Refactor & Bug Check
dpdata/vasp/outcar.py
Added a runtime check in system_info for atom type/count mismatch; refactored get_frames to use a context manager and delegate logic to a new helper function _get_frames_lower.
Test for Atom Type Mismatch Handling
tests/test_vasp_outcar.py
Added TestVaspOUTCARLongIonTypes to verify that a RuntimeError is raised for OUTCAR files with >10 atom types.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant get_frames
    participant _get_frames_lower
    participant system_info

    User->>get_frames: Call with OUTCAR file
    get_frames->>_get_frames_lower: Open file and delegate
    _get_frames_lower->>system_info: Parse system info
    system_info-->>_get_frames_lower: (If atom type/count mismatch) Raise RuntimeError
    _get_frames_lower-->>get_frames: Return frames or propagate error
    get_frames-->>User: Return frames or propagate error
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Suggested reviewers

  • njzjz

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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: 0

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

135-144: Remove unused variable assignment.

The test correctly verifies the RuntimeError is raised for the VASP bug condition, but the variable assignment is unnecessary within the assertRaises context.

Apply this diff to fix the unused variable:

         with self.assertRaises(RuntimeError) as c:
-            ss = dpdata.LabeledSystem("poscars/outcar.longit/OUTCAR")
+            dpdata.LabeledSystem("poscars/outcar.longit/OUTCAR")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c129cc3 and f0ab50f.

📒 Files selected for processing (2)
  • dpdata/vasp/outcar.py (2 hunks)
  • tests/test_vasp_outcar.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
tests/test_vasp_outcar.py

140-140: Local variable ss is assigned to but never used

Remove assignment to unused variable ss

(F841)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: benchmark
🔇 Additional comments (3)
dpdata/vasp/outcar.py (3)

98-104: Excellent runtime validation for VASP bug detection.

This runtime check effectively detects the known VASP ≤ 6.3 bug where more than 10 atom types cause mismatches between atom counts and type names. The error message is descriptive and provides helpful guidance to use vasprun.xml as an alternative.


141-149: Good refactoring for safer file handling.

Using a context manager ensures proper file closure and follows Python best practices. The delegation to _get_frames_lower maintains the original functionality while improving code organization.


152-217: Well-structured helper function extraction.

The _get_frames_lower function properly extracts the core frame parsing logic while maintaining the same functionality. The underscore prefix correctly indicates this is an internal helper function.

@wanghan-iapcm
Copy link
Contributor Author

also fix the unclosed file issue when the exception is raised.

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 6, 2025

CodSpeed WallTime Performance Report

Merging #861 will not alter performance

Comparing wanghan-iapcm:fix-long-ions-per-type (f0ab50f) with devel (c129cc3)

Summary

✅ 2 untouched benchmarks

@wanghan-iapcm wanghan-iapcm merged commit 8263565 into deepmodeling:devel Aug 6, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants