cnotebook
CNotebook - Ergonomic chemistry visualization in notebooks.
Auto-detects available backends (Pandas/Polars) and environments (Jupyter/Marimo). Only requires openeye-toolkits; all other dependencies are optional.
- class cnotebook.LevelSpecificFormatter[source]
Bases:
FormatterA logging formatter that uses level-specific formats.
Uses a simple format for INFO and above, and includes the level name for DEBUG messages to help distinguish debug output.
- Variables:
NORMAL_FORMAT – Format string for INFO and above.
DEBUG_FORMAT – Format string for DEBUG level.
- NORMAL_FORMAT = '%(message)s'
- DEBUG_FORMAT = '%(levelname)s: %(message)s'
- format(record)[source]
Format the specified record as text.
The record’s attribute dictionary is used as the operand to a string formatting operation which yields the returned string. Before formatting the dictionary, a couple of preparatory steps are carried out. The message attribute of the record is computed using LogRecord.getMessage(). If the formatting string uses the time (as determined by a call to usesTime(), formatTime() is called to format the event time. If there is exception information, it is formatted using formatException() and appended to the message.
- class cnotebook.CNotebookEnvInfo(pandas_version, polars_version, ipython_version, marimo_version, molgrid_available, c3d_available, is_jupyter_notebook, is_marimo_notebook)[source]
Bases:
objectEnvironment information for CNotebook.
This class provides read-only access to detected backend and environment availability. A singleton instance is created at module load time and can be retrieved via
get_env().All properties are read-only to ensure consistency throughout the application lifecycle. Availability is determined by checking if the version string is non-empty.
- Parameters:
- __init__(pandas_version, polars_version, ipython_version, marimo_version, molgrid_available, c3d_available, is_jupyter_notebook, is_marimo_notebook)[source]
Create environment info (typically called once at module load).
- Parameters:
pandas_version (str) – Detected Pandas version string, or empty if unavailable.
polars_version (str) – Detected Polars version string, or empty if unavailable.
ipython_version (str) – Detected IPython version string, or empty if unavailable.
marimo_version (str) – Detected Marimo version string, or empty if unavailable.
molgrid_available (bool) – Whether MolGrid widget dependencies are available.
c3d_available (bool) – Whether C3D viewer dependencies are available.
is_jupyter_notebook (bool) – Whether running in a Jupyter notebook environment.
is_marimo_notebook (bool) – Whether running in a Marimo notebook environment.
- cnotebook.get_env()[source]
Get environment information for CNotebook.
Returns a singleton instance containing information about available backends and environments. The environment is detected once at module load time and the same object is returned on subsequent calls.
- Returns:
CNotebookEnvInfo instance with read-only properties.
- Return type:
Example:
env = cnotebook.get_env() if env.pandas_available: print(f"Pandas {env.pandas_version} is available")
- cnotebook.display(obj, ctx=None)[source]
Display an OpenEye molecule, display object, or DataFrame in the current notebook environment.
This function provides a unified way to display chemistry objects in both Jupyter and Marimo notebooks. It automatically detects the environment and uses the appropriate display mechanism.
- Parameters:
obj – Object to display. Can be: -
oechem.OEMolBase- OpenEye molecule -oedepict.OE2DMolDisplay- OpenEye display object -pandas.DataFrame- Pandas DataFrame (if pandas available) -polars.DataFrame- Polars DataFrame (if polars available)ctx (CNotebookContext | None) – Optional rendering context. Only applied to molecules and display objects, not DataFrames. If None, uses the global context.
- Returns:
A displayable object appropriate for the current environment.
- Raises:
TypeError – If the object type is not supported.
Example:
import cnotebook from openeye import oechem mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "c1ccccc1") # Display with default context cnotebook.display(mol) # Display with custom context ctx = cnotebook.cnotebook_context.get().copy() ctx.width = 300 ctx.height = 300 cnotebook.display(mol, ctx=ctx)
Package Overview
The cnotebook package provides automatic molecule rendering in Jupyter and
Marimo notebooks. Simply importing the package registers formatters for OpenEye
molecule objects.
Usage
import cnotebook
from openeye import oechem
mol = oechem.OEGraphMol()
oechem.OESmilesToMol(mol, "c1ccccc1")
mol # Automatically rendered as chemical structure
Module Attributes
- cnotebook.cnotebook_context
Global context variable for rendering configuration. Access the context using
cnotebook_context.get().
Environment Detection
Use the get_env() function to retrieve environment information:
import cnotebook
env = cnotebook.get_env()
if env.pandas_available:
print(f"Pandas {env.pandas_version} is available")