displaying molecule images by URI

User 870ab5b546

13-09-2013 13:23:28

While playing around with Marvin for JavaScript, I learned that one can display a molecule's image by setting the src parameter of an img object to a variable whose value is a URI generated by Marvin for JavaScript.  Is there a comparable method in the MarvinSketch API that I can use to generate a URI?  I am trying to get away from using MarvinView (applet problems caused by recent updates to Java), but I would also like to avoid writing images to disk (need to change the image file when the molecule changes, and sometimes need to refresh the browser). I didn't find anything in the API that seemed like it would do the trick.

ChemAxon 2c555f5717

13-09-2013 14:02:23

Dear Bob!


   The best I can suggest you is to generate an svg image that can be embed to html pages directly. For this you should use the headless parameter. We currently do not have other solution, but I agree we should. :)


Regards:
Balázs 

User 870ab5b546

13-09-2013 15:13:02

But the SVG is binary and needs to be written directly to a file, right?  I would like a format that has a text value that I can assign to a Javascript variable or write out in a JSP page.  W3Schools gives this example of SVG code embedded directly into HTML:


<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <circle cx="100" cy="50" r="40" stroke="black"
  stroke-width="2" fill="red"/>
</svg>

ChemAxon 2c555f5717

16-09-2013 08:00:36

Dear Bob!


   Sorry I forgot that (currently) binary formats can only be requested through API or webservices. However this parameter is used by other costumers to generate svg sources that can be directly embed to HTML. Currently we do not have other solution for this. I will suggest this feature to our PO.


Regards:
Balázs 

User 870ab5b546

16-09-2013 13:33:37

I don't suppose you can ask your customers to post an example of code that does this, or at least to point me to a Java library that has a method that could convert the binary SVG file into embeddable HTML?

ChemAxon 2c555f5717

16-09-2013 21:18:44

Dear Bob!


   This Java code (since Marvin 6.0.1) generates a directly embedable svg image:


public String toSVG(String source) throws IOException {
Molecule mol = MolImporter.importMol(source);
Cleaner.clean(mol, 2, null);
byte[] bytes = MolExporter.exportToBinFormat(mol, "svg:headless");
return new String(bytes);
}

Regards:
Balázs 


 

User 870ab5b546

17-09-2013 13:36:22

