Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtom


   * org.openscience.cdk.controller.IChemModelRelay#addAtomWithoutUndo(java
   * .lang.String, int, javax.vecmath.Point2d)
   */
  public IAtom addAtomWithoutUndo(String atomType, int isotopeNumber,
      Point2d worldCoord, boolean makePseudoAtom) {
    IAtom newAtom;
    if (makePseudoAtom) {
      newAtom = chemModel.getBuilder()
          .newInstance(IPseudoAtom.class,atomType, worldCoord);
    } else {
      newAtom = chemModel.getBuilder().newInstance(IAtom.class,atomType, worldCoord);
    }
    if (isotopeNumber != 0)
      newAtom.setMassNumber(isotopeNumber);
    // FIXME : there should be an initial hierarchy?
    IAtomContainerSet molSet = chemModel.getMoleculeSet();
    if (molSet == null) {
      molSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
      IAtomContainer ac = chemModel.getBuilder().newInstance(IAtomContainer.class);
      ac.addAtom(newAtom);
      molSet.addAtomContainer(ac);
      chemModel.setMoleculeSet(molSet);
    }
    IAtomContainer newAtomContainer = chemModel.getBuilder().newInstance(IAtomContainer.class);
    if (chemModel.getMoleculeSet().getAtomContainer(0).getAtomCount() == 0)
      newAtomContainer = (IAtomContainer) chemModel.getMoleculeSet()
          .getAtomContainer(0);
    else
      molSet.addAtomContainer(newAtomContainer);
    newAtomContainer.addAtom(newAtom);
    updateAtom(newAtom);
    JChemPaintRendererModel model = this.getRenderer().getRenderer2DModel();
    double nudgeDistance = model.getHighlightDistance() / model.getScale();
    if (getClosestAtom(newAtom) != null)
      newAtom.getPoint2d().x += nudgeDistance;
    structureChanged();
    return newAtom;
  }
