def run_short_ci(model_input, cuda_device_index, long_check=True): start_dir = os.getcwd() model, xml_path = prepare.prepare(model_input, force_overwrite=False) model_dir = os.path.dirname(xml_path) model.anchor_rootdir = os.path.abspath(model_dir) check.check_pre_simulation_all(model) run.run(model, "any", min_b_surface_simulation_length=1000, num_rev_launches=10, cuda_device_index=cuda_device_index, save_state_file=True) data_sample_list = converge.converge(model, k_on_state=0) rmsd_convergence_results = common_converge.calc_RMSD_conv_amount( model, data_sample_list) transition_minima, transition_details, transition_times \ = common_converge.calc_transition_steps( model, data_sample_list[-1]) converge.print_convergence_results( model, rmsd_convergence_results, cutoff=0.1, transition_results=transition_details, transition_time_results=transition_times, minimum_anchor_transitions=10, bd_transition_counts=data_sample_list[-1].bd_transition_counts) check.check_post_simulation_all(model, long_check=long_check) analysis = analyze.analyze(model) analysis.print_results() os.chdir(start_dir) return
def test_converge_incomplete_md_only_mmvt(toy_mmvt_model): num_steps = 100000 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, "any", force_overwrite=True) runner_openmm.cleanse_anchor_outputs(toy_mmvt_model, toy_mmvt_model.anchors[3]) cutoff = 0.1 minimum_anchor_transitions = 100 image_directory = common_analyze.make_image_directory(toy_mmvt_model, None) k_on_state = None data_sample_list = converge.converge(toy_mmvt_model, k_on_state, image_directory=image_directory, verbose=True) rmsd_convergence_results = common_converge.calc_RMSD_conv_amount( toy_mmvt_model, data_sample_list) transition_minima, transition_prob_results, transition_time_results \ = common_converge.calc_transition_steps( toy_mmvt_model, data_sample_list[-1]) bd_transition_counts = data_sample_list[-1].bd_transition_counts converge.print_convergence_results(toy_mmvt_model, rmsd_convergence_results, cutoff, transition_prob_results, transition_time_results, minimum_anchor_transitions, bd_transition_counts) return
def test_converge_default_bd_only_mmvt(host_guest_mmvt_model): model = host_guest_mmvt_model bd_directory = os.path.join(host_guest_mmvt_model.anchor_rootdir, "b_surface") runner_browndye2.run_bd_top(model.browndye_settings.browndye_bin_dir, bd_directory, force_overwrite=True) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) cutoff = 0.1 minimum_anchor_transitions = 100 image_directory = common_analyze.make_image_directory( host_guest_mmvt_model, None) k_on_state = 0 data_sample_list = converge.converge(host_guest_mmvt_model, k_on_state, image_directory=image_directory, verbose=True) rmsd_convergence_results = common_converge.calc_RMSD_conv_amount( host_guest_mmvt_model, data_sample_list) transition_minima, transition_prob_results, transition_time_results \ = common_converge.calc_transition_steps( host_guest_mmvt_model, data_sample_list[-1]) bd_transition_counts = data_sample_list[-1].bd_transition_counts converge.print_convergence_results(host_guest_mmvt_model, rmsd_convergence_results, cutoff, transition_prob_results, transition_time_results, minimum_anchor_transitions, bd_transition_counts) return
def test_converge_default_md_only_elber(toy_elber_model): num_steps = 100000 fwd_rev_interval = 100 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, "any") cutoff = 0.1 minimum_anchor_transitions = 100 image_directory = common_analyze.make_image_directory( toy_elber_model, None) k_on_state = None data_sample_list = converge.converge(toy_elber_model, k_on_state, image_directory=image_directory, verbose=True) rmsd_convergence_results = common_converge.calc_RMSD_conv_amount( toy_elber_model, data_sample_list) transition_minima, transition_prob_results, transition_time_results \ = common_converge.calc_transition_steps( toy_elber_model, data_sample_list[-1]) bd_transition_counts = data_sample_list[-1].bd_transition_counts converge.print_convergence_results(toy_elber_model, rmsd_convergence_results, cutoff, transition_prob_results, transition_time_results, minimum_anchor_transitions, bd_transition_counts) return
def test_calc_RMSD_conv_amount_elber(toy_elber_model): for anchor in toy_elber_model.anchors: runner_openmm.cleanse_anchor_outputs(toy_elber_model, anchor) anchor1 = toy_elber_model.anchors[1] anchor1_output_filename = os.path.join(toy_elber_model.anchor_rootdir, anchor1.directory, anchor1.production_directory, "forward.restart1.out") copyfile(test_output_filename_elber, anchor1_output_filename) image_directory = common_analyze.make_image_directory( toy_elber_model, None) data_sample_list = converge.converge(toy_elber_model, 0, image_directory=image_directory, verbose=True) convergence_results = common_converge.calc_RMSD_conv_amount( toy_elber_model, data_sample_list) for alpha, anchor in enumerate(toy_elber_model.anchors): if anchor.bulkstate: continue if anchor.index == 1: assert convergence_results[alpha] < 1.0 else: assert convergence_results[alpha] == 1e99 return
def test_calc_transition_steps_elber(toy_elber_model): for anchor in toy_elber_model.anchors: runner_openmm.cleanse_anchor_outputs(toy_elber_model, anchor) anchor1 = toy_elber_model.anchors[1] anchor1_output_filename = os.path.join(toy_elber_model.anchor_rootdir, anchor1.directory, anchor1.production_directory, "forward.restart1.out") copyfile(test_output_filename_elber, anchor1_output_filename) image_directory = common_analyze.make_image_directory( toy_elber_model, None) data_sample_list = converge.converge(toy_elber_model, 0, image_directory=image_directory, verbose=True) transition_minima, transition_prob_results, transition_time_results \ = common_converge.calc_transition_steps( toy_elber_model, data_sample_list[-1]) for alpha, anchor in enumerate(toy_elber_model.anchors): if anchor.bulkstate: continue if anchor.index == 1: assert transition_minima[alpha] == 3 assert transition_prob_results[alpha][(1, 2)] == 5 assert transition_prob_results[alpha][(1, 0)] == 3 assert np.isclose(transition_time_results[alpha][1], (1.324 / 5)) else: assert transition_minima[alpha] == 0 for key in transition_prob_results[alpha]: assert transition_prob_results[alpha][key] == 0 for key in transition_time_results[alpha]: assert transition_time_results[alpha][key] == 0 return
def choose_next_simulation_namd(model, instruction, min_total_simulation_length, max_total_simulation_length, convergence_cutoff, minimum_anchor_transitions, force_overwrite): """ Examine the model and all MD simulations that have run so far. Using this information, as well as the specified criteria (minimum number of steps, minimum convergence, maximum number of steps, etc.), construct a list of anchors to run, in order. """ import seekr2.modules.runner_namd as runner_namd import seekr2.modules.mmvt_sim_namd as mmvt_sim_namd if instruction == "any_bd": return [] anchor_info_to_run_unsorted = [] for alpha, anchor in enumerate(model.anchors): if anchor.bulkstate: continue if instruction not in ["any", "any_md"]: try: integer_instruction = int(instruction) except ValueError: #print("Invalid argument for INSTRUCTION provided: "\ # "'{}'. ".format(instruction)\ # +"Allowed arguments: 'any', 'any_md', 'any_bd'.") #exit() return [] if alpha != integer_instruction: continue if min_total_simulation_length is None: min_total_simulation_length \ = model.calculation_settings.num_production_steps output_directory = os.path.join(model.anchor_rootdir, anchor.directory, anchor.production_directory) restart_checkpoint_filename = os.path.join( output_directory, runner_namd.RESTART_CHECKPOINT_FILENAME + ".xsc") if os.path.exists(restart_checkpoint_filename) and not force_overwrite: currentStep = runner_namd.read_xsc_step_number( restart_checkpoint_filename) restart = True else: currentStep = 0 restart = False if max_total_simulation_length is not None: if currentStep > max_total_simulation_length: # this simulation has run long enough continue # make sure that all simulations reach minimum number of steps # before sorting by convergence steps_to_go_to_minimum = min_total_simulation_length - currentStep if steps_to_go_to_minimum <= 0: data_sample_list = converge.converge(model) steps_to_go_to_minimum = 0 transition_results, dummy \ = common_converge.calc_transition_steps( model, data_sample_list[-1]) num_transitions = transition_results[alpha] if convergence_cutoff is not None: if model.get_type() == "mmvt": rmsd_convergence_results \ = common_converge.calc_RMSD_conv_amount( model, data_sample_list) elif model.get_type() == "elber": raise Exception("Elber auto-run not available.") convergence = rmsd_convergence_results[alpha] if convergence < float(convergence_cutoff): continue else: print("anchor", alpha, "has not reached the point of "\ "convergence:", convergence, "of", convergence_cutoff) total_simulation_length \ = (currentStep // CONVERGENCE_INTERVAL + 1) \ * CONVERGENCE_INTERVAL anchor_info = [ steps_to_go_to_minimum, num_transitions, alpha, restart, total_simulation_length ] anchor_info_to_run_unsorted.append(anchor_info) continue if minimum_anchor_transitions is not None: minimum_anchor_transitions = int(minimum_anchor_transitions) if num_transitions >= minimum_anchor_transitions: continue else: print("anchor", alpha, "has not had the minimum number of "\ "transitions:", num_transitions, "of", minimum_anchor_transitions) total_simulation_length = ( currentStep // CONVERGENCE_INTERVAL + 1) \ * (CONVERGENCE_INTERVAL) anchor_info = [ steps_to_go_to_minimum, num_transitions, alpha, restart, total_simulation_length ] anchor_info_to_run_unsorted.append(anchor_info) else: print("anchor", alpha, "has not run the minimum number of steps", currentStep, "of", min_total_simulation_length) total_simulation_length = min_total_simulation_length num_transitions = 0 anchor_info = [ steps_to_go_to_minimum, num_transitions, alpha, restart, total_simulation_length ] anchor_info_to_run_unsorted.append(anchor_info) # sort anchors first by how many steps still to run, then by how many # transitions have been completed. anchor_info_to_run = sorted( anchor_info_to_run_unsorted, key=lambda item: (min_total_simulation_length - item[0], item[1])) return anchor_info_to_run
def choose_next_simulation_browndye2(model, instruction, min_b_surface_simulation_length, min_bd_milestone_simulation_length, max_b_surface_trajs_to_extract, force_overwrite, min_b_surface_encounters=None, min_bd_milestone_encounters=None): """ Examine the model and all Browndye2 simulations that have run so far (if any), then construct a list of which BD milestones to run, in order. """ if instruction == "any_md": return [] if instruction not in ["any", "any_bd" ] and not instruction.startswith("b"): return [] import seekr2.modules.common_sim_browndye2 as sim_browndye2 import seekr2.modules.runner_browndye2 as runner_browndye2 if min_b_surface_simulation_length is None: min_b_surface_simulation_length \ = model.k_on_info.b_surface_num_trajectories # if overwrite is True, cleanse all BD directories for new runs b_surface_directory = os.path.join(model.anchor_rootdir, model.k_on_info.b_surface_directory) if force_overwrite and instruction in ["any", "any_bd", "b_surface"]: runner_browndye2.cleanse_bd_outputs(b_surface_directory, check_mode=False) for bd_milestone in model.k_on_info.bd_milestones: bd_milestone_directory = os.path.join(model.anchor_rootdir, bd_milestone.directory) bd_milestone_info_to_run_unsorted = [] data_sample_list = converge.converge(model) data_sample = data_sample_list[-1] bd_transition_counts = data_sample.bd_transition_counts if instruction in ["any", "any_bd", "b_surface"]: # then try to run the b-surface simulations if "b_surface" not in bd_transition_counts: bd_milestone_info_to_run_unsorted.append([ min_b_surface_simulation_length, 0, "b_surface", False, min_b_surface_simulation_length, max_b_surface_trajs_to_extract ]) else: # see how many simulations need to be run in b_surface total_b_surface_sims = sum( bd_transition_counts["b_surface"].values()) total_b_surface_encounters = min( bd_transition_counts["b_surface"].values()) steps_to_go_minimum = min_b_surface_simulation_length \ - total_b_surface_sims if steps_to_go_minimum > 0: bd_milestone_info_to_run_unsorted.append( [steps_to_go_minimum, total_b_surface_encounters, \ "b_surface", True, steps_to_go_minimum, \ max_b_surface_trajs_to_extract]) elif min_b_surface_encounters is not None: if total_b_surface_encounters < min_b_surface_encounters: total_bd_simulation_length \ = (total_b_surface_sims \ // B_SURFACE_CONVERGENCE_INTERVAL + 1) \ * B_SURFACE_CONVERGENCE_INTERVAL bd_milestone_info_to_run_unsorted.append( [total_bd_simulation_length-total_b_surface_sims, \ total_b_surface_encounters, "b_surface", True, \ total_bd_simulation_length, \ max_b_surface_trajs_to_extract]) for i, bd_milestone in enumerate(model.k_on_info.bd_milestones): if instruction == "b_surface": break if instruction not in ["any", "any_bd"]: if instruction.startswith("b"): try: integer_instruction = int(instruction[1:]) except ValueError: return [] if bd_milestone.index != integer_instruction: continue else: return [] if min_bd_milestone_simulation_length is None: min_bd_milestone_simulation_length = bd_milestone.num_trajectories if max_b_surface_trajs_to_extract is None: max_b_surface_trajs_to_extract \ = bd_milestone.max_b_surface_trajs_to_extract if bd_milestone.index not in bd_transition_counts: bd_milestone_info_to_run_unsorted.append([ min_bd_milestone_simulation_length, 0, bd_milestone.index, False, min_bd_milestone_simulation_length, max_b_surface_trajs_to_extract ]) else: # see how many simulations need to be run in b_surface total_b_surface_sims = sum( bd_transition_counts[bd_milestone.index].values()) total_b_surface_encounters = min( bd_transition_counts[bd_milestone.index].values()) steps_to_go_minimum = min_bd_milestone_simulation_length \ * max_b_surface_trajs_to_extract - total_b_surface_sims if steps_to_go_minimum > 0: bd_milestone_info_to_run_unsorted.append( [steps_to_go_minimum, total_b_surface_encounters, \ bd_milestone.index, True, \ min_bd_milestone_simulation_length, \ max_b_surface_trajs_to_extract]) elif min_bd_milestone_encounters is not None: if total_b_surface_encounters < min_bd_milestone_encounters: total_bd_simulation_length \ = (total_b_surface_sims \ // BD_MILESTONE_CONVERGENCE_INTERVAL + 1) \ * BD_MILESTONE_CONVERGENCE_INTERVAL bd_milestone_info_to_run_unsorted.append( [0, total_b_surface_encounters, \ bd_milestone.index, True, total_bd_simulation_length, \ max_b_surface_trajs_to_extract]) return bd_milestone_info_to_run_unsorted
def choose_next_simulation_openmm(model, instruction, min_total_simulation_length, max_total_simulation_length, convergence_cutoff, minimum_anchor_transitions, force_overwrite, umbrella_restart_mode): """ Examine the model and all MD simulations that have run so far. Using this information, as well as the specified criteria (minimum number of steps, minimum convergence, maximum number of steps, etc.), construct a list of anchors to run, in order. """ import seekr2.modules.runner_openmm as runner_openmm import seekr2.modules.mmvt_sim_openmm as mmvt_sim_openmm import seekr2.modules.elber_sim_openmm as elber_sim_openmm if instruction == "any_bd": return [] anchor_info_to_run_unsorted = [] for alpha, anchor in enumerate(model.anchors): if anchor.bulkstate: continue if instruction not in ["any", "any_md"]: try: integer_instruction = int(instruction) except ValueError: return [] if alpha != integer_instruction: continue if min_total_simulation_length is None: if model.get_type() == "mmvt": min_total_simulation_length \ = model.calculation_settings.num_production_steps elif model.get_type() == "elber": min_total_simulation_length \ = model.calculation_settings.num_umbrella_stage_steps output_directory = os.path.join(model.anchor_rootdir, anchor.directory, anchor.production_directory) restart_checkpoint_filename = os.path.join( output_directory, runner_openmm.RESTART_CHECKPOINT_FILENAME) if os.path.exists(restart_checkpoint_filename) and not force_overwrite\ and not umbrella_restart_mode: dummy_file = tempfile.NamedTemporaryFile() if model.get_type() == "mmvt": sim_openmm_obj = mmvt_sim_openmm.create_sim_openmm( model, anchor, dummy_file.name) simulation = sim_openmm_obj.simulation elif model.get_type() == "elber": sim_openmm_obj = elber_sim_openmm.create_sim_openmm( model, anchor, dummy_file.name) simulation = sim_openmm_obj.umbrella_simulation simulation.loadCheckpoint(restart_checkpoint_filename) currentStep = int(math.ceil(simulation.context.getState().getTime()\ .value_in_unit(unit.picoseconds) \ / sim_openmm_obj.timestep)) dummy_file.close() restart = True else: currentStep = 0 restart = False if max_total_simulation_length is not None: if currentStep > max_total_simulation_length: # this simulation has run long enough continue # make sure that all simulations reach minimum number of steps # before sorting by convergence steps_to_go_to_minimum = min_total_simulation_length - currentStep if steps_to_go_to_minimum <= 0: data_sample_list = converge.converge(model) steps_to_go_to_minimum = 0 transition_minima, dummy \ = common_converge.calc_transition_steps( model, data_sample_list[-1]) num_transitions = transition_minima[alpha] if convergence_cutoff is not None: rmsd_convergence_results \ = common_converge.calc_RMSD_conv_amount( model, data_sample_list) convergence = rmsd_convergence_results[alpha] if convergence < float(convergence_cutoff): continue else: print("anchor", alpha, "has not reached the point of "\ "convergence:", convergence, "of", convergence_cutoff) total_simulation_length \ = (currentStep // CONVERGENCE_INTERVAL + 1) \ * CONVERGENCE_INTERVAL anchor_info = [ steps_to_go_to_minimum, num_transitions, alpha, restart, total_simulation_length ] anchor_info_to_run_unsorted.append(anchor_info) continue if minimum_anchor_transitions is not None: minimum_anchor_transitions = int(minimum_anchor_transitions) if num_transitions >= minimum_anchor_transitions: continue else: print("anchor", alpha, "has not had the minimum number of "\ "transitions:", num_transitions, "of", minimum_anchor_transitions) total_simulation_length = ( currentStep // CONVERGENCE_INTERVAL + 1) \ * (CONVERGENCE_INTERVAL) anchor_info = [ steps_to_go_to_minimum, num_transitions, alpha, restart, total_simulation_length ] anchor_info_to_run_unsorted.append(anchor_info) else: print("anchor", alpha, "has not run the minimum number of steps", currentStep, "of", min_total_simulation_length) total_simulation_length = min_total_simulation_length num_transitions = 0 anchor_info = [ steps_to_go_to_minimum, num_transitions, alpha, restart, total_simulation_length ] anchor_info_to_run_unsorted.append(anchor_info) # sort anchors first by how many steps still to run, then by how many # transitions have been completed. anchor_info_to_run = sorted( anchor_info_to_run_unsorted, key=lambda item: (min_total_simulation_length - item[0], item[1])) return anchor_info_to_run