def __init__( self, energies: Dict[Spin, np.ndarray], kpoints: np.ndarray, ir_kpoints_idx: np.ndarray, ir_kpoint_mapping: np.ndarray, ir_kpoint_weights: np.ndarray, tetrahedra: Dict[Spin, np.ndarray], ir_tetrahedra: Dict[Spin, np.ndarray], ir_tetrahedra_energies: Dict[Spin, np.ndarray], ir_tetrahedra_idx: np.ndarray, ir_tetrahedra_to_full_idx: np.ndarray, ir_tetrahedra_weights: np.ndarray, e21: Dict[Spin, np.ndarray], e31: Dict[Spin, np.ndarray], e41: Dict[Spin, np.ndarray], e32: Dict[Spin, np.ndarray], e42: Dict[Spin, np.ndarray], e43: Dict[Spin, np.ndarray], max_tetrahedra_energies: Dict[Spin, np.ndarray], min_tetrahedra_energies: Dict[Spin, np.ndarray], cross_section_weights: Dict[Spin, np.ndarray], tetrahedron_volume: float, weights_cache: Optional[Dict[Spin, np.ndarray]] = None, weights_mask_cache: Optional[Dict[Spin, np.ndarray]] = None, energies_cache: Optional[Dict[Spin, np.ndarray]] = None, ): self.energies = energies self.kpoints = kpoints self.ir_kpoints_idx = ir_kpoints_idx self.ir_kpoint_mapping = ir_kpoint_mapping self.ir_kpoint_weights = ir_kpoint_weights self.tetrahedra = tetrahedra self.ir_tetrahedra = ir_tetrahedra self.ir_tetrahedra_energies = ir_tetrahedra_energies self.ir_tetrahedra_idx = ir_tetrahedra_idx self.ir_tetrahedra_to_full_idx = ir_tetrahedra_to_full_idx self.ir_tetrahedra_weights = ir_tetrahedra_weights self.e21 = e21 self.e31 = e31 self.e41 = e41 self.e32 = e32 self.e42 = e42 self.e43 = e43 self.max_tetrahedra_energies = max_tetrahedra_energies self.min_tetrahedra_energies = min_tetrahedra_energies self.cross_section_weights = cross_section_weights self._tetrahedron_volume = tetrahedron_volume self._weights_cache = {} if weights_cache is None else weights_cache self._weights_mask_cache = ({} if weights_mask_cache is None else weights_mask_cache) self._energies_cache = {} if energies_cache is None else energies_cache self.grouped_ir_to_full = groupby( np.arange(len(ir_tetrahedra_to_full_idx)), ir_tetrahedra_to_full_idx) self._ir_weights_shape = { s: (len(energies[s]), len(ir_kpoints_idx)) for s in energies }
def test_groupby(elements, groups, expected): elements = ["a", "b", "1", "2", "c", "d"] groups = [2, 0, 1, 2, 0, 0] expected_output = [["b", "c", "d"], ["1"], ["a", "2"]] output = groupby(elements, groups) output = [x.tolist() for x in output] assert output == expected_output
def __init__( self, structure: Structure, energies: Dict[Spin, np.ndarray], vvelocities_product: Dict[Spin, np.ndarray], velocities: Dict[Spin, np.ndarray], kpoint_mesh: np.ndarray, kpoints: np.ndarray, ir_kpoints_idx: np.ndarray, ir_to_full_kpoint_mapping: np.ndarray, tetrahedra: np.ndarray, ir_tetrahedra_info: np.ndarray, efermi: float, num_electrons: float, is_metal: bool, soc: bool, vb_idx: Optional[Dict[Spin, int]] = None, ): self.structure = structure self.velocities_product = vvelocities_product self.kpoint_mesh = kpoint_mesh self.intrinsic_fermi_level = efermi self.ir_to_full_kpoint_mapping = ir_to_full_kpoint_mapping self._soc = soc self.num_electrons = num_electrons self.is_metal = is_metal self.vb_idx = vb_idx self.spins = list(energies.keys()) self.velocities = { s: v.transpose((0, 2, 1)) for s, v in velocities.items() } self.dos = None self.scattering_rates = None self.scattering_labels = None self.doping = None self.temperatures = None self.fermi_levels = None self.electron_conc = None self.hole_conc = None self.conductivity = None self.seebeck = None self.electronic_thermal_conductivity = None self.mobility = None self.overlap_calculator = None self.mrta_calculator = None self.fd_cutoffs = None self.grouped_ir_to_full = groupby(np.arange(len(kpoints)), ir_to_full_kpoint_mapping) self.tetrahedral_band_structure = TetrahedralBandStructure.from_data( energies, kpoints, tetrahedra, structure, ir_kpoints_idx, ir_to_full_kpoint_mapping, *ir_tetrahedra_info) logger.info("Initializing momentum relaxation time factor calculator") self.mrta_calculator = MRTACalculator.from_data( kpoints, self.velocities)
def __init__( self, structure: Structure, energies: Dict[Spin, np.ndarray], vvelocities_product: Dict[Spin, np.ndarray], effective_mass: Dict[Spin, np.ndarray], projections: Dict[Spin, Dict[str, np.ndarray]], kpoint_mesh: np.ndarray, kpoints: np.ndarray, ir_kpoints: np.ndarray, ir_kpoints_idx: np.ndarray, ir_to_full_kpoint_mapping: np.ndarray, tetrahedra: np.ndarray, ir_tetrahedra_info: np.ndarray, efermi: float, num_electrons: float, is_metal: bool, soc: bool, vb_idx: Optional[Dict[Spin, int]] = None, ): self.structure = structure self.energies = energies self.velocities_product = vvelocities_product self.effective_mass = effective_mass self.kpoint_mesh = kpoint_mesh self.kpoints = kpoints self.ir_kpoints = ir_kpoints self.ir_kpoints_idx = ir_kpoints_idx self.ir_to_full_kpoint_mapping = ir_to_full_kpoint_mapping self.intrinsic_fermi_level = efermi self._soc = soc self.num_electrons = num_electrons self.is_metal = is_metal self.vb_idx = vb_idx self.spins = self.energies.keys() self.a_factor, self.c_factor = _calculate_orbital_factors(projections) self.dos = None self.scattering_rates = None self.scattering_labels = None self.doping = None self.temperatures = None self.fermi_levels = None self.electron_conc = None self.hole_conc = None self.conductivity = None self.seebeck = None self.electronic_thermal_conductivity = None self.mobility = None self.overlap_calculator = None self.fd_cutoffs = None self.grouped_ir_to_full = groupby(np.arange(len(kpoints)), ir_to_full_kpoint_mapping) self.tetrahedral_band_structure = TetrahedralBandStructure( energies, kpoints, tetrahedra, structure, ir_kpoints_idx, ir_to_full_kpoint_mapping, *ir_tetrahedra_info)
def __init__( self, energies: Dict[Spin, np.ndarray], kpoints: np.ndarray, tetrahedra: np.ndarray, structure: Structure, ir_kpoints_idx: np.ndarray, ir_kpoint_mapping: np.ndarray, ir_tetrahedra_idx: Optional[np.ndarray] = None, ir_tetrahedra_to_full_idx: Optional[np.ndarray] = None, ir_tetrahedra_weights: Optional[np.ndarray] = None, ): logger.info("Generating tetrahedron mesh") tparams = (ir_tetrahedra_idx, ir_tetrahedra_to_full_idx, ir_tetrahedra_weights) if len(set([x is None for x in tparams])) != 1: raise ValueError( "Either all or none of ir_tetrahedra_idx, " "ir_tetrahedra_to_full_idx and ir_tetrahedra_weights should be set." ) if ir_tetrahedra_idx is None: ir_tetrahedra_idx = np.arange(len(kpoints)) ir_tetrahedra_to_full_idx = np.ones_like(ir_tetrahedra_idx) ir_tetrahedra_weights = np.ones_like(ir_tetrahedra_idx) self.energies = energies self.kpoints = kpoints self.ir_tetrahedra_idx = ir_tetrahedra_idx self.ir_tetrahedra_to_full_idx = ir_tetrahedra_to_full_idx self.ir_tetrahedra_weights = ir_tetrahedra_weights self.ir_kpoints_idx = ir_kpoints_idx self.ir_kpoint_mapping = ir_kpoint_mapping _, self.ir_kpoint_weights = np.unique(ir_kpoint_mapping, return_counts=True) # need to keep track of full tetrahedra to recover full k-point indices # when calculating scattering rates (i.e., k-k' is symmetry inequivalent). self.tetrahedra, _ = process_tetrahedra(tetrahedra, self.energies) # store irreducible tetrahedra and use energies to calculate diffs and min/maxes self.ir_tetrahedra, self.ir_tetrahedra_energies = process_tetrahedra( tetrahedra[self.ir_tetrahedra_idx], self.energies) # the remaining properties are given for each irreducible tetrahedra ( self.e21, self.e31, self.e41, self.e32, self.e42, self.e43, ) = get_tetrahedra_energy_diffs(self.ir_tetrahedra_energies) ( self.max_tetrahedra_energies, self.min_tetrahedra_energies, ) = get_max_min_tetrahedra_energies(self.ir_tetrahedra_energies) self.cross_section_weights = get_tetrahedra_cross_section_weights( structure.lattice.reciprocal_lattice.matrix, self.kpoints, self.ir_tetrahedra, self.e21, self.e31, self.e41, ) self._tetrahedron_volume = 1 / len(tetrahedra) self.grouped_ir_to_full = groupby( np.arange(len(ir_tetrahedra_to_full_idx)), ir_tetrahedra_to_full_idx) self._ir_weights_shape = { s: (len(self.energies[s]), len(ir_kpoints_idx)) for s in self.energies } self._weights_cache = {} self._weights_mask_cache = {} self._energies_cache = {} self._tetrahedra_connections = defaultdict(set) for tet in tetrahedra: self._tetrahedra_connections[tet[0]].update(tet) self._tetrahedra_connections[tet[1]].update(tet) self._tetrahedra_connections[tet[2]].update(tet) self._tetrahedra_connections[tet[3]].update(tet)