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

11 151
from abc import ABC, abstractmethod, abstractclassmethod
12

13

14
# =======================================
15
# Molecule Class
16
# =======================================
17

18 151
class MolAdapter(ABC):
19
    """
20
    This is a ChemPer wrapper for a molecule from
21
    one of the cheminformatics toolkits.
22
    ChemPer molecules are initiated from the reference package molecule object.
23
    Currently we support OpenEye and RDKit toolkits.
24

25
    Attributes
26
    ----------
27
    mol : toolkit Mol
28
          Mol object from the reference cheminformatics toolkit
29
    """
30

31 151
    @classmethod
32 151
    @abstractmethod
33
    def from_smiles(cls, smiles):
34
        """
35
        Creates a ChemPer Mol form a SMILES string
36

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

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

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

63 151
    @abstractmethod
64
    def get_atom_by_index(self, idx):
65
        """
66
        Parameters
67
        ----------
68
        idx : int
69
            atom index
70

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

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

88 151
    @abstractmethod
89
    def get_bond_by_index(self, idx):
90
        """
91
        Parameters
92
        ----------
93
        idx: int
94
            bond index
95

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

103 151
    @abstractmethod
104
    def get_bond_by_atoms(self, atom1, atom2):
105
        """
106
        Finds a bond between two atoms
107

108
        Parameters
109
        ----------
110
        atom1 : ChemPer Atom
111
        atom2 : ChemPer Atom
112

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

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

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

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

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

149
# =======================================
150
# Atom Class
151
# =======================================
152

153

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

300 151
    @abstractmethod
301
    def get_molecule(self):
302
        """
303
        Extracts the parent molecule this atom is from.
304

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

312

313
# =======================================
314
# Bond Class
315
# =======================================
316

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

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

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

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

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

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

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

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

398 151
    @abstractmethod
399
    def get_molecule(self):
400
        """
401
        Extracts the parent molecule this bond is from
402

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

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

Read our documentation on viewing source code .

Loading