Beispiel #1
0
def cmpt_vasp(jdata, conf_dir, supercell) :

    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_dir)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_path = os.path.abspath(equi_path)
    equi_outcar = os.path.join(equi_path, 'OUTCAR')
    task_path = re.sub('confs', global_task_name, conf_dir)    
    task_path = os.path.join(task_path, vasp_str)
    task_path = os.path.abspath(task_path)
    print("# ", task_path)

    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)

    copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
    struct_path_widecard = os.path.join(task_path, 'struct-%s-*' % (copy_str))
    struct_path_list = glob.glob(struct_path_widecard)
    struct_path_list.sort()
    if len(struct_path_list) == 0:
        print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
    sys.stdout.write ("Structure: \tVac_E(eV)  E(eV) equi_E(eV)\n")
    for ii in struct_path_list :
        struct_poscar = os.path.join(ii, 'POSCAR')
        energy_shift = comput_e_shift(struct_poscar, vasp_str)
        structure_dir = os.path.basename(ii)
        outcar = os.path.join(ii, 'OUTCAR')
        natoms, epa, vpa = vasp.get_nev(outcar)
        evac = epa * natoms - equi_epa * natoms
        sys.stdout.write ("%s: %7.3f  %7.3f %7.3f \n" % (structure_dir, evac, epa * natoms, equi_epa*natoms))
Beispiel #2
0
def _cmpt_vasp(jdata, conf_dir, supercell, insert_ele) :
    fp_params = jdata['vasp_params']
    kspacing = fp_params['kspacing']

    equi_path = re.sub('confs', global_equi_name, conf_dir)
    equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing)
    equi_path = os.path.abspath(equi_path)
    equi_outcar = os.path.join(equi_path, 'OUTCAR')
    task_path = re.sub('confs', global_task_name, conf_dir)
    task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing)
    task_path = os.path.abspath(task_path)

    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)

    copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
    struct_path_widecard = os.path.join(task_path, 'struct-%s-%s-*' % (insert_ele, copy_str))
    print(struct_path_widecard)
    struct_path_list = glob.glob(struct_path_widecard)
    struct_path_list.sort()
    if len(struct_path_list) == 0:
        print("# cannot find results for conf %s supercell %s" % (conf_dir, supercell))
    sys.stdout.write ("Insert_ele-Struct: Inter_E(eV)\n")
    for ii in struct_path_list :
        structure_dir = os.path.basename(ii)
        outcar = os.path.join(ii, 'OUTCAR')
        natoms, epa, vpa = vasp.get_nev(outcar)
        evac = epa * natoms - equi_epa * natoms
        sys.stdout.write ("%s: %7.3f \n" % (structure_dir, evac))    
Beispiel #3
0
def cmpt_vasp(jdata, conf_dir, static=False):

    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_dir)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_path = os.path.abspath(equi_path)
    equi_outcar = os.path.join(equi_path, 'OUTCAR')
    task_path = re.sub('confs', global_task_name, conf_dir)
    if static:
        if 'scf_incar' in jdata.keys():
            vasp_static_str = 'vasp-static-scf_incar'
        else:
            kspacing = jdata['vasp_params']['kspacing']
            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)
    task_path = os.path.abspath(task_path)

    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)

    struct_path_widecard = os.path.join(task_path, 'struct-*-m*m')
    struct_path_list = glob.glob(struct_path_widecard)
    struct_path_list.sort()
    if len(struct_path_list) == 0:
        print("# cannot find results for conf %s" % (conf_dir))
    sys.stdout.write("Miller_Indices: \tSurf_E(J/m^2) EpA(eV) equi_EpA(eV)\n")

    result = os.path.join(task_path, 'result')
    with open(result, 'w') as fp:
        fp.write('conf_dir:%s\n' % (conf_dir))
        fp.write("Miller_Indices: \tSurf_E(J/m^2) EpA(eV) equi_EpA(eV)\n")
        for ii in struct_path_list:
            structure_dir = os.path.basename(ii)
            outcar = os.path.join(ii, 'OUTCAR')
            natoms, epa, vpa = vasp.get_nev(outcar)
            if static:
                e0 = np.array(vasp.get_energies(outcar)) / natoms
                epa = e0[0]
            boxes = vasp.get_boxes(outcar)
            AA = np.linalg.norm(np.cross(boxes[0][0], boxes[0][1]))
            Cf = 1.60217657e-16 / (1e-20 * 2) * 0.001
            evac = (epa * natoms - equi_epa * natoms) / AA * Cf
            sys.stdout.write("%s:\t %7.3f   %8.3f %8.3f\n" %
                             (structure_dir, evac, epa, equi_epa))
            fp.write("%s:\t %7.3f   %8.3f %8.3f\n" %
                     (structure_dir, evac, epa, equi_epa))
    fp.close()
    if 'upload_username' in jdata.keys():
        upload_username = jdata['upload_username']
        util.insert_data('surf', 'vasp', upload_username, result)
