Пример #1
0
def run_temp(iter_index, json_file):
    iter_name = make_iter_name(iter_index)
    work_path = iter_name + "/" + temp_name + "/"

    fp = open(json_file, 'r')
    jdata = json.load(fp)
    gmx_prep = jdata["gmx_prep"]
    gmx_run = jdata["gmx_run"]
    temp_thread = jdata["temp_thread"]
    gmx_run = gmx_run + (" -nt %d " % temp_thread)
    gmx_prep_log = "gmx_grompp.log"
    gmx_run_log = "gmx_mdrun.log"
    gmx_run = gmx_run + " -plumed " + temp_plm
    gmx_prep_cmd = cmd_append_log(gmx_prep, gmx_prep_log)
    gmx_run_cmd = cmd_append_log(gmx_run, gmx_run_log)
    numb_walkers = jdata["numb_walkers"]

    all_task = glob.glob(work_path + "/[0-9]*[0-9]")
    all_task.sort()

    global exec_machine
    exec_hosts(MachineLocal, gmx_prep_cmd, 1, all_task, None)
    if len(all_task) == 1:
        exec_hosts(MachineLocal, gmx_run_cmd, temp_thread, all_task, None)
    else:
        exec_hosts_batch(exec_machine, gmx_run_cmd, temp_thread, all_task,
                         None)
Пример #2
0
def post_enhc(iter_index, json_file):
    iter_name = make_iter_name(iter_index)
    work_path = iter_name + "/" + enhc_name + "/"

    fp = open(json_file, 'r')
    jdata = json.load(fp)
    gmx_split = jdata["gmx_split_traj"]
    gmx_split_log = "gmx_split.log"
    gmx_split_cmd = cmd_append_log(gmx_split, gmx_split_log)

    all_task = glob.glob(work_path + "/[0-9]*[0-9]")
    all_task.sort()

    cwd = os.getcwd()
    numb_walkers = jdata["numb_walkers"]
    for ii in range(numb_walkers):
        walker_path = work_path + make_walker_name(ii) + "/"
        os.chdir(walker_path)
        if os.path.isdir("confs"):
            shutil.rmtree("confs")
        os.makedirs("confs")
        os.chdir(cwd)

    global exec_machine
    exec_hosts(MachineLocal, gmx_split_cmd, 1, all_task, None)

    for ii in range(numb_walkers):
        walker_path = work_path + make_walker_name(ii) + "/"
        angles = np.loadtxt(walker_path + enhc_out_plm)
        np.savetxt(walker_path + enhc_out_angle, angles[:, 1:], fmt="%.6f")
Пример #3
0
def run_enhc(iter_index, json_file):
    iter_name = make_iter_name(iter_index)
    work_path = iter_name + "/" + enhc_name + "/"

    fp = open(json_file, 'r')
    jdata = json.load(fp)
    gmx_prep = jdata["gmx_prep"]
    gmx_run = jdata["gmx_run"]
    enhc_thread = jdata["bias_thread"]
    gmx_run = gmx_run + (" -nt %d " % enhc_thread)
    gmx_prep_log = "gmx_grompp.log"
    gmx_run_log = "gmx_mdrun.log"
    # assuming at least one walker
    graph_files = glob.glob(work_path + (make_walker_name(0)) + "/*.pb")
    if len(graph_files) != 0:
        gmx_run = gmx_run + " -plumed " + enhc_plm
    else:
        gmx_run = gmx_run + " -plumed " + enhc_bf_plm
    gmx_prep_cmd = cmd_append_log(gmx_prep, gmx_prep_log)
    gmx_run_cmd = cmd_append_log(gmx_run, gmx_run_log)
    numb_walkers = jdata["numb_walkers"]
    batch_jobs = jdata['batch_jobs']
    batch_time_limit = jdata['batch_time_limit']
    batch_modules = jdata['batch_modules']
    batch_sources = jdata['batch_sources']

    all_task = glob.glob(work_path + "/[0-9]*[0-9]")
    all_task.sort()

    global exec_machine
    exec_hosts(MachineLocal, gmx_prep_cmd, 1, all_task, None)
    if batch_jobs:
        exec_batch(gmx_run_cmd,
                   enhc_thread,
                   1,
                   all_task,
                   task_args=None,
                   time_limit=batch_time_limit,
                   modules=batch_modules,
                   sources=batch_sources)
    else:
        if len(all_task) == 1:
            exec_hosts(MachineLocal, gmx_run_cmd, enhc_thread, all_task, None)
        else:
            exec_hosts_batch(exec_machine, gmx_run_cmd, enhc_thread, all_task,
                             None)
