def cmpt_vasp(jdata, conf_dir):
    fp_params = jdata['vasp_params']
    kspacing = fp_params['kspacing']
    kgamma = fp_params['kgamma']
    strain_direct = jdata['strain_direct']
    a, b = strain_direct[0], strain_direct[1]

    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')
    task_path = re.sub('confs', global_task_name, conf_path)
    task_path = os.path.join(task_path, 'vasp-k%.2f' % kspacing)

    lst_dfm_path = glob.glob(os.path.join(task_path, 'dfm-*'))
    lst_strain = []
    lst_stress = []
    print('conf_dir:', conf_dir)
    print('strain\t stress(kB)')
    for ii in lst_dfm_path:
        strain = np.loadtxt(os.path.join(ii, 'strain.out'))
        stress = vasp.get_stress(os.path.join(ii, 'OUTCAR'))
        # convert from pressure in kB to stress
        stress = -stress
        lst_strain.append(strain[a, b])
        lst_stress.append(stress[a, b])
    index = np.argsort(lst_strain)
    for ii in range(len(lst_strain)):
        print('%7.4f %7.4f' % (lst_strain[index[ii]], lst_stress[index[ii]]))
Exemple #2
0
def cmpt_vasp(jdata, conf_dir):
    fp_params = jdata['vasp_params']
    kspacing = fp_params['kspacing']
    kgamma = fp_params['kgamma']

    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')
    task_path = re.sub('confs', global_task_name, conf_path)
    if 'relax_incar' in jdata.keys():
        vasp_str = 'vasp-relax_incar'
    else:
        vasp_str = 'vasp-k%.2f' % kspacing
    task_path = os.path.join(task_path, vasp_str)

    equi_stress = Stress(np.loadtxt(os.path.join(task_path,
                                                 'equi.stress.out')))

    lst_dfm_path = glob.glob(os.path.join(task_path, 'dfm-*'))
    lst_strain = []
    lst_stress = []
    for ii in lst_dfm_path:
        strain = np.loadtxt(os.path.join(ii, 'strain.out'))
        stress = vasp.get_stress(os.path.join(ii, 'OUTCAR'))
        # convert from pressure in kB to stress
        stress *= -1000
        lst_strain.append(Strain(strain))
        lst_stress.append(Stress(stress))
    et = ElasticTensor.from_independent_strains(lst_strain,
                                                lst_stress,
                                                eq_stress=equi_stress,
                                                vasp=False)
    # et = ElasticTensor.from_independent_strains(lst_strain, lst_stress, eq_stress = None)
    # bar to GPa
    # et = -et / 1e4
    print_et(et)
Exemple #3
0
    def _compute_lower(self, output_file, all_tasks, all_res):
        output_file = os.path.abspath(output_file)
        res_data = {}
        ptr_data = output_file + '\n'
        equi_stress = Stress(
            np.loadtxt(
                os.path.join(os.path.dirname(output_file), 'equi.stress.out')))
        lst_strain = []
        lst_stress = []
        for ii in all_tasks:
            with open(os.path.join(ii, 'inter.json')) as fp:
                idata = json.load(fp)
            inter_type = idata['type']
            strain = np.loadtxt(os.path.join(ii, 'strain.out'))
            if inter_type == 'vasp':
                stress = vasp.get_stress(os.path.join(ii, 'OUTCAR'))
                # convert from pressure in kB to stress
                stress *= -1000
                lst_strain.append(Strain(strain))
                lst_stress.append(Stress(stress))
            elif inter_type in ['deepmd', 'meam', 'eam_fs', 'eam_alloy']:
                stress = lammps.get_stress(os.path.join(ii, 'log.lammps'))
                # convert from pressure to stress
                stress = -stress
                lst_strain.append(Strain(strain))
                lst_stress.append(Stress(stress))
        et = ElasticTensor.from_independent_strains(lst_strain,
                                                    lst_stress,
                                                    eq_stress=equi_stress,
                                                    vasp=False)
        res_data['elastic_tensor'] = []
        for ii in range(6):
            for jj in range(6):
                res_data['elastic_tensor'].append(et.voigt[ii][jj] / 1e4)
                ptr_data += "%7.2f " % (et.voigt[ii][jj] / 1e4)
            ptr_data += '\n'

        BV = et.k_voigt / 1e4
        GV = et.g_voigt / 1e4
        EV = 9 * BV * GV / (3 * BV + GV)
        uV = 0.5 * (3 * BV - 2 * GV) / (3 * BV + GV)

        res_data['BV'] = BV
        res_data['GV'] = GV
        res_data['EV'] = EV
        res_data['uV'] = uV
        ptr_data += "# Bulk   Modulus BV = %.2f GPa\n" % BV
        ptr_data += "# Shear  Modulus GV = %.2f GPa\n" % GV
        ptr_data += "# Youngs Modulus EV = %.2f GPa\n" % EV
        ptr_data += "# Poission Ratio uV = %.2f " % uV

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

        return res_data, ptr_data