Beispiel #4
0
    def _compute_lower(self, output_file, all_tasks, all_res):
        output_file = os.path.abspath(output_file)
        res_data = {}
        ptr_data = os.path.dirname(output_file) + '\n'

        if not self.reprod:
            ptr_data += "Miller_Indices: \tSurf_E(J/m^2) EpA(eV) equi_EpA(eV)\n"
            for ii in all_tasks:
                with open(os.path.join(ii, 'inter.json')) as fp:
                    idata = json.load(fp)
                inter_type = idata['type']
                equi_path = os.path.abspath(
                    os.path.join(os.path.dirname(output_file),
                                 '../relaxation'))
                structure_dir = os.path.basename(ii)
                if inter_type == 'vasp':
                    equi_outcar = os.path.join(equi_path, 'OUTCAR')
                    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)
                    outcar = os.path.join(ii, 'OUTCAR')
                    natoms, epa, vpa = vasp.get_nev(outcar)
                    if self.static:
                        e0 = np.array(vasp.get_energies(outcar)) / natoms
                        epa = e0[0]
                    boxes = vasp.get_boxes(outcar)
                    AA = np.linalg.norm(np.cross(boxes[0][0], boxes[0][1]))

                elif inter_type in ['deepmd', 'meam', 'eam_fs', 'eam_alloy']:
                    equi_log = os.path.join(equi_path, 'log.lammps')
                    equi_natoms, equi_epa, equi_vpa = lammps.get_nev(equi_log)
                    lmp_log = os.path.join(ii, 'log.lammps')
                    natoms, epa, vpa = lammps.get_nev(lmp_log)
                    AA = lammps.get_base_area(lmp_log)

                else:
                    raise RuntimeError('interaction type not supported')

                Cf = 1.60217657e-16 / (1e-20 * 2) * 0.001
                evac = (epa * natoms - equi_epa * natoms) / AA * Cf
                ptr_data += "%s: \t%7.3f    %8.3f %8.3f\n" % (
                    structure_dir, evac, epa, equi_epa)
                res_data[structure_dir] = [evac, epa, equi_epa]

        else:
            if 'vasp_path' not in self.parameter:
                raise RuntimeError(
                    "please provide the vasp_path for reproduction")
            vasp_path = os.path.abspath(self.parameter['vasp_path'])
            res_data, ptr_data = reproduce.post_repro(vasp_path, all_tasks,
                                                      ptr_data)

        with open(output_file, 'w') as fp:
            json.dump(res_data, fp, indent=4)

        return res_data, ptr_data
Beispiel #5
0
def comput_vasp_eos(jdata, conf_dir):
    conf_path = re.sub('confs', global_task_name, conf_dir)
    conf_path = os.path.abspath(conf_path)

    if 'relax_incar' in jdata.keys():
        vasp_str = 'vasp-relax_incar'
    else:
        kspacing = jdata['vasp_params']['kspacing']
        vasp_str = 'vasp-k%.2f' % kspacing
    task_path = os.path.join(conf_path, vasp_str)
    vol_paths = glob.glob(os.path.join(task_path, 'vol-*'))
    vol_paths.sort(key=lambda k: float(k.split('-')[-1]))
    result = os.path.join(task_path, 'result')
    print('Vpa(A^3)\tEpA(eV)')
    with open(result, 'w') as fp:
        fp.write('conf_dir:%s\n VpA(A^3)  EpA(eV)\n' % (conf_dir))
        for ii in vol_paths:
            outcar = os.path.join(ii, 'OUTCAR')
            natoms, epa, vpa = vasp.get_nev(outcar)
            print(vpa, epa)
            fp.write('%7.3f  %8.4f \n' % (vpa, epa))
    fp.close()
    if 'upload_username' in jdata.keys():
        upload_username = jdata['upload_username']
        util.insert_data('eos', 'vasp', upload_username, result)
