def get(b, d, n):
    """Get the results for the given parameters"""
    print("Running with: B = " + str(b) + " D = " + str(d) + " N = " + str(n))
    nn = int(n * (n + 1) / 2)

    cd(b, d, n)

    E, eigenvectors, index, c_max, H = \
        eigensystem.get(return_eigv=True, return_index=True,
                        return_cmax=True, return_H=True)

    # All available colors
    colors = ('black', 'red', 'teal', 'blue', 'orange', 'olive', 'magenta',
              'cyan', 'Brown', 'Goldenrod', 'Green', 'Violet')

    ir_reps, colormap = eigensystem.levels(E, index[c_max], colors=colors)

    # Build eigenvalue string
    # If the colormap element corresponding to the i-th eigenvalue is empty,
    # skip adding \color
    eigenvalues = ', '.join(
        optional_color(format_float(E[i]), colormap[i]) for i in range(E.size))

    return nn, H, E, eigenvalues, eigenvectors, index, c_max, ir_reps, \
        colors, colormap
Beispiel #2
0
def main(b, d, n, delta_n, st_epsilon, lvl_epsilon, cut=0):
    print("Running with: B = " + str(b) + " D = " + str(d) + " N = " + str(n))
    cd(b, d, n)
    start = timer()
    E, ket = eigensystem.get(return_ket=True)
    # Select irreducible representations
    # ir_reps = eigensystem.levels(E, ket)

    # Select only the stable levels
    # stable_levels = diff.stable(E, ir_reps, b, d, n, delta_n)
    stable_levels = diff.stable(E, b, d, n, delta_n, st_epsilon)
    # Reduce the number of stable levels to check the convergence
    stable_levels = int((1 - cut) * stable_levels)
    E = E[:stable_levels]
    # Select irreducible representations
    ir_reps = eigensystem.levels(E, ket, lvl_epsilon)

    stop = timer()
    print('Get data:', stop - start, 'seconds')
    rebde = open('rebde.dat', 'w')
    reuna = open('reuna.dat', 'w')
    reuns = open('reuns.dat', 'w')

    # Write only one level corresponding to the bidimensional representation
    skip_next = False
    for i in range(E.size):
        n1 = ket[i][0]
        n2 = ket[i][1]
        if ir_reps[i] == 2:  # bidimensional representation (rebde)
            if not skip_next:
                rebde.write('{0:.18f}'.format(E[i]) + '\t' + str(n1) + '\t' +
                            str(n2) + '\n')
                skip_next = True
            else:
                skip_next = False
        else:
            if n2 % 2:  # unidimensional anti-symmetric representation
                reuna.write('{0:.18f}'.format(E[i]) + '\t' + str(n1) + '\t' +
                            str(n2) + '\n')
            else:  # unidimensional symmetric representation
                reuns.write('{0:.18f}'.format(E[i]) + '\t' + str(n1) + '\t' +
                            str(n2) + '\n')

    rebde.close()
    reuna.close()
    reuns.close()

    os.chdir("../../Scripts")
    print("Done\n")
Beispiel #3
0
def main(b, d, n):
    """Create bar plots for eigenvectors"""
    cd(b, d, n)
    # Get states
    E, eigenvectors, ket, index = \
        eigensystem.get(return_eigv=True, return_ket=True,
                        return_index=True)
    # Get the index array that sorts the eigenvector coefficients
    # such that n1 + n2 is increasing
    sort_idx = np.argsort(index.sum(axis=1))
    # Sort the eigenvector coefficients
    eigenvectors = eigenvectors[:, sort_idx]
    # stable_levels = np.load('cache.npy')    # get cached stable levels
    no_eigv = 40  # number of eigenvectors to plot
    # Select the states corresponding to stable levels
    E = E[:no_eigv]
    eigenvectors = eigenvectors[:no_eigv]
    ket = ket[:no_eigv]
    # Get irreducible representation index
    ir_reps = eigensystem.levels(E, ket)
    # Build irreducible representation string
    reps = 'reuns', 'reuna', 'rebde'
    ir_str = [reps[i] for i in ir_reps]

    # Compute energy plot parameters
    k = index[sort_idx].sum(axis=1)  # n1 + n2
    w = 1 / (k + 1) - 0.01  # bar widths
    r = [j for i in range(n + 1) for j in range(i)]
    x = k - 0.5 + r / (k + 1)  # positions

    d_no = 0  # number of duplicate states

    clean_dir('eigenvectors')
    for i in range(eigenvectors.shape[0]):
        eigv_len = no_signif_el(eigenvectors[i])
        minor_ticks = np.arange(0, eigv_len, 0.5)
        # Plot label
        label = 'E = ' + str(E[i]) + '\n' + '$\\left|' + \
            str(ket[i][0]) + '\\,' + str(ket[i][1]) + '\\right\\rangle$\t' + \
            ir_str[i]
        fname = str(ket[i][0]) + ' ' + str(ket[i][1])  # filename

        index_plot(eigenvectors[i], eigv_len, label, index, sort_idx, fname,
                   d_no)

        energy_plot(eigenvectors[i], eigv_len, x, w, label, index, sort_idx,
                    fname, d_no)
