def test_relevant_transitions(self):
     extra_set = paths.VolumeInterfaceSet(self.cv_inc, 0.0, [0.2, 0.3])
     extra = paths.TISTransition(self.stateA, self.stateB, extra_set,
                                 self.cv_inc, "fake")
     transitions = self.network.sampling_transitions + [extra]
     # TODO: switch once network is working
     relevant = self.post_network.relevant_transitions(transitions)
     #relevant = self.ms_outer.relevant_transitions(transitions)
     assert_equal(len(relevant), 2)
     assert_equal(set(self.network.sampling_transitions), set(relevant))
예제 #2
0
    def _build_sampling_transitions(self, transitions):
        transitions = list(transitions)  # input may be iterator
        # TODO: I don't think transition pairs are used (see comment below;
        # I think that was the previous use case -- as input to all_in_pairs
        # However, existing files store this, so we won't actually remove it
        # yet.
        self.transition_pairs = self._build_transition_pairs(transitions)
        # this seems to no longer be used; I think it was necessary when the
        # MSOuter interface was done implicitly, instead of explicitly. Then
        # we turn the outermost to MS if and only if it was paired with the
        # reverse transition
        # if len(self.transition_pairs) > 0:
        # all_in_pairs = reduce(list.__add__, map(lambda x: list(x),
        # self.transition_pairs))
        # else:
        # all_in_pairs = []

        # build sampling transitions
        all_states = paths.join_volumes(self.initial_states +
                                        self.final_states)
        all_states_set = set(self.initial_states + self.final_states)
        self.transition_to_sampling = {}
        for transition in transitions:
            stateA = transition.stateA
            stateB = transition.stateB
            if self.strict_sampling:
                final_state = stateB
                other_states = paths.join_volumes(all_states_set -
                                                  set([stateA, stateB]))
                ensemble_to_intersect = paths.AllOutXEnsemble(other_states)
            else:
                final_state = paths.join_volumes(all_states_set)
                ensemble_to_intersect = paths.FullEnsemble()

            sample_trans = paths.TISTransition(
                stateA=stateA,
                stateB=final_state,
                interfaces=transition.interfaces,
                name=stateA.name + "->" + stateB.name,
                orderparameter=transition.orderparameter)

            new_ensembles = [
                e & ensemble_to_intersect for e in sample_trans.ensembles
            ]
            if self.strict_sampling:
                for (old, new) in zip(new_ensembles, sample_trans.ensembles):
                    old.name = new.name + " strict"
            sample_trans.ensembles = new_ensembles
            sample_trans.named("Sampling " + str(stateA) + "->" + str(stateB))
            self.transition_to_sampling[transition] = sample_trans

        self.x_sampling_transitions = \
                list(self.transition_to_sampling.values())

        self._build_sampling_minus_ensembles()
예제 #3
0
    def build_fromstate_transitions(self, trans_info):
        """
        Builds the sampling transitions (the self.from_state dictionary).

        This also sets self.states (list of states volumes), self.outers
        (list of interface volumes making the MS-outer interface), and 
        self.outer_ensembles (list of TISEnsembles associated with the
        self.outers interfaces). Additionally, it gives default names
        volumes, interfaces, and transitions.

        Parameters
        ----------
        trans_info : list of 2-tuples
            See description in __init__.

        """
        states, interfaces = zip(*trans_info)
        orderparams = [iface_set.cv for iface_set in interfaces]
        # NAMING STATES (give default names)
        all_states = paths.volume.join_volumes(states).named("all states")
        all_names = list(set([s.name for s in states]))
        unnamed_states = [s for s in states if not s.is_named]
        name_index = 0
        for state in unnamed_states:
            while index_to_string(name_index) in all_names:
                name_index += 1
            state.named(index_to_string(name_index))
            name_index += 1

        # BUILDING ENSEMBLES
        self.states = states
        for (state, ifaces) in trans_info:
            op = ifaces.cv
            state_index = states.index(state)
            other_states = states[:state_index]+states[state_index+1:]
            union_others = paths.volume.join_volumes(other_states)
            union_others.named("all states except " + str(state.name))

            this_trans = paths.TISTransition(
                stateA=state, 
                stateB=union_others,
                interfaces=ifaces,
                name="Out " + state.name,
                orderparameter=op
            )

            self.from_state[state] = this_trans

            this_minus = self.from_state[state].minus_ensemble
            this_inner = self.from_state[state].ensembles[0]
            try:
                self.special_ensembles['minus'][this_minus] = [this_trans]
            except KeyError:
                self.special_ensembles['minus'] = {this_minus : [this_trans]}
