Skip to content

Add CP2K support for dpgen2 - #190

Closed
Cloudac7 wants to merge 10 commits into
deepmodeling:masterfrom
Cloudac7:cp2k-support
Closed

Cloudac7 wants to merge 10 commits into
deepmodeling:masterfrom
Cloudac7:cp2k-support

Conversation

@Cloudac7

@Cloudac7 Cloudac7 commented Feb 18, 2024 •

Copy link
Copy Markdown

As described in #180 , dpgen2 did not support CP2K.
This PR add RunCp2k and is tested to be OK to generate fp tasks.

Thus solved #180.

Summary by CodeRabbit

  • New Features

    • Introduced CP2K support with new classes for preparing and running CP2K tasks.
    • Added functionality for generating CP2K input files from user configurations.
    • Included new test cases for CP2K input generation and task execution.
  • Bug Fixes

    • None
  • Documentation

    • None
  • Refactor

    • None
  • Style

    • None
  • Tests

    • Added test cases for Cp2kInputs and RunCp2k classes.
  • Chores

    • None
  • Revert

    • None

@njzjz njzjz linked an issue Feb 18, 2024 that may be closed by this pull request
@codecov

codecov Bot commented Feb 18, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 91.36691% with 12 lines in your changes are missing coverage. Please review.

Project coverage is 87.69%. Comparing base (76c9657) to head (3ccfe50).

❗ Current head 3ccfe50 differs from pull request most recent head 61fbc00

Please upload reports for the commit 61fbc00 to get more accurate results.

Files Patch % Lines
dpgen2/fp/cp2k_input.py 92.85% 7 Missing ⚠️
dpgen2/fp/cp2k.py 87.50% 5 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #190      +/-   ##
==========================================
+ Coverage   84.63%   87.69%   +3.06%     
==========================================
  Files          94       85       -9     
  Lines        5140     4322     -818     
==========================================
- Hits         4350     3790     -560     
+ Misses        790      532     -258     

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

@wanghan-iapcm wanghan-iapcm left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I would recommend supporting the fp method cp2k in fpop and wrap the operators like what @zjgemi does for abacus

@Andy6M

Andy6M commented May 18, 2024

Copy link
Copy Markdown

It seems that only the three elements C, N, and H and the corresponding pseudopotentials are considered in the code, and once there are other elements in the system, the code may be incorrect.

@Cloudac7

Cloudac7 commented May 22, 2024 •

Copy link
Copy Markdown
Author

It seems that only the three elements C, N, and H and the corresponding pseudopotentials are considered in the code, and once there are other elements in the system, the code may be incorrect.

No, it is just a default dict as placeholder. This PR would be soon refactored.

@coderabbitai

coderabbitai Bot commented May 22, 2024 •

Copy link
Copy Markdown
Walkthrough

Walkthrough

The changes introduce functionalities for integrating CP2K, a computational chemistry software package, into the dpgen2 framework. This integration includes adding new classes for preparing and running CP2K tasks, generating CP2K input files, and handling structural data. Additionally, new test cases are created to ensure the correctness of these functionalities. The updates enhance the capability of dpgen2 to support CP2K simulations, making it more versatile for computational chemistry applications.

Changes

Files/Paths Change Summary
dpgen2/fp/__init__.py Added imports for CP2K-related classes and a dictionary entry for "cp2k".
dpgen2/fp/cp2k.py Introduced PrepCp2k and RunCp2k classes with methods for CP2K task preparation and execution.
dpgen2/fp/cp2k_input.py Added functionality for generating CP2K input files, including dictionary updates and structural data handling.
tests/fp/data.cp2k/coord_n_cell.inc Introduced coordinate and cell information for Na atoms in a crystal structure.
tests/fp/data.cp2k/input.inp Added configuration settings for a CP2K simulation, including global settings, DFT parameters, and atomic details.
tests/fp/data.cp2k/input.json Defined parameters for a CP2K simulation in JSON format.
tests/fp/data.cp2k/sys-2/type.raw Included type information for a system.
tests/fp/data.cp2k/sys-2/type_map.raw Introduced type mapping for Na.
tests/fp/test_cp2k.py Added test cases for Cp2kInputs and RunCp2k classes to validate CP2K input generation and task execution.

Recent Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 76c9657 and 61fbc00.
Files selected for processing (9)
  • dpgen2/fp/init.py (2 hunks)
  • dpgen2/fp/cp2k.py (1 hunks)
  • dpgen2/fp/cp2k_input.py (1 hunks)
  • tests/fp/data.cp2k/coord_n_cell.inc (1 hunks)
  • tests/fp/data.cp2k/input.inp (1 hunks)
  • tests/fp/data.cp2k/input.json (1 hunks)
  • tests/fp/data.cp2k/sys-2/type.raw (1 hunks)
  • tests/fp/data.cp2k/sys-2/type_map.raw (1 hunks)
  • tests/fp/test_cp2k.py (1 hunks)
Files skipped from review due to trivial changes (4)
  • tests/fp/data.cp2k/coord_n_cell.inc
  • tests/fp/data.cp2k/input.json
  • tests/fp/data.cp2k/sys-2/type.raw
  • tests/fp/data.cp2k/sys-2/type_map.raw
Additional Context Used
Ruff (31)
dpgen2/fp/cp2k.py (14)

6-6: typing.Dict imported but unused


8-8: typing.Optional imported but unused


9-9: typing.Set imported but unused


