Пример #1
0
    def add_empty_to_cache(self, idx, sample_idxs, all_samples):
        if idx not in self.cache:
            obj = SampleSet(
                    samples=[all_samples[sample_idx.tolist()] for sample_idx in sample_idxs],
                    movepath=None
                )
            obj.idx[self.storage] = idx
            obj._origin = self.storage

            del obj.movepath

            self.cache[idx] = obj
Пример #2
0
    def test_first_hop_fails(self):
        crossing_traj = make_1d_traj([-0.11, 0.11, 0.31, 1.01], [1.0]*4)
        crossing_samp = Sample(replica=0, trajectory=crossing_traj,
                               ensemble=self.innermost)
        gs = SampleSet([crossing_samp])
        gs.sanity_check()

        change = self.mover.move(gs)
        assert_equal(change.accepted, False)
        assert_equal(len(change.results), 0)
        sub_trials = change.subchange.subchange.subchange.trials
        assert_equal(len(sub_trials), 1)
        assert_equal(sub_trials[0].trajectory, crossing_traj)
        assert_equal(sub_trials[0].ensemble, self.minus._segment_ensemble)
Пример #3
0
    def test_move_single_replica(self):
        sampleset = SampleSet([self.samp1])
        change = self.mover.move(sampleset)
        subchange = change.subchange
        assert_equal(subchange.mover, self.pathrev)
        assert_equal(subchange.accepted, True)
        assert_equal(change.accepted, True)
        assert_equal(len(subchange.samples), 1)

        sampleset = SampleSet([self.samp2])
        change = self.mover.move(sampleset)
        subchange = change.subchange
        assert_equal(subchange.mover, self.shooter)
        assert_equal(subchange.accepted, True)
        assert_equal(change.accepted, True)
Пример #4
0
    def test_extension_fails(self):
        innermost_bad_extension = [-0.25, 0.1, 0.5, 0.1, -0.25]
        traj_bad_extension = make_1d_traj(innermost_bad_extension, [1.0]*5)
        samp_bad_extension = Sample(
            replica=0,
            trajectory=traj_bad_extension,
            ensemble=self.innermost
        )
        
        assert_equal(self.innermost(traj_bad_extension), True)

        gs = SampleSet([self.minus_sample, samp_bad_extension])
        change = self.mover.move(gs)
        assert_equal(change.accepted, False) # whole minus has failed

        #     Minus : Filter  :ChooseFB : CondSeq
        sub = change.subchange.subchange.subchange
        assert_equal(len(sub.trials), 2)
        assert_equal(len(change.trials), 0) # no trials survive filtering
        assert_subchanges_set_accepted(sub, [True, False])

        # first two work and the extention fails
        # this only happens due to length
        assert_equal(
            len(sub[-1].trials[0].trajectory),
            len(traj_bad_extension)+self.dyn.n_frames_max-1
        )
Пример #5
0
 def test_move_multiple_replicas_weighted_ensembles(self):
     sampleset = SampleSet([self.samp1, self.samp2])
     ens_dict = {self.ens1 : self.pathrev, self.ens2 : self.shooter}
     # weighted_mover = EnsembleDictionaryMover(ens_dict, [1.0, 2.0])
     weighted_mover = RandomAllowedChoiceMover([self.pathrev,
                                                self.shooter], [1.0, 2.0])
     count = {}
     for i in range(100):
         change = weighted_mover.move(sampleset)
         subchange = change.subchange
         assert_equal(change.accepted, True)
         assert_equal(subchange.accepted, True)
         assert_equal(len(subchange.samples), 1)
         ens = subchange.trials[0].ensemble
         try:
             count[ens] += 1
         except KeyError:
             count[ens] = 1
         if ens == self.ens1:
             assert_equal(subchange.mover, self.pathrev)
         elif ens == self.ens2:
             assert_equal(subchange.mover, self.shooter)
         else:
             raise AssertionError("Resulting mover unknown!")
     assert_equal(set(count.keys()), set([self.ens1, self.ens2]))
     try:
         assert(count[self.ens1] < count[self.ens2])
     except AssertionError:
         raise AssertionError("Not true: "+str(count[self.ens1]) + " < "
                              + str(count[self.ens2]))
Пример #6
0
    def _load(self, idx):
        sample_set = SampleSet(
            self.vars['samples'][idx],
            movepath=LoaderProxy(self.storage.pathmovechanges, int(self.variables['movepath'][idx]))
        )

        return sample_set
