Exemplo n.º 1
0
def shooting_move_info():
    t0 = make_1d_traj([-0.1, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.1])
    t1 = make_1d_traj([-0.11, 2.1])
    t2 = make_1d_traj([5.2, 7.2, 9.2, 10.12])
    t3 = make_1d_traj([-0.13, 2.3, 5.3, 8.3])
    t4 = make_1d_traj([-0.14, 2.4, 4.4, 6.4])

    out1 = paths.Trajectory(t1 + t0[4:])
    out2 = paths.Trajectory(out1[0:3] + t2)
    out3 = paths.Trajectory(t3 + out2[5:])  # REJECT THIS
    out4 = paths.Trajectory(t4 + out2[4:])

    # for traj in [t0, out1, out2, out3, out4]:
        # print [s.xyz[0][0] for s in traj]

    # replica, full trial, shooting idx, one-way trial, direction
    moves = [
        (0, out1, 4, True, t1, -1),
        (0, out2, 2, True, t2, +1),
        (0, out3, 5, False, t3, -1),
        (0, out4, 4, True, t4, -1)
    ]
    initial_sample = paths.Sample(replica=0,
                                  trajectory=t0,
                                  ensemble=tps_ensemble)
    return initial_sample, moves
 def setup(self):
     super(TestINIT_CONDS, self).setup()
     self.traj = make_1d_traj([-0.1, 1.0, 4.4, 7.7, 10.01])
     ensemble = self.scheme.network.sampling_ensembles[0]
     self.sample_set = paths.SampleSet(
         [paths.Sample(trajectory=self.traj, replica=0, ensemble=ensemble)])
     self.other_traj = make_1d_traj([-1.0, 1.0, 100.0])
     self.other_sample_set = paths.SampleSet([
         paths.Sample(trajectory=self.other_traj,
                      replica=0,
                      ensemble=ensemble)
     ])
Exemplo n.º 3
0
 def setup(self):
     cv = paths.CoordinateFunctionCV('x', lambda x: x.xyz[0][0])
     vol_A = paths.CVDefinedVolume(cv, float("-inf"), 0.0)
     vol_B = paths.CVDefinedVolume(cv, 1.0, float("inf"))
     ensembles = [
         paths.LengthEnsemble(1).named("len1"),
         paths.LengthEnsemble(3).named("len3"),
         paths.SequentialEnsemble([
             paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_A),
             paths.AllOutXEnsemble(vol_A | vol_B),
             paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_A)
         ]).named('return'),
         paths.SequentialEnsemble([
             paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_A),
             paths.AllOutXEnsemble(vol_A | vol_B),
             paths.LengthEnsemble(1) & paths.AllInXEnsemble(vol_B)
         ]).named('transition'),
     ]
     self.ensembles = {ens.name: ens for ens in ensembles}
     self.traj_vals = [-0.1, 1.1, 0.5, -0.2, 0.1, -0.3, 0.4, 1.4, -1.0]
     self.trajectory = make_1d_traj(self.traj_vals)
     self.engine = CalvinistDynamics(self.traj_vals)
     self.satisfied_when_traj_len = {
         "len1": 1,
         "len3": 3,
         "return": 6,
         "transition": 8,
     }
     self.conditions = EnsembleSatisfiedContinueConditions(ensembles)
def test_shooting_move_force_accept(default_unidirectional_tis, accepted):
    # If the a given trial can be either accepted or rejected, then the
    # resulting change depends on the `accept` parameter of the mock move --
    # True accepts, False rejects, and None uses the default internal math.
    # Test this by trying each 25 times on a trial with a 50% acceptance
    # probability.
    # only test this with the forward shooting mover, since the logic is
    # shared with backward
    scheme = default_unidirectional_tis.scheme
    init_traj = default_unidirectional_tis.make_tis_trajectory(10)
    partial_traj = make_1d_traj([9.5] * (len(init_traj)-2) + [10.5])
    init_conds = scheme.initial_conditions_from_trajectories(init_traj)
    ensemble = scheme.network.sampling_ensembles[2]
    shooting_idx = len(init_traj) - 2

    move = MockForwardShooting(shooting_index=shooting_idx,
                               partial_traj=partial_traj,
                               accepted=accepted,
                               scheme=scheme,
                               ensemble=ensemble)

    n_attempts = 25
    changes = [move(init_conds) for _ in range(n_attempts)]
    # TODO: add assert to check that the pick probability is as expected?
    results = collections.Counter(change.accepted for change in changes)
    if accepted is not None:
        assert results[accepted] == n_attempts
        assert not accepted not in results
    else:
        assert results[True] > 0
        assert results[False] > 0
        assert results[True] + results[False] == n_attempts
