Skip to content

Commit

Permalink
Add q1q2 analysis wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
kain88-de committed Mar 28, 2016
1 parent 1082927 commit 469c089
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions package/MDAnalysis/analysis/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
Classes are available for two somewhat different ways to perform a contact
analysis:
1. Contacts between two groups of atoms are defined with
:class:`ContactAnalysis1`), which allows one to calculate *q(t)* over
time. This is especially useful in order to look at native contacts during
Expand Down Expand Up @@ -359,17 +361,18 @@ def _single_frame(self):
# compute distance array for a frame
d = distance_array(self.grA.positions, self.grB.positions)

y = np.empty(len(self.r0))
y = np.empty(len(self.r0) + 1)
y[0] = self._ts.frame
for i, (initial_contacts, r0) in enumerate(zip(self.initial_contacts,
self.r0)):
# select only the contacts that were formed in the reference state
r = d[initial_contacts]
r0 = r0[initial_contacts]
y[i] = self.fraction_contacts(r, r0, **self.fraction_kwargs)
y[i + 1] = self.fraction_contacts(r, r0, **self.fraction_kwargs)

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

def save(self, outfile):
"""save contacts timeseries
Expand All @@ -387,6 +390,24 @@ def save(self, outfile):
f.write("{frame:4d} {q1:8.6f}\n".format(**vars()))


def _new_selections(u_orig, selections, frame):
"""create stand alone AGs from selections at frame"""
u = MDAnalysis.Universe(u_orig.filename, u_orig.trajectory.filename)
u.trajectory[frame]
return (u.select_atoms(s) for s in selections)


def q1q2(u, selection=('all', 'all'), radius=4.5, method='cutoff',
start=None, stop=None, step=None, **kwargs):
"""Helper function to create q1q2 contact analysis"""
first_frame_refs = _new_selections(u, selection, 0)
last_frame_refs = _new_selections(u, selection, -1)
return Contacts(u, selection,
(first_frame_refs, last_frame_refs),
radius=radius, method=method,
start=start, stop=stop, step=step,
**kwargs)

################################################################################
################################################################################
################################################################################
Expand Down

0 comments on commit 469c089

Please sign in to comment.