shnitsel.vis.datasheet.figures.structure#

Functions#

mol_to_png(mol[, width, height])

Helper function to plot an rdkit.Mol object as a 2D structural representation

mol_to_svg(mol[, width, height])

Helper function to plot an rdkit.Mol object as a 2D structural representation using vector graphics

format_inchi(inchi[, max_line_length])

Helper function to split an inchi string across

plot_structure(mol[, name, smiles, inchi, fig, ax])

Plot function to create a 2d structure representation of a molecule mol using rdkit and create a graph with

plot_pca_structure(frames, pca_data[, fig, axs])

Function to plot the most extreme pca combinations as structure plots.

Module Contents#

mol_to_png(mol, width=320, height=240)#

Helper function to plot an rdkit.Mol object as a 2D structural representation

Parameters:
  • mol (rdChem.Mol) – RDKit representation of the molecule to plot

  • width (int, optional) – Width of the canvas to plot to. Defaults to 320.

  • height (int, optional) – Height of the canvas to plot to. Defaults to 240.

Returns:

The drawn structure of the mol molecule in 2D as a sequence of bytes.

Return type:

bytes

mol_to_svg(mol, width=320, height=240)#

Helper function to plot an rdkit.Mol object as a 2D structural representation using vector graphics

Parameters:
  • mol (rdChem.Mol) – RDKit representation of the molecule to plot

  • width (int, optional) – Width of the canvas to plot to. Defaults to 320.

  • height (int, optional) – Height of the canvas to plot to. Defaults to 240.

Returns:

The drawn structure of the mol molecule in 2D as a sequence of bytes.

Return type:

bytes

format_inchi(inchi, max_line_length=30)#

Helper function to split an inchi string across multiple lines to not overlap other plots in the DataSheet pages.

Parameters:
  • inchi (str) – InChi string as generated by RDKit

  • max_line_length (int, optional) – Maximum line length. Defaults to 30 characters

Returns:

The string broken into multiple lines with inserted n characters.

Return type:

str

plot_structure(mol, name='', smiles=None, inchi=None, fig=None, ax=None)#

Plot function to create a 2d structure representation of a molecule mol using rdkit and create a graph with a 2d image representation into fig or ax with at least one of the two needing to be provided.

Parameters:
  • mol (rdChem.Mol) – The RDKit molecule object to visualize.

  • name (str, optional) – The name of the structure. Would be used as a plot title if not empty. Defaults to ‘’.

  • smiles (str | None, optional) – Smiles strings to include in the x-axis label. Defaults to None.

  • inchi (str | None, optional) – InChI strings to include in the x-axis label. Defaults to None.

  • fig (Figure | SubFigure | None, optional) – Figure to plot the graphic into if ax not provided. Defaults to None.

  • ax (Axes | None, optional) – Axis to plot the graphic into. Defaults to None, meaning they will be created from fig.

Returns:

The axes the graphic was plotted to.

Return type:

Axes

plot_pca_structure(frames, pca_data, fig=None, axs=None)#

Function to plot the most extreme pca combinations as structure plots.

Parameters:
  • frames (Frames | xr.Dataset) – The raw input data to use for extracting the positional data and structure.

  • pca_data (xr.DataArray) – PCA decomposition data.

  • fig (Figure | SubFigure, optional) – Figure to create axes into. If axs are provided, this can be left empty.

  • axs (dict[tuple[int,str],Axes] | None, optional) – Axes to plot the extrema to. One row per pca, one column for ‘min’ or ‘max’. Defaults to None.

Returns:

The axes the extrema have been plotted to.

Return type:

dict[tuple[int,str],Axes]