Esempio n. 1
0
 def post_process(self, task_list):
     cwd = os.getcwd()
     poscar_start = os.path.abspath(
         os.path.join(task_list[0], '..', 'POSCAR'))
     os.chdir(os.path.join(task_list[0], '..'))
     if os.path.isfile(os.path.join(task_list[0], 'INCAR')):
         incar = incar_upper(
             Incar.from_file(os.path.join(task_list[0], 'INCAR')))
         kspacing = incar.get('KSPACING')
         kgamma = incar.get('KGAMMA', False)
         ret = vasp.make_kspacing_kpoints(poscar_start, kspacing, kgamma)
         kp = Kpoints.from_string(ret)
         if os.path.isfile('KPOINTS'):
             os.remove('KPOINTS')
         kp.write_file("KPOINTS")
         os.chdir(cwd)
         kpoints_universal = os.path.abspath(
             os.path.join(task_list[0], '..', 'KPOINTS'))
         for ii in task_list:
             if os.path.isfile(os.path.join(ii, 'KPOINTS')):
                 os.remove(os.path.join(ii, 'KPOINTS'))
             if os.path.islink(os.path.join(ii, 'KPOINTS')):
                 os.remove(os.path.join(ii, 'KPOINTS'))
             os.chdir(ii)
             os.symlink(os.path.relpath(kpoints_universal), 'KPOINTS')
     os.chdir(cwd)
Esempio n. 2
0
def make_vasp_kpoints_from_incar(work_dir, jdata):
    cwd = os.getcwd()
    fp_aniso_kspacing = jdata.get('fp_aniso_kspacing')
    os.chdir(work_dir)
    # get kspacing and kgamma from incar
    assert (os.path.exists('INCAR'))
    with open('INCAR') as fp:
        incar = fp.read()
    standard_incar = incar_upper(Incar.from_string(incar))
    if fp_aniso_kspacing is None:
        try:
            kspacing = standard_incar['KSPACING']
        except KeyError:
            raise RuntimeError("KSPACING must be given in INCAR")
    else:
        kspacing = fp_aniso_kspacing
    try:
        gamma = standard_incar['KGAMMA']
        if isinstance(gamma, bool):
            pass
        else:
            if gamma[0].upper() == "T":
                gamma = True
            else:
                gamma = False
    except KeyError:
        raise RuntimeError("KGAMMA must be given in INCAR")
    # check poscar
    assert (os.path.exists('POSCAR'))
    # make kpoints
    ret = make_kspacing_kpoints('POSCAR', kspacing, gamma)
    kp = Kpoints.from_string(ret)
    kp.write_file("KPOINTS")
    os.chdir(cwd)
Esempio n. 3
0
 def test_make_input_file_3(self):
     param = self.task_param.copy()
     param["cal_setting"] = {
         "relax_pos": True,
         "relax_shape": False,
         "relax_vol": False
     }
     self.VASP.make_input_file(self.equi_path, 'relaxation', param)
     incar = incar_upper(
         Incar.from_file(os.path.join(self.equi_path, "INCAR")))
     self.assertTrue(incar['ISIF'], 2)
Esempio n. 4
0
 def test_make_input_file_2(self):
     self.VASP.make_input_file(self.equi_path, 'relaxation',
                               self.task_param)
     self.assertTrue(
         os.path.isfile(os.path.join(self.equi_path, "task.json")))
     self.assertTrue(os.path.isfile(os.path.join(self.equi_path,
                                                 "KPOINTS")))
     self.assertTrue(os.path.isfile(os.path.join(self.equi_path, "INCAR")))
     incar = incar_upper(
         Incar.from_file(os.path.join(self.equi_path, "INCAR")))
     self.assertTrue(incar['ISIF'], 3)
