def plot_bott_lpparam_glatparam(self, lgbott=None, lpparam='delta', glatparam='ABDelta', outname=None, xlabel=None, ylabel=None, title=None, check_omegacs=False): """Plot phase diagram with lattice param varying on x axis and glatparam varying on y axis Parameters ---------- lgbott : N x 3 float array or None lattice params array, glatparam array, bott indices array glatparam : str outname : str or None """ if lgbott is None: lpV, glatV, botts, omegacs = self.collect_botts_lpparam_glatparam(glatparam=glatparam) # lgbott is the [lattice param, glat param, botts] vector lgbott = np.dstack((lpV, glatV, botts, omegacs))[0] print 'lpV, glatV, botts:' print 'lgbott = ', lgbott ngrid = len(lgbott) + 7 fig, ax, cbar_ax = leplt.initialize_1panel_cbar_cent() leplt.plot_pcolormesh(lgbott[:, 0], lgbott[:, 1], lgbott[:, 2], ngrid, ax=ax, cax=cbar_ax, method='nearest', make_cbar=True, cmap=lecmaps.diverging_cmap(250, 10, l=30), vmin=-1., vmax=1., title=None, xlabel=None, ylabel=None, ylabel_right=True, ylabel_rot=90, cax_label=r'Bott index, $B$', cbar_labelpad=-30, cbar_orientation='horizontal', ticks=[-1, 0, 1], fontsize=8, title_axX=None, title_axY=None, alpha=1.0) if title is not None: cbar_ax.text(0.5, 0.95, title, ha='center', va='center', transform=fig.transFigure) if xlabel is None: xlabel = leplt.param2description(glatparam) if ylabel is None: ylabel = leplt.param2description(lpparam) ax.set_xlabel(xlabel) ax.set_ylabel(ylabel) if outname is not None: print 'saving figure to ' + outname plt.savefig(outname) if check_omegacs: fig2, ax2 = leplt.initialize_1panel_centered_fig(wsfrac=0.5, tspace=4) leplt.plot_pcolormesh(lgbott[:, 0], lgbott[:, 1], omegacs[:, 3], ngrid, ax=ax2, cax=cbar_ax, method='nearest', make_cbar=True, cmap=lecmaps.diverging_cmap(250, 10, l=30), vmin=-1., vmax=1., title=None, xlabel=None, ylabel=None, ylabel_right=True, ylabel_rot=90, cax_label=r'Bott index, $B$', cbar_labelpad=-30, cbar_orientation='horizontal', ticks=[-1, 0, 1], fontsize=8, title_axX=None, title_axY=None, alpha=1.0) return fig, ax
def plot_gapbounds(abv, gapbounds, outname, lp): """Plot the gap closing as a function of Delta_AB for magnetic system. Axis parameters are fixed so that output can be made into a movie Parameters ---------- abv : n x 1 float array The Delta_AB values for each spectrum gapbounds: n x 2(#bands) float array The bottom and top of each band for each value of abv """ plt.close('all') fig, ax = leplt.initialize_1panel_centered_fig(wsfrac=0.5, tspace=2) # ax.plot(abv, gapbounds[:, 0], '.-', color=lecmaps.violet()) # ax.plot(abv, gapbounds[:, 1], '.-', color=lecmaps.green()) nbands = int(0.5 * np.shape(gapbounds)[1]) colors = [ lecmaps.green(), lecmaps.violet(), lecmaps.orange(), lecmaps.blue(), lecmaps.red(), '#000000' ] for ii in range(nbands): ax.fill_between(abv, gapbounds[:, 1 + 2 * ii], gapbounds[:, 0 + 2 * ii], color=colors[ii]) ax.text(0.5, 1.12, 'Bands for magnetic gyros (' + r'$a/\ell=$' + '{0:0.2f}'.format(lp['aoverl']) + ', ' r'$\Omega_k/\Omega_g=$' + '{0:0.3f}'.format(lp['Omk'] / lp['Omg']) + ')', ha='center', va='center', transform=ax.transAxes) ax.set_xlabel(r'Inversion symmetry breaking $\Delta_{AB}$') ax.set_ylabel(r'Frequency, $\omega$') ax.set_ylim(0, 3.5) print 'saving figure: ', outname plt.savefig(outname) plt.close('all')
def compare_dispersion_to_dos(omegas, kx, ky, mlat, outdir=None): """Compare the projection of the dispersion onto the omega axis with the DOS of the MagneticGyroLattice Parameters ---------- omegas kx ky mlat outdir Returns ------- """ # Save DOS from projection if outdir is None: outdir = dio.prepdir(mlat.lp['meshfn']) else: outdir = dio.prepdir(outdir) name = outdir + 'dispersion_gyro' + mlat.lp['meshfn_exten'] + '_nx' + str(len(kx)) + '_ny' + str(len(ky)) name += '_maxkx{0:0.3f}'.format(np.max(np.abs(kx))).replace('.', 'p') name += '_maxky{0:0.3f}'.format(np.max(np.abs(ky))).replace('.', 'p') # initialize figure fig, ax = leplt.initialize_1panel_centered_fig() ax2 = ax.twinx() ax.hist(omegas.ravel(), bins=1000) # Compare the histograms of omegas to the dos and save the figure eigval = np.imag(mlat.get_eigval()) print 'eigval = ', eigval ax2.hist(eigval[eigval > 0], bins=50, color=lecmap.green(), alpha=0.2) ax.set_title('DOS from dispersion') xlims = ax.get_xlim() ax.set_xlim(0, xlims[1]) plt.savefig(name + '_dos.png', dpi=300)
def infinite_dispersion_matk(matk, lat, kx=None, ky=None, nkxvals=50, nkyvals=20, save=True, save_plot=True, title='matrix dispersion relation', outdir=None, name=None, ax=None, lwscale=1., verbose=False): """ Parameters ---------- glat kx ky nkxvals nkyvals save save_plot title outdir name ax lwscale verbose Returns ------- """ name, kx, ky = prepare_generalized_dispersion_params(lat, kx=kx, ky=ky, nkxvals=nkxvals, nkyvals=nkyvals, outdir=outdir, name=name) print('checking for file: ' + name + '.pkl') if glob.glob(name + '.pkl'): saved = True with open(name + '.pkl', "rb") as fn: res = pkl.load(fn) omegas = res['omegas'] kx = res['kx'] ky = res['ky'] else: # dispersion is not saved, compute it! saved = False omegas = np.zeros((len(kx), len(ky), len(matk([0, 0])))) ii = 0 for kxi in kx: if ii % 50 == 0: print 'glatkspace_fns: infinite_dispersion(): ii = ', ii jj = 0 for kyj in ky: # print 'jj = ', jj matrix = matk([kxi, kyj]) # print 'glatkspace_fns: diagonalizing...' eigval, eigvect = np.linalg.eig(matrix) si = np.argsort(np.imag(eigval)) omegas[ii, jj, :] = np.imag(eigval[si]) jj += 1 ii += 1 if save_plot or ax is not None: if ax is None: fig, ax = leplt.initialize_1panel_centered_fig(Hfig=90, wsfrac=0.6) for jj in range(len(ky)): for kk in range(len(omegas[0, jj, :])): ax.plot(kx, omegas[:, jj, kk], 'k-', lw=lwscale * max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k$ $[\langle \ell \rangle ^{-1}]$') ax.set_ylabel(r'$\omega$') ylims = ax.get_ylim() ax.set_ylim(0, ylims[1]) # Save the plot if save_plot: print 'saving ' + name + '.png' plt.savefig(name + '.png', dpi=200) plt.close('all') if save: if not saved: res = {'omegas': omegas, 'kx': kx, 'ky': ky} with open(name + '.pkl', "wb") as fn: pkl.dump(res, fn) return omegas, kx, ky
def plot_cherns_vary_param(self, param_type='glat', sz_param_nu=None, reverse=False, param='percolation_density', title='Chern index calculation', xlabel=None): """Plot chern indices with x axis being the parameter which is varying between networks. If there are multiple chern calculations of a particular lattice, average nu over them all. Parameters ---------- param_type : str ('glat' or 'lat') Whether we are varying a lattice parameter (different lattices) or a gyrolattice parameter (same lattice, different physics) sz_param_nu : None or 'glat' or ('lat' or 'lp' -- last two do same thing) string specifier for how to vary params reverse : bool Compute cherns for GyroLattice instances in self.mgyro_collection in reverse order param : string string specifier for GyroLattice parameter to vary between networks; key for mglat.lp dict title : str title of the plot xlabel : str xlabel, if desired to be other than default for param (ie, param.replace('_', ' ')) """ if sz_param_nu is None: if param_type == 'lat' or param_type == 'lp': param_nu = self.collect_cherns_vary_lpparam(param=param, reverse=reverse) elif param_type == 'glat': param_nu = self.collect_cherns_vary_glatparam(param=param, reverse=reverse) else: raise RuntimeError("param_type argument passed is not 'glat' or 'lat/lp'") # Plot it as colormap plt.close('all') paramV = param_nu[:, 0] nu = param_nu[:, 1] # Make figure import lepm.plotting.plotting as leplt fig, ax = leplt.initialize_1panel_centered_fig(wsfrac=0.5, tspace=4) if xlabel is None: xlabel = param.replace('_', ' ') # Plot the curve # first sort the paramV values if isinstance(paramV[0], float): si = np.argsort(paramV) else: si = np.arange(len(paramV), dtype=int) ax.plot(paramV[si], nu[si], '.-') ax.set_xlabel(xlabel) # Add title ax.text(0.5, 0.95, title, transform=fig.transFigure, ha='center', va='center') # Save the plot if param_type == 'glat': outdir = rootdir + 'kspace_cherns_mgyro/chern_glatparam/' + param + '/' dio.ensure_dir(outdir) # Add meshfn name to the output filename outbase = self.cherns[self.cherns.items()[0][0]][0].mgyro_lattice.lp['meshfn'] if outbase[-1] == '/': outbase = outbase[:-1] outbase = outbase.split('/')[-1] outd_ex = self.cherns[self.cherns.items()[0][0]][0].mgyro_lattice.lp['meshfn_exten'] # If the parameter name is part of the meshfn_exten, replace its value with XXX in # the meshfnexten part of outdir. mfestr = glat_param2meshfnexten_name(param) if mfestr in outd_ex: 'param is in meshfn_exten, splitting...' # split the outdir by the param string od_split = outd_ex.split(mfestr) # split the second part by the value of the param string and the rest od2val_rest = od_split[1].split('_') odrest = od_split[1].split(od2val_rest[0])[1] print 'odrest = ', odrest print 'od2val_rest = ', od2val_rest outd_ex = od_split[0] + param + 'XXX' outd_ex += odrest print 'outd_ex = ', outd_ex else: outd_ex += '_' + param + 'XXX' elif param_type == 'lat': outdir = rootdir + 'kspace_cherns_mgyro/chern_lpparam/' + param + '/' outbase = self.cherns[self.cherns.items()[0][0]][0].mgyro_lattice.lp['meshfn'] # Take apart outbase to parse out the parameter that is varying mfestr = lat_param2meshfn_name(param) if mfestr in outbase : 'param is in meshfn_exten, splitting...' # split the outdir by the param string od_split = outbase.split(mfestr) # split the second part by the value of the param string and the rest od2val_rest = od_split[1].split('_') odrest = od_split[1].split(od2val_rest[0])[1] print 'odrest = ', odrest print 'od2val_rest = ', od2val_rest outd_ex = od_split[0] + param + 'XXX' outd_ex += odrest print 'outd_ex = ', outd_ex else: outbase += '_' + param + 'XXX' outd_ex = self.cherns[self.cherns.items()[0][0]][0].mgyro_lattice.lp['meshfn_exten'] dio.ensure_dir(outdir) fname = outdir + outbase fname += '_chern_' + param + '_Ncoll' + '{0:03d}'.format(len(self.mgyro_collection.mgyro_lattices)) fname += outd_ex print 'saving to ' + fname + '.png' plt.savefig(fname + '.png') plt.clf()
def infinite_dispersion_unstructured(glat, kxy, load=False, save=True, save_plot=True, title='gyro dispersion relation', outdir=None, name=None, ax=None, lwscale=1., verbose=False, overwrite=False, return_eigvects=False): """ Do not assume grid structure of kxy for this function. Compute the spectrum evaluated at the points given by the 2d array kxy. Parameters ---------- glat kxy save save_plot title outdir name ax lwscale verbose Returns ------- omegas : tuple (omegas, eigvects) if return_eigvects is True, otherwise len(kxy) x 2 * len(xy) float array The eigenvalues, and possibly the corresponding eigenvectors if kwarg return_eigvects is True, returned as float and complex arrays, respectively. omegas is a len(kxy) x 2 * len(xy) float array, while eigvects, if returned, is a len(kxy) x 2 * len(xy) x 2 * len(xy) complex array """ name, kx, ky = prepare_dispersion_params(glat, kx=kxy[:, 0], ky=kxy[:, 1], outdir=outdir, name=name) name += '_unstructured' if glob.glob(name + '.pkl') and not overwrite and load: print('checking for file: ' + name + '.pkl') saved = True with open(name + '.pkl', "rb") as fn: res = pkl.load(fn) omegas = res['omegas'] kx = res['kx'] ky = res['ky'] else: # dispersion is not saved, compute it! saved = False omegas = np.zeros((len(kxy), len(glat.lattice.xy) * 2)) if return_eigvects: eigvects = np.zeros( (len(kxy), len(glat.lattice.xy) * 2, len(glat.lattice.xy) * 2), dtype=complex) matk = lambda k: dynamical_matrix_kspace(k, glat, eps=1e-10) ii = 0 for pt in kxy: if ii % 50 == 1: print 'glatkspace_fns: infinite_dispersion(): ii = ', ii matrix = matk([pt[0], pt[1]]) eigval, eigvect = np.linalg.eig(matrix) si = np.argsort(np.imag(eigval)) omegas[ii, :] = np.imag(eigval[si]) if return_eigvects: eigvect = np.array(eigvect) eigvect_out = eigvect.T[si] # print 'eigvect_out = ', eigvect_out # if ortho_eigvect: # eigvect_out = gdh.orthonormal_eigvect(eigvect) # print 'eigvect_out = ', eigvect_out eigvects[ii] = eigvect_out ii += 1 if save_plot or ax is not None: if ax is None: fig, ax = leplt.initialize_1panel_centered_fig() for jj in range(len(ky)): for kk in range(len(omegas[0, jj, :])): ax.plot(kx, omegas[:, jj, kk], 'k-', lw=lwscale * max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k$ $[\langle \ell \rangle ^{-1}]$') ax.set_ylabel(r'$\omega$') ylims = ax.get_ylim() ax.set_ylim(0, ylims[1]) # Save the plot if save_plot: plt.savefig(name + '.png', dpi=300) plt.close('all') if save: if not saved: res = {'omegas': omegas, 'kx': kx, 'ky': ky} with open(name + '.pkl', "wb") as fn: pkl.dump(res, fn) if return_eigvects: omegas = (omegas, eigvects) return omegas, kx, ky
def infinite_dispersion(glat, kx=None, ky=None, nkxvals=50, nkyvals=20, save=True, save_plot=True, title='gyro dispersion relation', outdir=None, name=None, ax=None, lwscale=1., verbose=False): """Compute the imaginary part of the eigvalues of the dynamical matrix for a grid (or unstructued set) of wavevectors kx, ky. See also calc_bands() and calc_band_gaps() Parameters ---------- glat : GyroLattice class instance the gyro network whose dispersion we compute kx : n x 1 float array the x components of the wavevectors over which to diagonalize the dynamical matrix ky : m x 1 float array the y components of the wavevectors over which to diagonalize the dynamical matrix nkxvals : int If kx is unspecified, then nkxvals determines how many kvectors are sampled in x dimension. nkyvals : int If ky is unspecified and if network is not a periodic_strip, then nkyvals determines how many kvectors are sampled in y dimension. save : bool Save the omega vs k information in a pickle save_plot : bool Save the omega vs k info as a matplotlib figure png title : str title for the plot to save outdir : str or None The directory in which to output the image and pickle of the results if save == True Returns ------- """ name, kx, ky = prepare_dispersion_params(glat, kx=kx, ky=ky, nkxvals=nkxvals, nkyvals=nkyvals, outdir=outdir, name=name) print('checking for file: ' + name + '.pkl') if glob.glob(name + '.pkl'): saved = True with open(name + '.pkl', "rb") as fn: res = pkl.load(fn) omegas = res['omegas'] kx = res['kx'] ky = res['ky'] else: # dispersion is not saved, compute it! saved = False omegas = np.zeros((len(kx), len(ky), len(glat.lattice.xy) * 2)) matk = lambda k: dynamical_matrix_kspace(k, glat, eps=1e-10) ii = 0 for kxi in kx: if ii % 50 == 0: print 'glatkspace_fns: infinite_dispersion(): ii = ', ii jj = 0 for kyj in ky: # print 'jj = ', jj matrix = matk([kxi, kyj]) # print 'glatkspace_fns: diagonalizing...' eigval, eigvect = np.linalg.eig(matrix) si = np.argsort(np.imag(eigval)) omegas[ii, jj, :] = np.imag(eigval[si]) # print 'eigvals = ', eigval # print 'omegas --> ', omegas[ii, jj] jj += 1 ii += 1 if save_plot or ax is not None: if ax is None: fig, ax = leplt.initialize_1panel_centered_fig() for jj in range(len(ky)): for kk in range(len(omegas[0, jj, :])): ax.plot(kx, omegas[:, jj, kk], 'k-', lw=lwscale * max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k$ $[\langle \ell \rangle ^{-1}]$') ax.set_ylabel(r'$\omega$') ylims = ax.get_ylim() ax.set_ylim(0, ylims[1]) # Save the plot if save_plot: print 'saving ' + name + '.png' plt.savefig(name + '.png', dpi=300) plt.close('all') # Plot in 3D # fig = plt.gcf() # ax = fig.add_subplot(projection='3d') # 111, # # rows will be kx, cols wll be ky # kyv = np.array([[ky[i].tolist()] * len(kx) for i in range(len(ky))]).ravel() # kxv = np.array([[kx.tolist()] * len(ky)]).ravel() # print 'kyv = ', np.shape(kyv) # print 'kxv = ', np.shape(kxv) # for kk in range(len(omegas[0, 0, :])): # ax.plot_trisurf(kxv, kyv, omegas[:, :, kk].ravel()) # # ax.view_init(elev=0, azim=0.) # ax.set_title(title) # ax.set_xlabel(r'$k_x$ $[1/\langle l \rangle]$') # ax.set_ylabel(r'$k_y$ $[1/\langle l \rangle]$') # plt.savefig(name + '_3d.png') if save: if not saved: res = {'omegas': omegas, 'kx': kx, 'ky': ky} with open(name + '.pkl', "wb") as fn: pkl.dump(res, fn) return omegas, kx, ky
result[kk, 0] = ntest result[kk, 1] = bott results[nsize] = result # from scipy.linalg import logm # print 'total bott = ', np.trace(logm(np.dot(vv, np.dot(uu, np.dot(vv.conj().T, uu.conj().T))))) # bott = np.imag(np.trace(logm(np.dot(vv, np.dot(uu, np.dot(vv.conj().T, uu.conj().T)))))) ###################### kk += 1 plt.close('all') # print 'result = ', result # sys.exit() fig, ax = leplt.initialize_1panel_centered_fig() markers = ['o', '.', '^'] lines = ['-', '--', '-.'] kk = 0 for nsize in results: ax.plot(results[nsize][:, 0], results[nsize][:, 1], marker=markers[kk], linestyle=lines[kk], markersize=1, markeredgecolor=None, label=str(nsize)) kk += 1 ax.legend(loc='lower right') # check system size
def infinite_dispersion(mglat, kx=None, ky=None, nkxvals=50, nkyvals=20, save=True, save_plot=True, title='Dispersion relation', outdir=None): """ Parameters ---------- mglat : kx : ky : save : title : outdir : Returns ------- omegas, kx, ky """ if not mglat.lp['periodicBC']: raise RuntimeError('Cannot compute dispersion for open BC system') elif mglat.lp['periodic_strip']: print 'Evaluating infinite-system dispersion for strip: setting ky=constant=0.' ky = [0.] if ky is None or kx is None: bboxx = max(mglat.lattice.lp['BBox'][:, 0]) - min(mglat.lattice.lp['BBox'][:, 0]) bboxy = max(mglat.lattice.lp['BBox'][:, 1]) - min(mglat.lattice.lp['BBox'][:, 1]) if kx is None: tmp = np.linspace(-1. / bboxx, 1. / bboxx, nkxvals - 1) step = np.diff(tmp)[0] kx = 2. * np.pi * np.linspace(-1. / bboxx, 1. / bboxx + step, nkxvals) # kx = np.linspace(-5., 5., 40) if ky is None: tmp = np.linspace(-1. / bboxy, 1. / bboxy, nkyvals - 1) step = np.diff(tmp)[0] ky = 2. * np.pi * np.linspace(-1. / bboxy, 1. / bboxy + step, nkyvals) # ky = np.linspace(-5., 5., 4) # First check for saved dispersion if outdir is None: outdir = dio.prepdir(mglat.lp['meshfn']) else: outdir = dio.prepdir(outdir) name = outdir + 'dispersion' + mglat.lp['meshfn_exten'] + '_nx' + str(len(kx)) + '_ny' + str(len(ky)) name += '_maxkx{0:0.3f}'.format(np.max(np.abs(kx))).replace('.', 'p') name += '_maxky{0:0.3f}'.format(np.max(np.abs(ky))).replace('.', 'p') print('checking for file: ' + name + '.pkl') if glob.glob(name + '.pkl'): saved = True with open(name + '.pkl', "rb") as fn: res = pkl.load(fn) omegas = res['omegas'] kx = res['kx'] ky = res['ky'] else: # dispersion is not saved, compute it! saved = False # Use PVx and PVy to multiply exp(i*np.dot(k, PV[0,:])) to periodic vectors in x, similar in y omegas = np.zeros((len(kx), len(ky), len(mglat.lattice.xy) * 2)) matk = lambda k: dynamical_matrix_kspace(k, mglat, eps=1e-10) ii = 0 for kxi in kx: if ii % 25 == 0: print 'infinite_dispersion(): ii = ', ii jj = 0 for kyj in ky: # print 'jj = ', jj matrix = matk([kxi, kyj]) eigval, eigvect = np.linalg.eig(matrix) si = np.argsort(np.imag(eigval)) omegas[ii, jj, :] = np.imag(eigval[si]) # print 'omegas = ', omegas jj += 1 ii += 1 if save_plot: fig, ax = leplt.initialize_1panel_centered_fig() for jj in range(len(ky)): for kk in range(len(omegas[0, jj, :])): ax.plot(kx, omegas[:, jj, kk], 'k-', lw=max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k$ $[1/\langle l \rangle]$') ax.set_ylabel(r'$\omega$') print 'magnetic_gyro_kspace_functions: saving image to ' + name + '.png' plt.savefig(name + '.png') plt.close('all') # Plot in 3D # fig = plt.gcf() # ax = fig.add_subplot(projection='3d') # 111, # # rows will be kx, cols wll be ky # kyv = np.array([[ky[i].tolist()] * len(kx) for i in range(len(ky))]).ravel() # kxv = np.array([[kx.tolist()] * len(ky)]).ravel() # print 'kyv = ', np.shape(kyv) # print 'kxv = ', np.shape(kxv) # for kk in range(len(omegas[0, 0, :])): # ax.plot_trisurf(kxv, kyv, omegas[:, :, kk].ravel()) # # ax.view_init(elev=0, azim=0.) # ax.set_title(title) # ax.set_xlabel(r'$k_x$ $[1/\langle l \rangle]$') # ax.set_ylabel(r'$k_y$ $[1/\langle l \rangle]$') # plt.savefig(name + '_3d.png') if save: if not saved: res = {'omegas': omegas, 'kx': kx, 'ky': ky} with open(name + '.pkl', "wb") as fn: pkl.dump(res, fn) return omegas, kx, ky
def plot_cherns_vary_param(kcgcoll, param_type='glat', sz_param_nu=None, reverse=False, param='percolation_density', title='Chern index calculation', xlabel=None): """ Parameters ---------- kcgcoll : param_type : sz_param_nu : reverse : param : title : xlabel : Returns ------- """ if sz_param_nu is None: if param_type == 'lat' or param_type == 'lp': param_nu = self.collect_cherns_vary_lpparam(param=param, reverse=reverse) elif param_type == 'glat': param_nu = self.collect_cherns_vary_glatparam(param=param, reverse=reverse) else: raise RuntimeError( "param_type argument passed is not 'glat' or 'lat/lp'") # Plot it as colormap plt.close('all') paramV = param_nu[:, 0] nu = param_nu[:, 1] # Make figure import lepm.plotting.plotting as leplt fig, ax = leplt.initialize_1panel_centered_fig(wsfrac=0.5, tspace=4) if xlabel is None: xlabel = param.replace('_', ' ') # Plot the curve # first sort the paramV values if isinstance(paramV[0], float): si = np.argsort(paramV) else: si = np.arange(len(paramV), dtype=int) ax.plot(paramV[si], nu[si], '.-') ax.set_xlabel(xlabel) # Add title ax.text(0.5, 0.95, title, transform=fig.transFigure, ha='center', va='center') # Save the plot if param_type == 'glat': outdir = rootdir + 'kspace_cherns_gyro/chern_glatparam/' + param + '/' dio.ensure_dir(outdir) # Add meshfn name to the output filename outbase = self.cherns[self.cherns.items()[0] [0]][0].gyro_lattice.lp['meshfn'] if outbase[-1] == '/': outbase = outbase[:-1] outbase = outbase.split('/')[-1] outd_ex = self.cherns[self.cherns.items()[0] [0]][0].gyro_lattice.lp['meshfn_exten'] # If the parameter name is part of the meshfn_exten, replace its value with XXX in # the meshfnexten part of outdir. mfestr = glatfns.param2meshfnexten_name(param) if mfestr in outd_ex: 'param is in meshfn_exten, splitting...' # split the outdir by the param string od_split = outd_ex.split(mfestr) # split the second part by the value of the param string and the rest od2val_rest = od_split[1].split('_') odrest = od_split[1].split(od2val_rest[0])[1] print 'odrest = ', odrest print 'od2val_rest = ', od2val_rest outd_ex = od_split[0] + param + 'XXX' outd_ex += odrest print 'outd_ex = ', outd_ex else: outd_ex += '_' + param + 'XXX' elif param_type == 'lat': outdir = rootdir + 'kspace_cherns_gyro/chern_lpparam/' + param + '/' outbase = self.cherns[self.cherns.items()[0] [0]][0].gyro_lattice.lp['meshfn'] # Take apart outbase to parse out the parameter that is varying mfestr = latfns.param2meshfnexten_name(param) if mfestr in outbase: 'param is in meshfn_exten, splitting...' # split the outdir by the param string od_split = outbase.split(mfestr) # split the second part by the value of the param string and the rest od2val_rest = od_split[1].split('_') odrest = od_split[1].split(od2val_rest[0])[1] print 'odrest = ', odrest print 'od2val_rest = ', od2val_rest outd_ex = od_split[0] + param + 'XXX' outd_ex += odrest print 'outd_ex = ', outd_ex else: outbase += '_' + param + 'XXX' outd_ex = self.cherns[self.cherns.items()[0] [0]][0].gyro_lattice.lp['meshfn_exten'] dio.ensure_dir(outdir) fname = outdir + outbase fname += '_chern_' + param + '_Ncoll' + '{0:03d}'.format( len(self.gyro_collection.gyro_lattices)) fname += outd_ex print 'saving to ' + fname + '.png' plt.savefig(fname + '.png') plt.clf()
def infinite_dispersion(mlat, kx=None, ky=None, nkxvals=50, nkyvals=20, save=True, save_plot=True, title='twisty dispersion relation', outdir=None, name=None, ax=None): """Compute the imaginary part of the eigvalues of the dynamical matrix for a grid of wavevectors kx, ky Parameters ---------- mlat : MassLattice class instance the twisty network whose dispersion we compute kx : n x 1 float array the x components of the wavevectors over which to diagonalize the dynamical matrix ky : m x 1 float array the y components of the wavevectors over which to diagonalize the dynamical matrix nkxvals : int If kx is unspecified, then nkxvals determines how many kvectors are sampled in x dimension. nkyvals : int If ky is unspecified and if network is not a periodic_strip, then nkyvals determines how many kvectors are sampled in y dimension. save : bool Save the omega vs k information in a pickle save_plot : bool Save the omega vs k info as a matplotlib figure png title : str title for the plot to save outdir : str or None The directory in which to output the image and pickle of the results if save == True Returns ------- """ if not mlat.lp['periodicBC']: raise RuntimeError('Cannot compute dispersion for open BC system') elif mlat.lp['periodic_strip']: print 'Evaluating infinite-system dispersion for strip: setting ky=constant=0.' ky = [0.] bboxx = max(mlat.lattice.lp['BBox'][:, 0]) - min(mlat.lattice.lp['BBox'][:, 0]) elif ky is None or kx is None: bboxx = max(mlat.lattice.lp['BBox'][:, 0]) - min(mlat.lattice.lp['BBox'][:, 0]) bboxy = max(mlat.lattice.lp['BBox'][:, 1]) - min(mlat.lattice.lp['BBox'][:, 1]) if kx is None: if nkxvals == 0: kx = np.array([0.]) else: tmp = np.linspace(-1. / bboxx, 1. / bboxx, nkxvals - 1) step = np.diff(tmp)[0] kx = 2. * np.pi * np.linspace(-1. / bboxx, 1. / bboxx + step, nkxvals) # kx = np.linspace(-5., 5., 40) if ky is None: if nkyvals == 0: ky = np.array([0.]) else: tmp = np.linspace(-1. / bboxy, 1. / bboxy, nkyvals - 1) step = np.diff(tmp)[0] ky = 2. * np.pi * np.linspace(-1. / bboxy, 1. / bboxy + step, nkyvals) # ky = np.linspace(-5., 5., 4) # First check for saved dispersion if outdir is None: outdir = dio.prepdir(mlat.lp['meshfn']) else: outdir = dio.prepdir(outdir) if name is None: name = 'dispersion' + mlat.lp['meshfn_exten'] + '_nx' + str(len(kx)) + '_ny' + str(len(ky)) name += '_maxkx{0:0.3f}'.format(np.max(np.abs(kx))).replace('.', 'p') name += '_maxky{0:0.3f}'.format(np.max(np.abs(ky))).replace('.', 'p') name = outdir + name print('checking for file: ' + name + '.pkl') if glob.glob(name + '.pkl'): saved = True with open(name + '.pkl', "rb") as fn: res = pkl.load(fn) omegas = res['omegas'] kx = res['kx'] ky = res['ky'] else: # dispersion is not saved, compute it! saved = False omegas = np.zeros((len(kx), len(ky), len(mlat.lattice.xy) * 2)) matk = lambda k: dynamical_matrix_kspace(k, mlat, eps=1e-10) ii = 0 for kxi in kx: print 'mlatkspace_fns: infinite_dispersion(): ii = ', ii jj = 0 for kyj in ky: # print 'jj = ', jj matrix = matk([kxi, kyj]) print 'mlatkspace_fns: diagonalizing...' eigval, eigvect = np.linalg.eig(matrix) si = np.argsort(np.real(eigval)) omegas[ii, jj, :] = np.real(np.sqrt(-eigval[si])) # print 'eigvals = ', eigval # print 'omegas --> ', omegas[ii, jj] jj += 1 ii += 1 if save_plot: if ax is None: fig, ax = leplt.initialize_1panel_centered_fig() axsupplied = False else: axsupplied = True for jj in range(len(ky)): for kk in range(len(omegas[0, jj, :])): ax.plot(kx, omegas[:, jj, kk], 'k-', lw=max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k_x$ $[\langle \ell \rangle ^{-1}]$') ax.set_ylabel(r'$\omega$') ylims = ax.get_ylim() ylim0 = min(ylims[0], -0.1 * ylims[1]) ax.set_ylim(ylim0, ylims[1]) # Save the plot plt.savefig(name + '.png', dpi=300) ax.set_ylim(max(ylim0, -0.05 * ylims[1]), 0.05 * ylims[1]) # Save the plot plt.savefig(name + '_zoom.png', dpi=300) # Fixed zoom ax.set_ylim(-0.3, 0.6) plt.savefig(name + '_zoom2.png', dpi=300) plt.close('all') # save plot of ky if no axis supplied if not axsupplied: fig, ax = leplt.initialize_1panel_centered_fig() for jj in range(len(kx)): for kk in range(len(omegas[jj, 0, :])): ax.plot(ky, omegas[jj, :, kk], 'k-', lw=max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k_y$ $[\langle \ell \rangle ^{-1}]$') ax.set_ylabel(r'$\omega$') ylims = ax.get_ylim() ylim0 = min(ylims[0], -0.1 * ylims[1]) ax.set_ylim(ylim0, ylims[1]) # Save the plot plt.savefig(name + '_ky.png', dpi=300) ax.set_ylim(max(ylim0, -0.05 * ylims[1]), 0.05 * ylims[1]) # Save the plot plt.savefig(name + '_zoom_ky.png', dpi=300) # Fixed zoom ax.set_ylim(-0.3, 0.6) plt.savefig(name + '_zoom2_ky.png', dpi=300) plt.close('all') # Plot in 3D # fig = plt.gcf() # ax = fig.add_subplot(projection='3d') # 111, # # rows will be kx, cols wll be ky # kyv = np.array([[ky[i].tolist()] * len(kx) for i in range(len(ky))]).ravel() # kxv = np.array([[kx.tolist()] * len(ky)]).ravel() # print 'kyv = ', np.shape(kyv) # print 'kxv = ', np.shape(kxv) # for kk in range(len(omegas[0, 0, :])): # ax.plot_trisurf(kxv, kyv, omegas[:, :, kk].ravel()) # # ax.view_init(elev=0, azim=0.) # ax.set_title(title) # ax.set_xlabel(r'$k_x$ $[1/\langle l \rangle]$') # ax.set_ylabel(r'$k_y$ $[1/\langle l \rangle]$') # plt.savefig(name + '_3d.png') if save: if not saved: res = {'omegas': omegas, 'kx': kx, 'ky': ky} with open(name + '.pkl', "wb") as fn: pkl.dump(res, fn) return omegas, kx, ky
def infinite_dispersion(hlat, kx=None, ky=None, save=True, title='Dispersion relation', outdir=None): """Compute energy versus wavenumber for a grid of kx ky values for a haldane model network. If the network is a periodic strip, then ky is set to zero and we look at E(kx). Parameters ---------- hlat : HaldaneLattice instance the tight-binding network over which to compute the dispersion relation kx : N x 1 float array The x component of the wavenumbers to evaluate ky : M x 1 float array The y component of the wavenumbers to evaluate save : bool Whether to save the dispersion to disk title : str title of the plot to make if save is True outdir : str path to the place to save the plot if save is True Returns ------- """ if not hlat.lp['periodicBC']: raise RuntimeError('Cannot compute dispersion for open BC system') elif hlat.lp['periodic_strip']: print 'Evaluating infinite-system dispersion for strip: setting ky=constant=0.' ky = [0.] bboxx = max(hlat.lattice.lp['BBox'][:, 0]) - min( hlat.lattice.lp['BBox'][:, 0]) print 'bboxx = ', bboxx elif ky is None or kx is None: bboxx = max(hlat.lattice.lp['BBox'][:, 0]) - min( hlat.lattice.lp['BBox'][:, 0]) bboxy = max(hlat.lattice.lp['BBox'][:, 1]) - min( hlat.lattice.lp['BBox'][:, 1]) if kx is None: kx = np.linspace(-2. * np.pi / bboxx, 2. * np.pi / bboxx, 50) # kx = np.linspace(-5., 5., 40) if ky is None: ky = np.linspace(-2. * np.pi / bboxy, 2. * np.pi / bboxy, 5) # ky = np.linspace(-5., 5., 4) # First check for saved dispersion if outdir is None: outdir = dio.prepdir(hlat.lp['meshfn']) else: outdir = dio.prepdir(outdir) name = outdir + 'dispersion' + hlat.lp['meshfn_exten'] + '_nx' + str( len(kx)) + '_ny' + str(len(ky)) name += '_maxkx{0:0.3f}'.format(np.max(np.abs(kx))).replace('.', 'p') name += '_maxky{0:0.3f}'.format(np.max(np.abs(ky))).replace('.', 'p') print('checking for file: ' + name + '.pkl') if glob.glob(name + '.pkl'): saved = True with open(name + '.pkl', "rb") as fn: res = pkl.load(fn) omegas = res['omegas'] kx = res['kx'] ky = res['ky'] else: # dispersion is not saved, compute it! saved = False # Use PVx and PVy to multiply exp(i*np.dot(k, PV[0,:])) to periodic vectors in x, similar in y # First convert PVx and PVy to matrices that are the same shape as hlat.matrix # np.exp() omegas = np.zeros((len(kx), len(ky), len(hlat.lattice.xy))) matk = lambda k: dynamical_matrix_kspace(k, hlat, eps=1e-8) timer = Timer() ii = 0 for kxi in kx: print 'infinite_dispersion(): ii = ', ii jj = 0 for kyj in ky: # print 'jj = ', jj timer.restart() matrix = matk([kxi, kyj]) test = timer.get_time_ms() print 'test = ', test print('constructed matrix in: ' + timer.get_time_ms()) print 'diagonalizing...' eigval, eigvect = np.linalg.eig(matrix) timer.restart() print('diagonalized matrix in: ' + timer.get_time_ms()) si = np.argsort(np.real(eigval)) omegas[ii, jj, :] = eigval[si] # print 'omegas = ', omegas jj += 1 ii += 1 if save: fig, ax = leplt.initialize_1panel_centered_fig() for jj in range(len(ky)): for kk in range(len(omegas[0, jj, :])): ax.plot(kx, omegas[:, jj, kk], 'k-', lw=max(0.03, 5. / (len(kx) * len(ky)))) ax.set_title(title) ax.set_xlabel(r'$k$ $[1/\langle \ell \rangle]$') ax.set_ylabel(r'$\omega$') plt.savefig(name + '.png') plt.close('all') # Plot in 3D # fig = plt.gcf() # ax = fig.add_subplot(projection='3d') # 111, # # rows will be kx, cols wll be ky # kyv = np.array([[ky[i].tolist()] * len(kx) for i in range(len(ky))]).ravel() # kxv = np.array([[kx.tolist()] * len(ky)]).ravel() # print 'kyv = ', np.shape(kyv) # print 'kxv = ', np.shape(kxv) # for kk in range(len(omegas[0, 0, :])): # ax.plot_trisurf(kxv, kyv, omegas[:, :, kk].ravel()) # # ax.view_init(elev=0, azim=0.) # ax.set_title(title) # ax.set_xlabel(r'$k_x$ $[1/\langle l \rangle]$') # ax.set_ylabel(r'$k_y$ $[1/\langle l \rangle]$') # plt.savefig(name + '_3d.png') if not saved: res = {'omegas': omegas, 'kx': kx, 'ky': ky} with open(name + '.pkl', "wb") as fn: pkl.dump(res, fn) return omegas, kx, ky
def movie_varyDeltaAB(t1, t2, dab_arr, nx, ny, maindir, outdir, fontsize=20, tick_fontsize=16, saveims=True, dual_panel=False, color_berry=False, cmap='coolwarm', vmin=0.49, vmax=0.51, plot3d=False): """Create a movie of band structure with varying DeltaAB Parameters ---------- t1 : float magnitude of real NN hopping t2 : float magnitude of complex NNN hopping dab_arr : n x 1 float array the DeltaAB values to use for each frame nn : int number of kx values (same as # ky values) maindir : str where to save the movie outdir : str where to save the images saveims : bool overwrite the existing images dual_panel : bool plot the 2d dispersion with calibration of gap opening as function of DeltaAB vmin : float the minimimum color value from 0 to 1, if color_berry=True vmax : float the maximum color value from 0 to 1, if color_berry = True plot3d : bool whether to plot the dispersion in 3d or not """ if isinstance(cmap, str): cmap = lecmaps.ensure_cmap(cmap) kk = 0 gaps = [] dabs = [] for mm in dab_arr: if color_berry: km, kv, energy1, energy2, berry1, berry2 = haldane_dispersion_berry( nx, ny, t1, t2, mm) else: km, kv, energy1, energy2 = haldane_dispersion(nx, ny, t1, t2, mm) gap = np.min(energy1) * 2. print 'gap = ', gap gaps.append(gap) dabs.append(mm) if saveims: if not plot3d: if dual_panel: fig, ax = leplt.initialize_2panel_3o4ar_cent( fontsize=fontsize, x0frac=0.085) ax, ax2 = ax[0], ax[1] # Make second figure ax2.plot() ax2.set_xlim(0, 0.2) ax2.set_ylim(0, 0.7) ax2.plot([np.min(t2arr), np.max(t2arr)], [0.0, 2 * np.max(t2arr)], '-', color='#a1bfdb', lw=3) ax2.scatter(dabs, gaps, color='k', zorder=9999999999) title = 'Gap size: ' + r'$\Delta\omega/t_1 \approx 2 \, \Delta_{AB}$' ax2.text(0.5, 1.1, title, ha='center', va='center', fontsize=fontsize, transform=ax2.transAxes) for tick in ax2.xaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) for tick in ax2.yaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) ax2.set_xlabel(r'$t_2 = \Omega_k^2/8\Omega_g$', fontsize=fontsize, labelpad=15) ax2.set_ylabel( r'$\Delta\omega/t_1 = 2 \Delta\omega/\Omega_k$', fontsize=fontsize, rotation=90, labelpad=35) else: fig, ax = leplt.initialize_1panel_centered_fig( Wfig=180, Hfig=180, wsfrac=0.7, fontsize=fontsize) if not color_berry: # check if topological or not print 't2 = ', t2 print 'mm = ', mm * (3. * np.sqrt(3.)) if t2 > mm / np.sqrt(3.): # yes, topological ax.plot(km[1], energy1.reshape(np.shape(km[0])), '-', color=band1color) ax.plot(km[1], energy2.reshape(np.shape(km[0])), '-', color=band2color) elif t2 < -mm / np.sqrt(3.): # flipped topology ax.plot(km[1], energy1.reshape(np.shape(km[0])), '-', color=band2color) ax.plot(km[1], energy2.reshape(np.shape(km[0])), '-', color=band1color) else: # not topological ax.plot(km[1], energy1.reshape(np.shape(km[0])), '-', color=graycolor) ax.plot(km[1], energy2.reshape(np.shape(km[0])), '-', color=graycolor) else: b1color = berry1.reshape(np.shape( km[0])) / (2. * np.pi) + 0.5 b2color = berry2.reshape(np.shape( km[0])) / (2. * np.pi) + 0.5 energy1 = energy1.reshape(np.shape(km[0])) energy2 = energy2.reshape(np.shape(km[0])) # ax.scatter([0., 0.5, 1.0], [0., 0.5, 1.0], c=[0., 0.5, 1.0], edgecolor='none', cmap=cmap, alpha=1) for ii in range(len(km[0])): ax.scatter(km[1][ii], energy1[ii], c=b1color[ii], edgecolor='none', cmap=cmap, alpha=0.1, vmin=vmin, vmax=vmax) ax.scatter(km[1][ii], energy2[ii], c=b2color[ii], edgecolor='none', cmap=cmap, alpha=0.1, vmin=vmin, vmax=vmax) plt.show() sys.exit() ax.set_ylabel(r'$\omega$', labelpad=15, fontsize=fontsize, rotation=0) # title = r'$\Delta \omega =$' + '{0:0.3f}'.format(gap) + r' $t_1$' title = r'$t_2 =$' + '{0:0.3f}'.format(t2) + r' $t_1$, ' + \ r'$\Delta_{AB} =$' + '{0:0.3f}'.format(mm) + r' $t_1$' ax.text(0.5, 1.1, title, ha='center', va='center', fontsize=fontsize, transform=ax.transAxes) else: # Plot it in 3d fig, ax = leplt.initialize_1panel_centered_fig( Wfig=180, Hfig=180, wsfrac=0.7, fontsize=fontsize) ax = fig.gca(projection='3d') # Reshape colors, energies b1color = cmap((berry1.reshape(np.shape(km[0])) / (2. * np.pi)) / (vmax - vmin) + 0.5) b2color = cmap((berry2.reshape(np.shape(km[0])) / (2. * np.pi)) / (vmax - vmin) + 0.5) energy1 = energy1.reshape(np.shape(km[0])) energy2 = energy2.reshape(np.shape(km[0])) print 'b1color = ', b1color # Plot surfaces surf = ax.plot_surface(km[0], km[1], energy1, facecolors=b1color, rstride=1, cstride=1, vmin=vmin, vmax=vmax, cmap=cmap, linewidth=1, antialiased=False) surf = ax.plot_surface(km[0], km[1], energy2, facecolors=b2color, rstride=1, cstride=1, vmin=vmin, vmax=vmax, cmap=cmap, linewidth=1, antialiased=False) ax.set_ylabel(r'$k_y$', labelpad=15, fontsize=fontsize) ax.yaxis.set_ticks([-np.pi, 0, np.pi]) ax.yaxis.set_ticklabels([r'-$\pi$', 0, r'$\pi$'], fontsize=tick_fontsize) for tick in ax.xaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) ax.set_zlabel(r'$\omega$', labelpad=15, fontsize=fontsize, rotation=90) # ax.zaxis.set_ticks([-np.pi, 0, np.pi]) # ax.zaxis.set_ticklabels([r'-$\pi$', 0, r'$\pi$'], fontsize=tick_fontsize) for tick in ax.zaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) ax.axis('scaled') ax.set_zlim(-np.pi, np.pi) ax.set_xlabel(r'$k_x$', labelpad=15, fontsize=fontsize) ax.xaxis.set_ticks([-np.pi, 0, np.pi]) ax.xaxis.set_ticklabels([r'-$\pi$', 0, r'$\pi$'], fontsize=tick_fontsize) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) ax.axis('scaled') ax.set_xlim(-np.pi, np.pi) ax.set_ylim(-np.pi, np.pi) # Save it plt.savefig(outdir + 'dispersion_{0:04d}'.format(kk) + '.png'.format(t2), dpi=140) plt.close('all') kk += 1 print 'dirac = ', 2. * np.pi / 3., ', ', -2. * np.pi / ( 3. * np.sqrt(3.)) ind = np.argmin(energy1) dirac = kv[ind] print 'dirac where = ', dirac # print the fitting print 'dabs = ', dabs print 'gaps = ', gaps zz = np.polyfit(np.array(dabs), np.array(gaps), 1) pp = np.poly1d(zz) print 'pp = ', pp print 'zz[0] = ', zz[0] print 'zz[1] = ', zz[1] imgname = outdir + 'dispersion_' movname = maindir + 'dispersion_varyDeltaAB_{0:0.3f}'.format(t2).replace( '.', 'p') movname += '_nkx{0:06d}'.format(nx) + '_nky{0:06d}'.format(ny) lemov.make_movie(imgname, movname, indexsz='04', framerate=15)
def movie_varyt2(t1, t2arr, mm, nx, ny, maindir, outdir, fontsize=20, tick_fontsize=16, saveims=True, dual_panel=False, color_berry=False, cmap='bbr0', vmin=0.499, vmax=0.501, plot3d=False): """Plot the band structure of the haldane model as we vary the NNN hopping Parameters ---------- t1 : float magnitude of real NN hopping t2 : float magnitude of complex NNN hopping dab_arr : n x 1 float array the DeltaAB values to use for each frame nn : int number of kx values (same as # ky values) maindir : str where to save the movie outdir : str where to save the images saveims : bool overwrite the existing images dual_panel : bool plot the 2d dispersion with calibration of gap opening as function of DeltaAB vmin : float the minimimum color value from 0 to 1, if color_berry=True vmax : float the maximum color value from 0 to 1, if color_berry = True plot3d : bool whether to plot the dispersion in 3d or not """ kk = 0 gaps = [] t2s = [] if isinstance(cmap, str): cmap = lecmaps.ensure_cmap(cmap) for t2 in t2arr: if color_berry: km, kv, energy1, energy2, berry1, berry2 = haldane_dispersion_berry( nx, t1, t2, mm) else: km, kv, energy1, energy2 = haldane_dispersion(nx, ny, t1, t2, mm) gap = np.min(energy1) * 2. print 'gap = ', gap gaps.append(gap) t2s.append(t2) if saveims: if dual_panel: fig, ax = leplt.initialize_2panel_3o4ar_cent(fontsize=fontsize, x0frac=0.085) ax, ax2 = ax[0], ax[1] else: fig, ax = leplt.initialize_1panel_centered_fig( Wfig=180, Hfig=180, wsfrac=0.7, fontsize=fontsize) if not color_berry: if t2 > mm / np.sqrt(3.): ax.plot(km[1], energy1.reshape(np.shape(km[0])), '-', color=band1color) ax.plot(km[1], energy2.reshape(np.shape(km[0])), '-', color=band2color) elif t2 < -mm / np.sqrt(3.): ax.plot(km[1], energy1.reshape(np.shape(km[0])), '-', color=band2color) ax.plot(km[1], energy2.reshape(np.shape(km[0])), '-', color=band1color) else: ax.plot(km[1], energy1.reshape(np.shape(km[0])), '-', color=graycolor) ax.plot(km[1], energy2.reshape(np.shape(km[0])), '-', color=graycolor) else: b1color = berry1.reshape(np.shape(km[0])) / (2. * np.pi) + 0.5 b2color = berry2.reshape(np.shape(km[0])) / (2. * np.pi) + 0.5 print 'b1color=', b1color # sys.exit() energy1 = energy1.reshape(np.shape(km[0])) energy2 = energy2.reshape(np.shape(km[0])) # ax.scatter([0., 0.5, 1.0], [0., 0.5, 1.0], c=[0., 0.5, 1.0], edgecolor='none', cmap=cmap, alpha=1) for ii in range(len(km[0])): ax.scatter(km[1][ii], energy1[ii], c=b1color, edgecolor='none', cmap=cmap, alpha=1., vmin=vmin, vmax=vmax) ax.scatter(km[1][ii], energy2[ii], c=b2color, edgecolor='none', cmap=cmap, alpha=1., vmin=vmin, vmax=vmax) # plt.show() # sys.exit() ax.set_xlabel(r'$k_x$', labelpad=15, fontsize=fontsize) ax.set_ylabel(r'$\omega$', labelpad=15, fontsize=fontsize, rotation=0) ax.xaxis.set_ticks([-np.pi, 0, np.pi]) ax.xaxis.set_ticklabels([r'-$\pi$', 0, r'$\pi$'], fontsize=tick_fontsize) for tick in ax.yaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) ax.axis('scaled') ax.set_xlim(-np.pi, np.pi) ax.set_ylim(-np.pi, np.pi) # title = r'$\Delta \omega =$' + '{0:0.3f}'.format(gap) + r' $t_1$' title = r'$t_2 =$' + '{0:0.3f}'.format(t2) + r' $t_1$, ' + \ r'$\Delta_{AB} =$' + '{0:0.3f}'.format(mm) + r' $t_1$' ax.text(0.5, 1.1, title, ha='center', va='center', fontsize=fontsize, transform=ax.transAxes) if dual_panel: # Make second figure ax2.plot() ax2.set_xlim(0, 0.2) ax2.set_ylim(0, 0.7) ax2.plot([np.min(t2arr), np.max(t2arr)], [0.0, 3.36864398885 * np.max(t2arr)], '-', color='#a1bfdb', lw=3) ax2.scatter(t2s, gaps, color='k', zorder=9999999999) title = 'Gap size: ' + r'$\Delta\omega/t_1 \approx 3.369\, t_2$' ax2.text(0.5, 1.1, title, ha='center', va='center', fontsize=fontsize, transform=ax2.transAxes) for tick in ax2.xaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) for tick in ax2.yaxis.get_major_ticks(): tick.label.set_fontsize(tick_fontsize) ax2.set_xlabel(r'$t_2 = \Omega_k^2/8\Omega_g$', fontsize=fontsize, labelpad=15) ax2.set_ylabel(r'$\Delta\omega/t_1 = 2 \Delta\omega/\Omega_k$', fontsize=fontsize, rotation=90, labelpad=35) # Save the image plt.savefig(outdir + 'dispersion_{0:04d}'.format(kk) + '.png', dpi=140) plt.close('all') kk += 1 print 'dirac = ', 2. * np.pi / 3., ', ', -2. * np.pi / ( 3. * np.sqrt(3.)) ind = np.argmin(energy1) dirac = kv[ind] print 'dirac where = ', dirac print 't2s = ', t2s print 'gaps = ', gaps zz = np.polyfit(np.array(t2s), np.array(gaps), 1) pp = np.poly1d(zz) print pp print zz[0] print zz[1] imgname = outdir + 'dispersion_' movname = maindir + 'dispersion_varyt2' movname += '_nkx{0:06d}'.format(nx) + '_nky{0:06d}'.format(ny) lemov.make_movie(imgname, movname, indexsz='04', framerate=15)