コード例 #1
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def P_irrep_subspace_22(E, L, I):
    N = len(defns.list_nnk(E, L))
    Psub = np.zeros((5 * N, 0))
    for shell in defns.shell_list(E, L):
        Psub = np.column_stack(
            (Psub, P_irrep_subspace_o_l(E, L, I, shell, 2, lblock=True)))
    return Psub
コード例 #2
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def p_A1_old(E, L):
    Nshells = len(defns.shell_list(E, L))
    if Nshells == 1:
        pA1 = np.array([1, 0, 0, 0, 0, 0]).T
    elif Nshells == 2:
        pA1 = p_A1_2shells()
    return pA1
コード例 #3
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def evec_decomp(v, E, L, I):
    c0_list = []
    c2_list = []
    shells = defns.shell_list(E, L)
    for shell in shells:
        P0 = P_irrep_subspace_o_l(E, L, I, shell, 0)
        P2 = P_irrep_subspace_o_l(E, L, I, shell, 2)

        c0 = sum([np.dot(v, P0[:, i])**2
                  for i in range(P0.shape[1])]) / LA.norm(v)**2
        c2 = sum([np.dot(v, P2[:, i])**2
                  for i in range(P2.shape[1])]) / LA.norm(v)**2

        c0_list.append(c0)
        c2_list.append(c2)

    s = sum(c0_list) + sum(c2_list)
    print('Eigenvector decomposition for ' + str(I) + ' (total fraction: ' +
          str(round(s, 6)) + ')')
    for i in range(len(shells)):
        if s == 0:
            frac0 = 0.
            frac2 = 0.
        else:
            frac0 = c0_list[i] / s
            frac2 = c2_list[i] / s
        print(shells[i], '--- l=0:', round(frac0, 8), ',\t l=2:',
              round(frac2, 8))
    print()

    return s
コード例 #4
0
ファイル: K2i_mat.py プロジェクト: ferolo2/iso_optimized
def K2inv_mat00_A1(E, L, a0, r0, P0):
    shells = defns.shell_list(E, L)
    out = []
    for nkvec in shells:
        kvec = [i * 2 * pi / L for i in nkvec]
        out.append(K2inv(E, kvec, 0, 0, a0, r0, P0, 0))
    return np.diag(out)
コード例 #5
0
ファイル: F2_alt.py プロジェクト: blanton1/beyond_iso
def Fmat00(E,L,alpha):
  shells = shell_list(E,L)

  F_list = []
  for nnk in shells:
    F_list += [sums.F2KSS(E,L,nnk,0,0,0,0,alpha)] * len(shell_nnk_list(nnk))

  return np.diag(F_list)
コード例 #6
0
def Fmat(E, L, alpha):
    shells = shell_list(E, L)
    #print(shells)
    F_list = []
    for nnk in shells:
        F_list += Fmat_shell(E, L, nnk, alpha)

    # Should probably just return F_list for computations
    return block_diag(*F_list)
コード例 #7
0
ファイル: F2_alt.py プロジェクト: ferolo2/iso_optimized
def Fmat00_A1(E, L, alpha):
    shells = shell_list(E, L)

    F_list = []
    for nnk in shells:
        # All k's in the same shell give the same F(k) (s-wave case only)
        F_list.append(sums.F2KSS(E, L, nnk, 0, 0, 0, 0, alpha))

    return np.diag(F_list)
コード例 #8
0
ファイル: F2_alt.py プロジェクト: ferolo2/iso_optimized
def Fmat00(E, L, alpha, IPV=0):
    shells = shell_list(E, L)

    F_list = []
    for nnk in shells:
        nk = sums.norm(nnk)
        k = nk * 2 * math.pi / L
        hhk = sums.hh(E, k)
        omk = sqrt(1. + k**2)
        F_list += [(sums.F2KSS(E, L, nnk, 0, 0, 0, 0, alpha) + hhk * IPV /
                    (32 * math.pi * 2 * omk))] * len(shell_nnk_list(nnk))
#  print(F_list)
    return np.diag(F_list)
コード例 #9
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def P_irrep_subspace(E, L, I):
    # P_I = P_irrep_full(E,L,I)
    # elist, vlist = LA.eig(P_I)
    # # eigenvalues should all be 0 or 1; only want 1's
    # ivec = [i for i,e in enumerate(elist) if abs(e-1)<1e-13]
    # if len(ivec) != int(round(np.trace(P_I))):
    #   print('Error in P_irrep_subspace: wrong subspace dimension')
    # Psub = defns.chop(vlist[:,ivec].real)
    # if Psub.shape[1]==0:
    #   return Psub
    # else:
    #   return defns.chop(LA.qr(Psub)[0]) # orthonormalize

    N = len(defns.list_nnk(E, L))
    Psub = np.zeros((6 * N, 0))
    for shell in defns.shell_list(E, L):
        Psub = np.column_stack((Psub, P_irrep_subspace_o(E, L, I, shell)))
    return Psub
コード例 #10
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def P_irrep_subspace_o_l(E, L, I, shell, l, lblock=False):

    P_block_list = []
    for nk in defns.shell_list(E, L):
        if list(nk) == list(shell):
            P_block_list.append(P_irrep_o_l(shell, l, I, lblock))
        else:
            P_block_list.append(np.zeros(P_irrep_o_l(nk, l, I, lblock).shape))

    P_I = block_diag(*P_block_list)

    elist, vlist = LA.eig(P_I)
    # eigenvalues should all be 0 or 1; only want 1's
    ivec = [i for i, e in enumerate(elist) if abs(e - 1) < 1e-13]
    if len(ivec) != int(round(np.trace(P_I))):
        print('Error in P_irrep_subspace: wrong subspace dimension')
    Psub = defns.chop(vlist[:, ivec].real)
    if ivec == []:
        return Psub
    else:
        return defns.chop(LA.qr(Psub)[0])
