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

Remove duplicate ruff rule in pyproject.toml #3755

Merged
merged 3 commits into from
Apr 13, 2024
Merged

Conversation

Andrew-S-Rosen
Copy link
Member

@Andrew-S-Rosen Andrew-S-Rosen commented Apr 12, 2024

"TID" was listed twice.

Summary by CodeRabbit

  • Chores
    • Updated the linting tool from "TID" to "flake8-tidy-imports" for improved code quality checks.
  • Refactor
    • Restructured the logic for setting y-axis limits in the get_plot function of plotter.py.
    • Simplified the logic for updating the length of current_segment in the prepare_band_input function in bs.py.
    • Consolidated the edge data retrieval logic in the connected_components.py file for a more structured approach.
    • Refactored the logic related to parsing eigenvalues in VASP output files for improved organization.
    • Simplified the logic for determining the encut value in the calculate_ng function of sets.py.
    • Modified the logic for checking istruct in the apply_tags method of structure_vtk.py.
  • Documentation
    • Updated the return type annotation from History node to HistoryNode in the parse_history_node method.
  • Tests
    • Reorganized imports in the test_outputs.py file by switching to import ElementTree from xml.etree.
    • Streamlined import statements in the test_init.py file related to pymatgen.phonon module.

"TID" was listed twice.

Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
Copy link

coderabbitai bot commented Apr 12, 2024

Walkthrough

The recent changes focus on enhancing functionality and improving code structure across various files in the project. From simplifying logic in functions to refining data handling and parsing processes, these updates aim to streamline operations and boost clarity within the codebase.

Changes

Files Change Summary
connected_components.py Consolidated edge data retrieval logic for a more structured approach
cohp.py Restructured from_file to handle cases based on are_multi_center_cobis presence
bs.py Simplified logic for updating current_segment length
outputs.py Refactored eigenvalue parsing in VASP output files
sets.py Simplified logic for determining encut value
plotter.py Restructured y-axis limits setting logic in get_plot function
provenance.py Updated return type annotation in parse_history_node method
structure_vtk.py Modified logic for checking istruct in apply_tags method
pyproject.toml Removed "TID" linting tool and added "flake8-tidy-imports" in lint.select configuration
test_outputs.py, test_init.py Reorganized imports for ElementTree and modules in pymatgen.phonon

Poem

🐇✨
Code changes dance in the digital light,
Logic refined, clarity takes flight.
From TID to flake8, a shift so bright,
In fields of code, progress alight. 🌟📄


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between e2e11a8 and fcefc3d.
Files selected for processing (11)
  • pymatgen/analysis/chemenv/connectivity/connected_components.py (1 hunks)
  • pymatgen/electronic_structure/cohp.py (1 hunks)
  • pymatgen/io/aims/sets/bs.py (1 hunks)
  • pymatgen/io/vasp/outputs.py (3 hunks)
  • pymatgen/io/vasp/sets.py (1 hunks)
  • pymatgen/phonon/plotter.py (1 hunks)
  • pymatgen/util/provenance.py (1 hunks)
  • pymatgen/vis/structure_vtk.py (1 hunks)
  • pyproject.toml (2 hunks)
  • tests/io/vasp/test_outputs.py (1 hunks)
  • tests/phonon/test_init.py (1 hunks)
Files skipped from review due to trivial changes (1)
  • tests/phonon/test_init.py
Files skipped from review as they are similar to previous changes (1)
  • pyproject.toml
Additional comments not posted (51)
pymatgen/io/aims/sets/bs.py (1)

48-51: Simplified logic for updating current_segment["length"] enhances readability and likely improves performance by reducing conditional checks.

pymatgen/util/provenance.py (1)

96-99: Correcting the return type annotation from History node to HistoryNode improves type clarity and correctness.

pymatgen/analysis/chemenv/connectivity/connected_components.py (1)

244-253: Consolidating edge data retrieval logic by checking various key combinations simplifies and structures the approach, enhancing maintainability.

pymatgen/vis/structure_vtk.py (1)

991-991: The change from direct comparison to using not in with a tuple for checking istruct is a good improvement for clarity and future extensibility. This allows for easier addition of more conditions without changing the structure of the condition.

pymatgen/electronic_structure/cohp.py (1)

775-820: The restructuring of the from_file method in the CompleteCohp class to handle are_multi_center_cobis is well-implemented. However, consider adding more detailed comments explaining the logic, especially for the averaging process in lines 787-806. This will improve maintainability and understandability of the code.

tests/io/vasp/test_outputs.py (31)

