Rdkit: Java Wrapper Usage

Created on 6 Nov 2020  路  5Comments  路  Source: rdkit/rdkit

I'm trying to use the RDKit java Wrapper. I'm running Windows 10 with AdoptOpenJDK 11.0.9 in a IDEA IntelliJ environment. I tried to get insiparation from the Lucene (org.rdkit.lucene), NEO4J (neo4j-rdkit), KNIME (knime-rdkit) examples and I am always getting this error trying to canonicalize a SMILES representation with var csmiles = MolToSmiles(new SmilesMolSupplier(smiles).next()); in a simple java file :

java.lang.UnsatisfiedLinkError: 'long org.RDKit.RDKFuncsJNI.new_SmilesMolSupplier__SWIG_5(java.lang.String)'
    at org.RDKit.RDKFuncsJNI.new_SmilesMolSupplier__SWIG_5(Native Method)
    at org.RDKit.SmilesMolSupplier.<init>(SmilesMolSupplier.java:139)

All the native libraries have been put in the Maven POM file, in the java.library.path JVM argument. Nothing works. Where can I get some help? I took the jars and native libraries from the knime-rdkit repo and installed them with Maven as per the neo4j-rdkit repo instructions. I can see the Java code dependencies from Maven and use them. It just crashes at runtime. Using the neo4j-rdkit jars and native libraries give the same results. Thanks !

question

Most helpful comment

My problem was that I was calling System.loadLibrary("GraphMolWrap.dll") instead of System.loadLibrary("GraphMolWrap"). Problem fixed. And I have found code examples to bundle that into a jar. Might do an unofficial Maven distribution if I get to it later.

All 5 comments

And when I try to load the native lib using static { System.load("C:\\path\\to\\native\\os\\win32\\x86_64\\GraphMolWrap.dll"); }, I get this with the same call as above :

Error occured in aicrowd extraction loop :
org.RDKit.GenericRDKitException
    at org.RDKit.RDKFuncsJNI.new_SmilesMolSupplier__SWIG_5(Native Method)
    at org.RDKit.SmilesMolSupplier.<init>(SmilesMolSupplier.java:139)

I'm just trying to find a way to use the already compiled native libs and 2 jars from KNIME in my own application. This should work, right ?

Hi @contrebandeco,
I'm not 100% sure what is causing the specific problems you're having, but we can at least eliminate one problem by having you use the java wrappers correctly for your test.
A good place to look to find basics is in the tests for the Java wrappers. Here's one of those:
https://github.com/rdkit/rdkit/blob/master/Code/JavaWrappers/gmwrapper/src-test/org/RDKit/BasicMoleculeTests.java

The correct way to get the SMILES for a molecule is something like this:

String smiles="c1ccccc1";
var mol1 = RWMol.MolFromSmiles(smiles);
String smi = mol1.MolToSmiles();

For what it's worth, I just created the following simple java test program:

import org.RDKit.*;

class simple_demo {
public static void main(String args[]){
    System.loadLibrary("GraphMolWrap");
        System.out.println("Hello RDKit");
    String smiles = "c1ccccc1O";
        RWMol mol = RWMol.MolFromSmiles(smiles);
        System.out.println(mol.MolToSmiles());
}
}

put that in a directory containing org.RDKit.jar and GraphMolWrap.dll, compiled it with:

$ javac -classpath ./org.RDKit.jar simple_demo.java

and then ran it with;

$ java -classpath "./org.RDKit.jar;." simple_demo

and things worked fine on Windows 10.

Thanks. I confirm that I can make your use case work in a simple command line environment with the following files :

  1. org.RDKit.jar
  2. GraphMolWrap.dll

Which is good. But I am still unable to run it into Intellij and then from a production environment package. I will continue to investigate and post a solution here if I find one. Thanks again.

My problem was that I was calling System.loadLibrary("GraphMolWrap.dll") instead of System.loadLibrary("GraphMolWrap"). Problem fixed. And I have found code examples to bundle that into a jar. Might do an unofficial Maven distribution if I get to it later.

Was this page helpful?
0 / 5 - 0 ratings