render
- cnotebook.render.create_img_tag(width, height, image_mime_type, image_bytes, wrap_svg=True)[source]
Create the <img> HTML tag for rendering image bytes. This could be either plain text (in the case of SVG) or base64 encoded (in binary format cases). :param width: Image width :param height: Image height :param image_mime_type: Image MIME type :param image_bytes: Image bytes :param wrap_svg: Wrap SVG in a specifically sized <div> tag for maximum control of size :return: Image tag
- cnotebook.render.oedisp_to_html(disp, *, ctx)[source]
Convert an OpenEye 2D molecule display object to HTML :param ctx: Current molecule render context :param disp: OpenEye 2D molecule display object :return: HTML image tag
- Parameters:
disp (OE2DMolDisplay)
ctx (CNotebookContext)
- Return type:
- cnotebook.render.render_empty_molecule(*, ctx)[source]
Render an image that says Empty Molecule :param ctx: Render context :return: Image tag
- Parameters:
ctx (CNotebookContext)
- Return type:
- cnotebook.render.render_invalid_molecule(*, ctx)[source]
Render an image that says Empty Molecule :param ctx: Render context :return: Image tag
- Parameters:
ctx (CNotebookContext)
- Return type:
- cnotebook.render.render_exceeds_max_heavy_atoms(mol, *, ctx)[source]
Render a placeholder image for molecules that exceed the heavy atom limit.
- Parameters:
mol (OEMolBase) – Molecule (used to retrieve the title).
ctx (CNotebookContext) – Render context.
- Returns:
HTML image tag.
- Return type:
- cnotebook.render.oemol_to_disp(mol, *, ctx)[source]
Convert a valid OpenEye molecule object to a display object for depiction. Note that it is highly recommended to test that the molecule is valid first before calling this function. :param ctx: Render context :param mol: Molecule to convert :return: Display object for depiction
- Parameters:
mol (OEMolBase)
ctx (CNotebookContext)
- Return type:
OE2DMolDisplay
- cnotebook.render.oemol_to_image(mol, *, ctx)[source]
Convert an OpenEye molecule to an OEImage.
Handles valid, empty, and invalid molecules. For valid molecules the molecule is rendered via
oemol_to_disp(). Empty and invalid molecules produce placeholder images with descriptive text.- Parameters:
mol (OEMolBase) – Molecule to convert.
ctx (CNotebookContext) – Render context.
- Returns:
Rendered image.
- Return type:
OEImage
- cnotebook.render.oedu_to_disp(du, *, ctx)[source]
Convert an OEDesignUnit to a 2D molecule display.
Extracts the ligand from the design unit and renders it as a 2D display. Returns
Noneif the design unit has no ligand (apo structure).Important
The returned ligand molecule must be kept alive as long as the display is in use. The
OE2DMolDisplayholds an internal C++ reference to the molecule; if the molecule is garbage-collected the display will crash when rendered.- Parameters:
du (OEDesignUnit) – Design unit to render.
ctx (CNotebookContext) – Render context.
- Returns:
Tuple of (display, ligand), or
Noneif no ligand.- Return type:
tuple[OE2DMolDisplay, OEGraphMol] | None
- cnotebook.render.oedu_to_image(du, *, ctx)[source]
Convert an OEDesignUnit to an OEImage.
If the design unit has a ligand, renders the ligand with a small “OEDesignUnit” label. If no ligand is present (apo structure), renders a placeholder image with “Apo DesignUnit” text.
- Parameters:
du (OEDesignUnit) – Design unit to render.
ctx (CNotebookContext) – Render context.
- Returns:
Rendered image.
- Return type:
OEImage
- cnotebook.render.oemol_to_html(mol, *, ctx)[source]
Convert an OpenEye molecule to HTML.
- Parameters:
mol (OEMolBase) – Molecule to convert.
ctx (CNotebookContext) – Render context.
- Returns:
HTML image tag.
- Return type:
- cnotebook.render.oedu_to_html(du, *, ctx)[source]
Convert an OEDesignUnit to HTML.
If the design unit has a ligand, renders the ligand with a small “OEDesignUnit” label. If no ligand is present (apo structure), renders a placeholder image with “Apo DesignUnit” text.
- Parameters:
du (OEDesignUnit) – Design unit to render.
ctx (CNotebookContext) – Render context.
- Returns:
HTML image tag.
- Return type:
- cnotebook.render.oeimage_to_html(image, *, ctx)[source]
Convert an OEImage to HTML :param ctx: Render context :param image: Image to render :return: HTML string
- Parameters:
image (OEImage)
ctx (CNotebookContext)
- Return type:
Rendering Functions
The render module provides core functions for converting OpenEye molecules
to HTML representations.
Key Functions
oemol_to_html
Convert an OpenEye molecule to an HTML representation (PNG or SVG image).
from cnotebook.render import oemol_to_html
from cnotebook.context import CNotebookContext
ctx = CNotebookContext(width=200, height=200, image_format="svg")
html = oemol_to_html(mol, ctx=ctx)
render_molecule
Render a molecule with optional SMARTS highlighting.
from cnotebook.render import render_molecule
# Basic rendering
render_molecule(mol)
# With SMARTS highlighting
render_molecule(mol, smarts="c1ccccc1")