[chimera-dev] attribute for selection?
Conrad Huang
conrad at cgl.ucsf.edu
Thu Oct 11 08:50:43 PDT 2012
Chimera does not use an attribute for "selectedness" because there are
actually multiple classes of objects that may be selected. As you
discovered, chimera.selection.currentSOMETHING() will return the
selected objects of the correct type.
To make your code run faster, you should not call
chimera.selection.currentAtoms() inside the loop because it gets
recomputed unnecessarily. Instead, try something like:
selected = frozenset(chimera.selection.currentAtoms())
for a in chimera.openModels.list()[0].atoms:
if a in selected:
print "this atom is selected"
else:
print "this one isn't"
This should run much faster for two reasons: (a) the selected atoms are
not recomputed multiple times, and (b) the "a in ..." test is using a
set instead of a list (returned by currentAtoms()) and should be much
more efficient.
Hope this helps
Conrad
On 10/11/12 5:19 AM, Jean Didier Pie Marechal wrote:
> Sorry,
>
> just to clarify my previous request:
>
> this is a script that does what I want though a selection attribute would be faster I think.
>
> for a in chimera.openModels.list()[0].atoms:
> if a in chimera.selection.currentAtoms():
> print "this atom of the molecule is selected" #to say something
> else: print "this one isn't"
>
> cheers
>
>
> Dr. Jean-Didier Maréchal
> Lecturer
> The Computational Biotechnological Chemistry Team
> Unitat de Química Física
> Departament de Química
> Universitat Autònoma de Barcelona
> Edifici C.n.
> 08193 Cerdanyola (Barcelona)
> Tel: +34.935814936
> e-mail: JeanDidier.Marechal at uab.es
> www: http://asklipio.qf.uab.es
>
> ----- Missatge original -----
> De: Jean Didier Pie Marechal <JeanDidier.Marechal at uab.cat>
> Data: Dijous, Octubre 11, 2012 12:39 pm
> Assumpte: attribute for selection?
>
>> HI,
>>
>> I want to add attributes to atoms that are selected and those that
>> aren't. I thought that atoms had a selection attribute already
>> defined in chimera (something like a boolean) but I don't find it.
>> I am wrong with that?
>>
>> best,
>> JD
>>
>>
>> Dr. Jean-Didier Maréchal
>> Lecturer
>> The Computational Biotechnological Chemistry Team
>> Unitat de Química Física
>> Departament de Química
>> Universitat Autònoma de Barcelona
>> Edifici C.n.
>> 08193 Cerdanyola (Barcelona)
>> Tel: +34.935814936
>> e-mail: JeanDidier.Marechal at uab.es
>> www: http://asklipio.qf.uab.es
>>
>
>
> _______________________________________________
> Chimera-dev mailing list
> Chimera-dev at cgl.ucsf.edu
> http://www.rbvi.ucsf.edu/mailman/listinfo/chimera-dev
>
More information about the Chimera-dev
mailing list