-
Notifications
You must be signed in to change notification settings - Fork 663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set operations for Groups #726
Comments
Hey Kyle, Yeah I think this would be great. I think @jbarnoud ? recently proposed this somewhere else, but I can't find it for the life of me. We're changing how AtomGroups work quite soon, but I think most of the hard work here is coming up with solid tests (which won't change) rather than the actual AtomGroup methods (which will change). So yeah, put together something |
I have a work in progress based on the new topology scheme. I implemented all the set operators and I am working at testing them. The current status is visible at https://github.com/jbarnoud/mdanalysis/commits/issue-363-set-operators. |
Since |
As a workaround while we decide and develop you can use: # to emulate difference = grp1 - grp2
difference = grp1.select_atoms("not group other", other=grp2) |
@dotsdl Yes. When using set operations, the repeats are dropped in the result, and the index are sorted. |
Thank you for that @mnmelo - I didn't know about the other keyword. So since |
As a clarification on the workaround: difference = grp1.select_atoms("not group khuston", khuston=grp2) |
One option here is to not use the |
I really like the idea of having all set operators available, and not only the corresponding functions. But I have to agree that, in the particular case of |
My expectation for "-" would be that it
i.e., def subtract(a, b):
return [idx for idx in a.indices if idx in b.indices] Admittedly, these are not |
@orbeckst So for example? ag1 = [1, 2, 2, 5, 4, 3]
ag2 = [2, 4]
ag1 - ag2 = [1, 5, 3] That makes sense to me (and is the opposite to |
Yes, that's what makes sense to me. Oliver Beckstein Am Feb 23, 2016 um 3:24 schrieb Richard Gowers [email protected]:
|
@jbarnoud did some cool code here: Should we add these directly as Group methods? Or have a |
See #726 This commit introduce several method to the GroupBase class, including all the set operators, and a subtract method. Some operator symbols are overridden.
See #726 This commit introduce several method to the GroupBase class, including all the set operators, and a subtract method. Some operator symbols are overridden.
Introduce operators to groups Fixes #726
I apologize if this is already a feature or if has been discussed before, but I've often thought AtomGroup subtraction would be a convenient feature, in the same way
__add__
is already overridden for AtomGroup. It would be defined in the same way set subtraction is defined for Python:For AtomGroup instances:
For Atom instances:
It's a simple addition, but it seems to work. If it's alright, I can submit a pull request with the feature and tests.
Example usage:
The text was updated successfully, but these errors were encountered: