[chimerax-users] Chimerax scripting error and passing user supplied arguments
Ryan Woltz
rlwoltz at ucdavis.edu
Thu May 5 20:11:41 PDT 2022
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 at o to_atoms
#2:240-244,765-769,1290-1294,1815-1819 at 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 at o to_atoms
#2:240-244,765-769,1290-1294,1815-1819 at 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 at 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 at 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 at o to_atoms
> #2:240-244,765-769,1290-1294,1815-1819 at 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 at cgl.ucsf.edu
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.rbvi.ucsf.edu/pipermail/chimerax-users/attachments/20220505/8ea4851d/attachment.html>
More information about the ChimeraX-users
mailing list