def plot_components(eigvec_file, eigval_file, bas_state_index, majorX = 50, majorY = 0.02, col="b-o"):
    ###
    '''LDOS Plots function
       Plot squared components in all eigenvectors of a bas_state_index basis element (min bas_state_index = 0) as a function of the state energy.''' 
    ###
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_energy_data, read_eigenstates
    #
    #
    eigstates=read_eigenstates(eigvec_file)
    eigvals= read_energy_data(eigval_file)
    #
    #
    majorXLocator   = MultipleLocator(majorX)
    majorYLocator   = MultipleLocator(majorY)
    #
    ##    for bas_state in range(0,4):
    components = eigstates[bas_state_index,:]  ## Components of a given basis element in all eigenstates
    ##
    panel = pyplot.subplot(1, 1, 1)
    panel.tick_params(axis='both', which='major', labelsize=14)
    pyplot.plot(eigvals,components**2,col)
    ##
    panel.xaxis.set_major_locator(majorXLocator)
    panel.yaxis.set_major_locator(majorYLocator)
    ##
    ##
    ##    pyplot.annotate(bas_state, xy=(30, 0.07))
    pyplot.xlabel("Energy")
    pyplot.ylabel("Squared Eigenvector Components")
    panel.xaxis.label.set_fontsize(18)
    panel.yaxis.label.set_fontsize(18)
def hist_components(eigvec_file, basis_index, energy_file, N_value = 1, bins = 20, fig=False):
    ###
    '''Histogram of the squared components of the index-th basis state in the system eigenvectors 
       (min value = 0) as a function of the system eigenvalues.

       Options: 

           bins    : number of bins in the histogram
           N_value : renormalize by the system size
           fig     : plot bar fig

           '''
    #
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_eigenstates, read_energy_data
    #
    #
    eigstates=read_eigenstates(eigvec_file)
    ##
    eigenvalues = read_energy_data(energy_file)/N_value
    #
    ## Energy bins
    energy_bins=np.linspace(eigenvalues[0], eigenvalues[-1],num = bins)
    col_values = np.zeros(len(energy_bins)) # Initialize histogram values
    #
    ## Basis state components
    components = eigstates[basis_index,:]**2   
    #
    columns = np.zeros(bins)
    ###
    idx = 0
    for index_bin in range(1,bins):
        #
        for aval_index in range(idx, len(eigenvalues)+1):
            #
            energy = eigenvalues[aval_index]
            #
            if (energy < energy_bins[index_bin]):
                columns[index_bin] = columns[index_bin] + components[aval_index]
                idx = idx + 1
            else:
                break
    #
    # Define bar centroids
    wdth = (energy_bins[1]-energy_bins[0])
    lngth = bins - 1
    centroids = energy_bins + wdth/2
    ##
    if (fig):
        figure = pyplot.figure()
        ax = pyplot.subplot(111)
        ax.bar(centroids[:lngth], columns[:lngth],width=wdth,alpha=0.5)
    ##
    return centroids[:lngth], columns[:lngth]
def plot_components_grid(eigvec_file, min_eigstate_index, state_step, num_rows, num_cols, X_vector = 0, majorX = 50, majorY = 0.02, col="b-o"):
    ###
    '''Plot in a num_rows x num_cols grid squared components of eigstates 
    from min_eigenstate_index-th eigenvector (min value = 0) adding state_step.
    '''
    #
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_eigenstates
    #
    #
    eigstates=read_eigenstates(eigvec_file)
    #
    #
    fig,axes = pyplot.subplots(num_rows,num_cols,sharex=True,sharey=True)
    ##
#    if (not isinstance(X_vector,np.ndarray)):
#        majorXLocator   = MultipleLocator(majorX)
#        majorXFormatter = FormatStrFormatter('%d')
#    else:
#        axes.tick_params(axis='both', which='major', labelsize=12)
    ##