Пример #4
0
def post_temp(iter_index, json_file):
    iter_name = make_iter_name(iter_index)
    work_path = iter_name + "/" + temp_name + "/"

    fp = open(json_file, 'r')
    jdata = json.load(fp)
    gmx_split = jdata["gmx_split_traj"]
    gmx_split_log = "gmx_split.log"
    gmx_split_cmd = cmd_append_log(gmx_split, gmx_split_log)
    temp_test_intvl = jdata['temp_test_intvl']
    dev_trust_lvl = jdata['dev_trust_lvl']
    temp_incr_ratio = jdata['temp_incr_ratio']
    temp_decr_ratio = jdata['temp_decr_ratio']
    temp_incr_lvl = jdata['temp_incr_lvl']
    temp_decr_lvl = jdata['temp_decr_lvl']
    phys_temp = jdata['phys_temp']
    max_temp = jdata['max_temp']

    all_task = glob.glob(work_path + "/[0-9]*[0-9]")
    all_task.sort()

    cwd = os.getcwd()
    numb_walkers = jdata["numb_walkers"]
    for ii in range(numb_walkers):
        walker_path = work_path + make_walker_name(ii) + "/"
        os.chdir(walker_path)
        if os.path.isdir("confs"):
            shutil.rmtree("confs")
        os.makedirs("confs")
        os.chdir(cwd)

    global exec_machine
    exec_hosts(MachineLocal, gmx_split_cmd, 1, all_task, None)

    walker_stop_flags = []
    for ii in range(numb_walkers):
        walker_path = work_path + make_walker_name(ii) + "/"
        angles = np.loadtxt(walker_path + temp_out_plm)
        angles = angles[:, 1:]
        np.savetxt(walker_path + temp_out_angle, angles, fmt="%.6f")
        graph_files = glob.glob(walker_path + "/*.pb")
        cur_temp = np.loadtxt(os.path.join(walker_path, 'cur.temp'))
        if len(graph_files) != 0:
            next_temp, dec_list, model_dev\
                = make_next_temp(graph_files,
                                 cur_temp,
                                 angles,
                                 temp_test_intvl,
                                 dev_trust_lvl,
                                 temp_incr_ratio,
                                 temp_decr_ratio,
                                 temp_incr_lvl,
                                 temp_decr_lvl,
                                 phys_temp,
                                 max_temp)
            model_dev = np.concatenate(
                (angles, np.reshape(model_dev, [-1, 1])), axis=1)
            np.savetxt(os.path.join(walker_path, 'model.devi'), model_dev)
            np.savetxt(os.path.join(walker_path, 'dec_list'), dec_list)
        else:
            next_temp = cur_temp
        np.savetxt(os.path.join(walker_path, 'next.temp'), [next_temp])

        if cur_temp == max_temp and next_temp == max_temp:
            walker_stop_flags.append(True)
        else:
            walker_stop_flags.append(False)

    # return if the iteration continues
    if all(walker_stop_flags):
        return False
    else:
        return True
Пример #5
0
def run_enhc(iter_index, json_file):
    iter_name = make_iter_name(iter_index)
    work_path = iter_name + "/" + enhc_name + "/"

    fp = open(json_file, 'r')
    jdata = json.load(fp)
    bPosre = jdata.get("gmx_posre", False)
    gmx_prep = jdata["gmx_prep"]
    if bPosre:
        gmx_prep += " -f grompp_restraint.mdp -r conf_init.gro"
    gmx_run = jdata["gmx_run"]
    enhc_thread = jdata["bias_thread"]
    gmx_run = gmx_run + (" -nt %d " % enhc_thread)
    gmx_prep_log = "gmx_grompp.log"
    gmx_run_log = "gmx_mdrun.log"
    # assuming at least one walker
    graph_files = glob.glob(work_path + (make_walker_name(0)) + "/*.pb")
    if len(graph_files) != 0:
        gmx_run = gmx_run + " -plumed " + enhc_plm
    else:
        gmx_run = gmx_run + " -plumed " + enhc_bf_plm
    gmx_prep_cmd = cmd_append_log(gmx_prep, gmx_prep_log)
    gmx_run_cmd = cmd_append_log(gmx_run, gmx_run_log)
    numb_walkers = jdata["numb_walkers"]
    batch_jobs = jdata['batch_jobs']
    batch_time_limit = jdata['batch_time_limit']
    batch_modules = jdata['batch_modules']
    batch_sources = jdata['batch_sources']

    # print('debug', glob.glob(work_path + "/[0-9]*[0-9]"))
    # all_task = glob.glob(work_path + "/[0-9]*[0-9]")
    all_task = list(
        filter(lambda x: os.path.isdir(x),
               glob.glob(work_path + "/[0-9]*[0-9]")))
    all_task.sort()

    # all_task_basedir = [os.path.relpath(ii, work_path) for ii in all_task]
    # print('run_enhc:work_path', work_path)
    # print('run_enhc:gmx_prep_cmd:', gmx_prep_cmd)
    # print('run_enhc:gmx_run_cmd:', gmx_run_cmd)
    # print('run_enhc:all_task:', all_task)
    # print('run_enhc:all_task_basedir:', all_task_basedir)
    # print('run_enhc:batch_jobs:', batch_jobs)
    #
    # lazy_local_context = LazyLocalContext(local_root='./', work_profile=None)
    # # pbs = PBS(context=lazy_local_context)
    # slurm = Slurm(context=lazy_local_context)
    # gmx_prep_task = [Task(command=gmx_prep_cmd, task_work_path=ii, outlog='gmx_grompp.log', errlog='gmx_grompp.err') for
    #                  ii in all_task_basedir]
    # gmx_prep_submission = Submission(work_base=work_path, resources=resources, batch=slurm, task_list=gmx_prep_task)
    #
    # gmx_prep_submission.run_submission()
    #
    # gmx_run_task = [Task(command=gmx_run_cmd, task_work_path=ii, outlog='gmx_mdrun.log', errlog='gmx_mdrun.log') for ii
    #                 in all_task_basedir]
    # gmx_run_submission = Submission(work_base=work_path, resources=resources, batch=slurm, task_list=gmx_run_task)
    # gmx_run_submission.run_submission()

    global exec_machine
    exec_hosts(MachineLocal, gmx_prep_cmd, 1, all_task, None)
    if batch_jobs:
        exec_batch(gmx_run_cmd,
                   enhc_thread,
                   1,
                   all_task,
                   task_args=None,
                   time_limit=batch_time_limit,
                   modules=batch_modules,
                   sources=batch_sources)
    else:
        if len(all_task) == 1:
            exec_hosts(MachineLocal, gmx_run_cmd, enhc_thread, all_task, None)
        else:
            exec_hosts_batch(exec_machine, gmx_run_cmd, enhc_thread, all_task,
                             None)