From a77f7dbb16b8e05d9b7c7ab4a0f28cc01b48aff3 Mon Sep 17 00:00:00 2001 From: root Date: Tue, 9 Jan 2024 10:39:22 +0800 Subject: [PATCH] add log --- gentop.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/gentop.py b/gentop.py index 4eebce5..f60f014 100644 --- a/gentop.py +++ b/gentop.py @@ -13,11 +13,6 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa forcefield (str): Forcefield parameter for GROMACS. Default is "amber99sb-ildn". water_model (str): Water model parameter for GROMACS. Default is "tip3p". """ - # Ensure the GMXRC path is sourced if set - gmxrc_path = os.getenv("GMXRC_PATH") - if gmxrc_path: - subprocess.run(f"source {gmxrc_path}", shell=True, executable='/bin/bash') - # Find all PDB files in the specified directory pdb_files = Path(directory).glob("*.pdb") @@ -27,18 +22,22 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa output_gro = f"{name}.gro" topol_file = "topol.top" - # Construct and run the command with the working directory set to 'directory' + # Construct the command cmd = [ "mpirun", "-np", str(num_cores), "gmx_mpi", "pdb2gmx", - "-f", str(pdb_file), + "-f", pdb_file.absolute().as_posix(), "-o", output_gro, "-ff", forcefield, "-water", water_model, "-ignh", "-p", topol_file ] - subprocess.run(cmd, check=True, cwd=directory) + + # Run the command and capture the standard error (stderr) to a log file + log_file = pdb_file.absolute().parent.joinpath(f"{name}_gentop.log") + with open(log_file, "w") as log: + subprocess.run(cmd, check=True, cwd=directory, stderr=log) # Example usage directory = "pdb_top" # Replace with your actual directory path