-
Notifications
You must be signed in to change notification settings - Fork 135
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
feat: support spin for ABACUS #718
Conversation
WalkthroughWalkthroughThe changes focus on enhancing the Changes
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (2)
Files skipped from review as they are similar to previous changes (2)
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? TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
CodSpeed Performance ReportMerging #718 will not alter performanceComparing Summary
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #718 +/- ##
==========================================
+ Coverage 84.42% 84.73% +0.31%
==========================================
Files 81 81
Lines 7095 7345 +250
==========================================
+ Hits 5990 6224 +234
- Misses 1105 1121 +16 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
Outside diff range, codebase verification and nitpick comments (1)
dpdata/abacus/scf.py (1)
Line range hint
530-751
: The enhancements tomake_unlabeled_stru
are impressive!The modifications significantly enhance the functionality of the function by allowing the inclusion of additional atomic properties in the generated STRU file. The new parameters are correctly handled, and the code is well-structured with appropriate error handling and validation checks.
However, there are a couple of areas that could be improved:
- Test Coverage:
The static analysis hints from codecov indicate that some of the added lines are not covered by tests. To ensure the correctness and robustness of the new functionality, it would be beneficial to add tests for the new code paths.If you need any help with writing tests for the new functionality, please let me know. I'd be happy to assist you in improving the test coverage.
- Code Simplification:
The hint from Ruff suggests using a singleif
statement instead of nestedif
statements to improve code readability and simplicity.Consider simplifying the nested
if
statements at lines 604-605 to enhance code clarity. Here's a suggestion:if key is not None and not isinstance(ndarray2list(key), (list, tuple)) and len(key) != atom_numbs: key_name = [name for name, value in locals().items() if value is key][0] print(f"ERROR: make_unlabeled_stru: the length of '{key_name}' ({len(key)}) should be equal to the number of atom number ({atom_numbs}).") return ""This change combines the two conditions into a single
if
statement, making the code more concise and easier to understand.Tools
Ruff
604-605: Use a single
if
statement instead of nestedif
statements(SIM102)
GitHub Check: codecov/patch
[warning] 583-591: dpdata/abacus/scf.py#L583-L591
Added lines #L583 - L591 were not covered by tests
[warning] 595-595: dpdata/abacus/scf.py#L595
Added line #L595 was not covered by tests
[warning] 600-600: dpdata/abacus/scf.py#L600
Added line #L600 was not covered by tests
[warning] 608-610: dpdata/abacus/scf.py#L608-L610
Added lines #L608 - L610 were not covered by tests
[warning] 623-623: dpdata/abacus/scf.py#L623
Added line #L623 was not covered by tests
[warning] 629-630: dpdata/abacus/scf.py#L629-L630
Added lines #L629 - L630 were not covered by tests
[warning] 634-634: dpdata/abacus/scf.py#L634
Added line #L634 was not covered by tests
[warning] 639-641: dpdata/abacus/scf.py#L639-L641
Added lines #L639 - L641 were not covered by tests
[warning] 653-653: dpdata/abacus/scf.py#L653
Added line #L653 was not covered by tests
[warning] 658-659: dpdata/abacus/scf.py#L658-L659
Added lines #L658 - L659 were not covered by tests
[warning] 663-663: dpdata/abacus/scf.py#L663
Added line #L663 was not covered by tests
[warning] 668-669: dpdata/abacus/scf.py#L668-L669
Added lines #L668 - L669 were not covered by tests
[warning] 680-680: dpdata/abacus/scf.py#L680
Added line #L680 was not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spins and mag_forces are not registered, which means that when you dump LabeledSystem
to e.g. deepmd/npy, you won't have spins and mag_forces data output.
UTs detecting the issue are necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 13
Outside diff range, codebase verification and nitpick comments (5)
tests/abacus.spin/INPUT (1)
1-27
: Configuration file appears complete and correct.The configuration parameters are well-defined and appropriate for supporting spin calculations in ABACUS. Consider adding a header comment at the top of the file to briefly describe its purpose and usage.
tests/abacus.spin/STRU (1)
1-21
: Structure file appears complete and correct.The atomic structure definitions are well-defined and appropriate for supporting spin calculations in ABACUS. Consider adding a header comment at the top of the file to briefly describe its purpose and usage.
dpdata/abacus/scf.py (3)
Line range hint
201-250
: Approve modifications toget_coords
and suggest comprehensive testing.The changes to
get_coords
effectively integrate the parsing of new atomic properties usingparse_stru_pos
. It is crucial to ensure that these modifications are covered by comprehensive tests, especially since they involve multiple new data attributes that are critical to the system's modeling capabilities.Would you like assistance in setting up tests to cover these new functionalities?
Line range hint
392-454
: Approve updates toget_frame
and recommend verification of magnetic data integration.The updates to
get_frame
to include magnetic moment and force data are well-implemented. It is recommended to verify the integration of this new data through functional testing to ensure that the magnetic properties are correctly retrieved and represented in the output.Would you like assistance in setting up functional tests to verify the magnetic data integration?
Line range hint
527-754
: Approve enhancements tomake_unlabeled_stru
and suggest enhancing documentation.The enhancements to
make_unlabeled_stru
to include new parameters for movement, velocity, magnetic moments, angles, spin constraints, and lambda values are correctly implemented. It is advisable to enhance the documentation to clearly describe these new parameters and their impact on the output format, ensuring that users can effectively utilize the updated function.Would you like help in updating the documentation to reflect these changes?
Tools
Ruff
610-611: Use a single
if
statement instead of nestedif
statements(SIM102)
GitHub Check: codecov/patch
[warning] 586-594: dpdata/abacus/scf.py#L586-L594
Added lines #L586 - L594 were not covered by tests
[warning] 598-598: dpdata/abacus/scf.py#L598
Added line #L598 was not covered by tests
[warning] 603-603: dpdata/abacus/scf.py#L603
Added line #L603 was not covered by tests
[warning] 614-616: dpdata/abacus/scf.py#L614-L616
Added lines #L614 - L616 were not covered by tests
[warning] 629-629: dpdata/abacus/scf.py#L629
Added line #L629 was not covered by tests
[warning] 635-636: dpdata/abacus/scf.py#L635-L636
Added lines #L635 - L636 were not covered by tests
[warning] 640-640: dpdata/abacus/scf.py#L640
Added line #L640 was not covered by tests
[warning] 645-647: dpdata/abacus/scf.py#L645-L647
Added lines #L645 - L647 were not covered by tests
[warning] 659-659: dpdata/abacus/scf.py#L659
Added line #L659 was not covered by tests
[warning] 664-665: dpdata/abacus/scf.py#L664-L665
Added lines #L664 - L665 were not covered by tests
[warning] 669-669: dpdata/abacus/scf.py#L669
Added line #L669 was not covered by tests
[warning] 674-675: dpdata/abacus/scf.py#L674-L675
Added lines #L674 - L675 were not covered by tests
[warning] 686-686: dpdata/abacus/scf.py#L686
Added line #L686 was not covered by tests
There was a problem hiding this 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
Outside diff range, codebase verification and nitpick comments (2)
dpdata/abacus/scf.py (2)
Line range hint
206-255
: Review ofget_coords
function:This function is responsible for retrieving and storing atomic coordinates and related attributes from structured blocks of data. It utilizes the
parse_stru_pos
function to parse individual lines of atomic data.Observations and Recommendations:
- Integration with
parse_stru_pos
: The function correctly integrates theparse_stru_pos
function to parse each line of atomic data. This modular approach is good for maintainability.- Error Handling: Similar to
parse_stru_pos
, consider adding error handling for cases where the expected data blocks are not found or are malformed.- Performance Considerations: The function processes potentially large data blocks. Ensure that the performance is acceptable for large inputs. Consider optimizations if necessary.
Code Quality:
- The function is structured logically, and the use of helper functions like
get_stru_block
aids in readability.- Consider adding more inline comments explaining the logic, especially in the more complex parsing sections.
Security:
- As with
parse_stru_pos
, ensure that input data is validated and sanitized if it comes from untrusted sources.Documentation:
- The function's purpose and behavior are clear from the context, but adding a docstring describing the parameters, expected input format, and output would enhance understandability.
Tags:
- : The integration with
parse_stru_pos
is handled well.- : For missing error handling and potential performance issues with large inputs.
- : To help in optimizing performance and adding necessary error handling.
Would you like suggestions on optimizing performance or implementing error handling?
Line range hint
394-462
: Review ofget_frame
function:This function is a central part of the module, responsible for retrieving a complete frame of atomic data, including coordinates, energies, forces, and now magnetic moments and forces.
Observations and Recommendations:
- Integration of New Features: The function has been updated to include magnetic data, which is a significant enhancement. The integration seems to be handled correctly, using the
get_mag_force
function.- Error Handling: The function handles file existence checks but could be improved to handle other potential errors, such as parsing errors or data inconsistencies.
- Performance: The function deals with multiple file reads and data parsing operations. Ensure that its performance is acceptable, especially for large input files or numerous frames.
Code Quality:
- The function is well-organized, with clear separation of concerns. Each block of functionality (e.g., reading files, parsing data) is distinct, which aids in readability.
- Consider adding more detailed comments to explain the logic, especially for the new features related to magnetic data.
Security:
- Ensure that all file operations and data parsing are secure, especially if data can come from untrusted sources. Consider adding validation and sanitization steps.
Documentation:
- Update the documentation to reflect the new capabilities of the function, including the handling of magnetic data.
Tags:
- : The updates to include magnetic data are well-integrated.
- : For potential missing error handling and performance concerns.
- : To help in optimizing performance and enhancing error handling.
Would you like suggestions on optimizing performance or enhancing error handling?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you still have may lines not covered by the UT. please check carefully and improve the UTs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use register_data_type instead of hacking all over the code for spins and mag_forces.
Line 1087 in c685e62
def register_data_type(cls, *data_type: DataType): |
Is there some examples or doc to use this function? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (2)
dpdata/abacus/scf.py (2)
Line range hint
236-285
: Review ofget_coords
function:This function retrieves atomic coordinates and other related properties from a structured block of lines. It utilizes the
parse_stru_pos
function to parse individual lines and extract detailed atomic properties.Observations and Recommendations:
- Integration with
parse_stru_pos
: The function effectively integrates the output fromparse_stru_pos
, demonstrating good modularity and reuse of code.- Error Handling: The function assumes that the input lines are well-formed and that all necessary data is present. Consider adding checks to handle cases where the expected data is missing or malformed.
- Performance: The function iterates over the lines multiple times, which could be optimized. Consider processing the lines in a single pass if possible.
Code Quality:
- The use of list comprehensions and numpy for handling numerical data is efficient and concise.
- The function's logic is straightforward, but adding more detailed comments explaining each section would be helpful.
Security:
- If the input data can come from untrusted sources, consider adding mechanisms to validate and sanitize the input data.
Documentation:
- The function is documented with comments explaining the process, which is helpful. Ensure that the documentation is comprehensive and covers all aspects of the function's behavior.
Tags:
- : The basic functionality of retrieving atomic coordinates is implemented correctly.
- : For potential performance issues.
- : To help in optimizing the parsing logic and adding robust error handling.
Line range hint
565-822
: Review ofmake_unlabeled_stru
function:This function generates an unlabeled STRU file from a dictionary of system data. It handles various parameters such as pseudo potential files, orbital files, and atomic properties like magnetic moments and angles.
Observations and Recommendations:
- Complexity and Maintainability: The function is complex due to its handling of multiple parameters and conditions. Consider refactoring to simplify the logic and improve readability.
- Error Handling: The function prints errors but does not raise exceptions or handle errors robustly. Consider raising exceptions for critical errors to ensure that they are handled appropriately in the calling code.
- Performance: The function iterates over multiple lists and performs several checks, which could be optimized. Consider simplifying the logic and reducing the number of iterations.
Code Quality:
- The function uses descriptive variable names and comments, which help in understanding its logic. However, the complexity could be reduced.
- The function modifies the output string directly, which could lead to issues if the function is interrupted. Consider using a more robust method of constructing the output.
Security:
- If the input data can come from untrusted sources, consider adding sanitization and validation to prevent injection attacks or data corruption.
Documentation:
- The function is well-documented with a detailed docstring describing the input and output. Ensure that the documentation is updated if any changes are made to the function's logic or parameters.
Tags:
- : To improve readability and maintainability.
- : For missing error handling.
- : To help in optimizing the function and improving error handling.
Tools
Ruff
646-650: Use a single
if
statement instead of nestedif
statements(SIM102)
There was a problem hiding this 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
Outside diff range, codebase verification and nitpick comments (1)
dpdata/abacus/scf.py (1)
Line range hint
572-832
: Approve changes tomake_unlabeled_stru
with a refactoring suggestion.The modifications to
make_unlabeled_stru
correctly integrate the new attributes into the STRU file generation. The function handles various scenarios for the new attributes and implements the linking of files and handling ofspins
data correctly.However, consider the following refactoring suggestion:
- Refactor the nested
if
statements at lines 653-657 to use a singleif
statement with logical operators. This will improve code readability and maintainability.Here's an example of how you can refactor the nested
if
statements:if key is not None and not isinstance(ndarray2list(key), (list, tuple)) and len(key) != atom_numbs: key_name = [name for name, value in locals().items() if value is key][0] print(f"ERROR: make_unlabeled_stru: the length of '{key_name}' ({len(key)}) should be equal to the number of atom number ({atom_numbs}).") return ""Tools
Ruff
653-657: Use a single
if
statement instead of nestedif
statements(SIM102)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (1)
dpdata/abacus/scf.py (1)
Line range hint
583-832
: Approve the changes tomake_unlabeled_stru
and suggest minor refactoring and improving test coverage.The changes made to the
make_unlabeled_stru
function to include the new parameters and generate the corresponding output in the STRU file are implemented correctly. However, consider the following suggestions:
Use a single
if
statement instead of nestedif
statements at line range 653-657 to improve code readability.The static analysis hints indicate missing test coverage for several lines added to this function. Consider adding more comprehensive unit tests, especially for the lines flagged by the tool, to ensure the correctness of the function across various scenarios.
Would you like assistance in refactoring the code and adding unit tests?
Tools
Ruff
653-657: Use a single
if
statement instead of nestedif
statements(SIM102)
GitHub Check: codecov/patch
[warning] 625-633: dpdata/abacus/scf.py#L625-L633
Added lines #L625 - L633 were not covered by tests
[warning] 637-637: dpdata/abacus/scf.py#L637
Added line #L637 was not covered by tests
[warning] 642-642: dpdata/abacus/scf.py#L642
Added line #L642 was not covered by tests
[warning] 658-659: dpdata/abacus/scf.py#L658-L659
Added lines #L658 - L659 were not covered by tests
[warning] 662-662: dpdata/abacus/scf.py#L662
Added line #L662 was not covered by tests
[warning] 670-670: dpdata/abacus/scf.py#L670
Added line #L670 was not covered by tests
[warning] 681-681: dpdata/abacus/scf.py#L681
Added line #L681 was not covered by tests
[warning] 684-684: dpdata/abacus/scf.py#L684
Added line #L684 was not covered by tests
[warning] 688-688: dpdata/abacus/scf.py#L688
Added line #L688 was not covered by tests
[warning] 693-695: dpdata/abacus/scf.py#L693-L695
Added lines #L693 - L695 were not covered by tests
[warning] 707-707: dpdata/abacus/scf.py#L707
Added line #L707 was not covered by tests
[warning] 712-712: dpdata/abacus/scf.py#L712
Added line #L712 was not covered by tests
[warning] 715-715: dpdata/abacus/scf.py#L715
Added line #L715 was not covered by tests
[warning] 719-719: dpdata/abacus/scf.py#L719
Added line #L719 was not covered by tests
[warning] 724-726: dpdata/abacus/scf.py#L724-L726
Added lines #L724 - L726 were not covered by tests
[warning] 736-738: dpdata/abacus/scf.py#L736-L738
Added lines #L736 - L738 were not covered by tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (1)
dpdata/abacus/scf.py (1)
Line range hint
572-835
: Approve the implementation ofmake_unlabeled_stru
but recommend adding more unit tests.The changes to the
make_unlabeled_stru
function significantly enhance its functionality by supporting the generation of atomic positions with additional properties. The function correctly handles the new parameters and generates the appropriate output format.However, static analysis hints suggest that some lines are not covered by tests. To ensure the correctness of the function across various input scenarios, it is recommended to add more comprehensive unit tests, particularly for the lines that are currently uncovered.
Would you like assistance in writing unit tests for the uncovered lines?
Tools
Ruff
658-662: Use a single
if
statement instead of nestedif
statements(SIM102)
GitHub Check: codecov/patch
[warning] 626-627: dpdata/abacus/scf.py#L626-L627
Added lines #L626 - L627 were not covered by tests
[warning] 630-630: dpdata/abacus/scf.py#L630
Added line #L630 was not covered by tests
[warning] 633-634: dpdata/abacus/scf.py#L633-L634
Added lines #L633 - L634 were not covered by tests
[warning] 636-636: dpdata/abacus/scf.py#L636
Added line #L636 was not covered by tests
[warning] 642-642: dpdata/abacus/scf.py#L642
Added line #L642 was not covered by tests
[warning] 647-647: dpdata/abacus/scf.py#L647
Added line #L647 was not covered by tests
[warning] 663-664: dpdata/abacus/scf.py#L663-L664
Added lines #L663 - L664 were not covered by tests
[warning] 667-667: dpdata/abacus/scf.py#L667
Added line #L667 was not covered by tests
[warning] 675-675: dpdata/abacus/scf.py#L675
Added line #L675 was not covered by tests
[warning] 686-686: dpdata/abacus/scf.py#L686
Added line #L686 was not covered by tests
[warning] 689-689: dpdata/abacus/scf.py#L689
Added line #L689 was not covered by tests
[warning] 693-693: dpdata/abacus/scf.py#L693
Added line #L693 was not covered by tests
[warning] 712-712: dpdata/abacus/scf.py#L712
Added line #L712 was not covered by tests
[warning] 717-717: dpdata/abacus/scf.py#L717
Added line #L717 was not covered by tests
[warning] 720-720: dpdata/abacus/scf.py#L720
Added line #L720 was not covered by tests
[warning] 724-724: dpdata/abacus/scf.py#L724
Added line #L724 was not covered by tests
Please fix errors reported by |
The doc string should be clear enough. dpdata/tests/test_custom_data_type.py Line 56 in c685e62
|
I have added the register codes in dpdata/plugins/abacus.py, but when I dump a dpdata.System to deepmd npy type by
|
You register for |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range and nitpick comments (1)
tests/abacus.scf/stru.ref (1)
1-29
: Changes look good, but consider adding comments to clarify the additional attributes.The file structure and format appear to be correct for an ABACUS input file used for testing purposes. The additional attributes in the atomic positions section, like magnetic moments, angles, and lambda values, seem to be intentional based on the PR objectives related to handling spins and magnetic forces.
Assuming these changes align with the specific testing requirements, they are approved. However, consider adding comments to clarify the meaning and purpose of the additional attributes, if appropriate, to improve the maintainability and readability of the test file.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files ignored due to path filters (3)
tests/abacus.spin/OUT.ABACUS/running_md.log
is excluded by!**/*.log
tests/abacus.spin/OUT.ABACUS/running_relax.log
is excluded by!**/*.log
tests/abacus.spin/OUT.ABACUS/running_scf.log
is excluded by!**/*.log
Files selected for processing (15)
- dpdata/abacus/md.py (3 hunks)
- dpdata/abacus/relax.py (3 hunks)
- dpdata/abacus/scf.py (10 hunks)
- dpdata/plugins/abacus.py (4 hunks)
- tests/abacus.relax/INPUT.spin (1 hunks)
- tests/abacus.relax/STRU.spin (1 hunks)
- tests/abacus.scf/stru.ref (1 hunks)
- tests/abacus.spin/INPUT (1 hunks)
- tests/abacus.spin/INPUT.md (1 hunks)
- tests/abacus.spin/INPUT.relax (1 hunks)
- tests/abacus.spin/INPUT.scf (1 hunks)
- tests/abacus.spin/OUT.ABACUS/MD_dump (1 hunks)
- tests/abacus.spin/STRU (1 hunks)
- tests/test_abacus_spin.py (1 hunks)
- tests/test_abacus_stru_dump.py (2 hunks)
Files skipped from review due to trivial changes (1)
- tests/abacus.relax/INPUT.spin
Files skipped from review as they are similar to previous changes (8)
- dpdata/abacus/md.py
- dpdata/abacus/relax.py
- tests/abacus.relax/STRU.spin
- tests/abacus.spin/INPUT
- tests/abacus.spin/INPUT.relax
- tests/abacus.spin/INPUT.scf
- tests/abacus.spin/OUT.ABACUS/MD_dump
- tests/test_abacus_spin.py
Additional context used
LanguageTool
tests/abacus.spin/INPUT.md
[misspelling] ~9-~9: ‘pw’ zou fout kunnen zijn. Misschien bedoelt u: “p.w.”
Context: ...genelpa basis_type pw symmetry 0 nonco...(NL_SIMPLE_REPLACE_PW)
[misspelling] ~29-~29: In deze afkorting horen punten.
Context: ... 3 md_type nvt md_nstep 3 md_dt ...(NL_SIMPLE_REPLACE_NVT)
[misspelling] ~31-~31: ‘dt’ zou fout kunnen zijn. Misschien bedoelt u: “dat”, “dit”
Context: ... nvt md_nstep 3 md_dt 1 md_tfirst ...(NL_SIMPLE_REPLACE_DT)
Markdownlint
tests/abacus.spin/INPUT.md
11-11: Column: 9
Hard tabs(MD010, no-hard-tabs)
8-8: null
No space after hash on atx style heading(MD018, no-missing-space-atx)
Ruff
dpdata/abacus/scf.py
670-674: Use a single
if
statement instead of nestedif
statements(SIM102)
GitHub Check: codecov/patch
dpdata/abacus/scf.py
[warning] 638-639: dpdata/abacus/scf.py#L638-L639
Added lines #L638 - L639 were not covered by tests
[warning] 642-642: dpdata/abacus/scf.py#L642
Added line #L642 was not covered by tests
[warning] 645-646: dpdata/abacus/scf.py#L645-L646
Added lines #L645 - L646 were not covered by tests
[warning] 648-648: dpdata/abacus/scf.py#L648
Added line #L648 was not covered by tests
[warning] 654-654: dpdata/abacus/scf.py#L654
Added line #L654 was not covered by tests
[warning] 659-659: dpdata/abacus/scf.py#L659
Added line #L659 was not covered by tests
[warning] 675-676: dpdata/abacus/scf.py#L675-L676
Added lines #L675 - L676 were not covered by tests
[warning] 679-679: dpdata/abacus/scf.py#L679
Added line #L679 was not covered by tests
[warning] 687-687: dpdata/abacus/scf.py#L687
Added line #L687 was not covered by tests
[warning] 698-698: dpdata/abacus/scf.py#L698
Added line #L698 was not covered by tests
[warning] 701-701: dpdata/abacus/scf.py#L701
Added line #L701 was not covered by tests
[warning] 705-705: dpdata/abacus/scf.py#L705
Added line #L705 was not covered by tests
[warning] 724-724: dpdata/abacus/scf.py#L724
Added line #L724 was not covered by tests
[warning] 729-729: dpdata/abacus/scf.py#L729
Added line #L729 was not covered by tests
[warning] 732-732: dpdata/abacus/scf.py#L732
Added line #L732 was not covered by tests
[warning] 736-736: dpdata/abacus/scf.py#L736
Added line #L736 was not covered by tests
[warning] 776-776: dpdata/abacus/scf.py#L776
Added line #L776 was not covered by tests
[warning] 793-793: dpdata/abacus/scf.py#L793
Added line #L793 was not covered by tests
[warning] 806-806: dpdata/abacus/scf.py#L806
Added line #L806 was not covered by tests
[warning] 844-844: dpdata/abacus/scf.py#L844
Added line #L844 was not covered by tests
Additional comments not posted (13)
tests/abacus.spin/STRU (1)
1-21
: LGTM!The
STRU
file for the ABACUS spin test case looks good. It follows the standard format and correctly specifies the magnetic moments and selective coordinates for the Fe atoms.The code changes are approved.
tests/abacus.spin/INPUT.md (1)
1-34
: The past review comment is still valid and applicable:Well-structured input file for molecular dynamics simulations.
The file is well-structured and aligns with the PR's objective to enhance the handling of magnetic data in ABACUS. It would be beneficial to include documentation or comments explaining the parameters, especially the new ones related to magnetic data handling, to aid other developers or users in understanding their usage.
Would you like me to help draft the documentation for these parameters?
Tools
LanguageTool
[misspelling] ~9-~9: ‘pw’ zou fout kunnen zijn. Misschien bedoelt u: “p.w.”
Context: ...genelpa basis_type pw symmetry 0 nonco...(NL_SIMPLE_REPLACE_PW)
[misspelling] ~29-~29: In deze afkorting horen punten.
Context: ... 3 md_type nvt md_nstep 3 md_dt ...(NL_SIMPLE_REPLACE_NVT)
[misspelling] ~31-~31: ‘dt’ zou fout kunnen zijn. Misschien bedoelt u: “dat”, “dit”
Context: ... nvt md_nstep 3 md_dt 1 md_tfirst ...(NL_SIMPLE_REPLACE_DT)
Markdownlint
11-11: Column: 9
Hard tabs(MD010, no-hard-tabs)
8-8: null
No space after hash on atx style heading(MD018, no-missing-space-atx)
dpdata/plugins/abacus.py (5)
49-60
: LGTM!The code changes are approved. The
register_data
function correctly registers the optional data types for spins and magnetic forces withdpdata.LabeledSystem
based on their presence in the data.
68-70
: LGTM!The code changes are approved. Calling
register_data
after retrieving the frame data in thefrom_labeled_system
method ofAbacusSCFFormat
ensures that the optional data types for spins and magnetic forces are correctly registered if present.
79-81
: LGTM!The code changes are approved. Calling
register_data
after retrieving the frame data in thefrom_labeled_system
method ofAbacusMDFormat
ensures that the optional data types for spins and magnetic forces are correctly registered if present.
90-92
: LGTM!The code changes are approved. Calling
register_data
after retrieving the frame data in thefrom_labeled_system
method ofAbacusRelaxFormat
ensures that the optional data types for spins and magnetic forces are correctly registered if present.
42-43
: LGTM!The code changes are approved. Deriving
dest_dir
fromfile_name
usingos.path.dirname
in theto_system
method ofAbacusSTRUFormat
simplifies the method's interface and enhances usability while maintaining the core functionality.tests/test_abacus_stru_dump.py (5)
17-20
: LGTM!The changes to the
tearDown
method ensure proper cleanup of temporary files after tests, improving the overall test suite.
32-52
: LGTM!The new
test_dumpStruLinkFile
method enhances the test coverage by validating the creation of symbolic links during the structural data dump. The test checks for the existence of the temporary file and verifies that the expected symbolic links are created correctly.
54-75
: LGTM!The expanded
test_dump_spinconstrain
method improves the robustness of the test suite by including more parameters related to spin constraints and verifying the output against a reference file. This ensures that the functionality related to spin constraints is working as expected.
77-104
: LGTM!The new
test_dump_spin
method further enhances the test coverage by testing the dumping of spin data. The test sets thespins
data in the system and verifies that the dumped STRU file contains the expected spin data.
107-182
: LGTM!The new
TestABACUSParseStru
class significantly enhances the test coverage for theparse_stru_pos
function. Thetest_parse_stru_post
method thoroughly tests the parsing of various input scenarios, ensuring that the function correctly extracts the expected values. Thetest_parse_stru_error
method verifies that the function raises appropriate errors for invalid inputs, improving the robustness of the code. These additions greatly improve the overall quality and reliability of the codebase.dpdata/abacus/scf.py (1)
Line range hint
269-309
: Looks good! Please improve unit test coverage.The changes to the
get_coords
function are well-integrated and provide a more comprehensive set of atomic properties. The use of theparse_stru_pos
function simplifies the parsing logic.However, please ensure that the new code paths are adequately covered by unit tests to maintain a high level of code quality and prevent regressions.
There was a problem hiding this 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
Files selected for processing (1)
- dpdata/abacus/scf.py (11 hunks)
Additional context used
Ruff
dpdata/abacus/scf.py
670-674: Use a single
if
statement instead of nestedif
statements(SIM102)
GitHub Check: codecov/patch
dpdata/abacus/scf.py
[warning] 638-639: dpdata/abacus/scf.py#L638-L639
Added lines #L638 - L639 were not covered by tests
[warning] 642-642: dpdata/abacus/scf.py#L642
Added line #L642 was not covered by tests
[warning] 645-646: dpdata/abacus/scf.py#L645-L646
Added lines #L645 - L646 were not covered by tests
[warning] 648-648: dpdata/abacus/scf.py#L648
Added line #L648 was not covered by tests
[warning] 654-654: dpdata/abacus/scf.py#L654
Added line #L654 was not covered by tests
[warning] 659-659: dpdata/abacus/scf.py#L659
Added line #L659 was not covered by tests
[warning] 675-676: dpdata/abacus/scf.py#L675-L676
Added lines #L675 - L676 were not covered by tests
[warning] 679-679: dpdata/abacus/scf.py#L679
Added line #L679 was not covered by tests
[warning] 687-687: dpdata/abacus/scf.py#L687
Added line #L687 was not covered by tests
[warning] 698-698: dpdata/abacus/scf.py#L698
Added line #L698 was not covered by tests
[warning] 701-701: dpdata/abacus/scf.py#L701
Added line #L701 was not covered by tests
[warning] 705-705: dpdata/abacus/scf.py#L705
Added line #L705 was not covered by tests
[warning] 724-724: dpdata/abacus/scf.py#L724
Added line #L724 was not covered by tests
[warning] 729-729: dpdata/abacus/scf.py#L729
Added line #L729 was not covered by tests
[warning] 732-732: dpdata/abacus/scf.py#L732
Added line #L732 was not covered by tests
[warning] 736-736: dpdata/abacus/scf.py#L736
Added line #L736 was not covered by tests
[warning] 776-776: dpdata/abacus/scf.py#L776
Added line #L776 was not covered by tests
[warning] 789-789: dpdata/abacus/scf.py#L789
Added line #L789 was not covered by tests
[warning] 802-802: dpdata/abacus/scf.py#L802
Added line #L802 was not covered by tests
[warning] 840-840: dpdata/abacus/scf.py#L840
Added line #L840 was not covered by tests
Additional comments not posted (3)
dpdata/abacus/scf.py (3)
269-275
: LGTM!The code changes are approved. The modifications to
get_coords
correctly integrate the new attributes parsed byparse_stru_pos
and ensure they are properly stored and returned.Also applies to: 285-287, 301-308
115-258
: Approve the implementation ofparse_stru_pos
but recommend refactoring, adding error handling, and improving test coverage.The function
parse_stru_pos
is well-implemented with a clear parsing mechanism for various atomic properties. However, consider the following suggestions:
The function is quite complex with multiple nested conditions and loops. Consider refactoring to improve readability and maintainability.
There is no error handling for malformed input lines, which could lead to unexpected behavior or crashes. Add validation checks and error handling mechanisms.
Given the complexity and the critical role of the function, it is crucial to have comprehensive unit tests to ensure its correctness across various input scenarios. The static analysis tool indicates that some lines (e.g., 202) are not covered by tests. Please improve the test coverage.
Would you like assistance in refactoring this function or adding unit tests and error handling?
585-591
: Approve the implementation of the new parameters inmake_unlabeled_stru
but recommend improving test coverage and simplifying a condition.The modifications to
make_unlabeled_stru
correctly handle the new parameters related to movement, velocity, magnetic moments, angles, spin constraints, and lambda values. The changes ensure that these properties are properly formatted and included in the output structure file. The function also includes appropriate error handling and validation for the new parameters.However, please consider the following suggestions:
The static analysis tool indicates that some lines related to the new parameters (e.g., 675-676, 679) are not covered by unit tests. Please improve the test coverage for these lines.
At lines 670-674, consider using a single
if
statement instead of nestedif
statements to simplify the condition, as suggested by the static analysis tool.Also applies to: 665-679, 784-840
dpdata/plugins/abacus.py
Outdated
@Format.register("abacus/scf") | ||
@Format.register("abacus/pw/scf") | ||
@Format.register("abacus/lcao/scf") | ||
class AbacusSCFFormat(Format): | ||
# @Format.post("rot_lower_triangular") | ||
def from_labeled_system(self, file_name, **kwargs): | ||
return dpdata.abacus.scf.get_frame(file_name) | ||
data = dpdata.abacus.scf.get_frame(file_name) | ||
register_data(data) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need to register data if no magnetic label exists?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, in function register_data, it will register spins or mag_forces only when the key is in data.
tests/test_abacus_spin.py
Outdated
self.assertTrue(os.path.isfile(f"{self.dump_path}/set.000/spins.npy")) | ||
self.assertTrue(os.path.isfile(f"{self.dump_path}/set.000/mag_forces.npy")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we use a different filename in the deepmd-kit. What is the expected behavior here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,@wanghan-iapcm ,I need to clarify what the name should be, and they should be the same in DeepMD, LAMMPS, and ABACUS. In previous disccussion, you suggest the name "spins" and approve name "mag_forces".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We haven't had a documentation for spin data in the DeePMD-kit. xref: deepmodeling/deepmd-kit#3760
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@pxlxingliang please follow PR #727 to support the deepmd-kit labeling files doced in deepmodeling/deepmd-kit#3762
dpdata/plugins/abacus.py
Outdated
np.ndarray, | ||
(Axis.NFRAMES, Axis.NATOMS, 3), | ||
required=False, | ||
deepmd_name="mag_force", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's force_mag, not mag_force
Summary by CodeRabbit
New Features
Bug Fixes
Tests