Selections as boolean arrays #4555
Replies: 1 comment 4 replies
-
I think what you have is as close as it gets. The selection mechanism is pretty closely tied to generating AtomGroups, but given that an AtomGroup is effectively just the index array (ix), we generally don't consider it much of a draw back. However, # BAD CODE
u = mda.Universe(TOP, TRJ)
results = []
for ts in u.trajectory:
p = u.select_atoms("protein") # bad! creates same AG repeatedly
results.append(p.radius_of_gyration()) Instead # BETTER
u = mda.Universe(TOP, TRJ)
results = []
p = u.select_atoms("protein") # only make static selection once
for ts in u.trajectory:
results.append(p.radius_of_gyration()) The alternative is to completely circumvent the selection parser and roll your own selections as in ca = u.atoms[u.atoms.names == "CA"] which works well for many simple selections but is not quite as general for the typical user. Of course, in your case |
Beta Was this translation helpful? Give feedback.
-
Would it be possible to get the result of an atom group selection as a boolean array for the parent atom group?
I am getting it as an array as follows, but I'd like to potentially remove the need for the
np.isin()
to speed it up.I have a bit of a peak at the source code and it seems like it is likely not possible, but I'm also not very familiar with how it all works.
I'm using it for masking the parent atom group inside of Blender for updating selections, as updating the actual atom group that is associated with the object would be quite difficult.
blender_kRRUEqGSDF.mp4
Beta Was this translation helpful? Give feedback.
All reactions