Thanks, that works great!  Found a minor bug, though: Here is the same SMILES string ([H][C-]([H])([H])([N+])Br rendered by MolExporter into SVG and PNG formats.  (The SVG image was generated by JChem 6.1.0; the PNG image by JChem 5.11.5.)  Note the incorrect ? in the SVG image where a – sign is correctly present in the PNG image.  The SVG code is below.


I just noticed another difference between the two, the rendering of the H atoms around N.  Here JChem 6.1.0 is an improvement over 5.11.5.  


<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" width="113" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" height="116" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto">
<!--Generated by Marvin with Batik SVG Generator
MolSource:
<?xml version="1.0" encoding="UTF-8"?><cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.1.0">
<MDocument><MChemicalStruct><molecule molID="m1"><atomArray atomID="a1 a2 a3 a4 a5 a6" elementType="H C H H N Br" formalCharge="0 -1 0 0 1 0" x2="3.08 1.54 2.3099999999999996 0.7699999999999998 2.3099999999999996 0.0" y2="-1.885956070686924E-16 0.0 1.3336791218280357 1.3336791218280355 -1.3336791218280357 0.0"></atomArray><bondArray><bond id="b1" atomRefs2="a1 a2" order="1"></bond><bond id="b2" atomRefs2="a2 a3" order="1"></bond><bond id="b3" atomRefs2="a2 a4" order="1"></bond><bond id="b4" atomRefs2="a2 a5" order="1"></bond><bond id="b5" atomRefs2="a2 a6" order="1"></bond></bondArray></molecule></MChemicalStruct></MDocument>
</cml>-->
<defs id="genericDefs" />
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L113 0 L113 116 L0 116 L0 0 Z" />
</clipPath>
</defs>
<g font-size="15" stroke-linecap="round" fill="rgb(51,51,51)" text-rendering="optimizeLegibility" font-family="sans-serif" stroke-linejoin="bevel" shape-rendering="geometricPrecision" stroke="rgb(51,51,51)" stroke-width="1.5080628395080566">
<line clip-path="url(#clipPath1)" fill="none" x1="82.88826582549878" x2="74.64388038105523" y1="49.40587041280984" y2="49.40587041280983" />
<line clip-path="url(#clipPath1)" fill="none" x1="74.64388038105523" x2="66.39949493661167" y1="49.40587041280983" y2="49.405870412809826" stroke="black" />
<line clip-path="url(#clipPath1)" fill="none" x1="61.44974746830582" x2="65.5719401905276" y1="40.8326563130687" y2="33.69280907958992" stroke="black" />
<line clip-path="url(#clipPath1)" fill="none" x1="65.5719401905276" x2="69.69413291274938" y1="33.69280907958992" y2="26.55296184611114" />
<line clip-path="url(#clipPath1)" fill="none" x1="51.55025253169416" x2="47.42805980947238" y1="40.83265631306871" y2="33.69280907958993" stroke="black" />
<line clip-path="url(#clipPath1)" fill="none" x1="47.42805980947238" x2="43.3058670872506" y1="33.69280907958993" y2="26.552961846111145" />
<line clip-path="url(#clipPath1)" fill="none" x1="61.44974746830582" x2="65.5719401905276" y1="57.979084512550955" y2="65.11893174602974" stroke="black" />
<line clip-path="url(#clipPath1)" fill="none" x1="65.5719401905276" x2="69.69413291274938" y1="65.11893174602974" y2="72.25877897950853" stroke="rgb(51,51,153)" />
<line clip-path="url(#clipPath1)" fill="none" x1="46.600505063388326" x2="38.35611961894477" y1="49.40587041280983" y2="49.40587041280983" stroke="black" />
<line clip-path="url(#clipPath1)" fill="none" x1="38.35611961894477" x2="30.11173417450121" y1="49.40587041280983" y2="49.40587041280983" stroke="rgb(102,51,51)" />
</g>
<g font-size="15" fill="white" text-rendering="optimizeLegibility" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="white">
<rect x="87" y="41" clip-path="url(#clipPath1)" width="12" rx="4" ry="5" height="18" stroke="none" />
<text x="87" y="55" clip-path="url(#clipPath1)" fill="rgb(51,51,51)" stroke="none" xml:space="preserve">H
</text>
<rect x="51" y="41" clip-path="url(#clipPath1)" width="11" rx="3.5" ry="5" height="18" stroke="none" />
<text x="51" y="55" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">C
</text>
</g>
<g font-size="15" stroke-linecap="round" fill="red" text-rendering="optimizeLegibility" font-family="sans-serif" stroke-linejoin="bevel" shape-rendering="geometricPrecision" stroke="red" stroke-width="1.5080628395080566">
<line clip-path="url(#clipPath1)" fill="none" x1="51" x2="61" y1="56" y2="56" />
</g>
<g text-rendering="optimizeLegibility" font-size="11" shape-rendering="geometricPrecision" font-family="sans-serif">
<text xml:space="preserve" x="65" y="48" clip-path="url(#clipPath1)" stroke="none">?
</text>
<rect font-size="15" x="69" y="10" clip-path="url(#clipPath1)" fill="white" width="12" rx="4" ry="5" height="18" stroke="none" />
<text font-size="15" x="69" y="24" clip-path="url(#clipPath1)" fill="rgb(51,51,51)" stroke="none" xml:space="preserve">H
</text>
<rect font-size="15" x="33" y="10" clip-path="url(#clipPath1)" fill="white" width="12" rx="4" ry="5" height="18" stroke="none" />
<text font-size="15" x="33" y="24" clip-path="url(#clipPath1)" fill="rgb(51,51,51)" stroke="none" xml:space="preserve">H
</text>
<rect font-size="15" x="69" y="73" clip-path="url(#clipPath1)" fill="white" width="24" rx="8" ry="5" height="18" stroke="none" />
<rect font-size="15" x="91" y="81" clip-path="url(#clipPath1)" fill="white" width="7" rx="2.5" ry="4" height="14" stroke="none" />
<text font-size="15" x="69" y="87" clip-path="url(#clipPath1)" fill="rgb(51,51,153)" stroke="none" xml:space="preserve">NH
</text>
<text x="91" y="92" clip-path="url(#clipPath1)" fill="rgb(51,51,153)" stroke="none" xml:space="preserve">3
</text>
<text x="81" y="75" clip-path="url(#clipPath1)" fill="rgb(51,51,153)" stroke="none" xml:space="preserve">+
</text>
<rect x="12" y="41" clip-path="url(#clipPath1)" fill="white" width="17" rx="6" ry="5" height="18" stroke="none" />
<text font-size="15" x="12" y="55" clip-path="url(#clipPath1)" fill="rgb(102,51,51)" stroke="none" xml:space="preserve">Br
</text>
</g>
</g>
</svg>

User 870ab5b546

17-09-2013 13:43:14

Here's another example of the SVG not rendering properly.  This time, bullets are rendered as ?.


<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" width="147" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" height="68" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto">
<!--Generated by Marvin with Batik SVG Generator
MolSource:
<?xml version="1.0" encoding="UTF-8"?><cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.1.0">
<MDocument atomSetFont="0:SansSerif-PLAIN-12"><MChemicalStruct><molecule molID="m1"><atomArray atomID="a1 a2" elementType="C O" x2="8.933333333333334 11.11111111111111" y2="0.08888888888888889 0.13333333333333333"></atomArray><bondArray><bond id="b1" atomRefs2="a1 a2" order="3"></bond></bondArray></molecule></MChemicalStruct><MTextBox id="o2" fontScale="10.0" halign="LEFT" valign="TOP" autoSize="false"><Field name="text"><![CDATA[ \\u2022 ]]></Field><MPoint x="7.894444444444444" y="0.6499999999999999"></MPoint><MPoint x="9.894444444444444" y="0.6499999999999999"></MPoint><MPoint x="9.894444444444444" y="-1.35"></MPoint><MPoint x="7.894444444444444" y="-1.35"></MPoint></MTextBox><MTextBox id="o3" fontScale="10.0" halign="LEFT" valign="TOP" autoSize="false"><Field name="text"><![CDATA[ \\u2022 ]]></Field><MPoint x="7.894444444444444" y="0.3833333333333333"></MPoint><MPoint x="9.894444444444444" y="0.3833333333333333"></MPoint><MPoint x="9.894444444444444" y="-1.6166666666666667"></MPoint><MPoint x="7.894444444444444" y="-1.6166666666666667"></MPoint></MTextBox><MTextBox id="o4" fontScale="10.0" halign="LEFT" valign="TOP" autoSize="false"><Field name="text"><![CDATA[ \\u2022 ]]></Field><MPoint x="11.405555555555555" y="0.6944444444444444"></MPoint><MPoint x="13.405555555555555" y="0.6944444444444444"></MPoint><MPoint x="13.405555555555555" y="-1.3055555555555556"></MPoint><MPoint x="11.405555555555555" y="-1.3055555555555556"></MPoint></MTextBox><MTextBox id="o5" fontScale="10.0" halign="LEFT" valign="TOP" autoSize="false"><Field name="text"><![CDATA[ \\u2022 ]]></Field><MPoint x="11.405555555555555" y="0.4277777777777778"></MPoint><MPoint x="13.405555555555555" y="0.4277777777777778"></MPoint><MPoint x="13.405555555555555" y="-1.5722222222222222"></MPoint><MPoint x="11.405555555555555" y="-1.5722222222222222"></MPoint></MTextBox></MDocument>
</cml>-->
<defs id="genericDefs" />
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L147 0 L147 68 L0 68 L0 0 Z" />
</clipPath>
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath2">
<path d="M1.130810260772705 4.3439130783081055 L34.608150482177734 4.3439130783081055 L34.608150482177734 38.44120407104492 L1.130810260772705 38.44120407104492 L1.130810260772705 4.3439130783081055 Z" />
</clipPath>
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath3">
<path d="M1.130810260772705 11.337383270263672 L34.608150482177734 11.337383270263672 L34.608150482177734 45.43467330932617 L1.130810260772705 45.43467330932617 L1.130810260772705 11.337383270263672 Z" />
</clipPath>
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath4">
<path d="M93.10818481445312 3.2816596031188965 L126.58552551269531 3.2816596031188965 L126.58552551269531 37.37894821166992 L93.10818481445312 37.37894821166992 L93.10818481445312 3.2816596031188965 Z" />
</clipPath>
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath5">
<path d="M93.10818481445312 10.275130271911621 L126.58552551269531 10.275130271911621 L126.58552551269531 44.37242126464844 L93.10818481445312 44.37242126464844 L93.10818481445312 10.275130271911621 Z" />
</clipPath>
</defs>
<g font-size="16" stroke-linecap="round" text-rendering="optimizeLegibility" font-family="sans-serif" stroke-linejoin="bevel" shape-rendering="geometricPrecision" stroke-width="1.6758768558502197">
<line clip-path="url(#clipPath1)" fill="none" x1="39.152489573552884" x2="57.06127780856619" y1="19.381517458983247" y2="19.0160319847993" />
<line clip-path="url(#clipPath1)" fill="none" x1="39.00438487309156" x2="56.91317310810487" y1="12.124387136378484" y2="11.758901662194539" />
<line clip-path="url(#clipPath1)" fill="none" x1="39.30059427401421" x2="57.209382509027506" y1="26.63864778158801" y2="26.273162307404064" />
<line clip-path="url(#clipPath1)" fill="none" x1="57.06127780856619" x2="74.9700660435795" y1="19.0160319847993" y2="18.650546510615357" stroke="red" />
<line clip-path="url(#clipPath1)" fill="none" x1="56.91317310810487" x2="74.82196134311818" y1="11.758901662194539" y2="11.393416188010594" stroke="red" />
<line clip-path="url(#clipPath1)" fill="none" x1="57.209382509027506" x2="75.11817074404081" y1="26.273162307404064" y2="25.90767683322012" stroke="red" />
</g>
<g font-size="16" fill="white" text-rendering="optimizeLegibility" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="white">
<rect x="23" y="11" clip-path="url(#clipPath1)" width="12" rx="4" ry="5.5" height="19" stroke="none" />
<text x="23" y="26" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">C
</text>
<rect x="79" y="10" clip-path="url(#clipPath1)" width="14" rx="4.5" ry="5.5" height="19" stroke="none" />
<text x="79" y="25" clip-path="url(#clipPath1)" fill="red" stroke="none" xml:space="preserve">O
</text>
</g>
<g text-rendering="optimizeLegibility" font-size="10" shape-rendering="geometricPrecision" font-family="sans-serif" transform="matrix(1.6130314306072362,0,0,1.6130314306072362,-0.8240324712662908,-3.0068679638857345)">
<text xml:space="preserve" x="1.3441928625106812" y="14.904916763305664" clip-path="url(#clipPath2)" stroke="none"> ?
</text>
</g>
<g text-rendering="optimizeLegibility" font-size="10" shape-rendering="geometricPrecision" font-family="sans-serif" transform="matrix(1.6130314306072362,0,0,1.6130314306072362,-0.8240324712662908,-7.287556126308205)">
<text xml:space="preserve" x="1.3441928625106812" y="21.887737274169922" clip-path="url(#clipPath3)" stroke="none"> ?
</text>
</g>
<g text-rendering="optimizeLegibility" font-size="10" shape-rendering="geometricPrecision" font-family="sans-serif" transform="matrix(1.6130314306072362,0,0,1.6130314306072362,-57.18642660982883,-2.2934199368153223)">
<text xml:space="preserve" x="93.28466033935547" y="13.74111270904541" clip-path="url(#clipPath4)" stroke="none"> ?
</text>
</g>
<g text-rendering="optimizeLegibility" font-size="10" shape-rendering="geometricPrecision" font-family="sans-serif" transform="matrix(1.6130314306072362,0,0,1.6130314306072362,-57.18642660982883,-6.57410809923779)">
<text xml:space="preserve" x="93.28466033935547" y="20.72393226623535" clip-path="url(#clipPath5)" stroke="none"> ?
</text>
</g>
</g>
</svg>

User 870ab5b546

17-09-2013 17:10:51

The lp (lone pairs) parameter also does not appear to be working when SVG images are generated.  See the options in the first line and compare the image.


INFO: MolString.getImageXML: generated image XML with options svg:headless,w85,h54,valenceErrorVisible,H_all,cv_on,lp; isLewis = false
Image XML:
<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" width="85" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" height="54" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto">
<!--Generated by Marvin with Batik SVG Generator
MolSource:
<?xml version="1.0" encoding="UTF-8"?><cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.1.0">
<MDocument><MChemicalStruct><molecule molID="m1"><atomArray atomID="a1 a2 a3" elementType="O H H" x2="-2.117500066757202 -3.4511791885852374 -0.7838209449291667" y2="1.0106250047683716 0.240625004768371 0.24062500476837168"></atomArray><bondArray><bond id="b1" atomRefs2="a1 a2" order="1"></bond><bond id="b2" atomRefs2="a1 a3" order="1"></bond></bondArray></molecule></MChemicalStruct></MDocument>
</cml>-->
<defs id="genericDefs" />
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L85 0 L85 54 L0 54 L0 0 Z" />
</clipPath>
</defs>
<g font-size="13" stroke-linecap="round" fill="red" text-rendering="optimizeLegibility" font-family="sans-serif" stroke-linejoin="bevel" shape-rendering="geometricPrecision" stroke="red" stroke-width="1.3681106567382812">
<line clip-path="url(#clipPath1)" fill="none" x1="34.539158335954674" x2="28.245151599598003" y1="25.67603183279494" y2="29.30987831631179" />
<line clip-path="url(#clipPath1)" fill="none" x1="28.245151599598003" x2="21.951144863241332" y1="29.30987831631179" y2="32.94372479982864" stroke="rgb(51,51,51)" />
<line clip-path="url(#clipPath1)" fill="none" x1="50.46084166404533" x2="56.754848400402" y1="25.67603183279494" y2="29.30987831631178" />
<line clip-path="url(#clipPath1)" fill="none" x1="56.754848400402" x2="63.04885513675866" y1="29.30987831631178" y2="32.94372479982862" stroke="rgb(51,51,51)" />
</g>
<g font-size="13" fill="white" text-rendering="optimizeLegibility" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="white">
<rect x="38" y="13" clip-path="url(#clipPath1)" width="11" rx="3.5" ry="4.5" height="16" stroke="none" />
<text x="38" y="26" clip-path="url(#clipPath1)" fill="red" stroke="none" xml:space="preserve">O
</text>
<rect x="9" y="30" clip-path="url(#clipPath1)" width="11" rx="3.5" ry="4.5" height="16" stroke="none" />
<text x="9" y="43" clip-path="url(#clipPath1)" fill="rgb(51,51,51)" stroke="none" xml:space="preserve">H
</text>
<rect x="66" y="30" clip-path="url(#clipPath1)" width="11" rx="3.5" ry="4.5" height="16" stroke="none" />
<text x="66" y="43" clip-path="url(#clipPath1)" fill="rgb(51,51,51)" stroke="none" xml:space="preserve">H
</text>
</g>
</g>
</svg>

ChemAxon 2c555f5717

17-09-2013 19:13:28

Dear Bob!


   Give me a breath! If you want to explicitly embed pngs -- because they fit better to your idea -- it is possible you only need to base64 encode them.
    I have an idea about the negative charge sign: it is not a simple "-" sign its a "–" sign which is directly represented by a Unicode character. This exact character might be missing from your default font. (I could not reproduce it.)
   For the lone pairs did you use the lone pair visibility argument (lp) in your image generation string?
   By bullets  did you mean lone pairs?


Regards:
Balázs 

User 870ab5b546

17-09-2013 19:25:24

Hi Balazs,



  1. I don't care whether the images are SVG, PNG, or anything else.  I just want to embed an image directly into an HTML page without referring to a file on disk and without invoking an applet.  If it can be done with PNG, all the better.  But I haven't come across any examples of embedding PNG directly into an HTML file.

  2. Yes, the minus character is undoubtedly either a minus sign &minus; or an en dash &ndash;.  I really, really doubt I am missing the character from any of my fonts.  I think it is more likely that MolExporter's method for generating SVG XML doesn't recognize non-ASCII characters or doesn't render them properly.

  3. Yes, I used these options: 














    svg:headless,w85,h54,valenceErrorVisible,H_all,cv_on,lp




  4. By bullets I mean the character \u2022, which we use to represent electrons in Lewis structures.  We place the bullets in textboxes and arrange the textboxes around atoms.  We do this so that we can allow the user to display any number of unshared electrons, not just the eight that MarvinSketch allows.  You can see the entire MRV that we are converting to SVG in the comment section of the XML.


-- Bob


P.S.  Could the following snippet be messing up the display of non-ASCII characters?
















byte[] bytes = MolExporter.exportToBinFormat(mol, "svg:headless");
return new String(bytes);


User 870ab5b546

17-09-2013 23:54:14

I figured it out.  The problem was indeed with converting the byte[] to a String.  It needs to be done specifying the UTF-8 character set, and then the Unicode-containing String needs to have its Unicode characters converted to character entity references.  Here's code that works:


	/** Converts non-ASCII UCS-2 characters in a string into the 
* corresponding character entity references.
* @return string with only ASCII characters and CERs
*/
String unicodeToCERs(String s) {
if (s == null) return s;
final StringBuilder bld = new StringBuilder(s.length());
for (char theChar : s.toCharArray()) {
if (theChar >= 128) {
bld.append("&#").append((int) theChar).append(';');
} else bld.append(theChar);
} // for each character
return bld.toString();
} // unicodeToCERs()

final byte[] imageBytes = MolExporter.exportToBinFormat(mol, opts);
imageXML = unicodeToCERs(new String(imageBytes, "UTF-8"));

User 870ab5b546

18-09-2013 15:43:11

I spoke too soon.  I solved the problem of the minus sign and the bullets not appearing.  However, the lone pair parameter lp is still not generating an image with lone pairs visible.  The options used to generate the given image were svg:headless,w104,h107,valenceErrorVisible,H_heteroterm,cv_inChain,lp.  The XML of the image is below.  Note that there are no empty <text> elements that would suggest that the lone pairs are being generated by MolExporter but are invisible for some reason.  


<svg fill-opacity="1" xmlns:xlink="http://www.w3.org/1999/xlink" color-rendering="auto" color-interpolation="auto" stroke="black" text-rendering="auto" stroke-linecap="square" width="104" stroke-miterlimit="10" stroke-opacity="1" shape-rendering="auto" fill="black" stroke-dasharray="none" font-weight="normal" stroke-width="1" height="107" xmlns="http://www.w3.org/2000/svg" font-family="&apos;Dialog&apos;" font-style="normal" stroke-linejoin="miter" font-size="12" stroke-dashoffset="0" image-rendering="auto">
<!--Generated by Marvin with Batik SVG Generator
MolSource:
<?xml version="1.0" encoding="UTF-8"?><cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.1.0">
<MDocument><MChemicalStruct><molecule molID="m1"><atomArray atomID="a1 a2 a3" elementType="C C O" formalCharge="0 1 -1" x2="-5.486249923706055 -4.152570801878019 -4.152570801878019" y2="-0.1443749964237213 0.6256250035762786 2.1656250035762787"></atomArray><bondArray><bond id="b1" atomRefs2="a1 a2" order="1"></bond><bond id="b2" atomRefs2="a2 a3" order="1"></bond></bondArray></molecule></MChemicalStruct></MDocument>
</cml>-->
<defs id="genericDefs" />
<g>
<defs id="defs1">
<clipPath clipPathUnits="userSpaceOnUse" id="clipPath1">
<path d="M0 0 L104 0 L104 107 L0 107 L0 0 Z" />
</clipPath>
</defs>
<g font-size="16" stroke-linecap="round" text-rendering="optimizeLegibility" font-family="sans-serif" stroke-linejoin="bevel" shape-rendering="geometricPrecision" stroke-width="1.6797657012939453">
<line clip-path="url(#clipPath1)" fill="none" x1="36.13182870549277" x2="52.764851018312804" y1="81.34728934075116" y2="71.74420943100748" />
<line clip-path="url(#clipPath1)" fill="none" x1="61.95043755374972" x2="61.95043755374972" y1="55.83430685431016" y2="46.231226944566465" />
<line clip-path="url(#clipPath1)" fill="none" x1="61.95043755374972" x2="61.95043755374972" y1="46.231226944566465" y2="36.628147034822774" stroke="red" />
</g>
<g font-size="16" fill="white" text-rendering="optimizeLegibility" font-family="sans-serif" shape-rendering="geometricPrecision" stroke="white">
<rect x="1" y="78" clip-path="url(#clipPath1)" width="13" rx="4.5" ry="5.5" height="19" stroke="none" />
<rect x="13" y="87" clip-path="url(#clipPath1)" width="8" rx="3" ry="4.5" height="15" stroke="none" />
<rect x="21" y="78" clip-path="url(#clipPath1)" width="12" rx="4" ry="5.5" height="19" stroke="none" />
<text x="1" y="93" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">H
</text>
<text font-size="12" x="13" y="99" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">3
</text>
<text x="21" y="93" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">C
</text>
<rect x="56" y="58" clip-path="url(#clipPath1)" width="25" rx="8.5" ry="5.5" height="19" stroke="none" />
<text x="56" y="73" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">CH
</text>
<text font-size="12" x="69" y="60" clip-path="url(#clipPath1)" fill="black" stroke="none" xml:space="preserve">+
</text>
<rect x="55" y="18" clip-path="url(#clipPath1)" width="14" rx="4.5" ry="5.5" height="19" stroke="none" />
<text x="55" y="33" clip-path="url(#clipPath1)" fill="red" stroke="none" xml:space="preserve">O
</text>
<text font-size="12" x="69" y="19" clip-path="url(#clipPath1)" fill="red" stroke="none" xml:space="preserve">&#8211;
</text>
</g>
</g>
</svg>

ChemAxon 2c555f5717

18-09-2013 18:23:38

Dear Bob!


   Direct image embedding happens like this:



<img src="data:image/png;base64,*hear comes the source of your png base64 encoded*" />


  I will keep working on this lone-pair issue.


 


Regards:
Balázs 

User 870ab5b546

19-09-2013 14:10:32

I was able to embed the PNG with the base64 URI.  Two problems, though:



  1. The lp parameter still doesn't work.

  2. If I use AJAX to generate the entire <img> tag for a new figure and assign its value to a Javascript variable, then use document.getElementById().innerHTML to update the page, I always get a ? instead of the figure (using Safari 6.0 or Chrome on Mac).  I don't have this problem with the SVG.  

  3. If I use AJAX to generate the URI for a new figure and assign its value to a Javascript variable, then use document.getElementById().src to update the image, I sometimes (but not always) get a ? instead of the figure.  


So it appears that the PNG URI method has no advantages over the SVG XML method, and instead has a significant disadvantage.

User 870ab5b546

25-09-2013 13:47:08

Any progress on the lone pairs display issue in exported SVG and PNG images?

ChemAxon 2c555f5717

25-09-2013 15:03:38

Dear Bob!


   Sorry for the late answer, the problem is that: from Marvin 6.1 we have replaced lone pairs (which only were dots on the canvas) to be objects (that is why you can select them). Unfortunately these objects should be generated in the MDocument, or will not be painted. In the first round of painting they are generated, and painted in the second round. We did not know about it since your bug report. 


   If you ensure that the molecule have an MDocument than the following code can help:


MolExporter.exportToBinFormat(mol, "svg:lp"); // The first call only generates the lone pairs.
MolExporter.exportToBinFormat(mol, "svg:lp"); // The second call will paint the lone pairs.

 


You can ensure the molecule (prior the painting) by this call:


new MDocument(mol);

   I have made a task abut this bug. Sorry for the inconvenience!


Regards:
Balázs 

User 870ab5b546

25-09-2013 17:22:50

Well, that got the lone pairs to appear, but now graphical arrows are disappearing.  The MRV:


<?xml version="1.0" ?>
<cml>
<MDocument>
<MPolyline id="o1" headLength="0.8" headWidth="0.5">
<MPoint x="-5.891666889190674" y="2.0416667461395264" />
<MPoint x="-2.158333420753479" y="2.0999999046325684" />
</MPolyline>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18"
elementType="C C C C O C O C O H C C C C O C O C"
formalCharge="0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0"
x2="-11.756376898726481 -11.756376898726481 -10.422707557678223 -9.089038216629964 -10.422707557678223 -9.089038216629964 -7.837788426438314 -4.968542098999023 -3.4285420989990234 -4.375 -0.6491935326265814 -0.6491935326265814 0.6844758084216771 2.0181451494699356 0.6844758084216771 2.0181451494699356 3.3175199682718155 4.8575199682718155"
y2="2.461683662856709 0.921649781738628 0.15163284117958753 0.921649781738628 3.2317006034157494 2.461683662856709 3.183558653319966 3.043541669845581 3.043541669845581 1.0602083802223206 2.423347869707083 0.883313988589002 0.11329704802996154 0.883313988589002 3.1933648102661234 2.423347869707083 3.241472917390798 3.241472917390798"
/>
<bondArray>
<bond atomRefs2="a5 a1" order="1" />
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a2 a3" order="1" />
<bond atomRefs2="a3 a4" order="1" />
<bond atomRefs2="a4 a6" order="1" />
<bond atomRefs2="a5 a6" order="1" />
<bond atomRefs2="a6 a7" order="1" />
<bond atomRefs2="a8 a9" order="1" />
<bond atomRefs2="a15 a11" order="1" />
<bond atomRefs2="a11 a12" order="1" />
<bond atomRefs2="a12 a13" order="1" />
<bond atomRefs2="a13 a14" order="1" />
<bond atomRefs2="a14 a16" order="1" />
<bond atomRefs2="a15 a16" order="1" />
<bond atomRefs2="a16 a17" order="1" />
<bond atomRefs2="a17 a18" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

PNG image (generated through inline URI) is shown below.

User 870ab5b546

25-09-2013 20:29:27


OK, I got it to work with some modification:


final MDocument mDoc = mol.getDocument();
MolExporter.exportToBinFormat(mDoc, "svg:lp");
final byte[] bytes = MolExporter.exportToBinFormat(mDoc, "svg:lp");

Thanks for your help, and I'm looking forward to the fix that will make this workaround unnecessary.

User 870ab5b546

07-10-2013 03:06:41

Alas, I have found cases where this workaround falls down.  If a shortcut group is present in the figure, then neither lone pairs nor unpaired electrons (i.e., radicals) appear when I specify the lp parameter.


Also, if I do not specify the lp parameter, then unpaired electrons (i.e., radicals) do not appear.  Unpaired electrons should always appear.


Please fix these bugs ASAP. 

ChemAxon 2c555f5717

07-10-2013 07:11:23

Dear Bob!


   Could you provide me an example molecule. (An mrv file would be the best.)


Regards:
Balázs 

User 870ab5b546

07-10-2013 13:26:56

Here's one that doesn't display lone pairs or unshared electrons on either O or N.


<?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4"
elementType="O R N C"
radical="monovalent 0 0 0"
sgroupRef="0 sg1 0 0"
x2="-1.3956249952316284 0.14437500476837162 -3.9462499618530273 -5.486249961853027"
y2="1.2512500286102295 1.2512500286102295 4.379374980926514 4.379374980926514"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a3 a4" order="1" />
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="Me" molID="m2">
<atomArray
atomID="a5"
elementType="C"
attachmentPoint="1"
sgroupAttachmentPoint="1"
x2="0.38499999046325684"
y2="1.8287500143051147"
/>
<bondArray>
</bondArray>
</molecule>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

Change the Me shortcut group to CH3, and all unshared electrons display fine.  But remove the lp parameter, and the O atom's unshared electron does not display, as it should even when lone pair display is turned off.  I see the same behavior for both SVG XML and PNG URIs.  Options are typically:

png:w187,h128,valenceErrorVisible,H_heteroterm,cv_inChain,lp

or:

svg:headless,w201,h128,valenceErrorVisible,H_heteroterm,cv_inChain

Either may or may not have the lp parameter at the end.

ChemAxon 2c555f5717

17-10-2013 09:58:38

Dear Bob!


   I could not find the route cause of this bug yet, and I can not give you a comfortable solution. MarvinSketch does generate these electrons, but I do not know why does image export leave them out. Here you can find an Mdocument that has the Radical electron, but do not have the lonepairs:


<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.2.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray atomID="a1 a2 a3 a4" elementType="O R N C" radical="monovalent 0 0 0" sgroupRef="0 sg1 0 0" x2="-1.3956249952316284 0.14437500476837162 -3.9462499618530273 -5.486249961853027" y2="1.2512500286102295 1.2512500286102295 4.379374980926514 4.379374980926514"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a3 a4" order="1"/>
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="Me" molID="m2">
<atomArray atomID="a5" elementType="C" attachmentPoint="1" sgroupAttachmentPoint="1" x2="0.38499999046325684" y2="1.8287500143051147"/>
<bondArray/>
<AttachmentPointArray>
<attachmentPoint atom="a5" order="1" bond="b1"/>
</AttachmentPointArray>
</molecule>
</molecule>
</MChemicalStruct>
<MElectronContainer id="o2" occupation="0" radical="1">
<MElectron atomRefs="m1.a1" difLoc="-0.6159999999999997 0.0 0.0"/>
</MElectronContainer>
</MDocument>
</cml>

And here is an other MDocument that has all the electrons:


<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/help/formats/schema/mrvSchema_6_1_0.xsd" version="ChemAxon file format v6.1, generated by v6.2.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray atomID="a1 a2 a3 a4" elementType="O R N C" radical="monovalent 0 0 0" sgroupRef="0 sg1 0 0" x2="-1.3956249952316284 0.14437500476837162 -3.9462499618530273 -5.486249961853027" y2="1.2512500286102295 1.2512500286102295 4.379374980926514 4.379374980926514"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a3 a4" order="1"/>
</bondArray>
<molecule id="sg1" role="SuperatomSgroup" title="Me" molID="m2">
<atomArray atomID="a5" elementType="C" attachmentPoint="1" sgroupAttachmentPoint="1" x2="0.38499999046325684" y2="1.8287500143051147"/>
<bondArray/>
<AttachmentPointArray>
<attachmentPoint atom="a5" order="1" bond="b1"/>
</AttachmentPointArray>
</molecule>
</molecule>
</MChemicalStruct>
<MElectronContainer id="o2" occupation="0" radical="1">
<MElectron atomRefs="m1.a1" difLoc="-0.6159999999999997 0.0 0.0"/>
</MElectronContainer>
<MElectronContainer id="o3" occupation="0 0" radical="0">
<MElectron atomRefs="m1.a1" difLoc="0.1594325317831533 0.5950103089940644 0.0"/>
<MElectron atomRefs="m1.a1" difLoc="-0.15943253178314976 0.5950103089940644 0.0"/>
</MElectronContainer>
<MElectronContainer id="o4" occupation="0 0" radical="0">
<MElectron atomRefs="m1.a1" difLoc="-0.15943253178314976 -0.5950103089940662 0.0"/>
<MElectron atomRefs="m1.a1" difLoc="0.1594325317831533 -0.5950103089940662 0.0"/>
</MElectronContainer>
<MElectronContainer id="o5" occupation="0 0" radical="0">
<MElectron atomRefs="m1.a3" difLoc="0.1594325317831533 0.5950103089940653 0.0"/>
<MElectron atomRefs="m1.a3" difLoc="-0.15943253178314976 0.5950103089940653 0.0"/>
</MElectronContainer>
</MDocument>
</cml>

   If I can find any further information I will inform you. How did you generate these sources?


Regards:
Balázs 

User 870ab5b546

17-10-2013 18:05:45










bzaicsek wrote:

   If I can find any further information I will inform you. How did you generate these sources?



I drew the structures in MarvinSketch, probably version 5.4.1.1.

ChemAxon f052bdfe3c

06-12-2013 14:26:49

I am happy to inform you that version 6.2 will contain the requested fixes.


Best Regards,


Efi

ChemAxon f052bdfe3c

31-01-2014 10:29:52

Sorry. 6.2.1 will contain the fix.


Best,


Efi