Update miniconda URL
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 | 100 |
from abc import ABC, abstractmethod, abstractclassmethod |
12 |
|
|
13 |
|
|
14 |
# =======================================
|
|
15 |
# Molecule Class
|
|
16 |
# =======================================
|
|
17 |
|
|
18 | 100 |
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 | 100 |
@classmethod
|
32 | 100 |
@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 | 100 |
@abstractmethod
|
47 |
def set_aromaticity_mdl(self): |
|
48 |
"""
|
|
49 |
Sets the aromaticity flags in this molecule to use the MDL model
|
|
50 |
"""
|
|
51 |
pass
|
|
52 |
|
|
53 | 100 |
@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 |
pass
|
|
62 |
|
|
63 | 100 |
@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 |
pass
|
|
77 |
|
|
78 | 100 |
@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 |
pass
|
|
87 |
|
|
88 | 100 |
@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 |
pass
|
|
102 |
|
|
103 | 100 |
@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 |
pass
|
|
119 |
|
|
120 | 100 |
@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 |
pass
|
|
138 |
|
|
139 | 100 |
@abstractmethod
|
140 |
def get_smiles(self): |
|
141 |
"""
|
|
142 |
Returns
|
|
143 |
-------
|
|
144 |
smiles: str
|
|
145 |
SMILES string for the molecule
|
|
146 |
"""
|
|
147 |
pass
|
|
148 |
|
|
149 |
# =======================================
|
|
150 |
# Atom Class
|
|
151 |
# =======================================
|
|
152 |
|
|
153 |
|
|
154 | 100 |
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 | 100 |
@abstractmethod
|
166 |
def atomic_number(self): |
|
167 |
"""
|
|
168 |
Returns
|
|
169 |
-------
|
|
170 |
atomic_number : int
|
|
171 |
atomic number for the atom
|
|
172 |
"""
|
|
173 |
pass
|
|
174 |
|
|
175 | 100 |
@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 |
pass
|
|
184 |
|
|
185 | 100 |
@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 |
pass
|
|
194 |
|
|
195 | 100 |
@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 |
pass
|
|
204 |
|
|
205 | 100 |
@abstractmethod
|
206 |
def formal_charge(self): |
|
207 |
"""
|
|
208 |
Returns
|
|
209 |
-------
|
|
210 |
formal_charge : int
|
|
211 |
the atom's formal charge
|
|
212 |
"""
|
|
213 |
pass
|
|
214 |
|
|
215 | 100 |
@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 |
pass
|
|
224 |
|
|
225 | 100 |
@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 |
pass
|
|
234 |
|
|
235 | 100 |
@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 |
pass
|
|
244 |
|
|
245 | 100 |
@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 |
pass
|
|
254 |
|
|
255 | 100 |
@abstractmethod
|
256 |
def get_index(self): |
|
257 |
"""
|
|
258 |
Returns
|
|
259 |
-------
|
|
260 |
index : int
|
|
261 |
atom index in its molecule
|
|
262 |
"""
|
|
263 |
pass
|
|
264 |
|
|
265 | 100 |
@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 |
pass
|
|
279 |
|
|
280 | 100 |
@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 |
pass
|
|
289 |
|
|
290 | 100 |
@abstractmethod
|
291 |
def get_bonds(self): |
|
292 |
"""
|
|
293 |
Returns
|
|
294 |
-------
|
|
295 |
bonds : list[ChemPer Bonds]
|
|
296 |
Bonds connected to this atom
|
|
297 |
"""
|
|
298 |
pass
|
|
299 |
|
|
300 | 100 |
@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 |
pass
|
|
311 |
|
|
312 |
|
|
313 |
# =======================================
|
|
314 |
# Bond Class
|
|
315 |
# =======================================
|
|
316 |
|
|
317 | 100 |
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 | 100 |
@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 |
pass
|
|
337 |
|
|
338 | 100 |
@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 |
pass
|
|
347 |
|
|
348 | 100 |
@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 |
pass
|
|
357 |
|
|
358 | 100 |
@abstractmethod
|
359 |
def is_aromatic(self): |
|
360 |
"""
|
|
361 |
Returns
|
|
362 |
-------
|
|
363 |
is_aromatic : boolean
|
|
364 |
True if it is an aromatic bond
|
|
365 |
"""
|
|
366 |
pass
|
|
367 |
|
|
368 | 100 |
@abstractmethod
|
369 |
def is_single(self): |
|
370 |
"""
|
|
371 |
Returns
|
|
372 |
-------
|
|
373 |
is_single : boolean
|
|
374 |
True if it is a single bond
|
|
375 |
"""
|
|
376 |
pass
|
|
377 |
|
|
378 | 100 |
@abstractmethod
|
379 |
def is_double(self): |
|
380 |
"""
|
|
381 |
Returns
|
|
382 |
-------
|
|
383 |
is_double : boolean
|
|
384 |
True if it is a double bond
|
|
385 |
"""
|
|
386 |
pass
|
|
387 |
|
|
388 | 100 |
@abstractmethod
|
389 |
def is_triple(self): |
|
390 |
"""
|
|
391 |
Returns
|
|
392 |
-------
|
|
393 |
is_triple : boolean
|
|
394 |
True if it is a triple bond
|
|
395 |
"""
|
|
396 |
pass
|
|
397 |
|
|
398 | 100 |
@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 |
pass
|
|
409 |
|
|
410 | 100 |
@abstractmethod
|
411 |
def get_index(self): |
|
412 |
"""
|
|
413 |
Returns
|
|
414 |
-------
|
|
415 |
index : int
|
|
416 |
index of this bond in its parent molecule
|
|
417 |
"""
|
|
418 |
pass
|
Read our documentation on viewing source code .