Skip to content
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

fix: qe input blocks not seperated by empty lines #724

Merged
merged 6 commits into from
Sep 20, 2024

Conversation

wanghan-iapcm
Copy link
Contributor

@wanghan-iapcm wanghan-iapcm commented Sep 19, 2024

the qe support only parse input file, in which cell blocks are separated by empty lines, like

ATOMIC_SPECIES
 Na  22.989769  Na_ONCV_PBE-1.0.upf
                                                          
CELL_PARAMETERS {angstrom}
 7.171683039200000  0.000000000000000  0.000000000000000    

however, the input file is valid when no empty line exists, like the following

ATOMIC_SPECIES
 Na  22.989769  Na_ONCV_PBE-1.0.upf  
CELL_PARAMETERS {angstrom} 
 7.171683039200000  0.000000000000000  0.000000000000000    

This pr fixes the issue

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Improved handling of Quantum Espresso output data for better parsing and clarity.
    • Enhanced error handling for missing force and stress data.
    • Added configuration parameters for self-consistent field (SCF) calculations for sodium.
  • Bug Fixes

    • Updated functions to prevent unwanted lines in data extraction, ensuring cleaner output.
  • Tests

    • Introduced a new test class to validate the functionality of the dpdata.LabeledSystem class with Quantum Espresso output, enhancing test coverage.

Copy link

coderabbitai bot commented Sep 19, 2024

Walkthrough

Walkthrough

The changes enhance the scf.py module for improved handling of Quantum Espresso output data. A new list of keywords, _QE_BLOCK_KEYWORDS, is established to standardize block identification in output files. The get_block function is modified to utilize this list, while the get_stress function is updated to return None when no stress data is found. Additionally, a new test class TestNa is introduced to validate the functionality of the dpdata.LabeledSystem class with a specific Quantum Espresso output file, ensuring accurate atom and force data.

Changes

Files Change Summary
dpdata/qe/scf.py Added _QE_BLOCK_KEYWORDS list; modified get_block to use this list; updated get_stress to return None instead of empty when no stress data is found.
tests/qe.scf/na.in Introduced configuration parameters for SCF calculation for sodium, including sections for control, system, and electron configurations.
tests/test_qe_pw_scf.py Added TestNa class with a test method to validate dpdata.LabeledSystem functionality for sodium atom configurations in a Quantum Espresso output file.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SCFModule as SCF Module
    participant OutputFile as Quantum Espresso Output File
    participant TestSuite as Test Suite

    User->>SCFModule: Request data extraction
    SCFModule->>OutputFile: Read output data
    SCFModule->>SCFModule: Identify blocks using _QE_BLOCK_KEYWORDS
    SCFModule->>OutputFile: Extract forces and stress data
    alt No stress data found
        SCFModule-->>User: Return None
    else Stress data found
        SCFModule-->>User: Return stress data
    end

    User->>TestSuite: Run tests
    TestSuite->>SCFModule: Validate LabeledSystem with output data
    TestSuite-->>User: Return test results
Loading

Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 345aedd and 3b5033c.

