def test_is_diagonal(self): """Testing is_diagonal""" from abipy.core.kpoints import is_diagonal assert is_diagonal(np.eye(3, dtype=np.int)) assert is_diagonal(np.eye(3, dtype=np.float)) a = np.eye(3, dtype=np.float) atol = 1e-12 a[1, 2] = atol assert is_diagonal(a, atol=atol) assert not is_diagonal(a, atol=atol / 2)
def test_is_diagonal(self): """Testing is_diagonal""" from abipy.core.kpoints import is_diagonal assert is_diagonal(np.eye(3, dtype=np.int)) assert is_diagonal(np.eye(3, dtype=np.float)) a = np.eye(3, dtype=np.float) atol = 1e-12 a[1, 2] = atol assert is_diagonal(a, atol=atol) assert not is_diagonal(a, atol=atol / 2)
def to_string(self, verbose=0): """String representation.""" lines = []; app = lines.append app(marquee("File Info", mark="=")) app(self.filestat(as_string=True)) app("") app(self.structure.to_string(verbose=verbose, title="Structure")) app("") app(self.ebands.to_string(with_structure=False, title="Electronic Bands")) app("Direct lattice of the primitive cell:") to_s = lambda x: "%0.6f" % x app("abc : " + " ".join([to_s(i).rjust(10) for i in self.pc_lattice.abc])) app("angles: " + " ".join([to_s(i).rjust(10) for i in self.pc_lattice.angles])) if is_diagonal(self.fold_matrix): app("Diagonal folding: %s" % (str(np.diagonal(self.fold_matrix)))) else: app("Folding matrix: %s" % str(self.fold_matrix)) if verbose: app(self.uf_kpoints.to_string(verbose=verbose, title="Unfolded k-points")) if verbose > 2: app(self.hdr.to_string(verbose=verbose, title="Abinit Header")) return "\n".join(lines)
def __init__(self, filepath): super(Fold2BlochNcfile, self).__init__(filepath) self.reader = ElectronsReader(filepath) # Initialize the electron bands from file. # Spectral weights are dimensioned with `nss` # Fortran arrays. # nctkarr_t("reduced_coordinates_of_unfolded_kpoints", "dp", "number_of_reduced_dimensions, nk_unfolded") # nctkarr_t("unfolded_eigenvalues", "dp", "max_number_of_states, nk_unfolded, number_of_spins") # nctkarr_t("spectral_weights", "dp", "max_number_of_states, nk_unfolded, nsppol_times_nspinor") self._ebands = self.reader.read_ebands() self.nss = max(self.nsppol, self.nspinor) self.fold_matrix = self.reader.read_value("fold_matrix") # Compute direct lattice of the primitive cell from fold_matrix. if is_diagonal(self.fold_matrix): folds = np.diagonal(self.fold_matrix) self.pc_lattice = Lattice((self.structure.lattice.matrix.T * (1.0 / folds)).T.copy()) else: raise NotImplementedError("non diagonal fold_matrix: %s" % str(self.fold_matrix)) # Read fold2bloch output data. self.uf_kfrac_coords = self.reader.read_value("reduced_coordinates_of_unfolded_kpoints") self.uf_kpoints = KpointList(self.pc_lattice.reciprocal_lattice, self.uf_kfrac_coords) self.uf_nkpt = len(self.uf_kpoints)
def __init__(self, filepath): super(Fold2BlochNcfile, self).__init__(filepath) self.reader = ElectronsReader(filepath) # Initialize the electron bands from file. # Spectral weights are dimensioned with `nss` # Fortran arrays. # nctkarr_t("reduced_coordinates_of_unfolded_kpoints", "dp", "number_of_reduced_dimensions, nk_unfolded") # nctkarr_t("unfolded_eigenvalues", "dp", "max_number_of_states, nk_unfolded, number_of_spins") # nctkarr_t("spectral_weights", "dp", "max_number_of_states, nk_unfolded, nsppol_times_nspinor") self._ebands = self.reader.read_ebands() self.nss = max(self.nsppol, self.nspinor) self.fold_matrix = self.reader.read_value("fold_matrix") # Compute direct lattice of the primitive cell from fold_matrix. if is_diagonal(self.fold_matrix): folds = np.diagonal(self.fold_matrix) self.pc_lattice = Lattice( (self.structure.lattice.matrix.T * (1.0 / folds)).T.copy()) else: raise NotImplementedError("non diagonal fold_matrix: %s" % str(self.fold_matrix)) # Read fold2bloch output data. self.uf_kfrac_coords = self.reader.read_value( "reduced_coordinates_of_unfolded_kpoints") self.uf_kpoints = KpointList(self.pc_lattice.reciprocal_lattice, self.uf_kfrac_coords) self.uf_nkpt = len(self.uf_kpoints)
def to_string(self, verbose=0): """String representation.""" lines = [] app = lines.append app(marquee("File Info", mark="=")) app(self.filestat(as_string=True)) app("") app(self.structure.to_string(verbose=verbose, title="Structure")) app("") app( self.ebands.to_string(with_structure=False, title="Electronic Bands")) app("Direct lattice of the primitive cell:") to_s = lambda x: "%0.6f" % x app("abc : " + " ".join([to_s(i).rjust(10) for i in self.pc_lattice.abc])) app("angles: " + " ".join([to_s(i).rjust(10) for i in self.pc_lattice.angles])) if is_diagonal(self.fold_matrix): app("Diagonal folding: %s" % (str(np.diagonal(self.fold_matrix)))) else: app("Folding matrix: %s" % str(self.fold_matrix)) if verbose: app( self.uf_kpoints.to_string(verbose=verbose, title="Unfolded k-points")) if verbose > 2: app(self.hdr.to_string(verbose=verbose, title="Abinit Header")) return "\n".join(lines)