Exemplo n.º 1
0
Arquivo: plot.py Projeto: cpoli/tbee
    def intensity_1d(self, intensity, ms=20., lw=2., fs=20., title=r'$|\psi^{(j)}|^2$'):
        '''
        Plot intensity for 1D lattices.

        :param intensity: np.array. Field intensity.
        :param ms: Positive Float. Default value 20. Markersize.
        :param lw: Positive Float. Default value 2. Linewith, connect sublattice sites.
        :param fs: Positive Float. Default value 20. Font size.
        :param title: String. Default value 'Intensity'. Figure title.
        '''
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(lw, 'lw')
        error_handling.positive_real(fs, 'fs')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$j$', fontsize=fs)
        ax.set_ylabel(title, fontsize=fs)
        ax.set_title(title, fontsize=fs)
        for t, c in zip(self.sys.lat.tags, self.colors):
            plt.plot(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == t],
                        intensity[self.sys.lat.coor['tag'] == t],
                        '-o', color=c, ms=ms, lw=lw)
        plt.xlim([-1., self.sys.lat.sites])
        plt.ylim([0., np.max(intensity)+.05])
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemplo n.º 2
0
    def get_propagation(self, ham, psi_init, steps, dz, norm=False):
        """
        Get the time evolution.

        :param ham: sparse.csr_matrix. Tight-Binding Hamilonian.
        :param psi_init: np.ndarray. Initial state.
        :param steps: Positive Integer. Number of steps.
        :param dz: Positive number. Step.
        :param norm: Boolean. Default value True. Normalize the norm to 1 at each step.
        """
        error_handling.empty_ham(ham)
        error_handling.ndarray(psi_init, "psi_init", self.lat.sites)
        error_handling.positive_int(steps, "steps")
        error_handling.positive_real(dz, "dz")
        error_handling.boolean(norm, "norm")
        self.steps = steps
        self.dz = dz
        self.prop = np.empty((self.lat.sites, self.steps), "c16")
        self.prop[:, 0] = psi_init
        diag = 1j * np.ones(self.lat.sites, "c16")
        A = (sparse.diags(diag, 0) - 0.5 * self.dz * ham).toarray()
        B = (sparse.diags(diag, 0) + 0.5 * self.dz * ham).toarray()
        mat = np.dot(LA.inv(A), B)
        for i in range(1, self.steps):
            self.prop[:, i] = np.dot(mat, self.prop[:, i - 1])
            if norm:
                self.prop[:, i] /= np.abs(self.prop[:, i]).sum()
Exemplo n.º 3
0
    def get_propagation(self, ham, psi_init, steps, dz, norm=False):
        '''
        Get the time evolution.

        :param ham: sparse.csr_matrix. Tight-Binding Hamilonian.
        :param psi_init: np.ndarray. Initial state.
        :param steps: Positive Integer. Number of steps.
        :param dz: Positive number. Step.
        :param norm: Boolean. Default value True. Normalize the norm to 1 at each step.
        '''
        error_handling.empty_ham(ham)
        error_handling.ndarray(psi_init, 'psi_init', self.lat.sites)
        error_handling.positive_int(steps, 'steps')
        error_handling.positive_real(dz, 'dz')
        error_handling.boolean(norm, 'norm')
        self.steps = steps
        self.dz = dz
        self.prop = np.empty((self.lat.sites, self.steps), 'c16')
        self.prop[:, 0] = psi_init
        diag = 1j*np.ones(self.lat.sites, 'c16')
        A = (sparse.diags(diag, 0) - 0.5 * self.dz * ham).toarray()
        B = (sparse.diags(diag, 0) + 0.5 * self.dz * ham).toarray()
        mat = (np.dot(LA.inv(A), B))
        for i in range(1, self.steps):
            self.prop[:, i] = np.dot(mat, self.prop[:, i-1])
            if norm:
                self.prop[:, i] /= np.abs(self.prop[:, i]).sum()
