update error handle

This commit is contained in:
2024-01-10 09:47:01 +08:00
parent fbb1fcf3f4
commit a937bd0334

View File

@@ -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