Exemplo n.º 5
0
    def make_trajectory(lower, upper):
        """Make a trajectory from `lower` to `upper`.

        This makes a trajectory segment with x-values of frames spread by
        1.  For each trajectory, some random value epsilon is added (with ``0
        <= epsilon < 1``), such that the lowest value is ``lower + epsilon``
        and the highest value is ``upper + epsilon``. This is designed to
        facilitate test debugging, since all frames from the the same
        trajectory will have the same value of epsilon.

        Note that inputs here should be integers. This is very specifically
        for toy models where the boundaries are at integer values (though the
        CVs are allowed to take on arbitrary floats).

        Parameters
        ----------
        lower : int
            the lower bound x-value of the trajectory
        upper: int
            the upper bound x-value of the trajectory (NOTE: trajectories will
            cross this value, but not cross ``upper + 1``)

        Returns
        -------
        :class:`.Trajectory`
            the trajectory segment
        """
        xvals = np.array(range(lower, upper + 1)) + np.random.random()
        return make_1d_traj(xvals)
Exemplo n.º 6
0
def test_union_volume(volume_setup):
    wizard, vol = _binary_volume_test(volume_setup, UNION_VOLUME_PLUGIN)
    assert "union" in wizard.console.log_text
    traj = make_1d_traj([0.25, 0.75, 1.75])
    assert vol(traj[0])
    assert vol(traj[1])
    assert not vol(traj[2])
Exemplo n.º 7
0
def test_intersection_volume(volume_setup):
    wizard, vol = _binary_volume_test(volume_setup,
                                      INTERSECTION_VOLUME_PLUGIN)
    assert "intersection" in wizard.console.log_text
    traj = make_1d_traj([0.25, 0.75])
    assert not vol(traj[0])
    assert vol(traj[1])
    def test_build_cv_volume(self, inline, periodic):
        self.set_periodic(periodic)
        yml = self.yml.format(func=self.func[inline])
        dct = yaml.load(yml, Loader=yaml.FullLoader)
        period_min, period_max = {
            'periodic': (-np.pi, np.pi),
            'nonperiodic': (None, None)
        }[periodic]
        mock_cv = CoordinateFunctionCV(lambda s: s.xyz[0][0],
                                       period_min=period_min,
                                       period_max=period_max).named('foo')

        patch_loc = 'paths_cli.compiling.root_compiler._COMPILERS'

        if inline == 'external':
            compilers = {
                'cv': mock_compiler('cv', named_objs={'foo': mock_cv})
            }
        elif inline == 'inline':
            fake_plugin = CVCompilerPlugin(
                name="fake_type",
                parameters=[Parameter('input_data', str)],
                builder=lambda input_data: mock_cv)
            compilers = {
                'cv': mock_compiler('cv',
                                    type_dispatch={'fake_type': fake_plugin})
            }
        else:  # -no-cov-
            raise RuntimeError("Should never get here")

        with mock.patch.dict(patch_loc, compilers):
            vol = build_cv_volume(dct)

        in_state = make_1d_traj([0.5])[0]
        assert vol.collectivevariable(in_state) == 0.5
        assert vol(in_state)
        out_state = make_1d_traj([2.0])[0]
        assert vol.collectivevariable(out_state) == 2.0
        assert not vol(out_state)
        if_periodic = make_1d_traj([7.0])[0]
        assert (vol(if_periodic) == (periodic == 'periodic'))
        expected_class = {
            'nonperiodic': paths.CVDefinedVolume,
            'periodic': paths.PeriodicCVDefinedVolume
        }[periodic]
        assert isinstance(vol, expected_class)
Exemplo n.º 9
0
 def setup(self):
     self.cv = CollectiveVariable(lambda x: x.xyz[0][0])
     self.traj = make_1d_traj([1.0, 2.0, 3.0])
     ensemble = paths.LengthEnsemble(3)
     self.sample = paths.Sample(replica=0,
                                trajectory=self.traj,
                                ensemble=ensemble)
     self.snap = self.traj[0]
