Exemplo n.º 1
0
def run_res (iter_index,
             json_file, 
             exec_machine = MachineLocal) :
    fp = open (json_file, 'r')
    jdata = json.load (fp)
    gmx_prep = jdata["gmx_prep"]
    gmx_run = jdata["gmx_run"]
    res_thread = jdata["res_thread"]
    gmx_run = gmx_run + (" -nt %d " % res_thread)
    gmx_run = gmx_run + " -plumed " + res_plm
    gmx_cont_run = gmx_run + " -cpi state.cpt "
    gmx_prep_log = "gmx_grompp.log"
    gmx_run_log = "gmx_mdrun.log"
    gmx_prep_cmd = cmd_append_log (gmx_prep, gmx_prep_log)
    gmx_run_cmd = cmd_append_log (gmx_run, gmx_run_log)
    gmx_cont_run_cmd = cmd_append_log (gmx_cont_run, gmx_run_log)
    res_group_size = jdata['res_group_size']
    batch_jobs = jdata['batch_jobs']
    batch_time_limit = jdata['batch_time_limit']
    batch_modules = jdata['batch_modules']
    batch_sources = jdata['batch_sources']
    
    iter_name = make_iter_name (iter_index)
    res_path = iter_name + "/" + res_name + "/"  
    base_path = os.getcwd() + "/"

    if not os.path.isdir (res_path) : 
        raise RuntimeError ("do not see any restrained simulation (%s)." % res_path)

    all_task_propose = glob.glob(res_path + "/[0-9]*[0-9]")
    if len(all_task_propose) == 0 :
        return
    all_task_propose.sort()
    if batch_jobs :
        all_task = all_task_propose
    else :
        all_task = []
        all_cont_task = []
        for ii in all_task_propose :
            if not os.path.isfile(os.path.join(ii, "confout.gro")) :
                if os.path.isfile(os.path.join(ii, "state.cpt")) :
                    all_cont_task.append(ii)
                else :
                    all_task.append(ii)

    if batch_jobs:
        exec_hosts (MachineLocal, gmx_prep_cmd, 1, all_task, None)
        exec_batch_group(gmx_run_cmd, res_thread, 1, all_task, task_args = None, group_size = res_group_size, time_limit = batch_time_limit, modules = batch_modules, sources = batch_sources)
    else :
        if len(all_task) == 1 :
            exec_hosts (MachineLocal, gmx_prep_cmd, 1, all_task, None)
            exec_hosts (MachineLocal, gmx_run_cmd, res_thread, all_task, None)
        elif len(all_task) > 1 :
            exec_hosts (MachineLocal, gmx_prep_cmd, 1, all_task, None)
            exec_hosts_batch (exec_machine, gmx_run_cmd, res_thread, all_task, None)
        if len(all_cont_task) == 1 :
            exec_hosts (MachineLocal, gmx_cont_run_cmd, res_thread, all_cont_task, None)
        elif len(all_cont_task) > 1 :
            exec_hosts_batch (exec_machine, gmx_cont_run_cmd, res_thread, all_cont_task, None)
