-
Notifications
You must be signed in to change notification settings - Fork 825
Added get_connections #3160
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
Added get_connections #3160
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2250,15 +2250,47 @@ def _bondDict(self): | |
| def set_atoms(self, ag): | ||
| return NotImplementedError("Cannot set bond information") | ||
|
|
||
| def get_atoms(self, ag): | ||
| def get_atoms(self, ag, outside=True): | ||
| """ | ||
| Get subset for atoms. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| ag : AtomGroup | ||
| outside : bool (optional) | ||
| Whether to include connections to atoms outside the given | ||
| AtomGroup. | ||
|
|
||
| .. versionchanged:: 1.1.0 | ||
| Added the ``outside`` keyword. Set to ``True`` by default | ||
| to give the same behavior as previously | ||
| """ | ||
| warn = True | ||
| try: | ||
| unique_bonds = set(itertools.chain( | ||
| *[self._bondDict[a] for a in ag.ix])) | ||
| except TypeError: | ||
| # maybe we got passed an Atom | ||
| unique_bonds = self._bondDict[ag.ix] | ||
| bond_idx, types, guessed, order = np.hsplit( | ||
| np.array(sorted(unique_bonds), dtype=object), 4) | ||
| warn = False | ||
| unique_bonds = np.array(sorted(unique_bonds), dtype=object) | ||
| if not outside: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why use a It makes it more readable imo
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I started with This will make it easier to add to 2.0, though, where we will not have the deprecation warning. |
||
| indices = np.array([list(bd[0]) for bd in unique_bonds]) | ||
| try: | ||
| mask = np.all(np.isin(indices, ag.ix), axis=1) | ||
| except np.AxisError: | ||
| mask = [] | ||
| unique_bonds = unique_bonds[mask] | ||
| elif warn: | ||
| warnings.warn("This group contains all connections " | ||
| "where at least one atom in the " | ||
| "AtomGroup is involved. In MDAnalysis " | ||
| "2.0 this behavior will change so that " | ||
| "the group only contains connections " | ||
| "where all atoms are in the AtomGroup.", | ||
| DeprecationWarning) | ||
|
|
||
| bond_idx, types, guessed, order = np.hsplit(unique_bonds, 4) | ||
| bond_idx = np.array(bond_idx.ravel().tolist(), dtype=np.int32) | ||
| types = types.ravel() | ||
| guessed = guessed.ravel() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we're not using
atomgroup_intersectionhere because this method can handle not just things in aTopologyGroup?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it was more to avoid having to distinguish between Atoms and AtomGroups (etc) with
ix_array, asatomgroup_intersectiononly accepts AtomGroupsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just realised that
Residue.bondsis not existing functionality, so I added tests.