Beispiel #1
0
class BandstructureLoaderTest(unittest.TestCase):

    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))
        bs_sp = loadfn(os.path.join(test_dir, "N2_bandstructure.json"))
        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)

        self.loader_sp_up = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=1)
        self.loader_sp_dn = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=-1)
        self.assertTupleEqual(self.loader_sp_up.ebands.shape, (12, 198))
        self.assertTupleEqual(self.loader_sp_dn.ebands.shape, (12, 198))
        self.assertIsNotNone(self.loader_sp_dn)
        self.assertIsNotNone(self.loader_sp_up)
        
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.resetwarnings()

    def test_properties(self):
        self.assertTupleEqual(self.loader.ebands.shape, (20, 120))
        self.assertAlmostEqual(self.loader.fermi, 0.185266535678, 5)
        self.assertAlmostEqual(self.loader.structure.lattice.a, 4.64303565932548, 5)

    def test_get_volume(self):
        self.assertAlmostEqual(self.loader.get_volume(), 477.6256714925874, 5)

    def test_set_upper_lower_bands(self):
        min_bnd = min(self.loader_sp_up.ebands.min(),self.loader_sp_dn.ebands.min())
        max_bnd = max(self.loader_sp_up.ebands.max(),self.loader_sp_dn.ebands.max())
        self.loader_sp_up.set_upper_lower_bands(min_bnd,max_bnd)
        self.loader_sp_dn.set_upper_lower_bands(min_bnd,max_bnd)
        self.assertTupleEqual(self.loader_sp_up.ebands.shape, (14, 198))
        self.assertTupleEqual(self.loader_sp_dn.ebands.shape, (14, 198))
Beispiel #2
0
class BandstructureLoaderTest(unittest.TestCase):

    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))
        bs_sp = loadfn(os.path.join(test_dir, "N2_bandstructure.json"))
        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)

        self.loader_sp_up = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=1)
        self.loader_sp_dn = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=-1)
        self.assertTupleEqual(self.loader_sp_up.ebands.shape, (12, 198))
        self.assertTupleEqual(self.loader_sp_dn.ebands.shape, (12, 198))
        self.assertIsNotNone(self.loader_sp_dn)
        self.assertIsNotNone(self.loader_sp_up)
        
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.simplefilter("default")

    def test_properties(self):
        self.assertTupleEqual(self.loader.ebands.shape, (20, 120))
        self.assertAlmostEqual(self.loader.fermi, 0.185266535678, 5)
        self.assertAlmostEqual(self.loader.structure.lattice.a, 4.64303565932548, 5)

    def test_get_volume(self):
        self.assertAlmostEqual(self.loader.get_volume(), 477.6256714925874, 5)

    def test_set_upper_lower_bands(self):
        min_bnd = min(self.loader_sp_up.ebands.min(),self.loader_sp_dn.ebands.min())
        max_bnd = max(self.loader_sp_up.ebands.max(),self.loader_sp_dn.ebands.max())
        self.loader_sp_up.set_upper_lower_bands(min_bnd,max_bnd)
        self.loader_sp_dn.set_upper_lower_bands(min_bnd,max_bnd)
        self.assertTupleEqual(self.loader_sp_up.ebands.shape, (14, 198))
        self.assertTupleEqual(self.loader_sp_dn.ebands.shape, (14, 198))
Beispiel #3
0
    def setUp(self):
        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)

        self.loader_sp = BandstructureLoader(bs_sp, vrun_sp.structures[-1])
        self.assertIsNotNone(self.loader_sp)
        self.assertTupleEqual(self.loader_sp.ebands_all.shape, (24, 198))

        warnings.simplefilter("ignore")
Beispiel #4
0
    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))
        bs_sp = loadfn(os.path.join(test_dir, "N2_bandstructure.json"))
        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)

        self.loader_sp_up = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=1)
        self.loader_sp_dn = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=-1)
        self.assertTupleEqual(self.loader_sp_up.ebands.shape, (12, 198))
        self.assertTupleEqual(self.loader_sp_dn.ebands.shape, (12, 198))
        self.assertIsNotNone(self.loader_sp_dn)
        self.assertIsNotNone(self.loader_sp_up)
        
        warnings.simplefilter("ignore")
