Completed
Push — master ( 1b49d8...c3d981 )
by Rich
17:58
created

BondView   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 0
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A order() 0 3 2
A __getitem__() 0 6 2
A index() 0 3 1
A __len__() 0 2 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
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)
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...
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()
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...
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())]
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...
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...
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(), \
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...
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}
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...
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
0 ignored issues
show
Comprehensibility Bug introduced by
Bond is re-defining a name which is already available in the outer-scope (previously defined on line 18).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
Bug introduced by
This module seems to import itself.
Loading history...
76
        if index >= len(self):
77
            raise IndexError('Index {} out of range for molecule with {} bonds.'.format(index, len(self)))
0 ignored issues
show
Coding Style introduced by
This line is too long as per the coding-style (106/100).

This check looks for lines that are too long. You can specify the maximum line length.

Loading history...
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):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
87
        return pd.RangeIndex((bond.order for bond in self), index=self.index)
88
89
    @property
90
    def index(self):
0 ignored issues
show
Coding Style introduced by
This method should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
91
        return pd.RangeIndex(len(self), name='bond_idx')
92