This commit is contained in:
root
2024-01-09 10:39:22 +08:00
parent 930acfe247
commit a77f7dbb16

View File

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