First pass at update to Jmol embedding in notebook..

4 views
Skip to first unread message

Jonathan

unread,
Nov 20, 2009, 9:43:59 PM11/20/09
to sage-notebook
I've completed a first pass at an enhanced Jmol interface.
Instructions for setting this up on a test server are near the bottom
of this message. I think its an improvement, but needs work. Next, I
intend to focus my next effort on the file generated by the server.
Then I will come back to more interface enhancements.

The following is complete in a crude way (no buttons or menus, just
links):
1) Resize applet to a few predefined sizes or open in a resizable
window.
2) Number of simultaneously open applets is now limited (presently the
default is maximum of 4 applets. Others are put to sleep and replaced
with an image. Rather than number of applets it might be better to
base on total number of pixels (I'm guessing about 2e6 is a good
maximum).
3) A brief help file is now provided (needs to be expanded).

To do:
1) set the default size to a more appropriate 250 px (right now I'm
overriding the defaults as I haven't yet backtracked to where the size
is appended to the .jmol filename).
2) Add loading of second copy of surface as black mesh to overlay on
surface.
3) Put something appropriate in the caption string. Maybe make the
caption an editable text box?
4) Fix the file that is generated by SAGE. It appears that it is not
handled well by all browsers, so Jmol cannot always read it. In
particular I see a problem with Firefox on MacOS. May need to have a
number of separate files rather than a .zip archive.
5) Add advanced options for changing the lighting orientation, colors,
etc... This might be best done through the applet pop-up menu. We
should be able to add anything people want easy access to, like color
changes, translucency and apply it to selected surfaces.
6)Add saving of last Jmol size and orientation to the saving of a
worksheet. This will probably require saving a Jmol state script to
the server.
7) Need to properly readjust the jmolStatus structure if a single cell
containing Jmol is deleted from a page. Already handling clearing all
output. Other option is to try to construct this information on the
fly. Unfortunately, I kept running up against the asynchronous nature
of communication with the server.
8) Add text labels to the axes so that we know which variable goes
with which axis.


What was changed:
1) Upgraded to jmol 11.8.8 (also put all the jmolApplet0_<part_id>.jar
files into the applet directory. This allows Jmol to only load the
parts of the applet that are needed, saving bandwidth, memory and
time.
2) Extensively rewrote jmol_lib.js.
3) Fixed some applet naming bugs in Jmol.js
4) Made the following change to cell.py
*files_html(self, out)
**default size parameter set to 250 not 500.
5) Made the following change to notebook_lib.js
*delete_all_output()
**Added a call to jmol_delete_all_output();


I rolled a .zip file which can be used to modify an existing 4.2
installation. It contains a number of directories and files. Install
as listed below:

"jmol" is a directory which should replace "sage/local/lib/python2.6/
site-packages/sagenb/data/jmol".

"cell.py" should replace "sage/local/lib/python2.6/site-packages/
sagenb/notebook/cell.py". Don't forget to delete "cell.pyc" to force
an update when the server is restarted.

"jmol_lib.js" should replace "sage/local/lib/python2.6/site-packages/
sagenb/data/sage/js/jmol_lib.js".


"notebook_lib.js" should replace "sage/local/lib/python2.6/site-
packages/sagenb/data/sage/js/notebook_lib.js".

The zip file may be downloaded at the following link:

http://www.uwosh.edu/facult_staff/gutow/jmolinsage_gutow1109.zip

Let me know what you think.

Jonathan

Jonathan

unread,
Nov 20, 2009, 9:50:29 PM11/20/09
to sage-notebook
Sorry, the correct link is:

http://www.uwosh.edu/faculty_staff/gutow/jmolinsage_gutow1109.zip

I lost a "y".

Jonathan

Jonathan

unread,
Nov 20, 2009, 11:01:26 PM11/20/09
to sage-notebook
This is just to get the subject back to reasonable...sorry, I wasn't
clear on how this worked...

jason...@creativetrax.com

unread,
Nov 21, 2009, 1:25:45 AM11/21/09
to sage-n...@googlegroups.com
Jonathan wrote:
> I've completed a first pass at an enhanced Jmol interface.
> Instructions for setting this up on a test server are near the bottom
> of this message. I think its an improvement, but needs work. Next, I
> intend to focus my next effort on the file generated by the server.
> Then I will come back to more interface enhancements.
>


