[chimerax-users] python loop with ChimeraX

Tom Goddard goddard at sonic.net
Tue Jul 20 18:24:50 PDT 2021


Hi Amith,

It is also possible to run a ChimeraX command script (.cxc) file once on each PDB file in a directory.

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

as described in the docs

	https://www.rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile <https://www.rbvi.ucsf.edu/chimerax/docs/user/commands/open.html#forEachFile>

That was added after the ChimeraX 1.2 release so would need the ChimeraX daily build to use it.

	Tom


> On Jul 20, 2021, at 5:42 PM, Rangarajan, Amith via ChimeraX-users <chimerax-users at cgl.ucsf.edu> wrote:
> 
> Dear Elaine  & Eric
> 
> Thanks a lot !. i now have a better sense of how to approach this . I will update this thread soon with the results.
> 
> 
> best
> Amith
> From: Eric Pettersen <pett at cgl.ucsf.edu <mailto:pett at cgl.ucsf.edu>>
> Sent: Tuesday, July 20, 2021 3:50 PM
> To: ChimeraX Users Help <ChimeraX-users at cgl.ucsf.edu <mailto:ChimeraX-users at cgl.ucsf.edu>>
> Cc: Rangarajan, Amith <Amith.Rangarajan at ucsf.edu <mailto:Amith.Rangarajan at ucsf.edu>>
> Subject: Re: [chimerax-users] python loop with ChimeraX
>  
> This Message Is From an External Sender 
> This message came from outside your organization. 
> To supplement Elaine's answer, looping through a set of data files and applying commands to them is done in a fashion very similar to the way it is done in Chimera, and therefore the documentation for how to do it in Chimera is still pretty useful:  Very Basic Chimera Programming Primer <https://www.cgl.ucsf.edu/chimera/docs/ProgrammersGuide/basicPrimer.html>
> 
> The differences are:
> 
> 1) ChimeraX is Python 3 whereas Chimera is Python 2.  That doesn't actually make any difference to the code shown in the example except for the import statements, which would have to change anyway.
> 
> 2) To run a command, instead of:
> 
> from chimera import runCommand
> runCommand("color red")
> 
> it's:
> 
> from chimerax.core.commands import run
> run(session, "color red")
> 
> 3) To issue status messages, instead of:
> 
> from chimera import replyobj
> replyobj.status("Processing file")
> 
> it's just:
> 
> session.logger.status("Processing file")
> 
> --Eric
> 
> Eric Pettersen
> UCSF Computer Graphics Lab
> 
> 
>> On Jul 20, 2021, at 11:28 AM, Elaine Meng via ChimeraX-users <chimerax-users at cgl.ucsf.edu <mailto:chimerax-users at cgl.ucsf.edu>> wrote:
>> 
>> One correction, the saved attribute file should have "defattr" filename extension instead of "txt", so my examples should instead be:
>> 
>> save /location/myfile.defattr  attrName r:area
>> save /location/myfile.defattr attrName r:area selectedOnly true
>> 
>> Sorry about that.
>> Elaine
>> 
>>> On Jul 20, 2021, at 11:23 AM, Elaine Meng via ChimeraX-users <chimerax-users at cgl.ucsf.edu <mailto:chimerax-users at cgl.ucsf.edu>> wrote:
>>> 
>>> Hi Amith,
>>> Seems like two parts to this question:
>>> (A) what are the ChimeraX commands (which could be put into a .cxc file)?
>>> (B) how to loop over multiple inputs?  ...alluded to by "python loop" in your subject line... .cxc files only contain ChimeraX commands, not python.
>>> 
>>> I don't know python, so somebody else would need to address part B, but I can give some hints on part A.  However, depending on the solution to part B, you might instead choose to just make a python script instead of using ChimeraX commands directly.  The usual procedure is to figure out the commands first, often with some trial and error of simply typing them in to the command line.
>>> 
>>> Relevant ChimeraX commands are "measure sasa" to assign residue SASA values as an attribute and then "save" to write the file of attribute values. 
>>> 
>>> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/measure.html#sasa <https://rbvi.ucsf.edu/chimerax/docs/user/commands/measure.html#sasa>>
>>> <https://rbvi.ucsf.edu/chimerax/docs/user/commands/save.html#attributes <https://rbvi.ucsf.edu/chimerax/docs/user/commands/save.html#attributes>>
>>> 
>>> I'm guessing you want the SASA of the residues but in the context of the complex, i.e. if they are completely buried in the interface between two proteins even though they would be on the surface of one protein by itself, you would still expect SASA zero.  In that case, you'd want the surface to enclose all the proteins in one blob, and then get the SASA of individual residues, and the command would be something like
>>> 
>>> measure sasa protein setAttribute true
>>> save /location/myfile.txt  attrName r:area
>>> 
>>> However, if you only want to specify certain residues instead of writing a file for all residues, you would need to use "select" command to select them and then save with the selectedOnly option, e.g. something like
>>> 
>>> select /A:24-53 /B:258
>>> save /location/myfile.txt  attrName r:area selectedOnly true
>>> 
>>> For part B you may need to embed these in some python script where it keeps closing the previous structure, opening a new structure, and substituting a different name for each save file.
>>> 
>>> I hope this helps,
>>> Elaine
>>> -----
>>> Elaine C. Meng, Ph.D.                       
>>> UCSF Chimera(X) team
>>> Department of Pharmaceutical Chemistry
>>> University of California, San Francisco
>>> 
>>>> On Jul 20, 2021, at 10:12 AM, Rangarajan, Amith via ChimeraX-users <chimerax-users at cgl.ucsf.edu <mailto:chimerax-users at cgl.ucsf.edu>> wrote:
>>>> 
>>>> Hi,
>>>> I am new to chimeraX , i want to loop through a set of biological assemblies  measuring SASA of  selecting residues and write them to a file. I need some help with starting on this .How to include this into the .cxc script? is there a example somewhere?
>>>> please share your tips and suggestions,
>>>> thanks everyone !
>>>> warm regards,
>>>> Amith
>>> 
>>> 
>>> _______________________________________________
>>> ChimeraX-users mailing list
>>> ChimeraX-users at cgl.ucsf.edu <mailto:ChimeraX-users at cgl.ucsf.edu>
>>> Manage subscription:
>>> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
>> 
>> 
>> _______________________________________________
>> ChimeraX-users mailing list
>> ChimeraX-users at cgl.ucsf.edu <mailto:ChimeraX-users at cgl.ucsf.edu>
>> Manage subscription:
>> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users
> 
> _______________________________________________
> ChimeraX-users mailing list
> ChimeraX-users at cgl.ucsf.edu
> Manage subscription:
> https://www.rbvi.ucsf.edu/mailman/listinfo/chimerax-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimerax-users/attachments/20210720/910f4e44/attachment.html>


More information about the ChimeraX-users mailing list