Rendering multiple molecules with same MolPrinter instance

User 041aab2e15

15-12-2015 11:48:26

We were using Jchem version 6.1 for one of our product.  We ran into an issue with pdf generation
logic while trying to upgrade to Jchem version 15.3.30.  We use itext version 2.1.7 for pdf generation.  When attempting to render multiple molecules
with same Molprinter instance, we see a NullPointerException. We don’t see this
issue when we use Jchem version 6.1.  Creating a new Molprinter instance seem to the solve problem. Is
this an expected behavior or are we missing something?


 Attaching a sample code (MolPrinterTestUsingSameInstance.
java) that shows the problem.  The
following are instructions to execute the sample code.


Using JChem version 6.1


javac -cp
guava-15.0.jar:itext-rtf-2.1.7.jar:itext-2.1.7.jar:jchem-6.1.3.jar:rt.jar:.  MolPrinterTestUsingSameInstance.java


 java -cp
guava-15.0.jar:itext-rtf-2.1.7.jar:itext-2.1.7.jar:jchem-6.1.3.jar:rt.jar:.  MolPrinterTestUsingSameInstance


Ouptut: test.pdf has the structures rendered properly 


Using JChem version 15.3.30


javac -cp guava-15.0.jar:itext-rtf-2.1.7.jar:itext-2.1.7.jar:jchem-15.3.30.0.jar:rt.jar:.  MolPrinterTestUsingSameInstance.java


java -cp
guava-15.0.jar:itext-rtf-2.1.7.jar:itext-2.1.7.jar:jchem-15.3.30.0.jar:rt.jar:.  MolPrinterTestUsingSameInstance


Output:


              java.lang.NullPointerException


                at
com.lowagie.text.pdf.PdfGraphics2D.getFontMetrics(Unknown Source)


                at
chemaxon.marvin.paint.internal.util.FontUtil.getFontMetrics(FontUtil.java:27)


                at
chemaxon.marvin.paint.internal.fontsettings.AbstractFontSettings.getHeight(AbstractFontSettings.java:198)


                at
chemaxon.marvin.paint.internal.AbstractTeXGraphics.getTextBounds(AbstractTeXGraphics.java:144)


             …


                at
chemaxon.marvin.paint.internal.MolPainter.setBoundsFor(MolPainter.java:2365)


 


                at
chemaxon.marvin.MolPrinter.setMol(MolPrinter.java:1319)

ChemAxon f052bdfe3c

18-12-2015 09:44:28

We cannot reproduce this bug with the code you sent in the current (15.12.14) version. Could you confirm it please and update?


Best regards,


Efi 

User 041aab2e15

21-12-2015 12:32:08

The issue is indeed not reproducible with 15.12.14 version. Can you please provide the release version where the issue is fixed? Also, please suggest if its reasonable to create a new MolPrinter instance for rendering each molecule.


 


Thanks,
Suman 

ChemAxon 5433b8e56b

21-12-2015 14:22:26

Hi Suman,


we did not have a particular case like this to fix, however after trying out your code against the 15.3.30 API version, the exception ringed a bell, but I was not able to find a particular fix version, and issue to connect the problem with.


What I am remember is that, it was a nasty issue, with multiple fix attempts, that lead to a bigger refactoring in the codebase, that we did around the end of the summer, and the beginning of autumn.


Regardless of this information, I would encourage you to change to the current most recent version, since that also contains some small drawing related fixes compared to the 15.10.24 which was suggested to you in an other thread regarding the IllegalArgumentException caused by too small letters.


To create a new MolPrinter instance for every image, is not necessary, however the creation cost is not high. Despite the easy instance creation it is allowed to use the same MolPrinter instance to print out more structures, and it should work fine.


I hope these information can help you, if you have further questions please do not hesitate to ask.


Regards,
Istvan