This is absolutely fantastic. I'm really glad you're tackling these issues.




> To do:
> 2) Add loading of second copy of surface as black mesh to overlay on
> surface.
>

Will this work well to show a mesh? You probably saw my posts a while
ago about arbitrary mesh lines on a surface, and Bob mentioned that if
we did things with jvxl (instead of just transferred triangles in a
mesh), we could specify arbitrary mesh lines.

I'll mention one other thing that I find that looks bad in jmol. If you
have the intersection of two surfaces where the angle of intersection is
not that great, the intersection is very rough and flickers quite a
bit. Maybe we could do something on the Sage end to interpolate points
better, or maybe we're rescaling things in a bad way for jmol. Here's
an example:

http://sagenb.org/home/pub/1102/

This is great that you're working on a lot of these issues! Thank you
*very* much!

Jason

--
Jason Grout

Jonathan

unread,
Nov 21, 2009, 2:23:02 PM11/21/09
to sage-notebook
> This is absolutely fantastic.  I'm really glad you're tackling these issues.

Glad to help the little bit I can.

> > To do:
> > 2) Add loading of second copy of surface as black mesh to overlay on
> > surface.
>
> Will this work well to show a mesh?  You probably saw my posts a while
> ago about arbitrary mesh lines on a surface, and Bob mentioned that if
> we did things with jvxl (instead of just transferred triangles in a
> mesh), we could specify arbitrary mesh lines.
I've sent you a separate e-mail with a png of what it looks like. You
be the judge.
>
> I'll mention one other thing that I find that looks bad in jmol.  If you
> have the intersection of two surfaces where the angle of intersection is
> not that great, the intersection is very rough and flickers quite a
> bit.  Maybe we could do something on the Sage end to interpolate points
> better, or maybe we're rescaling things in a bad way for jmol.  Here's
> an example:
>
> http://sagenb.org/home/pub/1102/
I've noticed this two. It appears to be a scaling issue as things get
much better when you zoom in on the image. This suggests it is a Jmol
issue. I will talk to Bob Hanson about it.

Jonathan

Jonathan

unread,
Nov 21, 2009, 9:09:34 PM11/21/09
to sage-notebook
On Nov 20, 8:43 pm, Jonathan <gu...@uwosh.edu> wrote:
> 4) Fix the file that is generated by SAGE.  It appears that it is not
> handled well by all browsers, so Jmol cannot always read it.  In
> particular I see a problem with Firefox on MacOS. May need to have a
> number of separate files rather than a .zip archive.

The first part of the fix appears to be not zipping the file, but I
also need to rewrite the script. Unfortunately, I cannot find where
in the code most of the lines for the script are generated. The first
example is that the pmesh call should be changed to an isosurface call
because of deprecation and added functionality. I also need to
duplicate the call to load each surface more than once to allow
display flexibility. I had assumed there was somewhere where each
line of the script was generated, but it seems to be so abstracted I
cannot even find where the vocabulary used is hidden. I've found
references to "pmesh" in some of the .c files in plot3D, but in all
those cases they just seem to be constants. I'm not at all clear how
they are used. Can someone help me?

Jonathan

jason...@creativetrax.com

unread,
Nov 21, 2009, 10:07:15 PM11/21/09
to sage-n...@googlegroups.com
You want to look in the .pyx and .py files. The .c files are
auto-generated from the corresponding .pyx files (via Cython).

I believe it works by having shapes create indexed face setws (a list of
triangles, maybe quads as well). These then have functions for
describing themselves as jmol pmeshes. This is the "jmol_repr" function
in index_face_set.pyx, I believe (around line 641 or so). That function
appears to create a list of vertices and edges (in the "all" variable),
then writes it out to a .pmesh file. Then it writes a pmesh statement
and returns that string.

Thanks,

Jason


Jonathan

unread,
Nov 22, 2009, 12:25:27 PM11/22/09
to sage-notebook
That helps. It seems like you understand this part of the code much
better than I do. I have a suggestion about how to proceed.

