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

4
This script contains adapters or the structure for
5
molecules, atoms, and bonds.
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 2
from abc import ABC, abstractmethod, abstractclassmethod
16

17

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

22 2
class MolAdapter(ABC):
23
    """
24
    This is a ChemPer wrapper for a molecule from
25
    one of the cheminformatics toolkits.
26
    ChemPer molecules are initiated from the reference package molecule object.
27
    Currently we support OpenEye and RDKit toolkits.
28

29
    Attributes
30
    ----------
31
    mol : toolkit Mol
32
          Mol object from the reference cheminformatics toolkit
33
    """
34 2
    @abstractclassmethod
35
    def from_smiles(cls, smiles):
36
        """
37
        Creates a ChemPer Mol form a SMILES string
38

39
        Parameters
40
        ----------
41
        smiles : str
42
                 SMILES used to create molecule with wrapped toolkit
43

44
        Returns
45
        -------
46
        Mol : ChemPer Mol
47
        """
48 2
    @abstractmethod
49
    def set_aromaticity_mdl(self):
50
        """
51
        Sets the aromaticity flags in this molecule to use the MDL model
52
        """
53 0
        pass
54

55 2
    @abstractmethod
56
    def get_atoms(self):
57
        """
58
        Returns
59
        -------
60
        atom_list : list[ChemPer Atoms]
61
            list of all atoms in the molecule
62
        """
63 0
        pass
64

65 2
    @abstractmethod
66
    def get_atom_by_index(self, idx):
67
        """
68
        Parameters
69
        ----------
70
        idx : int
71
            atom index
72

73
        Returns
74
        -------
75
        atom : ChemPer Atom
76
            atom with index idx
77
        """
78 0
        pass
79

80 2
    @abstractmethod
81
    def get_bonds(self):
82
        """
83
        Returns
84
        -------
85
        bond_list : list[ChemPer Bonds]
86
            list of all bonds in the molecule
87
        """
88 0
        pass
89

90 2
    @abstractmethod
91
    def get_bond_by_index(self, idx):
92
        """
93
        Parameters
94
        ----------
95
        idx: int
96
            bond index
97

98
        Returns
99
        -------
100
        bond: ChemPer Bond
101
            bond with index idx
102
        """
103 0
        pass
104

105 2
    @abstractmethod
106
    def get_bond_by_atoms(self, atom1, atom2):
107
        """
108
        Finds a bond between two atoms
109

110
        Parameters
111
        ----------
112
        atom1 : ChemPer Atom
113
        atom2 : ChemPer Atom
114

115
        Returns
116
        -------
117
        bond : ChemPer Bond or None
118
            If atoms are connected returns bond otherwise None
119
        """
120 0
        pass
121

122 2
    @abstractmethod
123
    def smirks_search(self, smirks):
124
        """
125
        Performs a substructure search on the molecule with the provided
126
        SMIRKS pattern. Note - this function expects SMIRKS patterns with indexed atoms
127
        that is with :n for at least some atoms.
128

129
        Parameters
130
        ----------
131
        smirks : str
132
            SMIRKS pattern with indexed atoms (:n)
133

134
        Returns
135
        -------
136
        matches : list[match dictionary]
137
            match dictionaries have the form {smirks index: atom index}
138
        """
139 0
        pass
140

141 2
    @abstractmethod
142
    def get_smiles(self):
143
        """
144
        Returns
145
        -------
146
        smiles: str
147
            SMILES string for the molecule
148
        """
149 0
        pass
150

151
# =======================================
152
# Atom Class
153
# =======================================
154

155

156 2
class AtomAdapter(ABC):
157
    """
158
    This is a ChemPer wrapper for an atom from
159
    one of the cheminformatics toolkits.
160
    ChemPer Atoms are initiated from the reference package object.
161
    Currently we support OpenEye and RDKit toolkits.
162

163
    Attributes
164
    ----------
165
    atom : Atom from reference toolkit
166
    """
167 2
    @abstractmethod
168
    def atomic_number(self):
169
        """
170
        Returns
171
        -------
172
        atomic_number : int
173
            atomic number for the atom
174
        """
175 0
        pass
176

177 2
    @abstractmethod
178
    def degree(self):
179
        """
180
        Returns
181
        -------
182
        degree : int
183
            degree or number of explicit bond orders around the atom
184
        """
185 0
        pass
186

187 2
    @abstractmethod
188
    def connectivity(self):
189
        """
190
        Returns
191
        -------
192
        connectivity : int
193
            connectivity or total number of bonds (regardless of order) around the atom
194
        """
195 0
        pass
196

197 2
    @abstractmethod
198
    def valence(self):
199
        """
200
        Returns
201
        -------
202
        valence : int
203
            the atoms valence (equivalent to degree when all bonds are explicit)
204
        """
205 0
        pass
206

207 2
    @abstractmethod
208
    def formal_charge(self):
