Skip to content

Jhsmit/ipyketcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ipyketcher

Ipyketcher is a widget implementation of the Ketcher chemical structure editor for use in Jupyter notebooks and other environments supporting ipywidgets. image_example

How to use

from ipyketcher import KetcherEditor

editor = KetcherEditor(
    initial_molecule="OCC",
    return_formats=["smiles", "molfile"],
)

editor

You can now draw a structure, and access the currently drawn molecule in smiles or molfile format via editor.smiles or editor.molfile.

Other supported formats are: 'rxn', 'ket', 'smarts', 'cml', 'sdf', 'cdxml', 'cdx', 'inchi', 'inchi_key'. Set the format you want synchronized back to Python using the return_formats parameter, and observe the output via the corresponding attribute on the KetcherEditor instance.

The example.ipynb has a more elaborate exmaple of usage with RDKit integration.

Installation

pip install ipyketcher

or with uv:

uv add ipyketcher

Development

We recommend using uv for development. It will automatically manage virtual environments and dependencies for you.

uv run jupyter lab example.ipynb

Alternatively, create and manage your own virtual environment:

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
jupyter lab example.ipynb

The widget front-end code bundles it's JavaScript dependencies. After setting up Python, make sure to install these dependencies locally:

npm install

While developing, you can run the following in a separate terminal to automatically rebuild JavaScript as you make changes:

npm run dev

Open example.ipynb in JupyterLab, VS Code, or your favorite editor to start developing. Changes made in js/ will be reflected in the notebook.

Creating a new release:

  1. Bump the version in pyproject.toml.
  2. Create a new git tag with the version.
  3. Build and upload the package to PyPI:
npm build
hatch build
hatch publish -u __token__ -a pypi-<your-token>

Hot reloading

Set anywidget hot reloading on windows:

set ANYWIDGET_HMR=1

Resources

About

Ketcher editor as anywidget

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors