Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtomContainer


    return newAtom;
  }

  // OK
  public IAtom addAtom(String atomType, IAtom atom, boolean makePseudoAtom) {
    IAtomContainer undoRedoContainer = atom.getBuilder().newInstance(IAtomContainer.class);
    undoRedoContainer.addAtom(addAtomWithoutUndo(atomType, atom,
        makePseudoAtom));
    IAtomContainer atomContainer = ChemModelManipulator
        .getRelevantAtomContainer(getIChemModel(), undoRedoContainer
            .getAtom(0));
    IBond newBond = atomContainer.getBond(atom, undoRedoContainer
        .getAtom(0));
    undoRedoContainer.addBond(newBond);
    if (getUndoRedoFactory() != null && getUndoRedoHandler() != null) {
      IUndoRedoable undoredo = getUndoRedoFactory()
          .getAddAtomsAndBondsEdit(chemModel, undoRedoContainer,
View Full Code Here


    } 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);
      for (IAtom conAtom : connectedAtoms)
        placedAtoms.addAtom(conAtom);
      Point2d center2D = GeometryTools.get2DCenter(placedAtoms);

      IAtomContainer unplacedAtoms = atomCon.getBuilder()
          .newInstance(IAtomContainer.class);
      unplacedAtoms.addAtom(newAtom);

      atomPlacer.distributePartners(atom, placedAtoms, center2D,
          unplacedAtoms, bondLength);
    }
View Full Code Here

        } catch (Exception e) {
          // TODO Auto-generated catch block
          Assert.fail("File not found.");
          return;
        }
        IAtomContainer mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        JPanelFixture jcppanel=applet.panel("appletframe");
        JChemPaintPanel panel = (JChemPaintPanel)jcppanel.target;
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtomCount(), mol.getAtomCount());
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBondCount(), mol.getBondCount());
    }
View Full Code Here

        } catch (Exception e) {
          // TODO Auto-generated catch block
          Assert.fail("File not found.");
          return;
        }
        IAtomContainer mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        JPanelFixture jcppanel=applet.panel("appletframe");
        JChemPaintPanel panel = (JChemPaintPanel)jcppanel.target;
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtomCount(), mol.getAtomCount());
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBondCount(), mol.getBondCount());
    }
View Full Code Here

        makePseudoAtom);
  }

  // OK
  public void addNewBond(Point2d worldCoordinate, boolean makePseudoAtom) {
    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);

    IBond newBond = atomContainer.getBond(atom, newAtom);
    undoRedoContainer.addBond(newBond);
    updateAtom(newBond.getAtom(0));
    updateAtom(newBond.getAtom(1));

    structureChanged();
View Full Code Here

    IReactionSet reactionSet = model.getReactionSet();
    if (reactionSet == null)
    {
      reactionSet = model.getBuilder().newInstance(IReactionSet.class);
    }
    IAtomContainer container = null;
    if (object instanceof IAtom)
    {
      container = ChemModelManipulator.getRelevantAtomContainer(model, (IAtom) object);
    } else if(object instanceof IBond)
    {
      container = ChemModelManipulator.getRelevantAtomContainer(model, (IBond) object);
    } else
    {
      logger.error("Cannot add to reaction object of type: " + object.getClass().getName());
    }
    if (container == null)
    {
      logger.error("Cannot find container to add object to!");
    } else
    {
      IChemModelRelay hub = jcpPanel.get2DHub();
      IAtomContainer newContainer;
      try {
        newContainer = (IAtomContainer) container.clone();
        if(container.getID()!=null)
          newContainer.setID(container.getID());
        else
          newContainer.setID("ac"+System.currentTimeMillis());
      } catch (CloneNotSupportedException e) {
        logger.error("Could not clone IAtomContainer: ", e.getMessage());
        logger.debug(e);
        return;
      }
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
    IAtomContainer atomContainer = ChemModelManipulator
        .getRelevantAtomContainer(getIChemModel(), newAtom);
    IBond newBond = atomContainer.getBond(atom, newAtom);

    if (desiredDirection == Direction.UP) {
      newBond.setStereo(IBond.Stereo.UP);
    } else if (desiredDirection == Direction.DOWN) {
      newBond.setStereo(IBond.Stereo.DOWN);
View Full Code Here

  // OK
  public void moveTo(IAtom atom, Point2d worldCoords) {
    if (atom != null) {
      if (getUndoRedoFactory() != null && getUndoRedoHandler() != null) {
        IAtomContainer undoRedoContainer = chemModel.getBuilder()
            .newInstance(IAtomContainer.class);
        undoRedoContainer.addAtom(atom);
        Vector2d end = new Vector2d();
        end.sub(worldCoords, atom.getPoint2d());
        IUndoRedoable undoredo = getUndoRedoFactory().getMoveAtomEdit(
            undoRedoContainer, end, "Move atom");
        getUndoRedoHandler().postEdit(undoredo);
View Full Code Here

     * Tests element name is correctly passed to InChI.
     *
     * @throws Exception
     */
    @Test public void testGetInchiFromChlorineAtom() throws Exception {
        IAtomContainer ac = new AtomContainer();
        ac.addAtom(new Atom("Cl"));
        gen.setHydrogensNotAdded(true);
        Assert.assertEquals(gen.generateInchi(ac).getInChI(), "InChI=1S/Cl");
        gen.setHydrogensNotAdded(false);

    }
View Full Code Here

     * Tests charge is correctly passed to InChI.
     *
     * @throws Exception
     */
    @Test public void testGetInchiFromLithiumIon() throws Exception {
        IAtomContainer ac = new AtomContainer();
        IAtom a = new Atom("Li");
        a.setFormalCharge(+1);
        ac.addAtom(a);
        gen.setHydrogensNotAdded(true);
        Assert.assertEquals(gen.generateInchi(ac).getInChI(), "InChI=1S/Li/q+1");
        gen.setHydrogensNotAdded(false);

    }
View Full Code Here

TOP

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

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.