Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtomContainer


                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;
            } else {
                atomInRange = renderModel.getHighlightedAtom();
            }
            if (object instanceof IBond) {
                bondInRange = (IBond) object;
            } else {
                bondInRange = renderModel.getHighlightedBond();
            }
            IAtomContainer tocopyclone =
                jcpPanel.getChemModel().getBuilder().newInstance(IAtomContainer.class);
            if (atomInRange != null) {
                tocopyclone.addAtom(atomInRange);
                jcpPanel.get2DHub().removeAtom(atomInRange);
                renderModel.setHighlightedAtom(null);
            } else if (bondInRange != null) {
                tocopyclone.addBond(bondInRange);
                jcpPanel.get2DHub().removeBond(bondInRange);
            }else if(renderModel.getSelection()!=null && renderModel.getSelection().getConnectedAtomContainer()!=null){
                IChemObjectSelection selection = renderModel.getSelection();
                IAtomContainer selected = selection.getConnectedAtomContainer();
                tocopyclone.add(selected);
                jcpPanel.get2DHub().deleteFragment(selected);
                renderModel.setSelection(new LogicalSelection(
                        LogicalSelection.Type.NONE));
                jcpPanel.get2DHub().updateView();
            }
      if(tocopyclone.getAtomCount()>0 || tocopyclone.getBondCount()>0)
          addToClipboard(sysClip, tocopyclone);
     
        }else if (type.equals("selectAll")) {
            ControllerHub hub = jcpPanel.get2DHub();
            IChemObjectSelection allSelection =
                new LogicalSelection(LogicalSelection.Type.ALL);

            allSelection.select(hub.getIChemModel());
            renderModel.setSelection(allSelection);
            SelectSquareModule succusorModule = new SelectSquareModule(hub);
            succusorModule.setID("select");
            MoveModule newActiveModule = new MoveModule(hub, succusorModule);
            newActiveModule.setID("move");
            hub.setActiveDrawModule(newActiveModule);

        } else if (type.equals("selectFromChemObject")) {

          // FIXME: implement for others than Reaction, Atom, Bond
          IChemObject object = getSource(e);
            if (object instanceof IAtom) {
                SingleSelection<IAtom> container = new SingleSelection<IAtom>((IAtom)object);
                renderModel.setSelection(container);
            }
            else if (object instanceof IBond) {
                SingleSelection<IBond> container = new SingleSelection<IBond>((IBond)object);
                renderModel.setSelection(container);
            }
            else if (object instanceof IReaction) {
                IAtomContainer wholeModel =
                    jcpPanel.getChemModel().getBuilder().newInstance(IAtomContainer.class);
                for (IAtomContainer container :
                    ReactionManipulator.getAllAtomContainers(
                            (IReaction)object)) {
                    wholeModel.add(container);
                }
                ShapeSelection container = new RectangleSelection();
                for (IAtom atom : wholeModel.atoms()) {
                    container.atoms.add(atom);
                }
                for (IBond bond : wholeModel.bonds()) {
                    container.bonds.add(bond);
                }
                renderModel.setSelection(container);
            }
            else {
                logger.warn("Cannot select everything in : ", object);
            }
        } else if (type.equals("selectReactionReactants")) {
            IChemObject object = getSource(e);
            if (object instanceof IReaction) {
                IReaction reaction = (IReaction) object;
                IAtomContainer wholeModel =
                    jcpPanel.getChemModel().getBuilder().newInstance(IAtomContainer.class);
                for (IAtomContainer container :
                    MoleculeSetManipulator.getAllAtomContainers(
                            reaction.getReactants())) {
                        wholeModel.add(container);
                }
                ShapeSelection container = new RectangleSelection();
                for (IAtom atom : wholeModel.atoms()) {
                    container.atoms.add(atom);
                }
                for (IBond bond : wholeModel.bonds()) {
                    container.bonds.add(bond);
                }
                renderModel.setSelection(container);
            }
            else {
                logger.warn("Cannot select reactants from : ", object);
            }
        } else if (type.equals("selectReactionProducts")) {
            IChemObject object = getSource(e);
            if (object instanceof IReaction) {
                    IReaction reaction = (IReaction) object;
                    IAtomContainer wholeModel =
                        jcpPanel.getChemModel().getBuilder().newInstance(IAtomContainer.class);
                for (IAtomContainer container :
                    MoleculeSetManipulator.getAllAtomContainers(
                            reaction.getProducts())) {
                        wholeModel.add(container);
                }
                ShapeSelection container = new RectangleSelection();
                for (IAtom atom : wholeModel.atoms()) {
                    container.atoms.add(atom);
                }
                for (IBond bond : wholeModel.bonds()) {
                    container.bonds.add(bond);
                }
                renderModel.setSelection(container);
            }
            else {
View Full Code Here


    public void actionPerformed(ActionEvent actionEvent) {
        String actionCommand = actionEvent.getActionCommand();
        if (actionCommand.equals("comboBoxEdited")
                || actionCommand.equals(GT.get("Insert"))) {
            IAtomContainer molecule = getMolecule();
            if (molecule == null)
                return;
            try {
                JChemPaint.generateModel(jChemPaintPanel, molecule, true, false);
            } catch (CDKException e) {
View Full Code Here

        }
    }

    private IAtomContainer getMolecule() {

        IAtomContainer molecule;
        String text = (String) textCombo.getSelectedItem();
        text = text.trim(); // clean up extra white space

        if (text.equals("")) return null;

        if (text.startsWith("InChI")) { // handle it as an InChI
            try {

                IAtomContainer atomContainer = InChITool.parseInChI(text);
                molecule = atomContainer.getBuilder().newInstance(IAtomContainer.class, atomContainer);


            } catch (Exception e2) {
                JOptionPane.showMessageDialog(jChemPaintPanel, GT.get("Could not load InChI subsystem"));
                return null;
View Full Code Here

        if (!found) return null;

        // got the canonical SMILES, lets get the molecule
        SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
        try {
          IAtomContainer mol=smilesParser.parseSmiles(smiles);
            //for some reason, smilesparser sets valencies, which we don't want in jcp
            for(int i=0;i<mol.getAtomCount();i++){
              mol.getAtom(i).setValency(null);
            }
            return mol;
        } catch (InvalidSmilesException e1) {
            JOptionPane.showMessageDialog(jChemPaintPanel, "Couldn't process data from PubChem");
            return null;
View Full Code Here

            // molecule
            IChemObjectSelection selection = renderer.getRenderer2DModel()
                    .getSelection();

            if (selection != null) {
                IAtomContainer ac = selection.getConnectedAtomContainer();
                if (ac != null) {
                    int implicitHs = 0;
                    for (IAtom atom : ac.atoms()) {
                        if (atom.getImplicitHydrogenCount() != null) {
                            implicitHs += atom.getImplicitHydrogenCount();
                        }
                    }
                    String formula = MolecularFormulaManipulator
View Full Code Here

     * @param chemModel The chemodel
     * @return The result.
     */
    public static IAtomContainer getAllAtomContainersInOne(IChemModel chemModel){
    List<IAtomContainer> acs=ChemModelManipulator.getAllAtomContainers(chemModel);
    IAtomContainer allinone=chemModel.getBuilder().newInstance(IAtomContainer.class);
    for(int i=0;i<acs.size();i++){
      allinone.add(acs.get(i));
    }
    return allinone;
    }
View Full Code Here

        ElementGroup selectionElements = new ElementGroup();
        if(selection==null)
          return selectionElements;
        if (this.autoUpdateSelection || selection.isFilled()) {
            IAtomContainer selectedAC = selection.getConnectedAtomContainer();
           
            if (selectedAC != null) {
              super.setOverrideColor(selectionColor);
              super.setOverrideBondWidth(model.getSelectionRadius());
              selectionElements.add(super.generate(selectedAC, model));
View Full Code Here

        text.setText(file.toString());
        JButtonFixture okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        okbutton.click();
        //not the bug, but still worth testing
        MDLReader reader = new MDLReader(new FileInputStream(file));
        IAtomContainer mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtomCount(), mol.getAtomCount());
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBondCount(), mol.getBondCount());
        applet.menuItem("new").click();
        applet.button("hexagon").click();
        applet.click();
        applet.button("bondTool").click();
        Point2d moveto=getAtomPoint(panel,0);   
        applet.panel("renderpanel").robot.click(applet.panel("renderpanel").component(), new Point((int)moveto.x,(int)moveto.y), MouseButton.LEFT_BUTTON,1);
        applet.menuItem("saveAs").click();
        dialog = applet.dialog();
        combobox = dialog.robot.finder().find(new ComboBoxTextComponentMatcher("org.openscience.jchempaint.io.JCPFileFilter"));
        combobox.setSelectedItem(combobox.getItemAt(SAVE_AS_MOL_COMBOBOX_POS));
        text = dialog.textBox();
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test2.mol");
        if(file.exists())
            file.delete();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        okbutton.click();
        //not the bug, but still worth testing
        reader = new MDLReader(new FileInputStream(file));
        mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtomCount(), mol.getAtomCount());
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBondCount(), mol.getBondCount());
        //ok, now the critical bits - open mol1
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test1.mol");
        applet.menuItem("open").click();
        dialog = applet.dialog();
        text = dialog.textBox();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Open")));
        okbutton.click();
        //"save as" mol1
        file.delete();
        applet.menuItem("saveAs").click();
        dialog = applet.dialog();
        combobox = dialog.robot.finder().find(new ComboBoxTextComponentMatcher("org.openscience.jchempaint.io.JCPFileFilter"));
        combobox.setSelectedItem(combobox.getItemAt(SAVE_AS_MOL_COMBOBOX_POS));
        text = dialog.textBox();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        okbutton.click();
        //open mol2
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test2.mol");
        applet.menuItem("open").click();
        dialog = applet.dialog();
        text = dialog.textBox();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Open")));
        okbutton.click();
        //save should write to mol2, ie mol1=6 atoms, mol2=7atoms
        applet.menuItem("save").click();
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test1.mol");
        reader = new MDLReader(new FileInputStream(file));
        mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(6, mol.getAtomCount());
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test2.mol");
        reader = new MDLReader(new FileInputStream(file));
        mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(7, mol.getAtomCount());
        restoreModelToEmpty();
  }
View Full Code Here

        // panel.get2DHub().updateView();
        // so we crank the lever manually
        JCPAction act = new JCPAction().getAction(panel, "org.openscience.jchempaint.action.ChangeModeAction@select");
        act.actionPerformed(null);
        applet.panel("renderpanel").robot.waitForIdle();
    IAtomContainer ethane = panel.getChemModel().getMoleculeSet().getAtomContainer(0);
    Renderer r = panel.getRenderPanel().getRenderer();
    Point2d atompos0=ethane.getAtom(0).getPoint2d();
    Point2d atompos1=ethane.getAtom(1).getPoint2d();
    atompos0 = r.toScreenCoordinates(atompos0.x, atompos0.y);
    atompos1 = r.toScreenCoordinates(atompos1.x, atompos1.y);
    panel.get2DHub().mouseClickedDown((int)atompos0.x, (int)atompos0.y);
    panel.get2DHub().updateView();
    applet.panel("renderpanel").robot.waitForIdle();
View Full Code Here

        text.setText(file.toString());
        JButtonFixture okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        okbutton.click();
        //not the bug, but still worth testing
        MDLReader reader = new MDLReader(new FileInputStream(file));
        IAtomContainer mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtomCount(), mol.getAtomCount());
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBondCount(), mol.getBondCount());
        applet.menuItem("new").click();
        applet.button("hexagon").click();
        applet.click();
        applet.button("bondTool").click();
        Point2d moveto=getAtomPoint(panel,0);   
        applet.panel("renderpanel").robot.click(applet.panel("renderpanel").component(), new Point((int)moveto.x,(int)moveto.y), MouseButton.LEFT_BUTTON,1);
        applet.menuItem("saveAs").click();
        dialog = applet.dialog();
        combobox = dialog.robot.finder().find(new ComboBoxTextComponentMatcher("org.openscience.jchempaint.io.JCPFileFilter"));
        combobox.setSelectedItem(combobox.getItemAt(SAVE_AS_MOL_COMBOBOX_POS));
        text = dialog.textBox();
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test2.mol");
        if(file.exists())
            file.delete();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        okbutton.click();
        //not the bug, but still worth testing
        reader = new MDLReader(new FileInputStream(file));
        mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getAtomCount(), mol.getAtomCount());
        Assert.assertEquals(panel.getChemModel().getMoleculeSet().getAtomContainer(0).getBondCount(), mol.getBondCount());
        //ok, now the critical bits - open mol1
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test1.mol");
        applet.menuItem("open").click();
        dialog = applet.dialog();
        text = dialog.textBox();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Open")));
        okbutton.click();
        //"save as" mol1
        file.delete();
        applet.menuItem("saveAs").click();
        dialog = applet.dialog();
        combobox = dialog.robot.finder().find(new ComboBoxTextComponentMatcher("org.openscience.jchempaint.io.JCPFileFilter"));
        combobox.setSelectedItem(combobox.getItemAt(SAVE_AS_MOL_COMBOBOX_POS));
        text = dialog.textBox();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Save")));
        okbutton.click();
        //open mol2
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test2.mol");
        applet.menuItem("open").click();
        dialog = applet.dialog();
        text = dialog.textBox();
        text.setText(file.toString());
        okbutton = new JButtonFixture(dialog.robot, dialog.robot.finder().find(new ButtonTextComponentMatcher("Open")));
        okbutton.click();
        //save should write to mol2, ie mol1=6 atoms, mol2=7atoms
        applet.menuItem("save").click();
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test1.mol");
        reader = new MDLReader(new FileInputStream(file));
        mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(6, mol.getAtomCount());
        file=new File(System.getProperty("java.io.tmpdir")+File.separator+"test2.mol");
        reader = new MDLReader(new FileInputStream(file));
        mol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
        Assert.assertEquals(7, mol.getAtomCount());
        restoreModelToEmpty();
  }
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.