[Chimera-users] savepos
Tom Goddard
goddard at sonic.net
Wed Jun 3 11:07:50 PDT 2015
Hi Matt,
A Python dictionary is not ordered. So positions.keys() can return the values in any order and it can and does change order as more positions are added (because it is a hash map which reallocates as the size grows). So if you want them ordered then you order them yourself, for instance alphabetically:
pnames = list(positions.keys())
pnames.sort()
Tom
> On Jun 3, 2015, at 6:07 AM, Dougherty, Matthew T wrote:
>
> Hi,
>
> I have been automating the creation of positions using python scripts. Something relatively simple like p001, p002, etc.
>
> When I examine the positions using the python commands
> from Midas import positions
> pnames = positions.keys()
>
> at first things appear as I would expect, but later the sequence changes relative to the index, why is that?
>
> for example, using this to print the positions
>
> pnames = positions.keys()
> i=0
> for pname in pnames:
> print i,pnames[i]
> i=i+1
>
>
>
>
> I get these results:
>
> savepos p000
> savepos p001
> 0 p000
> 1 p001
> (as expected)
>
> savepos p002
> 0 p000
> 1 p001
> 2 p002
> (as expected)
>
> savepos p003
> 0 p000
> 1 p001
> 2 p002
> 3 p003
> (as expected)
>
> savepos p004
> 0 p004
> 1 p000
> 2 p001
> 3 p002
> 4 p003
> (not as expected)
>
> savepos p005
> 0 p004
> 1 p005
> 2 p000
> 3 p001
> 4 p002
> 5 p003
> (not as expected)
>
>
> I would expect pnames[0] to correspond to the first position created, pnames[1] to the second posiiton created, etc., assuming no ~savepos used.
>
> Want to create a situation where the default names would be pxxx, but could later be altered to more meaningful names but maintain the order of creation, or getting a session file from someone I would use their position names and tack on my default names to the end of the position list.
>
>
>
> Matthew Dougherty
> National Center for Macromolecular Imaging
> Baylor College of Medicine
> ===========================================================================
> _______________________________________________
> Chimera-users mailing list
> Chimera-users at cgl.ucsf.edu <mailto:Chimera-users at cgl.ucsf.edu>
> http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users <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/4c704b54/attachment.html>
More information about the Chimera-users
mailing list