After a bit more experimentation, I have something of an ugly hack that
works for a web page but won't work for a server app.  The issue is mostly
persuading the script to load the WASM file RDKit_minimal.wasm that
RDKit_minimal.js needs.  Greg's demo HTML files show how this can be done
in a web page, so I have left the importing of RDKit_minimal.js there, and
then used it via the window variable in the ReactJS components.  I have
RDKit_minimal.js and RDKit_minimal.wasm in my public folder in the react
app tree.

So, in index.html I have the line:

<script src="./RDKit_minimal.js"></script>

in between <body></body> and <head></head>.

In my React component I have:

constructor(props) {
    super(props);
    this.state = {
        rdkit: null,
    }
}

async componentDidMount() {
    let rdkit_mod = await window.initRDKitModule();
    this.setState({rdkit: rdkit_mod});
    console.log(this.state.rdkit.version());
}


I can then pass the rdkit instance into other components and functions
via the props as normal:

function DrawMol(props) {
    if (props.rdkit) {
        let mol = props.rdkit.get_mol(props.smiles);
        let svg = mol.get_svg();
        return (<div><img
src={`data:image/svg+xml;base64,${btoa(svg)}`} alt={''} /></div>);
    } else {
        return (<div>{props.smiles}</div>);
    }
}

I believe that node does have a WASM loader, and if I can work out how
to use that directly, I'll post a further reply.


Hopefully that all makes sense and might be helpful to other people.


Best,

Dave





On Wed, Apr 14, 2021 at 5:10 PM David Cosgrove <davidacosgrov...@gmail.com>
wrote:

> Hi,
>
> I have compiled the latest RDKit (2021_03_1) into .js and .wasm files
> using the Dockerfile in $RDBASE/Code/MinimalLib/docker.  I would like to
> use these in a reactjs app.  This appears to be non-trivial and after
> several days of googling and experimentation I am no further forward.  Has
> anyone had success with this that they can share?
>
> Thanks,
> Dave
>
>
> --
> David Cosgrove
> Freelance computational chemistry and chemoinformatics developer
> http://cozchemix.co.uk
>
>

-- 
David Cosgrove
Freelance computational chemistry and chemoinformatics developer
http://cozchemix.co.uk
_______________________________________________
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

Reply via email to