예제 #1
0
    def load_hdf5_chern(self, h5fn, load_paramsregs=False):
        # todo: test this method
        # Load data from hdf5 file
        fi = h5py.File(h5fn, "r")

        # Get subdir path from h5fn
        hfnsplit = self.cp['cpmeshfn'].split(
            '/' + self.gyro_lattice.lp['LatticeTop'] + '/')
        subgroup = hfnsplit[-1]
        self.chern_finsize = fi[subgroup].attrs['chern_finsize']
        if load_paramsregs:
            # Load each kitaev region dictionary into the nested params_regs dictionary
            subg_preg = le.prepdir(subgroup) + 'params_regs'
            if subg_preg in fi:
                preg_groups = fi[le.prepdir(subgroup) + 'params_regs']
                ind = 0
                for preg_fn in preg_groups:
                    if ind % 200 == 0:
                        print 'Loading params_regs #', ind, ' of ', len(
                            paramregdicts.attrs), '\n'
                    ksizekey = preg_fn.split('ksize')[-1]
                    pregdict = {}
                    for key in fi[subg_preg + '/' + preg_fn].attrs:
                        pregdict[key] = fi[subg_preg + '/' +
                                           preg_fn].attrs[key]
                    self.params_regs[ksizekey] = pregdict
                    ind += 1
            else:
                print 'Could not load requested params_regs from hdf5...'
        fi.close()
예제 #2
0
 def plot_eigval_hist(self, infodir=None, show=False):
     print 'mass: self.eigval = ', self.eigval
     fig, DOS_ax = leplt.initialize_DOS_plot(self.eigval, 'mass', pin=-5000)
     if infodir is not None:
         infodir = le.prepdir(infodir)
         plt.savefig(infodir + 'eigval_mass_hist.png')
     if show:
         plt.show()
     plt.clf()
def plot_projector_locality_singlept(haldane_lattice,
                                     proj_ind,
                                     dists,
                                     magproj,
                                     ax=None,
                                     save=True,
                                     outdir=None,
                                     network_str='none',
                                     show=False,
                                     alpha=1.0):
    """
    Plot the locality of the projection operator wrt a point

    Parameters
    ----------
    haldane_lattice : HaldaneLattice instance
        The network on which to characterize the projector
    proj_ind : int
        The haldane index to analyze wrt
    dists : dists : NP x NP float array
        Euclidean distances between points. Element i,j is the distance between particle i and j
    magproj : NP x NP float array
        Element i,j gives the magnitude of the projector connecting site i to particle j
    evxymag : 2*NP x NP float array
        Same as magproj, but with x and y components separate. So, element 2*i,j gives the magnitude of the x component
        of the projector connecting site i to the full xy of particle j and element 2*i+1,j gives the
        magnitude of the y component of the projector connecting site i to the full xy of particle j.
    outdir : str or None
        Path to save dists and magproj as pickles in outdir, also saves plots there
    network_str : str
        Description of the network for the title of the plot. If 'none', network_str = haldane_lattice.lp['LatticeTop'].
    show : bool
        Plot the result (forces a matplotlib close event)
    alpha : float
        opacity
    """
    # Initialize plot
    if ax is None:
        fig, axes = leplt.initialize_1panel_fig(Wfig=90,
                                                Hfig=None,
                                                x0frac=0.15,
                                                y0frac=0.15,
                                                wsfrac=0.4,
                                                hs=None,
                                                vspace=5,
                                                hspace=8,
                                                tspace=10,
                                                fontsize=8)
        ax = axes[0]

    if network_str is 'none':
        network_str = haldane_lattice.lp['LatticeTop']

    ax.scatter(dists[proj_ind],
               np.log10(magproj[proj_ind]),
               s=1,
               color='k',
               alpha=alpha)
    ax.set_title('Locality of projection operator $P$\nfor ' + network_str +
                 ' network')
    ax.set_xlabel('Distance $|\mathbf{x}_i-\mathbf{x}_j|$')
    ax.set_ylabel('$\log_{10} |P_{ij}|$')
    if save:
        if outdir is None:
            outdir = le.prepdir(haldane_lattice.lp['meshfn'].replace(
                'networks', 'projectors'))
        le.ensure_dir(outdir)
        plt.savefig(outdir + haldane_lattice.lp['LatticeTop'] +
                    '_projector_xy2_log_{0:06d}'.format(proj_ind) + '.png',
                    dpi=300)

        ax.set_xlim(-0.5, 5)
        ax.set_ylim(-3, 0)
        plt.savefig(outdir + haldane_lattice.lp['LatticeTop'] +
                    '_projector_xy2_zoom_log_{0:06d}'.format(proj_ind) +
                    '.png',
                    dpi=300)

        # save dists and magproj as pkl
        outfn = outdir + haldane_lattice.lp[
            'LatticeTop'] + "_dists_singlept_{0:06d}".format(proj_ind) + ".pkl"
        with open(outfn, "wb") as fn:
            pickle.dump(dists[proj_ind], fn)
        with open(
                outdir + haldane_lattice.lp['LatticeTop'] +
                "_magproj_{0:06d}".format(proj_ind) + ".pkl", "wb") as fn:
            pickle.dump(magproj[proj_ind], fn)
    if show:
        plt.show()
