Skip to main content

RDKit and Raphael.js



The ChEMBL group had the honour of hosting the second RDKit UGM. It was a great way to catch up with the RDKit community, find out about what they are working and learn about new features the toolkit offers. We gave two talks during the meeting, so if you want to know how Clippy can make interacting with different chemical formats on your desktop easier, go here, and if you want to learn about wrapping RDKit up in a RESTful Web Service a.k.a. Beaker (to be described in future blog post), go here. Many discussions about new features RDKit could offer were had throughout the meeting and one which caught my attention was support for plotting compound images on HTML5 Canvas.

Unable to participate in a hackathon held on the final day, I set about hosting my own small hackathon during the weekend (only 1 attendee). The result of this weekend coding effect was a pull request made against RDKit github repo, introducing the new class called JSONCanvas.

Technical Details

As a general rule of the past, the model for generating image relies on the server to sending a binary representation of the compound (e.g. .png, .jpeg) to the client. With advances in browser technologies, it is now feasible to rely on the client to generate the graphical representation of the compound as it now has access to many methods, which allows it to handle geometrical primitives. It can decide if those primitives should be rendered as SVG, VML or even HTML5 Canvas (check out  Kinetic.js for HTML5 canvas rendering, as it knows how to draw some core shapes on canvas). 

My solution uses Raphael.js - a JavaScript library for drawing vector graphics in the browser. For displaying the graphic is uses SVG on browsers that support this format. On older browsers it will fail over to VML. In the library documentation we can find a very interesting method called Paper.add(). This method accepts JSON containing an array of geometrical objects (such as circle, rectangle, path) to be displayed and returns a handle for manipulating (moving, rotating, scaling) the object as a whole. This means that if we could create a JSON object, which uses shapes to represent a chemical compound, we could draw it or manipulate the compound directly. The new JSONCanvas class produces the previously described JSON object for any* given RDKit compound.

(*I am sure we might find a couple of exceptions)

But why?

1. Cost - reduced server processing required to raster image and often third-party drawing libraries are also required.

2. Bandwidth - reduced bandwidth required to transfer JSON representation of compounds. Also, as it  is text-based you can employ further compression (by configuring your server to send gziped JSON which most modern browsers understand) or using AMF.

3. Accuracy - improved scaling quality made possible with vector graphics.

4. Interactivity - compounds rendered using JSON on the client side can handle standard events such as click, hover, etc. Complex operations (animating, sorting, dragging,...), can also be applied to these objects.

Usage

As an example usage of this technique please look at our chemical game. To give you some idea of scale and performance the game loads 1000 compounds when page first loads. If you want to see raw example please explore source of my demo page. Other examples can involve:

1.  Online compound cloud (similar to tag cloud but with compound images instead of words). Such a cloud can be used to visualise compound similarity.

2. Compound stream - substructure search can sometimes return very large number of results. Such results can be represented as pseudo-infinite stream of compounds - only small portion of results is presented on the screen but scrolling down causes more results to be rendered when older one are discarded.

How can I use it?

1. You can download my fork or RDKit containing all relevant changes.

2. Today Greg Landrum, RDKit creator made his own branch containing modified version of the original pull request, so hopefully this is on it's way to be accepted in master branch in future.

As a group we are happy to participate in such a great open source library!

--
Michał

Comments

Popular posts from this blog

ChEMBL 34 is out!

We are delighted to announce the release of ChEMBL 34, which includes a full update to drug and clinical candidate drug data. This version of the database, prepared on 28/03/2024 contains:         2,431,025 compounds (of which 2,409,270 have mol files)         3,106,257 compound records (non-unique compounds)         20,772,701 activities         1,644,390 assays         15,598 targets         89,892 documents Data can be downloaded from the ChEMBL FTP site:  https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/releases/chembl_34/ Please see ChEMBL_34 release notes for full details of all changes in this release:  https://ftp.ebi.ac.uk/pub/databases/chembl/ChEMBLdb/releases/chembl_34/chembl_34_release_notes.txt New Data Sources European Medicines Agency (src_id = 66): European Medicines Agency's data correspond to EMA drugs prior to 20 January 2023 (excluding ...

SureChEMBL gets a facelift

    Dear SureChEMBL users, Over the past year, we’ve introduced several updates to the SureChEMBL platform, focusing on improving functionality while maintaining a clean and intuitive design. Even small changes can have a big impact on your experience, and our goal remains the same: to provide high-quality patent annotation with a simple, effective way to find the data you need. What’s Changed? After careful consideration, we’ve redesigned the landing page to make your navigation smoother and more intuitive. From top to bottom: - Announcements Section: Stay up to date with the latest news and updates directly from this blog. Never miss any update! - Enhanced Search Bar: The main search bar is still your go-to for text searches, still with three pre-filter radio buttons to quickly narrow your results without hassle. - Improved Query Assistant: Our query assistant has been redesigned and upgraded to help you craft more precise queries. It now includes five operator options: E...

ChEMBL webinar @ School of Chemoinformatics in Latin America

Recently, the ChEMBL team participated in the " School of Chemoinformatics in Latin America " which was kindly organized by José Medina-Franco and Karina Martinez-Mayorga (both at the National Autonomous University of Mexico). The event was very well attended with 1,181 registrants from 79 different countries. 57% of the participants attended from Latin America, 23% from Asia, and around 8% from Africa and Europe, respectively. 52% of the participants were students (undergraduate and graduate students). Distribution by country Distribution by role Participants could learn a bou t the ChEMBL database and UniChem. We covered different topics to answer these questions: • What is ChEMBL and how is it structured ? • Which data does ChEMBL contain ? • How is data extracted from scientic articles ? • How is the data in ChEMBL curated ? • How is drug ...

Here's a nice Christmas gift - ChEMBL 35 is out!

Use your well-deserved Christmas holidays to spend time with your loved ones and explore the new release of ChEMBL 35!            This fresh release comes with a wealth of new data sets and some new data sources as well. Examples include a total of 14 datasets deposited by by the ASAP ( AI-driven Structure-enabled Antiviral Platform) project, a new NTD data se t by Aberystwyth University on anti-schistosome activity, nine new chemical probe data sets, and seven new data sets for the Chemogenomic library of the EUbOPEN project. We also inlcuded a few new fields that do impr ove the provenance and FAIRness of the data we host in ChEMBL:  1) A CONTACT field has been added to the DOCs table which should contain a contact profile of someone willing to be contacted about details of the dataset (ideally an ORCID ID; up to 3 contacts can be provided). 2) In an effort to provide more detailed information about the source of a deposited dat...

Improvements in SureChEMBL's chemistry search and adoption of RDKit

    Dear SureChEMBL users, If you frequently rely on our "chemistry search" feature, today brings great news! We’ve recently implemented a major update that makes your search experience faster than ever. What's New? Last week, we upgraded our structure search engine by aligning it with the core code base used in ChEMBL . This update allows SureChEMBL to leverage our FPSim2 Python package , returning results in approximately one second. The similarity search relies on 256-bit RDKit -calculated ECFP4 fingerprints, and a single instance requires approximately 1 GB of RAM to run. SureChEMBL’s FPSim2 file is not currently available for download, but we are considering generating it periodicaly and have created it once for you to try in Google Colab ! For substructure searches, we now also use an RDKit -based solution via SubstructLibrary , which returns results several times faster than our previous implementation. Additionally, structure search results are now sorted by...