[Jmol-users] Jmol.js prototype: Jmol-new.js and jmolScriptWait

2006-05-05 Thread Bob Hanson
It's probably time I told people about some of the prototype Jmol.js 
niceties in

 http://www.stolaf.edu/people/hansonr/jmol/test/proto/Jmol-new.js

Here are a few, at least:

*JAR File Option*

An enhanced jmolInitialize() function that allows for specification of a 
particular Jar file as the second parameter.


 jmolInitialize(., JmolAppletProto.jar)

This then allows testing of different versions. Leaving that parameter 
off defaults to JmolApplet0.jar, which then also requires 1-6. But 
setting it to a copy of the JmolApplet.jar file from any release pr 
prerelease of Jmol or from your own compiling bypasses the 1-6 jar files 
and directs Jmol to use the Jar file you specifically want it to use. 
Note that this may only require a single Jar file in the specified 
directory. But if you specify the release's JmolApplet0.jar file, then 
all the othere, 1-6, must be there as well.


*Synchronous Scripting*

OK, the main subject of this message deals with scripting. It answers 
Eric's question about how one can get a pop-up message if a script has 
an error along with several other possibilities.


One of the problems with scripting the applet has always been that the 
script runs in a separate, parallel thread. This means that you can't 
expect the applet to have done anything at all right after executing


 jmolScript(.)

For example, if you use:

 jmolScript(load myfile)
 alert(testing

the alert will appear long before the file is actually loaded.

The new option

 result = jmolScriptWait()

1) waits until the script has completed running to return, and
2) returns valuable status messages in the assigned variable (result 
in this case).


jmolScriptWait() turns out to be VERY powerful. Consider, for example:

var fileContents = jmolScriptWait(show file)

or

var returnStatus = jmolScriptWait(selct not hydrogen)
if(status.indexOf(ERROR)=0)alert(returnStatus)

I'm starting to use jmolScriptWait() a LOT in my work because I can get 
information from the applet and do something with it. For many 
applications, jmolScriptWait() removes the need for callbacks. Here are 
a few examples:



*Save/Restore orientation*

One of the nicest script commands is show orientation, which returns 
the moveTo command required to set an orientation as the first line, 
ending with a semicolon.


So consider this sequence:

 var thisOrientation = jmolScriptWait(show orientation).split(;)[0]
..
later
..
 jmolScriptWait(thisOrientation)

That give you any ideas? You can check this out at 


http://www.stolaf.edu/people/hansonr/jmol/xtalx

I built this into Jmol-new.js as two new functions:

 jmolSaveOrientation(id, targetSuffix)

and

 jmolRestoreOrientation(id, targetSuffix)

The idea of the id is that you can then name different save/restore 
points under different identifiers. Call one initial and one final, 
for example.


*getProperty*

I'm not going to detail this at this time, but something new you can do 
in the prototype is get all sorts of information just using 
jmolScriptWait(). Here are a few examples only:


var info = jmolScriptWait(getProperty appletinfo)

This returns what at first may look rather peculiar:

{appletinfo: {version: 10.3.BH,date: 2006-05-01 
20:08,javaVersion: 1.5.0_06,htmlName: jmolApplet0,javaVendor: 
Sun Microsystems Inc.,operatingSystem: Windows XP}}


This is called JavaScript Object Notation, or JSON, 
http://www.json.org/ and it is just a compact form of a relatively new 
way to work with JavaScript. Interestingly, JSON is a lot like XML, but 
is it more compact and more easily handled in common browsers. For these 
reasons JSON is starting to replace XML in certain applications.


If you unpack this returned string, you will see that it is what is 
called a JavaScript object literal:


{appletinfo: {
   version: 10.3.BH,
   date: 2006-05-01 20:08,
   javaVersion: 1.5.0_06,
   htmlName: jmolApplet0,
   javaVendor: Sun Microsystems Inc.,
   operatingSystem: Windows XP
}}

That's actual JavaScript. It is returned as a string, but you can 
evaluate it by placing it in parentheses:


 eval((+info+))

Now you can check

appletinfo.version
appletinfo.date
appletinfo.javaVersion

etc.

I've built several different properties that you can get. I'll elaborate 
on these in a future message, but if you want to play with this, some of 
the more useful ones are given below:


appletinfo
animationinfo
modelinfo
shapeinfo
measurementinfo
boundboxinfo
centerinfo
orientationinfo
transforminfo
zoominfo
atominfo
bondinfo
polymerinfo
chaininfo
stateinfo

The following three are special in that they return straight text, not JSON:

fileName
fileHeader
fileContents
extractModel

(That last one will be discussed below.)

Some of these can take an additional argument that specifies WHICH 
information. You must specify this information in IN PARENTHESES. For 
example:


getproperty atominfo atomno=32

might return:

