/** * 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); }
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); } }
@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); } }
/** * 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; }