nice mesh lines in jmol

108 views
Skip to first unread message

Jason Grout

unread,
Oct 22, 2009, 2:51:52 AM10/22/09
to sage-...@googlegroups.com
A few days ago I posted a query to the jmol mailing list about getting
nice mesh lines in jmol that we could make pretty arbitrary, like in
http://trac.sagemath.org/sage_trac/attachment/ticket/5511/mesh_function.jpeg
(see trac #5511 for the code for that figure). Two people have
responded and it looks like we may be making progress; we are now
looking for people with ideas about how to make everything work. If you
would like to join the discussion (or comment here and I can forward it
to the jmol list), please see:

http://www.mail-archive.com/jmol-...@lists.sourceforge.net/msg13044.html

For reference, my initial posting is below.

Thanks,

Jason

I've been using jmol quite a bit lately in Sage for drawing 3d
mathematical surfaces. One thing I really miss is the ability to have
nice meshes (including arbitrary meshes) on a surface. Currently Jmol
allows a mesh option to pmesh surfaces, but that only draws a specific
grid that is hard to see (it is the same color as the surface, but
lighter or something).

Probably the easiest change would be to make the mesh default to black
lines (like the black lines for contour plots on cut planes). That
would make the mesh lines much easier to see. Seeing the mesh lines
often really helps us mathematicians (especially those of us teaching).

A very nice functionality to add would be the ability to draw arbitrary
meshes on surfaces, similar to what is implemented here (but as black
lines on the surface, rather than the crude approximation constructed
here):
http://trac.sagemath.org/sage_trac/attachment/ticket/5511/mesh_function.jpeg.

I think Mathematica has a nice interface to these sorts
of things: http://reference.wolfram.com/mathematica/ref/MeshFunctions.html

We (Sage) can take care of the interface to draw meshes. What we'd need
from jmol is the ability to draw a line *on* a surface and have it look
like the contour lines look like on a plane. Maybe for each triangle in
the surface, we could give a list of lines to draw on that triangle by
specifying (for each line) the two edges the line crosses and the
fraction of the distance along the edge to make the intersection between
the line and the edge of the triangle.

What do you think?

Thanks,

Jason

--
Jason Grout

Jason Grout

unread,
Oct 22, 2009, 3:01:34 AM10/22/09
to sage-...@googlegroups.com
Jason Grout wrote:
> A few days ago I posted a query to the jmol mailing list about getting
> nice mesh lines in jmol that we could make pretty arbitrary, like in
> http://trac.sagemath.org/sage_trac/attachment/ticket/5511/mesh_function.jpeg
> (see trac #5511 for the code for that figure). Two people have
> responded and it looks like we may be making progress; we are now
> looking for people with ideas about how to make everything work. If you
> would like to join the discussion (or comment here and I can forward it
> to the jmol list), please see:
>
> http://www.mail-archive.com/jmol-...@lists.sourceforge.net/msg13044.html
>


In fact, Bob Hanson suggests creating a new mathematics plot type that
has things like arbitrary meshes, annotations, and whatever else we want:

What you suggest might be possible -- even now -- but I suggest
we start talking about a new object type. Maybe a "plot3d" that
is an extended isosurface. We already have that for molecular
orbitals, LCAO cartoons, and pmesh. The way it works is that the
extended object has more capabilities -- in this case, to map
more than just contours onto an isosurface. Like you say, a
totally variable mesh, which would just be a set of lines of
variable width, color, and translucency. Possibly annotations. In
addition, possibly, automatic scaling. Right now you have to do
some transforms that are oblivious to Jmol. I'd like the
oblivious part to be in the use interface and let Jmol take care
of anisotropic scaling.

So, now is the time to dream about the perfect jmol primitive for our
graphics. Any ideas? People that have worked on the 3d graphics in
Sage are especially encouraged to reply.

Jonathan

unread,
Oct 31, 2009, 10:34:25 PM10/31/09
to sage-devel
Jason,
I think this is a great idea. As I use Sage a bit in my teaching,
it would be nice to have a primitive with separate items for axes,
axes' labels, axes scale (the numbers on the axes). Then buttons
could be added to turn these on and off at the user request. If some
things can be passed to Jmol as functions, they will render well at
any zoom level. It would also be easier to use the slab function for
slicing 3-D objects.
That said there are some serious problems with how the notebook/
plot3D uses Jmol presently, that have little to do with whether a
primitive exists or not. I'm willing to help fix them, but need to
understand where in the code the html and javascript for Jmol is
generated. The way it is presently done the following things are a
problem:

1) It does not work in Firefox on Macs. Since I never have trouble
with this, I'm assuming something abnormal is being done with the
javascript that controls Jmol. Again, I bet I can help with this, but
I could not easily find where the code was generated. All I can do is
look at a web page.
2) Since people are running into memory problems, I suggest that only
a limited number of live Jmols (present default JavaVM configurations
support about 8 - 10 per page) be allowed in any given notebook. I
provided some example code that does not require any server
intervention that does this. I could help fold this in, if I could
figure out how you are generating the javascript to control Jmol.
3) Since there is room next to Jmol in the notebook, I suggest that
simple instructions on what Jmol can do and how to access the pop-up
be added and maybe a link to more extensive documentation (the Jmol
Site?). I'm an expert with Jmol and found it difficult to do anything
but rotate the image without significant experimentation.
4) It also might be worth loading only a static image first with a
link to make live. This saves a lot of bandwidth and will decrease
the time users have to wait to see their plots.
5) It would probably be a good idea to upgrade Jmol to the latest
stable release 11.8. I will try slipping that into a copy of 4.2 I
just downloaded.

