diff --git a/src/poli/core/exceptions.py b/src/poli/core/exceptions.py index ae2ed27e..38c372c4 100644 --- a/src/poli/core/exceptions.py +++ b/src/poli/core/exceptions.py @@ -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 diff --git a/src/poli/objective_repository/foldx_rfp_lambo/register.py b/src/poli/objective_repository/foldx_rfp_lambo/register.py index 4da48dd8..8be137b4 100644 --- a/src/poli/objective_repository/foldx_rfp_lambo/register.py +++ b/src/poli/objective_repository/foldx_rfp_lambo/register.py @@ -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 @@ -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 ( diff --git a/src/poli/objective_repository/foldx_sasa/register.py b/src/poli/objective_repository/foldx_sasa/register.py index d02153b5..8a5f5ed8 100644 --- a/src/poli/objective_repository/foldx_sasa/register.py +++ b/src/poli/objective_repository/foldx_sasa/register.py @@ -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 @@ -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 @@ -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, @@ -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 ( @@ -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, @@ -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 @@ -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, diff --git a/src/poli/objective_repository/foldx_stability/register.py b/src/poli/objective_repository/foldx_stability/register.py index c05cf236..0659d363 100644 --- a/src/poli/objective_repository/foldx_stability/register.py +++ b/src/poli/objective_repository/foldx_stability/register.py @@ -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 @@ -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 @@ -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, @@ -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 ( @@ -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, @@ -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, diff --git a/src/poli/objective_repository/foldx_stability_and_sasa/register.py b/src/poli/objective_repository/foldx_stability_and_sasa/register.py index 3254205a..32c9203f 100644 --- a/src/poli/objective_repository/foldx_stability_and_sasa/register.py +++ b/src/poli/objective_repository/foldx_stability_and_sasa/register.py @@ -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 @@ -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 @@ -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, @@ -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 ( @@ -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, @@ -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 @@ -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,