Getting started with RDKit-JS

Drawing molecules

First we'll work with an SVG drawing:


As of v2020.09 of the RDKit we can do the same thing using the HTML5 canvas:


We can do substructure searches and highlight the results:


You can also change drawing options and do highlighting with the SVG renderer, but we don't show it here. You just need to replace
mol.draw_to_canvas_with_highlights(canvas, mdetails);
with
var svg = mol.get_svg_with_highlights(mdetails);

The same call can be used to control drawing options or to manually set the atoms/bonds which should be highlighted:


and of course we can combine the two:


The currently supported options are:
  1. atoms,bonds: lists to specify which atoms/bonds are highlighted
  2. width,heightoffsetx,offsety: used to draw in a subregion of a canvas. Only supported by the HTML5 canvas drawer.
  3. legend: the legend drawn under the molecule
  4. These MolDrawOptions values: atomLabelDeuteriumTritium, dummiesAreAttachments, circleAtoms, splitBonds, continuousHighlight, fillHighlights, highlightRadius, flagCloseContactsDist, includeAtomTags, clearBackground, legendFontSize, maxFontSize, minFontSize, annotationFontScale, fontFile, multipleBondOffset, padding, additionalAtomLabelPadding, noAtomLabels, bondLineWidth, scaleBondWidth, scaleHighlightBondWidth, highlightBondWidthMultiplier, prepareMolsBeforeDrawing, fixedScale, fixedBondLength, rotate, addAtomIndices, addBondIndices, isotopeLabels, dummyIsotopeLabels, addStereoAnnotation, atomHighlightsAreCircles, centreMoleculesBeforeDrawing, explicitMethyl, includeMetadata, includeRadicals, comicMode, variableBondWidthMultiplier, variableAtomRadius, includeChiralFlagLabel, simplifiedStereoGroupLabel, singleColourWedgeBonds

It's often useful to generate molecule renderings where the coordinates of a core are constrained.


get_mol can be passed a JSON dictionary of boolean options. Currently supported options are: sanitize, kekulize, removeHs, mergeQueryHs


The SubstructLibrary functionality is exposed to enable running fast substructure searches taking advantage of pre-filtering through pattern fingerprints: