/** * The reader is already set to read the record buffer. * @return the read IChemObject * @throws CDKException an error occurred whilst reading the file */ protected IChemObject processContent() throws CDKException { return chemObjectReader.read(builder.newInstance(IChemFile.class)); }
private static IAtomContainer createMolecule(String molecule) throws IOException, CDKException { IAtomContainer structure = null; if (molecule != null) { ISimpleChemObjectReader reader = new MDLV2000Reader(new StringReader(molecule)); Assert.assertNotNull("Could not create reader", reader); if (reader.accepts(AtomContainer.class)) { structure = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class)); } } return structure; }
@Test public void testRead_IChemObject() throws Exception { Assert.assertNotNull("No test file has been set!", testFile); boolean read = false; for (IChemObject object : acceptableChemObjects()) { if (chemObjectIO.accepts(object.getClass())) { InputStream ins = SimpleChemObjectReaderTest.class.getClassLoader().getResourceAsStream(testFile); chemObjectIO.setReader(ins); IChemObject readObject = chemObjectIO.read(object); chemObjectIO.close(); Assert.assertNotNull("Failed attempt to read the file as " + object.getClass().getName(), readObject); read = true; } } if (!read) { Assert.fail("Reading an IChemObject from the Reader did not work properly."); } }
/** * @cdk.bug 2984581 * @throws Exception */ @Test public void testAromaticRingsLine() throws Exception { String filename = "data/hin/bug2984581.hin"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); ISimpleChemObjectReader reader = new HINReader(ins); IChemFile content = reader.read(new ChemFile()); reader.close(); List<IAtomContainer> cList = ChemFileManipulator.getAllAtomContainers(content); Assert.assertEquals(1, cList.size()); }
public boolean accepts(Class<? extends IChemObject> classObject) { return chemObjectReader.accepts(classObject); }
/** * Read an IChemModel from a given file. * @param file * @param type * @param panel * @return * @throws CDKException * @throws FileNotFoundException */ public static IChemModel readFromFile(File file, String type, AbstractJChemPaintPanel panel) throws CDKException, FileNotFoundException { String url = file.toURI().toString(); ISimpleChemObjectReader cor = null; try { cor = FileHandler.createReader(file.toURI().toURL(), url, type); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (cor instanceof CMLReader) cor.setReader(new FileInputStream(file)); // hack else cor.setReader(new FileReader(file)); // hack IChemModel chemModel = JChemPaint.getChemModelFromReader(cor,panel); boolean avoidOverlap=true; if (cor instanceof RGroupQueryReader) avoidOverlap=false; JChemPaint.cleanUpChemModel(chemModel, avoidOverlap, panel); return chemModel; }
public IChemFile getChemFile(ISimpleChemObjectReader reader, boolean useRebond) throws Exception { Assert.assertNotNull(reader); reader.getSetting("UseRebondTool").setSetting(String.valueOf(useRebond)); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); Assert.assertNotNull(chemFile); return chemFile; }
private TestResults testFile(String dir, String filename, ISimpleChemObjectReader reader) throws Exception { CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(DefaultChemObjectBuilder.getInstance()); InputStream ins = this.getClass().getClassLoader().getResourceAsStream(dir + filename); reader.setReader(ins); IAtomContainer mol = null; if (reader.accepts(AtomContainer.class)) { mol = reader.read(new AtomContainer()); } else if (reader.accepts(ChemFile.class)) { IChemFile cf = reader.read(new ChemFile()); mol = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); List<IAtomContainer> containers = ChemFileManipulator.getAllAtomContainers(cf);
@Test public void testIsConnectedFromHINFile() throws Exception { String filename = "data/hin/connectivity1.hin"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); ISimpleChemObjectReader reader = new HINReader(ins); IChemFile content = reader.read(new ChemFile()); reader.close(); List<IAtomContainer> cList = ChemFileManipulator.getAllAtomContainers(content); IAtomContainer ac = cList.get(0); Assert.assertEquals(57, ac.getAtomCount()); Assert.assertEquals(59, ac.getBondCount()); }
/** * Returns the object at given record No. * * Record numbers are zero-based! */ @Override public synchronized IChemObject readRecord(int record) throws Exception { String buffer = readContent(record); if (chemObjectReader == null) throw new CDKException("No chemobject reader!"); else { chemObjectReader.setReader(new StringReader(buffer)); currentRecord = record; return processContent(); } }
/** * The reader is already set to read the record buffer. * @return the read IChemObject * @throws CDKException an error occurred whilst reading the file */ protected IChemObject processContent() throws CDKException { return chemObjectReader.read(builder.newInstance(IChemFile.class)); }
ChemModel chemModel = null; IChemFile chemFile = null; if (cor.accepts(IChemFile.class) && chemModel==null) { chemFile = (IChemFile) cor.read((IChemObject) new ChemFile()); if (chemFile == null) { error = "The object chemFile was empty unexpectedly!"; if (cor.accepts(ChemModel.class) && chemModel==null) { chemModel = (ChemModel) cor.read((IChemObject) new ChemModel()); if (chemModel == null) { error = "The object chemModel was empty unexpectedly!"; if (cor.accepts(IAtomContainerSet.class) && chemModel==null) { IAtomContainerSet som = (AtomContainerSet) cor.read(new AtomContainerSet()); chemModel = new ChemModel(); chemModel.setMoleculeSet(som); if (cor.accepts(IAtomContainer.class) && chemModel==null) { IAtomContainer mol = (AtomContainer) cor.read(new AtomContainer()); if(mol!=null ) try{ if (cor.accepts(RGroupQuery.class) && chemModel==null) { IRGroupQuery rgroupQuery = (RGroupQuery) cor.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance())); if(rgroupQuery!=null )
@Test public void testRead_IChemObject() throws Exception { Assert.assertNotNull("No test file has been set!", testFile); boolean read = false; for (IChemObject object : acceptableChemObjects()) { if (chemObjectIO.accepts(object.getClass())) { InputStream ins = SimpleChemObjectReaderTest.class.getClassLoader().getResourceAsStream(testFile); chemObjectIO.setReader(ins); IChemObject readObject = chemObjectIO.read(object); chemObjectIO.close(); Assert.assertNotNull("Failed attempt to read the file as " + object.getClass().getName(), readObject); read = true; } } if (!read) { Assert.fail("Reading an IChemObject from the Reader did not work properly."); } }
@Test(expected = CDKException.class) public void testUndefinedPartialCharge() throws Exception { String filename = "data/mdl/burden_undefined.sdf"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); ISimpleChemObjectReader reader = new MDLV2000Reader(ins); ChemFile content = reader.read(new ChemFile()); reader.close(); List<IAtomContainer> cList = ChemFileManipulator.getAllAtomContainers(content); IAtomContainer ac = cList.get(0); Assert.assertNotNull(ac); addExplicitHydrogens(ac); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac); Aromaticity.cdkLegacy().apply(ac); addExplicitHydrogens(ac); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac); lpcheck.saturate(ac); GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges(); peoe.calculateCharges(ac); } }
@Test public void testAccepts() { Assert.assertTrue(chemObjectIO.accepts(ChemFile.class)); }
/** * Returns the object at given record No. * * Record numbers are zero-based! */ @Override public synchronized IChemObject readRecord(int record) throws Exception { String buffer = readContent(record); if (chemObjectReader == null) throw new CDKException("No chemobject reader!"); else { chemObjectReader.setReader(new StringReader(buffer)); currentRecord = record; return processContent(); } }
private IAtomContainer readMol(File file) { IAtomContainer molecule = null; try { List<IAtomContainer> allAtomContainers; String extension = FileFilterUtility.getExtension(file); try (ISimpleChemObjectReader reader = getReader(file, extension)) { IChemFile chemFile = reader.read(new ChemFile()); allAtomContainers = ChemFileManipulator.getAllAtomContainers(chemFile); } for (IAtomContainer frag : allAtomContainers) { if (molecule == null || frag.getAtomCount() > molecule.getAtomCount()) { molecule = frag; } } configure(molecule, extension); count = 0; jTextArea1.append("Created Mol = " + file.getName() + NEW_LINE); jTextArea1.setCaretPosition(jTextArea1.getDocument().getLength()); } catch (IOException ex) { Logger.getLogger(SMSDFrame.class.getName()).log(Level.SEVERE, null, ex); } catch (CDKException ex) { Logger.getLogger(SMSDFrame.class.getName()).log(Level.SEVERE, null, ex); } return molecule; }