Пример #1
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);
  }
Пример #2
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);
  }