10-10: Consider adding a docstring to the TestVasprun class to explain its purpose and the functionalities it tests.


Line range hint 28-28: Add a docstring to the test_vasprun_ml method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 38-38: Add a docstring to the test_vasprun_md method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 48-48: Add a docstring to the test_bad_random_seed method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 58-58: Add a docstring to the test_multiple_dielectric method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 68-68: Add a docstring to the test_charge_charge_dielectric method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 78-78: Add a docstring to the test_optical_absorption_coeff method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 88-88: Add a docstring to the test_vasprun_with_more_than_two_unlabelled_dielectric_functions method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 98-98: Add a docstring to the test_bad_vasprun method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 108-108: Add a docstring to the test_runtype method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 118-118: Add a docstring to the test_vdw method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 128-128: Add a docstring to the test_energies method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 138-138: Add a docstring to the test_nonlmn method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 148-148: Add a docstring to the test_standard method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 158-158: Add a docstring to the test_unconverged method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 168-168: Add a docstring to the test_dfpt method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 178-178: Add a docstring to the test_dfpt_ionic method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 188-188: Add a docstring to the test_dfpt_unconverged method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 198-198: Add a docstring to the test_chi method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 208-208: Add a docstring to the test_uniform method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 218-218: Add a docstring to the test_no_projected method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 228-228: Add a docstring to the test_dielectric method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 238-238: Add a docstring to the test_dielectric_vasp608 method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 248-248: Add a docstring to the test_indirect_vasprun method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 258-258: Add a docstring to the test_optical_vasprun method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 268-268: Add a docstring to the test_force_constants method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 278-278: Add a docstring to the test_xe method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 288-288: Add a docstring to the test_invalid_element method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 298-298: Add a docstring to the test_selective_dynamics method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 308-308: Add a docstring to the test_as_dict method to explain what specific aspect of the Vasprun class it is testing.


Line range hint 318-318: Add a docstring to the test_get_band_structure method to explain what specific aspect of the Vasprun class it is testing.

pymatgen/io/vasp/outputs.py (15)

355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Refactor the _generate_nbmax method to improve readability and maintainability.

- def _generate_nbmax(self) -> None:
+ def _calculate_max_g_vectors(self) -> np.ndarray:
      # existing code...
-     self._nbmax = np.max([nbmaxA, nbmaxB, nbmaxC], axis=0).astype(int)
+     return np.max([nbmaxA, nbmaxB, nbmaxC], axis=0).astype(int)

- self._generate_nbmax()
+ self._nbmax = self._calculate_max_g_vectors()

Renaming _generate_nbmax to _calculate_max_g_vectors and changing it to return the calculated values instead of setting them directly improves the method's clarity and testability.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Optimize the loop in _generate_G_points to enhance performance.

Consider using numpy operations to vectorize the loop that calculates G-points, which could significantly speed up the execution if the number of iterations is large.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Verify the normalization factor in evaluate_wavefunc.

Ensure that the normalization factor used in the wavefunction evaluation is consistent with the VASP documentation and the physical interpretation of the wavefunction.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Add documentation for the fft_mesh method to clarify its usage and parameters.

Improving the documentation for this method will help users understand its purpose and how to use it effectively, especially the meaning and impact of the shift parameter.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Refactor eigenvalue_band_properties to improve clarity and efficiency.

- for d in self.eigenvalues.values():
+ for spin, d in self.eigenvalues.items():
      # existing code...

Using .items() to iterate over the dictionary provides both the key and value, which can be used to enhance the readability and potential debugging of the method.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Optimize data processing in Waveder.from_file for efficiency.

Consider using numpy operations to process data arrays directly from the file buffer, which can significantly speed up the data handling and reduce memory usage.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Add documentation for the WSWQ class to clarify its usage and parameters.

Improving the documentation for this class will help users understand its purpose and how to use it effectively, especially the meaning and impact of the overlap operator and matrix elements.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Verify the data reshaping logic in WSWQ.from_file.

Ensure that the reshaping of data arrays from the WSWQ file matches the expected dimensions and order of indices, which is crucial for the correct interpretation of wavefunction overlaps.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Ensure consistent usage of UnconvergedVASPWarning across different modules.

Verify that UnconvergedVASPWarning is used consistently in all modules where VASP run convergence is checked, to maintain uniformity in handling and reporting unconverged runs.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Refactor the _generate_nbmax method to improve readability and maintainability.

- def _generate_nbmax(self) -> None:
+ def _calculate_max_g_vectors(self) -> np.ndarray:
      # existing code...