Пример #7
0
    def test_successful_move(self):
        init_innermost = make_1d_traj(self.list_innermost, [1.0]*5)
        init_sample = Sample(
            replica=0,
            trajectory=init_innermost,
            ensemble=self.innermost
        )
        gs = SampleSet([init_sample, self.minus_sample])

        extend_forward =  self.list_innermost + [0.12, 0.32, -0.131]
        extend_backward = [-0.13, 0.13, 0.33] + self.list_innermost

        assert_equal(self.minus(make_1d_traj(extend_forward)), True)
        assert_equal(self.minus(make_1d_traj(extend_backward)), True)

        seg_dir = {}
        for i in range(100):
            change = self.mover.move(gs)
            samples = change.results
            sub_samples = change.subchange.subchange.results
            assert_equal(len(samples), 2)
            assert_equal(len(sub_samples), 4)
            s_inner = [s for s in sub_samples if s.ensemble==self.innermost]
            s_minus = [s for s in sub_samples if s.ensemble==self.minus]
            s_sub = [s for s in sub_samples if s.ensemble==self.minus._segment_ensemble]
            assert_equal(len(s_inner), 1)
            assert_equal(len(s_minus), 1)
            assert_equal(len(s_sub), 2)

            for c in change:
                assert_equal(c.accepted, True)

            assert_equal(change.canonical.mover, self.mover)

            key = ""
            s_inner0_xvals = [s.coordinates[0,0] for s in s_inner[0].trajectory]
            if items_equal(s_inner0_xvals, self.first_segment):
                key += "1"
            elif items_equal(s_inner0_xvals, self.second_segment):
                key += "2"
            else:
                print "s_inner0_xvals:", s_inner0_xvals
                raise RuntimeError("Chosen segment neither first nor last!")

            # final sample s_minus is accepted
            s_minus_xvals = [s.coordinates[0,0] for s in s_minus[-1].trajectory]
            if items_equal(s_minus_xvals, extend_forward):
                key += "f"
            elif items_equal(s_minus_xvals, extend_backward):
                key += "b"
            else:
                print "s_minus_xvals:", s_minus_xvals
                raise RuntimeError("Unexpected minus extension result!")

            try:
                seg_dir[key] += 1
            except KeyError:
                seg_dir[key] = 1
        assert_equal(len(seg_dir.keys()), 4)
Пример #8
0
 def test_AB_path(self):
     trajAXB = make_1d_traj(coordinates=[-0.2, 0.75, 1.8])
     sampAXB = Sample(trajectory=trajAXB,
                      ensemble=self.tis,
                      replica=0)
     gs_AXB = SampleSet([sampAXB])
     change = self.move.move(gs_AXB)
     assert_equal(change.accepted, False)
Пример #9
0
 def test_A_A_path(self):
     trajA_A = make_1d_traj(coordinates=[-0.3, 0.1, -0.4])
     sampA_A = Sample(trajectory=trajA_A,
                      ensemble=self.tis,
                      replica=0)
     gs_A_A = SampleSet([sampA_A])
     change = self.move.move(gs_A_A)
     assert_equal(change.accepted, False)
Пример #10
0
    def _add_empty_to_cache(self, idx, sample_idxs, pmc_idx):
        if idx not in self.cache:
            obj = SampleSet(
                samples=[self.storage.samples[sample_idx.tolist()] for sample_idx in sample_idxs],
                movepath=LoaderProxy(self.storage.pathmovechanges, int(pmc_idx))
            )

            self.index[obj] = idx
            self.cache[idx] = obj
Пример #11
0
 def setup(self):
     self.mytraj = make_1d_traj(coordinates=[-0.5, 0.1, 0.2, 0.3, 0.5],
                                velocities=[1.0, 1.0, 1.0, 1.0, 1.0])
     self.dyn = CalvinistDynamics(
         [-0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4, 0.5])
     self.dyn.initialized = True
     self.ens = LengthEnsemble(5)
     self.gs = SampleSet(
         Sample(replica=0, trajectory=self.mytraj, ensemble=self.ens))
Пример #12
0
 def setup(self):
     self.l1 = LengthEnsemble(1)
     self.l2 = LengthEnsemble(2)
     self.l3 = LengthEnsemble(3)
     self.s1 = Sample(replica=1, ensemble=self.l2)
     self.s2 = Sample(replica=2, ensemble=self.l1)
     self.s3 = Sample(replica=3, ensemble=self.l1)
     self.s4 = Sample(replica=2, ensemble=self.l3)
     self.sset = SampleSet([self.s1, self.s2, self.s3, self.s4])
