jglaser commited on
Commit
fcb9799
0 Parent(s):

Initial commit

Browse files
README.md ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - molecules
4
+ - chemistry
5
+ - SMILES
6
+ ---
7
+
8
+ ## How to use the data sets
9
+
10
+ This dataset contains more than 16,000 unique pairs of protein sequences and ligand SMILES with experimentally determined
11
+ binding affinities and protein-ligand contacts (ligand atom/SMILES token vs. Calpha within 5 Angstrom). These
12
+ are represented by a list that contains the positions of non-zero elements of the flattened, sparse (2048,512)
13
+ sequence x smiles tokens matrix.
14
+
15
+ It can be used for fine-tuning a language model.
16
+
17
+ The data solely uses data from PDBind-cn.
18
+
19
+ ### Use the already preprocessed data
20
+
21
+ Load a test/train split using
22
+
23
+ ```
24
+ from datasets import load_dataset
25
+ train = load_dataset("jglaser/protein_ligand_contacts",split='train[:90%]')
26
+ validation = load_dataset("jglaser/protein_lgiand_contacts",split='train[90%:]')
27
+ ```
28
+
29
+ ### Pre-process yourself
30
+
31
+ To manually perform the preprocessing, download the data sets from P.DBBind-cn
32
+
33
+ Register for an account at <https://www.pdbbind.org.cn/>, confirm the validation
34
+ email, then login and download
35
+
36
+ - the Index files (1)
37
+ - the general protein-ligand complexes (2)
38
+ - the refined protein-ligand complexes (3)
39
+
40
+ Extract those files in `pdbbind/data`
41
+
42
+ Run the script `pdbbind.py` in a compute job on an MPI-enabled cluster
43
+ (e.g., `mpirun -n 64 pdbbind.py`).
44
+
45
+ Perform the steps in the notebook `pdbbind.ipynb`
data/pdbbind_with_contacts.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f12e5a389dad93a0f2a2f5505fb6cacb12cc224047b87b0f2fa6d79084653567
3
+ size 16032905
pdbbind.ipynb ADDED
@@ -0,0 +1,783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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "834aeced-c3c5-42a0-bad1-41e009dd86ee",
6
+ "metadata": {},
7
+ "source": [
8
+ "### Preprocessing"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "id": "86476f6e-802a-463b-a1b0-2ae228bb92af",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "import pandas as pd"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": 2,
24
+ "id": "9b2be11c-f4bb-4107-af49-abd78052afcf",
25
+ "metadata": {},
26
+ "outputs": [],
27
+ "source": [
28
+ "df = pd.read_table('data/pdbbind/index/INDEX_general_PL_data.2020',skiprows=4,sep=r'\\s+',usecols=[0,4]).drop(0)\n",
29
+ "df = df.rename(columns={'#': 'name','release': 'affinity'})\n",
30
+ "df_refined = pd.read_table('data/pdbbind/index/INDEX_refined_data.2020',skiprows=4,sep=r'\\s+',usecols=[0,4]).drop(0)\n",
31
+ "df_refined = df_refined.rename(columns={'#': 'name','release': 'affinity'})\n",
32
+ "df = pd.concat([df,df_refined])"
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": 3,
38
+ "id": "68983ab8-bf11-4ed6-ba06-f962dbdc077e",
39
+ "metadata": {},
40
+ "outputs": [],
41
+ "source": [
42
+ "quantities = ['ki','kd','ka','k1/2','kb','ic50','ec50']"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 4,
48
+ "id": "3acbca3c-9c0b-43a1-a45e-331bf153bcfa",
49
+ "metadata": {},
50
+ "outputs": [],
51
+ "source": [
52
+ "from pint import UnitRegistry\n",
53
+ "ureg = UnitRegistry()\n",
54
+ "\n",
55
+ "def to_uM(affinity):\n",
56
+ " val = ureg(affinity)\n",
57
+ " try:\n",
58
+ " return val.m_as(ureg.uM)\n",
59
+ " except Exception:\n",
60
+ " pass\n",
61
+ " \n",
62
+ " try:\n",
63
+ " return 1/val.m_as(1/ureg.uM)\n",
64
+ " except Exception:\n",
65
+ " pass"
66
+ ]
67
+ },
68
+ {
69
+ "cell_type": "code",
70
+ "execution_count": 5,
71
+ "id": "58e5748b-2cea-43ff-ab51-85a5021bd50b",
72
+ "metadata": {},
73
+ "outputs": [],
74
+ "source": [
75
+ "df['affinity_uM'] = df['affinity'].str.split('[=\\~><]').str[1].apply(to_uM)\n",
76
+ "df['affinity_quantity'] = df['affinity'].str.split('[=\\~><]').str[0]"
77
+ ]
78
+ },
79
+ {
80
+ "cell_type": "code",
81
+ "execution_count": 6,
82
+ "id": "d92f0004-68c1-4487-94b9-56b4fd598de4",
83
+ "metadata": {},
84
+ "outputs": [
85
+ {
86
+ "data": {
87
+ "text/plain": [
88
+ "<AxesSubplot:>"
89
+ ]
90
+ },
91
+ "execution_count": 6,
92
+ "metadata": {},
93
+ "output_type": "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IOAfYA1xRVV8Z9mB0VrsYODDL+rVJvpjkH9o/Zuh8PctkV5vJVpNmc7L3rQ8Bt1fV64FvzNXOFlMgPA/8M3DtsAei/9emgFdV1euAdwMfT7KCF/n1LNIMJ3vfeiPwibb8sbna2WIKhP8GfgN4fZL3DHswOqsdAi7ttaKqnquqb7flA8BXgdfQOSNY3dXUr2fRizHb+9ac/0GxmAKBqvpP4G3AVUk8U1C/Pg68Iclbjxfaf/B0SZJXtv/fgySvBtYBX6uqKeDZJBva3UVX05kKkGZ1kvetf6LzFT8AV83VvhbVRWWAqvpOknHg80mG8hXFOrtV1feTvA34YJIP0jmt/1fgBuBNwB8lOQa8ALyzqr7Tul4H7ASW0bmY7AVlvSg93rduoDMdeQPwybnaj19dIUkCFtmUkSTp5AwESRJgIEiSGgNBkgQYCJKkxkCQJAEGgiSp+R+8kn6fv7jc8QAAAABJRU5ErkJggg==\n",
98
+ "text/plain": [
99
+ "<Figure size 432x288 with 1 Axes>"
100
+ ]
101
+ },
102
+ "metadata": {
103
+ "needs_background": "light"
104
+ },
105
+ "output_type": "display_data"
106
+ }
107
+ ],
108
+ "source": [
109
+ "df['affinity_quantity'].hist()"
110
+ ]
111
+ },
112
+ {
113
+ "cell_type": "code",
114
+ "execution_count": 7,
115
+ "id": "aa358835-55f3-4551-9217-e76a15de4fe8",
116
+ "metadata": {},
117
+ "outputs": [],
118
+ "source": [
119
+ "df_filter = df[df['affinity_quantity'].str.lower().isin(quantities)]"
120
+ ]
121
+ },
122
+ {
123
+ "cell_type": "code",
124
+ "execution_count": 8,
125
+ "id": "d6dda488-f709-4fe7-b372-080042cf7c66",
126
+ "metadata": {},
127
+ "outputs": [],
128
+ "source": [
129
+ "df_complex = pd.read_parquet('data/pdbbind_complex.parquet')"
130
+ ]
131
+ },
132
+ {
133
+ "cell_type": "code",
134
+ "execution_count": 19,
135
+ "id": "ed3fe035-6035-4d39-b072-d12dc0a95857",
136
+ "metadata": {},
137
+ "outputs": [],
138
+ "source": [
139
+ "import dask.array as da\n",
140
+ "import dask.dataframe as dd\n",
141
+ "from dask.bag import from_delayed\n",
142
+ "from dask import delayed\n",
143
+ "import pyarrow as pa\n",
144
+ "import pyarrow.parquet as pq"
145
+ ]
146
+ },
147
+ {
148
+ "cell_type": "code",
149
+ "execution_count": 10,
150
+ "id": "cd26125b-e68b-4fa3-846e-2b6e7f635fe0",
151
+ "metadata": {},
152
+ "outputs": [],
153
+ "source": [
154
+ "contacts_dask = da.from_npy_stack('data/pdbbind_contacts')\n",
155
+ "contacts_dask = contacts_dask.reshape(-1,contacts_dask.shape[-2]*contacts_dask.shape[-1])"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 11,
161
+ "id": "0e773f9d-6555-49c0-b0af-202c5e19b2cc",
162
+ "metadata": {},
163
+ "outputs": [
164
+ {
165
+ "data": {
166
+ "text/html": [
167
+ "<div>\n",
168
+ "<style scoped>\n",
169
+ " .dataframe tbody tr th:only-of-type {\n",
170
+ " vertical-align: middle;\n",
171
+ " }\n",
172
+ "\n",
173
+ " .dataframe tbody tr th {\n",
174
+ " vertical-align: top;\n",
175
+ " }\n",
176
+ "\n",
177
+ " .dataframe thead th {\n",
178
+ " text-align: right;\n",
179
+ " }\n",
180
+ "</style>\n",
181
+ "<table border=\"1\" class=\"dataframe\">\n",
182
+ " <thead>\n",
183
+ " <tr style=\"text-align: right;\">\n",
184
+ " <th></th>\n",
185
+ " <th>name</th>\n",
186
+ " <th>seq</th>\n",
187
+ " <th>smiles</th>\n",
188
+ " </tr>\n",
189
+ " </thead>\n",
190
+ " <tbody>\n",
191
+ " <tr>\n",
192
+ " <th>0</th>\n",
193
+ " <td>2lbv</td>\n",
194
+ " <td>MTVPDRSEIAGKWYVVALASNTEFFLREKDKMKMAMARISFLGEDE...</td>\n",
195
+ " <td>CCCCCCCCCCCCCCCCCCCC(=O)O</td>\n",
196
+ " </tr>\n",
197
+ " <tr>\n",
198
+ " <th>1</th>\n",
199
+ " <td>1lt6</td>\n",
200
+ " <td>APQTITELCSEYRNTQIYTINDKILSYTESMAGKREMVIITFKSGE...</td>\n",
201
+ " <td>O=[N+]([O-])c1cccc(OC2OC(CO)C(O)C(O)C2O)c1</td>\n",
202
+ " </tr>\n",
203
+ " <tr>\n",
204
+ " <th>2</th>\n",
205
+ " <td>4lwi</td>\n",
206
+ " <td>VETFAFQAEIAQLMSLIINTFYSNKEIFLRELISNSSDALDKIRYE...</td>\n",
207
+ " <td>COc1ccc(-c2c(-c3cc(C(C)C)c(O)cc3O)noc2NC(=O)C2...</td>\n",
208
+ " </tr>\n",
209
+ " <tr>\n",
210
+ " <th>3</th>\n",
211
+ " <td>6oyz</td>\n",
212
+ " <td>VQLQESGGGLVQTGGSLTLSCATSGRSFSLYAMAWFRQAPGKEREF...</td>\n",
213
+ " <td>COC1C(O)C(n2ccc(=O)[nH]c2=O)OC1C(OC1OC(C(=O)NC...</td>\n",
214
+ " </tr>\n",
215
+ " <tr>\n",
216
+ " <th>4</th>\n",
217
+ " <td>4i11</td>\n",
218
+ " <td>GSFVEMVDNLRGKSGQGYYVEMTVGSPPQTLNILVDTGSSNFAVGA...</td>\n",
219
+ " <td>CC1(C)Cc2ccccc2C(NC(Cc2ccccc2)C(=O)O)=N1</td>\n",
220
+ " </tr>\n",
221
+ " </tbody>\n",
222
+ "</table>\n",
223
+ "</div>"
224
+ ],
225
+ "text/plain": [
226
+ " name seq \\\n",
227
+ "0 2lbv MTVPDRSEIAGKWYVVALASNTEFFLREKDKMKMAMARISFLGEDE... \n",
228
+ "1 1lt6 APQTITELCSEYRNTQIYTINDKILSYTESMAGKREMVIITFKSGE... \n",
229
+ "2 4lwi VETFAFQAEIAQLMSLIINTFYSNKEIFLRELISNSSDALDKIRYE... \n",
230
+ "3 6oyz VQLQESGGGLVQTGGSLTLSCATSGRSFSLYAMAWFRQAPGKEREF... \n",
231
+ "4 4i11 GSFVEMVDNLRGKSGQGYYVEMTVGSPPQTLNILVDTGSSNFAVGA... \n",
232
+ "\n",
233
+ " smiles \n",
234
+ "0 CCCCCCCCCCCCCCCCCCCC(=O)O \n",
235
+ "1 O=[N+]([O-])c1cccc(OC2OC(CO)C(O)C(O)C2O)c1 \n",
236
+ "2 COc1ccc(-c2c(-c3cc(C(C)C)c(O)cc3O)noc2NC(=O)C2... \n",
237
+ "3 COC1C(O)C(n2ccc(=O)[nH]c2=O)OC1C(OC1OC(C(=O)NC... \n",
238
+ "4 CC1(C)Cc2ccccc2C(NC(Cc2ccccc2)C(=O)O)=N1 "
239
+ ]
240
+ },
241
+ "execution_count": 11,
242
+ "metadata": {},
243
+ "output_type": "execute_result"
244
+ }
245
+ ],
246
+ "source": [
247
+ "df_complex.head()"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": 12,
253
+ "id": "9c7c9849-2345-4baf-89e7-d412f52353b6",
254
+ "metadata": {},
255
+ "outputs": [
256
+ {
257
+ "data": {
258
+ "text/html": [
259
+ "<table>\n",
260
+ "<tr>\n",
261
+ "<td>\n",
262
+ "<table>\n",
263
+ " <thead>\n",
264
+ " <tr><td> </td><th> Array </th><th> Chunk </th></tr>\n",
265
+ " </thead>\n",
266
+ " <tbody>\n",
267
+ " <tr><th> Bytes </th><td> 1.71 GiB </td> <td> 1.71 GiB </td></tr>\n",
268
+ " <tr><th> Shape </th><td> (438, 1048576) </td> <td> (438, 1048576) </td></tr>\n",
269
+ " <tr><th> Count </th><td> 75 Tasks </td><td> 1 Chunks </td></tr>\n",
270
+ " <tr><th> Type </th><td> float32 </td><td> numpy.ndarray </td></tr>\n",
271
+ " </tbody>\n",
272
+ "</table>\n",
273
+ "</td>\n",
274
+ "<td>\n",
275
+ "<svg width=\"170\" height=\"75\" style=\"stroke:rgb(0,0,0);stroke-width:1\" >\n",
276
+ "\n",
277
+ " <!-- Horizontal lines -->\n",
278
+ " <line x1=\"0\" y1=\"0\" x2=\"120\" y2=\"0\" style=\"stroke-width:2\" />\n",
279
+ " <line x1=\"0\" y1=\"25\" x2=\"120\" y2=\"25\" style=\"stroke-width:2\" />\n",
280
+ "\n",
281
+ " <!-- Vertical lines -->\n",
282
+ " <line x1=\"0\" y1=\"0\" x2=\"0\" y2=\"25\" style=\"stroke-width:2\" />\n",
283
+ " <line x1=\"120\" y1=\"0\" x2=\"120\" y2=\"25\" style=\"stroke-width:2\" />\n",
284
+ "\n",
285
+ " <!-- Colored Rectangle -->\n",
286
+ " <polygon points=\"0.0,0.0 120.0,0.0 120.0,25.412616514582485 0.0,25.412616514582485\" style=\"fill:#ECB172A0;stroke-width:0\"/>\n",
287
+ "\n",
288
+ " <!-- Text -->\n",
289
+ " <text x=\"60.000000\" y=\"45.412617\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" >1048576</text>\n",
290
+ " <text x=\"140.000000\" y=\"12.706308\" font-size=\"1.0rem\" font-weight=\"100\" text-anchor=\"middle\" transform=\"rotate(-90,140.000000,12.706308)\">438</text>\n",
291
+ "</svg>\n",
292
+ "</td>\n",
293
+ "</tr>\n",
294
+ "</table>"
295
+ ],
296
+ "text/plain": [
297
+ "dask.array<blocks, shape=(438, 1048576), dtype=float32, chunksize=(438, 1048576), chunktype=numpy.ndarray>"
298
+ ]
299
+ },
300
+ "execution_count": 12,
301
+ "metadata": {},
302
+ "output_type": "execute_result"
303
+ }
304
+ ],
305
+ "source": [
306
+ "contacts_dask.blocks[1]"
307
+ ]
308
+ },
309
+ {
310
+ "cell_type": "code",
311
+ "execution_count": 76,
312
+ "id": "d21a5d74-69f1-4a5a-85f8-917d3c1d690a",
313
+ "metadata": {},
314
+ "outputs": [
315
+ {
316
+ "data": {
317
+ "text/plain": [
318
+ "(array([ 1046, 2578, 2579, 2582, 2584, 6144, 6145, 6146, 6149,\n",
319
+ " 6156, 6157, 6158, 6159, 6160, 6161, 6162, 6163, 6166,\n",
320
+ " 6168, 7173, 7174, 7175, 7176, 18432, 18433, 18434, 18435,\n",
321
+ " 18436, 18437, 18438, 19456, 19457, 19458, 19459, 19467, 19468,\n",
322
+ " 19469, 19472, 19473, 19474, 19475, 20498, 20499, 20502, 20504,\n",
323
+ " 24576, 24577, 24578, 24579, 24580, 24581, 24586, 24587, 24588,\n",
324
+ " 25090, 25091, 25092, 25093, 25603, 25604, 25605, 25606, 25607,\n",
325
+ " 25608, 26116, 26117, 33281, 33283, 33291, 33292, 43009, 43015,\n",
326
+ " 43016, 43017, 43018, 43019, 43020, 43021, 43022, 43023, 44046,\n",
327
+ " 44047, 44048, 44049, 44050, 44051, 44056, 45582, 45583, 45584,\n",
328
+ " 45585, 45586, 45587, 45592, 46606, 46607, 46608, 46609, 46610,\n",
329
+ " 46611, 46614, 46616, 48654, 48655, 49672, 49673, 49674, 49675,\n",
330
+ " 49676, 49677, 49678, 49679, 49680, 50696, 50697, 57350, 57351,\n",
331
+ " 57352, 57353, 57354, 58368, 58369, 58370, 58371, 58372, 58373,\n",
332
+ " 58374, 58375, 58376, 58377, 58378, 58379, 58380, 58381]),)"
333
+ ]
334
+ },
335
+ "execution_count": 76,
336
+ "metadata": {},
337
+ "output_type": "execute_result"
338
+ }
339
+ ],
340
+ "source": [
341
+ "np.where(contacts_dask.blocks[0].compute()[0])"
342
+ ]
343
+ },
344
+ {
345
+ "cell_type": "code",
346
+ "execution_count": 121,
347
+ "id": "42e95d84-ef27-4417-9479-8b356462b8c3",
348
+ "metadata": {},
349
+ "outputs": [],
350
+ "source": [
351
+ "def chunk_to_sparse(chunk, idx_chunk):\n",
352
+ " res = df_complex.iloc[idx_chunk].copy()\n",
353
+ " res['contacts'] = [np.where(a) for a in chunk]\n",
354
+ " return res\n",
355
+ "\n",
356
+ "partitions = [delayed(chunk_to_sparse)(b,k)\n",
357
+ " for b,k in zip(contacts_dask.blocks, da.arange(contacts_dask.shape[0],chunks=contacts_dask.chunks[0:1]).blocks)\n",
358
+ " ]"
359
+ ]
360
+ },
361
+ {
362
+ "cell_type": "code",
363
+ "execution_count": 123,
364
+ "id": "5520a925-693f-43f0-9e76-df2e128f272e",
365
+ "metadata": {},
366
+ "outputs": [
367
+ {
368
+ "data": {
369
+ "text/html": [
370
+ "<div>\n",
371
+ "<style scoped>\n",
372
+ " .dataframe tbody tr th:only-of-type {\n",
373
+ " vertical-align: middle;\n",
374
+ " }\n",
375
+ "\n",
376
+ " .dataframe tbody tr th {\n",
377
+ " vertical-align: top;\n",
378
+ " }\n",
379
+ "\n",
380
+ " .dataframe thead th {\n",
381
+ " text-align: right;\n",
382
+ " }\n",
383
+ "</style>\n",
384
+ "<table border=\"1\" class=\"dataframe\">\n",
385
+ " <thead>\n",
386
+ " <tr style=\"text-align: right;\">\n",
387
+ " <th></th>\n",
388
+ " <th>name</th>\n",
389
+ " <th>seq</th>\n",
390
+ " <th>smiles</th>\n",
391
+ " <th>contacts</th>\n",
392
+ " </tr>\n",
393
+ " </thead>\n",
394
+ " <tbody>\n",
395
+ " <tr>\n",
396
+ " <th>0</th>\n",
397
+ " <td>2lbv</td>\n",
398
+ " <td>MTVPDRSEIAGKWYVVALASNTEFFLREKDKMKMAMARISFLGEDE...</td>\n",
399
+ " <td>CCCCCCCCCCCCCCCCCCCC(=O)O</td>\n",
400
+ " <td>([1046, 2578, 2579, 2582, 2584, 6144, 6145, 61...</td>\n",
401
+ " </tr>\n",
402
+ " <tr>\n",
403
+ " <th>1</th>\n",
404
+ " <td>1lt6</td>\n",
405
+ " <td>APQTITELCSEYRNTQIYTINDKILSYTESMAGKREMVIITFKSGE...</td>\n",
406
+ " <td>O=[N+]([O-])c1cccc(OC2OC(CO)C(O)C(O)C2O)c1</td>\n",
407
+ " <td>([514, 518, 520, 521, 522, 523, 525, 526, 546,...</td>\n",
408
+ " </tr>\n",
409
+ " <tr>\n",
410
+ " <th>2</th>\n",
411
+ " <td>4lwi</td>\n",
412
+ " <td>VETFAFQAEIAQLMSLIINTFYSNKEIFLRELISNSSDALDKIRYE...</td>\n",
413
+ " <td>COc1ccc(-c2c(-c3cc(C(C)C)c(O)cc3O)noc2NC(=O)C2...</td>\n",
414
+ " <td>([521, 523, 526, 542, 544, 546, 547, 548, 1041...</td>\n",
415
+ " </tr>\n",
416
+ " <tr>\n",
417
+ " <th>3</th>\n",
418
+ " <td>6oyz</td>\n",
419
+ " <td>VQLQESGGGLVQTGGSLTLSCATSGRSFSLYAMAWFRQAPGKEREF...</td>\n",
420
+ " <td>COC1C(O)C(n2ccc(=O)[nH]c2=O)OC1C(OC1OC(C(=O)NC...</td>\n",
421
+ " <td>([35332, 35334, 35336, 35338, 35342, 35347, 35...</td>\n",
422
+ " </tr>\n",
423
+ " <tr>\n",
424
+ " <th>4</th>\n",
425
+ " <td>4i11</td>\n",
426
+ " <td>GSFVEMVDNLRGKSGQGYYVEMTVGSPPQTLNILVDTGSSNFAVGA...</td>\n",
427
+ " <td>CC1(C)Cc2ccccc2C(NC(Cc2ccccc2)C(=O)O)=N1</td>\n",
428
+ " <td>([36372, 36373, 36375, 36376, 36377, 36378, 36...</td>\n",
429
+ " </tr>\n",
430
+ " </tbody>\n",
431
+ "</table>\n",
432
+ "</div>"
433
+ ],
434
+ "text/plain": [
435
+ " name seq \\\n",
436
+ "0 2lbv MTVPDRSEIAGKWYVVALASNTEFFLREKDKMKMAMARISFLGEDE... \n",
437
+ "1 1lt6 APQTITELCSEYRNTQIYTINDKILSYTESMAGKREMVIITFKSGE... \n",
438
+ "2 4lwi VETFAFQAEIAQLMSLIINTFYSNKEIFLRELISNSSDALDKIRYE... \n",
439
+ "3 6oyz VQLQESGGGLVQTGGSLTLSCATSGRSFSLYAMAWFRQAPGKEREF... \n",
440
+ "4 4i11 GSFVEMVDNLRGKSGQGYYVEMTVGSPPQTLNILVDTGSSNFAVGA... \n",
441
+ "\n",
442
+ " smiles \\\n",
443
+ "0 CCCCCCCCCCCCCCCCCCCC(=O)O \n",
444
+ "1 O=[N+]([O-])c1cccc(OC2OC(CO)C(O)C(O)C2O)c1 \n",
445
+ "2 COc1ccc(-c2c(-c3cc(C(C)C)c(O)cc3O)noc2NC(=O)C2... \n",
446
+ "3 COC1C(O)C(n2ccc(=O)[nH]c2=O)OC1C(OC1OC(C(=O)NC... \n",
447
+ "4 CC1(C)Cc2ccccc2C(NC(Cc2ccccc2)C(=O)O)=N1 \n",
448
+ "\n",
449
+ " contacts \n",
450
+ "0 ([1046, 2578, 2579, 2582, 2584, 6144, 6145, 61... \n",
451
+ "1 ([514, 518, 520, 521, 522, 523, 525, 526, 546,... \n",
452
+ "2 ([521, 523, 526, 542, 544, 546, 547, 548, 1041... \n",
453
+ "3 ([35332, 35334, 35336, 35338, 35342, 35347, 35... \n",
454
+ "4 ([36372, 36373, 36375, 36376, 36377, 36378, 36... "
455
+ ]
456
+ },
457
+ "execution_count": 123,
458
+ "metadata": {},
459
+ "output_type": "execute_result"
460
+ }
461
+ ],
462
+ "source": [
463
+ "partitions[0].compute().head()"
464
+ ]
465
+ },
466
+ {
467
+ "cell_type": "code",
468
+ "execution_count": 125,
469
+ "id": "4982c3b1-5ce9-4f17-9834-a02c4e136bc2",
470
+ "metadata": {},
471
+ "outputs": [],
472
+ "source": [
473
+ "ddf = dd.from_delayed(partitions)"
474
+ ]
475
+ },
476
+ {
477
+ "cell_type": "code",
478
+ "execution_count": 129,
479
+ "id": "f6cdee43-33c6-445c-8619-ace20f90638c",
480
+ "metadata": {},
481
+ "outputs": [],
482
+ "source": [
483
+ "ddf_all = ddf.merge(df_filter, on='name').drop(columns=['affinity','affinity_quantity'],axis=1)"
484
+ ]
485
+ },
486
+ {
487
+ "cell_type": "code",
488
+ "execution_count": 132,
489
+ "id": "8f49f871-76f6-4fb2-b2db-c0794d4c07bf",
490
+ "metadata": {},
491
+ "outputs": [],
492
+ "source": [
493
+ "df_all_contacts = ddf_all.compute()"
494
+ ]
495
+ },
496
+ {
497
+ "cell_type": "code",
498
+ "execution_count": 134,
499
+ "id": "45e4b4fa-6338-4abe-bd6e-8aea46e2a09c",
500
+ "metadata": {},
501
+ "outputs": [],
502
+ "source": [
503
+ "df_all_contacts['neg_log10_affinity_M'] = 6-np.log10(df_all_contacts['affinity_uM'])"
504
+ ]
505
+ },
506
+ {
507
+ "cell_type": "code",
508
+ "execution_count": 136,
509
+ "id": "7c3db301-6565-4053-bbd4-139bb41dd1c4",
510
+ "metadata": {},
511
+ "outputs": [
512
+ {
513
+ "data": {
514
+ "text/plain": [
515
+ "(array([6.3455065]), array([3.57430038]))"
516
+ ]
517
+ },
518
+ "execution_count": 136,
519
+ "metadata": {},
520
+ "output_type": "execute_result"
521
+ }
522
+ ],
523
+ "source": [
524
+ "from sklearn.preprocessing import StandardScaler\n",
525
+ "scaler = StandardScaler()\n",
526
+ "df_all_contacts['affinity'] = scaler.fit_transform(df_all_contacts['neg_log10_affinity_M'].values.reshape(-1,1))\n",
527
+ "scaler.mean_, scaler.var_"
528
+ ]
529
+ },
530
+ {
531
+ "cell_type": "code",
532
+ "execution_count": 138,
533
+ "id": "c9d674bb-d6a2-4810-aa2b-e3bc3b4bbc98",
534
+ "metadata": {},
535
+ "outputs": [],
536
+ "source": [
537
+ "df_all_contacts.drop(columns=['name'],axis=1).to_parquet('data/pdbbind_with_contacts.parquet')"
538
+ ]
539
+ },
540
+ {
541
+ "cell_type": "code",
542
+ "execution_count": 127,
543
+ "id": "ec1afbc1-8072-4818-a925-0a9a6ad04759",
544
+ "metadata": {},
545
+ "outputs": [],
546
+ "source": [
547
+ "df_all = df_complex.merge(df_filter,on='name').drop('affinity',axis=1)"
548
+ ]
549
+ },
550
+ {
551
+ "cell_type": "code",
552
+ "execution_count": 128,
553
+ "id": "744f1e6e-a097-4b8f-8d4b-1a54f564dab8",
554
+ "metadata": {},
555
+ "outputs": [
556
+ {
557
+ "data": {
558
+ "text/html": [
559
+ "<div>\n",
560
+ "<style scoped>\n",
561
+ " .dataframe tbody tr th:only-of-type {\n",
562
+ " vertical-align: middle;\n",
563
+ " }\n",
564
+ "\n",
565
+ " .dataframe tbody tr th {\n",
566
+ " vertical-align: top;\n",
567
+ " }\n",
568
+ "\n",
569
+ " .dataframe thead th {\n",
570
+ " text-align: right;\n",
571
+ " }\n",
572
+ "</style>\n",
573
+ "<table border=\"1\" class=\"dataframe\">\n",
574
+ " <thead>\n",
575
+ " <tr style=\"text-align: right;\">\n",
576
+ " <th></th>\n",
577
+ " <th>name</th>\n",
578
+ " <th>seq</th>\n",
579
+ " <th>smiles</th>\n",
580
+ " <th>affinity_uM</th>\n",
581
+ " <th>affinity_quantity</th>\n",
582
+ " </tr>\n",
583
+ " </thead>\n",
584
+ " <tbody>\n",
585
+ " <tr>\n",
586
+ " <th>0</th>\n",
587
+ " <td>2lbv</td>\n",
588
+ " <td>MTVPDRSEIAGKWYVVALASNTEFFLREKDKMKMAMARISFLGEDE...</td>\n",
589
+ " <td>CCCCCCCCCCCCCCCCCCCC(=O)O</td>\n",
590
+ " <td>0.026</td>\n",
591
+ " <td>Kd</td>\n",
592
+ " </tr>\n",
593
+ " <tr>\n",
594
+ " <th>1</th>\n",
595
+ " <td>1lt6</td>\n",
596
+ " <td>APQTITELCSEYRNTQIYTINDKILSYTESMAGKREMVIITFKSGE...</td>\n",
597
+ " <td>O=[N+]([O-])c1cccc(OC2OC(CO)C(O)C(O)C2O)c1</td>\n",
598
+ " <td>500.000</td>\n",
599
+ " <td>IC50</td>\n",
600
+ " </tr>\n",
601
+ " <tr>\n",
602
+ " <th>2</th>\n",
603
+ " <td>4lwi</td>\n",
604
+ " <td>VETFAFQAEIAQLMSLIINTFYSNKEIFLRELISNSSDALDKIRYE...</td>\n",
605
+ " <td>COc1ccc(-c2c(-c3cc(C(C)C)c(O)cc3O)noc2NC(=O)C2...</td>\n",
606
+ " <td>0.023</td>\n",
607
+ " <td>IC50</td>\n",
608
+ " </tr>\n",
609
+ " <tr>\n",
610
+ " <th>3</th>\n",
611
+ " <td>6oyz</td>\n",
612
+ " <td>VQLQESGGGLVQTGGSLTLSCATSGRSFSLYAMAWFRQAPGKEREF...</td>\n",
613
+ " <td>COC1C(O)C(n2ccc(=O)[nH]c2=O)OC1C(OC1OC(C(=O)NC...</td>\n",
614
+ " <td>0.185</td>\n",
615
+ " <td>IC50</td>\n",
616
+ " </tr>\n",
617
+ " <tr>\n",
618
+ " <th>4</th>\n",
619
+ " <td>4i11</td>\n",
620
+ " <td>GSFVEMVDNLRGKSGQGYYVEMTVGSPPQTLNILVDTGSSNFAVGA...</td>\n",
621
+ " <td>CC1(C)Cc2ccccc2C(NC(Cc2ccccc2)C(=O)O)=N1</td>\n",
622
+ " <td>27.200</td>\n",
623
+ " <td>IC50</td>\n",
624
+ " </tr>\n",
625
+ " <tr>\n",
626
+ " <th>...</th>\n",
627
+ " <td>...</td>\n",
628
+ " <td>...</td>\n",
629
+ " <td>...</td>\n",
630
+ " <td>...</td>\n",
631
+ " <td>...</td>\n",
632
+ " </tr>\n",
633
+ " <tr>\n",
634
+ " <th>20822</th>\n",
635
+ " <td>2bok</td>\n",
636
+ " <td>IVGGQECKDGECPWQALLINEENEGFCGGTILSEFYILTAAHCLYQ...</td>\n",
637
+ " <td>C[N+](C)(C)CCCN1C(=O)C2C(C1=O)C(c1ccc(C(=N)N)c...</td>\n",
638
+ " <td>0.280</td>\n",
639
+ " <td>Ki</td>\n",
640
+ " </tr>\n",
641
+ " <tr>\n",
642
+ " <th>20823</th>\n",
643
+ " <td>4j46</td>\n",
644
+ " <td>GTIYPRNPAMYSEEARLKSFQNWPDYAHLTPRELASAGLYYTGIGD...</td>\n",
645
+ " <td>CCC(C)C(NC(=O)C1CCCN1C(=O)C(NC(=O)C(C)[NH3+])C...</td>\n",
646
+ " <td>5.240</td>\n",
647
+ " <td>Ki</td>\n",
648
+ " </tr>\n",
649
+ " <tr>\n",
650
+ " <th>20824</th>\n",
651
+ " <td>4j46</td>\n",
652
+ " <td>GTIYPRNPAMYSEEARLKSFQNWPDYAHLTPRELASAGLYYTGIGD...</td>\n",
653
+ " <td>CCC(C)C(NC(=O)C1CCCN1C(=O)C(NC(=O)C(C)[NH3+])C...</td>\n",
654
+ " <td>5.240</td>\n",
655
+ " <td>Ki</td>\n",
656
+ " </tr>\n",
657
+ " <tr>\n",
658
+ " <th>20825</th>\n",
659
+ " <td>2c80</td>\n",
660
+ " <td>DHIKVIYFNGRGRAESIRMTLVAAGVNYEDERISFQDWPKIKPTIP...</td>\n",
661
+ " <td>CCCCCCSCC(NC(=O)CCC([NH3+])C(=O)O)C(=O)NCC(=O)O</td>\n",
662
+ " <td>4.700</td>\n",
663
+ " <td>Kd</td>\n",
664
+ " </tr>\n",
665
+ " <tr>\n",
666
+ " <th>20826</th>\n",
667
+ " <td>2c80</td>\n",
668
+ " <td>DHIKVIYFNGRGRAESIRMTLVAAGVNYEDERISFQDWPKIKPTIP...</td>\n",
669
+ " <td>CCCCCCSCC(NC(=O)CCC([NH3+])C(=O)O)C(=O)NCC(=O)O</td>\n",
670
+ " <td>4.700</td>\n",
671
+ " <td>Kd</td>\n",
672
+ " </tr>\n",
673
+ " </tbody>\n",
674
+ "</table>\n",
675
+ "<p>20827 rows × 5 columns</p>\n",
676
+ "</div>"
677
+ ],
678
+ "text/plain": [
679
+ " name seq \\\n",
680
+ "0 2lbv MTVPDRSEIAGKWYVVALASNTEFFLREKDKMKMAMARISFLGEDE... \n",
681
+ "1 1lt6 APQTITELCSEYRNTQIYTINDKILSYTESMAGKREMVIITFKSGE... \n",
682
+ "2 4lwi VETFAFQAEIAQLMSLIINTFYSNKEIFLRELISNSSDALDKIRYE... \n",
683
+ "3 6oyz VQLQESGGGLVQTGGSLTLSCATSGRSFSLYAMAWFRQAPGKEREF... \n",
684
+ "4 4i11 GSFVEMVDNLRGKSGQGYYVEMTVGSPPQTLNILVDTGSSNFAVGA... \n",
685
+ "... ... ... \n",
686
+ "20822 2bok IVGGQECKDGECPWQALLINEENEGFCGGTILSEFYILTAAHCLYQ... \n",
687
+ "20823 4j46 GTIYPRNPAMYSEEARLKSFQNWPDYAHLTPRELASAGLYYTGIGD... \n",
688
+ "20824 4j46 GTIYPRNPAMYSEEARLKSFQNWPDYAHLTPRELASAGLYYTGIGD... \n",
689
+ "20825 2c80 DHIKVIYFNGRGRAESIRMTLVAAGVNYEDERISFQDWPKIKPTIP... \n",
690
+ "20826 2c80 DHIKVIYFNGRGRAESIRMTLVAAGVNYEDERISFQDWPKIKPTIP... \n",
691
+ "\n",
692
+ " smiles affinity_uM \\\n",
693
+ "0 CCCCCCCCCCCCCCCCCCCC(=O)O 0.026 \n",
694
+ "1 O=[N+]([O-])c1cccc(OC2OC(CO)C(O)C(O)C2O)c1 500.000 \n",
695
+ "2 COc1ccc(-c2c(-c3cc(C(C)C)c(O)cc3O)noc2NC(=O)C2... 0.023 \n",
696
+ "3 COC1C(O)C(n2ccc(=O)[nH]c2=O)OC1C(OC1OC(C(=O)NC... 0.185 \n",
697
+ "4 CC1(C)Cc2ccccc2C(NC(Cc2ccccc2)C(=O)O)=N1 27.200 \n",
698
+ "... ... ... \n",
699
+ "20822 C[N+](C)(C)CCCN1C(=O)C2C(C1=O)C(c1ccc(C(=N)N)c... 0.280 \n",
700
+ "20823 CCC(C)C(NC(=O)C1CCCN1C(=O)C(NC(=O)C(C)[NH3+])C... 5.240 \n",
701
+ "20824 CCC(C)C(NC(=O)C1CCCN1C(=O)C(NC(=O)C(C)[NH3+])C... 5.240 \n",
702
+ "20825 CCCCCCSCC(NC(=O)CCC([NH3+])C(=O)O)C(=O)NCC(=O)O 4.700 \n",
703
+ "20826 CCCCCCSCC(NC(=O)CCC([NH3+])C(=O)O)C(=O)NCC(=O)O 4.700 \n",
704
+ "\n",
705
+ " affinity_quantity \n",
706
+ "0 Kd \n",
707
+ "1 IC50 \n",
708
+ "2 IC50 \n",
709
+ "3 IC50 \n",
710
+ "4 IC50 \n",
711
+ "... ... \n",
712
+ "20822 Ki \n",
713
+ "20823 Ki \n",
714
+ "20824 Ki \n",
715
+ "20825 Kd \n",
716
+ "20826 Kd \n",
717
+ "\n",
718
+ "[20827 rows x 5 columns]"
719
+ ]
720
+ },
721
+ "execution_count": 128,
722
+ "metadata": {},
723
+ "output_type": "execute_result"
724
+ }
725
+ ],
726
+ "source": [
727
+ "df_all"
728
+ ]
729
+ },
730
+ {
731
+ "cell_type": "code",
732
+ "execution_count": 14,
733
+ "id": "8f75499c-8895-4395-867e-7d9a9d394910",
734
+ "metadata": {},
735
+ "outputs": [],
736
+ "source": [
737
+ "df_all.to_parquet('data/pdbbind.parquet')"
738
+ ]
739
+ },
740
+ {
741
+ "cell_type": "code",
742
+ "execution_count": 15,
743
+ "id": "0af83f72-5bf6-4643-aa0e-0a94d51e7da7",
744
+ "metadata": {},
745
+ "outputs": [
746
+ {
747
+ "data": {
748
+ "text/plain": [
749
+ "20827"
750
+ ]
751
+ },
752
+ "execution_count": 15,
753
+ "metadata": {},
754
+ "output_type": "execute_result"
755
+ }
756
+ ],
757
+ "source": [
758
+ "len(df_all)"
759
+ ]
760
+ }
761
+ ],
762
+ "metadata": {
763
+ "kernelspec": {
764
+ "display_name": "Python 3 (ipykernel)",
765
+ "language": "python",
766
+ "name": "python3"
767
+ },
768
+ "language_info": {
769
+ "codemirror_mode": {
770
+ "name": "ipython",
771
+ "version": 3
772
+ },
773
+ "file_extension": ".py",
774
+ "mimetype": "text/x-python",
775
+ "name": "python",
776
+ "nbconvert_exporter": "python",
777
+ "pygments_lexer": "ipython3",
778
+ "version": "3.9.6"
779
+ }
780
+ },
781
+ "nbformat": 4,
782
+ "nbformat_minor": 5
783
+ }
pdbbind.py ADDED
@@ -0,0 +1,108 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from mpi4py import MPI
2
+ from mpi4py.futures import MPICommExecutor
3
+
4
+ import warnings
5
+ from Bio.PDB import PDBParser, PPBuilder, CaPPBuilder
6
+ from Bio.PDB.NeighborSearch import NeighborSearch
7
+ from Bio.PDB.Selection import unfold_entities
8
+
9
+ import numpy as np
10
+ import dask.array as da
11
+
12
+ from rdkit import Chem
13
+
14
+ import os
15
+ import re
16
+
17
+ # all punctuation
18
+ punctuation_regex = r"""(\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])"""
19
+
20
+ # tokenization regex (Schwaller)
21
+ molecule_regex = r"""(\[[^\]]+]|Br?|Cl?|N|O|S|P|F|I|b|c|n|o|s|p|\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9])"""
22
+
23
+ cutoff = 5
24
+ max_seq = 2048
25
+ max_smiles = 512
26
+ chunk_size = '1G'
27
+
28
+ def parse_complex(fn):
29
+ try:
30
+ name = os.path.basename(fn)
31
+
32
+ # parse protein sequence and coordinates
33
+ parser = PDBParser()
34
+ with warnings.catch_warnings():
35
+ warnings.simplefilter("ignore")
36
+ structure = parser.get_structure('protein',fn+'/'+name+'_protein.pdb')
37
+
38
+ # ppb = PPBuilder()
39
+ ppb = CaPPBuilder()
40
+ seq = []
41
+ for pp in ppb.build_peptides(structure):
42
+ seq.append(str(pp.get_sequence()))
43
+ seq = ''.join(seq)
44
+
45
+ # parse ligand, convert to SMILES and map atoms
46
+ suppl = Chem.SDMolSupplier(fn+'/'+name+'_ligand.sdf')
47
+ mol = next(suppl)
48
+ smi = Chem.MolToSmiles(mol)
49
+
50
+ # position of atoms in SMILES (not counting punctuation)
51
+ atom_order = mol.GetProp("_smilesAtomOutputOrder")
52
+ atom_order = [int(s) for s in list(filter(None,re.sub(r'[\[\]]','',mol.GetProp("_smilesAtomOutputOrder")).split(',')))]
53
+
54
+ # tokenize the SMILES
55
+ tokens = list(filter(None, re.split(molecule_regex, smi)))
56
+
57
+ # remove punctuation
58
+ masked_tokens = [re.sub(punctuation_regex,'',s) for s in tokens]
59
+
60
+ k = 0
61
+ token_pos = []
62
+ token_id = []
63
+ for i,token in enumerate(masked_tokens):
64
+ if token != '':
65
+ token_pos.append(tuple(mol.GetConformer().GetAtomPosition(atom_order[k])))
66
+ token_id.append(i)
67
+ k += 1
68
+
69
+ # query protein for ligand contacts
70
+ atoms = unfold_entities(structure, 'A')
71
+ neighbor_search = NeighborSearch(atoms)
72
+
73
+ close_residues = [neighbor_search.search(center=t, level='R', radius=cutoff) for t in token_pos]
74
+ residue_id = [[c.get_id()[1]-1 for c in query] for query in close_residues] # zero-based
75
+
76
+ # contact map
77
+ contact_map = np.zeros((max_seq, max_smiles),dtype=np.float32)
78
+
79
+ for query,t in zip(residue_id,token_id):
80
+ for r in query:
81
+ contact_map[r,t] = 1
82
+
83
+ return name, seq, smi, contact_map
84
+ except Exception as e:
85
+ print(e)
86
+ return None
87
+
88
+
89
+ if __name__ == '__main__':
90
+ import glob
91
+
92
+ filenames = glob.glob('data/pdbbind/v2020-other-PL/*')
93
+ filenames.extend(glob.glob('data/pdbbind/refined-set/*'))
94
+ comm = MPI.COMM_WORLD
95
+ with MPICommExecutor(comm, root=0) as executor:
96
+ if executor is not None:
97
+ result = executor.map(parse_complex, filenames)
98
+ result = list(result)
99
+ names = [r[0] for r in result if r is not None]
100
+ seqs = [r[1] for r in result if r is not None]
101
+ all_smiles = [r[2] for r in result if r is not None]
102
+ all_contacts = [r[3] for r in result if r is not None]
103
+
104
+ import pandas as pd
105
+ df = pd.DataFrame({'name': names, 'seq': seqs, 'smiles': all_smiles})
106
+ all_contacts = da.from_array(all_contacts, chunks=chunk_size)
107
+ da.to_npy_stack('data/pdbbind_contacts/', all_contacts)
108
+ df.to_parquet('data/pdbbind_complex.parquet')
pdbbind.slurm ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ #SBATCH -J preprocess_pdbbind
3
+ #SBATCH -p gpu
4
+ #SBATCH -A STF006
5
+ #SBATCH -t 3:00:00
6
+ #SBATCH -N 2
7
+ #SBATCH --ntasks-per-node=16
8
+
9
+ srun python pdbbind.py
protein_ligand_contacts.py ADDED
@@ -0,0 +1,130 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The HuggingFace Datasets Authors and the current dataset script contributor.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """TODO: A dataset of protein sequences, ligand SMILES, binding affinities and contacts."""
16
+
17
+ import huggingface_hub
18
+ import os
19
+ import pyarrow.parquet as pq
20
+ import datasets
21
+
22
+
23
+ # TODO: Add BibTeX citation
24
+ # Find for instance the citation on arxiv or on the dataset repo/website
25
+ _CITATION = """\
26
+ @InProceedings{huggingface:dataset,
27
+ title = {jglaser/protein_ligand_contacts},
28
+ author={Jens Glaser, ORNL
29
+ },
30
+ year={2022}
31
+ }
32
+ """
33
+
34
+ # TODO: Add description of the dataset here
35
+ # You can copy an official description
36
+ _DESCRIPTION = """\
37
+ A dataset to fine-tune language models on protein-ligand binding affinity and contact prediction.
38
+ """
39
+
40
+ # TODO: Add a link to an official homepage for the dataset here
41
+ _HOMEPAGE = ""
42
+
43
+ # TODO: Add the licence for the dataset here if you can find it
44
+ _LICENSE = "BSD two-clause"
45
+
46
+ # TODO: Add link to the official dataset URLs here
47
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
48
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
49
+ _URL = "https://huggingface.co/datasets/jglaser/protein_ligand_contacts/resolve/main/"
50
+ _data_dir = "data/"
51
+ _file_names = {'default': _data_dir+'pddbind_contacts.parquet'}
52
+
53
+ _URLs = {name: _URL+_file_names[name] for name in _file_names}
54
+
55
+
56
+ # TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
57
+ class BindingAffinity(datasets.ArrowBasedBuilder):
58
+ """List of protein sequences, ligand SMILES and binding affinities."""
59
+
60
+ VERSION = datasets.Version("1.4.1")
61
+
62
+ def _info(self):
63
+ # TODO: This method specifies the datasets.DatasetInfo object which contains informations and typings for the dataset
64
+ #if self.config.name == "first_domain": # This is the name of the configuration selected in BUILDER_CONFIGS above
65
+ # features = datasets.Features(
66
+ # {
67
+ # "sentence": datasets.Value("string"),
68
+ # "option1": datasets.Value("string"),
69
+ # "answer": datasets.Value("string")
70
+ # # These are the features of your dataset like images, labels ...
71
+ # }
72
+ # )
73
+ #else: # This is an example to show how to have different features for "first_domain" and "second_domain"
74
+ features = datasets.Features(
75
+ {
76
+ "seq": datasets.Value("string"),
77
+ "smiles": datasets.Value("string"),
78
+ "affinity_uM": datasets.Value("float"),
79
+ "neg_log10_affinity_M": datasets.Value("float"),
80
+ "affinity": datasets.Value("float"),
81
+ "contacts": datasets.Sequence('int'),
82
+ # These are the features of your dataset like images, labels ...
83
+ }
84
+ )
85
+ return datasets.DatasetInfo(
86
+ # This is the description that will appear on the datasets page.
87
+ description=_DESCRIPTION,
88
+ # This defines the different columns of the dataset and their types
89
+ features=features, # Here we define them above because they are different between the two configurations
90
+ # If there's a common (input, target) tuple from the features,
91
+ # specify them here. They'll be used if as_supervised=True in
92
+ # builder.as_dataset.
93
+ supervised_keys=None,
94
+ # Homepage of the dataset for documentation
95
+ homepage=_HOMEPAGE,
96
+ # License for the dataset if available
97
+ license=_LICENSE,
98
+ # Citation for the dataset
99
+ citation=_CITATION,
100
+ )
101
+
102
+ def _split_generators(self, dl_manager):
103
+ """Returns SplitGenerators."""
104
+ # TODO: This method is tasked with downloading/extracting the data and defining the splits depending on the configuration
105
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
106
+
107
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
108
+ # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
109
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
110
+ files = dl_manager.download_and_extract(_URLs)
111
+
112
+ return [
113
+ datasets.SplitGenerator(
114
+ # These kwargs will be passed to _generate_examples
115
+ name=datasets.Split.TRAIN,
116
+ gen_kwargs={
117
+ 'filepath': files["default"],
118
+ },
119
+ ),
120
+
121
+ ]
122
+
123
+ def _generate_tables(
124
+ self, filepath
125
+ ):
126
+ from pyarrow import fs
127
+ local = fs.LocalFileSystem()
128
+
129
+ for i, f in enumerate([filepath]):
130
+ yield i, pq.read_table(f,filesystem=local)