Menu

#249 jmolscript with zipped data (and xsf file format)

v14
open
nobody
5
2019-09-13
2019-09-10
Eugene
No

Hi, some time ago the ticket related to XSF Grid Data format suport was written, but no positive reaction followed. This format is used wildly by such computational software as crystal14 and wannier90. Here is the link to the ticket: https://sourceforge.net/p/jmol/feature-requests/122/
Since there is no feedback for twelve years I've wrote a tiny converter program, if someone need it you can grab it here:
https://github.com/ladyteam/LADYtools/blob/master/xsf2cube.py
The program works with 3d pereodical structure only but maybe I wrote an extention to work with molecules. Anyway CUBE format (wich is used by GAUSSIAN program) have an option to store atomic numbers and positions, but there is no room for unitcell lattice vectors for periodical structures. It's pity, but there is a trick since Jmol could work with jmolscripts, hence the second stirng of the converted to CUBE file contains all needed crystallographical data, here is example (this is a single string):
jmolscript: load "" {444 555 1} UNITCELL [4.6449562,0.0000000,0.0000000,0.0000000,4.6449562,0.0000000,0.0000000,0.0000000,7.3963378]
OK, everything works fine, except one thing. All these files with isosurface data are completele oversized, hence it would be fine to gzip them and Jmol is smart enought to read gzipped isosurfaces, but not that smart to read jmolscript command from binary file. FINALLY THE QUESTION IS:
Is it possible some day to Jmol recognize if the data are zipped and jmolscript have to read second line after unzipping of content, not before as this is the case at the moment. I'm using Jmol v.14.29.52.

Thank you for reading whole text, and thank you in advance!

Related

Feature Requests: #249

