@Override public boolean accepts(Class<? extends IChemObject> classObject) { Class<?>[] interfaces = classObject.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (IChemFile.class.equals(interfaces[i])) return true; } if (IChemFile.class.equals(classObject)) return true; Class superClass = classObject.getSuperclass(); if (superClass != null) return this.accepts(superClass); return false; }
protected IReaction parseCML(String input) throws FileNotFoundException, CDKException { File f = new File(input); if (!f.isFile()) { LOGGER.warn(WARNING, format("CML file not found! " + f.getName())); exit(1); } String[] split = f.getName().split(".cml"); CMLReader cmlReader = new CMLReader(new FileInputStream(input)); AtomContainer ac = cmlReader.read(new AtomContainer()); IReaction r = new Reaction(); r.addReactant(ac, 1.0); r.addProduct(ac, 1.0); r.setID(split[0]); return r; }
logger.debug("******************************"); CMLReader reader = new CMLReader(new ByteArrayInputStream(serializedMol.getBytes())); reader.registerConvention("md:mdMolecule", new MDMoleculeConvention(new ChemFile())); IChemFile file = (IChemFile) reader.read(new ChemFile()); reader.close(); List containers = ChemFileManipulator.getAllAtomContainers(file); Assert.assertEquals(1, containers.size());
private ISimpleChemObjectReader getReader(String type, String filename) throws IOException { File input = new File(filename); if (input.isDirectory()) { throw new IOException( "Input path " + filename + " is a directory, not a file"); } switch (type) { case "MOL": return new MDLV2000Reader( new FileReader(input), IChemObjectReader.Mode.RELAXED); case "CML": return new CMLReader(new FileInputStream(input)); case "ML2": return new Mol2Reader(new FileReader(input)); case "PDB": return new PDBReader(new FileReader(input)); } return null; }
private ISimpleChemObjectReader getReader(File file, String extension) throws IOException, CDKException { if (file.isDirectory()) { throw new IOException( "Input path " + file + " is a directory, not a file"); } switch (extension) { case "mol": return new MDLV2000Reader( new FileReader(file), IChemObjectReader.Mode.RELAXED); case "sdf": return new MDLV2000Reader( new FileReader(file)); case "cml": return new CMLReader(new FileInputStream(file)); case "ml2": return new Mol2Reader(new FileReader(file)); case "pdb": PDBReader reader = new PDBReader(new FileReader(file)); reader.getSetting("UseRebondTool").setSetting("false"); // UseRebondTool reader.getSetting("ReadConnectSection").setSetting("true"); // ReadConnectSection return reader; } return null; }
LOGGER.debug("Attempting to read template ", line); try { CMLReader structureReader = new CMLReader(this.getClass().getClassLoader() .getResourceAsStream(line)); IChemFile file = (IChemFile) structureReader.read(builder.newInstance(IChemFile.class)); List<IAtomContainer> files = ChemFileManipulator.getAllAtomContainers(file); for (int i = 0; i < files.size(); i++)
@BeforeClass public static void setup() { setSimpleChemObjectReader(new CMLReader(), "data/cml/3.cml"); }
@Override public boolean accepts(Class<? extends IChemObject> classObject) { Class<?>[] interfaces = classObject.getInterfaces(); for (int i = 0; i < interfaces.length; i++) { if (IChemFile.class.equals(interfaces[i])) return true; } if (IChemFile.class.equals(classObject)) return true; Class superClass = classObject.getSuperclass(); if (superClass != null) return this.accepts(superClass); return false; }
LOGGER.debug("Attempting to read template ", line); try { CMLReader structureReader = new CMLReader(this.getClass().getClassLoader() .getResourceAsStream(line)); IChemFile file = (IChemFile) structureReader.read(builder.newInstance(IChemFile.class)); List<IAtomContainer> files = ChemFileManipulator.getAllAtomContainers(file); for (int i = 0; i < files.size(); i++)
/** * @cdk.bug 2114987 */ @Test public void testCMLTestCase() throws Exception { String filename = "data/cml/olaCmlAtomType.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = new ChemFile(); chemFile = (IChemFile) reader.read(chemFile); reader.close(); IAtomContainer container = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); for (IAtom atom : container.atoms()) { Assert.assertEquals(CDKConstants.UNSET, atom.getImplicitHydrogenCount()); } }
@Test public void testFile3() throws Exception { String filename = "data/cml/3.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); IChemFile chemFile = (IChemFile) reader.read(new ChemFile()); // test the resulting ChemFile content Assert.assertNotNull(chemFile); IAtomContainer mol = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); String[] expectedTypes = {"C.sp2", "N.sp2", "C.sp2", "N.sp3", "C.sp2", "N.sp2", "O.sp3", "C.sp2", "C.sp2", "C.sp2"}; assertAtomTypes(testedAtomTypes, expectedTypes, mol); }
reader = new CMLReader(new ByteArrayInputStream(content.getBytes()));
@Test public void testMixedNamespaces() throws Exception { InputStream in = getClass().getResourceAsStream("US06358966-20020319-C00001-enr.cml"); CMLReader reader = new CMLReader(in); try { IChemFile cfile = reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IChemFile.class)); Assert.assertEquals(34, ChemFileManipulator.getAtomCount(cfile)); Assert.assertEquals(39, ChemFileManipulator.getBondCount(cfile)); } finally { reader.close(); } } }
public void visualBugPMR() throws Exception { String filename = "data/cml/SL0016a.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemObject) new ChemFile()); IChemSequence seq = chemFile.getChemSequence(0); IChemModel model = seq.getChemModel(0); IAtomContainer mol = model.getMoleculeSet().getAtomContainer(0); //MoleculeViewer2D.display(mol, true, false, JFrame.DO_NOTHING_ON_CLOSE,""); }
/** * @cdk.bug 1930029 */ @Test public void testAtomProperties() throws Exception { String filename = "data/cml/custompropertiestest.cml"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); CMLReader reader = new CMLReader(ins); ChemFile chemFile = (ChemFile) reader.read((ChemFile) new ChemFile()); reader.close(); Assert.assertNotNull(chemFile); IAtomContainer container = ChemFileManipulator.getAllAtomContainers(chemFile).get(0); for (int i = 0; i < container.getAtomCount(); i++) { Assert.assertEquals(2, container.getAtom(i).getProperties().size()); } }