Giter VIP home page Giter VIP logo

jna-inchi's Introduction

Maven Central Javadoc MIT license Build Status

JNA-InChI

Wrapper to access InChI and RInchI from Java. This wraps the latest version of InChI (1.06) and RInChI (1.00) using JNA. A simple native Java interface can then be used to call InChI. Java 8 or higher is required. Detailed information about the capabilities and limitations when converting from and to RInChI can be found in the io.github.dan2097.jnarinchi package documentation.

Examples

Mol file to StdInChI

InchiOutput output = JnaInchi.molToInchi(molText);
if (output.getStatus() == InchiStatus.SUCCESS || output.getStatus() == InchiStatus.WARNING) {
  String inchi = output.getInchi();
}

SMILES to StdInChI

InchiOutput output = SmilesToInchi.toInchi(smiles);
if (output.getStatus() == InchiStatus.SUCCESS || output.getStatus() == InchiStatus.WARNING) {
  String inchi = output.getInchi();
}

InChI to InChIKey

InchiKeyOutput output = JnaInchi.inchiToInchiKey(inchi);
if (output.getStatus() == InchiKeyStatus.OK) {
  String inchiKey = output.getInchiKey();
}

Custom molecule to StdInChI

InchiInput inchiInput = new InchiInput();
inchiInput.addAtom(atom);
inchiInput.addBond(bond);
inchiInput.addStereo(stereo);
InchiOutput output = JnaInchi.toInchi(inchiInput);

Reaction file to RInChI

RinchiOutput rinchiOutput = JnaRinchi.fileTextToRinchi(reactionFileText);
if (rinchiOutput.getStatus() == Status.SUCCESS || rinchiOutput.getStatus() == Status.WARNING) {
  String rinchi = rinchiOutput.getRinchi();
}

RInChI to RInChIKey-Long

RinchiKeyOutput rinchiKeyOutput = JnaRinchi.fileTextToRinchiKey(reactionFileText, RinchiKeyType.LONG);
if (rinchiKeyOutput.getStatus() == Status.SUCCESS) {
  String longRinchiKey = rinchiKeyOutput.getRinchiKey();
}

Decompose RInChI into its constituent InChIs (and associated AuxInfo if any)

RinchiDecompositionOutput rinchiDecompositionOutput = JnaRinchi.decomposeRinchi(rinchi, rauxInfo);
if (rinchiDecompositionOutput.getStatus() == Status.SUCCESS) {
  String[] inchis = rinchiDecompositionOutput.getInchis();
  String[] auxInfos = rinchiDecompositionOutput.getAuxInfos();
}

Supported platforms

InChI and RInChI are C libraries and hence require platform-specific binaries. The following table lists the availability of the binaries for specific platforms. Pull requests for other platforms are welcome.

Platform InChI RInChI
Linux x86 Yes Yes
Linux x86-64 Yes Yes
Linux ARM Yes Yes
Linux ARM64 Yes No
Mac x86-64 Yes No
Mac ARM64 Yes No
Windows x86 Yes Yes
Windows x86-64 Yes Yes

Maven artifacts

The simplest way to use the library is with:

<dependency>
  <groupId>io.github.dan2097</groupId>
  <artifactId>jna-inchi-all</artifactId>
  <version>1.2.1</version>
</dependency>

which includes binaries for most common platforms, support for converting SMILES to InChI/InChIKey and MDL RDfile and RXN to RInChI/RInChIKey.

If you don't need SMILES to InChI support, RInChI support, or do not require support for all platforms, the dependency size can be reduced by only including the required modules.

Artifact Description
jna-inchi-all Includes all artifacts
jna-inchi-smiles JNA-InChI API with SMILES to InChI support
jna-inchi-core JNA-InChI API with binaries for all platforms
jna-inchi-api JNA-InChI API
jna-inchi-darwin-aarch64 InChI 64-bit ARM Mac support
jna-inchi-darwin-x86-64 InChI 64-bit Intel Mac support
jna-inchi-linux-aarch64 InChI 64-bit ARM Linux support e.g. Apple M1
jna-inchi-linux-arm InChI 32-bit ARM Linux support e.g. Raspberry Pi
jna-inchi-linux-x86 InChI 32-bit Linux support
jna-inchi-linux-x86-64 InChI 64-bit Linux support
jna-inchi-win32-x86 InChI 32-bit Windows support
jna-inchi-win32-x86-64 InChI 64-bit Windows support
jna-rinchi-core JNA-RInChI API with binaries for Windows and Linux
jna-rinchi-linux-arm RInChI 32-bit ARM Linux support e.g. Raspberry Pi
jna-rinchi-linux-x86 RInChI 32-bit Linux support
jna-rinchi-linux-x86-64 RInChI 64-bit Linux support
jna-rinchi-win32-x86 RInChI 32-bit Windows support
jna-rinchi-win32-x86-64 RInChI 64-bit Windows support

For example, jna-inchi-core omits SMILES support. If you only need 64-bit linux support, depending on if SMILES support was desired, you would choose jna-inchi-smiles + jna-inchi-linux-x86-64, or jna-inchi-api + jna-inchi-linux-x86-64

License

This project is licensed under the GNU Lesser General Public License v2.1 or later

jna-inchi's People

Contributors

ntk73 avatar dan2097 avatar uli-f avatar mjw99 avatar johnmay avatar kerberizer avatar

Stargazers

この中二病に爆焔を! avatar  avatar Markus Fleischauer avatar  avatar  avatar Sam avatar Egon Willighagen avatar  avatar Matt Swain avatar

Watchers

Xin Wang avatar  avatar  avatar  avatar

jna-inchi's Issues

DataSGroups

