def test_get_grid_point_from_address(self): self._mesh = (10, 10, 10) print("Compare get_grid_point_from_address from spglib and that " "written in python") print("with mesh numbers [%d %d %d]" % self._mesh) for address in list(np.ndindex(self._mesh)): gp_spglib = get_grid_point_from_address(address, self._mesh) gp_py = get_grid_point_from_address_py(address, self._mesh) # print("%s %d %d" % (address, gp_spglib, gp_py)) self.assertEqual(gp_spglib, gp_py)
def get_rotations_for_stars(self): "Finding the equivalent qpoints as the original q-star and their corresponding rotation matrices" if os.path.exists("reverse_mapping-m%d%d%d"%tuple(self._mesh)) and os.path.exists("kpt_rotations_at_stars-m%d%d%d"%tuple(self._mesh)): self._reverse_mapping=pickle.load(open("reverse_mapping-m%d%d%d"%tuple(self._mesh),"rb")) self._kpt_rotations_at_stars=pickle.load(open("kpt_rotations_at_stars-m%d%d%d"%tuple(self._mesh),"rb")) else: try: kpt_rotations_at_stars=[] reverse_mapping=[] for index, grid_point in enumerate(np.unique(self._mapping)): equi_pos = np.where(self._mapping == grid_point) kpt_rotations_at_stars.append([np.linalg.inv(rot) for rot in self._rot_mappings[equi_pos]]) reverse_mapping.append(equi_pos[0]) assert len(kpt_rotations_at_stars[index]) == self._weight[index] self._kpt_rotations_at_stars = kpt_rotations_at_stars self._reverse_mapping = reverse_mapping except ImportError: all_orbits=[] kpt_rotations_at_stars=[] for index, grid_point in enumerate(np.unique(self._mapping)): orig_address = self._grid[grid_point] orbits = [] rotations = [] for rot in self._kpoint_operations: rot_address = np.dot(rot, orig_address) % self._mesh in_orbits = False for orbit in orbits: if (rot_address == orbit).all(): in_orbits = True break if not in_orbits: orbits.append(rot_address) rotations.append(rot) # check if the number of rotations is correct. assert len(rotations) == self._weight[index], \ "Num rotations %d, weight %d" % ( len(rotations), self._weight[index]) all_orbits.append(orbits) kpt_rotations_at_stars.append(rotations) self._reverse_mapping=[[get_grid_point_from_address(o, self._mesh) for o in p]for p in all_orbits] assert len(sum(self._reverse_mapping, []))==len(self._mapping) self._kpt_rotations_at_stars=kpt_rotations_at_stars pickle.dump(self._reverse_mapping, open("reverse_mapping-m%d%d%d"%tuple(self._mesh),"wb")) pickle.dump(self._kpt_rotations_at_stars, open("kpt_rotations_at_stars-m%d%d%d"%tuple(self._mesh),"wb"))
def get_phono3py_configurations(settings, options): primitive_matrix = settings.get_primitive_matrix() supercell_matrix = settings.get_supercell_matrix() phonon_supercell_matrix = settings.get_phonon_supercell_matrix() masses = settings.get_masses() mesh = settings.get_mesh_numbers() mesh_divs = settings.get_mesh_divisors() coarse_mesh_shifts = settings.get_coarse_mesh_shifts() grid_points = settings.get_grid_points() grid_addresses = settings.get_grid_addresses() if grid_addresses is not None: grid_points = [get_grid_point_from_address(ga, mesh) for ga in grid_addresses] band_indices = settings.get_band_indices() # Brillouin zone integration: Tetrahedron (default) or smearing method sigma = settings.get_sigma() if sigma is None: sigmas = [] elif isinstance(sigma, float): sigmas = [sigma] else: sigmas = sigma if settings.get_is_tetrahedron_method(): sigmas = [None] + sigmas if len(sigmas) == 0: sigmas = [None] if settings.get_temperatures() is None: if settings.get_is_joint_dos(): temperature_points = None temperatures = None else: t_max = settings.get_max_temperature() t_min = settings.get_min_temperature() t_step = settings.get_temperature_step() temperature_points = [0.0, 300.0] # For spectra temperatures = np.arange(t_min, t_max + float(t_step) / 10, t_step) else: temperature_points = settings.get_temperatures() # For spectra temperatures = settings.get_temperatures() # For others if options.factor is None: frequency_factor_to_THz = VaspToTHz else: frequency_factor_to_THz = options.factor if settings.get_num_frequency_points() is None: if settings.get_frequency_pitch() is None: num_frequency_points = 201 frequency_step = None else: num_frequency_points = None frequency_step = settings.get_frequency_pitch() else: num_frequency_points = settings.get_num_frequency_points() frequency_step = None if options.freq_scale is None: frequency_scale_factor = 1.0 else: frequency_scale_factor = options.freq_scale if settings.get_cutoff_frequency() is None: cutoff_frequency = 1e-2 else: cutoff_frequency = settings.get_cutoff_frequency() if settings.get_is_translational_symmetry(): tsym_type = 1 elif settings.get_tsym_type() > 0: tsym_type = settings.get_tsym_type() else: tsym_type = 0 conf = {} conf['primitive_matrix'] = primitive_matrix conf['supercell_matrix'] = supercell_matrix conf['phonon_supercell_matrix'] = phonon_supercell_matrix conf['masses'] = masses conf['mesh'] = mesh conf['mesh_divs'] = mesh_divs conf['coarse_mesh_shifts'] = coarse_mesh_shifts conf['grid_points'] = grid_points conf['band_indices'] = band_indices conf['sigmas'] = sigmas conf['temperature_points'] = temperature_points conf['temperatures'] = temperatures conf['frequency_factor_to_THz'] = frequency_factor_to_THz conf['num_frequency_points'] = num_frequency_points conf['frequency_step'] = frequency_step conf['frequency_scale_factor'] = frequency_scale_factor conf['cutoff_frequency'] = cutoff_frequency conf['tsym_type'] = tsym_type return conf
def get_phono3py_configurations(settings, options): primitive_matrix = settings.get_primitive_matrix() supercell_matrix = settings.get_supercell_matrix() phonon_supercell_matrix = settings.get_phonon_supercell_matrix() masses = settings.get_masses() mesh = settings.get_mesh_numbers() mesh_divs = settings.get_mesh_divisors() coarse_mesh_shifts = settings.get_coarse_mesh_shifts() grid_points = settings.get_grid_points() grid_addresses = settings.get_grid_addresses() if grid_addresses is not None: grid_points = [ get_grid_point_from_address(ga, mesh) for ga in grid_addresses ] band_indices = settings.get_band_indices() # Brillouin zone integration: Tetrahedron (default) or smearing method sigma = settings.get_sigma() if sigma is None: sigmas = [] elif isinstance(sigma, float): sigmas = [sigma] else: sigmas = sigma if settings.get_is_tetrahedron_method(): sigmas = [None] + sigmas if len(sigmas) == 0: sigmas = [None] if settings.get_temperatures() is None: if settings.get_is_joint_dos(): temperature_points = None temperatures = None else: t_max = settings.get_max_temperature() t_min = settings.get_min_temperature() t_step = settings.get_temperature_step() temperature_points = [0.0, 300.0] # For spectra temperatures = np.arange(t_min, t_max + float(t_step) / 10, t_step) else: temperature_points = settings.get_temperatures() # For spectra temperatures = settings.get_temperatures() # For others if options.factor is None: frequency_factor_to_THz = VaspToTHz else: frequency_factor_to_THz = options.factor if settings.get_num_frequency_points() is None: if settings.get_frequency_pitch() is None: num_frequency_points = 201 frequency_step = None else: num_frequency_points = None frequency_step = settings.get_frequency_pitch() else: num_frequency_points = settings.get_num_frequency_points() frequency_step = None if options.freq_scale is None: frequency_scale_factor = 1.0 else: frequency_scale_factor = options.freq_scale if settings.get_cutoff_frequency() is None: cutoff_frequency = 1e-2 else: cutoff_frequency = settings.get_cutoff_frequency() if settings.get_is_translational_symmetry(): tsym_type = 1 elif settings.get_tsym_type() > 0: tsym_type = settings.get_tsym_type() else: tsym_type = 0 conf = {} conf['primitive_matrix'] = primitive_matrix conf['supercell_matrix'] = supercell_matrix conf['phonon_supercell_matrix'] = phonon_supercell_matrix conf['masses'] = masses conf['mesh'] = mesh conf['mesh_divs'] = mesh_divs conf['coarse_mesh_shifts'] = coarse_mesh_shifts conf['grid_points'] = grid_points conf['band_indices'] = band_indices conf['sigmas'] = sigmas conf['temperature_points'] = temperature_points conf['temperatures'] = temperatures conf['frequency_factor_to_THz'] = frequency_factor_to_THz conf['num_frequency_points'] = num_frequency_points conf['frequency_step'] = frequency_step conf['frequency_scale_factor'] = frequency_scale_factor conf['cutoff_frequency'] = cutoff_frequency conf['tsym_type'] = tsym_type return conf