Пример #1
0
    def __init__(self, storage, engine, starting_volume, forward_ensemble,
                 backward_ensemble, randomizer, initial_snapshots):
        super(ShootFromSnapshotsSimulation, self).__init__(storage)
        self.engine = engine
        # FIXME: this next line seems weird; but tests fail without it
        paths.EngineMover.default_engine = engine
        try:
            initial_snapshots = list(initial_snapshots)
        except TypeError:
            initial_snapshots = [initial_snapshots]
        self.initial_snapshots = initial_snapshots
        self.randomizer = randomizer

        self.starting_ensemble = (paths.AllInXEnsemble(starting_volume)
                                  & paths.LengthEnsemble(1))

        self.forward_ensemble = forward_ensemble
        self.backward_ensemble = backward_ensemble

        self.forward_mover = paths.ForwardExtendMover(
            ensemble=self.starting_ensemble,
            target_ensemble=self.forward_ensemble)
        self.backward_mover = paths.BackwardExtendMover(
            ensemble=self.starting_ensemble,
            target_ensemble=self.backward_ensemble)

        # subclasses will often override this
        self.mover = paths.RandomChoiceMover(
            [self.forward_mover, self.backward_mover])
    def __init__(self,
                 storage,
                 engine=None,
                 state_S=None,
                 randomizer=None,
                 initial_snapshots=None,
                 trajectory_length=None):

        # Defintion of state S (A and B are only required for analysis).
        self.state_S = state_S

        # Set forward/backward shot length.
        self.trajectory_length = trajectory_length
        l = self.trajectory_length

        # Define backward ensemble:
        # trajectory starts in S and has fixed length l.
        backward_ensemble = paths.SequentialEnsemble([
            paths.LengthEnsemble(l),
            paths.AllInXEnsemble(state_S) & paths.LengthEnsemble(1)
        ])

        # Define forward ensemble:
        # CAUTION: first trajectory is in backward ensemble,
        # then continues with fixed length l.
        forward_ensemble = paths.SequentialEnsemble([
            paths.LengthEnsemble(l),
            paths.AllInXEnsemble(state_S) & paths.LengthEnsemble(1),
            paths.LengthEnsemble(l)
        ])

        super(SShootingSimulation,
              self).__init__(storage=storage,
                             engine=engine,
                             starting_volume=state_S,
                             forward_ensemble=forward_ensemble,
                             backward_ensemble=backward_ensemble,
                             randomizer=randomizer,
                             initial_snapshots=initial_snapshots)

        # Create backward mover (starting from single point).
        self.backward_mover = paths.BackwardExtendMover(
            ensemble=self.starting_ensemble,
            target_ensemble=self.backward_ensemble)

        # Create forward mover (starting from the backward ensemble).
        self.forward_mover = paths.ForwardExtendMover(
            ensemble=self.backward_ensemble,
            target_ensemble=self.forward_ensemble)

        # Create mover combining forward and backward shooting. No condition
        # here, shots in both directions are executed in any case.
        self.mover = paths.NonCanonicalConditionalSequentialMover(
            [self.backward_mover, self.forward_mover])
    def __init__(self,
                 storage,
                 engine=None,
                 states=None,
                 randomizer=None,
                 initial_snapshots=None,
                 direction=None):
        super(CommittorSimulation, self).__init__(storage)
        self.engine = engine
        paths.EngineMover.default_engine = engine
        self.states = states
        self.randomizer = randomizer
        try:
            initial_snapshots = list(initial_snapshots)
        except TypeError:
            initial_snapshots = [initial_snapshots]
        self.initial_snapshots = initial_snapshots
        self.direction = direction

        all_state_volume = paths.join_volumes(states)

        # we should always start from a single frame not in any state
        self.starting_ensemble = (paths.AllOutXEnsemble(all_state_volume)
                                  & paths.LengthEnsemble(1))
        # shoot forward until we hit a state
        self.forward_ensemble = paths.SequentialEnsemble([
            paths.AllOutXEnsemble(all_state_volume),
            paths.AllInXEnsemble(all_state_volume) & paths.LengthEnsemble(1)
        ])
        # or shoot backward until we hit a state
        self.backward_ensemble = paths.SequentialEnsemble([
            paths.AllInXEnsemble(all_state_volume) & paths.LengthEnsemble(1),
            paths.AllOutXEnsemble(all_state_volume)
        ])

        self.forward_mover = paths.ForwardExtendMover(
            ensemble=self.starting_ensemble,
            target_ensemble=self.forward_ensemble)
        self.backward_mover = paths.BackwardExtendMover(
            ensemble=self.starting_ensemble,
            target_ensemble=self.backward_ensemble)

        if self.direction is None:
            self.mover = paths.RandomChoiceMover(
                [self.forward_mover, self.backward_mover])
        elif self.direction > 0:
            self.mover = self.forward_mover
        elif self.direction < 0:
            self.mover = self.backward_mover
Пример #4
0
    def __init__(self, storage, engine=None, states=None, randomizer=None,
                 initial_snapshots=None, rc=None):

        # state definition
        self.states = states
        state_A = states[0]
        state_B = states[1]

        # get min/max reaction coordinate of initial snapshots
        self.rc = rc
        rc_array = np.array(self.rc(initial_snapshots))
        rc_min = np.nextafter(rc_array.min(), -np.inf)
        rc_max = np.nextafter(rc_array.max(), np.inf)

        # define reaction coordinate region of initial snapshots
        # = starting_volume
        self.dividing_surface = paths.CVDefinedVolume(self.rc, rc_min, rc_max)

        # define volume between state A and the dividing surface (including A)
        self.volume_towards_A = paths.CVDefinedVolume(self.rc, -np.inf, rc_max)

        # shoot backward until we hit A but never cross the dividing surface
        backward_ensemble = paths.SequentialEnsemble([
            paths.AllInXEnsemble(state_A) & paths.LengthEnsemble(1),
            paths.AllInXEnsemble(self.volume_towards_A - state_A)
        ])

        # shoot forward until we hit state B without hitting A first
        # caution: since the mover will consist of backward and forward
        #          shoot in sequence, the starting ensemble for the forward
        #          shoot is the output of the backward shoot, i.e. a
        #          trajectory that runs from A to the dividing surface and
        #          not just a point there.
        forward_ensemble = paths.SequentialEnsemble([
            paths.AllInXEnsemble(state_A) & paths.LengthEnsemble(1),
            paths.AllOutXEnsemble(state_A | state_B),
            paths.AllInXEnsemble(state_B) & paths.LengthEnsemble(1),
        ])

        super(ReactiveFluxSimulation, self).__init__(
            storage=storage,
            engine=engine,
            starting_volume=self.dividing_surface,
            forward_ensemble=forward_ensemble,
            backward_ensemble=backward_ensemble,
            randomizer=randomizer,
            initial_snapshots=initial_snapshots
        )

        # create backward mover (starting from single point)
        self.backward_mover = paths.BackwardExtendMover(
            ensemble=self.starting_ensemble,
            target_ensemble=self.backward_ensemble
        )

        # create forward mover (starting from the backward ensemble)
        self.forward_mover = paths.ForwardExtendMover(
            ensemble=self.backward_ensemble,
            target_ensemble=self.forward_ensemble
        )

        # create mover combining forward and backward shooting,
        # abort if backward mover fails
        self.mover = paths.NonCanonicalConditionalSequentialMover([
            self.backward_mover,
            self.forward_mover
        ])