encodermap.plot package#

Submodules#

encodermap.plot.interactive_plotting module#

ToDo: * Check if vmd rendering works * Animate the path and the torsions inside the Interactive Plotting class. * ToolTip when hovering over buttons. * Path Tool. * Allow a path that selects closest points for points on path. Maybe do both for any given bezier/path path. * Allow autoencoder to be None. Catch the exception that tries to get autoencoder.trajs. * Superpose option with mdtraj not working * Keep the lasso select. * Movie along paths.

class encodermap.plot.interactive_plotting.InteractivePlotting(autoencoder, trajs=None, data=None, ax=None, align_string='name CA', top=None, hist=False, scatter_kws={'s': 5}, ball_and_stick=False, top_index=0)[source]#

Bases: object

Class to open up an interactive plotting window.

Contains sub-classes to handle user-clickable menus and selectors.

trajs#

The trajs passed into this class.

Type:

encodermap.TrajEnsemble

fig#

The figure plotted onto. If ax is passed when this class is instantiated the parent figure will be fetched with self.fig = self.ax.get_figure()

Type:

matplotlib.figure

ax#

The axes where the lowd data of the trajs is plotted on.

Type:

matplotlib.axes

menu_ax#

The axes where the normal menu is plotted on.

Type:

matplotlib.axes

status_menu_ax#

The axes on which the status menu is plotted on.

Type:

matplotlib.axes

pts#

The points which are plotted. Based on some other class variables the color of this collection is adjusted.

Type:

matplotlib.collections.Collection

statusmenu#

The menu containing the status buttons.

Type:

encodermap.plot.utils.StatusMenu

menu#

The menu containing the remaining buttons.

Type:

encodermap.plot.utils.Menu

tool#

The currentlty active tool used to select points. This can be lasso, polygon, etc…

Type:

encodermap.plot.utils.SelectFromCollection

mode#

Current mode of the statusmenu.

Type:

str

Examples

>>> sess = ep.InteractivePlotting(trajs)
__init__(autoencoder, trajs=None, data=None, ax=None, align_string='name CA', top=None, hist=False, scatter_kws={'s': 5}, ball_and_stick=False, top_index=0)[source]#

Instantiate the InteractivePlotting class.

Parameters:
  • trajs (encodermap.TrajEnsemble) – The trajs of which the lowd info should be plotted.

  • ax (matplotlib.axes, optional) – On what axes to plot. If no axes is provided a new figure and axes will be created defaults to None.

accept()[source]#
bezier()[source]#
property cluster_zoomed#
ellipse()[source]#
lasso()[source]#
property mode#
on_click(event)[source]#

Decides whether the release event happened in the drawing area or the menu.

Parameters:

event (matplotlib.backend_bases.Event) – The event provided by figure.canvas.connect().

on_click_menu(event)[source]#

Chooses the function to call based on what MenuItem was clicked.

Parameters:

event (matplotlib.backend_bases.Event) – The event provided by figure.canvas.connect().

on_click_tool(event)[source]#

Left here for convenience if some tools need a button release event.

on_enter_ax(event)[source]#

Chosses the tool to use when self.ax is entered, based on current mode.

Parameters:

event (matplotlib.backend_bases.Event) – The event provided by figure.canvas.connect().

on_leave_ax(event)[source]#

Disconnect the current tool.

path()[source]#
polygon()[source]#
rectangle()[source]#
render_move()[source]#
reset()[source]#

Called when ‘Reset’ is pressed.

set_points()[source]#

Called when ‘Set Points’ is pressed.

write()[source]#

Called when ‘Write’ is pressed.

encodermap.plot.jinja_template module#

This is a template for a README.md generated when a user writes a cluster to disk.

encodermap.plot.plotting module#

Convenience functions for Plotting.

Todo

  • Add interactive Plotting

  • Find a way to use interactive plotting with less points but still cluster everything.

