-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathquery_chembl
27 lines (21 loc) · 927 Bytes
/
query_chembl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from chembl_webresource_client.new_client import new_client
import pandas as pd
smiles_list = ['Cc1ccccc1', 'CC(C)NCC(O)COc1ccc(NC(=O)c2ccccc2)cc1']
# Initialize ChEMBL API client
client = new_client()
# Initialize an empty list to store the results
results = []
# Loop through the SMILES list and query ChEMBL for each compound
for smiles in smiles_list:
try:
molecule = client.molecule.filter(smiles=smiles).only(['molecule_chembl_id', 'pref_name']).first()
result = {'SMILES': smiles, 'ChEMBL_ID': molecule.molecule_chembl_id, 'Name': molecule.pref_name}
results.append(result)
except AttributeError:
result = {'SMILES': smiles, 'ChEMBL_ID': None, 'Name': None}
results.append(result)
# Convert the results list to a pandas DataFrame and save it to a CSV file
df = pd.DataFrame(results)
df.to_csv('results.csv', index=False)
# Print the results to the console
print(df)