def test_multiple_initial_snapshots(self):
     snap1 = toys.Snapshot(coordinates=np.array([[0.1]]),
                           velocities=np.array([[-1.0]]),
                           engine=self.engine)
     sim = CommittorSimulation(storage=self.storage,
                               engine=self.engine,
                               states=[self.left, self.right],
                               randomizer=paths.NoModification(),
                               initial_snapshots=[self.snap0, snap1])
     sim.run(10)
     assert_equal(len(self.storage.steps), 20)
     snap0_coords = self.snap0.coordinates.tolist()
     snap1_coords = snap1.coordinates.tolist()
     count = {self.snap0: 0, snap1: 0}
     for step in self.storage.steps:
         shooting_snap = step.change.canonical.details.shooting_snapshot
         if shooting_snap.coordinates.tolist() == snap0_coords:
             mysnap = self.snap0
         elif shooting_snap.coordinates.tolist() == snap1_coords:
             mysnap = snap1
         else:
             msg = "Shooting snapshot matches neither test snapshot"
             raise AssertionError(msg)
         count[mysnap] += 1
     assert_equal(count, {self.snap0: 10, snap1: 10})
    def setup(self):
        # As a test system, let's use 1D motion on a flat potential. If the
        # velocity is positive, you right the state on the right. If it is
        # negative, you hit the state on the left.
        pes = toys.LinearSlope(m=[0.0], c=[0.0])  # flat line
        topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes)
        integrator = toys.LeapfrogVerletIntegrator(0.1)
        options = {
            'integ': integrator,
            'n_frames_max': 100000,
            'n_steps_per_frame': 5
        }
        self.engine = toys.Engine(options=options, topology=topology)
        self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]),
                                   velocities=np.array([[1.0]]),
                                   engine=self.engine)
        cv = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0])
        starting_volume = paths.CVDefinedVolume(cv, -0.01, 0.01)
        forward_ensemble = paths.LengthEnsemble(5)
        backward_ensemble = paths.LengthEnsemble(3)
        randomizer = paths.NoModification()

        self.filename = data_filename("shoot_from_snaps.nc")
        self.storage = paths.Storage(self.filename, 'w')
        self.simulation = ShootFromSnapshotsSimulation(
            storage=self.storage,
            engine=self.engine,
            starting_volume=starting_volume,
            forward_ensemble=forward_ensemble,
            backward_ensemble=backward_ensemble,
            randomizer=randomizer,
            initial_snapshots=self.snap0)
        self.simulation.output_stream = open(os.devnull, "w")
    def setup(self):
        # As a test system, let's use 1D motion on a flat potential. If the
        # velocity is positive, you right the state on the right. If it is
        # negative, you hit the state on the left.
        pes = toys.LinearSlope(m=[0.0], c=[0.0]) # flat line
        topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes)
        integrator = toys.LeapfrogVerletIntegrator(0.1)
        options = {
            'integ': integrator,
            'n_frames_max': 100000,
            'n_steps_per_frame': 5
        }
        self.engine = toys.Engine(options=options, topology=topology)
        self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]),
                                   velocities=np.array([[1.0]]),
                                   engine=self.engine)
        cv = paths.FunctionCV("Id", lambda snap : snap.coordinates[0][0])
        self.left = paths.CVDefinedVolume(cv, float("-inf"), -1.0)
        self.right = paths.CVDefinedVolume(cv, 1.0, float("inf"))
        self.state_labels = {"Left" : self.left,
                             "Right" : self.right,
                             "None" : ~(self.left | self.right)}

        randomizer = paths.NoModification()

        self.filename = data_filename("committor_test.nc")
        self.storage = paths.Storage(self.filename, mode="w")
        self.storage.save(self.snap0)

        self.simulation = CommittorSimulation(storage=self.storage,
                                              engine=self.engine,
                                              states=[self.left, self.right],
                                              randomizer=randomizer,
                                              initial_snapshots=self.snap0)
        self.simulation.output_stream = open(os.devnull, 'w')
