File size: 11,519 Bytes
fc0d038
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
=== [BBBP] Data generation started at 2026-01-06 12:40:31 ===
========================= Preprocessing BBBP =========================
  1. Download dataset from DeepChem
  2. Trim columns - keep only SMILES, label, and raw_ID
  3. Add embedding - ECFP or MolT5-{small, base, large}
  4. Split dataset - stratified for classification, random for regression
======================================================================

==================== Morgan Fingerprint Embedding ====================
Load `df_raw` from url
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2050 entries, 0 to 2049
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   num     2050 non-null   int64 
 1   name    2050 non-null   object
 2   p_np    2050 non-null   int64 
 3   smiles  2050 non-null   object
dtypes: int64(2), object(2)
memory usage: 64.2+ KB
======================================================================
Keep only `smiles`, `label`, and `raw_ID` columns
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2050 entries, 0 to 2049
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   raw_ID  2050 non-null   int64 
 1   smiles  2050 non-null   object
 2   label   2050 non-null   int64 
dtypes: int64(2), object(1)
memory usage: 48.2+ KB
======================================================================
[INFO] Corrected invalid SMILES for BBBP raw_ID=651
Remove NaNs
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2050 entries, 0 to 2049
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   raw_ID  2050 non-null   int64 
 1   smiles  2050 non-null   object
 2   label   2050 non-null   int64 
