openprotein-python 0.5.0.dev1__py3-none-any.whl → 0.5.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openprotein/__init__.py +53 -23
- openprotein/api/__init__.py +0 -1
- openprotein/api/align.py +1 -23
- openprotein/api/deprecated/poet.py +5 -1
- openprotein/api/design.py +12 -8
- openprotein/api/designer.py +262 -0
- openprotein/api/embedding.py +37 -15
- openprotein/api/fold.py +5 -5
- openprotein/api/job.py +3 -0
- openprotein/api/predict.py +43 -9
- openprotein/api/predictor.py +110 -6
- openprotein/api/svd.py +48 -5
- openprotein/api/umap.py +247 -0
- openprotein/app/__init__.py +13 -4
- openprotein/app/models/__init__.py +19 -7
- openprotein/app/models/align/msa.py +1 -8
- openprotein/app/models/align/prompt.py +1 -6
- openprotein/app/models/deprecated/poet.py +4 -3
- openprotein/app/models/design.py +10 -7
- openprotein/app/models/designer.py +121 -0
- openprotein/app/models/embeddings/base.py +82 -14
- openprotein/app/models/embeddings/future.py +36 -7
- openprotein/app/models/embeddings/poet.py +79 -24
- openprotein/app/models/fold/alphafold2.py +11 -7
- openprotein/app/models/fold/esmfold.py +5 -2
- openprotein/app/models/futures.py +21 -6
- openprotein/app/models/predict.py +81 -11
- openprotein/app/models/predictor/predict.py +3 -3
- openprotein/app/models/predictor/predictor.py +169 -6
- openprotein/app/models/predictor/validate.py +37 -0
- openprotein/app/models/svd.py +99 -10
- openprotein/app/models/train.py +14 -11
- openprotein/app/models/umap.py +156 -0
- openprotein/app/services/__init__.py +10 -4
- openprotein/app/services/design.py +9 -7
- openprotein/app/services/designer.py +73 -0
- openprotein/app/services/job.py +16 -3
- openprotein/app/services/predict.py +11 -5
- openprotein/app/services/umap.py +97 -0
- openprotein/auth.py +21 -0
- openprotein/base.py +33 -31
- openprotein/csv.py +26 -0
- openprotein/schemas/__init__.py +23 -9
- openprotein/schemas/align.py +7 -13
- openprotein/schemas/design.py +151 -41
- openprotein/schemas/designer.py +38 -0
- openprotein/schemas/embeddings.py +3 -4
- openprotein/schemas/features.py +7 -0
- openprotein/schemas/job.py +19 -0
- openprotein/schemas/predict.py +2 -3
- openprotein/schemas/predictor.py +4 -12
- openprotein/schemas/svd.py +2 -3
- openprotein/schemas/train.py +3 -3
- openprotein/schemas/umap.py +35 -0
- {openprotein_python-0.5.0.dev1.dist-info → openprotein_python-0.5.2.dist-info}/METADATA +6 -7
- openprotein_python-0.5.2.dist-info/RECORD +88 -0
- {openprotein_python-0.5.0.dev1.dist-info → openprotein_python-0.5.2.dist-info}/WHEEL +1 -1
- openprotein_python-0.5.0.dev1.dist-info/RECORD +0 -76
- {openprotein_python-0.5.0.dev1.dist-info → openprotein_python-0.5.2.dist-info}/licenses/LICENSE.txt +0 -0
openprotein/base.py
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import openprotein.config as config
|
|
2
|
-
|
|
3
|
-
import requests
|
|
4
|
-
from urllib.parse import urljoin
|
|
5
1
|
from typing import Union
|
|
2
|
+
from urllib.parse import urljoin
|
|
6
3
|
|
|
4
|
+
import requests
|
|
7
5
|
from requests.adapters import HTTPAdapter
|
|
8
6
|
from requests.packages.urllib3.util.retry import Retry
|
|
9
|
-
|
|
7
|
+
|
|
8
|
+
import openprotein.config as config
|
|
9
|
+
from openprotein.errors import APIError, AuthError, HTTPError
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class BearerAuth(requests.auth.AuthBase):
|
|
@@ -38,23 +38,28 @@ class APISession(requests.Session):
|
|
|
38
38
|
>>> session = APISession("username", "password")
|
|
39
39
|
"""
|
|
40
40
|
|
|
41
|
-
def __init__(
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
def __init__(
|
|
42
|
+
self,
|
|
43
|
+
username: str,
|
|
44
|
+
password: str,
|
|
45
|
+
backend: str = "https://api.openprotein.ai/api/",
|
|
46
|
+
timeout: int = 180,
|
|
47
|
+
):
|
|
45
48
|
super().__init__()
|
|
46
49
|
self.backend = backend
|
|
47
50
|
self.verify = True
|
|
48
51
|
self.timeout = timeout
|
|
49
52
|
|
|
50
53
|
# Custom retry strategies
|
|
51
|
-
#auto retry for pesky connection reset errors and others
|
|
54
|
+
# auto retry for pesky connection reset errors and others
|
|
52
55
|
# 503 will catch if BE is refreshing
|
|
53
|
-
retry = Retry(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
retry = Retry(
|
|
57
|
+
total=4,
|
|
58
|
+
backoff_factor=3, # 0,1,4,13s
|
|
59
|
+
status_forcelist=[500, 502, 503, 504, 101, 104],
|
|
60
|
+
)
|
|
56
61
|
adapter = HTTPAdapter(max_retries=retry)
|
|
57
|
-
self.mount(
|
|
62
|
+
self.mount("https://", adapter)
|
|
58
63
|
self.login(username, password)
|
|
59
64
|
|
|
60
65
|
def post(self, url, data=None, json=None, **kwargs):
|
|
@@ -68,30 +73,27 @@ class APISession(requests.Session):
|
|
|
68
73
|
:rtype: requests.Response
|
|
69
74
|
"""
|
|
70
75
|
timeout = self.timeout
|
|
71
|
-
if
|
|
72
|
-
timeout = kwargs.pop(
|
|
73
|
-
|
|
74
|
-
return self.request(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
def login(self, username:str, password:str):
|
|
82
|
-
"""
|
|
76
|
+
if "timeout" in kwargs:
|
|
77
|
+
timeout = kwargs.pop("timeout")
|
|
78
|
+
|
|
79
|
+
return self.request(
|
|
80
|
+
"POST", url, data=data, json=json, timeout=timeout, **kwargs
|
|
81
|
+
)
|
|
82
|
+
|
|
83
|
+
def login(self, username: str, password: str):
|
|
84
|
+
"""
|
|
83
85
|
Authenticate connection to OpenProtein with your credentials.
|
|
84
|
-
|
|
86
|
+
|
|
85
87
|
Parameters
|
|
86
88
|
-----------
|
|
87
89
|
username: str
|
|
88
|
-
username
|
|
90
|
+
username
|
|
89
91
|
password: str
|
|
90
92
|
password
|
|
91
93
|
"""
|
|
92
94
|
self.auth = self._get_auth_token(username, password)
|
|
93
95
|
|
|
94
|
-
def _get_auth_token(self, username:str, password:str):
|
|
96
|
+
def _get_auth_token(self, username: str, password: str):
|
|
95
97
|
endpoint = "v1/login/access-token"
|
|
96
98
|
url = urljoin(self.backend, endpoint)
|
|
97
99
|
try:
|
|
@@ -106,9 +108,9 @@ class APISession(requests.Session):
|
|
|
106
108
|
|
|
107
109
|
result = response.json()
|
|
108
110
|
token = result.get("access_token")
|
|
109
|
-
if token is None:
|
|
111
|
+
if token is None:
|
|
110
112
|
raise AuthError("Unable to authenticate with given credentials.")
|
|
111
|
-
return BearerAuth(token)
|
|
113
|
+
return BearerAuth(token)
|
|
112
114
|
|
|
113
115
|
def request(
|
|
114
116
|
self, method: Union[str, bytes], url: Union[str, bytes], *args, **kwargs
|
openprotein/csv.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import codecs
|
|
2
|
+
import csv
|
|
3
|
+
from typing import Iterator
|
|
4
|
+
|
|
5
|
+
import requests
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def csv_stream(response: requests.Response) -> Iterator[list[str]]:
|
|
9
|
+
"""
|
|
10
|
+
Returns a CSV reader from a requests.Response object.
|
|
11
|
+
|
|
12
|
+
Parameters
|
|
13
|
+
----------
|
|
14
|
+
response : requests.Response
|
|
15
|
+
The response object to parse.
|
|
16
|
+
|
|
17
|
+
Returns
|
|
18
|
+
-------
|
|
19
|
+
csv.reader
|
|
20
|
+
A csv reader object for the response.
|
|
21
|
+
"""
|
|
22
|
+
# get raw bytes stream
|
|
23
|
+
raw_content = response.raw
|
|
24
|
+
# force the response to be encoded as utf-8
|
|
25
|
+
content = codecs.getreader("utf-8")(raw_content)
|
|
26
|
+
return csv.reader(content)
|
openprotein/schemas/__init__.py
CHANGED
|
@@ -16,13 +16,16 @@ from .predict import (
|
|
|
16
16
|
PredictJob as WorkflowPredictJob,
|
|
17
17
|
PredictSingleSiteJob as WorkflowPredictSingleSiteJob,
|
|
18
18
|
)
|
|
19
|
-
from .design import
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
from .design import (
|
|
20
|
+
ModelCriterion,
|
|
21
|
+
NMutationCriterion,
|
|
22
|
+
n_mutations,
|
|
23
|
+
Subcriterion,
|
|
24
|
+
Criterion,
|
|
25
|
+
Criteria,
|
|
26
|
+
DesignJobCreate as WorkflowDesignJobCreate,
|
|
27
|
+
DesignJob as WorkflowDesignJob,
|
|
28
|
+
Design as WorkflowDesign,
|
|
26
29
|
)
|
|
27
30
|
from .align import MSAJob, MSASamplingMethod, PoetInputType, PromptJob, PromptPostParams
|
|
28
31
|
from .embeddings import (
|
|
@@ -39,15 +42,20 @@ from .embeddings import (
|
|
|
39
42
|
GenerateJob,
|
|
40
43
|
)
|
|
41
44
|
from .fold import FoldJob
|
|
45
|
+
from .features import FeatureType
|
|
42
46
|
from .svd import (
|
|
43
47
|
SVDMetadata,
|
|
44
|
-
FitJob,
|
|
48
|
+
FitJob as SVDFitJob,
|
|
45
49
|
EmbeddingsJob as SVDEmbeddingsJob,
|
|
46
50
|
)
|
|
51
|
+
from .umap import (
|
|
52
|
+
UMAPMetadata,
|
|
53
|
+
FitJob as UMAPFitJob,
|
|
54
|
+
EmbeddingsJob as UMAPEmbeddingsJob,
|
|
55
|
+
)
|
|
47
56
|
from .predictor import (
|
|
48
57
|
Constraints,
|
|
49
58
|
CVJob,
|
|
50
|
-
FeatureType,
|
|
51
59
|
Kernel,
|
|
52
60
|
PredictJob,
|
|
53
61
|
PredictMultiJob,
|
|
@@ -57,3 +65,9 @@ from .predictor import (
|
|
|
57
65
|
PredictSingleSiteJob,
|
|
58
66
|
TrainJob,
|
|
59
67
|
)
|
|
68
|
+
from .designer import (
|
|
69
|
+
Design,
|
|
70
|
+
DesignJob,
|
|
71
|
+
DesignAlgorithm,
|
|
72
|
+
DesignConstraint,
|
|
73
|
+
)
|
openprotein/schemas/align.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from enum import Enum
|
|
2
2
|
from typing import Literal
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel, Field
|
|
4
|
+
from pydantic import BaseModel, Field
|
|
5
5
|
|
|
6
6
|
from .job import Job, JobType
|
|
7
7
|
|
|
@@ -34,22 +34,16 @@ class PromptPostParams(BaseModel):
|
|
|
34
34
|
|
|
35
35
|
|
|
36
36
|
class MSAJob(Job):
|
|
37
|
-
msa_id: str | None = None
|
|
38
37
|
job_type: Literal[JobType.align_align]
|
|
39
38
|
|
|
40
|
-
@
|
|
41
|
-
def
|
|
42
|
-
|
|
43
|
-
values["msa_id"] = values.get("job_id")
|
|
44
|
-
return values
|
|
39
|
+
@property
|
|
40
|
+
def msa_id(self):
|
|
41
|
+
return self.msa_id
|
|
45
42
|
|
|
46
43
|
|
|
47
44
|
class PromptJob(MSAJob, Job):
|
|
48
|
-
prompt_id: str | None = None
|
|
49
45
|
job_type: Literal[JobType.align_prompt]
|
|
50
46
|
|
|
51
|
-
@
|
|
52
|
-
def
|
|
53
|
-
|
|
54
|
-
values["prompt_id"] = values.get("job_id")
|
|
55
|
-
return values
|
|
47
|
+
@property
|
|
48
|
+
def prompt_id(self):
|
|
49
|
+
return self.job_id
|
openprotein/schemas/design.py
CHANGED
|
@@ -1,75 +1,190 @@
|
|
|
1
1
|
import re
|
|
2
|
-
from datetime import datetime
|
|
3
2
|
from enum import Enum
|
|
4
|
-
from typing import Literal
|
|
3
|
+
from typing import Any, Literal
|
|
5
4
|
|
|
6
|
-
from pydantic import
|
|
5
|
+
from pydantic import (
|
|
6
|
+
BaseModel,
|
|
7
|
+
ConfigDict,
|
|
8
|
+
Field,
|
|
9
|
+
RootModel,
|
|
10
|
+
field_validator,
|
|
11
|
+
model_serializer,
|
|
12
|
+
)
|
|
7
13
|
|
|
8
14
|
from .job import Job, JobType
|
|
9
15
|
|
|
10
16
|
|
|
11
|
-
class
|
|
17
|
+
class SubscoreMetadata(BaseModel):
|
|
12
18
|
y_mu: float | None = None
|
|
13
19
|
y_var: float | None = None
|
|
14
20
|
|
|
15
21
|
|
|
16
22
|
class DesignSubscore(BaseModel):
|
|
17
23
|
score: float
|
|
18
|
-
metadata:
|
|
24
|
+
metadata: SubscoreMetadata
|
|
19
25
|
|
|
20
26
|
|
|
21
|
-
class
|
|
27
|
+
class DesignResult(BaseModel):
|
|
22
28
|
step: int
|
|
23
29
|
sample_index: int
|
|
24
30
|
sequence: str
|
|
25
31
|
# scores: List[int]
|
|
26
32
|
# subscores_metadata: List[List[DesignSubscore]]
|
|
27
|
-
scores: list[float]
|
|
28
|
-
|
|
33
|
+
# scores: list[float]
|
|
34
|
+
scores: list[list[DesignSubscore]] = Field(..., alias="subscores_metadata")
|
|
29
35
|
# umap1: float
|
|
30
36
|
# umap2: float
|
|
31
37
|
|
|
32
38
|
|
|
33
|
-
class
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
start_date: datetime
|
|
39
|
-
end_date: datetime | None
|
|
39
|
+
class DesignJob(Job):
|
|
40
|
+
job_type: Literal[JobType.workflow_design]
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Design(DesignJob):
|
|
40
44
|
assay_id: str
|
|
41
45
|
num_rows: int
|
|
42
|
-
result: list[
|
|
46
|
+
result: list[DesignResult]
|
|
47
|
+
|
|
43
48
|
|
|
49
|
+
class CriterionType(str, Enum):
|
|
50
|
+
model = "model"
|
|
51
|
+
n_mutations = "n_mutations"
|
|
44
52
|
|
|
45
|
-
class DirectionEnum(str, Enum):
|
|
46
|
-
gt = ">"
|
|
47
|
-
lt = "<"
|
|
48
|
-
eq = "="
|
|
49
53
|
|
|
54
|
+
class Subcriterion(BaseModel):
|
|
55
|
+
|
|
56
|
+
criterion_type: CriterionType
|
|
57
|
+
|
|
58
|
+
def __and__(self, other: "Subcriterion | Criterion | Any") -> "Criterion":
|
|
59
|
+
"""Returns a Criterion with the two subcriteria AND-ed."""
|
|
60
|
+
others = []
|
|
61
|
+
if isinstance(other, Subcriterion):
|
|
62
|
+
others = [other]
|
|
63
|
+
elif isinstance(other, Criterion):
|
|
64
|
+
others = other.root
|
|
65
|
+
else:
|
|
66
|
+
raise ValueError(
|
|
67
|
+
f"Expected to chain only with criterion or subcriterion, got {type(other)}"
|
|
68
|
+
)
|
|
69
|
+
return Criterion([self] + others) # type: ignore - doesnt like Self
|
|
70
|
+
|
|
71
|
+
def __or__(self, other: "Subcriterion | Criterion | Any") -> "Criteria":
|
|
72
|
+
"""Returns a Criteria with the two subcriteria OR-ed."""
|
|
73
|
+
if isinstance(other, Criterion):
|
|
74
|
+
pass
|
|
75
|
+
elif isinstance(other, Subcriterion):
|
|
76
|
+
other = Criterion([other])
|
|
77
|
+
else:
|
|
78
|
+
raise ValueError(
|
|
79
|
+
f"Expected to chain only with criterion or subcriterion, got {type(other)}"
|
|
80
|
+
)
|
|
81
|
+
return Criteria([Criterion([self]), other])
|
|
50
82
|
|
|
51
|
-
class Criterion(BaseModel):
|
|
52
|
-
target: float
|
|
53
|
-
weight: float
|
|
54
|
-
direction: str
|
|
55
83
|
|
|
84
|
+
class ModelCriterion(Subcriterion):
|
|
56
85
|
|
|
57
|
-
class
|
|
58
|
-
|
|
86
|
+
class Criterion(BaseModel):
|
|
87
|
+
class DirectionEnum(str, Enum):
|
|
88
|
+
gt = ">"
|
|
89
|
+
lt = "<"
|
|
90
|
+
eq = "="
|
|
91
|
+
|
|
92
|
+
weight: float = 1.0
|
|
93
|
+
direction: DirectionEnum | None = None
|
|
94
|
+
target: float | None = None
|
|
95
|
+
|
|
96
|
+
criterion_type: CriterionType = CriterionType.model
|
|
59
97
|
model_id: str
|
|
60
98
|
measurement_name: str
|
|
61
|
-
criterion: Criterion
|
|
99
|
+
criterion: Criterion = Criterion()
|
|
100
|
+
|
|
101
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
102
|
+
|
|
103
|
+
def __mul__(self, weight: float) -> "ModelCriterion":
|
|
104
|
+
self.criterion.weight = weight
|
|
105
|
+
return self
|
|
106
|
+
|
|
107
|
+
def __lt__(self, other: float) -> "ModelCriterion":
|
|
108
|
+
self.criterion.target = other
|
|
109
|
+
self.criterion.direction = ModelCriterion.Criterion.DirectionEnum.lt
|
|
110
|
+
return self
|
|
111
|
+
|
|
112
|
+
def __gt__(self, other: float) -> "ModelCriterion":
|
|
113
|
+
self.criterion.target = other
|
|
114
|
+
self.criterion.direction = ModelCriterion.Criterion.DirectionEnum.gt
|
|
115
|
+
return self
|
|
116
|
+
|
|
117
|
+
def __eq__(self, other: float) -> "ModelCriterion":
|
|
118
|
+
self.criterion.target = other
|
|
119
|
+
self.criterion.direction = ModelCriterion.Criterion.DirectionEnum.eq
|
|
120
|
+
return self
|
|
121
|
+
|
|
122
|
+
__rmul__ = __mul__
|
|
62
123
|
|
|
63
|
-
|
|
64
|
-
|
|
124
|
+
@model_serializer(mode="wrap")
|
|
125
|
+
def validate_criterion_before_serialize(self, handler):
|
|
126
|
+
if (
|
|
127
|
+
self.criterion is None
|
|
128
|
+
or self.criterion.direction is None
|
|
129
|
+
or self.criterion.target is None
|
|
130
|
+
):
|
|
131
|
+
raise ValueError("Expected direction and target to be set")
|
|
132
|
+
return handler(self)
|
|
65
133
|
|
|
66
134
|
|
|
67
|
-
class NMutationCriterion(
|
|
68
|
-
criterion_type:
|
|
69
|
-
|
|
135
|
+
class NMutationCriterion(Subcriterion):
|
|
136
|
+
criterion_type: CriterionType = CriterionType.n_mutations
|
|
137
|
+
sequences: list[str] = Field(default_factory=list)
|
|
70
138
|
|
|
139
|
+
@model_serializer(mode="wrap")
|
|
140
|
+
def remove_empty_sequences(self, handler):
|
|
141
|
+
d = handler(self)
|
|
142
|
+
if not d["sequences"]:
|
|
143
|
+
del d["sequences"]
|
|
144
|
+
return d
|
|
71
145
|
|
|
72
|
-
|
|
146
|
+
|
|
147
|
+
n_mutations = NMutationCriterion
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
class Criterion(RootModel):
|
|
151
|
+
root: list[ModelCriterion | NMutationCriterion | Subcriterion]
|
|
152
|
+
|
|
153
|
+
def __and__(self, other: "Criterion | Subcriterion") -> "Criterion":
|
|
154
|
+
"""Returns a Criteria with the other criterion OR-ed with itself."""
|
|
155
|
+
others = []
|
|
156
|
+
|
|
157
|
+
if isinstance(other, Subcriterion):
|
|
158
|
+
others = [other]
|
|
159
|
+
elif isinstance(other, Criterion):
|
|
160
|
+
others = other.root
|
|
161
|
+
|
|
162
|
+
return Criterion(self.root + others)
|
|
163
|
+
|
|
164
|
+
def __or__(self, other: "Criterion | Subcriterion") -> "Criteria":
|
|
165
|
+
"""Returns a Criteria with the other criterion OR-ed with itself."""
|
|
166
|
+
|
|
167
|
+
if isinstance(other, Criterion):
|
|
168
|
+
pass
|
|
169
|
+
elif isinstance(other, Subcriterion):
|
|
170
|
+
other = Criterion([other])
|
|
171
|
+
|
|
172
|
+
return Criteria([self, other])
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
class Criteria(RootModel):
|
|
176
|
+
root: list[Criterion]
|
|
177
|
+
|
|
178
|
+
def __or__(self, other: "Criterion | Subcriterion | Criteria") -> "Criteria":
|
|
179
|
+
"""Returns a Criteria with the other criteria OR-ed with itself."""
|
|
180
|
+
if isinstance(other, Criteria):
|
|
181
|
+
pass
|
|
182
|
+
if isinstance(other, Criterion):
|
|
183
|
+
other = Criteria([other])
|
|
184
|
+
elif isinstance(other, Subcriterion):
|
|
185
|
+
other = Criteria([Criterion([other])])
|
|
186
|
+
|
|
187
|
+
return Criteria(self.root + other.root)
|
|
73
188
|
|
|
74
189
|
|
|
75
190
|
class DesignConstraint:
|
|
@@ -114,8 +229,8 @@ class DesignConstraint:
|
|
|
114
229
|
|
|
115
230
|
class DesignJobCreate(BaseModel):
|
|
116
231
|
assay_id: str
|
|
117
|
-
criteria:
|
|
118
|
-
num_steps: int
|
|
232
|
+
criteria: Criteria
|
|
233
|
+
num_steps: int = 8
|
|
119
234
|
pop_size: int | None = None
|
|
120
235
|
n_offsprings: int | None = None
|
|
121
236
|
crossover_prob: float | None = None
|
|
@@ -123,8 +238,7 @@ class DesignJobCreate(BaseModel):
|
|
|
123
238
|
mutation_average_mutations_per_seq: int | None = None
|
|
124
239
|
allowed_tokens: DesignConstraint | dict[int, list[str]] | None = None
|
|
125
240
|
|
|
126
|
-
|
|
127
|
-
arbitrary_types_allowed = True
|
|
241
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
128
242
|
|
|
129
243
|
@field_validator("allowed_tokens", mode="before")
|
|
130
244
|
def ensure_dict(cls, v):
|
|
@@ -245,7 +359,3 @@ def no_change(sequence: str):
|
|
|
245
359
|
|
|
246
360
|
def keep_cys(sequence: str):
|
|
247
361
|
return {k + 1: [v] for k, v in enumerate(sequence) if v == "C"}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
class DesignJob(Job):
|
|
251
|
-
job_type: Literal[JobType.workflow_design]
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from enum import Enum
|
|
3
|
+
from typing import Literal
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from .design import Criteria, DesignConstraint
|
|
8
|
+
from .job import Job, JobStatus, JobType
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class DesignAlgorithm(str, Enum):
|
|
12
|
+
genetic_algorithm = "genetic-algorithm"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class Design(BaseModel):
|
|
16
|
+
id: str
|
|
17
|
+
status: JobStatus
|
|
18
|
+
progress_counter: int
|
|
19
|
+
created_date: datetime
|
|
20
|
+
algorithm: DesignAlgorithm
|
|
21
|
+
num_rows: int
|
|
22
|
+
num_steps: int
|
|
23
|
+
assay_id: str
|
|
24
|
+
criteria: Criteria
|
|
25
|
+
allowed_tokens: dict[str, list[str]] | None
|
|
26
|
+
pop_size: int
|
|
27
|
+
# ga params
|
|
28
|
+
n_offsprings: int
|
|
29
|
+
crossover_prob: float
|
|
30
|
+
crossover_prob_pointwise: float
|
|
31
|
+
mutation_average_mutations_per_seq: int
|
|
32
|
+
|
|
33
|
+
def is_done(self):
|
|
34
|
+
return self.status.done()
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class DesignJob(Job):
|
|
38
|
+
job_type: Literal[JobType.designer]
|
|
@@ -4,7 +4,7 @@ from enum import Enum
|
|
|
4
4
|
from typing import Literal
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
|
-
from pydantic import BaseModel, Field
|
|
7
|
+
from pydantic import BaseModel, ConfigDict, Field
|
|
8
8
|
|
|
9
9
|
from .job import BatchJob, Job, JobType
|
|
10
10
|
|
|
@@ -51,12 +51,11 @@ class EmbeddedSequence(BaseModel):
|
|
|
51
51
|
Represented as an iterable yielding the sequence followed by the embedding.
|
|
52
52
|
"""
|
|
53
53
|
|
|
54
|
-
class Config:
|
|
55
|
-
arbitrary_types_allowed = True
|
|
56
|
-
|
|
57
54
|
sequence: bytes
|
|
58
55
|
embedding: np.ndarray
|
|
59
56
|
|
|
57
|
+
model_config = ConfigDict(arbitrary_types_allowed=True)
|
|
58
|
+
|
|
60
59
|
def __iter__(self):
|
|
61
60
|
yield self.sequence
|
|
62
61
|
yield self.embedding
|
openprotein/schemas/job.py
CHANGED
|
@@ -44,6 +44,9 @@ class JobType(str, Enum):
|
|
|
44
44
|
svd_fit = "/svd/fit"
|
|
45
45
|
svd_embed = "/svd/embed"
|
|
46
46
|
|
|
47
|
+
umap_fit = "/umap/fit"
|
|
48
|
+
umap_embed = "/umap/embed"
|
|
49
|
+
|
|
47
50
|
embeddings_fold = "/embeddings/fold"
|
|
48
51
|
|
|
49
52
|
# predictor jobs
|
|
@@ -54,6 +57,9 @@ class JobType(str, Enum):
|
|
|
54
57
|
predictor_predict_multi = "/predictor/predict_multi"
|
|
55
58
|
predictor_predict_multi_single_site = "/predictor/predict_multi_single_site"
|
|
56
59
|
|
|
60
|
+
# designer
|
|
61
|
+
designer = "/design"
|
|
62
|
+
|
|
57
63
|
|
|
58
64
|
class JobStatus(str, Enum):
|
|
59
65
|
PENDING = "PENDING"
|
|
@@ -102,6 +108,19 @@ class Job(BaseModel):
|
|
|
102
108
|
raise ValueError(f"Error parsing job from obj: {obj}: {e}")
|
|
103
109
|
return job # type: ignore - static checker cannot know runtime type
|
|
104
110
|
|
|
111
|
+
# hide extra allowed fields
|
|
112
|
+
def __repr_args__(self):
|
|
113
|
+
for k, v in self.__dict__.items():
|
|
114
|
+
field = self.model_fields.get(k)
|
|
115
|
+
if field and field.repr:
|
|
116
|
+
yield k, v
|
|
117
|
+
|
|
118
|
+
yield from (
|
|
119
|
+
(k, getattr(self, k))
|
|
120
|
+
for k, v in self.model_computed_fields.items()
|
|
121
|
+
if v.repr
|
|
122
|
+
)
|
|
123
|
+
|
|
105
124
|
# allows to carry over subclassed job fields when factory creating
|
|
106
125
|
model_config = ConfigDict(extra="allow")
|
|
107
126
|
|
openprotein/schemas/predict.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from datetime import datetime
|
|
2
2
|
from typing import Literal
|
|
3
3
|
|
|
4
|
-
from pydantic import BaseModel,
|
|
4
|
+
from pydantic import BaseModel, ConfigDict
|
|
5
5
|
|
|
6
6
|
from .job import Job, JobType
|
|
7
7
|
|
|
@@ -44,8 +44,7 @@ class Prediction(BaseModel):
|
|
|
44
44
|
model_name: str
|
|
45
45
|
properties: dict[str, dict[str, float]]
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
protected_namespaces = ()
|
|
47
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
49
48
|
|
|
50
49
|
|
|
51
50
|
class PredictJobBase(BaseModel):
|
openprotein/schemas/predictor.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from enum import Enum
|
|
2
1
|
from typing import Literal
|
|
3
2
|
|
|
4
|
-
from pydantic import BaseModel
|
|
3
|
+
from pydantic import BaseModel, ConfigDict
|
|
5
4
|
|
|
5
|
+
from .features import FeatureType
|
|
6
6
|
from .job import Job, JobStatus, JobType
|
|
7
7
|
|
|
8
8
|
|
|
@@ -15,19 +15,12 @@ class Constraints(BaseModel):
|
|
|
15
15
|
sequence_length: int | None = None
|
|
16
16
|
|
|
17
17
|
|
|
18
|
-
class FeatureType(str, Enum):
|
|
19
|
-
|
|
20
|
-
PLM = "PLM"
|
|
21
|
-
SVD = "SVD"
|
|
22
|
-
|
|
23
|
-
|
|
24
18
|
class Features(BaseModel):
|
|
25
19
|
type: FeatureType
|
|
26
20
|
model_id: str | None = None
|
|
27
21
|
reduction: str | None = None
|
|
28
22
|
|
|
29
|
-
|
|
30
|
-
protected_namespaces = ()
|
|
23
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
31
24
|
|
|
32
25
|
|
|
33
26
|
class PredictorArgs(BaseModel):
|
|
@@ -55,8 +48,7 @@ class PredictorMetadata(BaseModel):
|
|
|
55
48
|
def is_done(self):
|
|
56
49
|
return self.status.done()
|
|
57
50
|
|
|
58
|
-
|
|
59
|
-
protected_namespaces = ()
|
|
51
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
60
52
|
|
|
61
53
|
|
|
62
54
|
class TrainJob(Job):
|
openprotein/schemas/svd.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from datetime import datetime
|
|
4
4
|
from typing import Literal
|
|
5
5
|
|
|
6
|
-
from pydantic import BaseModel,
|
|
6
|
+
from pydantic import BaseModel, ConfigDict
|
|
7
7
|
|
|
8
8
|
from .job import BatchJob, Job, JobStatus, JobType
|
|
9
9
|
|
|
@@ -20,8 +20,7 @@ class SVDMetadata(BaseModel):
|
|
|
20
20
|
def is_done(self):
|
|
21
21
|
return self.status.done()
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
protected_namespaces = ()
|
|
23
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
class FitJob(Job):
|
openprotein/schemas/train.py
CHANGED
|
@@ -16,9 +16,9 @@ class CVItem(BaseModel):
|
|
|
16
16
|
|
|
17
17
|
class CVJob(Job):
|
|
18
18
|
job_type: Literal[JobType.workflow_crossvalidate]
|
|
19
|
-
num_rows: int
|
|
20
|
-
page_size: int
|
|
21
|
-
page_offset: int
|
|
19
|
+
num_rows: int | None = None
|
|
20
|
+
page_size: int | None = None
|
|
21
|
+
page_offset: int | None = None
|
|
22
22
|
result: list[CVItem] | None = None
|
|
23
23
|
|
|
24
24
|
|