Re: [Jmol-users] Dissect PNGJ content?
The presence of TRUE as a parameter in Jmol just distinguishes one form of a function from another, both with the same name. So in the case of split, we have: split()split along line boundaries; same as split(\n) split(x) split at x, removing that character; x could be any string split(, TRUE) these two specific parameters indicate the data are in CSV table format split(\t, TRUE) these two specific parameters indicate the data are in tab-separated table format I generally prefer to stick with one function name rather than introducing a bunch of somewhat related ones. That way all the options appear under one heading. These could have been named splitLines, splitString, splitCSV, and splitTabSeparated, I suppose. Every function is different, of course... Bob -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
Thanks, Rolf. I should start a new thread. There are two additional split functions at http://chemapps.stolaf.edu/jmol/docs/index.htm?ver=14.2 , as compared to the split function in your link, and these two contain the “true” parameter. However, the documentation is kind of spare about the need and use for “true” in these additional split functions. I’ll play around with it and start a new thread when I get stuck. Matt On Aug 22, 2015, at 1:42 PM, Rolf Huehne rhue...@fli-leibniz.demailto:rhue...@fli-leibniz.de wrote: Am 22.08.15 um 17:23 schrieb Kubasik, Matthew A.: Thanks, Bob, for this. Can you clarify the purpose of “true”, as in: var x = load(“filename”, TRUE) I would like to learn when is it necessary. Your example uses “true” for .png but not for .cif. The help page shows the TRUE flag showing up elsewhere, as in the function x = y.split(, TRUE) I am uncertain of how to use “true properly. The meaning of true as a parameter depends on the specific command/function. You should look up the documentation for the commands/functions you want to use. http://jena3d.fli-leibniz.de/doc/jmol_scripting/index.htm#functions contains for 'x = load(filename,TRUE)': Adding a second parameter TRUE creates a binary associative array variable x that contains the contents of the file. Data are stored as raw bytes (but will appear as a string in the PRINT command). If the file is a standard file, the key _DATA_ will hold the file data. If the file is a PNGJ file, the key _IMAGE_ will hold the image data and additional files will be keyed by file name. If the file is a zip file, the files will be keyed by file name, but no _IMAGE_ key will be present (presumably). Note that x = load(myfile) without TRUE loads just the file list for PNGJ or ZIP files, not the actual data. Regards, Rolf -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
Am 22.08.15 um 17:23 schrieb Kubasik, Matthew A.: Thanks, Bob, for this. Can you clarify the purpose of “true”, as in: var x = load(“filename”, TRUE) I would like to learn when is it necessary. Your example uses “true” for .png but not for .cif. The help page shows the TRUE flag showing up elsewhere, as in the function x = y.split(, TRUE) I am uncertain of how to use “true properly. The meaning of true as a parameter depends on the specific command/function. You should look up the documentation for the commands/functions you want to use. http://jena3d.fli-leibniz.de/doc/jmol_scripting/index.htm#functions contains for 'x = load(filename,TRUE)': Adding a second parameter TRUE creates a binary associative array variable x that contains the contents of the file. Data are stored as raw bytes (but will appear as a string in the PRINT command). If the file is a standard file, the key _DATA_ will hold the file data. If the file is a PNGJ file, the key _IMAGE_ will hold the image data and additional files will be keyed by file name. If the file is a zip file, the files will be keyed by file name, but no _IMAGE_ key will be present (presumably). Note that x = load(myfile) without TRUE loads just the file list for PNGJ or ZIP files, not the actual data. Regards, Rolf -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
Thanks, Bob, for this. Can you clarify the purpose of “true”, as in: var x = load(“filename”, TRUE) I would like to learn when is it necessary. Your example uses “true” for .png but not for .cif. The help page shows the TRUE flag showing up elsewhere, as in the function x = y.split(, TRUE) I am uncertain of how to use “true properly. Matt On Aug 22, 2015, at 12:51 AM, Robert Hanson hans...@stolaf.edumailto:hans...@stolaf.edu wrote: http://sourceforge.net/projects/jmol/files/Jmol-beta/Jmol%2014.3/Jmol%2014.3.16/Jmol-14.3.16_2015.08.21-binary.zip/download Jmol.___JmolVersion=14.3.16_2015.08.21 new feature: load var x -- same as load @x -- similar in syntax to write var x t.png -- example: var x = load(quartz.cif) load var x {1 1 1} bug fix: creating and running and saving binary hash from PNGJ fails -- allows creating an associative binary array from a PNGJ file then modifying it and loading that variable then saving it as a new PNGJ file -- initial PNGJ file is not necessary if binary array x is created first -- example: var x = load(test.png,true) load @x write test2.png as PNGJ bug fix: hover callback is not supposed to be stopped with HOVER OFF bug fix: atom.sx and atom.syhttp://atom.sy/ and atom.szhttp://atom.sz/ report incorrectly when antialiasing is on bug fix: write VAR x test.png creates a ZIP file instead of a PNGJ file when x is from load(test.png,true) bug fix: write test.png as PNGJ (without initial quotes) fails comments: OK, that wasn't so bad. Thank you, Rolf, for suggesting this. It is a nice complement to write var x. This completes the capability for Jmol or JSmol to read, modify, load, and save PNGJ and ZIP files. 1) Reading a PNGJ or ZIP file into a variable using TRUE to indicate binary file: x = load(test.png, TRUE) # [x is a binary associative array] print x.keys $_BINARY_$ JmolManifest.txt Jmol_version_14.3.16_2015.08.21__2015-08-21_09.06 _IMAGE_ http___cactus.nci.nih.gov_chemical_structure_caffeine_file_format_sdf_get3d_True state.spt where $_BINARY_$ indicates that entries are byte arrays. and _IMAGE_ is the PNG image, indicating this is from a PNGJ file 2) modifying that file if desired # coerce to string: s = + x[state.spt] # ...modify here... # replace state.spt in PNGJ file data x[state.spt] = s # Or, for example, adding an image that will be used for an optional background image x = load(test.png,true) # a standard binary associative array will have just two keys, $BINARY$ and _DATA_ # only PNGJ has _IMAGE_ x[z.jpg] = load(z.jpg,true)._DATA_ print x.keys write var x test3.png sometime later... load test3.png background image test3.png|z.jpg 3) write to a new PNGJ file write var x test2.png 4) optionally, load that PNGJ data directly from the variable, perhaps to see that the modifications are correct: load var x (new syntax; same as older load @x) Note that both of these syntaxes work with standard string file data and can be extended with options: x = load(quartz.cif) load var x {1 1 1} Bob -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.netmailto:Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
*http://sourceforge.net/projects/jmol/files/Jmol-beta/Jmol%2014.3/Jmol%2014.3.16/Jmol-14.3.16_2015.08.21-binary.zip/download http://sourceforge.net/projects/jmol/files/Jmol-beta/Jmol%2014.3/Jmol%2014.3.16/Jmol-14.3.16_2015.08.21-binary.zip/download* Jmol.___JmolVersion=14.3.16_2015.08.21 new feature: load var x -- same as load @x -- similar in syntax to write var x t.png -- example: var x = load(quartz.cif) load var x {1 1 1} bug fix: creating and running and saving binary hash from PNGJ fails -- allows creating an associative binary array from a PNGJ file then modifying it and loading that variable then saving it as a new PNGJ file -- initial PNGJ file is not necessary if binary array x is created first -- example: var x = load(test.png,true) load @x write test2.png as PNGJ bug fix: hover callback is not supposed to be stopped with HOVER OFF bug fix: atom.sx and atom.sy and atom.sz report incorrectly when antialiasing is on bug fix: write VAR x test.png creates a ZIP file instead of a PNGJ file when x is from load(test.png,true) bug fix: write test.png as PNGJ (without initial quotes) fails comments: OK, that wasn't so bad. Thank you, Rolf, for suggesting this. It is a nice complement to write var x. This completes the capability for Jmol or JSmol to read, modify, load, and save PNGJ and ZIP files. 1) Reading a PNGJ or ZIP file into a variable using TRUE to indicate binary file: x = load(test.png, TRUE) # [x is a binary associative array] print x.keys *$_BINARY_$JmolManifest.txtJmol_version_14.3.16_2015.08.21__2015-08-21_09.06_IMAGE_http___cactus.nci.nih.gov_chemical_structure_caffeine_file_format_sdf_get3d_Truestate.spt* where $_BINARY_$ indicates that entries are byte arrays. and _IMAGE_ is the PNG image, indicating this is from a PNGJ file 2) modifying that file if desired # coerce to string: s = + x[state.spt] # ...modify here... # replace state.spt in PNGJ file data x[state.spt] = s # Or, for example, adding an image that will be used for an optional background image x = load(test.png,true) # a standard binary associative array will have just two keys, $BINARY$ and _DATA_ # only PNGJ has _IMAGE_ x[z.jpg] = load(z.jpg,true)._DATA_ print x.keys write var x test3.png sometime later... load test3.png background image test3.png|z.jpg 3) write to a new PNGJ file write var x test2.png 4) optionally, load that PNGJ data directly from the variable, perhaps to see that the modifications are correct: load var x (new syntax; same as older *load @x*) Note that both of these syntaxes work with standard string file data and can be extended with options: x = load(quartz.cif) load var x {1 1 1} Bob -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
[Jmol-users] Dissect PNGJ content?
Hi all, because a PNGJ file is actually a combination of a PNG and a ZIP file I assumed that it would be treated like a ZIP or JAR file by the commands 'x = getProperty(fileContents, test.png)' and 'x = getProperty(fileContents, test.png|JmolManifest)'. This would mean to get a content listing or the content of the 'JmolManifest' file inside the PNGJ file. But in Jmol 14.3.16 I get with both commands just the content of the model file. Q: Is there any other way to dissect a PNGJ file within Jmol into individual subfiles or getting the content info? 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
Re: [Jmol-users] Dissect PNGJ content?
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) -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
ps -- Note that you can display the file listing of a PNGJ or ZIP file using show file xxx Bob -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
On 08/21/2015 04:17 PM, Robert Hanson wrote: ps -- Note that you can display the file listing of a PNGJ or ZIP file using show file xxx Thanks for the reminder,Bob. I thought that 'show' could do it but forgot about the 'file' keyword. So one can get a file name array like this: fileList = script('show file test.png').trim().split(); show fileList; fileList = [ state.spt,JmolManifest.txt,Jmol_version_14.3.16_2015.08.17__2015-08-17_22.19 ] 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
Re: [Jmol-users] Dissect PNGJ content?
Am 21.08.15 um 22:23 schrieb Robert Hanson: On Fri, Aug 21, 2015 at 1:51 PM, Rolf Huehne rhue...@fli-leibniz.de mailto:rhue...@fli-leibniz.de wrote: 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) == I think the problem there would be figuring out a way to save that in a state. It could be done, but it would be pretty ugly -- all of that in base64? Bob, I don't understand why there should be needed an extra encoding. The following things are working: 1) load test.png; 2) x = load(test.png, true); write VAR x test2.png; load test2.png; So what would be different if the write step in 2) would be omitted and the data loaded instead from variable 'x'? I thought the current error would just occur because of misinterpretation of the variable content. Regards, Rolf -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
Exactly. And you could also use: fileList = show(file 'test.png').lines.find() the find() function strips out empty lines along the lines of the trim() function you are using there. -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
On Fri, Aug 21, 2015 at 1:51 PM, Rolf Huehne rhue...@fli-leibniz.de wrote: 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) == I think the problem there would be figuring out a way to save that in a state. It could be done, but it would be pretty ugly -- all of that in base64? Bob -- Robert M. Hanson Larson-Anderson Professor of Chemistry Chair, Department of Chemistry St. Olaf College Northfield, MN http://www.stolaf.edu/people/hansonr 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 -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users
Re: [Jmol-users] Dissect PNGJ content?
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)
Re: [Jmol-users] Dissect PNGJ content?
I have to make sure that a state can be saved. This means that all information leading to that state must be available. Typically the way this is done is to re-read a data file on its way to the ZIP part of the PNGJ output stream. This involves all data files and the state script. When a model is loaded from a variable, we have to create and maintain a data structure to hold that model data so that when/if a PNGJ file is created, we have it on hand -- it was never in a file, and Jmol does not lay down temporary files. We recreate that data structure in the state as part of a LOAD DATA END command. Now, if you in memory only are creating binary data structures and loading them, then these will need to be cached and restored in their entirety. That's the issue. It's not that we couldn't *load* the data. The issue would be how to *save* it again. But I can think about it. By the way, load xxx.png doesn't really use the LOAD command -- it switches to the SCRIPT command, runs the state.spt script, which then loads files from the (cached) PNGJ data. So perhaps that is the answer to my own question. In some ways this might be like how we read data in JSmol from drag-dropped files -- we don't get the filename; we only get the byte stream. OK, so that might work... Bob -- ___ Jmol-users mailing list Jmol-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-users