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

Survival probability: Intermittency, Step, Residues, Overlapping SP Selection Example #2226

Merged
merged 20 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
0a24544
Added skipping frames that are not used in the Survival Probability a…
bieniekmateusz Jan 18, 2019
a0edf64
Use the same code for loading the frames regardless of whether the step
bieniekmateusz Jan 23, 2019
a9abc50
A test case that checks if all frames are loaded. This is the
bieniekmateusz Jan 23, 2019
036140a
Refactoring with the simpler "return_value" when possible with the mock
bieniekmateusz Jan 23, 2019
f45a005
Better "verbose" message - avoid polluting.
bieniekmateusz Jan 23, 2019
91037bc
The SP value of entire residues can be calculated, regardless
bieniekmateusz Jan 31, 2019
f9e829b
Intermittency added with a simple implementation. Intermittency is taken
bieniekmateusz Feb 28, 2019
91a1781
Refactored intermittency: fewer nested blocks, giving the user access
bieniekmateusz Feb 28, 2019
4dde01f
Minor updates to the documentation.
bieniekmateusz Mar 1, 2019
ba79bcf
New test cases for the step+intermittency relation. - not finished
bieniekmateusz Mar 8, 2019
ff4d266
The relationship between the intermittency and the window "step"
bieniekmateusz Mar 8, 2019
417d229
Corrected documentation / proofreading.
bieniekmateusz Mar 8, 2019
3576984
An example covering the case with multiple references for the SP
bieniekmateusz Mar 8, 2019
4083378
Merge branch 'survival_probability' of https://github.com/bieniekmate…
orbeckst Apr 3, 2019
b67a7da
Logging changes made regarding Survival Probability
bieniekmateusz Apr 3, 2019
970e05b
Corrections from PR #2226
bieniekmateusz Apr 3, 2019
3a46b34
Merge branch 'survival_probability' of https://github.com/bieniekmate…
orbeckst Apr 4, 2019
aaf30bc
Numpy documentation style: PR #2226
bieniekmateusz Apr 5, 2019
d2b4f08
Merge branch 'survival_probability' of github.com:bieniekmateusz/mdan…
bieniekmateusz Apr 5, 2019
657f918
Merge branch 'develop' into survival_probability
orbeckst Apr 5, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions package/MDAnalysis/analysis/waterdynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1273,15 +1273,42 @@ def run(self, tau_max=20, start=0, stop=None, step=1, verbose=False):
if tau_max > (stop - start):
raise ValueError("Too few frames selected for given tau_max.")

# load all frames to an array of sets
# preload the frames (selected ids) to a list of sets
selected_ids = []
for ts in self.universe.trajectory[start:stop]:
self.print(verbose, "Loading frame:", ts)
selected_ids.append(set(self.universe.select_atoms(self.selection).ids))
if step <= tau_max + 1:
# load all frames
for ts in self.universe.trajectory[start:stop]:
self.print(verbose, "Loading frame:", ts)
selected_ids.append(set(self.universe.select_atoms(self.selection).ids))
else:
# skip frames that will not be used
# Example: step 5 and tau 2: L, L, L, S, S, L, L, L, S, S, ... with L = Load, and S = Skip
loaded_counter = 0
bieniekmateusz marked this conversation as resolved.
Show resolved Hide resolved
no_of_frames_to_load = tau_max + 1
skipped = 0
no_of_frames_to_skip = step - (tau_max + 1)
for ts in self.universe.trajectory[start:stop]:
if skipped == no_of_frames_to_skip:
skipped = 0
loaded_counter = 0

if loaded_counter == no_of_frames_to_load:
self.print(verbose, "Skipping loading frame:", ts)
skipped += 1
continue

self.print(verbose, "Loading frame:", ts)
selected_ids.append(set(self.universe.select_atoms(self.selection).ids))

loaded_counter += 1


tau_timeseries = np.arange(1, tau_max + 1)
sp_timeseries_data = [[] for _ in range(tau_max)]

# frames not analysed are skipped because they were not loaded
step = tau_max + 1 if step >= (tau_max + 1) else step

for t in range(0, len(selected_ids), step):
Nt = len(selected_ids[t])

Expand Down
14 changes: 13 additions & 1 deletion testsuite/MDAnalysisTests/analysis/test_waterdynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import numpy as np
from mock import patch
from mock import Mock
from numpy.testing import assert_almost_equal
from numpy.testing import assert_almost_equal, assert_equal

SELECTION1 = "byres name OH2"
SELECTION2 = "byres name P1"
Expand Down Expand Up @@ -120,3 +120,15 @@ def test_SurvivalProbability_alwaysPresent(universe):
sp = waterdynamics.SurvivalProbability(universe, "")
sp.run(tau_max=3, start=0, stop=6)
assert all(np.equal(sp.sp_timeseries, 1))


def test_SurvivalProbability_stepLargerThanDtmax(universe):
# Testing if the frames are skipped correctly
with patch.object(universe, 'select_atoms', return_value=Mock(ids=(1,))) as select_atoms_mock:
sp = waterdynamics.SurvivalProbability(universe, "")
sp.run(tau_max=2, step=5, stop=9, verbose=True)
assert_equal(sp.sp_timeseries, [1, 1])
# with tau_max=2 for all the frames we only read 6 of them
# this is because the frames which are not used are skipped, and therefore 'select_atoms'
assert universe.trajectory.n_frames > 6
assert_equal(select_atoms_mock.call_count, 6)