Example #1
0
def plot_p(p):

    xlim = [-50, 50]

    subp = [3, 1, 1]

    plt.subplot(*subp)
    subp[-1] += 1
    oploti(p.g0_w[0, 0], label=r'$G_0(i\omega_n)$')
    oploti(p.g_w[0, 0], label=r'$G(i\omega_n)$')
    oploti(p.sigma_w[0, 0], label=r'$\Sigma(i\omega_n)$')
    plt.legend(loc='best')
    plt.xlim(xlim)

    plt.subplot(*subp)
    subp[-1] += 1
    oplotr(p.G_tau_raw['up'], alpha=0.75)
    oplotr(p.G_tau['up'])
    plt.gca().legend().set_visible(False)

    plt.subplot(*subp)
    subp[-1] += 1
    G_l = p.G_l.copy()
    for b, g in G_l:
        G_l[b].data[:] = np.abs(g.data)
    oplotr(G_l['up'], 'o-')

    plt.semilogy([], [])
    plt.gca().legend().set_visible(False)

    plt.tight_layout()
    plt.savefig('figure_field_sc_gf.svg')
Example #2
0
def plot_chi_k(p, color=None):

    chi_k = p.chi_kw[:, Idx(0)]

    k_vecs, k_plot, K_plot, K_labels = get_path()
    kx, ky, kz = k_vecs.T

    interp = np.vectorize(lambda kx, ky, kz : np.squeeze(chi_k([kx, ky, kz]).real))
    interp = interp(kx, ky, kz)
    p.chi_G = np.squeeze(chi_k[Idx(0, 0, 0)].real)    

    line = plt.plot(k_plot, interp, '-', label=r'$N_{\nu} = $'+'${:d}$'.format(p.nwf))

    plt.gca().set_xticks(K_plot); plt.gca().set_xticklabels(K_labels)
    plt.grid(True); plt.ylabel(r'$\chi(\mathbf{Q})$')
    plt.legend(loc='best', fontsize=8)
    return line[0].get_color()
Example #3
0
def plot_ps(ps):

    subp = [2, 1, 1]

    plt.subplot(*subp)
    subp[-1] += 1
    plt.plot(ps.iter, ps.dG_l, 's-', label=r'$\Delta G_l$')
    plt.plot(ps.iter, ps.dM, 'o-', label=r'$\Delta M$')
    plt.semilogy([], [])
    plt.ylabel('$\Delta G_l$, $\Delta M$')
    plt.legend(loc='best')
    plt.xlabel('Iteration')

    plt.subplot(*subp)
    subp[-1] += 1
    plt.plot(ps.iter, ps.B, 's-', label=r'$B$')
    plt.plot(ps.iter, ps.M, 'o-', label=r'$M$')
    plt.ylabel(r'$M$, $B$')
    plt.legend(loc='best')
    plt.xlabel('Iteration')

    plt.tight_layout()
    plt.savefig('figure_field_sc.svg')
Example #4
0
    for filename in filenames:
        print '--> Loading:', filename
        with HDFArchive(filename, 'r') as s:
            p = s['p']

        if hasattr(p, 'chi'):

            nw = p.solve.measure_G2_n_fermionic
            nc = int(np.log10(p.n_cycles))

            style = styles[(nw, nc)]

            plt.plot(1. / p.beta, p.chi, style, alpha=0.5)

    for (nw, nc), style in styles.items():
        plt.plot([], [],
                 style,
                 alpha=0.5,
                 label='cthyb dynamic $n_w=%i$, $\log n_c=%i$' % (nw, nc))

    # ------------------------------------------------------------------

    plt.legend(loc='best', fontsize=6, frameon=False)
    plt.xlabel(r'$T$')
    plt.ylabel(r'$\chi_m$')

    plt.tight_layout()
    plt.savefig('figure_summary.pdf')
    plt.show()
Example #5
0
from pytriqs.gf.local import *
from pytriqs.archive import *
from pytriqs.plot.mpl_interface import oplot, plt

with HDFArchive("dmft_solution.h5", "r") as ar:
    for i in range(5):
        oplot(ar["G_iw-%i" % i]["up"], "-o", mode="I", label="Iteration = %s" % i, x_window=(0, 2))

plt.legend(loc=4)
Example #6
0
    plt.subplot(*subp); subp[-1] += 1
    plt.plot(1./p.nwf, p.chi_G, 'o', color=color)
    ps.append(p)

# -- Extrapolation to nwf -> oo
ps = ParameterCollections(objects=ps)
x, y = 1./ps.nwf, ps.chi_G
sidx = np.argsort(x)
x, y = x[sidx], y[sidx]
p = np.polyfit(x, y, 1)
y0 = np.polyval(p, 0)
X = np.linspace(0, x.max())
Y = np.polyval(p, X)

