class BztTransportPropertiesTest(unittest.TestCase): def setUp(self): loader = VasprunLoader().from_file(vrunfile) bztInterp = BztInterpolator(loader) self.bztTransp = BztTransportProperties(bztInterp,temp_r = np.arange(300,600,100)) self.assertIsNotNone(self.bztTransp) warnings.simplefilter("ignore") def tearDown(self): warnings.resetwarnings() def test_properties(self): for p in [self.bztTransp.Conductivity_mu,self. bztTransp.Seebeck_mu, self.bztTransp.Kappa_mu,self.bztTransp.Effective_mass_mu, self.bztTransp.Power_Factor_mu]: self.assertTupleEqual(p.shape,(3, 3670, 3, 3)) for p in [self.bztTransp.Carrier_conc_mu,self.bztTransp.Hall_carrier_conc_trace_mu]: self.assertTupleEqual(p.shape,(3, 3670)) def test_compute_properties_doping(self): self.bztTransp.compute_properties_doping(doping=10.**np.arange(16,23)) for p in [self.bztTransp.Conductivity_doping,self. bztTransp.Seebeck_doping, self.bztTransp.Kappa_doping,self.bztTransp.Effective_mass_doping, self.bztTransp.Power_Factor_doping]: self.assertTupleEqual(p['n'].shape,(3, 7, 3, 3))
class BztTransportPropertiesTest(unittest.TestCase): def setUp(self): loader = VasprunLoader(vrun) bztInterp = BztInterpolator(loader, lpfac=2) self.bztTransp = BztTransportProperties(bztInterp, temp_r = np.arange(300,600,100)) self.assertIsNotNone(self.bztTransp) warnings.simplefilter("ignore") def tearDown(self): warnings.simplefilter("default") def test_properties(self): for p in [self.bztTransp.Conductivity_mu, self.bztTransp.Seebeck_mu, self.bztTransp.Kappa_mu, self.bztTransp.Effective_mass_mu, self.bztTransp.Power_Factor_mu]: self.assertTupleEqual(p.shape, (3, 3670, 3, 3)) for p in [self.bztTransp.Carrier_conc_mu, self.bztTransp.Hall_carrier_conc_trace_mu]: self.assertTupleEqual(p.shape, (3, 3670)) def test_compute_properties_doping(self): self.bztTransp.compute_properties_doping(doping=10.**np.arange(20,22)) for p in [self.bztTransp.Conductivity_doping,self. bztTransp.Seebeck_doping, self.bztTransp.Kappa_doping,self.bztTransp.Effective_mass_doping, self.bztTransp.Power_Factor_doping]: self.assertTupleEqual(p['n'].shape,(3, 2, 3, 3))
def make_effective_mass(vasprun, temp, concentrations, band_gap): try: from pymatgen.electronic_structure.boltztrap2 import VasprunBSLoader, \ BztInterpolator, BztTransportProperties except BoltztrapError: raise ImportError('Calculating effective mass requires BoltzTrap2') vl = VasprunBSLoader(vasprun) energy_range = band_gap / 2 + 2.0 bi = BztInterpolator(vl, energy_range=energy_range) btp = BztTransportProperties(bi, temp_r=np.array([temp])) btp.compute_properties_doping(concentrations) return EffectiveMass(p=btp.Effective_mass_doping["p"].tolist()[0], n=btp.Effective_mass_doping["n"].tolist()[0], temperature=temp, concentrations=concentrations)
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")
def nonspin_boltz(vrunfile="", k_latt=1.0, write_json=False): fname = vrunfile.replace("vasprun.xml", "boltz2data.json") if not os.path.isfile(fname): vrun = Vasprun(vrunfile, parse_projected_eigen=True) loader = VasprunLoader().from_file(vrunfile) temp_r = np.array([300, 400, 500, 600, 700, 800]) doping = np.array([0, 10**18, 10**19, 10**20, 10**21, 10**22]) bztInterp = BztInterpolator(loader, lpfac=2) bztTransp = BztTransportProperties(bztInterp, temp_r=temp_r, doping=doping) 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")
class BztTransportPropertiesTest(unittest.TestCase): def setUp(self): loader = VasprunBSLoader(vrun) bztInterp = BztInterpolator(loader, lpfac=2) self.bztTransp = BztTransportProperties(bztInterp, temp_r=np.arange(300, 600, 100)) self.assertIsNotNone(self.bztTransp) warnings.simplefilter("ignore") self.bztTransp = BztTransportProperties( bztInterp, doping=10.0 ** np.arange(20, 22), temp_r=np.arange(300, 600, 100) ) self.assertIsNotNone(self.bztTransp) self.assertEqual(self.bztTransp.contain_props_doping, True) warnings.simplefilter("ignore") bztInterp = BztInterpolator(loader, lpfac=2) self.bztTransp = BztTransportProperties( bztInterp, temp_r=np.arange(300, 600, 100), save_bztTranspProps=True, fname=bzttransp_fn, ) self.assertIsNotNone(self.bztTransp) warnings.simplefilter("ignore") bztInterp = BztInterpolator(loader, lpfac=2) self.bztTransp = BztTransportProperties(bztInterp, load_bztTranspProps=True, fname=bzttransp_fn) self.assertIsNotNone(self.bztTransp) warnings.simplefilter("ignore") loader_sp = VasprunBSLoader(vrun_sp) bztInterp_sp = BztInterpolator(loader_sp, lpfac=2) self.bztTransp_sp = BztTransportProperties(bztInterp_sp, temp_r=np.arange(300, 600, 100)) self.assertIsNotNone(self.bztTransp_sp) warnings.simplefilter("ignore") bztInterp_sp = BztInterpolator(loader_sp, lpfac=2) self.bztTransp_sp = BztTransportProperties( bztInterp_sp, temp_r=np.arange(300, 600, 100), save_bztTranspProps=True, fname=bzttransp_fn, ) self.assertIsNotNone(self.bztTransp_sp) warnings.simplefilter("ignore") bztInterp_sp = BztInterpolator(loader_sp, lpfac=2) self.bztTransp_sp = BztTransportProperties(bztInterp_sp, load_bztTranspProps=True, fname=bzttransp_fn) self.assertIsNotNone(self.bztTransp_sp) warnings.simplefilter("ignore") def tearDown(self): warnings.simplefilter("default") def test_properties(self): for p in [ self.bztTransp.Conductivity_mu, self.bztTransp.Seebeck_mu, self.bztTransp.Kappa_mu, self.bztTransp.Effective_mass_mu, self.bztTransp.Power_Factor_mu, ]: self.assertTupleEqual(p.shape, (3, 3686, 3, 3)) for p in [ self.bztTransp.Carrier_conc_mu, self.bztTransp.Hall_carrier_conc_trace_mu, ]: self.assertTupleEqual(p.shape, (3, 3686)) for p in [ self.bztTransp_sp.Conductivity_mu, self.bztTransp_sp.Seebeck_mu, self.bztTransp_sp.Kappa_mu, self.bztTransp_sp.Effective_mass_mu, self.bztTransp_sp.Power_Factor_mu, ]: self.assertTupleEqual(p.shape, (3, 3252, 3, 3)) for p in [ self.bztTransp_sp.Carrier_conc_mu, self.bztTransp_sp.Hall_carrier_conc_trace_mu, ]: self.assertTupleEqual(p.shape, (3, 3252)) def test_compute_properties_doping(self): self.bztTransp.compute_properties_doping(doping=10.0 ** np.arange(20, 22)) for p in [ self.bztTransp.Conductivity_doping, self.bztTransp.Seebeck_doping, self.bztTransp.Kappa_doping, self.bztTransp.Effective_mass_doping, self.bztTransp.Power_Factor_doping, ]: self.assertTupleEqual(p["n"].shape, (3, 2, 3, 3)) self.assertEqual(self.bztTransp.contain_props_doping, True) self.bztTransp_sp.compute_properties_doping(doping=10.0 ** np.arange(20, 22)) for p in [ self.bztTransp_sp.Conductivity_doping, self.bztTransp_sp.Seebeck_doping, self.bztTransp_sp.Kappa_doping, self.bztTransp_sp.Effective_mass_doping, self.bztTransp_sp.Power_Factor_doping, ]: self.assertTupleEqual(p["n"].shape, (3, 2, 3, 3)) self.assertEqual(self.bztTransp_sp.contain_props_doping, True)