Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtom


   
    public void setChemObject(IChemObject object) {
        if (object instanceof IAtom) {
            source = object;
            // update table contents
            IAtom atom = (IAtom)source;
            symbolField.setText(atom.getSymbol());
            hCountField.setValue(new Integer(atom.getImplicitHydrogenCount()==null ? 0 : atom.getImplicitHydrogenCount()));
            formalChargeField.setValue(new Integer(atom.getFormalCharge()));
            if(atom.getProperty(CDKConstants.COMMENT)!=null)
              commentField.setText((String)(atom.getProperty(CDKConstants.COMMENT)));
           
            try {
                IIsotope isotope =
                    XMLIsotopeFactory.getInstance(
                                atom.getBuilder()).getMajorIsotope(
                                atom.getSymbol());
                majorIsotopeNumber = isotope.getMassNumber();
                isotopeField.setValue(atom.getMassNumber()-majorIsotopeNumber);
            } catch (Exception exception) {
                logger.error("Error while configuring atom");
                logger.debug(exception);
                isotopeField.setValue(0);
            }
View Full Code Here


            throw new IllegalArgumentException("Argument must be an Atom");
        }
    }
 
    public void applyChanges() {
        IAtom atom = (IAtom)source;
        try{
          if(XMLIsotopeFactory.getInstance(atom.getBuilder()).getElement(symbolField.getText())!=null){
            if(atom.getImplicitHydrogenCount()==null || atom.getImplicitHydrogenCount()!=((Integer)hCountField.getValue()).intValue())
              hub.setImplicitHydrogenCount(atom,((Integer)hCountField.getValue()).intValue());
            if(atom.getFormalCharge()==null || atom.getFormalCharge()!=((Integer)formalChargeField.getValue()).intValue())
              hub.setCharge(atom,((Integer)formalChargeField.getValue()).intValue());
            if(!atom.getSymbol().equals(symbolField.getText()))
              hub.setSymbol(atom, symbolField.getText());
            if(atom.getMassNumber()==null || atom.getMassNumber()!=majorIsotopeNumber+((Integer)isotopeField.getValue()).intValue())
              hub.setMassNumber(atom,majorIsotopeNumber+((Integer)isotopeField.getValue()).intValue());
          }else{
              PseudoAtom pseudo = new PseudoAtom(atom);
              pseudo.setLabel(symbolField.getText());
              pseudo.setImplicitHydrogenCount(((Integer)hCountField.getValue()).intValue());
              pseudo.setFormalCharge(((Integer)formalChargeField.getValue()).intValue());
              pseudo.setMassNumber(majorIsotopeNumber+((Integer)isotopeField.getValue()).intValue());
          }

        }catch(IOException ex){
          if(atom.getImplicitHydrogenCount()!=((Integer)hCountField.getValue()).intValue())
            hub.setImplicitHydrogenCount(atom,((Integer)hCountField.getValue()).intValue());
          if(atom.getFormalCharge()!=((Integer)formalChargeField.getValue()).intValue())
            hub.setCharge(atom,((Integer)formalChargeField.getValue()).intValue());
          if(!atom.getSymbol().equals(symbolField.getText()))
            hub.setSymbol(atom, symbolField.getText());
          if(atom.getMassNumber()!=majorIsotopeNumber+((Integer)isotopeField.getValue()).intValue())
            hub.setMassNumber(atom,majorIsotopeNumber+((Integer)isotopeField.getValue()).intValue());
          logger.error("IOException when trying to test element symbol");
        }
        finally {
          atom.setProperty(CDKConstants.COMMENT, commentField.getText());
        }
    }
