Ejemplo n.º 1
0
def get_wavefunction(potcar="POTCAR",
                     wavecar="WAVECAR",
                     vasprun="vasprun.xml",
                     directory=None):
    from pawpyseed.core import pawpyc
    from pawpyseed.core.wavefunction import CoreRegion, Wavefunction

    if directory:
        wf = Wavefunction.from_directory(path=directory)
    else:
        if isinstance(vasprun, str):
            vasprun = Vasprun(vasprun)

        if isinstance(potcar, str):
            potcar = Potcar.from_file(potcar)

        ngx = vasprun.parameters["NGX"]
        ngy = vasprun.parameters["NGY"]
        ngz = vasprun.parameters["NGZ"]
        dim = np.array([ngx, ngy, ngz])
        symprec = vasprun.parameters["SYMPREC"]
        structure = vasprun.final_structure

        pwf = pawpyc.PWFPointer(wavecar, vasprun)
        core_region = CoreRegion(potcar)

        wf = Wavefunction(structure, pwf, core_region, dim, symprec, False)

    wf = wf.desymmetrized_copy(time_reversal_symmetry=False, symprec=1e-4)
    return wf
Ejemplo n.º 2
0
    def initialize_wf_and_mm(self):
        SIZE = 60
        self.wf = Wavefunction.from_directory(".")
        vol = self.wf.structure.volume
        self.realspace_wf = self.wf.get_state_realspace(0,
                                                        0,
                                                        0,
                                                        dim=(SIZE, SIZE, SIZE),
                                                        remove_phase=True)
        # self.realspace_chg = np.abs(self.realspace_wf)**2
        self.realspace_chg = self.wf.get_state_realspace_density(0,
                                                                 0,
                                                                 0,
                                                                 dim=(SIZE,
                                                                      SIZE,
                                                                      SIZE))
        self.recipspace_wf = np.fft.fftn(
            self.realspace_wf) / SIZE**3 * np.sqrt(vol)
        self.recipspace_chg = np.fft.fftn(self.realspace_chg) / SIZE**3 * vol
        self.mm_real = MomentumMatrix(self.wf, encut=3000)
        self.mm_direct = MomentumMatrix(self.wf)
        self.mm_direct2 = MomentumMatrix(self.wf, encut=self.wf.encut)

        self.ncl_wf = NCLWavefunction.from_directory("noncollinear")
        self.ncl_realspace_wf = self.ncl_wf.get_state_realspace(
            0, 0, 0, dim=(SIZE, SIZE, SIZE), remove_phase=True)
        self.ncl_recipspace_wf = (
            np.fft.fftn(self.ncl_realspace_wf[0]) / SIZE**3 * np.sqrt(vol),
            np.fft.fftn(self.ncl_realspace_wf[1]) / SIZE**3 * np.sqrt(vol),
        )
Ejemplo n.º 3
0
    def run_pawpy(self):
        """
        Container for running pawpyseed on all defects in this workflow
        """

        vbm = None
        bulk_dirs, wf_dirs = [], []
        bulk_sizes, wf_sizes = [], []
        for sc_size, bulk_fw in self.bulk_fw_sets.items():
            launch_dir = bulk_fw.launches[-1].launch_dir
            bulk_sizes.append(sc_size)
            bulk_dirs.append(launch_dir)
            if not vbm:
                # need to check different filenames
                vr = Vasprun(os.path.join(launch_dir, "vasprun.xml"))
                vbm = vr.eigenvalue_band_properties[2]
                print("\twill use vbm value of ", vbm)
        for sc_size, size_set in self.dwo.defect_fw_sets.items():
            for fw in size_set:
                wf_sizes.append(sc_size)
                wf_dirs.append(fw.launches[-1].launch_dir)
        projector_list, bases = Projector.setup_bases(bulk_dirs, wf_dirs, True)
        num_proj_els = bases[0].num_proj_els
        store_all_data = {}
        basis_sets = {}
        for i, sc_size in enumerate(bulk_sizes):
            basis_sets[sc_size] = bases[i]

        # for each defect, in a given supercell size
        for sc_size, size_set in self.dwo.defect_fw_sets.items():
            for fw in size_set:
                try:
                    launch_dir = fw.launches[-1].launch_dir
                    print(f"start parsing of {fw.name} wavefunction")

                    # setup file path,
                    print("\tsetting up files")
                    self._setup_file_for_parsing(launch_dir)

                    # find band number which is at VBM and iniitalize band_dict and find spin polarization
                    print("\tinitializing band_dict")
                    band_dict, spinpol = self._get_vbm_band_dict(
                        launch_dir, vbm)

                    # setup defect wavefunction
                    print("\tmerging wf from dir")
                    wf = Wavefunction.from_atomate_directory(
                        launch_dir, setup_projectors=False)

                    # loop over band projections around band edge and store results
                    print("\tperforming projections")
                    pr = Projector(
                        wf,
                        basis_sets[sc_size],
                        projector_list=projector_list,
                        unsym_wf=True,
                    )
                    for bandnum in band_dict.keys():
                        v, c = pr.proportion_conduction(bandnum,
                                                        spinpol=spinpol)
                        band_dict[bandnum]["VB_projection"] = v[:]
                        band_dict[bandnum]["CB_projection"] = c[:]
                        print(bandnum, band_dict[bandnum])

                    # then tear down file path
                    print("\ttear down files")
                    rmtree(os.path.join(launch_dir, "kyle_file"))

                    # release defect memory
                    pr.wf.free_all()

                    store_all_data[fw.fw_id] = band_dict
                except Exception as e:
                    print(
                        "___&*$#&(*#@&$)(*&@#)($----\n--> ERROR OCCURED. "
                        "Skipping this defect.\n-------------^#$^*&^#$&*^#@^$#-------------"
                    )
                    print(repr(e))

        # now release all bulk basis memory
        for bulk_basis in basis_sets.values():
            bulk_basis.free_all()

        Projector.free_projector_list(projector_list, num_proj_els)

        return store_all_data