[chimerax-users] using variables in command files

Elaine Meng meng at cgl.ucsf.edu
Fri Jun 24 09:42:15 PDT 2022


Hi Pranav,
If all the maps are colored by the same second map, then there isn't an issue.  However, if each map has its own partner map for coloring, maybe it's possible by putting them in separate subdirectories, e.g.

open myscript.cxc foreach ~/data/*.mrc

and in this case include another "open" inside the myscript.cxc that would open the second map in different subdir

open ~/data2/$file.mrc

I haven't tried it, just an idea.  However, depending on the complexity of whatever is your current workflow you may need to use python instead.  As you can see, "foreach" is just for the common case of wanting to process many input files individually but with the same series of steps.

Somebody else would have to advise if you need help with the python, however, as that is outside my skill set.
Best,
Elaine
-----
Elaine C. Meng, Ph.D.                       
UCSF Chimera(X) team
Department of Pharmaceutical Chemistry
University of California, San Francisco

> On Jun 24, 2022, at 9:18 AM, Pranav Shah via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
> 
> HI Elaine, sorry to write to you privately. Writing for the sake of
> reducing the spam in other peoples inboxes. Can I ask how I could then
> use the foreach command to color the map value using values from
> another map? It seems forachfile has a very limited capacity to handle
> more complex workflows and I might have to turn to writing stuff up in
> python using the chimerax api.
> Best,
> Pranav
> --
> Pranav Shah
> Postdoctoral Research Fellow.
> 
> Division of Structural Biology,
> Wellcome Trust Centre for Human Genetics,
> University of Oxford,
> Roosevelt Drive, Oxford OX3 7BN,
> UK
> 
> On Fri, Jun 24, 2022 at 5:02 PM Elaine Meng <meng at cgl.ucsf.edu> wrote:
>> 
>> Yes, sorry about that, my example was wrong and should not have had the "open" command inside the cxc file.
>> 
>> Glad you figured it out.
>> Best,
>> Elaine
>> 
>>> On Jun 24, 2022, at 8:56 AM, Pranav Shah via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
>>> 
>>> Ah! OK i see where I was going wrong. essentially there is no need to
>>> include an open command in the command file because that is implicit
>>> in the open call to the command file in the GUI.
>>> Best,
>>> Pranav
>>> --
>>> Pranav Shah
>>> Postdoctoral Research Fellow.
>>> 
>>> Division of Structural Biology,
>>> Wellcome Trust Centre for Human Genetics,
>>> University of Oxford,
>>> Roosevelt Drive, Oxford OX3 7BN,
>>> UK
>>> 
>>> On Fri, Jun 24, 2022 at 4:50 PM Pranav Shah <p.shah.lab at gmail.com> wrote:
>>>> 
>>>> Thanks for that pointer Elaine. I have a question-
>>>> (a) <file> has no suffix error -
>>>> I am running the program as described in the help page. Essentially,
>>>> open test.cxc foreach myfile.*
>>>> My script has the following three lines in it
>>>> open $file
>>>> color radial #1 palette rainbow
>>>> 
>>>> 
>>>>                                              save $file.png
>>>> transparentBackground true
>>>> 
>>>> Looking at the log, ChimeraX appears to be running two open commands
>>>> for some reason. In the first instance it opens the map as expected
>>>> but then stops executing a second open with the aforementioned error.
>>>> Not sure why it needs to run open twice.
>>>> 
>>>> Not sure where I am going wrong.
>>>> Best,
>>>> Pranav
>>>> --
>>>> Pranav Shah
>>>> Postdoctoral Research Fellow.
>>>> 
>>>> Division of Structural Biology,
>>>> Wellcome Trust Centre for Human Genetics,
>>>> University of Oxford,
>>>> Roosevelt Drive, Oxford OX3 7BN,
>>>> UK
>>>> 
>>>> On Fri, Jun 24, 2022 at 4:18 PM Elaine Meng <meng at cgl.ucsf.edu> wrote:
>>>>> 
>>>>> Hi Pranav,
>>>>> For something like this I believe you would instead use the "foreach" option of the "open" command to open the ChimeraX command file, which could contain "$file" meaning the base name (before suffix) of the input files.  This also allows specifying multiple input files to loop through in one "open" command, as explained here
>>>>> 
>>>>> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile>
>>>>> 
>>>>> Your command file would contain something like
>>>>> 
>>>>> open $file
>>>>> color radial palette rainbow
>>>>> save $file.png height 512 width 512 transparentBackground True
>>>>> 
>>>>> ...i.e. there is only one substitution string $file (you can't have a different $outfile), but in the example above if you opened 2gbp.pdb, the saved image would then be named 2gbp.png.  If you opened infile.mrc, then the saved image would be named infile.png.
>>>>> 
>>>>> I hope this helps,
>>>>> Elaine
>>>>> -----
>>>>> Elaine C. Meng, Ph.D.
>>>>> UCSF Chimera(X) team
>>>>> Department of Pharmaceutical Chemistry
>>>>> University of California, San Francisco
>>>>> 
>>>>>> On Jun 24, 2022, at 5:57 AM, Pranav Shah via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
>>>>>> 
>>>>>> Hi Team,
>>>>>> Is it possible for one to declare a variable in a command file that
>>>>>> can then be passed to via the chimeraX command line interface. A
>>>>>> minimal example of something I would like to do is -
>>>>>> command.cxc
>>>>>> open $file
>>>>>> color radial palette rainbow
>>>>>> save $outfile.png height 512 width 512 transparentBackground True
>>>>>> 
>>>>>> In the chimeraX command line window I would then like to run
>>>>>> open command.cxc infile.mrc outfile.png
>>>>>> Best,
>>>>>> Pranav
>>>>> 
>>> 
>>> _______________________________________________
>>> ChimeraX-users mailing list
>>> ChimeraX-users at cgl.ucsf.edu
>>> Manage subscription:
>>> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
>> 
> 
> _______________________________________________
> 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