View Full Code Here

    }

    @Override
    public IRenderingElement generate(IAtomContainer ac, RendererModel model) {
        JChemPaintRendererModel jcpModel = (JChemPaintRendererModel) model;
        IAtom atom = model.getHighlightedAtom();
        if (atom != null && shouldHighlight(atom, jcpModel)) {
            Point2d p = atom.getPoint2d();
           
            // the element size has to be scaled to model space
            // so that it can be scaled back to screen space...
            double radius = jcpModel.getHighlightDistance() / jcpModel.getScale();
            radius /= 2.0;
View Full Code Here

        IChemModel chemModel = jcpPanel.getChemModel();
        Clipboard sysClip = jcpPanel.getToolkit().getSystemClipboard();

        if ("copy".equals(type)) {
            handleSystemClipboard(sysClip);
            IAtom atomInRange = null;
            IChemObject object = getSource(e);
            logger.debug("Source of call: ", object);
            if (object instanceof IAtom) {
                atomInRange = (IAtom) object;
            } else {
                atomInRange = renderModel.getHighlightedAtom();
            }
            if (atomInRange != null) {
                IAtomContainer tocopyclone =
                    atomInRange.getBuilder().newInstance(IAtomContainer.class);
                try {
          tocopyclone.addAtom((IAtom) atomInRange.clone());
        } catch (CloneNotSupportedException e1) {
          // TODO Auto-generated catch block
          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;
View Full Code Here

     */
    public void assertAtomTypesPerceived(IAtomContainer container) throws Exception {
      CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(container.getBuilder());
      Iterator<IAtom> atoms = container.atoms().iterator();
      while (atoms.hasNext()) {
        IAtom atom = atoms.next();
        IAtomType type = matcher.findMatchingAtomType(container, atom);
        Assert.assertNotNull(
          "Could not perceive atom type for: " + atom,
          type
        );
View Full Code Here

  protected void assertAllSingleAndAromatic(IAtomContainer container) throws Exception {
    for (Iterator<IBond> bonds = container.bonds().iterator(); bonds.hasNext();)
      Assert.assertEquals(IBond.Order.SINGLE, bonds.next().getOrder());
   
    for (Iterator<IAtom> atoms = container.atoms().iterator(); atoms.hasNext();) {
      IAtom atom = atoms.next();
      if (atom.getSymbol().equals("H"))
        Assert.assertFalse(atom.getFlag(CDKConstants.ISAROMATIC));
      else
        Assert.assertTrue(atom.getFlag(CDKConstants.ISAROMATIC));
    }
  }
View Full Code Here

    public void keyReleased(KeyEvent arg0) {
        JChemPaintRendererModel model = renderPanel.getRenderer().getRenderer2DModel();
        ControllerHub relay = renderPanel.getHub();
        if (model.getHighlightedAtom() != null) {
            try {
                IAtom closestAtom = model.getHighlightedAtom();
                char x = arg0.getKeyChar();               
                if (Character.isLowerCase(x))
                    x = Character.toUpperCase(x);
                System.out.println(x);
                IsotopeFactory ifa;
                ifa = XMLIsotopeFactory.getInstance(closestAtom.getBuilder());
                IIsotope iso = ifa.getMajorIsotope(Character.toString(x));
                if (iso != null) {
                    relay.setSymbol(closestAtom, Character.toString(x));
                }
                this.get2DHub().updateView();
View Full Code Here

        ElementGroup elementGroup = new ElementGroup();
        Color mappingColor = model.getAtomAtomMappingLineColor();
        for (IMapping mapping : reaction.mappings()) {
            // XXX assume that there are only 2 endpoints!
            // XXX assume that the ChemObjects are actually IAtoms...
            IAtom endPointA = (IAtom) mapping.getChemObject(0);
            IAtom endPointB = (IAtom) mapping.getChemObject(1);
            Point2d pA = endPointA.getPoint2d();
            Point2d pB = endPointB.getPoint2d();
            elementGroup.add(
                    new LineElement(pA.x, pA.y, pB.x, pB.y, getWidthForMappingLine(model), mappingColor));
        }
        return elementGroup;
    }
View Full Code Here

      while (!inputOkay);
        }

    range:
    while(atomsInRange.hasNext()){
            IAtom atom = atomsInRange.next();
          if(type.equals("normal")){
                PseudoAtom pseudo = (PseudoAtom)atom;
                IAtom normal = pseudo.getBuilder().newInstance(IPseudoAtom.class,pseudo);
                normal.setSymbol("C");
                jcpPanel.get2DHub().replaceAtom(normal,pseudo);
          }else {
            jcpPanel.get2DHub().convertToPseudoAtom(atom,label);
                AddAtomModule newActiveModule = new AddAtomModule(jcpPanel.get2DHub(), IBond.Stereo.NONE);
                if(jcpPanel.get2DHub().getActiveDrawModule() instanceof AddBondDragModule)
View Full Code Here

        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);
    }
   
    protected Point2d getAtomPoint(JChemPaintPanel panel, int atomnumber){
        IAtom atom = panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtom(atomnumber);
        return panel.getRenderPanel().getRenderer().toScreenCoordinates(atom.getPoint2d().x,atom.getPoint2d().y);
    }   
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.