-
Notifications
You must be signed in to change notification settings - Fork 151
/
astrazeneca_chembl_solubility.py
157 lines (134 loc) · 6.01 KB
/
astrazeneca_chembl_solubility.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
#
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
#
# Experimental solubility determined at AstraZeneca on a
# set of compounds, recorded in ChEMBL
import pandas as pd
from dgl.data.utils import get_download_dir, download, _get_dgl_url
from .csv_dataset import MoleculeCSVDataset
from ..utils.mol_to_graph import smiles_to_bigraph
__all__ = ['AstraZenecaChEMBLSolubility']
class AstraZenecaChEMBLSolubility(MoleculeCSVDataset):
r"""Experimental solubility determined at AstraZeneca, extracted from ChEMBL
The dataset provides experimental solubility (in nM unit) for 1763 molecules
in pH7.4 using solid starting material using the method described in [1].
References:
* [1] A Highly Automated Assay for Determining the Aqueous Equilibrium
Solubility of Drug Discovery Compounds
* [2] `CHEMBL3301361 <https://www.ebi.ac.uk/chembl/document_report_card/CHEMBL3301361/>`__
Parameters
----------
smiles_to_graph: callable, str -> DGLGraph
A function turning a SMILES string into a DGLGraph.
Default to :func:`dgllife.utils.smiles_to_bigraph`.
node_featurizer : callable, rdkit.Chem.rdchem.Mol -> dict
Featurization for nodes like atoms in a molecule, which can be used to update
ndata for a DGLGraph. Default to None.
edge_featurizer : callable, rdkit.Chem.rdchem.Mol -> dict
Featurization for edges like bonds in a molecule, which can be used to update
edata for a DGLGraph. Default to None.
load : bool
Whether to load the previously pre-processed dataset or pre-process from scratch.
``load`` should be False when we want to try different graph construction and
featurization methods and need to preprocess from scratch. Default to False.
log_every : bool
Print a message every time ``log_every`` molecules are processed. Default to 1000.
cache_file_path : str
Path to the cached DGLGraphs. Default to 'AstraZeneca_chembl_solubility_graph.bin'.
log_of_values : bool
Whether to take the logarithm of the solubility values. Before taking the logarithm,
the values can have a range of [100, 1513600]. After taking the logarithm, the
values will have a range of [4.61, 14.23]. Default to True.
n_jobs : int
The maximum number of concurrently running jobs for graph construction and featurization,
using joblib backend. Default to 1.
Examples
--------
>>> from dgllife.data import AstraZenecaChEMBLSolubility
>>> from dgllife.utils import smiles_to_bigraph, CanonicalAtomFeaturizer
>>> dataset = AstraZenecaChEMBLSolubility(smiles_to_bigraph, CanonicalAtomFeaturizer())
>>> # Get size of the dataset
>>> len(dataset)
1763
>>> # Get the 0th datapoint, consisting of SMILES, DGLGraph and solubility
>>> dataset[0]
('Cc1nc(C)c(-c2ccc([C@H]3CC[C@H](Cc4nnn[nH]4)CC3)cc2)nc1C(N)=O',
DGLGraph(num_nodes=29, num_edges=64,
ndata_schemes={'h': Scheme(shape=(74,), dtype=torch.float32)}
edata_schemes={}),
tensor([12.5032]))
We also provide information for the ChEMBL id and molecular weight of the compound.
>>> dataset.chembl_ids[i]
>>> dataset.mol_weight[i]
We can also get the ChEMBL id and molecular weight along with SMILES, DGLGraph and
solubility at once.
>>> dataset.load_full = True
>>> dataset[0]
('Cc1nc(C)c(-c2ccc([C@H]3CC[C@H](Cc4nnn[nH]4)CC3)cc2)nc1C(N)=O',
DGLGraph(num_nodes=29, num_edges=64,
ndata_schemes={'h': Scheme(shape=(74,), dtype=torch.float32)}
edata_schemes={}),
tensor([12.5032]),
'CHEMBL2178940',
391.48)
"""
def __init__(self,
smiles_to_graph=smiles_to_bigraph,
node_featurizer=None,
edge_featurizer=None,
load=False,
log_every=1000,
cache_file_path='./AstraZeneca_chembl_solubility_graph.bin',
log_of_values=True,
n_jobs=1):
self._url = 'dataset/AstraZeneca_ChEMBL_Solubility.csv'
data_path = get_download_dir() + '/AstraZeneca_ChEMBL_Solubility.csv'
download(_get_dgl_url(self._url), path=data_path, overwrite=False)
df = pd.read_csv(data_path)
super(AstraZenecaChEMBLSolubility, self).__init__(
df=df,
smiles_to_graph=smiles_to_graph,
node_featurizer=node_featurizer,
edge_featurizer=edge_featurizer,
smiles_column='Smiles',
cache_file_path=cache_file_path,
task_names=['Solubility'],
load=load,
log_every=log_every,
init_mask=False,
n_jobs=n_jobs)
self.load_full = False
# ChEMBL ids
self.chembl_ids = df['Molecule ChEMBL ID'].tolist()
self.chembl_ids = [self.chembl_ids[i] for i in self.valid_ids]
# Molecular weight
self.mol_weight = df['Molecular Weight'].tolist()
self.mol_weight = [self.mol_weight[i] for i in self.valid_ids]
if log_of_values:
self.labels = self.labels.log()
def __getitem__(self, item):
"""Get datapoint with index
Parameters
----------
item : int
Datapoint index
Returns
-------
str
SMILES for the ith datapoint
DGLGraph
DGLGraph for the ith datapoint
Tensor of dtype float32 and shape (1)
Labels of the ith datapoint
str, optional
ChEMBL id of the ith datapoint, returned only when ``self.load_full`` is True.
float, optional
Molecular weight of the ith datapoint, returned only when ``self.load_full`` is True.
"""
if self.load_full:
return self.smiles[item], self.graphs[item], self.labels[item], \
self.chembl_ids[item], self.mol_weight[item]
else:
return self.smiles[item], self.graphs[item], self.labels[item]