Ejemplo n.º 1
0
def create_sim_openmm(model, anchor, output_filename, state_prefix=None):
    """
    Take all relevant model and anchor information and generate
    the necessary OpenMM objects to run the simulation.
    
    Parameters
    ----------
    model : Model()
        The Model which contains the anchor and all settings for
        the simulation that is about to be run.
        
    anchor : Anchor()
        The anchor object that this OpenMM simulation applies to.
        
    output_filename : str
        The name of the directory that will be written by the plugin as
        the Elber simulation proceeds, recording every 'bounce'.
        
    state_prefix : str or None
        The plugin can optionally save every state during a
        bounce. These can be used to seed simulations in other
        cells. This argument provides the file prefix for these
        saved states. If None, then no states will be written.
        
    Returns
    -------
    sim_openmm : Sim_openmm()
        The sim_openmm object, which contains everything needed
        to run an MMVT simulation within OpenMM.
        
    """
    sim_openmm = Elber_sim_openmm()
    fwd_output_filename = output_filename
    directory = os.path.dirname(output_filename)
    basename = os.path.basename(output_filename)
    suffix = re.sub(elber_base.OPENMM_ELBER_BASENAME, "", basename)
    rev_basename = elber_base.ELBER_REV_BASENAME+suffix
    rev_output_filename = os.path.join(directory, rev_basename)
    sim_openmm.rev_output_filename = rev_output_filename
    sim_openmm.fwd_output_filename = fwd_output_filename
    sim_openmm.output_filename = output_filename
    umbrella_system, umbrella_topology, umbrella_positions, \
        umbrella_box_vectors, umbrella_num_frames \
        = common_sim_openmm.create_openmm_system(sim_openmm, model, anchor)
    rev_system, rev_topology, rev_positions, rev_box_vectors, rev_num_frames \
        = common_sim_openmm.create_openmm_system(sim_openmm, model, anchor)
    fwd_system, fwd_topology, fwd_positions, fwd_box_vectors, fwd_num_frames \
        = common_sim_openmm.create_openmm_system(sim_openmm, model, anchor)
    sim_openmm.umbrella_system = umbrella_system
    sim_openmm.rev_system = rev_system
    sim_openmm.fwd_system = fwd_system
    add_integrators(sim_openmm, model, state_prefix=state_prefix)
    common_sim_openmm.add_barostat(umbrella_system, model)
    common_sim_openmm.add_barostat(rev_system, model)
    common_sim_openmm.add_barostat(fwd_system, model)
    common_sim_openmm.add_platform(sim_openmm, model)
    add_forces(sim_openmm, model, anchor)
    add_simulations(sim_openmm, model, umbrella_topology, umbrella_positions, 
                         umbrella_box_vectors)
    return sim_openmm
Ejemplo n.º 2
0
def create_sim_openmm(model,
                      anchor,
                      output_filename,
                      state_prefix=None,
                      frame=0,
                      load_state_file=None):
    """
    Take all relevant model and anchor information and generate
    the necessary OpenMM objects to run the simulation.
    
    Parameters
    ----------
    model : Model()
        The Model which contains the anchor and all settings for
        the simulation that is about to be run.
        
    anchor : Anchor()
        The anchor object that this OpenMM simulation applies to.
        
    output_filename : str
        The name of the file that will be written by the plugin as
        the MMVT simulation proceeds, recording every 'bounce'.
        
    state_prefix : str or None
        The plugin can optionally save every state during a
        bounce. These can be used to seed simulations in other
        cells. This argument provides the file prefix for these
        saved states. If None, then no states will be written.
    
    frame : int
        Which frame of the starting positions file to retrieve.
    
    Returns
    -------
    sim_openmm : Sim_openmm()
        The sim_openmm object, which contains everything needed
        to run an MMVT simulation within OpenMM.
        
    """
    sim_openmm = MMVT_sim_openmm()
    sim_openmm.output_filename = output_filename
    system, topology, positions, box_vectors, num_frames \
        = common_sim_openmm.create_openmm_system(
            sim_openmm, model, anchor, frame, load_state_file=load_state_file)
    sim_openmm.system = system
    add_integrator(sim_openmm, model, state_prefix=state_prefix)
    common_sim_openmm.add_barostat(system, model)
    common_sim_openmm.add_platform(sim_openmm, model)
    add_forces(sim_openmm, model, anchor)
    positions = add_simulation(sim_openmm, model, topology, positions,
                               box_vectors, load_state_file)
    if anchor.__class__.__name__ == "MMVT_toy_anchor":
        out_file_name = os.path.join(model.anchor_rootdir, anchor.directory,
                                     anchor.building_directory, "toy.pdb")
        common_sim_openmm.write_toy_pdb_file(topology, positions,
                                             out_file_name)

    return sim_openmm
Ejemplo n.º 3
0
def test_add_platform_ref(toy_mmvt_model):
    my_sim_openmm = common_sim_openmm.Common_sim_openmm()
    anchor = toy_mmvt_model.anchors[0]
    system, topology, positions, box_vectors, num_frames \
        = common_sim_openmm.create_openmm_system(
        my_sim_openmm, toy_mmvt_model, anchor, frame=0)
    common_sim_openmm.add_platform(my_sim_openmm, toy_mmvt_model)
    assert my_sim_openmm.platform.getName() == "Reference"
    assert my_sim_openmm.properties == {}