subp = [1, 2, 1]
plt.subplot(*subp); subp[-1] += 1
plt.plot(0, y0, 'rx')
plt.plot(0, 0.3479, 'r+')
plt.subplot(*subp); subp[-1] += 1
plt.plot(X, Y, '--k', lw=1.0, zorder=-100)
plt.plot(0, 0.3479, 'r+', label=r'Field')
plt.plot(0, y0, 'rx', label=r'BSE')
plt.grid(True); plt.legend(loc='best', fontsize=8)
plt.xlabel(r'$1/N_\nu$'); plt.ylabel(r'$\chi(\mathbf{0})$')
plt.title(
    r'$\lim_{n_\nu \rightarrow \infty} \, \chi(\mathbf{0}) \approx $' + \
    '${:3.4f}$'.format(y0))
plt.tight_layout()
plt.savefig('figure_bse.svg')
plt.show()
Example #7
0
    tau = np.array([float(t) for t in cthyb.O_tau.mesh])

    tau_ref = np.array([float(t) for t in pyed.O_tau.mesh])
    O_ref = pyed.O_tau.data.copy()
    O_interp = np.interp(tau, tau_ref, O_ref)

    O_tau_diff = cthyb.O_tau.copy()
    O_tau_diff.data[:] -= O_interp
    O_tau_diff.name = r'$\Delta$' + 'O_tau'

    oplotr(O_tau_diff, '-', label=r'cthyb - pyed', alpha=0.75)

    plt.subplot(*subp)
    subp[-1] += 1

    oplotr(cthyb.G_tau, '.', label='cthyb G_tau', alpha=0.2)
    oplotr(pyed.G_tau, label='pyed G_tau')
    plt.plot(0, -1 + cthyb.n_exp * 0.5, 'ob', alpha=0.25, clip_on=False)
    plt.plot(cthyb.G_tau.mesh.beta,
             -cthyb.n_exp * 0.5,
             'ob',
             alpha=0.25,
             clip_on=False)

    #oplotr(cthyb.Gl_tau, '-', label='cthyb Gl_tau', alpha=0.75)

    plt.legend(loc='best')
    plt.tight_layout()
    plt.savefig('figure_n_n_by_insertion_cthyb.pdf')
    plt.show()
Example #8
0
from pytriqs.gf.local import *
from pytriqs.archive import *
from pytriqs.plot.mpl_interface import oplot, plt

with HDFArchive("dmft_solution.h5", 'r') as ar:
    for i in range(5):
        oplot(ar['G_iw-%i' % i]['up'],
              '-o',
              mode='I',
              label='Iteration = %s' % i,
              x_window=(0, 2))

plt.legend(loc=4)
Example #9
0
subp[-1] += 1
plt.plot(ps.iter, ps.dG_l, 's-')
plt.ylabel('$\max | \Delta G_l |$')
plt.xlabel('Iteration')
plt.semilogy([], [])

plt.subplot(*subp)
subp[-1] += 1
for b, g in p.G_l:
    p.G_l[b].data[:] = np.abs(g.data)
oplotr(p.G_l['up'], 'o-', label=None)
plt.ylabel('$| G_l |$')
plt.semilogy([], [])

plt.subplot(*subp)
subp[-1] += 1
oplotr(p.G_tau_raw['up'], alpha=0.75, label='Binned')
oplotr(p.G_tau['up'], label='Legendre')
plt.legend(loc='best', fontsize=8)
plt.ylabel(r'$G(\tau)$')

plt.subplot(*subp)
subp[-1] += 1
oploti(p.sigma_w[0, 0], '.-', label=None)
plt.ylabel(r'$\Sigma(i\omega_n)$')
plt.xlim([-100, 100])