#    majorYLocator   = MultipleLocator(majorY)
    #
    ##pyplot.xlim(-5,240)
    #
    index_plot = min_eigstate_index
    #
    for index_row in range(0,num_rows):
        for index_col in range(0,num_cols):
            ##
            components = eigstates[:,index_plot]    ## Eigenstate's components
            ##
            axes[index_row,index_col].tick_params(axis='both', which='major', labelsize=12)
            ##
            if (not isinstance(X_vector,np.ndarray)):
                axes[index_row,index_col].plot(components**2,col) 
 #               axes[index_row,index_col].xaxis.set_major_formatter(majorXFormatter)
            else:
                axes[index_row,index_col].plot(X_vector, components**2, col, markersize = 6) 
            string_label = "$k = " + str(index_plot) + "$"
            axes[index_row,index_col].text(0.6, 0.05, string_label, fontsize=12)
            ##
            ## axes[index_row,index_col].annotate(min_eigstate_index+index_row+index_col+1, xy=(11, 0.75))
            ##
  #          axes[index_row,index_col].xaxis.set_major_locator(majorXLocator)
  #          axes[index_row,index_col].tick_params(axis='both', which='major', labelsize=9)
  #          axes[index_row,index_col].annotate(eigstate_index, xy=(150, 0.2))
            ##
            index_plot = index_plot + state_step

    pyplot.subplots_adjust(wspace=0,hspace=0)
def plot_components(eigvec_file,
                    eigval_file,
                    bas_state_index,
                    majorX=50,
                    majorY=0.02,
                    col="b-o"):
    ###
    '''LDOS Plots function
       Plot squared components in all eigenvectors of a bas_state_index basis element (min bas_state_index = 0) as a function of the state energy.'''
    ###
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_energy_data, read_eigenstates
    #
    #
    eigstates = read_eigenstates(eigvec_file)
    eigvals = read_energy_data(eigval_file)
    #
    #
    majorXLocator = MultipleLocator(majorX)
    majorYLocator = MultipleLocator(majorY)
    #
    ##    for bas_state in range(0,4):
    components = eigstates[
        bas_state_index, :]  ## Components of a given basis element in all eigenstates
    ##
    panel = pyplot.subplot(1, 1, 1)
    panel.tick_params(axis='both', which='major', labelsize=14)
    pyplot.plot(eigvals, components**2, col)
    ##
    panel.xaxis.set_major_locator(majorXLocator)
    panel.yaxis.set_major_locator(majorYLocator)
    ##
    ##
    ##    pyplot.annotate(bas_state, xy=(30, 0.07))
    pyplot.xlabel("Energy")
    pyplot.ylabel("Squared Eigenvector Components")
    panel.xaxis.label.set_fontsize(18)
    panel.yaxis.label.set_fontsize(18)
def plot_components(eigvec_file, eigstate_index, save_data = False, X_vector = 0, file_name = "sqrd_component_out.dat", majorX = 50, majorY = 0.02, col="b-o"):
    ###
    '''Plot or save the squared components of the eigstate_index-th eigenvector (min value = 0).

       Options: 
           save_data : if True do no plot the data but save them.
           X_vector  : plot as a function of the X_vector instead of simple indices.
           file_name  : squared component filename if save_data = True 

           '''
    #
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_eigenstates
    #
    #
    eigstates=read_eigenstates(eigvec_file)
    #
    #
    majorYLocator   = MultipleLocator(majorY)
    #
    components = eigstates[:,eigstate_index]**2    ## Eigenstate's squared components
    ##
    if (save_data):
        # Saving data
        if (isinstance(X_vector,np.ndarray)):
            data_save = np.transpose(np.array([X_vector,components])) 
        else:
            data_save = np.transpose(np.array([range(len(components)),components])) 
            ##
        np.savetxt(file_name, data_save)
    else:
        # Plot data
        panel = pyplot.subplot(1, 1, 1) 
    ##
    ##
        if (not isinstance(X_vector,np.ndarray)):
            majorXLocator   = MultipleLocator(majorX)
            majorXFormatter = FormatStrFormatter('%d')
            panel.tick_params(axis='both', which='major', labelsize=12)
            pyplot.plot(components, col)
            panel.xaxis.set_major_locator(majorXLocator)
            panel.xaxis.set_major_formatter(majorXFormatter)
        else:
            panel.tick_params(axis='both', which='major', labelsize=12)
            pyplot.plot(X_vector, components, col, markersize = 6)        
    ##
            panel.yaxis.set_major_locator(majorYLocator)
    ##
    ##
            panel.text(0.7, 0.03, r'$k = 49$', fontsize=15)
            pyplot.plot([0.4166666666666667, 0.4166666666666667], [0, 0.039], 'k-.', lw=2)
    ## pyplot.annotate("$k = 148$", xy=(0.1, 0.025))
    ## pyplot.xlabel("Normalized Basis State Energy $e_\omega$")  ## SO(4) basis
            pyplot.xlabel("Normalized Basis State Energy $e_n$") ## U(3) basis
    ## pyplot.ylabel("$|C_\omega^{(k)}|^2$") ## SO(4) basis
            pyplot.ylabel("$|C_n^{(k)}|^2$") ## U(3) basis
            panel.xaxis.label.set_fontsize(18)
            panel.yaxis.label.set_fontsize(18)
    return
            