def plot_projector_locality(haldane_lattice,
                            dists,
                            magproj,
                            evxymag,
                            outdir=None,
                            network_str='none',
                            show=False,
                            alpha=None):
    """
    Plot the locality of the projection operator

    Parameters
    ----------
    haldane_lattice : HaldaneLattice instance
        The network on which to characterize the projector
    dists : dists : NP x NP float array
        Euclidean distances between points. Element i,j is the distance between particle i and j
    magproj : NP x NP float array
        Element i,j gives the magnitude of the projector connecting site i to particle j
    evxymag : 2*NP x NP float array
        Same as magproj, but with x and y components separate. So, element 2*i,j gives the magnitude of the x component
        of the projector connecting site i to the full xy of particle j and element 2*i+1,j gives the
        magnitude of the y component of the projector connecting site i to the full xy of particle j.
    outdir : str or None
        Path to save dists and magproj as pickles in outdir, also saves plots there
    network_str : str
        Description of the network for the title of the plot. If 'none', network_str = haldane_lattice.lp['LatticeTop'].
    show : bool
        Plot the result (forces a matplotlib close event)
    alpha : float or None
        opacity. If none, sets alpha = 3./len(dists)
    """
    if alpha is None:
        alpha = 3. / len(dists)

    # Initialize plot
    fig, ax = leplt.initialize_1panel_fig(Wfig=90,
                                          Hfig=None,
                                          x0frac=0.15,
                                          y0frac=0.15,
                                          wsfrac=0.4,
                                          hs=None,
                                          vspace=5,
                                          hspace=8,
                                          tspace=10,
                                          fontsize=8)

    # print 'np.shape(xymag) = ', np.shape(xymag)
    for ind in range(len(dists)):
        ax[0].scatter(dists[ind],
                      np.log10(evxymag[:, 2 * ind].ravel()),
                      s=1,
                      color='r',
                      alpha=alpha)
        ax[0].scatter(dists[ind],
                      np.log10(evxymag[:, 2 * ind + 1].ravel()),
                      s=1,
                      color='b',
                      alpha=alpha)

    if network_str is 'none':
        network_str = haldane_lattice.lp['LatticeTop']

    ax[0].set_title('Locality of projection operator $P$\nfor ' + network_str +
                    ' network')
    ax[0].set_xlabel('Distance $|\mathbf{x}_i-\mathbf{x}_j|$')
    ax[0].set_ylabel('$|P_{ij}|$')
    if outdir is None:
        outdir = le.prepdir(haldane_lattice.lp['meshfn'].replace(
            'networks', 'projectors'))
    le.ensure_dir(outdir)
    plt.savefig(outdir + haldane_lattice.lp['LatticeTop'] +
                '_projector_log.png',
                dpi=300)

    ax[0].set_xlim(-0.5, 5)
    ax[0].set_ylim(-3.5, 0.5)
    plt.savefig(outdir + haldane_lattice.lp['LatticeTop'] +
                '_projector_zoom_log.png',
                dpi=300)
    if show:
        plt.show()
    plt.clf()

    # Combine x and y
    # put projector magnitude on log-log plot
    fig, ax = leplt.initialize_1panel_fig(Wfig=90,
                                          Hfig=None,
                                          x0frac=0.15,
                                          y0frac=0.15,
                                          wsfrac=0.4,
                                          hs=None,
                                          vspace=5,
                                          hspace=8,
                                          tspace=10,
                                          fontsize=8)
    for ind in range(len(dists)):
        ax[0].scatter(dists[ind],
                      np.log10(magproj[ind]),
                      s=1,
                      color='k',
                      alpha=alpha)
    ax[0].set_title('Locality of projection operator $P$\nfor ' + network_str +
                    ' network')
    ax[0].set_xlabel('Distance $|\mathbf{x}_i-\mathbf{x}_j|$')
    ax[0].set_ylabel('$\log_{10} |P_{ij}|$')
    if outdir is None:
        outdir = le.prepdir(haldane_lattice.lp['meshfn'].replace(
            'networks', 'projectors'))
    le.ensure_dir(outdir)
    plt.savefig(outdir + haldane_lattice.lp['LatticeTop'] +
                '_projector_xy2_log.png',
                dpi=300)

    ax[0].set_xlim(-0.5, 5)
    ax[0].set_ylim(-3.5, 0.5)
    plt.savefig(outdir + haldane_lattice.lp['LatticeTop'] +
                '_projector_xy2_zoom_log.png',
                dpi=300)
    if show:
        plt.show()
    plt.clf()

    # save dists and magproj as pkl
    with open(outdir + haldane_lattice.lp['LatticeTop'] + "_dists.pkl",
              "wb") as fn:
        pickle.dump(dists, fn)
    with open(outdir + haldane_lattice.lp['LatticeTop'] + "_magproj.pkl",
              "wb") as fn:
        pickle.dump(magproj, fn)
