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

Adding a function that could deal with the magnetic_force and spin when using the ABACUS's deltaspin module #657

Closed
wants to merge 126 commits into from

Conversation

RenguangLiu
Copy link

@RenguangLiu RenguangLiu commented May 15, 2024

Adding a new function, two files were changed.

I add three parameters in the data when reading data from the OUT.ABACUS/running_scf.log.

When we use the deltaspin module during the scf calculation, the dpdata could grep the magnetic force and spin to the system and print the modified coords.npy and forces.npy.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected import statement for py3Dmol to ensure proper functionality.
  • Refactor

    • Reorganized and reformatted import statements across multiple plugins for improved code readability.
    • Adjusted method signatures and added new functions to enhance the functionality of specific formats.
  • Chores

    • Updated .pre-commit-config.yaml with new URLs and revisions for repositories.
    • Modified .gitattributes to enforce line endings for Python test files.

Copy link

coderabbitai bot commented May 15, 2024

Walkthrough

The recent update focuses on code quality improvements, reorganization, and minor functional enhancements across multiple files. Key changes include fixing import statements, reformatting code, and adding new functions to handle specific data in the abacus module. Additionally, the .pre-commit-config.yaml and .gitattributes files have been updated for better code management and consistency in line endings.

Changes

File(s) Change Summary
dpdata/plugins/3dmol.py Corrected import statement for py3Dmol and fixed indexing in types.
dpdata/plugins/__init__.py Reordered and reformatted import statements.
dpdata/plugins/abacus.py, dpdata/abacus/scf.py Reorganized imports, adjusted indentation, updated method calls, and added new functions for handling magnetic and spin data.
dpdata/plugins/amber.py Adjusted method signatures in AmberMDFormat and from_labeled_system.
dpdata/plugins/ase.py Removed from __future__ import annotations, adjusted type annotations, and reorganized imports.
dpdata/plugins/cp2k.py, dpdata/plugins/dftbplus.py, dpdata/plugins/fhi_aims.py, dpdata/plugins/gaussian.py Made formatting and spacing adjustments.
dpdata/plugins/deepmd.py Refactored code by removing redundant imports and adjusting method signatures.
dpdata/deepmd/comp.py Added coords_deltaspin parameter and handling for force_deltaspin in the dump function.
.pre-commit-config.yaml Updated URLs and revisions for repositories, adjusted comments, and reformatted file structure.
.gitattributes Added *.py test eol=lf pattern for line endings.

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.

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

Out of diff range and nitpick comments (1)
dpdata/abacus/scf.py (1)

Line range hint 370-401: Remove commented-out print statements.

Commented-out code should be removed to maintain code cleanliness.

-    # print(force_deltaspin)
-    # print(coords_deltaspin)
-    # print(spin)
-    # print(mag_forces)
-    # print(force)
-    # print(coords)
-    # print("atom_names = ", data['atom_names'])
-    # print("natoms = ", data['atom_numbs'])
-    # print("types = ", data['atom_types'])
-    # print("cells = ", data['cells'])
-    # print("coords = ", data['coords'])
-    # print("energy = ", data['energies'])
-    # print("force = ", data['forces'])
-    # print("virial = ", data['virials'])
-    # print("spin = ", data['spin'])
-    # print("mag_forces = ", data['mag_forces'])
-    # print("force_deltaspin = ", data['force_deltaspin'])
-    # print("coords_deltaspin = ", data['coords_deltaspin'])

dpdata/deepmd/comp.py Outdated Show resolved Hide resolved
dpdata/abacus/scf.py Outdated Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
dpdata/abacus/scf.py Outdated Show resolved Hide resolved
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: 4

dpdata/abacus/scf.py Outdated Show resolved Hide resolved
dpdata/abacus/scf.py Outdated Show resolved Hide resolved
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: 3

Out of diff range and nitpick comments (7)
dpdata/abacus/scf.py (7)

Line range hint 26-26: Use format specifiers instead of percent format for better readability and consistency.

- print("Can not find file %s" % ifile)
+ print("Can not find file {}".format(ifile))

Line range hint 94-94: Use format specifiers instead of percent format for better readability and consistency.

- print("coord_type = %s" % coord_type)
+ print("coord_type = {}".format(coord_type))

Line range hint 134-134: Use format specifiers instead of percent format for better readability and consistency.

- print("Input coordination type is invalid.\n Only direct and cartesian are accepted.")
+ print("Input coordination type is invalid.\n Only direct and cartesian are accepted.")

Line range hint 527-527: Use format specifiers instead of percent format for better readability and consistency.

- out += "%.3f " % mass[iele]
+ out += "{:.3f} ".format(mass[iele])

Line range hint 531-531: Use format specifiers instead of percent format for better readability and consistency.

- out += "%s\n" % pp_file[iele]
+ out += "{}\n".format(pp_file[iele])

Line range hint 540-540: Use format specifiers instead of percent format for better readability and consistency.

- out += "%s\n" % numerical_orbital[iele]
+ out += "{}\n".format(numerical_orbital[iele])

Line range hint 545-545: Use format specifiers instead of percent format for better readability and consistency.

- out += "NUMERICAL_DESCRIPTOR\n%s\n" % numerical_descriptor
+ out += "NUMERICAL_DESCRIPTOR\n{}\n".format(numerical_descriptor)

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

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

