From 254a17f25cf8723f19f3dec87b205d6e7a92ee7b Mon Sep 17 00:00:00 2001 From: Danfeng Zhao <154488229+DanielZhao0432@users.noreply.github.com> Date: Wed, 15 Jul 2026 13:28:29 +0800 Subject: [PATCH 1/5] fix: resolve undefined variable and early termination in aveElecStatPot.py Refactored input file handling to check for 'ElecStaticPot.cube' in subdirectories. Added error handling for missing input files. --- .../average_pot/aveElecStatPot.py | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/tools/02_postprocessing/average_pot/aveElecStatPot.py b/tools/02_postprocessing/average_pot/aveElecStatPot.py index 60bc1804ac4..e370ba2d93a 100644 --- a/tools/02_postprocessing/average_pot/aveElecStatPot.py +++ b/tools/02_postprocessing/average_pot/aveElecStatPot.py @@ -4,6 +4,10 @@ import matplotlib.pyplot as plt from scipy.interpolate import interp1d +input_file = None +output_file = None +output_png = None + current_dir = os.getcwd() if os.path.exists(os.path.join(current_dir, "ElecStaticPot.cube")): @@ -15,16 +19,20 @@ dir_path = os.path.join(current_dir, dir_name) if os.path.isdir(dir_path) and dir_name.startswith("OUT."): - input_file = os.path.join(dir_path, "ElecStaticPot.cube") - output_file = os.path.join(dir_path, "ElecStaticPot_AVE") - output_png = os.path.join(dir_path, "ElecStaticPot-vs-Z.png") - if os.path.exists(input_file): + candidate_file = os.path.join(dir_path, "ElecStaticPot.cube") + if os.path.exists(candidate_file): + input_file = candidate_file + output_file = os.path.join(dir_path, "ElecStaticPot_AVE") + output_png = os.path.join(dir_path, "ElecStaticPot-vs-Z.png") print(f"Processeding: {input_file}") break - else: - print(f"File does not exist: {input_file}") - sys.exit() - + +if input_file is None: + print("Error: 'ElecStaticPot.cube' was not found in the current directory or any 'OUT.*' subdirectories.", file=sys.stderr) + print("Please check if ABACUS has completed successfully with 'out_pot' enabled (e.g., set to 2).", file=sys.stderr) + sys.exit(1) + + with open(input_file, 'r') as inpt: temp = inpt.readlines() From 40654d5bdf0a4a3079602906c370ff46a6861028 Mon Sep 17 00:00:00 2001 From: Danfeng Zhao <154488229+DanielZhao0432@users.noreply.github.com> Date: Mon, 20 Jul 2026 11:29:53 +0800 Subject: [PATCH 2/5] Fix file reading and MPI_Bcast type --- source/source_md/fire.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/source_md/fire.cpp b/source/source_md/fire.cpp index fa575b508d7..8c65c026baf 100644 --- a/source/source_md/fire.cpp +++ b/source/source_md/fire.cpp @@ -130,13 +130,16 @@ void FIRE::restart(const std::string& global_readin_dir) if (ok) { - file >> step_rst_ >> md_tfirst >> alpha >> negative_count >> dt_max >> md_dt; + if(!(file >> step_rst_ >> md_tfirst >> alpha >> negative_count >> dt_max >> md_dt)) + { + ok = false; + } file.close(); } } #ifdef __MPI - MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Bcast(&ok, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD); #endif if (!ok) From 5282a085e923a62a37c9603b79ad0eb3e7674234 Mon Sep 17 00:00:00 2001 From: Danfeng Zhao <154488229+DanielZhao0432@users.noreply.github.com> Date: Mon, 20 Jul 2026 11:31:56 +0800 Subject: [PATCH 3/5] Update msst.cpp --- source/source_md/msst.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/source/source_md/msst.cpp b/source/source_md/msst.cpp index e33c24b45e5..cc8703c1a40 100644 --- a/source/source_md/msst.cpp +++ b/source/source_md/msst.cpp @@ -209,13 +209,16 @@ void MSST::restart(const std::string& global_readin_dir) if (ok) { - file >> step_rst_ >> md_tfirst >> omega[mdp.msst_direction] >> e0 >> v0 >> p0 >> lag_pos; + if(!(file >> step_rst_ >> md_tfirst >> omega[mdp.msst_direction] >> e0 >> v0 >> p0 >> lag_pos)) + { + ok = false; + } file.close(); } } #ifdef __MPI - MPI_Bcast(&ok, 1, MPI_INT, 0, MPI_COMM_WORLD); + MPI_Bcast(&ok, 1, MPI_C_BOOL, 0, MPI_COMM_WORLD); #endif if (!ok) From 39d4e82224fe9396322b3098418b41dc5548f095 Mon Sep 17 00:00:00 2001 From: Danfeng Zhao <154488229+DanielZhao0432@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:12:03 +0800 Subject: [PATCH 4/5] Fix file reading condition in fire.cpp --- source/source_md/fire.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/source_md/fire.cpp b/source/source_md/fire.cpp index 8c65c026baf..e67529852c7 100644 --- a/source/source_md/fire.cpp +++ b/source/source_md/fire.cpp @@ -130,7 +130,8 @@ void FIRE::restart(const std::string& global_readin_dir) if (ok) { - if(!(file >> step_rst_ >> md_tfirst >> alpha >> negative_count >> dt_max >> md_dt)) + file >> step_rst_ >> md_tfirst >> alpha >> negative_count >> dt_max >> md_dt; + if(!file) { ok = false; } From 30d2709d54b48ff9f29ecd582bc38adb77edaf32 Mon Sep 17 00:00:00 2001 From: Danfeng Zhao <154488229+DanielZhao0432@users.noreply.github.com> Date: Tue, 21 Jul 2026 18:12:57 +0800 Subject: [PATCH 5/5] Fix file reading condition in msst.cpp --- source/source_md/msst.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/source_md/msst.cpp b/source/source_md/msst.cpp index cc8703c1a40..de63a2e838c 100644 --- a/source/source_md/msst.cpp +++ b/source/source_md/msst.cpp @@ -209,7 +209,8 @@ void MSST::restart(const std::string& global_readin_dir) if (ok) { - if(!(file >> step_rst_ >> md_tfirst >> omega[mdp.msst_direction] >> e0 >> v0 >> p0 >> lag_pos)) + file >> step_rst_ >> md_tfirst >> omega[mdp.msst_direction] >> e0 >> v0 >> p0 >> lag_pos; + if(!file) { ok = false; }