Beispiel #4
0
def main(b, d, n):
    cd(b, d, n)
    # Get states
    E, eigenvectors, ket = eigensystem.get(return_eigv=True, return_ket=True)
    # Select stable levels
    st_idx = int(np.loadtxt('stable.txt')[0])
    E, eigenvectors, ket = E[:st_idx], eigenvectors[:st_idx], ket[:st_idx]
    if b:
        # Get irreducible representations
        ir_reps = eigensystem.levels(E, ket)
        rebde = np.loadtxt('rebde.dat', usecols=(0, ))
        reuna = np.loadtxt('reuna.dat', usecols=(0, ))
        reuns = np.loadtxt('reuns.dat', usecols=(0, ))
        # Compute participation ratio for each representation
        P_b = compute_p(eigenvectors, condition=np.where(ir_reps == 2))
        P_a = compute_p(eigenvectors, condition=np.where(ir_reps == 1))
        P_s = compute_p(eigenvectors, condition=np.where(ir_reps == 0))
        # Plot the participation ratio for each representation
        plt.scatter(rebde, P_b[::2], s=1, label='$\Gamma_b$')
        plt.scatter(reuna, P_a, s=1, label='$\Gamma_a$', color='r')
        plt.scatter(reuns, P_s, s=1, label='$\Gamma_s$', color='y')
        plt.xlabel('$E$')
        plt.ylabel('Participation ratio')
        plt.legend()
        plt.savefig('participation_ratio_rep.pdf')
        plt.close()
        # Plot the difference between the states of the bidimensional
        # representation
        plt.plot(rebde,
                 P_b[::2] - P_b[1::2],
                 lw=0.7,
                 label='$\Gamma_{b1} - \Gamma_{b2}$')
        plt.xlabel('$E$')
        plt.ylabel('$\\Delta$Participation ratio')
        plt.legend()
        plt.savefig('participation_ratio_rebde.pdf')
        plt.close()
    else:
        # P = 1 / (eigenvectors[0].size * np.sum(eigenvectors**4, axis=1))
        P = compute_p(eigenvectors)
        plt.scatter(E, P, s=1)
        plt.xlabel('$E$')
        plt.ylabel('Participation ratio')
        plt.savefig('participation_ratio.pdf')
        plt.close()
def difference(E1, b, d, n, delta_n, ir_reps1=np.empty(0)):
    """Return the differences between the energy levels and of the
    structure of the irreducible representations (optional) for the given
    diagonalization basis and n + delta_n"""
    # Load the energy levels in the second basis
    os.chdir("../B" + str(b) + " D" + str(d) + " N" + str(n + delta_n))
    E2, ket2 = eigensystem.get(return_ket=True)
    if ir_reps1.size:
        ir_reps2 = eigensystem.levels(E2, ket2)

    if E2.size > E1.size:
        E_diff = (E2[:E1.size] - E1) / E1
        if ir_reps1.size:
            ir_diff = ir_reps2[:ir_reps1.size] - ir_reps1
    else:
        E_diff = (E1[:E2.size] - E2) / E2
        if ir_reps1.size:
            ir_diff = ir_reps1[:ir_reps2.size] - ir_reps2

    os.chdir("../B" + str(b) + " D" + str(d) + " N" + str(n))
    if ir_reps1.size == 0:
        return np.abs(E_diff)
    return np.abs(E_diff), ir_diff