Exemplo n.º 4
0
    def intensity_disk(self,
                       intensity,
                       s=200.,
                       fs=20.,
                       lims=None,
                       figsize=None,
                       title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Colormap with identical disk shape.

        :param intensity: np.array.Field intensity.
        :param s: Default value 200. Disk size.
        :param fs: Default value 20. Font size.
        :param lims: List. Default value None. Colormap limits.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_n|^2$'. Title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots(figsize=figsize)
        plt.title(title, fontsize=fs + 5)
        map_red = plt.get_cmap('Reds')
        if lims is None:
            lims = [0., np.max(intensity)]
            y_ticks = ['0', 'max']
        else:
            y_ticks = lims
        plt.scatter(self.sys.lat.coor['x'],
                    self.sys.lat.coor['y'],
                    c=intensity,
                    s=s,
                    cmap=map_red,
                    vmin=lims[0],
                    vmax=lims[1])
        cbar = plt.colorbar(ticks=lims)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_xlim(
            np.min(self.sys.lat.coor['x']) - 1.,
            np.max(self.sys.lat.coor['x']) + 1.)
        ax.set_ylim(
            np.min(self.sys.lat.coor['y']) - 1.,
            np.max(self.sys.lat.coor['y']) + 1.)
        cbar.ax.set_yticklabels([y_ticks[0], y_ticks[1]])
        cbar.ax.tick_params(labelsize=fs)
        ax.set_aspect('equal')
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemplo n.º 5
0
Arquivo: plot.py Projeto: cpoli/tbee
    def intensity_area(self, intensity, s=1000., lw=1., fs=20., plt_hop=False,
                                  figsize=None, title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Intensity propotional to disk shape.

        :param intensity: np.array. Intensity.
        :param s: Positive Float. Default value 1000. 
            Circle size given by s * intensity.
        :param lw: Positive Float. Default value 1. Hopping linewidths.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param plt_hop: Boolean. Default value False. Plot hoppings.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_{ij}|^2$'. Figure title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.boolean(plt_hop, 'plt_hop')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$i$', fontsize=fs)
        ax.set_ylabel('$j$', fontsize=fs)
        ax.set_title(title, fontsize=fs)
        if plt_hop:
            plt.plot([self.sys.lat.coor['x'][self.sys.hop['i'][:]], 
                             self.sys.lat.coor['x'][self.sys.hop['j'][:]]],
                            [self.sys.lat.coor['y'][self.sys.hop['i'][:]],
                             self.sys.lat.coor['y'][self.sys.hop['j'][:]]],
                            'k', lw=lw)
        for tag, color in zip(self.sys.lat.tags, self.colors):
            plt.scatter(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == tag],
                        self.sys.lat.coor['y'][self.sys.lat.coor['tag'] == tag],
                        s=100*s*intensity[self.sys.lat.coor['tag'] == tag],
                        c=color, alpha=0.5)
        ax.set_aspect('equal')
        ax.axis('off')
        x_lim = [np.min(self.sys.lat.coor['x'])-2., np.max(self.sys.lat.coor['x'])+2.]
        y_lim = [np.min(self.sys.lat.coor['y'])-2., np.max(self.sys.lat.coor['y'])+2.]
        ax.set_xlim(x_lim)
        ax.set_ylim(y_lim)
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemplo n.º 6
0
    def get_pumping(self, hams, psi_init, steps, dz, norm=True):
        '''
        Get the time evolution with adiabatic pumpings.

        :param hams: List of sparse.csr_matrices. Tight-Binding Hamilonians.
        :param psi_init: np.ndarray. Initial state.
        :param steps: Positive integer. Number of steps.
        :param dz: Positive number. Step.
        :param norm: Boolean. Default value True. Normalize the norm to 1 at each step.
        '''
        error_handling.get_pump(hams)
        error_handling.ndarray(psi_init, 'psi_init', self.lat.sites)
        error_handling.positive_int(steps, 'steps')
        error_handling.positive_real(dz, 'dz')
        error_handling.boolean(norm, 'norm')
        self.steps = steps
        self.dz = dz
        no = len(hams)
        self.prop = np.empty((self.lat.sites, self.steps), 'c16')
        self.prop[:, 0] = psi_init
        diag = 1j * np.ones(self.lat.sites, 'c16')
        delta = self.steps // (1 + no)
        A = (sparse.diags(diag, 0) - 0.5 * self.dz * hams[0]).toarray()
        B = (sparse.diags(diag, 0) + 0.5 * self.dz * hams[0]).toarray()
        mat = (np.dot(LA.inv(A), B))
        # before pumping
        for i in range(1, delta):
           self.prop[:, i] = np.dot(mat, self.prop[:, i-1])
           if norm:
               self.prop[:, i] /= np.abs(self.prop[:, i]).sum()
      # pumping
        c = np.linspace(0, 1, delta)
        for j in range(0, no-1):
            for i in range(0, delta):
                ham = (1-c[i])*hams[j]+c[i]*hams[j+1]
                A = (sparse.diags(diag, 0) - 0.5 * self.dz * ham).toarray()
                B = (sparse.diags(diag, 0) + 0.5 * self.dz * ham).toarray()
                mat = (np.dot(LA.inv(A), B))
                self.prop[:, (j+1)*delta+i] = np.dot(mat, self.prop[:,  (j+1)*delta+i-1])
                if norm:
                    self.prop[:,  (j+1)*delta+i] /= \
                        np.abs(self.prop[:,  (j+1)*delta+i]).sum() 
      # after pumping
        j = no
        for i in range(0, self.steps - no*delta):
            self.prop[:,  no*delta+i] = np.dot(mat, self.prop[:,  no*delta+i-1])
            if norm:
                self.prop[:,  no*delta+i] /= np.abs(self.prop[:,  no*delta+i]).sum()
