1 | #! /usr/bin/env python |
||
2 | # |
||
3 | # Copyright (C) 2016 Rich Lewis <[email protected]> |
||
4 | # License: 3-clause BSD |
||
5 | |||
6 | 1 | """ |
|
7 | ## skchem.vis.mol |
||
8 | |||
9 | Module for drawing molecules. |
||
10 | """ |
||
11 | |||
12 | 1 | from matplotlib import pyplot as plt |
|
0 ignored issues
–
show
|
|||
13 | 1 | from rdkit.Chem.Draw import DrawingOptions, MolToImage |
|
0 ignored issues
–
show
The import
rdkit.Chem.Draw could not be resolved.
This can be caused by one of the following: 1. Missing DependenciesThis 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 filesThis error could also result from missing ![]() |
|||
14 | 1 | from matplotlib.widgets import CheckButtons |
|
0 ignored issues
–
show
The import
matplotlib.widgets could not be resolved.
This can be caused by one of the following: 1. Missing DependenciesThis 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 filesThis error could also result from missing ![]() |
|||
15 | 1 | from mpl_toolkits.mplot3d import Axes3D # needed to get 3D |
|
0 ignored issues
–
show
The import
mpl_toolkits.mplot3d could not be resolved.
This can be caused by one of the following: 1. Missing DependenciesThis 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 filesThis error could also result from missing ![]() |
|||
16 | 1 | import numpy as np |
|
0 ignored issues
–
show
The import
numpy could not be resolved.
This can be caused by one of the following: 1. Missing DependenciesThis 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 filesThis error could also result from missing ![]() |
|||
17 | |||
18 | 1 | def draw(mol, quality=1, ax=None): |
|
0 ignored issues
–
show
The name
ax does not conform to the argument naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
19 | |||
20 | """Draw a molecule on a matplotlib axis. |
||
21 | |||
22 | Args: |
||
23 | mol (skchem.Mol): |
||
24 | The molecule to be drawn. |
||
25 | quality (int): |
||
26 | The level of quality. Higher quality takes more time, but will |
||
27 | look better (so long as matplotlib's savefig.dpi is high enough). |
||
28 | ax (plt.Axes or None): |
||
29 | An existing axis on which to draw the molecule. |
||
30 | |||
31 | Returns: |
||
32 | plt.AxesImage: |
||
33 | A matplotlib AxesImage object with the molecule drawn. |
||
34 | """ |
||
35 | |||
36 | if not ax: |
||
37 | ax = plt.gca() |
||
38 | ax.grid('off') |
||
39 | ax.axis('off') |
||
40 | |||
41 | opts = DrawingOptions() |
||
42 | opts.dotsPerAngstrom *= quality |
||
43 | opts.atomLabelFontSize *= quality |
||
44 | opts.bondLineWidth *= quality |
||
45 | |||
46 | size = 300 * quality |
||
47 | |||
48 | img, canvas, drawer = MolToImage(mol, size=(size, size), options=opts, |
||
0 ignored issues
–
show
|
|||
49 | returnCanvas=True) |
||
50 | canvas.flush() |
||
51 | return ax.imshow(img, extent=(0, 1, 0, 1)) |
||
52 | |||
53 | |||
54 | 1 | def _plot_sphere(pos=(0, 0, 0), radius=1., ax=None, **kwargs): |
|
0 ignored issues
–
show
The name
ax does not conform to the argument naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
55 | |||
56 | """ Plot a sphere. |
||
57 | |||
58 | Args: |
||
59 | pos tuple[float]: |
||
60 | the centre of the sphere. |
||
61 | radius (bool): |
||
62 | The radius of the sphere. |
||
63 | ax (plt.axes): |
||
64 | The axes to draw the sphere on (defaults to current axis). |
||
65 | |||
66 | Note: |
||
67 | Keyword args are passed to Axes3D.plot_surface. |
||
68 | """ |
||
69 | |||
70 | if ax is None: |
||
71 | ax = plt.gca() |
||
72 | |||
73 | u, v = np.mgrid[0:2 * np.pi:100j], np.mgrid[0:np.pi:100j] |
||
0 ignored issues
–
show
The name
u does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() The name
v does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
74 | |||
75 | x = 2 * radius * np.outer(np.cos(u), np.sin(v)) + pos[0] |
||
0 ignored issues
–
show
The name
x does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
76 | y = 2 * radius * np.outer(np.sin(u), np.sin(v)) + pos[1] |
||
0 ignored issues
–
show
The name
y does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
77 | z = 2 * radius * np.outer(np.ones(np.size(u)), np.cos(v)) + pos[2] |
||
0 ignored issues
–
show
The name
z does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
78 | |||
79 | return ax.plot_surface(x, y, z, **kwargs) |
||
80 | |||
81 | |||
82 | 1 | _skchem_mpl3d_check = None |
|
0 ignored issues
–
show
The name
_skchem_mpl3d_check does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
83 | |||
84 | |||
85 | 1 | def draw_3d(m, conformer_id=-1, label_atoms=None): |
|
0 ignored issues
–
show
The name
m does not conform to the argument naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
86 | |||
87 | """ Draw a molecule in three dimensions. |
||
88 | |||
89 | Args: |
||
90 | conformer_id (int): |
||
91 | The id of the conformer to draw. |
||
92 | label_atoms (bool): |
||
93 | Whether to label the atoms (this can be toggled in interactive |
||
94 | mode): |
||
95 | |||
96 | Returns: |
||
97 | plt.figure |
||
98 | |||
99 | Note: |
||
100 | This works great in the notebook with `%matplotlib notebook`. |
||
101 | """ |
||
102 | |||
103 | # required to stop widgets getting garbage collected |
||
104 | global _skchem_mpl3d_check |
||
0 ignored issues
–
show
The name
_skchem_mpl3d_check does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
105 | |||
106 | fig = plt.figure() |
||
107 | ax = fig.add_subplot(111, projection='3d') |
||
0 ignored issues
–
show
The name
ax does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
108 | |||
109 | pos = m.conformers[conformer_id].positions |
||
110 | |||
111 | for i, j in m.bonds.atom_idxs: |
||
112 | ax.plot(*[(pos[i, d], pos[j, d]) for d in range(3)], c='black', |
||
113 | zorder=1) |
||
114 | |||
115 | for atom, p in zip(m.atoms, pos): |
||
0 ignored issues
–
show
The name
p does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
116 | _plot_sphere(p, radius=0.25 * atom.covalent_radius, ax=ax, |
||
0 ignored issues
–
show
|
|||
117 | color=atom.hexcode, linewidth=0, zorder=10) |
||
118 | x, y, z = p + 0.2 |
||
0 ignored issues
–
show
The name
x does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() The name
y does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() The name
z does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
119 | labels = [ax.text(x, y, z, i, visible=False) for i, p in enumerate(pos)] |
||
120 | |||
121 | # set limits |
||
122 | lo, hi = min(pos.flatten()) - 1, max( |
||
0 ignored issues
–
show
The name
lo does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() The name
hi does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
123 | pos.flatten()) + 1.5 # 1.5 angstrom outside bording box |
||
124 | ax.set_xlim(lo, hi) |
||
125 | ax.set_ylim(lo, hi) |
||
126 | ax.set_zlim(lo, hi) |
||
127 | ax.set_aspect('equal') |
||
128 | |||
129 | ax.set_xlabel('x') |
||
130 | ax.set_ylabel('y') |
||
131 | ax.set_zlabel('z') |
||
132 | |||
133 | rax = plt.axes([0.15, 0.1, 0.1, 0.15]) |
||
134 | |||
135 | _skchem_mpl3d_check = CheckButtons(rax, ('show labels', 'show axes'), |
||
136 | (False, True)) |
||
137 | |||
138 | def toggle(label): |
||
0 ignored issues
–
show
This function 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. ![]() |
|||
139 | if label == 'show labels': |
||
140 | for l in labels: |
||
0 ignored issues
–
show
The name
l does not conform to the variable naming conventions ([a-z_][a-z0-9_]{2,30}$ ).
This check looks for invalid names for a range of different identifiers. You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements. If your project includes a Pylint configuration file, the settings contained in that file take precedence. To find out more about Pylint, please refer to their site. ![]() |
|||
141 | l.set_visible(not l.get_visible()) |
||
142 | |||
143 | if label == 'show axes': |
||
144 | ax._axis3don = not ax._axis3don # easiest way |
||
0 ignored issues
–
show
It seems like
_axis3don was declared protected and should not be accessed from this context.
Prefixing a member variable class MyParent:
def __init__(self):
self._x = 1;
self.y = 2;
class MyChild(MyParent):
def some_method(self):
return self._x # Ok, since accessed from a child class
class AnotherClass:
def some_method(self, instance_of_my_child):
return instance_of_my_child._x # Would be flagged as AnotherClass is not
# a child class of MyParent
![]() |
|||
145 | |||
146 | plt.draw() |
||
147 | |||
148 | _skchem_mpl3d_check.on_clicked(toggle) |
||
149 | |||
150 | return ax |
||
151 |
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__.py
files in your module folders. Make sure that you place one file in each sub-folder.