-     self._nbmax = np.max([nbmaxA, nbmaxB, nbmaxC], axis=0).astype(int)
+     return np.max([nbmaxA, nbmaxB, nbmaxC], axis=0).astype(int)

- self._generate_nbmax()
+ self._nbmax = self._calculate_max_g_vectors()

Renaming _generate_nbmax to _calculate_max_g_vectors and changing it to return the calculated values instead of setting them directly improves the method's clarity and testability.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Optimize the loop in _generate_G_points to enhance performance.

Consider using numpy operations to vectorize the loop that calculates G-points, which could significantly speed up the execution if the number of iterations is large.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Verify the normalization factor in evaluate_wavefunc.

Ensure that the normalization factor used in the wavefunction evaluation is consistent with the VASP documentation and the physical interpretation of the wavefunction.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Add documentation for the fft_mesh method to clarify its usage and parameters.

Improving the documentation for this method will help users understand its purpose and how to use it effectively, especially the meaning and impact of the shift parameter.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Refactor eigenvalue_band_properties to improve clarity and efficiency.

- for d in self.eigenvalues.values():
+ for spin, d in self.eigenvalues.items():
      # existing code...

Using .items() to iterate over the dictionary provides both the key and value, which can be used to enhance the readability and potential debugging of the method.


355-361: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Optimize data processing in Waveder.from_file for efficiency.

Consider using numpy operations to process data arrays directly from the file buffer, which can significantly speed up the data handling and reduce memory usage.


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.

@janosh janosh added linting Linting and quality assurance housekeeping Moving around or cleaning up old code/files labels Apr 13, 2024
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

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

did a bit more clean up of the ruff config. several auto-fixes were needlessly disabled for "PLR0402", "PLR1714", "PLR5501"

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

Comment on lines +1117 to +1120
elif self.incar.get("ENCUT", 0) > 0:
encut = self.incar["ENCUT"] # get the ENCUT val
else:
if self.incar.get("ENCUT", 0) > 0:
encut = self.incar["ENCUT"] # get the ENCUT val
else:
encut = max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"])
encut = max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"])
Copy link

Choose a reason for hiding this comment

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

Refactor the conditional logic for setting encut to enhance readability and reduce redundancy.

-        if custom_encut is not None:
-            encut = custom_encut
-        elif self.incar.get("ENCUT", 0) > 0:
-            encut = self.incar["ENCUT"]  # get the ENCUT val
-        else:
-            encut = max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"])
+        encut = (
+            custom_encut if custom_encut is not None
+            else self.incar.get("ENCUT", max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"]))
+        )

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
elif self.incar.get("ENCUT", 0) > 0:
encut = self.incar["ENCUT"] # get the ENCUT val
else:
if self.incar.get("ENCUT", 0) > 0:
encut = self.incar["ENCUT"] # get the ENCUT val
else:
encut = max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"])
encut = max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"])
encut = (
custom_encut if custom_encut is not None
else self.incar.get("ENCUT", max(i_species.enmax for i_species in self.get_vasp_input()["POTCAR"]))
)

Comment on lines +208 to +215
elif invert_axes:
_ylim = ax.get_ylim()
relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]] or ax.get_xlim()
ax.set_xlim((min(relevant_x), max(relevant_x)))
else:
if invert_axes:
_ylim = ax.get_ylim()
relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]] or ax.get_xlim()
ax.set_xlim((min(relevant_x), max(relevant_x)))
else:
_xlim = ax.get_xlim()
relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]] or ax.get_ylim()
ax.set_ylim((min(relevant_y), max(relevant_y)))
_xlim = ax.get_xlim()
relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]] or ax.get_ylim()
ax.set_ylim((min(relevant_y), max(relevant_y)))
Copy link

Choose a reason for hiding this comment

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

Consider handling cases where relevant_x or relevant_y might be empty.

- relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]] or ax.get_xlim()
+ relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]]
+ if not relevant_x:
+     relevant_x = ax.get_xlim()

- relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]] or ax.get_ylim()
+ relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]]
+ if not relevant_y:
+     relevant_y = ax.get_ylim()