Exemplo n.º 10
0
 def setup(self):
     self.mytraj = make_1d_traj(coordinates=[-0.5, 0.1, 0.2, 0.3, 0.5], velocities=[1.0, 1.0, 1.0, 1.0, 1.0])
     self.dyn = CalvinistDynamics([-0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4, 0.5])
     # 0.5, 0.4, 0.3, 0.2, 0.1])
     # SampleMover.engine = self.dyn
     self.dyn.initialized = True
     self.ens = LengthEnsemble(5)
     self.gs = SampleSet(Sample(replica=0, trajectory=self.mytraj, ensemble=self.ens))
 def test_new_snapshot(self, selector_class):
     selector = selector_class()
     mytraj = make_1d_traj(
         coordinates=[-0.5, -0.4, -0.3, -0.1, 0.1, 0.2, 0.3, 0.5])
     with pytest.deprecated_call(match='new_snapshot'):
         _ = selector.probability_ratio(mytraj[1], mytraj, mytraj)
     # Reset the warning for the next class
     NEW_SNAPSHOT_SELECTOR.has_warned = False
Exemplo n.º 12
0
 def setup(self):
     self.tmpdir = tempfile.mkdtemp()
     self.storage_filename = os.path.join(self.tmpdir, "test.nc")
     self.storage = paths.Storage(self.storage_filename, mode='w')
     snap = make_1d_traj([1])[0]
     self.storage.save(snap)
     self.cv_x = paths.CoordinateFunctionCV("x", lambda s: s.xyz[0][0])
     self.cv_y = paths.CoordinateFunctionCV("y", lambda s: s.xyz[0][1])
     self.storage.save([self.cv_x, self.cv_y])
Exemplo n.º 13
0
 def setup(self):
     self.mytraj = make_1d_traj(coordinates=[-0.5, 0.1, 0.2, 0.3, 0.5],
                                velocities=[1.0, 1.0, 1.0, 1.0, 1.0])
     self.dyn = CalvinistDynamics(
         [-0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4, 0.5])
     self.dyn.initialized = True
     self.ens = LengthEnsemble(5)
     self.gs = SampleSet(
         Sample(replica=0, trajectory=self.mytraj, ensemble=self.ens))
Exemplo n.º 14
0
def test_coordinate(inputs):
    wizard = mock_wizard(inputs)
    cv = COORDINATE_CV(wizard)
    traj = make_1d_traj([5.0])
    assert cv(traj[0]) == 5.0
    if 'foo' in inputs:
        assert "I can't make an atom index" in wizard.console.log_text
    if 'q' in inputs:
        assert "Please select one of" in wizard.console.log_text
Exemplo n.º 15
0
 def test_f(self):
     mytraj = make_1d_traj(coordinates=[-0.5, -0.4, -0.3, -0.1,
                                        0.1, 0.2, 0.3, 0.5])
     expected_idx = 4
     idx = self.sel.pick(mytraj)
     frame = mytraj[idx]
     assert_equal(self.sel.f(frame, mytraj), 1.0)
     for idx1, frame in enumerate(mytraj):
         if (idx1 != expected_idx):
             assert_equal(self.sel.f(frame, mytraj), 0.0)
Exemplo n.º 16
0
 def test_f(self):
     mytraj = make_1d_traj(coordinates=[-0.5, -0.4, -0.3, -0.1,
                                        0.1, 0.2, 0.3, 0.5])
     expected_idx = 4
     idx = self.sel.pick(mytraj)
     frame = mytraj[idx]
     assert self.sel.f(frame, mytraj) == 1.0
     for idx1, frame in enumerate(mytraj):
         if (idx1 != expected_idx):
             assert self.sel.f(frame, mytraj) == 0.0
def test_build_gaussian_selector(cv_and_states):
    cv, _, _ = cv_and_states
    dct = {'cv': 'x', 'mean': 1.0, 'stddev': 2.0}
    compiler = {'cv': mock_compiler('cv', named_objs={'x': cv})}
    with patch.dict(_COMPILERS_LOC, compiler):
        sel = build_gaussian_selector(dct)

    assert isinstance(sel, paths.GaussianBiasSelector)
    traj = make_1d_traj([1.0, 1.0, 1.0])
    assert sel.f(traj[1], traj) == 1.0
