The basic scheme is what you have there:
JmolApplet(.....,"....... javascript appletLoaded()")
then your appletLoaded function will be called, and you can add JmolScript
or JmolGetPropertyAsArray commands then to that. You must not try to contact
Jmol until it is ready. Also, in the latest version of Jmol, we have
set readyCallback ....
which specifically calls you back when the applet is ready. Note, however,
that this event is sent BEFORE the script is executed, not after.
Bob
On Fri, Aug 5, 2011 at 11:26 AM, Daniel Carbajo <[email protected]>wrote:
> Dear everyone,
> the problem I have is the following:
> I load a structure in an applet and I check in a hash some residues that I
> put in wireframe by default. Since this second command is sent by
> jmolScriptWait just after jmolApplet, it does not succeed as the applet
> takes time to be built. There is a partial solution here
> http://jmol.sourceforge.net/jslibrary/index.en.html#jmolApplet but I
> cannot make it work, it reads:
>
> *Note*:
> It takes some time to build the applet, so if you put some immediate action
> like jmolScript() or jmolLoadInline() right after the jmolApplet() line,
> it will probably fail because it will be called before the applet has
> finished loading. There are two alternatives that will work:
>
> - Put the commands inside the call to jmolApplet() (its 2nd argument,
> script).
> - Have the browser wait until the applet reports to be finished. To do
> so, put this at the end of the script sent with applet creation: javascript
> appletLoaded(); and define a JavaScript function calledappletLoaded() (or
> any other name you like) that will trigger any further commands.
>
>
>
>
> I try the second solution since I have to check the residues in the hash,
> so I do the following (instead of the putting the residue in wireframe I
> alert the state, so I can see if the applet has already loaded):
>
> <script type=\"text/javascript\">
> function JmolCargado(res){
> if (res){
> var state=jmolGetPropertyAsString(\"stateInfo\");
> alert(res + ' --- ' + state);
> }
> }
> </script>
>
>
>
>
> $JMOL = "<script type=\"text/javascript\">
> jmolInitialize(\"Jmol-12new\", true);
> jmolSetAppletColor(\"white\");
> var jmolcmds = [
> \"load $jmolfile\",
> \"set frank off; select all; hbonds off; spin off; wireframe off;
> spacefill off; trace off; set ambient 40; set specpower 40; slab off;
> ribbons off; cartoons off; label off; monitor off\",
> \"set isosurfacePropertySmoothing TRUE\",
> \"set showAxes true\",
> \"frame all\",
> \"display all\",
> \"select 1.1; cartoon; set propertyColorScheme 'bwr'; color atoms property
> temperature ABSOLUTE $range\",
> \"set perspectiveModel 10\",
> \"set zoomLarge off\",
> \"move 0 0 0 50 0 0 0 0 2\",
> \"script Jmol-12new/myJMOLfunctions.spt\",
> \"javascript appletLoaded()\"
> ];
> jmolApplet([450,450], jmolcmds.join(\"; \"));
> </script>";
>
>
> foreach ($AllResidues as $residue){
> if (array_key_exists($residue, $SelectedResiduesHash)){
> echo "<script
> type=\"text/javascript\">JmolCargado(\"$residue\")</script>";
> }
>
>
> It works just partially... I have 3 residues in $SelectedResiduesHash so I
> get 3 alerts (plus one of the line javascript appletLoaded() I don't know
> why, but I filter it in the javascript function with if(res)); however, the
> first alert prints a 'null' as the variable 'state' value, which highlights
> the fact that the command is run BEFORE the applet actually finishes
> loading. I would really appreciate some help on this... Thanks to everyone!
> Daniel
>
>
> ------------------------------------------------------------------------------
> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
> The must-attend event for mobile developers. Connect with experts.
> Get tools for creating Super Apps. See the latest technologies.
> Sessions, hands-on labs, demos & much more. Register early & save!
> http://p.sf.net/sfu/rim-blackberry-1
> _______________________________________________
> Jmol-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/jmol-users
>
>
--
Robert M. Hanson
Professor of Chemistry
St. Olaf College
1520 St. Olaf Ave.
Northfield, MN 55057
http://www.stolaf.edu/people/hansonr
phone: 507-786-3107
If nature does not answer first what we want,
it is better to take what answer we get.
-- Josiah Willard Gibbs, Lecture XXX, Monday, February 5, 1900
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
The must-attend event for mobile developers. Connect with experts.
Get tools for creating Super Apps. See the latest technologies.
Sessions, hands-on labs, demos & much more. Register early & save!
http://p.sf.net/sfu/rim-blackberry-1
_______________________________________________
Jmol-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-users