Exemple #4
0
def make_vasp(jdata, conf_dir, norm_def = 2e-3, shear_def = 5e-3) :
    norm_def = jdata['norm_deform']
    shear_def = jdata['shear_deform']
    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')
    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)
        fc = open(relax_incar_path).read()
        kspacing =float(re.findall((r"KSPACING(.+?)\n"),fc)[0].replace('=',''))
        kgamma =('T' in re.findall((r"KGAMMA(.+?)\n"),fc)[0])
    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')
    cwd = os.getcwd()
Exemple #5
0
def make_vasp(jdata, conf_dir, norm_def=2e-3, shear_def=5e-3):
    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']
    strain_start = jdata['strain_start']
    strain_end = jdata['strain_end']
    strain_step = jdata['strain_step']
    strain_direct = jdata['strain_direct']

    conf_path = os.path.abspath(conf_dir)
    conf_poscar = os.path.join(conf_path, 'POSCAR')
    # get equi poscar
    equi_path = re.sub('confs', global_equi_name, conf_path)
    equi_path = os.path.join(equi_path, 'vasp-k%.2f' % kspacing)
    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-k%.2f' % kspacing)
    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 = np.arange(strain_start, strain_end, strain_step)
    print('gen with norm ' + str(norm_strains))
    deformations = []
    for ii in norm_strains:
        strain = Strain.from_index_amount(strain_direct, ii)
        deformations.append(strain.get_deformation_matrix())
    deformed_structures = [
        defo.apply_to_structure(ss) for defo in deformations
    ]
    n_dfm = len(deformed_structures)
    # gen incar
    fc = vasp.make_vasp_relax_incar(ecut,
                                    ediff,
                                    True,
                                    False,
                                    False,
                                    npar=npar,
                                    kpar=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)
    # 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
        deformed_structures[ii].to('POSCAR', 'POSCAR')
        # record strain
        strain = Strain.from_deformation(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')
    cwd = os.getcwd()
Exemple #6
0
    def make_confs(self, path_to_work, path_to_equi, refine=False):
        path_to_work = os.path.abspath(path_to_work)
        path_to_equi = os.path.abspath(path_to_equi)
        task_list = []
        cwd = os.getcwd()

        norm_def = self.norm_deform
        shear_def = self.shear_deform
        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
        ]
        print('gen with norm ' + str(norm_strains))
        print('gen with shear ' + str(shear_strains))

        equi_contcar = os.path.join(path_to_equi, 'CONTCAR')
        if not os.path.exists(equi_contcar):
            raise RuntimeError("please do relaxation first")

        ss = Structure.from_file(equi_contcar)
        dfm_ss = DeformedStructureSet(ss,
                                      symmetry=False,
                                      norm_strains=norm_strains,
                                      shear_strains=shear_strains)
        n_dfm = len(dfm_ss)

        os.chdir(path_to_work)
        if os.path.isfile('POSCAR'):
            os.remove('POSCAR')
        os.symlink(os.path.relpath(equi_contcar), 'POSCAR')
        #           task_poscar = os.path.join(output, 'POSCAR')
        # stress
        equi_outcar = os.path.join(path_to_equi, 'OUTCAR')
        equi_log = os.path.join(path_to_equi, 'log.lammps')
        if os.path.exists(equi_outcar):
            stress = vasp.get_stress(equi_outcar)
            np.savetxt('equi.stress.out', stress)
        elif os.path.exists(equi_log):
            stress = lammps.get_stress(equi_log)
            np.savetxt('equi.stress.out', stress)
        os.chdir(cwd)

        if refine:
            task_list = make_refine(self.parameter['init_from_suffix'],
                                    self.parameter['output_suffix'],
                                    path_to_work, n_dfm)
            os.chdir(cwd)
        else:
            for ii in range(n_dfm):
                output_task = os.path.join(path_to_work, 'task.%06d' % ii)
                os.makedirs(output_task, exist_ok=True)
                os.chdir(output_task)
                for jj in [
                        'INCAR', 'POTCAR', 'POSCAR', 'conf.lmp', 'in.lammps'
                ]:
                    if os.path.exists(jj):
                        os.remove(jj)
                task_list.append(output_task)
                dfm_ss.deformed_structures[ii].to('POSCAR', 'POSCAR')
                # record strain
                strain = Strain.from_deformation(dfm_ss.deformations[ii])
                np.savetxt('strain.out', strain)
            os.chdir(cwd)
        return task_list
Exemple #7
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)