Skip to content

Commit

Permalink
last update
Browse files Browse the repository at this point in the history
  • Loading branch information
asiomchen committed Jun 10, 2024
1 parent 3b756c5 commit 9cd8fc3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
25 changes: 19 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

# MolHarbour

MolHarbour is a Python wrapper for the Molport REST API. It allows you to search for chemical compounds and retrieve information about them.
MolHarbour is a unofficial Python wrapper for the Molport REST API. It allows you to search for chemical compounds and retrieve information about them.
Additionally, MolHarbour unifies the Molport API variables names and verifies the response data using wonderful [Pydantic](https://github.com/pydantic/pydantic) models.

This library is not affiliated with Molport in any way. Molport is a registered trademark of Molport SIA.
Expand Down Expand Up @@ -104,7 +104,7 @@ molport.find("O=C(O)c1ccccc1", search_type=SearchType.SUBSTRUCTURE, max_results=
MolHarbour design to simplify commonn tasks so `.find()` method returns a list of `MolportCompound` objects (which itself is a dataclass object with `smiles`, `molport_id` and `link` field).

However, you can access the raw response using the `return_response` parameter. Returned `Response` object inherits from Pydantic `BaseModel` and contains all the fields from the Molport API response with type validation provided by Pydantic.
All the fields have the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. Shipment Type -> shipment_type)
All the fields have the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. `Shipment Type` -> `shipment_type`)

```python
from molharbor import SearchType
Expand All @@ -120,16 +120,29 @@ molport.find("O=C(O)c1ccccc1", search_type=SearchType.SUBSTRUCTURE, max_results=
[Response(result=Result(status=1, message='Substructure search completed!'), data=Data(molecules=[Molecule(id=45........
```

### Supliers search
### Suppliers search

Having a Molport ID, you can search for suppliers using the `get_suppliers` method. Similar too `find()` method, you could either recieve a raw pydantic response with all the fields having the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. Shipment Type -> shipment_type) or processed dataframe with most important fields
Having a Molport ID, you can search for suppliers using the `get_suppliers` method. Similar too `find()` method, you could either recieve a raw pydantic response with all the fields having the same name as in Molport API docs, only lowercase and the spaces are replaced with underscores( e.g. `Shipment Type` -> `shipment_type`) or processed dataframe with most important fields

#### Processed dataframe
```python
df = molport.get_suppliers("Molport-001-794-639")
```

Or you could use id values of `MolportCompound` objects returned by `find()` method

```python
result = molport.find("C[C@H](CS)C(=O)N1CCC[C@H]1C(O)=O", search_type=SearchType.EXACT, max_results=1)[0]
result

MolportCompound(smiles='C[C@H](CS)C(=O)N1CCC[C@H]1C(O)=O', molport_id='Molport-001-794-639', link=...

df = molport.get_suppliers(result.molport_id)
```
#### Processed dataframe

Returned dataframe contains all the fields from the Molport API response with type validation provided by Pydantic. The fields are renamed to be more human-readable and to be consistent with the Molport API docs. Below is an example of the most important fields.

```python
df = molport.get_suppliers("Molport-001-794-639")
df[["supplier_name", "supplier_type", "amount", "measure",
"price", "currency", "delivery_days",
"stock", "stock_measure", "last_update_date_exact"]].head()
Expand Down
7 changes: 3 additions & 4 deletions molharbor/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ def get_suppliers(
"""
credentials = self.credentials
url = "https://api.molport.com/api/molecule/load?molecule={}"
if "API Key" in credentials:
if "api_key" in credentials:
url += "&apikey={}"
url = url.format(molport_id, self.api_key)
url = url.format(molport_id, credentials["api_key"])
else:
url += "&username={}&password={}"
url += "&username={}&authenticationcode={}"
url = url.format(molport_id, self.username, self.password)

response = self.client.get(url)
if response.status_code != 200:
raise ValueError(f"Error code: {response.status_code}\n{response.text}")
Expand Down

0 comments on commit 9cd8fc3

Please sign in to comment.