예제 #4
0
 def build_one_state_sampling_transition(state, interfaces, all_states):
     other_states = list(set(all_states) - set([state]))
     union_others = paths.join_volumes(volume_list=other_states,
                                       name="all states except " +
                                       str(state.name))
     this_trans = paths.TISTransition(stateA=state,
                                      stateB=union_others,
                                      interfaces=interfaces,
                                      name="Out " + state.name,
                                      orderparameter=interfaces.cv)
     return this_trans
예제 #5
0
    def __init__(self, trans_info, ms_outers=None, strict_sampling=False):
        super(MISTISNetwork, self).__init__(trans_info, ms_outers)
        self.strict_sampling = strict_sampling
        states_A, interfaces, states_B = zip(*trans_info)
        orderparams = [iface_set.cv for iface_set in interfaces]
        self.initial_states = list(set(states_A))
        self.final_states = list(set(states_B))
        list_all_states = list(set(self.initial_states + self.final_states))

        # name states
        all_state_names = list(set([s.name for s in list_all_states]))
        unnamed_states = [s for s in list_all_states if not s.is_named]
        name_index = 0
        for state in unnamed_states:
            while index_to_string(name_index) in all_state_names:
                name_index += 1
            state.named(index_to_string(name_index))
            name_index += 1

        if not hasattr(self, "input_transitions"):
            self.input_transitions = {
                (stateA, stateB):
                paths.TISTransition(stateA,
                                    stateB,
                                    interface,
                                    interface.cv,
                                    name=stateA.name + "->" + stateB.name,
                                    name_suffix=" (input)")
                for (stateA, interface, stateB) in self.trans_info
            }

        if not hasattr(self, 'x_sampling_transitions'):
            self.special_ensembles = {}
            self._build_sampling_transitions(self.input_transitions.values())
            if self.ms_outer_objects is not None:
                for ms_outer in self.ms_outer_objects:
                    all_transitions = self.x_sampling_transitions
                    if not self.strict_sampling:
                        self.add_ms_outer_interface(ms_outer, all_transitions)
                    else:
                        relevant = ms_outer.relevant_transitions(
                            all_transitions)
                        allowed = set(
                            sum([[t.stateA, t.stateB] for t in relevant], []))
                        forbidden = set(list_all_states) - allowed
                        self.add_ms_outer_interface(ms_outer, all_transitions,
                                                    forbidden)

        self._sampling_transitions = self.x_sampling_transitions

        # by default, we set assign these values to all ensembles
        self.hist_args = {}

        self._build_analysis_transitions()
예제 #6
0
 def test_calculate_no_max_lambda(self):
     mistis_AB = self.mistis.transitions[(self.state_A, self.state_B)]
     modified_transition = paths.TISTransition(
         stateA=mistis_AB.stateA,
         stateB=mistis_AB.stateB,
         interfaces=mistis_AB.interfaces.volumes,
         orderparameter=mistis_AB.orderparameter
     )
     mistis_AB_histogrammer = FullHistogramMaxLambdas(
         transition=modified_transition,
         hist_parameters={'bin_width': 0.1, 'bin_range': (-0.1, 1.1)}
     )
예제 #7
0
 def build_analysis_transitions(self):
     self.transitions = {}
     for trans in self.input_transitions.values():
         sample_trans = self.transition_to_sampling[trans]
         stateA = trans.stateA
         stateB = trans.stateB
         analysis_trans = paths.TISTransition(
             stateA=stateA,
             stateB=stateB,
             interfaces=sample_trans.interfaces,
             orderparameter=sample_trans.orderparameter)
         analysis_trans.ensembles = sample_trans.ensembles
         analysis_trans.named(trans.name)
         #analysis_trans.special_ensembles = sample_trans.special_ensembles
         self.transitions[(stateA, stateB)] = analysis_trans
예제 #8
0
 def ratcheter(self, interfaces, direction="out_in"):
     if direction == "in_out":
         stateA = self.DFG_in
         stateB = self.DFG_out
     elif direction == "out_in":
         stateA = self.DFG_out
         stateB = self.DFG_in
     else:
         raise RuntimeError("direction is " + str(direction) +
                            ": must be 'in_out' or 'out_in'.")
     transition = paths.TISTransition(stateA, stateB, interfaces, self.cv)
     ratcheter = paths.FullBootstrapping(
         transition=transition,
         snapshot=self.engine.current_snapshot,
         storage=self.storage,
         engine=self.engine)
     return ratcheter
예제 #9
0
 def build_analysis_transitions(self):
     # set up analysis transitions (not to be saved)
     for stateA in self.from_state.keys():
         state_index = self.states.index(stateA)
         fromA = self.from_state[stateA]
         other_states = self.states[:state_index] + self.states[
             state_index + 1:]
         for stateB in other_states:
             trans = paths.TISTransition(
                 stateA=stateA,
                 stateB=stateB,
                 interfaces=fromA.interfaces,
                 name=str(stateA) + "->" + str(stateB),
                 orderparameter=fromA.orderparameter)
             # override created stuff
             trans.ensembles = fromA.ensembles
             trans.minus_ensemble = fromA.minus_ensemble
             self.transitions[(stateA, stateB)] = trans
