image sizes

User 870ab5b546

19-04-2012 02:33:29

Hello,


See the attached image.  The three figures differ in the size of the atom captions.  I want them all to be the same.  My code always sets the scale to 30, and it reports the atom size to be 0.4 in every case.  We're using the dimensions that we get from the MolPrinter to set the size of the MarvinView applet window.  We're using JChem 5.9 and MarvinView 5.4.


            final MolPrinter printer = new MolPrinter(mol);
printer.setRendering(WIREFRAME_RENDERING_S);
printer.setImplicitH(isLewis ? IMPLICITH_ALL_S : IMPLICITH_HETEROTERM_S);
printer.setScale(MAX_SCALE); // = 30
final Rectangle boundingRect =
printer.getBoundingRectangle(
mol.getDocument().getAllMolecules());
debugPrint(SELF + "for ", molStruct, "\nimage at scale ",
MAX_SCALE, " has width ", boundingRect.width,
" and height ", boundingRect.height, "; atom size is ",
printer.getAtomSize()); /**/


Here's the log:


ChemUtils.getBestAppletSize: for <?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28"
elementType="C H N N H H N H H H H C H O H H H C O C O C H H H H H H"
formalCharge="0 0 0 -1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0"
mrvAlias="C 0 0 0 0 0 0 0 0 0 0 C 0 0 0 0 0 C 0 C 0 C 0 0 0 0 0 0"
x2="-6.063750982284546 -7.603750982284545 -4.523750982284547 -6.689374923706055 -8.229374923706054 -5.149374923706055 -0.8181250095367432 -2.3581250095367423 0.7218749904632569 -0.818125009536743 -0.818125009536743 4.8125 3.272500000000001 6.3525 4.8125 4.8125 7.8925 2.1401576674991176 2.1401576674991176 0.6001576674991185 3.6801576674991185 5.220157667499119 -0.9398423325008807 0.6001576674991185 0.6001576674991185 5.220157667499119 6.760157667499119 5.220157667499119"
y2="-0.8181251883506775 -0.8181251883506775 -0.8181251883506775 4.331250190734863 4.331250190734863 4.331250190734863 4.331250190734863 4.331250190734863 4.331250190734863 2.7912501907348632 5.871250190734863 4.331250190734863 4.331250190734863 4.331250190734863 2.7912501907348632 5.871250190734863 4.331250190734863 -0.8822625248352696 0.6577374751647307 -0.8822625248352693 -0.8822625248352696 -0.8822625248352696 -0.8822625248352696 0.6577374751647307 -2.4222625248352694 0.6577374751647307 -0.8822625248352696 -2.4222625248352694"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a1 a3" order="3" />
<bond atomRefs2="a4 a5" order="1" />
<bond atomRefs2="a4 a6" order="1" />
<bond atomRefs2="a7 a8" order="1" />
<bond atomRefs2="a7 a9" order="1" />
<bond atomRefs2="a7 a10" order="1" />
<bond atomRefs2="a7 a11" order="1" />
<bond atomRefs2="a12 a13" order="1" />
<bond atomRefs2="a12 a14" order="1" />
<bond atomRefs2="a12 a15" order="1" />
<bond atomRefs2="a12 a16" order="1" />
<bond atomRefs2="a14 a17" order="1" />
<bond atomRefs2="a18 a19" order="2" />
<bond atomRefs2="a18 a20" order="1" />
<bond atomRefs2="a18 a21" order="1" />
<bond atomRefs2="a21 a22" order="1" />
<bond atomRefs2="a20 a23" order="1" />
<bond atomRefs2="a20 a24" order="1" />
<bond atomRefs2="a20 a25" order="1" />
<bond atomRefs2="a22 a26" order="1" />
<bond atomRefs2="a22 a27" order="1" />
<bond atomRefs2="a22 a28" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

image at scale 30 has width 326 and height 188; atom size is 0.4
ChemUtils.getBestAppletSize: for <?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11"
elementType="C N C H H H O N O O H"
formalCharge="0 1 -1 0 0 0 0 1 0 -1 0"
x2="-7.21875 -5.67875 -4.13875 -7.21875 -8.75875 -7.21875 0.33687499165534973 1.8768749916553498 2.6468749916553502 2.6468749916553502 -0.43312500834464995"
y2="1.2512500286102295 1.2512500286102295 1.2512500286102295 2.7912500286102295 1.2512500286102297 -0.28874997138977054 1.347499966621399 1.347499966621399 2.6811790884494346 0.01382084479336343 2.6811790884494346"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a2 a3" order="3" />
<bond atomRefs2="a1 a4" order="1" />
<bond atomRefs2="a1 a5" order="1" />
<bond atomRefs2="a1 a6" order="1" />
<bond atomRefs2="a7 a8" order="1" />
<bond atomRefs2="a8 a9" order="2" />
<bond atomRefs2="a8 a10" order="1" />
<bond atomRefs2="a7 a11" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

