Hi! Could anybody help with streamlit-ketcher that was introduced earlier this year. I’d love to see two features:
- Get current editor selection/highlighting from Ketcher, in addition to SMILES strings.
- Get modifications from the editor on each edit operation, not only when user presses “Apply” button.
The first feature would allow to use the component like the following:
smiles, selection = st_ketcher("CCC", molecule_format="SMILES")
Streamlit-ketcher has a similar open issue, but there are no replies there.
It looks like the following piece of code should be modified (github):
const smile =
moleculeFormat === FORMAT_SMILES
? await ketcher.getSmiles()
: await ketcher.getMolfile();
setMolecule(smile);
Streamlit.setComponentValue(smile);
And it looks from KetcherFunctions that there is ketcher.editor.selection()
that we can use:
getSelectedAtomId: function () {
const selection = ketcherInstance.editor.selection()
if (!selection?.atoms) {
return null
}
let atoms = selection.atoms.join(', ')
return atoms
},
How to properly return a tuple with smiles and selection to Streamlit?
The second feature looks like coming from this code:
<Button theme={theme!} onClick={handleApply} disabled={!ketcher}>
Apply
</Button>
Is it possible to register handleApply
to be triggered on every Ketcher editor action?