Skip to content

Fix: resolve undefined variable and early termination in aveElecStatPot.py - #7640

Merged
mohanchen merged 1 commit into
deepmodeling:developfrom
DanielZhao0432:DanielZhao0432-fix-pot-script
Jul 15, 2026
Merged

Fix: resolve undefined variable and early termination in aveElecStatPot.py#7640
mohanchen merged 1 commit into
deepmodeling:developfrom
DanielZhao0432:DanielZhao0432-fix-pot-script

Conversation

@DanielZhao0432

@DanielZhao0432 DanielZhao0432 commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Linked Issue

Fixes #7559

Description

This PR addresses two logical issues in the aveElecStatPot.py script that could cause it to crash or exit prematurely when searching for ElecStaticPot.cube:

  1. Premature Termination (Early sys.exit):
    Previously, the script would immediately exit (sys.exit()) if the first matching OUT.* subdirectory scanned did not contain ElecStaticPot.cube. This prevented the script from checking subsequent OUT.* directories that might actually contain the target file.

  2. NameError (Undefined input_file):
    If no ElecStaticPot.cube was present in the root directory, and no OUT.* subdirectories existed, the nested search loop was never executed. Consequently, input_file was never defined, resulting in a NameError when the script reached the with open(input_file, 'r') block.

Changes Made

  • Initialized input_file, output_file, and output_png to None to prevent NameError.
  • Updated the directory scanning logic so that the script continues searching through all candidate OUT.* directories rather than exiting immediately on the first miss.
  • Added a unified check after the search block: if the file cannot be found anywhere, the script now exits cleanly with an informative error message.

…ot.py

Refactored input file handling to check for 'ElecStaticPot.cube' in subdirectories. Added error handling for missing input files.
@mohanchen
mohanchen merged commit a2a45f8 into deepmodeling:develop Jul 15, 2026
18 checks passed
@mohanchen mohanchen added the Refactor Refactor ABACUS codes label Jul 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Refactor ABACUS codes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Search all OUT directories before average_pot exits

2 participants