On 08/21/2015 04:16 PM, Robert Hanson wrote: > yes. First use > > x = load("test.png", TRUE) > > this loads test.png as a binary file, creating an associative array of > information in the file in the form of binary arrays. > > $ x = load("test.png", TRUE) > $ print x.keys > $_BINARY_$ > 1deh.pdb.gz > JmolManifest.txt > Jmol_version_14.3.16_2015.08.17__2015-08-17_22.19 > _IMAGE_ > state.spt > > Now you can inspect these. Caution, though! They are binary arrays. The > ascii files will look OK, but they are still not strings! > > $ print x["JmolManifest.txt"].type > bytearray > > $ print x["JmolManifest.txt"] > # Jmol Manifest Zip Format 1.1 > # Created Tue Aug 18 18:22:06 CDT 2015 > # JmolVersion 14.3.16_2015.08.17 2015-08-17 22:19 > state.spt > > [Note that JmolManifest.txt is not run - Jmol only looks for the first > ".spt" file in it and runs that.] > > # turn the byte array into a string: > > s = "" + x["JmolManifest.txt"] > > [change s] > > # write it back into x > > x["JmolManifest.txt"] = s; > > # creating more stuff in x > > x["testing.spt"] = "background red"; > > # write a new PNGJ file > > write VAR x "test2.png" > > UNFORTUNATELY there is a bug there in that very last command. Jmol > currently writes a ZIP file instead of a PNGJ file. > > I've put up at least a Jmol.jar file that corrects that, Rolf. > > http://chemapps.stolaf.edu/jmol/zip/Jmol.jar > > Jmol.___JmolVersion="14.3.16_2015.08.21" > > bug fix: write VAR x "test.png" creates a ZIP file instead of a PNGJ file > when x is from load("test.png",true) > Thank you very much, Bob!
My question aimed at the second task needed for my idea of storing/restoring custom Jmol extensions with a PNGJ file: If the custom system is already loaded it should be able to skip installing itself again in a maybe older version. so it would be necessary to modify it. But your answer actually also helped to achieve the first task of getting the extension into the PNGJ file (see below). The only thing that seems to be missing for the second task is to be able to load PNGJ data from a variable: ==== Load PNGJ from variable ========= x = load("test.png", true); $ load "@x" script ERROR: io error reading string: java.io.FileNotFoundException: string (No such file or directory) ====================================== The following example demonstrates the successful integration of a custom hoverCallback (showing a blue halo) into a PNGJ file, available (temporarily) at "http://www.fli-leibniz.de/~rhuehne/jmol/1deh_custom_state.png": ====== Custom PNGJ Creation ======================================= #------ Jmolscript hover callback implementation --------------- lastAtomIndexHovered = -1; lastHoverUnfinished = false; hoverTimeoutId = ""; function hoverAction(action) { if (hoverTimeoutId != "") { timeout ID @hoverTimeoutId off; hoverTimeoutId = ""; } var switchOff = false; var currentSelection = {selected}; if (action == "end") { if (lastHoverUnfinished) { switchOff = true; } } elseif (action == "start") { if (lastHoverUnfinished) { if (lastAtomIndexHovered != _atomhovered) { switchOff = true; } } } if (switchOff) { if (lastAtomIndexHovered >= 0) { select atomindex=@lastAtomIndexHovered; color halo yellow; halo off; } lastAtomIndexHovered = -1; lastHoverUnfinished = false; } if (_atomhovered >= 0 && action == "start") { lastAtomIndexHovered = _atomhovered; select atomindex=@lastAtomIndexHovered; color halo cyan; halo on; lastHoverUnfinished = true; hoverTimeoutId = "hoverEnd_" + now(); timeout ID @hoverTimeoutId 1.0 "hoverAction('end')"; } select @currentSelection; } set hoverCallback "jmolscript: hoverAction('start');"; #------------------------------------------------------- function buildCustomStateScript { var stateVariables = ["lastAtomIndexHovered", "lastHoverUnfinished", "hoverTimeoutId"]; var stateFunctions = ["hoverAction"]; var stateCommands = ['set hoverCallback "jmolscript: hoverAction(' + "'start');" + '";']; var customStateScript = []; for (var stateVariable IN stateVariables) { customStateScript.push(script("show " + stateVariable)); } for (var stateFunction IN stateFunctions) { customStateScript.push(script("show function " + stateFunction)); } for (var stateCommand IN stateCommands) { customStateScript.push(stateCommand); } return customStateScript.join(); } load =1deh; rotate best; zoom 600; customPNGJ = write("PNGJ"); modifiedState = ("" + customPNGJ["state.spt"]).split(); addOn = 'script /*file*/"$SCRIPT_PATH$customState.spt";'; modifiedState.push(addOn); customPNGJ["state.spt"] = modifiedState.join(); customPNGJ["customState.spt"] = buildCustomStateScript; write VAR customPNGJ "1deh_custom_state.png"; ========================================================== Regards, Rolf -- Rolf Huehne Postdoc Leibniz Institute for Age Research - Fritz Lipmann Institute (FLI) Beutenbergstrasse 11 07745 Jena, Germany Phone: +49 3641 65 6205 Fax: +49 3641 65 6210 E-Mail: rhue...@fli-leibniz.de Website: http://www.fli-leibniz.de Scientific Director: Prof. Dr. K. Lenhard Rudolph Head of Administration: Dr. Daniele Barthel Chairman of Board of Trustees: Dennys Klein VAT No: DE 153 925 464 Register of Associations: No. 230296, Amtsgericht Jena Tax Number: 162/141/08228 ------------------------------------------------------------------------------ _______________________________________________ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users