encodermap.plot.plotting._zoomingBoxManual(ax1, ax2, color='red', linewidth=2, roiKwargs={}, arrowKwargs={})[source]#

Fakes a zoom effect between two mpl.axes.Axes.

Uses mpl.patches.ConnectionPatch and mpl.patches.Rectangle to make it seem like ax2 is a zoomed in version of ax1. Instead of defining the coordinates of the zooming rectangle The axes limits of ax2 are used.

Parameters:
  • ax1 (plt.axes) – The axes with the zoomed-out data.

  • ax2 (plt.axes) – The second axes with the zoomed-in data.

  • color (str) – The color of the zoom effect. Is passed into mpl, thus can be str, or tuple, … Defaults to ‘red’

  • linewidth (int) – The linewidth. Defaults to 2.

  • roiKwargs (dict) – Keyworded arguments for the rectangle. Defaults to {}.

  • arrowKwargs (dict) – Keyworded arguments for the arrow. Defaults to {}.

encodermap.plot.plotting.distance_histogram(data, periodicity, sigmoid_parameters, axes=None, low_d_max=5, bins='auto')[source]#

Plots the histogram of all pairwise distances in the data. It also shows the sigmoid function and its normalized derivative.

Parameters:
  • data (np.ndarray) – 2-dimensional numpy array. Columns should iterate over the dimensions of the datapoints, i.e. the dimensionality of the data. The rows should iterate over datapoints.

  • periodicity (float) – Periodicity of the data. Use float(“inf”) for non-periodic data.

  • sigmoid_parameters (tuple) – Tuple of sketchmap sigmoid parameters in shape (sigma, a, b).

  • axes (Union[np.ndarray, None], optional) – A numpy array of two matplotlib.axes objects or None. If None is provided, the axes will be created. Defaults to None.

  • low_d_max (int, optional) – Upper limit for plotting the low_d sigmoid. Defaults to 5.

  • bins (Union[str, int]. optional) – Number of bins for histogram. Use ‘auto’ to let matplotlib decide how many bins to use. Defaults to ‘auto’.

encodermap.plot.utils module#

Utils for plotting. Ideas and Code taken from the matplotlib documentation. Menu: https://matplotlib.org/3.1.0/gallery/widgets/menu.html LassoSelector: https://matplotlib.org/3.1.1/gallery/widgets/lasso_selector_demo_sgskip.html PolygonSelector: https://matplotlib.org/3.1.3/gallery/widgets/polygon_selector_demo.html Bezier: https://gist.github.com/gavincangan/b88a978e878e9bb1c0f8804e3af8de3c

encodermap.plot.utils.Bernstein(n, k)[source]#

Bernstein polynomial.

encodermap.plot.utils.Bezier(points, num=200)[source]#

Build Bézier curve from points.

class encodermap.plot.utils.BezierBuilder(control_polygon, ax_main, ax_bernstein=None)[source]#

Bases: object

Bézier curve interactive builder.

__init__(control_polygon, ax_main, ax_bernstein=None)[source]#

Constructor. Receives the initial control polygon of the curve.

_build_bezier()[source]#
_update_bernstein()[source]#
_update_bezier()[source]#
disconnect()[source]#
property ind#
class encodermap.plot.utils.DummyTool[source]#

Bases: object

disconnect()[source]#
class encodermap.plot.utils.Menu(ax, items=['Reset', 'Write', 'Set Points'])[source]#

Bases: object

add_items(items)[source]#
get_coords(no_items, gap_space=0.05)[source]#
on_move(event)[source]#
class encodermap.plot.utils.MenuItem(fig, xy, width, height, labelstr, props={}, hoverprops={}, on_select=None, standalone=False)[source]#

Bases: Rectangle, Artist

check_select(event)[source]#
draw(renderer)[source]#

Overwriting Base Class method to include labelstr