예제 #10
0
    def _build_analysis_transition_for_sampling(sampling_transition,
                                                all_states):
        local_transitions = {}
        state_A = sampling_transition.stateA
        other_states = set(all_states) - set([state_A])
        str_A = _default_state_name(state_A)
        for state_B in other_states:
            str_B = _default_state_name(state_B)
            trans = paths.TISTransition(
                stateA=state_A,
                stateB=state_B,
                interfaces=sampling_transition.interfaces,
                name=str_A + "->" + str_B,
                orderparameter=sampling_transition.orderparameter)
            # override created stuff
            trans.ensembles = sampling_transition.ensembles
            for i in range(len(trans.ensembles)):
                trans.ensembles[i].named(trans.name + "[" + str(i) + "]")

            trans.minus_ensemble = sampling_transition.minus_ensemble
            local_transitions[(state_A, state_B)] = trans
        return local_transitions
예제 #11
0
    def __init__(self, trans_info):
        super(MISTISNetwork, self).__init__()
        self.trans_info = trans_info
        states_A, interfaces, orderparams, states_B = zip(*trans_info)
        self.initial_states = list(set(states_A))
        self.final_states = list(set(states_B))
        list_all_states = list(set(self.initial_states + self.final_states))

        # name states
        all_state_names = list(set([s.name for s in list_all_states]))
        unnamed_states = [s for s in list_all_states if not s.is_named]
        name_index = 0
        for state in unnamed_states:
            while index_to_string(name_index) in all_names:
                name_index += 1
            state.named(index_to_string(name_index))
            name_index += 1

        if not hasattr(self, "input_transitions"):
            self.input_transitions = {
                (stateA, stateB):
                paths.TISTransition(stateA,
                                    stateB,
                                    interface,
                                    orderparam,
                                    name=stateA.name + "->" + stateB.name)
                for (stateA, interface, orderparam, stateB) in self.trans_info
            }

        if not hasattr(self, 'x_sampling_transitions'):
            self.special_ensembles = {}
            self.build_sampling_transitions(self.input_transitions.values())
        self._sampling_transitions = self.x_sampling_transitions

        # by default, we set assign these values to all ensembles
        self.hist_args = {}

        self.build_analysis_transitions()
예제 #12
0
 def build_analysis_transitions(self):
     # set up analysis transitions (not to be saved)
     for stateA in self.from_state.keys():
         state_index = self.states.index(stateA)
         fromA = self.from_state[stateA]
         other_states = self.states[:state_index]+self.states[state_index+1:]
         for stateB in other_states:
             strA = stateA.name if stateA.is_named else str(stateA)
             strB = stateB.name if stateB.is_named else str(stateB)
             trans = paths.TISTransition(
                 stateA=stateA,
                 stateB=stateB,
                 interfaces=fromA.interfaces,
                 name=strA + "->" + strB,
                 orderparameter=fromA.orderparameter
             )
             # override created stuff
             trans.ensembles = fromA.ensembles
             for i in range(len(trans.ensembles)):
                 trans.ensembles[i].named(trans.name + "[" + str(i) + "]")
                                          
             trans.minus_ensemble = fromA.minus_ensemble
             self.transitions[(stateA, stateB)] = trans
