Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtomContainer


    }
  }

  // OK
  public void replaceAtom(IAtom atomnew, IAtom atomold) {
    IAtomContainer relevantContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atomold);
    AtomContainerManipulator.replaceAtomByAtom(relevantContainer, atomold,
        atomnew);
    updateAtom(atomnew);
    structureChanged();
View Full Code Here


   *
   * @seeorg.openscience.cdk.controller.IAtomBondEdits#addSingleElectron(org.
   * openscience.cdk.interfaces.IAtom)
   */
  public void addSingleElectron(IAtom atom) {
    IAtomContainer relevantContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atom);
    ISingleElectron singleElectron = atom.getBuilder().newInstance(ISingleElectron.class,atom);
    relevantContainer.addSingleElectron(singleElectron);
    updateAtom(atom);
    if (undoredofactory != null && undoredohandler != null) {
      IUndoRedoable undoredo = undoredofactory.getSingleElectronEdit(
          relevantContainer, singleElectron, true, this, atom,
          "Add Single Electron");
View Full Code Here

   * @see
   * org.openscience.cdk.controller.IAtomBondEdits#removeSingleElectron(org
   * .openscience.cdk.interfaces.IAtom)
   */
  public void removeSingleElectron(IAtom atom) {
    IAtomContainer relevantContainer = ChemModelManipulator
        .getRelevantAtomContainer(chemModel, atom);
    if (relevantContainer.getConnectedSingleElectronsCount(atom) > 0) {
      ISingleElectron removedElectron = relevantContainer
          .removeSingleElectron(relevantContainer
              .getConnectedSingleElectronsCount(atom) - 1);
      updateAtom(atom);
      if (undoredofactory != null && undoredohandler != null) {
        IUndoRedoable undoredo = undoredofactory.getSingleElectronEdit(
            relevantContainer, removedElectron, false, this, atom,
View Full Code Here

  public void clearValidation() {
    Iterator<IAtomContainer> containers = ChemModelManipulator
        .getAllAtomContainers(chemModel).iterator();
    while (containers.hasNext()) {
      IAtomContainer atoms = containers.next();
      for (int i = 0; i < atoms.getAtomCount(); i++) {
        ProblemMarker.unmark(atoms.getAtom(i));
      }
    }
  }
View Full Code Here

  // OK
  public void flip(boolean horizontal) {
    HashMap<IAtom, Point2d[]> atomCoordsMap = new HashMap<IAtom, Point2d[]>();
    JChemPaintRendererModel renderModel = renderer.getRenderer2DModel();
    IAtomContainer toflip;
    if (renderModel.getSelection().getConnectedAtomContainer() != null
        && renderModel.getSelection().getConnectedAtomContainer()
            .getAtomCount() != 0) {
      toflip = renderModel.getSelection().getConnectedAtomContainer();
    } else {
      List<IAtomContainer> toflipall = ChemModelManipulator
          .getAllAtomContainers(chemModel);
      toflip = toflipall.get(0).getBuilder().newInstance(IAtomContainer.class);
      for (IAtomContainer atomContainer : toflipall) {
        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;
      }
      Point2d newCoord = p2d;
      if (!oldCoord.equals(newCoord)) {
        Point2d[] coords = new Point2d[2];
        coords[0] = newCoord;
        coords[1] = oldCoord;
        atomCoordsMap.put(atom, coords);
      }
    }
    // Stereo bonds must be flipped as well to keep the structure
    for (IBond bond : toflip.bonds()) {
      if (bond.getStereo() == IBond.Stereo.UP)
        bond.setStereo(IBond.Stereo.DOWN);
      else if (bond.getStereo() == IBond.Stereo.DOWN)
        bond.setStereo(IBond.Stereo.UP);
      else if (bond.getStereo() == IBond.Stereo.UP_INVERTED)
View Full Code Here

    IChemModelRelay hub = jcpPanel.get2DHub();
    boolean isNewRgroup=false;
    RGroupHandler rGroupHandler=null;
    Map<IAtom,IAtomContainer> existingAtomDistr = new HashMap<IAtom,IAtomContainer>();
    Map<IBond,IAtomContainer> existingBondDistr= new HashMap<IBond,IAtomContainer>();
    IAtomContainer existingRoot=null;
    Map<IAtom, Map<Integer, IBond>> existingRootAttachmentPoints = null;
    Map<RGroup, Map<Integer,IAtom>> existingRGroupApo=null;
    Map<Integer,RGroupList> existingRgroupLists =null;

    IRGroupQuery rgrpQuery=null;
    IAtomContainer molecule=null;

    /* User action: generate possible configurations for the R-group */
    if(type.equals("rgpGenerate")) {
      if((jcpPanel.get2DHub().getRGroupHandler()==null)) {
        JOptionPane.showMessageDialog(jcpPanel, GT.get("Please define an R-group (root and substituents) first."));
        return;
      }
            try {
        JFileChooser chooser = new JFileChooser();
        chooser.setCurrentDirectory(jcpPanel.getCurrentWorkDirectory());
        chooser.setFileView(new JCPFileView());
        chooser.showSaveDialog(jcpPanel);
        File outFile = chooser.getSelectedFile();
        System.out.println(outFile);
        List<IAtomContainer> molecules= jcpPanel.get2DHub().getRGroupHandler().getrGroupQuery().getAllConfigurations();
        if (molecules.size() > 0) {
          IAtomContainerSet molSet = molecules.get(0).getBuilder().newInstance(IAtomContainerSet.class);
          for (IAtomContainer mol : molecules) {
            molSet.addAtomContainer(mol);
          }
          SDFWriter sdfWriter = new SDFWriter(new FileWriter(outFile));
          sdfWriter.write(molSet);
          sdfWriter.close();
        }
      } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(jcpPanel, GT.get("There was an error generating the configurations {0}", e.getMessage()));
        return;
      }
   
    }
    /* User action: advanced R-group logic */
    else if(type.equals("rgpAdvanced")) {

      if((jcpPanel.get2DHub().getRGroupHandler()==null)) {
        JOptionPane.showMessageDialog(jcpPanel, GT.get("Please define an R-group (root and substituent) first."));
        return;
      }
      jcpPanel.get2DHub().getRGroupHandler().cleanUpRGroup(jcpPanel.get2DHub().getChemModel().getMoleculeSet());
      ChemObjectEditor editor = new RGroupEditor(hub);
      editor.setChemObject((org.openscience.cdk.ChemObject)hub.getRGroupHandler().getrGroupQuery());
      ChemObjectPropertyDialog frame = new ChemObjectPropertyDialog(JOptionPane.getFrameForComponent(editor), jcpPanel.get2DHub(),editor);
      frame.pack();
      frame.setVisible(true);
      jcpPanel.get2DHub().updateView();
    }


    //FOLLOWING actions involve undo/redo

    else
    {

      /* User action: generate possible configurations for the R-group */
      if(type.equals("clearRgroup")) {
        if((jcpPanel.get2DHub().getRGroupHandler()==null)) {
          JOptionPane.showMessageDialog(jcpPanel, GT.get("There is no R-group defined"));
          return;
        }
        rGroupHandler=hub.getRGroupHandler();
        hub.unsetRGroupHandler();
        jcpPanel.get2DHub().updateView();

      }

      /* User has indicated that a certain atom in a substituent needs to become attachment point 1 or 2 */
      else if (type.startsWith("setAtomApoAction")) {
        rGroupHandler=hub.getRGroupHandler();
        IAtom apoAtom = (IAtom) eventSource;
        apoLoop:
          for (Iterator<Integer> rnumItr=rGroupHandler.getrGroupQuery().getRGroupDefinitions().keySet().iterator(); rnumItr.hasNext();) {
            for (RGroup rgrp: rGroupHandler.getrGroupQuery().getRGroupDefinitions().get(rnumItr.next()).getRGroups()) {
              if(rgrp.getGroup().contains(apoAtom)) {
                existingRGroupApo= new HashMap <RGroup,Map<Integer,IAtom>>();
                HashMap<Integer,IAtom> map = new HashMap<Integer,IAtom>();
                map.put(1, rgrp.getFirstAttachmentPoint());
                map.put(2, rgrp.getSecondAttachmentPoint());
                existingRGroupApo.put(rgrp,map);

                boolean firstApo = type.endsWith("1");
                if (firstApo) {
                  rgrp.setFirstAttachmentPoint(apoAtom);
                }
                else {
                  rgrp.setSecondAttachmentPoint(apoAtom);
                }
                break apoLoop;
              }
            }
          }
      }

      /* User action : certain bond in the root needs to become attachment bond 1 or 2 */
      else if (type.startsWith("setBondApoAction")) {
        rGroupHandler=hub.getRGroupHandler();
        IBond apoBond = (IBond) eventSource;
        Map<Integer, IBond> apoBonds=null;

        //Undo/redo business______
        IAtom pseudo=null;
        if (apoBond.getAtom(0) instanceof IPseudoAtom)
          pseudo=apoBond.getAtom(0);
        else
          pseudo=apoBond.getAtom(1);
        Map<Integer, IBond> keepApoBonds = new HashMap<Integer, IBond>();
        if (rGroupHandler.getrGroupQuery().getRootAttachmentPoints()!=null &&
            rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo)!=null) {
          apoBonds= rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo);
          for (Iterator<Integer> apoItr =apoBonds.keySet().iterator(); apoItr.hasNext();) {
            int apoNum=apoItr.next();
            keepApoBonds.put(apoNum,apoBonds.get(apoNum));
          }
        }
        existingRootAttachmentPoints = new HashMap<IAtom, Map<Integer, IBond>>();
        existingRootAttachmentPoints.put(pseudo, keepApoBonds);
        //________________________


        //Set the new Root APO
        if (rGroupHandler.getrGroupQuery().getRootAttachmentPoints()==null) {
          rGroupHandler.getrGroupQuery().setRootAttachmentPoints(new HashMap<IAtom, Map<Integer, IBond>>());
        }
        Map<IAtom, Map<Integer, IBond>> rootApo=rGroupHandler.getrGroupQuery().getRootAttachmentPoints();
        if (rootApo.get(pseudo)==null) {
          apoBonds=new HashMap<Integer,IBond>();
          rootApo.put(pseudo, apoBonds);
        }
        else
          apoBonds=rGroupHandler.getrGroupQuery().getRootAttachmentPoints().get(pseudo);

        if (type.endsWith("1")) {
          apoBonds.put(1, apoBond);
          if (apoBonds.get(2)!=null && apoBonds.get(2).equals(apoBond))
            apoBonds.remove(2);
        }
        if (type.endsWith("2")) {
          apoBonds.put(2, apoBond);
          if (apoBonds.get(1)!=null && apoBonds.get(1).equals(apoBond))
            apoBonds.remove(1);
        }

      }


      /* User action: certain atom+bond selection is to be the root structure. */
      else if (type.equals("setRoot")) {

        IAtomContainer atc =selection.getConnectedAtomContainer();
        if (!isProperSelection(atc)) {
          JOptionPane.showMessageDialog(jcpPanel, GT.get("Please do not make a fragmented selection."));
          return;
        }

        molecule = createMolecule (atc,existingAtomDistr,existingBondDistr);
        hub.getChemModel().getMoleculeSet().addAtomContainer(molecule);

        if (hub.getRGroupHandler() == null) {
          isNewRgroup=true;
          rgrpQuery = newRGroupQuery(molecule.getBuilder());
          rGroupHandler = new RGroupHandler(rgrpQuery, this.jcpPanel);
          hub.setRGroupHandler(rGroupHandler);
        }
        else {
          rGroupHandler=hub.getRGroupHandler();
          rgrpQuery = hub.getRGroupHandler().getrGroupQuery();
          if(rgrpQuery.getRootStructure()!=null) {
            existingRoot=rgrpQuery.getRootStructure();
            rgrpQuery.getRootStructure().removeProperty(CDKConstants.TITLE);
          }
        }
        molecule.setProperty(CDKConstants.TITLE,RGroup.ROOT_LABEL);
        rgrpQuery.setRootStructure(molecule);

        //Remove old root apo's
        existingRootAttachmentPoints = rgrpQuery.getRootAttachmentPoints();
        rgrpQuery.setRootAttachmentPoints(null);

        //Define new root apo's
        Map<IAtom, Map<Integer, IBond>> apoBonds= new HashMap<IAtom, Map<Integer, IBond>>();
        for (IAtom atom : molecule.atoms()) {
          if (atom instanceof IPseudoAtom) {
            IPseudoAtom pseudo = (IPseudoAtom)atom;
            if (pseudo.getLabel()!=null && RGroupQuery.isValidRgroupQueryLabel(pseudo.getLabel())) {
              chooseRootAttachmentBonds(pseudo,molecule,apoBonds);
            }
          }
        }
        rgrpQuery.setRootAttachmentPoints(apoBonds);

      }

      /* User action: certain atom+bond selection is to be a substituent. */
      else if (type.equals("setSubstitute")) {

        if (hub.getRGroupHandler() == null || hub.getRGroupHandler().getrGroupQuery()==null ||
            hub.getRGroupHandler().getrGroupQuery().getRootStructure()==null) {
          JOptionPane.showMessageDialog(jcpPanel, GT.get("Please define a root structure first."));
          return;
        }

        IAtomContainer atc =selection.getConnectedAtomContainer();
        if (!isProperSelection(atc)) {
          JOptionPane.showMessageDialog(jcpPanel, GT.get("Please do not make a fragmented selection."));
          return;
        }

View Full Code Here

   */
  private boolean isProperSelection(IAtomContainer atc) {
    boolean properSelection = true;
    completeSelection: for (IAtom atom : atc.atoms()) {

      IAtomContainer modelAtc = ChemModelManipulator
          .getRelevantAtomContainer(jcpPanel.getChemModel(), atom);
      List<IAtom> connectedAtoms = new ArrayList<IAtom>();
      findConnectedAtoms(atom, modelAtc, connectedAtoms);
      for (IAtom modelAt : connectedAtoms) {
        if (!atc.contains(modelAt)) {
View Full Code Here

      getUndoRedoHandler().postEdit(undoredo);
    }
  }

  public void invertStereoInSelection() {
    IAtomContainer toflip;
    JChemPaintRendererModel renderModel = renderer.getRenderer2DModel();
    if (renderModel.getSelection().getConnectedAtomContainer() != null
        && renderModel.getSelection().getConnectedAtomContainer()
            .getAtomCount() != 0) {
      toflip = renderModel.getSelection().getConnectedAtomContainer();
    } else
      return;

    for (IBond bond : toflip.bonds()) {
      if (bond.getStereo() == IBond.Stereo.UP)
        bond.setStereo(IBond.Stereo.DOWN);
      else if (bond.getStereo() == IBond.Stereo.DOWN)
        bond.setStereo(IBond.Stereo.UP);
      else if (bond.getStereo() == IBond.Stereo.UP_INVERTED)
View Full Code Here

   */
  private IAtomContainer createMolecule(IAtomContainer atc,
      Map<IAtom, IAtomContainer> existingAtomDistr,
      Map<IBond, IAtomContainer> existingBondDistr) {
    for (IAtom atom : atc.atoms()) {
      IAtomContainer original = ChemModelManipulator
          .getRelevantAtomContainer(jcpPanel.getChemModel(), atom);
      existingAtomDistr.put(atom, original);
      original.removeAtom(atom);
    }
    for (IBond bond : atc.bonds()) {
      IAtomContainer original = ChemModelManipulator
          .getRelevantAtomContainer(jcpPanel.getChemModel(), bond);
      existingBondDistr.put(bond, original);
      original.removeBond(bond);
    }
    IAtomContainer molecule = atc.getBuilder().newInstance(IAtomContainer.class);
    molecule.add(atc);
    return molecule;
  }
View Full Code Here

    IAtomContainerSet oldMoleculeSet = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
    if (moleculeToAddTo == null) {
      newMoleculeSet.addAtomContainer(toPaste);
      moleculeToAddTo = toPaste;
    } else {
      IAtomContainer mol = chemModel.getBuilder().newInstance(IAtomContainer.class);
      for (IAtom atom: moleculeToAddTo.atoms())
        mol.addAtom(atom);
      for (IBond bond: moleculeToAddTo.bonds())
        mol.addBond(bond);
      oldMoleculeSet.addAtomContainer(mol);
      moleculeToAddTo.add(toPaste);
    }
    if (toRemove != null) {
      oldMoleculeSet.addAtomContainer(toRemove);
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.