Package org.openscience.cdk.interfaces

Examples of org.openscience.cdk.interfaces.IAtomContainer


    IMolecule mol = sp.parseSmiles("C1CC12CC2CC1CC1");
    AllRingsFinder ar = new AllRingsFinder();
    IRingSet ringSet = ar.findAllRings(mol);
    List l = RingPartitioner.partitionRings(ringSet);
    for(Object o : l) {
      IAtomContainer ac = RingPartitioner.convertToAtomContainer((IRingSet)o);
      IMolecule nMol = new Molecule(ac);
      System.out.println(new SmilesGenerator().createSMILES(nMol));
    }
  }
View Full Code Here


    if(igf != null) {
      //System.out.println("Use IGF!");
      try {
        lock.lock();
        //getInstance().igf.
        IAtomContainer iac = igf.getInChIToStructure(InChI).getAtomContainer();
        IMolecule mol = new Molecule(iac);
        molCache.put(InChI, mol);

        return mol;
        //return getInstance().igf.getInChIGenerator(mol).getInchi();
View Full Code Here

   
    public void setChemObject(IChemObject object) {
        if (object instanceof IAtomContainer) {
            source = object;
            // update table contents
            IAtomContainer container = (IAtomContainer)source;
            String title = "";
            if (container.getProperty(CDKConstants.TITLE) != null) title = container.getProperty(CDKConstants.TITLE).toString();
            titleField.setText(title);
        } else {
            throw new IllegalArgumentException("Argument must be an AtomContainer");
        }
    }
View Full Code Here

            while(it.hasNext()) {
                String key=it.next();
                JPanel panel = new JPanel();
                panel.setLayout(experimentLayout);
                for(int k=0;k<entriesMol.get(key).size();k++){
                    IAtomContainer cdkmol = entriesMol.get(key).get(k);
                    Icon icon = entriesIcon.get(entriesMolName.get(cdkmol));
                    JButton button = new JButton();
                    if(icon!=null)
                        button.setIcon(icon);
                    panel.add(button);
                    button.setPreferredSize(new Dimension(100,120));
                    button.setMaximumSize(new Dimension(100,120));
                    button.addActionListener(this);
                    button.setVerticalTextPosition(SwingConstants.BOTTOM);
                    button.setHorizontalTextPosition(SwingConstants.CENTER);
                    button.setText((String)cdkmol.getProperty(CDKConstants.TITLE));
                    button.setToolTipText((String)cdkmol.getProperty(CDKConstants.TITLE));
                    button.setFont(button.getFont().deriveFont(10f));
                    button.setName((String)cdkmol.getProperty(CDKConstants.TITLE));
                    mols.put(button, cdkmol);
                    JButton allButton = new JButton();
                    if(icon!=null)
                        allButton.setIcon(icon);
                    panel.add(button);
                    allButton.setPreferredSize(new Dimension(100,120));
                    allButton.setMaximumSize(new Dimension(100,120));
                    allButton.addActionListener(this);
                    allButton.setVerticalTextPosition(SwingConstants.BOTTOM);
                    allButton.setHorizontalTextPosition(SwingConstants.CENTER);
                    allButton.setText((String)cdkmol.getProperty(CDKConstants.TITLE));
                    allButton.setToolTipText((String)cdkmol.getProperty(CDKConstants.TITLE));
                    allButton.setFont(allButton.getFont().deriveFont(10f));
                    mols.put(allButton, cdkmol);
                    allPanel.add(allButton);
                    scrollPane.setPreferredSize(new Dimension(allPanel.getPreferredSize().width
                            +scrollPane.getVerticalScrollBar().getPreferredSize().width,360));
View Full Code Here

                                entriesMol.put(restname.substring(0,restname.length()-1), new ArrayList<IAtomContainer>());
                            }else if(restname.indexOf("/")>-1 && withsubdirs){
                                if(entry.getName().indexOf(".mol")>-1){
                                    InputStream ins = dummy.getClass().getClassLoader().getResourceAsStream(entry.getName());
                                    MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.RELAXED);
                                    IAtomContainer cdkmol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
                                    entriesMol.get(restname.substring(0,restname.indexOf("/"))).add(cdkmol);
                                    entriesMolName.put(cdkmol,entry.getName().substring(0,entry.getName().length()-4));
                                }else{
                                    Icon icon = new ImageIcon(new URL(url.toString()+entry.getName()));
                                    entriesIcon.put(entry.getName().substring(0,entry.getName().length()-4),icon);
                                }
                            }
                        }
                    }
                }
            }catch(IOException ex){
                //This is a version we fall back to if no jar available. This should be in Eclipse only.
                File file = new File(new File(dummy.getClass().getProtectionDomain().getCodeSource().getLocation().toURI()).getAbsolutePath()+File.separator+TEMPLATES_PACKAGE.replace('/', File.separatorChar));
                for (int i=0;i<file.listFiles().length ; i++) {
                    if(file.listFiles()[i].isDirectory()){
                        File dir = file.listFiles()[i];
                        if(!dir.getName().startsWith(".")) {
                            entriesMol.put(dir.getName(), new ArrayList<IAtomContainer>());
                            if(withsubdirs){
                                for(int k=0;k<dir.list().length;k++){
                                    if(dir.listFiles()[k].getName().indexOf(".mol")>-1){
                                        MDLV2000Reader reader = new MDLV2000Reader(new FileInputStream(dir.listFiles()[k]), Mode.RELAXED);
                                        IAtomContainer cdkmol = (IAtomContainer)reader.read(DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class));
                                        entriesMol.get(dir.getName()).add(cdkmol);
                                        entriesMolName.put(cdkmol,dir.listFiles()[k].getName().substring(0,dir.listFiles()[k].getName().length()-4));
                                    }else{
   
                                        Icon icon = new ImageIcon(dir.listFiles()[k].getAbsolutePath());
View Full Code Here

        applet.panel("renderpanel").robot.waitForIdle();
       
        applet.button("select").click();
        panel.get2DHub().updateView();
        applet.panel("renderpanel").robot.waitForIdle();
    IAtomContainer ethane = panel.getChemModel().getMoleculeSet().getAtomContainer(0);
        RectangleSelection sel = new RectangleSelection();
        sel.addAtom (ethane.getAtom(0));
        sel.addBond(ethane.getBond(0));
        panel.getRenderPanel().getRenderer().getRenderer2DModel().setSelection(sel);
        panel.selectionChanged();
        try {
      applet.button("cut").click();
          panel.get2DHub().updateView();
View Full Code Here

        }

        // MDLV3000 reading
        if (cor.accepts(IAtomContainer.class) && chemModel==null) {
            // try to read a Molecule
                IAtomContainer mol = (AtomContainer) cor.read(new AtomContainer());
                if(mol!=null )
                    try{
                        IAtomContainerSet newSet = new AtomContainerSet();
                        newSet.addAtomContainer(mol);
                        chemModel = new ChemModel();
                        chemModel.setMoleculeSet(newSet);
                        if (chemModel == null) {
                            error = "The object chemModel was empty unexpectedly!";
                        }
                    } catch (Exception exception) {
                        error = "Error while reading file: " + exception.getMessage();
                        exception.printStackTrace();
                    }
        }

        // RGroupQuery reading
        if (cor.accepts(RGroupQuery.class) && chemModel==null) {
          IRGroupQuery rgroupQuery = (RGroupQuery) cor.read(new RGroupQuery(DefaultChemObjectBuilder.getInstance()));
          if(rgroupQuery!=null )
            try{
              chemModel = new ChemModel();
              RGroupHandler rgHandler =  new RGroupHandler(rgroupQuery, panel);
              panel.get2DHub().setRGroupHandler(rgHandler);
              chemModel.setMoleculeSet(rgHandler.getMoleculeSet(chemModel));
              rgHandler.layoutRgroup();
             
            } catch (Exception exception) {
              error = "Error while reading file: " + exception.getMessage();
              exception.printStackTrace();
            }
        }
       
        if (error != null) {
            throw new CDKException(error);
        }

        if (chemModel == null && chemFile != null) {
            chemModel = (ChemModel) chemFile.getChemSequence(0).getChemModel(0);
        }

      //SmilesParser sets valencies, switch off by default.
        if(cor instanceof SMILESReader){
          IAtomContainer allinone = JChemPaintPanel.getAllAtomContainersInOne(chemModel);
             for(int k=0;k<allinone.getAtomCount();k++){
               allinone.getAtom(k).setValency(null);
        }
        }
        return chemModel;
    }
View Full Code Here

     * @throws Exception
     */
    private static void generate2dCoordinates(List<IAtomContainer> molecules) {
        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        for (int atIdx = 0; atIdx < molecules.size(); atIdx++) {
            IAtomContainer mol = molecules.get(atIdx);
            sdg.setMolecule(mol.getBuilder().newInstance(IAtomContainer.class,mol));
            try {
                sdg.generateCoordinates();
            } catch (Exception e) {
                e.printStackTrace();
            }
            IAtomContainer ac = sdg.getMolecule();
            for(int i=0;i<ac.getAtomCount();i++){
                mol.getAtom(i).setPoint2d(ac.getAtom(i).getPoint2d());
            }
        }
    }
View Full Code Here

    }

    public static Rectangle2D calculateBounds(IAtomContainerSet moleculeSet) {
        Rectangle2D totalBounds = new Rectangle2D.Double();
        for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
            IAtomContainer ac = moleculeSet.getAtomContainer(i);
            Rectangle2D acBounds = calculateBounds(ac);
            if (totalBounds.isEmpty()) {
                totalBounds = acBounds;
            } else {
                Rectangle2D.union(totalBounds, acBounds, totalBounds);
View Full Code Here

        JChemPaintPanel panel = (JChemPaintPanel)jcppanel.target;
        applet.button("C").click();
        applet.button("bondTool").click();
        applet.panel("renderpanel").robot.click(applet.panel("renderpanel").component(),new Point(100,100));
        applet.button("select").click();
    IAtomContainer ethane = panel.getChemModel().getMoleculeSet().getAtomContainer(0);
    Point2d p1 = ethane.getAtom(0).getPoint2d();
    Renderer r = panel.getRenderPanel().getRenderer();
    p1 = r.toScreenCoordinates(p1.x, p1.y);
      panel.get2DHub().mouseClickedDown((int)(p1.x), (int)(p1.y));
        applet.panel("renderpanel").robot.waitForIdle();
      panel.get2DHub().mouseClickedUp((int)p1.x, (int)p1.y);
        panel.get2DHub().updateView();
        applet.panel("renderpanel").robot.waitForIdle();
        IChemObjectSelection sel = r.getRenderer2DModel().getSelection();
        Assert.assertEquals(true, sel.contains(ethane.getAtom(0)));

    double d = r.getRenderer2DModel().getSelectionRadius() / r.getRenderer2DModel().getScale();
      panel.get2DHub().mouseClickedDown((int)(p1.x+d/2), (int)(p1.y+d/2));
        applet.panel("renderpanel").robot.waitForIdle();
      panel.get2DHub().mouseDrag((int)(p1.x+d/2), (int)(p1.y+d/2),(int)p1.x+100, (int)p1.y+100);
      panel.get2DHub().mouseClickedUp((int)p1.x+100, (int)p1.y+100);
        panel.get2DHub().updateView();
        applet.panel("renderpanel").robot.waitForIdle();
        sel = panel.getRenderPanel().getRenderer().getRenderer2DModel().getSelection();
        Point2d p2 = ethane.getAtom(0).getPoint2d();
        p2 = r.toScreenCoordinates(p2.x, p2.y);
        Assert.assertEquals((int)(p1.x+100), (int)p2.x);
    }
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.