Skip to content
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

Merged
merged 3 commits into from
Apr 4, 2021
Merged

Conversation

lilyminium
Copy link
Member

Relates to #1264
Relates to #2821

Changes made in this Pull Request:

  • Added get_connections method for Components and Groups to control which connections get returned
  • Added outside keyword to get_atoms argument of the Connection topology attributes, to easily toggle the behaviour of Groups.bonds, Groups.angles, etc. This is set to True to keep status quo for 1.1.0. It will be set to False in 2.0.0.
  • Added deprecation warning for the Groups.bonds, Groups.angles, etc. methods

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@pep8speaks
Copy link

pep8speaks commented Mar 14, 2021

Hello @lilyminium! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2021-04-04 13:46:20 UTC

@lilyminium lilyminium requested review from orbeckst and cbouy March 14, 2021 19:39
@lilyminium lilyminium mentioned this pull request Mar 14, 2021
9 tasks
@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #3160 (9c78cc1) into master (0880dc1) will increase coverage by 0.80%.
The diff coverage is 76.92%.

❗ Current head 9c78cc1 differs from pull request most recent head 85b84b9. Consider uploading reports for the commit 85b84b9 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3160      +/-   ##
==========================================
+ Coverage   90.98%   91.79%   +0.80%     
==========================================
  Files         162      167       +5     
  Lines       22197    22725     +528     
  Branches     3201     3206       +5     
==========================================
+ Hits        20196    20860     +664     
- Misses       1378     1781     +403     
+ Partials      623       84     -539     
Impacted Files Coverage Δ
package/MDAnalysis/core/topologyattrs.py 96.11% <57.14%> (+0.51%) ⬆️
package/MDAnalysis/core/groups.py 99.02% <100.00%> (+0.88%) ⬆️
package/MDAnalysis/topology/tpr/obj.py 96.82% <0.00%> (-3.18%) ⬇️
...onality_reduction/DimensionalityReductionMethod.py 97.14% <0.00%> (-2.86%) ⬇️
package/MDAnalysis/coordinates/ParmEd.py 88.26% <0.00%> (-2.29%) ⬇️
package/MDAnalysis/tests/__init__.py 100.00% <0.00%> (ø)
package/MDAnalysis/analysis/legacy/__init__.py 0.00% <0.00%> (ø)
package/MDAnalysis/analysis/legacy/x3dna.py 0.00% <0.00%> (ø)
package/MDAnalysis/due.py 56.09% <0.00%> (ø)
package/MDAnalysis/tests/datafiles.py 31.25% <0.00%> (ø)
... and 88 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0880dc1...85b84b9. Read the comment docs.

return mda.Universe(TPR)


class TestGetConnections(object):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get some tests to cover at the very least the two cases that were outlined in #1264 and #2821?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean those specific files and selections, or do you mean using the .bonds and .dihedrals attributes? The latter will have to wait until 2.0

Copy link
Member

@richardjgowers richardjgowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm.

.. versionadded:: 1.1.0
"""
# AtomGroup has handy error messages for missing attributes
ugroup = getattr(self.universe.atoms, typename)
Copy link
Member

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_intersection here because this method can handle not just things in a TopologyGroup?

Copy link
Member Author

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, as atomgroup_intersection only accepts AtomGroups

Copy link
Member Author

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.bonds is not existing functionality, so I added tests.

bond_idx, types, guessed, order = np.hsplit(
np.array(sorted(unique_bonds), dtype=object), 4)
unique_bonds = np.array(sorted(unique_bonds), dtype=object)
if not outside:
Copy link
Member

@cbouy cbouy Mar 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use a not here?

if outside: 
    <deprecation code>
else:
    <np.all>

It makes it more readable imo

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I started with strict=False 😅

This will make it easier to add to 2.0, though, where we will not have the deprecation warning.

@lilyminium
Copy link
Member Author

@IAlibay I forget where you asked me this, but the reason get_atoms doesn't use get_connections is it results in recursive logic. I think get_atoms is used to create the TopologyGroup that get_connections works off.

@richardjgowers richardjgowers merged commit b5ab73d into MDAnalysis:master Apr 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants