|
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
|
1 |
|
|
|
15
|
|
|
from . import Atom |
|
16
|
1 |
|
from .base import ChemicalObject, PropertyView, ChemicalObjectView |
|
17
|
|
|
|
|
18
|
|
|
class Bond(rdkit.Chem.rdchem.Bond, ChemicalObject): |
|
19
|
|
|
|
|
20
|
|
|
""" |
|
21
|
|
|
Class representing a chemical bond in scikit-chem. |
|
22
|
|
|
|
|
23
|
1 |
|
""" |
|
24
|
|
|
|
|
25
|
|
|
@property |
|
26
|
|
|
def props(self): |
|
27
|
|
|
|
|
28
|
|
|
""" PropertyView: rdkit properties of the atom. """ |
|
29
|
|
|
|
|
30
|
1 |
|
if not hasattr(self, '_props'): |
|
31
|
|
|
self._props = PropertyView(self) |
|
|
|
|
|
|
32
|
|
|
return PropertyView(self) |
|
33
|
|
|
|
|
34
|
|
|
@property |
|
35
|
|
|
def order(self): |
|
36
|
|
|
|
|
37
|
1 |
|
""" int: the order of the bond. """ |
|
38
|
|
|
|
|
39
|
|
|
return self.GetBondTypeAsDouble() |
|
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
@property |
|
42
|
|
|
def atoms(self): |
|
43
|
|
|
|
|
44
|
|
|
""" list[Atom]: list of atoms involved in the bond. """ |
|
45
|
1 |
|
|
|
46
|
|
|
return [Atom.from_super(self.GetBeginAtom()), Atom.from_super(self.GetEndAtom())] |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
def draw(self): |
|
49
|
|
|
|
|
50
|
|
|
""" str: Draw the bond in ascii. """ |
|
51
|
1 |
|
|
|
52
|
|
|
return '{}{}{}'.format(self.atoms[0].element, \ |
|
53
|
|
|
'-' if self.order == 1 else self.GetSmarts(), \ |
|
|
|
|
|
|
54
|
|
|
self.atoms[1].element) |
|
55
|
|
|
|
|
56
|
1 |
|
def to_dict(self): |
|
57
|
|
|
|
|
58
|
|
|
""" dict: Convert to a dictionary representation. """ |
|
59
|
|
|
|
|
60
|
|
|
return {"b": self.GetBeginAtomIdx(), "e": self.GetEndAtomIdx(), "o": self.order} |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
def __repr__(self): |
|
63
|
|
|
return '<{klass} type="{bond}" at {address}>'.format(klass=self.__class__.__name__, \ |
|
64
|
|
|
bond=self.draw(), \ |
|
65
|
|
|
address=hex(id(self))) |
|
66
|
|
|
|
|
67
|
|
|
def __str__(self): |
|
68
|
|
|
return self.draw() |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
class BondView(ChemicalObjectView): |
|
72
|
|
|
|
|
73
|
|
|
""" Bond interface wrapper """ |
|
74
|
|
|
def __getitem__(self, index): |
|
75
|
|
|
from .bond import Bond |
|
|
|
|
|
|
76
|
|
|
if index >= len(self): |
|
77
|
|
|
raise IndexError('Index {} out of range for molecule with {} bonds.'.format(index, len(self))) |
|
|
|
|
|
|
78
|
|
|
else: |
|
79
|
|
|
return Bond.from_super(self.owner.GetBondWithIdx(index)) |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
def __len__(self): |
|
83
|
|
|
return self.owner.GetNumBonds() |
|
84
|
|
|
|
|
85
|
|
|
@property |
|
86
|
|
|
def order(self): |
|
|
|
|
|
|
87
|
|
|
return pd.RangeIndex((bond.order for bond in self), index=self.index) |
|
88
|
|
|
|
|
89
|
|
|
@property |
|
90
|
|
|
def index(self): |
|
|
|
|
|
|
91
|
|
|
return pd.RangeIndex(len(self), name='bond_idx') |
|
92
|
|
|
|
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.