Chimerax scripting error and passing user supplied arguments

Dear community, I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code. I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise. Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now. cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit This script is perfect if run for have a single model with the exact name written into the script after typing: chimerax-daily --nogui chimera-data-processing.cxc I have two main solutions A) run a while loop that counts down and passes a filename to chimerax: while ( X < 1000 ) chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this: open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30 Option B is to use the foreach command described in the open command documentation ( https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html). However, a copy and past of that command: *open myscript.cxc foreach ~/data/*.cif * *or* *open chimera-data-processing.cxc foreach results/S_0001_*-4-* all-chain-A.pdb results in this error: Missing filename suffix foreach I also tried this: chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt pdb transformations if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized. ###code to extract metal coords for S_0001_$x-4-*.pdb done fi chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time. Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms. Thanks for any help that can be given, Ryan

Hi Ryan, The "foreach" option you tried is exactly intended for this use. The error message "Missing filename suffix foreach" suggests you are using an old version of ChimeraX (older than ChimeraX 1.3) that does not have the "foreach" option so it thinks that "foreach" is the name of a file. Your script only saves one file so I don't understand what you mean by saving two files $file1 and $file2. You would just use "save $file-sf-aligned.pdb ..." to save the aligned file. Tom
On May 4, 2022, at 10:41 PM, Ryan Woltz via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Dear community,
I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code.
I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise.
Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now.
cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit
This script is perfect if run for have a single model with the exact name written into the script after typing:
chimerax-daily --nogui chimera-data-processing.cxc
I have two main solutions A) run a while loop that counts down and passes a filename to chimerax:
while ( X < 1000 )
chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this:
open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30
Option B is to use the foreach command described in the open command documentation (https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html <https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html>). However, a copy and past of that command:
open myscript.cxc foreach ~/data/*.cif or open chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
results in this error:
Missing filename suffix foreach
I also tried this:
chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt
pdb transformations
if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized.
###code to extract metal coords for S_0001_$x-4-*.pdb
done fi
chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit
if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time.
Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms.
Thanks for any help that can be given,
Ryan _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Hi Tom, Thank you for your quick reply. Your solution worked to get "foreach" to work and I have notes below if others in the future run into my problem. I was able to solve the issue with a bash script that creates command run files on the fly but it's pretty messy so if you have another way to do this it'd be nice to have things a bit cleaner. Below is my solution/follow-up question, a clarification to the $file1 question you asked and some notes about updating. Major apologies if I repeat myself or grammatical errors, as I wrote this email I came up with several ideas on how to make things work and had to edit the post multiple times each time I tried something new. Follow up question: With your help I got this to work by typing these commands into the terminal directly: $:chimerax --nogui (waited to load chimerax) $:open chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb Is there a way to run the command script with foreach while opening chimerax? for example: $:chimerax --nogui chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb If I run this it give me a bunch of python errors and errors related to $file. The workaround I made was to have the master bash script write a new chimera script on the fly every time with the user inputted filenames saved in the master bash script. masterscript.sh: ###run in terminal: "./masterscript.sh S_0001_ hsk2-template-with-metals.pdb pdbstoalign=$1 pdbwithmetals=$2 ###$1 and $2 are equal to the user input while starting the script ###pdb editing stuff happening if ($x = 5) ###5th alignment ###create foreach running script echo "open chimera-data-processing.cxc foreach $pdbstoalign-[1-1000]-all-chain-A.pdb" > chimeraxrun.cxc echo "quit" >> chimeraxrun.cxc ###create data processing script echo 'open $file.pdb' > chimera-data-processing.cxc ###print exactly this line not variable $file echo "open $pdbwithmetals" >> chimera-data-processing.cxc echo "info" >> chimera-data-processing.cxc echo "align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300" >> chimera-data-processing.cxc echo "save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30" >> chimera-data-processing.cxc chimerax --nogui chimeraxrun.cxc ###pdb processing with output chimeraxrun.cxc: open foreach chimera-data-processing.cxc foreach S_0001_[1-1000]-4-all-chain-A.pdb ###pdb filename comes from bash script chimera-data-processing: open $file.pdb open hsk2-template-with-metals.pdb ###filename from bash master script info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30 While this works it is very messy and I need to create multiple files on the fly. It would be much easier if I could pass variables into the chimerax scripts that I can use inside the script. Does this make any sense? Clarification: Hopefully the above example scripts clarifies why I asked about $file1 and $file2. I have 2 input files. a model with no metals and a template with models I need to align onto. Updating issues: I forgot to mention that I tried updating chimerax-daily with this command sudo /usr/bin/chimerax-daily -m pip install --upgrade pip which gave a success code. But when I checked the version via chimerax-daily --version I get this version. UCSF ChimeraX version: 0.93 (2020-03-24) Is there a way to update to the newest version without reinstalling? I found toolshed update documentation but this appears to be for packages not the entire build. As you can see it is not them most updated version. I downloaded bother chimerax and chimerax-daily again. chimerax installed and used foreach with no errors. However, chimerax-daily will not install unless I do a complete uninstall so I think I'll go forward with chimerax. Another thing I noticed, while attempting ranges with chimerax-daily it only took single digit ranges. For example S_0001-[1-10]-chain-A.pdb if only took pdbs with "1" in place of the range. if the range is 1-9 then it takes all files. If the range is 01-19 (trying to match number of digits) if only takes models 1 and 9. I get what it is doing here but I don't know the fix or if I'm doing it right. I'm just using a range for now to test 9 files instead of the full 1000. I'll replace the numbering with a '*' so it'll get them all. I won't have an issues going forward but thought this was significant for others in the future if I had typed it wrong. Thank you again for your time and help, Ryan On Thu, May 5, 2022 at 12:01 AM Tom Goddard <goddard@sonic.net> wrote:
Hi Ryan,
The "foreach" option you tried is exactly intended for this use. The error message "Missing filename suffix foreach" suggests you are using an old version of ChimeraX (older than ChimeraX 1.3) that does not have the "foreach" option so it thinks that "foreach" is the name of a file. Your script only saves one file so I don't understand what you mean by saving two files $file1 and $file2. You would just use "save $file-sf-aligned.pdb ..." to save the aligned file.
Tom
On May 4, 2022, at 10:41 PM, Ryan Woltz via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Dear community,
I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code.
I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise.
Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now.
cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit
This script is perfect if run for have a single model with the exact name written into the script after typing:
chimerax-daily --nogui chimera-data-processing.cxc
I have two main solutions A) run a while loop that counts down and passes a filename to chimerax:
while ( X < 1000 )
chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this:
open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30
Option B is to use the foreach command described in the open command documentation ( https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html). However, a copy and past of that command:
*open myscript.cxc foreach ~/data/*.cif * *or* *open chimera-data-processing.cxc foreach results/S_0001_*-4-* all-chain-A.pdb
results in this error:
Missing filename suffix foreach
I also tried this:
chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt
pdb transformations
if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized.
###code to extract metal coords for S_0001_$x-4-*.pdb
done fi
chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit
if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time.
Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms.
Thanks for any help that can be given,
Ryan _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Hi Ryan, I followed your conversation here, and maybe I can propose another solution. Your current workflow is a shell script, generating a chimerax cxc file with all the commands. And as you already mentioned, it's messy. I did this for e.g. a series of images before, but for iterative stuff, like you're facing, I used a python script, executed by chimerax. First line, import the chimera cmd: from chimerax.core.commands import run and than you can execute the chimerax commands like: run(session, "open model.pdb") and for loops, you could do smth like: for model in ["model1.pdb", "model2.pdb", ..]: run(session, f"open {model}") # do stuff with the model run(session, f"save new_{model} #1) And then you execute the script with "run script.py" directly inside chimerax or during starting with --nogui (or "open script.py" - I'm always unsure, but one of these works, the other raises an error) By this, you'll have a relatively clear code and not a messy cxc file. But Tom/Elaine might add the correct links to the documentation of this :) Please note, (a) I am not sure, if this is what you're looking for :), and (b) I havn't worked with the foreach command before, which might do the job without scripting as Tom already said. Best Christian
Ryan Woltz via ChimeraX-users <chimerax-users@cgl.ucsf.edu> 05/06/22 5:13 AM >>> Hi Tom,
Thank you for your quick reply. Your solution worked to get "foreach" to work and I have notes below if others in the future run into my problem. I was able to solve the issue with a bash script that creates command run files on the fly but it's pretty messy so if you have another way to do this it'd be nice to have things a bit cleaner. Below is my solution/follow-up question, a clarification to the $file1 question you asked and some notes about updating. Major apologies if I repeat myself or grammatical errors, as I wrote this email I came up with several ideas on how to make things work and had to edit the post multiple times each time I tried something new. Follow up question: With your help I got this to work by typing these commands into the terminal directly: $:chimerax --nogui (waited to load chimerax) $:open chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb Is there a way to run the command script with foreach while opening chimerax? for example: $:chimerax --nogui chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb If I run this it give me a bunch of python errors and errors related to $file. The workaround I made was to have the master bash script write a new chimera script on the fly every time with the user inputted filenames saved in the master bash script. masterscript.sh: ###run in terminal: "./masterscript.sh S_0001_ hsk2-template-with-metals.pdb pdbstoalign=$1 pdbwithmetals=$2 ###$1 and $2 are equal to the user input while starting the script ###pdb editing stuff happening if ($x = 5) ###5th alignment ###create foreach running script echo "open chimera-data-processing.cxc foreach $pdbstoalign-[1-1000]-all-chain-A.pdb" > chimeraxrun.cxc echo "quit" >> chimeraxrun.cxc ###create data processing script echo 'open $file.pdb' > chimera-data-processing.cxc ###print exactly this line not variable $file echo "open $pdbwithmetals" >> chimera-data-processing.cxc echo "info" >> chimera-data-processing.cxc echo "align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300" >> chimera-data-processing.cxc echo "save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30" >> chimera-data-processing.cxc chimerax --nogui chimeraxrun.cxc ###pdb processing with output chimeraxrun.cxc: open foreach chimera-data-processing.cxc foreach S_0001_[1-1000]-4-all-chain-A.pdb ###pdb filename comes from bash script chimera-data-processing: open $file.pdb open hsk2-template-with-metals.pdb ###filename from bash master script info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30 While this works it is very messy and I need to create multiple files on the fly. It would be much easier if I could pass variables into the chimerax scripts that I can use inside the script. Does this make any sense? Clarification: Hopefully the above example scripts clarifies why I asked about $file1 and $file2. I have 2 input files. a model with no metals and a template with models I need to align onto. Updating issues: I forgot to mention that I tried updating chimerax-daily with this command sudo /usr/bin/chimerax-daily -m pip install --upgrade pip which gave a success code. But when I checked the version via chimerax-daily --version I get this version. UCSF ChimeraX version: 0.93 (2020-03-24) Is there a way to update to the newest version without reinstalling? I found toolshed update documentation but this appears to be for packages not the entire build. As you can see it is not them most updated version. I downloaded bother chimerax and chimerax-daily again. chimerax installed and used foreach with no errors. However, chimerax-daily will not install unless I do a complete uninstall so I think I'll go forward with chimerax. Another thing I noticed, while attempting ranges with chimerax-daily it only took single digit ranges. For example S_0001-[1-10]-chain-A.pdb if only took pdbs with "1" in place of the range. if the range is 1-9 then it takes all files. If the range is 01-19 (trying to match number of digits) if only takes models 1 and 9. I get what it is doing here but I don't know the fix or if I'm doing it right. I'm just using a range for now to test 9 files instead of the full 1000. I'll replace the numbering with a '*' so it'll get them all. I won't have an issues going forward but thought this was significant for others in the future if I had typed it wrong. Thank you again for your time and help, Ryan On Thu, May 5, 2022 at 12:01 AM Tom Goddard <goddard@sonic.net> wrote:
Hi Ryan,
The "foreach" option you tried is exactly intended for this use. The error message "Missing filename suffix foreach" suggests you are using an old version of ChimeraX (older than ChimeraX 1.3) that does not have the "foreach" option so it thinks that "foreach" is the name of a file. Your script only saves one file so I don't understand what you mean by saving two files $file1 and $file2. You would just use "save $file-sf-aligned.pdb ..." to save the aligned file.
Tom
On May 4, 2022, at 10:41 PM, Ryan Woltz via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Dear community,
I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code.
I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise.
Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now.
cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit
This script is perfect if run for have a single model with the exact name written into the script after typing:
chimerax-daily --nogui chimera-data-processing.cxc
I have two main solutions A) run a while loop that counts down and passes a filename to chimerax:
while ( X < 1000 )
chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this:
open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30
Option B is to use the foreach command described in the open command documentation ( https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html). However, a copy and past of that command:
*open myscript.cxc foreach ~/data/*.cif * *or* *open chimera-data-processing.cxc foreach results/S_0001_*-4-* all-chain-A.pdb
results in this error:
Missing filename suffix foreach
I also tried this:
chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt
pdb transformations
if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized.
###code to extract metal coords for S_0001_$x-4-*.pdb
done fi
chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit
if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time.
Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms.
Thanks for any help that can be given,
Ryan _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Thank you Christian for your input, I think you're absolutely right from the documentation I've read chimera or Chimerax could do this with a python script. However, I've never written a line of code in python, was mostly self taught in perl/bash and a beginner class in C++ 15 years ago, and I needed a script to finish a project that is behind schedule. So I was hoping for a quick and dirty way to import variables in a language I know (bash/cheers command) I attempted to modify the python code in documentation but kept getting syntax errors. From what I've read in other posts it can be done using the sys.arg variables in.python and the code you provided, if anyone reading this is proficient in Python. My current script is a Frankenstein of about 500 lines of code in various languages doing multiple alignments using Rosetta and then extracting the corresponding metal coordinates repeating this at least 5 times. It was written over a coarse of 6 months and anytime I decided to do the next step in my modeling I'd just add slither function. Terrible method I know. I'm really grateful for our conversation and both yours and Tom's help as I have a good idea of the framework of how to do this in python now. My summer is probably going to be learning python and trying to convert my entire workflow into a single concise and useable Chimerax script. When I get this working in python I'll copy and paste my code in reply to this email so others can use it. Thanks again for your help, Ryan On Thu, May 5, 2022, 11:51 PM Christian Tüting < christian.tueting@biochemtech.uni-halle.de> wrote:
Hi Ryan,
I followed your conversation here, and maybe I can propose another solution.
Your current workflow is a shell script, generating a chimerax cxc file with all the commands. And as you already mentioned, it's messy. I did this for e.g. a series of images before, but for iterative stuff, like you're facing, I used a python script, executed by chimerax.
First line, import the chimera cmd: from chimerax.core.commands import run
and than you can execute the chimerax commands like: run(session, "open model.pdb")
and for loops, you could do smth like: for model in ["model1.pdb", "model2.pdb", ..]: run(session, f"open {model}") # do stuff with the model run(session, f"save new_{model} #1)
And then you execute the script with "run script.py" directly inside chimerax or during starting with --nogui (or "open script.py" - I'm always unsure, but one of these works, the other raises an error)
By this, you'll have a relatively clear code and not a messy cxc file.
But Tom/Elaine might add the correct links to the documentation of this :)
Please note, (a) I am not sure, if this is what you're looking for :), and (b) I havn't worked with the foreach command before, which might do the job without scripting as Tom already said.
Best Christian
Ryan Woltz via ChimeraX-users <chimerax-users@cgl.ucsf.edu> 05/06/22 5:13 AM >>> Hi Tom,
Thank you for your quick reply. Your solution worked to get "foreach" to work and I have notes below if others in the future run into my problem. I was able to solve the issue with a bash script that creates command run files on the fly but it's pretty messy so if you have another way to do this it'd be nice to have things a bit cleaner. Below is my solution/follow-up question, a clarification to the $file1 question you asked and some notes about updating. Major apologies if I repeat myself or grammatical errors, as I wrote this email I came up with several ideas on how to make things work and had to edit the post multiple times each time I tried something new.
Follow up question: With your help I got this to work by typing these commands into the terminal directly: $:chimerax --nogui (waited to load chimerax) $:open chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb
Is there a way to run the command script with foreach while opening chimerax? for example: $:chimerax --nogui chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb
If I run this it give me a bunch of python errors and errors related to $file. The workaround I made was to have the master bash script write a new chimera script on the fly every time with the user inputted filenames saved in the master bash script.
masterscript.sh: ###run in terminal: "./masterscript.sh S_0001_ hsk2-template-with-metals.pdb pdbstoalign=$1 pdbwithmetals=$2 ###$1 and $2 are equal to the user input while starting the script ###pdb editing stuff happening if ($x = 5) ###5th alignment ###create foreach running script echo "open chimera-data-processing.cxc foreach $pdbstoalign-[1-1000]-all-chain-A.pdb" > chimeraxrun.cxc echo "quit" >> chimeraxrun.cxc ###create data processing script echo 'open $file.pdb' > chimera-data-processing.cxc ###print exactly this line not variable $file echo "open $pdbwithmetals" >> chimera-data-processing.cxc echo "info" >> chimera-data-processing.cxc echo "align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300" >> chimera-data-processing.cxc echo "save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30" >> chimera-data-processing.cxc
chimerax --nogui chimeraxrun.cxc ###pdb processing with output
chimeraxrun.cxc: open foreach chimera-data-processing.cxc foreach S_0001_[1-1000]-4-all-chain-A.pdb ###pdb filename comes from bash script
chimera-data-processing: open $file.pdb open hsk2-template-with-metals.pdb ###filename from bash master script info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30
While this works it is very messy and I need to create multiple files on the fly. It would be much easier if I could pass variables into the chimerax scripts that I can use inside the script. Does this make any sense?
Clarification: Hopefully the above example scripts clarifies why I asked about $file1 and $file2. I have 2 input files. a model with no metals and a template with models I need to align onto.
Updating issues:
I forgot to mention that I tried updating chimerax-daily with this command
sudo /usr/bin/chimerax-daily -m pip install --upgrade pip
which gave a success code. But when I checked the version via chimerax-daily --version I get this version.
UCSF ChimeraX version: 0.93 (2020-03-24)
Is there a way to update to the newest version without reinstalling? I found toolshed update documentation but this appears to be for packages not the entire build. As you can see it is not them most updated version. I downloaded bother chimerax and chimerax-daily again. chimerax installed and used foreach with no errors. However, chimerax-daily will not install unless I do a complete uninstall so I think I'll go forward with chimerax.
Another thing I noticed, while attempting ranges with chimerax-daily it only took single digit ranges. For example S_0001-[1-10]-chain-A.pdb if only took pdbs with "1" in place of the range. if the range is 1-9 then it takes all files. If the range is 01-19 (trying to match number of digits) if only takes models 1 and 9. I get what it is doing here but I don't know the fix or if I'm doing it right. I'm just using a range for now to test 9 files instead of the full 1000. I'll replace the numbering with a '*' so it'll get them all. I won't have an issues going forward but thought this was significant for others in the future if I had typed it wrong.
Thank you again for your time and help,
Ryan
On Thu, May 5, 2022 at 12:01 AM Tom Goddard <goddard@sonic.net> wrote:
Hi Ryan,
The "foreach" option you tried is exactly intended for this use. The error message "Missing filename suffix foreach" suggests you are using an old version of ChimeraX (older than ChimeraX 1.3) that does not have the "foreach" option so it thinks that "foreach" is the name of a file. Your script only saves one file so I don't understand what you mean by saving two files $file1 and $file2. You would just use "save $file-sf-aligned.pdb ..." to save the aligned file.
Tom
On May 4, 2022, at 10:41 PM, Ryan Woltz via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Dear community,
I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code.
I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise.
Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now.
cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open
hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit
This script is perfect if run for have a single model with the exact name written into the script after typing:
chimerax-daily --nogui chimera-data-processing.cxc
I have two main solutions A) run a while loop that counts down and passes a filename to chimerax:
while ( X < 1000 )
chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb
hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this:
open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30
Option B is to use the foreach command described in the open
command
documentation ( https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html). However, a copy and past of that command:
*open myscript.cxc foreach ~/data/*.cif * *or* *open chimera-data-processing.cxc foreach results/S_0001_*-4-* all-chain-A.pdb
results in this error:
Missing filename suffix foreach
I also tried this:
chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt
pdb transformations
if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized.
###code to extract metal coords for S_0001_$x-4-*.pdb
done fi
chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit
if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time.
Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms.
Thanks for any help that can be given,
Ryan _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Hi Ryan, I'm not sure I'm answering all your questions, but here's a few answers. You run a command non-interactely with: chimerax --nogui --cmd "open blah.cxc foreach *.pdb" --exit The "--exit" is to exit to the shell afterward instead of an interactive ChimeraX command prompt. You can see the synopsis of available startup options with "chimerax --help" and they are described in more detail here: System Command-Line Options <https://www.cgl.ucsf.edu/chimerax/docs/user/options.html>. ChimeraX is using the Python glob <https://docs.python.org/3/library/glob.html#module-glob> module, which does shell-style globbing, and in the shell [1-10] does not match "10". You would need [0-9]* to match arbitrary numbers, and the matching would be in lexicographical order, not numerical order, (so 1, 10, 2, etc.). You cannot upgrade ChimeraX via pip, you have to install a new version. You don't have to install over the old version -- you can keep as many versions as you like, but on Linux this might be ugly/complicated and therefore uninstalling first might be easier. --Eric Eric Pettersen UCSF Computer Graphics Lab
On May 6, 2022, at 12:56 AM, Ryan Woltz via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Thank you Christian for your input, I think you're absolutely right from the documentation I've read chimera or Chimerax could do this with a python script. However, I've never written a line of code in python, was mostly self taught in perl/bash and a beginner class in C++ 15 years ago, and I needed a script to finish a project that is behind schedule. So I was hoping for a quick and dirty way to import variables in a language I know (bash/cheers command)
I attempted to modify the python code in documentation but kept getting syntax errors. From what I've read in other posts it can be done using the sys.arg variables in.python and the code you provided, if anyone reading this is proficient in Python.
My current script is a Frankenstein of about 500 lines of code in various languages doing multiple alignments using Rosetta and then extracting the corresponding metal coordinates repeating this at least 5 times. It was written over a coarse of 6 months and anytime I decided to do the next step in my modeling I'd just add slither function. Terrible method I know.
I'm really grateful for our conversation and both yours and Tom's help as I have a good idea of the framework of how to do this in python now. My summer is probably going to be learning python and trying to convert my entire workflow into a single concise and useable Chimerax script. When I get this working in python I'll copy and paste my code in reply to this email so others can use it.
Thanks again for your help,
Ryan
On Thu, May 5, 2022, 11:51 PM Christian Tüting <christian.tueting@biochemtech.uni-halle.de <mailto:christian.tueting@biochemtech.uni-halle.de>> wrote: Hi Ryan,
I followed your conversation here, and maybe I can propose another solution.
Your current workflow is a shell script, generating a chimerax cxc file with all the commands. And as you already mentioned, it's messy. I did this for e.g. a series of images before, but for iterative stuff, like you're facing, I used a python script, executed by chimerax.
First line, import the chimera cmd: from chimerax.core.commands import run
and than you can execute the chimerax commands like: run(session, "open model.pdb")
and for loops, you could do smth like: for model in ["model1.pdb", "model2.pdb", ..]: run(session, f"open {model}") # do stuff with the model run(session, f"save new_{model} #1)
And then you execute the script with "run script.py" directly inside chimerax or during starting with --nogui (or "open script.py" - I'm always unsure, but one of these works, the other raises an error)
By this, you'll have a relatively clear code and not a messy cxc file.
But Tom/Elaine might add the correct links to the documentation of this :)
Please note, (a) I am not sure, if this is what you're looking for :), and (b) I havn't worked with the foreach command before, which might do the job without scripting as Tom already said.
Best Christian
Ryan Woltz via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> 05/06/22 5:13 AM >>> Hi Tom,
Thank you for your quick reply. Your solution worked to get "foreach" to work and I have notes below if others in the future run into my problem. I was able to solve the issue with a bash script that creates command run files on the fly but it's pretty messy so if you have another way to do this it'd be nice to have things a bit cleaner. Below is my solution/follow-up question, a clarification to the $file1 question you asked and some notes about updating. Major apologies if I repeat myself or grammatical errors, as I wrote this email I came up with several ideas on how to make things work and had to edit the post multiple times each time I tried something new.
Follow up question: With your help I got this to work by typing these commands into the terminal directly: $:chimerax --nogui (waited to load chimerax) $:open chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb
Is there a way to run the command script with foreach while opening chimerax? for example: $:chimerax --nogui chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb
If I run this it give me a bunch of python errors and errors related to $file. The workaround I made was to have the master bash script write a new chimera script on the fly every time with the user inputted filenames saved in the master bash script.
masterscript.sh: ###run in terminal: "./masterscript.sh S_0001_ hsk2-template-with-metals.pdb pdbstoalign=$1 pdbwithmetals=$2 ###$1 and $2 are equal to the user input while starting the script ###pdb editing stuff happening if ($x = 5) ###5th alignment ###create foreach running script echo "open chimera-data-processing.cxc foreach $pdbstoalign-[1-1000]-all-chain-A.pdb" > chimeraxrun.cxc echo "quit" >> chimeraxrun.cxc ###create data processing script echo 'open $file.pdb' > chimera-data-processing.cxc ###print exactly this line not variable $file echo "open $pdbwithmetals" >> chimera-data-processing.cxc echo "info" >> chimera-data-processing.cxc echo "align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300" >> chimera-data-processing.cxc echo "save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30" >> chimera-data-processing.cxc
chimerax --nogui chimeraxrun.cxc ###pdb processing with output
chimeraxrun.cxc: open foreach chimera-data-processing.cxc foreach S_0001_[1-1000]-4-all-chain-A.pdb ###pdb filename comes from bash script
chimera-data-processing: open $file.pdb open hsk2-template-with-metals.pdb ###filename from bash master script info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30
While this works it is very messy and I need to create multiple files on the fly. It would be much easier if I could pass variables into the chimerax scripts that I can use inside the script. Does this make any sense?
Clarification: Hopefully the above example scripts clarifies why I asked about $file1 and $file2. I have 2 input files. a model with no metals and a template with models I need to align onto.
Updating issues:
I forgot to mention that I tried updating chimerax-daily with this command
sudo /usr/bin/chimerax-daily -m pip install --upgrade pip
which gave a success code. But when I checked the version via chimerax-daily --version I get this version.
UCSF ChimeraX version: 0.93 (2020-03-24)
Is there a way to update to the newest version without reinstalling? I found toolshed update documentation but this appears to be for packages not the entire build. As you can see it is not them most updated version. I downloaded bother chimerax and chimerax-daily again. chimerax installed and used foreach with no errors. However, chimerax-daily will not install unless I do a complete uninstall so I think I'll go forward with chimerax.
Another thing I noticed, while attempting ranges with chimerax-daily it only took single digit ranges. For example S_0001-[1-10]-chain-A.pdb if only took pdbs with "1" in place of the range. if the range is 1-9 then it takes all files. If the range is 01-19 (trying to match number of digits) if only takes models 1 and 9. I get what it is doing here but I don't know the fix or if I'm doing it right. I'm just using a range for now to test 9 files instead of the full 1000. I'll replace the numbering with a '*' so it'll get them all. I won't have an issues going forward but thought this was significant for others in the future if I had typed it wrong.
Thank you again for your time and help,
Ryan
On Thu, May 5, 2022 at 12:01 AM Tom Goddard <goddard@sonic.net <mailto:goddard@sonic.net>> wrote:
Hi Ryan,
The "foreach" option you tried is exactly intended for this use. The error message "Missing filename suffix foreach" suggests you are using an old version of ChimeraX (older than ChimeraX 1.3) that does not have the "foreach" option so it thinks that "foreach" is the name of a file. Your script only saves one file so I don't understand what you mean by saving two files $file1 and $file2. You would just use "save $file-sf-aligned.pdb ..." to save the aligned file.
Tom
On May 4, 2022, at 10:41 PM, Ryan Woltz via ChimeraX-users < chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
Dear community,
I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code.
I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise.
Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now.
cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit
This script is perfect if run for have a single model with the exact name written into the script after typing:
chimerax-daily --nogui chimera-data-processing.cxc
I have two main solutions A) run a while loop that counts down and passes a filename to chimerax:
while ( X < 1000 )
chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this:
open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30
Option B is to use the foreach command described in the open command documentation ( https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html <https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html>). However, a copy and past of that command:
*open myscript.cxc foreach ~/data/*.cif * *or* *open chimera-data-processing.cxc foreach results/S_0001_*-4-* all-chain-A.pdb
results in this error:
Missing filename suffix foreach
I also tried this:
chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt
pdb transformations
if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized.
###code to extract metal coords for S_0001_$x-4-*.pdb
done fi
chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit
if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time.
Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms.
Thanks for any help that can be given,
Ryan _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu <mailto:ChimeraX-users@cgl.ucsf.edu> Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users <https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users>
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

Dear Eric and Tom, Thank you for your help. The Chimerax running of a script the Eric suggested is extremely helpful in getting this done for now. Also thank you for the number range explanation. I'm still slightly confused but the terms you gave me is enough to Google some articles I'm sure and it is a lot clearer what I need to look for. I'll also uninstall my old version of chimerax. Lastly thanks for your advice on python Tom, yes I think after this conversation learning python is my next project over the summer and converting my current script into python. Cheers, Ryan On Fri, May 6, 2022, 11:23 AM Eric Pettersen <pett@cgl.ucsf.edu> wrote:
Hi Ryan, I'm not sure I'm answering all your questions, but here's a few answers. You run a command non-interactely with:
chimerax --nogui --cmd "open blah.cxc foreach *.pdb" --exit
The "--exit" is to exit to the shell afterward instead of an interactive ChimeraX command prompt. You can see the synopsis of available startup options with "chimerax --help" and they are described in more detail here: System Command-Line Options <https://www.cgl.ucsf.edu/chimerax/docs/user/options.html>. ChimeraX is using the Python glob <https://docs.python.org/3/library/glob.html#module-glob> module, which does shell-style globbing, and in the shell [1-10] does not match "10". You would need [0-9]* to match arbitrary numbers, and the matching would be in lexicographical order, not numerical order, (so 1, 10, 2, etc.). You cannot upgrade ChimeraX via pip, you have to install a new version. You don't *have* to install over the old version -- you can keep as many versions as you like, but on Linux this might be ugly/complicated and therefore uninstalling first might be easier.
--Eric
Eric Pettersen UCSF Computer Graphics Lab
On May 6, 2022, at 12:56 AM, Ryan Woltz via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Thank you Christian for your input, I think you're absolutely right from the documentation I've read chimera or Chimerax could do this with a python script. However, I've never written a line of code in python, was mostly self taught in perl/bash and a beginner class in C++ 15 years ago, and I needed a script to finish a project that is behind schedule. So I was hoping for a quick and dirty way to import variables in a language I know (bash/cheers command)
I attempted to modify the python code in documentation but kept getting syntax errors. From what I've read in other posts it can be done using the sys.arg variables in.python and the code you provided, if anyone reading this is proficient in Python.
My current script is a Frankenstein of about 500 lines of code in various languages doing multiple alignments using Rosetta and then extracting the corresponding metal coordinates repeating this at least 5 times. It was written over a coarse of 6 months and anytime I decided to do the next step in my modeling I'd just add slither function. Terrible method I know.
I'm really grateful for our conversation and both yours and Tom's help as I have a good idea of the framework of how to do this in python now. My summer is probably going to be learning python and trying to convert my entire workflow into a single concise and useable Chimerax script. When I get this working in python I'll copy and paste my code in reply to this email so others can use it.
Thanks again for your help,
Ryan
On Thu, May 5, 2022, 11:51 PM Christian Tüting < christian.tueting@biochemtech.uni-halle.de> wrote:
Hi Ryan,
I followed your conversation here, and maybe I can propose another solution.
Your current workflow is a shell script, generating a chimerax cxc file with all the commands. And as you already mentioned, it's messy. I did this for e.g. a series of images before, but for iterative stuff, like you're facing, I used a python script, executed by chimerax.
First line, import the chimera cmd: from chimerax.core.commands import run
and than you can execute the chimerax commands like: run(session, "open model.pdb")
and for loops, you could do smth like: for model in ["model1.pdb", "model2.pdb", ..]: run(session, f"open {model}") # do stuff with the model run(session, f"save new_{model} #1)
And then you execute the script with "run script.py" directly inside chimerax or during starting with --nogui (or "open script.py" - I'm always unsure, but one of these works, the other raises an error)
By this, you'll have a relatively clear code and not a messy cxc file.
But Tom/Elaine might add the correct links to the documentation of this :)
Please note, (a) I am not sure, if this is what you're looking for :), and (b) I havn't worked with the foreach command before, which might do the job without scripting as Tom already said.
Best Christian
Ryan Woltz via ChimeraX-users <chimerax-users@cgl.ucsf.edu> 05/06/22 5:13 AM >>> Hi Tom,
Thank you for your quick reply. Your solution worked to get "foreach" to work and I have notes below if others in the future run into my problem. I was able to solve the issue with a bash script that creates command run files on the fly but it's pretty messy so if you have another way to do this it'd be nice to have things a bit cleaner. Below is my solution/follow-up question, a clarification to the $file1 question you asked and some notes about updating. Major apologies if I repeat myself or grammatical errors, as I wrote this email I came up with several ideas on how to make things work and had to edit the post multiple times each time I tried something new.
Follow up question: With your help I got this to work by typing these commands into the terminal directly: $:chimerax --nogui (waited to load chimerax) $:open chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb
Is there a way to run the command script with foreach while opening chimerax? for example: $:chimerax --nogui chimera-data-processing.cxc foreach S_0001_*-4-all-chain-A.pdb
If I run this it give me a bunch of python errors and errors related to $file. The workaround I made was to have the master bash script write a new chimera script on the fly every time with the user inputted filenames saved in the master bash script.
masterscript.sh: ###run in terminal: "./masterscript.sh S_0001_ hsk2-template-with-metals.pdb pdbstoalign=$1 pdbwithmetals=$2 ###$1 and $2 are equal to the user input while starting the script ###pdb editing stuff happening if ($x = 5) ###5th alignment ###create foreach running script echo "open chimera-data-processing.cxc foreach $pdbstoalign-[1-1000]-all-chain-A.pdb" > chimeraxrun.cxc echo "quit" >> chimeraxrun.cxc ###create data processing script echo 'open $file.pdb' > chimera-data-processing.cxc ###print exactly this line not variable $file echo "open $pdbwithmetals" >> chimera-data-processing.cxc echo "info" >> chimera-data-processing.cxc echo "align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300"
chimera-data-processing.cxc echo "save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30" >> chimera-data-processing.cxc
chimerax --nogui chimeraxrun.cxc ###pdb processing with output
chimeraxrun.cxc: open foreach chimera-data-processing.cxc foreach S_0001_[1-1000]-4-all-chain-A.pdb ###pdb filename comes from bash script
chimera-data-processing: open $file.pdb open hsk2-template-with-metals.pdb ###filename from bash master script info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save $file-sf-aligned.pdb #1 format pdb relModel #2; wait 30
While this works it is very messy and I need to create multiple files on the fly. It would be much easier if I could pass variables into the chimerax scripts that I can use inside the script. Does this make any sense?
Clarification: Hopefully the above example scripts clarifies why I asked about $file1 and $file2. I have 2 input files. a model with no metals and a template with models I need to align onto.
Updating issues:
I forgot to mention that I tried updating chimerax-daily with this command
sudo /usr/bin/chimerax-daily -m pip install --upgrade pip
which gave a success code. But when I checked the version via chimerax-daily --version I get this version.
UCSF ChimeraX version: 0.93 (2020-03-24)
Is there a way to update to the newest version without reinstalling? I found toolshed update documentation but this appears to be for packages not the entire build. As you can see it is not them most updated version. I downloaded bother chimerax and chimerax-daily again. chimerax installed and used foreach with no errors. However, chimerax-daily will not install unless I do a complete uninstall so I think I'll go forward with chimerax.
Another thing I noticed, while attempting ranges with chimerax-daily it only took single digit ranges. For example S_0001-[1-10]-chain-A.pdb if only took pdbs with "1" in place of the range. if the range is 1-9 then it takes all files. If the range is 01-19 (trying to match number of digits) if only takes models 1 and 9. I get what it is doing here but I don't know the fix or if I'm doing it right. I'm just using a range for now to test 9 files instead of the full 1000. I'll replace the numbering with a '*' so it'll get them all. I won't have an issues going forward but thought this was significant for others in the future if I had typed it wrong.
Thank you again for your time and help,
Ryan
On Thu, May 5, 2022 at 12:01 AM Tom Goddard <goddard@sonic.net> wrote:
Hi Ryan,
The "foreach" option you tried is exactly intended for this use. The error message "Missing filename suffix foreach" suggests you are using an old version of ChimeraX (older than ChimeraX 1.3) that does not have the "foreach" option so it thinks that "foreach" is the name of a file. Your script only saves one file so I don't understand what you mean by saving two files $file1 and $file2. You would just use "save $file-sf-aligned.pdb ..." to save the aligned file.
Tom
On May 4, 2022, at 10:41 PM, Ryan Woltz via ChimeraX-users < chimerax-users@cgl.ucsf.edu> wrote:
Dear community,
I'm sorry if this is a repeated question, I've seen a few posts about taking in a file for the command line and doing some things then exiting. I got most of this down and I'm sure at this point it is just a matter or correcting a few lines of code.
I'm trying to automate a protein modeling protocol and I have 1000 decoys at this point. Now I need to insert the 5 metals into 5 different pockets into all my decoys for a final relax before selecting my top model. I have a template pdb with all the metals in place. For 4 of these metals I have used rosetta align mover to align a decoy onto the template around a single metal binding site, save the pdb, then add on the metal coordinates then repeat for the next binding site. So this method works because the chain is continuous around these metal binding sites. However the final metal binding site is in the center and coordinated by 4 chains coming together and the positioning needs to be very precise.
Chimera or chimerax solves this very well but I don't know how to put this into a script. I have a few solutions if someone can help me edit this to work. My script (chimera-data-processing.cxc) looks like this right now.
cd results/ open S_0001_X-4-all-chain-A.pdb ###X = 1-1000 open
hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
info align #1:240-244,765-769,1290-1294,1815-1819@o to_atoms #2:240-244,765-769,1290-1294,1815-1819@o matchAtomNames true; wait 300 save S_0001_X-4-all-chain-A-sf-aligned.pdb #1 format pdb relModel #2; wait 30 cd ../ close quit
This script is perfect if run for have a single model with the exact name written into the script after typing:
chimerax-daily --nogui chimera-data-processing.cxc
I have two main solutions A) run a while loop that counts down and passes a filename to chimerax:
while ( X < 1000 )
chimerax-daily --nogui chimera-data-processing.cxc S_0001_X-4-all-chain-A.pdb
hsk2-cam-homology-from-map-refined-6cno-alignment-template-1-all-chain-A.pdb
Where in the chimerax script I take the arg1 (S_0001*.pdb) and arg2 (hsk2*.pdb)(assuming chimera-data-processing.cxc is arg0) and modify to look like this:
open $arg1 open $arg2 ... save $arg1-sf-aligned.pdb #1 format pdb relModel #2; wait 30
Option B is to use the foreach command described in the open
command
documentation ( https://www.cgl.ucsf.edu/chimerax/docs/user/commands/open.html). However, a copy and past of that command:
*open myscript.cxc foreach ~/data/*.cif * *or* *open chimera-data-processing.cxc foreach results/S_0001_*-4-* all-chain-A.pdb
results in this error:
Missing filename suffix foreach
I also tried this:
chimerax-daily --nogui chimera-data-processing.cxc foreach results/S_0001_*-4-all-chain-A.pdb
But it just runs the command. this seems to ignore everything after the first filename. I also read that if I used foreach inside the script I could use $file to replace the filename it is currently working on, would there be a way to fave $file1 and $file2? to automate this I'd also like the change the name of the template file I'm aligning to. I also attempted the python method using sys.arg = arg[1] then running things but I couldn't get it to work because I have no experience in python. What is the suggested way to complete this task? Again this is in a much larger script with user inputs so ideally it would look like this in a script (very shorthanded just for the concepts). I can also run a python command script in my bash sctipt
pdb transformations
if (y = 5) ###alignment metal number) while ( x < 1000) ###arg0 = command script arg1 = pdb to align arg2 = template pdb with metals chimerax-daily --nogui chimera-command-script.cxc $filenamebase$x-$alignmentnumber-*.pdb $template.pdb ###strings for variables are provided when script is initialized.
###code to extract metal coords for S_0001_$x-4-*.pdb
done fi
chimera-command-script.cxc: open arg1 open arg2 align model #1 to model #2 on specific atoms save arg1-new-filename.pdb close exit
if someone would like a follow-up email with my attempt at chimera python sctipt using runcommand I'm very happy to supply that as a foundation to help fix, I just thought this one is easier to fix since it is really close, the script works but only for 1 pdb at a time.
Apologies for bad scripting terminology and confusion with python, I've had to teach coding to myself so I might have misused terms.
Thanks for any help that can be given,
Ryan _______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
_______________________________________________ ChimeraX-users mailing list ChimeraX-users@cgl.ucsf.edu Manage subscription: https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
participants (4)
-
Christian Tüting
-
Eric Pettersen
-
Ryan Woltz
-
Tom Goddard