Skip to content
Merged
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
Tests for TIS with candidate=True
  • Loading branch information
dwhswenson committed Feb 18, 2017
commit 4f5ebfc4d832800dceb78be5be5449a24606d90d
18 changes: 13 additions & 5 deletions openpathsampling/ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -2792,18 +2792,26 @@ def __init__(self, initial_states, final_states, interface,
self.orderparameter = orderparameter
# TODO: add max_orderparameter as a traj CV
self.lambda_i = lambda_i
self._initial_volumes = volumes_a
self._final_volumes = volumes_b
self._initial_volumes = volume_a
self._final_volumes = volume_b | volume_a

def __call__(self, trajectory, trusted=None, candidate=False):
use_candidate = (candidate and self.lambda_i is not None
and self.orderparameter is not None)
if use_candidate:
# as a candidate trajectory, we assume that only the first and
# final frames can be in a state
return (self._initial_volumes(trajectory[0])
& self._final_volumes(trajectory[-1])
& max(self.orderparameter(trajectory)) >= self.lambda_i)
#logger.debug("initial: " +
#str(self._initial_volumes(trajectory[0])))
#logger.debug("final: " +
#str(self._final_volumes(trajectory[0])))
#logger.debug("max: " +
#str(max(self.orderparameter(trajectory))))
return (
self._initial_volumes(trajectory[0])
& self._final_volumes(trajectory[-1])
& (max(self.orderparameter(trajectory)) > self.lambda_i)
)
else:
# it still works fine if we use the slower algorithm
return super(TISEnsemble, self).__call__(trajectory, trusted)
Expand Down
22 changes: 21 additions & 1 deletion openpathsampling/tests/testensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def test_strict_can_prepend(self):

class testTISEnsemble(EnsembleTest):
def setUp(self):
self.tis = TISEnsemble(vol1, vol3, vol2, op)
self.tis = TISEnsemble(vol1, vol3, vol2, op)
self.traj = ttraj['upper_in_out_cross_out_in']
self.minl = min(op(self.traj))
self.maxl = max(op(self.traj))
Expand All @@ -1300,6 +1300,26 @@ def test_tis_trajectory_summary_str(self):
str(self.minl) + " max_lambda=" + str(self.maxl) + " ")
assert_equal(mystr, teststr)

def test_tis_ensemble_candidate(self):
tis = TISEnsemble(vol1, vol3, vol2, op, lambda_i=0.7)
test_f = lambda t: tis(t, candidate=True)
results = {}
upper_keys = [k for k in ttraj.keys() if k[:6] == "upper_"]
for test in upper_keys:
results[test] = False
# results where we SHOULD get True
results['upper_in_out_cross_out_in'] = True
results['upper_in_cross_in'] = True
# results where the input isn't actually a candidate trajectory, so
# it accepts the path even though it shouldn't
results['upper_in_cross_in_cross_in'] = True
results['upper_in_out_cross_out_in_out_in_out_cross_out_in'] = True
results['upper_in_in_cross_in'] = True

for test in results.keys():
failmsg = "Failure in "+test+"("+str(ttraj[test])+"): "
self._single_test(test_f, ttraj[test], results[test], failmsg)

class EnsembleCacheTest(EnsembleTest):
def _was_cache_reset(self, cache):
return cache.contents == { }
Expand Down