Thanks - this works.

I modified your script to also return the atoms at the max min  
positions so that these could be selected and subsequent calls to  
getScreenBoundary only had to examine the {selected} atoms (because  
there's no rotation between calls).

Curiously this showed that the 'rotate best' needed to be done first  
(before the initial zoom) otherwise the coordinates did not reflect  
the rotated model.
Perhaps the subsequent zoom forces a refresh...

Anyway, many thanks for your help with this - another job done :-)

Cheers

Simon

Quoting Rolf Huehne <rhue...@leibniz-fli.de>:

> Am 04.12.15 um 18:47 schrieb si...@publcif.co.uk:
>>
>> Thanks for this Angel
>>
>> My task was to effectively "crop" the model so that a static image
>> could be created that was as large as possible with respect to the
>> model, but also exactly reflected what would be seen in the applet -
>> i.e. the static image could be used in e.g. a PDF but scaled to a
>> 'thumbnail' size, but still had minimal margins and still represented
>> what the associated applet would show.
>>
>> Anyway, a script such as:
>>
>> zoom {visible} 0;
>> rotate best;
>> refresh;
>> margin=15;
>> c=0;
>> while ({visible}.sx.all.max < _width-margin && {visible}.sx.all.min >
>> margin && {visible}.sy.all.max < _height-margin &&
>> {visible}.sy.all.min > margin ) {
>>    zm=100+c;
>>    zoom {visible} @zm;
>>    refresh;
>>    c=c+1;
>>    if (c>100) {break;}
>> }
>> echo @c;
>>
>> achieves this nicely and shows that in many cases there is room for a
>> zoom of 130+ percent.
>>
>> Unfortunately, however, the script requires calling 'refresh' in order
>> to update
>> the screen coordinates of the model (.sx, .sy), which it seems is not
>> possible when running the script from the command line to generate a
>> static image (i.e. running the jmol application with -ionx and the
>> script contained in an spt file) - which is essential to my task,
>> which involves automated production of print content and html content
>> without user intervention.
>>
>> So at the moment I'm left with having to 'crop' the static images for
>> print use and reproducing the 'crop' effect in the html versions - not
>> a major problem, but it would have been nice to have just had the one
>> image with the load script embedded, etc., which could then be used
>> for print and html...
>>
>> Anyway, if anyone has any suggestions regarding running the jmol
>> application 'headless' with scripts that appear to require an 'event
>> loop' I'd be very grateful...
>>
> The 'point({x,y,z},true)' function to calculate the screen coordinates
> does work headless in Jmol 14.4.0. So you can determine the minima and
> maxima in a loop (startZoom set to '80' for testing):
>
> ---- scriptfile 'autozoom.spt' --------
> startZoom = 80
> zoom {visible} @startZoom;
> rotate best;
> margin=15;
> c=0;
>
> function getScreenBoundary(atomSet) {
>    if (atomSet.type == "bitset") {
>      var screenMinX = "";
>      var screenMaxX = "";
>      var screenMinY = "";
>      var screenMaxY = "";
>      for (var i from [1 atomSet.size]) {
>        var screenXYZ = point(atomSet[i].xyz, true);
>        if (screenMinX == "") {
>          screenMinX = screenXYZ.x;
>          screenMaxX = screenXYZ.x;
>          screenMinY = screenXYZ.y;
>          screenMaxY = screenXYZ.y;
>        } else {
>          screenMinX = [screenMinX, screenXYZ.x].min;
>          screenMaxX = [screenMaxX, screenXYZ.x].max;
>          screenMinY = [screenMinY, screenXYZ.y].min;
>          screenMinY = [screenMinY, screenXYZ.y].min;
>        }
>      }
>      return [screenMinX, screenMaxX, screenMinY, screenMaxY];
>    }
> }
>
> sxInfo = getScreenBoundary({visible});
> while (sxInfo[2] < _width-margin && sxInfo[1] > margin && sxInfo[4] <
> _height-margin && sxInfo[3] > margin ) {
>    zm=startZoom+c;
>    zoom {visible} @zm;
>    c=c+1;
>    if (c>100) {break;}
>    sxInfo = getScreenBoundary({visible});
> }
> print "c=" + c;
>
> ------ Headless Jmol call ----------------------------
> java -jar JmolData.jar -g800x800 -J 'load =1deh; script "autozoom.spt";
> write PNGJ 9 "autozoom-test.png";'
> ------------------------------------------------------
>
> Regards,
> Rolf
>
>
> ------------------------------------------------------------------------------
> Go from Idea to Many App Stores Faster with Intel(R) XDK
> Give your users amazing mobile app experiences with Intel(R) XDK.
> Use one codebase in this all-in-one HTML5 development environment.
> Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
> http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
> _______________________________________________
> Jmol-users mailing list
> Jmol-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>



------------------------------------------------------------------------------
Go from Idea to Many App Stores Faster with Intel(R) XDK
Give your users amazing mobile app experiences with Intel(R) XDK.
Use one codebase in this all-in-one HTML5 development environment.
Design, debug & build mobile apps & 2D/3D high-impact games for multiple OSs.
http://pubads.g.doubleclick.net/gampad/clk?id=254741911&iu=/4140
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to