public static void main(String[] args) throws Exception { StdInChIParser parser = new StdInChIParser(); IAtomContainer m = parser.parseInchi("InChI=1S/C2H6/c1-2/h1-2H3"); for (int i = 0; i < 10; i++) { StdInChIGenerator gen = new StdInChIGenerator(); gen.generateInchi(m); } }
/** * 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)); }
System.setErr(new PrintStream(new ByteArrayOutputStream())); InChI inchi = new InChI(); String tmpFileBase = "cdk"+getFileSeq(); inchi.setInChI(strLine); inchi.setAuxInfo(strLine); inchi.setKey(strLine); if (inchi.getInChI()==null) { String errMsg=getErrorMsg (tmpLogFile); if(!errMsg.equals("")) { throw new CDKException (errMsg); deleteFileIfExists(tmpMolFile); deleteFileIfExists(tmpOutFile); deleteFileIfExists(tmpLogFile); deleteFileIfExists(tmpPrbFile); System.setErr(stErr);
@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; } }
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; }
@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); } }
/** * Load an IChemModel from an InChI. * * @param url location * @return InChI instance * @throws CDKException InChI could not be generated */ public static IChemModel readInChI(URL url) throws CDKException { IChemModel chemModel = new ChemModel(); try { IAtomContainerSet moleculeSet = new AtomContainerSet(); chemModel.setMoleculeSet(moleculeSet); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) { if (line.toLowerCase().startsWith("inchi=")) { moleculeSet.addAtomContainer(parseInChI(line)); } } in.close(); } catch (Exception e) { e.printStackTrace(); throw new CDKException(e.getMessage()); } return chemModel; } }
@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(); }
String tmpFileBase = "cdk"+getFileSeq(); String errMsg=getErrorMsg (tmpLogFile); if(!errMsg.equals("")) { throw new CDKException (errMsg); errMsg=getErrorMsg (tmpLogFile); if(!errMsg.equals("")) { throw new CDKException (errMsg); deleteFileIfExists(tmpInFile); deleteFileIfExists(tmpOutFile); deleteFileIfExists(tmpMolFile); deleteFileIfExists(tmpLogFile); deleteFileIfExists(tmpPrbFile); System.setErr(stErr);
@Override public InChI generate(IAtomContainer container) throws CDKException { try { return new StdInChIGenerator().generateInchi(container); } catch (CDKException e) { throw new CDKException("Could not generate InChI", e); } catch (IOException e) { throw new CDKException("Could not generate InChI", e); } } }
/** * Read the InChI=.. lines from a give text file containing InChI(s) * @param url * @return chemModel with molecule set with molecule(s) created using InChI * @throws org.openscience.cdk.exception.CDKException */ public static IChemModel readInChI(URL url) throws CDKException { IChemModel chemModel = new ChemModel(); try { IAtomContainerSet moleculeSet = new AtomContainerSet(); chemModel.setMoleculeSet(moleculeSet); StdInChIParser parser = new StdInChIParser(); BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); String line; while ((line = in.readLine()) != null) { if (line.toLowerCase().startsWith("inchi=")) { IAtomContainer atc = parser.parseInchi(line); moleculeSet.addAtomContainer(atc); } } in.close(); } catch (Exception e) { e.printStackTrace(); throw new CDKException(e.getMessage()); } return chemModel; }
/** * Generate an InChI string from a CDK structure representation. * * @param container structure representation * @return InChI instance * @throws CDKException InChI could not be generated */ public static InChI generateInchi(IAtomContainer container) throws CDKException { assert !handlers.isEmpty(); return handlers.get(0).generate(container); }
/** * Generate InChI for a given atom container.<BR> * Take current user's home directory as temporary dir.<BR> * Overloads {@linkplain #parseInchi(String, String)}. * * @param inchi to convert to an IAtomContainer * @return CDK IAtomContainer * @throws Exception */ public IAtomContainer parseInchi(String inchi)throws Exception { String workingDir=System.getProperty("user.dir")+ System.getProperty("file.separator"); return parseInchi(inchi,workingDir); }
/** * Generate InChI for a given atom container.<BR> * Take current user's home directory as temporary dir.<BR> * Overloads {@linkplain #generateInchi(org.openscience.cdk.interfaces.IAtomContainer, String)} * * @param molfile * @return InChI generated from Molfile * @throws java.io.IOException * @throws org.openscience.cdk.exception.CDKException */ public InChI generateInchi(IAtomContainer atc) throws IOException, CDKException { String workingDir=System.getProperty("user.dir")+ System.getProperty("file.separator"); return generateInchi(atc,workingDir); }
public static IChemModel readFromFileReader(URL fileURL, String url, String type, AbstractJChemPaintPanel panel) throws CDKException { IChemModel chemModel = null; WaitDialog.showDialog(); // InChI workaround - guessing for InChI results into an INChIReader // (this does not work, we'd need an INChIPlainTextReader..) // Instead here we use STDInChIReader, to be consistent throughout JCP // using the nestedVm based classes. try { ISimpleChemObjectReader cor=null; if(url.endsWith("txt")) { chemModel = InChITool.readInChI(fileURL); } else { cor = FileHandler.createReader(fileURL, url,type); chemModel = JChemPaint.getChemModelFromReader(cor,panel); } boolean avoidOverlap=true; if (cor instanceof RGroupQueryReader) avoidOverlap=false; JChemPaint.cleanUpChemModel(chemModel, avoidOverlap, panel); } finally { WaitDialog.hideDialog(); } return chemModel; }
InChI inchi = InChITool.generateInchi(container); dialogText.append(inchi.getInChI() + eol); dialogText.append(inchi.getAuxInfo()+ eol); dialogText.append(inchi.getKey() + eol);
try { IAtomContainer atomContainer = InChITool.parseInChI(text); molecule = atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);
try{ if (content.toLowerCase().indexOf("inchi")>-1 ) { toPaste = InChITool.parseInChI(content);