Beispiel #6
0
def comput_vasp_nev(jdata, conf_dir, write_stable=False):
    kspacing = jdata['vasp_params']['kspacing']
    conf_path = re.sub('confs', global_equi_name, conf_dir)
    conf_path = os.path.abspath(conf_path)
    poscar = os.path.join(conf_path, 'POSCAR')
    if write_stable:
        ele_types = vasp.get_poscar_types(poscar)
        if len(ele_types) > 1:
            raise RuntimeError(
                'stable energy and volume only for one element, current you have %s from POSCAR'
                % str(ele_types))
    ener_shift = comput_e_shift(poscar, 'vasp-k%.2f' % kspacing)

    vasp_path = os.path.join(conf_path, 'vasp-k%.2f' % kspacing)
    outcar = os.path.join(vasp_path, 'OUTCAR')
    # tag_fin = os.path.join(vasp_path, 'tag_finished')
    if not os.path.isfile(outcar):
        warnings.warn("cannot find OUTCAR in " + vasp_path + " skip")
    elif not vasp.check_finished(outcar):
        warnings.warn("incomplete job " + vasp_path + " use the last frame")
    if os.path.isfile(outcar):
        natoms, epa, vpa = vasp.get_nev(outcar)
        epa = (epa * natoms - ener_shift) / natoms
        if write_stable:
            stable_dir = 'stables'
            os.makedirs(stable_dir, exist_ok=True)
            name_prefix = os.path.join(
                stable_dir, '%s.vasp-k%.2f' % (ele_types[0], kspacing))
            open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
            open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
        return natoms, epa, vpa
    else:
        return None, None, None
Beispiel #7
0
def _cmpt_vasp(jdata, conf_dir, supercell, insert_ele):

    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_dir)
    equi_path = os.path.join(equi_path, vasp_str)
    equi_path = os.path.abspath(equi_path)
    equi_outcar = os.path.join(equi_path, 'OUTCAR')
    task_path = re.sub('confs', global_task_name, conf_dir)
    task_path = os.path.join(task_path, vasp_str)
    task_path = os.path.abspath(task_path)

    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)

    copy_str = "%sx%sx%s" % (supercell[0], supercell[1], supercell[2])
    struct_path_widecard = os.path.join(
        task_path, 'struct-%s-%s-*' % (insert_ele, copy_str))
    print(struct_path_widecard)
    struct_path_list = glob.glob(struct_path_widecard)
    struct_path_list.sort()
    if len(struct_path_list) == 0:
        print("# cannot find results for conf %s supercell %s" %
              (conf_dir, supercell))
    sys.stdout.write("Insert_ele-Struct: Inter_E(eV)  E(eV) equi_E(eV)\n")
    result = os.path.join(task_path, 'result')
    with open(result, 'w') as fp:
        fp.write('conf_dir:%s\n' % (conf_dir))
        fp.write("Insert_ele-Struct: Inter_E(eV)  E(eV) equi_E(eV)\n")
        for ii in struct_path_list:
            structure_dir = os.path.basename(ii)
            outcar = os.path.join(ii, 'OUTCAR')
            natoms, epa, vpa = vasp.get_nev(outcar)
            evac = epa * natoms - equi_epa * natoms
            sys.stdout.write(
                "%s: %7.3f  %7.3f %7.3f \n" %
                (structure_dir, evac, epa * natoms, equi_epa * natoms))
            fp.write("%s: %7.3f  %7.3f %7.3f \n" %
                     (structure_dir, evac, epa * natoms, equi_epa * natoms))
    fp.close()
Beispiel #8
0
def comput_vasp_eos(jdata, conf_dir):
    kspacing = jdata['vasp_params']['kspacing']
    conf_path = re.sub('confs', global_task_name, conf_dir)
    conf_path = os.path.abspath(conf_path)
    conf_path = os.path.join(conf_path, 'vasp-k%.2f' % kspacing)
    vol_paths = glob.glob(os.path.join(conf_path, 'vol-*'))
    vol_paths.sort()
    print('Vpa(A^3)\tEpA(eV)')
    for ii in vol_paths:
        outcar = os.path.join(ii, 'OUTCAR')
        natoms, epa, vpa = vasp.get_nev(outcar)
        print(vpa, epa)
