Example #1
0
File: run.py Project: obaica/dpgen
def run_task(json_file, machine_file):
    with open(json_file, 'r') as fp:
        jdata = json.load(fp)
    with open(machine_file, 'r') as fp:
        mdata = json.load(fp)

    record = "record.auto_test"

    model_devi_mdata = decide_model_devi_machine(mdata)
    model_devi_machine = model_devi_mdata['model_devi_machine']
    if ('machine_type' in model_devi_machine) and  \
       (model_devi_machine['machine_type'] == 'ucloud'):
        model_devi_ssh_sess = None
    else:
        model_devi_ssh_sess = SSHSession(model_devi_machine)

    fp_mdata = decide_fp_machine(mdata)
    fp_machine = fp_mdata['fp_machine']
    if ('machine_type' in fp_machine) and  \
       (fp_machine['machine_type'] == 'ucloud'):
        fp_ssh_sess = None
    else:
        fp_ssh_sess = SSHSession(fp_machine)

    confs = jdata['conf_dir']
    ele_list = [key for key in jdata['potcar_map'].keys()]
    key_id = jdata['key_id']

    ii = jdata['task_type']
    jj = jdata['task']
    task_list = [
        'equi', 'eos', 'elastic', 'vacancy', 'interstitial', 'surf', 'phonon',
        'all'
    ]
    task_type_list = ['vasp'] + lammps_task_type
    if jj not in task_list:
        raise RuntimeError("unknow task %s, something wrong" % jj)
    if ii not in task_type_list:
        raise RuntimeError("unknow task type %s, something wrong" % ii)

    #gen_configuration
    if 'confs' in confs and (not os.path.exists(confs + '/POSCAR')):
        print('generate %s' % (ele_list))
        if len(ele_list) == 1:
            gen_confs.gen_element(ele_list[0], key_id)
        else:
            gen_confs.gen_alloy(ele_list, key_id)
    #default task
    log_iter("gen_equi", ii, "equi")
    gen_equi(ii, jdata, mdata)
    log_iter("run_equi", ii, "equi")
    run_equi(ii, jdata, mdata, model_devi_ssh_sess)
    log_iter("cmpt_equi", ii, "equi")
    cmpt_equi(ii, jdata, mdata)
    if jj == "eos" or jj == "all":
        log_iter("gen_eos", ii, "eos")
        gen_eos(ii, jdata, mdata)
        log_iter("run_eos", ii, "eos")
        run_eos(ii, jdata, mdata, model_devi_ssh_sess)
        log_iter("cmpt_eos", ii, "eos")
        cmpt_eos(ii, jdata, mdata)
    if jj == "elastic" or jj == "all":
        log_iter("gen_elastic", ii, "elastic")
        gen_elastic(ii, jdata, mdata)
        log_iter("run_elastic", ii, "elastic")
        run_elastic(ii, jdata, mdata, model_devi_ssh_sess)
        log_iter("cmpt_elastic", ii, "elastic")
        cmpt_elastic(ii, jdata, mdata)
    if jj == "vacancy" or jj == "all":
        log_iter("gen_vacancy", ii, "vacancy")
        gen_vacancy(ii, jdata, mdata)
        log_iter("run_vacancy", ii, "vacancy")
        run_vacancy(ii, jdata, mdata, model_devi_ssh_sess)
        log_iter("cmpt_vacancy", ii, "vacancy")
        cmpt_vacancy(ii, jdata, mdata)
    if jj == "interstitial" or jj == "all":
        log_iter("gen_interstitial", ii, "interstitial")
        gen_interstitial(ii, jdata, mdata)
        log_iter("run_interstitial", ii, "interstitial")
        run_interstitial(ii, jdata, mdata, model_devi_ssh_sess)
        log_iter("cmpt_interstitial", ii, "interstitial")
        cmpt_interstitial(ii, jdata, mdata)
    if jj == "surf" or jj == "all":
        log_iter("gen_surf", ii, "surf")
        gen_surf(ii, jdata, mdata)
        log_iter("run_surf", ii, "surf")
        run_surf(ii, jdata, mdata, model_devi_ssh_sess)
        log_iter("cmpt_surf", ii, "surf")
        cmpt_surf(ii, jdata, mdata)
    '''
    if jj=="phonon":
        log_iter ("gen_phonon", ii, "phonon")
        gen_phonon (ii, jdata, mdata) 
        log_iter ("run_phonon", ii, "phonon")
        run_phonon  (ii, jdata, mdata,model_devi_ssh_sess)
        log_iter ("cmpt_phonon", ii, "phonon")
        cmpt_phonon (ii, jdata, mdata)
    '''
    record_iter(record, confs, ii, jj)
