/** * Create an entry for the provided container and add it to the library. * * @param container structure representation */ void add(IAtomContainer container) { add(createEntry(container)); }
/** * Sets the templateHandler attribute of the StructureDiagramGenerator object * * @param templateHandler The new templateHandler value * @deprecated substructure templates are no longer used for layout but those provided here * will be converted to identity templates */ @Deprecated public void setTemplateHandler(TemplateHandler templateHandler) { IdentityTemplateLibrary lib = templateHandler.toIdentityTemplateLibrary(); lib.add(identityLibrary); identityLibrary = lib; // new ones take priority }
/** * Sets the templateHandler attribute of the StructureDiagramGenerator object * * @param templateHandler The new templateHandler value * @deprecated substructure templates are no longer used for layout but those provided here * will be converted to identity templates */ @Deprecated public void setTemplateHandler(TemplateHandler templateHandler) { IdentityTemplateLibrary lib = templateHandler.toIdentityTemplateLibrary(); lib.add(identityLibrary); identityLibrary = lib; // new ones take priority }
/** * Create an entry for the provided container and add it to the library. * * @param container structure representation */ void add(IAtomContainer container) { add(createEntry(container)); }
/** * Load a template library from an input stream. * * @return loaded template library * @throws java.io.IOException low level IO error */ static IdentityTemplateLibrary load(InputStream in) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line = null; IdentityTemplateLibrary library = new IdentityTemplateLibrary(); while ((line = br.readLine()) != null) { // skip comments if (line.charAt(0) == '#') continue; library.add(decodeEntry(line)); } return library; }
/** * Load a template library from an input stream. * * @return loaded template library * @throws java.io.IOException low level IO error */ static IdentityTemplateLibrary load(InputStream in) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line = null; IdentityTemplateLibrary library = new IdentityTemplateLibrary(); while ((line = br.readLine()) != null) { // skip comments if (line.charAt(0) == '#') continue; library.add(decodeEntry(line)); } return library; }
/** * Convert to an identity template library. * * @return identity template library */ IdentityTemplateLibrary toIdentityTemplateLibrary() { IdentityTemplateLibrary lib = IdentityTemplateLibrary.empty(); for (IAtomContainer mol : templates) { lib.add(AtomContainerManipulator.anonymise(mol)); } return lib; } }
/** * Convert to an identity template library. * * @return identity template library */ IdentityTemplateLibrary toIdentityTemplateLibrary() { IdentityTemplateLibrary lib = IdentityTemplateLibrary.empty(); for (IAtomContainer mol : templates) { lib.add(AtomContainerManipulator.anonymise(mol)); } return lib; } }
@Test public void store() throws IOException { IdentityTemplateLibrary lib = IdentityTemplateLibrary.empty(); lib.add(IdentityTemplateLibrary.decodeEntry("[C][C][O] 0, 1, 2, 3, 4, 5")); lib.add(IdentityTemplateLibrary.decodeEntry("[C][C] 0, 1, 2, 3")); ByteArrayOutputStream baos = new ByteArrayOutputStream(); lib.store(baos); baos.close(); assertThat(new String(baos.toByteArray()), is("[C][C][O] |(.0,1.0,;2.0,3.0,;4.0,5.0,)|\n[C][C] |(.0,1.0,;2.0,3.0,)|\n")); } }
@Test public void assignEthanol() { IAtomContainer container = new AtomContainer(); container.addAtom(new Atom("O")); container.addAtom(new Atom("C")); container.addAtom(new Atom("C")); container.getAtom(0).setImplicitHydrogenCount(0); container.getAtom(1).setImplicitHydrogenCount(0); container.getAtom(2).setImplicitHydrogenCount(0); container.addBond(0, 1, IBond.Order.SINGLE); container.addBond(1, 2, IBond.Order.SINGLE); IdentityTemplateLibrary lib = IdentityTemplateLibrary.empty(); lib.add(IdentityTemplateLibrary.decodeEntry("OCC 4, 5, 2, 3, 0, 1")); assertTrue(lib.assignLayout(container)); assertThat(container.getAtom(0).getPoint2d().x, closeTo(4, 0.01)); assertThat(container.getAtom(0).getPoint2d().y, closeTo(5, 0.01)); assertThat(container.getAtom(1).getPoint2d().x, closeTo(2, 0.01)); assertThat(container.getAtom(1).getPoint2d().y, closeTo(3, 0.01)); assertThat(container.getAtom(2).getPoint2d().x, closeTo(0, 0.01)); assertThat(container.getAtom(2).getPoint2d().y, closeTo(1, 0.01)); }