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
Exemple #2
0
def test_check_toy_openmm_context_within_boundary(toy_mmvt_model, tmp_path):
    """
    Test whether the check can find systems that exist outside the proper
    Voronoi cells.
    """
    # Test check success: system starting within Voronoi cells
    anchor = toy_mmvt_model.anchors[0]
    output_file = os.path.join(tmp_path, "output.txt")
    toy_mmvt_model.openmm_settings.cuda_platform_settings = None
    toy_mmvt_model.openmm_settings.reference_platform = True
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        toy_mmvt_model, anchor, output_file)
    context = my_sim_openmm.simulation.context
    
    final_result = True
    for milestone in anchor.milestones:
        cv = toy_mmvt_model.collective_variables[milestone.cv_index]
        result = cv.check_openmm_context_within_boundary(
            context, milestone.variables, verbose=True)
        final_result = final_result and result
        
    assert final_result
    
    # Test check failure(s): system outside Voronoi cells
    toy_mmvt_model.anchors[0].starting_positions = np.array(
        [[[0.0, -0.7, 0.0]], [[0.2, -0.5, 0.0]]])
    toy_mmvt_model.anchors[1].starting_positions = np.array(
        [[[0.0, -0.3, 0.0]]])
    
    anchor = toy_mmvt_model.anchors[0]
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        toy_mmvt_model, anchor, output_file, frame=1)
    context = my_sim_openmm.simulation.context
    
    final_result = True
    for milestone in anchor.milestones:
        cv = toy_mmvt_model.collective_variables[milestone.cv_index]
        result = cv.check_openmm_context_within_boundary(
            context, milestone.variables, verbose=True)
        final_result = final_result and result
        
    assert not final_result
    
    anchor = toy_mmvt_model.anchors[1]
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        toy_mmvt_model, anchor, output_file)
    context = my_sim_openmm.simulation.context
    
    final_result = True
    for milestone in anchor.milestones:
        cv = toy_mmvt_model.collective_variables[milestone.cv_index]
        result = cv.check_openmm_context_within_boundary(
            context, milestone.variables, verbose=True)
        final_result = final_result and result
        
    assert not final_result
    
    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_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
Exemple #5
0
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
Exemple #6
0
def test_mmvt_sim_openmm_forcefield(tmp_path):

    mymodel = make_test_model.make_test_model(tmp_path, mode='forcefield')
    myanchor = mymodel.anchors[1]
    output_file = os.path.join(tmp_path, "output.txt")
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(mymodel, myanchor,
                                                      output_file)
    return
def test_mmvt_sim_openmm_amber(tmp_path, host_guest_mmvt_model):
    myanchor = host_guest_mmvt_model.anchors[1]
    output_file = os.path.join(tmp_path, "output.txt")
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        host_guest_mmvt_model, myanchor, output_file)
    assert my_sim_openmm.system is not None
    assert my_sim_openmm.integrator is not None
    assert my_sim_openmm.simulation is not None
    return
Exemple #8
0
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_add_forces(tmp_path, toy_mmvt_model):
    anchor = toy_mmvt_model.anchors[0]
    output_file = os.path.join(tmp_path, "output.txt")
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        toy_mmvt_model, anchor, output_file)
    forces = my_sim_openmm.system.getForces()
    old_force_len = len(forces)
    assert my_sim_openmm.integrator.getNumMilestoneGroups() \
        == len(anchor.milestones)
    mmvt_sim_openmm.add_forces(my_sim_openmm, toy_mmvt_model, anchor)
    forces2 = my_sim_openmm.system.getForces()
    assert len(forces2) == old_force_len + len(anchor.milestones)
    return
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)
Exemple #11
0
def get_checkpoint_step(model, anchor):
    dummy_file = tempfile.NamedTemporaryFile()
    sim_openmm_obj = mmvt_sim_openmm.create_sim_openmm(model,
                                                       anchor,
                                                       dummy_file.name,
                                                       frame=0,
                                                       load_state_file=None)
    simulation = sim_openmm_obj.simulation
    output_directory = os.path.join(model.anchor_rootdir, anchor.directory,
                                    anchor.production_directory)
    restart_checkpoint_basename = runner_openmm.RESTART_CHECKPOINT_FILENAME
    restart_checkpoint_glob = os.path.join(output_directory,
                                           restart_checkpoint_basename + "*")
    restart_checkpoint_list = glob.glob(restart_checkpoint_glob)
    if len(restart_checkpoint_list) > 0:
        simulation.loadCheckpoint(restart_checkpoint_list[0])
        currentStep = simulation.context.getState().getStepCount()
    else:
        currentStep = 0
    dummy_file.close()
    return currentStep