Exemplo n.º 7
0
    def get_pumping(self, hams, psi_init, steps, dz, norm=True):
        """
        Get the time evolution with adiabatic pumpings.

        :param hams: List of sparse.csr_matrices. Tight-Binding Hamilonians.
        :param psi_init: np.ndarray. Initial state.
        :param steps: Positive integer. Number of steps.
        :param dz: Positive number. Step.
        :param norm: Boolean. Default value True. Normalize the norm to 1 at each step.
        """
        error_handling.get_pump(hams)
        error_handling.ndarray(psi_init, "psi_init", self.lat.sites)
        error_handling.positive_int(steps, "steps")
        error_handling.positive_real(dz, "dz")
        error_handling.boolean(norm, "norm")
        self.steps = steps
        self.dz = dz
        no = len(hams)
        self.prop = np.empty((self.lat.sites, self.steps), "c16")
        self.prop[:, 0] = psi_init
        diag = 1j * np.ones(self.lat.sites, "c16")
        delta = self.steps // (1 + no)
        A = (sparse.diags(diag, 0) - 0.5 * self.dz * hams[0]).toarray()
        B = (sparse.diags(diag, 0) + 0.5 * self.dz * hams[0]).toarray()
        mat = np.dot(LA.inv(A), B)
        # before pumping
        for i in range(1, delta):
            self.prop[:, i] = np.dot(mat, self.prop[:, i - 1])
            if norm:
                self.prop[:, i] /= np.abs(self.prop[:, i]).sum()
        # pumping
        c = np.linspace(0, 1, delta)
        for j in range(0, no - 1):
            for i in range(0, delta):
                ham = (1 - c[i]) * hams[j] + c[i] * hams[j + 1]
                A = (sparse.diags(diag, 0) - 0.5 * self.dz * ham).toarray()
                B = (sparse.diags(diag, 0) + 0.5 * self.dz * ham).toarray()
                mat = np.dot(LA.inv(A), B)
                self.prop[:, (j + 1) * delta + i] = np.dot(mat, self.prop[:, (j + 1) * delta + i - 1])
                if norm:
                    self.prop[:, (j + 1) * delta + i] /= np.abs(self.prop[:, (j + 1) * delta + i]).sum()
        # after pumping
        j = no
        for i in range(0, self.steps - no * delta):
            self.prop[:, no * delta + i] = np.dot(mat, self.prop[:, no * delta + i - 1])
            if norm:
                self.prop[:, no * delta + i] /= np.abs(self.prop[:, no * delta + i]).sum()
