Search in sources :

Example 1 with INCHI_RET

use of net.sf.jniinchi.INCHI_RET in project ambit-mirror by ideaconsult.

the class CompoundLookup method atomcontainer2inchi.

public String[] atomcontainer2inchi(IAtomContainer c, String origin) throws ResourceException {
    try {
        Kekulization.kekulize(c);
        // inchi can't process aromatic bonds...
        for (IBond bond : c.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false);
        // now generate unique inchi, as SMILES are not
        searchType = _searchtype.inchi;
        InChIGeneratorFactory f = InChIGeneratorFactory.getInstance();
        InChIGenerator gen = f.getInChIGenerator(c);
        INCHI_RET status = gen.getReturnStatus();
        if (INCHI_RET.OKAY.equals(status) || INCHI_RET.WARNING.equals(status))
            return new String[] { gen.getInchi(), gen.getInchiKey() };
        else
            throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, String.format("Error converting to InChI: %s %s %s %s", status, gen.getMessage(), gen.getLog(), origin));
    } catch (ResourceException x) {
        throw x;
    } catch (InvalidSmilesException x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    } catch (CDKException x) {
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, x.getMessage(), x);
    }
}
Also used : InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) CDKException(org.openscience.cdk.exception.CDKException) IBond(org.openscience.cdk.interfaces.IBond) ResourceException(org.restlet.resource.ResourceException) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) InChIGeneratorFactory(org.openscience.cdk.inchi.InChIGeneratorFactory) INCHI_RET(net.sf.jniinchi.INCHI_RET)

Example 2 with INCHI_RET

use of net.sf.jniinchi.INCHI_RET 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 3 with INCHI_RET

use of net.sf.jniinchi.INCHI_RET 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 4 with INCHI_RET

use of net.sf.jniinchi.INCHI_RET in project ambit-mirror by ideaconsult.

the class InChI method calculate.

public DescriptorValue calculate(IAtomContainer mol) {
    try {
        InChIGenerator gen = processor.process(mol);
        INCHI_RET ret = gen.getReturnStatus();
        if (ret.equals(INCHI_RET.OKAY) || ret.equals(INCHI_RET.WARNING)) {
            StringArrayResult value = new StringArrayResult(new String[] { gen.getInchi(), null, gen.getInchiKey() });
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), value, getDescriptorNames());
        } else {
            return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), null, getDescriptorNames(), new Exception(String.format("[%s] %s", gen.getReturnStatus(), gen.getMessage())));
        }
    } catch (Exception x) {
        return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), null, getDescriptorNames(), x);
    }
}
Also used : StringArrayResult(ambit2.core.data.StringArrayResult) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) CDKException(org.openscience.cdk.exception.CDKException) INCHI_RET(net.sf.jniinchi.INCHI_RET) DescriptorValue(org.openscience.cdk.qsar.DescriptorValue)

Example 5 with INCHI_RET

use of net.sf.jniinchi.INCHI_RET in project ambit-mirror by ideaconsult.

the class SimilarityManager method getInchiKey.

String getInchiKey(IAtomContainer mol) throws Exception {
    InChIGenerator ig = inchiGeneratorFactory.getInChIGenerator(mol, inchiOptions);
    INCHI_RET returnCode = ig.getReturnStatus();
    if (INCHI_RET.ERROR == returnCode) {
    // Error
    }
    return ig.getInchiKey();
}
Also used : InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) INCHI_RET(net.sf.jniinchi.INCHI_RET)

Aggregations

INCHI_RET (net.sf.jniinchi.INCHI_RET)16 InChIGenerator (org.openscience.cdk.inchi.InChIGenerator)14 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)7 CDKException (org.openscience.cdk.exception.CDKException)6 InChIGeneratorFactory (org.openscience.cdk.inchi.InChIGeneratorFactory)6 INCHI_OPTION (net.sf.jniinchi.INCHI_OPTION)3 Test (org.junit.Test)3 InChIToStructure (org.openscience.cdk.inchi.InChIToStructure)3 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 SmilesParser (org.openscience.cdk.smiles.SmilesParser)2 EmptyMoleculeException (ambit2.base.exceptions.EmptyMoleculeException)1 StringArrayResult (ambit2.core.data.StringArrayResult)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 RandomAccessFile (java.io.RandomAccessFile)1 Entry (java.util.Map.Entry)1 TreeSet (java.util.TreeSet)1 AmbitException (net.idea.modbcum.i.exceptions.AmbitException)1