Quick Start =========== This guide will help you get started with CNotebook in just a few minutes. Basic Molecule Rendering ------------------------ The simplest way to use CNotebook is to import it and display molecules: .. code-block:: python import cnotebook from openeye import oechem # Create a molecule from SMILES mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, "c1ccccc1") mol.SetTitle("Benzene") # In a Jupyter/Marimo cell, simply display the molecule mol # Renders as a chemical structure Outputs: .. image:: _static/benzene.png :align: center That's it. CNotebook automatically registers formatters so that OpenEye molecule objects display as chemical structures instead of text representations. Working with DataFrames ----------------------- CNotebook integrates with Pandas and Polars DataFrames: **Pandas Example:** .. code-block:: python import cnotebook import oepandas as oepd import pandas as pd # Create a DataFrame with SMILES df = pd.DataFrame({ "Name": ["Benzene", "Pyridine", "Pyrimidine"], "SMILES": ["c1ccccc1", "c1cnccc1", "n1cnccc1"] }) # Convert SMILES to molecules df.chem.as_molecule("SMILES", inplace=True) # Display the DataFrame - molecules render automatically df Will output: .. raw:: html
Name SMILES
0 Benzene
1 Pyridine
  N
2 Pyrimidine
  N   N
**Polars Example:** .. code-block:: python import cnotebook import oepolars as oeplr import polars as pl # Create a DataFrame with SMILES df = pl.DataFrame({ "Name": ["Benzene", "Pyridine", "Pyrimidine"], "smiles": ["c1ccccc1", "c1cnccc1", "n1cnccc1"] }) # Convert SMILES to molecules df = df.chem.as_molecule("smiles") # Display the DataFrame - molecules render automatically df This will output the DataFrame using the default built-in Marimo table UI with pagination and all other capabilities. .. image:: _static/marimo_ui_dataframe.png :align: center Using MolGrid ------------- MolGrid provides an interactive grid for browsing molecules: .. code-block:: python from cnotebook import molgrid from openeye import oechem # Create molecules molecules = [] for smi in ["CCO", "c1ccccc1", "CC(=O)O"]: mol = oechem.OEGraphMol() oechem.OESmilesToMol(mol, smi) molecules.append(mol) # Display interactive grid grid = molgrid(molecules) grid.display() # Later, retrieve selected molecules selected = grid.get_selection() .. image:: _static/small_molgrid.png :align: center For more details, see the :doc:`molgrid` documentation. Customizing Rendering --------------------- You can customize rendering through the global context. Settings will automatically propogate down to rendering other objects such DataFrames, keeping rendering uniform. You can also use local rendering contexts as well. .. code-block:: python # Access the rendering context ctx = cnotebook.cnotebook_context.get() ctx.width = 300 ctx.height = 300 ctx.title_font_scale = 0.25 ctx.structure_scale = oedepict.OEScale_AutoScale .. image:: _static/benzene_scaled.png :align: center You can always reset the contex to default values with ``ctx.reset()``. Environment Support ------------------- Nearly all code in this package works seemlessly with `Pandas`_, `Polars`_, `Jupyter`_ and `Marimo`_. .. _Pandas: https://pandas.pydata.org/ .. _Polars: https://pola.rs/ .. _Jupyter: https://jupyter.org/ .. _Marimo: https://marimo.io/ Next Steps ---------- - :doc:`rendering` - Detailed rendering options and customization - :doc:`dataframes` - DataFrame integration guide - :doc:`molgrid` - Interactive molecule grid documentation - :doc:`api/index` - Full API reference