def main(b, d, n, delta_n, st_epsilon, lvl_epsilon, stable_only=True):
    start = timer()
    tools.cd(b, d, n)

    # Get data
    E, ket = eigensystem.get(return_ket=True)
    ir_reps = eigensystem.levels(E, ket, lvl_epsilon)
    if stable_only:  # choose all levels or only the stable ones
        stable_levels = int(np.loadtxt('stable.txt')[0])
        E = E[:stable_levels]

    rebde = np.loadtxt('rebde.dat', usecols=(0, ), unpack=True)
    reuna = np.loadtxt('reuna.dat', usecols=(0, ), unpack=True)
    reuns = np.loadtxt('reuns.dat', usecols=(0, ), unpack=True)

    # Bi-directional search
    E_in_rebde = np.in1d(E, rebde, assume_unique=False)
    E_in_reuna = np.in1d(E, reuna, assume_unique=False)
    E_in_reuns = np.in1d(E, reuns, assume_unique=False)

    rebde_in_E = np.in1d(rebde, E, assume_unique=False)
    reuna_in_E = np.in1d(reuna, E, assume_unique=False)
    reuns_in_E = np.in1d(reuns, E, assume_unique=False)

    if E.size < max(rebde.size, reuna.size, reuns.size):
        rebde = rebde[:E.size]
        reuna = reuna[:E.size]
        reuns = reuns[:E.size]

        rebde_in_E = rebde_in_E[:E.size]
        reuna_in_E = reuna_in_E[:E.size]
        reuns_in_E = reuns_in_E[:E.size]

    # Padding
    rebde = np.pad(rebde, pad_width=(0, E.size - rebde.size), mode='constant')
    reuna = np.pad(reuna, pad_width=(0, E.size - reuna.size), mode='constant')
    reuns = np.pad(reuns, pad_width=(0, E.size - reuns.size), mode='constant')

    rebde_in_E = np.pad(rebde_in_E,
                        pad_width=(False, E.size - rebde_in_E.size),
                        mode='constant')
    reuna_in_E = np.pad(reuna_in_E,
                        pad_width=(False, E.size - reuna_in_E.size),
                        mode='constant')
    reuns_in_E = np.pad(reuns_in_E,
                        pad_width=(False, E.size - reuns_in_E.size),
                        mode='constant')

    files = np.array([
        E, rebde, reuna, reuns, E_in_rebde, E_in_reuna, E_in_reuns, rebde_in_E,
        reuna_in_E, reuns_in_E
    ])

    with open("table.tex", "w") as f:
        f.write("\\documentclass{article}\n\n")
        f.write("\\usepackage[margin=0.2in]{geometry}\n")
        f.write("\\usepackage{longtable}\n")
        f.write("\\usepackage[table]{xcolor}\n\n")
        f.write("\\begin{document}\n\n")
        f.write("\\begin{longtable}{" + " | ".join(["c"] * 4) + "}\n")
        f.write("energy levels & rebde.dat & reuna.dat & reuns.dat\t\\\\\n")
        f.write("\\hline\n\\endfirsthead\n")
        for row in range(files.shape[1]):
            # Find the representation of the energy level
            c = 0
            for x in range(1, 4):
                if files[x + 3][row]:
                    c = x

            line = color(c, True) + '{:.18f}'.format(files[0][row]) + " & " + \
                " & ".join(color(x, files[x + 6][row]) +
                           '{:.18f}'.format(files[x][row])
                           for x in range(1, 4))
            f.write('\t' + line + " \\\\\n")
        f.write("\\end{longtable}")
        f.write("\n\n\\end{document}")

    os.chdir("../../Scripts")
    end = timer()
    print('total: ', end - start)
Beispiel #7
0
def main(b, d, n):
    cd(b, d, n)
    # Get states
    E, eigenvectors, ket = eigensystem.get(return_eigv=True, return_ket=True)
    # Select stable levels
    st_idx = int(np.loadtxt('stable.txt')[0])
    E, eigenvectors, ket = E[:st_idx], eigenvectors[:st_idx], ket[:st_idx]

    # Get reference states
    cd(0.0, d, n)
    E_ref, eigenvectors_ref, ket_ref = eigensystem.get(return_eigv=True,
                                                       return_ket=True)
    # Select stable reference levels
    st_idx = int(np.loadtxt('stable.txt')[0])
    E_ref, eigenvectors_ref, ket_ref = E_ref[:st_idx], \
        eigenvectors_ref[:st_idx], ket_ref[:st_idx]
    # Reference participation ratio
    P_ref = compute_p(eigenvectors_ref)
    # Find the index of the states with energy closest to the reference ones
    # idx = np.searchsorted(E, E_ref)
    # idx = np.clip(idx, 1, len(E) - 1)
    # left = E[idx - 1]
    # right = E[idx]
    # idx -= E_ref - left < right - E_ref
    # Compute the participation ratio
    P = compute_p(eigenvectors)

    cd(b, d, n)
    ylim = ()
    ylim = plot(E,
                P,
                E_ref,
                P_ref,
                label='$B=' + str(b) + '$',
                fname='participation_ratio_cmp.pdf')

    # Get irreducible representations
    ir_reps = eigensystem.levels(E, ket)
    rebde = np.loadtxt('rebde.dat', usecols=(0, ))
    reuna = np.loadtxt('reuna.dat', usecols=(0, ))
    reuns = np.loadtxt('reuns.dat', usecols=(0, ))
    # Compute participation ratio for each representation
    P_b = compute_p(eigenvectors, condition=np.where(ir_reps == 2))
    P_a = compute_p(eigenvectors, condition=np.where(ir_reps == 1))
    P_s = compute_p(eigenvectors, condition=np.where(ir_reps == 0))

    # Plot the participation ratio for each representation
    plot(rebde,
         P_b[::2],
         E_ref,
         P_ref,
         label='$\Gamma_b$',
         ylim=ylim,
         fname='participation_ratio_cmp_rebde.pdf')
    plot(reuna,
         P_a,
         E_ref,
         P_ref,
         label='$\Gamma_a$',
         ylim=ylim,
         fname='participation_ratio_cmp_reuna.pdf')
    plot(reuns,
         P_s,
         E_ref,
         P_ref,
         label='$\Gamma_s$',
         ylim=ylim,
         fname='participation_ratio_cmp_reuns.pdf')