Skip to content

Conversation

@BobHanson
Copy link

@BobHanson BobHanson commented Feb 28, 2025

This pull request shares the inchi-web.c code modified for openchemlib (OCL-SwingJS), Jmol-SwingJS, JME-SwingJS (which is incorporated into Jmol-SwingJS), and CDK-SwingJS.

It adds two significant features to INCHI-WEB-DEMO:

  1. a "version" JSON key to go along with message, log, return_code for all methods, that reports the full APP_DESCRIPTION of inchi c, such as:

    InChI version 1, Software 1.07.2 (inchi-1 executable)

as demonstrated at SimpleDemo/index1.html

  1. a new method, model_from_inchi, that returns a JSON string for the "model" key that contains all the necessary information required to regenerate a 2D or 3D structure with stereochemistry from an InChI.

as demonstrated at at SimpleDemo/index1.html and SimpleDemo/index.html

Item 1 is going to be particularly useful as inchi-web-WASM becomes more widely available, and we start seeing different implementations with a range of InChI versions out there. The savvy user wants to know what version of InChI is being accessed.

Item 2 is particularly useful when inchi-web.wasm is coupled with larger packages, complementing the feature of Java JNA-InChI in JavaScript. For example, at CDK-SwingJSTest_core we see a simple case starting with

    String inchi = "InChI=1S/C41H45NO21/c43-13-27-32(51)34(53)37(56)40(61-27)59-25-11-19(45)10-21-20(25)12-26(30(42-21)17-4-7-22(46)23(47)9-17)60-41-38(63-39-36(55)31(50)24(48)14-58-39)35(54)33(52)28(62-41)15-57-29(49)8-3-16-1-5-18(44)6-2-16/h1-12,24,27-28,31-41,43-48,50-56H,13-15H2"
            + "/b8-3+/t24-,27-,28-,31+,32-,33-,34+,35+,36-,37-,38-,39+,40-,41-/m1/s1";

CDK-SwingJS/JavaScript delivers the SMILES:

 C=1C=C(C=CC1/C=C/C(=O)OC[C@@H]2[C@H]([C@@H]([C@H]([C@H](OC=3C=C4C(C=C(C=C4O[C@H]5[C@@H]([C@H]([C@@H]([C@@H](CO)O5)O)O)O)O)=NC3C=6C=CC(=C(C6)O)O)O2)O[C@H]7[C@@H]([C@H]([C@@H](CO7)O)O)O)O)O)O

using this sequence (written in Java, but executed in JavaScript in a browser):

InChI to model to molecule

        IAtomContainer mol = AtomContainerManipulator.suppressHydrogens(
             InChIGeneratorFactory.getInstance()
                       .getInChIToStructure(inchi, getBuilder(), "")
                       .getAtomContainer()
        );
        new StructureDiagramGenerator().generateCoordinates(mol);

molecule to SMILES

        String smi = new SmilesGenerator(SmiFlavor.Isomeric).create(mol);
        System.out.println(smi);

In addition, the following bits of code generated PNG and SVG images in JavaScript:

        Font f = new Font("SansSerif", Font.BOLD, 20);
        DepictionGenerator dg = new DepictionGenerator(f).withSize(600,600);
        BufferedImage image = dg.depict(mol).toImg();
        FileOutputStream bos = new FileOutputStream("c:/temp/testcdk.png");
        ImageIO.write(image, "PNG", bos);
        bos.close();

        bos = new FileOutputStream("c:/temp/testcdk.svg");
        String svg = dg.depict(mol).toSvgStr();
        bos.write(svg.getBytes());
        bos.close();

(PNG)

testcdk(86)

(SVG)

testcdk(16)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant