Behavior of "cd" when executed through a script

Dear ChimeraX team, I have a series of scripts that contain a “cd” statement to set the working directory. I execute the scripts (which opens a model and map and colors the map). I then manually adjust the orientation and threshold and want to save a picture with “save map.png” (I want this png tp be saved in the folder that I set with the script). I have noticed that in this scenario ChimeraX has “forgotten” the cd statement from the script file and has fallen back to default working directory (or the last working directory manually set in the session before I exectuted my script). At least for me it would be more convenient and logical if the working directory can be set and maintained after habing executed a script. Note: if I don’t execute the script by double clicking but by copy/paste, the working directory is correctly maintained. Would be great if the behavior could be adjusted 😊 Many thanks and best wishes, Matthias

Hi Matthias, When you open a ChimeraX command file (.cxc) ChimeraX changes the current directory to the directory that the script is in, and then when the script ends it changes the current directory back to the original current directory. This is a feature. It allows one command script in a directory to call another command script in the same directory without having to specify a path to that script (e.g. "open script2.cxc"), and when the script ends you are in the original directory (e.g. the directory with some data files). I think the way you are trying to use it is unusual. I guess there could be an open command option that lets you tell it not to restore, or maybe not set or restore the directory. This sound like something no one but you would ever use, so I can't say it is too likely we would add that option. I'm also a bit baffled why you are changing the current directory in a script file. If you have a command script that is specific to a set of data files I think it is most common to put the script file in the same directory as those data files. And if scripts and data are in a directory, it is most common that you change to that directory in ChimeraX (cd /where/my/data/is) or you start ChimeraX in that directory (usually on Linux from a shell). Tom
On May 27, 2024, at 6:49 AM, Vorländer,Matthias Kopano via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear ChimeraX team,
I have a series of scripts that contain a “cd” statement to set the working directory. I execute the scripts (which opens a model and map and colors the map). I then manually adjust the orientation and threshold and want to save a picture with “save map.png” (I want this png tp be saved in the folder that I set with the script). I have noticed that in this scenario ChimeraX has “forgotten” the cd statement from the script file and has fallen back to default working directory (or the last working directory manually set in the session before I exectuted my script). At least for me it would be more convenient and logical if the working directory can be set and maintained after habing executed a script. Note: if I don’t execute the script by double clicking but by copy/paste, the working directory is correctly maintained. Would be great if the behavior could be adjusted 😊
Many thanks and best wishes, Matthias _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/

Hi Tom, Thanks for the reply. The exact use case was to make many entry images for EMDB deposition, where the maps and models for EMDB were organised in individual folders. The advantage of having cd in the script is that I can run the script to load the data, quickly interactively change the scene, and save the image with a simple command ("save map.png") without having to worry about file paths. In practice it's faster to just launch another script that contains a "close all" statement at the beginning with ChimeraX still open then to close and re-open ChimeraX. I realise that this might be a special way to use it, but by analogy to how the cd command works in for example bash scripts I was surprised that it automatically changes back to another directory when the script is completed without receiving another cd command. Anyhow, thanks for the clarification and I can certainly work around this. Best wishes, Matthias Sent from Outlook for Android<https://aka.ms/AAb9ysg> ________________________________ From: Tom Goddard <goddard@sonic.net> Sent: Wednesday, May 29, 2024 2:48:39 AM To: Vorländer,Matthias Kopano <matthias.vorlaender@imp.ac.at> Cc: ChimeraX-users@cgl.ucsf.edu <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] Behavior of "cd" when executed through a script Hi Matthias, When you open a ChimeraX command file (.cxc) ChimeraX changes the current directory to the directory that the script is in, and then when the script ends it changes the current directory back to the original current directory. This is a feature. It allows one command script in a directory to call another command script in the same directory without having to specify a path to that script (e.g. "open script2.cxc"), and when the script ends you are in the original directory (e.g. the directory with some data files). I think the way you are trying to use it is unusual. I guess there could be an open command option that lets you tell it not to restore, or maybe not set or restore the directory. This sound like something no one but you would ever use, so I can't say it is too likely we would add that option. I'm also a bit baffled why you are changing the current directory in a script file. If you have a command script that is specific to a set of data files I think it is most common to put the script file in the same directory as those data files. And if scripts and data are in a directory, it is most common that you change to that directory in ChimeraX (cd /where/my/data/is) or you start ChimeraX in that directory (usually on Linux from a shell). Tom On May 27, 2024, at 6:49 AM, Vorländer,Matthias Kopano via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote: Dear ChimeraX team, I have a series of scripts that contain a “cd” statement to set the working directory. I execute the scripts (which opens a model and map and colors the map). I then manually adjust the orientation and threshold and want to save a picture with “save map.png” (I want this png tp be saved in the folder that I set with the script). I have noticed that in this scenario ChimeraX has “forgotten” the cd statement from the script file and has fallen back to default working directory (or the last working directory manually set in the session before I exectuted my script). At least for me it would be more convenient and logical if the working directory can be set and maintained after habing executed a script. Note: if I don’t execute the script by double clicking but by copy/paste, the working directory is correctly maintained. Would be great if the behavior could be adjusted 😊 Many thanks and best wishes, Matthias _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu<mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/