コード例 #11
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def P_A1_full(E, L):
    P_block_list = []
    for shell in defns.shell_list(E, L):
        P_block_list.append(P_A1_o(shell))
    return block_diag(*P_block_list)
コード例 #12
0
def main():
    # Choose what scenario to test

    #irreps = GT.irrep_list()
    irreps = ['A1+']

    shell = 'all'
    l = 'both'

    E_MIN = 3.1
    E_MAX = 3.1
    L = 5

    show_eigs = False

    find_root = False
    E0 = 4.342  # initial guess for root-finder
    order = 1  # polynomial order used for fit

    new_plots = False
    (Ymin, Ymax) = (-1e6, 1e6)
    (ymin, ymax) = (-1e5, 1e5)

    # Separate energies by # of active shells
    breaks = defns.shell_breaks(E_MAX, L)
    breaks.append(E_MAX)
    for b in range(1, len(breaks) - 1):  # skip first window
        Emin = breaks[b] + 1e-8
        Emax = breaks[b + 1] - 1e-8 if breaks[b + 1] != E_MAX else breaks[b +
                                                                          1]
        if Emax < E_MIN or Emin > E_MAX:
            continue
        else:
            Emin = max(Emin, E_MIN)
            Emax = min(Emax, E_MAX)

        #########################################################
        # Define parameters (necessary for several functions)

        # K2 parameters
        # a0=-10; r0=0.5; P0=0.5; a2=-1
        # K2_dir = 'a0=m10_r0=0.5_P0=0.5_a2=m1/'

        # a0=0.1; r0=0; P0=0; a2=1
        # K2_dir = 'a0=0.1_r0=0_P0=0_a2=1/'

        # a0=0.1; r0=0; P0=0; a2=0.5
        # K2_dir = 'a0=0.1_r0=0_P0=0_a2=0.5/'

        # a0=0.1; r0=0; P0=0; a2=0.1
        # K2_dir = 'a0=0.1_r0=0_P0=0_a2=0.1/'

        a0 = 0.1
        r0 = 0
        P0 = 0
        a2 = 0
        K2_dir = 'a0=0.1_r0=0_P0=0_a2=0/'

        # a0=0; r0=0; P0=0; a2=0.1
        # K2_dir = 'a0=0_r0=0_P0=0_a2=0.1/'

        # F2_KSS parameter
        alpha = 0.5  # so far I've ALWAYS set alpha=0.5

        # Data & plot directories
        data_dir = 'Data/' + K2_dir
        plot_dir = 'Plots/' + K2_dir

        # Total CM energy & lattice size (lists)
        E_list = [
            2.9,
            2.95,
            2.99,
            2.995,
            2.999,
            2.9999,
            3.0001,
            3.001,
            3.005,
            3.01,
            #3.0318609166490167, # A1+ single root
            3.03186092,
            3.05,
            3.1,
            3.15,
            3.16303178,
            #3.1630317882, # T1+ triple root
            3.16303179,
            3.2,
            3.25,
            3.3,
            #3.30679060158175, # T2- triple root
            3.30679061,
            3.35,
            3.4,
            3.45,
            3.5,
            3.55,
            3.6,
            3.61,
            3.62,
            3.63,
            3.65,
            3.67,
            3.68,
            3.69,
            3.7,
            3.75,
            3.8,
            3.81,
            3.82,
            3.827,
            3.82755621,  # just below where (1,1,0) turns on
            #
            #################################
            # Begin 3-shell regime
            3.84,
            3.85,
            3.86,
            3.87,
            3.88,
            3.89,
            #3.8950494797495034, # T2+ triple root
            3.89504948,
            3.9,
            3.91,
            3.92,
            3.93,
            #3.9360802243295736, # E- double root
            3.93608023,
            3.94,
            #3.9485642787554895, # A2- single root
            3.94856428,
            3.95,
            3.96,
            #3.963,3.965,3.967,3.96798888,
            #3.9679888998546713, # old root of Ftilde before removing q's
            #3.96798890,3.968,3.969,
            3.97,  #3.973,3.975,3.977,
            3.98,
            3.99,
            4.0,
            4.05,
            4.1,
            #4.105402464984292, # T2- triple root
            4.10540247,
            4.15,
            4.16,
            4.17,
            4.19,
            4.2,
            #4.209892475540663, # T1+ triple root
            4.20989248,
            4.21,
            4.21193816,
            #4.211938171368993, # non-interacting energy E1
            4.21193818,
            4.215,
            4.22,
            4.25,
            4.27,
            4.3,
            4.32,
            4.33,  #4.33374164,
            #4.333741640225551, # A1+ single root
            4.33374165,
            4.335,
            4.338,
            4.34,
            #4.341716880828459, # T1- triple root
            4.34171689,
            4.342,
            4.345,
            4.35,
            4.37,
            4.4,
            4.43,
            #4.441146045889443, # T2- triple root
            4.44114605,
            4.45,
            #4.486997310056035, # T1+ triple root
            4.48699732,
            4.5,
            4.55,
            4.58101788  # just below where (1,1,1) turns on
        ]

        E_list = [x for x in E_list if Emin <= x <= Emax]
        L_list = [5.0]

        # print('E='+str(E)+', L='+str(L)+'\n')
        # print('Shells: ', defns.shell_list(E,L), '\n')
        # print('Matrix dimension: ', len(defns.list_nnk(E,L))*6, '\n')

        ####################################################################################
        # Load F3 matrix from file if exists, otherwise compute from scratch & save to file

        for L in L_list:
            F3_list = []

            for E in E_list:
                if a2 == 0:
                    datafile = data_dir + 'F3_00_E' + str(E) + '_L' + str(
                        L) + '.dat'
                elif a0 == 0:
                    datafile = data_dir + 'F3_22_E' + str(E) + '_L' + str(
                        L) + '.dat'
                else:
                    datafile = data_dir + 'F3_E' + str(E) + '_L' + str(
                        L) + '.dat'

                try:
                    with open(datafile, 'rb') as fp:
                        F3 = pickle.load(fp)
                        #F3 = pickle.loads(fp.read())
                        print('F3 loaded from ' + datafile + '\n')

                except IOError:
                    print(datafile +
                          ' not found; computing F3 from scratch...')
                    t0 = time.time()
                    if a2 == 0:
                        F3 = F3_mat.F3mat00(E, L, a0, r0, P0, a2, alpha)
                    elif a0 == 0:
                        F3 = F3_mat.F3mat22(E, L, a0, r0, P0, a2, alpha)
                    else:
                        F3 = F3_mat.F3mat(E, L, a0, r0, P0, a2, alpha)
                    t1 = time.time()
                    print('Calculation complete (time:', t1 - t0, ')')
                    with open(datafile, 'wb') as fp:
                        pickle.dump(F3, fp, protocol=4, fix_imports=False)
                        print('F3 saved to ' + datafile + '\n')

                F3_list.append(F3)

            ###################################################
            # Create list of inputs needed by several functions
            inputs = [L, a0, r0, P0, a2, alpha]

            # Free energies
            E_free = defns.E_free_list(L, 3, 1).values()
            E_free = [e for e in E_free if Emin < e < Emax]

            ##################################################
            # Project onto chosen irrep
            for flag in irreps:

                # General irrep
                if flag in GT.irrep_list():
                    I = flag
                    inputs.append(I)

                    if a2 == 0:
                        if sum([
                                GT.subspace_dim_o_l(s, I, 0)
                                for s in defns.shell_list(Emax, L)
                        ]) == 0:
                            print("0-dim l'=l=0 subspace for " + I +
                                  ' for E<' + str(round(Emax, 4)))
                            continue

                        irrep_eigs_array_list = AD.F3i_00_I_eigs_list(
                            E_list, L, F3_list, I)

                        irrep_eigs_array_list_flip = AD.F3i_00_I_eigs_list(
                            E_list, L, F3_list, I, flip=True)

                        f_eigs = F3_mat.F3i_00_I_eigs

                    elif a0 == 0:
                        if sum([
                                GT.subspace_dim_o_l(s, I, 2)
                                for s in defns.shell_list(Emax, L)
                        ]) == 0:
                            print("0-dim l'=l=2 subspace for " + I +
                                  ' for E<' + str(round(Emax, 4)))
                            continue

                        irrep_eigs_array_list = AD.F3i_22_I_eigs_list(
                            E_list, L, F3_list, I)

                        irrep_eigs_array_list_flip = AD.F3i_22_I_eigs_list(
                            E_list, L, F3_list, I, flip=True)

                        f_eigs = F3_mat.F3i_22_I_eigs

                    else:
                        if sum([
                                GT.subspace_dim_o(s, I)
                                for s in defns.shell_list(Emax, L)
                        ]) == 0:
                            print('0-dim subspace for ' + I + ' for E<' +
                                  str(round(Emax, 4)))
                            continue

                        irrep_eigs_array_list = AD.F3i_I_eigs_list(
                            E_list, L, F3_list, I)

                        irrep_eigs_array_list_flip = AD.F3i_I_eigs_list(
                            E_list, L, F3_list, I, flip=True)

                        f_eigs = F3_mat.F3i_I_eigs

                    if show_eigs == True:
                        print(irrep_eigs_array_list)

                    if find_root == True:
                        root = AD.root_finder_secant(E_list,
                                                     irrep_eigs_array_list,
                                                     f_eigs, inputs, E0, order)
                        print(root)

                        # irrep_roots_list = AD.root_finder(E_list, irrep_eigs_array_list, f_eigs, inputs)

                    #print(irrep_eigs_array_list)

                    #print(irrep_roots_list)
                    #print(root)

                    #irrep_roots_file = data_dir+I+'_roots_L='+str(L)+'.dat'
                    #with open(irrep_roots_file,'w') as fp:
                    #  fp.write(str(irrep_roots_list))

                #################################################
                # # BAD isotropic approx (A1+ proj, l=0)
                # elif flag == 'iso':
                #   iso_eigs_array_list = AD.F3i_iso_eigs_list_bad(E_list,L,F3_list)

                #   iso_roots_list = AD.root_finder(E_list, iso_eigs_array_list, F3_mat.F3i_iso_eigs_bad, inputs)
                #   # print(iso_roots_list)

                #   iso_roots_file = data_dir+'iso_roots_L='+str(L)+'.dat'
                #   with open(iso_roots_file,'w') as fp:
                #     fp.write(str(iso_roots_list))

                # #################################################
                # # A1+ projection (l=0 and l=2 contributions)
                # elif flag == 'A1':
                #   A1_eigs_array_list = AD.F3i_A1_eigs_list(E_list,L,F3_list)

                #   A1_roots_list = AD.root_finder(E_list, A1_eigs_array_list, F3_mat.F3i_A1_eigs, inputs)

                #   #print(A1_roots_list)

                #   A1_roots_file = data_dir+'A1_roots_L='+str(L)+'.dat'
                #   with open(A1_roots_file,'w') as fp:
                #     fp.write(str(A1_roots_list))

                #################################################
                # Full matrix, no projections (doesn't work well)
                elif flag == 'full':
                    eigs_array_list = AD.F3i_eigs_list(E_list, L, F3_list)

                    roots_list = AD.root_finder(E_list, eigs_array_list,
                                                F3_mat.F3i_eigs, inputs)
                    # print(roots_list)

                    roots_file = data_dir + 'roots_L=' + str(L) + '.dat'
                    with open(roots_file, 'w') as fp:
                        fp.write(str(roots_list))

                #################################################
                # Plot F3i eigenvalues vs. E
                if new_plots == True:
                    plotfile1 = plot_dir + str(flag) + '_' + str(
                        b + 1) + 'shells.pdf'
                    plotfile2 = plot_dir + str(flag) + '_' + str(
                        b + 1) + 'shells_zoom.pdf'

                    if len(flag) == 2:
                        irrep_tex = '$' + flag[0] + '^' + flag[1] + '$'
                    elif len(flag) == 3 and flag != 'iso':
                        irrep_tex = '$' + flag[0] + '_' + flag[1] + '^' + flag[
                            2] + '$'

                    plt.plot(E_list, irrep_eigs_array_list, '.')
                    plt.plot(E_list,
                             irrep_eigs_array_list_flip,
                             'o',
                             mfc='none')
                    plt.xlabel('E')
                    plt.ylabel(r'$\lambda$')
                    plt.title(r'$F_3^{-1}$ eigenvalues, ' + irrep_tex +
                              ' irrep, ' + str(b + 1) + ' shells')

                    for e0 in E_free:
                        plt.axvline(x=e0, c='k', ls='--', lw=1)

                    plt.xlim((Emin, Emax))
                    plt.ylim((Ymin, Ymax))
                    plt.tight_layout()
                    plt.grid(True)
                    plt.savefig(plotfile1)
                    plt.savefig('tmp.pdf')

                    plt.ylim((ymin, ymax))
                    plt.savefig(plotfile2)
                    plt.savefig('tmp2.pdf')

                    plt.close()
