Exemplo n.º 1
0
def test_mmvt_sim_namd_amber(tmp_path):

    mymodel = make_test_model.make_test_model(tmp_path, engine="namd")
    myanchor = mymodel.anchors[1]
    output_file = os.path.join(tmp_path, "output.txt")
    my_sim_openmm = mmvt_sim_namd.create_sim_namd(mymodel, myanchor,
                                                  output_file)
    return
Exemplo n.º 2
0
def test_mmvt_sim_namd_amber(tmp_path, host_guest_mmvt_model_namd):
    myanchor = host_guest_mmvt_model_namd.anchors[1]
    output_file = os.path.join(tmp_path, "output.txt")
    my_sim_openmm = mmvt_sim_namd.create_sim_namd(host_guest_mmvt_model_namd,
                                                  myanchor, output_file)
    assert my_sim_openmm.colvars_config is not None
    assert my_sim_openmm.seekr_namd_settings is not None
    return
Exemplo n.º 3
0
def run_namd(model, anchor_index, restart, total_simulation_length, 
                    cuda_device_index=False, force_overwrite=False,
                    save_state_file=False, save_state_boundaries=False,
                    namd_command="namd2", namd_arguments="", 
                    load_state_file=None):
    """Run a NAMD simulation."""
    import seekr2.modules.runner_namd as runner_namd
    import seekr2.modules.mmvt_sim_namd as mmvt_sim_namd
        
    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:
        old_num_production_steps = \
            model.calculation_settings.num_production_steps
        model.calculation_settings.num_production_steps = \
            total_simulation_length
    
    if model.calculation_settings.num_production_steps \
            < model.calculation_settings.restart_checkpoint_interval:
        model.calculation_settings.restart_checkpoint_interval \
            = model.calculation_settings.num_production_steps
        
    runner = runner_namd.Runner_namd(model, myanchor, namd_command, 
                                     namd_arguments)
    default_output_file, output_basename, state_file_prefix, restart_index \
        = runner.prepare(restart, save_state_file, save_state_boundaries, 
                         force_overwrite)
    
    if model.get_type() == "mmvt":
        sim_namd_obj = mmvt_sim_namd.create_sim_namd(
            model, myanchor, output_basename)
    else:
        raise Exception("Method not implemented for NAMD:", model.get_type())
    
    sim_namd_obj.seekr_namd_settings.save_state = save_state_file
    sim_namd_obj.seekr_namd_settings.save_one_state_for_all_boundaries\
         = runner.save_one_state_for_all_boundaries
    sim_namd_obj.seekr_namd_settings.check_state_interval\
         = runner.check_state_interval
    
    runner.run(sim_namd_obj, default_output_file, restart, load_state_file,
               restart_index)
    model.calculation_settings.num_production_steps = old_num_production_steps
Exemplo n.º 4
0
def test_Runner_namd_default(host_guest_mmvt_model):
    host_guest_mmvt_model.calculation_settings.num_production_steps = 10
    host_guest_mmvt_model.namd_settings = base.Namd_settings()
    myanchor = host_guest_mmvt_model.anchors[1]
    namd_command = "namd2"
    namd_arguments = ""
    runner = runner_namd.Runner_namd(host_guest_mmvt_model, myanchor,
                                     namd_command, namd_arguments)
    default_output_file, output_basename, state_file_prefix, restart_index = \
        runner.prepare()
    mmvt_output_filename = os.path.join(
        host_guest_mmvt_model.anchor_rootdir, myanchor.directory, "prod",
        "%s%d" % (mmvt_base.NAMDMMVT_BASENAME, 1))
    my_sim_namd = mmvt_sim_namd.create_sim_namd(host_guest_mmvt_model,
                                                myanchor, mmvt_output_filename)
    my_sim_namd.namd_root.periodic_boundary_conditions.PMEGridSpacing = None
    runner.run(my_sim_namd, mmvt_output_filename + ".out")
    myglob = mmvt_output_filename + ".out*"
    outfiles = glob.glob(myglob)
    outfile = outfiles[0]
    assert os.path.exists(outfile)
    return
