Skip to content

Commit f69f550

Browse files
authored
Adds an exception for when foldx is not found (#165)
1 parent 33c6ae7 commit f69f550

File tree

5 files changed

+26
-41
lines changed

5 files changed

+26
-41
lines changed

src/poli/core/exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ class BudgetExhaustedException(PoliException):
1111
"""Exception raised when the budget is exhausted."""
1212

1313
pass
14+
15+
16+
class FoldXNotFoundException(PoliException):
17+
"""Exception raised when FoldX wasn't found in ~/foldx/foldx."""
18+
19+
pass

src/poli/objective_repository/foldx_rfp_lambo/register.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,14 @@
22

33
__author__ = "Simon Bartels"
44

5-
import logging
65
from pathlib import Path
7-
import os
8-
import random
9-
from typing import Tuple
106

11-
import numpy as np
12-
13-
# import hydra
14-
# import torch
157
from poli.core.abstract_black_box import AbstractBlackBox
168
from poli.core.abstract_problem_factory import AbstractProblemFactory
179
from poli.core.problem import Problem
1810
from poli.core.black_box_information import BlackBoxInformation
11+
from poli.core.exceptions import FoldXNotFoundException
1912

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

42+
if not (Path.home() / "foldx" / "foldx").exists():
43+
raise FoldXNotFoundException(
44+
"FoldX wasn't found in ~/foldx/foldx. Please install it."
45+
)
5046
if not force_isolation:
5147
try:
5248
from poli.objective_repository.foldx_rfp_lambo.isolated_function import (

src/poli/objective_repository/foldx_sasa/register.py

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from poli.core.abstract_problem_factory import AbstractProblemFactory
2424
from poli.core.black_box_information import BlackBoxInformation
2525
from poli.core.problem import Problem
26+
from poli.core.exceptions import FoldXNotFoundException
2627

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

@@ -39,8 +40,6 @@ class FoldXSASABlackBox(AbstractBlackBox):
3940
-----------
4041
wildtype_pdb_path : Union[Path, List[Path]]
4142
The path(s) to the wildtype PDB file(s). Default is None.
42-
alphabet : List[str], optional
43-
The alphabet of amino acids. Default is None.
4443
experiment_id : str, optional
4544
The ID of the experiment. Default is None.
4645
tmp_folder : Path, optional
@@ -68,7 +67,6 @@ class FoldXSASABlackBox(AbstractBlackBox):
6867
def __init__(
6968
self,
7069
wildtype_pdb_path: Union[Path, List[Path]],
71-
alphabet: List[str] = None,
7270
experiment_id: str = None,
7371
tmp_folder: Path = None,
7472
eager_repair: bool = False,
@@ -85,6 +83,10 @@ def __init__(
8583
num_workers=num_workers,
8684
evaluation_budget=evaluation_budget,
8785
)
86+
if not (Path.home() / "foldx" / "foldx").exists():
87+
raise FoldXNotFoundException(
88+
"FoldX wasn't found in ~/foldx/foldx. Please install it."
89+
)
8890
if not force_isolation:
8991
try:
9092
from poli.objective_repository.foldx_sasa.isolated_function import (
@@ -177,7 +179,6 @@ def get_setup_information(self) -> BlackBoxInformation:
177179
def create(
178180
self,
179181
wildtype_pdb_path: Union[Path, List[Path]],
180-
alphabet: List[str] = None,
181182
experiment_id: str = None,
182183
tmp_folder: Path = None,
183184
eager_repair: bool = False,
@@ -196,9 +197,6 @@ def create(
196197
----------
197198
wildtype_pdb_path : Union[Path, List[Path]]
198199
Path or list of paths to the wildtype PDB files.
199-
alphabet : List[str], optional
200-
List of amino acid symbols. By defualt, the 20 amino acids
201-
shown in poli.core.util.proteins.defaults are used.
202200
experiment_id : str, optional
203201
Identifier for the experiment.
204202
tmp_folder : Path, optional
@@ -259,12 +257,9 @@ def create(
259257

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

265261
f = FoldXSASABlackBox(
266262
wildtype_pdb_path=wildtype_pdb_path,
267-
alphabet=alphabet,
268263
experiment_id=experiment_id,
269264
tmp_folder=tmp_folder,
270265
eager_repair=eager_repair,

src/poli/objective_repository/foldx_stability/register.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from poli.core.black_box_information import BlackBoxInformation
2424
from poli.core.problem import Problem
2525
from poli.core.abstract_black_box import AbstractBlackBox
26+
from poli.core.exceptions import FoldXNotFoundException
2627

2728
from poli.core.util.seeding import seed_python_numpy_and_torch
2829

@@ -39,9 +40,6 @@ class FoldXStabilityBlackBox(AbstractBlackBox):
3940
----------
4041
wildtype_pdb_path : Union[Path, List[Path]]
4142
The path(s) to the wildtype PDB file(s).
42-
alphabet : List[str], optional
43-
The alphabet of amino acids. By default, we use the 20
44-
amino acids shown in poli.core.util.proteins.defaults.
4543
experiment_id : str, optional
4644
The ID of the experiment (default is None).
4745
tmp_folder : Path, optional
@@ -74,7 +72,6 @@ class FoldXStabilityBlackBox(AbstractBlackBox):
7472
def __init__(
7573
self,
7674
wildtype_pdb_path: Union[Path, List[Path]],
77-
alphabet: List[str] = None,
7875
experiment_id: str = None,
7976
tmp_folder: Path = None,
8077
eager_repair: bool = False,
@@ -91,6 +88,10 @@ def __init__(
9188
num_workers=num_workers,
9289
evaluation_budget=evaluation_budget,
9390
)
91+
if not (Path.home() / "foldx" / "foldx").exists():
92+
raise FoldXNotFoundException(
93+
"FoldX wasn't found in ~/foldx/foldx. Please install it."
94+
)
9495
if not force_isolation:
9596
try:
9697
from poli.objective_repository.foldx_stability.isolated_function import (
@@ -173,7 +174,6 @@ def get_setup_information(self) -> BlackBoxInformation:
173174
def create(
174175
self,
175176
wildtype_pdb_path: Union[Path, List[Path]],
176-
alphabet: List[str] = None,
177177
experiment_id: str = None,
178178
tmp_folder: Path = None,
179179
eager_repair: bool = False,
@@ -248,15 +248,9 @@ def create(
248248
# By this point, we know that wildtype_pdb_path is a
249249
# list of Path objects.
250250

251-
if alphabet is None:
252-
# We use the default alphabet.
253-
# See AMINO_ACIDS in foldx_utils.py
254-
alphabet = self.get_setup_information().get_alphabet()
255-
256251
# TODO: add support for a larger batch-size.
257252
f = FoldXStabilityBlackBox(
258253
wildtype_pdb_path=wildtype_pdb_path,
259-
alphabet=alphabet,
260254
experiment_id=experiment_id,
261255
tmp_folder=tmp_folder,
262256
eager_repair=eager_repair,

src/poli/objective_repository/foldx_stability_and_sasa/register.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from poli.core.black_box_information import BlackBoxInformation
2626
from poli.core.problem import Problem
2727
from poli.core.abstract_problem_factory import AbstractProblemFactory
28+
from poli.core.exceptions import FoldXNotFoundException
2829

2930

3031
from poli.core.util.seeding import seed_python_numpy_and_torch
@@ -44,8 +45,6 @@ class FoldXStabilityAndSASABlackBox(AbstractBlackBox):
4445
-----------
4546
wildtype_pdb_path : Union[Path, List[Path]]
4647
The path(s) to the wildtype PDB file(s).
47-
alphabet : List[str], optional
48-
The alphabet of amino acids. Default is None.
4948
experiment_id : str, optional
5049
The ID of the experiment. Default is None.
5150
tmp_folder : Path, optional
@@ -73,7 +72,6 @@ class FoldXStabilityAndSASABlackBox(AbstractBlackBox):
7372
def __init__(
7473
self,
7574
wildtype_pdb_path: Union[Path, List[Path]],
76-
alphabet: List[str] = None,
7775
experiment_id: str = None,
7876
tmp_folder: Path = None,
7977
eager_repair: bool = False,
@@ -90,6 +88,10 @@ def __init__(
9088
num_workers=num_workers,
9189
evaluation_budget=evaluation_budget,
9290
)
91+
if not (Path.home() / "foldx" / "foldx").exists():
92+
raise FoldXNotFoundException(
93+
"FoldX wasn't found in ~/foldx/foldx. Please install it."
94+
)
9395
if not force_isolation:
9496
try:
9597
from poli.objective_repository.foldx_stability_and_sasa.isolated_function import (
@@ -181,7 +183,6 @@ def get_setup_information(self) -> BlackBoxInformation:
181183
def create(
182184
self,
183185
wildtype_pdb_path: Union[Path, List[Path]],
184-
alphabet: List[str] = None,
185186
experiment_id: str = None,
186187
tmp_folder: Path = None,
187188
eager_repair: bool = False,
@@ -200,9 +201,6 @@ def create(
200201
----------
201202
wildtype_pdb_path : Union[Path, List[Path]]
202203
Path or list of paths to the wildtype PDB files.
203-
alphabet : List[str], optional
204-
List of amino acid symbols. By default, we use the
205-
20 amino acids shown in poli.core.util.proteins.defaults.
206204
experiment_id : str, optional
207205
Identifier for the experiment.
208206
tmp_folder : Path, optional
@@ -261,12 +259,8 @@ def create(
261259

262260
# We use the default alphabet if None was provided.
263261
# See ENCODING in foldx_utils.py
264-
if alphabet is None:
265-
alphabet = self.get_setup_information().get_alphabet()
266-
267262
f = FoldXStabilityAndSASABlackBox(
268263
wildtype_pdb_path=wildtype_pdb_path,
269-
alphabet=alphabet,
270264
experiment_id=experiment_id,
271265
tmp_folder=tmp_folder,
272266
eager_repair=eager_repair,

0 commit comments

Comments
 (0)