PageRenderTime 69ms CodeModel.GetById 61ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/rcdkjar/src/org/guha/rcdk/view/ViewMolecule2D.java

http://github.com/rajarshi/cdkr
Java | 63 lines | 44 code | 13 blank | 6 comment | 0 complexity | 249e9e37def816027253baf871e45efa MD5 | raw file
 1package org.guha.rcdk.view;
 2
 3import org.guha.rcdk.view.panels.MoleculeCell;
 4import org.openscience.cdk.DefaultChemObjectBuilder;
 5import org.openscience.cdk.interfaces.IAtomContainer;
 6import org.openscience.cdk.smiles.SmilesParser;
 7
 8import javax.swing.*;
 9import java.awt.event.WindowAdapter;
10import java.awt.event.WindowEvent;
11
12
13public class ViewMolecule2D extends JFrame {
14    MoleculeCell panel;
15
16    class ApplicationCloser extends WindowAdapter {
17        public void windowClosing(WindowEvent e) {
18            dispose();
19        }
20    }
21
22    public ViewMolecule2D(IAtomContainer molecule) throws Exception {
23        this(molecule, 300, 300);
24    }
25
26    public ViewMolecule2D(IAtomContainer molecule, int width, int height) throws Exception {
27        this(molecule, new RcdkDepictor(width, height, 1.3, "cow", "off", "reagents", true, false, 100, ""));
28    }
29
30    public ViewMolecule2D(IAtomContainer molecule, RcdkDepictor depictor) throws Exception {
31        panel = new MoleculeCell(molecule, depictor);
32        setTitle("2D Viewer");
33        addWindowListener(new ApplicationCloser());
34        setSize(depictor.getWidth(), depictor.getHeight());
35
36    }
37
38    public void draw() {
39        getContentPane().add(panel);
40        pack();
41        setVisible(true);
42    }
43
44    public static void main(String[] arg) throws Exception {
45        String home = "/Users/guhar/";
46        String[] fname = {home + "src/cdkr/data/dan001.sdf",
47                home + "src/cdkr/data/dan002.sdf",
48                home + "src/cdkr/data/dan003.sdf"};
49//        IAtomContainer[] acs = null;
50//        try {
51//            acs = Misc.loadMolecules(fname, true, true, true);
52//        } catch (CDKException e) {
53//            e.printStackTrace();
54//        }
55        SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
56        sp.kekulise(false);
57        IAtomContainer mol = sp.parseSmiles("c1ccccc1");
58
59        ViewMolecule2D v2d = new ViewMolecule2D(mol);
60
61        v2d.draw();
62    }
63}