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

Add pbc kwarg to Contacts #2646

Merged
merged 8 commits into from Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package/CHANGELOG
Expand Up @@ -73,6 +73,7 @@ Fixes
* Fixed HydrogenBondAnalysis to return atom indices rather than atom ids (PR #2572).
Fixed the check for bond information in the _get_dh_pairs method (Issue #2396).
* Added missing selection module to leaflet.py (Issue #2612)
* Contact Analysis class respects PBC (Issue #2368)

Enhancements
* Added new density.DensityAnalysis (Issue #2502)
Expand Down
2 changes: 2 additions & 0 deletions package/MDAnalysis/analysis/contacts.py
Expand Up @@ -373,6 +373,8 @@ class Contacts(AnalysisBase):
.. versionchanged:: 1.0.0
``save()`` method has been removed. Use ``np.savetxt()`` on
:attr:`Contacts.timeseries` instead.
.. versionchanged:: 2.0.0
Copy link
Member

Choose a reason for hiding this comment

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

Thanks @ss62171, just one final thing -- this should be for version 1.0.0 which hasn't been released yet.

added ``pbc`` attribute to calculate distances using PBC.

"""
def __init__(self, u, select, refgroup, method="hard_cut", radius=4.5,
Expand Down
17 changes: 7 additions & 10 deletions testsuite/MDAnalysisTests/analysis/test_contacts.py
Expand Up @@ -303,8 +303,13 @@ def test_non_callable_method(self, universe):
with pytest.raises(ValueError):
self._run_Contacts(universe, method=2, stop=2)

@pytest.mark.parametrize("pbc", (True, False))
def test_distance_box(self, pbc):
@pytest.mark.parametrize("pbc,expected", [
(True, [1., 0.43138152, 0.3989021, 0.43824337, 0.41948765,
0.42223239, 0.41354071, 0.43641354, 0.41216834, 0.38334858]),
(False, [1., 0.42327791, 0.39192399, 0.40950119, 0.40902613,
0.42470309, 0.41140143, 0.42897862, 0.41472684, 0.38574822])
])
def test_distance_box(self, pbc, expected):
u = mda.Universe(TPR, XTC)
sel_basic = "(resname ARG LYS)"
sel_acidic = "(resname ASP GLU)"
Expand All @@ -314,14 +319,6 @@ def test_distance_box(self, pbc):
r = contacts.Contacts(u, select=(sel_acidic, sel_basic),
refgroup=(acidic, basic), radius=6.0, pbc=pbc)
r.run()
if pbc:
expected = [1., 0.43138152, 0.3989021, 0.43824337, 0.41948765,
0.42223239, 0.41354071, 0.43641354, 0.41216834, 0.38334858]

else:
expected = [1., 0.42327791, 0.39192399, 0.40950119, 0.40902613,
0.42470309, 0.41140143, 0.42897862, 0.41472684, 0.38574822]

assert_array_almost_equal(r.timeseries[:, 1], expected)

def test_q1q2():
Expand Down