Exemplo n.º 5
0
    assert anchor_index >= 0, "only positive indices allowed."
    try:
        myanchor = model.anchors[anchor_index]
    except IndexError:
        print("Invalid anchor index provided.")
        exit()

    if total_simulation_length is not None:
        model.namd_settings.total_simulation_length = \
            total_simulation_length
    runner = Runner_namd(model, myanchor, namd_command, namd_arguments)
    default_output_file, output_basename, state_file_prefix, restart_index \
        = runner.prepare(restart, save_state_file, force_overwrite)
    if output_file is None:
        output_file = default_output_file

    if model.get_type() == "mmvt":
        sim_namd_obj = mmvt_sim_namd.create_sim_namd(model, myanchor,
                                                     output_basename)
    else:
        raise Exception("Calculation type not supported for NAMD: {1}".format(
            model.get_type()))

    sim_namd_obj.seekr_namd_settings.save_state = save_state_file
    sim_namd_obj.seekr_namd_settings.save_one_state_for_all_boundaries\
         = runner.save_one_state_for_all_boundaries
    sim_namd_obj.seekr_namd_settings.check_state_interval\
         = runner.check_state_interval
    runner.run(sim_namd_obj, output_file, restart, load_state_file,
               restart_index)
Exemplo n.º 6
0
def test_Runner_namd_default(tmp_path):
    if not os.path.exists(tmp_path):
        os.mkdir(tmp_path)
    mymodel = make_test_model.make_test_model(tmp_path, engine="namd")
    #sim_namd_factory = sim_namd.Sim_namd_factory()
    myanchor = mymodel.anchors[1]
    mmvt_output_filename = os.path.join(
                    tmp_path, myanchor.name, "prod", 
                    "%s%d" % (mmvt_base.NAMDMMVT_BASENAME, 1))
    namd_command = "namd2"
    namd_arguments = ""
    runner = runner_namd.Runner_namd(mymodel, myanchor, namd_command, 
                                     namd_arguments)
    default_output_file, output_basename, state_file_prefix, restart_index = \
    runner.prepare()
    #sim_namd_factory = sim_namd.Sim_namd_factory()
    my_sim_namd = mmvt_sim_namd.create_sim_namd(mymodel, myanchor, 
                                                      mmvt_output_filename)
    my_sim_namd.namd_root.periodic_boundary_conditions.PMEGridSpacing = None
    print("PME turned off")
    runner.run(my_sim_namd, mmvt_output_filename+".out")
    myglob = mmvt_output_filename+".out*"
    outfiles = glob.glob(myglob)
    outfile = outfiles[0]
    assert os.path.exists(outfile)
    has_correct_line1 = False
    has_correct_line2 = False
    with open(outfile,"r") as f:
        for line in f:
            if re.search("^WallClock", line):
                has_correct_line1 = True
            if re.search("^WRITING", line):
                has_correct_line2 = True
    assert has_correct_line1 == True
    assert has_correct_line2 == True
    """
    namd_arguments = "+wtf"
    runner = runner_namd.Runner_namd(mymodel, myanchor, namd_command, 
                                     namd_arguments)
    default_output_file, output_basename, state_file_prefix, restart_index = \
    runner.prepare(force_overwrite=True)
    #sim_namd_factory = sim_namd.Sim_namd_factory()
    my_sim_namd = mmvt_sim_namd.create_sim_namd(mymodel, myanchor, 
                                                      mmvt_output_filename)
    runner.run(my_sim_namd, mmvt_output_filename+".out")
    myglob = mmvt_output_filename+".out*"
    outfiles = glob.glob(myglob)
    outfile = outfiles[0]
    assert os.path.exists(outfile)
    has_correct_line1 = False
    has_correct_line2 = False
    with open(outfile,"r") as f:
        for line in f:
            print("line:", line)
            
            if re.search("^WallClock", line):
                has_correct_line1 = True
            if re.search("^WRITING", line):
                has_correct_line2 = True
    
    with pytest.raises(Exception):
        assert has_correct_line1 == True
    with pytest.raises(Exception):
        assert has_correct_line2 == True
    """
    return