mirror of
https://github.com/microsoft/foldingdiff.git
synced 2026-06-04 13:30:33 +08:00
Add a docker wrapper for gromacs
This commit is contained in:
@@ -20,7 +20,7 @@ import subprocess
|
||||
import shutil
|
||||
import multiprocessing as mp
|
||||
|
||||
GRO_FILE_DIR = "/home/wukevin/software/md_template/mdp/"
|
||||
GRO_FILE_DIR = os.path.join(os.path.dirname(__file__), "mdp")
|
||||
|
||||
|
||||
def run_gromacs(
|
||||
|
||||
50
scripts/gromacs/gromacs_docker.py
Normal file
50
scripts/gromacs/gromacs_docker.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""
|
||||
Simple script to wrap the gromacs.py file in an easy to run docker container
|
||||
to avoid all the messiness of trying to do mounting and stuff.
|
||||
|
||||
Usage: python gromacs_docker.py <input_file> <output_dir>
|
||||
"""
|
||||
import os
|
||||
import shutil
|
||||
import tempfile
|
||||
import subprocess
|
||||
import argparse
|
||||
|
||||
|
||||
def build_parser():
|
||||
"""Build a basic CLI parser"""
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("input_file", help="Input file to run GROMACS on")
|
||||
parser.add_argument("output_dir", help="Output dir to write output files to")
|
||||
return parser
|
||||
|
||||
|
||||
def run_gromacs_in_docker(fname: str, out_dir: str):
|
||||
"""
|
||||
Run gromacs in docker
|
||||
"""
|
||||
assert os.path.isfile(fname), f"Input file {fname} not found"
|
||||
assert shutil.which("nvidia-docker")
|
||||
out_dir = os.path.abspath(out_dir)
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
os.chdir(tmpdir)
|
||||
# Copy the file into the directory
|
||||
shutil.copy(fname, tmpdir)
|
||||
# Build and run the command
|
||||
cmd = f"nvidia-docker run -it --rm -v {tmpdir}:/host_pwd --workdir /host_pwd wukevin:gromacs-latest {os.path.basename(fname)}"
|
||||
subprocess.call(cmd, shell=True)
|
||||
|
||||
for fname in os.listdir(tmpdir):
|
||||
shutil.copy(fname, out_dir)
|
||||
|
||||
|
||||
def main():
|
||||
"""Run script"""
|
||||
args = build_parser().parse_args()
|
||||
if not os.path.isdir(args.output_dir):
|
||||
os.makedirs(args.output_dir)
|
||||
run_gromacs_in_docker(args.input_file, args.output_dir)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user