Opened 3 years ago

Closed 3 years ago

#7172 closed enhancement (fixed)

Allow substituting arguments in a .cxc file command script

Reported by: p.shah.lab@… Owned by: Tom Goddard
Priority: moderate Milestone:
Component: Input/Output Version:
Keywords: Cc: Elaine Meng
Blocked By: Blocking:
Notify when closed: Platform: all
Project: ChimeraX

Description

Pranav Shah asked how to use two filename arguments to a *.cxc command script. Maybe the runscript command could be enhanced to work with .cxc files (currently just Python files) and substitute arguments for $1, $2, $3 ... in the .cxc file.

On Jun 24, 2022, at 5:57 AM, Pranav Shah via ChimeraX-users <chimerax-users@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
From: Tom Goddard
Subject: Re: [chimerax-users] using variables in command files
Date: June 24, 2022 at 12:09:06 PM PDT
To: Pranav Shah
Cc: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu>

Hi Pranav,

 Currently ChimeraX does not have a way to substitute argument values into a *.cxc file except for the open command "foreach" option which allows substituting the file name in for $file.  For simple series of commands you could define an alias, for example,

	alias radcolor open $1 ; color radial palette rainbow ; save $2 height 512 width 512 transparentBackground true

This defines the radcolor command that you can use like

	radcolor mymap.mrc image.png

Here's the documentation for the "alias" command

	https://www.cgl.ucsf.edu/chimerax/docs/user/commands/alias.html

The other mechanism for handing arguments to a script is the "runscript" command which passes arguments to Python scripts only.  I could imagine runscript being enhanced so that it works with a *.cxc command script and substitutes arguments in for $1, $2, $3, ... occurring in the script.

	https://www.cgl.ucsf.edu/chimerax/docs/user/commands/runscript.html

 Tom

Change History (2)

comment:1 by Tom Goddard, 3 years ago

Could even do something a bit fancier so meaningful variable names could be used in the .cxc script like

runscript radcolor.cxc substitute file=myfile.mrc,out=image.png

where the script would have $file and $out that would get replaced.

comment:2 by Tom Goddard, 3 years ago

Cc: Elaine Meng added
Resolution: fixed
Status: assignedclosed

I made the runscript command accept .cxc files (or .py as before). The arguments replace $1, $2, $3 ... in the .cxc file before the commands are executed. All commands in the script are logged.

Elaine, could you update the runscript documentation?

Note: See TracTickets for help on using tickets.