Skip to content

Commit 063309c

Browse files
authored
Add support for batch priorities
* Add support for batch priorities * Include priorities in documentation * Update README.md
1 parent aa74c39 commit 063309c

4 files changed

Lines changed: 37 additions & 5 deletions

File tree

README.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ m1wrapper = MoleculeOneWrapper(api_token, 'https://app.molecule.one')
1818
server, but you will need to provide custom value if you're using a dedicated solution.
1919

2020
### Running batch scoring request:
21-
2221
```py
2322
search = m1wrapper.run_batch_search(
2423
targets=['cc', 'O=C(Nc1cc(Nc2nc(-c3cnccc3)ccn2)c(cc1)C)c3ccc(cc3)CN3CCN(CC3)C'],
@@ -28,7 +27,28 @@ search = m1wrapper.run_batch_search(
2827
- *targets*: list of target compounds in SMILES format
2928
- *parameters* (optional): additional configuration for your batch
3029
scoring request. See [Batch Scoring API](https://github.com/molecule-one/api/blob/master/batch-scoring.md) for more information.
30+
- *priority* (optional): priority of the batch request.
3131
- *starting_materials* (optional): list of available compounds in SMILES format
32+
33+
### Batch scoring priorities:
34+
Priorities are defined as integers in a range of 1 to 10. Requests with higher priority will be processed before those with lower priority.
35+
For convenience, we also define a `Priority` enum with the following variants:
36+
- `Priority.LOWEST` (1)
37+
- `Priority.LOW` (3)
38+
- `Priority.NORMAL` (5, default)
39+
- `Priority.HIGH` (8)
40+
- `Priority.HIGHEST` (10)
41+
42+
#### Example:
43+
```py
44+
from m1wrapper import MoleculeOneWrapper, Priority
45+
m1wrapper = MoleculeOneWrapper(api_token, 'https://app.molecule.one')
46+
search = m1wrapper.run_batch_search(
47+
targets=['cc', 'O=C(Nc1cc(Nc2nc(-c3cnccc3)ccn2)c(cc1)C)c3ccc(cc3)CN3CCN(CC3)C'],
48+
parameters={'exploratory_search': False, 'detail_level': 'score'},
49+
priority=Priority.HIGH)
50+
```
51+
3252
### Getting exisiting scoring request by id:
3353
```py
3454
search = m1wrapper.get_batch_search(id)

m1wrapper/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from .m1wrapper import MoleculeOneWrapper
1+
from .m1wrapper import MoleculeOneWrapper, Priority

m1wrapper/m1wrapper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
from typing import List, Dict
2+
from enum import IntEnum
23

34
from .search import BatchSearch
45
from .config import api_token_version, wrapper_version, api_base_url
56

7+
class Priority(IntEnum):
8+
LOWEST = 1,
9+
LOW = 3,
10+
NORMAL = 5,
11+
HIGH = 8,
12+
HIGHEST = 10
613

714
class MoleculeOneWrapper:
815
"""
@@ -29,13 +36,15 @@ def run_batch_search(
2936
self,
3037
targets: List[str],
3138
parameters: Dict = None,
39+
priority = Priority.NORMAL,
3240
starting_materials: List[str] = None,
3341
) -> BatchSearch:
3442
return BatchSearch(
3543
self.api_base_url,
3644
self.request_headers,
3745
targets=targets,
3846
parameters=parameters,
47+
priority=int(priority),
3948
starting_materials=starting_materials
4049
)
4150

m1wrapper/search.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def __init__(
4343
search_id=None,
4444
targets=None,
4545
parameters=None,
46+
priority=None,
4647
starting_materials=None,
4748
):
4849
self.search_id = search_id
@@ -53,14 +54,16 @@ def __init__(
5354
new_search = self.__run(
5455
targets=targets,
5556
parameters=parameters,
57+
priority=priority,
5658
starting_materials=starting_materials
5759
)
5860
self.search_id = new_search['id']
5961

60-
def __prepare_payload(self, targets, parameters, starting_materials) -> dict:
62+
def __prepare_payload(self, targets, parameters, priority, starting_materials ) -> dict:
6163
payload = {
6264
'targets': targets,
6365
'params': parameters or {},
66+
'priority': priority
6467
}
6568
if starting_materials is not None:
6669
payload["startingMaterials"] = starting_materials
@@ -81,8 +84,8 @@ def __prepare_http(self):
8184
http.mount("http://", adapter)
8285
return http
8386

84-
def __run(self, targets, parameters, starting_materials):
85-
payload = self.__prepare_payload(targets, parameters, starting_materials)
87+
def __run(self, targets, parameters, priority, starting_materials):
88+
payload = self.__prepare_payload(targets, parameters, priority, starting_materials)
8689
response = self.http.post(
8790
urljoin(self.base_url, api_search_endpoint),
8891
data=json.dumps(payload),

0 commit comments

Comments
 (0)