rdkit / rdkit-js

A powerful cheminformatics and molecule rendering toolbelt for JavaScript, powered by RDKit .
https://rdkitjs.com
BSD 3-Clause "New" or "Revised" License
143 stars 36 forks source link

Use rdkit-js as vanilla.js without wasm module #272

Open ninabina921 opened 1 year ago

ninabina921 commented 1 year ago

Do you have a version of rdkit-js that is strictly javascript that does not require a wasm-module? I currently use smiles-drawer, however it lacks many features that rdkit-js has.

MichelML commented 1 year ago

@ninabina921 unfortunately this is not possible as rdkit-js is built on top of the main rdkit package which is built in C++ and python, wasm is the necessary building block to offer rdkit in javascript, I will close this but feel free to comment with additional thoughts if this doesn't answer your question :+1:

Smiles-drawer is an alternative like you said, but it's indeed less powerful and flexible

ptosco commented 1 year ago

@ninabina921 In case this is still of interest, here: https://github.com/rdkit/rdkit-structure-renderer/blob/master/public/RDKit_minimal_plainJs.1.1.11.js you may find a vanilla JS version of the RDKit MinimalLib, which was compiled to plain JS with emscripten.

MichelML commented 1 year ago

@ptosco this is so great! Could we adapt the dockerfile to output the fully js-compiled file? What are the caveats compared to the wasm module approach? https://github.com/rdkit/rdkit-js/blob/master/Dockerfile . An example of your emscripten config to achieve this would be greatly appreciated. Any additional explanation would be more than welcome.

This is a big update and I think will allow newcomers to get started and use the library more easily since having a single js file makes it way more easy to import rdkit-js in modern front-end stacks.

Please give more context here, and if it's mature enough, I'll be happy to release the lib with the fully compiled js version.

Merry Christmas in advance!

ptosco commented 1 year ago

Yes, we can. Well, the main drawback is that performance is worse. The main plus is that it can be used in headless browsers like PhantomJS and Puppeteer.

MichelML commented 1 year ago

@ptosco can you share an example of the build command you use for that, basically an alternative to https://github.com/rdkit/rdkit-js/blob/master/Dockerfile#L50 to generate the vanilla js output?

ptosco commented 1 year ago

@MichelML You only need to add the following CMAKE_EXE_LINKER_FLAGS: --memory-init-file 0 -s WASM=0.

MichelML commented 1 year ago

Thank you, will try that!

bugzpodder commented 1 year ago

just trying to integrate the react version into nextjs and wasnt fun

I think what's in the README and the doc site isn't nearly enough to encapsulate these steps. Even when the demo react example is working it took some reverse engineering to actually get to the steps above ^^

MichelML commented 1 year ago

Thanks for the feedback @bugzpodder , this is something we are aware of. If you feel confident enough to make a PR to (minimally) improve the documentation based on your experience integrating the package in a react app, please help us make this project better :pray: . Otherwise, I'll do it in a near future :+1: .