These are just some thoughts. The key thing is I think I could help,
but do not have time to wade through the code to figure out how
everything is connected. Can someone just tell me were to look?

Jonathan


On Oct 22, 2:01 am, Jason Grout <jason-s...@creativetrax.com> wrote:
> Jason Grout wrote:
> > A few days ago I posted a query to thejmolmailing list about getting
> > nice mesh lines injmolthat we could make pretty arbitrary, like in
> >http://trac.sagemath.org/sage_trac/attachment/ticket/5511/mesh_functi...
> > (see trac #5511 for the code for that figure).  Two people have
> > responded and it looks like we may be making progress; we are now
> > looking for people with ideas about how to make everything work.  If you
> > would like to join the discussion (or comment here and I can forward it
> > to thejmollist), please see:
>
> > http://www.mail-archive.com/jmol-us...@lists.sourceforge.net/msg13044.html
>
> In fact, Bob Hanson suggests creating a new mathematics plot type that
> has things like arbitrary meshes, annotations, and whatever else we want:
>
> What you suggest might be possible -- even now -- but I suggest
> we start talking about a new object type. Maybe a "plot3d" that
> is an extended isosurface. We already have that for molecular
> orbitals, LCAO cartoons, and pmesh. The way it works is that the
> extended object has more capabilities -- in this case, to map
> more than just contours onto an isosurface. Like you say, a
> totally variable mesh, which would just be a set of lines of
> variable width, color, and translucency. Possibly annotations. In
> addition, possibly, automatic scaling. Right now you have to do
> some transforms that are oblivious toJmol. I'd like the
> oblivious part to be in the use interface and letJmoltake care
> of anisotropic scaling.
>
> So, now is the time to dream about the perfectjmolprimitive for our

Jason Grout

unread,
Nov 3, 2009, 2:02:05 AM11/3/09
to sage-...@googlegroups.com


Here's what I found by poking around for a bit. Everything has changed
since the new notebook, so someone that knows, *please* correct me if
I'm wrong.

In Sage 4.2, it looks like the jmol-invoking javascript code is in:

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

That appears to be the code that actually sets up a jmol applet and
makes the "Get Image" link.

That file is loaded in
local/lib/python2.6/site-packages/sagenb/data/sage/js/notebook_lib.js

Jmol is initialized at the bottom of the template file:

local/lib/python2.6/site-packages/sagenb/data/sage/html/notebook/head.tmpl


The actual jmol application is in:

local/lib/python2.6/site-packages/sagenb/data/jmol

The jmol code gets invoked when a ".jmol" file is created by a 3d plot.
The notebook then comes by, sees the .jmol file, and creates the jmol
applet. The code that does this is in
local/lib/python2.6/site-packages/sagenb/notebook/cell.py (search for
jmol).

The code in Sage that generates the .jmol files is (I believe) in
devel/sage/sage/plot/plot3d/base.pyx (see the show method, starting with
the following code. EMBEDDED_MODE is True when you are inside the
notebook, and False if you are not executing inside the notebook.)

if DOCTEST_MODE or viewer=='jmol':
# Temporary hack: encode the desired applet size in the end
of the filename:
# (This will be removed once we have dynamic resizing of
applets in the browser.)
base, ext = os.path.splitext(filename)
fg = figsize[0]
#if fg >= 2:
# fg = 2
filename = '%s-size%s%s'%(base, fg*100, ext)
ext = "jmol"
archive_name = "%s.%s.zip" % (filename, ext)
if EMBEDDED_MODE:
# jmol doesn't seem to correctly parse the ?params part
of a URL
archive_name = "%s-%s.%s.zip" % (filename, randint(0, 1
<< 30), ext)

T = self._prepare_for_jmol(frame, axes, frame_aspect_ratio,
aspect_ratio, zoom)
T.export_jmol(archive_name, force_reload=EMBEDDED_MODE,
zoom=zoom*100, **kwds)
viewer_app = "sage-native-execute " +
os.path.join(sage.misc.misc.SAGE_LOCAL, "bin/jmol")

# We need a script to load the file
f = open(filename + '.jmol', 'w')
f.write('set defaultdirectory "%s"\n' % archive_name)
f.write('script SCRIPT\n')
f.close()


I hope this helps.

Jonathan

unread,
Nov 3, 2009, 8:56:58 AM11/3/09
to sage-devel
Thanks, I'll try to get a look at it. This appears to be what I
needed to find. No promises, as I'm pretty swamped, but now I have
somewhere to start.

Jonathan

Lubomir Dechevsky

unread,
Oct 11, 2015, 10:27:07 AM10/11/15
to sage-devel, gu...@uwosh.edu
Here is one suggestion for a general solution in SAGE to the problem about generating arbitrary meshes of curves on surfaces in 3D or of curves and/or surfaces in 3D-volume deformations (i.e., (x=fx(u,v,w),y=fy(u,v,w),z=fz(u,v,w)), which includes also 3D-scalar fields (i.e., t=f(x,y,z), t is a scalar, say, real). In this setting, the necessary result is achieved in a simple way using the currently available visualization classes parametric_plot3d and implicit_plot3d:


Comments, remarks, improvements and  optimizations are very welcome! 

Regards,

shao-linux :)

kcrisman

unread,
Oct 13, 2015, 9:15:17 AM10/13/15
to sage-devel
This could be worth a ticket?
Reply all
Reply to author
Forward
0 new messages