This commit is contained in:
2024-01-09 13:18:23 +08:00
parent a77f7dbb16
commit fbb1fcf3f4

View File

@@ -19,8 +19,13 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa
# Iterate over each PDB file and execute the GROMACS command # Iterate over each PDB file and execute the GROMACS command
for pdb_file in pdb_files: for pdb_file in pdb_files:
name = pdb_file.stem # Extract the name without the '.pdb' extension name = pdb_file.stem # Extract the name without the '.pdb' extension
parent = pdb_file.parent
output_gro = f"{name}.gro" output_gro = f"{name}.gro"
topol_file = "topol.top" topol_file = f"{name}_topol.top"
# Check if topol_file already exists, and if so, skip this task
if Path(topol_file).exists():
continue
# Construct the command # Construct the command
cmd = [ cmd = [
@@ -35,7 +40,7 @@ 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 # Run the command and capture the standard error (stderr) to a log file
log_file = pdb_file.absolute().parent.joinpath(f"{name}_gentop.log") log_file = parent.joinpath(f"{name}_topol.log")
with open(log_file, "w") as log: with open(log_file, "w") as log:
subprocess.run(cmd, check=True, cwd=directory, stderr=log) subprocess.run(cmd, check=True, cwd=directory, stderr=log)