예제 #1
0
def dispersion_abtransition_gapbounds(lp, abvals=None):
    """

    Parameters
    ----------
    lp

    Returns
    -------

    """
    # prepare the values of inversion symmetry breaking
    if abvals is None:
        # abvals = np.arange(0, 2.4, 0.1)
        abvals = np.arange(0, 1.0, 0.025)

    meshfn = le.find_meshfn(lp)
    lat = lattice_class.Lattice(lp)
    lat.load(check=lp['check'])
    lp['ABDelta'] = np.max(abvals)
    mglat = MagneticGyroLattice(lat, lp)
    outname = dio.prepdir(meshfn) + 'dispersion_abtrans' + mglat.lp[
        'meshfn_exten'] + '_gapbounds'
    gapbounds_glob = glob.glob(outname + '.txt')
    if gapbounds_glob:
        # Load the text file and save the image
        gapbounds = np.loadtxt(outname + '.txt')
        plot_gapbounds(gapbounds[:, 0], gapbounds[:, 1:], outname + '.png', lp)
    else:
        # Compute the dispersions and save the image (occurs inside dispersion_abtransition
        omegas, kx, ky = dispersion_abtransition(lp,
                                                 save_plots=False,
                                                 return_omegas=True)
예제 #2
0
def dice_glat(lp, args):
    """make the OmK arrays to load when computing cherns for diced networks
        Example usage:
        python run_series.py -pro gyro_lattice_class -opts LT/hexagonal/-N/11/-shape/square/-dice_glat/-gridspacing/3.0 -var weakbond_val n1.0:0.1:0.05

    Parameters
    ----------
    lp
    args

    Returns
    -------

    """
    import lepm.line_segments as lsegs
    # Create a glat with bonds that are weakened in a gridlike fashion (bonds crossing gridlines are weak)
    meshfn = le.find_meshfn(lp)
    lp['meshfn'] = meshfn
    lat = lattice_class.Lattice(lp)
    lat.load()

    # Find where bonds cross gridlines
    gridspacing = args.gridspacing
    lp['OmKspec'] = 'gridlines{0:0.2f}'.format(gridspacing).replace('.', 'p') + \
                    'strong{0:0.3f}'.format(lp['Omk']).replace('.', 'p').replace('-', 'n') + \
                    'weak{0:0.3f}'.format(args.weakbond_val).replace('.', 'p').replace('-', 'n')
    maxval = max(np.max(np.abs(lat.xy[:, 0])), np.max(np.abs(lat.xy[:, 1]))) + 1
    gridright = np.arange(gridspacing, maxval, gridspacing)
    gridleft = -gridright
    gridvals = np.hstack((gridleft, 0, gridright))
    # Draw grid
    gridlinesH = np.array([[-maxval, gridv, maxval, gridv] for gridv in gridvals])
    gridlinesV = np.array([[gridv, -maxval, gridv, maxval] for gridv in gridvals])
    gridsegs = np.vstack((gridlinesH, gridlinesV))
    print 'np.shape(gridlines) = ', np.shape(gridsegs)
    # Make the bond linesegments
    xy = lat.xy
    bondsegs = np.array([[xy[b[0], 0], xy[b[0], 1], xy[b[1], 0], xy[b[1], 1]] for b in lat.BL])
    # get crossings
    print 'gridsegs = ', gridsegs
    does_intersect = lsegs.linesegs_intersect_linesegs(bondsegs, gridsegs)
    tmp_glat = GyroLattice(lat, lp)
    OmK = copy.deepcopy(tmp_glat.OmK)
    print 'Altering weak bonds --> ', args.weakbond_val
    for bond in lat.BL[does_intersect]:
        OmK[bond[0], np.where(lat.NL[bond[0]] == bond[1])] = args.weakbond_val
    glat = GyroLattice(lat, lp, OmK=OmK)
    glat.plot_OmK()
    if args.dice_eigval:
        glat.save_eigval_eigvect()
        glat.save_DOSmovie()
