Esempio n. 1
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,
                                     ])
        self.dyn.initialized = True
        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)
        volX = CVRangeVolume(op, -100, 0.25)
        volY = CVRangeVolume(op, -100, 0.40)
        self.ens1 = paths.TISEnsemble(stateA, stateB, volX, op)
        self.ens2 = paths.TISEnsemble(stateA, stateB, volY, op)
        init_traj1 = make_1d_traj(
            coordinates=[-0.1, 0.1, 0.2, 0.3, 0.24, 0.15, 0.06, -0.07],
            velocities=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        )
        init_traj2 = 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.samp1 = Sample(trajectory=init_traj1, replica=0, 
                            ensemble=self.ens1)
        self.samp2 = Sample(trajectory=init_traj2, replica=1,
                            ensemble=self.ens2)

        self.shooter = ForwardShootMover(selector=UniformSelector(),
                                         ensemble=self.ens2)
        self.pathrev = PathReversalMover(ensemble=self.ens1)

        ens_dict = {self.ens1 : self.pathrev, self.ens2 : self.shooter}
        # self.mover = EnsembleDictionaryMover(ens_dict)
        self.mover = RandomAllowedChoiceMover([self.shooter, self.pathrev])
Esempio n. 2
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])
Esempio n. 3
0
 def setup(self):
     self.ensA = LengthEnsemble(1)
     self.ensB = LengthEnsemble(2)
     traj0A = Trajectory([0.5])
     traj1A = Trajectory([1.0])
     traj2B = Trajectory([0.5, 0.75])
     traj2B_ = Trajectory([0.8, 0.9])
     self.s0A = Sample(replica=0, trajectory=traj0A, ensemble=self.ensA)
     self.s1A = Sample(replica=1, trajectory=traj1A, ensemble=self.ensA)
     self.s2B = Sample(replica=2, trajectory=traj2B, ensemble=self.ensB)
     self.s2B_ = Sample(replica=2, trajectory=traj2B_, ensemble=self.ensB)
     self.testset = SampleSet([self.s0A, self.s1A, self.s2B])
Esempio n. 4
0
 def test_setitem_replica(self):
     ensC = LengthEnsemble(3)
     traj3C = Trajectory([-0.5, -0.25, 0.1])
     s3C = Sample(replica=3, trajectory=traj3C, ensemble=ensC)
     self.testset[3] = s3C
     self.testset.consistency_check()
     assert_equal(len(self.testset), 4)
Esempio n. 5
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
        )
Esempio n. 6
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)
Esempio n. 7
0
    def add_empty_to_cache(self, idx, trajectory_idx, replica_idx, bias):
        obj = Sample(
                trajectory=self.storage.trajectories[int(trajectory_idx)],
                replica=int(replica_idx),
                bias=float(bias)
            )
        obj.idx[self.storage] = idx
        obj._origin = self.storage

        del obj.details
        del obj.ensemble
        del obj.mover
        del obj.parent

        self.cache[idx] = obj

        return obj
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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)
     tis = paths.TISEnsemble(volA, volB, volX)
     tps = ef.A2BEnsemble(volA, volB)
     len3 = LengthEnsemble(3)
     len2 = LengthEnsemble(2)
     self.hop_to_tis = RandomAllowedChoiceMover(
         map(lambda ens : EnsembleHopMover(*ens),
             [[tis, tis],
              [tps, tis],
              [len3, tis],
              [len2, tis]]
         )
     )
     self.hop_to_tps = RandomAllowedChoiceMover(
         map(lambda ens : EnsembleHopMover(*ens),
             [[tis, tps],
              [tps, tps],
              [len3, tps],
              [len2, tps]]
         )
     )
     self.hop_to_len3 = RandomAllowedChoiceMover(
         map(lambda ens : EnsembleHopMover(*ens),
             [[tis, len3],
              [tps, len3],
              [len3, len3],
              [len2, len3]]
         )
     )
     self.hop_to_len2 = RandomAllowedChoiceMover(
         map(lambda ens : EnsembleHopMover(*ens),
             [[tis, len2],
              [tps, len2],
              [len3, len2],
              [len2, len2]]
         )
     )
     self.init_sample = Sample(trajectory=traj,
                               ensemble=len3,
                               replica=0)
     self.tis = tis
     self.tps = tps
     self.len3 = len3
     self.len2 = len2
     self.everything_accepted_movers = [
         self.hop_to_tis, self.hop_to_len3, self.hop_to_tps
     ]
     self.first_rejected_movers = [
         self.hop_to_len2, self.hop_to_len3, self.hop_to_tps
     ]
     self.last_rejected_movers = [
         self.hop_to_tis, self.hop_to_tps, self.hop_to_len2
     ]
