[Chimera-users] python script

Tom Goddard goddard at sonic.net
Thu Oct 25 16:27:35 PDT 2018


Hi Hernando,

  Here’s some Python that gets the residues of a molecule.  There is no Python chain object but the code shows how to get the chain ids.  Also it shows atom.xformCoord() that gets the transformed coordinate.  The transformed coordinate includes any rotation and translation you did with the mouse.

    Tom


import chimera
sel = chimera.selection.OSLSelection('#0')
sel.models()
-> [<_molecule.Molecule object at 0x11696ac10>]
m = sel.models[0]
r = m.residues
len(r)
-> 76
type(r)
-> <type 'list'>
r0 = r[0]
r0.id.chainId
-> u'A'
set(r0.id.chainId for r0 in r)
  -> set([u'A', u'B'])
a = r0.atoms[0]
a.xformCoord()
-> chimera.Point(15.491, 7.05, 17.165)





> On Oct 25, 2018, at 1:35 PM, Hernando J Sosa <hernando.sosa at einstein.yu.edu> wrote:
> 
> An additional question:
> Is it possible to retrieve the  atomic coordinates after a transformation (e.g. after an align/superposition  operation) rather than the original coordinate values?
>  
> e.g. I am currently using the following commands  to retrieve the coordinates (x,y,z) of  the CA atom in model,residue,chain
> atom    = chimera.selection.OSLSelection("#%d:%d.%c at CA" % (model,residue,chain)).vertices()
> (x,y,z)  = atom[0].coord()
>  
> However, this retrieves  the original coordinates not the coordinates after a transformation.
>  
> Thanks
>  
> Hernando
>  
> Hernando Sosa
> Dept. of Physiology and Biophysics 
> Albert Einstein College of Medicine 
> 1300 Morris Park Av. 
> Bronx NY 10461 
> phone (718) 430-3456 
> FAX (718) 430-8819 
> email hernando.sosa at einstein.yu.edu <mailto:hernando.sosa at einstein.yu.edu>
>  
> From: Chimera-users [mailto:chimera-users-bounces at cgl.ucsf.edu] On Behalf Of Hernando J Sosa
> Sent: Thursday, October 25, 2018 12:50 PM
> To: chimera-users BB
> Subject: [Chimera-users] python script
>  
> Dear Chimera,
>  
> I am writing a  Chimera python  script  and need to  get a list of the chains and residue numbers  of specific opened models . What would be the command/syntax to do that?  or can you point me to a code  example where something like this is done.
>  
> Thanks
>  
> Hernando  
>  
>  
> From: Chimera-users [mailto:chimera-users-bounces at cgl.ucsf.edu <mailto:chimera-users-bounces at cgl.ucsf.edu>] On Behalf Of Hernando J Sosa
> Sent: Monday, June 11, 2018 2:46 PM
> To: Eric Pettersen
> Cc: chimera-users BB
> Subject: Re: [Chimera-users] python script
>  
> Thanks Eric,
>  
> These alternatives is what I was looking for.
>  
> Best
>  
> Hernando
>  
> From: Eric Pettersen [mailto:pett at cgl.ucsf.edu <mailto:pett at cgl.ucsf.edu>] 
> Sent: Friday, June 08, 2018 7:27 PM
> To: Hernando J Sosa
> Cc: chimera-users BB
> Subject: Re: [Chimera-users] python script
>  
> Hi Hernando,
>             Perhaps runCommand should return a value but it doesn’t.  The reasoning there was that the argument to runCommand could be anything, including several commands separated by semi-colons, so in some cases it’s confusing what the return value should be.  In any case that ship has sailed and you have to do something else to get the value.  In most cases it calling the underlying function that performs the command and using it’s return value, but looking at the code that implements the “measure center” command I can see that it doesn’t return anything either.
>             So in the particular case of the example you provided, I can see two options for getting the value:
>  
> Option 1)
>             atoms = chimera.selection.OSLSelection(“#0:.A at CA”).vertices()
>             center = chimera.Point([a.coord() for a in atoms])
>             x, y, z = center.data()
>  
> Option 2)
>             rc(“sel #0:.A at CA”)
>             center = chimera.Point([a.coord() for a in chimera.selection.currentAtoms()])
>             x, y, z = center.data()
>  
> I hope this helps.
>  
> —Eric
>  
>             Eric Pettersen
>             UCSF Computer Graphics Lab
>  
>  
> 
> On Jun 8, 2018, at 11:10 AM, Hernando J Sosa <hernando.sosa at einstein.yu.edu <mailto:hernando.sosa at einstein.yu.edu>> wrote:
>  
> Dear Chimera,
>  
> Is it possible to assign the result of running a chimera command in python to a string or something else?  E.g doing something like:
>  
> from chimera import runCommand as rc
> myresult  = rc('measure center  #0:.A at CA')
>  
> And then using the  myresults somewhere else in the script after parsing for the relevant values?
>  
> Maybe there is a n easier way to accomplish this?
>  
> Thanks
>  
> Hernando
>  
>  
>  
> _______________________________________________
> Chimera-users mailing list: Chimera-users at cgl.ucsf.edu <mailto:Chimera-users at cgl.ucsf.edu>
> Manage subscription: http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users <http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users>
>  
> _______________________________________________
> Chimera-users mailing list: Chimera-users at cgl.ucsf.edu
> Manage subscription: http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20181025/5264ea5a/attachment.html>


More information about the Chimera-users mailing list