Пример #1
0
 def _get_dos_calc(self, phonon, structure, kpoint_density):
     tempfilename = tempfile.gettempprefix() + '.yaml'
     kpoint = Kpoints.automatic_density(structure=structure,
                                        kppa=kpoint_density,
                                        force_gamma=True)
     phonon.run_mesh(kpoint.kpts[0])
     phonon.run_total_dos()
     phonon.write_total_dos(filename=tempfilename)
     dos = get_ph_dos(tempfilename)
     os.remove(tempfilename)
     return dos
Пример #2
0
    def _get_phono3pyobject_phono3py(self, structure, potential,
                                     kpoint_density,
                                     displacementdistancephono3py,
                                     max_distance_third_order):
        cell = get_phonopy_structure(structure)

        kpoint = Kpoints.automatic_density(structure=structure,
                                           kppa=kpoint_density,
                                           force_gamma=True)
        mesh = kpoint.kpts[0]
        phono3py = Phono3py(cell,
                            self.smat,
                            primitive_matrix=[[1, 0., 0.], [0., 1, 0.],
                                              [0., 0., 1]],
                            mesh=mesh,
                            log_level=1)

        phono3py.generate_displacements(
            distance=displacementdistancephono3py,
            cutoff_pair_distance=max_distance_third_order)
        scells_with_disps = phono3py.get_supercells_with_displacements()

        disp_dataset = phono3py.get_displacement_dataset()
        numatoms = len(scells_with_disps[0].get_scaled_positions())
        dummy_force = np.zeros((numatoms, 3))

        set_of_forces = []
        for scell in scells_with_disps:
            if scell is not None:
                # this part is adapted from: https://web.archive.org/web/20200610084959/https://github.com/phonopy/phonopy/blob/develop/example/ase/8Si-phonon.py
                # Copyright by Atsushi Togo
                cell = Atoms(symbols=scell.get_chemical_symbols(),
                             scaled_positions=scell.get_scaled_positions(),
                             cell=scell.get_cell(),
                             pbc=True)
                cell.set_calculator(potential)
                forces = cell.get_forces()
                drift_force = forces.sum(axis=0)
                print(("[Phonopy] Drift force:" + "%11.5f" * 3) %
                      tuple(drift_force))
                for force in forces:
                    force -= drift_force / forces.shape[0]
                set_of_forces.append(forces)
            else:
                set_of_forces.append(dummy_force)
        phono3py.produce_fc3(set_of_forces,
                             displacement_dataset=disp_dataset,
                             symmetrize_fc3r=True)

        fc3 = phono3py.get_fc3()

        show_drift_fc3(fc3)
        return phono3py
Пример #3
0
    def from_structure(cls,
                       structure: Structure,
                       reciprocal_density: Optional[int] = 50000,
                       **kwargs):
        """
        Get a ShengBTE control object from a structure.

        Args:
            structure: A structure object.
            reciprocal_density: If not None, the q-point grid ("ngrid") will be
                set using this density.
            kwargs: Additional options to be passed to the Control constructor.
                See the docstring of the __init__ method for more details

        Returns:
            A ShengBTE control object.
        """

        elements = list(map(str, structure.composition.elements))

        unique_nums = np.unique(structure.atomic_numbers)
        types_dict = dict(zip(unique_nums, range(len(unique_nums))))
        types = [types_dict[i] + 1 for i in structure.atomic_numbers]

        control_dict = {
            "nelements": structure.ntypesp,
            "natoms": structure.num_sites,
            "norientations": 0,
            "lfactor": 0.1,
            "lattvec": structure.lattice.matrix.tolist(),
            "elements": elements,
            "types": types,
            "positions": structure.frac_coords.tolist(),
        }

        if reciprocal_density:
            kpoints = Kpoints.automatic_density(structure, reciprocal_density)
            control_dict["ngrid"] = kpoints.kpts[0]

        control_dict.update(**kwargs)

        return Control(**control_dict)