Пример #13
0
 def test_BA_path(self):
     trajBXA = make_1d_traj(coordinates=[1.2, 0.7, -0.25])
     sampBXA = Sample(trajectory=trajBXA,
                      ensemble=self.tis,
                      replica=0)
     gs_BXA = SampleSet([sampBXA])
     change = self.move.move(gs_BXA)
     # print [[v.coordinates[0] for v in t.trajectory] for t in change.trials]
     assert_equal(change.accepted, True)
Пример #14
0
    def setup(self):
        op = CV_Function("myid", f=lambda snap :
                             snap.coordinates[0][0])

        state1 = CVRangeVolume(op, -100, 0.0)
        state2 = CVRangeVolume(op, 1, 100)
        volA = CVRangeVolume(op, -100, 0.25)
        volB = CVRangeVolume(op, -100, 0.50)
        self.tisA = paths.TISEnsemble(state1, state2, volA)
        self.tisB = paths.TISEnsemble(state1, state2, volB)
        self.traj0 = make_1d_traj([-0.1, 0.2, 0.3, 0.1, -0.2])
        self.traj1 = make_1d_traj([-0.1, 0.1, 0.4, 0.6, 0.3, 0.2, -0.15]) 
        self.traj2 = make_1d_traj([-0.1, 0.2, 0.3, 0.7, 0.6, 0.4, 0.1, -0.15])
        self.sampA0 = Sample(replica=0, trajectory=self.traj0, ensemble=self.tisA)
        self.sampB1 = Sample(replica=1, trajectory=self.traj1, ensemble=self.tisB)
        self.sampA2 = Sample(replica=2, trajectory=self.traj2, ensemble=self.tisA)
        self.gs_B1A2 = SampleSet([self.sampB1, self.sampA2])
        self.gs_A0B1 = SampleSet([self.sampA0, self.sampB1])
Пример #15
0
 def test_everything_accepted(self):
     move = ConditionalSequentialMover(movers=self.everything_accepted_movers)
     gs = SampleSet(self.init_sample)
     change = move.move(gs)
     samples = change.results
     assert_equal(len(samples), 3)
     for ch in change:
         assert_equal(change.accepted, True)
     gs = gs + change
     assert_equal(gs[0].ensemble, self.tps)
Пример #16
0
 def test_setup_sanity(self):
     # sanity checks to make sure that what we set up makes sense
     assert_equal(self.minus_sample.ensemble(self.minus_sample.trajectory),
                 True)
     first_subtraj = FirstSubtrajectorySelectMover(
         ensemble=self.minus,
         sub_ensemble=self.minus._segment_ensemble
     )
     change = first_subtraj.move(SampleSet(self.minus_sample))
     samples = change.results
     assert_equal(samples[0].ensemble(samples[0].trajectory), True)
     final_subtraj = FinalSubtrajectorySelectMover(
         ensemble=self.minus,
         sub_ensemble=self.minus._segment_ensemble
     )
     change = final_subtraj.move(SampleSet(self.minus_sample))
     samples = change.results
     assert_equal(samples[0].ensemble(samples[0].trajectory), True)
     assert_equal(samples[0].ensemble, self.minus._segment_ensemble)
Пример #17
0
 def test_AXA_path(self):
     trajAXA = make_1d_traj(coordinates=[-0.1, 0.75, -0.6],
                            velocities=[0.1, 0.05, -0.05])
     assert_equal(self.tis(trajAXA), True)
     sampAXA = Sample(trajectory=trajAXA,
                      ensemble=self.tis,
                      replica=0)
     gs_AXA = SampleSet([sampAXA])
     change = self.move.move(gs_AXA)
     assert_equal(change.accepted, True)
Пример #18
0
 def test_everything_accepted(self):
     move = PartialAcceptanceSequentialMover(movers=self.everything_accepted_movers)
     gs = SampleSet(self.init_sample)
     change = move.move(gs)
     samples = change.results
     assert_equal(len(samples), 3)
     for subchange in change:
         assert_equal(subchange.accepted, True)
     assert_equal(len(change.trials,),3)
     gs = gs + change
     assert_equal(gs[0].ensemble, self.tps)
Пример #19
0
 def test_first_rejected(self):
     move = ConditionalSequentialMover(movers=self.first_rejected_movers)
     gs = SampleSet(self.init_sample)
     change = move.move(gs)
     samples = change.results
     # should be zero since the move is completely rejected
     assert_equal(len(samples), 0)
     allsamp = change.trials
     assert_equal(len(allsamp), 1)
     assert_equal(change[0].accepted, False)
     gs = gs + change
     assert_equal(gs[0].ensemble, self.len3)
