MobleyLab / chemper
1
"""
2
adapters.py
3

4
This script contains adapters or the structure for atoms, molecules and
5
substructure searches.
6
Our chemical perception code is designed to be independent of the users
7
cheminformatics packages. For each cheminformatics package we support we
8
will provide classes following the structure in these adapters.
9

10
AUTHORS:
11

12
Caitlin C. Bannan <bannanc@uci.edu>, Mobley Group, University of California Irvine
13
"""
14

15 9
from abc import ABC, abstractmethod
16

17

18
# =======================================
19
# Molecule Class
20
# =======================================
21

22 9
class MolAdapter(ABC):
23
    """
24
    Template class for wrapping a molecule object
25
    from a given cheminformatics package into a chemper Mol.
26
    chemper `Mol` are initiated from the reference package molecule object.
27
    The class MolFromSmiles initiates a chemper Mol from a SMILES string.
28
    Currently we support OpenEye toolkits and RDKit
29
    """
30 9
    @abstractmethod
31
    def set_aromaticity_mdl(self):
32
        """
33
        Sets the aromaticity flags in this molecule to use the MDL model
34
        """
35 0
        pass
36

37 9
    @abstractmethod
38
    def get_atoms(self):
39
        """
40
        Returns
41
        -------
42
        atom_list: list of chemper Atoms
43
            list of all atoms in the molecule
44
        """
45 0
        pass
46

47 9
    @abstractmethod
48
    def get_atom_by_index(self, idx):
49
        """
50
        Parameters
51
        ----------
52
        idx: int
53
            atom index
54

55
        Returns
56
        -------
57
        atom: chemper Atom object
58
            atom with index idx
59
        """
60 0
        pass
61

62 9
    @abstractmethod
63
    def get_bonds(self):
64
        """
65
        Returns
66
        -------
67
        bond_list: list of chemper Bonds
68
            list of all bonds in the molecule
69
        """
70 0
        pass
71

72 9
    @abstractmethod
73
    def get_bond_by_index(self, idx):
74
        """
75
        Parameters
76
        ----------
77
        idx: ing
78
            bond index
79

80
        Returns
81
        -------
82
        bond: chemper Bond object
83
            bond with index idx
84
        """
85 0
        pass
86

87 9
    @abstractmethod
88
    def get_bond_by_atoms(self, atom1, atom2):
89
        """
90
        Finds a bond between two atoms
91
        Parameters
92
        ----------
93
        atom1: chemper Atom object
94
        atom2: chemper Atom object
95

96
        Returns
97
        -------
98
        bond: chemper Bond object or None
99
            if atoms are connected returns bond otherwise None
100
        """
101 0
        pass
102

103 9
    @abstractmethod
104
    def smirks_search(self, smirks):
105
        """
106
        Performs a substructure search on the molecule with the provided
107
        SMIRKS pattern. Note - this function expects SMIRKS patterns with indexed atoms
108
        that is with :n for at least some atoms.
109

110
        Parameters
111
        ----------
112
        smirks: str
113
            SMIRKS pattern with indexed atoms (:n)
114

115
        Returns
116
        -------
117
        matches: list of dictionaries
118
            dictionary for each match with the form {smirks index: atom index}
119
        """
120 0
        pass
121

122 9
    @abstractmethod
123
    def get_smiles(self):
124
        """
125
        Returns
126
        -------
127
        smiles: str
128
            SMILES string for the molecule
129
        """
130 0
        pass
131

132
# =======================================
133
# Atom Class
134
# =======================================
135

136

137 9
class AtomAdapter(ABC):
138
    """
139
    Template class for wrapping an atom object
140
    from a given cheminformatics package into a chemper Atom.
141
    These are always initiated from a reference package Atom object.
142
    Currently we support OpenEye toolkits and RDKit
143
    """
144

145 9
    @abstractmethod
146
    def atomic_number(self):
147
        """
148
        Returns
149
        -------
150
        atomic_number: int
151
            atomic number for the atom
152
        """
153 0
        pass
154

155 9
    @abstractmethod
156
    def degree(self):
157
        """
158
        Returns
159
        -------
160
        degree: int
161
            degree or number of explicit bonds around the atom
162
        """
163 0
        pass
164

165 9
    @abstractmethod
166
    def connectivity(self):
167
        """
168
        Returns
169
        -------
170
        connectivity: int
171
            connectivity or total number of bonds around the atom
172
        """
173 0
        pass
174

175 9
    @abstractmethod
176
    def valence(self):
177
        """
178
        Returns
179
        -------
180
        valence: int
181
            the atoms valence
182
        """
183 0
        pass
184

185 9
    @abstractmethod
186
    def formal_charge(self):
