Load many molecules into MarvinView

User 37df300f74

16-11-2006 00:38:19

I need to load many smiles into MarvinView class. In my code, I first use viewer.setParams(.....) copied from your API doc.


Then I loop through to setup molecule in each cell


for(int i=0; i<rows;i++)


{


for(int j=0; j<cols; j++)


{


if(mols[j]!=null)


{


Molecule mol = MolImporter.importMol(mols[j]);


//use kekule format


mol.dearomatize();


viewer.setM((i*cols+j),mol);


}


}


}





However in debug mode, each time I use viewer.setM(..), it start a new thread "Thread [MRV-setCursor] (Running)" and takes several seconds so in all it took quite a while to load all smiles.


I loaded the same set into your MarvinView application very quicky, so what am I wrong?








Thanks


Hongzhou

ChemAxon 7c2d26e5cf

16-11-2006 17:52:13

Encapsulate molecule loading in an MViewPane.beginHourglass() and MViewPane.endHourglass() block.


Code:
viewPane.beginHourglass();


for(int i=0;i<rows*cols;i++) {


    Molecule m = MolImporter.importMol(mols[i]);


    m.dearomatize();


    viewPane.setM(i,m);


}


viewPane.endHourglass();



"Thread [MRV-setCursor]" is the cursor changing thread. (Each cursor changing event creates a new thread.)


Before each expensive operation (like molecule loading or cleaning), Marvin changes the the cursor to hourglass unless it set to it earlier. After the time consuming operation, Marvin sets it back to the default cursor.


To avoid invoking too much cursor changing event at filling of cells, turn on hourglass before the loop (that includes costly molecule loading operations). After then, you can set it back.

User 37df300f74

16-11-2006 19:30:14

Thanks Tomas:





Two functions you provides solved the thread issue. However it still takes a while to actually see the molecules in MViewPane contrary to your MView.exe application which load thousand of molecules immediately. Is there any magic here?





I found that setParams(...) function call takes several seconds when loadeing several hundred molecules. Is that normal and how can I optimize it? Do I have to call this function everytime even though I use the same MViewPane object because I am mostly interested in rows and columns parameters?





Thanks a lot





viewer.setParams(


"#\n"+


"# MarvinView properties\n"+


"#\n"+


"rows="+rows+"\n"+


"cols="+cols+"\n"+


"visibleRows ="+visibleRows +"\n" +


"layout0=:2:1:M:1:0:1:1:c:b:1:1:L:0:0:1:1:c:n:0:1\n"+


"param0=:M:100:100\n"+


"\n"+


"#\n"+


"# MarvinSketch properties also have to be specified here for the sketcher\n"+


"# windows that are launched from the viewer (using Edit/Structure).\n"+


"#\n"+


"extrabonds=arom,wedge\n");

ChemAxon 7c2d26e5cf

30-11-2006 17:06:12

The magic is that MView.exe does not load the whole file (just fill the visible cells with the records). When you scroll down in the table, Marvin browses in the file stream and load further structures.


In applets, you can not control it. Actually, Marvin applet's mol parameter is an URL. It means Marvin will get the whole content from the server and process all, immediatelly.