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

Refactor pmda after universe can be serialized #132

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1e3d27b
refactor parallel.py
yuxuanzhuang Jul 15, 2020
4435f29
refactor custom
yuxuanzhuang Jul 15, 2020
1981673
pep8
yuxuanzhuang Jul 15, 2020
0a70857
refactor rmsd
yuxuanzhuang Jul 15, 2020
cafe65f
refactor rmsf
yuxuanzhuang Jul 15, 2020
185d19a
refactor contacts
yuxuanzhuang Jul 15, 2020
ef86b9d
refactor density
yuxuanzhuang Jul 15, 2020
c0b0bd6
refactor rdf
yuxuanzhuang Jul 15, 2020
bfa629c
refactor HBonds
yuxuanzhuang Jul 15, 2020
495033f
leaflet broken
yuxuanzhuang Jul 15, 2020
8700223
build mdanalysis on serialize_io
yuxuanzhuang Jul 16, 2020
c8e9973
build mdanalysis on serialize_io fix
yuxuanzhuang Jul 16, 2020
356cfb9
push leaflet fix back
yuxuanzhuang Jul 16, 2020
58fea5d
travis fix
yuxuanzhuang Jul 16, 2020
dfd3588
travis fix
yuxuanzhuang Jul 16, 2020
0921882
test parallel
yuxuanzhuang Jul 16, 2020
49288e8
timing test
yuxuanzhuang Jul 16, 2020
9a0e0c5
leaflet fix
yuxuanzhuang Jul 16, 2020
187463b
pep8
yuxuanzhuang Jul 17, 2020
8a42040
make sure universe before atomgroup
yuxuanzhuang Jul 17, 2020
053225b
change travis back
yuxuanzhuang Aug 9, 2020
83becd7
travis to develop
yuxuanzhuang Aug 13, 2020
f9c89e6
remove getstate
yuxuanzhuang Aug 19, 2020
61bce8f
pep8
yuxuanzhuang Aug 19, 2020
cb99fc8
update setup.py
yuxuanzhuang Aug 19, 2020
d95add1
pep8 warning
yuxuanzhuang Aug 19, 2020
a505282
travis
yuxuanzhuang Aug 19, 2020
608a803
setup reverse
yuxuanzhuang Aug 19, 2020
18988c5
pep
yuxuanzhuang Aug 19, 2020
61a34c7
setup py3
yuxuanzhuang Aug 19, 2020
7bf68f5
rewind doc
yuxuanzhuang Aug 19, 2020
5ceaebf
doc
yuxuanzhuang Aug 20, 2020
d424f6d
merge to develop
yuxuanzhuang Aug 23, 2020
b649c04
Merge branch 'master' into refactor_pmda
orbeckst May 12, 2021
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
9 changes: 5 additions & 4 deletions pmda/contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ def __init__(self,
respective functions for reasonable values.
"""
universe = mobiles[0].universe
super(Contacts, self).__init__(universe, mobiles)
super().__init__(universe)
self._mobiles = mobiles

if method == 'hard_cut':
self.fraction_contacts = hard_cut_q
Expand Down Expand Up @@ -267,13 +268,13 @@ def __init__(self,
def _prepare(self):
self.timeseries = None

def _single_frame(self, ts, atomgroups):
grA, grB = atomgroups
def _single_frame(self):
grA, grB = self._mobiles
# compute distance array for a frame
d = distance_array(grA.positions, grB.positions)

y = np.empty(len(self.r0) + 1)
y[0] = ts.frame
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
Expand Down
22 changes: 4 additions & 18 deletions pmda/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
same universe and return a value.

"""
from __future__ import absolute_import

from MDAnalysis.core.groups import AtomGroup
from MDAnalysis.core.universe import Universe
from MDAnalysis.coordinates.base import ProtoReader
Expand Down Expand Up @@ -77,27 +75,15 @@ def __init__(self, function, universe, *args, **kwargs):
"""

self.function = function

# collect all atomgroups with the same trajectory object as universe
trajectory = universe.trajectory
arg_ags = []
self.other_args = []
for arg in args:
if isinstance(arg,
AtomGroup) and arg.universe.trajectory == trajectory:
arg_ags.append(arg)
else:
self.other_args.append(arg)

super(AnalysisFromFunction, self).__init__(universe, arg_ags)
super().__init__(universe)
self.args = args
self.kwargs = kwargs

def _prepare(self):
self.results = []

def _single_frame(self, ts, atomgroups):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, cool that this works.

args = atomgroups + self.other_args
return self.function(*args, **self.kwargs)
def _single_frame(self):
return self.function(*self.args, **self.kwargs)

def _conclude(self):
self.results = np.concatenate(self._results)
Expand Down
31 changes: 12 additions & 19 deletions pmda/density.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
MDAnalysis.analysis.density.density_from_Universe

"""

from __future__ import absolute_import

import numpy as np

from MDAnalysis.lib.util import fixedwidth_bins
Expand Down Expand Up @@ -241,7 +238,7 @@ def __init__(self, atomgroup, delta=1.0, atomselection=None,
parameters=None, gridcenter=None, xdim=None, ydim=None,
zdim=None):
u = atomgroup.universe
super(DensityAnalysis, self).__init__(u, (atomgroup, ))
super().__init__(u)
self._atomgroup = atomgroup
self._delta = delta
self._atomselection = atomselection
Expand All @@ -259,10 +256,15 @@ def __init__(self, atomgroup, delta=1.0, atomselection=None,
elif not updating and atomselection is not None:
raise ValueError("""With updating=False, the atomselection='{}' is
not used and should be None""".format(atomselection))
elif updating and atomselection is not None:
self._select_atomgroup = atomgroup.select_atoms(atomselection,
updating=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do updating AtomGroups work with the serialization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Thanks to what has already been implemented by Richard:)

else:
self._select_atomgroup = atomgroup


def _prepare(self):
coord = self.current_coordinates(self._atomgroup, self._atomselection,
self._updating)
coord = self._select_atomgroup.positions
if self._gridcenter is not None:
# Generate a copy of smin/smax from coords to later check if the
# defined box might be too small for the selection
Expand Down Expand Up @@ -294,10 +296,10 @@ def _prepare(self):
self._arange = arange
self._bins = bins

def _single_frame(self, ts, atomgroups):
coord = self.current_coordinates(atomgroups[0], self._atomselection,
self._updating)
result = np.histogramdd(coord, bins=self._bins, range=self._arange,
def _single_frame(self):
result = np.histogramdd(self._select_atomgroup.positions,
bins=self._bins,
range=self._arange,
normed=False)
return result[0]

Expand Down Expand Up @@ -330,12 +332,3 @@ def _reduce(res, result_single_frame):
else:
res += result_single_frame
return res

@staticmethod
def current_coordinates(atomgroup, atomselection, updating):
"""Retrieves the current coordinates of all atoms in the chosen atom
selection.
Note: currently required to allow for updating selections"""
ag = atomgroup if not updating else atomgroup.select_atoms(
atomselection)
return ag.positions
34 changes: 12 additions & 22 deletions pmda/hbond_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
:members:

"""
from __future__ import absolute_import, division

import numpy as np

from MDAnalysis.lib.distances import capped_distance, calc_angles
Expand Down Expand Up @@ -172,7 +170,8 @@ def __init__(self, universe, donors_sel=None, hydrogens_sel=None,
"""

ag = universe.atoms
super(HydrogenBondAnalysis, self).__init__(universe, (ag, ))
super().__init__(universe)
self._atomgroup = ag
self.donors_sel = donors_sel
self.hydrogens_sel = hydrogens_sel
self.acceptors_sel = acceptors_sel
Expand Down Expand Up @@ -218,7 +217,7 @@ def guess_hydrogens(self, selection='all', max_mass=1.1, min_charge=0.3):
:attr:`hydrogens_sel`.
"""

u = self._universe()
u = self._universe
ag = u.select_atoms(selection)
hydrogens_ag = ag[
np.logical_and(
Expand Down Expand Up @@ -282,7 +281,7 @@ def guess_donors(self, selection='all', max_charge=-0.5):
hydrogens_sel = self.guess_hydrogens()
else:
hydrogens_sel = self.hydrogens_sel
u = self._universe()
u = self._universe
hydrogens_ag = u.select_atoms(hydrogens_sel)

ag = hydrogens_ag.residues.atoms.select_atoms(
Expand Down Expand Up @@ -335,7 +334,7 @@ def guess_acceptors(self, selection='all', max_charge=-0.5):
attribute :attr:`acceptors_sel`.
"""

u = self._universe()
u = self._universe
ag = u.select_atoms(selection)
acceptors_ag = ag[ag.charges < max_charge]
acceptors_list = np.unique(
Expand Down Expand Up @@ -393,7 +392,7 @@ def _get_dh_pairs(self, u):
return donors, hydrogens

def _prepare(self):
u = mda.Universe(self._top, self._traj)
u = self._universe
self.hbonds = []
self.frames = np.arange(self.start, self.stop, self.step)
self.timesteps = (self.frames*u.trajectory.dt) + u.trajectory[0].time
Expand All @@ -410,10 +409,9 @@ def _prepare(self):
self._donors_ids = donors.ids
self._hydrogens_ids = hydrogens.ids

def _single_frame(self, ts, atomgroups):
u = atomgroups[0].universe

box = ts.dimensions
def _single_frame(self):
u = self._universe
box = self._ts.dimensions

# Update donor-hydrogen pairs if necessary
if self.update_selections:
Expand Down Expand Up @@ -459,7 +457,7 @@ def _single_frame(self, ts, atomgroups):

# Store data on hydrogen bonds found at this frame
hbonds = [[], [], [], [], [], []]
hbonds[0].extend(np.full_like(hbond_donors, ts.frame))
hbonds[0].extend(np.full_like(hbond_donors, self._ts.frame))
hbonds[1].extend(hbond_donors.ids)
hbonds[2].extend(hbond_hydrogens.ids)
hbonds[3].extend(hbond_acceptors.ids)
Expand Down Expand Up @@ -508,7 +506,7 @@ def count_by_type(self):
resname and atom type of the donor and acceptor atoms in a hydrogen
bond.
"""
u = self._universe()
u = self._universe
d = u.atoms[self.hbonds[:, 1].astype(np.int)]
a = u.atoms[self.hbonds[:, 3].astype(np.int)]

Expand Down Expand Up @@ -541,7 +539,7 @@ def count_by_ids(self):
hydrogen atom id and acceptor atom id in a hydrogen bond.
"""

u = self._universe()
u = self._universe
d = u.atoms[self.hbonds[:, 1].astype(np.int)]
h = u.atoms[self.hbonds[:, 2].astype(np.int)]
a = u.atoms[self.hbonds[:, 3].astype(np.int)]
Expand All @@ -558,14 +556,6 @@ def count_by_ids(self):

return unique_hbonds

def _universe(self):
# A Universe containing position information is needed for guessing
# donors and acceptors.
u = mda.Universe(self._top)
if not hasattr(u.atoms, 'positions'):
u.load_new(self._positions)
return u

@staticmethod
def _reduce(res, result_single_frame):
""" Use numpy array append to combine results"""
Expand Down
Loading