Beispiel #5
0
    def setUp(self):
        self.loader = VasprunLoader(vrun)
        self.assertTupleEqual(self.loader.proj.shape, (120, 20, 2, 9))
        self.bztInterp = BztInterpolator(self.loader, lpfac=2)
        self.assertIsNotNone(self.bztInterp)
        warnings.simplefilter("ignore")

        bs_sp = loadfn(os.path.join(test_dir, "N2_bandstructure.json"))
        loader_sp_up = BandstructureLoader(bs_sp,
                                           vrun_sp.structures[-1],
                                           spin=1)
        loader_sp_dn = BandstructureLoader(bs_sp,
                                           vrun_sp.structures[-1],
                                           spin=-1)

        min_bnd = min(loader_sp_up.ebands.min(), loader_sp_dn.ebands.min())
        max_bnd = max(loader_sp_up.ebands.max(), loader_sp_dn.ebands.max())
        loader_sp_up.set_upper_lower_bands(min_bnd, max_bnd)
        loader_sp_dn.set_upper_lower_bands(min_bnd, max_bnd)

        self.bztI_up = BztInterpolator(loader_sp_up,
                                       lpfac=2,
                                       energy_range=np.inf,
                                       curvature=False)
        self.bztI_dn = BztInterpolator(loader_sp_dn,
                                       lpfac=2,
                                       energy_range=np.inf,
                                       curvature=False)
Beispiel #6
0
def spin_boltz(vrunfile="", spin=1, k_latt=1.0, write_json=True):
    fname = vrunfile.replace("vasprun.xml", "boltz2data.json")
    if not os.path.isfile(fname):
        kp = vrunfile.replace("vasprun.xml", "KPOINTS")
        v = Vasprun(vrunfile)
        nelect = v.parameters["NELECT"]
        bs = v.get_band_structure(kp, line_mode=False)
        # doping=10.**np.arange(20,22)
        temp_r = np.array([300, 400, 500, 600, 700, 800])
        doping = np.array([0, 10**18, 10**19, 10**20, 10**21, 10**22])
        loader = BandstructureLoader(bs,
                                     v.structures[-1],
                                     spin=spin,
                                     nelect=nelect)
        bztInterp = BztInterpolator(loader, lpfac=2, curvature=True)
        bztTransp = BztTransportProperties(bztInterp,
                                           doping=doping,
                                           temp_r=temp_r)
        xx = bztTransp.compute_properties_doping(doping=doping)
        # 4 temps, 2 doping
        Conductivity_doping = bztTransp.Conductivity_doping
        Seebeck_doping = bztTransp.Seebeck_doping
        Kappa_doping = bztTransp.Kappa_doping
        Effective_mass_doping = bztTransp.Effective_mass_doping
        Power_Factor_doping = bztTransp.Power_Factor_doping
        mu_r_eV = bztTransp.mu_r_eV

        info = {}
        info["mu_r_eV"] = mu_r_eV
        info["temp_r"] = temp_r
        info["doping"] = doping
        info["Conductivity_doping"] = Conductivity_doping
        info["Seebeck_doping"] = Seebeck_doping
        info["Kappa_doping"] = Kappa_doping
        info["Effective_mass_doping"] = Effective_mass_doping
        info["Power_Factor_doping"] = Power_Factor_doping

        info["Conductivity_mu"] = bztTransp.Conductivity_mu
        info["Seebeck_mu"] = bztTransp.Seebeck_mu
        info["Kappa_mu"] = bztTransp.Kappa_mu
        info["Power_Factor_mu"] = bztTransp.Power_Factor_mu
        info["Effective_mass_mu"] = bztTransp.Effective_mass_mu
        info[
            "Hall_carrier_conc_trace_mu"] = bztTransp.Hall_carrier_conc_trace_mu
        zt = []
        temp_zt = []
        for i, ii in enumerate(info["temp_r"]):
            for j, k in zip(info["Power_Factor_mu"][i], info["Kappa_mu"][i]):
                temp_zt.append(0.001 * j * ii / (k + k_latt))
            zt.append(temp_zt)
            temp_zt = []
        zt = np.array(zt)
        info["zt_mu"] = zt
        if write_json == True:
            f = open(fname, "w")
            f.write(json.dumps(info, cls=MontyEncoder))
            f.close()
        return info
    else:
        print("File exists")
Beispiel #7
0
def dos_from_boltztrap(bs_dict, energy_grid=0.005, avoid_projections=False):
    """
    Function to just interpolate a DOS from a bandstructure using BoltzTrap
    Args:
        bs_dict(dict): A MSONable dictionary for a bandstructure object
        energy_grid(float): the energy_grid spacing for the DOS in eV
        avoid_projections(bool): don't interpolate projections even if present
    """

    bs = BandStructure.from_dict(bs_dict)
    st = bs.structure
    energy_grid = energy_grid * units.eV
    projections = True if bs.projections and not avoid_projections else False

    if bs.is_spin_polarized:
        data_up = BandstructureLoader(bs, st, spin=1)
        data_dn = BandstructureLoader(bs, st, spin=-1)

        min_bnd = min(data_up.ebands.min(), data_dn.ebands.min())
        max_bnd = max(data_up.ebands.max(), data_dn.ebands.max())
        data_up.set_upper_lower_bands(min_bnd, max_bnd)
        data_dn.set_upper_lower_bands(min_bnd, max_bnd)
        bztI_up = BztInterpolator(data_up,
                                  energy_range=np.inf,
                                  curvature=False)
        bztI_dn = BztInterpolator(data_dn,
                                  energy_range=np.inf,
                                  curvature=False)

        npts_mu = int((max_bnd - min_bnd) / energy_grid)
        dos_up = bztI_up.get_dos(partial_dos=projections, npts_mu=npts_mu)
        dos_dn = bztI_dn.get_dos(partial_dos=projections, npts_mu=npts_mu)
        cdos = merge_up_down_doses(dos_up, dos_dn)

    else:
        data = BandstructureLoader(bs, st)
        min_bnd = min(data.ebands.min(), data.ebands.min())
        max_bnd = max(data.ebands.max(), data.ebands.max())
        npts_mu = int((max_bnd - min_bnd) / energy_grid)
        bztI = BztInterpolator(data, energy_range=np.inf, curvature=False)
        cdos = bztI.get_dos(partial_dos=projections, npts_mu=npts_mu)

    return cdos.as_dict()
