import numpy as np from ulmic.atomic_units import AtomicUnits from ulmic.ulmi.jit.linear_response import jit_linear_interband_response from ulmic.external.hdf5interface import Hdf5Interface # from ulmic.result import Result # from ulmic.medium import Medium au = AtomicUnits() class FinalStateAnalyzer: """ A class for analyzing the electronic state at the end of a simulation. CURRENTLY, THIS CLASS WORKS ONLY FOR TDSE SIMULATIONS. """ def __init__(self, medium, result, copy_wavefunctions=False): self.medium = medium self.neighbour_table = None if copy_wavefunctions: self.psi = result.final_state.copy() else: self.psi = result.final_state self.rho_diagonal = np.sum(np.real(self.psi * self.psi.conj()), axis=-1) # (nk, nb) def delta_response(self, t0, A0, t_array, ignore_coherences=False, subtract_initial_state=False): """ Return the electric current density induced by A(t) = A_0 delta(t-t0).
def __init__(self, input_file, k_points=None, buffer_width=(0,0,0), read_now=True, band_max=None, read_momentum=True, read_overlap=False, logger=None, **kwargs): """ Class responsible for loading data from hdf5-files. Causes the specified k-points to be loaded. [Should only change if hdf5-format changes] input_file: hdf5 input File k_points: None for all k-points, int for single k-point, ndarray for list for set of k-points, (size,rank) tuple for MPI with automatic partioning, (n,m,l,rank) tuple for MPI with custom partitioning, buffer_width: three-dimensional tuple with number of buffer points in each direction. Positive number for buffer in one direction, or negative number for buffer in both directions. """ """ HDF5 Data format: nk: number of k-points nb: number of bands nv: number of valence band electrons size: number of k-points along each reciprocal axis (Monkhorst-Pack w/ Gamma point) spin_factor:number of electrons per band klist1d: (nk,3) array of reduced coordinates of the k-points kllist3d: (nk1,nk2,nk3) array of k-point indices with (0,0,0) being the Gamma point lattice_vectors: (3,3) column vectors of the unit cell in Cartesian coordinates reciprocal_vectors: (3,3) column vectors energy: (nk,nb) momentum: (nk,nb,nb,3) overlap: (nk,3,2,nb,nb) neighbour_table: (nk,3,2) """ self.logger = logger or logging.getLogger(__name__) self.input_file = input_file self.buffer_width = buffer_width self.au = AtomicUnits() if os.path.isfile(input_file): hdf5_data = h5py.File(input_file, 'r') elif os.path.isfile(os.path.join(ue.get_data_dir(),input_file)): hdf5_data = h5py.File(os.path.join(ue.get_data_dir(),input_file), 'r') else: raise RuntimeError('File {} not found'.format(input_file)) self.klist1d = hdf5_data['klist1d'][()] self.klist3d = hdf5_data['klist3d'][()] self.lattice_vectors = hdf5_data['lattice_vectors'][()] self.reciprocal_vectors = hdf5_data['reciprocal_vectors'][()] self.size = hdf5_data['size'][()] self.spin_factor = hdf5_data['spin_factor'][()] self.nv = hdf5_data['valence_bands'][()] if read_overlap: self.neighbour_table = hdf5_data['neighbour_table'][()] self.volume = np.abs(np.dot(self.lattice_vectors[:,0], np.cross(self.lattice_vectors[:,1],self.lattice_vectors[:,2]))) self.check_input_data() self.nk1d = len(self.klist1d) self.nk = len(self.klist1d) self.nk_vol,self.nb = hdf5_data['energy'].shape self.unique_points_no_buffer = list(set(list(self.klist3d.flatten()))) self.k_inner = self.generate_k_slice(k_points) self.k_buffer = self.generate_k_buffer(self.k_inner, buffer_width) self.k_slice_buffer = np.concatenate((self.k_inner, self.k_buffer)) self.local_to_global = np.copy(self.k_slice_buffer) self.global_to_local = {} for i in range(len(self.k_slice_buffer)): self.global_to_local[str(self.k_slice_buffer[i])] = i self.nk_eval = len(self.k_inner) self.nk_buffer = len(self.k_buffer) self.nk_local = len(self.k_slice_buffer) if band_max is None: band_max = self.nb else: band_max = min(self.nb, band_max) self.nb = band_max self.band_slice = np.arange(self.nb, dtype=np.intp) if read_now: self.read(read_momentum,read_overlap) self.k_gamma = None for i in range(self.nk): if np.allclose(self.klist1d[i],0.0): self.k_gamma = i logging.info('{} successfully loaded.'.format(self.input_file))