Examples of IAtomContainer


Examples of org.openscience.cdk.interfaces.IAtomContainer

  }

  // OK
  public IAtomContainer deleteFragment(IAtomContainer selected) {

    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()) {
        IBond bond = it.next();
        if (!removed.contains(bond)) {
          removed.addBond(bond);
          ac.addBond(bond);
        }
      }
      ChemModelManipulator.removeAtomAndConnectedElectronContainers(
                                       chemModel, atom);
      for (IBond bond : ac.bonds()) {
        if (bond.getAtom(0) == atom)
          updateAtom(bond.getAtom(1));
        else
          updateAtom(bond.getAtom(0));
      }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

  public static void removeEmptyContainers(IChemModel chemModel) {
    Iterator<IAtomContainer> it = ChemModelManipulator
        .getAllAtomContainers(chemModel).iterator();
    while (it.hasNext()) {
      IAtomContainer ac = it.next();
      if (ac.getAtomCount() == 0) {
        chemModel.getMoleculeSet().removeAtomContainer(ac);
      }
    }
    if (chemModel.getMoleculeSet().getAtomContainerCount() == 0)
      chemModel.getMoleculeSet().addAtomContainer(
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

   *            The AtomContainer to work on
   *@param atom
   *            The Atom to update
   */
  public void updateAtom(IAtom atom) {
    IAtomContainer container = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atom);
    if (container != null) {
      updateAtom(container, atom);
    }
  }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

    }
  }

  // OK
  public void makeAllExplicitImplicit() {
    IAtomContainer undoRedoContainer = chemModel.getBuilder()
        .newInstance(IAtomContainer.class);
    List<IAtomContainer> containers = ChemModelManipulator
        .getAllAtomContainers(chemModel);
    for (int i = 0; i < containers.size(); i++) {
      IAtomContainer removeatoms = chemModel.getBuilder()
          .newInstance(IAtomContainer.class);
      for (IAtom atom : containers.get(i).atoms()) {
        if (atom.getSymbol().equals("H")) {
          removeatoms.addAtom(atom);
          removeatoms.addBond(containers.get(i)
              .getConnectedBondsList(atom).get(0));
          containers
              .get(i)
              .getConnectedAtomsList(atom)
              .get(0)
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

    structureChanged();
  }

  // OK
  public void makeAllImplicitExplicit() {
    IAtomContainer undoRedoContainer = chemModel.getBuilder()
        .newInstance(IAtomContainer.class);
    List<IAtomContainer> containers = ChemModelManipulator
        .getAllAtomContainers(chemModel);
    for (int i = 0; i < containers.size(); i++) {
      for (IAtom atom : containers.get(i).atoms()) {
        int hcount = atom.getImplicitHydrogenCount();
        for (int k = 0; k < hcount; k++) {
          IAtom newAtom = this.addAtomWithoutUndo("H", atom, false);
          IAtomContainer atomContainer = ChemModelManipulator
              .getRelevantAtomContainer(getIChemModel(), newAtom);
          IBond newBond = atomContainer.getBond(atom, newAtom);
          undoRedoContainer.addAtom(newAtom);
          undoRedoContainer.addBond(newBond);
        }
      }
    }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

    // more attractive and avoid tilted rings
    //
    Map<IAtom, IAtom> mergeMap = model.getMerge();
    it = model.getMerge().keySet().iterator();
    if (it.hasNext()) {
      IAtomContainer movedAtomContainer = renderer.getRenderer2DModel()
          .getSelection().getConnectedAtomContainer();
      if (movedAtomContainer != null) {
        IAtom atomA = (IAtom) it.next();
        IAtom atomB = mergeMap.get(atomA);
        Vector2d shift = new Vector2d();
        shift.sub(atomB.getPoint2d(), atomA.getPoint2d());

        for (IAtom shiftAtom : movedAtomContainer.atoms()) {
          shiftAtom.getPoint2d().add(shift);
        }
      }
    }
    List<IAtom> mergedAtoms = new ArrayList<IAtom>();
    List<IAtomContainer> containers = new ArrayList<IAtomContainer>();
    List<IAtomContainer> droppedContainers = new ArrayList<IAtomContainer>();

    List<List<IBond>> removedBondss = new ArrayList<List<IBond>>();
    List<Map<IBond, Integer>> bondsWithReplacedAtoms = new ArrayList<Map<IBond, Integer>>();
    List<IAtom> mergedPartnerAtoms = new ArrayList<IAtom>();

    // Done shifting, now the actual merging.
    it = model.getMerge().keySet().iterator();
    while (it.hasNext()) {
      List<IBond> removedBonds = new ArrayList<IBond>();
      Map<IBond, Integer> bondsWithReplacedAtom = new HashMap<IBond, Integer>();
      IAtom mergedAtom = (IAtom) it.next();

      mergedAtoms.add(mergedAtom);
      IAtom mergedPartnerAtom = model.getMerge().get(mergedAtom);
      mergedPartnerAtoms.add(mergedPartnerAtom);

      IAtomContainer container1 = ChemModelManipulator
          .getRelevantAtomContainer(chemModel, mergedAtom);
      containers.add(container1);

      IAtomContainer container2 = ChemModelManipulator
          .getRelevantAtomContainer(chemModel, mergedPartnerAtom);

      // If the atoms are in different atom containers till now, we merge
      // the atom containers first.
      if (container1 != container2) {
        container1.add(container2);
        chemModel.getMoleculeSet().removeAtomContainer(container2);
        droppedContainers.add(container2);
      } else {
        droppedContainers.add(null);
      }

      // Handle the case of a bond between mergedAtom and mergedPartnerAtom.
      // This bond should be removed.
      IBond rb = container1.getBond(mergedAtom, mergedPartnerAtom);
      if (rb != null) {
        container1.removeBond(rb);
        removedBonds.add(rb);
      }
       
      // In the next loop we remove bonds that are redundant, that is
      // to say bonds that exist on both sides of the parts to be merged
      // and would cause duplicate bonding in the end result.
      for (IAtom atom : container1.atoms()) {

        if (!atom.equals(mergedAtom)) {
          if (container1.getBond(mergedAtom, atom) != null) {
            if (model.getMerge().containsKey(atom)) {
              for (IAtom atom2 : container2.atoms()) {
                if (!atom2.equals(mergedPartnerAtom)) {
                  if (container1.getBond(mergedPartnerAtom,
                      atom2) != null) {
                    if (model.getMerge().get(atom).equals(
                        atom2)) {
                      IBond redundantBond = container1
                          .getBond(atom, mergedAtom);
                      container1
                          .removeBond(redundantBond);
                      removedBonds.add(redundantBond);
                    }
                  }
                }
              }
            }
          }
        }
      }
      removedBondss.add(removedBonds);

      // After the removal of redundant bonds, the actual merge is done.
      // One half of atoms in the merge map are removed and their bonds
      // are mapped to their replacement atoms.
      for (IBond bond : container1.bonds()) {
        if (bond.contains(mergedAtom)) {
          if (bond.getAtom(0).equals(mergedAtom)) {
            bond.setAtom(mergedPartnerAtom, 0);
            bondsWithReplacedAtom.put(bond, 0);
          } else {
            bond.setAtom(mergedPartnerAtom, 1);
            bondsWithReplacedAtom.put(bond, 1);
          }
        }
      }
      container1.removeAtom(mergedAtom);
      updateAtom(mergedPartnerAtom);
      bondsWithReplacedAtoms.add(bondsWithReplacedAtom);
    }

    Map<Integer, Map<Integer, Integer>> oldRGroupHash = null;
    Map<Integer, Map<Integer, Integer>> newRGroupHash = null;

    if (rGroupHandler != null) {
      try {
        oldRGroupHash = rGroupHandler.makeHash();
        rGroupHandler.adjustAtomContainers(chemModel.getMoleculeSet());
        newRGroupHash = rGroupHandler.makeHash();

      } catch (CDKException e) {
        unsetRGroupHandler();
        for (IAtomContainer atc : droppedContainers) {
          atc.setProperty(CDKConstants.TITLE, null);
        }
        e.printStackTrace();
      }
    }

    // Undo section to undo/redo the merge
    IUndoRedoFactory factory = getUndoRedoFactory();
    UndoRedoHandler handler = getUndoRedoHandler();
    if (movedDistance != null && factory != null && handler != null) {
      // we look if anything has been moved which was not merged
      IAtomContainer undoRedoContainer = getIChemModel().getBuilder()
          .newInstance(IAtomContainer.class);

      if (renderer.getRenderer2DModel().getSelection()
          .getConnectedAtomContainer() != null) {
        undoRedoContainer.add(renderer.getRenderer2DModel()
            .getSelection().getConnectedAtomContainer());
      }

      Iterator<IAtom> it2 = mergeMap.keySet().iterator();
      while (it2.hasNext()) {
        IAtom remove = it2.next();
        undoRedoContainer.removeAtom(remove);
      }
      IUndoRedoable moveundoredo = getUndoRedoFactory().getMoveAtomEdit(
          undoRedoContainer, movedDistance, "Move atom");
      IUndoRedoable undoredo = factory.getMergeMoleculesEdit(mergedAtoms,
          containers, droppedContainers, removedBondss,
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

   * org.openscience.cdk.controller.IChemModelRelay#removeBondAndLoneAtoms
   * (org.openscience.cdk.interfaces.IBond)
   */
  public void removeBondAndLoneAtoms(IBond bondToRemove) {

    IAtomContainer container = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, bondToRemove.getAtom(0));
    IAtomContainer undoRedoContainer = chemModel.getBuilder()
        .newInstance(IAtomContainer.class);
    undoRedoContainer.addBond(bondToRemove);

    removeBondWithoutUndo(bondToRemove);

    if (container != null) {
      for (int i = 0; i < 2; i++) {
        if (container.getConnectedAtomsCount(bondToRemove.getAtom(i)) == 0) {
          removeAtomWithoutUndo(bondToRemove.getAtom(i));
          undoRedoContainer.addAtom(bondToRemove.getAtom(i));
        }
      }
    }
    removeEmptyContainers(chemModel);
    IUndoRedoable undoredo = getUndoRedoFactory()
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

  // OK
  public void moveBy(Collection<IAtom> atoms, Vector2d move,
      Vector2d totalmove) {
    if (totalmove != null && getUndoRedoFactory() != null
        && getUndoRedoHandler() != null) {
      IAtomContainer undoRedoContainer = chemModel.getBuilder()
          .newInstance(IAtomContainer.class);
      for (IAtom atom : atoms) {
        undoRedoContainer.addAtom(atom);
      }
      IUndoRedoable undoredo = getUndoRedoFactory().getMoveAtomEdit(
          undoRedoContainer, totalmove, "Move atom");
      getUndoRedoHandler().postEdit(undoredo);
    }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

        JTextComponentFixture text = dialog.textBox();
        text.setText(file.toString());
        JButtonFixture savebutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        savebutton.click();
        MDLReader reader = new MDLReader(new FileInputStream(file));
        IAtomContainer mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals("aaa",(String)mol.getProperty(CDKConstants.TITLE));
  }
View Full Code Here

Examples of org.openscience.cdk.interfaces.IAtomContainer

        JTextComponentFixture text = dialog.textBox();
        text.setText(file.toString());
        JButtonFixture savebutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        savebutton.click();
        MDLReader reader = new MDLReader(new FileInputStream(file));
        IAtomContainer mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals("aaa",(String)mol.getProperty(CDKConstants.TITLE));
  }
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.