def plot_components(eigvec_file, eigstate_index, save_data = False, X_vector = 0, file_name = "sqrd_component_out.dat", majorX = 50, majorY = 0.02, col="b-o"):
    ###
    '''Plot or save the squared components of the eigstate_index-th eigenvector (min value = 0).

       Options: 
           save_data : if True do no plot the data but save them.
           X_vector  : plot as a function of the X_vector instead of simple indices.
           file_name  : squared component filename if save_data = True 

           '''
    #
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_eigenstates
    #
    #
    eigstates=read_eigenstates(eigvec_file)
    #
    #
    majorYLocator   = MultipleLocator(majorY)
    #
    components = eigstates[:,eigstate_index]**2    ## Eigenstate's squared components
    ##
    if (save_data):
        # Saving data
        if (isinstance(X_vector,np.ndarray)):
            data_save = np.transpose(np.array([X_vector,components])) 
        else:
            data_save = np.transpose(np.array([range(len(components)),components])) 
            ##
        np.savetxt(file_name, data_save)
    else:
        # Plot data
        panel = pyplot.subplot(1, 1, 1) 
    ##
    ##
        if (not isinstance(X_vector,np.ndarray)):
            majorXLocator   = MultipleLocator(majorX)
            majorXFormatter = FormatStrFormatter('%d')
            panel.tick_params(axis='both', which='major', labelsize=12)
            pyplot.plot(components, col)
            panel.xaxis.set_major_locator(majorXLocator)
            panel.xaxis.set_major_formatter(majorXFormatter)
        else:
            panel.tick_params(axis='both', which='major', labelsize=12)
            pyplot.plot(X_vector, components, col, markersize = 6)        
    ##
            panel.yaxis.set_major_locator(majorYLocator)
    ##
    ##
            panel.text(0.7, 0.03, r'$k = 49$', fontsize=15)
            pyplot.plot([0.4166666666666667, 0.4166666666666667], [0, 0.039], 'k-.', lw=2)
    ## pyplot.annotate("$k = 148$", xy=(0.1, 0.025))
    ## pyplot.xlabel("Normalized Basis State Energy $e_\omega$")  ## SO(4) basis
            pyplot.xlabel("Normalized Basis State Energy $e_n$") ## U(3) basis
    ## pyplot.ylabel("$|C_\omega^{(k)}|^2$") ## SO(4) basis
            pyplot.ylabel("$|C_n^{(k)}|^2$") ## U(3) basis
            panel.xaxis.label.set_fontsize(18)
            panel.yaxis.label.set_fontsize(18)
    return
## Variable length grids
t_max = 60.;dim_t = 5000
time_grid = np.zeros(dim_t+1)
for index in np.arange(0,dim_t+1):
    time_grid[index] = t_max*index**3/dim_t**3

