Lone pairs and other 'decorations' clipped off images

User 44bb556150

16-07-2009 03:19:22

I'm using the MarvinView library to generate molecule images (PNG).  The library auto-scales the molecule drawing sizes such that they fill up the image drawing canvas without clipping off any atoms or bonds.  However, if I want to include additional "decorations" such as lone pairs on the atoms, the auto-scale algorithm does not appear to take these into account.  This results in occasional images getting these decorations clipped off, which can make them look like invalid Lewis structures.


Please update the auto-scaling algorithm to take these decorations into account.  A simple solution might be to just add a few more pixels of "cellpadding" to the image canvas in the scaling algorithm, such that it is unlikely for any added decorations to be added beyond the actual canvas border.

ChemAxon 5433b8e56b

17-07-2009 14:32:45

Dear Jonathan,


We noticed an another issue with brackets in Marvin that is related to your problem, and we are keen on to fix that. I have updated our bug database with this form of the known problem, my colleagues will repair this soon.


We will inform you in this forum topic when the fix is ready.


Best regards,
Istvan

ChemAxon e500b51457

08-09-2009 20:53:03

Hello,

The fix is available in version 5.2.4. Please give us feedback if this is working for you.

Best regards,
Erika.

User 44bb556150

22-12-2009 03:49:36

Thanks for the updates, though it has taken me a long time to get back to this issue.  I was keen on testing out the update, but found that the change ended up crashing my existing code, which has prevented me from upgrading to the latest Marvin version.


I attached a small code example of an image export that used to work with Marvin 5.1.3, but now fails in 5.2.6 with a NullPointerException.  Inspecting closer, it appears to happen during the molecule "clean 2D" phase.  Unclear to me, but perhaps I need to have some properties or config file on my classpath or something for the "PeriodicSystem?"

ChemAxon 7c2d26e5cf

29-12-2009 10:35:37

We have managed to compile and run your example with both Marvin Beans versions (5.1.3 and 5.2.6).


We have not found any exception by running your code.


I assume there can be a configuration problem on your machine that caused the error by 5.2.6 version.


Probably, the old Marvin left in the classpath.

User 44bb556150

30-12-2009 01:30:47

I looked into it further, and what makes this tricky is that I'm actually trying to run the code through a Java servlet in a Tomcat server.  Below is a full stack trace of the initial error:


java.lang.ExceptionInInitializerError
 chemaxon.struc.MolAtom.isotopeType(Unknown Source)
 chemaxon.marvin.modules.GraphInvariants.<clinit>(Unknown Source)
 java.lang.Class.forName0(Native Method)
 java.lang.Class.forName(Unknown Source)
 chemaxon.marvin.util.MarvinModule.loadClass(Unknown Source)
 chemaxon.marvin.util.MarvinModule.load(Unknown Source)
 chemaxon.marvin.util.MarvinModule.load(Unknown Source)
 chemaxon.struc.MoleculeGraph.a(Unknown Source)
 chemaxon.struc.MoleculeGraph.getGrinv(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.modfunc(Unknown Source)
 chemaxon.struc.MoleculeGraph.clean(Unknown Source)
 chemaxon.struc.Molecule.clean(Unknown Source)
 chemaxon.struc.MoleculeGraph.clean(Unknown Source)
 TestWebService.testImage(TestWebService.java:68)
 TestWebService.doGet(TestWebService.java:47)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803)



root cause


