def strip_sigma(nw, beta, sigma_in, debug=False): np.testing.assert_almost_equal(beta, sigma_in.mesh.beta) wmesh = MeshImFreq(beta, 'Fermion', n_max=nw) sigma = Gf(mesh=wmesh, target_shape=sigma_in.target_shape) for w in wmesh: index = w.linear_index + wmesh.first_index() # absolute index sigma[w] = sigma_in[Idx(index)] if debug: from triqs.plot.mpl_interface import oplot, plt oplot(p.Sigmalatt_iw) oplot(sigma, 'x') plt.show() exit() return sigma
def plot_output(g0_wk, gamma): from triqs.plot.mpl_interface import oplot, plt initial_delta = semi_random_initial_delta(g0_wk) next_delta_summation = eliashberg_product(gamma_big, g0_wk, initial_delta) gamma_dyn_tr, gamma_const_r = preprocess_gamma_for_fft(gamma) next_delta_fft = eliashberg_product_fft(gamma_dyn_tr, gamma_const_r, g0_wk, initial_delta) deltas = [initial_delta, next_delta_summation, next_delta_fft] warnings.filterwarnings("ignore") #ignore some matplotlib warnings subp = [4, 3, 1] fig = plt.figure(figsize=(18, 15)) titles = ['Input', 'Summation', 'FFT'] for k_point in [Idx(0, 0, 0), Idx(1, 0, 0)]: ax = plt.subplot(*subp) subp[-1] += 1 oplot(g0_wk[:, k_point]) plt.title('GF') ax = plt.subplot(*subp) subp[-1] += 1 oplot(gamma[:, k_point]) plt.title('Gamma') ax = plt.subplot(*subp) subp[-1] += 1 oplot(gamma_dyn_tr[:, k_point]) plt.title('Gamma dyn tr') for delta, title in zip(deltas, titles): ax = plt.subplot(*subp) subp[-1] += 1 oplot(delta[:, k_point]) plt.title(title) ax.legend_ = None plt.show()
plt.figure(figsize=(6 * 2, 8)) #subp = [3, 6, 1] subp = [4, 1, 1] #idx = 20 idx = 0 vmax = np.max(np.abs(ana.gamma_m.data.real)) opt = dict(vmin=-vmax, vmax=vmax, cmap='PuOr') #opt = dict(vmin=-10., vmax=10., cmap='PuOr') #opt = dict(cmap='PuOr') ax = plt.subplot(*subp) subp[-1] += 1 oplot(ana.G_iw) if True: g2 = ana.gamma_m label = 'gamma ana' s = np.squeeze(g2.data[0, :, :]) ax = plt.subplot(*subp) subp[-1] += 1 plt.title('Re ' + label + ' [i,:,:]') plt.pcolormesh(s.real, **opt) plt.colorbar() if False: g2 = ana.gamma_m
import numpy class myObject: def _plot_(self, options): PI = numpy.pi xdata = numpy.arange(-PI, PI, 0.1) ydata1 = numpy.cos(xdata) ydata2 = numpy.sin(xdata) return ([{ 'xdata': xdata, 'ydata': ydata1, 'label': 'Cos' }, { 'xdata': xdata, 'ydata': ydata2, 'label': 'Sin' }]) X = myObject() from triqs.plot.mpl_interface import oplot oplot(X, '-o')
# get S_w from the auxilliary spectral function Aaux_w Aaux_w = {} w = res['up_0'].omega for key in res: Aaux_w[key] = res[key].analyzer_results['LineFitAnalyzer']['A_out'] isc.set_Gaux_w_from_Aaux_w(Aaux_w, w, np_interp_A=10000, np_omega=4000, w_min=-1.0, w_max=1.0) # save SigmaContinuator again (now it contains S_w) with HDFArchive('Sr2RuO4_b37.h5', 'a') as ar: ar['isc'] = isc # check linfit and plot S_w plt.figure() plt.subplot(1, 2, 1) for key in res: res[key].analyzer_results['LineFitAnalyzer'].plot_linefit() plt.ylim(1e1, 1e4) plt.subplot(1, 2, 2) oplot(isc.S_w['up_0'], mode='I', label='maxent xy', lw=3) oplot(isc.S_w['up_1'], mode='I', label='maxent xz', lw=3) plt.ylabel(r'$\Sigma(\omega)$') plt.xlim(-0.75, 0.75) plt.ylim(-0.4, 0.0)
from triqs.plot.mpl_interface import oplot from triqs.fit.fit import Fit, linear, quadratic from triqs.gf import * from triqs.gf.descriptors import iOmega_n g = GfImFreq(indices=[1], beta=300, n_points=1000, name="g") g << inverse(iOmega_n + 0.5) print(" van plot") oplot(g, '-o', x_window=(0, 3)) print("plot done") g << inverse(iOmega_n + 0.5) print("ok ----------------------") from h5 import HDFArchive R = HDFArchive('myfile.h5', 'r') for n, calculation in list(R.items()): #g = calculation['g'] g << inverse(iOmega_n + 0.5) print("pokokook") X, Y = g.x_data_view(x_window=(0, 0.2), flatten_y=True) #fitl = Fit ( X,Y.imag, linear ) g << inverse(iOmega_n + 0.5) print(" van plot") oplot(g, '-o', x_window=(0, 3))
from triqs.gf import * from h5 import * from triqs.plot.mpl_interface import oplot, oploti, oplotr, plt import numpy as np ar_w2dyn = HDFArchive('aim_solution_w2dyn.h5', 'r') ar_triqs = HDFArchive('aim_solution_triqs.h5', 'r') beta = ar_triqs["G_iw/down/mesh/domain/beta"] print("beta", beta) ### plot Matsubara GF oplot(ar_triqs['G_iw']['up'][0, 0], '-', x_window=(-25, 25), mode='R', name="Re G$_{triqs}$") oplot(ar_triqs['G_iw']['up'][0, 0], '-', x_window=(-25, 25), mode='I', name="Re G$_{triqs}$") oplot(ar_w2dyn['G_iw']['up'][0, 0], '-', x_window=(-25, 25), mode='R', name="Re G$_{w2dyn}$") oplot(ar_w2dyn['G_iw']['up'][0, 0], '-', x_window=(-25, 25), mode='I',
from triqs.gf import * from triqs.plot.mpl_interface import oplot # A Green's function on the Matsubara axis set to a semicircular gw = GfImFreq(indices=[1], beta=50) gw << SemiCircular(half_bandwidth=1) # Create an imaginary-time Green's function gt = GfImTime(indices=[1], beta=50) gt << Fourier(gw) # Plot the Legendre Green's function oplot(gt, '-')
plt.ylim(1e1, 1e3) # curvature(alpha) plt.subplot(2, 2, 3) res.analyzer_results['Chi2CurvatureAnalyzer'].plot_curvature() # probablity(alpha) plt.subplot(2, 2, 2) res.plot_probability() # backtransformed G_rec(tau) and original G(tau) # by default (plot_G=True) also original G(tau) is plotted plt.subplot(2, 2, 4) res.plot_G_rec(alpha_index=5) plt.tight_layout() # spectral function A fig2 = plt.figure() oplot(G_w, mode='S', color='k', lw=3, label='Original Model') plt.plot(res.omega, res.analyzer_results['LineFitAnalyzer']['A_out'], '-', lw=3, label='LineFit') plt.plot(res.omega, res.analyzer_results['Chi2CurvatureAnalyzer']['A_out'], '--', lw=3, label='Chi2Curvature') plt.plot(res.omega, res.analyzer_results['BryanAnalyzer']['A_out'], '-', lw=3, label='Bryan')
with HDFArchive('preblur.h5', 'w') as ar: ar['result_normal'] = result_normal.data ar['results_preblur'] = [r.data for r in results_preblur] # extract the chi2 value from the optimal alpha for each blur parameter chi2s = [] # we have to reverse-sort it because fit_piecewise expects it in that order b_vals = sorted(list(results_preblur.keys()), reverse=True) for b in b_vals: r = results_preblur[b] alpha_index = r.analyzer_results['LineFitAnalyzer']['alpha_index'] chi2s.append(r.chi2[alpha_index]) # perform a linefit to get the optimal b value b_index, _ = fit_piecewise(np.log10(b_vals), np.log10(chi2s)) b_ideal = b_vals[b_index] print('Ideal b value = ', b_ideal) if plot: import matplotlib.pyplot as plt from triqs.plot.mpl_interface import oplot oplot(G_w, mode='S') result_normal.analyzer_results['LineFitAnalyzer'].plot_A_out() results_preblur[b_ideal].analyzer_results['LineFitAnalyzer'].plot_A_out() plt.xlabel(r'$\omega$') plt.ylabel(r'$A(\omega)$') plt.legend(['original', 'normal', 'preblur']) plt.xlim(-2.5, 2.5) plt.savefig('preblur_A.png') plt.show()
G, Sigma = {}, {} for solver in solver_lst: dat = HDFArchive('results/' + solver + '.h5', 'r') G[solver] = dat['G'] Sigma[solver] = G0_iw.copy() Sigma[solver] << inverse(G0_iw) - inverse(G[solver]) # === For every block and solver, plot Green function and Self energy block_lst = list(G[solver_lst[0]].indices) n_blocks = len(block_lst) for g, name in [[G, 'G'], [Sigma, '$\Sigma$']]: plt.subplots(n_blocks, 1, figsize=(10, 6 * n_blocks)) for i, block in enumerate(block_lst, 1): fig = plt.subplot(n_blocks, 1, i) fig.set_title(name + "[" + block + "]") for solver in solver_lst: marker = marker_lst[solver_lst.index(solver)] oplot(g[solver][block][0, 0], marker, name=name + "[0,0]_%s" % solver) plt.xlabel("$\omega_n$") plt.ylabel(name + "[" + block + "]$(i\omega_n)$") plt.tight_layout() plt.show()
from triqs.gf import * from h5 import * from triqs.plot.mpl_interface import oplot with HDFArchive('aim_solution.h5', 'r') as ar: oplot(ar['G_iw']['up'], '-o', x_window=(0, 10))
import numpy as np from triqs.gf import GfReFreq, SemiCircular g = GfReFreq(indices = ['eg1', 'eg2'], window = (-5, 5), n_points = 1000, name = "egBlock") g['eg1','eg1'] = SemiCircular(half_bandwidth = 1) g['eg2','eg2'] = SemiCircular(half_bandwidth = 2) from triqs.plot.mpl_interface import oplot oplot(g['eg1','eg1'], '-o', RI = 'S') # S : spectral function oplot(g['eg2','eg2'], '-x', RI = 'S')
pm.set_G_tau(G_tau_rot, tau_new=np.linspace(0, G_iw_rot.beta, 200)) pm.set_error(1.e-4) result_pm = pm.run() # Plot resulting spectra ######################## import matplotlib matplotlib.rcParams['figure.figsize'] = (12, 12) matplotlib.rcParams.update({'font.size': 16}) from triqs.plot.mpl_interface import oplot fig = plt.figure() for i in range(G_iw_rot.N1): for j in range(G_iw_rot.N2): plt.subplot(2, 2, i * 2 + j + 1) oplot(G_w_rot[i, j], mode='S', color='b', lw=3, label='Model') plt.plot(result_ew.omega, result_ew.get_A_out('LineFitAnalyzer')[i][j], 'k', lw=3, label='Elementwise') plt.plot(result_pm.omega, result_pm.get_A_out('LineFitAnalyzer')[i][j], 'r', lw=3, label='Poorman') plt.xlim(-3, 3) plt.ylabel(r'A$_{%s%s}$($\omega$)' % (i, j)) plt.xlabel(r'$\omega$ (eV)') plt.grid() plt.legend(loc='upper right', prop={'size': 12})
from triqs.gf import * from h5 import * from triqs.plot.mpl_interface import oplot A = HDFArchive("aim_solution.h5",'r') oplot(A['G_l']['up'], '-o', x_window=(15,45) )
nwf = p.n_iw / 2, nwf_gf = p.n_iw, ) a = analytic_hubbard_atom(**parm.dict()) a.G_iw.name = r'$G_{analytic}$' plt.figure(figsize=(3.25*2, 3*2)) subp = [2, 2, 1] plt.subplot(*subp); subp[-1] += 1 oploti(p.G_iw) oploti(a.G_iw) plt.subplot(*subp); subp[-1] += 1 diff = a.G_iw.copy() diff << p.G_iw['up'] - a.G_iw diff.name = r'$G_{ctint} - G_{analytic}$' oplot(diff) plt.subplot(*subp); subp[-1] += 1 vmax = np.max(np.abs(p.chi_m.data.real)) opt = dict(vmax=vmax, vmin=-vmax, cmap='PuOr') data = np.squeeze(p.chi_m.data.real) plt.pcolormesh(data, **opt) plt.tight_layout() plt.show()
from triqs.gf import GfReFreq from h5 import HDFArchive from math import pi R = HDFArchive('myfile.h5', 'r') from triqs.plot.mpl_interface import oplot, plt for name, g in list( R.items()): # iterate on the elements of R, like a dict ... oplot((-1 / pi * g).imag, "-o", name=name) plt.xlim(-1, 1) plt.ylim(0, 7) p.savefig("./tut_ex3b.png")
def test_cf_G_tau_and_G_iw_nonint(verbose=False): beta = 3.22 eps = 1.234 niw = 64 ntau = 2 * niw + 1 H = eps * c_dag(0, 0) * c(0, 0) fundamental_operators = [c(0, 0)] ed = TriqsExactDiagonalization(H, fundamental_operators, beta) # ------------------------------------------------------------------ # -- Single-particle Green's functions G_tau = GfImTime(beta=beta, statistic='Fermion', n_points=ntau, target_shape=(1, 1)) G_iw = GfImFreq(beta=beta, statistic='Fermion', n_points=niw, target_shape=(1, 1)) G_iw << inverse(iOmega_n - eps) G_tau << Fourier(G_iw) G_tau_ed = GfImTime(beta=beta, statistic='Fermion', n_points=ntau, target_shape=(1, 1)) G_iw_ed = GfImFreq(beta=beta, statistic='Fermion', n_points=niw, target_shape=(1, 1)) ed.set_g2_tau(G_tau_ed[0, 0], c(0, 0), c_dag(0, 0)) ed.set_g2_iwn(G_iw_ed[0, 0], c(0, 0), c_dag(0, 0)) # ------------------------------------------------------------------ # -- Compare gfs from triqs.utility.comparison_tests import assert_gfs_are_close assert_gfs_are_close(G_tau, G_tau_ed) assert_gfs_are_close(G_iw, G_iw_ed) # ------------------------------------------------------------------ # -- Plotting if verbose: from triqs.plot.mpl_interface import oplot, plt subp = [3, 1, 1] plt.subplot(*subp) subp[-1] += 1 oplot(G_tau.real) oplot(G_tau_ed.real) plt.subplot(*subp) subp[-1] += 1 diff = G_tau - G_tau_ed oplot(diff.real) oplot(diff.imag) plt.subplot(*subp) subp[-1] += 1 oplot(G_iw) oplot(G_iw_ed) plt.show()
import numpy class myObject: def _plot_(self, options): PI = numpy.pi xdata = numpy.arange(-PI,PI,0.1) phi = options.pop('phi',0) # Crucial : removes the entry from the dict ydata1 = numpy.cos(xdata + phi) ydata2 = numpy.sin(xdata + phi) dict1 = {'xdata': xdata, 'ydata': ydata1, 'label': r'$x \rightarrow \cos (x + \phi), \quad \phi = %s$'%phi} dict2 = {'xdata': xdata, 'ydata': ydata2, 'label': r'$x \rightarrow \sin (x + \phi), \quad \phi = %s$'%phi} dict1.update(options) dict2.update(options) return [dict1, dict2] X = myObject() from triqs.plot.mpl_interface import oplot oplot(X,'-o') oplot(X,'-x', phi = 0.3)
from math import pi from triqs.gf import * gw = GfReFreq(indices=[1], window=(-5, 5), n_points=1001, name="egBlock") gw << SemiCircular(2.0) gt = GfReTime(indices=[1], mesh=make_adjoint_mesh(gw.mesh), name="egBlock") gt << Fourier(gw) from triqs.plot.mpl_interface import oplot oplot(gt.imag, '-o')
from triqs.gf import GfImFreq, SemiCircular g = GfImFreq(indices=['eg1', 'eg2'], beta=50, n_points=1000, name="egBlock") g['eg1', 'eg1'] = SemiCircular(half_bandwidth=1) g['eg2', 'eg2'] = SemiCircular(half_bandwidth=2) from triqs.plot.mpl_interface import oplot, plt oplot(g, '-o', x_window=(0, 10)) plt.ylim(-2, 1)
from triqs.gf import GfReFreq, Omega, Wilson, inverse import numpy eps_d, t = 0.3, 0.2 # Create the real-frequency Green's function and initialize it g = GfReFreq(indices=['s', 'd'], window=(-2, 2), n_points=1000, name="$G_\mathrm{s+d}$") g['d', 'd'] = Omega - eps_d g['d', 's'] = t g['s', 'd'] = t g['s', 's'] = inverse(Wilson(1.0)) g.invert() # Plot it with matplotlib. 'S' means: spectral function ( -1/pi Imag (g) ) from triqs.plot.mpl_interface import oplot, plt oplot(g['d', 'd'], '-o', mode='S', x_window=(-1.8, 1.8), name="Impurity") oplot(g['s', 's'], '-x', mode='S', x_window=(-1.8, 1.8), name="Bath") plt.show()
from triqs.gf import * from triqs.plot.mpl_interface import oplot # A Green's function on the Matsubara axis set to a semicircular gw = GfImFreq(indices = [1], beta = 50) gw << SemiCircular(half_bandwidth = 1) # Create a Legendre Green's function with 40 coefficients # initialize it from gw and plot it gl = GfLegendre(indices = [1], beta = 50, n_points = 40) gl << MatsubaraToLegendre(gw) oplot(gl, '-o')
from triqs.plot.mpl_interface import oplot from triqs.gf import GfImFreq, Omega, inverse g = GfImFreq(indices=[0], beta=300, n_points=1000, name="g") g << inverse(Omega + 0.5) # the data we want to fit... # The green function for omega \in [0,0.2] X, Y = g.x_data_view(x_window=(0, 0.2), flatten_y=True) from triqs.fit import Fit, linear, quadratic fitl = Fit(X, Y.imag, linear) fitq = Fit(X, Y.imag, quadratic) oplot(g, '-o', x_window=(0, 5)) oplot(fitl, '-x', x_window=(0, 0.5)) oplot(fitq, '-x', x_window=(0, 1)) # a bit more complex, we want to fit with a one fermion level .... # Cf the definition of linear and quadratic in the lib one_fermion_level = lambda X, a, b: 1 / (a * X * 1j + b ), r"${1}/(%f x + %f)$", (1, 1) fit1 = Fit(X, Y, one_fermion_level) oplot(fit1, '-x', x_window=(0, 3))
# Semicircle def GSC(z): return 2.0 * (z + sqrt(1 - z**2) * (log(1 - z) - log(-1 + z)) / pi) # A superposition of GLorentz(z) and GSC(z) with equal weights def G(z): return 0.5 * GLorentz(z) + 0.5 * GSC(z) # Matsubara GF gm = GfImFreq(indices=[0], beta=beta, name="gm", n_points=2000) gm << Function(G) # Real frequency BlockGf(documentation/manual/triqs) gr = GfReFreq(indices=[0], window=(-5.995, 5.995), n_points=1200, name="gr") gr << Function(G) # Analytic continuation of gm g_pade = GfReFreq(indices=[0], window=(-5.995, 5.995), n_points=1200, name="g_pade") g_pade.set_from_pade(gm, n_points=L, freq_offset=eta) # Comparison plot from triqs.plot.mpl_interface import oplot oplot(gr[0, 0], '-o', mode='S', name="Original DOS") oplot(g_pade[0, 0], '-x', mode='S', name="Pade-reconstructed DOS")
BL = BravaisLattice(units=[(1, 0, 0), (0, 1, 0)]) # Prepare a nearest neighbour hopping on BL t = -1.00 # First neighbour Hopping tp = 0.0 * t # Second neighbour Hopping # Hopping[ Displacement on the lattice] = [[t11,t12,t13....],[t21,t22,t23....],...,[....,tnn]] # where n=Number_Orbitals hop = { (1, 0): [[t]], (-1, 0): [[t]], (0, 1): [[t]], (0, -1): [[t]], (1, 1): [[tp]], (-1, -1): [[tp]], (1, -1): [[tp]], (-1, 1): [[tp]] } TB = TightBinding(BL, hop) # Compute the density of states d = dos(TB, n_kpts=500, n_eps=101, name='dos')[0] # Plot the dos it with matplotlib from triqs.plot.mpl_interface import oplot from matplotlib import pylab as plt oplot(d, '-o') plt.xlim(-5, 5) plt.ylim(0, 0.4)