Skip to content

Commit

Permalink
Adds better error handling and exceptions when running commands on th…
Browse files Browse the repository at this point in the history
…e terminal in RaSP
  • Loading branch information
miguelgondu committed Oct 25, 2023
1 parent 9d510e4 commit 2becc26
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import openmm.app
import simtk.unit

basepath = os.path.dirname(os.path.realpath(__file__))
sys.path.insert(1, basepath)
import grid
from . import grid


def extract_atomic_features(pdb_filename):
Expand Down
64 changes: 45 additions & 19 deletions src/poli/core/util/proteins/rasp/rasp_interface.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import List
from pathlib import Path
import subprocess
import os, stat
import subprocess

Expand Down Expand Up @@ -45,6 +44,9 @@ def __init__(self, working_dir: Path) -> None:
self.reduce_executable_path = None
self.get_and_compile_reduce()

# At this point, we should have the reduce executable
# at self.reduce_executable_path.

# Downloading the cavity and downstream models.
# TODO: implement this. What's the best way of doing this?
# Where should we store the models?
Expand All @@ -65,20 +67,35 @@ def get_and_compile_reduce(self):
# Clone it using git.
# TODO: Is there a way of downloading the contents
# of the repo without cloning it?
subprocess.run(
"git clone https://github.com/rlabduke/reduce.git",
cwd=RASP_DIR,
shell=True,
stdout=subprocess.DEVNULL,
)
try:
subprocess.run(
"git clone https://github.com/rlabduke/reduce.git",
cwd=RASP_DIR,
shell=True,
stdout=subprocess.DEVNULL,
check=True,
)
except subprocess.CalledProcessError:
raise RuntimeError(
"Could not clone the reduce repository. "
"Please check your internet connection."
)

# compile it.

subprocess.run(
"make",
cwd=REDUCE_DIR,
stdout=subprocess.DEVNULL,
)
try:
subprocess.run(
"make",
cwd=REDUCE_DIR,
stdout=subprocess.DEVNULL,
check=True,
)
except subprocess.CalledProcessError:
# TODO: should we be purging it ourselves?
raise RuntimeError(
"Something went wrong while compiling reduce. "
"Purge the folder ~/.poli_objectives/rasp/reduce "
" and try again."
)

# Change its permissions.
os.chmod(EXECUTABLE_PATH, stat.S_IEXEC)
Expand Down Expand Up @@ -192,12 +209,21 @@ def raw_pdb_to_unique_chain(self, wildtype_pdb_path: Path, chain: str = "A"):
str(raw_output_path.resolve()),
]

subprocess.run(
" ".join(pdb_tools_command_for_cleanup),
check=True,
cwd=self.working_dir,
shell=True,
)
try:
subprocess.run(
" ".join(pdb_tools_command_for_cleanup),
check=True,
cwd=self.working_dir,
shell=True,
)
except subprocess.CalledProcessError:
raise RuntimeError(
"Something went wrong while running pdbtools. "
"Make sure they are installed in the relevant environment, "
"and that you have the correct permissions to run them.\n"
"The command for installing them is:\n"
"pip install pdb-tools"
)

def unique_chain_to_clean_pdb(self, wildtype_pdb_path: Path):
"""
Expand Down

0 comments on commit 2becc26

Please sign in to comment.