Esempio n. 5
0
def gen_init_bulk(args) :
    try:
       import ruamel
       from monty.serialization import loadfn,dumpfn
       warnings.simplefilter('ignore', ruamel.yaml.error.MantissaNoDotYAML1_1Warning)
       jdata=loadfn(args.PARAM)
       if args.MACHINE is not None:
          mdata=loadfn(args.MACHINE)
    except:
       with open (args.PARAM, 'r') as fp :
           jdata = json.load (fp)
       if args.MACHINE is not None:
          with open (args.MACHINE, "r") as fp:
              mdata = json.load(fp)

    if args.MACHINE is not None:
       # Selecting a proper machine
       mdata = decide_fp_machine(mdata)
       #disp = make_dispatcher(mdata["fp_machine"])

    # Decide work path
    out_dir = out_dir_name(jdata)
    jdata['out_dir'] = out_dir
    dlog.info ("# working dir %s" % out_dir)
    # Decide whether to use a given poscar
    from_poscar = False 
    if 'from_poscar' in jdata :
        from_poscar = jdata['from_poscar']
    # Verify md_nstep
    md_nstep_jdata = jdata["md_nstep"]
    try:
        md_incar = jdata['md_incar']
        if os.path.isfile(md_incar):
            standard_incar = incar_upper(Incar.from_file(md_incar))
            nsw_flag = False
            if "NSW" in standard_incar:
                    nsw_flag = True
                    nsw_steps = standard_incar['NSW']
            #dlog.info("nsw_steps is", nsw_steps)
            #dlog.info("md_nstep_jdata is", md_nstep_jdata)
            if nsw_flag:
                if (nsw_steps != md_nstep_jdata):
                    dlog.info("WARNING: your set-up for MD steps in PARAM and md_incar are not consistent!")
                    dlog.info("MD steps in PARAM is %d"%(md_nstep_jdata))
                    dlog.info("MD steps in md_incar is %d"%(nsw_steps))
                    dlog.info("DP-GEN will use settings in md_incar!")
                    jdata['md_nstep'] = nsw_steps
    except KeyError:
        pass
    ## correct element name 
    temp_elements = []
    for ele in jdata['elements']:
        temp_elements.append(ele[0].upper() + ele[1:])
    jdata['elements'] = temp_elements
    dlog.info("Elements are %s"% ' '.join(jdata['elements']))

    ## Iteration 
    stage_list = [int(i) for i in jdata['stages']]
    for stage in stage_list:
        if stage == 1 :
            dlog.info("Current stage is 1, relax")
            create_path(out_dir)
            shutil.copy2(args.PARAM, os.path.join(out_dir, 'param.json'))
            if from_poscar :
                make_super_cell_poscar(jdata)
            else :
                make_unit_cell(jdata)
                make_super_cell(jdata)
                place_element(jdata)
            if args.MACHINE is not None:
               make_vasp_relax(jdata, mdata)
               run_vasp_relax(jdata, mdata)
            else:
               make_vasp_relax(jdata, {"fp_resources":{}})
        elif stage == 2 :
            dlog.info("Current stage is 2, perturb and scale")
            make_scale(jdata)
            pert_scaled(jdata)
        elif stage == 3 :
            dlog.info("Current stage is 3, run a short md")
            make_vasp_md(jdata)
            if args.MACHINE is not None:
               run_vasp_md(jdata, mdata)
        elif stage == 4 :
            dlog.info("Current stage is 4, collect data")
            coll_vasp_md(jdata)
        else :
            raise RuntimeError("unknown stage %d" % stage)
Esempio n. 6
0
def make_vasp(jdata, conf_dir) :
    vol_start = jdata['vol_start']
    vol_end = jdata['vol_end']
    vol_step = jdata['vol_step']
    eos_relax_cell_shape = jdata.get('eos_relax_cell_shape', True)
    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')

    if 'relax_incar' in jdata.keys():
        vasp_str='vasp-relax_incar'
    else:
        kspacing = jdata['vasp_params']['kspacing']
        vasp_str='vasp-k%.2f' % kspacing

    # get equi poscar
    equi_path = re.sub('confs', global_equi_name, conf_path)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_contcar = os.path.join(equi_path, 'CONTCAR')
    task_path = re.sub('confs', global_task_name, conf_path)
    task_path = os.path.join(task_path, vasp_str)
    os.makedirs(task_path, exist_ok = True)    
    # link poscar
    cwd = os.getcwd()
    from_poscar = os.path.join(equi_contcar)
    to_poscar = os.path.join(task_path, 'POSCAR')
    if os.path.exists(to_poscar) :
        assert(filecmp.cmp(from_poscar, to_poscar))
    else :
        os.chdir(task_path)
        os.symlink(os.path.relpath(from_poscar), 'POSCAR')
        os.chdir(cwd)
    vol_to_poscar = vasp.poscar_vol(to_poscar) / vasp.poscar_natoms(to_poscar)
    # print(to_poscar, vol_to_poscar)
    is_alloy = \
               os.path.exists(
                   os.path.join(
                       os.path.join(conf_path, '..'),
                       'alloy'
                   )
               )  
    # read potcar
    with open(to_poscar,'r') as fp :
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list :
        assert os.path.exists(os.path.abspath(potcar_map[ii])),"No POTCAR in the potcar_map of %s"%(ii)
        potcar_list.append(os.path.abspath(potcar_map[ii]))

    # gen incar
    if  'relax_incar' in jdata.keys():
        relax_incar_path = jdata['relax_incar']
        assert(os.path.exists(relax_incar_path))
        relax_incar_path = os.path.abspath(relax_incar_path)
        incar = incar_upper(Incar.from_file(relax_incar_path))
        if eos_relax_cell_shape:
            isif = 4
        else:
            isif = 2
        if incar.get('ISIF') != isif:
            dlog.info("%s:%s setting ISIF to %d" % (__file__, make_vasp.__name__, isif))
            incar['ISIF'] = isif
        fc = incar.get_string()
        kspacing = incar['KSPACING']
        kgamma = incar['KGAMMA']
    else :
        fp_params = jdata['vasp_params']
        ecut = fp_params['ecut']
        ediff = fp_params['ediff']
        npar = fp_params['npar']
        kpar = fp_params['kpar']
        kspacing = fp_params['kspacing']
        kgamma = fp_params['kgamma']
        fc = vasp.make_vasp_relax_incar(ecut, ediff, is_alloy,  True, False, npar, kpar, kspacing, kgamma)

    os.chdir(task_path)

    with open('INCAR', 'w') as fp :
        fp.write(fc)
    # gen potcar
    with open('POTCAR', 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    # loop over volumes
    for vol in np.arange(vol_start, vol_end, vol_step) :
        vol_path = os.path.join(task_path, 'vol-%.2f' % vol)        
        os.makedirs(vol_path, exist_ok = True)
        os.chdir(vol_path)
        for ii in ['INCAR', 'POTCAR', 'POSCAR.orig', 'POSCAR'] :
            if os.path.exists(ii) :
                os.remove(ii)
        # link incar, potcar
        os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR')
        os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')), 'POTCAR')
        # gen poscar
        os.symlink(os.path.relpath(to_poscar), 'POSCAR.orig')
        scale = (vol / vol_to_poscar) ** (1./3.)
        # print(scale)
        vasp.poscar_scale('POSCAR.orig', 'POSCAR', scale)
        # print(vol_path, vasp.poscar_vol('POSCAR') / vasp.poscar_natoms('POSCAR'))
        # gen kpoints
        fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma)
        with open('KPOINTS', 'w') as fp: fp.write(fc)
        #copy cvasp
        if ('cvasp' in jdata) and (jdata['cvasp'] == True):
           shutil.copyfile(cvasp_file, os.path.join(vol_path,'cvasp.py'))
        os.chdir(cwd)