Esempio n. 11
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)
Esempio n. 12
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])
 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))
Esempio n. 14
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)
Esempio n. 15
0
    def _load(self, idx):
        obj = Sample(
            trajectory=self.vars['trajectory'][idx],
            replica=self.vars['replica'][idx],
            ensemble=self.vars['ensemble'][idx],
            parent=self.vars['parent'][idx],
            details=self.vars['details'][idx],
            bias=self.vars['bias'][idx],
            mover=self.vars['mover'][idx]
        )

        return obj
Esempio n. 16
0
    def setup(self):
        op = CV_Function("myid", f=lambda snap :
                             snap.coordinates[0][0])

        volA = CVRangeVolume(op, -100, 0.0)
        volB = CVRangeVolume(op, 1.0, 100)
        volX = CVRangeVolume(op, -100, 0.25)
        self.dyn = CalvinistDynamics([
            # successful move: (backward extension then forward)
            -0.13, 0.13, 0.33, -0.11, -0.12, 0.12, 0.32, -0.131,
            # never leaves state: 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.25, 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            # goes to other state:
            1.16, 1.26, 1.16, -0.16, 1.16, 1.26, 1.16
        ])
        SampleMover.engine = self.dyn
        self.dyn.initialized = True
        self.innermost = paths.TISEnsemble(volA, volB, volX)
        self.minus = paths.MinusInterfaceEnsemble(volA, volX)
        self.mover = MinusMover(
            minus_ensemble=self.minus,
            innermost_ensembles=self.innermost
        )
        self.first_segment = [-0.1, 0.1, 0.3, 0.1, -0.15] 
        self.list_innermost = [-0.11, 0.11, 0.31, 0.11, -0.12]
        self.second_segment = [-0.25, 0.2, 0.4, 0.2, -0.2]
        init_minus = make_1d_traj(
            coordinates=self.first_segment + [-0.35] + self.second_segment,
            velocities=[1.0]*11
        )
        self.minus_sample = Sample(
            replica=-1,
            trajectory=init_minus,
            ensemble=self.minus
        )
Esempio n. 17
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])
Esempio n. 18
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)
Esempio n. 19
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])
Esempio n. 20
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
Esempio n. 21
0
    def _add_empty_to_cache(self, idx, trajectory_idx, replica_idx, bias,
                           ensemble_idx, parent_idx, details_idx, mover_idx):
        storage = self.storage
        obj = Sample(
            trajectory=storage.trajectories[int(trajectory_idx)],
            replica=int(replica_idx),
            bias=float(bias),
            ensemble=storage.ensembles[int(ensemble_idx)],
            mover=storage.pathmovers[int(mover_idx)],
            parent=LoaderProxy(storage.samples, int(parent_idx)),
            details=LoaderProxy(storage.details, int(details_idx))
        )

        self.index[obj] = idx
        self.cache[idx] = obj

        return obj
Esempio n. 22
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
     )])
Esempio n. 23
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])
Esempio n. 24
0
    def setup(self):
        op = CV_Function("myid", fcn=lambda snap :
                             snap.coordinates[0][0])

        volA = CVRangeVolume(op, -100, 0.0)
        volB = CVRangeVolume(op, 1.0, 100)
        volX = CVRangeVolume(op, -100, 0.25)
        self.dyn = CalvinistDynamics([
            # successful move: (backward extension then forward)
            -0.13, 0.13, 0.33, -0.11, -0.12, 0.12, 0.32, -0.131,
            # never leaves state: 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.25, 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            # goes to other state:
            1.16, 1.26, 1.16, -0.16, 1.16, 1.26, 1.16
        ])
        SampleGeneratingMover.engine = self.dyn
        self.dyn.initialized = True
        self.innermost = paths.TISEnsemble(volA, volB, volX)
        self.minus = paths.MinusInterfaceEnsemble(volA, volX)
        self.mover = MinusMover(
            minus_ensemble=self.minus,
            innermost_ensembles=self.innermost
        )
        self.first_segment = [-0.1, 0.1, 0.3, 0.1, -0.15] 
        self.list_innermost = [-0.11, 0.11, 0.31, 0.11, -0.12]
        self.second_segment = [-0.25, 0.2, 0.4, 0.2, -0.2]
        init_minus = make_1d_traj(
            coordinates=self.first_segment + [-0.35] + self.second_segment,
            velocities=[1.0]*11
        )
        self.minus_sample = Sample(
            replica=-1,
            trajectory=init_minus,
            ensemble=self.minus
        )
Esempio n. 25
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
     ))
