Thursday, 12 February 2015

cheminformatics.js: RDKit

Following on from the previous post, the second toolkit we'll look at is RDKit. Again, we want to convert RDKit to JavaScript and use it to depict SMILES in the browser.

And here's the result.

Here's how the sausage was made...

Compile RDKit with Emscripten

I used the latest RDKit release (2014-09-2). When configuring, the key insight is that by turning off every option, we don't need any boost libs. Yippee! I can see myself doing this more often in future...
~/Tools/cmake-3.1.2/bin/cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/noel/Tools/emscripten/cmake/Modules/Platform/Emscripten.cmake -DRDK_BUILD_PYTHON_WRAPPERS=OFF -DRDK_BUILD_CPP_TESTS=OFF -DRDK_BUILD_SLN_SUPPORT=OFF -DBoost_INCLUDE_DIR=/home/noel/Tools/boostinstall/include
make -j2

Add RDKit to a webpage

Create a webdepict.cpp file with the SmilesToSVG functionality and compile it by linking against RDKit. The following CMakeLists.txt may be useful:
  cmake_minimum_required(VERSION 3.0)
  include_directories(${RDKIT_INCLUDE_DIR} ${Boost_INCLUDE_DIR})
  add_executable(webdepict webdepict.cpp)
  target_link_libraries(webdepict ${RDKIT_LIBRARIES})
...which can be configured with...
export RDLIB=/home/noel/Tools/rdkit-2014-09-2/lib
  ~/Tools/cmake-3.1.2/bin/cmake .. -DCMAKE_TOOLCHAIN_FILE=/home/noel/Tools/emscripten/cmake/Modules/Platform/Emscripten.cmake -DRDKIT_INCLUDE_DIR=/home/noel/Tools/rdkit-2014-09-2/Code -DBoost_INCLUDE_DIR=/home/noel/Tools/boostinstall/include -DRDKIT_LIBRARIES=${RDLIB}/;${RDLIB}/;${RDLIB}/;$RDLIB/;${RDLIB}/"
If tested with nodejs, it will write out the SVG for a molecule.

Finally, as with the previous toolkit, modify the CMake build command to create the HTML page which we then edit as desired. Note that this time we need to turn on exception catching:
/home/noel/Tools/emscripten/em++ -O3 @CMakeFiles/webdepict.dir/objects1.rsp -o webdepict.html @CMakeFiles/webdepict.dir/linklibs.rsp -s EXPORTED_FUNCTIONS="['_SmilesToSVG']" -s DISABLE_EXCEPTION_CATCHING=0


guillaume godin said...

Hello Noel,

Great job!

Q: Did you use also ubuntu 14.04 for rdkit depict conversion to js ?


Noel O'Boyle said...

Yes indeed.

guillaume godin said...

Ok, on ubunut 14.04, I tried to compile with emscripten but I have issues with pthread_create (unresolved symbol) and boost_path.

I've received to compile rkdit with cmake 3.1.2 without any arguments (cmake ..).

any ideas ?

Noel O'Boyle said...

I've made a slight correction to the RDKit command-line. Should be RDKIT_BUILD_SLN_SUPPORT not RDK_BUILD_SLN_SUPPORT. Not sure if this helps you or not.

guillaume godin said...

Hello, It's working on MacOSX yosemite too!
cmake 3.2.2, python 2.7.9, emscripten + fastcomp compiled on the mac!

guillaume godin said...

Dear Noel,

I made some progress to wrap RDKit functions:

Do you want to contribute ?

best regards,


Noel O'Boyle said...

No time, I'm afraid.

Brian Kelley said...

Noel, Greg and I just reached out to Guillaume regarding emscripten and he kindly pointed us to your blog.

A few months, ago I made an RDKit fork which uses emscripten in the toolchain. (Great minds think alike,eh?) This allows compiling the SLN parser and actually running the regression tests under node as well.

The hard part is getting CMAKE to see the emscripten supplied boost libraries, but I can forward you a FindBoost.cmake that helps to fix this if necessary and if you are still interested (it looks like you may not have enough time these days!).

Anyway, nice work. If you have any thoughts about how an RDKit Javascript API should look, I'd love to hear them.

Noel O'Boyle said...

Nice. I did manage to figure out how to handle Boost when compiling Helium (see next post) but it was very hacky.

I won't be doing any more work on this, but I'm very interested to see where you guys take this. I'll add links from the top of this blog post to more recent work, for anyone who lands here.

And as for Javascript like jQuery? (A super useful comment I'm sure.)