set(*, agg_filter=<UNSET>, alpha=<UNSET>, angle=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, axes=<UNSET>, bounds=<UNSET>, capstyle=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, data=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, height=<UNSET>, hover=<UNSET>, hover_props=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, x=<UNSET>, xy=<UNSET>, y=<UNSET>, zorder=<UNSET>)#

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: scalar or None angle: unknown animated: bool antialiased or aa: bool or None axes: unknown bounds: (left, bottom, width, height) capstyle: .CapStyle or {‘butt’, ‘projecting’, ‘round’} clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None color: color data: unknown edgecolor or ec: color or None facecolor or fc: color or None figure: unknown fill: bool gid: str hatch: {‘/’, ‘\’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’} height: unknown hover: unknown hover_props: unknown in_layout: bool joinstyle: .JoinStyle or {‘miter’, ‘round’, ‘bevel’} label: object linestyle or ls: {‘-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …} linewidth or lw: float or None mouseover: bool path_effects: .AbstractPathEffect picker: None or bool or float or callable rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: unknown url: str visible: bool width: unknown x: unknown xy: (float, float) y: unknown zorder: float

set_axes(axes)[source]#

Overwriting Base Class method to include labelstr

set_data(x, y)[source]#

Overwriting Base Class method to include labelstr

set_figure(figure)[source]#

Overwriting Base Class method to include labelstr

set_hover(event)[source]#

Check the hover status of MenuItem

set_hover_props(check)[source]#
set_transform(transform)[source]#

Overwriting Base Class method to include labelstr

class encodermap.plot.utils.ModeButton(*args, **kwargs)[source]#

Bases: MenuItem

_on_select_rotation()[source]#

Old function to rotate labelstrings.

check_select(event, overwrite=False)[source]#
set(*, agg_filter=<UNSET>, alpha=<UNSET>, angle=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, axes=<UNSET>, bounds=<UNSET>, capstyle=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, color=<UNSET>, data=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, fill=<UNSET>, gid=<UNSET>, hatch=<UNSET>, height=<UNSET>, hover=<UNSET>, hover_props=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, width=<UNSET>, x=<UNSET>, xy=<UNSET>, y=<UNSET>, zorder=<UNSET>)#

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: scalar or None angle: unknown animated: bool antialiased or aa: bool or None axes: unknown bounds: (left, bottom, width, height) capstyle: .CapStyle or {‘butt’, ‘projecting’, ‘round’} clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None color: color data: unknown edgecolor or ec: color or None facecolor or fc: color or None figure: unknown fill: bool gid: str hatch: {‘/’, ‘\’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’} height: unknown hover: unknown hover_props: unknown in_layout: bool joinstyle: .JoinStyle or {‘miter’, ‘round’, ‘bevel’} label: object linestyle or ls: {‘-’, ‘–’, ‘-.’, ‘:’, ‘’, (offset, on-off-seq), …} linewidth or lw: float or None mouseover: bool path_effects: .AbstractPathEffect picker: None or bool or float or callable rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None transform: unknown url: str visible: bool width: unknown x: unknown xy: (float, float) y: unknown zorder: float

set_hover(event)[source]#

Check the hover status of MenuItem

class encodermap.plot.utils.Props(**kwargs)[source]#

Bases: object

Class to contain the properties of MenuItems.

Each MenuItem contains two copies of this class. One for props when the mouse cursor hovers over them. One for the rest of times. Can be used used as class or as dict.

labelcolor#

The color of the text.

Type:

str

labelcolor_rgb#

The RGBA value of labelcolor.

Type:

tuple

bgcolor#

The color of the background.

Type:

str

bgcolor_rgb#

The RGBA value of bgcolor.

Type:

tuple

fontsize#

The fontsize.

Type:

int

alpha#

The alpha value of the background.

Type:

float

defaults#

Class Variable of default values.

Type:

dict

Examples

>>> props = Props()
>>> props.labelcolor
black
__init__(**kwargs)[source]#

Instantiate the Props class.

Takes a dict as input and overwrites the class defaults. The dict is directly stored as an attribute and can be accessed via dot-notation.