This change ensures that the axis limits are set to the current limits if no points fall within the specified range, preventing potential errors or unexpected behavior.


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
elif invert_axes:
_ylim = ax.get_ylim()
relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]] or ax.get_xlim()
ax.set_xlim((min(relevant_x), max(relevant_x)))
else:
if invert_axes:
_ylim = ax.get_ylim()
relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]] or ax.get_xlim()
ax.set_xlim((min(relevant_x), max(relevant_x)))
else:
_xlim = ax.get_xlim()
relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]] or ax.get_ylim()
ax.set_ylim((min(relevant_y), max(relevant_y)))
_xlim = ax.get_xlim()
relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]] or ax.get_ylim()
ax.set_ylim((min(relevant_y), max(relevant_y)))
elif invert_axes:
_ylim = ax.get_ylim()
relevant_x = [p[1] for p in all_pts if _ylim[0] < p[0] < _ylim[1]]
if not relevant_x:
relevant_x = ax.get_xlim()
ax.set_xlim((min(relevant_x), max(relevant_x)))
else:
_xlim = ax.get_xlim()
relevant_y = [p[1] for p in all_pts if _xlim[0] < p[0] < _xlim[1]]
if not relevant_y:
relevant_y = ax.get_ylim()
ax.set_ylim((min(relevant_y), max(relevant_y)))

Comment on lines 355 to 361
# The start event tells us when we have entered blocks
if tag == "calculation":
parsed_header = True
elif tag == "eigenvalues_kpoints_opt" or tag == "projected_kpoints_opt":
elif tag in ("eigenvalues_kpoints_opt", "projected_kpoints_opt"):
in_kpoints_opt = True
else: # event == "end":
# The end event happens when we have read a block, so have
Copy link

Choose a reason for hiding this comment

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

📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Consider adding error handling for file operations in Wavecar.

- with open(self.filename, "rb") as file:
+ try:
+     with open(self.filename, "rb") as file:
+         # existing code...
+ except IOError as e:
+     raise IOError(f"Failed to open or read from file {self.filename}: {str(e)}")

This change ensures that any issues with file access are caught and reported clearly, improving the robustness of file operations.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Handle the gamma point check more robustly in get_parchg.

- if phase and not np.all(self.kpoints[kpoint] == 0.0):
+ if phase and not np.isclose(self.kpoints[kpoint], 0.0, atol=1e-5).all():

Using np.isclose with a tolerance allows for minor numerical inaccuracies in specifying the gamma point, which is more robust than a direct comparison to zero.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Ensure consistent data types in Eigenval initialization.

- self.ispin = int(file.readline().split()[-1])
+ self.ispin = int(float(file.readline().split()[-1]))

Casting the spin value to float before converting to int ensures that the code handles cases where the spin value might be represented as a floating-point number in the file.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Add error handling for file operations in Waveder.from_file.

- with zopen(filename, mode="rt") as file:
+ try:
+     with zopen(filename, mode="rt") as file:
+         # existing code...
+ except IOError as e:
+     raise IOError(f"Failed to open or read from file {filename}: {str(e)}")

This change ensures that any issues with file access are caught and reported clearly, improving the robustness of file operations.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Consider adding error handling for file operations in Wavecar.

- with open(self.filename, "rb") as file:
+ try:
+     with open(self.filename, "rb") as file:
+         # existing code...
+ except IOError as e:
+     raise IOError(f"Failed to open or read from file {self.filename}: {str(e)}")

This change ensures that any issues with file access are caught and reported clearly, improving the robustness of file operations.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Handle the gamma point check more robustly in get_parchg.

- if phase and not np.all(self.kpoints[kpoint] == 0.0):
+ if phase and not np.isclose(self.kpoints[kpoint], 0.0, atol=1e-5).all():

Using np.isclose with a tolerance allows for minor numerical inaccuracies in specifying the gamma point, which is more robust than a direct comparison to zero.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Ensure consistent data types in Eigenval initialization.

- self.ispin = int(file.readline().split()[-1])
+ self.ispin = int(float(file.readline().split()[-1]))

Casting the spin value to float before converting to int ensures that the code handles cases where the spin value might be represented as a floating-point number in the file.


📝 NOTE
This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [358-414]

Add error handling for file operations in Waveder.from_file.

- with zopen(filename, mode="rt") as file:
+ try:
+     with zopen(filename, mode="rt") as file:
+         # existing code...
+ except IOError as e:
+     raise IOError(f"Failed to open or read from file {filename}: {str(e)}")

This change ensures that any issues with file access are caught and reported clearly, improving the robustness of file operations.

@janosh janosh merged commit a4e033a into master Apr 13, 2024
22 checks passed
@janosh janosh deleted the Andrew-S-Rosen-patch-1 branch April 13, 2024 05:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Moving around or cleaning up old code/files linting Linting and quality assurance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants