StandardAtomGenerator { AtomSymbol generateSymbol(IAtomContainer container, IAtom atom, HydrogenPosition position, RendererModel model) { if (atom instanceof IPseudoAtom) { IPseudoAtom pAtom = (IPseudoAtom) atom; if (pAtom.getAttachPointNum() <= 0) { if (pAtom.getLabel().equals("*")) { int mass = unboxSafely(pAtom.getMassNumber(), 0); int charge = unboxSafely(pAtom.getFormalCharge(), 0); int hcnt = unboxSafely(pAtom.getImplicitHydrogenCount(), 0); int nrad = container.getConnectedSingleElectronsCount(atom); return generatePeriodicSymbol(0, hcnt, mass, charge, nrad, position, model); } return generatePseudoSymbol(accessPseudoLabel(pAtom, "?"), position, model); } else return null; } else { int number = unboxSafely(atom.getAtomicNumber(), Elements.ofString(atom.getSymbol()).number()); Integer mass = atom.getMassNumber(); if (number != 0 && mass != null && model != null && model.get(StandardGenerator.OmitMajorIsotopes.class) && isMajorIsotope(number, mass)) { mass = null; } return generatePeriodicSymbol(number, unboxSafely(atom.getImplicitHydrogenCount(), 0), unboxSafely(mass, -1), unboxSafely(atom.getFormalCharge(), 0), container.getConnectedSingleElectronsCount(atom), position, model); } } StandardAtomGenerator(Font font); private  StandardAtomGenerator(Font font, double adjunctSpacing, double scriptSize);   }
@Test public void generatesRgroupPseudoAtom() { IAtomContainer container = mock(IAtomContainer.class); IPseudoAtom atom = mock(IPseudoAtom.class); when(atom.getLabel()).thenReturn("R1"); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, null); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(2)); }
@Test public void generatesCarbon12() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(12); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); RendererModel model = new RendererModel(); model.registerParameters(new StandardGenerator(new Font(Font.SANS_SERIF, Font.PLAIN, 12))); model.set(StandardGenerator.OmitMajorIsotopes.class, true); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, model); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(1)); }
@Test public void generatesCarbon13() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(13); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); RendererModel model = new RendererModel(); model.registerParameters(new StandardGenerator(new Font(Font.SANS_SERIF, Font.PLAIN, 12))); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, model); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(2)); }
@Test public void nullMassNumber() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(null); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, new RendererModel()); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(1)); }
@Test public void nullHydrogenCount() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(12); when(atom.getImplicitHydrogenCount()).thenReturn(null); when(atom.getFormalCharge()).thenReturn(0); RendererModel model = new RendererModel(); model.registerParameters(new StandardGenerator(new Font(Font.SANS_SERIF, Font.PLAIN, 12))); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, model); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(2)); }
@Test public void nullFormatCharge() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(12); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(null); RendererModel model = new RendererModel(); model.registerParameters(new StandardGenerator(new Font(Font.SANS_SERIF, Font.PLAIN, 12))); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, model); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(2)); }
@Test public void nullAtomicNumber() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(null); when(atom.getSymbol()).thenReturn("C"); when(atom.getMassNumber()).thenReturn(12); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); RendererModel model = new RendererModel(); model.registerParameters(new StandardGenerator(new Font(Font.SANS_SERIF, Font.PLAIN, 12))); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, model); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(2)); assertThat(atomSymbol.elementOutline().text(), is("C")); }
@Test public void nullAtomicNumberAndSymbol() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(null); when(atom.getSymbol()).thenReturn(null); when(atom.getMassNumber()).thenReturn(0); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, new RendererModel()); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(1)); assertThat(atomSymbol.elementOutline().text(), is("*")); }
@Test public void unpairedElectronsAreAccessed() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(12); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); when(container.getConnectedSingleElectronsCount(atom)).thenReturn(1); RendererModel model = new RendererModel(); model.registerParameters(new StandardGenerator(new Font(Font.SANS_SERIF, Font.PLAIN, 12))); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, model); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(3)); verify(container).getConnectedSingleElectronsCount(atom); }