187
        """
188
        Returns
189
        -------
190
        formal_charge: int
191
            the atom's formal charge
192
        """
193 0
        pass
194

195 9
    @abstractmethod
196
    def hydrogen_count(self):
197
        """
198
        Returns
199
        -------
200
        H_count: int
201
            total number of hydrogen atoms connected to this Atom
202
        """
203 0
        pass
204

205 9
    @abstractmethod
206
    def min_ring_size(self):
207
        """
208
        Returns
209
        -------
210
        min_ring_size: int
211
            size of the smallest ring this atom is a part of
212
        """
213 0
        pass
214

215 9
    @abstractmethod
216
    def ring_connectivity(self):
217
        """
218
        Returns
219
        -------
220
        ring_connectivity: int
221
            number of bonds on the atom that are a part of a ring
222
        """
223 0
        pass
224

225 9
    @abstractmethod
226
    def is_aromatic(self):
227
        """
228
        Returns
229
        -------
230
        is_aromatic: boolean
231
            True if the atom is aromatic otherwise False
232
        """
233 0
        pass
234

235 9
    @abstractmethod
236
    def get_index(self):
237
        """
238
        Returns
239
        -------
240
        index: int
241
            atom index in its molecule
242
        """
243 0
        pass
244

245 9
    @abstractmethod
246
    def is_connected_to(self, atom2):
247
        """
248
        Parameters
249
        ----------
250
        atom2: chemper Atom object
251
            atom to check if it is connected to this atom
252

253
        Returns
254
        -------
255
        connected: boolean
256
            True if atom2 is a direct neighbor or atom1
257
        """
258 0
        pass
259

260 9
    @abstractmethod
261
    def get_neighbors(self):
262
        """
263
        Returns
264
        -------
265
        neighbors: list of chemper Atoms
266
            atoms that are one bond away from this atom
267
        """
268 0
        pass
269

270 9
    @abstractmethod
271
    def get_bonds(self):
272
        """
273
        Returns
274
        -------
275
        bonds: list of chemper Bonds
276
            bonds connected to this atom
277
        """
278 0
        pass
279

280 9
    @abstractmethod
281
    def get_molecule(self):
282
        """
283
        Extracts the parent molecule this atom is in
284

285
        Returns
286
        -------
287
        mol: chemper Mol
288
            molecule this atom is stored in
289
        """
290 0
        pass
291

292

293
# =======================================
294
# Bond Class
295
# =======================================
296

297 9
class BondAdapter(ABC):
298
    """
299
    Template class for wrapping a bond object
300
    from a given cheminformatics package into a chemper Bond.
301
    These are always initiated from a reference package Bond object.
302
    Currently we support OpenEye toolkits and RDKit
303
    """
304

305 9
    @abstractmethod
306
    def get_order(self):
307
        """
308
        Returns
309
        -------
310
        order: int or float
311
            This is the absolute order, returns 1.5 if bond is aromatic
312
        """
313 0
        pass
314

315 9
    @abstractmethod
316
    def get_atoms(self):
317
        """
318
        Returns
319
        -------
320
        atoms: list of chemper Atoms
321
            the two atoms connected by this bond
322
        """
323 0
        pass
324

325 9
    @abstractmethod
326
    def is_ring(self):
327
        """
328
        Returns
329
        -------
330
        is_ring: boolean
331
            True if bond is a part of a ring, otherwise False
332
        """
333 0
        pass
334

335 9
    @abstractmethod
336
    def is_aromatic(self):
337
        """
338
        Returns
339
        -------
340
        is_aromatic: boolean
341
            True if it is an aromatic bond
342
        """
343 0
        pass
344

345 9
    @abstractmethod
346
    def is_single(self):
347
        """
348
        Returns
349
        -------
350
        is_single: boolean
351
            True if it is a single bond
352
        """
353 0
        pass
354

355 9
    @abstractmethod
356
    def is_double(self):
357
        """
358
        Returns
359
        -------
360
        is_double: boolean
361
            True if it is a double bond
362
        """
363 0
        pass
364

365 9
    @abstractmethod
366
    def is_triple(self):
367
        """
368
        Returns
369
        -------
370
        is_triple: boolean
371
            True if it is a triple bond
372
        """
373 0
        pass
374

375 9
    @abstractmethod
376
    def get_molecule(self):
377
        """
378
        Extracts the parent molecule this bond is in
379

380
        Returns
381
        -------
382
        mol: chemper Mol
383
            molecule this bond is stored in
384
        """
385 0
        pass
386

387 9
    @abstractmethod
388
    def get_index(self):
389
        """
390
        Returns
391
        -------
392
        index: int
393
            index of this bond in its parent molecule
394
        """
395 0
        pass

Read our documentation on viewing source code .

Loading