Пример #4
0
def vac_antisite_def_struct_gen(args):
    mpid = args.mpid
    mapi_key = args.mapi_key
    cellmax = args.cellmax

    if not mpid:
        print ("============\nERROR: Provide an mpid\n============")
        return

    if not mapi_key:
        with MPRester() as mp:
            struct = mp.get_structure_by_material_id(mpid)
    else:
        with MPRester(mapi_key) as mp:
            struct = mp.get_structure_by_material_id(mpid)

    prim_struct_sites = len(struct.sites)
    struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure()
    conv_struct_sites = len(struct.sites)
    conv_prim_rat = int(conv_struct_sites/prim_struct_sites)
    sc_scale = get_sc_scale(struct,cellmax)

    mpvis = MPRelaxSet(struct, user_incar_settings={"LDAU": False})

    # Begin defaults: All default settings.
    blk_vasp_incar_param = {'IBRION':-1,'EDIFF':1e-4,'EDIFFG':0.001,'NSW':0,}
    def_vasp_incar_param = {'ISIF':2,'NELM':99,'IBRION':2,'EDIFF':1e-6, 
                            'EDIFFG':0.001,'NSW':40,}
    kpoint_den = 6000
    # End defaults
    
    ptcr_flag = True
    try:
        potcar = mpvis.potcar
    except:
        print ("VASP POTCAR folder not detected.\n" \
              "Only INCAR, POSCAR, KPOINTS are generated.\n" \
              "If you have VASP installed on this system, \n" \
              "refer to pymatgen documentation for configuring the settings.")
        ptcr_flag = False


    vac = Vacancy(struct, {}, {})
    scs = vac.make_supercells_with_defects(sc_scale)
    site_no = scs[0].num_sites
    if site_no > cellmax:
        max_sc_dim = max(sc_scale)
        i = sc_scale.index(max_sc_dim)
        sc_scale[i] -= 1
        scs = vac.make_supercells_with_defects(sc_scale)

    for i in range(len(scs)):
        sc = scs[i]
        mpvis = MPRelaxSet(sc, user_incar_settings={"LDAU": False})
        poscar = mpvis.poscar
        kpoints = Kpoints.automatic_density(sc,kpoint_den)
        incar = mpvis.incar
        if ptcr_flag:
            potcar = mpvis.potcar

        interdir = mpid
        if not i:
            fin_dir = os.path.join(interdir,'bulk')
            try:
                os.makedirs(fin_dir)
            except:
                pass
            incar.update(blk_vasp_incar_param)
            incar.write_file(os.path.join(fin_dir,'INCAR'))
            poscar.write_file(os.path.join(fin_dir,'POSCAR'))
            if ptcr_flag:
                potcar.write_file(os.path.join(fin_dir,'POTCAR'))
            kpoints.write_file(os.path.join(fin_dir,'KPOINTS'))
        else:
            blk_str_sites = set(scs[0].sites)
            vac_str_sites = set(sc.sites)
            vac_sites = blk_str_sites - vac_str_sites
            vac_site = list(vac_sites)[0]
            site_mult = int(vac.get_defectsite_multiplicity(i-1)/conv_prim_rat)
            vac_site_specie = vac_site.specie
            vac_symbol = vac_site.specie.symbol

            vac_dir ='vacancy_{}_mult-{}_sitespecie-{}'.format(str(i),
                    site_mult, vac_symbol)
            fin_dir = os.path.join(interdir,vac_dir)
            try:
                os.makedirs(fin_dir)
            except:
                pass
            incar.update(def_vasp_incar_param)
            poscar.write_file(os.path.join(fin_dir,'POSCAR'))
            incar.write_file(os.path.join(fin_dir,'INCAR'))
            if ptcr_flag:
                potcar.write_file(os.path.join(fin_dir,'POTCAR'))
            kpoints.write_file(os.path.join(fin_dir,'KPOINTS'))

            # Antisite generation at all vacancy sites
            struct_species = scs[0].types_of_specie
            for specie in set(struct_species)-set([vac_site_specie]):
                subspecie_symbol = specie.symbol
                anti_struct = sc.copy()
                anti_struct.append(specie, vac_site.frac_coords)
                mpvis = MPRelaxSet(anti_struct, user_incar_settings={"LDAU": False})
                poscar = mpvis.poscar
                incar = mpvis.incar
                incar.update(def_vasp_incar_param)
                as_dir ='antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format(
                        str(i), site_mult, vac_symbol, subspecie_symbol)
                fin_dir = os.path.join(interdir,as_dir)
                try:
                    os.makedirs(fin_dir)
                except:
                    pass
                poscar.write_file(os.path.join(fin_dir,'POSCAR'))
                incar.write_file(os.path.join(fin_dir,'INCAR'))
                if ptcr_flag:
                    potcar.write_file(os.path.join(fin_dir,'POTCAR'))
                kpoints.write_file(os.path.join(fin_dir,'KPOINTS'))
