PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 7ms RepoModel.GetById 2ms 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
 1package org.guha.rcdk.app;
 2
 3import org.guha.rcdk.util.Misc;
 4import org.guha.rcdk.view.MoleculeImageToClipboard;
 5import org.guha.rcdk.view.RcdkDepictor;
 6import org.guha.rcdk.view.ViewMolecule2D;
 7import org.guha.rcdk.view.ViewMolecule2DTable;
 8import org.openscience.cdk.DefaultChemObjectBuilder;
 9import org.openscience.cdk.interfaces.IAtomContainer;
10import 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 */
21public 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}