-
Notifications
You must be signed in to change notification settings - Fork 22
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 InterRDF_s #70
Add InterRDF_s #70
Changes from 10 commits
0ca2f0f
3582cba
fc512db
16e369a
a4d38f8
396b758
e56c5f7
b17d737
ea65bc4
9024223
df87438
166d78f
9c49991
f384984
9f738b6
44b5549
eea692f
d238bb4
f09b024
60a000d
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*- | ||
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | ||
# | ||
# PMDA | ||
# Copyright (c) 2017 The MDAnalysis Development Team and contributors | ||
# (see the file AUTHORS for the full list of names) | ||
# | ||
# Released under the GNU Public Licence, v2 or any higher version | ||
from __future__ import absolute_import, division | ||
|
||
import pytest | ||
|
||
from numpy.testing import assert_almost_equal | ||
|
||
import MDAnalysis as mda | ||
import numpy as np | ||
from pmda.rdf import InterRDF_s | ||
from MDAnalysis.analysis import rdf | ||
|
||
from MDAnalysisTests.datafiles import GRO_MEMPROT, XTC_MEMPROT | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def u(): | ||
return mda.Universe(GRO_MEMPROT, XTC_MEMPROT) | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def sels(u): | ||
s1 = u.select_atoms('name ZND and resid 289') | ||
s2 = u.select_atoms( | ||
'(name OD1 or name OD2) and resid 51 and sphzone 5.0 (resid 289)') | ||
s3 = u.select_atoms('name ZND and (resid 291 or resid 292)') | ||
s4 = u.select_atoms('(name OD1 or name OD2) and sphzone 5.0 (resid 291)') | ||
ags = [[s1, s2], [s3, s4]] | ||
return ags | ||
|
||
|
||
@pytest.fixture(scope='module') | ||
def rdf_s(u, sels): | ||
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. Test with different schedulers: def rdf_s(u, sels, scheduler) 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. (The |
||
return InterRDF_s(u, sels).run() | ||
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. Can you test with different I don't know if this is actually testing multiple blocks or not. We need to know that the "accumulator" is working with multiple blocks. 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. Should work with |
||
|
||
|
||
def test_nbins(u): | ||
ags = sels(u) | ||
rdf = InterRDF_s(u, ags, nbins=412).run() | ||
|
||
assert len(rdf.bins) == 412 | ||
|
||
|
||
def test_range(u): | ||
ags = sels(u) | ||
rmin, rmax = 1.0, 13.0 | ||
rdf = InterRDF_s(u, ags, range=(rmin, rmax)).run() | ||
|
||
assert rdf.edges[0] == rmin | ||
assert rdf.edges[-1] == rmax | ||
|
||
|
||
def test_count_size(rdf_s): | ||
# ZND vs OD1 & OD2 | ||
# should see 2 elements in rdf.count | ||
# 1 element in rdf.count[0] | ||
# 2 elements in rdf.count[0][0] | ||
# 2 elements in rdf.count[1] | ||
# 2 elements in rdf.count[1][0] | ||
# 2 elements in rdf.count[1][1] | ||
assert len(rdf_s.count) == 2 | ||
assert len(rdf_s.count[0]) == 1 | ||
assert len(rdf_s.count[0][0]) == 2 | ||
assert len(rdf_s.count[1]) == 2 | ||
assert len(rdf_s.count[1][0]) == 2 | ||
assert len(rdf_s.count[1][1]) == 2 | ||
|
||
|
||
def test_count(rdf_s): | ||
# should see one distance with 5 counts in count[0][0][1] | ||
# should see one distance with 3 counts in count[1][1][0] | ||
assert len(rdf_s.count[0][0][1][rdf_s.count[0][0][1] == 5]) == 1 | ||
assert len(rdf_s.count[1][1][0][rdf_s.count[1][1][0] == 3]) == 1 | ||
|
||
|
||
def test_double_run(rdf_s): | ||
# running rdf twice should give the same result | ||
assert len(rdf_s.count[0][0][1][rdf_s.count[0][0][1] == 5]) == 1 | ||
assert len(rdf_s.count[1][1][0][rdf_s.count[1][1][0] == 3]) == 1 | ||
|
||
|
||
def test_cdf(rdf_s): | ||
rdf_s.get_cdf() | ||
assert rdf_s.cdf[0][0][0][-1] == rdf_s.count[0][0][0].sum()/rdf_s.nf | ||
|
||
|
||
def test_reduce(rdf_s): | ||
# should see numpy.array addtion | ||
res = [] | ||
single_frame = np.array([np.array([1, 2]), np.array([3])]) | ||
res = rdf_s._reduce(res, single_frame) | ||
res = rdf_s._reduce(res, single_frame) | ||
assert_almost_equal(res[0], np.array([2, 4])) | ||
assert_almost_equal(res[1], np.array([6])) | ||
|
||
|
||
def test_same_result(u, sels): | ||
# should see same results from analysis.rdf.InterRDF_s | ||
# and pmda.rdf.InterRDF_s | ||
nrdf = rdf.InterRDF_s(u, sels).run() | ||
prdf = InterRDF_s(u, sels).run(n_jobs=3) | ||
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. @orbeckst Here is one that is testing multiple blocks. Maybe I should add one test for "n_blocks=1" case |
||
assert_almost_equal(nrdf.count[0][0][0], prdf.count[0][0][0]) | ||
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 compare just one element? Shouldn't assert_almost_equal(nrdf.count, prdf.count) work? |
||
assert_almost_equal(nrdf.rdf[0][0][0], prdf.rdf[0][0][0]) | ||
|
||
|
||
@pytest.mark.parametrize("density, value", [ | ||
(True, 13275.775528444701), | ||
(False, 0.021915460340071267)]) | ||
def test_density(u, sels, density, value): | ||
rdf = InterRDF_s(u, sels, density=density).run() | ||
assert_almost_equal(max(rdf.rdf[0][0][0]), value) |
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.
Ok, the failure is due to this line.
distributed
cannot pass atomgroups to blocks.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.
Seems related to PR #65 .
(Also, thanks for raising #79 )