Exemplo n.º 18
0
def test_snapshot_registration_info():
    snapshot = make_1d_traj([0.0])[0]
    schema, class_info_list = snapshot_registration_info(snapshot, 3)
    expected_schema = {'snapshot3': TOY_SCHEMA['snapshot']}
    assert schema == expected_schema
    assert len(class_info_list) == 1
    info = class_info_list[0]
    assert info.table == 'snapshot3'
    assert info.lookup_result == (get_uuid(snapshot.engine),
                                  snapshot.__class__)
    assert info.cls == snapshot.__class__
Exemplo n.º 19
0
    def test_pickle_cv_with_imports(self):
        template = make_1d_traj([0.0])[0]

        def test_cv_func(snap):
            import math
            return math.ceil(snap.coordinates[0][0])

        cv = paths.FunctionCV("y", test_cv_func)
        storage = paths.Storage("myfile.nc", "w", template)
        storage.save(cv)
        storage.close()
    def test_pickle_cv_with_imports(self):
        template = make_1d_traj([0.0])[0]

        def test_cv_func(snap):
            import math
            return math.ceil(snap.coordinates[0][0])

        cv = paths.FunctionCV("y", test_cv_func)
        storage = paths.Storage("myfile.nc", "w", template)
        storage.save(cv)
        storage.close()
 def setup(self):
     self.cv = paths.FunctionCV("x", lambda x: x.xyz[0][0])
     vol_A = paths.CVDefinedVolume(self.cv, 0.0, 1.0).named("A")
     vol_B = paths.CVDefinedVolume(self.cv, 2.0, 3.0).named("B")
     vol_C = paths.CVDefinedVolume(self.cv, 4.0, 5.0).named("C")
     vol_D = paths.CVDefinedVolume(self.cv, 6.0, 7.0).named("D")
     self.states = [vol_A, vol_B, vol_C, vol_D]
     self.ensemble = VisitAllStatesEnsemble(self.states, progress='silent')
     sequence = [-0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5]
     self.state_seq = [[], [vol_A], [], [vol_B], [], [vol_C], [], [vol_D],
                       []]
     self.traj = make_1d_traj(sequence)
Exemplo n.º 22
0
def test_negated_volume(volume_setup):
    init_vol, _ = volume_setup
    traj = make_1d_traj([0.5, 1.5])
    assert init_vol(traj[0])
    assert not init_vol(traj[1])
    wizard = mock_wizard([])
    mock_vol = mock.Mock(return_value=init_vol)
    patch_loc = 'paths_cli.wizard.volumes.VOLUMES_PLUGIN'
    with mock.patch(patch_loc, new=mock_vol):
        vol = NEGATED_VOLUME_PLUGIN(wizard)

    assert "not in" in wizard.console.log_text
    assert not vol(traj[0])
    assert vol(traj[1])
 def test_probability_ratio_modified_coordinates(self, new_coord, expected):
     # Test if probability ratio still works when coordinates are modified
     mytraj = make_1d_traj(
         coordinates=[-0.5, -0.4, -0.3, -0.1, 0.1, 0.2, 0.3, 0.5])
     idx = self.sel.pick(mytraj)
     frame = mytraj[idx]
     # Alter 0.1 to 0.11 and replace the original snapshot with the modded
     # one
     mod_frame = frame.copy_with_replacement(coordinates=[[new_coord]])
     mod_traj = mytraj[:idx]
     mod_traj += paths.Trajectory([mod_frame])
     mod_traj += mytraj[idx + 1:]
     prob = self.sel.probability_ratio(frame, mytraj, mod_traj, mod_frame)
     assert prob == expected
Exemplo n.º 24
0
def shooting_move_info():
    t0 = make_1d_traj(
        [-0.1, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.1])
    t1 = make_1d_traj([-0.11, 2.1])
    t2 = make_1d_traj([5.2, 7.2, 9.2, 10.12])
    t3 = make_1d_traj([-0.13, 2.3, 5.3, 8.3])
    t4 = make_1d_traj([-0.14, 2.4, 4.4, 6.4])

    out1 = paths.Trajectory(t1 + t0[4:])
    out2 = paths.Trajectory(out1[0:3] + t2)
    out3 = paths.Trajectory(t3 + out2[5:])  # REJECT THIS
    out4 = paths.Trajectory(t4 + out2[4:])

    # for traj in [t0, out1, out2, out3, out4]:
    # print [s.xyz[0][0] for s in traj]

    # replica, full trial, shooting idx, one-way trial, direction
    moves = [(0, out1, 4, True, t1, -1), (0, out2, 2, True, t2, +1),
             (0, out3, 5, False, t3, -1), (0, out4, 4, True, t4, -1)]
    initial_sample = paths.Sample(replica=0,
                                  trajectory=t0,
                                  ensemble=tps_ensemble)
    return initial_sample, moves
