User bc3eb0a599
29-09-2011 15:43:47
Hi All,
I 'm trying to converter a Markush structure(in mol string format) to image(png) using chemaxon.formats.MolConvert. Please see the code example below. It seems that MolConverter only generates image for the base molecule, not the R-groups. Please see the attached input Markush mol file that I used. Thanks in advance for your help.
Tom
[email protected]
============ Example Codes =======================
/** Convert a structure in mol string format to a PNG image. **/
public byte [] convertStructureToImage(String structure)
{
byte [] converted = EMPTY_IMAGE;
try
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
MolConverter converter =
new MolConverter(new ByteArrayInputStream(structure.getBytes()), os,
imageOption_, false);
converted = os.toByteArray();
}
catch (MolFormatException e)
{
log.log(Level.WARNING, "Format conversion exception", e);
}
catch (IOException e)
{
log.log(Level.WARNING, "IO error", e);
}
return converted;
}
ChemAxon a202a732bf
30-09-2011 10:05:00
Hi Tom,
It seems that the problem is that the convert() method is not called. Please, add calling convert() and close() (see the code below).
Note, that the method convert() converts only the next structure in the input stream, if it contains more than one, then convert() should be called in a cycle until it returns false.
Best regards,
Zsuzsa
MolConverter converter = new MolConverter(
new ByteArrayInputStream(structure.getBytes()), os, imageOption_, false);
converter.convert();
converter.close();
converted = os.toByteArray();
User bc3eb0a599
30-09-2011 13:48:09
Hi Zsuzsa,
Not calling convert() is a cut and paste error. I tested it again after incorporating your suggestion. However, it still only gives me the base structure. The updated codes is listed below. I also attached a file with images that explains the output. Thanks again.
Tom
=========== sample codes ==================
public byte [] convertStructureToImage(String structure)
{
byte [] converted = EMPTY_IMAGE;
try
{
ByteArrayOutputStream os = new ByteArrayOutputStream();
MolConverter converter =
new MolConverter(new ByteArrayInputStream(structure.getBytes()), os,
imageOption_, false);
while (converter.convert())
{
}
converted = os.toByteArray();
converter.close();
}
catch (MolFormatException e)
{
log.log(Level.WARNING, "Format conversion exception", e);
}
catch (IOException e)
{
log.log(Level.WARNING, "IO error", e);
}
return converted;
}
ChemAxon a202a732bf
03-10-2011 11:45:16
Hi Tom,
I could not reproduce the problem. When I tried a similar code (see below), the R-groups were in the generated picture (attached). Could you provide more information, please:
- which version are you using?
- what is the value of imageOption_?
Thank you in advance,
Zsuzsa
FileInputStream fis = new FileInputStream("in/markushV3000.mol");
byte[] structure = new byte[10000];
fis.read(structure);
structure = java.util.Arrays.copyOf(structure, structure.length);
ByteArrayInputStream bis = new ByteArrayInputStream(structure);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
MolConverter converter = new MolConverter(bis, bos, "png", false);
while (converter.convert()) {}
byte[] converted = bos.toByteArray();
converter.close();
FileOutputStream fos = new FileOutputStream("out/markushV3000.png");
fos.write(converted);
fos.close();
User bc3eb0a599
03-10-2011 14:56:12
Hi Zsuzsa,
I'm using Marvin 5.0.1 and the imageOption_ is "png".
I tried your codes and I still got the wrong image!
I also tried running Marvin's command line utility "molconvert" (see below) and got the wrong incomplete image also.
C:\Program Files\ChemAxon\MarvinBeans\bin\molconvert "png" c:/Users/tomt/Documents/structureFiles/markushV3000.mol -o nice.png
I'm starting to think it 's either (1) I need to set some property(i.e. setting output to V3000 format ) in a properties file before calling molconverter or (2) Version 5.0.1 does not work and you have a different version.
Please advise. Thanks.
Tom
ChemAxon a202a732bf
04-10-2011 09:53:32
Hi Tom,
I have checked version 5.0.01. You are correct, the R-groups are not there on the image if using this version. This issue has been solved since then, if you download our latest version 5.6, using that you shouldn't have this problem any more.
Best regards,
Zsuzsa
User bc3eb0a599
05-10-2011 13:47:44
Hi Zsuzsa,
Thanks for finding this out for me.
I'm going to try it with the new version. What was the version that fixed this problem? I need to know this so that I can tell my customers what is the minimum required for this to work.
Tom
User bc3eb0a599
05-10-2011 14:42:39
Hi Zsuzsa,
The test with new version was successful. I have another question in addition to my last post.
I use MViewPane for rendering, MSketchPane for invoking the sketcher and MolConverter for converting mol file strings to images. I used to include just a couple jar files, MarvinBeans.jar and forms-1.1.0.jar, in my project. Now, I noticed that many classes have been refactored and repackaged into different jars. I had a difficult time trying to figue out what jar files to include and was unsuccessful in doing so. Finally, I just included every jar files in the Marvin installation. Although this works. But I think I've included a whole bunch of jar files that are not needed. Can you please tell what files I need to include? Thanks again.
Tom
ChemAxon a202a732bf
05-10-2011 20:03:25
Hi Tom,
I could find out the answer to your first question: this bug was fixed in version 5.0.3. Regarding your second question I will get back to you later.
Best regards,
Zsuzsa
ChemAxon a202a732bf
06-10-2011 09:44:24