Search in sources :

Example 6 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator in project ambit-mirror by ideaconsult.

the class InchiProcessorTest method testEquals.

@Test
public void testEquals() throws Exception {
    List<INCHI_OPTION> options = new ArrayList<INCHI_OPTION>();
    options.add(INCHI_OPTION.FixedH);
    options.add(INCHI_OPTION.SAbs);
    options.add(INCHI_OPTION.SAsXYZ);
    options.add(INCHI_OPTION.SPXYZ);
    options.add(INCHI_OPTION.FixSp3Bug);
    options.add(INCHI_OPTION.AuxNone);
    SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol = p.parseSmiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    CDKHydrogenAdder.getInstance(mol.getBuilder()).addImplicitHydrogens(mol);
    IAtomContainer molH = mol.clone();
    MoleculeTools.convertImplicitToExplicitHydrogens(molH);
    InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
    InChIGenerator gen = factory.getInChIGenerator(mol, options);
    Assert.assertEquals(INCHI_RET.OKAY, gen.getReturnStatus());
    InChIGenerator genH = factory.getInChIGenerator(mol, options);
    Assert.assertEquals(INCHI_RET.OKAY, genH.getReturnStatus());
    Assert.assertEquals(gen.getInchi(), genH.getInchi());
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) INCHI_OPTION(net.sf.jniinchi.INCHI_OPTION) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) ArrayList(java.util.ArrayList) InChIGeneratorFactory(org.openscience.cdk.inchi.InChIGeneratorFactory) Test(org.junit.Test)

Example 7 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator in project ambit-mirror by ideaconsult.

the class InchiProcessorTest method testTautomers.

@Test
public void testTautomers() throws Exception {
    List<INCHI_OPTION> options = new ArrayList<INCHI_OPTION>();
    options.add(INCHI_OPTION.FixedH);
    options.add(INCHI_OPTION.SAbs);
    options.add(INCHI_OPTION.SAsXYZ);
    options.add(INCHI_OPTION.SPXYZ);
    options.add(INCHI_OPTION.FixSp3Bug);
    options.add(INCHI_OPTION.AuxNone);
    SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol1 = p.parseSmiles("S=NNCC");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol1);
    CDKHydrogenAdder.getInstance(mol1.getBuilder()).addImplicitHydrogens(mol1);
    IAtomContainer mol2 = p.parseSmiles("SN=NCC");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol2);
    CDKHydrogenAdder.getInstance(mol2.getBuilder()).addImplicitHydrogens(mol2);
    InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
    InChIGenerator gen1 = factory.getInChIGenerator(mol1, options);
    System.out.println(gen1.getReturnStatus());
    System.out.println(gen1.getMessage());
    // Assert.assertEquals(INCHI_RET.OKAY, gen1.getReturnStatus());
    InChIGenerator gen2 = factory.getInChIGenerator(mol2, options);
    // Assert.assertEquals(INCHI_RET.OKAY, gen2.getReturnStatus());
    System.out.println(gen2.getReturnStatus());
    System.out.println(gen2.getMessage());
    Assert.assertEquals("InChI=1/C2H6N2S/c1-2-3-4-5/h2H2,1H3,(H,3,5)/f/h3H", gen1.getInchi());
    Assert.assertEquals("HLBPZSLHBUKVDX-TULZNQERNA-N", gen1.getInchiKey());
    Assert.assertEquals("InChI=1/C2H6N2S/c1-2-3-4-5/h2H2,1H3,(H,3,5)/f/h5H", gen2.getInchi());
    Assert.assertEquals("HLBPZSLHBUKVDX-JSWHHWTPNA-N", gen2.getInchiKey());
    Assert.assertTrue(!gen1.getInchi().equals(gen2.getInchi()));
    Assert.assertTrue(!gen1.getInchiKey().equals(gen2.getInchiKey()));
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) INCHI_OPTION(net.sf.jniinchi.INCHI_OPTION) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) ArrayList(java.util.ArrayList) InChIGeneratorFactory(org.openscience.cdk.inchi.InChIGeneratorFactory) Test(org.junit.Test)

Example 8 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator in project ambit-mirror by ideaconsult.

the class InchiProcessorTest method testProcessAromaticity.

