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.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 #2
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 #3
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 #4
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 #5
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()