Bob,

Wow. Nice work. This sounds like a very, very useful addition to Jmol, allowing for a huge increase in interactivity. I look forward to using these new features.

Frieda


On Feb 12, 2007, at 12:34 PM, Bob Hanson wrote:

When Jmol 11.1.12 comes out, it will introduce something interesting to
web page developers, I think. It's two new scripting capabilities:

1) Interrupting a running script
--------------------------------
With the implementation of a script queue, we also needed "quit",
"pause", and "exit" to interrupt a running script. But execution of
script commands during script running was not possible -- the scripts
just got queued. In Jmol 11.1.12 you will be able to execute any Jmol
command (including "script somefile.spt") DURING a running script. The
way this is done is to prepend "!" to the script command, like this:

!background white

Now if a script is running, the ! tells the script processor that you
want to interrupt that script, execute "background white", and then
resume the script. This adds some neat looping capability. For example:


load caffeine.xyz
going = true
message _here
[some commands]
if (!going)
 goto _continuing
endif
goto _here
message _continuing
[more commands here]


This script will load caffeine.xyz and then loop forever OR if a button
is provided:

jmolButton("!going=false","stop script")

and the user clicks that button, the script will stop looping AND
CONTINUE. The exclamation point at the beginning allows GOING to be set
FALSE even though another script is running.

Alternatively, that button could just say

jmolButton("quit","stop script")

but that would not exit gracefully and would not allow for continuing
with more commands.


2) Command execution during pause
---------------------------------
The capability to pause and resume a script was introduced earlier, but
the problem was that during the pause all scripting was disabled. Jmol
11.1.12 will allow for user/script interaction during the pause. So, for
example, you could pause a script, ask a user to click on some atom or
do some operation, then resume the script again. This would involve a
pickCallback as well as a messageCallback. The sequence would be
something like this:


jmolScript("set messageCallback mymsg;set pickCallback mypick;
blah,blah,blah....;pause for nitrogen;...more commands....")

function mymsg(a,m) {
  var msg = ""+m;
  if (msg.indexOf("paused: for nitrogen") >= 0)
    alert("now click on the nitrogen")
}

function mypick(a,m) {
  var msg = ""+m;
  if (msg.indexOf("N")==0) {
    alert("Good!")
    jmolScript("resume")
  }else{
    alert("No, that's not nitrogen. Try again.")
  }
}

Notice that we are pausing the script using

  pause for nitrogen

The message returned to the messageCallback function mymsg() is:

  "script execution paused: for nitrogen"

So we pick up on that and give the alert message. Then, if the user
picks nitrogen,
we reward the user and resume the script. If the user doesn't pick
nitrogen, we send
a different message and do NOT resume the script.

Note that during a pause we could even set some value using

jmolScript("somevalue = 3")

and then resume and check that value with an IF command:

if (somevalue = 3)
....
else
...
endif

So I think this adds some very interesting interactive scripting
capability that was not there before.



Comments appreciated.

Bob


---------------------------------------------------------------------- --- 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=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

///////////////////////////////////////////

Frieda Reichsman, PhD
Molecules in Motion
Interactive Molecular Structures
http://www.moleculesinmotion.com

///////////////////////////////////////////


-------------------------------------------------------------------------
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=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Jmol-users mailing list
Jmol-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-users

Reply via email to