def test_Runner_openmm_default(host_guest_mmvt_model): host_guest_mmvt_model.calculation_settings.num_production_steps = 10 host_guest_mmvt_model.openmm_settings.cuda_platform_settings = None host_guest_mmvt_model.openmm_settings.reference_platform = True myanchor = host_guest_mmvt_model.anchors[1] mmvt_output_filename = os.path.join( host_guest_mmvt_model.anchor_rootdir, myanchor.directory, "prod", "%s%d.%s" % (mmvt_base.OPENMMVT_BASENAME, 1, mmvt_base.OPENMMVT_EXTENSION)) runner = runner_openmm.Runner_openmm(host_guest_mmvt_model, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( force_overwrite=True) my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(host_guest_mmvt_model, myanchor, mmvt_output_filename) runner.run(my_sim_openmm, False) assert os.path.exists(mmvt_output_filename) # restart host_guest_mmvt_model.calculation_settings.num_production_steps = 20 mmvt_output_filename = os.path.join( host_guest_mmvt_model.anchor_rootdir, myanchor.directory, "prod", "%s%d.%s" % (mmvt_base.OPENMMVT_BASENAME, 2, mmvt_base.OPENMMVT_EXTENSION)) runner = runner_openmm.Runner_openmm(host_guest_mmvt_model, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( restart=True) my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(host_guest_mmvt_model, myanchor, mmvt_output_filename) runner.run(my_sim_openmm, True, restart_index=restart_index) return
def test_mmvt_swarm(host_guest_mmvt_model): """ If a multi-frame trajectory is provided as the input PDB, then an MMVT swarm should be started. """ swarm_file_name = "hostguest_at0.5_swarm.pdb" host_guest_mmvt_model.anchors[0].amber_params.pdb_coordinates_filename \ = swarm_file_name anchor_building_dir = os.path.join( host_guest_mmvt_model.anchor_rootdir, host_guest_mmvt_model.anchors[0].directory, host_guest_mmvt_model.anchors[0].building_directory) assert os.path.exists(anchor_building_dir) src_filename = os.path.join(TEST_DATA_DIRECTORY, swarm_file_name) dest_filename = os.path.join(anchor_building_dir, swarm_file_name) shutil.copyfile(src_filename, dest_filename) host_guest_mmvt_model.calculation_settings.num_production_steps = 10 host_guest_mmvt_model.openmm_settings.cuda_platform_settings = None host_guest_mmvt_model.openmm_settings.reference_platform = True myanchor = host_guest_mmvt_model.anchors[0] for i in range(10): runner = runner_openmm.Runner_openmm(host_guest_mmvt_model, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( force_overwrite=True, swarm_index=i) my_sim_openmm = mmvt_sim_openmm.create_sim_openmm( host_guest_mmvt_model, myanchor, default_output_file) runner.run(my_sim_openmm, False) assert os.path.exists(default_output_file) return
def test_saveCheckpoint(host_guest_mmvt_model): host_guest_mmvt_model.calculation_settings.num_production_steps = 10 host_guest_mmvt_model.openmm_settings.cuda_platform_settings = None host_guest_mmvt_model.openmm_settings.reference_platform = True myanchor = host_guest_mmvt_model.anchors[1] mmvt_output_filename = os.path.join( host_guest_mmvt_model.anchor_rootdir, myanchor.directory, "prod", "%s%d.%s" % (mmvt_base.OPENMMVT_BASENAME, 1, mmvt_base.OPENMMVT_EXTENSION)) runner = runner_openmm.Runner_openmm(host_guest_mmvt_model, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( force_overwrite=True) my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(host_guest_mmvt_model, myanchor, mmvt_output_filename) assert not os.path.exists(runner.restart_checkpoint_filename) runner_openmm.saveCheckpoint(my_sim_openmm, runner.restart_checkpoint_filename) assert os.path.exists(runner.restart_checkpoint_filename) lastline = "" with open(my_sim_openmm.output_filename, "r") as f: for line in f.readlines(): lastline = line print("line:", line) assert lastline.startswith("CHECKPOINT")
def test_Runner_openmm_other_settings(tmp_path): if not os.path.exists(tmp_path): os.mkdir(tmp_path) mymodel = make_test_model.make_test_model(tmp_path) #sim_openmm_factory = sim_openmm.Sim_openmm_factory() myanchor = mymodel.anchors[1] mmvt_output_filename = os.path.join( tmp_path, myanchor.name, "prod", "%s%d.%s" % (mmvt_base.OPENMMVT_BASENAME, 1, mmvt_base.OPENMMVT_EXTENSION)) loading_state_filename = os.path.join(tmp_path, "start.state") runner = runner_openmm.Runner_openmm(mymodel, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( False, True) my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(mymodel, myanchor, mmvt_output_filename, state_file_prefix) my_sim_openmm.simulation.saveState(loading_state_filename) runner.run(my_sim_openmm, False, load_state_file=loading_state_filename) assert my_sim_openmm.integrator.getOutputFileName() == mmvt_output_filename lines = 0 assert os.path.exists(mmvt_output_filename) assert os.path.exists(loading_state_filename) #print("glob.glob(state_file_prefix+'*')", glob.glob(state_file_prefix+'*')) #assert len(glob.glob(state_file_prefix+'*')) > 0 with open(mmvt_output_filename, "r") as f: for line in f: lines += 1
def run_openmm(model, anchor_index, restart, total_simulation_length, cuda_device_index=False, force_overwrite=False, save_state_file=False, num_rev_launches=1, umbrella_restart_mode=False): """Run an OpenMM simulation.""" 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 assert anchor_index >= 0, "only positive indices allowed." try: myanchor = model.anchors[anchor_index] except IndexError: print("Invalid anchor index provided.") exit() if cuda_device_index is not None: assert model.openmm_settings.cuda_platform_settings is not None model.openmm_settings.cuda_platform_settings.cuda_device_index = \ cuda_device_index if total_simulation_length is not None: if model.get_type() == "mmvt": old_num_production_steps = \ model.calculation_settings.num_production_steps model.calculation_settings.num_production_steps = \ total_simulation_length elif model.get_type() == "elber": old_num_production_steps = \ model.calculation_settings.num_umbrella_stage_steps model.calculation_settings.num_umbrella_stage_steps = \ total_simulation_length model.calculation_settings.num_rev_launches = num_rev_launches runner = runner_openmm.Runner_openmm(model, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( restart, save_state_file, force_overwrite, umbrella_restart_mode) if model.get_type() == "mmvt": sim_openmm_obj = mmvt_sim_openmm.create_sim_openmm( model, myanchor, default_output_file, state_file_prefix) elif model.get_type() == "elber": sim_openmm_obj = elber_sim_openmm.create_sim_openmm( model, myanchor, default_output_file, state_file_prefix) runner.run(sim_openmm_obj, restart, None, restart_index) if model.get_type() == "mmvt": model.calculation_settings.num_production_steps \ = old_num_production_steps elif model.get_type() == "elber": model.calculation_settings.num_umbrella_stage_steps \ = old_num_production_steps
def test_Runner_openmm_forcefield(tmp_path, host_guest_mmvt_model_forcefield): if not os.path.exists(tmp_path): os.mkdir(tmp_path) mymodel = host_guest_mmvt_model_forcefield myanchor = mymodel.anchors[1] mmvt_output_filename = os.path.join( tmp_path, myanchor.directory, "prod", "%s%d.%s" % (mmvt_base.OPENMMVT_BASENAME, 1, mmvt_base.OPENMMVT_EXTENSION)) runner = runner_openmm.Runner_openmm(mymodel, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( force_overwrite=True) my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(mymodel, myanchor, mmvt_output_filename) runner.run(my_sim_openmm, False) assert os.path.exists(mmvt_output_filename)
def test_Runner_openmm_forcefield(tmp_path): if not os.path.exists(tmp_path): os.mkdir(tmp_path) mymodel = make_test_model.make_test_model(tmp_path, mode="forcefield") #sim_openmm_factory = sim_openmm.Sim_openmm_factory() myanchor = mymodel.anchors[1] mmvt_output_filename = os.path.join( tmp_path, myanchor.name, "prod", "%s%d.%s" % (mmvt_base.OPENMMVT_BASENAME, 1, mmvt_base.OPENMMVT_EXTENSION)) runner = runner_openmm.Runner_openmm(mymodel, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare() my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(mymodel, myanchor, mmvt_output_filename) runner.run(my_sim_openmm, False) assert os.path.exists(mmvt_output_filename) lines = 0 with open(mmvt_output_filename, "r") as f: for line in f: lines += 1
def test_runner_openmm_elber(host_guest_elber_model): runner_openmm.REV_STAGE_STEPS_PER_BLOCK = 10 runner_openmm.FWD_STAGE_STEPS_PER_BLOCK = 10 host_guest_elber_model.calculation_settings.num_umbrella_stage_steps = 2 host_guest_elber_model.calculation_settings.umbrella_energy_reporter_interval = 1 host_guest_elber_model.calculation_settings.umbrella_trajectory_reporter_interval = 1 host_guest_elber_model.calculation_settings.fwd_rev_interval = 1 host_guest_elber_model.openmm_settings.cuda_platform_settings = None host_guest_elber_model.openmm_settings.reference_platform = True myanchor = host_guest_elber_model.anchors[1] myanchor.milestones[0].variables["radius"] = 0.140 myanchor.milestones[2].variables["radius"] = 0.160 runner = runner_openmm.Runner_openmm(host_guest_elber_model, myanchor) default_output_file, state_file_prefix, restart_index = runner.prepare( force_overwrite=True) elber_output_filename = os.path.join(host_guest_elber_model.anchor_rootdir, myanchor.directory, "prod", "elber1.out") my_sim_openmm = elber_sim_openmm.create_sim_openmm(host_guest_elber_model, myanchor, elber_output_filename) runner.run(my_sim_openmm, False) return