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