예제 #13
0
    def build_sampling_transitions(self, transitions):
        # identify transition pairs
        transition_pair_set_dict = {}
        for initial in self.initial_states:
            for t1 in [t for t in transitions if t.stateA==initial]:
                t_reverse = [
                    t for t in transitions 
                    if t.stateA == t1.stateB and t.stateB == t1.stateA
                ]
                if len(t_reverse) == 1:
                    key = frozenset([t1.stateA, t1.stateB])
                    new_v = [t1, t_reverse[0]]
                    if key not in transition_pair_set_dict.keys():
                        transition_pair_set_dict[key] = new_v
                elif len(t_reverse) > 1:  # pragma: no cover
                    raise RuntimeError("More than one reverse transition")
                # if len(t_reverse) is 0, we just pass

        self.transition_pairs = transition_pair_set_dict.values()

        if len(self.transition_pairs) > 0:
            all_in_pairs = reduce(list.__add__, map(lambda x: list(x), 
                                                    self.transition_pairs))
        else:
            all_in_pairs = []

        # build sampling transitions
        all_states = paths.join_volumes(self.initial_states + self.final_states)
        all_states_set = set(self.initial_states + self.final_states)
        self.transition_to_sampling = {}
        for transition in transitions:
            stateA = transition.stateA
            stateB = transition.stateB
            if self.strict_sampling:
                final_state = stateB
                other_states = paths.join_volumes(all_states_set -
                                                  set([stateA, stateB]))
                ensemble_to_intersect = paths.AllOutXEnsemble(other_states)
            else:
                final_state = all_states
                ensemble_to_intersect = paths.FullEnsemble()

            sample_trans = paths.TISTransition(
                stateA=stateA,
                stateB=final_state,
                interfaces=transition.interfaces,
                orderparameter=transition.orderparameter
            )

            new_ensembles = [e & ensemble_to_intersect 
                             for e in sample_trans.ensembles]
            if self.strict_sampling:
                for (old, new) in zip(new_ensembles, sample_trans.ensembles):
                    old.name = new.name + " strict"
            sample_trans.ensembles = new_ensembles
            sample_trans.named("Sampling " + str(stateA) + "->" + str(stateB))
            self.transition_to_sampling[transition] = sample_trans

        self.x_sampling_transitions = self.transition_to_sampling.values()

        # combining the minus interfaces
        for initial in self.initial_states:
            innermosts = []
            trans_from_initial = [
                t for t in self.x_sampling_transitions
                if t.stateA==initial
            ]
            for t1 in trans_from_initial:
                innermosts.append(t1.interfaces[0])
            minus = paths.MinusInterfaceEnsemble(
                state_vol=initial,
                innermost_vols=innermosts
            )
            try:
                self.special_ensembles['minus'][minus] = trans_from_initial
            except KeyError:
                self.special_ensembles['minus'] = {minus : trans_from_initial}
예제 #14
0
    def build_sampling_transitions(self, transitions):
        # identify transition pairs
        for initial in self.initial_states:
            transition_pair_dict = {}
            for t1 in [t for t in transitions if t.stateA == initial]:
                reverse_trans = None
                for t2 in transitions:
                    if t2.stateA == t1.stateB and t2.stateB == t1.stateA:
                        transition_pair_dict[t1] = t2
            # TODO: speed this up with a set?
            for key in transition_pair_dict.keys():
                value = transition_pair_dict[key]
                if value in transition_pair_dict.keys():
                    del transition_pair_dict[value]
        self.transition_pairs = [(k, transition_pair_dict[k])
                                 for k in transition_pair_dict.keys()]

        all_in_pairs = reduce(list.__add__,
                              map(lambda x: list(x), self.transition_pairs))

        # build sampling transitions

        # TODO: really, I'd like to FORBID all other states (change the
        # ensemble to intersection with AllOutXEnsemble(other_states)), but
        # for now, let's accept all other states -- the key is to stop the
        # trajectory.  Forbidding all other states can be done once building
        # the movers is better separated.
        all_states = paths.join_volumes(self.initial_states +
                                        self.final_states)
        self.transition_to_sampling = {}
        for transition in transitions:
            stateA = transition.stateA
            stateB = transition.stateB
            if transition not in all_in_pairs:
                sample_trans = paths.TISTransition(
                    stateA=stateA,
                    stateB=all_states,
                    interfaces=transition.interfaces,
                    orderparameter=transition.orderparameter)
            else:
                sample_trans = paths.TISTransition(
                    stateA=stateA,
                    stateB=all_states,
                    interfaces=transition.interfaces[:-1],
                    orderparameter=transition.orderparameter)
            sample_trans.named("Sampling " + str(stateA) + "->" + str(stateB))
            self.transition_to_sampling[transition] = sample_trans
        self.x_sampling_transitions = self.transition_to_sampling.values()

        # build non-transition interfaces

        # combining the MS-outer interfaces
        for pair in self.transition_pairs:
            this_outer = paths.ensemble.join_ensembles(
                [pair[0].ensembles[-1], pair[1].ensembles[-1]])
            s_pair = [self.transition_to_sampling[p] for p in pair]
            try:
                self.special_ensembles['ms_outer'][this_outer] = list(s_pair)
            except KeyError:
                self.special_ensembles['ms_outer'] = {this_outer: list(s_pair)}

        # combining the minus interfaces
        for initial in self.initial_states:
            innermosts = []
            trans_from_initial = [
                t for t in self.x_sampling_transitions if t.stateA == initial
            ]
            for t1 in trans_from_initial:
                innermosts.append(t1.interfaces[0])
            minus = paths.MinusInterfaceEnsemble(state_vol=initial,
                                                 innermost_vols=innermosts)
            try:
                self.special_ensembles['minus'][minus] = trans_from_initial
            except KeyError:
                self.special_ensembles['minus'] = {minus: trans_from_initial}