Skip to content

Commit 129c3d7

Browse files
authored
Merge pull request #8 from molecule-one/improvement/rename-compound-metadata
Rename metadata to targets_metadata
2 parents c812435 + e9d7677 commit 129c3d7

3 files changed

Lines changed: 54 additions & 27 deletions

File tree

README.md

Lines changed: 44 additions & 17 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')
@@ -75,14 +88,14 @@ search = m1wrapper.run_batch_search(
7588

7689
### Batch scoring request with compound metadata
7790
`run_batch_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`.
91+
- *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`.
7992
- *parameters* (optional): additional configuration for your batch
8093
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
94+
- _detail_level_ (optional): [detail level of the batch request](#batch-scoring-detail-level)
95+
- _priority_ (optional): [priority of the batch request](#batch-scoring-priorities)
96+
- _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`.
97+
- _starting_materials_ (optional): list of available compounds in SMILES format
98+
- _name_ (optional): name of your batch request
8699

87100
```py
88101
run_batch_search_with_metadata(
@@ -92,35 +105,43 @@ run_batch_search_with_metadata(
92105
```
93106

94107
### Getting exisiting scoring request by id:
108+
95109
```py
96110
search = m1wrapper.get_batch_search(id)
97111
```
98112

99113
### Checking if your scoring request processing is finished:
114+
100115
```py
101116
search.is_finished()
102117
```
103118

104119
### Checking full search status:
120+
105121
```py
106122
status = search.get_status()
107123
```
124+
108125
In response, you’ll get information about your batch scoring processing progress, i.e.:
109126
`{"queued":92,"running":4,"finished":104,"error":0}`
110127

111128
### Getting partial results:
129+
112130
Results are made available as soon as they are processed. This method
113131
provided a way to start working with some of your results without waiting until all targets are processed.
114132
This usually means implementing some kind of polling/scheduling on your side.
133+
115134
```py
116135
results = search.get_partial_results(precision=5, only=["target_smiles", "result"])
117136
```
118-
- *precision* (optional): format the floating point scores returned by the system (certainty, result, price) to given number of significant digits.
119-
- *only* (optional): fetch only a subset of values. Defaults to
137+
138+
- _precision_ (optional): format the floating point scores returned by the system (certainty, result, price) to given number of significant digits.
139+
- _only_ (optional): fetch only a subset of values. Defaults to
120140
all values.
121141

122142
Returns JSON object of the following shape:
123143
Returns an object of the following shape:
144+
124145
```python
125146
[
126147
{
@@ -130,12 +151,15 @@ Returns an object of the following shape:
130151
...
131152
]
132153
```
154+
133155
#### All values:
156+
134157
```py
135158
results = search.get_partial_results(precision=5)
136159
```
137160

138161
Returns JSON object of the following shape:
162+
139163
```python
140164
[
141165
{
@@ -158,16 +182,19 @@ Returns JSON object of the following shape:
158182
See [Batch Scoring API](https://github.com/molecule-one/api/blob/master/api-v2.md) for a full explaination of returned fields.
159183

160184
### Getting complete results:
185+
161186
```py
162187
results = search.get_results(precision=5, only=["target_smiles", "result"])
163188
```
189+
164190
If you don't want to implement scheduling on your own, this method
165191
provides a simple way to wait until all targets are processed (sending periodical checks using
166192
`search.is_finished()`), and execute only when all results are available. It's a
167193
blocking operation.
168194
Parameters and returned JSON are the same as with `get_partial_results()`.
169195

170196
### Deleting your data:
197+
171198
```py
172199
m1wrapper.delete_batch_search(search.search_id)
173200
```

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)