java.lang.NullPointerException: in is null
 java.util.zip.ZipInputStream.<init>(Unknown Source)
 chemaxon.struc.PeriodicSystem.a(Unknown Source)
 chemaxon.struc.PeriodicSystem.<clinit>(Unknown Source)
 chemaxon.struc.MolAtom.isotopeType(Unknown Source)
 chemaxon.marvin.modules.GraphInvariants.<clinit>(Unknown Source)
 java.lang.Class.forName0(Native Method)
 java.lang.Class.forName(Unknown Source)
 chemaxon.marvin.util.MarvinModule.loadClass(Unknown Source)
 chemaxon.marvin.util.MarvinModule.load(Unknown Source)
 chemaxon.marvin.util.MarvinModule.load(Unknown Source)
 chemaxon.struc.MoleculeGraph.a(Unknown Source)
 chemaxon.struc.MoleculeGraph.getGrinv(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.a(Unknown Source)
 chemaxon.marvin.modules.Clean2D.modfunc(Unknown Source)
 chemaxon.struc.MoleculeGraph.clean(Unknown Source)
 chemaxon.struc.Molecule.clean(Unknown Source)
 chemaxon.struc.MoleculeGraph.clean(Unknown Source)
 TestWebService.testImage(TestWebService.java:68)
 TestWebService.doGet(TestWebService.java:47)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


I investigated further and I am almost certain this has something to do with the chemaxon.marvin.util.Environment.getResourceAsStream method.  The chemaxon.marvin.struc.PeriodicSystem wants to initialize with a resource referenced as "/chemaxon/elements.zip," but is getting back a null resource instead (causing the failure on instantiation of the ZipInputStream).


I did a test, and if I copied the chemaxon folder from my Marvin installation (including the elements.zip file) to my working directory, I can get the TestImageGenerator.java command-line program working.  However, I still cannot get my Java servlet working, because I don't know where this resource should be copied to / installed.  I tried several places in my Tomcat root and webapps directory, but none seemed to work.


What is strange, is that this still worked with Marvin 5.1.3, even though the chemaxon/elements.zip resource was not installed anywhere with the Java servlet.  Similarly strange is why the molecule "clean" method should care about element isotopes anyway.


 

ChemAxon 8b644e6bf4

31-12-2009 06:25:59

Dear Jonathan,


 


Tamas is on holiday now, he will be back next week.


 


Regards,


Gabor

ChemAxon 7c2d26e5cf

05-01-2010 15:18:53

Hi Jonathan,


You are right Environment.getResourceAsStream returns with null in this case and ZipInputStream constructor gets null parameter that causes the NullPointerException.


If you run Marvin applets, Marvin tries to download elements.zip from the applet codebase (from the server). In any other cases, Marvin searches this file inside the jar file where PeriodicSystem class is located.
In the Marvin Applets package, the PeriodicSystem class is located in the marvin/sjars/periodicsystem.jar and elements.zip is outside of the jar. In the Marvin Beans package this class and the chemaxon/elements.zip file are also part of the MarvinBeans.jar. I guess when you run your code, Java loaded PeriodicSystem class from the periodicsystem.jar that's why Marvin did not find elements.zip in the same jar.


So, I assume that you use wrong jars in your classpath. The stack trace and your description about the problem proves that marvin applet package jars were loaded when this exception was invoked.


Please do not use Marvin Applets package for custom applications. It is designed to run applet on web sites. You need the Marvin Beans package in server side Java code.


Please check your Tomcat classpath, root and webapps directory. If you find the following jars in those directories that your web applicaton can access, please remove them:


jmarvin.jar
appletlaunch.jar
marvin.jar
mspace.jar
sjars/*.jar
sjars/**.jar


If you would like to integrate Marvin applets into your web pages, copy the marvin directory (that you can find in the Marvin Applets package) to the same folder where your html pages are located.


In your web applicaton classpath, place only the jars that you can find in the "lib" subdirectory of the Marvin Beans package.


By the way, would you share me the info how you find out that Environment.getResourceAsStream returned with null and ZipInputStream got this null value?

User 44bb556150

09-01-2010 03:53:56

Thanks for the information.  You are correct, I was using the Marvin applets library files.  I switched to instead use the MarvinBeans library files (v5.2.6) and the code compiled and executed as expected. 


Unfortunately, it still does not seem to have solved the original issue of atom lone pair "decorations" getting clipped off.  In running the Windows application of MarvinSketch with MarvinBeans, it does seem to be scaling the images well to avoid the clipping.  When I try to do it through a custom application however, the images are still getting clipped.


Attached is another simple script I ran using MarvinBeans 5.2.6 library to demonstrate the problem, as well as the images that were generated by the script.


Per your other question, I traced the NullPointerException by using debug tools like JAD to trace the stack trace execution.

ChemAxon 7c2d26e5cf

14-01-2010 15:22:50

Thanks for the bug report. We will debug lone pair clipping issue.