I have an issue with DataSGroups. In my environment (accessing inchi.dll via old C interface) I always get valid output. With jna-inchi, I get only valid output without DataSGroups. Is this an issue on my side or can you reproduce this behaviour?
test_IXA_DataSGroup.mol.txt
test_IXA.mol.txt

Incorrect SMILES to InChI allenal stereochemistry handling

In an allenal system e.g. AB(A')=C=D(E)E', the original InChI API uses A,B,D,E as reference atoms. However the IXA API uses A,A',E,E'. This does better capture that the system is effectively an extended tetrahedran.

The SMILES to InChI input incorrectly assumes the former convention. This needs to be fixed and documented as to what the expected behaviour is. Adding static convenience methods to construct appropriate InchiStereo objects for double bond/tetrahedral/allenal stereo may help.

The case where a reference atom is an implicit hydrogen needs to be handled.

Cleaner InChI mass interaction/API quality of life

Since InChI stores mass as a delta you need to know what the base line it is a delta from. The InChI API (and by extension JNA InChI) is asymmetric in that you pass in an exact mass and get a "isotopic shift" out - the caller then needs to translate this to something sane. I think perhaps it accepts both an exact 'mass number' or a 'isotopic shift' on input so it's not quite asymmetric but I believe it always gives an 'isotopic shift' on output.

I've just fixed the issue in CDK and found the table in the INCHI-BASE directory:
cdk/cdk#936. It would also be possible to derive the table by round-tripping in enough values.

I wonder if doing the translation in JNA InChI would be reasonable and a more usable API?

JNAInchi and OSGi

I have a cheminformatics app for Cytoscape called chemViz that uses CDK. I was very excited to see that CDK was moving to use JNAInchi, but I have been unable to make it work with OSGi. The problem is that the native code is not on a classpath since it's part of the OSGi bundle. I can load native code using OSGi's implementation of System.loadLibrary(), which is bundle-aware, but System.load is not bundle aware, so JNA can't find the native modules. Do you have anyone who has successfully used JNAInchi in an OSGi setting?

GPL?

Noel pointed me here, looks cool but any reason for the GPL, wouldn't a better option just be to use the InChI license?

Achieve performance parity with JNI-InChI

Type mapping incurrs a performance penalty with JNA. ~15% performance gains are achievable by using Pointer rather than subclasses of PointerType, and by using byte[] rather than String.

Failure to generate InChI for stereo molecule with JNA 5.13.0 and later

We have a project that uses jna-inchi version 1.2. We recently added a new dependency to our project, which caused the indirect dependency on JNA to be updated from version 5.12.1 to 5.13.0. This change caused jni-inchi to break: some molecules for which an InChI was succesfully generated with JNA 5.12.1 now fail with the error message 'Atom ID is invalid'. The problem seems to affect molecules with stereochemistry. The same problem is exhibited with the latest version of JNA, 5.14.0.

We've found that we can work around the problem by replacing the dummy vertices with the actual indices in the DoubleBond case statement of the JnaInchi.addStereos(...) method, but we can't see how this fix works because we don't have access to the C code of jna-inchi's native methods. If you think it might take a while for you to investigate this problem, we'd appeciate it if you would make the code of the native methods available to us so that we can investigate the problem ourselves. Then, if we're able to find a fix, we'll make a pull request.

The following code fragment illustrates the problem:

InchiInput input = new InchiInput();

InchiAtom atom0 = new InchiAtom("F");
input.addAtom(atom0);

InchiAtom atom1 = new InchiAtom("C");
atom1.setImplicitHydrogen(1);
input.addAtom(atom1);

InchiAtom atom2 = new InchiAtom("C");
atom2.setImplicitHydrogen(1);
input.addAtom(atom2);

InchiAtom atom3 = new InchiAtom("Cl");
input.addAtom(atom3);

input.addBond(new InchiBond(atom0, atom1, InchiBondType.SINGLE));
input.addBond(new InchiBond(atom1, atom2, InchiBondType.DOUBLE));
input.addBond(new InchiBond(atom2, atom3, InchiBondType.SINGLE));

input.addStereo(InchiStereo.createDoubleBondStereo(atom0, atom1, atom2, atom3, InchiStereoParity.ODD));

InchiOutput output = JnaInchi.toInchi(input);
System.out.println(output.getStatus() + "  " + output.getMessage());

For version 5.12.1, the output is
SUCCESS

For version 5.13.0, the output is
ERROR Atom ID is invalid

Runtime exception within Tomcat

This is more of a question than anything else.
I recently modified a Java 8 application to use jna-inchi. It works fine locally but when called from a servlet running under Tomcat, there is an exception:
java.lang.NoClassDefFoundError: Could not initialize class io.github.dan2097.jnainchi.inchi.InchiLibrary

First noticed this error on my Windows laptop and was able to get rid of the error by extracting the appropriate dll from the platform-specific JAR (jna-inchi-win32-x86-64-1.0.1.jar) and copying it to tomcat/bin.
On the production Linux server, the same strategy didn't work. (Extracted and copied the .so file from the corresponding JAR files to tomcat/bin.)

So, what I'm looking to find out: has anyone else come across the java.lang.NoClassDefFoundError: Could not initialize class io.github.dan2097.jnainchi.inchi.InchiLibrary when running an application that uses jna-inchi under Tomcat on Linus? How do you avoid the error?

Maven Central?

Is the module available from Maven Central? I do not seem to be able to find it. If not, can you please consider uploading it there?

Version 1.06

Do you think you could update to version 1.06 which was released in December 2020. It has some new flags for polymers and query atoms (NPZz)

Add implicit deuterium/tritium

These are unfortunately required to correctly roundtrip when InChI is used as input. Storing them into an array of bytes probably is most efficient.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.