-
Notifications
You must be signed in to change notification settings - Fork 825
Make contacts.Contacts use the Results class #3264
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8b6c2be
Adds results.timeseries, and tests
IAlibay 79d53ac
fix tests
IAlibay b82c1b4
update changelog
IAlibay a704536
Update contacts.py
IAlibay 5096bff
Merge branch 'develop' into results-contacts
orbeckst 4470725
update deprecation in CHANGELOG
orbeckst 3cfa8c6
Update docstring, add deprecation changelog entry
IAlibay 95953ed
Merge branch 'results-contacts' of github.com:IAlibay/mdanalysis into…
IAlibay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,13 +20,15 @@ | |
| # MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations. | ||
| # J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787 | ||
| # | ||
| import warnings | ||
| import MDAnalysis as mda | ||
| import pytest | ||
| from MDAnalysis.analysis import contacts | ||
| from MDAnalysis.analysis.distances import distance_array | ||
|
|
||
| from numpy.testing import ( | ||
| assert_almost_equal, | ||
| assert_equal, | ||
| assert_array_equal, | ||
| assert_array_almost_equal | ||
| ) | ||
|
|
@@ -185,18 +187,18 @@ def test_startframe(self, universe): | |
|
|
||
| """ | ||
| CA1 = self._run_Contacts(universe) | ||
| assert len(CA1.timeseries) == universe.trajectory.n_frames | ||
| assert len(CA1.results.timeseries) == universe.trajectory.n_frames | ||
|
|
||
| def test_end_zero(self, universe): | ||
| """test_end_zero: TestContactAnalysis1: stop frame 0 is not ignored""" | ||
| CA1 = self._run_Contacts(universe, stop=0) | ||
| assert len(CA1.timeseries) == 0 | ||
| assert len(CA1.results.timeseries) == 0 | ||
|
|
||
| def test_slicing(self, universe): | ||
| start, stop, step = 10, 30, 5 | ||
| CA1 = self._run_Contacts(universe, start=start, stop=stop, step=step) | ||
| frames = np.arange(universe.trajectory.n_frames)[start:stop:step] | ||
| assert len(CA1.timeseries) == len(frames) | ||
| assert len(CA1.results.timeseries) == len(frames) | ||
|
|
||
| def test_villin_folded(self): | ||
| # one folded, one unfolded | ||
|
|
@@ -213,7 +215,7 @@ def test_villin_folded(self): | |
| q.run() | ||
|
|
||
| results = soft_cut(f, u, sel, sel) | ||
| assert_almost_equal(q.timeseries[:, 1], results[:, 1]) | ||
| assert_almost_equal(q.results.timeseries[:, 1], results[:, 1]) | ||
|
|
||
| def test_villin_unfolded(self): | ||
| # both folded | ||
|
|
@@ -230,7 +232,7 @@ def test_villin_unfolded(self): | |
| q.run() | ||
|
|
||
| results = soft_cut(f, u, sel, sel) | ||
| assert_almost_equal(q.timeseries[:, 1], results[:, 1]) | ||
| assert_almost_equal(q.results.timeseries[:, 1], results[:, 1]) | ||
|
|
||
| def test_hard_cut_method(self, universe): | ||
| ca = self._run_Contacts(universe) | ||
|
|
@@ -254,8 +256,8 @@ def test_hard_cut_method(self, universe): | |
| 0.48543689, 0.44660194, 0.4368932, 0.40776699, 0.41747573, | ||
| 0.48543689, 0.45631068, 0.46601942, 0.47572816, 0.51456311, | ||
| 0.45631068, 0.37864078, 0.42718447] | ||
| assert len(ca.timeseries) == len(expected) | ||
| assert_array_almost_equal(ca.timeseries[:, 1], expected) | ||
| assert len(ca.results.timeseries) == len(expected) | ||
| assert_array_almost_equal(ca.results.timeseries[:, 1], expected) | ||
|
|
||
| def test_radius_cut_method(self, universe): | ||
| acidic = universe.select_atoms(self.sel_acidic) | ||
|
|
@@ -268,7 +270,7 @@ def test_radius_cut_method(self, universe): | |
| expected.append(contacts.radius_cut_q(r[initial_contacts], None, radius=6.0)) | ||
|
|
||
| ca = self._run_Contacts(universe, method='radius_cut') | ||
| assert_array_equal(ca.timeseries[:, 1], expected) | ||
| assert_array_equal(ca.results.timeseries[:, 1], expected) | ||
|
|
||
| @staticmethod | ||
| def _is_any_closer(r, r0, dist=2.5): | ||
|
|
@@ -285,7 +287,7 @@ def test_own_method(self, universe): | |
| 1., 0., 1., 1., 1., 1., 1., 1., 0., 1., 1., 0., 1., | ||
| 0., 0., 1., 1., 0., 0., 1., 1., 1., 0., 1., 0., 0., | ||
| 1., 0., 1., 1., 1., 1., 1.] | ||
| assert_array_equal(ca.timeseries[:, 1], bound_expected) | ||
| assert_array_equal(ca.results.timeseries[:, 1], bound_expected) | ||
|
|
||
| @staticmethod | ||
| def _weird_own_method(r, r0): | ||
|
|
@@ -315,7 +317,16 @@ def test_distance_box(self, pbc, expected): | |
| r = contacts.Contacts(u, select=(sel_acidic, sel_basic), | ||
| refgroup=(acidic, basic), radius=6.0, pbc=pbc) | ||
| r.run() | ||
| assert_array_almost_equal(r.timeseries[:, 1], expected) | ||
| assert_array_almost_equal(r.results.timeseries[:, 1], expected) | ||
|
|
||
| def test_warn_deprecated_attr(self, universe): | ||
| """Test for warning message emitted on using deprecated `timeseries` | ||
| attribute""" | ||
| CA1 = self._run_Contacts(universe, stop=1) | ||
| wmsg = "The `timeseries` attribute was deprecated in MDAnalysis" | ||
| with pytest.warns(DeprecationWarning, match=wmsg): | ||
| assert_equal(CA1.timeseries, CA1.results.timeseries) | ||
|
Comment on lines
+322
to
+328
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. good test: check for message and equality |
||
|
|
||
|
|
||
| def test_q1q2(): | ||
| u = mda.Universe(PSF, DCD) | ||
|
|
@@ -342,7 +353,7 @@ def test_q1q2(): | |
| 0.93097184, 0.93006358, 0.93188011, 0.93278837, 0.93006358, | ||
| 0.92915531, 0.92824705, 0.92733878, 0.92643052, 0.93188011, | ||
| 0.93006358, 0.9346049, 0.93188011] | ||
| assert_array_almost_equal(q1q2.timeseries[:, 1], q1_expected) | ||
| assert_array_almost_equal(q1q2.results.timeseries[:, 1], q1_expected) | ||
|
|
||
| q2_expected = [0.94649446, 0.94926199, 0.95295203, 0.95110701, 0.94833948, | ||
| 0.95479705, 0.94926199, 0.9501845, 0.94926199, 0.95387454, | ||
|
|
@@ -364,4 +375,4 @@ def test_q1q2(): | |
| 0.97140221, 0.97601476, 0.97693727, 0.98154982, 0.98431734, | ||
| 0.97601476, 0.9797048, 0.98154982, 0.98062731, 0.98431734, | ||
| 0.98616236, 0.9898524, 1.] | ||
| assert_array_almost_equal(q1q2.timeseries[:, 2], q2_expected) | ||
| assert_array_almost_equal(q1q2.results.timeseries[:, 2], q2_expected) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.