Out of diff range and nitpick comments (7)
dpdata/abacus/scf.py (7)

Line range hint 26-26: Use format specifiers instead of percent format for better readability and consistency.

- print("Can not find file %s" % ifile)
+ print("Can not find file {}".format(ifile))

Line range hint 94-94: Use format specifiers instead of percent format for better readability and consistency.

- print("coord_type = %s" % coord_type)
+ print("coord_type = {}".format(coord_type))

Line range hint 134-134: Use format specifiers instead of percent format for better readability and consistency.

- path_out = os.path.join(fname, "OUT.%s/running_scf.log" % suffix)
+ path_out = os.path.join(fname, "OUT.{}/running_scf.log".format(suffix))

Line range hint 530-530: Use format specifiers instead of percent format for better readability and consistency.

- inlines = ["ntype %d" % nele]
+ inlines = ["ntype {}".format(nele)]

Line range hint 534-534: Use format specifiers instead of percent format for better readability and consistency.

- out += "%.3f " % mass[iele]
+ out += "{:.3f} ".format(mass[iele])

Line range hint 543-543: Use format specifiers instead of percent format for better readability and consistency.

- out += "%s\n" % pp_file[iele]
+ out += "{}\n".format(pp_file[iele])

Line range hint 548-548: Use format specifiers instead of percent format for better readability and consistency.

- out += "%s\n" % numerical_orbital[iele]
+ out += "{}\n".format(numerical_orbital[iele])

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

dpdata/abacus/scf.py Outdated Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
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: 3

dpdata/abacus/scf.py Outdated Show resolved Hide resolved
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: 3

dpdata/abacus/scf.py Show resolved Hide resolved
dpdata/abacus/scf.py Outdated Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
@RenguangLiu
Copy link
Author

@amcadmus @chazeon I cloned the original dpdata code into my local space. But failed to pip install with these codes. Now, I add some function into the dpdata to deal with the deltaspin_scf abacus calculation results. And now, it failed with the PR process. I checked my code. It should be workable. Could you please help me with it?

Defaulting to user installation because normal site-packages is not writeable
Processing /mnt/d/AISI/dpdata
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Installing backend dependencies ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: UNKNOWN
  Building wheel for UNKNOWN (pyproject.toml) ... done
  Created wheel for UNKNOWN: filename=UNKNOWN-0.2.19.dev20+ge1f02fd.d20240515-py3-none-any.whl size=4091 sha256=85056635321a8add11d86137b7469a82fa56dd77b985682e5def93568b00e9df
  Stored in directory: /tmp/pip-ephem-wheel-cache-9kbvnwiy/wheels/00/6a/08/3bb0e14df3403c9233763f1104d7951eb1cd83c31155a6d7b0
Successfully built UNKNOWN
Installing collected packages: UNKNOWN
  Attempting uninstall: UNKNOWN
    Found existing installation: UNKNOWN 0.1.dev698+g658a511
    Uninstalling UNKNOWN-0.1.dev698+g658a511:
      Successfully uninstalled UNKNOWN-0.1.dev698+g658a511
Successfully installed UNKNOWN-0.2.19.dev20+ge1f02fd.d20240515

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

dpdata/abacus/scf.py Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
dpdata/abacus/scf.py Show resolved Hide resolved
@RenguangLiu RenguangLiu requested a review from njzjz May 21, 2024 05:26
Copy link
Member

@njzjz njzjz left a comment

Choose a reason for hiding this comment

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

It looks like you changed the line ending of each file from LF to CRLF, which should be reverted

@njzjz njzjz closed this May 22, 2024
@njzjz njzjz reopened this May 22, 2024
njzjz and others added 2 commits May 22, 2024 18:34
Signed-off-by: Jinzhe Zeng <jinzhe.zeng@rutgers.edu>
@RenguangLiu
Copy link
Author

It looks like you changed the line ending of each file from LF to CRLF, which should be reverted

I don't know in what step led me to make this mistake. I will change the format and resubmit again.

Comment on lines +380 to +384
data["mag_forces"] = mag_forces[np.newaxis, :, :]
data["spin"] = spin[np.newaxis, :, :]
data["coords_deltaspin"] = coords_deltaspin[np.newaxis, :, :]
data["force_deltaspin"] = force_deltaspin[np.newaxis, :, :]
data["deltaspin"] = deltaspin
Copy link
Member

Choose a reason for hiding this comment

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

Still, these data types should be added to DTYPES, otherwise I don't think indexing, slicing, or appending will work.

dpdata/dpdata/system.py

Lines 1193 to 1198 in 1d87e82

DTYPES: tuple[DataType, ...] = System.DTYPES + (
DataType("energies", np.ndarray, (Axis.NFRAMES,)),
DataType("forces", np.ndarray, (Axis.NFRAMES, Axis.NATOMS, 3)),
DataType("virials", np.ndarray, (Axis.NFRAMES, 3, 3), required=False),
DataType("atom_pref", np.ndarray, (Axis.NFRAMES, Axis.NATOMS), required=False),
)

Comment on lines +397 to +400
# print("spin = ", data['spin'])
# print("mag_forces = ", data['mag_forces'])
# print("force_deltaspin = ", data['force_deltaspin'])
# print("coords_deltaspin = ", data['coords_deltaspin'])
Copy link
Member

Choose a reason for hiding this comment

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

commented codes should be removed

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.

3 participants