image at scale 30 has width 247 and height 88; atom size is 0.4
ChemUtils.getBestAppletSize: for <?xml version="1.0" ?>
<cml>
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray
atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10"
elementType="B F F F F Al H H H H"
formalCharge="-1 0 0 0 0 -1 0 0 0 0"
x2="-4.668125152587891 -5.757069595615174 -3.5791807095606076 -5.757069595615174 -3.5791807095606076 1.2512500286102295 0.16230558558294628 2.3401944716375125 0.16230558558294628 2.3401944716375125"
y2="0.9143750071525574 2.0033194501798404 2.0033194501798404 -0.17456943587472584 -0.17456943587472584 0.9624999761581421 2.051444419185425 2.051444419185425 -0.12644446686914113 -0.12644446686914113"
/>
<bondArray>
<bond atomRefs2="a1 a2" order="1" />
<bond atomRefs2="a1 a3" order="1" />
<bond atomRefs2="a1 a4" order="1" />
<bond atomRefs2="a1 a5" order="1" />
<bond atomRefs2="a6 a7" order="1" />
<bond atomRefs2="a6 a8" order="1" />
<bond atomRefs2="a6 a9" order="1" />
<bond atomRefs2="a6 a10" order="1" />
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>

image at scale 30 has width 169 and height 69; atom size is 0.4

Is there a way to set the atom size relative to an absolute scale?

ChemAxon 12eab24e0a

23-04-2012 08:25:43

Dear Bob!


We'll investigate the problem in the near future; it is not that simple as to answer it immediately. My first guess is that it is a bug, but I have to deal with it. I think your code should work properly, it's correct. I'll be back soon with this problem, at the moment we've got new features to finish in a very short term.


Thank you for your patience!


Best Regards,


Eva

ChemAxon 12eab24e0a

08-05-2012 10:29:37

Dear Bob,


As I've checked all around MolPrinter and MViewPane, calculating boundingRect, visualizing the molecules, I did not find any serious problem. What I've experienced, the boundaries of your pictures are absolutely correct. The problem is in the applet by the painting of the structures. (You can see an empty area between the painting and the picture boundary.) Do you set the same parameters for the applet, as you have done it by the calculation of the bounding rectangle for the MolPrinter? Please see "tabScale" and "atomsize" parameters!


I hope this will help, and sorry for the late answer!


Regards,


Eva

User 870ab5b546

08-05-2012 17:10:15

We store the dimensions from boundingRect in the int[] dims, and we use them to start MarvinView:


                    <table style="width:100%;" summary="marvinView">
<tr><td>
<table style="width:<%= dims[0] %>px; margin-left:auto;
margin-right:auto;">
<tr><td class="boldtext" style="text-align:right;">
MarvinView&trade;
</td></tr>
<tr><td class="whiteTable" id="content<%= contentNum %>"
style="text-align:center;">
<script type="text/javascript">
// <!-- <% %>
startMView(<%= -dims[0] %>,
<%= dims[1] %>,
'<%= Utils.toValidJS(data) %>',
<%= viewOpts %>,
<%= contentNum %>,
'content<%= contentNum %>',
-1);
// -->
</script>
</td></tr>
</table>

