Skip to content

Commit 1a39219

Browse files
author
basiekjusz
committed
Rename metadata to targets_metadata
1 parent 521c3da commit 1a39219

3 files changed

Lines changed: 58 additions & 29 deletions

File tree

README.md

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,42 +7,52 @@
77
```
88
pip install git+https://github.com/molecule-one/m1wrapper-python
99
```
10+
1011
### Initialization:
12+
1113
```py
1214
from m1wrapper import MoleculeOneWrapper
1315
m1wrapper = MoleculeOneWrapper(api_token, 'https://app.molecule.one')
1416
```
15-
- *api_token*: API token you'll need to authorize in our system. You can
17+
18+
- _api_token_: API token you'll need to authorize in our system. You can
1619
generate yours at https://app.molecule.one/dashboard/user/api-tokens
17-
- *api_base_url* (optional): URI of the batch scoring service. Defaults to Molecule One's public
20+
- _api_base_url_ (optional): URI of the batch scoring service. Defaults to Molecule One's public
1821
server, but you will need to provide custom value if you're using a dedicated solution.
1922

2023
### Getting a list of batch scoring requests:
24+
2125
```py
2226
searches = m1wrapper.list_batch_searches()
2327
```
2428

2529
### Running new batch scoring request:
30+
2631
```py
2732
search = m1wrapper.run_batch_search(
2833
targets=['cc', 'O=C(Nc1cc(Nc2nc(-c3cnccc3)ccn2)c(cc1)C)c3ccc(cc3)CN3CCN(CC3)C'],
2934
parameters={'model': 'gat'}
3035
)
3136
```
32-
- *targets*: list of target compounds in SMILES format
33-
- *parameters* (optional): additional configuration for your batch
37+
38+
- _targets_: list of target compounds in SMILES format
39+
- _parameters_ (optional): additional configuration for your batch
3440
scoring request. See [Batch Scoring API](https://github.com/molecule-one/api/blob/master/api-v2.md) for more information.
35-
- *detail_level* (optional): [detail level of the batch request](#batch-scoring-detail-level)
36-
- *priority* (optional): [priority of the batch request](#batch-scoring-priorities)
37-
- *invalid_target_strategy* (optional): if set to `InvalidTargetStrategy.PASS`, targets that cannot be canonized by our SMILES parser won't cause the whole batch request to be rejected. Defaults to `InvalidTargetStrategy.REJECT`.
38-
- *starting_materials* (optional): list of available compounds in SMILES format
39-
- *name* (optional): name of your batch request
41+
- _detail_level_ (optional): [detail level of the batch request](#batch-scoring-detail-level)
42+
- _priority_ (optional): [priority of the batch request](#batch-scoring-priorities)
43+
- _invalid_target_strategy_ (optional): if set to `InvalidTargetStrategy.PASS`, targets that cannot be canonized by our SMILES parser won't cause the whole batch request to be rejected. Defaults to `InvalidTargetStrategy.REJECT`.
44+
- _starting_materials_ (optional): list of available compounds in SMILES format
45+
- _name_ (optional): name of your batch request
4046

4147
### Batch scoring detail level
48+
4249
Detail level determines how much information about each target synthesis you'll get. We define it as a `DetailLevel` enum with two variants:
50+
4351
- `DetailLevel.SCORE` (default) - useful when you're not interested in full synthesis json/UI preview, but only numerical values
4452
- `DetailLevel.SYNTHESIS` - when you're also interested in reactions and compounds leading to the target product
53+
4554
#### Example:
55+
4656
```py
4757
from m1wrapper import MoleculeOneWrapper, DetailLevel
4858
m1wrapper = MoleculeOneWrapper(api_token, 'https://app.molecule.one')
@@ -54,15 +64,18 @@ search = m1wrapper.run_batch_search(
5464
```
5565

5666
### Batch scoring priorities
67+
5768
Priorities are defined as integers in a range of 1 to 10. Requests with higher priority will be processed before those with lower priority.
5869
For convenience, we also define a `Priority` enum with the following variants:
70+
5971
- `Priority.LOWEST` (1)
6072
- `Priority.LOW` (3)
6173
- `Priority.NORMAL` (5, default)
6274
- `Priority.HIGH` (8)
6375
- `Priority.HIGHEST` (10)
6476

6577
#### Example:
78+
6679
```py
6780
from m1wrapper import MoleculeOneWrapper, Priority
6881
m1wrapper = MoleculeOneWrapper(api_token, 'https://app.molecule.one')
@@ -73,51 +86,61 @@ search = m1wrapper.run_batch_search(
7386
)
7487
```
7588

76-
### Batch scoring request with compound metadata
89+
### Batch scoring request with targets metadata
90+
7791
`run_search_with_metadata(targets_with_metadata, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name)`
78-
- *targets_with_metadata*: list of target compounds with metadata. Each target compound should be a dictionary object of shape `{ smiles: str, name: str}` where the only required field is `smiles`.
79-
- *parameters* (optional): additional configuration for your batch
92+
93+
- _targets_with_metadata_: list of target compounds with metadata. Each target compound should be a dictionary object of shape `{ smiles: str, name: str}` where the only required field is `smiles`.
94+
- _parameters_ (optional): additional configuration for your batch
8095
scoring request. See [Batch Scoring API](https://github.com/molecule-one/api/blob/master/api-v2.md) for more information.
81-
- *detail_level* (optional): [detail level of the batch request](#batch-scoring-detail-level)
82-
- *priority* (optional): [priority of the batch request](#batch-scoring-priorities)
83-
- *invalid_target_strategy* (optional): if set to `InvalidTargetStrategy.PASS`, targets that cannot be canonized by our SMILES parser won't cause the whole batch request to be rejected. Defaults to `InvalidTargetStrategy.REJECT`.
84-
- *starting_materials* (optional): list of available compounds in SMILES format
85-
- *name* (optional): name of your batch request
96+
- _detail_level_ (optional): [detail level of the batch request](#batch-scoring-detail-level)
97+
- _priority_ (optional): [priority of the batch request](#batch-scoring-priorities)
98+
- _invalid_target_strategy_ (optional): if set to `InvalidTargetStrategy.PASS`, targets that cannot be canonized by our SMILES parser won't cause the whole batch request to be rejected. Defaults to `InvalidTargetStrategy.REJECT`.
99+
- _starting_materials_ (optional): list of available compounds in SMILES format
100+
- _name_ (optional): name of your batch request
86101

87102
```py
88103
run_search_with_metadata(targets_with_metadata=[{name: 'compound1', smiles: a}, {smiles: b}, {name: 'compound3', smiles: c}], priority=Priority.HIGH)
89104
```
90105

91106
### Getting exisiting scoring request by id:
107+
92108
```py
93109
search = m1wrapper.get_batch_search(id)
94110
```
95111

96112
### Checking if your scoring request processing is finished:
113+
97114
```py
98115
search.is_finished()
99116
```
100117

101118
### Checking full search status:
119+
102120
```py
103121
status = search.get_status()
104122
```
123+
105124
In response, you’ll get information about your batch scoring processing progress, i.e.:
106125
`{"queued":92,"running":4,"finished":104,"error":0}`
107126

108127
### Getting partial results:
128+
109129
Results are made available as soon as they are processed. This method
110130
provided a way to start working with some of your results without waiting until all targets are processed.
111131
This usually means implementing some kind of polling/scheduling on your side.
132+
112133
```py
113134
results = search.get_partial_results(precision=5, only=["target_smiles", "result"])
114135
```
115-
- *precision* (optional): format the floating point scores returned by the system (certainty, result, price) to given number of significant digits.
116-
- *only* (optional): fetch only a subset of values. Defaults to
136+
137+
- _precision_ (optional): format the floating point scores returned by the system (certainty, result, price) to given number of significant digits.
138+
- _only_ (optional): fetch only a subset of values. Defaults to
117139
all values.
118140

119141
Returns JSON object of the following shape:
120142
Returns an object of the following shape:
143+
121144
```python
122145
[
123146
{
@@ -127,12 +150,15 @@ Returns an object of the following shape:
127150
...
128151
]
129152
```
153+
130154
#### All values:
155+
131156
```py
132157
results = search.get_partial_results(precision=5)
133158
```
134159

135160
Returns JSON object of the following shape:
161+
136162
```python
137163
[
138164
{
@@ -155,16 +181,19 @@ Returns JSON object of the following shape:
155181
See [Batch Scoring API](https://github.com/molecule-one/api/blob/master/api-v2.md) for a full explaination of returned fields.
156182

157183
### Getting complete results:
184+
158185
```py
159186
results = search.get_results(precision=5, only=["target_smiles", "result"])
160187
```
188+
161189
If you don't want to implement scheduling on your own, this method
162190
provides a simple way to wait until all targets are processed (sending periodical checks using
163191
`search.is_finished()`), and execute only when all results are available. It's a
164192
blocking operation.
165193
Parameters and returned JSON are the same as with `get_partial_results()`.
166194

167195
### Deleting your data:
196+
168197
```py
169198
m1wrapper.delete_batch_search(search.search_id)
170199
```

m1wrapper/m1wrapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ def run_batch_search_with_metadata(
9494
) -> BatchSearch:
9595
targets = []
9696
targets_with_metadata_copy = copy.deepcopy(targets_with_metadata)
97-
metadata = {}
97+
targets_metadata = {}
9898
for index, item in enumerate(targets_with_metadata_copy):
9999
target = item.pop('smiles', None)
100100
targets.append(target)
101101

102102
if item:
103-
metadata[str(index)] = item
103+
targets_metadata[str(index)] = item
104104

105105
return BatchSearch(
106106
self.api_base_url,
@@ -112,7 +112,7 @@ def run_batch_search_with_metadata(
112112
invalid_target_strategy=invalid_target_strategy,
113113
starting_materials=starting_materials,
114114
name=name,
115-
metadata=metadata
115+
targets_metadata=targets_metadata
116116
)
117117

118118
def get_batch_search(self, search_id: str) -> BatchSearch:

m1wrapper/search.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def __init__(
3737
invalid_target_strategy=None,
3838
starting_materials=None,
3939
name=None,
40-
metadata=None,
40+
targets_metadata=None,
4141
):
4242
self.search_id = search_id
4343
self.base_url = base_url
@@ -52,11 +52,11 @@ def __init__(
5252
invalid_target_strategy=invalid_target_strategy,
5353
starting_materials=starting_materials,
5454
name=name,
55-
metadata=metadata
55+
targets_metadata=targets_metadata
5656
)
5757
self.search_id = new_search['id']
5858

59-
def __prepare_payload(self, targets, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name, metadata) -> dict:
59+
def __prepare_payload(self, targets, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name, targets_metadata) -> dict:
6060
payload = {
6161
'targets': targets,
6262
'parameters': parameters or {},
@@ -68,8 +68,8 @@ def __prepare_payload(self, targets, parameters, detail_level, priority, invalid
6868
payload["starting_materials"] = starting_materials
6969
if name is not None:
7070
payload["name"] = name
71-
if metadata is not None:
72-
payload['metadata'] = metadata
71+
if targets_metadata is not None:
72+
payload['targets_metadata'] = targets_metadata
7373

7474
return payload
7575

@@ -87,8 +87,8 @@ def __prepare_http(self):
8787
http.mount("http://", adapter)
8888
return http
8989

90-
def __run(self, targets, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name, metadata):
91-
payload = self.__prepare_payload(targets, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name, metadata)
90+
def __run(self, targets, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name, targets_metadata):
91+
payload = self.__prepare_payload(targets, parameters, detail_level, priority, invalid_target_strategy, starting_materials, name, targets_metadata)
9292
response = self.http.post(
9393
urljoin(self.base_url, api_search_endpoint),
9494
data=json.dumps(payload),

0 commit comments

Comments
 (0)