Skip to content

Commit

Permalink
Allow multiple reference groups
Browse files Browse the repository at this point in the history
This allows to track the contact differences to several states over
time. This is for example needed to implement a q1-q2 analysis.
  • Loading branch information
kain88-de committed Mar 28, 2016
1 parent 76bf3af commit 1082927
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions package/MDAnalysis/analysis/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@
import MDAnalysis.lib.distances
from MDAnalysis.lib.util import openany
from MDAnalysis.analysis.distances import distance_array
from MDAnalysis.core.AtomGroup import AtomGroup
from .base import AnalysisBase

logger = logging.getLogger("MDAnalysis.analysis.contacts")
Expand Down Expand Up @@ -342,14 +343,14 @@ def __init__(self, u, selection, refgroup, method="cutoff", radius=4.5,
self.r0 = []
self.initial_contacts = []

if isinstance(refgroup[0], mda.AtomGroup.AtomGroup):
if isinstance(refgroup[0], AtomGroup):
refA, refB = refgroup
self.r0.append(distance_array(refA.positions, refB.positions))
self.initial_contacts.append(contact_matrix(self.r0, radius))
self.initial_contacts.append(contact_matrix(self.r0[-1], radius))
else:
for refA, refB in refgroup:
self.r0.append(distance_array(refA.positions, refB.positions))
self.initial_contacts.append(contact_matrix(self.r0, radius))
self.initial_contacts.append(contact_matrix(self.r0[-1], radius))

self.fraction_kwargs = kwargs
self.timeseries = []
Expand All @@ -366,6 +367,8 @@ def _single_frame(self):
r0 = r0[initial_contacts]
y[i] = self.fraction_contacts(r, r0, **self.fraction_kwargs)

if len(y) == 1:
y = y[0]
self.timeseries.append((self._ts.frame, y))

def save(self, outfile):
Expand Down
2 changes: 1 addition & 1 deletion testsuite/MDAnalysisTests/analysis/test_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,5 @@ def test_villin_unfolded():
method="soft_cut")
q.run()

results = zip(*soft_cut(f, u, sel, sel)) [1]
results = zip(*soft_cut(f, u, sel, sel))[1]
assert_almost_equal(zip(*q.timeseries)[1], results)

0 comments on commit 1082927

Please sign in to comment.