Esempio n. 7
0
def make_vasp(jdata, conf_dir):
    conf_path = os.path.abspath(conf_dir)
    equi_path = re.sub('confs', global_task_name, conf_path)
    os.makedirs(equi_path, exist_ok=True)
    cwd = os.getcwd()
    from_poscar = os.path.join(conf_path, 'POSCAR')
    to_poscar = os.path.join(equi_path, 'POSCAR')
    if os.path.exists(to_poscar):
        assert (filecmp.cmp(from_poscar, to_poscar))
    else:
        os.chdir(equi_path)
        os.symlink(os.path.relpath(from_poscar), 'POSCAR')
        os.chdir(cwd)
    is_alloy = \
               os.path.exists(
                   os.path.join(
                       os.path.join(conf_path, '..'),
                       'alloy'
                   )
               )
    # read potcar
    with open(to_poscar, 'r') as fp:
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list:
        assert os.path.exists(os.path.abspath(
            potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii)
        potcar_list.append(os.path.abspath(potcar_map[ii]))

    # gen incar
    if 'relax_incar' in jdata.keys():
        relax_incar_path = jdata['relax_incar']
        assert (os.path.exists(relax_incar_path))
        relax_incar_path = os.path.abspath(relax_incar_path)
        incar = incar_upper(Incar.from_file(relax_incar_path))
        isif = 3
        if incar.get('ISIF') != isif:
            dlog.info("%s:%s setting ISIF to %d" %
                      (__file__, make_vasp.__name__, isif))
            incar['ISIF'] = isif
        fc = incar.get_string()
        kspacing = incar['KSPACING']
        kgamma = incar['KGAMMA']
        vasp_path = os.path.join(equi_path, 'vasp-relax_incar')
    else:
        fp_params = jdata['vasp_params']
        ecut = fp_params['ecut']
        ediff = fp_params['ediff']
        npar = fp_params['npar']
        kpar = fp_params['kpar']
        kspacing = fp_params['kspacing']
        kgamma = fp_params['kgamma']
        fc = vasp.make_vasp_relax_incar(ecut, ediff, is_alloy, True, True,
                                        npar, kpar, kspacing, kgamma)
        vasp_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing)

    os.makedirs(vasp_path, exist_ok=True)
    os.chdir(vasp_path)

    # write incar
    with open('INCAR', 'w') as fp:
        fp.write(fc)

    # gen poscar
    if os.path.exists('POSCAR'):
        os.remove('POSCAR')
    os.symlink(os.path.relpath(to_poscar), 'POSCAR')

    # gen kpoints
    fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma)
    with open('KPOINTS', 'w') as fp:
        fp.write(fc)

    #copy cvasp
    if ('cvasp' in jdata) and (jdata['cvasp'] == True):
        shutil.copyfile(cvasp_file, 'cvasp.py')

    # gen potcar
    with open('POTCAR', 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    os.chdir(cwd)
Esempio n. 8
0
    def make_input_file(self, output_dir, task_type, task_param):
        sepline(ch=output_dir)
        dumpfn(task_param, os.path.join(output_dir, 'task.json'), indent=4)

        assert (os.path.exists(self.incar)), 'no INCAR file for relaxation'
        relax_incar_path = os.path.abspath(self.incar)
        incar_relax = incar_upper(Incar.from_file(relax_incar_path))

        # deal with relaxation

        cal_type = task_param['cal_type']
        cal_setting = task_param['cal_setting']

        # user input INCAR for property calculation
        if 'input_prop' in cal_setting and os.path.isfile(
                cal_setting['input_prop']):
            incar_prop = os.path.abspath(cal_setting['input_prop'])
            incar = incar_upper(Incar.from_file(incar_prop))

        # revise INCAR based on the INCAR provided in the "interaction"
        else:
            incar = incar_relax
            if cal_type == 'relaxation':
                relax_pos = cal_setting['relax_pos']
                relax_shape = cal_setting['relax_shape']
                relax_vol = cal_setting['relax_vol']
                if [relax_pos, relax_shape, relax_vol] == [True, False, False]:
                    isif = 2
                elif [relax_pos, relax_shape, relax_vol] == [True, True, True]:
                    isif = 3
                elif [relax_pos, relax_shape,
                      relax_vol] == [True, True, False]:
                    isif = 4
                elif [relax_pos, relax_shape,
                      relax_vol] == [False, True, False]:
                    isif = 5
                elif [relax_pos, relax_shape,
                      relax_vol] == [False, True, True]:
                    isif = 6
                elif [relax_pos, relax_shape,
                      relax_vol] == [False, False, True]:
                    isif = 7
                elif [relax_pos, relax_shape,
                      relax_vol] == [False, False, False]:
                    nsw = 0
                    isif = 2
                    if not ('NSW' in incar and incar.get('NSW') == nsw):
                        dlog.info("%s setting NSW to %d" %
                                  (self.make_input_file.__name__, nsw))
                        incar['NSW'] = nsw
                else:
                    raise RuntimeError(
                        "not supported calculation setting for VASP")

                if not ('ISIF' in incar and incar.get('ISIF') == isif):
                    dlog.info("%s setting ISIF to %d" %
                              (self.make_input_file.__name__, isif))
                    incar['ISIF'] = isif

            elif cal_type == 'static':
                nsw = 0
                if not ('NSW' in incar and incar.get('NSW') == nsw):
                    dlog.info("%s setting NSW to %d" %
                              (self.make_input_file.__name__, nsw))
                    incar['NSW'] = nsw

            else:
                raise RuntimeError("not supported calculation type for VASP")

            if 'ediff' in cal_setting:
                dlog.info(
                    "%s setting EDIFF to %s" %
                    (self.make_input_file.__name__, cal_setting['ediff']))
                incar['EDIFF'] = cal_setting['ediff']

            if 'ediffg' in cal_setting:
                dlog.info(
                    "%s setting EDIFFG to %s" %
                    (self.make_input_file.__name__, cal_setting['ediffg']))
                incar['EDIFFG'] = cal_setting['ediffg']

            if 'encut' in cal_setting:
                dlog.info(
                    "%s setting ENCUT to %s" %
                    (self.make_input_file.__name__, cal_setting['encut']))
                incar['ENCUT'] = cal_setting['encut']

            if 'kspacing' in cal_setting:
                dlog.info(
                    "%s setting KSAPCING to %s" %
                    (self.make_input_file.__name__, cal_setting['kspacing']))
                incar['KSAPCING'] = cal_setting['kspacing']

            if 'kgamma' in cal_setting:
                dlog.info(
                    "%s setting KGAMMA to %s" %
                    (self.make_input_file.__name__, cal_setting['kgamma']))
                incar['KGAMMA'] = cal_setting['kgamma']

        try:
            kspacing = incar.get('KSPACING')
        except KeyError:
            raise RuntimeError("KSPACING must be given in INCAR")

        if 'KGAMMA' in incar:
            kgamma = incar.get('KGAMMA')
        else:
            kgamma = False

        incar.write_file(os.path.join(output_dir, '../INCAR'))
        cwd = os.getcwd()
        os.chdir(output_dir)
        if not os.path.islink('INCAR'):
            os.symlink('../INCAR', 'INCAR')
        elif not '../INCAR' == os.readlink('INCAR'):
            os.remove('INCAR')
            os.symlink('../INCAR', 'INCAR')
        os.chdir(cwd)
        ret = vasp.make_kspacing_kpoints(self.path_to_poscar, kspacing, kgamma)
        kp = Kpoints.from_string(ret)
        kp.write_file(os.path.join(output_dir, "KPOINTS"))
Esempio n. 9
0
def _make_vasp(jdata, conf_dir, supercell, insert_ele):

    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')
    # get equi poscar
    if 'relax_incar' in jdata.keys():
        vasp_str = 'vasp-relax_incar'
    else:
        kspacing = jdata['vasp_params']['kspacing']
        vasp_str = 'vasp-k%.2f' % (kspacing)
    equi_path = re.sub('confs', global_equi_name, conf_path)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_contcar = os.path.join(equi_path, 'CONTCAR')
    assert os.path.exists(
        equi_contcar), "Please compute the equilibrium state using vasp first"
    task_path = re.sub('confs', global_task_name, conf_path)
    task_path = os.path.join(task_path, vasp_str)
    os.makedirs(task_path, exist_ok=True)
    cwd = os.getcwd()
    os.chdir(task_path)
    if os.path.isfile('POSCAR'):
        os.remove('POSCAR')
    os.symlink(os.path.relpath(equi_contcar), 'POSCAR')
    os.chdir(cwd)
    task_poscar = os.path.join(task_path, 'POSCAR')
    # gen strcture
    print("task poscar: ", task_poscar)
    ss = Structure.from_file(task_poscar)
    # gen defects
    vds = InterstitialGenerator(ss, insert_ele)
    dss = []
    for jj in vds:
        dss.append(jj.generate_defect_structure(supercell))
    # gen incar
    if 'relax_incar' in jdata.keys():
        relax_incar_path = jdata['relax_incar']
        assert (os.path.exists(relax_incar_path))
        relax_incar_path = os.path.abspath(relax_incar_path)
        incar = incar_upper(Incar.from_file(relax_incar_path))
        fc = incar.get_string()
        kspacing = incar['KSPACING']
        kgamma = incar['KGAMMA']

    else:
        fp_params = jdata['vasp_params']
        ecut = fp_params['ecut']
        ediff = fp_params['ediff']
        npar = fp_params['npar']
        kpar = fp_params['kpar']
        kspacing = fp_params['kspacing']
        kgamma = fp_params['kgamma']
        fc = vasp.make_vasp_relax_incar(ecut,
                                        ediff,
                                        True,
                                        True,
                                        True,
                                        npar=npar,
                                        kpar=kpar,
                                        kspacing=kspacing,
                                        kgamma=kgamma)
    with open(os.path.join(task_path, 'INCAR'), 'w') as fp:
        fp.write(fc)
    # gen tasks
    copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
    cwd = os.getcwd()
    for ii in range(len(dss)):
        struct_path = os.path.join(
            task_path, 'struct-%s-%s-%03d' % (insert_ele, copy_str, ii))
        print('# generate %s' % (struct_path))
        os.makedirs(struct_path, exist_ok=True)
        os.chdir(struct_path)
        for jj in ['POSCAR', 'POTCAR', 'INCAR']:
            if os.path.isfile(jj):
                os.remove(jj)
        # make conf
        dss[ii].to('POSCAR', 'POSCAR')
        # gen potcar
        with open('POSCAR', 'r') as fp:
            lines = fp.read().split('\n')
            ele_list = lines[5].split()

        os.chdir(cwd)
        potcar_map = jdata['potcar_map']
        potcar_list = []
        for ii in ele_list:
            assert os.path.exists(os.path.abspath(
                potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii)
            potcar_list.append(os.path.abspath(potcar_map[ii]))
        os.chdir(struct_path)

        with open('POTCAR', 'w') as outfile:
            for fname in potcar_list:
                with open(fname) as infile:
                    outfile.write(infile.read())

        # link incar
        os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR')
        # save supercell
        np.savetxt('supercell.out', supercell, fmt='%d')

        # write kp
        fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma)
        with open('KPOINTS', 'w') as fp:
            fp.write(fc)

        #copy cvasp
        if ('cvasp' in jdata) and (jdata['cvasp'] == True):
            shutil.copyfile(cvasp_file, os.path.join(struct_path, 'cvasp.py'))
    os.chdir(cwd)
Esempio n. 10
0
def make_vasp(jdata, conf_dir):
    default_norm_def = 2e-3
    default_shear_def = 5e-3
    norm_def = jdata.get('norm_deform', default_norm_def)
    shear_def = jdata.get('shear_deform', default_shear_def)
    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')

    if 'relax_incar' in jdata.keys():
        vasp_str = 'vasp-relax_incar'
    else:
        kspacing = jdata['vasp_params']['kspacing']
        vasp_str = 'vasp-k%.2f' % kspacing

    # get equi poscar
    equi_path = re.sub('confs', global_equi_name, conf_path)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_contcar = os.path.join(equi_path, 'CONTCAR')
    task_path = re.sub('confs', global_task_name, conf_path)
    task_path = os.path.join(task_path, vasp_str)
    os.makedirs(task_path, exist_ok=True)
    cwd = os.getcwd()
    os.chdir(task_path)
    if os.path.isfile('POSCAR'):
        os.remove('POSCAR')
    os.symlink(os.path.relpath(equi_contcar), 'POSCAR')
    os.chdir(cwd)
    task_poscar = os.path.join(task_path, 'POSCAR')
    # stress
    equi_outcar = os.path.join(equi_path, 'OUTCAR')
    stress = vasp.get_stress(equi_outcar)
    np.savetxt(os.path.join(task_path, 'equi.stress.out'), stress)
    # gen strcture
    ss = Structure.from_file(task_poscar)
    # gen defomations
    norm_strains = [-norm_def, -0.5 * norm_def, 0.5 * norm_def, norm_def]
    shear_strains = [-shear_def, -0.5 * shear_def, 0.5 * shear_def, shear_def]
    dfm_ss = DeformedStructureSet(ss,
                                  symmetry=False,
                                  norm_strains=norm_strains,
                                  shear_strains=shear_strains)
    n_dfm = len(dfm_ss)
    # gen incar
    if 'relax_incar' in jdata.keys():
        relax_incar_path = jdata['relax_incar']
        assert (os.path.exists(relax_incar_path))
        relax_incar_path = os.path.abspath(relax_incar_path)
        incar = incar_upper(Incar.from_file(relax_incar_path))
        if incar.get('ISIF') != 2:
            dlog.info("%s:%s setting ISIF to 2" %
                      (__file__, make_vasp.__name__))
            incar['ISIF'] = 2
        fc = incar.get_string()
        kspacing = incar['KSPACING']
        kgamma = incar['KGAMMA']
    else:
        fp_params = jdata['vasp_params']
        ecut = fp_params['ecut']
        ediff = fp_params['ediff']
        npar = fp_params['npar']
        kpar = fp_params['kpar']
        kspacing = fp_params['kspacing']
        kgamma = fp_params['kgamma']
        fc = vasp.make_vasp_relax_incar(ecut,
                                        ediff,
                                        True,
                                        False,
                                        False,
                                        npar=npar,
                                        kpar=kpar,
                                        kspacing=kspacing,
                                        kgamma=kgamma)

    with open(os.path.join(task_path, 'INCAR'), 'w') as fp:
        fp.write(fc)
    # gen potcar
    with open(task_poscar, 'r') as fp:
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list:
        assert os.path.exists(os.path.abspath(
            potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii)
        potcar_list.append(os.path.abspath(potcar_map[ii]))
    with open(os.path.join(task_path, 'POTCAR'), 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    # gen kpoints
    fc = vasp.make_kspacing_kpoints(task_poscar, kspacing, kgamma)
    with open(os.path.join(task_path, 'KPOINTS'), 'w') as fp:
        fp.write(fc)
    # gen tasks
    cwd = os.getcwd()
    for ii in range(n_dfm):
        # make dir
        dfm_path = os.path.join(task_path, 'dfm-%03d' % ii)
        os.makedirs(dfm_path, exist_ok=True)
        os.chdir(dfm_path)
        for jj in ['POSCAR', 'POTCAR', 'INCAR', 'KPOINTS']:
            if os.path.isfile(jj):
                os.remove(jj)
        # make conf
        dfm_ss.deformed_structures[ii].to('POSCAR', 'POSCAR')
        # record strain
        strain = Strain.from_deformation(dfm_ss.deformations[ii])
        np.savetxt('strain.out', strain)
        # link incar, potcar, kpoints
        os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR')
        os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')),
                   'POTCAR')
        os.symlink(os.path.relpath(os.path.join(task_path, 'KPOINTS')),
                   'KPOINTS')
        #copy cvasp
        if ('cvasp' in jdata) and (jdata['cvasp'] == True):
            shutil.copyfile(cvasp_file, os.path.join(dfm_path, 'cvasp.py'))
    os.chdir(cwd)
Esempio n. 11
0
def make_vasp(jdata, conf_dir) :
    
    supercell_matrix=jdata['supercell_matrix']
    band_path=jdata['band']

    if 'relax_incar' in jdata.keys():
        vasp_str='vasp-relax_incar'
    else:
        vasp_str='vasp-k%.2f' % kspacing

    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')
    equi_path = re.sub('confs', global_equi_name, conf_path)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_contcar = os.path.join(equi_path, 'CONTCAR')
    task_path = re.sub('confs', global_task_name, conf_path)
    if 'user_incar' in jdata.keys():
        vasp_user_str='vasp-user_incar'
    else:
        vasp_user_str='vasp-k%.2f' % kspacing
    task_path = os.path.join(task_path, vasp_user_str)
    os.makedirs(task_path, exist_ok=True)
    cwd = os.getcwd()
    os.chdir(task_path)
    print(task_path)
    if os.path.isfile('POSCAR-unitcell') :
        os.remove('POSCAR-unitcell')
    if os.path.isfile('POSCAR') :
        os.remove('POSCAR')
    os.symlink(os.path.relpath(equi_contcar), 'POSCAR-unitcell')
    os.chdir(cwd)
    task_poscar = os.path.join(task_path, 'POSCAR-unitcell')   
    # gen incar
    if  'user_incar' in jdata.keys():
        user_incar_path = jdata['user_incar']
        assert(os.path.exists(user_incar_path))
        user_incar_path = os.path.abspath(user_incar_path)
        incar = incar_upper(Incar.from_file(user_incar_path))
        fc = incar.get_string()
        kspacing = incar['KSPACING']
        kgamma = incar['KGAMMA']
    else :
        fp_params = jdata['vasp_params']
        ecut = fp_params['ecut']
        ediff = fp_params['ediff']
        npar = fp_params['npar']
        kpar = fp_params['kpar']
        kspacing = fp_params['kspacing']
        kgamma = fp_params['kgamma']
        fc = vasp.make_vasp_phonon_incar(ecut, ediff, npar, kpar, kspacing = None, kgamma = None)
    with open(os.path.join(task_path, 'INCAR'), 'w') as fp :
        fp.write(fc)
    # gen potcar
    with open(task_poscar,'r') as fp :
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list :
        assert(os.path.exists(potcar_map[ii]))
        potcar_list.append(potcar_map[ii])
    with open(os.path.join(task_path,'POTCAR'), 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    # gen kpoints
#    fc = vasp.make_kspacing_kpoints(task_poscar, kspacing, kgamma)
#    with open(os.path.join(task_path,'KPOINTS'), 'w') as fp:
#        fp.write(fc)

    # write kp
    fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma)
    with open('KPOINTS', 'w') as fp: fp.write(fc)
    #copy cvasp
    if ('cvasp' in jdata) and (jdata['cvasp'] == True):
       shutil.copyfile(cvasp_file, os.path.join(task_path,'cvasp.py'))

    # gen band.conf
    os.chdir(task_path)
    with open('band.conf','w') as fp:
        fp.write('ATOM_NAME = ')
        for ii in ele_list:
            fp.write(ii)
            fp.write(' ')
        fp.write('\n')
        fp.write('DIM = %d %d %d\n'%(supercell_matrix[0],supercell_matrix[1],supercell_matrix[2]))
        fp.write('BAND = %s\n'%band_path)
        fp.write('FORCE_CONSTANTS=READ')
    # gen POSCAR
    os.system('phonopy -d --dim="%d %d %d" -c POSCAR-unitcell'%(supercell_matrix[0],supercell_matrix[1],supercell_matrix[2]))
    os.symlink('SPOSCAR', 'POSCAR')
Esempio n. 12
0
def make_vasp(jdata, conf_dir, max_miller=2, relax_box=False, static=False):

    min_slab_size = jdata['min_slab_size']
    min_vacuum_size = jdata['min_vacuum_size']
    pert_xz = jdata['pert_xz']

    if 'relax_incar' in jdata.keys():
        vasp_str = 'vasp-relax_incar'
    else:
        kspacing = jdata['vasp_params']['kspacing']
        vasp_str = 'vasp-k%.2f' % (kspacing)

    # get conf poscar
    # conf_path = os.path.abspath(conf_dir)
    # conf_poscar = os.path.join(conf_path, 'POSCAR')
    equi_path = re.sub('confs', global_equi_name, conf_dir)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_path = os.path.abspath(equi_path)
    equi_contcar = os.path.join(equi_path, 'CONTCAR')
    assert os.path.exists(
        equi_contcar), "Please compute the equilibrium state using vasp first"
    task_path = re.sub('confs', global_task_name, conf_dir)
    task_path = os.path.abspath(task_path)
    if static:
        if 'scf_incar' in jdata.keys():
            vasp_static_str = 'vasp-static-scf_incar'
        else:
            vasp_static_str = 'vasp-static-k%.2f' % (kspacing)
        task_path = os.path.join(task_path, vasp_static_str)
    else:
        task_path = os.path.join(task_path, vasp_str)
    os.makedirs(task_path, exist_ok=True)
    cwd = os.getcwd()
    os.chdir(task_path)
    if os.path.isfile('POSCAR'):
        os.remove('POSCAR')
    os.symlink(os.path.relpath(equi_contcar), 'POSCAR')
    os.chdir(cwd)
    task_poscar = os.path.join(task_path, 'POSCAR')
    ptypes = vasp.get_poscar_types(task_poscar)
    # gen strcture
    ss = Structure.from_file(task_poscar)
    # gen slabs
    all_slabs = generate_all_slabs(ss, max_miller, min_slab_size,
                                   min_vacuum_size)
    # gen incar
    if static:
        if 'scf_incar' in jdata.keys():
            scf_incar_path = jdata['scf_incar']
            assert (os.path.exists(scf_incar_path))
            scf_incar_path = os.path.abspath(scf_incar_path)
            incar = incar_upper(Incar.from_file(scf_incar_path))
            fc = incar.get_string()
            kspacing = incar['KSPACING']
            kgamma = incar['KGAMMA']
        else:
            fp_params = jdata['vasp_params']
            ecut = fp_params['ecut']
            ediff = fp_params['ediff']
            npar = fp_params['npar']
            kpar = fp_params['kpar']
            kspacing = fp_params['kspacing']
            kgamma = fp_params['kgamma']
            fc = vasp.make_vasp_static_incar(ecut,
                                             ediff,
                                             npar=npar,
                                             kpar=kpar,
                                             kspacing=kspacing,
                                             kgamma=kgamma)
    else:
        if 'relax_incar' in jdata.keys():
            relax_incar_path = jdata['relax_incar']
            assert (os.path.exists(relax_incar_path))
            relax_incar_path = os.path.abspath(relax_incar_path)
            incar = incar_upper(Incar.from_file(relax_incar_path))
            fc = incar.get_string()
            kspacing = incar['KSPACING']
            kgamma = incar['KGAMMA']
        else:
            fp_params = jdata['vasp_params']
            ecut = fp_params['ecut']
            ediff = fp_params['ediff']
            npar = fp_params['npar']
            kpar = fp_params['kpar']
            kspacing = fp_params['kspacing']
            kgamma = fp_params['kgamma']
            fc = vasp.make_vasp_relax_incar(ecut,
                                            ediff,
                                            True,
                                            relax_box,
                                            False,
                                            npar=npar,
                                            kpar=kpar,
                                            kspacing=kspacing,
                                            kgamma=kgamma)
    with open(os.path.join(task_path, 'INCAR'), 'w') as fp:
        fp.write(fc)
    # gen potcar
    with open(task_poscar, 'r') as fp:
        lines = fp.read().split('\n')
        ele_list = lines[5].split()
    potcar_map = jdata['potcar_map']
    potcar_list = []
    for ii in ele_list:
        assert os.path.exists(os.path.abspath(
            potcar_map[ii])), "No POTCAR in the potcar_map of %s" % (ii)
        potcar_list.append(os.path.abspath(potcar_map[ii]))
    with open(os.path.join(task_path, 'POTCAR'), 'w') as outfile:
        for fname in potcar_list:
            with open(fname) as infile:
                outfile.write(infile.read())
    # gen tasks
    cwd = os.getcwd()
    for ii in range(len(all_slabs)):
        slab = all_slabs[ii]
        miller_str = "m%d.%d.%dm" % (
            slab.miller_index[0], slab.miller_index[1], slab.miller_index[2])
        # make dir
        struct_path = os.path.join(task_path,
                                   'struct-%03d-%s' % (ii, miller_str))
        os.makedirs(struct_path, exist_ok=True)
        os.chdir(struct_path)
        for jj in ['POSCAR', 'POTCAR', 'INCAR']:
            if os.path.isfile(jj):
                os.remove(jj)
        print("# %03d generate " % ii, struct_path,
              " \t %d atoms" % len(slab.sites))
        # make conf
        slab.to('POSCAR', 'POSCAR.tmp')
        vasp.regulate_poscar('POSCAR.tmp', 'POSCAR')
        vasp.sort_poscar('POSCAR', 'POSCAR', ptypes)
        vasp.perturb_xz('POSCAR', 'POSCAR', pert_xz)
        # record miller
        np.savetxt('miller.out', slab.miller_index, fmt='%d')
        # link incar, potcar, kpoints
        os.symlink(os.path.relpath(os.path.join(task_path, 'INCAR')), 'INCAR')
        os.symlink(os.path.relpath(os.path.join(task_path, 'POTCAR')),
                   'POTCAR')

        # write kp
        fc = vasp.make_kspacing_kpoints('POSCAR', kspacing, kgamma)
        with open('KPOINTS', 'w') as fp:
            fp.write(fc)

        #copy cvasp
        if ('cvasp' in jdata) and (jdata['cvasp'] == True):
            shutil.copyfile(cvasp_file, os.path.join(struct_path, 'cvasp.py'))
    cwd = os.getcwd()