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 emptysubtitles (
Optional[Iterable[str]]) – Iterable of subtitle strings, one per frame (must match length of frames)interval (
int) – Delay between frames in millisecondsrepeat (
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 renderstyle (
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 sizesimage_size (
Tuple[int,int]) – Output image size (width, height)padding (
int) – Padding in pixels around the drawing regionupsample (
int) – Supersampling factor for antialiasingchainbreak (
int) – Distance threshold for breaking segmentsshadow (
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 separatelyc (
Optional[Iterable[ndarray]]) – Iterable of 1D arrays used to color the protein, aligned one-to-one withsegments; defaults to residue indexsizes (
Optional[Iterable[ndarray]]) – Iterable of 1D arrays of radii/size values, aligned one-to-one withsegments; interpreted in the same units as coordinatescmap (
str) – Color map name or callable used for coloring the proteincmin (
Optional[float]) – Minimum value for coloring, automatically calculated if Nonecmax (
Optional[float]) – Maximum value for coloring, automatically calculated if Noneimage_size (
Tuple[int,int]) – Final image size in pixels (width, height)padding (
int) – Padding in pixels around the drawing regionline_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 shadowsbackground_color (
Tuple[int,int,int]) – Background RGB colorupsample (
int) – Factor to draw at higher resolution and downsample for antialiasingchainbreak (
int) – Minimum distance in angstroms between chains / segments before being considered a chain break (int)
- Return type:
Image- Returns:
Pillow Image containing the rendering