Search in sources :

Example 11 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator 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 12 with InChIGenerator

use of org.openscience.cdk.inchi.InChIGenerator 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)

Example 13 with InChIGenerator

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

the class ReactionSequence method getInchiKey.

public String getInchiKey(IAtomContainer mol) {
    try {
        InChIGenerator ig = inchiGeneratorFactory.getInChIGenerator(mol, inchiOptions);
        INCHI_RET returnCode = ig.getReturnStatus();
        if (INCHI_RET.ERROR == returnCode) {
            Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, ig.getMessage());
        }
        return ig.getInchiKey();
    } catch (Exception e) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.getMessage());
    }
    return null;
}
Also used : InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException) INCHI_RET(net.sf.jniinchi.INCHI_RET)

Example 14 with InChIGenerator

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

the class Reactor method addReagent.

void addReagent(ReactorNode node, IAtomContainer mol) {
    if (strategy.FlagCalcProductInchiKey) {
        try {
            InChIGenerator ig = igf.getInChIGenerator(mol, igf_options);
            mol.setProperty(PropertyInchiKey, ig.getInchiKey());
        } catch (Exception e) {
        }
        ;
    }
    if (strategy.FlagRemoveReagentIfAllowedProduct) {
        String inchiKey = mol.getProperty(PropertyInchiKey);
        if (isAllowedProduct(inchiKey)) {
            node.allowedProducts.addAtomContainer(mol);
            return;
        }
    }
    if (strategy.FlagRemoveReagentIfForbiddenProduct) {
        String inchiKey = mol.getProperty(PropertyInchiKey);
        if (isForbiddenProduct(inchiKey)) {
            node.forbiddenProducts.addAtomContainer(mol);
            return;
        }
    }
    node.reagents.addAtomContainer(mol);
}
Also used : InChIGenerator(org.openscience.cdk.inchi.InChIGenerator) EmptyMoleculeException(ambit2.base.exceptions.EmptyMoleculeException)

Example 15 with InChIGenerator

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

the class ReactorStrategy method configureStructureRecord.

public static void configureStructureRecord(StructureRecord strRecord, InChIGeneratorFactory igf, List<INCHI_OPTION> options) throws Exception {
    if (strRecord.getSmiles() == null)
        return;
    IAtomContainer mol = SmartsHelper.getMoleculeFromSmiles(strRecord.getSmiles());
    InChIGenerator ig = igf.getInChIGenerator(mol, options);
    // String inchi = ig.getInchi();
    strRecord.setInchiKey(ig.getInchiKey());
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) InChIGenerator(org.openscience.cdk.inchi.InChIGenerator)

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