def __init__(self, transition, snapshot, storage=None, engine=None, extra_interfaces=None, forbidden_states=None): super(FullBootstrapping, self).__init__(storage, engine) if extra_interfaces is None: extra_interfaces = list() if forbidden_states is None: forbidden_states = list() interface0 = transition.interfaces[0] ensemble0 = transition.ensembles[0] state = transition.stateA self.state = state self.first_traj_ensemble = paths.SequentialEnsemble([ paths.OptionalEnsemble(paths.AllOutXEnsemble(state)), paths.AllInXEnsemble(state), paths.OptionalEnsemble( paths.AllOutXEnsemble(state) & paths.AllInXEnsemble(interface0) ), paths.OptionalEnsemble(paths.AllInXEnsemble(interface0)), paths.AllOutXEnsemble(interface0), paths.OptionalEnsemble(paths.AllOutXEnsemble(state)), paths.SingleFrameEnsemble(paths.AllInXEnsemble(state)) ]) & paths.AllOutXEnsemble(paths.join_volumes(forbidden_states)) self.extra_ensembles = [paths.TISEnsemble(transition.stateA, transition.stateB, iface, transition.orderparameter) for iface in extra_interfaces ] self.transition_shooters = [ paths.OneWayShootingMover(selector=paths.UniformSelector(), ensemble=ens) for ens in transition.ensembles ] self.extra_shooters = [ paths.OneWayShootingMover(selector=paths.UniformSelector(), ensemble=ens) for ens in self.extra_ensembles ] self.snapshot = snapshot.copy() self.ensemble0 = ensemble0 self.all_ensembles = transition.ensembles + self.extra_ensembles self.n_ensembles = len(self.all_ensembles) self.error_max_rounds = True
def make_ensemble(self, transitions, forbidden=None): """ Create the ensemble for this MS outer interface. Parameters ---------- transitions : list of :class:`.TISTransition` possible transitions of relevance forbidden : list of :class:`.Volume` or None (optional) volumes to disallow from the ensemble (e.g., other states that should cause the trajectory to stop) Returns ------- :class:`.Ensemble` the union of the TISEnsembles for each volume of the MS outer interface """ if forbidden is None: ensemble_to_intersect = paths.FullEnsemble() else: try: _ = len(forbidden) except TypeError: forbidden = [forbidden] forbidden_vol = paths.join_volumes(forbidden) ensemble_to_intersect = paths.AllOutXEnsemble(forbidden_vol) # TODO: maybe we should crash if given transitions aren't relevant? relevant_transitions = self.relevant_transitions(transitions) outer_ensembles = [] for trans in relevant_transitions: initial = trans.stateA final = trans.stateB volume = self.volume_for_interface_set(trans.interfaces) # TODO: move following to a logger.debug #print initial.name, final.name,\ #self.lambda_for_interface_set(trans.interfaces) outer_ensembles.append(ensemble_to_intersect & paths.TISEnsemble(initial, final, volume)) return paths.join_ensembles(outer_ensembles)
def _build_ensembles(self, stateA, stateB, interfaces, orderparameter): try: cv = interfaces.cv except AttributeError: cv = orderparameter if cv is None: # in case interface.cv is None and orderparameter is not None cv = orderparameter try: cv_max = interfaces.cv_max except AttributeError: cv_max = None try: lambdas = [interfaces.get_lambda(iface_vol) for iface_vol in interfaces] except AttributeError: lambdas = [None] * len(interfaces) self.ensembles = [ paths.TISEnsemble( initial_states=stateA, final_states=stateB, interface=iface_vol, orderparameter=cv, cv_max=cv_max, lambda_i=lambda_i ) for (iface_vol, lambda_i) in zip(interfaces, lambdas) ] #self.ensembles = paths.EnsembleFactory.TISEnsembleSet( #stateA, stateB, self.interfaces, orderparameter #) for ensemble in self.ensembles: ensemble.named(self.name + " " + str(self.ensembles.index(ensemble)))
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 4-tuples See description in __init__. """ states, interfaces, orderparams = zip(*trans_info) # 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 outer_ensembles = [] self.states = states for (state, ifaces, op) in trans_info: 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[:-1], 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]} outer_ensemble = paths.TISEnsemble(initial_states=state, final_states=all_states, interface=ifaces[-1]) outer_ensemble.named("outer " + str(state)) outer_ensembles.append(outer_ensemble) ms_outer = paths.ensemble.join_ensembles(outer_ensembles) transition_outers = self.from_state.values() try: self.special_ensembles['ms_outer'][ms_outer] = transition_outers except KeyError: self.special_ensembles['ms_outer'] = {ms_outer: transition_outers}