epam / Indigo

Universal cheminformatics toolkit, utilities and database search tools
http://lifescience.opensource.epam.com
Apache License 2.0
318 stars 104 forks source link

How to Obtain the WASM Version of Indigo Toolkit for Web Use? #2360

Open SeungyulOh opened 2 months ago

SeungyulOh commented 2 months ago

Is it possible to convert the Indigo Toolkit to WebAssembly (WASM) for use on the web? I couldn't find any information related to WASM on the download page, but from the issues section, it seems like the Indigo Toolkit is being used in WASM format within Ketcher. How can I obtain the WASM-converted version of the Indigo Toolkit?

SeungyulOh commented 2 months ago

image

https://github.com/epam/Indigo/issues/2359

even1024 commented 2 months ago

You can build it from the source code. There is an instruction here: https://github.com/epam/Indigo/blob/master/README.md Check "How to build Indigo-WASM" section.

AliaksandrDziarkach commented 2 months ago

You can get it from NPM repository - https://www.npmjs.com/package/indigo-ketcher

SeungyulOh commented 2 months ago

You can get it from NPM repository - https://www.npmjs.com/package/indigo-ketcher

The package does not include all the features I need. For example, I want to declare an IndigoObject and implement the functionality to directly add atoms and bonds, as shown in the addAtom function. indigo.h

I have been able to use these functions successfully in Python, but I am curious if it is possible to use these features, such as the ones in [indigo.h] on the web.

SeungyulOh commented 2 months ago

You can build it from the source code. There is an instruction here: https://github.com/epam/Indigo/blob/master/README.md Check "How to build Indigo-WASM" section.

I was planning to try this approach. Specifically, I want to convert the indigo module and the indigo-render module into WebAssembly (WASM). Is this possible? From the instructions, it seems like only the contents in the indigo-ketcher folder are supported, and when I tried it, I was able to convert the contents of the indigo-ketcher folder into WASM. However, my goal is to use the indigo module and indigo-render module on the web.

Indigo module Indigo-renderer module

even1024 commented 2 months ago

"I want to convert the indigo module and the indigo-render module into WebAssembly (WASM)." - you can do that without a special wrapper which exports API to WASM. And you can see such wrapper in the indigo-ketcher. It exports the following list of functions to WASM:

EMSCRIPTEN_BINDINGS(module)
{
    emscripten::function("version", &version);
    emscripten::function("versionInfo", &versionInfo);
    emscripten::function("convert", &convert);
    emscripten::function("convert_explicit_hydrogens", &convert_explicit_hydrogens);
    emscripten::function("aromatize", &aromatize);
    emscripten::function("dearomatize", &dearomatize);
    emscripten::function("layout", &layout);
    emscripten::function("clean2d", &clean2d);
    emscripten::function("automap", &automap);
    emscripten::function("check", &check);
    emscripten::function("calculateCip", &calculateCip);
    emscripten::function("calculate", &calculate);
    emscripten::function("render", &render);
    emscripten::function("reactionComponents", &reactionComponents);

    emscripten::register_vector<int>("VectorInt");
    emscripten::register_map<std::string, std::string>("MapStringString");
};

If you want more functionality, you have to extend indigo-ketcher.cpp. There is no way to use indigo and indigo-renderer modules without an indigo-ketcher.cpp wrapper class. You will meet the same situation with any C++ library - you need a special wrapper to export what you need.

SeungyulOh commented 2 months ago

"I want to convert the indigo module and the indigo-render module into WebAssembly (WASM)." - you can do that without a special wrapper which exports API to WASM. And you can see such wrapper in the indigo-ketcher. It exports the following list of functions to WASM:

EMSCRIPTEN_BINDINGS(module)
{
    emscripten::function("version", &version);
    emscripten::function("versionInfo", &versionInfo);
    emscripten::function("convert", &convert);
    emscripten::function("convert_explicit_hydrogens", &convert_explicit_hydrogens);
    emscripten::function("aromatize", &aromatize);
    emscripten::function("dearomatize", &dearomatize);
    emscripten::function("layout", &layout);
    emscripten::function("clean2d", &clean2d);
    emscripten::function("automap", &automap);
    emscripten::function("check", &check);
    emscripten::function("calculateCip", &calculateCip);
    emscripten::function("calculate", &calculate);
    emscripten::function("render", &render);
    emscripten::function("reactionComponents", &reactionComponents);

    emscripten::register_vector<int>("VectorInt");
    emscripten::register_map<std::string, std::string>("MapStringString");
};

If you want more functionality, you have to extend indigo-ketcher.cpp. There is no way to use indigo and indigo-renderer modules without an indigo-ketcher.cpp wrapper class. You will meet the same situation with any C++ library - you need a special wrapper to export what you need.

If I want to use a function like indigoAddAtom in WASM, my understanding is that I need to create a corresponding wrapper function("new_function") in indigo-ketcher.cpp and then add it like this:

EMSCRIPTEN_BINDINGS(module)
{
    ...
    emscripten::function("new_function", &new_function);
};

Is this correct?