HydrogenPlacer { public void placeHydrogens2D(final IAtomContainer container, final double bondLength) { logger.debug("placing hydrogens on all atoms"); for (IAtom atom : container.atoms()) { if (atom.getPoint2d() != null) { placeHydrogens2D(container, atom, bondLength); } } logger.debug("hydrogen placement complete"); }  void placeHydrogens2D(final IAtomContainer container, final double bondLength); void placeHydrogens2D(IAtomContainer container, IAtom atom); void placeHydrogens2D(IAtomContainer container, IAtom atom, double bondLength);  }
@Test(expected = IllegalArgumentException.class) public void testAtomWithoutCoordinates() { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); hydrogenPlacer.placeHydrogens2D(new AtomContainer(), new Atom(), 1.5); }
@Test(expected = IllegalArgumentException.class) public void testNullContainer() { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); hydrogenPlacer.placeHydrogens2D(null, new Atom(), 1.5); }
@Test public void testNoConnections() { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); AtomContainer container = new AtomContainer(); Atom atom = new Atom("C", new Point2d(0, 0)); container.addAtom(atom); hydrogenPlacer.placeHydrogens2D(container, atom, 1.5); }
@Test public void testH2() { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); IAtom h1 = new Atom("H"); IAtom h2 = new Atom("H", new Point2d(0, 0)); IAtomContainer m = new AtomContainer(); m.addAtom(h1); m.addAtom(h2); m.addBond(new Bond(h1, h2)); hydrogenPlacer.placeHydrogens2D(m, 1.5); assertNotNull(h1.getPoint2d()); }
@Test(expected = IllegalArgumentException.class) public void unplacedNonHydrogen() { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); IAtom c1 = new Atom("C", new Point2d(0, 0)); IAtom c2 = new Atom("C"); IAtomContainer m = new AtomContainer(); m.addAtom(c1); m.addAtom(c2); m.addBond(new Bond(c1, c2)); hydrogenPlacer.placeHydrogens2D(m, 1.5); }
@Test public void testBug933572() throws Exception { IAtomContainer ac = new AtomContainer(); ac.addAtom(new Atom("H")); ac.getAtom(0).setPoint2d(new Point2d(0, 0)); addExplicitHydrogens(ac); HydrogenPlacer hPlacer = new HydrogenPlacer(); hPlacer.placeHydrogens2D(ac, 36); for (int i = 0; i < ac.getAtomCount(); i++) { Assert.assertNotNull(ac.getAtom(i).getPoint2d()); } }
@Test public void testPlaceHydrogens2D() throws Exception { HydrogenPlacer hydrogenPlacer = new HydrogenPlacer(); IAtomContainer dichloromethane = new AtomContainer(); Atom carbon = new Atom("C"); Point2d carbonPos = new Point2d(0.0, 0.0); carbon.setPoint2d(carbonPos); Atom h1 = new Atom("H"); Atom h2 = new Atom("H"); Atom cl1 = new Atom("Cl"); Point2d cl1Pos = new Point2d(0.0, -1.0); cl1.setPoint2d(cl1Pos); Atom cl2 = new Atom("Cl"); Point2d cl2Pos = new Point2d(-1.0, 0.0); cl2.setPoint2d(cl2Pos); dichloromethane.addAtom(carbon); dichloromethane.addAtom(h1); dichloromethane.addAtom(h2); dichloromethane.addAtom(cl1); dichloromethane.addAtom(cl2); dichloromethane.addBond(new Bond(carbon, h1)); dichloromethane.addBond(new Bond(carbon, h2)); dichloromethane.addBond(new Bond(carbon, cl1)); dichloromethane.addBond(new Bond(carbon, cl2)); Assert.assertNull(h1.getPoint2d()); Assert.assertNull(h2.getPoint2d()); hydrogenPlacer.placeHydrogens2D(dichloromethane, carbon); assertEquals(carbonPos, carbon.getPoint2d(), 0.01); assertEquals(cl1Pos, cl1.getPoint2d(), 0.01); assertEquals(cl2Pos, cl2.getPoint2d(), 0.01); Assert.assertNotNull(h1.getPoint2d()); Assert.assertNotNull(h2.getPoint2d()); }