11-11: typing.Union imported but unused


15-15: numpy imported but unused


18-18: dargs.ArgumentEncoder imported but unused


19-19: dargs.Variant imported but unused


20-20: dargs.dargs imported but unused


23-23: dflow.python.OP imported but unused


24-24: dflow.python.OPIO imported but unused


25-25: dflow.python.Artifact imported but unused


26-26: dflow.python.BigParameter imported but unused


27-27: dflow.python.FatalError imported but unused


28-28: dflow.python.OPIOSign imported but unused

dpgen2/fp/cp2k_input.py (8)

2-2: pathlib.Path imported but unused


6-6: typing.List imported but unused


8-8: typing.Set imported but unused


9-9: typing.Tuple imported but unused


10-10: typing.Union imported but unused


17-17: dargs.ArgumentEncoder imported but unused


18-18: dargs.Variant imported but unused


19-19: dargs.dargs imported but unused

tests/fp/test_cp2k.py (9)

1-1: glob imported but unused


2-2: json imported but unused


3-3: os imported but unused


4-4: shutil imported but unused


5-5: sys imported but unused


6-6: textwrap imported but unused


17-17: numpy imported but unused


21-21: .context.dpgen2 imported but unused


33-33: Redefinition of unused json from line 2

Additional comments not posted (5)
tests/fp/data.cp2k/input.inp (1)

1-52: The CP2K configuration file is well-structured and aligns with the standard practices for setting up simulations. Good job on maintaining clarity and organization in the file.

dpgen2/fp/__init__.py (1)

6-10: The addition of CP2K classes to the imports and the fp_styles dictionary is correctly implemented. This setup enables the framework to handle CP2K tasks effectively.

Also applies to: 48-52

tests/fp/test_cp2k.py (1)

31-93: The test cases for CP2K input generation and task execution are comprehensive and well-implemented. These tests should effectively validate the CP2K integration.

dpgen2/fp/cp2k.py (1)

55-164: The implementations of PrepCp2k and RunCp2k classes are robust and well-documented. These classes are crucial for integrating CP2K support into the framework.

dpgen2/fp/cp2k_input.py (1)

51-211: The functions update_dict and iterdict, along with the class Cp2kInputs, are well-implemented and crucial for generating CP2K input files. These implementations are essential for the CP2K support in the framework.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Comment thread tests/fp/test_cp2k.py
Comment on lines +1 to +6
import glob
import json
import os
import shutil
import sys
import textwrap

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider removing unused imports to clean up the code.

- import glob
- import json
- import os
- import shutil
- import sys
- import textwrap
- import numpy as np
- from .context import dpgen2

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.

Suggested change
import glob
import json
import os
import shutil
import sys
import textwrap

Comment thread dpgen2/fp/cp2k.py
Comment on lines +6 to +30
Dict,
List,
Optional,
Set,
Tuple,
Union,
)

import dpdata
import numpy as np
from dargs import (
Argument,
ArgumentEncoder,
Variant,
dargs,
)
from dflow.python import (
OP,
OPIO,
Artifact,
BigParameter,
FatalError,
OPIOSign,
TransientError,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider removing unused imports to clean up the code.

- from typing import Dict, Optional, Set, Union
- import numpy as np
- from dargs import ArgumentEncoder, Variant, dargs
- from dflow.python import OP, OPIO, Artifact, BigParameter, FatalError, OPIOSign

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.

Suggested change
Dict,
List,
Optional,
Set,
Tuple,
Union,
)
import dpdata
import numpy as np
from dargs import (
Argument,
ArgumentEncoder,
Variant,
dargs,
)
from dflow.python import (
OP,
OPIO,
Artifact,
BigParameter,
FatalError,
OPIOSign,
TransientError,
)
from typing import List, Tuple
import dpdata
from dargs import Argument
from dflow.python import TransientError

Comment thread dpgen2/fp/cp2k_input.py
Comment on lines +2 to +20
Path,
)
from typing import (
Dict,
List,
Optional,
Set,
Tuple,
Union,
)

import dpdata
import numpy as np
from dargs import (
Argument,
ArgumentEncoder,
Variant,
dargs,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider removing unused imports to clean up the code.

- from typing import List, Set, Tuple, Union
- from dargs import ArgumentEncoder, Variant, dargs

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.

Suggested change
Path,
)
from typing import (
Dict,
List,
Optional,
Set,
Tuple,
Union,
)
import dpdata
import numpy as np
from dargs import (
Argument,
ArgumentEncoder,
Variant,
dargs,
)
Path,
)
from typing import (
Dict,
Optional,
)
import dpdata
import numpy as np
from dargs import (
Argument,
)

@Andy6M

Andy6M commented Jun 8, 2024

Copy link
Copy Markdown

Hi @Cloudac7 :

Could you please provide the following example files:

An example of the CP2K inp file.
A corresponding input.json file for dpgen2.

These example files would be incredibly helpful for us to quickly get started and verify the new functionality.

Thank you very much!

@zjgemi

zjgemi commented Jul 1, 2024

Copy link
Copy Markdown
Collaborator

#238

@zjgemi

zjgemi commented Jul 5, 2024

Copy link
Copy Markdown
Collaborator

#238
CP2K support is implemented with FPOP. Please feed back if there is any question. I will close this PR.

@zjgemi zjgemi closed this Jul 5, 2024
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.

dpgen2 can not support CP2K

4 participants