plt.tight_layout()
plt.savefig('figure_sc.svg')
plt.show()
Example #10
0
def dcore_check(filename, fileplot=None):
    """
    Main routine for checking convergence

    Parameters
    ----------
    filename : string
        Input-file name

    fileplot : string
        Output file name. File format is determined by the extension (pdf, eps, jpg, etc).
    """
    if mpi.is_master_node():
        print("\n  @ Reading {0} ...".format(filename))
    #
    # Construct a parser with default values
    #
    pars = create_parser()
    #
    # Parse keywords and store
    #
    pars.read(filename)
    p = pars.as_dict()
    #
    solver = DMFTCoreSolver(p["model"]["seedname"], p)
    #

    # Just for convenience
    sol = solver.S
    output_file = p["model"]["seedname"] + '.out.h5'
    output_group = 'dmft_out'
    beta = p["system"]["beta"]
    omega_check = p['tool']['omega_check']
    gs = GridSpec(2, 1)

    if fileplot is not None:  # if graph is to be printed in a file
        import matplotlib
        matplotlib.use('Agg')  # do not plot on x11
    from pytriqs.plot.mpl_interface import oplot, plt
    plt.figure(figsize=(8, 10))
    #
    # Chemical potential
    #
    ar = HDFArchive(output_file, 'r')
    iteration_number = ar[output_group]['iterations']
    perform_tail_fit = p["system"]["perform_tail_fit"] and \
        not ar[output_group]['parameters']["system"]["perform_tail_fit"]
    nsh = solver.SK.n_inequiv_shells
    print("  Total number of Iteration: {0}".format(iteration_number))
    print("\n  Iter  Chemical-potential")
    for itr in range(1, iteration_number + 1):
        print("  {0} {1}".format(
            itr, ar[output_group]['chemical_potential'][str(itr)]))
    #
    # Read Sigma and average it
    #
    sigma_ave = []
    sigma_fit = []
    nsigma = 0
    itr_sigma = [0] * 7
    for itr in range(1, iteration_number + 1):
        if itr > iteration_number - 7:
            itr_sigma[nsigma] = itr
            sigma_ave.append(
                GfImFreq(indices=[0], beta=beta, n_points=p["system"]["n_iw"]))
            sigma_fit.append(
                GfImFreq(indices=[0], beta=beta, n_points=p["system"]["n_iw"]))
            sigma_ave[nsigma].data[:, 0, 0] = 0.0
            sigma_fit[nsigma].data[:, 0, 0] = 0.0
            norb_tot = 0
            for ish in range(nsh):
                spn = solver.SK.spin_block_names[solver.SK.corr_shells[
                    solver.SK.inequiv_to_corr[ish]]['SO']]
                norb = solver.SK.corr_shells[
                    solver.SK.inequiv_to_corr[ish]]['dim']
                sol[ish].Sigma_iw << ar[output_group]['Sigma_iw'][str(itr)][
                    str(ish)]
                sigma_iw_fit = sol[ish].Sigma_iw.copy()
                if perform_tail_fit:
                    tail_fit(sigma_iw_fit,
                             fit_max_moment=p["system"]["fit_max_moment"],
                             fit_min_w=p["system"]["fit_min_w"],
                             fit_max_w=p["system"]["fit_max_w"])
                for isp in spn:
                    for iorb in range(norb):
                        norb_tot += 1
                        for jorb in range(norb):
                            sigma_ave[nsigma].data[:, 0, 0] += sol[
                                ish].Sigma_iw[isp].data[:, iorb, jorb]
                            sigma_fit[nsigma].data[:, 0, 0] += sigma_iw_fit[
                                isp].data[:, iorb, jorb]
            sigma_ave[nsigma].data[:, 0, 0] /= norb_tot
            sigma_fit[nsigma].data[:, 0, 0] /= norb_tot
            nsigma += 1
    #
    # Real part
    #
    plt.subplot(gs[0])
    for itr in range(nsigma):
        oplot(sigma_ave[itr],
              '-o',
              mode='R',
              x_window=(0.0, omega_check),
              name='Sigma-%s' % itr_sigma[itr])
        if perform_tail_fit:
            oplot(sigma_fit[itr],
                  '-o',
                  mode='R',
                  x_window=(0.0, omega_check),
                  name='S_fit-%s' % itr_sigma[itr])
    plt.legend(loc=0)
    #
    # Imaginary part
    #
    plt.subplot(gs[1])
    for itr in range(nsigma):
        oplot(sigma_ave[itr],
              '-o',
              mode='I',
              x_window=(0.0, omega_check),
              name='Sigma-%s' % itr_sigma[itr])
        if perform_tail_fit:
            oplot(sigma_fit[itr],
                  '-o',
                  mode='I',
                  x_window=(0.0, omega_check),
                  name='S_fit-%s' % itr_sigma[itr])
    plt.legend(loc=0)

    plt.show()
    if fileplot is not None:
        plt.savefig(fileplot)
    #
    # Output Sigma into a text file
    #
    print("\n Output Local Self Energy : ",
          p["model"]["seedname"] + "_sigma.dat")
    with open(p["model"]["seedname"] + "_sigma.dat", 'w') as fo:
        print("# Local self energy at imaginary frequency", file=fo)
        #
        # Column information
        #
        print("# [Column] Data", file=fo)
        print("# [1] Frequency", file=fo)
        icol = 1
        for ish in range(nsh):
            spn = solver.SK.spin_block_names[solver.SK.corr_shells[
                solver.SK.inequiv_to_corr[ish]]['SO']]
            norb = solver.SK.corr_shells[solver.SK.inequiv_to_corr[ish]]['dim']
            for isp in spn:
                for iorb in range(norb):
                    for jorb in range(norb):
                        icol += 1
                        print("# [%d] Re(Sigma_{shell=%d, spin=%s, %d, %d})" %
                              (icol, ish, isp, iorb, jorb),
                              file=fo)
                        icol += 1
                        print("# [%d] Im(Sigma_{shell=%d, spin=%s, %d, %d})" %
                              (icol, ish, isp, iorb, jorb),
                              file=fo)
        #
        # Write data
        #
        omega = [x for x in sol[0].Sigma_iw.mesh]
        for iom in range(len(omega)):
            print("%f " % omega[iom].imag, end="", file=fo)
            for ish in range(nsh):
                spn = solver.SK.spin_block_names[solver.SK.corr_shells[
                    solver.SK.inequiv_to_corr[ish]]['SO']]
                norb = solver.SK.corr_shells[
                    solver.SK.inequiv_to_corr[ish]]['dim']
                for isp in spn:
                    for iorb in range(norb):
                        for jorb in range(norb):
                            print("%f %f " %
                                  (sol[ish].Sigma_iw[isp].data[iom, iorb,
                                                               jorb].real,
                                   sol[ish].Sigma_iw[isp].data[iom, iorb,
                                                               jorb].imag),
                                  end="",
                                  file=fo)
            print("", file=fo)
    #
    # Output Legendre polynomial
    #
    if p["system"]["n_l"] > 0:
        #
        # Output Sigma into a text file
        #
        print("\n Output Local Self Energy : ",
              p["model"]["seedname"] + "_legendre.dat")
        with open(p["model"]["seedname"] + "_legendre.dat", 'w') as fo:
            print("# Local self energy at imaginary frequency", file=fo)
            #
            # Column information
            #
            print("# [Column] Data", file=fo)
            print("# [1] Order of Legendre polynomials", file=fo)
            icol = 1
            for ish in range(nsh):
                sol[ish].G_l << ar[output_group]['G_l'][str(ish)]
                spn = solver.SK.spin_block_names[solver.SK.corr_shells[
                    solver.SK.inequiv_to_corr[ish]]['SO']]
                norb = solver.SK.corr_shells[
                    solver.SK.inequiv_to_corr[ish]]['dim']
                for isp in spn:
                    for iorb in range(norb):
                        for jorb in range(norb):
                            icol += 1
                            print(
                                "# [%d] Re(G_l_{shell=%d, spin=%s, %d, %d})" %
                                (icol, ish, isp, iorb, jorb),
                                file=fo)
                            icol += 1
                            print(
                                "# [%d] Im(G_l_{shell=%d, spin=%s, %d, %d})" %
                                (icol, ish, isp, iorb, jorb),
                                file=fo)
            #
            # Write data
            #
            for il in range(p["system"]["n_l"]):
                print("%d " % il, end="", file=fo)
                for ish in range(nsh):
                    spn = solver.SK.spin_block_names[solver.SK.corr_shells[
                        solver.SK.inequiv_to_corr[ish]]['SO']]
                    norb = solver.SK.corr_shells[
                        solver.SK.inequiv_to_corr[ish]]['dim']
                    for isp in spn:
                        for iorb in range(norb):
                            for jorb in range(norb):
                                print("%f %f " %
                                      (sol[ish].G_l[isp].data[il, iorb,
                                                              jorb].real,
                                       sol[ish].G_l[isp].data[il, iorb,
                                                              jorb].imag),
                                      end="",
                                      file=fo)
                print("", file=fo)

    #
    # Finish
    #
    del ar
    print("\n  Done\n")