コード例 #13
0
a0=25
r0=8.34
E=3.1
L=10
k=2.25
IPV=-1
print(K2.K2inv(E,np.array([0.,0.,k*2*math.pi/L]),0,0,a0,r0,0.,0.,IPV))
    

exit()


L=4.5
E=np.sqrt(1+(2*math.pi/L)**2)*2+1

print(defns.shell_list(E,L))
print(defns.kmax(E)/(2*math.pi/L))

E=3.262


print(defns.shell_list(E,L))
print(defns.kmax(E)/(2*math.pi/L))


print(sums.hh(E,np.sqrt(2**2+2**2)*2*math.pi/L ))

print(defns.kmax(E)/(2*math.pi/L))
print(np.sqrt(5.))
exit()
start = time.time()
コード例 #14
0
def main():
    # Choose what scenario to test

    #irreps = GT.irrep_list()
    irreps = ['A1+']

    shell = 'all'
    l = 'both'

    E_MIN = 2.9
    E_MAX = 4.9
    L = 6

    show_eigs = False

    find_root = False
    E0 = 4.25  # initial guess for root-finder
    order = 1  # polynomial order used for fit

    new_plots = True
    temp_plots = True
    (Ymin, Ymax) = (-1e6, 1e6)
    (ymin, ymax) = (-1e4, 1e4)

    (xmin, xmax) = (0, 0)  # gets changed later to full shell window
    #(xmin,xmax) = (4.22,4.5) # only uncomment/edit if you want to zoom in

    # Separate energies by # of active shells
    breaks = defns.shell_breaks(E_MAX, L)
    breaks.append(E_MAX)
    for b in range(1, len(breaks) - 1):  # skip first window
        Emin = breaks[b] + 1e-8
        Emax = breaks[b + 1] - 1e-8 if breaks[b + 1] != E_MAX else breaks[b +
                                                                          1]
        if Emax < E_MIN or Emin > E_MAX:
            continue
        else:
            Emin = max(Emin, E_MIN)
            Emax = min(Emax, E_MAX)

        #########################################################
        # Define parameters (necessary for several functions)

        # K2 parameters

        # a0=-10; r0=0.5; P0=0.5; a2=-1
        # K2_dir = 'a0=m10_r0=0.5_P0=0.5_a2=m1/'

        #a0=0.1; r0=0; P0=0; a2=0

        #a0=0.1; r0=0; P0=0; a2=0.1

        a0 = 0.1
        r0 = 0
        P0 = 0
        a2 = 0.3

        #a0=0.1; r0=0; P0=0; a2=0.5

        #a0=0.1; r0=0; P0=0; a2=0.7

        #a0=0.1; r0=0; P0=0; a2=0.9

        #a0=0.1; r0=0; P0=0; a2=1

        #a0=0; r0=0; P0=0; a2=0.1

        #a0=0; r0=0; P0=0; a2=0.3

        #a0=0; r0=0; P0=0; a2=0.5

        #a0=0; r0=0; P0=0; a2=0.7

        #a0=0; r0=0; P0=0; a2=0.9

        #a0=0; r0=0; P0=0; a2=1

        # F2_KSS parameter
        alpha = 0.5  # so far I've ALWAYS set alpha=0.5

        # Data & plot directories
        K2_dir = 'L=' + str(L) + '/a0=' + str(a0) + '_r0=' + str(
            r0) + '_P0=' + str(P0) + '_a2=' + str(a2) + '/'
        data_dir = '../Data/' + K2_dir
        plot_dir = '../Plots/' + K2_dir

        if not os.path.exists(data_dir):
            os.makedirs(data_dir)
        if not os.path.exists(plot_dir):
            os.makedirs(plot_dir)

        # Total CM energy & lattice size (lists)
        E_list = [
            2.9,
            2.95,  #2.99,2.995,2.999,2.9999,
            3.0001,  #3.001,3.005,3.01,
            3.05,
            3.1,
            3.15,
            3.2,
            3.25,
            3.3,
            3.35,
            3.4,
            3.45,
            3.5,
            3.55,
            3.6,
            3.65,
            3.7,
            3.75,
            3.8,
            #3.82755621, # just below where (1,1,0) turns on
            #
            #################################
            # Begin 3-shell regime
            3.85,
            #3.86,3.87,3.88,3.89,
            #3.9, # just above where shell turns on
            3.91,  #3.92,3.93,3.94,
            3.95,
            4.0,
            4.05,
            4.1,
            4.15,  #4.16,4.17,4.19,4.195,
            4.2,
            #4.21,4.22,4.23,4.24,
            4.25,  #4.27,
            4.3,  #4.32,4.33,
            4.35,  #4.37,
            4.4,  #4.43,
            4.45,
            4.5,
            4.55,
            #4.58101788 # just below where (1,1,1) turns on
            4.6,
            4.65,
            4.7,
            4.75,
            4.8,
            4.85,
            4.91
        ]

        E_list = [x for x in E_list if Emin <= x <= Emax]

        # print('E='+str(E)+', L='+str(L)+'\n')
        # print('Shells: ', defns.shell_list(E,L), '\n')
        # print('Matrix dimension: ', len(defns.list_nnk(E,L))*6, '\n')

        ####################################################################################
        # Load F3 matrix from file if exists, otherwise compute from scratch & save to file

        F3_list = []

        for E in E_list:
            if a2 == 0:
                datafile = data_dir + 'F3_00_E=' + str(E) + '.dat'
            elif a0 == 0:
                datafile = data_dir + 'F3_22_E=' + str(E) + '.dat'
            else:
                datafile = data_dir + 'F3_E=' + str(E) + '.dat'

            try:
                with open(datafile, 'rb') as fp:
                    F3 = pickle.load(fp)
                    #F3 = pickle.loads(fp.read())
                    print('F3 loaded from ' + datafile + '\n')

            except IOError:
                print(datafile + ' not found; computing F3 from scratch...')
                t0 = time.time()
                if a2 == 0:
                    F3 = F3_mat.F3mat00(E, L, a0, r0, P0, a2, alpha)
                elif a0 == 0:
                    F3 = F3_mat.F3mat22(E, L, a0, r0, P0, a2, alpha)
                else:
                    F3 = F3_mat.F3mat(E, L, a0, r0, P0, a2, alpha)
                t1 = time.time()
                print('Calculation complete (time:', t1 - t0, ')')
                with open(datafile, 'wb') as fp:
                    pickle.dump(F3, fp, protocol=4, fix_imports=False)
                    print('F3 saved to ' + datafile + '\n')

            F3_list.append(F3)

        ###################################################
        # Create list of inputs needed by several functions
        inputs = [L, a0, r0, P0, a2, alpha]

        # Free energies
        E_free = defns.E_free_list(L, 5, 2).values()
        E_free = [e for e in E_free if Emin < e < Emax]

        ##################################################
        # Project onto chosen irrep
        for irrep in irreps:

            # General irrep
            if irrep in GT.irrep_list():
                I = irrep
                inputs.append(I)

                if a2 == 0:
                    if sum([
                            GT.subspace_dim_o_l(s, I, 0)
                            for s in defns.shell_list(Emax, L)
                    ]) == 0:
                        print("0-dim l'=l=0 subspace for " + I + ' for E<' +
                              str(round(Emax, 4)))
                        continue

                    irrep_eigs_array_list = AD.F3i_00_I_eigs_list(
                        E_list, L, F3_list, I)

                    irrep_eigs_array_list_flip = AD.F3i_00_I_eigs_list(
                        E_list, L, F3_list, I, flip=True)

                    f_eigs = F3_mat.F3i_00_I_eigs

                elif a0 == 0:
                    if sum([
                            GT.subspace_dim_o_l(s, I, 2)
                            for s in defns.shell_list(Emax, L)
                    ]) == 0:
                        print("0-dim l'=l=2 subspace for " + I + ' for E<' +
                              str(round(Emax, 4)))
                        continue

                    irrep_eigs_array_list = AD.F3i_22_I_eigs_list(
                        E_list, L, F3_list, I)

                    irrep_eigs_array_list_flip = AD.F3i_22_I_eigs_list(
                        E_list, L, F3_list, I, flip=True)

                    f_eigs = F3_mat.F3i_22_I_eigs

                else:
                    if sum([
                            GT.subspace_dim_o(s, I)
                            for s in defns.shell_list(Emax, L)
                    ]) == 0:
                        print('0-dim subspace for ' + I + ' for E<' +
                              str(round(Emax, 4)))
                        continue

                    irrep_eigs_array_list = AD.F3i_I_eigs_list(
                        E_list, L, F3_list, I)

                    irrep_eigs_array_list_flip = AD.F3i_I_eigs_list(E_list,
                                                                    L,
                                                                    F3_list,
                                                                    I,
                                                                    flip=True)

                    f_eigs = F3_mat.F3i_I_eigs

                if show_eigs == True:
                    for i in range(len(E_list)):
                        E = E_list[i]
                        x = irrep_eigs_array_list[i]
                        #x = [y for y in x if abs(y)<1e2]
                        print(E, x)
                        #print(E,min(x,key=abs))

                if find_root == True:
                    root = AD.root_finder_secant(E_list, irrep_eigs_array_list,
                                                 f_eigs, inputs, E0, order)
                    print(root)

                    # irrep_roots_list = AD.root_finder(E_list, irrep_eigs_array_list, f_eigs, inputs)

                    #irrep_roots_file = data_dir+I+'_roots_L='+str(L)+'.dat'
                    #with open(irrep_roots_file,'w') as fp:
                    #  fp.write(str(irrep_roots_list))

            #################################################
            # Full matrix, no projections (all eigenvalues present --> very messy plots)
            elif irrep == 'full':
                eigs_array_list = AD.F3i_eigs_list(E_list, L, F3_list)

                #roots_list = AD.root_finder(E_list, eigs_array_list, F3_mat.F3i_eigs, inputs)  # I can't see any reason why we'd ever want to do this
                #  print(roots_list)

                #roots_file = data_dir+'roots_L='+str(L)+'.dat'
                #with open(roots_file,'w') as fp:
                #  fp.write(str(roots_list))

            #################################################
            # Plot F3i eigenvalues vs. E
            if new_plots == True or temp_plots == True:
                plotfile1 = plot_dir + str(irrep) + '_' + str(b +
                                                              1) + 'shells.pdf'
                plotfile2 = plot_dir + str(irrep) + '_' + str(
                    b + 1) + 'shells_zoom.pdf'

                if len(irrep) == 2:
                    irrep_tex = '$' + irrep[0] + '^' + irrep[1] + '$'
                elif len(irrep) == 3 and irrep != 'iso':
                    irrep_tex = '$' + irrep[0] + '_' + irrep[1] + '^' + irrep[
                        2] + '$'

                plt.plot(E_list, irrep_eigs_array_list, '.')
                plt.plot(E_list, irrep_eigs_array_list_flip, 'o', mfc='none')
                plt.xlabel('E')
                plt.ylabel(r'$\lambda$')
                plt.title(r'$F_3^{-1}$ eigenvalues, ' + irrep_tex +
                          ' irrep, ' + str(b + 1) + ' shells')

                for e0 in E_free:
                    plt.axvline(x=e0, c='k', ls='--', lw=1)

                plt.xlim((Emin, Emax))
                plt.ylim((Ymin, Ymax))
                plt.tight_layout()
                plt.grid(True)
                if new_plots == True:
                    plt.savefig(plotfile1)
                elif temp_plots == True:
                    plt.savefig('temp.pdf')

                plt.ylim((ymin, ymax))
                if new_plots == True:
                    plt.savefig(plotfile2)
                elif temp_plots == True:
                    if Emin <= xmin < xmax <= Emax:
                        plt.xlim(xmin, xmax)
                    plt.savefig('temp_zoom.pdf')
                plt.close()