# Global geometric params
parser.add_argument(
    '-delta',
    '--delta',
    help='for hexagonal kitaev region, deformation opening angle',
    type=float,
    default=2. / 3.)
args = parser.parse_args()

####################################################################################
####################################################################################
cprootdir = '/Users/npmitchell/Desktop/test/chern/'

# Grab and prepare directories for both input (datadir) and output (outdir)
if args.seriesdir is not 'none':
    outdir = le.prepdir(cprootdir + args.seriesdir)
    datadir = le.prepdir(args.rootdir + args.seriesdir)
else:
    outdir = le.prepdir(cprootdir)
    datadir = args.rootdir

le.ensure_dir(outdir)

cp = {
    'ksize_frac_arr':
    le.string_sequence_to_numpy_array(args.ksize_frac_array, dtype=float),
    'omegac':
    args.omegac,
    'regalph':
    args.regalph,
    'regbeta':
예제 #6
0
            proj_ind = ((lat.xy[:, 0] - xyloc[0])**2 +
                        (lat.xy[:, 1] - xyloc[1])**2).argmin()
            print 'proj_ind = ', proj_ind
        else:
            proj_ind = args.proj_ind
        kpfns.plot_projector_locality_singlept(glat,
                                               proj_ind,
                                               dists,
                                               magproj,
                                               outdir=None,
                                               network_str=network_str)

        # Save evxyproj as pkl
        evxyproj = np.dstack(
            (proj[2 * proj_ind, :], proj[2 * proj_ind + 1, :]))[0].T
        outdir = le.prepdir(glat.lp['meshfn'].replace('networks',
                                                      'projectors'))
        with open(
                outdir + glat.lp['LatticeTop'] +
                "_evxyproj_singlept_{0:06d}".format(proj_ind) + ".pkl",
                "wb") as fn:
            pickle.dump(evxyproj, fn)

        fig, ax, cbar_ax = kpfns.plot_projector_singlept_network(glat,
                                                                 evxyproj,
                                                                 fig=None,
                                                                 ax=None,
                                                                 wsfrac=0.5,
                                                                 vspace=0)
        plt.savefig(outdir + glat.lp['LatticeTop'] +
                    '_projector_singlept_network.pdf')
예제 #7
0
def load_chern_hdf5(cherndir, cn, overwrite=False, verbose=False):
    """
    From cherndir, load chern_finsize.txt, chern_params.txt, lattice_params.txt, params_regs, and contribs into
    hdf5 group cn.

    Parameters
    ----------
    cherndir : str
        Path to chern data on disk
    cn : h5py subgroup
        Where the data will be stored in hdf5 format
    overwrite : bool
        Overwrite the data if already exists in the hdf5 format
    verbose : bool
        Output more to command line
    """
    # load numpy array chern_finsize.txt
    print 'loading ' + le.prepdir(cherndir) + 'chern_finsize.txt'
    chern_finsize = np.loadtxt(le.prepdir(cherndir) + 'chern_finsize.txt', delimiter=',')
    cn.attrs['chern_finsize'] = chern_finsize

    # load dict chern_params.txt
    cp = le.load_params(le.prepdir(cherndir) + 'chern_params.txt')
    if 'cp' not in cn:
        cpgroup = cn.create_group('cp')
        # By continuing we are not overwriting data
        overwriting = False
    else:
        cpgroup = cn['cp']
        # By continuing we are overwriting data
        overwriting = True

    if overwrite or not overwriting:
        for key in cp:
            cpgroup.attrs[key] = cp[key]

        # load lattice_params.txt if it exists
        if glob.glob(cherndir + 'lattice_params.txt'):
            # load dict chern_params.txt
            if verbose:
                print 'creating lp group in ', cn
            lp = le.load_params(le.prepdir(cherndir) + 'lattice_params.txt')
            if 'lp' not in cn:
                lpgroup = cn.create_group('lp')
            else:
                lpgroup = cn['lp']
            for key in lp:
                lpgroup.attrs[key] = lp[key]

        # Store params_regs
        if glob.glob(cherndir + 'params_regs/'):
            pregs = cn.create_group("params_regs")

            for preg_fn in glob.glob(cherndir + 'params_regs/params_regs_*.txt'):
                pregname = preg_fn.split('/')[-1]
                # load dict params_regs_ksize#p###.txt
                params_regs = le.load_params(preg_fn)
                prgroup = pregs.create_group(pregname)
                for key in params_regs:
                    prgroup.attrs[key] = params_regs[key]
        elif glob.glob(cherndir + 'params_regs.pkl'):
            if verbose:
                print 'found params_regs pickle: ' + cherndir + 'params_regs.pkl'
            with open(glob.glob(cherndir + 'params_regs.pkl')[0], "rb") as fn:
                pregdict = pkl.load(fn)
            if "params_regs" not in cn:
                pregs = cn.create_group("params_regs")
            else:
                pregs = cn["params_regs"]
            # print 'pregdict = ', pregdict
            for prkey in pregdict:
                if verbose:
                    print 'Creating group in pregs: ', prkey
                params_regs = pregdict[prkey]
                prgroup = pregs.create_group(prkey)
                for key in params_regs:
                    prgroup.attrs[key] = params_regs[key]

        # Store contribs
        if glob.glob(cherndir + 'contribs/'):
            print 'found contributions directory: ' + cherndir + 'contribs/'
            cons = cn.create_group("contribs")
            for contrib_fn in glob.glob(cherndir + 'contribs/contribs_*.txt'):
                contribname = contrib_fn.split('/')[-1]
                # load dict contribs_ksize#p###.txt
                contribs = le.load_params(contrib_fn)
                print 'contribname = ', contribname
                ctgroupname = contribname.split('_')[-1].split('.')[0].split(['ksize'])[-1]
                print 'ctgroupname = ', ctgroupname
                ctgroup = cons.create_group(ctgroupname)
                for key in cons:
                    ctgroup.attrs[key] = contribs[key]
        elif glob.glob(cherndir + 'contribs.pkl'):
            print 'found contributions pickle: ' + cherndir + 'contribs.pkl'
            with open(glob.glob(cherndir + 'contribs.pkl')[0], "rb") as fn:
                contribs = pkl.load(fn)
            if 'contribs' not in cn:
                cons = cn.create_group("contribs")
            else:
                cons = cn['contribs']
            for ckey in contribs:
                if verbose:
                    print 'Creating group in cons: ', ckey
                contrib = contribs[ckey]
                ctgroup = cons.create_group(ckey)
                for key in contrib:
                    ctgroup.attrs[key] = contrib[key]
    else:
        print 'Data already exists and overwrite=False: skipping load...'

    return cn
예제 #8
0
        if meshfn not in f:
            fmf = f.create_group(meshfn)
        else:
            fmf = f[meshfn]

        # Get chernfns which are dirs
        chernfns = le.find_subdirs('Omk*polyoff*', meshfndir)
        for cherndir in chernfns:
            chernname = cherndir.split('/')[-2]

            # Check if chernname holds the chern calculation or is a set of chern calculations.
            # If chernname ends in _XY, then it holds the chern calculation. Otherwise, it is a set.
            if cherndir[-4:-1] == '_XY':
                # If chern subgroup in meshfn subgroup has not been made and data exists, load it
                if chernname not in fmf and glob.glob(le.prepdir(cherndir) + 'chern_finsize.txt'):
                    cn = fmf.create_group(chernname)
                    load_chern_hdf5(cherndir, cn, overwrite=args.overwrite_existing_data, verbose=args.verbose)
                elif glob.glob(le.prepdir(cherndir) + 'chern_finsize.txt'):
                    cn = fmf[chernname]
                    load_chern_hdf5(cherndir, cn, overwrite=args.overwrite_existing_data, verbose=args.verbose)
                else:
                    print 'data missing, skip chern...'
            else:
                # Chernname is a set of calculations at different positions in the network.
                if chernname not in fmf:
                    csubgroup = fmf.create_group(chernname)
                else:
                    csubgroup = fmf[chernname]

                # Get chernfns which are dirs: offset in Y is a subdir