Beispiel #4
0
    def setup(self):
        # PES is one-dimensional linear slope (y(x) = x)
        pes = toys.LinearSlope(m=[-1.0], c=[0.0])
        # one particle with mass 1.0
        topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes)
        integrator = toys.LeapfrogVerletIntegrator(0.02)
        options = {
            'integ': integrator,
            'n_frames_max': 1000,
            'n_steps_per_frame': 5
        }
        self.engine = toys.Engine(options=options, topology=topology)
        # test uses three snapshots with different velocities
        # 0: direction ok, velocity too low => falls back to dividing surface
        # 1: wrong direction => backward shot towards B
        # 2: direction ok, velocity high enough => successfull new trajectory
        self.initial_snapshots = [
            toys.Snapshot(coordinates=np.array([[0.0]]),
                          velocities=np.array([[1.0]]),
                          engine=self.engine),
            toys.Snapshot(coordinates=np.array([[0.0]]),
                          velocities=np.array([[-1.0]]),
                          engine=self.engine),
            toys.Snapshot(coordinates=np.array([[0.0]]),
                          velocities=np.array([[2.0]]),
                          engine=self.engine)
        ]
        # reaction coordinate is just x coordinate
        rc = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0])
        # state A: [-inf, -1]
        self.state_A = paths.CVDefinedVolume(rc, float("-inf"), -1.0)
        # area between A and dividing surface: [-1, 0]
        self.towards_A = paths.CVDefinedVolume(rc, -1.0, 0.0)
        # state B: [1, inf]
        self.state_B = paths.CVDefinedVolume(rc, 1.0, float("inf"))
        # define state labels
        self.state_labels = {
            "A": self.state_A,
            "B": self.state_B,
            "ToA": self.towards_A,
            "None": ~(self.state_A | self.state_B | self.towards_A)
        }

        # velocities are not randomized
        randomizer = paths.NoModification()

        self.filename = data_filename("rf_test.nc")
        self.storage = paths.Storage(self.filename, mode="w")
        self.storage.save(self.initial_snapshots)

        self.simulation = ReactiveFluxSimulation(
            storage=self.storage,
            engine=self.engine,
            states=[self.state_A, self.state_B],
            randomizer=randomizer,
            initial_snapshots=self.initial_snapshots,
            rc=rc)
        self.simulation.output_stream = open(os.devnull, 'w')
    def setup(self):
        # PES is one-dimensional zero function (y(x) = 0)
        pes = toys.LinearSlope(m=[0.0], c=[0.0])
        topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes)
        integrator = toys.LeapfrogVerletIntegrator(0.02)
        options = {
            'integ' : integrator,
            'n_frames_max' : 1000,
            'n_steps_per_frame' : 1
        }
        self.engine = toys.Engine(options=options, topology=topology)
        # test uses snapshots with different velocities
        self.initial_snapshots = [toys.Snapshot(
                                      coordinates=np.array([[0.0]]),
                                      velocities=np.array([[1.0]]),
                                      engine=self.engine),
                                  toys.Snapshot(
                                      coordinates=np.array([[0.1]]),
                                      velocities=np.array([[-1.0]]),
                                      engine=self.engine),
                                  toys.Snapshot(
                                      coordinates=np.array([[-0.2]]),
                                      velocities=np.array([[2.0]]),
                                      engine=self.engine)]
        # trajectory length is set to 100 steps
        self.l = 100
        # reaction coordinate is just x coordinate
        rc = paths.FunctionCV("Id", lambda snap : snap.coordinates[0][0])
        # state S: [-0.5, 0.5]
        self.state_S = paths.CVDefinedVolume(rc, -0.5, 0.5)
        # define state labels
        self.state_labels = {
            "S" : self.state_S,
            "NotS" :~self.state_S}
        # velocities are not randomized
        randomizer = paths.NoModification()

        self.filename = data_filename("sshooting_test.nc")
        self.storage = paths.Storage(self.filename, mode="w")
        self.storage.save(self.initial_snapshots)

        self.simulation = SShootingSimulation(
            storage=self.storage,
            engine=self.engine,
            state_S=self.state_S,
            randomizer=randomizer,
            initial_snapshots=self.initial_snapshots,
            trajectory_length=self.l
        )
        self.simulation.output_stream = open(os.devnull, 'w')
    def setup(self):
        self.HAS_TQDM = paths.progress.HAS_TQDM
        paths.progress.HAS_TQDM = False
        # taken from the TestCommittorSimulation
        import openpathsampling.engines.toy as toys
        pes = toys.LinearSlope(m=[0.0], c=[0.0])  # flat line
        topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes)
        descriptor = peng.SnapshotDescriptor.construct(
            toys.Snapshot,
            {
                'n_atoms': 1,
                'n_spatial': 1
            }
        )
        engine = peng.NoEngine(descriptor)
        self.snap0 = toys.Snapshot(coordinates=np.array([[0.0]]),
                                   velocities=np.array([[1.0]]),
                                   engine=engine)
        self.snap1 = toys.Snapshot(coordinates=np.array([[0.1]]),
                                   velocities=np.array([[1.0]]),
                                   engine=engine)
        integrator = toys.LeapfrogVerletIntegrator(0.1)
        options = {
            'integ': integrator,
            'n_frames_max': 10000,
            'n_steps_per_frame': 5
        }
        self.engine = toys.Engine(options=options, topology=topology)
        self.cv = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0])
        self.left = paths.CVDefinedVolume(self.cv, float("-inf"), -1.0)
        self.right = paths.CVDefinedVolume(self.cv, 1.0, float("inf"))

        randomizer = paths.NoModification()
        self.filename = data_filename("shooting_analysis.nc")
        self.storage = paths.Storage(self.filename, mode="w")

        self.simulation = paths.CommittorSimulation(
            storage=self.storage,
            engine=self.engine,
            states=[self.left, self.right],
            randomizer=randomizer,
            initial_snapshots=[self.snap0, self.snap1]
        )
        self.simulation.output_stream = open(os.devnull, 'w')
        self.simulation.run(20)
        # set up the analysis object
        self.analyzer = ShootingPointAnalysis(self.storage.steps,
                                              [self.left, self.right])
 def test_backward_only_committor(self):
     sim = CommittorSimulation(storage=self.storage,
                               engine=self.engine,
                               states=[self.left, self.right],
                               randomizer=paths.NoModification(),
                               initial_snapshots=self.snap0,
                               direction=-1)
     sim.output_stream = open(os.devnull, 'w')
     sim.run(n_per_snapshot=10)
     assert_equal(len(sim.storage.steps), 10)
     for step in self.simulation.storage.steps:
         s = step.active[0]
         step.active.sanity_check()  # traj is in ensemble
         assert_equal(
             s.trajectory.summarize_by_volumes_str(self.state_labels),
             "Left-None")
         assert_equal(s.ensemble, sim.backward_ensemble)
         assert_equal(step.change.canonical.mover, sim.backward_mover)
