PageRenderTime 44ms CodeModel.GetById 21ms RepoModel.GetById 0ms 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
  1. package org.guha.rcdk.view;
  2. import org.guha.rcdk.view.panels.MoleculeCell;
  3. import org.openscience.cdk.DefaultChemObjectBuilder;
  4. import org.openscience.cdk.interfaces.IAtomContainer;
  5. import org.openscience.cdk.smiles.SmilesParser;
  6. import javax.swing.*;
  7. import java.awt.event.WindowAdapter;
  8. import java.awt.event.WindowEvent;
  9. public class ViewMolecule2D extends JFrame {
  10. MoleculeCell panel;
  11. class ApplicationCloser extends WindowAdapter {
  12. public void windowClosing(WindowEvent e) {
  13. dispose();
  14. }
  15. }
  16. public ViewMolecule2D(IAtomContainer molecule) throws Exception {
  17. this(molecule, 300, 300);
  18. }
  19. public ViewMolecule2D(IAtomContainer molecule, int width, int height) throws Exception {
  20. this(molecule, new RcdkDepictor(width, height, 1.3, "cow", "off", "reagents", true, false, 100, ""));
  21. }
  22. public ViewMolecule2D(IAtomContainer molecule, RcdkDepictor depictor) throws Exception {
  23. panel = new MoleculeCell(molecule, depictor);
  24. setTitle("2D Viewer");
  25. addWindowListener(new ApplicationCloser());
  26. setSize(depictor.getWidth(), depictor.getHeight());
  27. }
  28. public void draw() {
  29. getContentPane().add(panel);
  30. pack();
  31. setVisible(true);
  32. }
  33. public static void main(String[] arg) throws Exception {
  34. String home = "/Users/guhar/";
  35. String[] fname = {home + "src/cdkr/data/dan001.sdf",
  36. home + "src/cdkr/data/dan002.sdf",
  37. home + "src/cdkr/data/dan003.sdf"};
  38. // IAtomContainer[] acs = null;
  39. // try {
  40. // acs = Misc.loadMolecules(fname, true, true, true);
  41. // } catch (CDKException e) {
  42. // e.printStackTrace();
  43. // }
  44. SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  45. sp.kekulise(false);
  46. IAtomContainer mol = sp.parseSmiles("c1ccccc1");
  47. ViewMolecule2D v2d = new ViewMolecule2D(mol);
  48. v2d.draw();
  49. }
  50. }