1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324
|
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="Author" content="greg Landrum">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<style>
h1,
h2,
h3,
h4 {
color: #044484;
}
</style>
</head>
<script src="./RDKit_minimal.js"></script>
<script>
onRuntimeInitialized: initRDKitModule().then(function (instance) {
RDKitModule = instance;
console.log('version: ' + RDKitModule.version());
});
</script>
<body>
<div class="container-fluid col-md-12">
<h1>Getting started with RDKit-JS</h1>
<h2>Drawing molecules</h2>
<p>First we'll work with an SVG drawing:
<div class="row">
<div class="col-sm-6">
<textarea id="example-1" cols="40" rows="5" wrap="off">
var smiles = "CC(=O)Oc1ccccc1C(=O)O";
var mol = RDKitModule.get_mol(smiles);
var dest = document.getElementById("example-1-output");
var svg = mol.get_svg();
dest.outerHTML = "<div id='drawing'>" + svg + "</div>";
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-1').value)" type="button" />
</div>
<div id="example-1-output" class="col-sm-6">
</div>
</div>
</p>
<p>As of v2020.09 of the RDKit we can do the same thing using the HTML5 canvas:
<div class="row">
<div class="col-sm-6">
<textarea id="example-2" cols="40" rows="5" wrap="off">
var smiles = "CC(=O)Oc1ccccc1C(=O)O";
var mol = RDKitModule.get_mol(smiles);
var canvas = document.getElementById("canvas-2");
mol.draw_to_canvas(canvas, -1, -1);
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-2').value)" type="button" />
</div>
<div id="example-2-output" class="col-sm-6">
<canvas id="canvas-2" width="250" height="200" >
</canvas>
</div>
</div>
</p>
<p>We can do substructure searches and highlight the results:
<div class="row">
<div class="col-sm-6">
<textarea id="example-3" cols="40" rows="5" wrap="off">
var smiles = "CC(=O)Oc1ccccc1C(=O)O";
var mol = RDKitModule.get_mol(smiles);
var smarts = "Oc1[c,n]cccc1";
var qmol = RDKitModule.get_qmol(smarts)
var mdetails = mol.get_substruct_match(qmol)
var canvas = document.getElementById("canvas-3");
mol.draw_to_canvas_with_highlights(canvas, mdetails);
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-3').value)" type="button" />
</div>
<div id="example-3-output" class="col-sm-6">
<canvas id="canvas-3" width="250" height="200">
</canvas>
</div>
</div>
</p>
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
<pre>
mol.draw_to_canvas_with_highlights(canvas, mdetails);
</pre>
with
<pre>
var svg = mol.get_svg_with_highlights(mdetails);
</pre>
<p>The same call can be used to control drawing options or to manually
set the atoms/bonds which should be highlighted:
<div class="row">
<div class="col-sm-6">
<textarea id="example-4" cols="40" rows="5" wrap="off">
var smiles = "CC(=O)Oc1ccccc1C(=O)O";
var mol = RDKitModule.get_mol(smiles);
var mdetails = {};
mdetails['atoms']=[0,1,10];
mdetails['explicitMethyl'] = true;
mdetails['addAtomIndices'] = true;
mdetails['legend']='aspirin';
var canvas = document.getElementById("canvas-4");
mol.draw_to_canvas_with_highlights(canvas, JSON.stringify(mdetails));
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-4').value)" type="button" />
</div>
<div id="example-4-output" class="col-sm-6">
<canvas id="canvas-4" width="250" height="200">
</canvas>
</div>
</div>
</p>
<p>and of course we can combine the two:
<div class="row">
<div class="col-sm-6">
<textarea id="example-5" cols="40" rows="5" wrap="off">
var smiles = "CC(=O)Oc1ccccc1C(=O)O";
var mol = RDKitModule.get_mol(smiles);
var smarts = "O=C";
var qmol = RDKitModule.get_qmol(smarts)
var mdetails = JSON.parse(mol.get_substruct_match(qmol));
mdetails['highlightColour'] = [1,0,1];
mdetails['legend']='aspirin';
var canvas = document.getElementById("canvas-5");
mol.draw_to_canvas_with_highlights(canvas, JSON.stringify(mdetails));
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-5').value)" type="button" />
</div>
<div id="example-5-output" class="col-sm-6">
<canvas id="canvas-5" width="250" height="200">
</canvas>
</div>
</div>
</p>
The currently supported options are:
<ol>
<li><tt>atoms</tt>,<tt>bonds</tt>: lists to specify which atoms/bonds are highlighted</li>
<li><tt>width</tt>,<tt>height</tt><tt>offsetx</tt>,<tt>offsety</tt>: used to
draw in a subregion of a canvas. Only supported by the HTML5 canvas
drawer.</li>
<li><tt>legend</tt>: the legend drawn under the molecule</li>
<li>These <tt>MolDrawOptions</tt> values: <tt>
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
</tt></li>
</ol>
<p>It's often useful to generate molecule renderings where the coordinates of a core are constrained.
<div class="row">
<div class="col-sm-6">
<textarea id="example-6" cols="40" rows="5" wrap="off">
var smiles = "c1cnc(C)nc1C(=O)O";
var mol = RDKitModule.get_mol(smiles);
var template = `
Mrv2014 10192005332D
0 0 0 0 0 999 V3000
M V30 BEGIN CTAB
M V30 COUNTS 6 6 0 0 0
M V30 BEGIN ATOM
M V30 1 C -5.7917 2.5817 0 0
M V30 2 N -7.1253 1.8117 0 0
M V30 3 C -7.1253 0.2716 0 0
M V30 4 C -5.7917 -0.4984 0 0
M V30 5 C -4.458 0.2716 0 0
M V30 6 N -4.458 1.8117 0 0
M V30 END ATOM
M V30 BEGIN BOND
M V30 1 1 1 2
M V30 2 2 2 3
M V30 3 1 3 4
M V30 4 2 4 5
M V30 5 1 5 6
M V30 6 2 1 6
M V30 END BOND
M V30 END CTAB
M END
`;
var qmol = RDKitModule.get_mol(template);
mol.generate_aligned_coords(qmol,true);
var tdetails = mol.get_substruct_match(qmol);
var canvas = document.getElementById("canvas-6");
mol.draw_to_canvas_with_highlights(canvas,tdetails);
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-6').value)" type="button" />
</div>
<div id="example-6-output" class="col-sm-6">
<canvas id="canvas-6" width="250" height="200">
</canvas>
</div>
</div>
</p>
<p><tt>get_mol</tt> can be passed a JSON dictionary of boolean options. Currently supported options are:
<tt>
sanitize,
kekulize,
removeHs,
mergeQueryHs
</tt>
<div class="row">
<div class="col-sm-6">
<textarea id="example-7" cols="40" rows="5" wrap="off">
var smiles = "[*:1]ccc[*:2]";
var mol = RDKitModule.get_mol(smiles, JSON.stringify({ kekulize: false }));
var canvas = document.getElementById("canvas-7");
mol.draw_to_canvas(canvas, -1, -1);
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-7').value)" type="button" />
</div>
<div id="example-7-output" class="col-sm-6">
<canvas id="canvas-7" width="250" height="200">
</canvas>
</div>
</div>
</p>
<p>The <tt>SubstructLibrary</tt> functionality is exposed to enable running fast substructure searches
taking advantage of pre-filtering through pattern fingerprints:
<div class="row">
<div class="col-sm-6">
<textarea id="example-8" cols="40" rows="5" wrap="off">
var sslib = new RDKitModule.SubstructLibrary();
var mol0 = RDKitModule.get_mol("Cc1cc(F)ccc1");
var mol1 = RDKitModule.get_mol("Clc1ccccn1");
sslib.add_trusted_smiles(mol0.get_smiles());
sslib.add_trusted_smiles(mol1.get_smiles());
var query = RDKitModule.get_mol(`
MJ201100 2D
6 6 0 0 0 0 0 0 0 0999 V2000
-1.0491 0.7134 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7635 0.3009 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7635 -0.5241 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.0491 -0.9366 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.3346 -0.5241 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.3346 0.3009 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2 3 1 0 0 0 0
5 6 2 0 0 0 0
1 2 2 0 0 0 0
6 1 1 0 0 0 0
3 4 2 0 0 0 0
4 5 1 0 0 0 0
M END`);
matches = JSON.parse(sslib.get_matches(query));
var canvas_query = document.getElementById("canvas-8-query");
query.draw_to_canvas_with_highlights(canvas_query, JSON.stringify({ legend: 'query' }));
var canvas_mol0 = document.getElementById("canvas-8-mol0");
mol0.draw_to_canvas_with_highlights(canvas_mol0, JSON.stringify({ legend: `mol0 matches: ${matches.includes(0)}` }));
var canvas_mol1 = document.getElementById("canvas-8-mol1");
mol1.draw_to_canvas_with_highlights(canvas_mol1, JSON.stringify({ legend: `mol1 matches: ${matches.includes(1)}` }));
</textarea>
<br /><input value="run" onclick="eval(document.getElementById('example-8').value)" type="button" />
</div>
<div id="example-8-output" class="col-sm-6">
<canvas id="canvas-8-query" width="150" height="150">
</canvas>
<canvas id="canvas-8-mol0" width="150" height="150">
</canvas>
<canvas id="canvas-8-mol1" width="150" height="150">
</canvas>
</div>
</div>
</p>
</div>
</body>
</html>
|