Hi Matthias, It is hard for me to advise you with the limited details you provide. I understand you have data in many different directories and want to save images in each of those directories, and you want to hand adjust each of those images. I gather it is tedious to go to each of those directories. But how did you get the path to each of those directories into a command script -- that would be equally tedious if you hand typed all those paths into scripts. So I guess you actually automatically generated the command scripts somehow. If that is the case then maybe you want add to the auto-generated script something like alias si cd /path/to/this/scripts/data ; save map.png This defines a new command "si" that saves your image, so after you run the script and adjust the appearance you can just type command "si" to save the image with the data. The ChimeraX behaviour with command scripts is just like Unix bash scripts. If you make a bash script that has in it a "cd" command and you execute it, the current directory in your shell where you executed does not change. The bash script is executed in its own subshell and the cd only happens in the subshell which is closed when the script completes. Tom
On May 28, 2024, at 11:07 PM, Vorländer,Matthias Kopano via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi Tom,
Thanks for the reply. The exact use case was to make many entry images for EMDB deposition, where the maps and models for EMDB were organised in individual folders. The advantage of having cd in the script is that I can run the script to load the data, quickly interactively change the scene, and save the image with a simple command ("save map.png") without having to worry about file paths. In practice it's faster to just launch another script that contains a "close all" statement at the beginning with ChimeraX still open then to close and re-open ChimeraX. I realise that this might be a special way to use it, but by analogy to how the cd command works in for example bash scripts I was surprised that it automatically changes back to another directory when the script is completed without receiving another cd command. Anyhow, thanks for the clarification and I can certainly work around this.
Best wishes, Matthias
Sent from Outlook for Android <https://aka.ms/AAb9ysg> From: Tom Goddard <goddard@sonic.net> Sent: Wednesday, May 29, 2024 2:48:39 AM To: Vorländer,Matthias Kopano <matthias.vorlaender@imp.ac.at> Cc: ChimeraX-users@cgl.ucsf.edu <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] Behavior of "cd" when executed through a script
Hi Matthias,
When you open a ChimeraX command file (.cxc) ChimeraX changes the current directory to the directory that the script is in, and then when the script ends it changes the current directory back to the original current directory. This is a feature. It allows one command script in a directory to call another command script in the same directory without having to specify a path to that script (e.g. "open script2.cxc"), and when the script ends you are in the original directory (e.g. the directory with some data files).
I think the way you are trying to use it is unusual. I guess there could be an open command option that lets you tell it not to restore, or maybe not set or restore the directory. This sound like something no one but you would ever use, so I can't say it is too likely we would add that option.
I'm also a bit baffled why you are changing the current directory in a script file. If you have a command script that is specific to a set of data files I think it is most common to put the script file in the same directory as those data files. And if scripts and data are in a directory, it is most common that you change to that directory in ChimeraX (cd /where/my/data/is) or you start ChimeraX in that directory (usually on Linux from a shell).
Tom
On May 27, 2024, at 6:49 AM, Vorländer,Matthias Kopano via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear ChimeraX team,
I have a series of scripts that contain a “cd” statement to set the working directory. I execute the scripts (which opens a model and map and colors the map). I then manually adjust the orientation and threshold and want to save a picture with “save map.png” (I want this png tp be saved in the folder that I set with the script). I have noticed that in this scenario ChimeraX has “forgotten” the cd statement from the script file and has fallen back to default working directory (or the last working directory manually set in the session before I exectuted my script). At least for me it would be more convenient and logical if the working directory can be set and maintained after habing executed a script. Note: if I don’t execute the script by double clicking but by copy/paste, the working directory is correctly maintained. Would be great if the behavior could be adjusted 😊
Many thanks and best wishes, Matthias _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu Archives: https://mail.cgl.ucsf.edu/mailman/archives/list/chimerax-users@cgl.ucsf.edu/
participants (2)
-
Tom Goddard
-
Vorländer,Matthias Kopano