Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IBond


    }

  }
 
  private boolean getAtomsAfterAtom(IMolecule mol, IAtom a1, IAtom a2, Set<IAtom> atoms) throws Exception {
    IBond b = mol.getBond(a1, a2);
    if(b == null) throw new Exception();

    return getAtomsAfterAtom(mol, a1, a1, a2, atoms);
  }
View Full Code Here


      }
    }
   
    // Find the best bond
    PriorityInformation bestPi = null;
    IBond bestBond = null;
    for(Object o : l) {
      IAtom aa = (IAtom)o;
      IBond bond = mol.getBond(a, aa);
      if(bond.getStereo() != CDKConstants.STEREO_BOND_NONE) continue;
      Set<IAtom> danglingAtoms = new HashSet<IAtom>();
      boolean isCyclic = getAtomsAfterAtom(mol, aa, a, danglingAtoms);
      PriorityInformation pi = new PriorityInformation(isCyclic, bond.getOrder() != CDKConstants.BONDORDER_SINGLE, aa.getAtomicNumber(), danglingAtoms.size());
      if(bestPi == null || pi.compareTo(bestPi) > 0) {
        bestBond = bond;
        bestPi = pi;
      }
    }
View Full Code Here

    IAtom a = atomMap.get(atomId);
    List l = mol.getConnectedAtomsList(a);
    // Find a pre-existing stereo bond
    for(Object o : l) {
      IAtom aa = (IAtom)o;
      IBond bond = mol.getBond(a, aa);
      if(bond.getStereo() != CDKConstants.STEREO_BOND_NONE) {
        boolean inv = (bond.getStereo() == CDKConstants.STEREO_BOND_UP_INV || bond.getStereo() == CDKConstants.STEREO_BOND_DOWN_INV);
        if(inv && (bond.getAtom(0) == a)) continue;
        if(!inv && !(bond.getAtom(0) == a)) continue;
       
        if(bond.getStereo() == CDKConstants.STEREO_BOND_UP) {
          bond.setStereo(CDKConstants.STEREO_BOND_DOWN);
        } else if(bond.getStereo() == CDKConstants.STEREO_BOND_DOWN) {
          bond.setStereo(CDKConstants.STEREO_BOND_UP);         
        } else if(bond.getStereo() == CDKConstants.STEREO_BOND_UP_INV) {
          bond.setStereo(CDKConstants.STEREO_BOND_DOWN_INV);
        } else if(bond.getStereo() == CDKConstants.STEREO_BOND_DOWN_INV) {
          bond.setStereo(CDKConstants.STEREO_BOND_UP_INV);         
        }
        return;
      }
    }
    throw new Exception("Couldn't invert the stereochemistry at a stereocenter");
View Full Code Here

    }
  }
 
  private static void deAromatise(IMolecule mm) {
    for(int i=0;i<mm.getBondCount();i++) {
      IBond b = mm.getBond(i);
      b.setOrder(b.getOrder());
    }
    for(int i=0;i<mm.getBondCount();i++) {
      IBond b = mm.getBond(i);
      b.setFlag(CDKConstants.ISAROMATIC, false);
    }
    for(int i=0;i<mm.getAtomCount();i++) {
      IAtom a = mm.getAtom(i);
      a.setHybridization(0);
      a.setFlag(CDKConstants.ISAROMATIC, false);
View Full Code Here

      if(a.getFormalCharge() == 1 || a.getFormalCharge() == -1) c += 1;
      int hr = 4 - c;
      for(int j=0;j<hr;j++) {
        IAtom ha = new Atom("H");
        isotopeFactory.configure(ha);
        IBond b = new Bond(a, ha);
        mol.addAtom(ha);
        mol.addBond(b);
      }
    }
  }
View Full Code Here

    }

    public void setChemObject(IChemObject object) {
        if (object instanceof org.openscience.cdk.interfaces.IBond) {
            source = object;
            IBond bond = (IBond) source;
            orderField.setSelectedIndex(bondOrderIndex(bond.getOrder()));
            if (!blacklist.contains("stereochemistry"))
                stereoField.setSelectedIndex(bondStereoIndex(bond.getStereo()));
        }
        else {
            throw new IllegalArgumentException("Argument must be an Bond");
        }
    }