Parameters:

**kwargs – Dict containing values. If unknonwn values are passed they will be dropped.

_setattr(dictionary)[source]#
_string_summary()[source]#
property bgcolor_rgb#
defaults = {'alpha': 0.2, 'bgcolor': 'blue', 'fontsize': 15, 'labelcolor': 'black'}#
property labelcolor_rgb#
class encodermap.plot.utils.SelectFromCollection(ax, collection, alpha_other=0.3, selector=<class 'matplotlib.widgets.LassoSelector'>)[source]#

Bases: object

Select indices from a matplotlib collection using LassoSelector.

Selected indices are saved in the ind attribute. This tool fades out the points that are not part of the selection (i.e., reduces their alpha values). If your collection has alpha < 1, this tool will permanently alter the alpha values.

Note that this tool selects collection objects based on their origins (i.e., offsets).

Parameters:
  • ax (matplotlib.axes.Axes) – Axes to interact with.

  • collection (matplotlib.collections.Collection) – Subclass of collection you want to select from.

  • alpha_other (float) – To highlight a selection, this tool sets all selected points to an alpha value of 1 and non-selected points to alpha_other. Needs to fulfill 0 <= alpha_other <= 1

_string_summary()[source]#
disconnect()[source]#
onselect(verts)[source]#
class encodermap.plot.utils.StatusMenu(ax)[source]#

Bases: Menu

add_items(items)[source]#
on_click(event)[source]#
set_idle()[source]#

Sets the idle status. Called at __init__ and when nothing is pressed.

encodermap.plot.utils._check_all_templates_defined(template, info_dict)[source]#
encodermap.plot.utils._create_readme(main_path, now, info_dict)[source]#
encodermap.plot.utils._get_system_info()[source]#
encodermap.plot.utils._match_tops_and_trajs(min_topfiles, list_of_frames)[source]#
encodermap.plot.utils._unpack_cluster_info(trajs, main_path, selector, dummy_traj, align_string)[source]#
encodermap.plot.utils._unpack_path_info(path)[source]#
encodermap.plot.utils.abc_to_rgb(A=0.0, B=0.0, C=0.0)[source]#

Map values A, B, C (all in domain [0,1]) to suitable red, green, blue values.

encodermap.plot.utils.calculate_dssps(trajs, simplified=True)[source]#

Calculates dssp from TrajEnsemble.

Calculates dssps from ep.TrajEnsemble and returns a numpy array.

Parameters:
  • trajs (ep.TrajEnsemble) – The TrajEnsemble class to calculate the dssps from.

  • simplified (bool, optional) – Whether to return [H ,E, C] dssp values (True), or [H, B, E, G, I, T, S, ‘’] dssp values (False). Defaults to True.

Returns:

The dssp array of shape (trajs.n_frames, trajs.n_residues);

Return type:

np.ndarray

Todo

Make it work with different protein legths.

encodermap.plot.utils.correct_missing_uniques(uniques, sorted_, progbar=None)[source]#

Takes a list of DSSP letters and counts and adds zeros for all missing letters in sorted_.

Parameters:
  • uniques (list of np.ndarray) – A list of np.ndarrays. For every frame the DSSP letters and their respective counts should be provided. So for example [‘H’, 151] or [‘H’, ‘E’, 75, 76].

  • sorted (np.ndarray) – The sorted list of DSSP letters. This list will be used to update every frame. So The using [‘H’, ‘E’, ‘C’], the two examples from above will become [‘H’, ‘E’, ‘C’, 151, 0, 0] or [‘H’, ‘E’, ‘C’, 75, 76, 0], respectively.

  • progbar (tqdm) – A tqdm progbar. Defaults to None

Returns:

The corrected uniques.

Return type:

np.ndarray

encodermap.plot.utils.digitize_dssp(trajs, dssp, imshow=True, bins=100, progbar=None)[source]#

Digitizes the DSSP array

Module contents#