Discussion

  • Eugene

    Eugene - 2019-09-10

    Oops, I'm sorry. Jmolscript is OK. There is the other problem. When I open the CUBE file in Jmol (using open in menu file) only surface is plotted but no atoms, and the surface do not react on offset option, i.e. if I put the command: isosurface cutoff 0.1; isosurface cutoff 0.2; nothing happens. Everything good if I put these commands in console:
    $ load "w90_00001.cube"
    $ isosurface s1 sign cyan yellow cutoff 0.5 "w90_00001.cube" color translucent 0.45
    It would be nice these commands run automaticaly when opening CUBE files in jmol

    Warm wishes

     
    • Bob Hanson

      Bob Hanson - 2019-09-12

      I think if you wanted to, you could load the isosurface first and then use
      that command to load the structure using the APPEND option after SET
      APPENDNEW FALSE.

      Another smart way to proceed would be to write a little script that creates
      a JVXL file for your surface and save it. It will be WAY smaller (100x?
      300x?) and could be packaged as an inline data in a variable:

      *INLINE @varName The isosurface data may be in a variable already. For
      example: x = load("mydata.dat"); isosurface INLINE @x first loads the data
      into the variable x, then displays the isosurface from that data, possibly
      giving the opportunity to peek at the data first. It is advisable to reset
      the variable after use to improve performance, however note that the state
      will only be preserved if the value of the variable is left unchanged. *

      In this way, you could load the variable, extract your script, load the
      structure, and then do the isosurface command whenever you are ready to.
      Just a suggestion.

      Another thing you could do would be to run a script that packages the JVXL
      data and the script in a zip file. (Jmol can read and write ZIP files).
      Then it's just a matter of reading the zip file, using one of the entries
      as a script and the other as the isosurface data.

      I do not recommend leaving it as a cube file.

      Bob

      On Tue, Sep 10, 2019 at 10:58 AM Pedro Roginovicci roginovicci@users.sourceforge.net wrote:

      Oops, I'm sorry. Jmolscript is OK. There is the other problem. When I open
      the CUBE file in Jmol (using open in menu file) only surface is plotted but
      no atoms, and the surface do not react on offset option, i.e. if I put the
      command: isosurface cutoff 0.1; isosurface cutoff 0.2; nothing happens.
      Everything good if I put these commands in console:
      $ load "w90_00001.cube"
      $ isosurface s1 sign cyan yellow cutoff 0.5 "w90_00001.cube" color
      translucent 0.45
      It would be nice these commands run automaticaly when opening CUBE files
      in jmol

      Warm wishes

      Status: open
      Group: v14
      Labels: CUBE isosurface jmolscript XSF
      Created: Tue Sep 10, 2019 03:44 PM UTC by Pedro Roginovicci
      Last Updated: Tue Sep 10, 2019 03:44 PM UTC
      Owner: nobody

      Hi, some time ago the ticket related to XSF Grid Data format suport was
      written, but no positive reaction followed. This format is used wildly by
      such computational software as crystal14 and wannier90. Here is the link to
      the ticket: https://sourceforge.net/p/jmol/feature-requests/122/
      Since there is no feedback for twelve years I've wrote a tiny converter
      program, if someone need it you can grab it here:
      https://github.com/ladyteam/LADYtools/blob/master/xsf2cube.py
      The program works with 3d pereodical structure only but maybe I wrote an
      extention to work with molecules. Anyway CUBE format (wich is used by
      GAUSSIAN program) have an option to store atomic numbers and positions, but
      there is no room for unitcell lattice vectors for periodical structures.
      It's pity, but there is a trick since Jmol could work with jmolscripts,
      hence the second stirng of the converted to CUBE file contains all needed
      crystallographical data, here is example (this is a single string):
      jmolscript: load "" {444 555 1} UNITCELL
      [4.6449562,0.0000000,0.0000000,0.0000000,4.6449562,0.0000000,0.0000000,0.0000000,7.3963378]
      OK, everything works fine, except one thing. All these files with
      isosurface data are completele oversized, hence it would be fine to gzip
      them and Jmol is smart enought to read gzipped isosurfaces, but not that
      smart to read jmolscript command from binary file. FINALLY THE QUESTION IS:
      Is it possible some day to Jmol recognize if the data are zipped and
      jmolscript have to read second line after unzipping of content, not before
      as this is the case at the moment. I'm using Jmol v.14.29.52.

      Thank you for reading whole text, and thank you in advance!

      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/jmol/feature-requests/249/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

      --
      Robert M. Hanson
      Professor 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

       

      Related

      Feature Requests: #249

      • Bob Hanson

        Bob Hanson - 2019-09-12

        forgot to clip the quote; that probably went over.

        I think if you wanted to, you could load the isosurface first and then use
        that command to load the structure using the APPEND option after SET
        APPENDNEW FALSE.

        Another smart way to proceed would be to write a little script that creates
        a JVXL file for your surface and save it. It will be WAY smaller (100x?
        300x?) and could be packaged as an inline data in a variable:

        *INLINE @varName The isosurface data may be in a variable already. For
        example: x = load("mydata.dat"); isosurface INLINE @x first loads the data
        into the variable x, then displays the isosurface from that data, possibly
        giving the opportunity to peek at the data first. It is advisable to reset
        the variable after use to improve performance, however note that the state
        will only be preserved if the value of the variable is left unchanged. *

        In this way, you could load the variable, extract your script, load the
        structure, and then do the isosurface command whenever you are ready to.
        Just a suggestion.

        Another thing you could do would be to run a script that packages the JVXL
        data and the script in a zip file. (Jmol can read and write ZIP files).
        Then it's just a matter of reading the zip file, using one of the entries
        as a script and the other as the isosurface data.

        I do not recommend leaving it as a cube file.

         
        • Eugene

          Eugene - 2019-09-12

          Dear Bob,
          Thank you for the very helpfull answer. Indeed it is possible to extract both atomic position data (into XYZ format) and convert isosurface data into JVXL format, and then write a jmol script file to sequentially load of atomic positions and isosurface data. It seems to work nicely. But one have to always keep in mind, converting into JVXL will lead to lost volumetric CUTOFF parameter, so this parameter should be set up properly before converting to JVXL. Finally it's a little bit complicated way: convert from XSF to CUBE and than split on XYZ, JVXL and make a jmolescript SPT one to load directly with open dialogbox. SPT file is simple like that:

          load "filename.xyz"
          isosurface "filename.jvxl"
          

          Routine, but I wrote script to do the stuff automatically (see below, left here just in a case some one will need it). By the way, is there any way to combain all these three files into one jar or zip in that way it could be opened directly from open dialogbox and the jmolscript inside archive will run automatically?
          But still it's a kind of lack, that CUBE formate do provide atomic numbers and positions wich JMOL ignore, it a kind of sad feeling that JMOL don't completele capable with CUBE format.

          #!/bin/bash
          
          atom_data=(X H He Li Be B C N O F Ne Na Mg Al Si P S Cl Ar K Ca Sc Ti V Cr Mn Fe Co Ni Cu Zn Ga Ge \                                                           
          As Se Br Kr Rb Sr Y Zr Nb Mo Tc Ru Rh Pd Ag Cd In Sn Sb Te I Xe Cs Ba La Ce Pr Nd Pm Sm Eu Gd Tb Dy \                                                          
          Ho Er Tm Yb Lu Hf Ta W Re Os Ir Pt Au Hg Tl Pb Bi Po At Rn Fr Ra Ac Th Pa U Np Pu Am Cm Bk Cf Es Fm \                                                          
          Md No Lr Rf Db Sg Bh Hs Mt Ds Rg Cn Uut Uuq Uup Uuh Uus Uuo)
          
          #temporary jmolscript file for converting isourface in JVXL format
          sptfn=jmolscript_$$".spt"
          
          for i in *.cube; do
          # isosurface jvxl filename
              o=${i%cube}"jvxl"
          # structural data filename
              xyz=${i%cube}"xyz"
          # persistent jmolscript filename
              scriptfn=${i%cube}"spt"
          # write script and do isosurface conversion
              echo "load \"$i\"" > $sptfn
              echo "write isosurface \"$o\"" >> $sptfn
          
              echo "Converting file $i"
              /opt/jmol/jmol.sh -ions $sptfn
              rm $sptfn
          # Read atomic data from zipped cube file and write in xyz format
              nat=`zcat wannier90_00002.cube | head -n3 | tail -n1 | awk '{print($1)}'`
              ((nl=nat+6))
              echo $nat > $xyz
              zcat wannier90_00002.cube | head -n2 | tail -n1 | awk -F";" '{print $1}' >> $xyz
              zcat wannier90_00002.cube | head -n $nl | tail -n $nat | \
              awk -v var="${atom_data[*]}" 'BEGIN{split(var,list," ");a2b=0.52917721092}{printf("%3s % 10.6f % 10.6f % 10.6f\n", list[$1+1],$3*a2b,$4*a2b,$5*a2b)}' >> $xyz
          # Write jmolscript file
              echo "load \"$xyz\"" > $scriptfn
              echo "isosurface s1 sign cyan yellow cutoff 1 \"$o\" color translucent 0.45" >> $scriptfn
          done
          
           
          • Bob Hanson

            Bob Hanson - 2019-09-12

            Exactly! You can also, if you prepare a zip file, have all the data and
            script in there.

             
            • Eugene

              Eugene - 2019-09-12

              But for some reason zip can't be loaded correctly, first I zip all three files:
              zip file.zip file.spt file.xyz file.jvxl
              The content of file.spt is:

              load "file.xyz"
              isosurface "file.jvxl"
              

              then I run in Jmol console

              load "file.zip" 
              

              and finally I have error message:

              Unrecognized file format for file.zip|file.spt
              load "file.xyz"
              isosurface "file.jvxl"
              Maybe I have to put some other command in JMOL console to load script in side zip?

               
            • Eugene

              Eugene - 2019-09-12

              Oh, after writing zip with JMOL console write ZIP "filename.zip" command I gues I've found, that additional JmolManifest.txt file is need with script filename inside. At least it working. Thank you Bob!

               
            • Eugene

              Eugene - 2019-09-13

              Finally the best way to convert CUBE to JVXL format and save to zip is to use jmolscript by invoking Jmol.jar. The final version of convers could be downloaded here (for cube to zip, bash script):
              https://github.com/ladyteam/LADYtools/blob/master/cube2jvxl.sh
              and here (XSF format to CUBE, python3 code):
              https://github.com/ladyteam/LADYtools/blob/master/xsf2cube.py

              Hope some one find these converters useful.

              I'm really appreciated for your helpful advices, thank you so much!
              p.s. Tested with Jmol v14.29.52

               
  • Angel Herraez

    Angel Herraez - 2019-09-10

    Hello, Pedro
    I cannot be sure about ypur problem since I do not use those formats, but maybe investigating about the MANIFEST file inside a zipped file you can find a solution.
    https://chemapps.stolaf.edu/jmol/docs/#loadzip/jarfilesandjmolmanifest

    "Jmol will look for a file within the collection with the name JmolManifest and follow the directives within it. These directives may be as simple as a list of files to be loaded, one filename per line (which will be read in the order listed)"

    One of those files might be a script for Jmol
    Good luck!

     
    • Eugene

      Eugene - 2019-09-11

      Dear Angel, I'm deeply sorry for inconvinience because my first message was not correct, and I didn't found the way how to edit original message, hence I've report about my mistake in first answer to the original message (see above). In fact the problem are not in the zip, rather than how CUBE format opens in Jmol. Let me explain (in short) about the CUBE format. There are two sections in the file, first one related to atomic positions and the second section is isosurface related. When I open CUBE file by open dialog the actual command which transfered to Jmol driver is:
      $ isosurface sign red blue "wannier.cube"
      Thus isosurface is loaded but atoms do not. Atoms could be loaded manually by running the command:
      $ load "wannier.cube"

      What I'm trying to say is that atoms not loaded because load command is missing. I believe it is very easy to implement loading of the atoms and isosurfaces by opening the CUBE file from open dialogbox. I am able to share all necesary information and examples.

      Friendly

       

      Last edit: Eugene 2019-09-13

Log in to post a comment.