{atominfo: [{
   visible: true,
   model: 1,
   radius: 0.875,
   

Re: [Jmol-users] Jmol.js prototype: Jmol-new.js and jmolScriptWait

2006-05-05 Thread nvervell


binQfg41Vl0od.bin
Description: undefined


Re: [Jmol-users] Jmol.js prototype: Jmol-new.js and jmolScriptWait

2006-05-05 Thread Eric Martz

At 5/5/06, you wrote:
It's probably time I told people about some of the prototype Jmol.js 
niceties in

 http://www.stolaf.edu/people/hansonr/jmol/test/proto/Jmol-new.js


Dear Bob,

This all looks extremely useful. At last there is a mechanism to keep track 
of when the applet has completed a task! And better yet, whether it 
completed the task successfully.


1. Is there any way to tell when the applet is initially loaded and ready 
for the first script? My inability to do this caused lots of head 
scratching when I began designing FirstGlance.


2. Is there any way to tell when the Protein Data Bank does not supply the 
PDB file requested in a load command? FirstGlance presently just leaves a 
blank applet (white, Jmol frank disappears), a very ungraceful failure.


Unfortunately, I cannot immediately take advantage of the new jmol.js ...

3. LACK OF JMOL.JS DOCUMENTATION. When I started coding FirstGlance, I 
decided not to use jmol.js. This was partly because it didn't support some 
functions I needed, but mainly because it is undocumented and I was afraid 
to use it. From inspection of the contents of jmol.js, it appears to do 
some sort of browser/java version testing, but I cannot tell what this is 
supposed to accomplish. Until someone documents the situations this is 
supposed to handle and what it is attempting to do, I will continue to be 
reluctant to use jmol.js for FirstGlance. I want to avoid a situation where 
a (common) client situation that I haven't tested causes an unanticipated 
failure mode. For example, no java in Windows, or a very old version of 
java. Right now, FirstGlance would fail to work at all, or to work 
correctly, without any explicit error messages. That is certainly not 
optimal. But I can't tell whether jmol.js would do better.


One bit of code in jmol.js that particularly concerns me (and is 
inscrutable to me) is this:


  windowsClassId: clsid:8AD9C840-044E-11D1-B3E9-00805F499D93,
  windowsCabUrl:
   http://java.sun.com/update/1.5.0/jinstall-1_5_0_07-windows-i586.cab;,

I wish someone would explain to me what this is designed to do, and how I 
could test it.


More generally, I think we need thorough on-line documentation, in one 
place, on what jmol.js is designed to do, how to use the functions in it, etc.


-Eric 




---
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users


Re: [Jmol-users] Jmol.js prototype: Jmol-new.js and jmolScriptWait

2006-05-05 Thread Bob Hanson



Eric Martz wrote:


At 5/5/06, you wrote:

It's probably time I told people about some of the prototype Jmol.js 
niceties in

 http://www.stolaf.edu/people/hansonr/jmol/test/proto/Jmol-new.js



Dear Bob,

This all looks extremely useful. At last there is a mechanism to keep 
track of when the applet has completed a task! And better yet, whether 
it completed the task successfully.


1. Is there any way to tell when the applet is initially loaded and 
ready for the first script? My inability to do this caused lots of head 
scratching when I began designing FirstGlance.


This needs experimentation on a variety of platforms.




2. Is there any way to tell when the Protein Data Bank does not supply 
the PDB file requested in a load command? FirstGlance presently just 
leaves a blank applet (white, Jmol frank disappears), a very ungraceful 
failure.


 myVar = jmolScriptWait(load jmol.js)

The file exist, but the return message is

ERROR: ScriptException:unrecognized file format | Script line:load 
jmol.js



3. LACK OF JMOL.JS DOCUMENTATION. When I started coding FirstGlance, I 
decided not to use jmol.js. This was partly because it didn't support 
some functions I needed, but mainly because it is undocumented and I was 
afraid to use it. From inspection of the contents of jmol.js, it appears 
to do some sort of browser/java version testing, but I cannot tell what 
this is supposed to accomplish. Until someone documents the situations 
this is supposed to handle and what it is attempting to do, I will 
continue to be reluctant to use jmol.js for FirstGlance. I want to avoid 
a situation where a (common) client situation that I haven't tested 
causes an unanticipated failure mode. For example, no java in Windows, 
or a very old version of java. Right now, FirstGlance would fail to work 
at all, or to work correctly, without any explicit error messages. That 
is certainly not optimal. But I can't tell whether jmol.js would do better.


You have to give Miguel credit for writing a VERY GOOD browser testing 
sequence into Jmol.js. Initially I felt the same as you -- too much of 
a black box. After using Jmol.js with touches of modification here and 
there, I can tell you that it is SUPERB. I don't think I'll ever write 
any page using Jmol without it now. I think you should sit down, take 
the time to understand it, and use it.


No documentation will ever provide what you are asking for, I think -- 
a description of HOW it works. I'm not sure what more you could want 
than http://jmol.sourceforge.net/jslibrary/




One bit of code in jmol.js that particularly concerns me (and is 
inscrutable to me) is this:


  windowsClassId: clsid:8AD9C840-044E-11D1-B3E9-00805F499D93,
  windowsCabUrl:
   http://java.sun.com/update/1.5.0/jinstall-1_5_0_07-windows-i586.cab;,

I wish someone would explain to me what this is designed to do, and how 
I could test it.


Miguel can do that.



More generally, I think we need thorough on-line documentation, in one 
place, on what jmol.js is designed to do, how to use the functions in 
it, etc.


Is it possible you haven't seen http://jmol.sourceforge.net/jslibrary/

?



Bob

--

Robert M. Hanson, [EMAIL PROTECTED], 507-646-3107
Professor of Chemistry, St. Olaf College
1520 St. Olaf Ave., Northfield, MN 55057
mailto:[EMAIL PROTECTED]
http://www.stolaf.edu/people/hansonr

Imagination is more important than knowledge.  - Albert Einstein


---
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnkkid=120709bid=263057dat=121642
___
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users