Debian Codegraph @

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

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