Пример #5
0
def vac_antisite_def_struct_gen(args):
    mpid = args.mpid
    mapi_key = args.mapi_key
    cellmax = args.cellmax

    if not mpid:
        print("============\nERROR: Provide an mpid\n============")
        return

    if not mapi_key:
        with MPRester() as mp:
            struct = mp.get_structure_by_material_id(mpid)
    else:
        with MPRester(mapi_key) as mp:
            struct = mp.get_structure_by_material_id(mpid)

    prim_struct_sites = len(struct.sites)
    struct = SpacegroupAnalyzer(struct).get_conventional_standard_structure()
    conv_struct_sites = len(struct.sites)
    conv_prim_rat = int(conv_struct_sites / prim_struct_sites)
    sc_scale = get_sc_scale(struct, cellmax)

    mpvis = MPRelaxSet(struct, user_incar_settings={"LDAU": False})

    # Begin defaults: All default settings.
    blk_vasp_incar_param = {
        'IBRION': -1,
        'EDIFF': 1e-4,
        'EDIFFG': 0.001,
        'NSW': 0,
    }
    def_vasp_incar_param = {
        'ISIF': 2,
        'NELM': 99,
        'IBRION': 2,
        'EDIFF': 1e-6,
        'EDIFFG': 0.001,
        'NSW': 40,
    }
    kpoint_den = 6000
    # End defaults

    ptcr_flag = True
    try:
        potcar = mpvis.potcar
    except:
        print ("VASP POTCAR folder not detected.\n" \
              "Only INCAR, POSCAR, KPOINTS are generated.\n" \
              "If you have VASP installed on this system, \n" \
              "refer to pymatgen documentation for configuring the settings.")
        ptcr_flag = False

    vac = Vacancy(struct, {}, {})
    scs = vac.make_supercells_with_defects(sc_scale)
    site_no = scs[0].num_sites
    if site_no > cellmax:
        max_sc_dim = max(sc_scale)
        i = sc_scale.index(max_sc_dim)
        sc_scale[i] -= 1
        scs = vac.make_supercells_with_defects(sc_scale)

    for i in range(len(scs)):
        sc = scs[i]
        mpvis = MPRelaxSet(sc, user_incar_settings={"LDAU": False})
        poscar = mpvis.poscar
        kpoints = Kpoints.automatic_density(sc, kpoint_den)
        incar = mpvis.incar
        if ptcr_flag:
            potcar = mpvis.potcar

        interdir = mpid
        if not i:
            fin_dir = os.path.join(interdir, 'bulk')
            try:
                os.makedirs(fin_dir)
            except:
                pass
            incar.update(blk_vasp_incar_param)
            incar.write_file(os.path.join(fin_dir, 'INCAR'))
            poscar.write_file(os.path.join(fin_dir, 'POSCAR'))
            if ptcr_flag:
                potcar.write_file(os.path.join(fin_dir, 'POTCAR'))
            kpoints.write_file(os.path.join(fin_dir, 'KPOINTS'))
        else:
            blk_str_sites = set(scs[0].sites)
            vac_str_sites = set(sc.sites)
            vac_sites = blk_str_sites - vac_str_sites
            vac_site = list(vac_sites)[0]
            site_mult = int(
                vac.get_defectsite_multiplicity(i - 1) / conv_prim_rat)
            vac_site_specie = vac_site.specie
            vac_symbol = vac_site.specie.symbol

            vac_dir = 'vacancy_{}_mult-{}_sitespecie-{}'.format(
                str(i), site_mult, vac_symbol)
            fin_dir = os.path.join(interdir, vac_dir)
            try:
                os.makedirs(fin_dir)
            except:
                pass
            incar.update(def_vasp_incar_param)
            poscar.write_file(os.path.join(fin_dir, 'POSCAR'))
            incar.write_file(os.path.join(fin_dir, 'INCAR'))
            if ptcr_flag:
                potcar.write_file(os.path.join(fin_dir, 'POTCAR'))
            kpoints.write_file(os.path.join(fin_dir, 'KPOINTS'))

            # Antisite generation at all vacancy sites
            struct_species = scs[0].types_of_specie
            for specie in set(struct_species) - set([vac_site_specie]):
                subspecie_symbol = specie.symbol
                anti_struct = sc.copy()
                anti_struct.append(specie, vac_site.frac_coords)
                mpvis = MPRelaxSet(anti_struct,
                                   user_incar_settings={"LDAU": False})
                poscar = mpvis.poscar
                incar = mpvis.incar
                incar.update(def_vasp_incar_param)
                as_dir = 'antisite_{}_mult-{}_sitespecie-{}_subspecie-{}'.format(
                    str(i), site_mult, vac_symbol, subspecie_symbol)
                fin_dir = os.path.join(interdir, as_dir)
                try:
                    os.makedirs(fin_dir)
                except:
                    pass
                poscar.write_file(os.path.join(fin_dir, 'POSCAR'))
                incar.write_file(os.path.join(fin_dir, 'INCAR'))
                if ptcr_flag:
                    potcar.write_file(os.path.join(fin_dir, 'POTCAR'))
                kpoints.write_file(os.path.join(fin_dir, 'KPOINTS'))