Completed
Push — master ( 9a5d50...d0f258 )
by Rich
13:27 queued 06:27
created

Bond.is_in_ring()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 2
cts 2
cp 1
rs 9.4285
cc 1
crap 1
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 1
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
16 1
from .atom import Atom
17 1
from .base import ChemicalObject, PropertyView, ChemicalObjectView
18
19
20 1
class Bond(rdkit.Chem.rdchem.Bond, ChemicalObject):
21
22
    """
23
    Class representing a chemical bond in scikit-chem.
24
25
    """
26
27 1
    @property
28
    def atoms(self):
29
30
        """ tuple[Atom]: list of atoms involved in the bond. """
31
32 1
        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 1
            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 1
        return PropertyView(self)
50
51 1
    @property
52
    def order(self):
53
54
        """ int: the order of the bond. """
55
56 1
        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 1
        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 1
    @property
66
    def is_conjugated(self):
67
68
        """ bool: whether the bond is conjugated. """
69
70 1
        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
    def owner(self):
74
75
        """ skchem.Mol: the molecule this bond is a part of. """
76
77 1
        from .mol import Mol
78 1
        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
80 1
    @property
81
    def stereo_symbol(self):
82
83
        """ str: the stereo label of the bond ('Z', 'E', 'ANY', 'NONE') """
84
85 1
        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
87 1
    @property
88
    def is_in_ring(self):
89
90
        """ bool: whether the bond is in a ring. """
91
92 1
        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
94 1
    def draw(self):
95
96
        """ str: Draw the bond in ascii. """
97
98 1
        return '{}{}{}'.format(self.atoms[0].symbol,
99
                               '-' 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 1
    def to_dict(self):
103
104
        """ dict: Convert to a dictionary representation. """
105
106 1
        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 1
    def __repr__(self):
111 1
        return '<{klass} type="{bond}" at {address}>'.format(
112
            klass=self.__class__.__name__,
113
            bond=self.draw(),
114
            address=hex(id(self)))
115
116 1
    def __str__(self):
117 1
        return self.draw()
118
119
120 1
class BondView(ChemicalObjectView):
121
122
    """ Bond interface wrapper """
123 1
    def __getitem__(self, index):
124 1
        res = super(BondView, self).__getitem__(index)
125 1
        if res is None:
126 1
            if abs(index) >= len(self):
127 1
                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 1
            if index < 0:
132 1
                index += len(self)
133
134 1
            return Bond.from_super(self.owner.GetBondWithIdx(index))
135
136
        else:
137 1
            return res
138
139 1
    def __len__(self):
140 1
        return self.owner.GetNumBonds()
141
142 1
    @property
143
    def atom_idxs(self):
144
145
        """ The atom indices for the bonds in the view. """
146
147 1
        return np.array([atom.atom_idxs for atom in self])
148
149 1
    @property
150
    def order(self):
151
152
        """ np.array<int> the bond orders of the bonds in the view. """
153
154 1
        return np.array([bond.order for bond in self])
155
156 1
    @property
157
    def is_aromatic(self):
158
159
        """ np.array<bool> whether each of the bonds in the view are
160
        aromatic. """
161
162 1
        return np.array([bond.is_aromatic for bond in self])
163
164 1
    @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 1
        return np.array([bond.is_conjugated for bond in self])
171
172 1
    @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 1
        return np.array([bond.is_in_ring for bond in self])
179
180 1
    @property
181
    def stereo_symbol(self):
182
183
        """ np.array<str> the stereo symbol of the bonds in the view. """
184
185 1
        return np.array([bond.stereo_symbol for bond in self])
186
187 1
    @property
188
    def index(self):
189
190
        """ A `pd.Index` of the bonds in the `BondView`. """
191
192 1
        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