예제 #3
0
def localization(lp, args):
    """Load a periodic lattice from file, provide physics, and seek exponential localization of modes

    Example usage:
    python run_series.py -pro gyro_lattice_class -opts LT/hucentroid/-periodic/-NP/20/-localization/-save_eig -var AB 0.0:0.05:1.0
    python run_series.py -pro gyro_lattice_class -opts LT/hyperuniform/-periodic/-NP/50/-localization/-save_eig -var Vpin 0.1/0.5/1.0/2.0/4.0/6.0
    python run_series.py -pro gyro_lattice_class -opts LT/hyperuniform/-periodic/-NP/50/-DOSmovie/-save_eig -var Vpin 0.1/0.5/1.0/2.0/4.0/6.0

    """
    meshfn = le.find_meshfn(lp)
    lp['meshfn'] = meshfn
    lat = lattice_class.Lattice(lp)
    lat.load()
    extent = 2 * max(np.max(lat.xy[:, 0]), np.max(lat.xy[:, 1]))
    glat = GyroLattice(lat, lp)
    glat.save_localization(attribute=True, save_images=args.save_images, save_eigvect_eigval=args.save_eig)
    glat.plot_ill_dos(vmax=4. / extent, xlim=(0., 14.), ticks=[0, 2. / extent, 4. / extent],
                      cbar_ticklabels=[0, r'$2/L$', r'$4/L$'], cbar_labelpad=15)
 python ./bott/bott_magnetic_gyro_collection_collection.py -ABphase -LT hexagonal -shape square -paramV 0.:0.1:0.9 -N 15 -shortrange -aol 0.6 -Vpin 0.01 -save_as_txt
 python ./bott/bott_magnetic_gyro_collection_collection.py -ABphase -LT hexagonal -shape square -paramV 0.:0.1:0.9 -N 11 -shortrange -aol 0.6 -Vpin 0.01 -save_as_txt
 python ./bott/bott_magnetic_gyro_collection_collection.py -ABphase -LT hexagonal -shape square -paramV 0.:0.1:0.9 -N 15 -shortrange -aol 0.8 -Vpin 0.01 -save_as_txt
 """
 # Collate botts for one lattice with a mgyro_lattice parameter that varies between instances of that lattice
 lp_master = copy.deepcopy(lp)
 paramV = sf.string_sequence_to_numpy_array(args.paramV, dtype=float)
 if args.lpparam == 'delta':
     # vary delta between lattices
     deltaV = np.arange(0.7, 1.31, 0.1)
     deltaV = np.hstack((0.667, deltaV))
     bmgcollcoll = BottMagneticGyroCollectionCollection()
     for delta in deltaV:
         lp = copy.deepcopy(lp_master)
         lp['delta_lattice'] = '{0:0.3f}'.format(delta)
         meshfn = le.find_meshfn(lp)
         lp['meshfn'] = meshfn
         print '\n\n\nlp[meshfn] = ', lp['meshfn']
         lat = lattice_class.Lattice(lp)
         lat.load()
         mgc = magnetic_gyro_collection.MagneticGyroCollection()
         lp_submaster = copy.deepcopy(lp)
         # Need only to add one single mgryo_lattice
         # for glatpval in paramV:
         #     lpii = copy.deepcopy(lp_submaster)
         #     lpii[args.glatparam] = glatpval
         #     mglat = magnetic_gyro_lattice_class.MagneticGyroLattice(lat, lpii)
         #     mglat.load()
         #     mgc.add_mgyro_lattice(mglat)
         lpii = copy.deepcopy(lp_submaster)
         lpii[args.glatparam] = paramV[0]
예제 #5
0
        'Ndefects': args.Ndefects,
        'Bvec': args.Bvec,
        'dislocxy': (args.dislocation_xy.split('/')),
        'cutz_method': args.cutz_method,
        'origin': np.array([0., 0.]),
        'source': 'hexner',
    }
    if doNP:
        print 'check'
        lp['NP_load'] = N
    else:
        lp['NP_load'] = 0

    meshfn = le.find_meshfn(args.LatticeTop,
                            shape,
                            sourcedir,
                            NH,
                            NV,
                            lattice_params=lp)
    print 'found meshfn = ', meshfn

    if glob.glob(meshfn + '/harmonic_diffusivity_sigmax.pkl'):
        with open(meshfn + '/harmonic_diffusivity_sigma.pkl',
                  "rb") as input_file:
            SS = pickle.load(input_file)
        with open(meshfn + '/harmonic_diffusivity_sigmax.pkl',
                  "rb") as input_file:
            SSx = pickle.load(input_file)
        with open(meshfn + '/harmonic_diffusivity_sigmay.pkl',
                  "rb") as input_file:
            SSy = pickle.load(input_file)
        with open(meshfn + '/eigval_mass.pkl', "rb") as input_file:
예제 #6
0
def dispersion_abtransition(lp,
                            save_plots=True,
                            return_omegas=False,
                            abvals=None,
                            fullspectrum=False):
    """

    Parameters
    ----------
    lp : dictionary
        lattice parameter dictionary
    return_omegas : bool
        Return a list of the frequencies in the dispersion
    abvals : n x 1 float array or list
        The Delta_AB values for each spectrum

    Returns
    -------

    """
    # prepare the values of inversion symmetry breaking
    if abvals is None:
        # abvals = np.arange(0, 2.4, 0.1)
        abvals = np.arange(0, 1.0, 0.025)

    # Prepare magnetic gyro lattice
    meshfn = le.find_meshfn(lp)
    lp['meshfn'] = meshfn
    lpmaster = copy.deepcopy(lp)
    # create a place to put images
    outdir = dio.prepdir(
        meshfn) + 'dispersion_abtransition_aol' + sf.float2pstr(
            lp['aoverl']) + '/'
    dio.ensure_dir(outdir)
    fs = 20

    if return_omegas:
        omegas_out = []
        kx_out = []
        ky_out = []

    # go through each ab and make the image
    ii = 0
    for ab in abvals:
        lp = copy.deepcopy(lpmaster)
        lp['ABDelta'] = ab
        lat = lattice_class.Lattice(lp)
        lat.load(check=lp['check'])
        glat = MagneticGyroLattice(lat, lp)
        # glat.get_eigval_eigvect(attribute=True)
        fig, ax = leplt.initialize_portrait(ax_pos=[0.12, 0.2, 0.76, 0.6])
        omegas, kx, ky = glat.infinite_dispersion(save=False,
                                                  nkxvals=50,
                                                  nkyvals=50,
                                                  outdir=outdir,
                                                  save_plot=False)
        if return_omegas:
            omegas_out.append(omegas)
            kx_out.append(kx)
            ky_out.append(ky)

        if save_plots:
            # plot and save it
            title = r'$\Delta_{AB} =$' + '{0:0.2f}'.format(ab)
            for jj in range(len(ky)):
                for kk in range(len(omegas[0, jj, :])):
                    ax.plot(kx,
                            omegas[:, jj, kk],
                            'k-',
                            lw=max(0.5, 30. / (len(kx) * len(ky))))

            ax.set_title(title, fontsize=fs)
            ax.set_xlabel(r'$k$ $[\langle \ell \rangle ^{-1}]$', fontsize=fs)
            ax.set_ylabel(r'$\omega$', fontsize=fs)
            for tick in ax.xaxis.get_major_ticks():
                tick.label.set_fontsize(fs)
            for tick in ax.yaxis.get_major_ticks():
                tick.label.set_fontsize(fs)
            if ii == 0:
                ylims = ax.get_ylim()

            if fullspectrum:
                ax.set_ylim(-ylims[1] * 1.2, ylims[1] * 1.2)
            else:
                ax.set_ylim(0., ylims[1] * 1.2)

            # Save it
            name = outdir + 'dispersion{0:04d}'.format(ii)
            plt.savefig(name + '.png', dpi=300)
            plt.close('all')

        ii += 1

    # Save a movie of the dispersions
    movname = dio.prepdir(
        meshfn) + 'dispersion_abtrans' + glat.lp['meshfn_exten']
    if save_plots:
        # Turn images into a movie
        imgname = outdir + 'dispersion'
        lemov.make_movie(imgname,
                         movname,
                         indexsz='04',
                         framerate=4,
                         imgdir=outdir,
                         rm_images=True,
                         save_into_subdir=True)

    if return_omegas:
        # Save the gap bounds and return the arrays of kx, ky, and omega
        omegas, kx, ky = np.array(omegas_out), np.array(kx_out), np.array(
            ky_out)
        # Get gap bounds:
        botmin = []
        botmax = []
        topmin = []
        topmax = []
        for band in omegas:
            botmin.append(np.min(band[:, :, 2]))
            botmax.append(np.max(band[:, :, 2]))
            topmin.append(np.min(band[:, :, 3]))
            topmax.append(np.max(band[:, :, 3]))

        botmin = np.array(botmin)
        botmax = np.array(botmax)
        topmin = np.array(topmin)
        topmax = np.array(topmax)
        gapbounds = np.dstack((abvals, botmin, botmax, topmin, topmax))[0]
        outfn = movname + '_gapbounds.txt'
        print 'saving to ', outfn
        header = 'Delta_AB, band min frequency, band max frequency, band 2 min, band 2 max...'
        np.savetxt(outfn, gapbounds, header=header)
        plot_gapbounds(abvals, gapbounds, movname + '_gapbounds.png', lp)
        return omegas, kx, ky
    else:
        return None
예제 #7
0
def twistbcs(lp):
    """Load a periodic lattice from file, twist the BCs by phases theta_twist and phi_twist with vals finely spaced
    between 0 and 2pi. Then compute the berry curvature associated with |alpha(theta, phi)>

    Example usage:
    python haldane_lattice_class.py -twistbcs -N 3 -LT hexagonal -shape square -periodic

    Parameters
    ----------
    lp

    Returns
    -------

    """
    lp['periodicBC'] = True
    meshfn = le.find_meshfn(lp)
    lp['meshfn'] = meshfn
    lat = lattice_class.Lattice(lp)
    lat.load()
    # Make a big array of the eigvals: N x N x thetav x phiv
    # thetav = np.arange(0., 2. * np.pi, 0.5)
    # phiv = np.arange(0., 2. * np.pi, 0.5)

    # First just test for two values of theta and two of phi
    thetav = [0., 0.01]
    phiv = [0., 0.01]
    eigvects = {}
    ii = 0
    for theta in thetav:
        eigvects[ii] = {}
        jj = 0
        for phi in phiv:
            lpnew = copy.deepcopy(lp)
            lpnew['theta_twist'] = theta
            lpnew['phi_twist'] = phi
            hlat = HaldaneLattice(lat, lpnew)
            ev, evec = hlat.get_eigval_eigvect(attribute=True)
            if ii == 0 and jj == 0:
                eigval = copy.deepcopy(ev)
                ill = hlat.get_ill()
            eigvects[ii][jj] = evec
            jj += 1
        ii += 1

    # Dot the derivs of eigvects together
    # Ensure that there is a nonzero-amplitude wannier with matching phase
    dtheta = eigvects[1][0] - eigvects[0][0]
    dphi = eigvects[0][1] - eigvects[0][0]

    thetamov_fn = dio.prepdir(
        hlat.lp['meshfn']
    ) + 'twistbc_theta' + hlat.lp['meshfn_exten'] + '_dos_ev.mov'
    if not glob.glob(thetamov_fn):
        # Plot differences
        fig, DOS_ax, eig_ax = leplt.initialize_eigvect_DOS_header_plot(
            ev,
            hlat.lattice.xy,
            sim_type='haldane',
            colorV=ill,
            colormap='viridis',
            linewidth=0,
            cax_label=r'$\xi^{-1}$',
            cbar_nticks=2,
            xlabel_pad=10,
            ylabel_pad=10,
            cbar_tickfmt='%0.3f')
        DOS_ax.set_title(r'$\partial_\phi \psi$')
        hlat.lattice.plot_BW_lat(fig=fig,
                                 ax=eig_ax,
                                 save=False,
                                 close=False,
                                 axis_off=False,
                                 title='')
        outdir = dio.prepdir(
            hlat.lp['meshfn']
        ) + 'twistbc_theta' + hlat.lp['meshfn_exten'] + '/'
        dio.ensure_dir(outdir)
        for ii in range(len(ev)):
            fig, [scat_fg, scat_fg2, p, f_mark, lines_12_st], cw_ccw = \
                hlatpfns.construct_haldane_eigvect_DOS_plot(hlat.lattice.xy, fig, DOS_ax, eig_ax, eigval,
                                                            dtheta, ii, hlat.lattice.NL, hlat.lattice.KL,
                                                            marker_num=0, color_scheme='default', normalization=1.)
            print 'saving theta ', ii
            plt.savefig(outdir + 'dos_ev' + '{0:05}'.format(ii) + '.png')
            scat_fg.remove()
            scat_fg2.remove()
            p.remove()
            f_mark.remove()
            lines_12_st.remove()

        plt.close('all')

        imgname = outdir + 'dos_ev'
        movname = dio.prepdir(
            hlat.lp['meshfn']
        ) + 'twistbc_theta' + hlat.lp['meshfn_exten'] + '_dos_ev'
        lemov.make_movie(imgname, movname, rm_images=False)

    phimov_fn = dio.prepdir(
        hlat.lp['meshfn']
    ) + 'twistbc_phi' + hlat.lp['meshfn_exten'] + '_dos_ev.mov'
    if not glob.glob(phimov_fn):
        fig, DOS_ax, eig_ax = leplt.initialize_eigvect_DOS_header_plot(
            ev,
            hlat.lattice.xy,
            sim_type='haldane',
            colorV=ill,
            colormap='viridis',
            linewidth=0,
            cax_label=r'$\xi^{-1}$',
            cbar_nticks=2,
            xlabel_pad=10,
            ylabel_pad=10,
            cbar_tickfmt='%0.3f')
        DOS_ax.set_title(r'$\partial_\phi \psi$')
        outdir = dio.prepdir(
            hlat.lp['meshfn']) + 'twistbc_phi' + hlat.lp['meshfn_exten'] + '/'
        dio.ensure_dir(outdir)
        for ii in range(len(ev)):
            fig, [scat_fg, scat_fg2, p, f_mark, lines_12_st], cw_ccw = \
                hlatpfns.construct_haldane_eigvect_DOS_plot(hlat.lattice.xy, fig, DOS_ax, eig_ax, eigval,
                                                            dphi, ii, hlat.lattice.NL, hlat.lattice.KL,
                                                            marker_num=0, color_scheme='default', normalization=1.)
            print 'saving phi ', ii
            plt.savefig(outdir + 'dos_ev' + '{0:05}'.format(ii) + '.png')
            scat_fg.remove()
            scat_fg2.remove()
            p.remove()
            f_mark.remove()
            lines_12_st.remove()

        plt.close('all')

        imgname = outdir + 'dos_ev'
        movname = dio.prepdir(
            hlat.lp['meshfn']
        ) + 'twistbc_phi' + hlat.lp['meshfn_exten'] + '_dos_ev'
        lemov.make_movie(imgname, movname, rm_images=False)

    # Check
    # print 'shape(dtheta) = ', np.shape(dtheta)
    # print 'shape(dphi) = ', np.shape(dphi)
    # le.plot_complex_matrix(dtheta, show=True, name='dtheta')
    # le.plot_complex_matrix(dphi, show=True, name='dphi')

    fig, ax = leplt.initialize_nxmpanel_fig(4, 1, wsfrac=0.6, x0frac=0.3)
    # < dphi | dtheta >
    dpdt = np.einsum('ij...,ij...->i...', dtheta, dphi.conj())
    # < dtheta | dphi >
    dtdp = np.einsum('ij...,ij...->i...', dphi, dtheta.conj())
    print 'dtdp = ', dtdp
    ax[0].plot(np.arange(len(dtdp)), dtdp, '-')
    ax[1].plot(np.arange(len(dpdt)), dpdt, '-')
    hc = 2. * np.pi * 1j * (dpdt - dtdp)
    ax[2].plot(np.arange(len(lat.xy)), hc, '.-')
    # Plot cumulative sum
    sumhc = np.cumsum(hc)
    ax[3].plot(np.arange(len(lat.xy)), sumhc, '.-')

    ax[2].set_xlabel(r'Eigvect number')
    ax[0].set_ylabel(
        r'$\langle \partial_{\theta} \alpha_i | \partial_{\phi} \alpha_i \rangle$'
    )
    ax[2].set_xlabel(r'Eigvect number')
    ax[1].set_ylabel(
        r'$\langle \partial_{\phi} \alpha_i | \partial_{\theta} \alpha_i \rangle$'
    )
    ax[2].set_xlabel(r'Eigvect number')
    ax[2].set_ylabel(r'$c_H$')
    ax[3].set_xlabel(r'Eigvect number')
    ax[3].set_ylabel(r'$\sum_{E_\alpha < E_c} c_H$')
    outdir = '/Users/npmitchell/Dropbox/Soft_Matter/GPU/twistbc_test/'
    dio.ensure_dir(outdir)
    print 'saving ', outdir + 'test' + hlat.lp['meshfn_exten'] + '.png'
    plt.savefig(outdir + 'test' + hlat.lp['meshfn_exten'] + '.png')

    # ### Now do the same thing but with different values of theta, phi
    # First just test for two values of theta and two of phi
    thetav = [1., 1.01]
    phiv = [1., 1.01]
    eigvects = {}
    ii = 0
    for theta in thetav:
        eigvects[ii] = {}
        jj = 0
        for phi in phiv:
            lpnew = copy.deepcopy(lp)
            lpnew['theta_twist'] = theta
            lpnew['phi_twist'] = phi
            hlat = HaldaneLattice(lat, lpnew)
            ev, evec = hlat.get_eigval_eigvect(attribute=True)
            if ii == 0 and jj == 0:
                eigval = copy.deepcopy(ev)
                ill = hlat.get_ill()
            eigvects[ii][jj] = evec
            jj += 1
        ii += 1

    # Dot the derivs of eigvects together
    dtheta = eigvects[1][0] - eigvects[0][0]
    dphi = eigvects[0][1] - eigvects[0][0]

    # Plot differences
    thetamov_fn = dio.prepdir(
        hlat.lp['meshfn']
    ) + 'twistbc_theta' + hlat.lp['meshfn_exten'] + '_dos_ev.mov'
    if not glob.glob(thetamov_fn):
        fig, DOS_ax, eig_ax = leplt.initialize_eigvect_DOS_header_plot(
            ev,
            hlat.lattice.xy,
            sim_type='haldane',
            colorV=ill,
            colormap='viridis',
            linewidth=0,
            cax_label=r'$\xi^{-1}$',
            cbar_nticks=2,
            xlabel_pad=10,
            ylabel_pad=10,
            cbar_tickfmt='%0.3f')
        DOS_ax.set_title(r'$\partial_\theta \psi$')
        hlat.lattice.plot_BW_lat(fig=fig,
                                 ax=eig_ax,
                                 save=False,
                                 close=False,
                                 axis_off=False,
                                 title='')
        outdir = dio.prepdir(
            hlat.lp['meshfn']
        ) + 'twistbc_theta' + hlat.lp['meshfn_exten'] + '/'
        dio.ensure_dir(outdir)
        for ii in range(len(ev)):
            fig, [scat_fg, scat_fg2, p, f_mark, lines_12_st], cw_ccw = \
                hlatpfns.construct_haldane_eigvect_DOS_plot(hlat.lattice.xy, fig, DOS_ax, eig_ax, eigval,
                                                            dtheta, ii, hlat.lattice.NL, hlat.lattice.KL,
                                                            marker_num=0, color_scheme='default', normalization=1.)
            print 'saving theta ', ii
            plt.savefig(outdir + 'dos_ev' + '{0:05}'.format(ii) + '.png')
            scat_fg.remove()
            scat_fg2.remove()
            p.remove()
            f_mark.remove()
            lines_12_st.remove()

        plt.close('all')

        imgname = outdir + 'dos_ev'
        movname = dio.prepdir(
            hlat.lp['meshfn']
        ) + 'twistbc_theta' + hlat.lp['meshfn_exten'] + '_dos_ev'
        lemov.make_movie(imgname, movname, rm_images=False)

    # Now do phi
    phimov_fn = dio.prepdir(
        hlat.lp['meshfn']
    ) + 'twistbc_phi' + hlat.lp['meshfn_exten'] + '_dos_ev.mov'
    if not glob.glob(phimov_fn):
        fig, DOS_ax, eig_ax = leplt.initialize_eigvect_DOS_header_plot(
            ev,
            hlat.lattice.xy,
            sim_type='haldane',
            colorV=ill,
            colormap='viridis',
            linewidth=0,
            cax_label=r'$\xi^{-1}$',
            cbar_nticks=2,
            xlabel_pad=10,
            ylabel_pad=10,
            cbar_tickfmt='%0.3f')
        DOS_ax.set_title(r'$\partial_\phi \psi$')
        hlat.lattice.plot_BW_lat(fig=fig,
                                 ax=eig_ax,
                                 save=False,
                                 close=False,
                                 axis_off=False,
                                 title='')
        outdir = dio.prepdir(
            hlat.lp['meshfn']) + 'twistbc_phi' + hlat.lp['meshfn_exten'] + '/'
        dio.ensure_dir(outdir)
        for ii in range(len(ev)):
            fig, [scat_fg, scat_fg2, p, f_mark, lines_12_st], cw_ccw = \
                hlatpfns.construct_haldane_eigvect_DOS_plot(hlat.lattice.xy, fig, DOS_ax, eig_ax, eigval,
                                                            dphi, ii, hlat.lattice.NL, hlat.lattice.KL,
                                                            marker_num=0, color_scheme='default', normalization=1.)
            print 'saving phi ', ii
            plt.savefig(outdir + 'dos_ev' + '{0:05}'.format(ii) + '.png')
            scat_fg.remove()
            scat_fg2.remove()
            p.remove()
            f_mark.remove()
            lines_12_st.remove()

        plt.close('all')

        imgname = outdir + 'dos_ev'
        movname = dio.prepdir(
            hlat.lp['meshfn']
        ) + 'twistbc_phi' + hlat.lp['meshfn_exten'] + '_dos_ev'
        lemov.make_movie(imgname, movname, rm_images=False)

    # Check
    # print 'shape(dtheta) = ', np.shape(dtheta)
    # print 'shape(dphi) = ', np.shape(dphi)
    # le.plot_complex_matrix(dtheta, show=True, name='dtheta')
    # le.plot_complex_matrix(dphi, show=True, name='dphi')

    fig, ax = leplt.initialize_nxmpanel_fig(4, 1, wsfrac=0.6, x0frac=0.3)
    # < dphi | dtheta >
    dpdt = np.einsum('ij...,ij...->i...', dtheta, dphi.conj())
    # < dtheta | dphi >
    dtdp = np.einsum('ij...,ij...->i...', dphi, dtheta.conj())
    print 'dtdp = ', dtdp
    ax[0].plot(np.arange(len(dtdp)), dtdp, '-')
    ax[1].plot(np.arange(len(dpdt)), dpdt, '-')
    hc = 2. * np.pi * 1j * (dpdt - dtdp)
    ax[2].plot(np.arange(len(lat.xy)), hc, '.-')
    # Plot cumulative sum
    sumhc = np.cumsum(hc)
    ax[3].plot(np.arange(len(lat.xy)), sumhc, '.-')

    ax[2].set_xlabel(r'Eigvect number')
    ax[0].set_ylabel(
        r'$\langle \partial_{\theta} \alpha_i | \partial_{\phi} \alpha_i \rangle$'
    )
    ax[2].set_xlabel(r'Eigvect number')
    ax[1].set_ylabel(
        r'$\langle \partial_{\phi} \alpha_i | \partial_{\theta} \alpha_i \rangle$'
    )
    ax[2].set_xlabel(r'Eigvect number')
    ax[2].set_ylabel(r'$c_H$')
    ax[3].set_xlabel(r'Eigvect number')
    ax[3].set_ylabel(r'$\sum_{E_\alpha < E_c} c_H$')
    outdir = '/Users/npmitchell/Dropbox/Soft_Matter/GPU/twistbc_test/'
    dio.ensure_dir(outdir)
    plt.savefig(outdir + 'test' + hlat.lp['meshfn_exten'] + '_theta1p0.png')

    sys.exit()
    ########################################
    # Now test for more theta values, more phi values
    thetav = np.arange(0., 0.14, 0.1)
    phiv = np.arange(0., 0.14, 0.1)
    eigvects = np.zeros((len(lat.xy), len(lat.xy), len(thetav), len(phiv)),
                        dtype=complex)
    ii = 0
    for theta in thetav:
        jj = 0
        for phi in phiv:
            lpnew = copy.deepcopy(lp)
            lpnew['theta_twist'] = theta
            lpnew['phi_twist'] = phi
            hlat = HaldaneLattice(lat, lpnew)
            ev, evec = hlat.get_eigval_eigvect()
            eigvects[:, :, ii, jj] = evec
            jj += 1
        ii += 1

    # Dot the derivs of eigvects together
    print 'eigvects = ', eigvects
    dtheta = np.diff(eigvects, axis=2)
    dphi = np.diff(eigvects, axis=3)
    print 'dtheta = ', dtheta

    print 'shape(dtheta) = ', np.shape(dtheta)
    print 'shape(dphi) = ', np.shape(dphi)
    le.plot_complex_matrix(dtheta[:, :, 0, 0], show=True)
    le.plot_complex_matrix(dphi[:, :, 0, 0], show=True)

    dtheta = dtheta[:, :, :, 0:np.shape(dtheta)[3] - 1]
    dphi = dphi[:, :, 0:np.shape(dphi)[2] - 1, :]
    print 'shape(dtheta) = ', np.shape(dtheta)
    print 'shape(dphi) = ', np.shape(dphi)

    for ii in range(np.shape(dtheta)[-1]):
        le.plot_complex_matrix(dtheta[:, :, ii, 0], show=True)

    fig, ax = leplt.initialize_nxmpanel_fig(3, 1)
    for ii in range(np.shape(dphi)[-1]):
        for jj in range(np.shape(dphi)[-1]):
            # < dphi | dtheta >
            dpdt = np.dot(dtheta[:, :, ii, jj], dphi[:, :, ii, jj].conj().T)
            # < dtheta | dphi >
            dtdp = np.dot(dphi[:, :, ii, jj], dtheta[:, :, ii, jj].conj().T)
            print 'np.shape(dpdt) = ', np.shape(dpdt)
            print 'np.shape(dtdp) = ', np.shape(dtdp)
            ax[0].plot(np.arange(len(dtdp)), dtdp, '-')
            ax[1].plot(np.arange(len(dpdt)), dpdt, '-')

            hc = 2. * np.pi * 1j * (dpdt - dtdp)
            ax[2].plot(np.arange(len(lat.xy)), hc, '.-')

    ax[0].set_xlabel(r'$\theta$')
    ax[0].set_ylabel(
        r'$\langle \partial_{\theta} \alpha_i | \partial_{\phi} \alpha_i \rangle$'
    )
    ax[1].set_xlabel(r'$\phi$')
    ax[1].set_ylabel(
        r'$\langle \partial_{\phi} \alpha_i | \partial_{\theta} \alpha_i \rangle$'
    )
    ax[2].set_xlabel(r'Eigvect number')
    ax[2].set_ylabel(r'$\partial_{\phi} \alpha_i$')
    plt.show()
예제 #8
0
def dispersion_abtransition(lp, invert_bg=False, color1=None, color2=None, color_thres=None,
                            nkxvals=50, dab_step=0.005, dpi=100, plot_positive_only=True, ab_max=2.6):
    """

    Parameters
    ----------
    lp

    Returns
    -------

    """
    if invert_bg:
        plt.style.use('dark_background')

    if invert_bg:
        if color1 is None:
            # blue
            color1 = '#70a6ff'
        if color2 is None:
            # red
            color2 = '#ff7777'  # '#90354c'
        # print 'color1, 2 = ', color1, color2
        # sys.exit()
    else:
        cmap = lecmaps.diverging_cmap(250, 10, l=30)
        color1 = cmap(0.)
        color2 = cmap(1.)

    meshfn = le.find_meshfn(lp)
    lp['meshfn'] = meshfn
    lpmaster = copy.deepcopy(lp)
    ablist = np.arange(0, ab_max + dab_step, dab_step)
    # create a place to put images
    outdir = dio.prepdir(meshfn) + 'dispersion_abtransition/'
    dio.ensure_dir(outdir)
    fs = 20

    # go through each ab and make the image
    ii = 0
    for ab in ablist:
        print 'ab = ', ab
        lp = copy.deepcopy(lpmaster)
        lp['ABDelta'] = ab
        lat = lattice_class.Lattice(lp)
        lat.load(check=lp['check'])

        glat = GyroLattice(lat, lp)
        # glat.get_eigval_eigvect(attribute=True)
        fig, ax = leplt.initialize_portrait(ax_pos=[0.12, 0.2, 0.76, 0.6])
        omegas, kx, ky = glat.infinite_dispersion(save=False, nkxvals=nkxvals, nkyvals=50, outdir=outdir, save_plot=False)

        # plot and save it
        title = r'$\Delta_{AB} =$' + '{0:0.2f}'.format(ab)
        for jj in range(len(ky)):
            for kk in range(len(omegas[0, jj, :])):
                if color_thres is None or ab > 0.26:
                    if invert_bg:
                        ax.plot(kx, omegas[:, jj, kk], 'w-', lw=max(1., 30. / (len(kx) * len(ky))))
                    else:
                        ax.plot(kx, omegas[:, jj, kk], 'k-', lw=max(1., 30. / (len(kx) * len(ky))))
                else:
                    # if positive frequencies, color top band blue
                    if len(np.where(omegas[:, jj, kk] > 0)[0]) > 0.5 * len(omegas[:, jj, kk]):
                        # color top band blue
                        if len(np.where(np.abs(omegas[:, jj, kk]) > color_thres)[0]) > 0.5 * len(omegas[:, jj, kk]):
                            ax.plot(kx, omegas[:, jj, kk], '-', lw=max(1., 30. / (len(kx) * len(ky))), color=color1)
                        else:
                            ax.plot(kx, omegas[:, jj, kk], '-', lw=max(1., 30. / (len(kx) * len(ky))), color=color2)

                    # if negative frequencies, color bottom band blue
                    if len(np.where(omegas[:, jj, kk] < 0)[0]) > 0.5 * len(omegas[:, jj, kk]):
                        # color bottom band blue
                        if len(np.where(np.abs(omegas[:, jj, kk]) > color_thres)[0]) > 0.5 * len(omegas[:, jj, kk]):
                            ax.plot(kx, omegas[:, jj, kk], '-', lw=max(1., 30. / (len(kx) * len(ky))), color=color2)
                        else:
                            ax.plot(kx, omegas[:, jj, kk], '-', lw=max(1., 30. / (len(kx) * len(ky))), color=color1)

        ax.text(0.5, 1.15, title, fontsize=fs, ha='center', va='center', transform=ax.transAxes)
        ax.set_xlim(-np.pi, np.pi)
        ax.xaxis.set_ticks([-np.pi, 0, np.pi])
        ax.xaxis.set_ticklabels([r'$-\pi$', 0, r'$\pi$'])
        ax.set_xlabel(r'$k_x$', fontsize=fs)
        ax.set_ylabel(r'$\omega$', fontsize=fs)
        for tick in ax.xaxis.get_major_ticks():
            tick.label.set_fontsize(fs)
        for tick in ax.yaxis.get_major_ticks():
            tick.label.set_fontsize(fs)
        if ii == 0:
            ylims = ax.get_ylim()

        if plot_positive_only:
            ax.set_ylim(0., ylims[1])
        else:
            ax.set_ylim(ylims[0], ylims[1])

        # Save it
        name = outdir + 'dispersion{0:04d}'.format(ii)
        plt.savefig(name + '.png', dpi=dpi)
        plt.close('all')

        ii += 1

    # Turn images into a movie
    imgname = outdir + 'dispersion'
    movname = dio.prepdir(meshfn) + 'dispersion_abtrans' + glat.lp['meshfn_exten']
    lemov.make_movie(imgname, movname, indexsz='04', framerate=10, imgdir=outdir, rm_images=True,
                     save_into_subdir=True)