Esempio n. 26
0
class testMinusMover(object):
    def setup(self):
        op = CV_Function("myid", f=lambda snap :
                             snap.coordinates[0][0])

        volA = CVRangeVolume(op, -100, 0.0)
        volB = CVRangeVolume(op, 1.0, 100)
        volX = CVRangeVolume(op, -100, 0.25)
        self.dyn = CalvinistDynamics([
            # successful move: (backward extension then forward)
            -0.13, 0.13, 0.33, -0.11, -0.12, 0.12, 0.32, -0.131,
            # never leaves state: 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.25, 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            # goes to other state:
            1.16, 1.26, 1.16, -0.16, 1.16, 1.26, 1.16
        ])
        SampleMover.engine = self.dyn
        self.dyn.initialized = True
        self.innermost = paths.TISEnsemble(volA, volB, volX)
        self.minus = paths.MinusInterfaceEnsemble(volA, volX)
        self.mover = MinusMover(
            minus_ensemble=self.minus,
            innermost_ensembles=self.innermost
        )
        self.first_segment = [-0.1, 0.1, 0.3, 0.1, -0.15] 
        self.list_innermost = [-0.11, 0.11, 0.31, 0.11, -0.12]
        self.second_segment = [-0.25, 0.2, 0.4, 0.2, -0.2]
        init_minus = make_1d_traj(
            coordinates=self.first_segment + [-0.35] + self.second_segment,
            velocities=[1.0]*11
        )
        self.minus_sample = Sample(
            replica=-1,
            trajectory=init_minus,
            ensemble=self.minus
        )

    def test_is_ensemble_change_mover(self):
        assert_equal(self.mover.is_ensemble_change_mover, True)

    def test_is_canonical(self):
        assert_equal(self.mover.is_canonical, True)

    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)
        

    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)

    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
        # only one sample which is not a segment

    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])

    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])

    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

        sub = change.subchange.subchange
        assert_equal(len(sub.trials), 4)

        # after filtering there are only 2 trials
        assert_equal(len(change.trials), 2)

        assert_subchanges_set_accepted(sub, [True] * 2 + [False])
        # first two work and the extention fails
        # this only happens due to length
        assert_equal(
            len(sub[-1][0].trials[0].trajectory),
            len(traj_bad_extension)+self.dyn.n_frames_max-1
        )
Esempio n. 27
0
class testMinusMover(object):
    def setup(self):
        op = CV_Function("myid", fcn=lambda snap :
                             snap.coordinates[0][0])

        volA = CVRangeVolume(op, -100, 0.0)
        volB = CVRangeVolume(op, 1.0, 100)
        volX = CVRangeVolume(op, -100, 0.25)
        self.dyn = CalvinistDynamics([
            # successful move: (backward extension then forward)
            -0.13, 0.13, 0.33, -0.11, -0.12, 0.12, 0.32, -0.131,
            # never leaves state: 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.25, 
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15, -0.15,
            # goes to other state:
            1.16, 1.26, 1.16, -0.16, 1.16, 1.26, 1.16
        ])
        SampleGeneratingMover.engine = self.dyn
        self.dyn.initialized = True
        self.innermost = paths.TISEnsemble(volA, volB, volX)
        self.minus = paths.MinusInterfaceEnsemble(volA, volX)
        self.mover = MinusMover(
            minus_ensemble=self.minus,
            innermost_ensembles=self.innermost
        )
        self.first_segment = [-0.1, 0.1, 0.3, 0.1, -0.15] 
        self.list_innermost = [-0.11, 0.11, 0.31, 0.11, -0.12]
        self.second_segment = [-0.25, 0.2, 0.4, 0.2, -0.2]
        init_minus = make_1d_traj(
            coordinates=self.first_segment + [-0.35] + self.second_segment,
            velocities=[1.0]*11
        )
        self.minus_sample = Sample(
            replica=-1,
            trajectory=init_minus,
            ensemble=self.minus
        )

    def test_is_ensemble_change_mover(self):
        assert_equal(self.mover.is_ensemble_change_mover, True)

    def test_is_canonical(self):
        assert_equal(self.mover.is_canonical, True)

    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)
        

    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)

    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
        # only one sample which is not a segment

    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])

    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])

    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

        sub = change.subchange.subchange
        assert_equal(len(sub.trials), 4)

        # after filtering there are only 2 trials
        assert_equal(len(change.trials), 2)

        assert_subchanges_set_accepted(sub, [True] * 2 + [False])
        # first two work and the extention fails
        # this only happens due to length
        assert_equal(
            len(sub[-1][0].trials[0].trajectory),
            len(traj_bad_extension)+self.dyn.n_frames_max-1
        )
Esempio n. 28
0
 def test_sanity_insane(self):
     traj0A = self.s0A.trajectory
     ensB = self.s2B.ensemble
     bad_samp = Sample(replica=0, trajectory=traj0A, ensemble=ensB)
     testset = SampleSet([bad_samp])
     testset.sanity_check()