Examples of IRing


Examples of org.openscience.cdk.interfaces.IRing

      e.printStackTrace();
    }
  }

  public IRing addRing(int ringSize, Point2d worldcoord, boolean undoable) {
    IRing ring = chemModel.getBuilder().newInstance(IRing.class,ringSize, "C");
    double bondLength = calculateAverageBondLength(chemModel
        .getMoleculeSet());
    ringPlacer
        .placeRing(ring, worldcoord, bondLength, RingPlacer.jcpAngles);
    IAtomContainerSet set = chemModel.getMoleculeSet();

    // the molecule set should not be null, but just in case...
    if (set == null) {
      set = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
      chemModel.setMoleculeSet(set);
    }
    IAtomContainer newAtomContainer = chemModel.getBuilder().newInstance(IAtomContainer.class);
    if (chemModel.getMoleculeSet().getAtomContainer(0).getAtomCount() == 0)
      newAtomContainer = (IAtomContainer) chemModel.getMoleculeSet()
          .getAtomContainer(0);
    else
      chemModel.getMoleculeSet().addAtomContainer(newAtomContainer);
    newAtomContainer.add(ring);
    updateAtoms(ring, ring.atoms());
    structureChanged();
    if (undoable && getUndoRedoFactory() != null
        && getUndoRedoHandler() != null) {
      IUndoRedoable undoredo = getUndoRedoFactory()
          .getAddAtomsAndBondsEdit(getIChemModel(),
              ring.getBuilder().newInstance(IAtomContainer.class,ring), null,
              "Ring" + " " + ringSize, this);
      getUndoRedoHandler().postEdit(undoredo);
    }
    return ring;
  }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

    return ring;
  }

  // OK
  public IRing addPhenyl(Point2d worldcoord, boolean undoable) {
    IRing ring = chemModel.getBuilder().newInstance(IRing.class,6, "C");
    ring.getBond(0).setOrder(IBond.Order.DOUBLE);
    ring.getBond(2).setOrder(IBond.Order.DOUBLE);
    ring.getBond(4).setOrder(IBond.Order.DOUBLE);

    double bondLength = calculateAverageBondLength(chemModel
        .getMoleculeSet());
    ringPlacer
        .placeRing(ring, worldcoord, bondLength, RingPlacer.jcpAngles);
    IAtomContainerSet set = chemModel.getMoleculeSet();

    // the molecule set should not be null, but just in case...
    if (set == null) {
      set = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
      chemModel.setMoleculeSet(set);
    }
    IAtomContainer newAtomContainer = chemModel.getBuilder().newInstance(IAtomContainer.class);
    if (chemModel.getMoleculeSet().getAtomContainer(0).getAtomCount() == 0)
      newAtomContainer = (IAtomContainer) chemModel.getMoleculeSet()
          .getAtomContainer(0);
    else
      chemModel.getMoleculeSet().addAtomContainer(newAtomContainer);
    newAtomContainer.add(ring);
    updateAtoms(ring, ring.atoms());
    structureChanged();
    if (undoable && getUndoRedoFactory() != null
        && getUndoRedoHandler() != null) {
      IUndoRedoable undoredo = getUndoRedoFactory()
          .getAddAtomsAndBondsEdit(getIChemModel(),
              ring.getBuilder().newInstance(IAtomContainer.class,ring), null,
              "Benzene", this);
      getUndoRedoHandler().postEdit(undoredo);
    }
    return ring;
  }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

    IAtomContainer sourceContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atom);
    IAtomContainer sharedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
    sharedAtoms.addAtom(atom);

    IRing newRing = createAttachRing(sharedAtoms, ringSize, "C", phantom);
    double bondLength = GeometryTools.getBondLengthAverage(sourceContainer);
    Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms, chemModel);

    Point2d sharedAtomsCenter = atom.getPoint2d();
    Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter);
    ringCenterVector.sub(conAtomsCenter);

    if ((ringCenterVector.x == 0 && ringCenterVector.y == 0)) {
      // Rare bug case:
      // the spiro ring can not be attached, it will lead
      // to NaN values deeper down and serious picture distortion.
      // Instead, return empty ring, let user try otherwise..
      return chemModel.getBuilder().newInstance(IRing.class);
    } else {
      ringPlacer.placeSpiroRing(newRing, sharedAtoms, sharedAtomsCenter,
          ringCenterVector, bondLength);

      for (IAtom ringAtom : newRing.atoms()) {
        if (ringAtom != atom) {
          if (phantom)
            this.addPhantomAtom(ringAtom);
          else
            sourceContainer.addAtom(ringAtom);
        }
      }

      for (IBond ringBond : newRing.bonds()) {
        if (phantom)
          this.addPhantomBond(ringBond);
        else
          sourceContainer.addBond(ringBond);
      }
      if (!phantom)
        updateAtoms(sourceContainer, newRing.atoms());

      JChemPaintRendererModel rModel = this.getRenderer().getRenderer2DModel();
      double d = rModel.getHighlightDistance() / rModel.getScale();
      for (IAtom newatom : newRing.atoms()) {
        if (atom != newatom && getClosestAtom(atom) != null) {
          atom.getPoint2d().x += d;
        }
      }
      structureChanged();
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

        .getRelevantAtomContainer(chemModel, atom);
    IAtomContainer sharedAtoms = atom.getBuilder().newInstance(IAtomContainer.class);
    sharedAtoms.addAtom(atom);

    // make a benzene ring
    IRing newRing = createAttachRing(sharedAtoms, 6, "C", phantom);
    newRing.getBond(0).setOrder(IBond.Order.DOUBLE);
    newRing.getBond(2).setOrder(IBond.Order.DOUBLE);
    newRing.getBond(4).setOrder(IBond.Order.DOUBLE);

    double bondLength;
    if (sourceContainer.getBondCount() == 0) {
      /*
       * Special case of adding a ring to a single, unconnected atom -
       * places the ring centered on the place where the atom was.
       */
      bondLength = calculateAverageBondLength(chemModel.getMoleculeSet());
      Point2d ringCenter = new Point2d(atom.getPoint2d());
      ringPlacer.placeRing(newRing, ringCenter, bondLength,
          RingPlacer.jcpAngles);
    } else {
      bondLength = GeometryTools.getBondLengthAverage(sourceContainer);
      Point2d conAtomsCenter = getConnectedAtomsCenter(sharedAtoms,
          chemModel);

      Point2d sharedAtomsCenter = atom.getPoint2d();
      Vector2d ringCenterVector = new Vector2d(sharedAtomsCenter);
      ringCenterVector.sub(conAtomsCenter);

      if ((ringCenterVector.x == 0 && ringCenterVector.y == 0)) {
        return chemModel.getBuilder().newInstance(IRing.class);
      } else {
        ringPlacer.placeSpiroRing(newRing, sharedAtoms,
            sharedAtomsCenter, ringCenterVector, bondLength);
      }
    }

    // add the ring to the source container/phantoms
    for (IAtom ringAtom : newRing.atoms()) {
      if (ringAtom != atom) {
        if (phantom)
          this.addPhantomAtom(ringAtom);
        else
          sourceContainer.addAtom(ringAtom);
      }
    }

    for (IBond ringBond : newRing.bonds()) {
      if (phantom)
        this.addPhantomBond(ringBond);
      else
        sourceContainer.addBond(ringBond);
    }
    if (!phantom)
      updateAtoms(sourceContainer, newRing.atoms());
    for (IAtom newatom : newRing.atoms()) {
      if (atom != newatom && getClosestAtom(atom) != null) {
        JChemPaintRendererModel rModel = this.getRenderer().getRenderer2DModel();
        double d = rModel.getHighlightDistance() / rModel.getScale();
        atom.getPoint2d().x += d;
      }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

   *            into undo.
   * @return The constructed Ring
   */
  private IRing createAttachRing(IAtomContainer sharedAtoms, int ringSize,
      String symbol, boolean phantom) {
    IRing newRing = sharedAtoms.getBuilder().newInstance(IRing.class,ringSize);
    IAtom[] ringAtoms = new IAtom[ringSize];
    for (int i = 0; i < sharedAtoms.getAtomCount(); i++) {
      ringAtoms[i] = sharedAtoms.getAtom(i);
    }
    for (int i = sharedAtoms.getAtomCount(); i < ringSize; i++) {
      ringAtoms[i] = sharedAtoms.getBuilder().newInstance(IAtom.class,symbol);
    }
    for (IBond bond : sharedAtoms.bonds())
      newRing.addBond(bond);
    for (int i = sharedAtoms.getBondCount(); i < ringSize - 1; i++) {
      newRing.addBond(sharedAtoms.getBuilder().newInstance(IBond.class,ringAtoms[i],
          ringAtoms[i + 1], IBond.Order.SINGLE));
    }
    newRing.addBond(sharedAtoms.getBuilder().newInstance(IBond.class,
        ringAtoms[ringSize - 1], ringAtoms[0], IBond.Order.SINGLE));
    newRing.setAtoms(ringAtoms);
    if (!phantom && getUndoRedoFactory() != null
        && getUndoRedoHandler() != null) {
      IAtomContainer undoRedoContainer = newRing.getBuilder()
          .newInstance(IAtomContainer.class,newRing);
      for (IAtom atom : sharedAtoms.atoms())
        undoRedoContainer.removeAtom(atom);
      for (IBond bond : sharedAtoms.bonds())
        undoRedoContainer.removeBond(bond);
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

      ringCenterVector.sub(newPoint2);
    }

    // construct a new Ring that contains the highlighted bond an its two
    // atoms
    IRing newRing = createAttachRing(sharedAtoms, size, "C", phantom);
    ringPlacer.placeFusedRing(newRing, sharedAtoms, sharedAtomsCenter,
        ringCenterVector, bondLength);
    // add the new atoms and bonds
    for (IAtom ringAtom : newRing.atoms()) {
      if (ringAtom != firstAtom && ringAtom != secondAtom) {
        if (phantom)
          addPhantomAtom(ringAtom);
        else
          sourceContainer.addAtom(ringAtom);
      }
    }
    for (IBond ringBond : newRing.bonds()) {
      if (ringBond != bond) {
        if (phantom)
          addPhantomBond(ringBond);
        else
          sourceContainer.addBond(ringBond);
      }
    }
    if (!phantom)
      updateAtoms(sourceContainer, newRing.atoms());

    JChemPaintRendererModel rModel = this.getRenderer().getRenderer2DModel();
    double d = rModel.getHighlightDistance() / rModel.getScale();
    for (IAtom atom : newRing.atoms()) {
      if (atom != firstAtom && atom != secondAtom
          && getClosestAtom(atom) != null) {
        atom.getPoint2d().x += d;
      }
    }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

      ringCenterVector.sub(newPoint2);
    }

    // construct a new Ring that contains the highlighted bond an its two
    // atoms
    IRing newRing = createAttachRing(sharedAtoms, 6, "C", phantom);
    ringPlacer.placeFusedRing(newRing, sharedAtoms, sharedAtomsCenter,
        ringCenterVector, bondLength);
    if (sourceContainer.getMaximumBondOrder(bond.getAtom(0)) == IBond.Order.SINGLE
        && sourceContainer.getMaximumBondOrder(bond.getAtom(1)) == IBond.Order.SINGLE) {
      newRing.getBond(1).setOrder(IBond.Order.DOUBLE);
      newRing.getBond(3).setOrder(IBond.Order.DOUBLE);
      newRing.getBond(5).setOrder(IBond.Order.DOUBLE);
    } else { // assume Order.DOUBLE, so only need to add 2 double bonds
      newRing.getBond(2).setOrder(IBond.Order.DOUBLE);
      newRing.getBond(4).setOrder(IBond.Order.DOUBLE);
    }
    // add the new atoms and bonds
    for (IAtom ringAtom : newRing.atoms()) {
      if (ringAtom != firstAtom && ringAtom != secondAtom) {
        if (phantom)
          this.addPhantomAtom(ringAtom);
        else
          sourceContainer.addAtom(ringAtom);
      }
    }
    for (IBond ringBond : newRing.bonds()) {
      if (ringBond != bond) {
        if (phantom)
          this.addPhantomBond(ringBond);
        else
          sourceContainer.addBond(ringBond);
      }
    }
    if (!phantom)
      updateAtoms(sourceContainer, newRing.atoms());

    JChemPaintRendererModel rModel = this.getRenderer().getRenderer2DModel();
    double d = rModel.getHighlightDistance() / rModel.getScale();
    for (IAtom atom : newRing.atoms()) {
      if (atom != firstAtom && atom != secondAtom
          && getClosestAtom(atom) != null) {
        atom.getPoint2d().x += d;
      }
    }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

            return chemModelRelay.addRing(ringSize, p, false);
        }
    }

    private IRing addRingToAtom(IAtom closestAtom, boolean phantom) {
        IRing newring;
        if (addingBenzene) {
           newring = chemModelRelay.addPhenyl(closestAtom, phantom);
        } else {
            newring = chemModelRelay.addRing(closestAtom, ringSize, phantom);
        }
        newring.removeAtom(closestAtom);
        return newring;
    }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

        newring.removeAtom(closestAtom);
        return newring;
    }

    private IRing addRingToBond(IBond bond, boolean phantom) {
        IRing newring;
        if (addingBenzene) {
            newring = chemModelRelay.addPhenyl(bond, phantom);
        } else {
           newring = chemModelRelay.addRing(bond, ringSize, phantom);
        }
        newring.removeAtom(bond.getAtom(0));
        newring.removeAtom(bond.getAtom(1));
        newring.removeBond(bond);
        return newring;
    }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IRing

        IChemObject singleSelection = getHighlighted( worldCoord,
                                                      closestAtom,closestBond );

        if (singleSelection == null) {
            //we add the ring
        IRing newRing = this.addRingToEmptyCanvas(worldCoord);
            chemModelRelay.getRenderer().getRenderer2DModel().getMerge().clear();
            //we look if it would merge
            for(IAtom atom : newRing.atoms()){
                IAtom closestAtomInRing = this.chemModelRelay.getClosestAtom(atom);
                if( closestAtomInRing != null) {
                        chemModelRelay.getRenderer().getRenderer2DModel().getMerge().put(atom, closestAtomInRing);
                }
            }
            //if we need to merge, we first move the ring so that the merge atoms
            //are exactly on top of each other - if not doing this, rings get distorted.
            if(chemModelRelay.getRenderer().getRenderer2DModel().getMerge().size()>0){
                try {
                    IAtom toleave = chemModelRelay.getRenderer().getRenderer2DModel().getMerge().keySet().iterator().next();
                    IAtom toshift = (IAtom)chemModelRelay.getRenderer().getRenderer2DModel().getMerge().get(chemModelRelay.getRenderer().getRenderer2DModel().getMerge().keySet().iterator().next()).clone();
                    toleave.getPoint2d().sub(toshift.getPoint2d());
                    Point2d pointSub = new Point2d(toleave.getPoint2d().x, toleave.getPoint2d().y);
                    for(IAtom atom: newRing.atoms()){
                        atom.getPoint2d().sub(pointSub);
                    }
                } catch (CloneNotSupportedException e) {
                    //should not happen
                }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.