Exemplo n.º 2
0
def run_res(iter_index, json_file, exec_machine=MachineLocal):
    fp = open(json_file, 'r')
    jdata = json.load(fp)
    cmd_env = jdata.get("cmd_sources", [])
    sits_param = jdata.get("sits_settings", None)
    gmx_prep = jdata["gmx_prep"]
    bPosre = jdata.get("gmx_posre", False)
    if sits_param is not None:
        if not bPosre:
            gmx_prep += " -f grompp_sits.mdp"
        else:
            gmx_prep += " -f grompp_sits_restraint.mdp -r conf_init.gro"
        if sits_param.get("sits_energrp", None) not in ["Protein", "MOL"]:
            gmx_prep += " -n index.ndx"
    gmx_run = jdata["gmx_run"]
    res_thread = jdata["res_thread"]
    gmx_run = gmx_run + (" -nt %d " % res_thread)
    gmx_run = gmx_run + " -plumed " + res_plm
    gmx_cont_run = gmx_run + " -cpi state.cpt "
    gmx_prep_log = "gmx_grompp.log"
    gmx_run_log = "gmx_mdrun.log"
    gmx_prep_cmd = cmd_append_log(gmx_prep, gmx_prep_log, env=cmd_env)
    gmx_run_cmd = cmd_append_log(gmx_run, gmx_run_log, env=cmd_env)
    gmx_cont_run_cmd = cmd_append_log(gmx_cont_run, gmx_run_log, env=cmd_env)
    res_group_size = jdata['res_group_size']
    batch_jobs = jdata['batch_jobs']
    batch_time_limit = jdata['batch_time_limit']
    batch_modules = jdata['batch_modules']
    batch_sources = jdata['batch_sources']

    iter_name = make_iter_name(iter_index)
    res_path = iter_name + "/" + res_name + "/"
    base_path = os.getcwd() + "/"

    if not os.path.isdir(res_path):
        raise RuntimeError("do not see any restrained simulation (%s)." %
                           res_path)

    # all_task_propose = glob.glob(res_path + "/[0-9]*[0-9]")
    # assume that
    # TODO
    all_task_propose = list(
        filter(lambda x: os.path.isdir(x),
               glob.glob(res_path + "/[0-9]*[0-9]")))
    # print('lib.modeling.run_res:all_task_propose:', all_task)
    # print('lib.modeling.run_res:gmx_prep_cmd:', gmx_prep_cmd)
    # print('lib.modeling.run_res:gmx_run_cmd:', gmx_run_cmd)
    # print('lib.modeling.run_res:gmx_cont_run_cmd:', gmx_cont_run_cmd)
    # raise RuntimeError('lib.modeling.run_res:debug')

    if len(all_task_propose) == 0:
        return
    all_task_propose.sort()
    if batch_jobs:
        all_task = all_task_propose
    else:
        all_task = []
        all_cont_task = []
        for ii in all_task_propose:
            if not os.path.isfile(os.path.join(ii, "confout.gro")):
                if os.path.isfile(os.path.join(ii, "state.cpt")):
                    all_cont_task.append(ii)
                else:
                    all_task.append(ii)
    # if len(all_task) == 0:
    #     return None
    # all_task.sort()

    # all_task_basedir = [os.path.relpath(ii, res_path) for ii in all_task]
    # lazy_local_context = LazyLocalContext(local_root='./', work_profile=None)
    # slurm = Slurm(context=lazy_local_context)
    # # pbs = PBS(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=res_path, resources=res_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=res_path, resources=res_resources, batch=slurm, task_list=gmx_run_task)
    # gmx_run_submission.run_submission()

    if batch_jobs:
        exec_hosts(MachineLocal, gmx_prep_cmd, 1, all_task, None)
        exec_batch_group(gmx_run_cmd,
                         res_thread,
                         1,
                         all_task,
                         task_args=None,
                         group_size=res_group_size,
                         time_limit=batch_time_limit,
                         modules=batch_modules,
                         sources=batch_sources)
    else:
        if len(all_task) == 1:
            exec_hosts(MachineLocal, gmx_prep_cmd, 1, all_task, None)
            exec_hosts(MachineLocal, gmx_run_cmd, res_thread, all_task, None)
        elif len(all_task) > 1:
            exec_hosts(MachineLocal, gmx_prep_cmd, 1, all_task, None)
            exec_hosts_batch(exec_machine, gmx_run_cmd, res_thread, all_task,
                             None)
        if len(all_cont_task) == 1:
            exec_hosts(MachineLocal, gmx_cont_run_cmd, res_thread,
                       all_cont_task, None)
        elif len(all_cont_task) > 1:
            exec_hosts_batch(exec_machine, gmx_cont_run_cmd, res_thread,
                             all_cont_task, None)