Skip to content

Commit

Permalink
Adds an exception for when foldx is not found (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgondu authored Mar 8, 2024
1 parent 33c6ae7 commit f69f550
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 41 deletions.
6 changes: 6 additions & 0 deletions src/poli/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ class BudgetExhaustedException(PoliException):
"""Exception raised when the budget is exhausted."""

pass


class FoldXNotFoundException(PoliException):
"""Exception raised when FoldX wasn't found in ~/foldx/foldx."""

pass
14 changes: 5 additions & 9 deletions src/poli/objective_repository/foldx_rfp_lambo/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@

__author__ = "Simon Bartels"

import logging
from pathlib import Path
import os
import random
from typing import Tuple

import numpy as np

# import hydra
# import torch
from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.abstract_problem_factory import AbstractProblemFactory
from poli.core.problem import Problem
from poli.core.black_box_information import BlackBoxInformation
from poli.core.exceptions import FoldXNotFoundException

from poli.core.problem_setup_information import ProblemSetupInformation
from poli.objective_repository.foldx_rfp_lambo import PROBLEM_SEQ, CORRECT_SEQ
from poli.core.util.isolation.instancing import instance_function_as_isolated_process
from poli.core.util.seeding import seed_python_numpy_and_torch
Expand Down Expand Up @@ -47,6 +39,10 @@ def __init__(
self.inverse_alphabet = {i + 1: AMINO_ACIDS[i] for i in range(len(AMINO_ACIDS))}
self.inverse_alphabet[0] = "-"

if not (Path.home() / "foldx" / "foldx").exists():
raise FoldXNotFoundException(
"FoldX wasn't found in ~/foldx/foldx. Please install it."
)
if not force_isolation:
try:
from poli.objective_repository.foldx_rfp_lambo.isolated_function import (
Expand Down
15 changes: 5 additions & 10 deletions src/poli/objective_repository/foldx_sasa/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from poli.core.abstract_problem_factory import AbstractProblemFactory
from poli.core.black_box_information import BlackBoxInformation
from poli.core.problem import Problem
from poli.core.exceptions import FoldXNotFoundException

from poli.core.util.isolation.instancing import instance_function_as_isolated_process

Expand All @@ -39,8 +40,6 @@ class FoldXSASABlackBox(AbstractBlackBox):
-----------
wildtype_pdb_path : Union[Path, List[Path]]
The path(s) to the wildtype PDB file(s). Default is None.
alphabet : List[str], optional
The alphabet of amino acids. Default is None.
experiment_id : str, optional
The ID of the experiment. Default is None.
tmp_folder : Path, optional
Expand Down Expand Up @@ -68,7 +67,6 @@ class FoldXSASABlackBox(AbstractBlackBox):
def __init__(
self,
wildtype_pdb_path: Union[Path, List[Path]],
alphabet: List[str] = None,
experiment_id: str = None,
tmp_folder: Path = None,
eager_repair: bool = False,
Expand All @@ -85,6 +83,10 @@ def __init__(
num_workers=num_workers,
evaluation_budget=evaluation_budget,
)
if not (Path.home() / "foldx" / "foldx").exists():
raise FoldXNotFoundException(
"FoldX wasn't found in ~/foldx/foldx. Please install it."
)
if not force_isolation:
try:
from poli.objective_repository.foldx_sasa.isolated_function import (
Expand Down Expand Up @@ -177,7 +179,6 @@ def get_setup_information(self) -> BlackBoxInformation:
def create(
self,
wildtype_pdb_path: Union[Path, List[Path]],
alphabet: List[str] = None,
experiment_id: str = None,
tmp_folder: Path = None,
eager_repair: bool = False,
Expand All @@ -196,9 +197,6 @@ def create(
----------
wildtype_pdb_path : Union[Path, List[Path]]
Path or list of paths to the wildtype PDB files.
alphabet : List[str], optional
List of amino acid symbols. By defualt, the 20 amino acids
shown in poli.core.util.proteins.defaults are used.
experiment_id : str, optional
Identifier for the experiment.
tmp_folder : Path, optional
Expand Down Expand Up @@ -259,12 +257,9 @@ def create(

# We use the default alphabet if None was provided.
# See ENCODING in foldx_utils.py
if alphabet is None:
alphabet = self.get_setup_information().get_alphabet()

f = FoldXSASABlackBox(
wildtype_pdb_path=wildtype_pdb_path,
alphabet=alphabet,
experiment_id=experiment_id,
tmp_folder=tmp_folder,
eager_repair=eager_repair,
Expand Down
16 changes: 5 additions & 11 deletions src/poli/objective_repository/foldx_stability/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from poli.core.black_box_information import BlackBoxInformation
from poli.core.problem import Problem
from poli.core.abstract_black_box import AbstractBlackBox
from poli.core.exceptions import FoldXNotFoundException

from poli.core.util.seeding import seed_python_numpy_and_torch

Expand All @@ -39,9 +40,6 @@ class FoldXStabilityBlackBox(AbstractBlackBox):
----------
wildtype_pdb_path : Union[Path, List[Path]]
The path(s) to the wildtype PDB file(s).
alphabet : List[str], optional
The alphabet of amino acids. By default, we use the 20
amino acids shown in poli.core.util.proteins.defaults.
experiment_id : str, optional
The ID of the experiment (default is None).
tmp_folder : Path, optional
Expand Down Expand Up @@ -74,7 +72,6 @@ class FoldXStabilityBlackBox(AbstractBlackBox):
def __init__(
self,
wildtype_pdb_path: Union[Path, List[Path]],
alphabet: List[str] = None,
experiment_id: str = None,
tmp_folder: Path = None,
eager_repair: bool = False,
Expand All @@ -91,6 +88,10 @@ def __init__(
num_workers=num_workers,
evaluation_budget=evaluation_budget,
)
if not (Path.home() / "foldx" / "foldx").exists():
raise FoldXNotFoundException(
"FoldX wasn't found in ~/foldx/foldx. Please install it."
)
if not force_isolation:
try:
from poli.objective_repository.foldx_stability.isolated_function import (
Expand Down Expand Up @@ -173,7 +174,6 @@ def get_setup_information(self) -> BlackBoxInformation:
def create(
self,
wildtype_pdb_path: Union[Path, List[Path]],
alphabet: List[str] = None,
experiment_id: str = None,
tmp_folder: Path = None,
eager_repair: bool = False,
Expand Down Expand Up @@ -248,15 +248,9 @@ def create(
# By this point, we know that wildtype_pdb_path is a
# list of Path objects.

if alphabet is None:
# We use the default alphabet.
# See AMINO_ACIDS in foldx_utils.py
alphabet = self.get_setup_information().get_alphabet()

# TODO: add support for a larger batch-size.
f = FoldXStabilityBlackBox(
wildtype_pdb_path=wildtype_pdb_path,
alphabet=alphabet,
experiment_id=experiment_id,
tmp_folder=tmp_folder,
eager_repair=eager_repair,
Expand Down
16 changes: 5 additions & 11 deletions src/poli/objective_repository/foldx_stability_and_sasa/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from poli.core.black_box_information import BlackBoxInformation
from poli.core.problem import Problem
from poli.core.abstract_problem_factory import AbstractProblemFactory
from poli.core.exceptions import FoldXNotFoundException


from poli.core.util.seeding import seed_python_numpy_and_torch
Expand All @@ -44,8 +45,6 @@ class FoldXStabilityAndSASABlackBox(AbstractBlackBox):
-----------
wildtype_pdb_path : Union[Path, List[Path]]
The path(s) to the wildtype PDB file(s).
alphabet : List[str], optional
The alphabet of amino acids. Default is None.
experiment_id : str, optional
The ID of the experiment. Default is None.
tmp_folder : Path, optional
Expand Down Expand Up @@ -73,7 +72,6 @@ class FoldXStabilityAndSASABlackBox(AbstractBlackBox):
def __init__(
self,
wildtype_pdb_path: Union[Path, List[Path]],
alphabet: List[str] = None,
experiment_id: str = None,
tmp_folder: Path = None,
eager_repair: bool = False,
Expand All @@ -90,6 +88,10 @@ def __init__(
num_workers=num_workers,
evaluation_budget=evaluation_budget,
)
if not (Path.home() / "foldx" / "foldx").exists():
raise FoldXNotFoundException(
"FoldX wasn't found in ~/foldx/foldx. Please install it."
)
if not force_isolation:
try:
from poli.objective_repository.foldx_stability_and_sasa.isolated_function import (
Expand Down Expand Up @@ -181,7 +183,6 @@ def get_setup_information(self) -> BlackBoxInformation:
def create(
self,
wildtype_pdb_path: Union[Path, List[Path]],
alphabet: List[str] = None,
experiment_id: str = None,
tmp_folder: Path = None,
eager_repair: bool = False,
Expand All @@ -200,9 +201,6 @@ def create(
----------
wildtype_pdb_path : Union[Path, List[Path]]
Path or list of paths to the wildtype PDB files.
alphabet : List[str], optional
List of amino acid symbols. By default, we use the
20 amino acids shown in poli.core.util.proteins.defaults.
experiment_id : str, optional
Identifier for the experiment.
tmp_folder : Path, optional
Expand Down Expand Up @@ -261,12 +259,8 @@ def create(

# We use the default alphabet if None was provided.
# See ENCODING in foldx_utils.py
if alphabet is None:
alphabet = self.get_setup_information().get_alphabet()

f = FoldXStabilityAndSASABlackBox(
wildtype_pdb_path=wildtype_pdb_path,
alphabet=alphabet,
experiment_id=experiment_id,
tmp_folder=tmp_folder,
eager_repair=eager_repair,
Expand Down

0 comments on commit f69f550

Please sign in to comment.