polars_ext

Polars DataFrame Accessor

The chem accessor provides chemistry-aware operations on Polars DataFrames and Series containing molecule columns. Install oepolars>=0.3.0 to use the current CNotebook-supported Polars extension types.

Usage

import cnotebook
import polars as pl
import oepolars as oeplr

# The accessor is automatically registered when cnotebook is imported
df = pl.DataFrame({"smiles": ["CCO", "c1ccccc1"]})

# Convert SMILES to molecules
df = df.chem.as_molecule("smiles")

# Highlight substructures
df.get_column("smiles").chem.highlight("c1ccccc1")

# Align depictions
df.get_column("smiles").chem.align_depictions("first")

DataFrame Methods

DataFrame.chem.as_molecule(column)

Convert a SMILES column to molecules.

Returns:

New DataFrame with molecules

DataFrame.chem.highlight_using_column(mol_col, pattern_col)

Highlight substructures using patterns from another column.

Returns:

New DataFrame with highlighted molecules

DataFrame.chem.fingerprint_similarity(mol_col, reference)

Color molecules by fingerprint similarity to a reference.

Returns:

New DataFrame with similarity coloring

Series Methods

Series.chem.highlight(smarts)

Highlight a SMARTS pattern in the molecule column.

Series.chem.align_depictions(reference)

Align molecule depictions to a reference.