Пример #20
0
 def test_first_rejected(self):
     move = SequentialMover(movers=self.first_rejected_movers)
     gs = SampleSet(self.init_sample)
     change = move.move(gs)
     samples = change.results
     # @DWHS: This should have two samples since two are accepted
     # and thus applied
     assert_equal(len(samples), 2)
     assert_equal(change[0].accepted, False)
     assert_equal(change[1].accepted, True)
     assert_equal(change[2].accepted, True)
     gs = gs + change
     assert_equal(gs[0].ensemble, self.tps)
Пример #21
0
 def test_first_rejected(self):
     move = PartialAcceptanceSequentialMover(movers=self.first_rejected_movers)
     gs = SampleSet(self.init_sample)
     change = move.move(gs)
     samples = change.results
     # returns zero sample since even the first is rejected
     # the first one is still stored
     assert_equal(len(samples), 0)
     allsamp = change.trials
     assert_equal(len(allsamp), 1)
     assert_equal(change[0].accepted, False)
     gs = gs + change
     assert_equal(gs[0].ensemble, self.len3)
Пример #22
0
 def test_last_rejected(self):
     move = SequentialMover(movers=self.last_rejected_movers)
     gs = SampleSet(self.init_sample)
     change = move.move(gs)
     samples = change.results
     assert_equal(len(samples), 2)
     # @DWHS: I think if the last is rejected then there should only be two
     # samples to be used, since the last one is not accepted and thus
     # discarded (does not mean that it is not stored!!!)
     assert_equal(change[0].accepted, True)
     assert_equal(change[1].accepted, True)
     assert_equal(change[2].accepted, False)
     gs = gs + change
     assert_equal(gs[0].ensemble, self.tps)
Пример #23
0
    def test_repex_fails_innermost_crosses_state(self):
        innermost_crosses_to_state = make_1d_traj([-0.11, 0.5, 1.8])
        samp_crosses_to_state = Sample(
            replica=0,
            trajectory=innermost_crosses_to_state,
            ensemble=self.innermost
        )
        gs = SampleSet([samp_crosses_to_state, self.minus_sample])
        
        change = self.mover.move(gs)
        assert_equal(len(change.trials), 1) # stop after failed repex

        sub = change.subchange.subchange
        assert_equal(self.innermost(innermost_crosses_to_state), True)
        assert_equal(len(sub.trials), 3) # stop after failed repex
        assert_subchanges_set_accepted(sub, [True, False, False])
Пример #24
0
    def test_last_rejected(self):
        move = PartialAcceptanceSequentialMover(movers=self.last_rejected_movers)
        gs = SampleSet(self.init_sample)
        change = move.move(gs)
        samples = change.results
        # @see above, this should return 2 samples. Important the third is
        # still run!
        assert_equal(len(samples), 2)
        allsamp = change.trials
        assert_equal(len(allsamp), 3)

        assert_equal(change[0].accepted, True)
        assert_equal(change[1].accepted, True)
        assert_equal(change[2].accepted, False)
        gs = gs + change
        assert_equal(gs[0].ensemble, self.tps)
Пример #25
0
    def test_repex_fails_other_ensemble(self):
        innermost_other_ensemble = make_1d_traj([-0.11, 0.1, -0.12])
        samp_other_ensemble = Sample(
            replica=0,
            trajectory=innermost_other_ensemble,
            ensemble=self.innermost
        )
        gs = SampleSet([samp_other_ensemble, self.minus_sample])
        
        change = self.mover.move(gs)
        assert_equal(len(change.trials), 1)

        sub = change.subchange.subchange
        assert_equal(self.innermost(innermost_other_ensemble), False)
        assert_equal(sub[0].accepted, True)
        assert_equal(sub[1].accepted, False)
        assert_equal(len(sub.trials), 3) # stop after failed repex
Пример #26
0
    def test_last_rejected(self):
        move = ConditionalSequentialMover(movers=self.last_rejected_movers)
        gs = SampleSet(self.init_sample)
        change = move.move(gs)
        samples = change.results
        # number of accepted samples is 0 for this type of mover
        assert_equal(len(samples), 0)
        allsamp = change.trials
        assert_equal(len(allsamp), 3)

        # check here if last actual samples was false
        # this actually allows to see later if the single samples were
        # accepted or not, even from the change without loading samples
        assert_equal(change[0].accepted, True)
        assert_equal(change[1].accepted, True)
        assert_equal(change[2].accepted, False)
        gs = gs + change
        assert_equal(gs[0].ensemble, self.len3)
