Completed
Push — master ( 87dea9...e88bec )
by Rich
15:57
created

Bond.is_conjugated()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
ccs 1
cts 2
cp 0.5
rs 9.4285
cc 1
crap 1.125
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
0 ignored issues
show
Configuration introduced by
The import pandas could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
13 1
import rdkit.Chem
0 ignored issues
show
Configuration introduced by
The import rdkit.Chem could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
14
import numpy as np
0 ignored issues
show
Configuration introduced by
The import numpy could not be resolved.

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.

# .scrutinizer.yml
before_commands:
    - sudo pip install abc # Python2
    - sudo pip3 install abc # Python3
Tip: We are currently not using virtualenv to run pylint, when installing your modules make sure to use the command for the correct version.

2. Missing __init__.py files

This error could also result from missing __init__.py files in your module folders. Make sure that you place one file in each sub-folder.

Loading history...
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()),
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetBeginAtom.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
33
                Atom.from_super(self.GetEndAtom()))
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetEndAtom.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetBeginAtomIdx.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
Bug introduced by
The Instance of Bond does not seem to have a member named GetEndAtomIdx.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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)
0 ignored issues
show
Coding Style introduced by
The attribute _props was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
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()
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetBondTypeAsDouble.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
57
58 1
    @property
59
    def is_aromatic(self):
60
61
        """ bool: whether the bond is aromatic. """
62
63
        return self.GetIsAromatic()
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetIsAromatic.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
64
65
    @property
66 1
    def is_conjugated(self):
67
68
        """ bool: whether the bond is conjugated. """
69
70
        return self.GetIsConjugated()
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetIsConjugated.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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())
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetOwningMol.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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')
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetStereo.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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()
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named IsInRing.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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(),
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetSmarts.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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(),
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetBeginAtomIdx.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
107
                "e": self.GetEndAtomIdx(),
0 ignored issues
show
Bug introduced by
The Instance of Bond does not seem to have a member named GetEndAtomIdx.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
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']
0 ignored issues
show
Bug introduced by
Undefined variable name 'AtomView' in __all__
Loading history...
195