Step-by-step code examples

    Create a JFrame containing a MarvinSpace canvas

    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:

    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();
    
    }

    Load a molecule

    To go one step further, we will need some molecules to display. The following code lines can be placed for example before the 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 );

    .