On Thu, Jan 28, 2010 at 1:11 PM, Eric Martz <martzeric@yahoo.com> wrote:
Dear Bob,

Thanks for the good overview and examples which I found very very useful!

Here is what I am trying to do. Please suggest the best way to handle this.

(I remind you that way back in 2005 I made the decision not to use Jmol.js. At this point it seems easiest not to rewrite FirstGlance to use Jmol.js. The lack of Jmol.js has not caused any problem that I am aware of.)


amazing that your pages work on all browsers -- or maybe you are copying that part of the Jmol.js code?
 
I am trying to detect the case when a PDB file is requested (by FirstGlance in Jmol) but is not available. The most likely case is when the PDB file corresponding to a new article in Nature has not been released on the date of publication, which occurs because nobody tells the PDB in advance when publication will occur. The PDB file is in the PDB but has status "HPUB" (hold for publication), so is not publically available. 


If I wanted to find out BEFORE loading the file, I would just load the PDB file into a variable and see what you get.  You can limit the amount of file to read using a number:

This is in Jmol:

if (load("=1crn",100).find("HEADER") != 1).....


This is JavaScript:

if(jmolEvaluate('load("=1crn",100).find("HEADER")) != 1)....




A current example (should remain HPUB at least until next Tuesday's new release batch) is http://www.rcsb.org/pdb/cgi/export.cgi/3IYE.pdb.gz


Right, the message coming back for that is:

java.io.FileNotFoundException: http://www.rcsb.org/pdb/files/3IYE.pdb

so no HEADER and the find returns 0
 
So Jmol applet gets the command
load http://www.rcsb.org/pdb/cgi/export.cgi/3IYE.pdb.gz

this URL is redirected to
http://www.rcsb.org/pdb/nosuchfile.jsp

Jmol 11.8.14 generates this in the messageCallback stream:
script ERROR: java.io.FileNotFoundException: http://www.rcsb.org/pdb/cgi/export.cgi/3IYE.pdb.gz

Jmol displays this in a tiny red font at the top:
java.io.FileNotFoundException: http://www.rcsb.org/pdb/nosuchfile.jsp

My code watches the messageCallback stream for "FileNotFoundException" in the same line as "error" (ignoring case) and if this occurs, attempts to say something helpful to the user. My current code is confounded by the multiple concurrent messageCallbacks. 


If this is all you are after, why not a loadStructCallback? That's what they are for. I think you are using messageCallbacks way too much. That was the problem years ago, of course, and that hasn't changed. The solution was to provide a wider variety of callbacks.

JmolScript("set loadstructcallback 'myCallback')

function myCallback(a, b, c, d) {
 if (!b)jmolScript("zap;set echo top left;echo file did not load")
}

or whatever.

The main question is whether you want to alert the person BEFORE any changes to the current model (then use the load() function to check the file first) or allow the zap to be made (then use the loadStructCallback)

Note that checking with load might double your download time. Do check that - I don't know if Java will cache the file or not -- probably will, but I'm not sure.

Bob


--
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