Example #2
0
def run_task (json_file, machine_file) :
    with open (json_file, 'r') as fp :
        jdata = json.load (fp)
    with open (machine_file, 'r') as fp:
        mdata = json.load (fp)

    record = "record.auto_test"

    confs = jdata['conf_dir']
    ele_list=[key for key in jdata['potcar_map'].keys()]
    key_id = jdata['key_id']

    ii = jdata['task_type']
    jj=jdata['task']
    task_list=['equi','eos','elastic','vacancy','interstitial','surf','phonon']

    if isinstance(jj,str):
       if jj=='all':
          all_task_list=task_list.copy()
       else:
          try:
             assert jj in task_list
          except AssertionError:
             raise RuntimeError ("unknow task %s, something wrong" % jj)
          all_task_list=[jj]
    elif isinstance(jj,list):
       try:
          assert set(jj).issubset(set(task_list))
       except AssertionError:
          raise RuntimeError ("unknow task %s, some tasks may not supported" % ' '.join(jj))
       all_task_list=jj.copy()
    else:
       raise RuntimeError ('unknow format for task, it must be a string or list')

    task_type_list=['vasp']+lammps_task_type
    #if jj not in task_list :
    #    raise RuntimeError ("unknow task %s, something wrong" % jj)
    if ii not in task_type_list :
        raise RuntimeError ("unknow task type %s, something wrong" % ii)

    #gen_configuration
    if 'confs' in confs and (not os.path.exists(confs+'/POSCAR')) :
        print('generate %s' % (ele_list))
        if len(ele_list) == 1 :
                gen_confs.gen_element(ele_list[0],key_id)
        else :
                gen_confs.gen_alloy(ele_list,key_id)
    #default task
    # log_iter ("gen_equi", ii, "equi")
    # gen_equi (ii, jdata, mdata)
    # log_iter ("run_equi", ii, "equi")
    # run_equi  (ii, jdata, mdata)
    # log_iter ("cmpt_equi", ii,"equi")
    # cmpt_equi (ii, jdata, mdata)
    for jj in all_task_list:
        if jj == "equi":
            log_iter ("gen_equi", ii, "equi")
            gen_equi (ii, jdata, mdata)
            log_iter ("run_equi", ii, "equi")
            run_equi  (ii, jdata, mdata)
            log_iter ("cmpt_equi", ii,"equi")
            cmpt_equi (ii, jdata, mdata)
        if jj == "eos":
            log_iter ("gen_eos", ii, "eos")
            gen_eos (ii, jdata, mdata)
            log_iter ("run_eos", ii, "eos")
            run_eos  (ii, jdata, mdata)
            log_iter ("cmpt_eos", ii, "eos")
            cmpt_eos (ii, jdata, mdata)
        if jj=="elastic":
            log_iter ("gen_elastic", ii, "elastic")
            gen_elastic (ii, jdata, mdata)
            log_iter ("run_elastic", ii, "elastic")
            run_elastic  (ii, jdata, mdata)
            log_iter ("cmpt_elastic", ii, "elastic")
            cmpt_elastic (ii, jdata, mdata)
        if jj=="vacancy":
            log_iter ("gen_vacancy", ii, "vacancy")
            gen_vacancy (ii, jdata, mdata)
            log_iter ("run_vacancy", ii, "vacancy")
            run_vacancy  (ii, jdata, mdata)
            log_iter ("cmpt_vacancy", ii, "vacancy")
            cmpt_vacancy (ii, jdata, mdata)
        if jj=="interstitial":
            log_iter ("gen_interstitial", ii, "interstitial")
            gen_interstitial (ii, jdata, mdata)
            log_iter ("run_interstitial", ii, "interstitial")
            run_interstitial  (ii, jdata, mdata)
            log_iter ("cmpt_interstitial", ii, "interstitial")
            cmpt_interstitial (ii, jdata, mdata)
        if jj=="surf":
            log_iter ("gen_surf", ii, "surf")
            gen_surf (ii, jdata, mdata)
            log_iter ("run_surf", ii, "surf")
            run_surf  (ii, jdata, mdata)
            log_iter ("cmpt_surf", ii, "surf")
            cmpt_surf (ii, jdata, mdata)
        
        # if jj=="phonon":
        #     log_iter ("gen_phonon", ii, "phonon")
        #     gen_phonon (ii, jdata, mdata)
        #     log_iter ("run_phonon", ii, "phonon")
        #     run_phonon  (ii, jdata, mdata)
        #     log_iter ("cmpt_phonon", ii, "phonon")
        #     cmpt_phonon (ii, jdata, mdata)
        
        record_iter (record, confs, ii, jj)