Exemplo n.º 25
0
def test_cv_defined_volume(periodic):
    if periodic:
        min_ = 0.0
        max_ = 1.0
        cv = CoordinateFunctionCV(
            lambda snap: snap.xyz[0][0],
            period_min=min_, period_max=max_
        ).named('x')
        inputs = ['x', '0.75', '1.25']
        in_state = make_1d_traj([0.2, 0.8])
        out_state = make_1d_traj([0.5])
    else:
        cv = CoordinateFunctionCV(lambda snap: snap.xyz[0][0]).named('x')
        inputs = ['x', '0.0', '1.0']
        in_state = make_1d_traj([0.5])
        out_state = make_1d_traj([-0.1, 1.1])
    wizard = mock_wizard(inputs)
    wizard.cvs[cv.name] = cv
    vol = CV_DEFINED_VOLUME_PLUGIN(wizard)
    assert "interval" in wizard.console.log_text
    for snap in in_state:
        assert vol(snap)
    for snap in out_state:
        assert not vol(snap)
Exemplo n.º 26
0
    def setup(self):
        class RunOnceFunction(object):
            def __init__(self):
                self.previously_seen = set([])

            def __call__(self, snap):
                if snap in self.previously_seen:  # -no-cov-
                    # this is only covered if an error occurs
                    raise AssertionError("Second CV eval for " + str(snap))
                self.previously_seen.update({snap})
                return snap.xyz[0][0]

        self.cv = paths.FunctionCV("test", RunOnceFunction())
        traj = make_1d_traj([2, 1])
        self.snap = traj[0]
        self.other_snap = traj[1]
 def test_can_append_new_trajectory(self, strict, trusted):
     can_append = {False: self.ensemble.can_append,
                   True: self.ensemble.strict_can_append}[strict]
     my_traj = self._run_trajectory(can_append, trusted)
     report = self.ensemble.progress_report(my_traj)
     steps, found, looking = extract_info_from_default_report(report)
     assert steps == 7
     assert found == {'A','B','C','D'}
     assert looking == {}
     new_traj = make_1d_traj([-0.6])
     assert can_append(new_traj, trusted=trusted)
     report = self.ensemble.progress_report(new_traj)
     steps, found, looking = extract_info_from_default_report(report)
     assert steps == 0
     assert found == {}
     assert looking == {'A','B','C','D'}
Exemplo n.º 28
0
    def setup(self):
        # On using side_effect: https://stackoverflow.com/a/16162114
        mock_func = mock.MagicMock(side_effect=lambda s: s.xyz[0][0])
        self.func = CoordinateFunctionCV(mock_func)
        values = [1.0, 2.0, 3.0]
        traj = make_1d_traj(values)
        self.inputs = {'traj': traj.reversed, 'snap': traj[0].reversed}
        self.expected = {'traj': list(reversed(values)), 'snap': values[0]}
        _ = self.func(traj)  # run once to cache initial results
        mock_func.reset_mock()

        backend = MockBackend()
        backend.register_storable_function(get_uuid(self.func), 'float')
        self.storage = mock.NonCallableMock(backend=backend)
        self.storage._sf_handler = StorageFunctionHandler(self.storage)
        self.storage._sf_handler.register_function(self.func)
        self.storage._sf_handler.update_cache(self.func.local_cache)
