[Chimera-users] FW: Python code problem

Eric Pettersen pett at cgl.ucsf.edu
Wed Jun 3 11:24:57 PDT 2015


Hi Mahendra,
	Oops, yep my code was missing a triple quote.  Anyway, maybe you should send me your code and a test PDB file offline.  Clearly the code you included below is not the code that produced the output you provided.  In your code, j takes values in range(3429,3450), which does not include the value 3450 itself, yet in your output clearly j does have the value 3450.  So you either provided the wrong script or the wrong output.  I don't think anyone else on the list is interested in the details of what went wrong, so you should just mail me directly.

--Eric

On Jun 3, 2015, at 11:04 AM, Mahendra B Thapa <thapamb at mail.uc.edu> wrote:

> Dear Eric
> 
> I had not realized that not every amino acid consisted of CB atom. Thank you for the code which worked; just want to add a very minor addition ( """ ) to the left of the code, i.e.
> sel = OSLSelection("""#0.1:%d.B at CB""" %i) instead of sel = OSLSelection(#0.1:%d.B at CB""" %i)
> 
> I tried another code as
> import string
> rc("open " + 'test.pdb')   # 60 models, each model has chains A,B,C
> for i in [2196,2197]:
>             for j in range(3429,3450):
>                      for k in ['A','B','C']:
>                                sel = OSLSelection("""#0.3:%d.%s at CA""" %(j,k))
>                                sol = OSLSelection("""#0.2:%d.B at CA""" %i)
>                                if ((len(sel.residues()) != 1) or (len(sel.residues()) != 1)):
>                                             continue
>                                if ((len(sol.residues()) != 1) and (len(sol.residues()) != 1)):
>                                              continue
>                               rc("""distance #0.2:%d.B at CA #0.3:%d.%s at CA""" %(i,j,k))
> 
> I got the output as (without any error message)
> Distance between #0.2:2196.B at CA and #0.3:3450.C at CA: 104.315
> 
> The 'for' loop did not work for k (above) and only gave results for C only but not for A and B. 
> 
> Thank you for help,
> Mahendra Thapa
> University of Cincinnati,OH
> 
> 
> On Fri, May 29, 2015 at 1:55 PM, Thapa, Mahendra (thapamb) <thapamb at mail.uc.edu> wrote:
>  
>  From: Eric Pettersen
> Sent: Friday, May 29, 2015 11:55:18 AM (UTC-06:00) Central America
> To: Thapa, Mahendra (thapamb)
> Cc: chimera-users at cgl.ucsf.edu
> Subject: Re: [Chimera-users] Python code problem
> 
> Hi Mahendra,
> In the first case, as you saw, it tries exactly two distances; the first involving :2011.B and the second involving :2420.B.  In the second case it will try every distance from :2011.B through :2419.B (note that the range command does not include the ending number in the range).  This means if the structure is missing any of those residues then the distance command will fail with the error you got, since the atom spec will only select one atom.
> So you either need to explicitly use just the residue numbers that exist, or you need to test if the residue you are about to try to use exists.  So code to do that might be:
> 
> from chimera.selection import OSLSelection
> sel = OSLSelection(#0.1:%d.B at CB""" %i)
> if len(sel.residues()) != 1:
> continue
> 
> --Eric
> 
>                         Eric Pettersen
>                         UCSF Computer Graphics Lab
>                         http://www.cgl.ucsf.edu
> 
> On May 29, 2015, at 6:37 AM, Mahendra B Thapa <thapamb at mail.uc.edu> wrote:
> 
>> Dear Chimera users,
>> 
>>                         The command I used was
>>                          chimera --nogui test.py
>> I tried two codes (following previous posts and tutorials in chimera) in 'test.py' as follows
>> 
>> (i) 
>> import os
>> from chimera import runCommand as rc
>> from chimera import replyobj
>> rc("open " + 'test.pdb')
>> for i in [2011,2420]:
>> rc("""distance #0.2:2010.B at CB #0.1:%d.B at CB""" %i)
>> 
>> This code gave the result as expected:
>> Executing test.py...
>> Opening test.pdb...
>> 60 models opened
>> Distance between #0.2:2010.B at CB and #0.1:2011.B at CB: 72.346
>> Distance between #0.2:2010.B at CB and #0.1:2420.B at CB: 92.979
>> Executed test.py
>> 
>> (ii)
>> import os
>> from chimera import runCommand as rc
>> from chimera import replyobj
>> rc("open " + 'test.pdb')
>> for i in range(2011,2420):
>> rc("""distance #0.2:2010.B at CB #0.1:%d.B at CB""" %i)
>> 
>> This code gave the result as
>> '  You selected %d.' % numSelected)
>> MidasError: Exactly two atoms/axes/planes must be selected.  You selected 1.
>> Error while processing test.py:
>> MidasError: Exactly two atoms/axes/planes must be selected.  You selected 1.
>> 
>>   File "/opt/UCSF/Chimera64-1.5.3/share/Midas/__init__.py", line 1266, in distance
>>     '  You selected %d.' % numSelected)
>> 
>> What could be the error this code? Only difference between two codes is:  "for i in [2011,2420]:"  &  "for i in range(2011,2420):"
>> That is, I am interested to use range operator in 2nd case instead of two values as in the 1st case.
>> 
>> Thank you for help,
>> Mahendra Thapa
>> University of Cincinnati,OH
>> 
>> 
>> _______________________________________________
>> Chimera-users mailing list
>> Chimera-users at cgl.ucsf.edu
>> http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
> 
> 
> 
> 
> _______________________________________________
> Chimera-users mailing list
> Chimera-users at cgl.ucsf.edu
> 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/20150603/6e92868c/attachment-0001.html>


More information about the Chimera-users mailing list