Exemple #12
0
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
Exemple #13
0
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
Exemple #14
0
def test_check_openmm_context_within_boundary(host_guest_mmvt_model, tmp_path):
    """
    Test whether the check can find systems that exist outside the proper
    Voronoi cells.
    """
    # Test check success: system starting within Voronoi cells
    anchor = host_guest_mmvt_model.anchors[0]
    output_file = os.path.join(tmp_path, "output.txt")
    host_guest_mmvt_model.openmm_settings.cuda_platform_settings = None
    host_guest_mmvt_model.openmm_settings.reference_platform = True
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        host_guest_mmvt_model, anchor, output_file)
    context = my_sim_openmm.simulation.context
    
    final_result = True
    for milestone in anchor.milestones:
        cv = host_guest_mmvt_model.collective_variables[milestone.cv_index]
        result = cv.check_openmm_context_within_boundary(
            context, milestone.variables, verbose=True)
        final_result = final_result and result
        
    assert final_result
    
    # Test check failure(s): system outside Voronoi cells
    anchor_pdb1 \
        = host_guest_mmvt_model.anchors[0].amber_params.pdb_coordinates_filename
    anchor_pdb2 \
        = host_guest_mmvt_model.anchors[1].amber_params.pdb_coordinates_filename
    anchor_pdb_src_path1 = os.path.join(
        host_guest_mmvt_model.anchor_rootdir, 
        host_guest_mmvt_model.anchors[0].directory,
        host_guest_mmvt_model.anchors[0].building_directory, 
        anchor_pdb1)
    anchor_pdb_src_path2 = os.path.join(
        host_guest_mmvt_model.anchor_rootdir, 
        host_guest_mmvt_model.anchors[1].directory,
        host_guest_mmvt_model.anchors[1].building_directory, 
        anchor_pdb2)
    anchor_pdb_dest_path1 = os.path.join(
        host_guest_mmvt_model.anchor_rootdir, 
        host_guest_mmvt_model.anchors[0].directory,
        host_guest_mmvt_model.anchors[0].building_directory, 
        anchor_pdb2)
    anchor_pdb_dest_path2 = os.path.join(
        host_guest_mmvt_model.anchor_rootdir, 
        host_guest_mmvt_model.anchors[1].directory,
        host_guest_mmvt_model.anchors[1].building_directory, 
        anchor_pdb1)
    shutil.copyfile(anchor_pdb_src_path1, anchor_pdb_dest_path2)
    shutil.copyfile(anchor_pdb_src_path2, anchor_pdb_dest_path1)
    host_guest_mmvt_model.anchors[0].amber_params.pdb_coordinates_filename \
        = anchor_pdb2
    host_guest_mmvt_model.anchors[1].amber_params.pdb_coordinates_filename \
        = anchor_pdb1
        
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        host_guest_mmvt_model, anchor, output_file)
    context = my_sim_openmm.simulation.context
    
    final_result = True
    for milestone in anchor.milestones:
        cv = host_guest_mmvt_model.collective_variables[milestone.cv_index]
        result = cv.check_openmm_context_within_boundary(
            context, milestone.variables, verbose=True)
        final_result = final_result and result
        
    assert not final_result
    
    return