コード例 #15
0
ファイル: test.py プロジェクト: ferolo2/beyond_iso
from scipy.linalg import eig

import os, sys, time, pickle
cwd = os.getcwd()
sys.path.insert(0, cwd + '/F3')
sys.path.insert(0, cwd + '/K3df')
#sys.path.insert(0,cwd)

from K3df import K3A, K3B, K3quad
from F3 import F2_alt, Gmatrix, sums_alt as sums, K2i_mat
from F3 import H_mat, F3_mat
import defns, projections as proj, analysis_defns as AD, group_theory_defns as GT

E = 5
L = 6
K0 = 40
K1 = 0
K2 = 0
A = 30
B = 20
#K3 = np.around(K3quad.K3mat(E,L,K0,K1,K2,A,B,'r'),4)

print(defns.shell_list(3.85, L))
print(defns.Emin([1, 1, 1], L, alpH=-1, xmin=0))
print(defns.shell_breaks(E, L))

#E0_list = defns.E_free_list(L,4,3)
#for e in E0_list:
#  print(e,E0_list[e])
コード例 #16
0
ファイル: roots_master.py プロジェクト: ferolo2/beyond_iso
def main():
    # Choose what scenario to test

    #irreps = GT.irrep_list()
    irreps = ['A1+']

    shell = 'all'
    l = 'both'

    E_MIN = 4.24
    E_MAX = 4.24
    L = 5

    show_eigs = True

    find_root = False
    E0 = 4.25  # initial guess for root-finder
    order = 1  # polynomial order used for fit

    new_plots = False
    temp_plots = False
    (Ymin, Ymax) = (-1e6, 1e6)
    (ymin, ymax) = (-1e4, 1e4)

    (xmin, xmax) = (4.22, 4.5)  # only uncomment/edit if you want to zoom in

    # Separate energies by # of active shells
    breaks = defns.shell_breaks(E_MAX, L)
    breaks.append(E_MAX)
    for b in range(1, len(breaks) - 1):  # skip first window
        Emin = breaks[b] + 1e-8
        Emax = breaks[b + 1] - 1e-8 if breaks[b + 1] != E_MAX else breaks[b +
                                                                          1]
        if Emax < E_MIN or Emin > E_MAX:
            continue
        else:
            Emin = max(Emin, E_MIN)
            Emax = min(Emax, E_MAX)

        #########################################################
        # Define parameters (necessary for several functions)

        # K2 parameters

        # a0=-10; r0=0.5; P0=0.5; a2=-1
        # K2_dir = 'a0=m10_r0=0.5_P0=0.5_a2=m1/'

        #a0=0.1; r0=0; P0=0; a2=0

        #a0=0.1; r0=0; P0=0; a2=0.1

        a0 = 0.1
        r0 = 0
        P0 = 0
        a2 = 0.3

        #a0=0.1; r0=0; P0=0; a2=0.5

        #a0=0.1; r0=0; P0=0; a2=0.7

        #a0=0.1; r0=0; P0=0; a2=0.9

        #a0=0.1; r0=0; P0=0; a2=1

        #a0=0; r0=0; P0=0; a2=0.1

        #a0=0; r0=0; P0=0; a2=0.3

        #a0=0; r0=0; P0=0; a2=0.5

        #a0=0; r0=0; P0=0; a2=0.7

        #a0=0; r0=0; P0=0; a2=0.9

        #a0=0; r0=0; P0=0; a2=1

        # F2_KSS parameter
        alpha = 0.5  # so far I've ALWAYS set alpha=0.5

        # Data & plot directories
        K2_dir = 'a0=' + str(a0) + '_r0=' + str(r0) + '_P0=' + str(
            P0) + '_a2=' + str(a2) + '/'
        data_dir = '../Data/' + K2_dir
        plot_dir = '../Plots/' + K2_dir

        if not os.path.exists(data_dir):
            os.makedirs(data_dir)
        if not os.path.exists(plot_dir):
            os.makedirs(plot_dir)

        # Total CM energy & lattice size (lists)
        E_list = [
            2.9,
            2.95,  #2.99,2.995,2.999,2.9999,
            3.0001,  #3.001,3.005,3.01,
            #3.0318609166490167, # A1+ single root
            3.03186092,
            3.05,
            3.1,
            3.15,
            #3.16303178,
            #3.1630317882, # T1+ triple root
            3.16303179,
            3.2,
            3.25,
            3.3,
            #3.30679060158175, # T2- triple root
            3.30679061,
            3.35,
            3.4,
            3.45,
            3.5,
            3.55,
            3.6,
            3.61,
            3.62,
            3.63,
            3.65,
            3.67,
            3.68,
            3.69,
            3.7,
            3.75,
            3.8,
            3.81,
            3.82,
            3.827,
            3.82755621,  # just below where (1,1,0) turns on
            #
            #################################
            # Begin 3-shell regime
            3.84,
            3.85,
            3.86,
            3.87,
            3.88,
            3.89,
            #3.8950494797495034, # T2+ triple root
            3.89504948,
            3.9,
            3.91,
            3.92,
            3.93,
            #3.9360802243295736, # E- double root
            3.93608023,
            3.94,
            #3.9485642787554895, # A2- single root
            3.94856428,
            3.95,
            3.96,
            #3.963,3.965,3.967,3.96798888,
            #3.9679888998546713, # old root of Ftilde before removing q's
            #3.96798890,3.968,3.969,
            3.97,  #3.973,3.975,3.977,
            3.98,
            3.99,
            4.0,
            4.05,
            4.1,
            #4.105402464984292, # T2- triple root
            4.10540247,
            4.15,
            4.16,
            4.17,
            4.19,
            4.195,
            4.2,
            4.205,
            #4.209892475540663, # T1+ triple root
            4.20989248,
            4.21,
            4.211,
            4.2112,
            4.2114,
            4.2116,
            4.2117,
            4.2118,
            4.21182,
            4.21184,
            4.21186,
            4.21188,
            4.2119,
            4.21191,
            4.21192,
            4.211925,
            4.21193,
            4.211933,
            4.211935,
            #4.2119352,4.2119354,4.2119356,4.2119358,
            4.211936,  #4.2119361,
            4.2119362,
            4.2119364,
            4.2119366,
            4.2119368,
            4.211937,
            4.2119372,
            4.2119374,
            4.2119376,
            4.2119378,
            4.211938,
            4.21193816,
            4.21193817,
            #4.211938171368993, # non-interacting energy E1         #############
            4.21193818,
            4.2119385,
            4.211939,
            4.21193948,  # A1+ single root for a0=0, a2=0.1 ?
            4.21194,
            4.211941,
            4.211942,
            4.211944,
            4.211946,
            4.211948,
            4.21195,
            4.211955,
            4.21196,
            #4.21196290, # E+ double root for a0=0, a2=0.1 ?
            4.21196291,
            4.211965,
            4.21197,
            4.211975,
            4.21198,
            4.21199,
            4.212,
            4.2121,
            4.2122,
            4.2125,
            4.213,
            4.2135,
            4.214,
            4.2145,
            4.215,
            4.22,
            4.23,
            4.24,
            #4.2421632582173645, # E+ double root for a0=0.1, a2=0 (r0=P0=0)
            4.24216326,
            4.25,
            4.27,
            #4.2784624639738, # A1+ single root for a0=0.1, a2=0 (r0=P0=0)
            4.27846247,
            4.3,
            4.32,
            4.33,  #4.33374164,
            #4.333741640225551, # A1+ single root
            4.33374165,
            4.335,
            4.338,
            4.34,
            #4.341716880828459, # T1- triple root
            4.34171689,
            4.342,
            4.345,
            4.35,
            4.37,
            4.4,
            4.43,
            #4.441146045889443, # T2- triple root
            4.44114605,
            4.45,
            #4.486997310056035, # T1+ triple root
            4.48699732,
            4.5,
            4.55,
            4.58101788  # just below where (1,1,1) turns on
        ]

        E_list = [x for x in E_list if Emin <= x <= Emax]
        L_list = [5.0]

        # print('E='+str(E)+', L='+str(L)+'\n')
        # print('Shells: ', defns.shell_list(E,L), '\n')
        # print('Matrix dimension: ', len(defns.list_nnk(E,L))*6, '\n')

        ####################################################################################
        # Load F3 matrix from file if exists, otherwise compute from scratch & save to file

        for L in L_list:
            F3_list = []

            for E in E_list:
                if a2 == 0:
                    datafile = data_dir + 'F3_00_E' + str(E) + '_L' + str(
                        L) + '.dat'
                elif a0 == 0:
                    datafile = data_dir + 'F3_22_E' + str(E) + '_L' + str(
                        L) + '.dat'
                else:
                    datafile = data_dir + 'F3_E' + str(E) + '_L' + str(
                        L) + '.dat'

                try:
                    with open(datafile, 'rb') as fp:
                        F3 = pickle.load(fp)
                        #F3 = pickle.loads(fp.read())
                        print('F3 loaded from ' + datafile + '\n')

                except IOError:
                    print(datafile +
                          ' not found; computing F3 from scratch...')
                    t0 = time.time()
                    if a2 == 0:
                        F3 = F3_mat.F3mat00(E, L, a0, r0, P0, a2, alpha)
                    elif a0 == 0:
                        F3 = F3_mat.F3mat22(E, L, a0, r0, P0, a2, alpha)
                    else:
                        F3 = F3_mat.F3mat(E, L, a0, r0, P0, a2, alpha)
                    t1 = time.time()
                    print('Calculation complete (time:', t1 - t0, ')')
                    with open(datafile, 'wb') as fp:
                        pickle.dump(F3, fp, protocol=4, fix_imports=False)
                        print('F3 saved to ' + datafile + '\n')

                F3_list.append(F3)

            ###################################################
            # Create list of inputs needed by several functions
            inputs = [L, a0, r0, P0, a2, alpha]

            # Free energies
            E_free = defns.E_free_list(L, 3, 1).values()
            E_free = [e for e in E_free if Emin < e < Emax]

            ##################################################
            # Project onto chosen irrep
            for irrep in irreps:

                # General irrep
                if irrep in GT.irrep_list():
                    I = irrep
                    inputs.append(I)

                    if a2 == 0:
                        if sum([
                                GT.subspace_dim_o_l(s, I, 0)
                                for s in defns.shell_list(Emax, L)
                        ]) == 0:
                            print("0-dim l'=l=0 subspace for " + I +
                                  ' for E<' + str(round(Emax, 4)))
                            continue

                        irrep_eigs_array_list = AD.F3i_00_I_eigs_list(
                            E_list, L, F3_list, I)

                        irrep_eigs_array_list_flip = AD.F3i_00_I_eigs_list(
                            E_list, L, F3_list, I, flip=True)

                        f_eigs = F3_mat.F3i_00_I_eigs

                    elif a0 == 0:
                        if sum([
                                GT.subspace_dim_o_l(s, I, 2)
                                for s in defns.shell_list(Emax, L)
                        ]) == 0:
                            print("0-dim l'=l=2 subspace for " + I +
                                  ' for E<' + str(round(Emax, 4)))
                            continue

                        irrep_eigs_array_list = AD.F3i_22_I_eigs_list(
                            E_list, L, F3_list, I)

                        irrep_eigs_array_list_flip = AD.F3i_22_I_eigs_list(
                            E_list, L, F3_list, I, flip=True)

                        f_eigs = F3_mat.F3i_22_I_eigs

                    else:
                        if sum([
                                GT.subspace_dim_o(s, I)
                                for s in defns.shell_list(Emax, L)
                        ]) == 0:
                            print('0-dim subspace for ' + I + ' for E<' +
                                  str(round(Emax, 4)))
                            continue

                        irrep_eigs_array_list = AD.F3i_I_eigs_list(
                            E_list, L, F3_list, I)

                        irrep_eigs_array_list_flip = AD.F3i_I_eigs_list(
                            E_list, L, F3_list, I, flip=True)

                        f_eigs = F3_mat.F3i_I_eigs

                    if show_eigs == True:
                        for i in range(len(E_list)):
                            E = E_list[i]
                            x = irrep_eigs_array_list[i]
                            #x = [y for y in x if abs(y)<1e2]
                            print(E, x)
                            #print(E,min(x,key=abs))

                    if find_root == True:
                        root = AD.root_finder_secant(E_list,
                                                     irrep_eigs_array_list,
                                                     f_eigs, inputs, E0, order)
                        print(root)

                        # irrep_roots_list = AD.root_finder(E_list, irrep_eigs_array_list, f_eigs, inputs)

                        #irrep_roots_file = data_dir+I+'_roots_L='+str(L)+'.dat'
                        #with open(irrep_roots_file,'w') as fp:
                        #  fp.write(str(irrep_roots_list))

                #################################################
                # Full matrix, no projections (all eigenvalues present --> very messy plots)
                elif irrep == 'full':
                    eigs_array_list = AD.F3i_eigs_list(E_list, L, F3_list)

                    #roots_list = AD.root_finder(E_list, eigs_array_list, F3_mat.F3i_eigs, inputs)  # I can't see any reason why we'd ever want to do this
                    #  print(roots_list)

                    #roots_file = data_dir+'roots_L='+str(L)+'.dat'
                    #with open(roots_file,'w') as fp:
                    #  fp.write(str(roots_list))

                #################################################
                # Plot F3i eigenvalues vs. E
                if new_plots == True or temp_plots == True:
                    plotfile1 = plot_dir + str(irrep) + '_' + str(
                        b + 1) + 'shells.pdf'
                    plotfile2 = plot_dir + str(irrep) + '_' + str(
                        b + 1) + 'shells_zoom.pdf'

                    if len(irrep) == 2:
                        irrep_tex = '$' + irrep[0] + '^' + irrep[1] + '$'
                    elif len(irrep) == 3 and irrep != 'iso':
                        irrep_tex = '$' + irrep[0] + '_' + irrep[
                            1] + '^' + irrep[2] + '$'

                    plt.plot(E_list, irrep_eigs_array_list, '.')
                    plt.plot(E_list,
                             irrep_eigs_array_list_flip,
                             'o',
                             mfc='none')
                    plt.xlabel('E')
                    plt.ylabel(r'$\lambda$')
                    plt.title(r'$F_3^{-1}$ eigenvalues, ' + irrep_tex +
                              ' irrep, ' + str(b + 1) + ' shells')

                    for e0 in E_free:
                        plt.axvline(x=e0, c='k', ls='--', lw=1)

                    plt.xlim((Emin, Emax))
                    plt.ylim((Ymin, Ymax))
                    plt.tight_layout()
                    plt.grid(True)
                    if new_plots == True:
                        plt.savefig(plotfile1)
                    elif temp_plots == True:
                        plt.savefig('temp.pdf')

                    plt.ylim((ymin, ymax))
                    if new_plots == True:
                        plt.savefig(plotfile2)
                    elif temp_plots == True:
                        plt.xlim((xmin, xmax))
                        plt.savefig('temp_zoom.pdf')
                    plt.close()
コード例 #17
0
ファイル: projections.py プロジェクト: ferolo2/beyond_iso
def P_irrep_full(E, L, I):
    P_block_list = []
    for shell in defns.shell_list(E, L):
        P_block_list.append(P_irrep_o(shell, I))
    return block_diag(*P_block_list)