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,211 @@
1
+ """Calculator.py"""
2
+ import pandas as pd
3
+ from tqdm import tqdm
4
+
5
+ # 使用相对导入
6
+ from .basic.GroupA import GroupA
7
+ from .specific.GroupB import GroupB
8
+ from .specific.GroupC import GroupC
9
+ from .specific.GroupD import GroupD
10
+ from .specific.GroupE import GroupE
11
+ from .specific.GroupF import GroupF
12
+ from .specific.GroupG import GroupG
13
+ from .general.GroupH import GroupH
14
+ from .general.GroupI import GroupI
15
+ from .general.GroupJ import GroupJ
16
+ from .general.GroupK import GroupK
17
+
18
+
19
+
20
+ class MolCalculator:
21
+ def __init__(self, smiles_list):
22
+ self.groupa = GroupA(smiles_list)
23
+ self.groupb = GroupB(smiles_list)
24
+ self.groupc = GroupC(smiles_list)
25
+ self.groupd = GroupD(smiles_list)
26
+ self.groupe = GroupE(smiles_list)
27
+ self.groupf = GroupF(smiles_list)
28
+ self.groupg = GroupG(smiles_list)
29
+ self.grouph = GroupH(smiles_list)
30
+ self.groupi = GroupI(smiles_list)
31
+ self.groupj = GroupJ(smiles_list)
32
+ self.groupk = GroupK(smiles_list)
33
+
34
+ def calculate_all(self):
35
+ result_df = pd.DataFrame({
36
+
37
+ "A01_Molecular_Weight": self.groupa.get_A01_Molecular_Weight(),
38
+ "A02_cLogP": self.groupa.get_A02_cLogP(),
39
+ "A03_Hydrogen_Bond_Donor_Count": self.groupa.get_A03_Hydrogen_Bond_Donor_Count(),
40
+ "A04_Hydrogen_Bond_Acceptor_Count": self.groupa.get_A04_Hydrogen_Bond_Acceptor_Count(),
41
+ "A05_TPSA": self.groupa.get_A05_TPSA(),
42
+ "A06_Rotatable_Bond_Count": self.groupa.get_A06_Rotatable_Bond_Count(),
43
+ "A07_Macrocycle_Ring_Size": self.groupa.get_A07_Macrocycle_Ring_Size(),
44
+ "A08_Kier_Index": self.groupa.get_A08_Kier_Index(),
45
+
46
+ "B01_Normalised_Ring_Ratio": self.groupb.get_B01_Normalised_Ring_Ratio(),
47
+ "B02_Macrocycle_Fsp3_Ratio": self.groupb.get_B02_Macrocycle_Fsp3_Ratio(),
48
+ "B03_Ring_Chiral_Centre_Normalised": self.groupb.get_B03_Ring_Chiral_Centre_Normalised(),
49
+ "B04_Ring_Complexity_Carbon": self.groupb.get_B04_Ring_Complexity_Carbon(),
50
+ "B05_Ring_Complexity_Heteroatom": self.groupb.get_B05_Ring_Complexity_Heteroatom(),
51
+ "B06_Macrocycle_Amide_Ratio": self.groupb.get_B06_Macrocycle_Amide_Ratio(),
52
+ "B07_Other_Macrocycle_Count": self.groupb.get_B07_Other_Macrocycle_Count(),
53
+ "B08_Macrocycle_Exocyclic_Atom_Count": self.groupb.get_B08_Macrocycle_Exocyclic_Atom_Count(),
54
+
55
+ "C01_Ring_Heteroatom_Ratio": self.groupc.get_C01_Ring_Heteroatom_Ratio(),
56
+ "C02_Ring_Oxygen_Ratio": self.groupc.get_C02_Ring_Oxygen_Ratio(),
57
+ "C03_Ring_Nitrogen_Ratio": self.groupc.get_C03_Ring_Nitrogen_Ratio(),
58
+ "C04_Ring_Sulfur_Ratio": self.groupc.get_C04_Ring_Sulfur_Ratio(),
59
+ "C05_Ring_Nitrogen_to_Oxygen_Ratio": self.groupc.get_C05_Ring_Nitrogen_to_Oxygen_Ratio(),
60
+ "C06_Free_Amide_Count": self.groupc.get_C06_Free_Amide_Count(),
61
+ "C07_Substituent_Amide_Count": self.groupc.get_C07_Substituent_Amide_Count(),
62
+ "C08_Overall_Amide_Count": self.groupc.get_C08_Overall_Amide_Count(),
63
+ "C09_Macrocycle_Free_Amide_Ratio": self.groupc.get_C09_Macrocycle_Free_Amide_Ratio(),
64
+
65
+
66
+
67
+ "D01_Substituent_Fsp3_Ratio": self.groupd.get_D01_Substituent_Fsp3_Ratio(),
68
+ "D02_Substituent_Flexibility_Ratio": self.groupd.get_D02_Substituent_Flexibility_Ratio(),
69
+ "D03_Fragment_Rigid_Bond": self.groupd.get_D03_Fragment_Rigid_Bond(),
70
+ "D04_Large_Substituent_Count": self.groupd.get_D04_Large_Substituent_Count(),
71
+ "D05_Small_Substituent_Count": self.groupd.get_D05_Small_Substituent_Count(),
72
+ "D06_Normalised_Substituent_Heavy_Atom": self.groupd.get_D06_Normalised_Substituent_Heavy_Atom(),
73
+ "D07_Normalised_Substituent_to_Macrocycle_Ring_Size": self.groupd.get_D07_Normalised_Substituent_to_Macrocycle_Ring_Size(),
74
+ "D08_Normalised_Peripheral_to_Macrocycle_Ring_Size": self.groupd.get_D08_Normalised_Peripheral_to_Macrocycle_Ring_Size(),
75
+ "D09_Max_Substituent_Size": self.groupd.get_D09_Max_Substituent_Size(),
76
+ "D10_Min_Substituent_Size": self.groupd.get_D10_Min_Substituent_Size(),
77
+ "D11_Mean_Substituent_Size": self.groupd.get_D11_Mean_Substituent_Size(),
78
+ "D12_Substituent_Size_Standard_Deviation": self.groupd.get_D12_Substituent_Size_Standard_Deviation(),
79
+ "D13_Substituent_Size_Coefficient_of_Variation": self.groupd.get_D13_Substituent_Size_Coefficient_of_Variation(),
80
+ "D14_Max_Pair_Spacing": self.groupd.get_D14_Max_Pair_Spacing(),
81
+ "D15_Min_Pair_Spacing": self.groupd.get_D15_Min_Pair_Spacing(),
82
+ "D16_Mean_Pair_Spacing": self.groupd.get_D16_Mean_Pair_Spacing(),
83
+ "D17_Pair_Spacing_Standard_Deviation": self.groupd.get_D17_Pair_Spacing_Standard_Deviation(),
84
+ "D18_Pair_Spacing_Coefficient_of_Variation": self.groupd.get_D18_Pair_Spacing_Coefficient_of_Variation(),
85
+
86
+
87
+ "E01_Substituent_Heteroatom_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E01_Substituent_Heteroatom_to_Substituent_Heavy_Atom_Ratio(),
88
+ "E02_Peripheral_Heteroatom_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E02_Peripheral_Heteroatom_to_Peripheral_Heavy_Atom_Ratio(),
89
+ "E03_Substituent_N_to_O_Ratio": self.groupe.get_E03_Substituent_N_to_O_Ratio(),
90
+ "E04_Peripheral_N_to_O_Ratio": self.groupe.get_E04_Peripheral_N_to_O_Ratio(),
91
+ "E05_Substituent_O_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E05_Substituent_O_to_Substituent_Heavy_Atom_Ratio(),
92
+ "E06_Peripheral_O_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E06_Peripheral_O_to_Peripheral_Heavy_Atom_Ratio(),
93
+ "E07_Substituent_N_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E07_Substituent_N_to_Substituent_Heavy_Atom_Ratio(),
94
+ "E08_Peripheral_N_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E08_Peripheral_N_to_Peripheral_Heavy_Atom_Ratio(),
95
+ "E09_Substituent_P_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E09_Substituent_P_to_Substituent_Heavy_Atom_Ratio(),
96
+ "E10_Peripheral_P_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E10_Peripheral_P_to_Peripheral_Heavy_Atom_Ratio(),
97
+ "E11_Substituent_S_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E11_Substituent_S_to_Substituent_Heavy_Atom_Ratio(),
98
+ "E12_Peripheral_S_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E12_Peripheral_S_to_Peripheral_Heavy_Atom_Ratio(),
99
+ "E13_Substituent_F_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E13_Substituent_F_to_Substituent_Heavy_Atom_Ratio(),
100
+ "E14_Peripheral_F_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E14_Peripheral_F_to_Peripheral_Heavy_Atom_Ratio(),
101
+ "E15_Substituent_Cl_to_Substituent_Heavy_Atom_Ratio": self.groupe.get_E15_Substituent_Cl_to_Substituent_Heavy_Atom_Ratio(),
102
+ "E16_Peripheral_Cl_to_Peripheral_Heavy_Atom_Ratio": self.groupe.get_E16_Peripheral_Cl_to_Peripheral_Heavy_Atom_Ratio(),
103
+
104
+
105
+
106
+ "F01_Spiro_Atom_in_Macrocycle_Ring_Ratio": self.groupf.get_F01_Spiro_Atom_in_Macrocycle_Ring_Ratio(),
107
+ "F02_Fused_Bond_in_Macrocycle_Ring_Ratio": self.groupf.get_F02_Fused_Bond_in_Macrocycle_Ring_Ratio(),
108
+ "F03_Bridgehead_Atom_in_Macrocycle_Ring_Ratio": self.groupf.get_F03_Bridgehead_Atom_in_Macrocycle_Ring_Ratio(),
109
+ "F04_Bridge_Ring_in_Macrocycle_Ring_Ratio": self.groupf.get_F04_Bridge_Ring_in_Macrocycle_Ring_Ratio(),
110
+ "F05_Bridge_Atom_in_Macrocycle_Ring_Ratio": self.groupf.get_F05_Bridge_Atom_in_Macrocycle_Ring_Ratio(),
111
+ "F06_Restricted_Bond_in_Macrocycle_Ring_Ratio": self.groupf.get_F06_Restricted_Bond_in_Macrocycle_Ring_Ratio(),
112
+
113
+ "G01_Weiner_Ring": self.groupg.get_G01_Weiner_Ring(),
114
+ "G02_Harary_Ring": self.groupg.get_G02_Harary_Ring(),
115
+ "G03_Balaban_Ring": self.groupg.get_G03_Balaban_Ring(),
116
+ "G04_BertzCT_Ring": self.groupg.get_G04_BertzCT_Ring(),
117
+ "G05_Xu_Ring": self.groupg.get_G05_Xu_Ring(),
118
+
119
+ "H01_Heavy_Atom_Count": self.grouph.get_H01_Heavy_Atom_Count(),
120
+ "H02_Carbon_Atom_Count": self.grouph.get_H02_Carbon_Atom_Count(),
121
+ "H03_Exocyclic_Atom_Count": self.grouph.get_H03_Exocyclic_Atom_Count(),
122
+ "H04_Atom_with_at_Least_Two_Connected_Atoms_Having_More_than_Two_Connections_Count": self.grouph.get_H04_Atom_with_at_Least_Two_Connected_Atoms_Having_More_than_Two_Connections_Count(),
123
+ "H05_Atom_in_Conjugated_Ring_Count": self.grouph.get_H05_Atom_in_Conjugated_Ring_Count(),
124
+ "H06_Bond_Count": self.grouph.get_H06_Bond_Count(),
125
+ "H07_Bond_with_at_Least_Three_Connections_on_Both_Atoms_Count": self.grouph.get_H07_Bond_with_at_Least_Three_Connections_on_Both_Atoms_Count(),
126
+ "H08_Ring_Count": self.grouph.get_H08_Ring_Count(),
127
+ "H09_Aromatic_Ring_Count": self.grouph.get_H09_Aromatic_Ring_Count(),
128
+ "H10_Hetero_Ring_Count": self.grouph.get_H10_Hetero_Ring_Count(),
129
+ "H11_Simple_Ring_Count": self.grouph.get_H11_Simple_Ring_Count(),
130
+ "H12_Ring_System_Count": self.grouph.get_H12_Ring_System_Count(),
131
+ "H13_Charged_Atom_Count": self.grouph.get_H13_Charged_Atom_Count(),
132
+ "H14_Net_Charge": self.grouph.get_H14_Net_Charge(),
133
+ "H15_Carbon_SP3_Hybridisation_Ratio": self.grouph.get_H15_Carbon_SP3_Hybridisation_Ratio(),
134
+ "H16_Chiral_Centre_to_Heavy_Atom_Ratio": self.grouph.get_H16_Chiral_Centre_to_Heavy_Atom_Ratio(),
135
+ "H17_Degree_of_Unsaturation_Index": self.grouph.get_H17_Degree_of_Unsaturation_Index(),
136
+ "H18_Hydrophilic_Index": self.grouph.get_H18_Hydrophilic_Index(),
137
+
138
+
139
+
140
+ "I01_Heteroatom_to_Heavy_Atom_Ratio": self.groupi.get_I01_Heteroatom_to_Heavy_Atom_Ratio(),
141
+ "I02_Total_N_to_O_Ratio": self.groupi.get_I02_Total_N_to_O_Ratio(),
142
+ "I03_Total_Oxygen_to_Heavy_Atom_Ratio": self.groupi.get_I03_Total_Oxygen_to_Heavy_Atom_Ratio(),
143
+ "I04_Total_Nitrogen_to_Heavy_Atom_Ratio": self.groupi.get_I04_Total_Nitrogen_to_Heavy_Atom_Ratio(),
144
+ "I05_Total_Sulfur_to_Heavy_Atom_Ratio": self.groupi.get_I05_Total_Sulfur_to_Heavy_Atom_Ratio(),
145
+ "I06_Total_Phosphorus_to_Heavy_Atom_Ratio": self.groupi.get_I06_Total_Phosphorus_to_Heavy_Atom_Ratio(),
146
+ "I07_Other_Heteroatom_to_Heavy_Atom_Ratio": self.groupi.get_I07_Other_Heteroatom_to_Heavy_Atom_Ratio(),
147
+ "I08_Heteroatom_with_More_than_Two_Connections_Count": self.groupi.get_I08_Heteroatom_with_More_than_Two_Connections_Count(),
148
+ "I09_Carbon_Atom_Connected_to_at_Least_Two_Heteroatoms_Count": self.groupi.get_I09_Carbon_Atom_Connected_to_at_Least_Two_Heteroatoms_Count(),
149
+ "I10_Bond_Connecting_Two_Heteroatoms_Count": self.groupi.get_I10_Bond_Connecting_Two_Heteroatoms_Count(),
150
+ "I11_Carbon_Carbon_Bond_Each_Carbon_with_Heteroatom_Count": self.groupi.get_I11_Carbon_Carbon_Bond_Each_Carbon_with_Heteroatom_Count(),
151
+
152
+
153
+ "J01_PAINS_Count": self.groupj.get_J01_PAINS_Count(),
154
+ "J02_Brenk_Count": self.groupj.get_J02_Brenk_Count(),
155
+ "J03_NIH_Count": self.groupj.get_J03_NIH_Count(),
156
+ "J04_Alkyl_Group_Count": self.groupj.get_J04_Alkyl_Group_Count(),
157
+ "J05_Ether_Count": self.groupj.get_J05_Ether_Count(),
158
+ "J06_Tertiary_Amine_Count": self.groupj.get_J06_Tertiary_Amine_Count(),
159
+ "J07_Secondary_Amine_Count": self.groupj.get_J07_Secondary_Amine_Count(),
160
+ "J08_Aliphatic_Alcohol_Count": self.groupj.get_J08_Aliphatic_Alcohol_Count(),
161
+ "J09_Carboxylic_Acid_Count": self.groupj.get_J09_Carboxylic_Acid_Count(),
162
+ "J10_Aromatic_Carbonyl_Count": self.groupj.get_J10_Aromatic_Carbonyl_Count(),
163
+ "J11_Aromatic_Hydroxyl_Count": self.groupj.get_J11_Aromatic_Hydroxyl_Count(),
164
+ "J12_Sulfonamide_Count": self.groupj.get_J12_Sulfonamide_Count(),
165
+ "J13_Aromatic_Amine_Count": self.groupj.get_J13_Aromatic_Amine_Count(),
166
+ "J14_Aliphatic_Amine_Count": self.groupj.get_J14_Aliphatic_Amine_Count(),
167
+ "J15_Ester_Count": self.groupj.get_J15_Ester_Count(),
168
+ "J16_Alkene_Count": self.groupj.get_J16_Alkene_Count(),
169
+ "J17_Ketone_Count": self.groupj.get_J17_Ketone_Count(),
170
+ "J18_Urea_Count": self.groupj.get_J18_Urea_Count(),
171
+ "J19_Thioether_Count": self.groupj.get_J19_Thioether_Count(),
172
+ "J20_Nitrile_Count": self.groupj.get_J20_Nitrile_Count(),
173
+ "J21_Carbamate_Count": self.groupj.get_J21_Carbamate_Count(),
174
+ "J22_Sulfone_Count": self.groupj.get_J22_Sulfone_Count(),
175
+ "J23_Guanidine_Count": self.groupj.get_J23_Guanidine_Count(),
176
+ "J24_Pyranose_Count": self.groupj.get_J24_Pyranose_Count(),
177
+ "J25_Benzene_Count": self.groupj.get_J25_Benzene_Count(),
178
+ "J26_Pyridine_Count": self.groupj.get_J26_Pyridine_Count(),
179
+ "J27_Piperidine_Count": self.groupj.get_J27_Piperidine_Count(),
180
+ "J28_Piperazine_Count": self.groupj.get_J28_Piperazine_Count(),
181
+ "J29_Indole_Count": self.groupj.get_J29_Indole_Count(),
182
+ "J30_Pyrrolidine_Count": self.groupj.get_J30_Pyrrolidine_Count(),
183
+ "J31_Pyridazine_Count": self.groupj.get_J31_Pyridazine_Count(),
184
+ "J32_Imidazole_Count": self.groupj.get_J32_Imidazole_Count(),
185
+ "J33_Cyclohexane_Count": self.groupj.get_J33_Cyclohexane_Count(),
186
+ "J34_Pyrazole_Count": self.groupj.get_J34_Pyrazole_Count(),
187
+ "J35_Cyclopropane_Count": self.groupj.get_J35_Cyclopropane_Count(),
188
+ "J36_Quinoline_Count": self.groupj.get_J36_Quinoline_Count(),
189
+ "J37_Thiazole_Count": self.groupj.get_J37_Thiazole_Count(),
190
+ "J38_Naphthalene_Count": self.groupj.get_J38_Naphthalene_Count(),
191
+ "J39_Morpholine_Count": self.groupj.get_J39_Morpholine_Count(),
192
+ "J40_Thiophene_Count": self.groupj.get_J40_Thiophene_Count(),
193
+ "J41_Tetrahydropyran_Count": self.groupj.get_J41_Tetrahydropyran_Count(),
194
+ "J42_Benzimidazole_Count": self.groupj.get_J42_Benzimidazole_Count(),
195
+ "J43_Triazole_124_Count": self.groupj.get_J43_Triazole_124_Count(),
196
+ "J44_Tetrahydrofuran_Count": self.groupj.get_J44_Tetrahydrofuran_Count(),
197
+
198
+ "K01_Weiner": self.groupk.get_K01_Weiner(),
199
+ "K02_Harary": self.groupk.get_K02_Harary(),
200
+ "K03_Balaban": self.groupk.get_K03_Balaban(),
201
+ "K04_BertzCT": self.groupk.get_K04_BertzCT(),
202
+ "K05_Xu": self.groupk.get_K05_Xu(),
203
+ "K06_Petitjean": self.groupk.get_K06_Petitjean(),
204
+ "K07_Zagreb1": self.groupk.get_K07_Zagreb1(),
205
+ "K08_Zagreb2": self.groupk.get_K08_Zagreb2(),
206
+
207
+ }
208
+
209
+ )
210
+ return result_df
211
+
@@ -0,0 +1,458 @@
1
+ """MacrocycleWizard/MolD/general/GroupH.py"""
2
+
3
+ """
4
+ Group H: Other general MolD for Overall Macrocycle Molecules
5
+ """
6
+
7
+ from tqdm import tqdm
8
+ from rdkit import Chem
9
+ from rdkit.Chem import rdmolops, Descriptors, rdMolDescriptors
10
+ from PyBioMed.PyMolecule import molproperty
11
+
12
+ from ..base import MacrocycleCalculator
13
+
14
+ class GroupH(MacrocycleCalculator):
15
+ @staticmethod
16
+ def _get_exocyclic_atoms_for_ring(mol, ring):
17
+ """
18
+ Get exocyclic atoms connected to a specific ring by multiple bonds.
19
+ The outside atom is defined relative to this ring, not relative to
20
+ the union of all ring atoms in the molecule.
21
+ """
22
+ ring_set = set(ring)
23
+ exocyclic_atoms = set()
24
+
25
+ for bond in mol.GetBonds():
26
+ bond_type = bond.GetBondType()
27
+ if bond_type not in (Chem.BondType.DOUBLE, Chem.BondType.TRIPLE):
28
+ continue
29
+
30
+ begin_idx = bond.GetBeginAtomIdx()
31
+ end_idx = bond.GetEndAtomIdx()
32
+
33
+ if begin_idx in ring_set and end_idx not in ring_set:
34
+ exocyclic_atoms.add(end_idx)
35
+ elif end_idx in ring_set and begin_idx not in ring_set:
36
+ exocyclic_atoms.add(begin_idx)
37
+
38
+ return exocyclic_atoms
39
+
40
+ @staticmethod
41
+ def _ring_has_exocyclic_atom(mol, ring):
42
+ """
43
+ Check whether a specific ring has at least one exocyclic atom connected
44
+ to the ring by a multiple bond.
45
+ """
46
+ return len(GroupH._get_exocyclic_atoms_for_ring(mol, ring)) > 0
47
+
48
+ @staticmethod
49
+ def _ring_is_conjugated(mol, ring):
50
+ """
51
+ A conjugated ring is defined here as:
52
+ 1. an aromatic ring; or
53
+ 2. a ring in which all ring bonds are marked as conjugated by RDKit.
54
+
55
+ This avoids treating a ring with only one isolated double bond as a
56
+ conjugated ring.
57
+ """
58
+ is_aromatic = all(mol.GetAtomWithIdx(idx).GetIsAromatic() for idx in ring)
59
+ if is_aromatic:
60
+ return True
61
+
62
+ ring_bonds = []
63
+ for i in range(len(ring)):
64
+ atom1_idx = ring[i]
65
+ atom2_idx = ring[(i + 1) % len(ring)]
66
+ bond = mol.GetBondBetweenAtoms(atom1_idx, atom2_idx)
67
+ if bond is None:
68
+ return False
69
+ ring_bonds.append(bond)
70
+
71
+ return all(bond.GetIsConjugated() for bond in ring_bonds)
72
+
73
+ def get_H01_Heavy_Atom_Count(self):
74
+ return self.HA
75
+
76
+ def get_H02_Carbon_Atom_Count(self):
77
+ H02_Carbon_Atom_Count = []
78
+ for mol in tqdm(self.mols):
79
+ carbon_atom_count = sum(1 for atom in mol.GetAtoms() if atom.GetSymbol() == 'C')
80
+ H02_Carbon_Atom_Count.append(carbon_atom_count)
81
+ return H02_Carbon_Atom_Count
82
+
83
+ def get_H03_Exocyclic_Atom_Count(self):
84
+ """
85
+ Count exocyclic atoms connected to rings by multiple bonds.
86
+ Exocyclic atoms are identified relative to each individual ring, not
87
+ relative to the union of all ring atoms in the molecule.
88
+ """
89
+ H03_Exocyclic_Atom_Count = []
90
+ for mol in tqdm(self.mols):
91
+ ring_info = mol.GetRingInfo()
92
+
93
+ exocyclic_atoms = set()
94
+ for ring in ring_info.AtomRings():
95
+ exocyclic_atoms.update(self._get_exocyclic_atoms_for_ring(mol, ring))
96
+
97
+ H03_Exocyclic_Atom_Count.append(len(exocyclic_atoms))
98
+
99
+ return H03_Exocyclic_Atom_Count
100
+
101
+ def get_H04_Atom_with_at_Least_Two_Connected_Atoms_Having_More_than_Two_Connections_Count(self):
102
+ """
103
+ Count atoms which at least two connected atoms have more than two connections
104
+ Single:1, Double:2, Triple:3,aromatic:1.5
105
+ """
106
+ H04_Atom_with_at_Least_Two_Connected_Atoms_Having_More_than_Two_Connections_Count = []
107
+ for mol in tqdm(self.mols):
108
+ count = 0
109
+ for atom in mol.GetAtoms():
110
+ # Get neighbor atoms
111
+ neighbors = atom.GetNeighbors()
112
+
113
+ # Count how many neighbors have more than 2 connections
114
+ branched_neighbors = 0
115
+ for neighbor in neighbors:
116
+ # Calculate total connections for this neighbor
117
+ total_connections = 0
118
+ for bond in neighbor.GetBonds():
119
+ bond_type = bond.GetBondType()
120
+ if bond_type == Chem.BondType.SINGLE:
121
+ total_connections += 1
122
+ elif bond_type == Chem.BondType.DOUBLE:
123
+ total_connections += 2
124
+ elif bond_type == Chem.BondType.TRIPLE:
125
+ total_connections += 3
126
+ elif bond_type == Chem.BondType.AROMATIC:
127
+ total_connections += 1.5
128
+
129
+ if total_connections > 2:
130
+ branched_neighbors += 1
131
+
132
+ # Check if at least 2 neighbors have more than 2 connections
133
+ if branched_neighbors >= 2:
134
+ count += 1
135
+
136
+ H04_Atom_with_at_Least_Two_Connected_Atoms_Having_More_than_Two_Connections_Count.append(count)
137
+
138
+ return H04_Atom_with_at_Least_Two_Connected_Atoms_Having_More_than_Two_Connections_Count
139
+
140
+
141
+ def get_H05_Atom_in_Conjugated_Ring_Count(self):
142
+ """
143
+ Count atoms in conjugated rings.
144
+ Here, a conjugated ring is defined as an aromatic ring or a ring in
145
+ which all ring bonds are conjugated according to RDKit. A ring with
146
+ only one isolated double bond is not counted as a conjugated ring.
147
+ """
148
+ H05_Atom_in_Conjugated_Ring_Count = []
149
+ for mol in tqdm(self.mols):
150
+ conjugated_atoms = set()
151
+ ring_info = mol.GetRingInfo()
152
+
153
+ for ring in ring_info.AtomRings():
154
+ if self._ring_is_conjugated(mol, ring):
155
+ conjugated_atoms.update(ring)
156
+
157
+ H05_Atom_in_Conjugated_Ring_Count.append(len(conjugated_atoms))
158
+
159
+ return H05_Atom_in_Conjugated_Ring_Count
160
+
161
+ def get_H06_Bond_Count(self):
162
+ H06_Bond_Count = []
163
+ for mol in tqdm(self.mols):
164
+ num_bonds = mol.GetNumBonds()
165
+ H06_Bond_Count.append(num_bonds)
166
+ return H06_Bond_Count
167
+
168
+ def get_H07_Bond_with_at_Least_Three_Connections_on_Both_Atoms_Count(self):
169
+ """
170
+ Count bonds where both atoms have at least three connections
171
+ Single:1, Double:2, Triple:3,aromatic:1.5
172
+ """
173
+ H07_Bond_with_at_Least_Three_Connections_on_Both_Atoms_Count = []
174
+ for mol in tqdm(self.mols):
175
+ count = 0
176
+ for bond in mol.GetBonds():
177
+ begin_atom = bond.GetBeginAtom()
178
+ end_atom = bond.GetEndAtom()
179
+
180
+ def total_connections(atom):
181
+ connections = 0
182
+ for b in atom.GetBonds():
183
+ bond_type = b.GetBondType()
184
+ if bond_type == Chem.BondType.SINGLE:
185
+ connections += 1
186
+ elif bond_type == Chem.BondType.DOUBLE:
187
+ connections += 2
188
+ elif bond_type == Chem.BondType.TRIPLE:
189
+ connections += 3
190
+ elif bond_type == Chem.BondType.AROMATIC:
191
+ connections += 1.5
192
+ return connections
193
+
194
+ if total_connections(begin_atom) >= 3 and total_connections(end_atom) >= 3:
195
+ count += 1
196
+
197
+ H07_Bond_with_at_Least_Three_Connections_on_Both_Atoms_Count.append(count)
198
+
199
+ return H07_Bond_with_at_Least_Three_Connections_on_Both_Atoms_Count
200
+
201
+
202
+ def get_H08_Ring_Count(self):
203
+ H08_Ring_Count = []
204
+ for mol in tqdm(self.mols):
205
+ num_ring = mol.GetRingInfo().NumRings()
206
+ H08_Ring_Count.append(num_ring)
207
+ return H08_Ring_Count
208
+
209
+ def get_H09_Aromatic_Ring_Count(self):
210
+ """
211
+ Count aromatic rings in each molecule
212
+ Returns:
213
+ list: List of aromatic ring counts for each molecule
214
+ """
215
+ H09_Aromatic_Ring_Count = []
216
+ for mol in tqdm(self.mols):
217
+ # Find rings where all atoms are aromatic
218
+ aromatic_rings = [ring for ring in mol.GetRingInfo().AtomRings()
219
+ if all(mol.GetAtomWithIdx(idx).GetIsAromatic() for idx in ring)]
220
+ # Count the rings for this specific molecule
221
+ H09_Aromatic_Ring_Count.append(len(aromatic_rings))
222
+ return H09_Aromatic_Ring_Count
223
+
224
+ def get_H10_Hetero_Ring_Count(self):
225
+ """
226
+ Count hetero rings in each molecule
227
+ Hetero rings are rings containing at least one heteroatom (non-carbon, non-hydrogen)
228
+ Returns:
229
+ list: List of hetero ring counts for each molecule
230
+ """
231
+ H10_Hetero_Ring_Count = []
232
+ for mol in tqdm(self.mols):
233
+ hetero_ring_count = 0
234
+ # Get all rings in the molecule
235
+ rings = mol.GetRingInfo().AtomRings()
236
+
237
+ for ring in rings:
238
+ # Check if ring contains at least one heteroatom
239
+ has_hetero = any(mol.GetAtomWithIdx(idx).GetSymbol() not in ['C', 'H']
240
+ for idx in ring)
241
+ if has_hetero:
242
+ hetero_ring_count += 1
243
+
244
+ H10_Hetero_Ring_Count.append(hetero_ring_count)
245
+
246
+ return H10_Hetero_Ring_Count
247
+
248
+ def get_H11_Simple_Ring_Count(self):
249
+ """
250
+ A simple ring is a 1 ring without any exocyclic atoms, nor any fused or bridged rings.
251
+ """
252
+ H11_Simple_Ring_Count = []
253
+ for mol in tqdm(self.mols):
254
+ ring_info = mol.GetRingInfo()
255
+ atom_rings = ring_info.AtomRings()
256
+
257
+ simple_ring_count = 0
258
+
259
+ for ring in atom_rings:
260
+ ring_set = set(ring)
261
+ is_simple = True
262
+
263
+ # Check if this ring shares atoms with other rings (fused/bridged)
264
+ for other_ring in atom_rings:
265
+ if ring == other_ring:
266
+ continue
267
+ other_ring_set = set(other_ring)
268
+ if ring_set & other_ring_set: # If there's any shared atoms
269
+ is_simple = False
270
+ break
271
+
272
+ if not is_simple:
273
+ continue
274
+
275
+ # Check for exocyclic atoms (atoms connected by multiple bonds to ring atoms)
276
+ for bond in mol.GetBonds():
277
+ begin_idx = bond.GetBeginAtomIdx()
278
+ end_idx = bond.GetEndAtomIdx()
279
+ bond_type = bond.GetBondType()
280
+
281
+ if bond_type == Chem.BondType.DOUBLE or bond_type == Chem.BondType.TRIPLE:
282
+ # One atom in ring, one atom outside
283
+ if (begin_idx in ring_set and end_idx not in ring_set):
284
+ is_simple = False
285
+ break
286
+ elif (end_idx in ring_set and begin_idx not in ring_set):
287
+ is_simple = False
288
+ break
289
+
290
+ if is_simple:
291
+ simple_ring_count += 1
292
+
293
+ H11_Simple_Ring_Count.append(simple_ring_count)
294
+
295
+ return H11_Simple_Ring_Count
296
+
297
+ def get_H12_Ring_System_Count(self):
298
+ """
299
+ A ring system is defined as:
300
+ 1. a set of rings that are fused or bridged together; or
301
+ 2. a single ring with at least one exocyclic atom connected to the ring
302
+ by a multiple bond.
303
+
304
+ A single isolated ring without exocyclic atoms is not counted as a ring
305
+ system here; it is counted by H11 as a simple ring.
306
+ """
307
+ H12_Ring_System_Count = []
308
+ for mol in tqdm(self.mols):
309
+ ring_info = mol.GetRingInfo()
310
+ atom_rings = ring_info.AtomRings()
311
+
312
+ if len(atom_rings) == 0:
313
+ H12_Ring_System_Count.append(0)
314
+ continue
315
+
316
+ # Build a graph of rings where edges represent shared atoms (fused/bridged)
317
+ ring_graph = {i: set() for i in range(len(atom_rings))}
318
+
319
+ for i in range(len(atom_rings)):
320
+ for j in range(i + 1, len(atom_rings)):
321
+ ring_i = set(atom_rings[i])
322
+ ring_j = set(atom_rings[j])
323
+ if ring_i & ring_j: # If rings share atoms (fused/bridged)
324
+ ring_graph[i].add(j)
325
+ ring_graph[j].add(i)
326
+
327
+ has_exocyclic_atom = [
328
+ self._ring_has_exocyclic_atom(mol, ring)
329
+ for ring in atom_rings
330
+ ]
331
+
332
+ # Find connected components using DFS
333
+ visited = set()
334
+ ring_systems = 0
335
+
336
+ def dfs(ring_idx, component):
337
+ visited.add(ring_idx)
338
+ component.append(ring_idx)
339
+ for neighbor in ring_graph[ring_idx]:
340
+ if neighbor not in visited:
341
+ dfs(neighbor, component)
342
+
343
+ for i in range(len(atom_rings)):
344
+ if i not in visited:
345
+ component = []
346
+ dfs(i, component)
347
+
348
+ # Count this component only if it is fused/bridged
349
+ # or if at least one ring in the component has exocyclic atoms.
350
+ if len(component) > 1 or any(has_exocyclic_atom[idx] for idx in component):
351
+ ring_systems += 1
352
+
353
+ H12_Ring_System_Count.append(ring_systems)
354
+
355
+ return H12_Ring_System_Count
356
+
357
+
358
+
359
+ def get_H13_Charged_Atom_Count(self):
360
+ H13_Charged_Atom_Count = []
361
+ for mol in tqdm(self.mols):
362
+ charged_atom_count = sum(1 for atom in mol.GetAtoms() if atom.GetFormalCharge() != 0)
363
+ H13_Charged_Atom_Count.append(charged_atom_count)
364
+ return H13_Charged_Atom_Count
365
+
366
+ def get_H14_Net_Charge(self):
367
+ H14_Net_Charge = []
368
+ for mol in tqdm(self.mols):
369
+ net_charge = rdmolops.GetFormalCharge(mol)
370
+ H14_Net_Charge.append(net_charge)
371
+ return H14_Net_Charge
372
+
373
+ def get_H15_Carbon_SP3_Hybridisation_Ratio(self):
374
+ """
375
+ Calculate the fraction of sp3 hybridized carbon atoms for each molecule
376
+ Returns:
377
+ list: List of sp3 carbon fractions
378
+ """
379
+ H15_Carbon_SP3_Hybridisation_Ratio = []
380
+ for mol in tqdm(self.mols):
381
+ sp3_carbons = 0
382
+ total_carbons = 0
383
+ for atom in mol.GetAtoms():
384
+ if atom.GetSymbol() == 'C': # Check if carbon atom
385
+ total_carbons += 1
386
+ if atom.GetHybridization() == Chem.HybridizationType.SP3:
387
+ sp3_carbons += 1
388
+ # Calculate fraction for this specific molecule
389
+ if total_carbons == 0:
390
+ fraction_sp3_carbon = 0
391
+ else:
392
+ fraction_sp3_carbon = sp3_carbons / total_carbons
393
+ H15_Carbon_SP3_Hybridisation_Ratio.append(fraction_sp3_carbon)
394
+ return H15_Carbon_SP3_Hybridisation_Ratio
395
+
396
+ def get_H16_Chiral_Centre_to_Heavy_Atom_Ratio(self):
397
+ H16_Chiral_Centre_to_Heavy_Atom_Ratio = []
398
+ for i, mol in enumerate(tqdm(self.mols)):
399
+ chiral_centers = Chem.FindMolChiralCenters(
400
+ mol,
401
+ includeUnassigned=True,
402
+ includeCIP=True,
403
+ useLegacyImplementation=False
404
+ )
405
+ num_chiral_centers = len(chiral_centers)
406
+ chiral_centers_normalized = (num_chiral_centers / self.HA[i]) if self.HA[i] > 0 else 0.0
407
+ H16_Chiral_Centre_to_Heavy_Atom_Ratio.append(chiral_centers_normalized)
408
+ return H16_Chiral_Centre_to_Heavy_Atom_Ratio
409
+
410
+
411
+ def get_H17_Degree_of_Unsaturation_Index(self):
412
+ """
413
+ Here we calculate DOU is further calculated using the (empirical) equation:
414
+ moleculeUnsaturation = (numCarbons) – [(numHydrogens)/2] – [(numHalogens)/2]
415
+ + [(numNitrogens)/2] + [(numPhosphorus)/2] + 1 + [(netFormalCharge)/2]
416
+ We considered P the same as N. Chalcogen (氧组元素) does not contribute to DOU cal.
417
+
418
+ Hydrogen atoms are counted using both explicit hydrogen atoms and
419
+ implicit/explicit hydrogen counts stored on heavy atoms. Formal charge
420
+ is included as a correction term, but charged molecules may still need
421
+ molecule-specific interpretation.
422
+ """
423
+ H17_Degree_of_Unsaturation_Index = []
424
+ for mol in tqdm(self.mols):
425
+ num_carbons = sum(1 for atom in mol.GetAtoms() if atom.GetSymbol() == 'C')
426
+
427
+ # Count explicit H atoms plus H counts attached to heavy atoms.
428
+ num_hydrogens = (
429
+ sum(1 for atom in mol.GetAtoms() if atom.GetAtomicNum() == 1)
430
+ + sum(atom.GetTotalNumHs() for atom in mol.GetAtoms() if atom.GetAtomicNum() != 1)
431
+ )
432
+
433
+ # Count Pnictogen (氮族元素) atoms
434
+ num_Pnictogen = sum(1 for atom in mol.GetAtoms() if atom.GetSymbol() in ['N','P'])
435
+ num_halogens = sum(1 for atom in mol.GetAtoms() if atom.GetSymbol() in ['F', 'Cl', 'Br', 'I'])
436
+ net_charge = rdmolops.GetFormalCharge(mol)
437
+
438
+ molecule_unsaturation = (
439
+ num_carbons
440
+ - (num_hydrogens / 2)
441
+ - (num_halogens / 2)
442
+ + (num_Pnictogen / 2)
443
+ + 1
444
+ + (net_charge / 2)
445
+ )
446
+
447
+ if abs(molecule_unsaturation) < 1e-12:
448
+ molecule_unsaturation = 0.0
449
+
450
+ H17_Degree_of_Unsaturation_Index.append(molecule_unsaturation)
451
+ return H17_Degree_of_Unsaturation_Index
452
+
453
+ def get_H18_Hydrophilic_Index(self):
454
+ H18_Hydrophilic_Index = []
455
+ for mol in tqdm(self.mols):
456
+ hy = molproperty.CalculateHydrophilicityFactor(mol)
457
+ H18_Hydrophilic_Index.append(hy)
458
+ return H18_Hydrophilic_Index