Skip to content

feat: support virial in qe/traj #859

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: devel
Choose a base branch
from

Conversation

wanghan-iapcm
Copy link
Contributor

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

Summary by CodeRabbit

  • New Features
    • Added support for reading and processing virial (stress) data from files, enabling calculation and storage of virial tensors for each structure.
  • Tests
    • Introduced new tests to verify correct handling of virial data and to ensure proper error handling when file data is inconsistent.

Copy link

codspeed-hq bot commented Aug 4, 2025

CodSpeed Instrumentation Performance Report

Merging #859 will not alter performance

Comparing wanghan-iapcm:feat-qe-traj-vir (aa3053b) with devel (efa66a7)

Summary

✅ 2 untouched benchmarks

Copy link

coderabbitai bot commented Aug 4, 2025

📝 Walkthrough

Walkthrough

Support for reading and processing virial (stress) data from ".str" files was added to the to_system_data function in dpdata/qe/traj.py. This includes file existence checks, unit conversion, and consistency validation. Corresponding tests were introduced in tests/test_qe_cp_traj.py to verify correct virial extraction and error handling for inconsistent step keys. Additionally, multiple new test data files were added under tests/qe.traj/si and tests/qe.traj/si.wrongstr directories to support these tests.

Changes

Cohort / File(s) Change Summary
Virial Support in QE Trajectory Parsing
dpdata/qe/traj.py
Added logic in to_system_data to read ".str" files, check step consistency, convert stress to virials, and store results. Introduced new unit conversion constant and imported os for file checks.
Virial Data Testing
tests/test_qe_cp_traj.py
Added TestVirial class with tests for correct virial extraction and error raising on inconsistent step keys. No changes to existing tests.
Test Data for Correct Virial Parsing
tests/qe.traj/si/*
Added multiple new files (si.cel, si.evp, si.for, si.in, si.pos, si.str) containing simulation input and output data for silicon system tests.
Test Data for Inconsistent Step Key Error
tests/qe.traj/si.wrongstr/*
Added multiple new files (si.cel, si.evp, si.for, si.in, si.pos, si.str) with data designed to trigger step key inconsistency errors during virial parsing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant LabeledSystem
    participant to_system_data
    participant Filesystem

    User->>LabeledSystem: Initialize from path with format "qe/cp/traj"
    LabeledSystem->>to_system_data: Call to_system_data(path)
    to_system_data->>Filesystem: Check for ".str" file
    alt ".str" file exists
        to_system_data->>Filesystem: Read stress tensor data
        to_system_data->>Filesystem: Read coordinate/cell data
        to_system_data->>to_system_data: Validate step key consistency
        to_system_data->>to_system_data: Convert stress (GPa) to virials (eV/bohr³)
        to_system_data->>LabeledSystem: Return data with "virials"
    else ".str" file missing
        to_system_data->>Filesystem: Read coordinate/cell data only
        to_system_data->>LabeledSystem: Return data without "virials"
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Note

⚡️ Unit Test Generation is now available in beta!

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


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between aa3053b and 64d06a3.

📒 Files selected for processing (1)
  • tests/test_qe_cp_traj.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_qe_cp_traj.py
✨ 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: 1

🧹 Nitpick comments (1)
dpdata/qe/traj.py (1)

235-259: Verify the virial calculation physics and optimize volume computation.

The implementation is well-structured and follows good practices. However, there are two concerns:

  1. Physics verification needed: In continuum mechanics, virial is typically defined as -stress × volume. The current implementation uses stress × volume without the negative sign. Please verify this is correct for your specific application.

  2. Minor optimization: The reshape(-1) on line 253 is unnecessary since np.linalg.det() already returns a 1D array.

-        volumes = np.linalg.det(data["cells"] / length_convert).reshape(-1)
+        volumes = np.linalg.det(data["cells"] / length_convert)

The rest of the implementation correctly:

  • Checks file existence before processing
  • Validates step consistency between coordinate and stress files
  • Handles unit conversions properly
  • Stores results in the expected format
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between efa66a7 and a5565c1.

📒 Files selected for processing (2)
  • dpdata/qe/traj.py (3 hunks)
  • tests/test_qe_cp_traj.py (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: Python package
dpdata/qe/traj.py

[warning] 59-59: UserWarning: unsupported ibrav 8 if no .cel file, the cell conversion may be wrong.

⏰ 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/qe/traj.py (2)

14-14: LGTM!

The os import is appropriately added and used for file existence checking in the virial handling code.


25-25: LGTM!

The unit conversion constant follows the established pattern and is correctly defined for converting stress data from GPa to eV/bohr³.

tests/test_qe_cp_traj.py (1)

72-94: LGTM!

The test method properly validates the virial functionality:

  • Correctly checks the expected shape (2, 3, 3) for virial tensors
  • Uses np.testing.assert_almost_equal for appropriate numerical precision comparison
  • Tests both frames of virial data with specific expected values
  • Provides comprehensive coverage of the new virial reading functionality

Copy link

codecov bot commented Aug 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.44%. Comparing base (5aade0d) to head (64d06a3).
⚠️ Report is 3 commits behind head on devel.

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #859      +/-   ##
==========================================
+ Coverage   85.40%   85.44%   +0.04%     
==========================================
  Files          82       82              
  Lines        7571     7592      +21     
==========================================
+ Hits         6466     6487      +21     
  Misses       1105     1105              

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

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Han Wang <[email protected]>
Copy link

codspeed-hq bot commented Aug 5, 2025

CodSpeed WallTime Performance Report

Merging #859 will not alter performance

Comparing wanghan-iapcm:feat-qe-traj-vir (64d06a3) with devel (c129cc3)

Summary

✅ 2 untouched benchmarks

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