#163 Use relative address in state files


On one computer, a file, 1edn.pdb, was opened. The state was saved as 1edn.spt in the same directory as 1edn.pdb. Both files were transferred to the same directory on another computer. On that computer, the state file gave an error because the directory structure was different than on the original computer. Can the state file be changed to use a relative address for the original file? Then, I could transfer state files from office to classroom and not have to worry as much about having the same directory structure.


  • Bob Hanson

    Bob Hanson - 2009-08-23

    So far I haven't figured out a simple way to do this. Suggestions welcome.

  • Bob Hanson

    Bob Hanson - 2009-08-24

    quick work-arounds ---

    1) save files on a flash drive, and check that both machines assign the same drive letter to the drive

    2) save files on the web.

    3) edit the spt files to remove the C:/xxx/xxx/ part of the file directory.

    4) write a small script that first reads the script file into a variable using the load() function, makes the character replacements using replace(), then runs the script using the script() function rather than the script command.

    5) load pdb files using the "=" default RCSB prefix. (load =1edn) This may be a bit slower, but it ensures getting the same file at least.

    I know -- not totally satisfying. But any of these might work. The problem is figuring out how to specify the correct working directory, and whether that change should be in the state file or in the reading of it.


  • Christopher King

    One approach would be to compare the paths of the script and the data files.
    How about this?
    If the operating system is windows then
    Are the two files on the same drive?
    If no, do nothing.
    If yes, does the data file’s path begin with the script file’s path?
    Script in C:\Work\ , data in C:\Work\Data\.
    If yes, remove the script’s path from the start of the data file’s path.
    That turns the data file’s path into a relative path.
    Data file path: data\ If no, find the relative path.
    Script in C:\Work\Figures\; Data in C:\Work\Data\ Remove the drive from the path strings
    Script in \Work\Figures\; Data in \Work\Data\ Is the remaining top-level directory present in both strings?
    If yes, remove it
    Script in Figures\; Data in Data\ Repeat until the common top-level directories have been removed
    If no, add “..\” to the data file’s path for each remaining directory in the script file’s path
    Data file’s path becomes “..\Figures\”
    Now you’ve got a relative path to the data file from the script file’s directory. (The ..\ means go up one directory level.)

  • Bob Hanson

    Bob Hanson - 2009-09-03

    OK, this is done. See Jmol 11.9.2 (http://chemapps.stolaf.edu/jmol/docs/examples-11/Jmol-11.zip and http://chemapps.stolaf.edu/jmol/docs/examples-11/new.htm\)

    There are two new options for SCRIPT and WRITE STATE commands. These are LOCALPATH and REMOTEPATH. Each takes an argument in quotes. Setting the LOCALPATH replaces any file reference in the script, either on reading or writing, to that path; setting REMOTEPATH does the same for anything with an "http" "https" or "ftp" prefix. So, for example, if you have a state that refers to files on a local file system and now you want to run it but load files from a different system, you would do something like this:

    script LOCALPATH "" "myfile.spt"

    That says, "whatever the local file path to a file accessed by this script command, (in LOAD or SCRIPT commands, for example), make them come from the current directory. (This might be on a web host or another local machine.)

    script LOCALPATH "data" "myfile.spt"

    would set all local file references to data/....

    If the file reference already contains .../data/... in its path, then it is simply truncated to data/....

    Same for REMOTEPATH, but here we are changing only the remote file references. So, for example, if you had used

    load =1crn

    and then saved the script as "myfile.spt", that script will have in it:

    load "http://rcsb.org/pdb/files/1crn.pdb"

    So, say now I have that file on disk and don't want to go back to the server for it. Then I just say:

    script REMOTEPATH "" "myfile.spt"

    This will now read 1crn.pdb from the local drive but otherwise run the same.

    Bob Hanson

  • Bob Hanson

    Bob Hanson - 2009-09-03
    • status: open --> closed
  • Bob Hanson

    Bob Hanson - 2009-09-03

    one more comment. This works by finding /*file*/"http://rcsb.org/pdb/files/1crn.pdb" in a state script. If you had your own script, you could do the same; just make sure you have /*file*/ immediately preceding a double-quoted file name.


Log in to post a comment.