PyScript demo with Ketcher and Rdkit.js

Ketcher window

Access JavaScript elements from python

Run this cell to add molecule to the drawing board and get its smiles back To run cell, click on it and press Shift+Enter. import js import asyncio async def get_smiles(): ketcherFrame = js.document.getElementById('ifKetcher') ketcher = ketcherFrame.contentWindow.ketcher await ketcher.setMolecule("CN1C=NC2=C1C(=O)N(C(=O)N2C)C") return await ketcher.getSmiles() asyncio.ensure_future(get_smiles()) smiles = asyncio.ensure_future(get_smiles()) smiles

Run this cell to convert ketcher smiles to rdkit smiles with rdkit.js mol = js.RDKitModule.get_mol(smiles.result()) mol.get_smiles()

There are many more Ketcher and Rdkit.js javascript methods. Refer to their documentation for more info:

How it works

You can read anacondas announcement on what is PyScript. Essentially it's python that runs in the browser. Important that it's not python translated to javascript, but it's actual python compiled for browser.

PyScript was created in such a way that you can easily use python functions in JavaScript and parts of JavaScript in python.

In this gist you can find how to set up ketcher and PyScript for local development.