Example #1
0
  /**
   * 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());
    }
  }
Example #2
0
  /**
   * Place ring with user provided angles.
   *
   * @param ring the ring to place.
   * @param ringCenter center coordinates of the ring.
   * @param bondLength given bond length.
   * @param startAngles a map with start angles when drawing the ring.
   */
  public void placeRing(
      IRing ring, Point2d ringCenter, double bondLength, Map<Integer, Double> startAngles) {
    double radius = this.getNativeRingRadius(ring, bondLength);
    double addAngle = 2 * Math.PI / ring.getRingSize();

    IAtom startAtom = ring.getFirstAtom();
    Point2d p = new Point2d(ringCenter.x + radius, ringCenter.y);
    startAtom.setPoint2d(p);
    double startAngle = Math.PI * 0.5;

    /* Different ring sizes get different start angles to have
     * visually correct placement */
    int ringSize = ring.getRingSize();
    if (startAngles.get(ringSize) != null) startAngle = startAngles.get(ringSize);

    List<IBond> bonds = ring.getConnectedBondsList(startAtom);
    /*
     * Store all atoms to draw in consecutive order relative to the
     * chosen bond.
     */
    Vector<IAtom> atomsToDraw = new Vector<IAtom>();
    IAtom currentAtom = startAtom;
    IBond currentBond = (IBond) bonds.get(0);
    for (int i = 0; i < ring.getBondCount(); i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }
Example #3
0
  /**
   * 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;
  }
Example #4
0
  /**
   * Generated coordinates for a given ring, which is connected to a spiro ring. The rings share
   * exactly one atom.
   *
   * @param ring The ring to be placed
   * @param sharedAtoms The atoms of this ring, also members of another ring, which are already
   *     placed
   * @param sharedAtomsCenter The geometric center of these atoms
   * @param ringCenterVector A vector pointing the the center of the new ring
   * @param bondLength The standard bondlength
   */
  public void placeSpiroRing(
      IRing ring,
      IAtomContainer sharedAtoms,
      Point2d sharedAtomsCenter,
      Vector2d ringCenterVector,
      double bondLength) {

    logger.debug("placeSpiroRing");
    double radius = getNativeRingRadius(ring, bondLength);
    Point2d ringCenter = new Point2d(sharedAtomsCenter);
    ringCenterVector.normalize();
    ringCenterVector.scale(radius);
    ringCenter.add(ringCenterVector);
    double addAngle = 2 * Math.PI / ring.getRingSize();

    IAtom startAtom = sharedAtoms.getAtom(0);

    // double centerX = ringCenter.x;
    // double centerY = ringCenter.y;

    // int direction = 1;

    IAtom currentAtom = startAtom;
    double startAngle =
        GeometryTools.getAngle(
            startAtom.getPoint2d().x - ringCenter.x, startAtom.getPoint2d().y - ringCenter.y);
    /*
     * Get one bond connected to the spiro bridge atom.
     * It doesn't matter in which direction we draw.
     */
    java.util.List bonds = ring.getConnectedBondsList(startAtom);

    IBond currentBond = (IBond) bonds.get(0);

    Vector atomsToDraw = new Vector();
    /*
     * Store all atoms to draw in consequtive order relative to the
     * chosen bond.
     */
    for (int i = 0; i < ring.getBondCount(); i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    logger.debug("currentAtom  " + currentAtom);
    logger.debug("startAtom  " + startAtom);

    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }
Example #5
0
  /**
   * Generated coordinates for a given ring, which is fused to another ring. The rings share exactly
   * one bond.
   *
   * @param ring The ring to be placed
   * @param sharedAtoms The atoms of this ring, also members of another ring, which are already
   *     placed
   * @param sharedAtomsCenter The geometric center of these atoms
   * @param ringCenterVector A vector pointing the the center of the new ring
   * @param bondLength The standard bondlength
   */
  public void placeFusedRing(
      IRing ring,
      IAtomContainer sharedAtoms,
      Point2d sharedAtomsCenter,
      Vector2d ringCenterVector,
      double bondLength) {
    logger.debug("RingPlacer.placeFusedRing() start");
    Point2d ringCenter = new Point2d(sharedAtomsCenter);
    double radius = getNativeRingRadius(ring, bondLength);
    double newRingPerpendicular = Math.sqrt(Math.pow(radius, 2) - Math.pow(bondLength / 2, 2));
    ringCenterVector.normalize();
    logger.debug("placeFusedRing->: ringCenterVector.length()" + ringCenterVector.length());
    ringCenterVector.scale(newRingPerpendicular);
    ringCenter.add(ringCenterVector);

    IAtom bondAtom1 = sharedAtoms.getAtom(0);
    IAtom bondAtom2 = sharedAtoms.getAtom(1);

    Vector2d bondAtom1Vector = new Vector2d(bondAtom1.getPoint2d());
    Vector2d bondAtom2Vector = new Vector2d(bondAtom2.getPoint2d());
    Vector2d originRingCenterVector = new Vector2d(ringCenter);

    bondAtom1Vector.sub(originRingCenterVector);
    bondAtom2Vector.sub(originRingCenterVector);

    double occupiedAngle = bondAtom1Vector.angle(bondAtom2Vector);

    double remainingAngle = (2 * Math.PI) - occupiedAngle;
    double addAngle = remainingAngle / (ring.getRingSize() - 1);

    logger.debug("placeFusedRing->occupiedAngle: " + Math.toDegrees(occupiedAngle));
    logger.debug("placeFusedRing->remainingAngle: " + Math.toDegrees(remainingAngle));
    logger.debug("placeFusedRing->addAngle: " + Math.toDegrees(addAngle));

    IAtom startAtom;

    double centerX = ringCenter.x;
    double centerY = ringCenter.y;

    double xDiff = bondAtom1.getPoint2d().x - bondAtom2.getPoint2d().x;
    double yDiff = bondAtom1.getPoint2d().y - bondAtom2.getPoint2d().y;

    double startAngle;
    ;

    int direction = 1;
    // if bond is vertical
    if (xDiff == 0) {
      logger.debug("placeFusedRing->Bond is vertical");
      // starts with the lower Atom
      if (bondAtom1.getPoint2d().y > bondAtom2.getPoint2d().y) {
        startAtom = bondAtom1;
      } else {
        startAtom = bondAtom2;
      }

      // changes the drawing direction
      if (centerX < bondAtom1.getPoint2d().x) {
        direction = 1;
      } else {
        direction = -1;
      }
    }

    // if bond is not vertical
    else {
      // starts with the left Atom
      if (bondAtom1.getPoint2d().x > bondAtom2.getPoint2d().x) {
        startAtom = bondAtom1;
      } else {
        startAtom = bondAtom2;
      }

      // changes the drawing direction
      if (centerY - bondAtom1.getPoint2d().y
          > (centerX - bondAtom1.getPoint2d().x) * yDiff / xDiff) {
        direction = 1;
      } else {
        direction = -1;
      }
    }
    startAngle =
        GeometryTools.getAngle(
            startAtom.getPoint2d().x - ringCenter.x, startAtom.getPoint2d().y - ringCenter.y);

    IAtom currentAtom = startAtom;
    // determine first bond in Ring
    //        int k = 0;
    //        for (k = 0; k < ring.getElectronContainerCount(); k++) {
    //            if (ring.getElectronContainer(k) instanceof IBond) break;
    //        }
    IBond currentBond = sharedAtoms.getBond(0);
    Vector atomsToDraw = new Vector();
    for (int i = 0; i < ring.getBondCount() - 2; i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    addAngle = addAngle * direction;
    try {
      logger.debug("placeFusedRing->startAngle: " + Math.toDegrees(startAngle));
      logger.debug("placeFusedRing->addAngle: " + Math.toDegrees(addAngle));
      logger.debug("placeFusedRing->startAtom is: " + (molecule.getAtomNumber(startAtom) + 1));
      logger.debug("AtomsToDraw: " + atomPlacer.listNumbers(molecule, atomsToDraw));
    } catch (Exception exc) {
      logger.debug("Caught an exception while logging in RingPlacer");
    }
    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }