MacrocycleWizard 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,343 @@
1
+ """MacrocycleWizard/MolD/specific/GroupE.py"""
2
+ """
3
+ Group E: Heteroatom and heavy atom counts in substituents and peripheral groups
4
+ """
5
+
6
+ from tqdm import tqdm
7
+ from rdkit import Chem
8
+ from ..base import MacrocycleCalculator
9
+ from rdkit.Chem.Lipinski import HeavyAtomCount
10
+ from rdkit.Chem import Descriptors
11
+ from ..base import _get_macrocycle_ring_mol_2
12
+
13
+
14
+ class GroupE(MacrocycleCalculator):
15
+ def get_E01_Substituent_Heteroatom_to_Substituent_Heavy_Atom_Ratio(self):
16
+ E01_Substituent_Heteroatom_to_Substituent_Heavy_Atom_Ratio = []
17
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
18
+ sum_fragments_heavy_atoms = 0
19
+ sum_fragments_hetero_atoms = 0
20
+ for fragment_smi in fragments:
21
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
22
+ if fragment_mol:
23
+ substituent_atoms = HeavyAtomCount(fragment_mol)
24
+ if substituent_atoms >= 2:
25
+ sum_fragments_heavy_atoms += substituent_atoms
26
+ hetero_atoms = Chem.rdMolDescriptors.CalcNumHeteroatoms(fragment_mol)
27
+ sum_fragments_hetero_atoms += hetero_atoms
28
+ if sum_fragments_heavy_atoms > 0:
29
+ normalized_value = sum_fragments_hetero_atoms / sum_fragments_heavy_atoms
30
+ else:
31
+ normalized_value = 0
32
+ E01_Substituent_Heteroatom_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
33
+ return E01_Substituent_Heteroatom_to_Substituent_Heavy_Atom_Ratio
34
+
35
+ def get_E02_Peripheral_Heteroatom_to_Peripheral_Heavy_Atom_Ratio(self):
36
+ E02_Peripheral_Heteroatom_to_Peripheral_Heavy_Atom_Ratio = []
37
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
38
+ sum_peripheral_heavy_atoms = 0
39
+ sum_peripheral_hetero_atoms = 0
40
+ for fragment_smi in fragments:
41
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
42
+ if fragment_mol:
43
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
44
+ if peripheral_atoms == 1:
45
+ sum_peripheral_heavy_atoms += peripheral_atoms
46
+ hetero_atoms = Chem.rdMolDescriptors.CalcNumHeteroatoms(fragment_mol)
47
+ sum_peripheral_hetero_atoms += hetero_atoms
48
+ if sum_peripheral_heavy_atoms > 0:
49
+ normalized_value = sum_peripheral_hetero_atoms / sum_peripheral_heavy_atoms
50
+ else:
51
+ normalized_value = 0
52
+ E02_Peripheral_Heteroatom_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
53
+ return E02_Peripheral_Heteroatom_to_Peripheral_Heavy_Atom_Ratio
54
+
55
+ def get_E03_Substituent_N_to_O_Ratio(self):
56
+ E03_Substituent_N_to_O_Ratio = []
57
+ for fragments in tqdm(self.fragment_smiles):
58
+ num_substituent_nitrogens = 0
59
+ num_substituent_oxygens = 0
60
+ for fragment_smi in fragments:
61
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
62
+ if fragment_mol:
63
+ if HeavyAtomCount(fragment_mol) >= 2:
64
+ for atom in fragment_mol.GetAtoms():
65
+ atomic_num = atom.GetAtomicNum()
66
+ if atomic_num == 7:
67
+ num_substituent_nitrogens += 1
68
+ elif atomic_num == 8:
69
+ num_substituent_oxygens += 1
70
+ ratio_sub_n_to_o = (num_substituent_nitrogens + 1) / (num_substituent_oxygens + 1)
71
+ E03_Substituent_N_to_O_Ratio.append(ratio_sub_n_to_o)
72
+ return E03_Substituent_N_to_O_Ratio
73
+
74
+ def get_E04_Peripheral_N_to_O_Ratio(self):
75
+ E04_Peripheral_N_to_O_Ratio = []
76
+ for fragments in tqdm(self.fragment_smiles):
77
+ num_peripheral_nitrogens = 0
78
+ num_peripheral_oxygens = 0
79
+ for fragment_smi in fragments:
80
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
81
+ if fragment_mol:
82
+ if HeavyAtomCount(fragment_mol) == 1:
83
+ for atom in fragment_mol.GetAtoms():
84
+ atomic_num = atom.GetAtomicNum()
85
+ if atomic_num == 7:
86
+ num_peripheral_nitrogens += 1
87
+ elif atomic_num == 8:
88
+ num_peripheral_oxygens += 1
89
+ ratio_periph_n_to_o = (num_peripheral_nitrogens + 1) / (num_peripheral_oxygens + 1)
90
+ E04_Peripheral_N_to_O_Ratio.append(ratio_periph_n_to_o)
91
+ return E04_Peripheral_N_to_O_Ratio
92
+
93
+ def get_E05_Substituent_O_to_Substituent_Heavy_Atom_Ratio(self):
94
+ E05_Substituent_O_to_Substituent_Heavy_Atom_Ratio = []
95
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
96
+ sum_fragments_heavy_atoms = 0
97
+ sum_fragments_oxygen_atoms = 0
98
+ for fragment_smi in fragments:
99
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
100
+ if fragment_mol:
101
+ substituent_atoms = HeavyAtomCount(fragment_mol)
102
+ if substituent_atoms >= 2:
103
+ sum_fragments_heavy_atoms += substituent_atoms
104
+ for atom in fragment_mol.GetAtoms():
105
+ if atom.GetAtomicNum() == 8:
106
+ sum_fragments_oxygen_atoms += 1
107
+ if sum_fragments_heavy_atoms > 0:
108
+ normalized_value = sum_fragments_oxygen_atoms / sum_fragments_heavy_atoms
109
+ else:
110
+ normalized_value = 0
111
+ E05_Substituent_O_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
112
+ return E05_Substituent_O_to_Substituent_Heavy_Atom_Ratio
113
+
114
+ def get_E06_Peripheral_O_to_Peripheral_Heavy_Atom_Ratio(self):
115
+ E06_Peripheral_O_to_Peripheral_Heavy_Atom_Ratio = []
116
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
117
+ sum_peripheral_heavy_atoms = 0
118
+ sum_peripheral_oxygen_atoms = 0
119
+ for fragment_smi in fragments:
120
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
121
+ if fragment_mol:
122
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
123
+ if peripheral_atoms == 1:
124
+ sum_peripheral_heavy_atoms += peripheral_atoms
125
+ for atom in fragment_mol.GetAtoms():
126
+ if atom.GetAtomicNum() == 8:
127
+ sum_peripheral_oxygen_atoms += 1
128
+ if sum_peripheral_heavy_atoms > 0:
129
+ normalized_value = sum_peripheral_oxygen_atoms / sum_peripheral_heavy_atoms
130
+ else:
131
+ normalized_value = 0
132
+ E06_Peripheral_O_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
133
+ return E06_Peripheral_O_to_Peripheral_Heavy_Atom_Ratio
134
+
135
+ def get_E07_Substituent_N_to_Substituent_Heavy_Atom_Ratio(self):
136
+ E07_Substituent_N_to_Substituent_Heavy_Atom_Ratio = []
137
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
138
+ sum_fragments_heavy_atoms = 0
139
+ sum_fragments_n_atoms = 0
140
+ for fragment_smi in fragments:
141
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
142
+ if fragment_mol:
143
+ substituent_atoms = HeavyAtomCount(fragment_mol)
144
+ if substituent_atoms >= 2:
145
+ sum_fragments_heavy_atoms += substituent_atoms
146
+ for atom in fragment_mol.GetAtoms():
147
+ if atom.GetAtomicNum() == 7:
148
+ sum_fragments_n_atoms += 1
149
+ if sum_fragments_heavy_atoms > 0:
150
+ normalized_value = sum_fragments_n_atoms / sum_fragments_heavy_atoms
151
+ else:
152
+ normalized_value = 0
153
+ E07_Substituent_N_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
154
+ return E07_Substituent_N_to_Substituent_Heavy_Atom_Ratio
155
+
156
+ def get_E08_Peripheral_N_to_Peripheral_Heavy_Atom_Ratio(self):
157
+ E08_Peripheral_N_to_Peripheral_Heavy_Atom_Ratio = []
158
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
159
+ sum_peripheral_heavy_atoms = 0
160
+ sum_peripheral_n_atoms = 0
161
+ for fragment_smi in fragments:
162
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
163
+ if fragment_mol:
164
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
165
+ if peripheral_atoms == 1:
166
+ sum_peripheral_heavy_atoms += peripheral_atoms
167
+ for atom in fragment_mol.GetAtoms():
168
+ if atom.GetAtomicNum() == 7:
169
+ sum_peripheral_n_atoms += 1
170
+ if sum_peripheral_heavy_atoms > 0:
171
+ normalized_value = sum_peripheral_n_atoms / sum_peripheral_heavy_atoms
172
+ else:
173
+ normalized_value = 0
174
+ E08_Peripheral_N_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
175
+ return E08_Peripheral_N_to_Peripheral_Heavy_Atom_Ratio
176
+
177
+ def get_E09_Substituent_P_to_Substituent_Heavy_Atom_Ratio(self):
178
+ E09_Substituent_P_to_Substituent_Heavy_Atom_Ratio = []
179
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
180
+ sum_fragments_heavy_atoms = 0
181
+ sum_fragments_p_atoms = 0
182
+ for fragment_smi in fragments:
183
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
184
+ if fragment_mol:
185
+ substituent_atoms = HeavyAtomCount(fragment_mol)
186
+ if substituent_atoms >= 2:
187
+ sum_fragments_heavy_atoms += substituent_atoms
188
+ for atom in fragment_mol.GetAtoms():
189
+ if atom.GetAtomicNum() == 15:
190
+ sum_fragments_p_atoms += 1
191
+ if sum_fragments_heavy_atoms > 0:
192
+ normalized_value = sum_fragments_p_atoms / sum_fragments_heavy_atoms
193
+ else:
194
+ normalized_value = 0
195
+ E09_Substituent_P_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
196
+ return E09_Substituent_P_to_Substituent_Heavy_Atom_Ratio
197
+
198
+ def get_E10_Peripheral_P_to_Peripheral_Heavy_Atom_Ratio(self):
199
+ E10_Peripheral_P_to_Peripheral_Heavy_Atom_Ratio = []
200
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
201
+ sum_peripheral_heavy_atoms = 0
202
+ sum_peripheral_p_atoms = 0
203
+ for fragment_smi in fragments:
204
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
205
+ if fragment_mol:
206
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
207
+ if peripheral_atoms == 1:
208
+ sum_peripheral_heavy_atoms += peripheral_atoms
209
+ for atom in fragment_mol.GetAtoms():
210
+ if atom.GetAtomicNum() == 15:
211
+ sum_peripheral_p_atoms += 1
212
+ if sum_peripheral_heavy_atoms > 0:
213
+ normalized_value = sum_peripheral_p_atoms / sum_peripheral_heavy_atoms
214
+ else:
215
+ normalized_value = 0
216
+ E10_Peripheral_P_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
217
+ return E10_Peripheral_P_to_Peripheral_Heavy_Atom_Ratio
218
+
219
+ def get_E11_Substituent_S_to_Substituent_Heavy_Atom_Ratio(self):
220
+ E11_Substituent_S_to_Substituent_Heavy_Atom_Ratio = []
221
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
222
+ sum_fragments_heavy_atoms = 0
223
+ sum_fragments_s_atoms = 0
224
+ for fragment_smi in fragments:
225
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
226
+ if fragment_mol:
227
+ substituent_atoms = HeavyAtomCount(fragment_mol)
228
+ if substituent_atoms >= 2:
229
+ sum_fragments_heavy_atoms += substituent_atoms
230
+ for atom in fragment_mol.GetAtoms():
231
+ if atom.GetAtomicNum() == 16:
232
+ sum_fragments_s_atoms += 1
233
+ if sum_fragments_heavy_atoms > 0:
234
+ normalized_value = sum_fragments_s_atoms / sum_fragments_heavy_atoms
235
+ else:
236
+ normalized_value = 0
237
+ E11_Substituent_S_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
238
+ return E11_Substituent_S_to_Substituent_Heavy_Atom_Ratio
239
+
240
+ def get_E12_Peripheral_S_to_Peripheral_Heavy_Atom_Ratio(self):
241
+ E12_Peripheral_S_to_Peripheral_Heavy_Atom_Ratio = []
242
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
243
+ sum_peripheral_heavy_atoms = 0
244
+ sum_peripheral_s_atoms = 0
245
+ for fragment_smi in fragments:
246
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
247
+ if fragment_mol:
248
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
249
+ if peripheral_atoms == 1:
250
+ sum_peripheral_heavy_atoms += peripheral_atoms
251
+ for atom in fragment_mol.GetAtoms():
252
+ if atom.GetAtomicNum() == 16:
253
+ sum_peripheral_s_atoms += 1
254
+ if sum_peripheral_heavy_atoms > 0:
255
+ normalized_value = sum_peripheral_s_atoms / sum_peripheral_heavy_atoms
256
+ else:
257
+ normalized_value = 0
258
+ E12_Peripheral_S_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
259
+ return E12_Peripheral_S_to_Peripheral_Heavy_Atom_Ratio
260
+
261
+ def get_E13_Substituent_F_to_Substituent_Heavy_Atom_Ratio(self):
262
+ E13_Substituent_F_to_Substituent_Heavy_Atom_Ratio = []
263
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
264
+ sum_fragments_heavy_atoms = 0
265
+ sum_fragments_f_atoms = 0
266
+ for fragment_smi in fragments:
267
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
268
+ if fragment_mol:
269
+ substituent_atoms = HeavyAtomCount(fragment_mol)
270
+ if substituent_atoms >= 2:
271
+ sum_fragments_heavy_atoms += substituent_atoms
272
+ for atom in fragment_mol.GetAtoms():
273
+ if atom.GetAtomicNum() == 9:
274
+ sum_fragments_f_atoms += 1
275
+ if sum_fragments_heavy_atoms > 0:
276
+ normalized_value = sum_fragments_f_atoms / sum_fragments_heavy_atoms
277
+ else:
278
+ normalized_value = 0
279
+ E13_Substituent_F_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
280
+ return E13_Substituent_F_to_Substituent_Heavy_Atom_Ratio
281
+
282
+ def get_E14_Peripheral_F_to_Peripheral_Heavy_Atom_Ratio(self):
283
+ E14_Peripheral_F_to_Peripheral_Heavy_Atom_Ratio = []
284
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
285
+ sum_peripheral_heavy_atoms = 0
286
+ sum_peripheral_f_atoms = 0
287
+ for fragment_smi in fragments:
288
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
289
+ if fragment_mol:
290
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
291
+ if peripheral_atoms == 1:
292
+ sum_peripheral_heavy_atoms += peripheral_atoms
293
+ for atom in fragment_mol.GetAtoms():
294
+ if atom.GetAtomicNum() == 9:
295
+ sum_peripheral_f_atoms += 1
296
+ if sum_peripheral_heavy_atoms > 0:
297
+ normalized_value = sum_peripheral_f_atoms / sum_peripheral_heavy_atoms
298
+ else:
299
+ normalized_value = 0
300
+ E14_Peripheral_F_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
301
+ return E14_Peripheral_F_to_Peripheral_Heavy_Atom_Ratio
302
+
303
+ def get_E15_Substituent_Cl_to_Substituent_Heavy_Atom_Ratio(self):
304
+ E15_Substituent_Cl_to_Substituent_Heavy_Atom_Ratio = []
305
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
306
+ sum_fragments_heavy_atoms = 0
307
+ sum_fragments_cl_atoms = 0
308
+ for fragment_smi in fragments:
309
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
310
+ if fragment_mol:
311
+ substituent_atoms = HeavyAtomCount(fragment_mol)
312
+ if substituent_atoms >= 2:
313
+ sum_fragments_heavy_atoms += substituent_atoms
314
+ for atom in fragment_mol.GetAtoms():
315
+ if atom.GetAtomicNum() == 17:
316
+ sum_fragments_cl_atoms += 1
317
+ if sum_fragments_heavy_atoms > 0:
318
+ normalized_value = sum_fragments_cl_atoms / sum_fragments_heavy_atoms
319
+ else:
320
+ normalized_value = 0
321
+ E15_Substituent_Cl_to_Substituent_Heavy_Atom_Ratio.append(normalized_value)
322
+ return E15_Substituent_Cl_to_Substituent_Heavy_Atom_Ratio
323
+
324
+ def get_E16_Peripheral_Cl_to_Peripheral_Heavy_Atom_Ratio(self):
325
+ E16_Peripheral_Cl_to_Peripheral_Heavy_Atom_Ratio = []
326
+ for i, fragments in enumerate(tqdm(self.fragment_smiles)):
327
+ sum_peripheral_heavy_atoms = 0
328
+ sum_peripheral_cl_atoms = 0
329
+ for fragment_smi in fragments:
330
+ fragment_mol = Chem.MolFromSmiles(fragment_smi)
331
+ if fragment_mol:
332
+ peripheral_atoms = HeavyAtomCount(fragment_mol)
333
+ if peripheral_atoms == 1:
334
+ sum_peripheral_heavy_atoms += peripheral_atoms
335
+ for atom in fragment_mol.GetAtoms():
336
+ if atom.GetAtomicNum() == 17:
337
+ sum_peripheral_cl_atoms += 1
338
+ if sum_peripheral_heavy_atoms > 0:
339
+ normalized_value = sum_peripheral_cl_atoms / sum_peripheral_heavy_atoms
340
+ else:
341
+ normalized_value = 0
342
+ E16_Peripheral_Cl_to_Peripheral_Heavy_Atom_Ratio.append(normalized_value)
343
+ return E16_Peripheral_Cl_to_Peripheral_Heavy_Atom_Ratio
@@ -0,0 +1,222 @@
1
+ """MacrocycleWizard/MolD/specific/GroupF.py"""
2
+ """
3
+ Group F: Ring-Macrocycle Ring Interactions
4
+ """
5
+
6
+ from tqdm import tqdm
7
+ from rdkit import Chem
8
+ from rdkit.Chem import rdMolDescriptors
9
+
10
+ from ..base import _get_macrocycle_ring_mol_2, _get_chemically_relevant_rings, _identify_bridge_rings, _count_bridge_atoms_in_macrocycle
11
+ from ..base import _get_macrocycle_spiro_atom_count, _get_macrocycle_fused_bond_count, _get_macrocycle_bridge_rings_count, _get_macrocycle_bridge_atoms_count
12
+ from ..base import MacrocycleCalculator
13
+
14
+ class GroupF(MacrocycleCalculator):
15
+ def get_F01_Spiro_Atom_in_Macrocycle_Ring_Ratio(self):
16
+ """
17
+ If the Spiro Ring is attached to a bridge ring inside the MC Ring, it does not count.
18
+ The molD Caluculated here is a little different from Viarengo-Baker et al.,2021. Here we
19
+ only count the spiro ATOMS not the RINGS. This is similar while calculate later.
20
+ """
21
+ F01_Spiro_Atom_in_Macrocycle_Ring_Ratio = []
22
+ for mol, ring_size in tqdm(zip(self.mols, self.ring_size)):
23
+ spiro_count = _get_macrocycle_spiro_atom_count(mol)
24
+ if ring_size > 0:
25
+ spiro_atom_in_macrocycle_ring_ratio = spiro_count / ring_size
26
+ else:
27
+ spiro_atom_in_macrocycle_ring_ratio = 0
28
+ F01_Spiro_Atom_in_Macrocycle_Ring_Ratio.append(spiro_atom_in_macrocycle_ring_ratio)
29
+
30
+ return F01_Spiro_Atom_in_Macrocycle_Ring_Ratio
31
+
32
+ def get_F02_Fused_Bond_in_Macrocycle_Ring_Ratio(self):
33
+ """
34
+ Here we define the fused ring by:
35
+ i) There are and only are two shared atoms with the MC ring
36
+ ii) The distance of the shared atoms is 1 (ie form one bond).
37
+ With the definition, we count the BONDS in the fused ring.
38
+
39
+ Notice ⚠️: we are counting the BONDS, not rings nor atoms.
40
+ """
41
+ F02_Fused_Bond_in_Macrocycle_Ring_Ratio = []
42
+
43
+ for mol, ring_size in tqdm(zip(self.mols, self.ring_size)):
44
+ fused_bond_count = _get_macrocycle_fused_bond_count(mol)
45
+ if ring_size > 0:
46
+ fused_bond_in_macrocycle_ring_ratio = fused_bond_count / ring_size
47
+ else:
48
+ fused_bond_in_macrocycle_ring_ratio = 0
49
+ F02_Fused_Bond_in_Macrocycle_Ring_Ratio.append(fused_bond_in_macrocycle_ring_ratio)
50
+ return F02_Fused_Bond_in_Macrocycle_Ring_Ratio
51
+
52
+ def get_F03_Bridgehead_Atom_in_Macrocycle_Ring_Ratio(self):
53
+ """
54
+ In RDKit,calculation of Bridgehead_atoms is provide. We use the the function directly.
55
+ However, if the Bridgehead_atoms is in the MC ring is hard to detect, so we:
56
+ use the Total Bridgehead_atoms - Fragment Bridgehead_atoms
57
+ """
58
+ F03_Bridgehead_Atom_in_Macrocycle_Ring_Ratio = []
59
+
60
+ for mol, ring_mol, ring_size, fragments in tqdm(zip(
61
+ self.mols,
62
+ self.ring_mol,
63
+ self.ring_size,
64
+ self.fragment_smiles
65
+ )):
66
+ total_bridgehead = rdMolDescriptors.CalcNumBridgeheadAtoms(mol)
67
+ substituent_bridgehead = 0
68
+ if fragments:
69
+ for frag_smi in fragments:
70
+ frag_mol = Chem.MolFromSmiles(frag_smi)
71
+ if frag_mol:
72
+ substituent_bridgehead += rdMolDescriptors.CalcNumBridgeheadAtoms(frag_mol)
73
+ macrocycle_bridgehead = max(0, total_bridgehead - substituent_bridgehead)
74
+ bridgehead_atom_in_macrocycle_ring_ratio = macrocycle_bridgehead / ring_size if ring_size > 0 else 0
75
+ F03_Bridgehead_Atom_in_Macrocycle_Ring_Ratio.append(bridgehead_atom_in_macrocycle_ring_ratio)
76
+
77
+ return F03_Bridgehead_Atom_in_Macrocycle_Ring_Ratio
78
+
79
+ def get_F04_Bridge_Ring_in_Macrocycle_Ring_Ratio(self):
80
+ """
81
+ Define Bridge Ring as:
82
+ i) A ring that has three or more atoms in common with the main ring (MC)
83
+ ii) A ring that has two atoms in common with the main ring, but the two atoms are not adjacent on the main ring
84
+
85
+ Count the humber of Bridge Rings and normalize them according to the size of the main ring
86
+ """
87
+ F04_Bridge_Ring_in_Macrocycle_Ring_Ratio = []
88
+
89
+ for mol, ring_size in tqdm(zip(self.mols, self.ring_size)):
90
+ bridge_rings_count = _get_macrocycle_bridge_rings_count(mol)
91
+
92
+ if ring_size > 0:
93
+ bridge_ring_in_macrocycle_ring_ratio = bridge_rings_count / ring_size
94
+ else:
95
+ bridge_ring_in_macrocycle_ring_ratio = 0
96
+
97
+ F04_Bridge_Ring_in_Macrocycle_Ring_Ratio.append(bridge_ring_in_macrocycle_ring_ratio)
98
+
99
+ return F04_Bridge_Ring_in_Macrocycle_Ring_Ratio
100
+
101
+ def get_F05_Bridge_Atom_in_Macrocycle_Ring_Ratio(self):
102
+ """
103
+ F05: Normalized count of bridge atoms in the macrocycle
104
+
105
+ Counts atoms in the macrocycle that are part of bridge rings,
106
+ including bridge head atoms. Normalized by macrocycle size.
107
+ """
108
+ F05_Bridge_Atom_in_Macrocycle_Ring_Ratio = []
109
+ for mol, ring_size in tqdm(zip(self.mols, self.ring_size)):
110
+ bridge_atoms_count = _get_macrocycle_bridge_atoms_count(mol)
111
+ if ring_size > 0:
112
+ bridge_atom_in_macrocycle_ring_ratio = bridge_atoms_count / ring_size
113
+ else:
114
+ bridge_atom_in_macrocycle_ring_ratio = 0
115
+ F05_Bridge_Atom_in_Macrocycle_Ring_Ratio.append(bridge_atom_in_macrocycle_ring_ratio)
116
+ return F05_Bridge_Atom_in_Macrocycle_Ring_Ratio
117
+
118
+ def get_F06_Restricted_Bond_in_Macrocycle_Ring_Ratio(self):
119
+ """
120
+ F06: Restricted Fraction (Restricted/N)
121
+
122
+ Count of bonds in the macrocycle that are rigidified:
123
+ - Bonds that are part of a ring fusion
124
+ - Bridge bonds
125
+ - Amide bonds
126
+ - Double, triple and aromatic bonds
127
+
128
+ Normalized to the macrocycle size.
129
+ """
130
+ F06_Restricted_Bond_in_Macrocycle_Ring_Ratio = []
131
+
132
+ for mol, ring_size in tqdm(zip(self.mols, self.ring_size)):
133
+ # Skip if no macrocycle
134
+ if ring_size == 0:
135
+ F06_Restricted_Bond_in_Macrocycle_Ring_Ratio.append(0.0)
136
+ continue
137
+
138
+ # Get macrocycle atoms and bonds
139
+ _, macrocycle_atoms = _get_macrocycle_ring_mol_2(mol)
140
+ macrocycle_atoms_set = set(macrocycle_atoms)
141
+
142
+ # Get macrocycle bonds
143
+ macrocycle_bonds = []
144
+ for i in range(len(macrocycle_atoms)):
145
+ atom1 = macrocycle_atoms[i]
146
+ atom2 = macrocycle_atoms[(i+1) % len(macrocycle_atoms)]
147
+ bond = mol.GetBondBetweenAtoms(atom1, atom2)
148
+ if bond:
149
+ macrocycle_bonds.append(bond.GetIdx())
150
+
151
+ # 1. Fused bonds - reuse existing function
152
+ fused_bond_count = _get_macrocycle_fused_bond_count(mol)
153
+ fused_bonds = []
154
+
155
+ # Get the actual fused bonds (not just the count)
156
+ ri = mol.GetRingInfo()
157
+ rings = ri.AtomRings()
158
+ for ring in rings:
159
+ if set(ring) == macrocycle_atoms_set:
160
+ continue
161
+
162
+ shared_atoms = set(ring).intersection(macrocycle_atoms_set)
163
+ if len(shared_atoms) == 2:
164
+ shared_atoms_list = list(shared_atoms)
165
+ bond = mol.GetBondBetweenAtoms(shared_atoms_list[0], shared_atoms_list[1])
166
+ if bond and bond.GetIdx() in macrocycle_bonds:
167
+ fused_bonds.append(bond.GetIdx())
168
+
169
+ # 2. Bridge bonds
170
+ bridge_rings = _identify_bridge_rings(mol, _get_chemically_relevant_rings(mol))
171
+ bridge_bonds = []
172
+
173
+ # Find bridge head atoms
174
+ for ring in bridge_rings:
175
+ ring_atoms = set(ring)
176
+ bridge_head_atoms = ring_atoms.intersection(macrocycle_atoms_set)
177
+
178
+ # For each bridge head atom, find bonds with adjacent atoms in the macrocycle
179
+ for head_idx in bridge_head_atoms:
180
+ for atom in mol.GetAtomWithIdx(head_idx).GetNeighbors():
181
+ adj_idx = atom.GetIdx()
182
+ # Ensure adjacent atom is also in the macrocycle
183
+ if adj_idx in macrocycle_atoms_set:
184
+ bond = mol.GetBondBetweenAtoms(head_idx, adj_idx)
185
+ if bond and bond.GetIdx() in macrocycle_bonds:
186
+ bridge_bonds.append(bond.GetIdx())
187
+
188
+ # 3. Amide bonds
189
+ amide_pattern = Chem.MolFromSmarts('[CX3](=[OX1])[NX3]')
190
+ matches = mol.GetSubstructMatches(amide_pattern)
191
+ amide_bonds = []
192
+
193
+ for match in matches:
194
+ c_idx, o_idx, n_idx = match
195
+ # Check if C-N bond is in the macrocycle
196
+ if c_idx in macrocycle_atoms_set and n_idx in macrocycle_atoms_set:
197
+ bond = mol.GetBondBetweenAtoms(c_idx, n_idx)
198
+ if bond:
199
+ amide_bonds.append(bond.GetIdx())
200
+
201
+ # 4. Multiple bonds (double, triple, aromatic)
202
+ multiple_bonds = []
203
+ for bond in mol.GetBonds():
204
+ begin_idx = bond.GetBeginAtomIdx()
205
+ end_idx = bond.GetEndAtomIdx()
206
+
207
+ # Check if bond is in the macrocycle
208
+ if begin_idx in macrocycle_atoms_set and end_idx in macrocycle_atoms_set:
209
+ bond_type = bond.GetBondType()
210
+ if (bond_type == Chem.BondType.DOUBLE or
211
+ bond_type == Chem.BondType.TRIPLE or
212
+ bond_type == Chem.BondType.AROMATIC):
213
+ multiple_bonds.append(bond.GetIdx())
214
+
215
+ # Combine all restricted bonds (removing duplicates)
216
+ all_restricted_bonds = set(fused_bonds + bridge_bonds + amide_bonds + multiple_bonds)
217
+
218
+ # Calculate restricted fraction
219
+ restricted_bond_in_macrocycle_ring_ratio = len(all_restricted_bonds) / ring_size
220
+ F06_Restricted_Bond_in_Macrocycle_Ring_Ratio.append(restricted_bond_in_macrocycle_ring_ratio)
221
+
222
+ return F06_Restricted_Bond_in_Macrocycle_Ring_Ratio
@@ -0,0 +1,80 @@
1
+ """MacrocycleWizard/MolD/specific/GroupG.py"""
2
+ """
3
+ Group G: Topological and connectivity MolD for Macrocycle Rings
4
+ """
5
+
6
+ from tqdm import tqdm
7
+ from PyBioMed.PyMolecule import topology, connectivity
8
+ from ..base import MacrocycleCalculator
9
+
10
+ class GroupG(MacrocycleCalculator):
11
+ """
12
+ Here we calculate topological and connectivity MolD for the macrocycle molecules
13
+ The molecular descriptions can be found in : https://www.researchgate.net/publication/235919348_manual_for_chemopy
14
+ The package is from https://github.com/gadsbyfly/PyBioMed
15
+ """
16
+
17
+ def get_G01_Weiner_Ring(self):
18
+ """
19
+ G01: Weiner Index for ring-stripped molecules
20
+ """
21
+ G01_Weiner_Ring = []
22
+ for mol in tqdm(self.ring_mol_stripped):
23
+ if mol is not None:
24
+ weiner = topology.CalculateWeiner(mol)
25
+ G01_Weiner_Ring.append(weiner)
26
+ else:
27
+ G01_Weiner_Ring.append(None)
28
+ return G01_Weiner_Ring
29
+
30
+ def get_G02_Harary_Ring(self):
31
+ """
32
+ G02: Harary Number for ring-stripped molecules
33
+ """
34
+ G02_Harary_Ring = []
35
+ for mol in tqdm(self.ring_mol_stripped):
36
+ if mol is not None:
37
+ harary = topology.CalculateHarary(mol)
38
+ G02_Harary_Ring.append(harary)
39
+ else:
40
+ G02_Harary_Ring.append(None)
41
+ return G02_Harary_Ring
42
+
43
+ def get_G03_Balaban_Ring(self):
44
+ """
45
+ G03: Balaban's J Index for ring-stripped molecules
46
+ """
47
+ G03_Balaban_Ring = []
48
+ for mol in tqdm(self.ring_mol_stripped):
49
+ if mol is not None:
50
+ balaban = topology.CalculateBalaban(mol)
51
+ G03_Balaban_Ring.append(balaban)
52
+ else:
53
+ G03_Balaban_Ring.append(None)
54
+ return G03_Balaban_Ring
55
+
56
+ def get_G04_BertzCT_Ring(self):
57
+ """
58
+ G04: BertzCT Index for ring-stripped molecules
59
+ """
60
+ G04_BertzCT_Ring = []
61
+ for mol in tqdm(self.ring_mol_stripped):
62
+ if mol is not None:
63
+ bertz_ct = topology.CalculateBertzCT(mol)
64
+ G04_BertzCT_Ring.append(bertz_ct)
65
+ else:
66
+ G04_BertzCT_Ring.append(None)
67
+ return G04_BertzCT_Ring
68
+
69
+ def get_G05_Xu_Ring(self):
70
+ """
71
+ G05: Xu Index for ring-stripped molecules
72
+ """
73
+ G05_Xu_Ring = []
74
+ for mol in tqdm(self.ring_mol_stripped):
75
+ if mol is not None:
76
+ xu_index = topology.CalculateXuIndex(mol)
77
+ G05_Xu_Ring.append(xu_index)
78
+ else:
79
+ G05_Xu_Ring.append(None)
80
+ return G05_Xu_Ring
@@ -0,0 +1,10 @@
1
+ """Specific descriptors module"""
2
+ """MacrocycleWizard/MolD/specific/__init__.py"""
3
+ from .GroupB import GroupB
4
+ from .GroupC import GroupC
5
+ from .GroupD import GroupD
6
+ from .GroupE import GroupE
7
+ from .GroupF import GroupF
8
+ from .GroupG import GroupG
9
+
10
+ __all__ = ['GroupB', 'GroupC', 'GroupD', 'GroupE', 'GroupF', 'GroupG']