Example #11
0
ps = []
filenames = np.sort(glob.glob('data_B_*.h5'))
for filename in filenames:
    with HDFArchive(filename, 'r') as a:
        p = a['ps'].objects[-1]
    ps.append(p)
ps = ParameterCollections(ps)

B, M = ps.B, ps.M
B = np.concatenate((-B[1:][::-1], B))
M = np.concatenate((-M[1:][::-1], M))
p = np.polyfit(M, B, 5)
m = np.linspace(-0.5, 0.5, num=1000)
b = np.polyval(p, m)
chi = 1. / np.polyval(np.polyder(p, 1), 0.).real

plt.figure(figsize=(3.25 * 1.5, 2.5 * 1.5))
plt.title(r'$\chi = \frac{dM}{dB}|_{B=0} \approx $' + '$ {:3.4f}$'.format(chi))
plt.plot(B, M, 'o', alpha=0.75, label='DMFT field')
plt.plot(b, m, '-', alpha=0.75, label='Poly fit')
plt.legend(loc='upper left')
plt.grid(True)
plt.xlabel(r'$B$')
plt.ylabel(r'$M$')
plt.xlim([B.min(), B.max()])
plt.ylim([-0.5, 0.5])
plt.tight_layout()
plt.savefig('figure_field.svg')
plt.show()