209
        """
210
        Returns
211
        -------
212
        formal_charge : int
213
            the atom's formal charge
214
        """
215 0
        pass
216

217 2
    @abstractmethod
218
    def hydrogen_count(self):
219
        """
220
        Returns
221
        -------
222
        H_count : int
223
            total number of hydrogen atoms connected to this Atom
224
        """
225 0
        pass
226

227 2
    @abstractmethod
228
    def min_ring_size(self):
229
        """
230
        Returns
231
        -------
232
        min_ring_size : int
233
            size of the smallest ring this atom is a part of
234
        """
235 0
        pass
236

237 2
    @abstractmethod
238
    def ring_connectivity(self):
239
        """
240
        Returns
241
        -------
242
        ring_connectivity : int
243
            number of bonds on the atom that are a part of a ring
244
        """
245 0
        pass
246

247 2
    @abstractmethod
248
    def is_aromatic(self):
249
        """
250
        Returns
251
        -------
252
        is_aromatic : boolean
253
            True if the atom is aromatic otherwise False
254
        """
255 0
        pass
256

257 2
    @abstractmethod
258
    def get_index(self):
259
        """
260
        Returns
261
        -------
262
        index : int
263
            atom index in its molecule
264
        """
265 0
        pass
266

267 2
    @abstractmethod
268
    def is_connected_to(self, atom2):
269
        """
270
        Parameters
271
        ----------
272
        atom2 : ChemPer Atom
273
            Atom to check if it is bonded to this atom
274

275
        Returns
276
        -------
277
        connected : boolean
278
            True if atom2 is a bonded to atom1
279
        """
280 0
        pass
281

282 2
    @abstractmethod
283
    def get_neighbors(self):
284
        """
285
        Returns
286
        -------
287
        neighbors : list[ChemPer Atoms]
288
            Atoms that are one bond away from this atom
289
        """
290 0
        pass
291

292 2
    @abstractmethod
293
    def get_bonds(self):
294
        """
295
        Returns
296
        -------
297
        bonds : list[ChemPer Bonds]
298
            Bonds connected to this atom
299
        """
300 0
        pass
301

302 2
    @abstractmethod
303
    def get_molecule(self):
304
        """
305
        Extracts the parent molecule this atom is from.
306

307
        Returns
308
        -------
309
        mol : ChemPer Mol
310
            Molecule this atom is stored in
311
        """
312 0
        pass
313

314

315
# =======================================
316
# Bond Class
317
# =======================================
318

319 2
class BondAdapter(ABC):
320
    """
321
    This is a ChemPer wrapper for a bond from
322
    one of the cheminformatics toolkits.
323
    ChemPer Bonds are initiated from the reference package object.
324
    Currently we support OpenEye and RDKit toolkits.
325

326
    Attributes
327
    ----------
328
    bond : Bond from reference class
329
    """
330 2
    @abstractmethod
331
    def get_order(self):
332
        """
333
        Returns
334
        -------
335
        order : int or float
336
            This is the absolute order, returns 1.5 if bond is aromatic
337
        """
338 0
        pass
339

340 2
    @abstractmethod
341
    def get_atoms(self):
342
        """
343
        Returns
344
        -------
345
        atoms : list[ChemPer Atoms]
346
            The two atoms connected by this bond
347
        """
348 0
        pass
349

350 2
    @abstractmethod
351
    def is_ring(self):
352
        """
353
        Returns
354
        -------
355
        is_ring : boolean
356
            True if bond is a part of a ring, otherwise False
357
        """
358 0
        pass
359

360 2
    @abstractmethod
361
    def is_aromatic(self):
362
        """
363
        Returns
364
        -------
365
        is_aromatic : boolean
366
            True if it is an aromatic bond
367
        """
368 0
        pass
369

370 2
    @abstractmethod
371
    def is_single(self):
372
        """
373
        Returns
374
        -------
375
        is_single : boolean
376
            True if it is a single bond
377
        """
378 0
        pass
379

380 2
    @abstractmethod
381
    def is_double(self):
382
        """
383
        Returns
384
        -------
385
        is_double : boolean
386
            True if it is a double bond
387
        """
388 0
        pass
389

390 2
    @abstractmethod
391
    def is_triple(self):
392
        """
393
        Returns
394
        -------
395
        is_triple : boolean
396
            True if it is a triple bond
397
        """
398 0
        pass
399

400 2
    @abstractmethod
401
    def get_molecule(self):
402
        """
403
        Extracts the parent molecule this bond is from
404

405
        Returns
406
        -------
407
        mol : ChemPer Mol
408
            Molecule this bond is stored in
409
        """
410 0
        pass
411

412 2
    @abstractmethod
413
    def get_index(self):
414
        """
415
        Returns
416
        -------
417
        index : int
418
            index of this bond in its parent molecule
419
        """
420 0
        pass

Read our documentation on viewing source code .

Loading