Exemplo n.º 8
0
Arquivo: plot.py Projeto: cpoli/tbee
    def intensity_disk(self, intensity, s=200., fs=20., lims=None, figsize=None, 
                                 title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Colormap with identical disk shape.

        :param intensity: np.array.Field intensity.
        :param s: Default value 200. Disk size.
        :param fs: Default value 20. Font size.
        :param lims: List. Default value None. Colormap limits.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_n|^2$'. Title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots(figsize=figsize)
        plt.title(title, fontsize=fs+5)
        map_red = plt.get_cmap('Reds')
        if lims is None:
            lims = [0., np.max(intensity)]
            y_ticks = ['0', 'max']
        else:
            y_ticks = lims
        plt.scatter(self.sys.lat.coor['x'], self.sys.lat.coor['y'], c=intensity, s=s,
                         cmap=map_red, vmin=lims[0], vmax=lims[1])
        cbar = plt.colorbar(ticks=lims)
        ax.set_xticks([])
        ax.set_yticks([])
        ax.set_xlim(np.min(self.sys.lat.coor['x'])-1., np.max(self.sys.lat.coor['x'])+1.)
        ax.set_ylim(np.min(self.sys.lat.coor['y'])-1., np.max(self.sys.lat.coor['y'])+1.)
        cbar.ax.set_yticklabels([y_ticks[0], y_ticks[1]])
        cbar.ax.tick_params(labelsize=fs)
        ax.set_aspect('equal')
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemplo n.º 9
0
    def intensity_1d(self,
                     intensity,
                     ms=20.,
                     lw=2.,
                     fs=20.,
                     title=r'$|\psi^{(j)}|^2$'):
        '''
        Plot intensity for 1D lattices.

        :param intensity: np.array. Field intensity.
        :param ms: Positive Float. Default value 20. Markersize.
        :param lw: Positive Float. Default value 2. Linewith, connect sublattice sites.
        :param fs: Positive Float. Default value 20. Font size.
        :param title: String. Default value 'Intensity'. Figure title.
        '''
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.positive_real(ms, 'ms')
        error_handling.positive_real(lw, 'lw')
        error_handling.positive_real(fs, 'fs')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$j$', fontsize=fs)
        ax.set_ylabel(title, fontsize=fs)
        ax.set_title(title, fontsize=fs)
        for t, c in zip(self.sys.lat.tags, self.colors):
            plt.plot(self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == t],
                     intensity[self.sys.lat.coor['tag'] == t],
                     '-o',
                     color=c,
                     ms=ms,
                     lw=lw)
        plt.xlim([-1., self.sys.lat.sites])
        plt.ylim([0., np.max(intensity) + .05])
        fig.set_tight_layout(True)
        plt.draw()
        return fig
Exemplo n.º 10
0
    def intensity_area(self,
                       intensity,
                       s=1000.,
                       lw=1.,
                       fs=20.,
                       plt_hop=False,
                       figsize=None,
                       title=r'$|\psi|^2$'):
        '''
        Plot the intensity. Intensity propotional to disk shape.

        :param intensity: np.array. Intensity.
        :param s: Positive Float. Default value 1000. 
            Circle size given by s * intensity.
        :param lw: Positive Float. Default value 1. Hopping linewidths.
        :param fs: Positive Float. Default value 20. Fontsize.
        :param plt_hop: Boolean. Default value False. Plot hoppings.
        :param figsize: Tuple. Default value None. Figure size.
        :param title: String. Default value '$|\psi_{ij}|^2$'. Figure title.

        :returns:
            * **fig** -- Figure.
        '''
        error_handling.empty_ndarray(self.sys.lat.coor, 'sys.get_lattice')
        error_handling.ndarray(intensity, 'intensity', self.sys.lat.sites)
        error_handling.positive_real(s, 's')
        error_handling.positive_real(fs, 'fs')
        error_handling.boolean(plt_hop, 'plt_hop')
        error_handling.tuple_2elem(figsize, 'figsize')
        error_handling.string(title, 'title')
        fig, ax = plt.subplots()
        ax.set_xlabel('$i$', fontsize=fs)
        ax.set_ylabel('$j$', fontsize=fs)
        ax.set_title(title, fontsize=fs)
        if plt_hop:
            plt.plot([
                self.sys.lat.coor['x'][self.sys.hop['i'][:]],
                self.sys.lat.coor['x'][self.sys.hop['j'][:]]
            ], [
                self.sys.lat.coor['y'][self.sys.hop['i'][:]],
                self.sys.lat.coor['y'][self.sys.hop['j'][:]]
            ],
                     'k',
                     lw=lw)
        for tag, color in zip(self.sys.lat.tags, self.colors):
            plt.scatter(
                self.sys.lat.coor['x'][self.sys.lat.coor['tag'] == tag],
                self.sys.lat.coor['y'][self.sys.lat.coor['tag'] == tag],
                s=100 * s * intensity[self.sys.lat.coor['tag'] == tag],
                c=color,
                alpha=0.5)
        ax.set_aspect('equal')
        ax.axis('off')
        x_lim = [
            np.min(self.sys.lat.coor['x']) - 2.,
            np.max(self.sys.lat.coor['x']) + 2.
        ]
        y_lim = [
            np.min(self.sys.lat.coor['y']) - 2.,
            np.max(self.sys.lat.coor['y']) + 2.
        ]
        ax.set_xlim(x_lim)
        ax.set_ylim(y_lim)
        fig.set_tight_layout(True)
        plt.draw()
        return fig