Beispiel #8
0
class BandstructureLoaderTest(unittest.TestCase):
    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))

        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.resetwarnings()

    def test_properties(self):
        self.assertTupleEqual(self.loader.ebands.shape, (20, 120))
        self.assertAlmostEqual(self.loader.fermi, 0.185266535678, 5)
        self.assertAlmostEqual(self.loader.structure.lattice.a,
                               4.64303565932548, 5)

    def test_get_volume(self):
        self.assertAlmostEqual(self.loader.get_volume(), 477.6256714925874, 5)
class BandstructureLoaderTest(unittest.TestCase):

    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))

        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)
        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.resetwarnings()

    def test_properties(self):
        self.assertTupleEqual(self.loader.ebands.shape, (20, 120))
        self.assertAlmostEqual(self.loader.fermi, 0.185266535678, 5)
        self.assertAlmostEqual(self.loader.structure.lattice.a, 4.64303565932548, 5)

    def test_get_volume(self):
        self.assertAlmostEqual(self.loader.get_volume(), 477.6256714925874, 5)
Beispiel #10
0
    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))
        bs_sp = loadfn(os.path.join(test_dir, "N2_bandstructure.json"))
        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)

        self.loader_sp_up = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=1)
        self.loader_sp_dn = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=-1)
        self.assertTupleEqual(self.loader_sp_up.ebands.shape, (12, 198))
        self.assertTupleEqual(self.loader_sp_dn.ebands.shape, (12, 198))
        self.assertIsNotNone(self.loader_sp_dn)
        self.assertIsNotNone(self.loader_sp_up)
        
        warnings.simplefilter("ignore")
Beispiel #11
0
class BandstructureLoaderTest(unittest.TestCase):
    def setUp(self):
        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)

        self.loader_sp = BandstructureLoader(bs_sp, vrun_sp.structures[-1])
        self.assertIsNotNone(self.loader_sp)
        self.assertTupleEqual(self.loader_sp.ebands_all.shape, (24, 198))

        warnings.simplefilter("ignore")

    def tearDown(self):
        warnings.simplefilter("default")

    def test_properties(self):
        self.assertTupleEqual(self.loader.ebands_all.shape, (20, 120))
        self.assertAlmostEqual(self.loader.fermi, 0.185266535678, 5)
        self.assertAlmostEqual(self.loader.structure.lattice.a, 4.64303565932548, 5)

    def test_get_volume(self):
        self.assertAlmostEqual(self.loader.get_volume(), 477.6256714925874, 5)
Beispiel #12
0
    def setUp(self):
        self.loader = VasprunLoader(vrun)
        self.assertTupleEqual(self.loader.proj.shape,(120, 20, 2, 9))
        self.bztInterp = BztInterpolator(self.loader,lpfac=2)
        self.assertIsNotNone(self.bztInterp)
        warnings.simplefilter("ignore")
        
        bs_sp = loadfn(os.path.join(test_dir, "N2_bandstructure.json"))
        loader_sp_up = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=1)
        loader_sp_dn = BandstructureLoader(bs_sp, vrun_sp.structures[-1],spin=-1)
        
        min_bnd = min(loader_sp_up.ebands.min(),loader_sp_dn.ebands.min())
        max_bnd = max(loader_sp_up.ebands.max(),loader_sp_dn.ebands.max())
        loader_sp_up.set_upper_lower_bands(min_bnd,max_bnd)
        loader_sp_dn.set_upper_lower_bands(min_bnd,max_bnd)

        self.bztI_up = BztInterpolator(loader_sp_up,lpfac=2,energy_range=np.inf,curvature=False)
        self.bztI_dn = BztInterpolator(loader_sp_dn,lpfac=2,energy_range=np.inf,curvature=False)
Beispiel #13
0
    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))

        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)
        warnings.simplefilter("ignore")
    def setUp(self):
        bs = loadfn(os.path.join(test_dir, "PbTe_bandstructure.json"))

        self.loader = BandstructureLoader(bs, vrun.structures[-1])
        self.assertIsNotNone(self.loader)
        warnings.simplefilter("ignore")