Beispiel #8
0
    def setup(self):
        # PES is one-dimensional negative slope (y(x) = -x)
        pes = toys.LinearSlope(m=[-1.0], c=[0.0])
        topology = toys.Topology(n_spatial=1, masses=[1.0], pes=pes)
        integrator = toys.LeapfrogVerletIntegrator(0.02)
        options = {
            'integ': integrator,
            'n_frames_max': 1000,
            'n_steps_per_frame': 1
        }
        self.engine = toys.Engine(options=options, topology=topology)
        # test uses snapshots with different velocities
        # (1) does not ever reach A
        # (2) goes form A to S to B
        # (3) goes from B to S to A
        self.initial_snapshots = [
            toys.Snapshot(coordinates=np.array([[0.0]]),
                          velocities=np.array([[1.0]]),
                          engine=self.engine),
            toys.Snapshot(coordinates=np.array([[0.1]]),
                          velocities=np.array([[2.0]]),
                          engine=self.engine),
            toys.Snapshot(coordinates=np.array([[-0.2]]),
                          velocities=np.array([[-2.0]]),
                          engine=self.engine)
        ]
        # trajectory length is set to 100 steps
        self.l = 100
        # reaction coordinate is just x coordinate
        rc = paths.FunctionCV("Id", lambda snap: snap.coordinates[0][0])
        # state A: [-inf, -1]
        self.state_A = paths.CVDefinedVolume(rc, float("-inf"), -1.0)
        # state B: [1, inf]
        self.state_B = paths.CVDefinedVolume(rc, 1.0, float("inf"))
        # state S: [-0.5, 0.5]
        self.state_S = paths.CVDefinedVolume(rc, -0.5, 0.5)
        # define state labels
        self.state_labels = {
            "A": self.state_A,
            "B": self.state_B,
            "S": self.state_S,
            "None": ~(self.state_A | self.state_B | self.state_S)
        }
        # velocities are not randomized
        randomizer = paths.NoModification()

        self.filename = data_filename("sshooting_test.nc")
        self.storage = paths.Storage(self.filename, mode="w")
        self.storage.save(self.initial_snapshots)

        self.simulation = SShootingSimulation(
            storage=self.storage,
            engine=self.engine,
            state_S=self.state_S,
            randomizer=randomizer,
            initial_snapshots=self.initial_snapshots,
            trajectory_length=self.l)
        self.simulation.output_stream = open(os.devnull, 'w')
        self.simulation.run(n_per_snapshot=1)
        self.analysis = SShootingAnalysis(
            steps=self.storage.steps,
            states=[self.state_A, self.state_B, self.state_S])