dtypes: int64(2), object(1)
memory usage: 48.2+ KB
======================================================================
smiles:O=N([O-])C1=C(CN=C1NCCSCc2ncccc2)Cc3ccccc3
smiles:c1(nc(NC(N)=[NH2])sc1)CSCCNC(=[NH]C#N)NC
smiles:Cc1nc(sc1)\[NH]=C(\N)N
smiles:s1cc(CSCCN\C(NC)=[NH]\C#N)nc1\[NH]=C(\N)N
smiles:c1c(c(ncc1)CSCCN\C(=[NH]\C#N)NCC)Br
smiles:n1c(csc1\[NH]=C(\N)N)c1ccccc1
smiles:n1c(csc1\[NH]=C(\N)N)c1cccc(c1)N
smiles:n1c(csc1\[NH]=C(\N)N)c1cccc(c1)NC(C)=O
smiles:n1c(csc1\[NH]=C(\N)N)c1cccc(c1)N\C(NC)=[NH]\C#N
smiles:c1(cc(N\C(=[NH]\c2cccc(c2)CC)C)ccc1)CC
Remove NaNs
<class 'pandas.core.frame.DataFrame'>
Index: 2040 entries, 0 to 2049
Data columns (total 4 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  2040 non-null   object
dtypes: int64(2), object(2)
memory usage: 79.7+ KB
======================================================================
Re-type `label` columns
<class 'pandas.core.frame.DataFrame'>
Index: 2040 entries, 0 to 2049
Data columns (total 4 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  2040 non-null   object
dtypes: int64(2), object(2)
memory usage: 79.7+ KB
======================================================================
Save `df_raw` as `raw_path`: ../MoleculeNetICL_SD-SPL/BBBP/raw.csv
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2050 entries, 0 to 2049
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   num     2050 non-null   int64 
 1   name    2050 non-null   object
 2   p_np    2050 non-null   int64 
 3   smiles  2050 non-null   object
dtypes: int64(2), object(2)
memory usage: 64.2+ KB
======================================================================
Save `df` as `trimmed_path`: ../MoleculeNetICL_SD-SPL/BBBP/trimmed.csv
<class 'pandas.core.frame.DataFrame'>
Index: 2040 entries, 0 to 2049
Data columns (total 4 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  2040 non-null   object
dtypes: int64(2), object(2)
memory usage: 79.7+ KB
======================================================================
Remove 10 rows due to empty SMILES, label or Scaffold SMILES
  >> 2040/2050 rows remaining after trimming
======================================================================
Init Morgan Fingerprint Embedding ...
Get embedding with FP
<class 'pandas.core.frame.DataFrame'>
Index: 2040 entries, 0 to 2049
Data columns (total 5 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  2040 non-null   object
 4   embed            2040 non-null   object
dtypes: int64(2), object(3)
memory usage: 95.6+ KB
======================================================================
Save `embed_col` as `embed_path`: ../MoleculeNetICL_SD-SPL/BBBP/embed_fp_r=2_b=1024.pk
<class 'pandas.core.frame.DataFrame'>
Index: 2040 entries, 0 to 2049
Data columns (total 5 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  2040 non-null   object
 4   embed            2040 non-null   object
dtypes: int64(2), object(3)
memory usage: 95.6+ KB
======================================================================
Remove 0 rows due to empty embedding
2040/2040 rows remaining after trimming
======================================================================
Saved Train/Valid/Test (8:1:1) splits
======================================================================
# train = 1632
sample: {
  raw_ID: 1392
  smiles: C3=C(C2(C(N(CN1CCOCC1)C(C2)=O)=O)C)C=CC=C3
  label: 1
fp <class 'numpy.ndarray'>
  embed: (1024,) 
}

# valid = 204
sample: {
  raw_ID: 1979
  smiles: C1=CC=CC2=C1N(C3=C(S2)C=CC=C3)CC(C)N(C)C
  label: 1
  embed: (1024,) 
}

# test  = 204
sample: {
  raw_ID: 1450
  smiles: CC1OC(C)OC(O1)C
  label: 1
  embed: (1024,) 
}

======================================================================

======================= MolT5-small Embedding ========================
Load `df_raw` from `raw_path`: ../MoleculeNetICL_SD-SPL/BBBP/raw.csv
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2050 entries, 0 to 2049
Data columns (total 4 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   num     2050 non-null   int64 
 1   name    2050 non-null   object
 2   p_np    2050 non-null   int64 
 3   smiles  2050 non-null   object
dtypes: int64(2), object(2)
memory usage: 64.2+ KB
======================================================================
Load `df` from `trimmed_path`: ../MoleculeNetICL_SD-SPL/BBBP/trimmed.csv
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2040 entries, 0 to 2039
Data columns (total 4 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  1941 non-null   object
dtypes: int64(2), object(2)
memory usage: 63.9+ KB
======================================================================
Remove 10 rows due to empty SMILES, label or Scaffold SMILES
  >> 2040/2050 rows remaining after trimming
======================================================================
Init MolT5-small Embedding ...
Use cuda

  0%|                                                                                                                                                                       | 0/2 [00:00<?, ?it/s]
 50%|███████████████████████████████████████████████████████████████████████████████▌                                                                               | 1/2 [00:01<00:01,  1.74s/it]
100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 2/2 [00:02<00:00,  1.16s/it]
                                                                                                                                                                                                  
Get embedding with MolT5
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2040 entries, 0 to 2039
Data columns (total 5 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  1941 non-null   object
 4   embed            2040 non-null   object
dtypes: int64(2), object(3)
memory usage: 79.8+ KB
======================================================================
Save `embed_col` as `embed_path`: ../MoleculeNetICL_SD-SPL/BBBP/embed_molt5_small_d512.pt
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2040 entries, 0 to 2039
Data columns (total 5 columns):
 #   Column           Non-Null Count  Dtype 
---  ------           --------------  ----- 
 0   raw_ID           2040 non-null   int64 
 1   smiles           2040 non-null   object
 2   label            2040 non-null   int64 
 3   scaffold_smiles  1941 non-null   object
 4   embed            2040 non-null   object
dtypes: int64(2), object(3)
memory usage: 79.8+ KB
======================================================================
Remove 0 rows due to empty embedding
2040/2040 rows remaining after trimming
======================================================================
Load split dfs from ../MoleculeNetICL_SD-SPL/BBBP
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1632 entries, 0 to 1631
Data columns (total 3 columns):
 #   Column  Non-Null Count  Dtype 
---  ------  --------------  ----- 
 0   raw_ID  1632 non-null   int64 
 1   smiles  1632 non-null   object
 2   label   1632 non-null   int64 
dtypes: int64(2), object(1)
memory usage: 38.4+ KB
======================================================================
# train = 1632
sample: {
  raw_ID: 1392
  smiles: C3=C(C2(C(N(CN1CCOCC1)C(C2)=O)=O)C)C=CC=C3
  label: 1
small <class 'torch.Tensor'>
  embed: torch.Size([512]) 
}

# valid = 204
sample: {
  raw_ID: 1979
  smiles: C1=CC=CC2=C1N(C3=C(S2)C=CC=C3)CC(C)N(C)C
  label: 1
  embed: torch.Size([512]) 
}

# test  = 204
sample: {
  raw_ID: 1450
  smiles: CC1OC(C)OC(O1)C
  label: 1
  embed: torch.Size([512]) 
}

======================================================================

=== Completed successfully at 2026-01-06 12:41:09 (Duration: 38s) ===