public String getInChIKey(net.bioclipse.core.domain.IMolecule.Property urgency) throws BioclipseException { switch (urgency) { case USE_CACHED: return cachedInchi == null ? "" : cachedInchi.getKey(); case USE_CACHED_OR_CALCULATED: if (cachedInchi != null) { return cachedInchi.getKey(); } case USE_CALCULATED: calculateInchi(); return cachedInchi.getKey(); default: throw new IllegalArgumentException("Unrecognized Property:" + urgency); } }
/** @throws BioclipseException */ private void calculateInchi() throws BioclipseException { try { IAtomContainer clone = (IAtomContainer) getAtomContainer().clone(); // remove aromaticity flags for (IAtom atom : clone.atoms()) atom.setFlag(CDKConstants.ISAROMATIC, false); for (IBond bond : clone.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false); if (factory == null) { factory = InChIGeneratorFactory.getInstance(); } InChIGenerator gen = factory.getInChIGenerator(clone); INCHI_RET status = gen.getReturnStatus(); if (status == INCHI_RET.OKAY || status == INCHI_RET.WARNING) { InChI inchi = new InChI(); inchi.setValue(gen.getInchi()); inchi.setKey(gen.getInchiKey()); cachedInchi = inchi; } else { throw new InvalidParameterException( "Error while generating InChI (" + status + "): " + gen.getMessage()); } } catch (Exception e) { throw new BioclipseException("Could not create InChI: " + e.getMessage(), e); } }