Exemple #15
0
def check_systems_within_Voronoi_cells(model):
    """
    Users might provide the wrong starting structure for a given 
    anchor, and the structure may actually belong in a different one.
    When the model defines Voronoi cells (such as in MMVT), check that
    the starting structures lie within the expected Voronoi cells, and
    suggest corrections if the check fails. Otherwise, the SEEKR2
    backend would fail with a non-helpful error message.
    """
    returning_result = True
    if model.get_type() != "mmvt":
        # only apply to MMVT systems
        return True

    curdir = os.getcwd()
    os.chdir(model.anchor_rootdir)

    for anchor in model.anchors:
        if model.using_toy():
            if anchor.starting_positions is None: continue
            if len(anchor.starting_positions) == 0: continue
            tmp_path = tempfile.NamedTemporaryFile()
            output_file = tmp_path.name
            model.openmm_settings.cuda_platform_settings = None
            model.openmm_settings.reference_platform = True
            if model.get_type() == "mmvt":
                my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
                    model, anchor, output_file)
                context = my_sim_openmm.simulation.context
            else:
                my_sim_openmm = elber_sim_openmm.create_sim_openmm(
                    model, anchor, output_file)
                context = my_sim_openmm.umbrella_simulation.context

        else:
            traj = load_structure_with_mdtraj(model, anchor)
            if traj is None:
                continue

        for milestone in anchor.milestones:
            cv = model.collective_variables[milestone.cv_index]
            if model.using_toy():
                result = cv.check_openmm_context_within_boundary(
                    context, milestone.variables, verbose=True)

            else:
                result = cv.check_mdtraj_within_boundary(traj,
                                                         milestone.variables,
                                                         verbose=True)

            if result == False:
                correct_anchor = None
                for anchor2 in model.anchors:
                    within_milestones = True
                    for milestone in anchor2.milestones:
                        if anchor.__class__.__name__ \
                                in ["MMVT_toy_anchor", "Elber_toy_anchor"]:
                            result2 = cv.check_openmm_context_within_boundary(
                                context, milestone.variables, verbose=True)

                        else:
                            result2 = cv.check_mdtraj_within_boundary(
                                traj, milestone.variables)
                        if not result2:
                            within_milestones = False
                            break
                    if within_milestones:
                        correct_anchor = anchor2
                        break

                warnstr = """CHECK FAILURE: The provided initial starting 
    structure for anchor {} does not lie within the 
    anchor boundaries. The simulation would fail. Please 
    carefully check this anchor's starting structure, as 
    well as the collective variable's (CV) atom selections, 
    and anchor/milestone variables.""".format(anchor.index)
                print(warnstr)
                if correct_anchor is not None:
                    print("It looks like the failed structure might belong in "\
                          "anchor {}.".format(correct_anchor.index))
                returning_result = False

    os.chdir(curdir)
    return returning_result
Exemple #16
0
    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:
        model.calculation_settings.num_production_steps = \
            total_simulation_length

    runner = Runner_openmm(model, myanchor)
    default_output_file, state_file_prefix, restart_index = runner.prepare(
        restart, save_state_file, force_overwrite, umbrella_restart_mode)
    if output_file is None:
        output_file = default_output_file

    if model.get_type() == "mmvt":
        sim_openmm_obj = mmvt_sim_openmm.create_sim_openmm(
            model, myanchor, output_file, state_file_prefix)
    elif model.get_type() == "elber":
        sim_openmm_factory = elber_sim_openmm.create_sim_openmm(
            model, myanchor, output_file, state_file_prefix)
        model.calculation_settings.num_rev_launches = num_rev_launches

    runner.run(sim_openmm_obj, restart, load_state_file, restart_index)
def test_add_simulation(tmp_path, toy_mmvt_model):
    anchor = toy_mmvt_model.anchors[0]
    output_file = os.path.join(tmp_path, "output.txt")
    my_sim_openmm = mmvt_sim_openmm.create_sim_openmm(
        toy_mmvt_model, anchor, output_file)
    assert my_sim_openmm.simulation is not None
Exemple #18
0
 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:
     model.calculation_settings.num_production_steps = \
         total_simulation_length
 
 runner = Runner_openmm(model, myanchor)
 default_output_file, state_file_prefix, restart_index = runner.prepare(
     restart, save_state_file, force_overwrite, umbrella_restart_mode)
 if output_file is None:
     output_file = default_output_file
 
 if model.get_type() == "mmvt":
     sim_openmm_obj = mmvt_sim_openmm.create_sim_openmm(
         model, myanchor, output_file, state_file_prefix, frame=0, 
         load_state_file=load_state_file)
 elif model.get_type() == "elber":
     sim_openmm_factory = elber_sim_openmm.create_sim_openmm(
         model, myanchor, output_file, state_file_prefix)
     model.calculation_settings.num_rev_launches = num_rev_launches
 
 runner.run(sim_openmm_obj, restart, load_state_file, restart_index)