View Full Code Here


   * org.openscience.cdk.controller.IChemModelRelay#addAtomWithoutUndo(java
   * .lang.String, org.openscience.cdk.interfaces.IAtom, int)
   */
  public IAtom addAtomWithoutUndo(String atomType, IAtom atom,
      IBond.Stereo stereo, Order order, boolean makePseudoAtom) {
    IAtom newAtom;
    if (makePseudoAtom) {
      newAtom = chemModel.getBuilder().newInstance(IPseudoAtom.class,atomType);
    } else {
      newAtom = chemModel.getBuilder().newInstance(IAtom.class,atomType);
    }
    IBond newBond;
    if (order == IBond.Order.DOUBLE) {
      newBond = chemModel.getBuilder().newInstance(IBond.class,atom, newAtom,
          CDKConstants.BONDORDER_DOUBLE, stereo);
    } else if (order == IBond.Order.TRIPLE) {
      newBond = chemModel.getBuilder().newInstance(IBond.class,atom, newAtom,
          CDKConstants.BONDORDER_TRIPLE, stereo);
    } else {
      newBond = chemModel.getBuilder().newInstance(IBond.class,atom, newAtom,
          CDKConstants.BONDORDER_SINGLE, stereo);
    }

    IAtomContainer atomCon = ChemModelManipulator.getRelevantAtomContainer(
        chemModel, atom);
    if (atomCon == null) {
      atomCon = chemModel.getBuilder().newInstance(IAtomContainer.class);
      IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
      if (moleculeSet == null) {
        moleculeSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
        chemModel.setMoleculeSet(moleculeSet);
      }
      moleculeSet.addAtomContainer(atomCon);
    }

    // The AtomPlacer generates coordinates for the new atom
    AtomPlacer atomPlacer = new AtomPlacer();
    atomPlacer.setMolecule(chemModel.getBuilder().newInstance(IAtomContainer.class,atomCon));
    double bondLength;
    if (atomCon.getBondCount() >= 1) {
      bondLength = GeometryTools.getBondLengthAverage(atomCon);
    } else {
      bondLength = calculateAverageBondLength(chemModel.getMoleculeSet());
    }

    // determine the atoms which define where the
    // new atom should not be placed
    List<IAtom> connectedAtoms = atomCon.getConnectedAtomsList(atom);

    if (connectedAtoms.size() == 0) {
      Point2d newAtomPoint = new Point2d(atom.getPoint2d());
      double angle = Math.toRadians(-30);
      Vector2d vec1 = new Vector2d(Math.cos(angle), Math.sin(angle));
      vec1.scale(bondLength);
      newAtomPoint.add(vec1);
      newAtom.setPoint2d(newAtomPoint);
    } else if (connectedAtoms.size() == 1) {
      IAtomContainer ac = atomCon.getBuilder().newInstance(IAtomContainer.class);
      ac.addAtom(atom);
      ac.addAtom(newAtom);
      Point2d distanceMeasure = new Point2d(0, 0); // XXX not sure about
      // this?
      IAtom connectedAtom = connectedAtoms.get(0);
      Vector2d v = atomPlacer.getNextBondVector(atom, connectedAtom,
          distanceMeasure, true);
      atomPlacer.placeLinearChain(ac, v, bondLength);
    } else {
      IAtomContainer placedAtoms = atomCon.getBuilder().newInstance(IAtomContainer.class);
View Full Code Here

    IAtomContainer undoRedoContainer = getIChemModel().getBuilder()
        .newInstance(IAtomContainer.class);

    // add the first atom in the new bond
    String atomType = getController2DModel().getDrawElement();
    IAtom atom = addAtomWithoutUndo(atomType, worldCoordinate,
        makePseudoAtom);
    undoRedoContainer.addAtom(atom);

    // add the second atom to this
    IAtom newAtom = addAtomWithoutUndo(atomType, atom, makePseudoAtom);
    undoRedoContainer.addAtom(newAtom);

    IAtomContainer atomContainer = ChemModelManipulator
        .getRelevantAtomContainer(getIChemModel(), newAtom);
View Full Code Here

  }

  // OK
  public IBond makeNewStereoBond(IAtom atom, Direction desiredDirection) {
    String atomType = getController2DModel().getDrawElement();
    IAtom newAtom = addAtomWithoutUndo(atomType, atom, controllerModel
        .getDrawPseudoAtom());
    IAtomContainer undoRedoContainer = getIChemModel().getBuilder()
        .newInstance(IAtomContainer.class);

    // XXX these calls would not be necessary if addAtom returned a bond
View Full Code Here

          .getChangeAtomSymbolEdit(atom, atom.getSymbol(), symbol,
              "Change Atom Symbol to " + symbol, this);
      getUndoRedoHandler().postEdit(undoredo);
    }
    if (atom instanceof IPseudoAtom) {
      IAtom newAtom = atom.getBuilder()
          .newInstance(IAtom.class,symbol, atom.getPoint2d());
      replaceAtom(newAtom, atom);
      atom = newAtom;
    } else {
      atom.setSymbol(symbol);
View Full Code Here

   * org.openscience.cdk.controller.IChemModelRelay#addRing(org.openscience
   * .cdk.interfaces.IBond, int, boolean)
   */
  public IRing addRing(IBond bond, int size, boolean phantom) {
    IAtomContainer sharedAtoms = bond.getBuilder().newInstance(IAtomContainer.class);
    IAtom firstAtom = bond.getAtom(0); // Assumes two-atom bonds only
    IAtom secondAtom = bond.getAtom(1);
    sharedAtoms.addAtom(firstAtom);
    sharedAtoms.addAtom(secondAtom);
    sharedAtoms.addBond(bond);
    IAtomContainer sourceContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, firstAtom);

    Point2d sharedAtomsCenter = GeometryTools.get2DCenter(sharedAtoms);

    // calculate two points that are perpendicular to the highlighted bond
    // and have a certain distance from the bond center
    Point2d firstPoint = firstAtom.getPoint2d();
    Point2d secondPoint = secondAtom.getPoint2d();
    Vector2d diff = new Vector2d(secondPoint);
    diff.sub(firstPoint);
    double bondLength = firstPoint.distance(secondPoint);
    double angle = GeometryTools.getAngle(diff.x, diff.y);
    Point2d newPoint1 = new Point2d( // FIXME: what is this point??
View Full Code Here

  public IAtom getAtomInRange(Collection<IAtom> toIgnore, IAtom atom) {
    Point2d atomPosition = atom.getPoint2d();
    JChemPaintRendererModel rModel = this.getRenderer().getRenderer2DModel();
    double highlight = rModel.getHighlightDistance() / rModel.getScale();

    IAtom bestClosestAtom = null;
    double bestDistance = -1;
    for (IAtomContainer atomContainer : ChemModelManipulator
        .getAllAtomContainers(getIChemModel())) {

      IAtom closestAtom = GeometryTools.getClosestAtom(atomContainer,
          atom);

      if (closestAtom != null) {
        double distance = closestAtom.getPoint2d().distance(
            atomPosition);
        if ((distance > highlight)
            || (toIgnore != null && toIgnore.contains(closestAtom))) {
          continue;
        } else {
View Full Code Here

   * org.openscience.cdk.controller.IChemModelRelay#addPhenyl(org.openscience
   * .cdk.interfaces.IBond, boolean)
   */
  public IRing addPhenyl(IBond bond, boolean phantom) {
    IAtomContainer sharedAtoms = bond.getBuilder().newInstance(IAtomContainer.class);
    IAtom firstAtom = bond.getAtom(0); // Assumes two-atom bonds only
    IAtom secondAtom = bond.getAtom(1);
    sharedAtoms.addAtom(firstAtom);
    sharedAtoms.addAtom(secondAtom);
    sharedAtoms.addBond(bond);
    IAtomContainer sourceContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, firstAtom);

    Point2d sharedAtomsCenter = GeometryTools.get2DCenter(sharedAtoms);

    // calculate two points that are perpendicular to the highlighted bond
    // and have a certain distance from the bond center
    Point2d firstPoint = firstAtom.getPoint2d();
    Point2d secondPoint = secondAtom.getPoint2d();
    Vector2d diff = new Vector2d(secondPoint);
    diff.sub(firstPoint);
    double bondLength = firstPoint.distance(secondPoint);
    double angle = GeometryTools.getAngle(diff.x, diff.y);
    Point2d newPoint1 = new Point2d( // FIXME: what is this point??
View Full Code Here

        toflip.add(atomContainer);
      }
    }
    Point2d center = GeometryTools.get2DCenter(toflip);
    for (int i = 0; i < toflip.getAtomCount(); i++) {
      IAtom atom = toflip.getAtom(i);
      Point2d p2d = atom.getPoint2d();
      Point2d oldCoord = new Point2d(p2d.x, p2d.y);
      if (horizontal) {
        p2d.y = 2.0 * center.y - p2d.y;
      } else {
        p2d.x = 2.0 * center.x - p2d.x;
View Full Code Here

    IAtomContainer removed = selected.getBuilder().newInstance(IAtomContainer.class);
    if(rGroupHandler!=null && !rGroupHandler.checkRGroupOkayForDelete(selected, this))
      return removed;
   
    for (int i = 0; i < selected.getAtomCount(); i++) {
      IAtom atom = selected.getAtom(i);
      removed.addAtom(atom);
      Iterator<IBond> it = ChemModelManipulator.getRelevantAtomContainer(
          chemModel, atom).getConnectedBondsList(atom).iterator();
      IAtomContainer ac = selected.getBuilder().newInstance(IAtomContainer.class);
      while (it.hasNext()) {
View Full Code Here

TOP

Related Classes of org.openscience.cdk.interfaces.IAtom

Copyright © 2018 www.massapicom. 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.