Files ignored due to path filters (1)
  • tests/qe.scf/na.out is excluded by !**/*.out
Files selected for processing (3)
  • dpdata/qe/scf.py (2 hunks)
  • tests/qe.scf/na.in (1 hunks)
  • tests/test_qe_pw_scf.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/qe.scf/na.in
Files skipped from review as they are similar to previous changes (2)
  • dpdata/qe/scf.py
  • tests/test_qe_pw_scf.py

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

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.
    -- Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    -- @coderabbitai modularize this function.
  • 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 generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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

@wanghan-iapcm wanghan-iapcm changed the title fix: qe input file not seperated by empty lines fix: qe input blocks not seperated by empty lines Sep 19, 2024
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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 480242e and 345aedd.

Files selected for processing (2)
  • dpdata/qe/scf.py (3 hunks)
  • tests/test_qe_pw_scf.py (1 hunks)
Additional context used
Ruff
tests/test_qe_pw_scf.py

194-194: Local variable b2a is assigned to but never used

Remove assignment to unused variable b2a

(F841)

Additional comments not posted (5)
dpdata/qe/scf.py (4)

14-26: LGTM!

The addition of the _QE_BLOCK_KEYWORDS list is a good practice for standardizing the parsing of QE output data. It improves code readability and maintainability.


34-39: LGTM!

The modification of the get_block function to utilize the _QE_BLOCK_KEYWORDS list enhances the robustness of block extraction. It ensures that only relevant lines are included in the returned block, preventing the inclusion of unwanted lines that could disrupt data parsing.


131-132: LGTM!

The modification of the get_force function to raise a RuntimeError when no force data is found improves error handling. It provides clearer feedback to users, making it easier to identify and address issues related to missing force data in the output file.


145-145: LGTM!

The modification of the get_stress function to return None when no stress data is found clarifies the function's behavior. It allows for better handling of the function's output and makes it easier to differentiate between the absence of stress data and an empty stress tensor.

tests/test_qe_pw_scf.py (1)

191-234: LGTM!

The new test class TestNa is a valuable addition to the test suite. It thoroughly validates the functionality of the dpdata.LabeledSystem class when processing a Quantum ESPRESSO output file for a sodium atom configuration.

The test method checks various properties of the labeled system, including the number of atoms, atom names, number of frames, atom types, coordinates, cell dimensions, and forces. The assertions confirm that the system correctly identifies three sodium atoms, verifies their names, and checks that the coordinates and cell parameters match expected values. It also ensures that the forces acting on the atoms are zero, indicating a stable configuration.

The use of np.testing.assert_array_equal and np.testing.assert_allclose functions ensures that the comparisons are precise, allowing for numerical tolerance in floating-point operations.

Overall, this addition enhances the test coverage for the dpdata library by specifically targeting sodium atom configurations and ensures that the dpdata.LabeledSystem class can correctly process Quantum ESPRESSO output files and extract relevant information.

Tools
Ruff

194-194: Local variable b2a is assigned to but never used

Remove assignment to unused variable b2a

(F841)

class TestNa(unittest.TestCase):
def test(self):
ss = dpdata.LabeledSystem("qe.scf/na.out", fmt="qe/pw/scf")
b2a = dpdata.unit.LengthConversion("bohr", "angstrom").value()
Copy link

Choose a reason for hiding this comment

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

Remove the unused variable b2a.

The local variable b2a is assigned the value of dpdata.unit.LengthConversion("bohr", "angstrom").value() but it is not used anywhere else in the test method.

Apply this diff to remove the unused variable:

-        b2a = dpdata.unit.LengthConversion("bohr", "angstrom").value()
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
b2a = dpdata.unit.LengthConversion("bohr", "angstrom").value()
Tools
Ruff

194-194: Local variable b2a is assigned to but never used

Remove assignment to unused variable b2a

(F841)

Copy link

codspeed-hq bot commented Sep 19, 2024

CodSpeed Performance Report

Merging #724 will not alter performance

Comparing wanghan-iapcm:fix-qe-in (3b5033c) with devel (480242e)

Summary

✅ 2 untouched benchmarks

Copy link

codecov bot commented Sep 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.53%. Comparing base (480242e) to head (3b5033c).

Additional details and impacted files
@@            Coverage Diff             @@
##            devel     #724      +/-   ##
==========================================
+ Coverage   84.51%   84.53%   +0.01%     
==========================================
  Files          81       81              
  Lines        7155     7156       +1     
==========================================
+ Hits         6047     6049       +2     
+ Misses       1108     1107       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@wanghan-iapcm wanghan-iapcm merged commit 2648d50 into deepmodeling:devel Sep 20, 2024
12 checks passed
@wanghan-iapcm wanghan-iapcm deleted the fix-qe-in branch September 20, 2024 00:29
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.

[Bug] QE input file not successfully parsed when information blocks are not seperated by an empty line
2 participants