[chimerax-users] ChimeraX image saving automation

Elaine Meng meng at cgl.ucsf.edu
Thu Jan 19 10:34:03 PST 2023


Hi Fedaa,
In ChimeraX, you can run a command script (.cxc) file on each structure, if you have a set of input files for those structures.  It does it one by one instead of having all the structures open at the same time.  It works well if you don't need to manually position them before image-saving (discussed further in the bottom half of this message).

(1) First you figure out the commands to run on each structure. It is OK if you want a different output file name for each structure, there is a way to do it...

(2) then using your favorite text-editor, just create a plain text file containing the same commands you would have typed into the command line.  This is a command script or command file, name it something that ends with .cxc

Command files:
<https://rbvi.ucsf.edu/chimerax/docs/user/commands/usageconventions.html#cxc-files>

(3) then use the "open" command to open and run this .cxc file, including the "forEachFile" option to specify what set of structure files you want to apply it to.  The description of "forEachFile" includes examples and also explains how you would get a different output file for each input file by including "$" in the save command inside the file:

<https://rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile>

It will automatically close each structure before going on to the next one.

Example: 

open myscript.cxc foreach /Users/meng/Desktop/project1/*.pdb

...where myscript.cxc is the command file. 

One difficulty with this process, however, is that it does not allow you to position each structure manually, since it just opens the file and runs the commands without your having a chance to set up the view.  If the structures are already in the position you want when you open the files, there is no problem.  However, usually they are not.   To handle this problem, possibilities are:

(A) don't use this foreach script approach.  Instead after setting up the position and other aspects of appearance, just use python scripting to save image of each one.  Somebody else would have to advise on that, however, since I don't know python.

(B) superimpose all the structures and re-save new files in the transformed position, then open the newly saved files with the foreach script ... however, you would probably still need to include a zoom command in the foreach script, with zoom factor determined by trial and error, and possibly also translations ("move" command).

(C) I had a third idea to open a reference structure before using the foreach script, manually position it and then undisplay it, and then in the foreach script, match each other structure to that reference structure to set its position.  However, I realized that will not work because the "foreach" approach will automatically close all the structures (including the hidden reference) each time it finishes processing a single structure.

I hope this helps,
Elaine
-----
Elaine C. Meng, Ph.D.
UCSF Chimera(X) team
Department of Pharmaceutical Chemistry
University of California, San Francisco

> On Jan 19, 2023, at 9:38 AM, Attana, Fedaa via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
> 
> Hi all,
> 
> I have started to use Chimera recently and found it very cool. I liked the way I can edit all of my structure with one command when no model is selected. However, to save images, I have to manually show each structure (model) and run the same saving command with a new name. 
> I wonder if there is an easier way to do this or if somebody did automate this process so one can save images of individual models with a script?
> 
> Thanks in advance,
> Fedaa
> _______________________________________________
> ChimeraX-users mailing list
> ChimeraX-users at cgl.ucsf.edu
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users




More information about the ChimeraX-users mailing list