neurosnap.rendering module#

Provides functions and classes related to rendering, plotting, animating, and visualizing data.

neurosnap.rendering.animate_frames(frames, output_fpath, *, title='', subtitles=None, interval=200, repeat=True, background_color=(255, 255, 255))[source]#

Animate a sequence of frames using Pillow only and write to disk.

Parameters:
  • frames (Iterable[Union[Image, ndarray]]) – Iterable of frames to animate (Pillow Images or arrays convertible to images)

  • output_fpath (Union[str, Path]) – Path where the animation will be written; format inferred from extension (gif, webp, mp4)

  • title (str) – Title text to display above the animation; omit if empty

  • subtitles (Optional[Iterable[str]]) – Iterable of subtitle strings, one per frame (must match length of frames)

  • interval (int) – Delay between frames in milliseconds

  • repeat (bool) – Whether the animation repeats when the sequence of frames is completed (loop=0 if True else 1 for gif/webp; ignored for mp4)

  • background_color (Tuple[int, int, int]) – RGB background color used for the entire canvas (including title/subtitle band)

neurosnap.rendering.render_protein_pseudo3D(protein, *, style='residue_id', use_radii=False, image_size=(576, 432), padding=20, shadow=0.95, upsample=2, chainbreak=5)[source]#

Render a protein using the pseudo-3D Pillow renderer.

Parameters:
  • protein (Protein) – Protein to render

  • style (str) – Coloring mode (residue_id, chain_id, b-factor, pLDDT, residue_type)

  • use_radii (bool) – If True, apply van der Waals radii as per-atom sizes

  • image_size (Tuple[int, int]) – Output image size (width, height)

  • padding (int) – Padding in pixels around the drawing region

  • upsample (int) – Supersampling factor for antialiasing

  • chainbreak (int) – Distance threshold for breaking segments

  • shadow (float) – Shadow intensity between 0 and 1

Return type:

Image

Returns:

Pillow Image containing the rendering

neurosnap.rendering.render_pseudo3D(segments, *, c=None, sizes=None, cmap='gist_rainbow', cmin=None, cmax=None, image_size=(800, 800), padding=20, line_w=2.0, shadow=0.95, background_color=(255, 255, 255), upsample=2, chainbreak=5)[source]#

Plot the famous Pseudo 3D projection of a protein using Pillow.

Adapted from an algorithm originally written By Dr. Sergey Ovchinnikov.

Parameters:
  • segments (Iterable[Union[ndarray, DataFrame]]) – Iterable of XYZ coordinates, where each element is a segment/molecule to draw separately

  • c (Optional[Iterable[ndarray]]) – Iterable of 1D arrays used to color the protein, aligned one-to-one with segments; defaults to residue index

  • sizes (Optional[Iterable[ndarray]]) – Iterable of 1D arrays of radii/size values, aligned one-to-one with segments; interpreted in the same units as coordinates

  • cmap (str) – Color map name or callable used for coloring the protein

  • cmin (Optional[float]) – Minimum value for coloring, automatically calculated if None

  • cmax (Optional[float]) – Maximum value for coloring, automatically calculated if None

  • image_size (Tuple[int, int]) – Final image size in pixels (width, height)

  • padding (int) – Padding in pixels around the drawing region

  • line_w (float) – Line width (interpreted in data space; converted to pixels)

  • shadow (float) – Shadow intensity between 0 and 1 inclusive, lower numbers mean darker more intense shadows

  • background_color (Tuple[int, int, int]) – Background RGB color

  • upsample (int) – Factor to draw at higher resolution and downsample for antialiasing

  • chainbreak (int) – Minimum distance in angstroms between chains / segments before being considered a chain break (int)

Return type:

Image

Returns:

Pillow Image containing the rendering