Frequently Asked Questions

Marvin Beans

  1. If I put MViewPane objects in JTable cells then I can display only about 200 molecules. These huge objects cause out of memory exceptions. Do you provide a simple and "thin" viewer component, which just displays a molecule without any rotation and linkage to the sketcher?
  2. If I put MView applets in an HTML table then I can display only about 200 molecules because the browser slows down and runs out of memory. Do you provide a simple and "thin" applet, which just displays molecules without any rotation and linkage to the sketcher?
  3. MViewPane.getM(int) returns with null.
  4. I called MViewPane.setParams() to change only one parameter in MarvinView but it changed all of them.
  5. Is there a way to generate image without opening a display
  6. I have not managed to load a molecule string from applet parameter in Mozilla.
  7. How can I get the selected atoms from MSketchPane?

  1. If I put MViewPane objects in JTable cells then I can display only about 200 molecules. These huge objects cause out of memory exceptions. Do you provide a simple and "thin" viewer component, which just displays a molecule without any rotation and linkage to the sketcher?

    The rotation and the linkage to the sketcher have negligible contribution to the memory footprint. The largest contributions are from

    1. double buffering of Swing components
    2. size of Molecule objects
    3. large color arrays that store the shades for 3D rendering modes

    Even if we provided a "thin" panel without 3D support, it would only enable you to use about twice as many molecules. Then you would run out of memory again because of the double buffering.

    The solution is to use only one n-molecule scrollable MViewPane instead of a JTable with n MViewPanes. Then the common data will be stored in only one place (instead of n) and the number of Swing components will be equal to the number of visible molecules which is usually much smaller than n.

  2. When I put MView applets into an HTML table, I can only display about 200 molecules because the browser slows down and runs out of memory. Do you provide a simple and "thin" applet, which just displays molecules without any rotation and linkage to the sketcher?

    You should use an n-molecule scrollable MView table instead of n applets, see explanation to the previous question.

  3. MViewPane.getM(int) returns with null.

    I have this problem when I want to get a Molecule from MViewPane: viewPane.getM(0) returns null although I put a molecule in 0. Here is my code:

    	    viewPane.setM(0, "mols-2d/caffeine.mol");
    	    Molecule m = viewPane.getM(0);
    The problem is that you called getM(0) too early. The molecule was not loaded yet, since viewPane.getM(0). MViewPane.setM(int,String) launches a new thread for loading a molecule and the getM(0) method does not wait until this thread is finished. Thus, there is no guaranty that the molecule loading process is finished until the method returns. This method is generally used in case of loading a huge set of molecules in the same time. If you use debug option: viewPane.setDebug(2), you can see when the molecule is loaded. Instead of setM(int, java.lang.String) use setM(int, java.io.File, java.lang.String) method. Using this method will cause setM to wait until molecule loading is finished.

    This example shows a similar problem:

    	viewPane.setM(0, "CN1C=NC2=C1C(=O)N(C)C(=O)N2C");
    	Molecule m = viewPane.getM(0);
    
    In this case, there are several ways to avoid this problem. For example, you can use MViewPane.setM(int, Molecule) method:
    	String smiles="CN1C=NC2=C1C(=O)N(C)C(=O)N2C";
    	byte[] buf=smiles.getBytes();
    	MolImporter mi = new MolImporter(new ByteArrayInputStream(buf));
    	try{
    	    Molecule mol = mi.importMol(buf);
    	    viewPane.setM(0,mol);
    	}catch(Exception e) {System.err.println(e);}
    	Molecule m = viewPane.getM(0);
    

  4. I called MViewPane.setParams() to change only one parameter in MarvinView but it changed all of them.

    The MarvinPanel.setParams(String) method is used to set parameters when MarvinPane is initialized (before loading the molecule). You should avoid calling this method after setMol(..) or any other property-setting method. You can find more details about it at here.

    The difference between a parameter and a property that you can modify a property's value after initialization, while a parameter can only be set once.

  5. Is there a way to generate image without opening a display

    It is possible with the Xvfb virtual X11 server. Documentation can be found on the xfree86 site and in the Linux manual (man Xvfb).

    Xvfb :2 -screen 0 649x480x24 2>>logfile &
    export DISPLAY=:2

  6. I have not managed to load a molecule string from applet parameter in Mozilla.

    Your molecule string may contain consecutive space characters in applet parameters which are converted to only one space. This bug applies to Mozilla 0.9.7-1.0 and probably some earlier versions too.

  7. How can I get the selected atoms from MSketchPane?

    Please see the below example to get selected atoms.

        Molecule mol = sketchPane.getMol();
        if(mol != null) {
            int size = mol.getAtomCount();
            for(int i = 0;i < size;i++) {
                MolAtom atom = mol.getAtom(i);
                if(atom.isSelected()) {
                    System.err.println(i+". atom is selected");
                }
            }
        }