protected File saveAsInChI(IChemObject object, File outFile) throws Exception { logger.info("Saving the contents in an InChI textfile..."); String fileName = outFile.toString(); if (!fileName.endsWith(".txt")) { fileName += ".txt"; outFile = new File(fileName); } BufferedWriter out = new BufferedWriter(new FileWriter(outFile)); String eol=System.getProperty("line.separator"); if (object instanceof IChemModel) { IAtomContainerSet mSet = ((IChemModel) object).getMoleculeSet(); for (IAtomContainer atc : mSet.atomContainers()) { InChI inchi = InChITool.generateInchi(atc); out.write(inchi.getInChI()+eol); out.write(inchi.getAuxInfo()+eol); out.write(inchi.getKey()+eol); } } else if (object instanceof IAtomContainer) { IAtomContainer atc = (IAtomContainer) object; InChI inchi = InChITool.generateInchi(atc); out.write(inchi.getInChI()+eol); out.write(inchi.getAuxInfo()+eol); out.write(inchi.getKey()+eol); } out.close(); return outFile; }
/** * Parse an InChI string and create a CDK structure representation. * * @param inchi InChI string * @return structure representation * @throws CDKException InChI could not be parsed */ public static IAtomContainer parseInChI(String inchi) throws CDKException { assert !handlers.isEmpty(); return handlers.get(0).parse(InChI.create(inchi)); }
@Override public InChI generate(IAtomContainer container) throws CDKException { InChIGeneratorFactory igf = InChIGeneratorFactory.getInstance(); InChIGenerator its = igf.getInChIGenerator(container); if (its.getReturnStatus() != INCHI_RET.OKAY && its.getReturnStatus() != INCHI_RET.WARNING) throw new CDKException("Could not generate InChI - " + its.getMessage()); InChI inchi = new InChI(); inchi.setInChI(its.getInchi()); inchi.setKey(its.getInchiKey()); inchi.setAuxInfo(its.getAuxInfo()); return inchi; } }
@Override public IAtomContainer parse(InChI inchi) throws CDKException { try { return new StdInChIParser().parseInchi(inchi.getInChI()); } catch (Exception e) { throw new CDKException("Could not parse InChI", e); } }
System.setErr(new PrintStream(new ByteArrayOutputStream())); InChI inchi = new InChI(); inchi.setInChI(strLine); inchi.setAuxInfo(strLine); inchi.setKey(strLine); if (inchi.getInChI()==null) {
@Override public IAtomContainer parse(InChI inchi) throws CDKException { InChIGeneratorFactory igf = InChIGeneratorFactory.getInstance(); InChIToStructure its = igf.getInChIToStructure(inchi.getInChI(), DefaultChemObjectBuilder.getInstance()); if (its.getReturnStatus() != INCHI_RET.OKAY && its.getReturnStatus() != INCHI_RET.WARNING) throw new CDKException("Could not parse InChI - " + its.getMessage()); return its.getAtomContainer(); }
dialogText.append(inchi.getInChI() + eol); dialogText.append(inchi.getAuxInfo()+ eol); dialogText.append(inchi.getKey() + eol);