update to cwd
This commit is contained in:
14
gentop.py
14
gentop.py
@@ -5,8 +5,7 @@ import os
|
|||||||
def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", water_model="tip3p"):
|
def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", water_model="tip3p"):
|
||||||
"""
|
"""
|
||||||
Generate GROMACS topology (.top) files for each PDB file in the specified directory
|
Generate GROMACS topology (.top) files for each PDB file in the specified directory
|
||||||
by running the 'gmx_mpi pdb2gmx' command in batch. All intermediate and output files
|
by running the 'gmx_mpi pdb2gmx' command in batch, with the working directory set to the specified directory.
|
||||||
are generated in the same directory as the PDB files.
|
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
directory (str): Directory containing PDB files.
|
directory (str): Directory containing PDB files.
|
||||||
@@ -19,11 +18,8 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa
|
|||||||
if gmxrc_path:
|
if gmxrc_path:
|
||||||
subprocess.run(f"source {gmxrc_path}", shell=True, executable='/bin/bash')
|
subprocess.run(f"source {gmxrc_path}", shell=True, executable='/bin/bash')
|
||||||
|
|
||||||
# Convert directory to Path object for ease of use
|
|
||||||
directory_path = Path(directory)
|
|
||||||
|
|
||||||
# Find all PDB files in the specified directory
|
# Find all PDB files in the specified directory
|
||||||
pdb_files = directory_path.glob("*.pdb")
|
pdb_files = Path(directory).glob("*.pdb")
|
||||||
|
|
||||||
# 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:
|
||||||
@@ -31,7 +27,7 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa
|
|||||||
output_gro = f"{name}.gro"
|
output_gro = f"{name}.gro"
|
||||||
topol_file = "topol.top"
|
topol_file = "topol.top"
|
||||||
|
|
||||||
# Construct and run the command
|
# Construct and run the command with the working directory set to 'directory'
|
||||||
cmd = [
|
cmd = [
|
||||||
"mpirun", "-np", str(num_cores),
|
"mpirun", "-np", str(num_cores),
|
||||||
"gmx_mpi", "pdb2gmx",
|
"gmx_mpi", "pdb2gmx",
|
||||||
@@ -42,9 +38,9 @@ def generate_gmx_top_files(directory, num_cores, forcefield="amber99sb-ildn", wa
|
|||||||
"-ignh",
|
"-ignh",
|
||||||
"-p", topol_file
|
"-p", topol_file
|
||||||
]
|
]
|
||||||
subprocess.run(cmd, check=True, cwd=directory_path)
|
subprocess.run(cmd, check=True, cwd=directory)
|
||||||
|
|
||||||
# Example usage
|
# Example usage
|
||||||
directory = "./pdb_top" # Replace with your actual directory path
|
directory = "pdb_top" # Replace with your actual directory path
|
||||||
num_cores = max(os.cpu_count() - 2, 1) # Determine the number of cores to use
|
num_cores = max(os.cpu_count() - 2, 1) # Determine the number of cores to use
|
||||||
generate_gmx_top_files(directory, num_cores) # Run the function
|
generate_gmx_top_files(directory, num_cores) # Run the function
|
||||||
|
|||||||
Reference in New Issue
Block a user