Send me (or put somewhere I can download) a worksheet with as
complicated a 3-D plot as you can think of (2-3 surfaces, at least one
of them closed) and I will take the file appart, rewrite the script
and provide you with what would be best to provide for Jmol. Then you
or someone more familiar with the plot3D code can rewrite that code to
generate the proper files in the proper formats. It will still take
me a while as I don't have much time to devote to this, but if someone
else can do the Sage coding I suspect this rewrite will proceed much
faster.

Jonathan

William Stein

unread,
Nov 22, 2009, 4:53:18 PM11/22/09
to sage-n...@googlegroups.com
On Sun, Nov 22, 2009 at 9:25 AM, Jonathan <gu...@uwosh.edu> wrote:
> That helps.  It seems like you understand this part of the code much
> better than I do.  I have a suggestion about how to proceed.
>
> Send me (or put somewhere I can download) a worksheet with as
> complicated a 3-D plot as you can think of (2-3 surfaces, at least one
> of them closed) and I will take the file appart, rewrite the script
> and provide you with what would be best to provide for Jmol.  Then you
> or someone more familiar with the plot3D code can rewrite that code to
> generate the proper files in the proper formats.  It will still take
> me a while as I don't have much time to devote to this, but if someone
> else can do the Sage coding I suspect this rewrite will proceed much
> faster.
>
> Jonathan

Here you are:

http://nt.sagenb.org/home/pub/5/

William

Jonathan

unread,
Nov 22, 2009, 5:27:53 PM11/22/09
to sage-notebook
Thanks. I'll take a look at this. Two comments:

1) the icosahedron looks very funny because the Z-axis range is so
much larger than the others, otherwise this looks like a good
selection of the kind of things we might plot.

2) Is there something special about the server this example is on?
Firefox on MacOS works with this server. I'll try putting the
worksheet on my server, but I've not been able to get things to work
with that browser/OS combination.

Jonathan

William Stein

unread,
Nov 22, 2009, 5:48:52 PM11/22/09
to sage-n...@googlegroups.com
On Sun, Nov 22, 2009 at 2:27 PM, Jonathan <gu...@uwosh.edu> wrote:
> Thanks.  I'll take a look at this. Two comments:
>
> 1) the icosahedron looks very funny because the Z-axis range is so
> much larger than the others, otherwise this looks like a good
> selection of the kind of things we might plot.

True. It's because the aspect ratio isn't square.

> 2) Is there something special about the server this example is on?

Nope.

> Firefox on MacOS works with this server.  I'll try putting the
> worksheet on my server, but I've not been able to get things to work
> with that browser/OS combination.

I do almost all my work/development on OS X with Firefox personally,
and it works well. There have been some issues with OS X 10.6,
though.

-- William

>
> Jonathan
>
>
> On Nov 22, 3:53 pm, William Stein <wst...@gmail.com> wrote:
>> On Sun, Nov 22, 2009 at 9:25 AM, Jonathan <gu...@uwosh.edu> wrote:
>> > That helps.  It seems like you understand this part of the code much
>> > better than I do.  I have a suggestion about how to proceed.
>>
>> > Send me (or put somewhere I can download) a worksheet with as
>> > complicated a 3-D plot as you can think of (2-3 surfaces, at least one
>> > of them closed) and I will take the file appart, rewrite the script
>> > and provide you with what would be best to provide for Jmol.  Then you
>> > or someone more familiar with the plot3D code can rewrite that code to
>> > generate the proper files in the proper formats.  It will still take
>> > me a while as I don't have much time to devote to this, but if someone
>> > else can do the Sage coding I suspect this rewrite will proceed much
>> > faster.
>>
>> > Jonathan
>>
>> Here you are:
>>
>>    http://nt.sagenb.org/home/pub/5/
>>
>> William
>



--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

Jonathan

unread,
Nov 22, 2009, 8:25:29 PM11/22/09
to sage-notebook


On Nov 22, 4:48 pm, William Stein <wst...@gmail.com> wrote:

> > 2) Is there something special about the server this example is on?
>
> Nope.

Hmm. The only thing I can think of is that I am running my server
using https, so that my students can use their campus logins if they
wish without compromising them. That said, I have the same problem
connecting to an insecure server running on my Mac OSX 10.5.8 at
localhost:8000. This is a little weird. I'd like to trace it as odd
behavior like this usually points to doing something not quite right.

Jonathan
Reply all
Reply to author
Forward
0 new messages