def run_browndye2(model, bd_milestone_index, restart, n_trajectories, force_overwrite=False): """Run a Browndye2 simulation.""" import seekr2.modules.runner_browndye2 as runner_browndye2 if bd_milestone_index == "b_surface": bd_milestone_directory = os.path.join( model.anchor_rootdir, model.k_on_info.b_surface_directory) bd_directory_list = [bd_milestone_directory] for bd_directory in bd_directory_list: runner_browndye2.run_bd_top( model.browndye_settings.browndye_bin_dir, bd_directory, restart, force_overwrite) n_trajectories_per_output = runner_browndye2.DEFAULT_N_TRAJ_PER_OUT if n_trajectories is not None: if n_trajectories_per_output > n_trajectories: n_trajectories_per_output = n_trajectories runner_browndye2.modify_variables( bd_directory, model.k_on_info.bd_output_glob, n_trajectories, restart=restart, n_trajectories_per_output\ =n_trajectories_per_output) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) 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 run_browndye2(model, bd_milestone_index, restart, n_trajectories, force_overwrite=False, max_b_surface_trajs_to_extract=1000): """Run a Browndye2 simulation.""" import seekr2.modules.runner_browndye2 as runner_browndye2 if bd_milestone_index == "b_surface": bd_milestone_directory = os.path.join( model.anchor_rootdir, model.k_on_info.b_surface_directory) bd_directory_list = [bd_milestone_directory] else: assert bd_milestone_index >= 0, "only positive indices allowed." try: bd_milestone = model.k_on_info.bd_milestones[bd_milestone_index] except IndexError: print("Invalid bd_milestone index provided.") exit() bd_milestone_directory = os.path.join(model.anchor_rootdir, bd_milestone.directory) #assert not b_surface, "Extraction may not be performed on the "\ # "b-surface." lig_pqr_filenames, rec_pqr_filenames \ = runner_browndye2.extract_bd_surface( model, bd_milestone, max_b_surface_trajs_to_extract, force_overwrite, restart) bd_directory_list = runner_browndye2.make_fhpd_directories( model, bd_milestone, lig_pqr_filenames, rec_pqr_filenames, force_overwrite) for bd_directory in bd_directory_list: runner_browndye2.run_bd_top(model.browndye_settings.browndye_bin_dir, bd_directory, restart, force_overwrite) n_trajectories_per_output = runner_browndye2.DEFAULT_N_TRAJ_PER_OUT if n_trajectories is not None: if n_trajectories_per_output > n_trajectories: n_trajectories_per_output = n_trajectories runner_browndye2.modify_variables( bd_directory, model.k_on_info.bd_output_glob, n_trajectories, restart=restart, n_trajectories_per_output\ =n_trajectories_per_output) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) if bd_milestone_index != "b_surface": runner_browndye2.combine_fhpd_results(model, bd_milestone, bd_directory_list) return
def test_modify_variables(host_guest_mmvt_model): """ Test the function that modifies variables within the BD input xml. """ bd_directory = os.path.join( host_guest_mmvt_model.anchor_rootdir, host_guest_mmvt_model.k_on_info.b_surface_directory) print("host_guest_mmvt_model.anchor_rootdir:", host_guest_mmvt_model.anchor_rootdir) assert os.path.exists(host_guest_mmvt_model.anchor_rootdir) print("bd_directory:", bd_directory) assert os.path.exists(bd_directory) runner_browndye2.run_bd_top( host_guest_mmvt_model.browndye_settings.browndye_bin_dir, bd_directory, force_overwrite=True) runner_browndye2.modify_variables( bd_directory, host_guest_mmvt_model.k_on_info.bd_output_glob, 100, 4, 3456, "my_out.xml", restart=False, n_trajectories_per_output=25) simulation_filename_base = sim_browndye2.BROWNDYE_RECEPTOR + "_" \ + sim_browndye2.BROWNDYE_LIGAND + "_simulation.xml" simulation_filename = os.path.join(bd_directory, simulation_filename_base) result = extract_xml_line(simulation_filename, "n_trajectories") assert result == "100" result = extract_xml_line(simulation_filename, "n_threads") assert result == "4" result = extract_xml_line(simulation_filename, "seed") assert result == "3456" result = extract_xml_line(simulation_filename, "output") assert result == "my_out.xml" result = extract_xml_line(simulation_filename, "n_trajectories_per_output") assert result == "25" return
def test_runner_browndye2_b_surface_elber(host_guest_elber_model): model = host_guest_elber_model bd_directory = os.path.join(host_guest_elber_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) assert len(glob.glob(os.path.join(bd_directory, "results*.xml"))) == 1 # Test restart n_trajectories = model.k_on_info.b_surface_num_trajectories * 2 runner_browndye2.run_bd_top(model.browndye_settings.browndye_bin_dir, bd_directory, restart=True) runner_browndye2.modify_variables(bd_directory, model.k_on_info.bd_output_glob, n_trajectories, restart=True) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) assert len(glob.glob(os.path.join(bd_directory, "results*.xml"))) == 2 # Test force overwrite n_trajectories = model.k_on_info.b_surface_num_trajectories runner_browndye2.run_bd_top(model.browndye_settings.browndye_bin_dir, bd_directory, force_overwrite=True) runner_browndye2.modify_variables(bd_directory, model.k_on_info.bd_output_glob, n_trajectories, restart=False) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) assert len(glob.glob(os.path.join(bd_directory, "results*.xml"))) == 1 return
def test_runner_browndye2_b_surface_default(tmp_path): model = make_test_model.make_test_model(tmp_path) b_surface_abs_path = os.path.join(tmp_path, "b_surface") receptor_pqr_filename = os.path.join( b_surface_abs_path, model.browndye_settings.receptor_pqr_filename) ligand_pqr_filename = os.path.join( b_surface_abs_path, model.browndye_settings.ligand_pqr_filename) bd_milestone = model.k_on_info.bd_milestones[0] ghost_index_rec = \ sim_browndye2.add_ghost_atom_to_pqr_from_atoms_center_of_mass( receptor_pqr_filename, bd_milestone.receptor_indices) ghost_index_lig = \ sim_browndye2.add_ghost_atom_to_pqr_from_atoms_center_of_mass( ligand_pqr_filename, bd_milestone.ligand_indices) assert ghost_index_rec == 148 assert ghost_index_lig == 16 receptor_xml_filename = sim_browndye2.make_pqrxml(receptor_pqr_filename) ligand_xml_filename = sim_browndye2.make_pqrxml(ligand_pqr_filename) debye_length, reaction_filename = \ runner_browndye2.make_browndye_input_xml( model, tmp_path, receptor_xml_filename, ligand_xml_filename, model.k_on_info.b_surface_num_steps) model.browndye_settings.debye_length = debye_length assert os.path.exists(os.path.join(b_surface_abs_path, "apbs_input.xml")) assert os.path.exists(os.path.join(b_surface_abs_path, "input.xml")) abs_reaction_path = os.path.join(b_surface_abs_path, reaction_filename) runner_browndye2.make_browndye_reaction_xml(model, abs_reaction_path) assert os.path.exists(abs_reaction_path) bd_directory = b_surface_abs_path runner_browndye2.run_bd_top(model.browndye_settings.browndye_bin_dir, bd_directory) #runner_browndye2.modify_variables(bd_directory, 10000) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) #assert os.path.exists(os.path.join(b_surface_abs_path, "results.xml")) assert len(glob.glob(os.path.join(b_surface_abs_path, "results*.xml"))) > 0 """ bd_milestone_abs_path = os.path.join(tmp_path, bd_milestone.directory) assert os.path.exists(bd_milestone_abs_path) runner_browndye2.extract_bd_surface(model, bd_milestone, 10) bd_directory_list = runner_browndye2.make_fhpd_directories( model, bd_milestone) for bd_directory in bd_directory_list: runner_browndye2.run_bd_top(model.browndye_settings.browndye_bin_dir, bd_directory) runner_browndye2.modify_variables(bd_directory, n_trajectories=1000) runner_browndye2.run_nam_simulation( model.browndye_settings.browndye_bin_dir, bd_directory, model.k_on_info.bd_output_glob) runner_browndye2.combine_fhpd_results( model, bd_milestone, bd_directory_list) assert os.path.exists(os.path.join(bd_milestone_abs_path, "results.xml")) """ return # TODO: bd_milestone test runs