From a937bd0334ef3c2485345254c1c11a7db0cd6248 Mon Sep 17 00:00:00 2001 From: hotwa Date: Wed, 10 Jan 2024 09:47:01 +0800 Subject: [PATCH] update error handle --- gentop.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/gentop.py b/gentop.py index bfa4df4..4a646d2 100644 --- a/gentop.py +++ b/gentop.py @@ -41,8 +41,11 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa # Run the command and capture the standard error (stderr) to a log file log_file = parent.joinpath(f"{name}_topol.log") - with open(log_file, "w") as log: - subprocess.run(cmd, check=True, cwd=directory, stderr=log) + try: + with open(log_file, "w") as log: + subprocess.run(cmd, check=True, cwd=directory, stderr=log) + except subprocess.CalledProcessError as e: + print(f"Error processing {pdb_file.name}: {e}") # Example usage directory = "pdb_top" # Replace with your actual directory path