|
1
|
|
|
#! /usr/bin/env python |
|
2
|
|
|
# |
|
3
|
|
|
# Copyright (C) 2015-2016 Rich Lewis <[email protected]> |
|
4
|
|
|
# License: 3-clause BSD |
|
5
|
|
|
|
|
6
|
1 |
|
""" |
|
7
|
|
|
## skchem.core.bond |
|
8
|
|
|
|
|
9
|
|
|
Defining chemical bonds in scikit-chem. |
|
10
|
|
|
""" |
|
11
|
|
|
|
|
12
|
1 |
|
import pandas as pd |
|
|
|
|
|
|
13
|
1 |
|
import rdkit.Chem |
|
|
|
|
|
|
14
|
|
|
import numpy as np |
|
|
|
|
|
|
15
|
1 |
|
|
|
16
|
1 |
|
from .atom import Atom |
|
17
|
|
|
from .base import ChemicalObject, PropertyView, ChemicalObjectView |
|
18
|
|
|
|
|
19
|
1 |
|
|
|
20
|
|
|
class Bond(rdkit.Chem.rdchem.Bond, ChemicalObject): |
|
21
|
|
|
|
|
22
|
|
|
""" |
|
23
|
|
|
Class representing a chemical bond in scikit-chem. |
|
24
|
|
|
|
|
25
|
|
|
""" |
|
26
|
1 |
|
|
|
27
|
|
|
@property |
|
28
|
|
|
def atoms(self): |
|
29
|
|
|
|
|
30
|
|
|
""" tuple[Atom]: list of atoms involved in the bond. """ |
|
31
|
|
|
|
|
32
|
|
|
return (Atom.from_super(self.GetBeginAtom()), |
|
|
|
|
|
|
33
|
|
|
Atom.from_super(self.GetEndAtom())) |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
1 |
|
@property |
|
36
|
|
|
def atom_idxs(self): |
|
37
|
|
|
|
|
38
|
|
|
""" tuple[int]: list of atom indexes involved in the bond. """ |
|
39
|
|
|
|
|
40
|
1 |
|
return (self.GetBeginAtomIdx(), self.GetEndAtomIdx()) |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
1 |
|
@property |
|
43
|
|
|
def props(self): |
|
44
|
|
|
|
|
45
|
|
|
""" PropertyView: rdkit properties of the atom. """ |
|
46
|
|
|
|
|
47
|
1 |
|
if not hasattr(self, '_props'): |
|
48
|
|
|
self._props = PropertyView(self) |
|
|
|
|
|
|
49
|
|
|
return PropertyView(self) |
|
50
|
1 |
|
|
|
51
|
|
|
@property |
|
52
|
|
|
def order(self): |
|
53
|
|
|
|
|
54
|
1 |
|
""" int: the order of the bond. """ |
|
55
|
|
|
|
|
56
|
|
|
return self.GetBondTypeAsDouble() |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
1 |
|
@property |
|
59
|
|
|
def is_aromatic(self): |
|
60
|
|
|
|
|
61
|
|
|
""" bool: whether the bond is aromatic. """ |
|
62
|
|
|
|
|
63
|
|
|
return self.GetIsAromatic() |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
@property |
|
66
|
1 |
|
def is_conjugated(self): |
|
67
|
|
|
|
|
68
|
|
|
""" bool: whether the bond is conjugated. """ |
|
69
|
|
|
|
|
70
|
|
|
return self.GetIsConjugated() |
|
|
|
|
|
|
71
|
|
|
|
|
72
|
1 |
|
@property |
|
73
|
1 |
|
def owner(self): |
|
74
|
|
|
|
|
75
|
|
|
""" skchem.Mol: the molecule this bond is a part of. """ |
|
76
|
1 |
|
|
|
77
|
|
|
from .mol import Mol |
|
78
|
|
|
return Mol.from_super(self.GetOwningMol()) |
|
|
|
|
|
|
79
|
1 |
|
|
|
80
|
1 |
|
@property |
|
81
|
1 |
|
def stereo_symbol(self): |
|
82
|
1 |
|
|
|
83
|
|
|
""" str: the stereo label of the bond ('Z', 'E', 'ANY', 'NONE') """ |
|
84
|
|
|
|
|
85
|
|
|
return self.GetStereo().name.lstrip('STEREO') |
|
|
|
|
|
|
86
|
1 |
|
|
|
87
|
|
|
@property |
|
88
|
|
|
def is_in_ring(self): |
|
89
|
|
|
|
|
90
|
1 |
|
""" bool: whether the bond is in a ring. """ |
|
91
|
1 |
|
|
|
92
|
|
|
return self.IsInRing() |
|
|
|
|
|
|
93
|
1 |
|
|
|
94
|
|
|
def draw(self): |
|
95
|
|
|
|
|
96
|
|
|
""" str: Draw the bond in ascii. """ |
|
97
|
|
|
|
|
98
|
|
|
return '{}{}{}'.format(self.atoms[0].symbol, |
|
99
|
1 |
|
'-' if self.order == 1 else self.GetSmarts(), |
|
|
|
|
|
|
100
|
|
|
self.atoms[1].symbol) |
|
101
|
|
|
|
|
102
|
|
|
def to_dict(self): |
|
103
|
|
|
|
|
104
|
|
|
""" dict: Convert to a dictionary representation. """ |
|
105
|
|
|
|
|
106
|
|
|
return {"b": self.GetBeginAtomIdx(), |
|
|
|
|
|
|
107
|
|
|
"e": self.GetEndAtomIdx(), |
|
|
|
|
|
|
108
|
|
|
"o": self.order} |
|
109
|
|
|
|
|
110
|
|
|
def __repr__(self): |
|
111
|
|
|
return '<{klass} type="{bond}" at {address}>'.format( |
|
112
|
|
|
klass=self.__class__.__name__, |
|
113
|
|
|
bond=self.draw(), |
|
114
|
|
|
address=hex(id(self))) |
|
115
|
|
|
|
|
116
|
|
|
def __str__(self): |
|
117
|
|
|
return self.draw() |
|
118
|
|
|
|
|
119
|
|
|
|
|
120
|
|
|
class BondView(ChemicalObjectView): |
|
121
|
|
|
|
|
122
|
|
|
""" Bond interface wrapper """ |
|
123
|
|
|
def __getitem__(self, index): |
|
124
|
|
|
res = super(BondView, self).__getitem__(index) |
|
125
|
|
|
if res is None: |
|
126
|
|
|
if abs(index) >= len(self): |
|
127
|
|
|
raise IndexError('Index {} out of range for molecule with ' |
|
128
|
|
|
'{} bonds.'.format(index, len(self))) |
|
129
|
|
|
|
|
130
|
|
|
# index is negative, so adding gives desired indexing from back |
|
131
|
|
|
if index < 0: |
|
132
|
|
|
index += len(self) |
|
133
|
|
|
|
|
134
|
|
|
return Bond.from_super(self.owner.GetBondWithIdx(index)) |
|
135
|
|
|
|
|
136
|
|
|
else: |
|
137
|
|
|
return res |
|
138
|
|
|
|
|
139
|
|
|
def __len__(self): |
|
140
|
|
|
return self.owner.GetNumBonds() |
|
141
|
|
|
|
|
142
|
|
|
@property |
|
143
|
|
|
def atom_idxs(self): |
|
144
|
|
|
|
|
145
|
|
|
""" The atom indices for the bonds in the view. """ |
|
146
|
|
|
|
|
147
|
|
|
return np.array([atom.atom_idxs for atom in self]) |
|
148
|
|
|
|
|
149
|
|
|
@property |
|
150
|
|
|
def order(self): |
|
151
|
|
|
|
|
152
|
|
|
""" np.array<int> the bond orders of the bonds in the view. """ |
|
153
|
|
|
|
|
154
|
|
|
return np.array([bond.order for bond in self]) |
|
155
|
|
|
|
|
156
|
|
|
@property |
|
157
|
|
|
def is_aromatic(self): |
|
158
|
|
|
|
|
159
|
|
|
""" np.array<bool> whether each of the bonds in the view are |
|
160
|
|
|
aromatic. """ |
|
161
|
|
|
|
|
162
|
|
|
return np.array([bond.is_aromatic for bond in self]) |
|
163
|
|
|
|
|
164
|
|
|
@property |
|
165
|
|
|
def is_conjugated(self): |
|
166
|
|
|
|
|
167
|
|
|
""" np.array<bool> whether each of the bonds in the view are c |
|
168
|
|
|
onjugated. """ |
|
169
|
|
|
|
|
170
|
|
|
return np.array([bond.is_conjugated for bond in self]) |
|
171
|
|
|
|
|
172
|
|
|
@property |
|
173
|
|
|
def is_in_ring(self): |
|
174
|
|
|
|
|
175
|
|
|
""" np.array<bool> whether each of the bonds in the view are in a |
|
176
|
|
|
ring. """ |
|
177
|
|
|
|
|
178
|
|
|
return np.array([bond.is_in_ring for bond in self]) |
|
179
|
|
|
|
|
180
|
|
|
@property |
|
181
|
|
|
def stereo_symbol(self): |
|
182
|
|
|
|
|
183
|
|
|
""" np.array<str> the stereo symbol of the bonds in the view. """ |
|
184
|
|
|
|
|
185
|
|
|
return np.array([bond.stereo_symbol for bond in self]) |
|
186
|
|
|
|
|
187
|
|
|
@property |
|
188
|
|
|
def index(self): |
|
189
|
|
|
|
|
190
|
|
|
""" A `pd.Index` of the bonds in the `BondView`. """ |
|
191
|
|
|
|
|
192
|
|
|
return pd.RangeIndex(len(self), name='bond_idx') |
|
193
|
|
|
|
|
194
|
|
|
__all__ = ['Atom', 'AtomView'] |
|
|
|
|
|
|
195
|
|
|
|
This can be caused by one of the following:
1. Missing Dependencies
This error could indicate a configuration issue of Pylint. Make sure that your libraries are available by adding the necessary commands.
2. Missing __init__.py files
This error could also result from missing
__init__.pyfiles in your module folders. Make sure that you place one file in each sub-folder.