Beispiel #9
0
def cmpt_vasp(jdata, conf_dir, static=False):
    fp_params = jdata['vasp_params']
    kspacing = fp_params['kspacing']

    equi_path = re.sub('confs', global_equi_name, conf_dir)
    equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing)
    equi_path = os.path.abspath(equi_path)
    equi_outcar = os.path.join(equi_path, 'OUTCAR')
    task_path = re.sub('confs', global_task_name, conf_dir)
    if static:
        task_path = os.path.join(task_path, 'vasp-static-k%.2f' % kspacing)
    else:
        task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing)
    task_path = os.path.abspath(task_path)

    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)

    struct_path_widecard = os.path.join(task_path, 'struct-*-m*m')
    struct_path_list = glob.glob(struct_path_widecard)
    struct_path_list.sort()
    if len(struct_path_list) == 0:
        print("# cannot find results for conf %s supercell %s" %
              (conf_dir, supercell))
    sys.stdout.write("Miller_Indices: \tSurf_E(J/m^2) EpA(eV) equi_EpA(eV)\n")
    for ii in struct_path_list:
        structure_dir = os.path.basename(ii)
        outcar = os.path.join(ii, 'OUTCAR')
        natoms, epa, vpa = vasp.get_nev(outcar)
        if static:
            e0 = np.array(vasp.get_energies(outcar)) / natoms
            epa = e0[0]
        boxes = vasp.get_boxes(outcar)
        AA = np.linalg.norm(np.cross(boxes[0][0], boxes[0][1]))
        Cf = 1.60217657e-16 / (1e-20 * 2) * 0.001
        evac = (epa * natoms - equi_epa * natoms) / AA * Cf
        sys.stdout.write("%s:\t %7.3f   %8.3f %8.3f\n" %
                         (structure_dir, evac, epa, equi_epa))
Beispiel #10
0
    def _compute_lower(self, output_file, all_tasks, all_res):
        output_file = os.path.abspath(output_file)
        res_data = {}
        ptr_data = os.path.dirname(output_file) + '\n'

        if not self.reprod:
            ptr_data += "Insert_ele-Struct: Inter_E(eV)  E(eV) equi_E(eV)\n"
            for ii in all_tasks:
                with open(os.path.join(ii, 'inter.json')) as fp:
                    idata = json.load(fp)
                inter_type = idata['type']
                equi_path = os.path.abspath(
                    os.path.join(os.path.dirname(output_file),
                                 '../relaxation'))
                structure_dir = os.path.basename(ii)

                if inter_type == 'vasp':
                    equi_outcar = os.path.join(equi_path, 'OUTCAR')
                    equi_natoms, equi_epa, equi_vpa = vasp.get_nev(equi_outcar)

                elif inter_type in ['deepmd', 'meam', 'eam_fs', 'eam_alloy']:
                    equi_log = os.path.join(equi_path, 'log.lammps')
                    equi_natoms, equi_epa, equi_vpa = lammps.get_nev(equi_log)

                else:
                    raise RuntimeError('interaction type not supported')

                natoms = len(all_res[ii]['force']) / 3
                epa = all_res[ii]['energy'] / natoms
                evac = epa * natoms - equi_epa * natoms
                ptr_data += "%s: %7.3f  %7.3f %7.3f \n" % (
                    structure_dir, evac, epa * natoms, equi_epa * natoms)
                res_data[structure_dir] = [
                    evac, epa * natoms, equi_epa * natoms
                ]

        else:
            if 'vasp_path' not in self.parameter:
                raise RuntimeError(
                    "please provide the vasp_path for reproduction")
            vasp_path = os.path.abspath(self.parameter['vasp_path'])
            res_data, ptr_data = reproduce.post_repro(vasp_path, all_tasks,
                                                      ptr_data)

        with open(output_file, 'w') as fp:
            json.dump(res_data, fp, indent=4)

        return res_data, ptr_data
Beispiel #11
0
def comput_vasp_nev(jdata, conf_dir, write_shift=False):

    conf_path = re.sub('confs', global_equi_name, conf_dir)
    conf_path = os.path.abspath(conf_path)
    poscar = os.path.join(conf_path, 'POSCAR')
    ele_types = vasp.get_poscar_types(poscar)

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

    vasp_path = os.path.join(conf_path, vasp_str)
    outcar = os.path.join(vasp_path, 'OUTCAR')
    # tag_fin = os.path.join(vasp_path, 'tag_finished')
    if not os.path.isfile(outcar):
        warnings.warn("cannot find OUTCAR in " + vasp_path + " skip")
    elif not vasp.check_finished(outcar):
        warnings.warn("incomplete job " + vasp_path + " use the last frame")
    if os.path.isfile(outcar):
        natoms, epa, vpa = vasp.get_nev(outcar)
        if write_shift and len(ele_types) > 1:
            ener_shift = comput_e_shift(poscar, vasp_str)
            shift = (epa * natoms - ener_shift) / natoms
            return natoms, epa, vpa, shift
        if len(ele_types) == 1:
            stable_dir = 'stables'
            os.makedirs(stable_dir, exist_ok=True)
            name_prefix = os.path.join(stable_dir,
                                       '%s.' % (ele_types[0]) + vasp_str)
            open(name_prefix + '.e', 'w').write('%.16f\n' % (epa))
            open(name_prefix + '.v', 'w').write('%.16f\n' % (vpa))
        return natoms, epa, vpa, None
    else:
        return None, None, None, None