Skip to content

Commit

Permalink
Merge pull request #891 from jdetle/nframes
Browse files Browse the repository at this point in the history
Changed nframes to n_frames, fixes #890
  • Loading branch information
kain88-de authored Jul 6, 2016
2 parents 7220db5 + 80eb6d3 commit 852daec
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 26 deletions.
5 changes: 3 additions & 2 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/16 kain88-de, jdetle, fiona-naughton, richardjgowers, tyler.je.reddy
??/??/16 kain88-de, fiona-naughton, richardjgowers, tyler.je.reddy, jdetle

* 0.15.1

Expand All @@ -24,7 +24,8 @@ Fixes
* SingleFrameReader now raises StopIteration instead of IOError on calling
next (Issue #869)
* Display of Deprecation warnings doesn't affect other modules anymore (Issue #754)

* Changed nframes to n_frames in analysis modules for consistency (Issue #890)

Changes
* Added protected variable _frame_index to to keep track of frame iteration
number in AnalysisBase
Expand Down
8 changes: 4 additions & 4 deletions package/MDAnalysis/analysis/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ def _prepare(self):
self._ref_com = self.ref_atoms.center_of_mass()
self._ref_coordinates = self.ref_atoms.positions - self._ref_com
# allocate the array for selection atom coords
self.rmsd = np.zeros((self.nframes,))
self.rmsd = np.zeros((self.n_frames,))

def _single_frame(self):
index = self._ts.frame
Expand Down Expand Up @@ -717,8 +717,8 @@ def rms_fit_trj(
traj_coordinates = traj_atoms.positions.copy()

# RMSD timeseries
nframes = len(frames)
rmsd = np.zeros((nframes,))
n_frames = len(frames)
rmsd = np.zeros((n_frames,))

# R: rotation matrix that aligns r-r_com, x~-x~com
# (x~: selected coordinates, x: all coordinates)
Expand All @@ -727,7 +727,7 @@ def rms_fit_trj(
R = np.matrix(rot.reshape(3, 3))

percentage = ProgressMeter(
nframes,
n_frames,
interval=10,
quiet=quiet,
format="Fitted frame %(step)5d/%(numsteps)d [%(percentage)5.1f%%] r")
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/analysis/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def _setup_frames(self, trajectory, start=None,
self.start = start
self.stop = stop
self.step = step
self.nframes = len(range(start, stop, step))
self.n_frames = len(range(start, stop, step))

def _single_frame(self):
"""Calculate data from a single frame of trajectory
Expand Down Expand Up @@ -99,7 +99,7 @@ def run(self, **kwargs):
self._trajectory[self.start:self.stop:self.step]):
self._frame_index = i
self._ts = ts
# logger.info("--> Doing frame {} of {}".format(i+1, self.nframes))
# logger.info("--> Doing frame {} of {}".format(i+1, self.n_frames))
self._single_frame()
logger.info("Finishing up")
self._conclude()
8 changes: 4 additions & 4 deletions package/MDAnalysis/analysis/lineardensity.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
# MDAnalysis --- http://www.MDAnalysis.org
# Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver Beckstein
Expand Down Expand Up @@ -46,7 +46,7 @@ class LinearDensity(AnalysisBase):
binsize : float
Bin width in Angstrom used to build linear density
histograms. Defines the resolution of the resulting density
histograms. Defines the resolution of the resulting density
profile (smaller --> higher resolution) [0.25]
start : int
Expand All @@ -58,7 +58,7 @@ class LinearDensity(AnalysisBase):
Example
-------
First create a LinearDensity object by supplying a selection,
First create a LinearDensity object by supplying a selection,
then use the `run` method:
ldens = LinearDensity(selection)
ldens.run()
Expand Down Expand Up @@ -161,7 +161,7 @@ def _conclude(self):
# Average results over the number of configurations
for dim in ['x', 'y', 'z']:
for key in ['pos', 'pos_std', 'char', 'char_std']:
self.results[dim][key] /= self.nframes
self.results[dim][key] /= self.n_frames
# Compute standard deviation for the error
self.results[dim]['pos_std'] = np.sqrt(self.results[dim]['pos_std']
- np.square(self.results[dim]['pos']))
Expand Down
8 changes: 3 additions & 5 deletions package/MDAnalysis/analysis/polymer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
# MDAnalysis --- http://www.MDAnalysis.org
# Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver Beckstein
Expand Down Expand Up @@ -84,7 +84,7 @@ def _single_frame(self):
# could optimise this by writing a "self dot array"
# we're only using the upper triangle of np.inner
# function would accept a bunch of coordinates and spit out the
# decorrel for that
# decorrel for that
n = len(self._atomgroups[0])

for chain in self._atomgroups:
Expand All @@ -101,7 +101,7 @@ def _conclude(self):
n = len(self._atomgroups[0])

norm = np.linspace(n - 1, 1, n - 1)
norm *= len(self._atomgroups) * self.nframes
norm *= len(self._atomgroups) * self.n_frames

self.results = self._results / norm
self._calc_bond_length()
Expand Down Expand Up @@ -169,5 +169,3 @@ def expfunc(x, a):
a = curve_fit(expfunc, x, y)[0][0]

return a


4 changes: 2 additions & 2 deletions package/MDAnalysis/analysis/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ def _conclude(self):
vol *= 4/3.0 * np.pi

# Average number density
box_vol = self.volume / self.nframes
box_vol = self.volume / self.n_frames
density = N / box_vol

rdf = self.count / (density * vol * self.nframes)
rdf = self.count / (density * vol * self.n_frames)

self.rdf = rdf
6 changes: 3 additions & 3 deletions package/MDAnalysis/analysis/rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,11 @@ def run(self, start=None, stop=None, step=None,
rot = None

# RMSD timeseries
nframes = len(np.arange(0, len(trajectory))[start:stop:step])
rmsd = np.zeros((nframes, 3 + len(self.groupselections_atoms)))
n_frames = len(np.arange(0, len(trajectory))[start:stop:step])
rmsd = np.zeros((n_frames, 3 + len(self.groupselections_atoms)))

percentage = ProgressMeter(
nframes, interval=10, format="RMSD %(rmsd)5.2f A at frame "
n_frames, interval=10, format="RMSD %(rmsd)5.2f A at frame "
"%(step)5d/%(numsteps)d [%(percentage)5.1f%%]\r")

for k, ts in enumerate(trajectory[start:stop:step]):
Expand Down
8 changes: 4 additions & 4 deletions testsuite/MDAnalysisTests/analysis/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,28 +55,28 @@ def tearDown(self):

def test_default(self):
an = FrameAnalysis(self.u.trajectory)
assert_(an.nframes == len(self.u.trajectory))
assert_(an.n_frames == len(self.u.trajectory))

an.run()
assert_(an.frames == list(range(len(self.u.trajectory))))

def test_start(self):
an = FrameAnalysis(self.u.trajectory, start=20)
assert_(an.nframes == len(self.u.trajectory) - 20)
assert_(an.n_frames == len(self.u.trajectory) - 20)

an.run()
assert_(an.frames == list(range(20, len(self.u.trajectory))))

def test_stop(self):
an = FrameAnalysis(self.u.trajectory, stop=20)
assert_(an.nframes == 20)
assert_(an.n_frames == 20)

an.run()
assert_(an.frames == list(range(20)))

def test_step(self):
an = FrameAnalysis(self.u.trajectory, step=20)
assert_(an.nframes == 5)
assert_(an.n_frames == 5)

an.run()
assert_(an.frames == list(range(98))[::20])

0 comments on commit 852daec

Please sign in to comment.