Menu

Isosurfaces for cube file loaded with load data

Plank
2015-04-27
2015-04-28
  • Plank

    Plank - 2015-04-27

    I am trying to load a cube file with load data and displaying isosurfaces. I had a working script where I could read from a file that was present on the webserver which looked like the following:

    var stateFile = "path/to/file/on/server/file.cube"
    var script = "set echo top left;font echo 16;echo \"Reading...\";refresh;";
    script += "load "+stateFile+";";
    script += "isosurface pos .001 '"+stateFile+"';color isosurface translucent;";
    script += "isosurface neg -.001 '"+stateFile+"';color isosurface translucent;";
    Jmol.script(resultsApplet, script);
    

    Unfortunately I can no longer save files on the webserver and so have to retrieve the cube files through an API call. As such I will have to use the 'load data' syntax to use the file as loaded in the variable directly.
    In my javascript I thus have a variable 'result' that contains the cube file I want to display. With the following script I can split it on newlines and add it explicitly to the jsmol script like so:

    var script = 'load data "myData"\n';
    script += result;
    script += 'end "myData"\n';
    Jmol.script(resultsApplet, script);
    

    This works but I now do not know how to add isosurfaces since I no longer can reference a filename like in the first script. How would I add isosurfaces in the latter case?

     
    • Bob Hanson

      Bob Hanson - 2015-04-28

      Explain what you mean by "using an API". How is that different from just
      calling that same service within the isosurface command?

       
  • Plank

    Plank - 2015-04-28

    Ok I will try to elaborate. The first script I posted works fine and reads a cube file directly from disk on the webserver. However I need to replicate this script that does not take the input from file but rather from a javascript variable. I will retrieve the file that is to be plotted from another server through a HTTP get request through an ajax call like so:

    $.ajax({
        type: "GET",
        url: "/file/path/on/server/file.cube"?view=read",
        success:function(result) {
            callbackSuccess(result);
        },
    });
    

    The variable result now contains the contents of the file that I want to display in jsmol. I was hoping to adapt the original script to use this variable in stead of the file on disk with the following:

     var stateFile = result; // result contains the contents of the file
     script = "set echo top left;font echo 16;echo \"Reading...\";refresh;\n";
     script += 'load data "myData";\n';
     script += stateFile;
     script += 'end "myData"\n';
     script += "isosurface pos .001 '"+stateFile+"';color isosurface translucent;";
     script += "isosurface neg -.001 '"+stateFile+"';color isosurface translucent;";
     script += "selectionHalos on;select "+data.atomNo+";javascript deleteStateFileFromServer();";
    

    However this does not work and the applet never displays the cube file. I am not sure how the isosurface command works but I think that is the problem now. In the original script the isosurface command also took the stateFile variable which in that case contained the path to the file on disk. But in the second script there is no file on disk and so I am not sure how I should adapt the isosurface commands accordingly.

    Hopefully this clears up the situation.

    I thank you for your time

     
    • Bob Hanson

      Bob Hanson - 2015-04-28

      Your syntax with the "neg" and "pos" is very very old. We don't generally
      do that anymore. Instead we just use two-color isosurface using the PHASE
      keyword

      I don't see why you couldn't do this:

      isosurface cutoff 0.001 phase "
      http://wherever.server.edu/file.cube?view=read"

      There is no need for the data statement; in that code you sent you weren't
      using it anyway. I would never recommend inserting a full CUBE file into a
      script. That's not going to perform well.

      Bob

      On Tue, Apr 28, 2015 at 12:27 PM, Plank sphuber@users.sf.net wrote:

      Ok I will try to elaborate. The first script I posted works fine and reads
      a cube file directly from disk on the webserver. However I need to
      replicate this script that does not take the input from file but rather
      from a javascript variable. I will retrieve the file that is to be plotted
      from another server through a HTTP get request through an ajax call like so:

      $.ajax({
      type: "GET",
      url: "/file/path/on/server/file.cube"?view=read",
      success:function(result) {
      callbackSuccess(result);
      },});

      The variable result now contains the contents of the file that I want to
      display in jsmol. I was hoping to adapt the original script to use this
      variable in stead of the file on disk with the following:

      var stateFile = result; // result contains the contents of the file
      script = "set echo top left;font echo 16;echo \"Reading...\";refresh;\n";
      script += 'load data "myData";\n';
      script += stateFile;
      script += 'end "myData"\n';
      script += "isosurface pos .001 '"+stateFile+"';color isosurface translucent;";
      script += "isosurface neg -.001 '"+stateFile+"';color isosurface translucent;";
      script += "selectionHalos on;select "+data.atomNo+";javascript deleteStateFileFromServer();";

      However this does not work and the applet never displays the cube file. I
      am not sure how the isosurface command works but I think that is the
      problem now. In the original script the isosurface command also took the
      stateFile variable which in that case contained the path to the file on
      disk. But in the second script there is no file on disk and so I am not
      sure how I should adapt the isosurface commands accordingly.

      Hopefully this clears up the situation.

      I thank you for your time

      Isosurfaces for cube file loaded with load data
      https://sourceforge.net/p/jsmol/discussion/general/thread/4f88ece4/?limit=25#165e


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/jsmol/discussion/general/

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

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

       
      • Plank

        Plank - 2015-04-28

        Ok I have tried to insert the http get request directly into the isosurface command but that does not seem to work. Probably I am doing something wrong but I am having a hard time debugging what that might be.
        Right now I use the javascript:

        var scr = 'isosurface cutoff 0.001 phase "https://server.edu/path/file/state.cube?view=read"';
        Jmol.script(resultsApplet, scr);
        

        The applet starts but just shows "loading..." for ever in the upper left corner. Nothing is being loaded though and no errors are thrown. I have verified that the url to the file is correct and will download the file. Am I missing something?

         
        • Bob Hanson

          Bob Hanson - 2015-04-28

          Could be your page is not https. Should be some JavaScript errors there.
          Also, if Jmol caught the error, you could use

          resultsApplet._showInfo(true)

          and see if there is something in the Jmol console.

          On Tue, Apr 28, 2015 at 4:21 PM, Plank sphuber@users.sf.net wrote:

          Ok I have tried to insert the http get request directly into the
          isosurface command but that does not seem to work. Probably I am doing
          something wrong but I am having a hard time debugging what that might be.
          Right now I use the javascript:

          var scr = 'isosurface cutoff 0.001 phase "https://server.edu/path/file/state.cube?view=read"';Jmol.script(resultsApplet, scr);

          The applet starts but just shows "loading..." for ever in the upper left
          corner. Nothing is being loaded though and no errors are thrown. I have
          verified that the url to the file is correct and will download the file. Am
          I missing something?


          Isosurfaces for cube file loaded with load data
          https://sourceforge.net/p/jsmol/discussion/general/thread/4f88ece4/?limit=25#165e/9f08/4dd4


          Sent from sourceforge.net because you indicated interest in
          https://sourceforge.net/p/jsmol/discussion/general/

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

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

           

Log in to post a comment.