/** * Place hydrogens connected to the provided atom <i>atom</i> using the specified * <i>bondLength</i>. * * @param container atom container * @param bondLength bond length to user * @throws IllegalArgumentException thrown if the <i>atom</i> or <i>container</i> was null or the * atom has connected atoms which have not been placed. */ @TestMethod("testNoConnections,testNullContainer,unplacedNonHydrogen") public void placeHydrogens2D(IAtomContainer container, IAtom atom, double bondLength) { if (container == null) throw new IllegalArgumentException("cannot place hydrogens, no container provided"); if (atom.getPoint2d() == null) throw new IllegalArgumentException("cannot place hydrogens on atom without coordinates"); logger.debug( "placing hydrogens connected to atom ", atom.getSymbol(), ": ", atom.getPoint2d()); logger.debug("bond length", bondLength); AtomPlacer atomPlacer = new AtomPlacer(); atomPlacer.setMolecule(container); List<IAtom> connected = container.getConnectedAtomsList(atom); IAtomContainer placed = container.getBuilder().newInstance(IAtomContainer.class); IAtomContainer unplaced = container.getBuilder().newInstance(IAtomContainer.class); // divide connected atoms into those which are have and haven't been placed for (final IAtom conAtom : connected) { if (conAtom.getPoint2d() == null) { if (conAtom.getSymbol().equals("H")) { unplaced.addAtom(conAtom); } else { throw new IllegalArgumentException( "cannot place hydrogens, atom has connected" + " non-hydrogens without coordinates"); } } else { placed.addAtom(conAtom); } } logger.debug("Atom placement before procedure:"); logger.debug("Centre atom ", atom.getSymbol(), ": ", atom.getPoint2d()); for (int i = 0; i < unplaced.getAtomCount(); i++) { logger.debug("H-" + i, ": ", unplaced.getAtom(i).getPoint2d()); } Point2d centerPlacedAtoms = GeometryTools.get2DCenter(placed); atomPlacer.distributePartners(atom, placed, centerPlacedAtoms, unplaced, bondLength); logger.debug("Atom placement after procedure:"); logger.debug("Centre atom ", atom.getSymbol(), ": ", atom.getPoint2d()); for (int i = 0; i < unplaced.getAtomCount(); i++) { logger.debug("H-" + i, ": ", unplaced.getAtom(i).getPoint2d()); } }
/** * Positions the aliphatic substituents of a ring system * * @param rs The RingSystem for which the substituents are to be laid out * @return A list of atoms that where laid out */ public IAtomContainer placeRingSubstituents(IRingSet rs, double bondLength) { logger.debug("RingPlacer.placeRingSubstituents() start"); IRing ring = null; IAtom atom = null; IRingSet rings = null; IAtomContainer unplacedPartners = rs.getBuilder().newInstance(IAtomContainer.class); IAtomContainer sharedAtoms = rs.getBuilder().newInstance(IAtomContainer.class); IAtomContainer primaryAtoms = rs.getBuilder().newInstance(IAtomContainer.class); IAtomContainer treatedAtoms = rs.getBuilder().newInstance(IAtomContainer.class); Point2d centerOfRingGravity = null; for (int j = 0; j < rs.getAtomContainerCount(); j++) { ring = (IRing) rs.getAtomContainer(j); /* Get the j-th Ring in RingSet rs */ for (int k = 0; k < ring.getAtomCount(); k++) { unplacedPartners.removeAllElements(); sharedAtoms.removeAllElements(); primaryAtoms.removeAllElements(); atom = ring.getAtom(k); rings = rs.getRings(atom); centerOfRingGravity = GeometryTools.get2DCenter(rings); atomPlacer.partitionPartners(atom, unplacedPartners, sharedAtoms); atomPlacer.markNotPlaced(unplacedPartners); try { for (int f = 0; f < unplacedPartners.getAtomCount(); f++) { logger.debug( "placeRingSubstituents->unplacedPartners: " + (molecule.getAtomNumber(unplacedPartners.getAtom(f)) + 1)); } } catch (Exception exc) { } treatedAtoms.add(unplacedPartners); if (unplacedPartners.getAtomCount() > 0) { atomPlacer.distributePartners( atom, sharedAtoms, centerOfRingGravity, unplacedPartners, bondLength); } } } logger.debug("RingPlacer.placeRingSubstituents() end"); return treatedAtoms; }