Exemple #1
0
def test_mcmc_algorithm_1_2x2_elber():
    """
    Test a simple 2x2 Elber system to ensure that the correct matrices
    are generated and sampled. Optionally generate a plot showing this.
    """
    max_x = 3.0 * 12.0 / 500.0
    max_y = 3.0 * 30.0 / 150.0
    N = np.array([[0, 12], [30, 0]])
    t = np.array([[500],[150]])
    R = np.array([[500], [150]])
    model = base.Model()
    model.num_milestones = 2
    data_sample = common_analyze.Data_sample(model)
    data_sample.N_ij = N
    data_sample.R_i = t
    data_sample.compute_rate_matrix()
    Q = data_sample.Q
    assert Q[0,0] == -12.0 / 500.0
    assert Q[0,1] == 12.0 / 500.0
    assert Q[1,0] == 30.0 / 150.0
    assert Q[1,1] == -30.0 / 150.0
    algorithm = markov_chain_monte_carlo\
            .irreversible_stochastic_matrix_algorithm_sample
    mcmc_algorithm_any_2x2_common(algorithm, Q, N, R, max_x, max_y, 
                                       make_plot=False)
    
    return
def test_Data_sample_calculate_kinetics(toy_mmvt_model):
    data_sample = common_analyze.Data_sample(toy_mmvt_model)
    fill_out_simple_statistics(toy_mmvt_model, data_sample)
    data_sample.calculate_thermodynamics()
    data_sample.calculate_kinetics()
    assert data_sample.MFPTs is not None
    assert data_sample.k_off is not None
    return
def test_Data_sample_calculate_thermodynamics(toy_mmvt_model):
    data_sample = common_analyze.Data_sample(toy_mmvt_model)
    fill_out_simple_statistics(toy_mmvt_model, data_sample)
    data_sample.calculate_thermodynamics()
    # assert all values of p_i are equal
    assert np.all(np.isclose(data_sample.p_i, data_sample.p_i[0]))
    assert np.all(np.isclose(data_sample.free_energy_profile, 0.0))
    return
def test_Data_sample_compute_rate_matrix(toy_mmvt_model):
    data_sample = common_analyze.Data_sample(toy_mmvt_model)
    n = toy_mmvt_model.num_milestones
    data_sample.N_ij = np.zeros((n, n))
    data_sample.R_i = np.zeros(n)
    for i in range(n):
        data_sample.R_i[i] = 0.5
        if i > 0:
            data_sample.N_ij[i, i - 1] = 10
        if i < n - 1:
            data_sample.N_ij[i, i + 1] = 10

    data_sample.compute_rate_matrix()
    for i in range(n):
        if i > 0:
            assert data_sample.Q[i, i - 1] == 10 / 0.5
        else:
            assert data_sample.K[i, i + 1] == 1.0

        if i < n - 1:
            assert data_sample.Q[i, i + 1] == 10 / 0.5
        else:
            assert data_sample.K[i, i - 1] == 1.0

        if (i > 0) and (i < n - 1):
            assert data_sample.Q[i, i] == -20 / 0.5
            assert data_sample.K[i, i + 1] == 0.5
            assert data_sample.K[i, i - 1] == 0.5

        else:
            assert data_sample.Q[i, i] == -10 / 0.5

        assert data_sample.K[i, i] == 0.0
        for j in range(n):
            if (j == i) or (j == i - 1) or (j == i + 1):
                continue
            else:
                assert data_sample.Q[i, j] == 0.0
                assert data_sample.K[i, j] == 0.0
    return
Exemple #5
0
def test_analyze_bd_only(host_guest_mmvt_model):
    """
    Test function analyze_bd_only(). This one also tests 
    get_bd_transition_counts().
    """
    test_bd_results_filename = os.path.join(
        TEST_DIRECTORY, "data/sample_bd_results_file2.xml")
    b_surface_directory = os.path.join(host_guest_mmvt_model.anchor_rootdir,
                                       "b_surface")
    b_surface_results_file = os.path.join(b_surface_directory, "results1.xml")
    data_sample = common_analyze.Data_sample(host_guest_mmvt_model)
    copyfile(test_bd_results_filename, b_surface_results_file)
    common_converge.analyze_bd_only(host_guest_mmvt_model, data_sample)
    assert len(data_sample.bd_transition_counts) == 1
    expected_counts_b_surface = {
        "total": 100000,
        "escaped": 54070,
        12: 65239,
        11: 45930,
        "stuck": 0
    }
    counts_b_surface = data_sample.bd_transition_counts["b_surface"]
    compare_dicts(counts_b_surface, expected_counts_b_surface)
    return
def test_Data_sample_parse_browndye_results(host_guest_mmvt_model):
    test_bd_results_filename = os.path.join(
        TEST_DIRECTORY, "data/sample_bd_results_file2.xml")
    b_surface_directory = os.path.join(host_guest_mmvt_model.anchor_rootdir,
                                       "b_surface")
    b_surface_results_file = os.path.join(b_surface_directory, "results1.xml")
    data_sample = common_analyze.Data_sample(host_guest_mmvt_model)
    copyfile(test_bd_results_filename, b_surface_results_file)
    data_sample.parse_browndye_results()
    assert len(data_sample.bd_transition_counts) == 2
    expected_counts_b_surface = {
        "total": 100000,
        "escaped": 54070,
        12: 65239,
        11: 45930,
        "stuck": 0
    }
    counts_b_surface = data_sample.bd_transition_counts["b_surface"]
    compare_dicts(counts_b_surface, expected_counts_b_surface)
    expected_counts_bd_milestone0 = {
        "total": 65239,
        "escaped": 65239 - 45930,
        11: 45930
    }
    counts_bd_milestone0 = data_sample.bd_transition_counts[0]
    compare_dicts(counts_bd_milestone0, expected_counts_bd_milestone0)

    expected_b_surface_probabilities = {
        "total": 1.0,
        "escaped": 54070 / 100000,
        12: 65239 / 100000,
        11: 45930 / 100000,
        "stuck": 0.0
    }
    b_surface_probabilities \
        = data_sample.bd_transition_probabilities["b_surface"]
    compare_dicts(b_surface_probabilities, expected_b_surface_probabilities)

    expected_probabilities_bd_milestone0 = {
        "total": 1.0,
        "escaped": (65239 - 45930) / 65239,
        11: 45930 / 65239
    }
    probabilities_bd_milestone0 \
        = data_sample.bd_transition_probabilities[0]
    compare_dicts(probabilities_bd_milestone0,
                  expected_probabilities_bd_milestone0)

    k_on = data_sample.b_surface_k_ons_src["total"]
    expected_k_ons = {
        "total": k_on,
        "escaped": k_on * 54070 / 100000,
        "stuck": 0.0,
        12: k_on * 65239 / 100000,
        11: k_on * 45930 / 100000
    }
    k_ons = data_sample.b_surface_k_ons_src
    compare_dicts(expected_k_ons, k_ons)
    k_on_err = data_sample.b_surface_b_surface_k_on_errors_src
    expected_k_ons_err = {
        "total": k_on / np.sqrt(100000 - 1),
        "escaped": k_on * (54070 / 100000) / np.sqrt(54070 - 1),
        "stuck": 1e99,
        12: k_on * (65239 / 100000) / np.sqrt(65239 - 1),
        11: k_on * (45930 / 100000) / np.sqrt(45930 - 1)
    }
    compare_dicts(k_on_err, expected_k_ons_err)
    return