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,92 @@
1
+ """MacrocycleWizard/MolD/general/GroupK.py"""
2
+ """Group K:Topological and connectivity descriptors."""
3
+
4
+ from tqdm import tqdm
5
+ from PyBioMed.PyMolecule import topology, connectivity
6
+ from ..base import MacrocycleCalculator
7
+
8
+ class GroupK(MacrocycleCalculator):
9
+ """
10
+ Here we calculate topological and connectivity MolD for the macrocycle molecules
11
+ The molecular descriptions can be found in : https://www.researchgate.net/publication/235919348_manual_for_chemopy
12
+ The package is from https://github.com/gadsbyfly/PyBioMed
13
+ """
14
+ def get_K01_Weiner(self):
15
+ """
16
+ K01: Weiner Index
17
+ """
18
+ K01_Weiner = []
19
+ for mol in tqdm(self.mols):
20
+ weiner = topology.CalculateWeiner(mol) if mol is not None else None
21
+ K01_Weiner.append(weiner)
22
+ return K01_Weiner
23
+
24
+ def get_K02_Harary(self):
25
+ """
26
+ K02: Harary Number
27
+ """
28
+ K02_Harary = []
29
+ for mol in tqdm(self.mols):
30
+ harary = topology.CalculateHarary(mol) if mol is not None else None
31
+ K02_Harary.append(harary)
32
+ return K02_Harary
33
+
34
+ def get_K03_Balaban(self):
35
+ """
36
+ K03: Balaban's J Index
37
+ """
38
+ K03_Balaban = []
39
+ for mol in tqdm(self.mols):
40
+ balaban = topology.CalculateBalaban(mol) if mol is not None else None
41
+ K03_Balaban.append(balaban)
42
+ return K03_Balaban
43
+
44
+ def get_K04_BertzCT(self):
45
+ """
46
+ K04: BertzCT Index
47
+ """
48
+ K04_BertzCT = []
49
+ for mol in tqdm(self.mols):
50
+ bertz_ct = topology.CalculateBertzCT(mol) if mol is not None else None
51
+ K04_BertzCT.append(bertz_ct)
52
+ return K04_BertzCT
53
+
54
+ def get_K05_Xu(self):
55
+ """
56
+ K05: Xu Index
57
+ """
58
+ K05_Xu = []
59
+ for mol in tqdm(self.mols):
60
+ xu_index = topology.CalculateXuIndex(mol) if mol is not None else None
61
+ K05_Xu.append(xu_index)
62
+ return K05_Xu
63
+
64
+ def get_K06_Petitjean(self):
65
+ """
66
+ K06: Petitjean Index
67
+ """
68
+ K06_Petitjean = []
69
+ for mol in tqdm(self.mols):
70
+ petitjean = topology.CalculatePetitjean(mol) if mol is not None else None
71
+ K06_Petitjean.append(petitjean)
72
+ return K06_Petitjean
73
+
74
+ def get_K07_Zagreb1(self):
75
+ """
76
+ K07: Zagreb Index 1
77
+ """
78
+ K07_Zagreb1 = []
79
+ for mol in tqdm(self.mols):
80
+ zagreb1 = topology.CalculateZagreb1(mol) if mol is not None else None
81
+ K07_Zagreb1.append(zagreb1)
82
+ return K07_Zagreb1
83
+
84
+ def get_K08_Zagreb2(self):
85
+ """
86
+ K08: Zagreb Index 2
87
+ """
88
+ K08_Zagreb2 = []
89
+ for mol in tqdm(self.mols):
90
+ zagreb2 = topology.CalculateZagreb2(mol) if mol is not None else None
91
+ K08_Zagreb2.append(zagreb2)
92
+ return K08_Zagreb2
@@ -0,0 +1,8 @@
1
+ """General descriptors module"""
2
+ """MacrocycleWizard/MolD/general/__init__.py"""
3
+ from .GroupH import GroupH
4
+ from .GroupI import GroupI
5
+ from .GroupJ import GroupJ
6
+ from .GroupK import GroupK
7
+
8
+ __all__ = ['GroupH', 'GroupI', 'GroupJ', 'GroupK']
@@ -0,0 +1,363 @@
1
+ """MacrocycleWizard/MolD/specific/GroupB.py"""
2
+
3
+ """
4
+ Macrocycle Ring Structural Descriptors.
5
+ """
6
+
7
+ from tqdm import tqdm
8
+ from rdkit import Chem
9
+ from rdkit.Chem import Descriptors
10
+ from ..base import MacrocycleCalculator
11
+ from ..base import _get_macrocycle_ring_mol_2
12
+
13
+
14
+ class GroupB(MacrocycleCalculator):
15
+ def _get_sub_amide_count_for_mol(self, mol):
16
+ macrocycle_mol = self.ring_mol[self.mols.index(mol)]
17
+ if macrocycle_mol is None:
18
+ return 0
19
+ sub_amide_smart = Chem.MolFromSmarts('[#6](=[#8])-[#7;H0]')
20
+ return len(macrocycle_mol.GetSubstructMatches(sub_amide_smart))
21
+
22
+ def _get_free_amide_count_for_mol(self, mol):
23
+ macrocycle_mol = self.ring_mol[self.mols.index(mol)]
24
+ if macrocycle_mol is None:
25
+ return 0
26
+ free_amide_smart = Chem.MolFromSmarts('[Nh][CX3]=[O]')
27
+ return len(macrocycle_mol.GetSubstructMatches(free_amide_smart))
28
+
29
+
30
+ def _trace_group_from_atom(self, mol, start_atom_idx, ring_atoms, max_depth=1):
31
+ group_atoms = [start_atom_idx]
32
+
33
+ start_atom = mol.GetAtomWithIdx(start_atom_idx)
34
+ for neigh in start_atom.GetNeighbors():
35
+ if neigh.GetIdx() in ring_atoms:
36
+ group_atoms.append(neigh.GetIdx())
37
+
38
+ return group_atoms
39
+
40
+ def get_B01_Normalised_Ring_Ratio(self):
41
+ B01_Normalised_Ring_Ratio = []
42
+ for ring_size, ha in tqdm(zip(self.ring_size, self.HA)):
43
+ Normalised_Ring_Size = ring_size / ha if ha > 0 else 0.0
44
+ B01_Normalised_Ring_Ratio.append(Normalised_Ring_Size)
45
+ return B01_Normalised_Ring_Ratio
46
+
47
+ def get_B02_Macrocycle_Fsp3_Ratio(self):
48
+ B02_Macrocycle_Fsp3_Ratio = []
49
+ for mol, ring_size in tqdm(zip(self.mols, self.ring_size)):
50
+ if ring_size == 0:
51
+ B02_Macrocycle_Fsp3_Ratio.append(0)
52
+ continue
53
+
54
+ try:
55
+ _, atoms_ring = _get_macrocycle_ring_mol_2(mol)
56
+ except ValueError:
57
+ B02_Macrocycle_Fsp3_Ratio.append(0)
58
+ continue
59
+
60
+ # Count hybridization on the original molecule so atom properties are preserved.
61
+ mc_sp3_carbons = sum(
62
+ 1 for orig_idx in atoms_ring
63
+ if mol.GetAtomWithIdx(orig_idx).GetSymbol() == 'C'
64
+ and mol.GetAtomWithIdx(orig_idx).GetHybridization() == Chem.HybridizationType.SP3
65
+ )
66
+
67
+ macrocycle_fsp3 = mc_sp3_carbons / ring_size
68
+ B02_Macrocycle_Fsp3_Ratio.append(macrocycle_fsp3)
69
+
70
+ return B02_Macrocycle_Fsp3_Ratio
71
+
72
+
73
+ def get_B03_Ring_Chiral_Centre_Normalised(self):
74
+ B03_Ring_Chiral_Centre_Normalised = []
75
+
76
+ for i, mol in enumerate(tqdm(self.mols)):
77
+ # Keep the stereochem information
78
+ mol_copy = Chem.Mol(mol)
79
+ _, atoms_ring = _get_macrocycle_ring_mol_2(mol_copy)
80
+
81
+ all_chiral_centers = Chem.FindMolChiralCenters(
82
+ mol_copy, includeUnassigned=True, useLegacyImplementation=False
83
+ )
84
+
85
+ # Original version: only count carbon chiral centers in the ring
86
+ # carbon_chiral_centers_in_ring = []
87
+ # for atom_idx, chirality in all_chiral_centers:
88
+ # atom = mol_copy.GetAtomWithIdx(atom_idx)
89
+ # if atom.GetSymbol() == 'C' and atom_idx in atoms_ring:
90
+ # carbon_chiral_centers_in_ring.append((atom_idx, chirality))
91
+ # num_carbon_chiral_centers = len(carbon_chiral_centers_in_ring)
92
+
93
+ # Modified version: count all chiral centers in the ring, not limited to carbon atoms
94
+
95
+ chiral_centers_in_ring = []
96
+ for atom_idx, chirality in all_chiral_centers:
97
+ if atom_idx in atoms_ring:
98
+ chiral_centers_in_ring.append((atom_idx, chirality))
99
+
100
+ num_chiral_centers = len(chiral_centers_in_ring)
101
+
102
+ ring_size = self.ring_size[i]
103
+
104
+ if ring_size > 0:
105
+ chiral_centers_normalised = num_chiral_centers / ring_size
106
+ else:
107
+ chiral_centers_normalised = 0
108
+
109
+ B03_Ring_Chiral_Centre_Normalised.append(chiral_centers_normalised)
110
+
111
+ return B03_Ring_Chiral_Centre_Normalised
112
+
113
+
114
+ def get_B04_Ring_Complexity_Carbon(self):
115
+ """
116
+ Calculate Ring Complexity with only consider Carbon (rComplxC).
117
+
118
+ Formula:
119
+ rComplxC = [2(rC) - rCH ] / [2rC]
120
+
121
+ Where:
122
+ - rC: Number of carbon atoms in the main macrocycle ring
123
+ - rCH: Number of C-H bonds in the main macrocycle ring (explicit and implicit)
124
+
125
+ """
126
+ B04_Ring_Complexity_Carbon = []
127
+
128
+ for mol in tqdm(self.mols):
129
+ if mol is None:
130
+ B04_Ring_Complexity_Carbon.append(0)
131
+ continue
132
+ mol = Chem.AddHs(mol)
133
+ #AllChem.EmbedMolecule(mol)
134
+ rings = mol.GetRingInfo().AtomRings()
135
+ if not rings:
136
+ B04_Ring_Complexity_Carbon.append(0)
137
+ continue
138
+ largest_ring = max(rings, key=len)
139
+ ring_atoms_idx = set(largest_ring)
140
+
141
+ num_MC_carbons = 0
142
+ for idx in ring_atoms_idx:
143
+ atom = mol.GetAtomWithIdx(idx)
144
+ atomic_num = atom.GetAtomicNum()
145
+ if atomic_num == 6:
146
+ num_MC_carbons += 1
147
+
148
+ num_MC_carbon_H_bonds = 0
149
+ for idx in ring_atoms_idx:
150
+ atom = mol.GetAtomWithIdx(idx)
151
+ if atom.GetAtomicNum() == 6:
152
+ neighbors = [neigh for neigh in atom.GetNeighbors()]
153
+ num_h_neighbors = sum(1 for neigh in neighbors if neigh.GetAtomicNum() == 1)
154
+ num_MC_carbon_H_bonds += num_h_neighbors
155
+
156
+ numerator = (2 * num_MC_carbons) - num_MC_carbon_H_bonds
157
+
158
+ denominator = (2 * num_MC_carbons)
159
+ if denominator != 0:
160
+ ring_complexity = numerator / denominator
161
+
162
+ else:
163
+ ring_complexity = 0
164
+
165
+ B04_Ring_Complexity_Carbon.append(ring_complexity)
166
+
167
+ return B04_Ring_Complexity_Carbon
168
+
169
+ def get_B05_Ring_Complexity_Heteroatom(self):
170
+ """
171
+ Calculate Ring Complexity with heteroatoms (rComplxHet).
172
+
173
+ Formula:
174
+ rComplxHet = [2(rC) - rCH + rN - rNH + r(S=O)] / [2(rC + rS) + rN]
175
+
176
+ Where:
177
+ - rC: Number of carbon atoms in the main macrocycle ring
178
+ - rN: Number of nitrogen atoms in the main macrocycle ring
179
+ - rS: Number of sulfur atoms in the main macrocycle ring
180
+ - rCH: Number of C-H bonds in the main macrocycle ring (explicit and implicit)
181
+ - rNH: Number of N-H bonds in the main macrocycle ring
182
+ - r(S=O): Number of S=O bonds in the main macrocycle ring
183
+ """
184
+ B05_Ring_Complexity_Heteroatom = []
185
+
186
+ for mol in tqdm(self.mols):
187
+ if mol is None:
188
+ B05_Ring_Complexity_Heteroatom.append(0)
189
+ continue
190
+ mol = Chem.AddHs(mol)
191
+ #AllChem.EmbedMolecule(mol)
192
+ rings = mol.GetRingInfo().AtomRings()
193
+ if not rings:
194
+ B05_Ring_Complexity_Heteroatom.append(0)
195
+ continue
196
+ largest_ring = max(rings, key=len)
197
+ ring_atoms_idx = set(largest_ring)
198
+ num_MC_carbons = 0
199
+ num_MC_nitrogens = 0
200
+ num_MC_sulfurs = 0
201
+ for idx in ring_atoms_idx:
202
+ atom = mol.GetAtomWithIdx(idx)
203
+ atomic_num = atom.GetAtomicNum()
204
+ if atomic_num == 6:
205
+ num_MC_carbons += 1
206
+ elif atomic_num == 7:
207
+ num_MC_nitrogens += 1
208
+ elif atomic_num == 16:
209
+ num_MC_sulfurs += 1
210
+ num_MC_carbon_H_bonds = 0
211
+ for idx in ring_atoms_idx:
212
+ atom = mol.GetAtomWithIdx(idx)
213
+ if atom.GetAtomicNum() == 6:
214
+ neighbors = [neigh for neigh in atom.GetNeighbors()]
215
+ num_h_neighbors = sum(1 for neigh in neighbors if neigh.GetAtomicNum() == 1)
216
+ num_MC_carbon_H_bonds += num_h_neighbors
217
+ num_MC_nitrogen_H_bonds = 0
218
+ for idx in ring_atoms_idx:
219
+ atom = mol.GetAtomWithIdx(idx)
220
+ if atom.GetAtomicNum() == 7:
221
+ neighbors = [neigh for neigh in atom.GetNeighbors()]
222
+ num_h_neighbors = sum(1 for neigh in neighbors if neigh.GetAtomicNum() == 1)
223
+ num_MC_nitrogen_H_bonds += num_h_neighbors
224
+ num_MC_sulfur_O_bonds = 0
225
+ if num_MC_sulfurs > 0:
226
+ s_o_pattern = Chem.MolFromSmarts('[#16]=O')
227
+ matches = mol.GetSubstructMatches(s_o_pattern)
228
+ for match in matches:
229
+ sulfur_idx = match[0]
230
+ if sulfur_idx in ring_atoms_idx:
231
+ #print(f" Found S=O bond with ring sulfur at index {sulfur_idx}")
232
+ num_MC_sulfur_O_bonds += 1
233
+ numerator = (2 * num_MC_carbons) - num_MC_carbon_H_bonds + \
234
+ (num_MC_nitrogens) - num_MC_nitrogen_H_bonds + \
235
+ num_MC_sulfur_O_bonds
236
+ denominator = (2 * num_MC_carbons) + num_MC_nitrogens + (2 * num_MC_sulfurs)
237
+ if denominator != 0:
238
+ ring_complexity = numerator / denominator
239
+ else:
240
+ ring_complexity = 0
241
+
242
+ B05_Ring_Complexity_Heteroatom.append(ring_complexity)
243
+ return B05_Ring_Complexity_Heteroatom
244
+
245
+ def get_B06_Macrocycle_Amide_Ratio(self):
246
+ B06_Macrocycle_Amide_Ratio = []
247
+ for MRS, mol in enumerate(tqdm(self.mols)):
248
+ free_amide_count = self._get_free_amide_count_for_mol(mol)
249
+ sub_amide_count = self._get_sub_amide_count_for_mol(mol)
250
+ overall_amide_count = free_amide_count + sub_amide_count
251
+ ring_size = self.ring_size[MRS]
252
+ amide_ratio = (overall_amide_count * 3 / ring_size) if ring_size > 0 else 0.0
253
+ B06_Macrocycle_Amide_Ratio.append(amide_ratio)
254
+ return B06_Macrocycle_Amide_Ratio
255
+
256
+ def get_B07_Other_Macrocycle_Count(self):
257
+ """
258
+ Calculate the number of other macrocycles (excluding the largest one).
259
+ A macrocycle is defined as a ring with 12 or more atoms.
260
+
261
+ Deduplication logic:
262
+ - Two rings are considered duplicates (same macrocycle) if they share ≥3 atoms
263
+ AND the shared atoms account for >50% of the smaller ring.
264
+ - This correctly handles cases where a bridge benzene ring is part of a macrocycle,
265
+ avoiding double counting (e.g., paths 1,2,3,4 and 1,6,5,4 in benzene).
266
+ """
267
+ B07_Other_Macrocycle_Count = []
268
+ MACROCYCLE_THRESHOLD = 12
269
+ MIN_SHARED_ATOMS = 3 # Minimum number of shared atoms to consider as duplicate
270
+ OVERLAP_RATIO_THRESHOLD = 0.5 # Shared atoms must be >50% of the smaller ring
271
+
272
+ for idx, mol in enumerate(tqdm(self.mols, desc="B07 Num Other Macrocycle")):
273
+ try:
274
+ ri = mol.GetRingInfo()
275
+ bond_rings = ri.BondRings()
276
+
277
+ if not bond_rings:
278
+ B07_Other_Macrocycle_Count.append(0)
279
+ continue
280
+
281
+ # Convert bond rings to atom rings
282
+ atom_rings = []
283
+ for bond_ring in bond_rings:
284
+ atoms_in_ring = set()
285
+ for bond_idx in bond_ring:
286
+ bond = mol.GetBondWithIdx(bond_idx)
287
+ atoms_in_ring.add(bond.GetBeginAtomIdx())
288
+ atoms_in_ring.add(bond.GetEndAtomIdx())
289
+ atom_rings.append(tuple(atoms_in_ring))
290
+
291
+ # Filter macrocycles (≥12 atoms)
292
+ macrocycles = [ring for ring in atom_rings if len(ring) >= MACROCYCLE_THRESHOLD]
293
+
294
+ if not macrocycles:
295
+ B07_Other_Macrocycle_Count.append(0)
296
+ continue
297
+
298
+ # Deduplicate macrocycles using the new logic
299
+ unique_macrocycles = []
300
+
301
+ for ring in macrocycles:
302
+ ring_set = set(ring)
303
+ is_duplicate = False
304
+
305
+ for unique_ring in unique_macrocycles:
306
+ unique_set = set(unique_ring)
307
+
308
+ # Calculate shared atoms
309
+ intersection = len(ring_set & unique_set)
310
+
311
+ # Calculate the size of the smaller ring
312
+ min_ring_size = min(len(ring_set), len(unique_set))
313
+
314
+ # Calculate overlap ratio relative to the smaller ring
315
+ overlap_ratio = intersection / min_ring_size if min_ring_size > 0 else 0
316
+
317
+ # Deduplication condition:
318
+ # shared atoms ≥ 3 AND overlap ratio > 50%
319
+ if intersection >= MIN_SHARED_ATOMS and overlap_ratio > OVERLAP_RATIO_THRESHOLD:
320
+ is_duplicate = True
321
+ break
322
+
323
+ if not is_duplicate:
324
+ unique_macrocycles.append(ring)
325
+
326
+ # Count "other" macrocycles (excluding the first/largest one)
327
+ other_macrocycles_count = max(0, len(unique_macrocycles) - 1)
328
+ B07_Other_Macrocycle_Count.append(other_macrocycles_count)
329
+
330
+ except Exception as e:
331
+ print(f"Error processing molecule {idx}: {type(e).__name__}: {e}")
332
+ B07_Other_Macrocycle_Count.append(0)
333
+
334
+ return B07_Other_Macrocycle_Count
335
+
336
+ def get_B08_Macrocycle_Exocyclic_Atom_Count(self):
337
+ """
338
+ Calculate the number of exocyclic atoms attached to the macrocycle via double or triple bonds.
339
+ """
340
+ B08_Macrocycle_Exocyclic_Atom_Count = []
341
+
342
+ for mol in tqdm(self.mols):
343
+ _, macrocycle_atoms = _get_macrocycle_ring_mol_2(mol)
344
+ macrocycle_atoms_set = set(macrocycle_atoms)
345
+
346
+ exocyclic_count = 0
347
+
348
+ for bond in mol.GetBonds():
349
+ begin_idx = bond.GetBeginAtomIdx()
350
+ end_idx = bond.GetEndAtomIdx()
351
+
352
+ # Check if the bond is a multiple bond (double or triple)
353
+ bond_type = bond.GetBondType()
354
+ if bond_type == Chem.BondType.DOUBLE or bond_type == Chem.BondType.TRIPLE:
355
+ # One atom in macrocycle, one atom outside
356
+ if (begin_idx in macrocycle_atoms_set and end_idx not in macrocycle_atoms_set):
357
+ exocyclic_count += 1
358
+ elif (end_idx in macrocycle_atoms_set and begin_idx not in macrocycle_atoms_set):
359
+ exocyclic_count += 1
360
+
361
+ B08_Macrocycle_Exocyclic_Atom_Count.append(exocyclic_count)
362
+
363
+ return B08_Macrocycle_Exocyclic_Atom_Count
@@ -0,0 +1,132 @@
1
+ """MacrocycleWizard/MolD/specific/GroupC.py"""
2
+
3
+ """
4
+ Macrocycle Heteroatom MolDs
5
+ """
6
+
7
+ from tqdm import tqdm
8
+ from rdkit import Chem
9
+ from rdkit.Chem import Descriptors
10
+ from ..base import MacrocycleCalculator
11
+ from ..base import _get_macrocycle_ring_mol_2
12
+ from rdkit.Chem.Lipinski import HeavyAtomCount
13
+
14
+ class GroupC(MacrocycleCalculator):
15
+ def _get_sub_amide_count_for_mol(self, mol):
16
+ macrocycle_mol = self.ring_mol[self.mols.index(mol)]
17
+ if macrocycle_mol is None:
18
+ return 0
19
+ sub_amide_smart = Chem.MolFromSmarts('[#6](=[#8])-[#7;H0]')
20
+ return len(macrocycle_mol.GetSubstructMatches(sub_amide_smart))
21
+
22
+ def _get_free_amide_count_for_mol(self, mol):
23
+ macrocycle_mol = self.ring_mol[self.mols.index(mol)]
24
+ if macrocycle_mol is None:
25
+ return 0
26
+ free_amide_smart = Chem.MolFromSmarts('[Nh][CX3]=[O]')
27
+ return len(macrocycle_mol.GetSubstructMatches(free_amide_smart))
28
+
29
+
30
+ def _trace_group_from_atom(self, mol, start_atom_idx, ring_atoms, max_depth=1):
31
+ group_atoms = [start_atom_idx]
32
+
33
+ start_atom = mol.GetAtomWithIdx(start_atom_idx)
34
+ for neigh in start_atom.GetNeighbors():
35
+ if neigh.GetIdx() in ring_atoms:
36
+ group_atoms.append(neigh.GetIdx())
37
+
38
+ return group_atoms
39
+
40
+ def get_C01_Ring_Heteroatom_Ratio(self):
41
+ C01_Ring_Heteroatom_Ratio = []
42
+ for ring_mol,ring_size in tqdm(zip(self.ring_mol_stripped, self.ring_size)):
43
+ if ring_mol is None or ring_size <= 0:
44
+ C01_Ring_Heteroatom_Ratio.append(0.0)
45
+ continue
46
+ hetero_atmo = Chem.rdMolDescriptors.CalcNumHeteroatoms(ring_mol)
47
+ hetero_atmo_normalised = hetero_atmo/ring_size
48
+ C01_Ring_Heteroatom_Ratio.append(hetero_atmo_normalised)
49
+ return C01_Ring_Heteroatom_Ratio
50
+
51
+ def get_C02_Ring_Oxygen_Ratio(self):
52
+ """The ratio of oxygen atoms in the macrocycle ring to ring size in the molecule"""
53
+ C02_Ring_Oxygen_Ratio = []
54
+ for ring_mol, ring_size in tqdm(zip(self.ring_mol_stripped, self.ring_size)):
55
+ if ring_mol is None or ring_size <= 0:
56
+ C02_Ring_Oxygen_Ratio.append(0.0)
57
+ continue
58
+ atoms = ring_mol.GetAtoms()
59
+ Ring_Oxygen = sum(1 for atom in atoms if atom.GetAtomicNum() == 8) # 8是氧的原子序数
60
+ oxygen_normalised = Ring_Oxygen / ring_size
61
+ C02_Ring_Oxygen_Ratio.append(oxygen_normalised)
62
+ return C02_Ring_Oxygen_Ratio
63
+
64
+ def get_C03_Ring_Nitrogen_Ratio(self):
65
+ """The ratio of nitrogen atoms in the macrocycle ring to ring size in the molecule"""
66
+ C03_Ring_Nitrogen_Ratio = []
67
+ for ring_mol, ring_size in tqdm(zip(self.ring_mol_stripped, self.ring_size)):
68
+ if ring_mol is None or ring_size <= 0:
69
+ C03_Ring_Nitrogen_Ratio.append(0.0)
70
+ continue
71
+ atoms = ring_mol.GetAtoms()
72
+ Ring_Nitrogen = sum(1 for atom in atoms if atom.GetAtomicNum() == 7) # 7是氮的原子序数
73
+ nitrogen_normalised = Ring_Nitrogen / ring_size
74
+ C03_Ring_Nitrogen_Ratio.append(nitrogen_normalised)
75
+ return C03_Ring_Nitrogen_Ratio
76
+
77
+ def get_C04_Ring_Sulfur_Ratio(self):
78
+ """The ratio of sulfur atoms in the macrocycle ring to ring size in the molecule"""
79
+ C04_Ring_Sulfur_Ratio = []
80
+ for ring_mol, ring_size in tqdm(zip(self.ring_mol_stripped, self.ring_size)):
81
+ if ring_mol is None or ring_size <= 0:
82
+ C04_Ring_Sulfur_Ratio.append(0.0)
83
+ continue
84
+ atoms = ring_mol.GetAtoms()
85
+ Ring_Sulfur = sum(1 for atom in atoms if atom.GetAtomicNum() == 16) # 16是硫的原子序数
86
+ sulfur_normalised = Ring_Sulfur / ring_size
87
+ C04_Ring_Sulfur_Ratio.append(sulfur_normalised)
88
+ return C04_Ring_Sulfur_Ratio
89
+
90
+ def get_C05_Ring_Nitrogen_to_Oxygen_Ratio(self):
91
+ """Calculate the ratio of N atoms in ring over O atoms in Ring"""
92
+ C05_Ring_Nitrogen_to_Oxygen_Ratio = []
93
+ for ring_mol in tqdm(self.ring_mol_stripped):
94
+ if ring_mol is None:
95
+ C05_Ring_Nitrogen_to_Oxygen_Ratio.append(1.0)
96
+ continue
97
+ atoms = ring_mol.GetAtoms()
98
+ Ring_Nitrogen = sum(1 for atom in atoms if atom.GetAtomicNum() == 7) # 7是氮的原子序数
99
+ Ring_Oxygen = sum(1 for atom in atoms if atom.GetAtomicNum() == 8) # 8是氧的原子序数
100
+ nitrogen_over_oxygen = (Ring_Nitrogen + 1) / (Ring_Oxygen + 1)
101
+ C05_Ring_Nitrogen_to_Oxygen_Ratio.append(nitrogen_over_oxygen)
102
+ return C05_Ring_Nitrogen_to_Oxygen_Ratio
103
+
104
+ def get_C06_Free_Amide_Count(self):
105
+ C06_Free_Amide_Count = []
106
+ for mol in tqdm(self.mols):
107
+ C06_Free_Amide_Count.append(self._get_free_amide_count_for_mol(mol))
108
+ return C06_Free_Amide_Count
109
+
110
+ def get_C07_Substituent_Amide_Count(self):
111
+ C07_Substituent_Amide_Count = []
112
+ for mol in tqdm(self.mols):
113
+ C07_Substituent_Amide_Count.append(self._get_sub_amide_count_for_mol(mol))
114
+ return C07_Substituent_Amide_Count
115
+
116
+ def get_C08_Overall_Amide_Count(self):
117
+ C08_Overall_Amide_Count = []
118
+ for mol in tqdm(self.mols):
119
+ free_amide_count = self._get_free_amide_count_for_mol(mol)
120
+ sub_amide_count = self._get_sub_amide_count_for_mol(mol)
121
+ overall_amide_count = free_amide_count + sub_amide_count
122
+ C08_Overall_Amide_Count.append(overall_amide_count)
123
+ return C08_Overall_Amide_Count
124
+
125
+ def get_C09_Macrocycle_Free_Amide_Ratio(self):
126
+ C09_Macrocycle_Free_Amide_Ratio = []
127
+ for MRS, mol in enumerate(tqdm(self.mols)):
128
+ free_amide_count = self._get_free_amide_count_for_mol(mol)
129
+ ring_size = self.ring_size[MRS] # 直接使用预计算的 ring_size
130
+ free_amide_ratio = (free_amide_count * 3 / ring_size) if ring_size > 0 else 0.0
131
+ C09_Macrocycle_Free_Amide_Ratio.append(free_amide_ratio)
132
+ return C09_Macrocycle_Free_Amide_Ratio