Esempio n. 1
0
    def setup(self):
        super(TestMinusMoveFlux, self).setup()

        a = 0.1  # just a number to simplify the trajectory-making
        minus_move_descriptions = [
            [-a, a, a, -a, -a, -a, -a, -a, a, a, a, a, a, -a],
            [-a, a, a, a, -a, -a, -a, a, a, a, -a]
        ]

        engine = RandomMDEngine()  # to get snapshot_timestep

        self.mistis_scheme = paths.DefaultScheme(self.mistis, engine)
        self.mistis_scheme.build_move_decision_tree()
        self.mistis_minus_steps = self._make_fake_minus_steps(
            scheme=self.mistis_scheme,
            descriptions=minus_move_descriptions
        )
        self.mistis_minus_flux = MinusMoveFlux(self.mistis_scheme)

        self.mstis_scheme = paths.DefaultScheme(self.mstis, engine)
        self.mstis_scheme.build_move_decision_tree()
        self.mstis_minus_steps = self._make_fake_minus_steps(
            scheme=self.mstis_scheme,
            descriptions=minus_move_descriptions
        )
        self.mstis_minus_flux = MinusMoveFlux(self.mstis_scheme)
Esempio n. 2
0
 def test_bad_network(self):
     # raises error if more than one transition shares a minus ensemble
     # (flux cannot be calculated with multiple interface set minus move)
     state_C = paths.CVDefinedVolume(self.cv_x, 0.5, 0.7)
     trans_AB = self.mistis.transitions[(self.state_A, self.state_B)]
     trans_BA = self.mistis.transitions[(self.state_B, self.state_A)]
     interfaces_AB = trans_AB.interfaces
     interfaces_BA = trans_BA.interfaces
     interfaces_AC = trans_AB.interfaces
     bad_mistis = paths.MISTISNetwork([
         (self.state_A, interfaces_AB, self.state_B),
         (self.state_B, interfaces_BA, self.state_A),
         (self.state_A, interfaces_AC, state_C)
     ])
     scheme = paths.DefaultScheme(bad_mistis)
     scheme.build_move_decision_tree()
     minus_flux = MinusMoveFlux(scheme)
def run_example(nsteps, setup, output_filename):
    engine, network, snapshots = setup()
    minus, outers = zip(*[prep_from_frame(network, init_frame, engine)
                          for init_frame in snapshots])
    minus = sum([list(m) for m in minus], [])
    outers = sum([list(o) for o in outers], [])

    scheme = paths.DefaultScheme(network, engine=engine)
    print("Loading initial conditions with outermost trajs")
    init_conds = scheme.initial_conditions_from_trajectories(outers)
    print("Loading initial conditions with minus trajs")
    init_conds = scheme.initial_conditions_from_trajectories(
        minus, sample_set=init_conds
    )

    storage = paths.Storage(output_filename, mode='w')
    simulation = paths.PathSampling(
        storage=storage,
        move_scheme=scheme,
        sample_set=init_conds
    )
    simulation.save_frequency = 50
    simulation.run(nsteps)
    storage.close()
Esempio n. 4
0
    def test_with_minus_move_flux(self):
        network = self.mstis
        scheme = paths.DefaultScheme(network, engine=RandomMDEngine())
        scheme.build_move_decision_tree()

        # create the minus move steps
        # `center` is the edge of the state/innermost interface
        center = {self.state_A: 0.0, self.state_B: 1.0}
        replica = {self.state_A: -1, self.state_B: -2}
        minus_ensemble_to_mover = {m.minus_ensemble: m
                                   for m in scheme.movers['minus']}
        state_to_minus_ensemble = {ens.state_vol: ens
                                   for ens in network.minus_ensembles}
        minus_changes = []
        # `delta` is the change on either side for in vs. out
        for (state, delta) in [(self.state_A, 0.1), (self.state_B, -0.1)]:
            minus_ens = state_to_minus_ensemble[state]
            minus_mover = minus_ensemble_to_mover[minus_ens]
            a_in = center[state] - delta
            a_out = center[state] + delta
            # note that these trajs are equivalent to minus move
            # descriptions in TestMinusMoveFlux
            seq_1 = [a_in] + [a_out]*2 + [a_in]*5 + [a_out]*5 + [a_in]
            seq_2 = [a_in] + [a_out]*3 + [a_in]*3 + [a_out]*3 + [a_in]

            for seq in [seq_1, seq_2]:
                traj = make_1d_traj(seq)
                assert_equal(minus_ens(traj), True)
                samp = paths.Sample(trajectory=traj,
                                    ensemble=minus_ens,
                                    replica=replica[state])
                sample_set = paths.SampleSet([samp])
                change = paths.AcceptedSampleMoveChange(
                    samples=[samp],
                    mover=minus_mover,
                    details=paths.Details()
                )
                minus_changes.append(change)

        active = self.mstis_steps[0].active
        steps = []
        cycle = -1
        for m_change in minus_changes:
            cycle += 1
            active = active.apply_samples(m_change.samples)
            step = paths.MCStep(mccycle=cycle,
                                active=active,
                                change=m_change)
            steps.append(step)
            for old_step in self.mstis_steps[1:]:
                cycle += 1
                active = active.apply_samples(old_step.change.samples)
                step = paths.MCStep(mccycle=cycle,
                                    active=active,
                                    change=old_step.change)
                steps.append(step)

        analysis = StandardTISAnalysis(
            network=self.mstis,
            scheme=scheme,
            max_lambda_calcs={t: {'bin_width': 0.1,
                                  'bin_range': (-0.1, 1.1)}
                              for t in network.sampling_transitions},
            steps=steps
        )

        # now we actually verify correctness
        avg_t_in = (5.0 + 3.0) / 2
        avg_t_out = (2.0 + 5.0 + 3.0 + 3.0) / 4
        expected_flux = 1.0 / (avg_t_in + avg_t_out)

        # NOTE: Apparently this approach screws up the TCP calculation. I
        # think this is a problem in the fake data, not the simulation.
        for flux in analysis.flux_matrix.values():
            assert_almost_equal(flux, expected_flux)
Esempio n. 5
0
                [cv(snapshot) for snapshot in initial_trajectories[0]])
            print(distances)
        print('minus trajectories')
        minus_trajectories = mistis.minus_ensembles[0].split(long_trajectory)
        print(minus_trajectories)
        if len(minus_trajectories) > 0:
            distances = np.array(
                [cv(snapshot) for snapshot in minus_trajectories[0]])
            print(distances)
        attempt += 1
        print('')

        # Create a network to study unbinding paths
        # note the list/tuple structure: that's because this is normally a list of tuples,
        # each tuple representing a transition to study
        scheme = paths.DefaultScheme(mistis, engine=engine)
        sset = scheme.initial_conditions_from_trajectories(
            initial_trajectories + minus_trajectories)
        print scheme.initial_conditions_report(sset)

elif initial_trajectory_method == 'bootstrap':
    print('Bootstrapping initial trajectory...')
    bootstrap = paths.FullBootstrapping(
        transition=mistis.transitions[(bound, unbound)],
        snapshot=initial_snapshot,
        engine=engine_hot)
    #storage.save(bootstrap) # Causes Dataframe error
    initial_sample_set = bootstrap.run()
    initial_trajectories = [s.trajectory for s in initial_sample_set]
    print(initial_trajectories)