Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
test_shift updated
  • Loading branch information
SarahMcCartan committed Apr 5, 2017
commit 54ec0029df83ada1033648ff80f656127862c598
6 changes: 3 additions & 3 deletions openpathsampling/shifting.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ def direction(self):

def _run(self, trajectory , shooting_index):

shift = random.choice([-1,1]*self.shift_length)
shift = random.choice([-1,1])*self.shift_length

details = {'Shift': shift}

if shift > 0: #forward shift condition
#print self.shift_length
Expand All @@ -55,7 +57,6 @@ def _run(self, trajectory , shooting_index):
self.engine.current_snapshot = chopped_traj[-1] # pick last frame
right_part = self.engine.generate_n_frames(self.shift_length) #gen time steps in future to add to
#chopped traj
details = {"Forward Shift":self.shift_length}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

More a suggestion and question @dwhswenson : Would is make sense to split the details into either

  1. {'shift_direction': ..., 'shift_lenght': } or even
  2. {'shift: positive/negative int}`

This way automatic analysis is easier to handle. The current approach would require a if 'Forward Shift' in x.details

#print 'Right part', right_part[1:]
return chopped_traj + right_part, details
Expand All @@ -70,7 +71,6 @@ def _run(self, trajectory , shooting_index):
#print self.shift_length, self.engine.current_snapshot

left_part = self.engine.generate_n_frames(self.shift_length)
details= {"Backward Shift":self.shift_length}


return left_part.reversed + chopped_traj, details
Expand Down
59 changes: 37 additions & 22 deletions openpathsampling/tests/test_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def test_run_len_traj(self):

def test_run_details(self):
#check keys and values of the dictonary output from the _run function of the Mover
#keys are the name of the shift - 2 choices Forward Shift and Backward Shift
#values are the shift length only 1 choice the input shift length 2
#also test the value of the shift length is 2 in all cases
#keys are the name of the move which has 1 choice - "Shift"
#values are the shift which has 2 choices, either +2 or -2 depending if fwd or bkwd shift.
#also test the value of the shift length is +/-2 in all cases


value_list = []
Expand All @@ -146,36 +146,51 @@ def test_run_details(self):
key_set = set(key_list)
value_set = set(value_list)

assert_equal(len(value_set), 1) #test the number of unique values is 1
assert_equal(len(key_set), 2) #test the number of unique keys is 2
assert_equal(len(value_set), 2) #test the number of unique values is 2, either+/-2
assert_equal(len(key_set), 1) #test the number of unique keys is 1

#assert_in(str(key_list), str('Forward Shift'))
#assert_in(str(key_list), str('Backward Shift'))
#assert_equal(str(key_list), str('Shift'))



for j in value_list:
assert_equal(j, 2)
assert_not_equal(j, 3)
#for j in value_list:
# assert_in(j, 2)
# assert_in(j, -2)
# assert_not_in(j, 3)

#print(type(j))

shift_list = []
for k in key_list:
if k in "Shift":
shift_list.append(k)
assert_equal(str(k),"Shift")

#print(type(j))
assert_equal(len(shift_list), 100)


fwd_list = []
bwd_list = []

for k in key_list:
if k in "Forward Shift":
fwd_list.append(k)

for l in value_list:
if l > 0:
fwd_list.append(l)
assert_equal(l, 2)
assert_not_equal(l,1)
elif l <0:
bwd_list.append(l)
assert_equal(l, -2)
assert_not_equal(l, -1)

assert_equal(str(k),"Forward Shift")
assert_equal(len(fwd_list) + len(bwd_list), 100)

elif k in "Backward Shift":
bwd_list.append(k)
#for x in fwd_list:
# print(x)

assert_equal(str(k), "Backward Shift")
#for y in bwd_list:
# print(y)

assert_equal(len(fwd_list)+len(bwd_list), 100)
#print(len(bwd_list))
#print(len(fwd_list)
#print(len(bwd_list)


#Test the Shifting Strategy by creating Test Setup to include state definitions, interfaces and
Expand Down