def test_MMVT_data_sample_fill_out_data_quantities(): model = make_simple_model() N_alpha_beta = {(0,1):12, (1,0):12, (1,2):12, (2,1):12, (2,3):6, (3,2):6} k_alpha_beta = {(0,1):20.0, (1,0):10.0, (1,2):10.0, (2,1):(40.0/3.0), (2,3):(20.0/3.0), (3,2):20.0} N_i_j_alpha = [{}, {(0,1):4, (1,0):4}, {(1,2):2, (2,1):2}, {}] R_i_alpha_total = [{0: 1.2}, {0: 1.2, 1:1.2}, {1: 1.2, 2:0.6}, {2: 0.6}] T_alpha_total = [1.2, 2.4, 1.8, 0.6] main_data_sample = mmvt_analyze.MMVT_data_sample( model, N_alpha_beta, k_alpha_beta, N_i_j_alpha, R_i_alpha_total, T_alpha_total) main_data_sample.calculate_pi_alpha() main_data_sample.fill_out_data_quantities() N_ij = {(0,1): 1, (1,0): 1, (1,2): 0.5, (2,1): 0.5} R_i = {0: 0.6, 1: 0.6, 2: 0.3} compare_dicts(N_ij, main_data_sample.N_ij) compare_dicts(R_i, main_data_sample.R_i) return
def test_Elber_data_sample_fill_out_data_quantities(): model = make_simple_model() N_i_j_list = [{(0,1): 4}, {(1,0): 4, (1,2): 2}, {(2,1): 2}] R_i_list = [2.4, 2.4] N_i_j_exp = {(0,1): 4, (1,0): 4, (1,2): 2} data_sample = elber_analyze.Elber_data_sample(model, N_i_j_list, R_i_list) data_sample.fill_out_data_quantities() compare_dicts(N_i_j_exp, data_sample.N_ij) assert len(R_i_list) == len(data_sample.R_i) for item1, item2 in zip(R_i_list, data_sample.R_i): assert item1 == data_sample.R_i[item2] return
def test_browndye_run_compute_rate_constant(): """ Test the function which extracts Browndye results from the b-surface simulations. """ test_bd_results_filename = os.path.join(TEST_DIRECTORY, "data/sample_bd_results_file.xml") k_ons, k_on_errors, reaction_probabilities, \ reaction_probability_errors, transition_counts \ = common_analyze.browndye_run_compute_rate_constant( "compute_rate_constant", [test_bd_results_filename], sample_error_from_normal=False) expected_k_ons = { 10: 1.18338e+09, "escaped": 2.480783458e+10, "stuck": 0, "total": 2.599121458e+10 } compare_dicts(k_ons, expected_k_ons) expected_k_on_errors = { 10: 1.7539737e+07, "escaped": 8.0298973e+07, "stuck": 1e+99, "total": 8.21918481e+7 } compare_dicts(k_on_errors, expected_k_on_errors) expected_reaction_probabilities = { 10: (4553 / 100000), "escaped": (95447 / 100000), "stuck": 0.0, "total": 1.0 } compare_dicts(reaction_probabilities, expected_reaction_probabilities) expected_reaction_probability_errors = { 10: 0.0006748333290290023, "escaped": 0.0030894659734406714, "stuck": 1e+99, "total": 0.0031622934716752666 } compare_dicts(reaction_probability_errors, expected_reaction_probability_errors) expected_transition_counts = { 10: 4553, "escaped": 95447, "stuck": 0, "total": 100000 } compare_dicts(transition_counts, expected_transition_counts) return
def test_MMVT_anchor_statistics_read_output_file_list(toy_mmvt_model): """ Test the read_output_file_list method of the MMVT_anchor_statistics object. """ stats = mmvt_analyze.MMVT_anchor_statistics(1) engine = "openmm" output_file_list = [test_output_filename] min_time = None max_time = None anchor = toy_mmvt_model.anchors[1] timestep = toy_mmvt_model.get_timestep() stats.read_output_file_list(engine, output_file_list, min_time, max_time, anchor, timestep) N_i_j_alpha_dict2 = {(1, 2): 52, (2, 1): 52} R_i_alpha_dict2 = {1: 1658.696, 2: 198.912} N_alpha_beta_dict2 = {1: 2423, 2: 98} T_alpha2 = 1954.760 k_alpha_beta_dict2 = {1: 2423/1954.760, 2: 98/1954.760} compare_dicts(N_i_j_alpha_dict2, stats.N_i_j_alpha) compare_dicts(R_i_alpha_dict2, stats.R_i_alpha_total) compare_dicts(N_alpha_beta_dict2, stats.N_alpha_beta) assert np.isclose(T_alpha2, stats.T_alpha_total) compare_dicts(k_alpha_beta_dict2, stats.k_alpha_beta) stats.print_stats() return
def test_MMVT_data_sample_fill_k_from_matrices(): model = make_simple_model() k_alpha_beta_exp = {(0,1):20.0, (1,0):10.0, (1,2):10.0, (2,1):(40.0/3.0), (2,3):(20.0/3.0), (3,2):20.0} k_alpha_beta_matrix = np.array([ [-20.0, 20.0, 0.0, 0.0], [10.0, -20.0, 10.0, 0.0], [0.0, (40.0/3.0), -(40.0/3.0)-(20.0/3.0), (20.0/3.0)], [0.0, 0.0, 20.0, -20.0]]) main_data_sample = mmvt_analyze.MMVT_data_sample( model, None, None, None, None, None) main_data_sample.fill_k_from_matrices(k_alpha_beta_matrix) compare_dicts(k_alpha_beta_exp, main_data_sample.k_alpha_beta) return
def test_Analysis_fill_out_data_samples_elber(): model = test_elber_analyze.make_simple_model() N_i_j_list = [{3: 4}, {1: 4, 3: 2}, {1: 2}] R_i_list = [2.4, 2.4, 1.2] N_i_j_list_exp = [{(0,1): 4}, {(1,0): 4, (1,2): 2}] R_i_list_exp = [2.4, 2.4] analysis = analyze.Analysis(model) for alpha in range(model.num_anchors): anchor_stats = elber_analyze.Elber_anchor_statistics(alpha) anchor_stats.N_i_j = N_i_j_list[alpha] anchor_stats.R_i_total = R_i_list[alpha] analysis.anchor_stats_list.append(anchor_stats) analysis.fill_out_data_samples_elber() for alpha in range(model.num_anchors): if model.anchors[alpha].bulkstate: continue compare_dicts(N_i_j_list_exp[alpha], analysis.main_data_sample.N_i_j_list[alpha]) assert analysis.main_data_sample.R_i_list[alpha] == R_i_list_exp[alpha] return
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
def test_Analysis_fill_out_data_samples_mmvt(): model = test_mmvt_analyze.make_simple_model() N_alpha_beta = [{1:12}, {1:12, 2:12}, {1:12, 2:6}, {1:6}] k_alpha_beta = [{1:20.0}, {1:10.0, 2:10.0}, {1:(40.0/3.0), 2:(20.0/3.0)}, {1:20.0}] N_i_j_alpha_list = [{}, {(1,2):4, (2,1):4}, {(1,2):2, (2,1):2}, {}] R_i_alpha_total_list = [{1: 1.2}, {1: 1.2, 2:1.2}, {1: 1.2, 2:0.6}, {1: 0.6}] T_alpha_total = [1.2, 2.4, 1.8, 0.6] analysis = analyze.Analysis(model) for alpha in range(model.num_anchors): anchor_stats = mmvt_analyze.MMVT_anchor_statistics(alpha) anchor_stats.N_i_j_alpha = N_i_j_alpha_list[alpha] anchor_stats.R_i_alpha_total = R_i_alpha_total_list[alpha] anchor_stats.T_alpha_total = T_alpha_total[alpha] anchor_stats.N_alpha_beta = N_alpha_beta[alpha] anchor_stats.k_alpha_beta = k_alpha_beta[alpha] analysis.anchor_stats_list.append(anchor_stats) analysis.fill_out_data_samples_mmvt() N_alpha_beta_exp = {(0,1):12, (1,0):12, (1,2):12, (2,1):12, (2,3):6, (3,2):6} k_alpha_beta_exp = {(0,1):20.0, (1,0):10.0, (1,2):10.0, (2,1):(40.0/3.0), (2,3):(20.0/3.0), (3,2):20.0} N_i_j_alpha_exp = [{}, {(0,1):4, (1,0):4}, {(1,2):2, (2,1):2}, {}] R_i_alpha_total_exp = [{0: 1.2}, {0: 1.2, 1:1.2}, {1: 1.2, 2:0.6}, {2: 0.6}] T_alpha_total_exp = [1.2, 2.4, 1.8, 0.6] compare_dicts(analysis.main_data_sample.N_alpha_beta, N_alpha_beta_exp) compare_dicts(analysis.main_data_sample.k_alpha_beta, k_alpha_beta_exp) for dict1, dict2 in zip(analysis.main_data_sample.N_i_j_alpha, N_i_j_alpha_exp): compare_dicts(dict1, dict2) for dict1, dict2 in zip(analysis.main_data_sample.R_i_alpha, R_i_alpha_total_exp): compare_dicts(dict1, dict2) for val1, val2 in zip(analysis.main_data_sample.T_alpha, T_alpha_total_exp): assert np.isclose(val1, val2) return
def test_MMVT_data_sample_fill_N_R_alpha_from_matrices(): model = make_simple_model() N_i_j_alpha_exp = [{}, {(0,1):4, (1,0):4}, {(1,2):2, (2,1):2}, {}] R_i_alpha_total_exp = [{0: 1.2}, {0: 1.2, 1:1.2}, {1: 1.2, 2:0.6}, {2: 0.6}] mmvt_Nij_alpha = [ np.array([ [0, 0, 0], [0, 0, 0], [0, 0, 0]]), np.array([ [0, 4, 0], [4, 0, 0], [0, 0, 0]]), np.array([ [0, 0, 0], [0, 0, 2], [0, 2, 0]]), np.array([ [0, 0, 0], [0, 0, 0], [0, 0, 0]])] mmvt_Ri_alpha = [ np.array([ [1.2], [0], [0]]), np.array([ [1.2], [1.2], [0]]), np.array([ [0], [1.2], [0.6]]), np.array([ [0], [0], [0.6]])] N_i_j_alpha_start = [{}, {(0,1):3, (1,0):3}, {(1,2):3, (2,1):3}, {}] R_i_alpha_total_start = [{0: 1.0}, {0: 1.0, 1:1.0}, {1: 1.0, 2:0.4}, {2: 0.4}] T_alpha_total_start = [1.2, 2.4, 1.8, 0.6] main_data_sample = mmvt_analyze.MMVT_data_sample( model, None, None, N_i_j_alpha_start, R_i_alpha_total_start, T_alpha_total_start) main_data_sample.fill_N_R_alpha_from_matrices(mmvt_Nij_alpha, mmvt_Ri_alpha) assert len(N_i_j_alpha_exp) == len(main_data_sample.N_i_j_alpha) for alpha in range(len(N_i_j_alpha_exp)): mmvt_Nij_exp = N_i_j_alpha_exp[alpha] mmvt_Nij = main_data_sample.N_i_j_alpha[alpha] compare_dicts(mmvt_Nij_exp, mmvt_Nij) assert len(R_i_alpha_total_exp) == len(main_data_sample.R_i_alpha) for alpha in range(len(R_i_alpha_total_exp)): mmvt_Ri_exp = R_i_alpha_total_exp[alpha] mmvt_Ri = main_data_sample.R_i_alpha[alpha] compare_dicts(mmvt_Ri_exp, mmvt_Ri) return