Пример #27
0
 def setup(self):
     self.dyn = CalvinistDynamics([-0.1, 0.1, 0.3, 0.5, 0.7, 
                                   -0.1, 0.2, 0.4, 0.6, 0.8,
                                  ])
     SampleMover.engine = self.dyn
     op = CV_Function("myid", f=lambda snap :
                          snap.coordinates[0][0])
     stateA = CVRangeVolume(op, -100, 0.0)
     stateB = CVRangeVolume(op, 0.65, 100)
     self.tps = ef.A2BEnsemble(stateA, stateB)
     init_traj = make_1d_traj(
         coordinates=[-0.1, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7],
         velocities=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
     )
     self.init_samp = SampleSet([Sample(
         trajectory=init_traj,
         replica=0,
         ensemble=self.tps
     )])
Пример #28
0
 def setup(self):
     traj = Trajectory([-0.5, 0.7, 1.1])
     op = CallIdentity()
     volA = CVRangeVolume(op, -100, 0.0)
     volB = CVRangeVolume(op, 1.0, 100)
     volX = CVRangeVolume(op, -100, 0.25)
     self.tis = paths.TISEnsemble(volA, volB, volX)
     self.tps = ef.A2BEnsemble(volA, volB)
     self.len3 = LengthEnsemble(3)
     self.init_samp = SampleSet([Sample(trajectory=traj,
                                        ensemble=self.len3, 
                                        replica=0)])
     self.hop_to_tis = EnsembleHopMover(
         ensemble=self.len3,
         target_ensemble=self.tis
     )
     self.hop_to_tps = EnsembleHopMover(
         ensemble=self.len3,
         target_ensemble=self.tps
     )
     self.mover = RandomChoiceMover([self.hop_to_tis, self.hop_to_tps])
Пример #29
0
 def test_move_multiple_replicas(self):
     sampleset = SampleSet([self.samp1, self.samp2])
     count = {}
     for i in range(100):
         change = self.mover.move(sampleset)
         subchange = change.subchange
         assert_equal(change.accepted, True)
         assert_equal(subchange.accepted, True)
         assert_equal(len(subchange.samples), 1)
         ens = subchange.trials[0].ensemble
         try:
             count[ens] += 1
         except KeyError:
             count[ens] = 1
         if ens == self.ens1:
             assert_equal(subchange.mover, self.pathrev)
         elif ens == self.ens2:
             assert_equal(subchange.mover, self.shooter)
         else:
             raise AssertionError("Resulting mover unknown!")
     assert_equal(set(count.keys()), set([self.ens1, self.ens2]))
Пример #30
0
    def test_repex_fails_minus_crosses_to_state(self):
        minus_crosses_to_state = make_1d_traj(
            [-0.11, 0.5, 1.8, 0.6, -0.12, 0.7, 1.7, 0.4, -0.13]
        )
        badminus_sample = Sample(
            replica=-1,
            trajectory=minus_crosses_to_state,
            ensemble=self.minus
        )
        init_sample = Sample(
            replica=0,
            trajectory=make_1d_traj(self.list_innermost, [1.0]*5),
            ensemble=self.innermost
        )
        gs = SampleSet([badminus_sample, init_sample])

        assert_equal(self.minus(minus_crosses_to_state), True)

        change = self.mover.move(gs)
        sub = change.subchange.subchange
        assert_equal(len(sub.trials), 3)  # stop after failed repex
        assert_equal(len(change.trials), 1)
        assert_subchanges_set_accepted(sub, [True, False, False])
Пример #31
0
 def setup(self):
     op = CallIdentity()
     vol = paths.CVRangeVolume(op, -0.5, 0.5)
     inX = paths.AllInXEnsemble(vol)
     outX = paths.AllOutXEnsemble(vol)
     self.ensemble = paths.SequentialEnsemble([
         inX, outX, inX, outX, inX, outX, inX
     ])
     self.subensemble = paths.SequentialEnsemble([
         paths.SingleFrameEnsemble(inX),
         outX,
         paths.SingleFrameEnsemble(inX)
     ])
     self.traj_with_3_subtrajs = Trajectory(
         [0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.0]
     )
     self.subtraj0 = Trajectory([0.0, 1.0, 1.0, 0.0])
     self.subtraj1 = Trajectory([0.0, 1.0, 0.0])
     self.subtraj2 = Trajectory([0.0, 2.0, 0.0])
     self.gs = SampleSet(Sample(
         replica=0,
         ensemble=self.ensemble,
         trajectory=self.traj_with_3_subtrajs
     ))