-
Notifications
You must be signed in to change notification settings - Fork 175
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
Enhance poscar_scale function (/data/gen.py)to detect Selective dynamics #1439
base: devel
Are you sure you want to change the base?
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## devel #1439 +/- ##
==========================================
+ Coverage 48.97% 49.42% +0.44%
==========================================
Files 83 83
Lines 14792 14820 +28
==========================================
+ Hits 7245 7325 +80
+ Misses 7547 7495 -52 ☔ View full report in Codecov by Sentry. |
@CodiumAI-Agent /review --pr_reviewer.inline_code_comments=true |
@CodiumAI-Agent /improve --extend |
PR Analysis
PR Feedback💡 General suggestions: The PR is well-structured and the changes are clear. It would be beneficial to add tests to ensure that the new functionality works as expected. Also, consider handling the case where the "Selective dynamics" line is not directly above the coordinate type line, even though it's not the standard format. ✨ Usage guide:Overview:
With a configuration file, use the following template:
See the review usage page for a comprehensive guide on using this tool. |
if "D" == lines[coord_type_line][0] or "d" == lines[coord_type_line][0]: | ||
lines = poscar_scale_direct(lines, scale) | ||
elif "C" == lines[7][0] or "c" == lines[7][0]: | ||
elif "C" == lines[coord_type_line][0] or "c" == lines[coord_type_line][0]: | ||
lines = poscar_scale_cartesian(lines, scale) |
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.
Suggestion: Use the str.startswith()
method to check the starting character of a string in a case-insensitive manner, instead of checking equality with both the uppercase and lowercase versions of the character. [best practice]
if "D" == lines[coord_type_line][0] or "d" == lines[coord_type_line][0]: | |
lines = poscar_scale_direct(lines, scale) | |
elif "C" == lines[7][0] or "c" == lines[7][0]: | |
elif "C" == lines[coord_type_line][0] or "c" == lines[coord_type_line][0]: | |
lines = poscar_scale_cartesian(lines, scale) | |
if lines[coord_type_line].startswith(("D", "d")): | |
lines = poscar_scale_direct(lines, scale) | |
elif lines[coord_type_line].startswith(("C", "c")): | |
lines = poscar_scale_cartesian(lines, scale) |
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 agree with this comment
raise RuntimeError( | ||
f"Unknown poscar style at line {coord_type_line + 1}: {lines[coord_type_line]}" | ||
) |
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.
Suggestion: The error message in the RuntimeError
could be more informative by specifying that the unknown style is related to the coordinate type. [enhancement]
raise RuntimeError( | |
f"Unknown poscar style at line {coord_type_line + 1}: {lines[coord_type_line]}" | |
) | |
raise RuntimeError( | |
f"Unknown coordinate type at line {coord_type_line + 1}: {lines[coord_type_line]}" | |
) |
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.
So, is it poscar style or coordinate type?
Summary
This pull request updates the
poscar_scale
function in thegen.py
file to enhance its functionality by accurately detecting the presence of "Selective dynamics" in POSCAR files. The update ensures that the coordinate type determination is correctly handled based on whether the "Selective dynamics" line is present, improving the function's reliability and correctness in handling various POSCAR file configurations.Changes Made
Impact
This enhancement allows users to work with a wider variety of POSCAR files, especially those that include the "Selective dynamics" setting, without manually adjusting the script for different file formats. It ensures that the
poscar_scale
function is more adaptable and accurate, providing a robust solution for scaling atomic positions in POSCAR files.Additional Notes
This update assumes that the "Selective dynamics" line, if present, is directly above the coordinate type line in POSCAR files, which is the standard format. Users should ensure that their POSCAR files follow this format for the script to function correctly.