function startMView(width, height, mol, displayFlags, mviewNum, elementId, qdNum) {
var isQDatum = !isNaN(qdNum) && qdNum >= 0;
var appletBld = new String.builder();
if (isQDatum) {
appletBld.append('<table><tr><td class="boldtext" '
+ 'style="text-align:right;">MarvinView&trade;');
appletBld.append('<input type="hidden" id="mviewNumOfQD');
appletBld.append(qdNum);
appletBld.append('" value="');
appletBld.append(mviewNum);
appletBld.append('" />');
appletBld.append('<\/td><\/tr>'
+ '<tr><td class="whiteTable">');
} // if is qDatum
// multidocument structure to display in table?
var molParts = (mol + ' ').split('<\/MDocument>');
var numMols = molParts.length - 1;
if (numMols == 0) numMols = 1;
var numCols = (numMols > 2 ? 2 : numMols);
var newWidth = width * numCols;
if (newWidth < 0) newWidth *= -1;
else if (newWidth > 300) newWidth = 300;
mview_name = 'marvinView' + mviewNum;
mview_begin('/nosession/marvin', newWidth, height);
if (numMols > 1) {
var numRows = (numMols + (numMols % 2 == 0 ? 0 : 1)) / 2;
mview_param('rows', numRows);
mview_param('cols', numCols);
mview_param('border', 1);
} // if there's more than one molecule to display
mview_param('mol', mol);
mview_param('molbg', '#FFFFFF');
mview_param('rendering', 'wireframe');
mview_param('valenceErrorVisible', 'true');
mview_param('valencePropertyVisible', 'false');
mview_param('implicitH', getHVisibility(displayFlags));
mview_param('viewCarbonVisibility', getCVisibility(displayFlags));
mview_param('lonePairsVisible', getLonePairsVisible(displayFlags));
mview_param('chiralitySupport', getRSLabelsVisible(displayFlags));
mview_param('atomMappingVisible', getAtomMapping(displayFlags));
appletBld.append(mview_end_to_string());
if (isQDatum) {
appletBld.append('<\/td><\/tr><\/table>');
}
var applet = appletBld.toString();
setInnerHTML(elementId, applet);
} // startMView()

Here's a typical call to startMView():


					<script type="text/javascript">
// <!--
startMView(-247,
88,
'<?xml version="1.0" ?>\n<cml>\n<MDocument>\n <MChemicalStruct>\n <molecule molID="m1">\n <atomArray\n atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11"\n elementType="C N C H H H O N O O H"\n formalCharge="0 1 -1 0 0 0 0 1 0 -1 0"\n x2="-7.21875 -5.67875 -4.13875 -7.21875 -8.75875 -7.21875 0.33687499165534973 1.8768749916553498 2.6468749916553502 2.6468749916553502 -0.43312500834464995"\n y2="1.2512500286102295 1.2512500286102295 1.2512500286102295 2.7912500286102295 1.2512500286102297 -0.28874997138977054 1.347499966621399 1.347499966621399 2.6811790884494346 0.01382084479336343 2.6811790884494346"\n \/>\n <bondArray>\n <bond atomRefs2="a1 a2" order="1" \/>\n <bond atomRefs2="a2 a3" order="3" \/>\n <bond atomRefs2="a1 a4" order="1" \/>\n <bond atomRefs2="a1 a5" order="1" \/>\n <bond atomRefs2="a1 a6" order="1" \/>\n <bond atomRefs2="a7 a8" order="1" \/>\n <bond atomRefs2="a8 a9" order="2" \/>\n <bond atomRefs2="a8 a10" order="1" \/>\n <bond atomRefs2="a7 a11" order="1" \/>\n <\/bondArray>\n <\/molecule>\n <\/MChemicalStruct>\n<\/MDocument>\n<\/cml>\n',
8390144,
20,
'content20',
-1);
// -->
</script>


ChemAxon 12eab24e0a

09-05-2012 10:22:46

Dear Bob!


Please try to give



    mview_param('tabScale', 30);


to your code!


'atomsize' is 0.4 by default, that shold be ok for you.


'tabScale' parameter is -1 by default, what means that an automatic scaling will work. If you set tabScale to the desired number, it forces the painting to keep this scale factor.


Regards,


Eva

User 870ab5b546

09-05-2012 16:38:24

The tabscale parameter fixes the bond length problem, but the window size is no longer right.  Note: I am using MarvinView 5.4.1.1.

ChemAxon 12eab24e0a

14-05-2012 07:01:34

Dear Bob,


Please add


printer.setLonePairsVisible(true);


to your code just before you calculate the bounding rectangle by MolPrinter!


That will help a lot, but the label of Hydrogen will be still out of the image on the last added picture (Figure 3.7).


I continue working on it and I'll be back with further information soon!


Thanks,


Eva

ChemAxon 12eab24e0a

15-05-2012 09:59:48

Hi Bob,


I've fixed the bug; image is no longer out of the window. The fix is coming out in version 5.10.


I know, you use Marvin 5.4 and you don't want to upgrade because of Java. In this case you can try to do a workaround by giving a different scale factor to MolPrinter for the bounding rectangle calculation. For me


printer.setScale(31); // = 30


has worked, but you can try other factors, which one you like better.


Thank you for your patience,


Eva

User 870ab5b546

16-05-2012 00:35:32

Thanks, those tips are very helpful.