@Test
public void testProcessAromaticity() throws Exception {
    SmilesParser p = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer mol = p.parseSmiles("CN1C=NC2=C1C(=O)N(C(=O)N2C)C");
    // IAtomContainer mol = p.parseSmiles("c1ccccc1");
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
    CDKHydrogenAdder ha = CDKHydrogenAdder.getInstance(SilentChemObjectBuilder.getInstance());
    ha.addImplicitHydrogens(mol);
    // AtomContainerManipulator.convertImplicitToExplicitHydrogens(mol); //
    // this is the most important
    InChIGeneratorFactory factory = InChIGeneratorFactory.getInstance();
    InChIGenerator gen = factory.getInChIGenerator(mol);
    INCHI_RET ret = gen.getReturnStatus();
    if (ret != INCHI_RET.OKAY) {
        throw new Exception(String.format("InChI failed: %s [%s]", ret.toString(), gen.getMessage()));
    }
    String inchi = gen.getInchi();
    Assert.assertEquals("InChI=1S/C8H10N4O2/c1-10-4-9-6-5(10)7(13)12(3)8(14)11(6)2/h4H,1-3H3", inchi);
}
Also used : SmilesParser(org.openscience.cdk.smiles.SmilesParser) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) InChIGeneratorFactory(org.openscience.cdk.inchi.InChIGeneratorFactory) INCHI_RET(net.sf.jniinchi.INCHI_RET) Test(org.junit.Test)

Example 9 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator in project ambit-mirror by ideaconsult.

the class InchiProcessor method process.

public InChIGenerator process(IAtomContainer target) throws AmbitException {
    try {
        List<net.sf.jniinchi.INCHI_OPTION> options = new ArrayList<net.sf.jniinchi.INCHI_OPTION>();
        /*
			options.add(INCHI_OPTION.ChiralFlagON);
			options.add(INCHI_OPTION.SUCF);
			options.add(INCHI_OPTION.SRel);
			*/
        options.add(INCHI_OPTION.SAbs);
        options.add(INCHI_OPTION.SAsXYZ);
        options.add(INCHI_OPTION.SPXYZ);
        options.add(INCHI_OPTION.FixSp3Bug);
        options.add(INCHI_OPTION.AuxNone);
        InChIGenerator gen = factory.getInChIGenerator(target, options);
        INCHI_RET ret = gen.getReturnStatus();
        if (ret == INCHI_RET.WARNING) {
            // InChI generated, but with warning message
            logger.warning("InChI warning: " + gen.getMessage());
        } else if (ret != INCHI_RET.OKAY) {
            // InChI generation failed
            throw new AmbitException("InChI failed: " + ret.toString() + " [" + gen.getMessage() + "]");
        }
        return gen;
    } catch (CDKException x) {
        throw new AmbitException(x);
    }
}
Also used : INCHI_OPTION(net.sf.jniinchi.INCHI_OPTION) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) INCHI_RET(net.sf.jniinchi.INCHI_RET) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 10 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator in project ambit-mirror by ideaconsult.

the class InchiProcessorTest method generate.

public void generate(IAtomContainer mol, String expected, boolean aromatic) throws Exception {
    InchiProcessor p = new InchiProcessor();
    HydrogenAdderProcessor ha = new HydrogenAdderProcessor();
    mol = ha.process(mol);
    if (aromatic) {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
        CDKHueckelAromaticityDetector.detectAromaticity(mol);
    }
    InChIGenerator gen = p.process(mol);
    String inchi = gen.getInchi();
    String auxinfo = gen.getAuxInfo();
    Assert.assertEquals(expected, inchi);
}
Also used : InchiProcessor(ambit2.core.processors.structure.InchiProcessor) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) HydrogenAdderProcessor(ambit2.core.processors.structure.HydrogenAdderProcessor)

Aggregations

InChIGenerator (org.openscience.cdk.inchi.InChIGenerator)38 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)22 InChIGeneratorFactory (org.openscience.cdk.inchi.InChIGeneratorFactory)17 INCHI_RET (net.sf.jniinchi.INCHI_RET)14 CDKException (org.openscience.cdk.exception.CDKException)14 ArrayList (java.util.ArrayList)9 CDKHydrogenAdder (org.openscience.cdk.tools.CDKHydrogenAdder)7 INCHI_OPTION (net.sf.jniinchi.INCHI_OPTION)6 SmilesParser (org.openscience.cdk.smiles.SmilesParser)6 Test (org.junit.Test)5 IBond (org.openscience.cdk.interfaces.IBond)5 EmptyMoleculeException (ambit2.base.exceptions.EmptyMoleculeException)3 InchiProcessor (ambit2.core.processors.structure.InchiProcessor)3 HDByteMolecularFormula (de.ipbhalle.metfraglib.molecularformula.HDByteMolecularFormula)3 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 FileReader (java.io.FileReader)3 IAtom (org.openscience.cdk.interfaces.IAtom)3 InchiStatus (io.github.dan2097.jnainchi.InchiStatus)2 InputStream (java.io.InputStream)2