Let's create a simple MarvinSpace application.
First, we have to install the Jogl native libraries. MSpaceInstaller
will do this for us.
The second step is creating a JFrame
.
Third, we have to put the MarvinSpace canvas on it. MSpaceEasy
makes it simple,
we can also add several GUI components such as Popup Menu and MenuBar.
Finally the frame is ready to show.
public void createSimpleMarvinSpaceFrame() throws Exception { //parameter true tells that dynamic loading of the Jogl native libraries is necessary final chemaxon.marvin.space.MSpaceEasy mspace = new chemaxon.marvin.space.MSpaceEasy(true); JFrame frame = new JFrame(); frame.setTitle(chemaxon.marvin.space.gui.MSpace.programName+" "+chemaxon.marvin.space.gui.MSpace.version); frame.setSize(800, 750); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mspace.addCanvas(frame.getContentPane()); mspace.addPopupMenu(); mspace.addMenuBar(frame); mspace.setSize(600, 600); frame.pack(); frame.show(); }
frame.pack()
call.
In case of having a SMILES String:
final String molS = "C1C2=CC=CC=C2C3=C4CC5=CC=CC=C5C4=C6CC7=CC=CC=C7C6=C13"; Molecule mol = MolImporter.importMol(molS); mspace.addMolecule( mol );By default MarvinSpace checks whether the molecule is defined in plane or not, and calls Clean, Hydrogenize and Aromatize functions of the Molecule.
Loading from a file or URL:
mspace.addMolecule("http://www.chemaxon.com/MarvinSpace/data/1AID.pdb");
Let's suppose we have a properly initilaized Vector containing Molecule
objects.
We can place them in different cells each:
for(int i=0; i<molVector.size(); i++) { mspace.addMoleculeToEmptyCell(molVector.get(i)); }
Loading a molecule without calling Clean, Hydrogenize and Aromatize:
mspace.addMoleculeWithoutChange( mol );
In the previous examples we added the molecules to the scene, but we can also load a molecule by closing all molecules before:
mspace.openMolecule( mol );
Loading molecule to a specific cell (indexing starts from 0, from top to bottom and left to right):
mspace.addMoleculeTo( mol, 1 );
Runnable code example can be found here.
public class AppletExample extends JApplet { MSpaceEasy mspace = null; public void init() { try { /* The first argument indicates, that loading native libraries is necessary. * The second is false, we do not need the technical information about loading the libraries. * The applet codebase has to be set as third argument. */ mspace= new MSpaceEasy(true, false, this.getCodeBase()); /* add Selection Panel and Canvas */ if(getParameter("selectionpanel")!=null && getParameter("selectionpanel").equals("true")) { mspace.addSelectionPanel(this); } /* add Canvas */ else { mspace.addCanvas(this.getContentPane()); } /* add MenuBar */ if(getParameter("menubar")!=null && getParameter("menubar").equals("true")) { mspace.addMenuBar(this); } /* add ToolBar */ if(getParameter("toolbar")!=null && getParameter("toolbar").equals("true")) { mspace.addToolBar(this); } /* add Popup Menu */ if(getParameter("popupmenu")!=null && getParameter("popupmenu").equals("true")) { mspace.addPopupMenu(); } this.setVisible(true); String rc = getParameter("rowCount"); String cc = getParameter("columnCount"); final int rowCount = rc == null ? 1 : Integer.parseInt(rc); final int columnCount = cc == null ? 1 : Integer.parseInt(cc); /* set the number of rows and columns */ if(rowCount > 1 || columnCount > 1) { mspace.setLayout(rowCount, columnCount); } /* load a molecule */ final String mol = getParameter("molecule"); if(mol!=null) { mspace.addMolecule(getAbsoluteFileName(mol)); } /* load molecules in case of multiple cell view */ int n = 0; while(n < rowCount * columnCount ) { final String moln = getParameter("cell"+n); if(moln != null) { mspace.addMoleculeToEmptyCell(moln); n++; } else { break; } } } catch (Exception e) { e.printStackTrace(); } } private String getAbsoluteFileName(String fileName) { java.io.File f = new java.io.File(fileName); if(fileName.startsWith("http:/") || fileName.startsWith("ftp:/")) { try{ new java.net.URL(fileName).openConnection(); } catch(Exception e ) { fileName = getCodeBase() + ((fileName.charAt(0)!='/') ? fileName : fileName.substring(1)); } } else if(!f.exists()) { fileName = getCodeBase() + ((fileName.charAt(0)!='/') ? fileName : fileName.substring(1)); } return fileName; } }
<?xml version="1.0" encoding="UTF-8"?> <jnlp spec="1.0+" codebase="http://www.chemaxon.com/marvinspace" href="jnlp/1_3/mspace1aid.jnlp"> <information> <title>MarvinSpace</title> <vendor>ChemAxon</vendor> <icon href="mspace64.gif"/> <homepage href="http://www.chemaxon.com"/> <description>MarvinSpace is a 3D molecule visualization tool.</description> <offline-allowed/> </information> <security> <all-permissions/> </security> <resources> <j2se href="http://java.sun.com/products/autodl/j2se" version="1.4+" initial-heap-size="256m" max-heap-size="512m"/> <jar href="lib/MarvinBeans.jar"/> <jar href="lib/jextexp.jar"/> <jar href="lib/chart.jar" download="lazy"/> <jar href="lib/batik-core.jar" download="lazy"/> <jar href="lib/freehep-base.jar" download="lazy"/> <jar href="lib/freehep-graphics2d.jar" download="lazy"/> <jar href="lib/freehep-graphicsio.jar" download="lazy"/> <jar href="lib/freehep-graphicsio-emf.jar" download="lazy"/> <jar href="lib/freehep-graphicsio-pdf.jar" download="lazy"/> <property name="sun.java2d.noddraw" value="true"/> <property name="jogl.GLContext.noopt" value="true"/> <extension name="jogl" href="http://www.chemaxon.com/marvinspace/jnlp/1_3/mspace_jogl.jnlp"/> </resources> <application-desc main-class="chemaxon.marvin.space.gui.MSpaceJWS"> <argument>-p</argument> <argument>Background.Smooth</argument> <argument>true</argument> <argument>-p</argument> <argument>Background.Color</argument> <argument>#cccccc</argument> <argument>-p</argument> <argument>Ligand.DrawType</argument> <argument>Stick</argument> <argument>-p</argument> <argument>MacroMolecule.DrawType</argument> <argument>Stick</argument> <argument>-p</argument> <argument>Water.DrawType</argument> <argument>Ball</argument> <argument>-p</argument> <argument>ShowSurface</argument> <argument>Connolly</argument> <argument>-p</argument> <argument>Surface.ColorType</argument> <argument>AtomType</argument> <argument>-p</argument> <argument>Surface.DrawType</argument> <argument>Transparent</argument> <argument>http://chemaxon.com/marvinspace/data/1AID.pdb</argument> </application-desc> </jnlp>