def test_Analysis_mmvt_check_anchor_stats(toy_mmvt_model): num_steps = 1000000 long_timescale_residence_time_in_ps = 1263.06 toy_mmvt_model.openmm_settings.cuda_platform_settings = None toy_mmvt_model.openmm_settings.reference_platform = True toy_mmvt_model.openmm_settings.langevin_integrator.friction_coefficient \ = 100.0 toy_mmvt_model.calculation_settings.num_production_steps = num_steps toy_mmvt_model.calculation_settings.energy_reporter_interval = num_steps run.run(toy_mmvt_model, "0") run.run(toy_mmvt_model, "1") run.run(toy_mmvt_model, "3") run.run(toy_mmvt_model, "4") analysis = analyze.Analysis(toy_mmvt_model, num_error_samples=100) analysis.extract_data() with pytest.raises(common_analyze.MissingStatisticsError): analysis.check_extraction() run.run(toy_mmvt_model, "any") analysis = analyze.Analysis(toy_mmvt_model, num_error_samples=100) analysis.extract_data() analysis.check_extraction() return
def test_Analysis_elber_check_anchor_stats(toy_elber_model): num_steps = 10000 fwd_rev_interval = 10 toy_elber_model.openmm_settings.cuda_platform_settings = None toy_elber_model.openmm_settings.reference_platform = True toy_elber_model.openmm_settings.langevin_integrator.friction_coefficient \ = 100.0 toy_elber_model.calculation_settings.num_umbrella_stage_steps = num_steps toy_elber_model.calculation_settings.fwd_rev_interval = fwd_rev_interval run.run(toy_elber_model, "0") run.run(toy_elber_model, "1") run.run(toy_elber_model, "3") run.run(toy_elber_model, "4") analysis = analyze.Analysis(toy_elber_model, num_error_samples=100) analysis.extract_data() with pytest.raises(common_analyze.MissingStatisticsError): analysis.check_extraction() run.run(toy_elber_model, "any") analysis = analyze.Analysis(toy_elber_model, num_error_samples=100) analysis.extract_data() analysis.check_extraction() return
def make_mmvt_data_sample(model): num_steps = 100000 model.openmm_settings.cuda_platform_settings = None model.openmm_settings.reference_platform = True model.openmm_settings.langevin_integrator.friction_coefficient \ = 100.0 model.calculation_settings.num_production_steps = num_steps model.calculation_settings.energy_reporter_interval = num_steps for anchor in model.anchors: runner_openmm.cleanse_anchor_outputs( model, anchor, skip_umbrella_files=False) run.run(model, "1", force_overwrite = True) analysis = analyze.Analysis(model) analysis.extract_data() analysis.fill_out_data_samples() return analysis.main_data_sample
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 check_milestone_convergence(model, k_on_state=None, verbose=False): """ Calculates the key MMVT quantities N, R, and Q as a function of simulation time to estimate which milestones have been sufficiently sampled. Quantities are pulled from the data at step intervals determined by the conv_stride value with the option to skip steps from the beginning of the data with the skip variable Parameters ----------- model : Model() milestoning model object containing all milestone and transition information. k_on_state: int or None, default None If not None, then assume then this is the bound state to assume for k-on calculations. A value of None will skip the k-on convergence. verbose : bool, Default False Whether to provide more verbose output information. Returns ------- k_on_conv : list list of calculated on rate at each convergence interval k_off_conv : list list of calculated off rate at each convergence interval N_ij_conv: list list of transition count matrix N for each convergence interval R_i_conv : list list of transition time matrix R for each convergence interval max_step_list : list list of maximum step numbers used for each convergence sample timestep_in_ns : float The length of the timestep in units of nanoseconds data_sample_list : list A list of Data_sample objects that can be used to quantitatively monitor convergence. """ data_sample_list = [] dt = model.get_timestep() timestep_in_ns = (dt * unit.picosecond).value_in_unit(unit.nanoseconds) if model.get_type() == "mmvt": max_step_list = get_mmvt_max_steps(model) elif model.get_type() == "elber": max_step_list = get_elber_max_steps(model) k_off_conv = np.zeros(DEFAULT_NUM_POINTS) k_on_conv = np.zeros(DEFAULT_NUM_POINTS) # partial allows us to create a defaultdict with values that are # empty arrays of a certain size DEFAULT_NUM_POINTS N_ij_conv = defaultdict(functools.partial(np.zeros, DEFAULT_NUM_POINTS)) R_i_conv = defaultdict(functools.partial(np.zeros, DEFAULT_NUM_POINTS)) analysis = analyze.Analysis(model, force_warning=False) for interval_index in range(DEFAULT_NUM_POINTS): if verbose and (interval_index % PROGRESS_UPDATE_INTERVAL == 0): print("Processing interval {} of {}".format(interval_index, DEFAULT_NUM_POINTS)) max_step = max_step_list[interval_index] k_on, k_off, N_ij, R_i = analyze_kinetics( model, analysis, max_step, k_on_state) data_sample_list.append(analysis.main_data_sample) k_on_conv[interval_index] = k_on k_off_conv[interval_index] = k_off if interval_index == 0: divisor = 1 else: divisor = interval_index for N_ij_key in N_ij: N_ij_conv[N_ij_key][interval_index] = N_ij[N_ij_key] / divisor for R_i_key in R_i: R_i_conv[R_i_key][interval_index] = R_i[R_i_key] / divisor return k_on_conv, k_off_conv, N_ij_conv, R_i_conv, max_step_list, \ timestep_in_ns, data_sample_list
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