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);
}
}
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);
}
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);
}
}
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);
}
}
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();
}
Aggregations