# Basis states indexes (start in 1)  -1 --> Closest to separatrix 
basis_states_indexes = [-1] 
###########################################
#  End of Defs  ## Edit only this section #
###########################################
#
print "N = ", Nval, ", L = ", Lval, ", xi = ", xi
## Read eigenvalues (absolute eigenvalues) and eigenvectors
Eigenvalues = read_energy_data("../../test/eigval_"+basis+"_N"+str(Nval)+"_L"+str(Lval)+".dat")
Eigenstates = read_eigenstates("../../test/eigvec_"+basis+"_N"+str(Nval)+"_L"+str(Lval)+".dat")
E0 = Eigenvalues[0]
Eigenvalues = Eigenvalues - E0 # Escitation energies
# Computing survival probability
print "Computing survival probability ... "
#
sp=np.zeros((time_grid.shape[0],len(basis_states_indexes)+1),order="F") # +1 for the abscyssa values
#
for index, index_state in enumerate(basis_states_indexes):
    if (index == -1):
        # Find basis state close to separatrix
        if basis is "u3":
            basisen = energy_basis_I(Nval,np.arange(0,Nval+1,2), Lval, xi)
        else:
            basisen = energy_basis_II(Nval,np.arange(0,Nval+1,2), Lval, xi)
        #
Example #8
0
#
N_value = 500
l_value = 0
xi_value = 0.4
##eigenvectors = "../test/eigvec_so3_xi04_N500_L0.dat"
eigenvectors = "../test/eigvec_u2_xi04_N500_L0.dat"
##eigenvalues = "../test/energy_so3_xi_04_N500_L0.dat"
eigenvalues = "../test/energy_u2_xi_04_N500_L0.dat"
#
## time_max = 16
## time_points = 300
time_max = 0.5
time_points = 200
nvals = np.arange(0, N_value + 2, 2)
#
eigstates = read_eigenstates(eigenvectors)
eigvals = read_energy_data(eigenvalues)
#
time_grid = np.linspace(0.0, time_max, time_points)
spb = survival_probability_basis_states(eigvals,
                                        eigstates,
                                        1,
                                        N_value / 2 + 1,
                                        t_max=time_max,
                                        dim_t=time_points)
#
##majorXLocator   = MultipleLocator(5)
##majorXFormatter = FormatStrFormatter('%d')
majorXLocator = MultipleLocator(0.2)
majorXFormatter = FormatStrFormatter('%3.1f')
#
#t_max = 5.;dim_t = 5000
#time_grid = np.zeros(dim_t+1)
#for index in np.arange(0,dim_t+1):
#    time_grid[index] = (t_max*index**3/dim_t**3)

# Basis states indexes (start in 1)  -1 --> Closest to separatrix
basis_states_indexes = [-1]
###########################################
#  End of Defs  ## Edit only this section #
###########################################
#
print "N = ", Nval, ", L = ", Lval, ", xi = ", xi
## Read eigenvalues (absolute eigenvalues) and eigenvectors
Eigenvalues = read_energy_data("../test/eigval_" + basis + "_N" + str(Nval) +
                               "_L" + str(Lval) + ".dat")
Eigenstates = read_eigenstates("../test/eigvec_" + basis + "_N" + str(Nval) +
                               "_L" + str(Lval) + ".dat")
E0 = Eigenvalues[0]
Eigenvalues = Eigenvalues - E0  # Excitation energies
# Computing survival probability
print "Computing survival probability ... "
#
sp = np.zeros((time_grid.shape[0], len(basis_states_indexes) + 1),
              order="F")  # +1 for the abscyssa values
#
for index, index_state in enumerate(basis_states_indexes):
    if (index_state == -1):
        # Find basis state close to separatrix
        if basis is "u2":
            basisen = energy_basis_u2(Nval, np.arange(Lval, Nval + 1, 2), Lval,
                                      xi)
        else:
