setThreadCount in JAVA API for sdf to mol converter

User 2bdca8573c

04-06-2015 15:45:41

The code doesn't works when I place  setThreadCount before convert().


 



public void Sdfmol() throws MolExportException, IllegalArgumentException,IllegalStateException, IOException {


MolConverter.Builder mcbld = new MolConverter.Builder();
            mcbld.addInput(Name1, "");
            mcbld.setOutput(Name2, "mol");
            mcbld.setOutputFlags(MolExporter.TEXT|MolExporter.MULTIPLE);
            MolConverter mc = mcbld.build();
            setThreadCount(0);  // Code doesn't run if I place this here.
            while(mc.convert())
                    {
                
                counter = counter+1;
                System.out.println("Converted molecule:"+counter);
                    }
            mc.close();
            System.out.println("Calculated: "+counter+"\n");

    }



If I place the setThreadCount after convert() it works fine. It runs perfectly fine without setThreadCount().


I am still very new to Java. So it would be my pleasure if you could direct me.


Thank you.

ChemAxon 4fa3cf533c

05-06-2015 08:57:11

Hi There,


From the code it seems you've added a method to your class which is not provided here. You are calling your own implementation of setThreadCount, and not on the one on the MolConverter, which I assume was your initial thought. By providing that method, maybe we can find out what went wrong.


Setting the thread count on MolConverter, by calling the setThreadCount method on the object, you can tell the converter, to use multiple threads during the conversion. It can speed up the convert, when running from a computer which has multiple cores in the CPU. By setting it to zero not makes much sense, but it won't, or should not affect the execution, it only affects the execution if this number is bigger than zero.


I hope I could help. 


Regards,


Tamas Fazekas-Vigh

User 2bdca8573c

05-06-2015 16:42:16

I seriously apologize to make such mistake. I did include the object calling.


Here is the correct code.





public void Sdfmol() throws MolExportException, IllegalArgumentException,IllegalStateException, IOException {


MolConverter.Builder mcbld = new MolConverter.Builder();
            mcbld.addInput(Name1, "");
            mcbld.setOutput(Name2, "mol");
            mcbld.setOutputFlags(MolExporter.TEXT|MolExporter.MULTIPLE);
            MolConverter mc = mcbld.build();
            mc.setThreadCount(0);  // Code doesn't run if I place this here.
            while(mc.convert())
                    {
                
                counter = counter+1;
                System.out.println("Converted molecule:"+counter);
                    }
            mc.close();
            System.out.println("Calculated: "+counter+"\n");

    }



The object was used from MolConverter mc = mcbld.build();


The code doesn't gives any error on execution. It just freezes and does not perform any conversion. Even if the number is 0 or 1 for setThreadCount


 

ChemAxon 4fa3cf533c

08-06-2015 09:29:30

Hi there,


Unfortunately, I was unable to reproduce the issue with the provided code. It converted the molecules for me, even when the thread count was set to 0. I've tried with multiple mol files even. 


Could you please provide, what kind of molecules you try to convert (I think the file extension would be sufficient), also please tell us what version of Marvin do you use, and preferably send us the About dialog of Marvin. 


Also a specific OS type, and processor architecture (32/64 bit), could get us moving towards fixing it.


Does it also fails to convert, if you do not set the threadCount, or if you set it to for example 2 or a bigger amount ? Setting the thread count after the conversion will have no effect, for the previous conversion, so that is why it works that way.


 


Best Regards,


Tamas Fazekas-Vigh