Menu

#262 Feed a Jmol script with input arguments from command line

v14
open
nobody
Normal
2023-05-09
2023-05-08
Federico
No

Haven't found any documentation regarding how to do it, but is there any way to input values into the script as command line arguments, such that they can be used (like the variable _arguments_ array, when invoking a Jmol function) in the script? I mean in a call like this:

$ ./jmol.sh --nodisplay --script ~/.jmol/macros/myscript.spt

Discussion

  • Bob Hanson

    Bob Hanson - 2023-05-08

    Interesting idea. An alternative would be to assign your variables in a script prior to the -s script call using

    -J "v1='test';v2='now'" -s myscript.spt

    and then use those variables in the script.

    Not quite the same, I realize.

    Bob

     
  • Federico

    Federico - 2023-05-08

    It does the job, but yes, the variables names are needed when calling the script.

     

    Last edit: Federico 2023-05-08
    • Angel Herraez

      Angel Herraez - 2023-05-09

      Hi Federico

      You are right, but anyway how would you set the script file for your intended command line parameters? I think there will always be the need to provide data in a variable.

      How about using an array variable?

      -J "arg = ['oxygen', 'pink']" -s myscript.spt

      and then in myscript.spt use
      arg[1] etc arg[2] etc , like this:

      select @{arg[1]}; color @{arg[2]};

       
      • Federico

        Federico - 2023-05-09

        Something like the positional scheme in bash would make it. Your array variable is what I had in mind, but in the end you need to reserve arg for such purpose in your scripts (needs documentation when you share them). @hansonr's solution with the _arguments variable is similar, only that now this variable is the one for all. This feature will help in batch processing.

         

        Last edit: Federico 2023-05-09
  • Bob Hanson

    Bob Hanson - 2023-05-09

    Jmol.___JmolVersion="16.1.14" // (swingJS) also 16.1.13 (legacy)

    new feature: Jmol application -A --scriptarguments flag

    • used in conjunction with -s --script
    • allows adding _arguments array variable to a script file on the command line
    • example:

      jmol -s "test.spt" -A "2,3,4"

    where test.spt is

     print "" + _arguments[1] + " and " + _arguments[2] + " and " + _arguments[3]
    

    result is

     2 and 3 and 4
    
     

Log in to post a comment.

MongoDB Logo MongoDB