rdkit in javascript-2

The day before yesterday, I posted short code about rdkitjs.
Today I added some sample code in my github repo.
RDKitjs can draw molecule as svg using Drawing2D function.
So, I wrote javascript and embedded it to HTML.
Following code…
I used replace function in moldraw, because Drawing2D() function return svg:svg tag.
does not work in HTML.

<script type='text/javascript' src='/static/rdkit.js'></script>
function molwt( smi ){
	var mol = RDKit.Molecule.fromSmiles( smi );
	var mw = mol.getMW();
	document.getElementById( 'molwt' ).innerHTML = 'molweight===>>>'+ '  '+ mw;
function moldraw( smi ){
	var mol = RDKit.Molecule.fromSmiles( smi );
	var mol2d = mol.Drawing2D();
	var remol = mol2d.replace( /svg:/g, '' );
	document.getElementById( 'molimage' ).innerHTML = remol;

<h>rdkitjs test</h><br><br>

<form name='chemo'>
    Input smilestrings;<br> 
    	<textarea name='smi'></textarea>
    input smiles<br><br>
    	<input name='calc' value='cal' type='button' onClick='molwt( document.chemo.smi.value )'><br><br>
    show mol<br>
    	<input name='getimage' value='mouseover' type='button' onMouseover='moldraw( document.chemo.smi.value )'>

<div id='molwt'></div><br>
<div id='molimage'></div><br>


Run script, and access localhost.
Input smile strings and mouseover the button.
The function draw molecule. 😉


Screen Shot 2015-05-23 at 10.56.05 PM


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s