#
N_value = 500
l_value = 0
xi_value = 0.4
##eigenvectors = "../test/eigvec_so3_xi04_N500_L0.dat"
eigenvectors = "../test/eigvec_u2_xi04_N500_L0.dat"
##eigenvalues = "../test/energy_so3_xi_04_N500_L0.dat"
eigenvalues = "../test/energy_u2_xi_04_N500_L0.dat"
#
## time_max = 16
## time_points = 300
time_max = 0.5
time_points = 200
nvals = np.arange(0, N_value + 2, 2)
#
eigstates=read_eigenstates(eigenvectors)
eigvals= read_energy_data(eigenvalues)
#
time_grid = np.linspace( 0.0, time_max, time_points)
spb = survival_probability_basis_states(eigvals, eigstates, 1, N_value/2 + 1, t_max = time_max, dim_t = time_points)
#
##majorXLocator   = MultipleLocator(5)
##majorXFormatter = FormatStrFormatter('%d')
majorXLocator   = MultipleLocator(0.2)
majorXFormatter = FormatStrFormatter('%3.1f')
#
fig,axes = pyplot.subplots(5,5,sharex=True,sharey=True)
#
pyplot.xlim(0,time_max)
pyplot.ylim(0,1)
#
def hist_components_LDOS(eigvec_file, basis_state, energy_file, ExcE = True, N_value = 1, bins = 20, OutputCentroid = False, fig=False, iprint=0):
    ###
    '''LDOS Plot: Histogram of the squared components of a basis state as a function of
       the system eigenvectors (min basis state value = 0) and as a function of the system eigenvalues.

       Options: 
           ExcE    : Transform energy_file to excitation energies. Default value True
           N_value : renormalize by the system size (N_value = N)
           bins    : number of bins in the histogram
           OutputCentroid : If True outputs the centroid value for the bardiagram.
           fig     : plot bar fig (pyplot.show())
           iprint  : control verbosity

           '''
    #
    import numpy as np
    from matplotlib import pyplot
    from matplotlib.ticker import MultipleLocator, FormatStrFormatter
    #
    from survival_probability_basis import read_eigenstates, read_energy_data
    #
    #
    eigstates=read_eigenstates(eigvec_file)
    ##
    eigenvalues = read_energy_data(energy_file)
    if (ExcE):
        E0 = eigenvalues[0]
        eigenvalues = eigenvalues - E0
    #
    eigenvalues = eigenvalues/N_value
    ## Energy bins
    energy_bins=np.linspace(eigenvalues[0], eigenvalues[-1],num = bins+1)
    if (iprint > 0):
        print "Energy bins = ", energy_bins
    #
    ## Basis state components
    components = eigstates[basis_state,:]**2   
    #
    columns = np.zeros(bins)
    ###
    idx = 0
    for index_bin in range(1,bins+1):
        #
        if (iprint > 0):
            print "bin index = ", index_bin, " of ", bins
        for aval_index in range(idx, len(eigenvalues)+1):
            #
            energy = eigenvalues[aval_index]
            if (iprint > 0):
                print "aval_index, energy = ", aval_index, energy
            #
            if (energy < energy_bins[index_bin]):
                columns[index_bin-1] = columns[index_bin-1] + components[aval_index]
                idx = idx + 1
                if (iprint > 0):
                    print "idx = ", idx, "col = ", columns[index_bin-1]
            else:
                if (iprint > 0):
                    print "BREAK", index_bin, aval_index
                break
    # Sum last component
    columns[index_bin-1] = columns[index_bin-1] + components[aval_index]
    if (iprint > 0):
        print "Columns = ", columns
    # Define bar centroids
    wdth = (energy_bins[1]-energy_bins[0])
    lngth = bins
    centroids = energy_bins + wdth/2.
    ##
    if (fig):
        figure = pyplot.figure()
        ax = pyplot.subplot(111)
        ax.bar(centroids[:lngth], columns[:lngth],width=wdth,alpha=0.5)
    ##
    if (OutputCentroid):
        return centroids[:lngth], columns[:lngth]
    else:
        output_data = np.zeros([2*bins+1,2]) # +1 to close the block diagram
        output_data[0,0] = energy_bins[0]
        output_data[0,1] = columns[0]
        #
        icount = 1
        for index_bin in range(1,bins):
            output_data[icount,0] = energy_bins[index_bin]
            output_data[icount,1] = columns[index_bin-1]
            output_data[icount+1,0] = energy_bins[index_bin]
            output_data[icount+1,1] = columns[index_bin]
            icount = icount + 2
        #   
        output_data[icount,0] = energy_bins[-1]
        output_data[icount,1] = columns[-1]
        output_data[icount+1,0] = energy_bins[-1]
        output_data[icount+1,1] = 0.0
        return output_data