Skip to content

Commit

Permalink
Moves test_iter_as_aux_highf & test_iter_as_aux_lowf to MultiFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
utkbansal committed Feb 7, 2017
1 parent def1dbb commit 71ce217
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions testsuite/MDAnalysisTests/coordinates/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,32 +108,31 @@ def __init__(self):
self.changing_dimensions = False

# for testing auxiliary addition
self.aux_lowf = AUX_XVG_LOWF # test auxiliary with lower frequency
self.aux_lowf_dt = 2 # has steps at 0ps, 2ps, 4ps
self.aux_lowf = AUX_XVG_LOWF # test auxiliary with lower frequency
self.aux_lowf_dt = 2 # has steps at 0ps, 2ps, 4ps
# representative data for each trajectory frame, assuming 'closest' option
self.aux_lowf_data = [[2 ** 0], # frame 0 = 0ps = step 0
[np.nan], # frame 1 = 1ps = no step
[2 ** 1], # frame 2 = 2ps = step 1
[np.nan], # frame 3 = 3ps = no step
[2 ** 2], # frame 4 = 4ps = step 2
]
self.aux_lowf_frames_with_steps = [0, 2, 4] # trajectory frames with
# corresponding auxiliary steps

self.aux_highf = AUX_XVG_HIGHF # test auxiliary with higher frequency
self.aux_highf_dt = 0.5 # has steps at 0, 0.5, 1, ... 3.5, 4ps
self.aux_highf_data = [[2 ** 0], # frame 0 = 0ps = step 0
[2 ** 2], # frame 1 = 1ps = step 2
[2 ** 4], # frame 2 = 2ps = step 4
[2 ** 6], # frame 3 = 3ps = step 6
[2 ** 8], # frame 4 = 4ps = step 8
self.aux_lowf_data = [[2 ** 0], # frame 0 = 0ps = step 0
[np.nan], # frame 1 = 1ps = no step
[2 ** 1], # frame 2 = 2ps = step 1
[np.nan], # frame 3 = 3ps = no step
[2 ** 2], # frame 4 = 4ps = step 2
]
self.aux_lowf_frames_with_steps = [0, 2, 4] # trajectory frames with
# corresponding auxiliary steps

self.aux_highf = AUX_XVG_HIGHF # test auxiliary with higher frequency
self.aux_highf_dt = 0.5 # has steps at 0, 0.5, 1, ... 3.5, 4ps
self.aux_highf_data = [[2 ** 0], # frame 0 = 0ps = step 0
[2 ** 2], # frame 1 = 1ps = step 2
[2 ** 4], # frame 2 = 2ps = step 4
[2 ** 6], # frame 3 = 3ps = step 6
[2 ** 8], # frame 4 = 4ps = step 8
]
self.aux_highf_n_steps = 10
self.aux_highf_all_data = [[2 ** i] for i in range(self.aux_highf_n_steps)]

self.aux_offset_by = 0.25


self.first_frame = Timestep(self.n_atoms)
self.first_frame.positions = np.arange(
3 * self.n_atoms).reshape(self.n_atoms, 3)
Expand Down Expand Up @@ -169,10 +168,9 @@ def __init__(self):
self.dt = 1
self.totaltime = 4


def iter_ts(self, i):
ts = self.first_frame.copy()
ts.positions = 2**i * self.first_frame.positions
ts.positions = 2 ** i * self.first_frame.positions
ts.time = i
ts.frame = i
ts.aux.lowf = np.array(self.aux_lowf_data[i])
Expand Down Expand Up @@ -272,21 +270,6 @@ def test_remove_auxiliary(self):
def test_remove_nonexistant_auxiliary_raises_ValueError(self):
self.reader.remove_auxiliary('nonexistant')

def test_iter_as_aux_highf(self):
# auxiliary has a higher frequency, so iter_as_aux should behave the
# same as regular iteration over the trjectory
for i, ts in enumerate(self.reader.iter_as_aux('highf')):
assert_timestep_almost_equal(ts, self.ref.iter_ts(i),
decimal=self.ref.prec)

def test_iter_as_aux_lowf(self):
# auxiliary has a lower frequency, so iter_as_aux should iterate over
# only frames where there is a corresponding auxiliary value
for i, ts in enumerate(self.reader.iter_as_aux('lowf')):
assert_timestep_almost_equal(ts,
self.ref.iter_ts(self.ref.aux_lowf_frames_with_steps[i]),
decimal=self.ref.prec)

def test_iter_auxiliary(self):
# should go through all steps in 'highf'
for i, auxstep in enumerate(self.reader.iter_auxiliary('highf')):
Expand All @@ -311,8 +294,6 @@ def test_iter_as_aux_cutoff(self):
assert_equal(num_frames, 0, "iter_as_aux should iterate over 0 frames,"
" not {}".format(num_frames))



def test_reload_auxiliaries_from_description(self):
# get auxiliary desscriptions form existing reader
descriptions = self.reader.get_aux_descriptions()
Expand All @@ -338,7 +319,6 @@ def test_stop_iter(self):


class MultiframeReaderTest(BaseReaderTest):

def test_last_frame(self):
ts = self.reader[-1]
assert_timestep_almost_equal(ts, self.ref.last_frame,
Expand All @@ -353,7 +333,6 @@ def test_frame_jump(self):
assert_timestep_almost_equal(ts, self.ref.jump_to_frame,
decimal=self.ref.prec)


def test_next_gives_second_frame(self):
reader = self.ref.reader(self.ref.trajectory)
ts = reader.next()
Expand All @@ -379,6 +358,20 @@ def test_rename_aux(self):
assert_equal(self.reader.ts.aux.lowf_renamed,
self.ref.aux_lowf_data[1])

def test_iter_as_aux_highf(self):
# auxiliary has a higher frequency, so iter_as_aux should behave the
# same as regular iteration over the trjectory
for i, ts in enumerate(self.reader.iter_as_aux('highf')):
assert_timestep_almost_equal(ts, self.ref.iter_ts(i),
decimal=self.ref.prec)

def test_iter_as_aux_lowf(self):
# auxiliary has a lower frequency, so iter_as_aux should iterate over
# only frames where there is a corresponding auxiliary value
for i, ts in enumerate(self.reader.iter_as_aux('lowf')):
assert_timestep_almost_equal(ts,
self.ref.iter_ts(self.ref.aux_lowf_frames_with_steps[i]),
decimal=self.ref.prec)


class BaseWriterTest(object):
Expand Down Expand Up @@ -444,7 +437,7 @@ def test_write_selection(self):
assert_array_almost_equal(
copy_ts._pos, sel.atoms.positions, self.ref.prec,
err_msg="coordinate mismatch between original and written "
"trajectory at frame {} (orig) vs {} (copy)".format(
"trajectory at frame {} (orig) vs {} (copy)".format(
orig_ts.frame, copy_ts.frame))

def _check_copy(self, fname):
Expand Down

0 comments on commit 71ce217

Please sign in to comment.