Ejemplo n.º 4
0
def test_create_openmm_system(toy_mmvt_model, host_guest_mmvt_model):
    my_sim_openmm = common_sim_openmm.Common_sim_openmm()
    anchor = toy_mmvt_model.anchors[0]
    system, topology, positions, box_vectors, num_frames \
        = common_sim_openmm.create_openmm_system(
        my_sim_openmm, toy_mmvt_model, anchor, frame=0, load_state_file=None)
    assert num_frames == 2
    assert np.isclose(positions, np.array([[0.0, -0.7, 0.0]])\
                      *unit.nanometers).all()
    system2, topology2, positions2, box_vectors2, num_frames2 \
        = common_sim_openmm.create_openmm_system(
        my_sim_openmm, toy_mmvt_model, anchor, frame=1, load_state_file=None)
    assert np.isclose(positions2, np.array([[0.3, -0.7, 0.0]])\
                      *unit.nanometers).all()

    anchor2 = host_guest_mmvt_model.anchors[0]
    system3, topology3, positions3, box_vectors3, num_frames3 \
        = common_sim_openmm.create_openmm_system(
        my_sim_openmm, host_guest_mmvt_model, anchor2)
Ejemplo n.º 5
0
def test_add_platform_cuda(host_guest_mmvt_model):
    host_guest_mmvt_model.openmm_settings.cuda_platform_settings\
        .cuda_device_index = "2"
    my_sim_openmm = common_sim_openmm.Common_sim_openmm()
    anchor = host_guest_mmvt_model.anchors[0]
    system, topology, positions, box_vectors, num_frames \
        = common_sim_openmm.create_openmm_system(
        my_sim_openmm, host_guest_mmvt_model, anchor, frame=0)
    common_sim_openmm.add_platform(my_sim_openmm, host_guest_mmvt_model)
    assert my_sim_openmm.platform.getName() == "CUDA"
    assert my_sim_openmm.properties["CudaPrecision"] == "mixed"
    assert my_sim_openmm.properties["CudaDeviceIndex"] == "2"
Ejemplo n.º 6
0
def test_add_barostat(host_guest_mmvt_model_npt):
    my_sim_openmm = common_sim_openmm.Common_sim_openmm()
    anchor = host_guest_mmvt_model_npt.anchors[0]
    system, topology, positions, box_vectors, num_frames \
        = common_sim_openmm.create_openmm_system(
        my_sim_openmm, host_guest_mmvt_model_npt, anchor, frame=0)
    forces = system.getForces()
    old_force_len = len(forces)
    common_sim_openmm.add_barostat(system, host_guest_mmvt_model_npt)
    forces2 = system.getForces()
    assert len(forces2) == old_force_len + 1
    barostat = forces2[-1]
    pressure = barostat.getDefaultPressure()
    assert pressure == 1.0 * unit.bar
    temperature = barostat.getDefaultTemperature()
    assert temperature == 298.15 * unit.kelvin
Ejemplo n.º 7
0
def get_starting_structure_num_frames(model,
                                      anchor,
                                      dummy_outfile,
                                      load_state_file=None):
    """
    For an anchor's starting structure, find and return the number of frames.
    """
    if load_state_file is None:
        sim_openmm = MMVT_sim_openmm()
        sim_openmm.output_filename = dummy_outfile
        dummy_system, dummy_topology, dummy_positions, dummy_box_vectors, \
            num_frames = common_sim_openmm.create_openmm_system(
                sim_openmm, model, anchor)
    else:
        num_frames = 1

    return num_frames
Ejemplo n.º 8
0
def create_sim_openmm(model, anchor, output_filename, state_prefix=None):
    """
    Take all relevant model and anchor information and generate
    the necessary OpenMM objects to run the simulation.
    
    Parameters
    ----------
    model : Model()
        The Model which contains the anchor and all settings for
        the simulation that is about to be run.
        
    anchor : Anchor()
        The anchor object that this OpenMM simulation applies to.
        
    output_filename : str
        The name of the file that will be written by the plugin as
        the MMVT simulation proceeds, recording every 'bounce'.
        
    state_prefix : str or None
        The plugin can optionally save every state during a
        bounce. These can be used to seed simulations in other
        cells. This argument provides the file prefix for these
        saved states. If None, then no states will be written.
        
    Returns
    -------
    sim_openmm : Sim_openmm()
        The sim_openmm object, which contains everything needed
        to run an MMVT simulation within OpenMM.
        
    """
    sim_openmm = MMVT_sim_openmm()
    common_sim_openmm.fill_generic_parameters(sim_openmm, model, anchor,
                                              output_filename)
    system, topology, positions, box_vectors \
        = common_sim_openmm.create_openmm_system(sim_openmm, model, anchor)
    sim_openmm.system = system
    add_integrator(sim_openmm, model, state_prefix=state_prefix)
    common_sim_openmm.add_barostat(sim_openmm, model)
    common_sim_openmm.add_platform(sim_openmm, model)
    add_forces(sim_openmm, model, anchor)
    add_simulation(sim_openmm, model, topology, positions, box_vectors)
    return sim_openmm