Exemplo n.º 29
0
    def test_precompute_cvs_and_inputs(self, cvs):
        with tempfile.TemporaryDirectory() as tmpdir:
            storage = paths.Storage(os.path.join(tmpdir, "test.nc"), mode='w')
            traj = make_1d_traj(list(range(10)))
            cv = paths.FunctionCV("test", lambda s: s.xyz[0][0])
            storage.save(traj)
            storage.save(cv)

            if cvs is not None:
                cvs = [storage.cvs[cv] for cv in cvs]

            precompute_func, blocks = precompute_cvs_func_and_inputs(
                input_storage=storage, cvs=cvs, blocksize=2)
            assert len(blocks) == 5
            for block in blocks:
                assert len(block) == 2

            # smoke test: only effect should be caching results
            precompute_func(blocks[0])
    def test_build_combo_volume(self, combo, inline):
        vol_A, yaml_A, desc_A = self._vol_and_yaml(0.0, 0.55, "A")
        vol_B, yaml_B, desc_B = self._vol_and_yaml(0.45, 1.0, "B")
        if inline:
            named_volumes_dict = {}
            descriptions = {}
            subvol_yaml = ['  ' + line for line in yaml_A + yaml_B]
        else:
            named_volumes_dict = {v.name: v for v in [vol_A, vol_B]}
            descriptions = {"A": desc_A, "B": desc_B}
            subvol_yaml = ['  - A', '  - B']

        yml = "\n".join([f"type: {combo}", "name: bar", "subvolumes:"] +
                        subvol_yaml)

        combo_class = {
            'union': paths.UnionVolume,
            'intersection': paths.IntersectionVolume
        }[combo]
        builder = {
            'union': build_union_volume,
            'intersection': build_intersection_volume
        }[combo]

        true_vol = combo_class(vol_A, vol_B)
        dct = yaml.load(yml, yaml.FullLoader)
        compiler = {
            'cv':
            mock_compiler('cv', named_objs={'foo': self.cv}),
            'volume':
            mock_compiler('volume',
                          type_dispatch={'cv-volume': build_cv_volume},
                          named_objs=named_volumes_dict),
        }
        with mock.patch.dict('paths_cli.compiling.root_compiler._COMPILERS',
                             compiler):
            vol = builder(dct)

        traj = make_1d_traj([0.5, 2.0, 0.2])
        assert vol(traj[0])
        assert not vol(traj[1])
        assert vol(traj[2]) == (combo == 'union')
def test_APPEND_FILE(ext):
    stored_functions = pre_monkey_patch()
    tempdir = tempfile.mkdtemp()
    filename = os.path.join(tempdir, "test_append_file." + ext)
    assert not os.path.exists(filename)
    storage = APPEND_FILE.get(filename)
    # print(storage)  # potentially useful debug; keep
    assert os.path.exists(filename)
    traj = make_1d_traj([0.0, 1.0])
    storage.tags['first_save'] = traj[0]
    storage.close()
    storage = APPEND_FILE.get(filename)
    assert storage.tags['first_save'] == traj[0]
    storage.tags['second_save'] = traj[1]
    storage.close()
    storage = APPEND_FILE.get(filename)
    assert len(storage.tags) == 2
    storage.close()
    os.remove(filename)
    os.rmdir(tempdir)
    undo_monkey_patch(stored_functions)
 def load_trajectory(self, file_name):
     f = open(os.path.join(self.test_dir, file_name), "r")
     traj_list = [float(line) for line in f]
     return make_1d_traj(traj_list)
 def setup(self):
     super(TestINIT_SNAP, self).setup()
     traj = make_1d_traj([1.0, 2.0])
     self.other_snap = traj[0]
     self.init_snap = traj[1]
 def setup(self):
     super(TestMULTI_TAG, self).setup()
     self.obj = make_1d_traj([1.0, 2.0, 3.0])
     self.get_arg = {'name': ['traj']}
Exemplo n.º 35
0
 def test_pick(self):
     mytraj = make_1d_traj(coordinates=[-0.5, -0.4, -0.3, -0.1,
                                        0.1, 0.2, 0.3, 0.5])
     assert_equal(self.sel.pick(mytraj), 4)
Exemplo n.º 36
0
 def test_all_in_interface(self):
     mytraj = make_1d_traj(coordinates=[-0.5, -0.4, -0.3, -0.1,
                                        -0.1, -0.2, -0.3])
     self.sel.pick(mytraj)
Exemplo n.º 37
0
 def test_sum_bias(self):
     mytraj = make_1d_traj(coordinates=[-0.5, 0.1, 0.2, 0.3, 0.5])
     assert_equal(self.sel.sum_bias(mytraj), 1.0)
Exemplo n.º 38
0
 def test_storable_function_integration(self):
     snap = make_1d_traj([5.0])[0]
     sf = StorableFunction(self.func, func_config=self.config)
     assert sf(snap) == 5.0
     np.testing.assert_array_equal(sf([snap]), np.array([5.0]))
Exemplo n.º 39
0
 def test_pickle_external_cv(self):
     template = make_1d_traj([0.0])[0]
     cv = paths.FunctionCV("x", lambda snap: snap.coordinates[0][0])
     storage = paths.Storage("myfile.nc", "w", template)
     storage.save(cv)
     storage.close()