PageRenderTime 16ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/rcdkjar/src/org/guha/rcdk/app/OSXHelper.java

http://github.com/rajarshi/cdkr
Java | 79 lines | 59 code | 11 blank | 9 comment | 12 complexity | 6b0f1bb44c5f9ee570cfb7f9505d2d8d MD5 | raw file
  1. package org.guha.rcdk.app;
  2. import org.guha.rcdk.util.Misc;
  3. import org.guha.rcdk.view.MoleculeImageToClipboard;
  4. import org.guha.rcdk.view.RcdkDepictor;
  5. import org.guha.rcdk.view.ViewMolecule2D;
  6. import org.guha.rcdk.view.ViewMolecule2DTable;
  7. import org.openscience.cdk.DefaultChemObjectBuilder;
  8. import org.openscience.cdk.interfaces.IAtomContainer;
  9. import org.openscience.cdk.smiles.SmilesParser;
  10. /**
  11. * Provide command line support for AWT based functions.
  12. * <p/>
  13. * This is required on OS X since we can't run the AWT
  14. * from within R. So we get around this by shelling out
  15. * to the command line. Not great, but gets the job done.
  16. *
  17. * @author Rajarshi Guha
  18. */
  19. public class OSXHelper {
  20. private static RcdkDepictor depictor;
  21. public void copyToClipboard(IAtomContainer molecule, int width, int height) throws Exception {
  22. MoleculeImageToClipboard.copyImageToClipboard(molecule, depictor);
  23. }
  24. public void viewMolecule2D(IAtomContainer molecule) throws Exception {
  25. ViewMolecule2D v = new ViewMolecule2D(molecule, depictor);
  26. v.draw();
  27. }
  28. public void viewMoleculeTable(IAtomContainer[] mols, int ncol, int cellx, int celly) throws Exception {
  29. ViewMolecule2DTable v = new ViewMolecule2DTable(mols, ncol, cellx, celly, depictor);
  30. }
  31. public static void main(String[] args) throws Exception {
  32. String method = args[0];
  33. String smiles = args[1]; // if viewing mol table, this will be filename
  34. int width = Integer.parseInt(args[2]);
  35. int height = Integer.parseInt(args[3]);
  36. double zoom = Double.parseDouble(args[4]);
  37. String style = args[5];
  38. String annotate = args[6];
  39. String abbr = args[7];
  40. boolean suppressh = args[8].equals("TRUE") ? true : false;
  41. boolean showTitle = args[9].equals("TRUE") ? true : false;
  42. int smaLimit = Integer.parseInt(args[10]);
  43. String sma = args[11];
  44. depictor = new RcdkDepictor(width, height, zoom, style, annotate, abbr,
  45. suppressh, showTitle, smaLimit, sma);
  46. int ncol = -1;
  47. if (args.length == 13)
  48. ncol = Integer.parseInt(args[12]);
  49. if (smiles != null && !smiles.equals("")) {
  50. OSXHelper helper = new OSXHelper();
  51. SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance());
  52. if (method.equals("copyToClipboard")) {
  53. IAtomContainer mol = sp.parseSmiles(smiles);
  54. helper.copyToClipboard(mol, width, height);
  55. } else if (method.equals("viewMolecule2D")) {
  56. IAtomContainer mol = sp.parseSmiles(smiles);
  57. helper.viewMolecule2D(mol);
  58. } else if (method.equals("viewMolecule2Dtable")) {
  59. IAtomContainer[] mols = Misc.loadMolecules(new String[]{smiles}, true, true, true);
  60. helper.viewMoleculeTable(mols, ncol, width, height);
  61. } else {
  62. System.out.println("Didn't recognize method to run");
  63. }
  64. } else {
  65. System.out.println("Didn't get a SMILES to process");
  66. }
  67. }
  68. }