View Full Code Here

            throw new IllegalArgumentException("Argument must be an Bond");
        }
    }

    public void applyChanges() {
        IBond bond = (IBond) source;

        int newOrder = orderField.getSelectedIndex();
        Order order = null;
        switch (newOrder) {
            case 0:
View Full Code Here

    for (Iterator<IAtom> atomItr=rootAttachmentPoints.keySet().iterator(); atomItr.hasNext();) {
      Map<Integer,IBond> bonds =rootAttachmentPoints.get(atomItr.next());
      for(Iterator<Integer> bondItr=bonds.keySet().iterator(); bondItr.hasNext();) {
        int bondNum=bondItr.next();
        IBond b = bonds.get(bondNum);
        if (ac.contains(b)) {
              double xAvg = (b.getAtom(0).getPoint2d().x + b.getAtom(1).getPoint2d().x)/2;
              double yAvg = (b.getAtom(0).getPoint2d().y + b.getAtom(1).getPoint2d().y)/2;
              diagram.add(new TextElement(xAvg+0.1, yAvg-0.1,(bondNum==1?APO1_LABEL:APO2_LABEL),APO_LABEL_COLOR));
        }
      }
    }
  }
View Full Code Here

          e1.printStackTrace();
        }
                addToClipboard(sysClip, tocopyclone);
            }
            else if(renderModel.getHighlightedBond()!=null){
                IBond bond = renderModel.getHighlightedBond();
                if (bond != null) {
                    IAtomContainer tocopyclone =
                        bond.getBuilder().newInstance(IAtomContainer.class);
                    try {
                        tocopyclone.addAtom((IAtom) bond.getAtom(0).clone());
                        tocopyclone.addAtom((IAtom) bond.getAtom(1).clone());
                    } catch (CloneNotSupportedException e1) {
                        e1.printStackTrace();
                    }
                    tocopyclone.addBond(bond.getBuilder().newInstance(IBond.class,tocopyclone.getAtom(0), tocopyclone.getAtom(1), bond.getOrder()));
                    addToClipboard(sysClip, tocopyclone);
                }
            }else if(renderModel.getSelection().getConnectedAtomContainer()!=null){
              addToClipboard(sysClip,
                  renderModel.getSelection().getConnectedAtomContainer());
            }else{
        addToClipboard(sysClip, JChemPaintPanel.getAllAtomContainersInOne(chemModel));
            }
        } else if ("copyAsSmiles".equals(type)) {
            handleSystemClipboard(sysClip);
            try {
               
                final IAtomContainer selection = renderModel.getSelection().getConnectedAtomContainer();
               
                if(selection!=null){
                    final IChemObjectBuilder bldr = selection.getBuilder();
                    IChemModel selectionModel = bldr.newInstance(IChemModel.class);
                    selectionModel.setMoleculeSet(bldr.newInstance(IAtomContainerSet.class));
                    selectionModel.getMoleculeSet().addAtomContainer(selection);
                    sysClip.setContents(new SmilesSelection(CreateSmilesAction.getSmiles(selectionModel)), null);
                }else{
                    sysClip.setContents(new SmilesSelection(CreateSmilesAction.getSmiles(chemModel)),null);
                }
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } else if ("eraser".equals(type)) {
            RemoveModule newActiveModule = new RemoveModule(jcpPanel.get2DHub());
            newActiveModule.setID(type);
            jcpPanel.get2DHub().setActiveDrawModule(newActiveModule);
            IAtom atomInRange = null;
            IBond bondInRange = null;
            IChemObject object = getSource(e);
            logger.debug("Source of call: ", object);
            if (object instanceof IAtom) {
                atomInRange = (IAtom) object;
            } else {
                atomInRange = renderModel.getHighlightedAtom();
            }
            if (object instanceof IBond) {
                bondInRange = (IBond) object;
            } else {
                bondInRange = renderModel.getHighlightedBond();
            }
            if (atomInRange != null) {
                jcpPanel.get2DHub().removeAtom(atomInRange);
                renderModel.setHighlightedAtom(null);
            } else if (bondInRange != null) {
                jcpPanel.get2DHub().removeBond(bondInRange);
            } else if(renderModel.getSelection()!=null && renderModel.getSelection().getConnectedAtomContainer()!=null){
                IChemObjectSelection selection = renderModel.getSelection();
                IAtomContainer selected = selection.getConnectedAtomContainer();
                jcpPanel.get2DHub().deleteFragment(selected);
                renderModel.setSelection(new LogicalSelection(
                        LogicalSelection.Type.NONE));
                jcpPanel.get2DHub().updateView();
            }
        } else if(type.indexOf("pasteTemplate")>-1){
            //if templates are shown, we extract the tab to show if any
            String templatetab="";
            if(type.indexOf("_")>-1){
                templatetab=type.substring(type.indexOf("_")+1);
            }
            TemplateBrowser templateBrowser = new TemplateBrowser(templatetab);
            if(templateBrowser.getChosenmolecule()!=null){
                scaleStructure(templateBrowser.getChosenmolecule());
                insertStructure(templateBrowser.getChosenmolecule(), renderModel);
                jcpPanel.getRenderPanel().setZoomWide(true);
                jcpPanel.get2DHub().getRenderer().getRenderer2DModel().setZoomFactor(1);
            }
        } else if ("paste".equals(type)) {
            handleSystemClipboard(sysClip);
            Transferable transfer = sysClip.getContents( null );
            ISimpleChemObjectReader reader = null;
            String content=null;
           
            if (supported(transfer, molFlavor) ) {
                StringBuffer sb = new StringBuffer();
              try {
                    //StringBufferInputStream sbis=null;
          //sbis = (StringBufferInputStream) transfer.getTransferData(molFlavor);

                    StringReader sbis=null;
          sbis = (StringReader) transfer.getTransferData(molFlavor);

               
                int x;
                    while((x=sbis.read())!=-1){
                        sb.append((char)x);
                    }
                    reader = new MDLReader(new StringReader(sb.toString()));
        } catch (UnsupportedFlavorException e1) {
          e1.printStackTrace();
        } catch (IOException e1) {
          e1.printStackTrace();
              } catch (Exception e1) {
                  reader = new RGroupQueryReader(new StringReader(sb.toString()));
                }

            } else if (supported(transfer, DataFlavor.stringFlavor) ) {
                try {
                    content = (String) transfer.getTransferData(DataFlavor.stringFlavor);
                    reader = new ReaderFactory().createReader(new StringReader(content));
                    //System.out.println(reader.getClass());
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }

            // if looks like CML - InputStream required. Reader throws error.
            if(content!=null && content.indexOf("cml")>-1) {
                reader = new CMLReader(new ByteArrayInputStream(content.getBytes()));
            }

            IAtomContainer toPaste = null;
            boolean rgrpQuery=false;
            if (reader != null) {
                IAtomContainer readMolecule =
                    chemModel.getBuilder().newInstance(IAtomContainer.class);
                try {
                    if (reader.accepts(IAtomContainer.class)) {
                        toPaste = (IAtomContainer) reader.read(readMolecule);
                    } else if (reader.accepts(ChemFile.class)) {
                        toPaste = readMolecule;
                        IChemFile file = (IChemFile) reader.read(new ChemFile());
                        for (IAtomContainer ac :
                            ChemFileManipulator.getAllAtomContainers(file)) {
                            toPaste.add(ac);

                        }
                  } else if (reader.accepts(RGroupQuery.class)) {
                rgrpQuery=true;
                    IRGroupQuery rgroupQuery = (RGroupQuery) reader.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance()));
                chemModel = new ChemModel();
                RGroupHandler rgHandler =  new RGroupHandler(rgroupQuery, this.jcpPanel);
                this.jcpPanel.get2DHub().setRGroupHandler(rgHandler);
                chemModel.setMoleculeSet(rgHandler.getMoleculeSet(chemModel));
                rgHandler.layoutRgroup();
               
                  }

                } catch (CDKException e1) {
                    e1.printStackTrace();
                }
            }

            //Attempt SMILES or InChI if no reader is found for content.
            if(rgrpQuery!=true && toPaste == null &&
                    supported(transfer, DataFlavor.stringFlavor)) {
                try{
                    if (content.toLowerCase().indexOf("inchi")>-1 ) {
                        toPaste = InChITool.parseInChI(content);
                    }
                    else {   
                        SmilesParser sp = new SmilesParser(
                                DefaultChemObjectBuilder.getInstance());
                        toPaste = sp.parseSmiles(
                                ((String) transfer.getTransferData(
                                        DataFlavor.stringFlavor)).trim());
                        toPaste = new FixBondOrdersTool().kekuliseAromaticRings(toPaste);

                        IAtomContainerSet mols = ConnectivityChecker.partitionIntoMolecules(toPaste);
                        for(int i=0;i<mols.getAtomContainerCount();i++)
                        {
                            StructureDiagramGenerator sdg =
                                new StructureDiagramGenerator((IAtomContainer)mols.getAtomContainer(i));

                            sdg.setTemplateHandler(
                                    new TemplateHandler(toPaste.getBuilder())
                            );
                            sdg.generateCoordinates();
                        }
                        //SMILES parser sets valencies, unset
                        for(int i=0;i<toPaste.getAtomCount();i++){
                            toPaste.getAtom(i).setValency(null);
                        }
                    }
                } catch (Exception ex) {
                    jcpPanel.announceError(ex);
                    ex.printStackTrace();
                }
            }
           
            if (toPaste != null || rgrpQuery==true) {
                jcpPanel.getRenderPanel().setZoomWide(true);
                jcpPanel.get2DHub().getRenderer().getRenderer2DModel().setZoomFactor(1);
                if ( rgrpQuery==true) {
                  this.jcpPanel.setChemModel(chemModel);
                }
                else {
                  scaleStructure(toPaste);
                  insertStructure(toPaste, renderModel);
                }
            }
            else{
                JOptionPane.showMessageDialog(jcpPanel, GT.get("The content you tried to copy could not be read to any known format"), GT.get("Could not process content"), JOptionPane.WARNING_MESSAGE);
            }

        } else if (type.equals("cut")) {
            handleSystemClipboard(sysClip);
            IAtom atomInRange = null;
            IBond bondInRange = null;
            IChemObject object = getSource(e);
            logger.debug("Source of call: ", object);
            if (object instanceof IAtom) {
                atomInRange = (IAtom) object;
            } else {
View Full Code Here

        panel = (JChemPaintPanel)jcppanel.target;
        viewer.setSize(700,700);
    }
   
    protected Point2d getBondPoint(JChemPaintPanel panel, int bondnumber) {
        IBond bond = panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBond(bondnumber);
        return panel.getRenderPanel().getRenderer().toScreenCoordinates((bond.getAtom(0).getPoint2d().x+bond.getAtom(1).getPoint2d().x)/2,(bond.getAtom(0).getPoint2d().y+bond.getAtom(1).getPoint2d().y)/2);
    }
View Full Code Here

TOP

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

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.