Exemple #1
0
def getGavgFromSelfEnergy(parms, se_filename = None):
    N_LAYERS = int(parms['N_LAYERS']); 
    FLAVORS  = int(parms['FLAVORS']);
    SPINS = int(parms['SPINS']);
    parms['BETA'] = 10;

    # prepare data
    NMaxFreq = int(parms['N_MAX_FREQ']);
    if se_filename is not None:
        print 'load self energy from file: ', se_filename;
        tmp = genfromtxt(se_filename);
        if NMaxFreq > len(tmp): NMaxFreq = len(tmp);
        w = tmp[:,0] + 1j*float(parms['BROADENING']);
        tmp = tmp[:, 1:];
        tmp = tmp[:NMaxFreq, 0::2] + 1j*tmp[:NMaxFreq, 1::2];
        se = zeros((SPINS, NMaxFreq, N_LAYERS*FLAVORS), dtype = complex);
        for s in range(SPINS):
            for f in range(N_LAYERS*FLAVORS):
                se[s, :, f] = tmp[:, SPINS*f+s];
    else: 
        se = zeros((SPINS, NMaxFreq, N_LAYERS*FLAVORS), dtype = complex); 
        w = linspace(float(parms['EMIN']), float(parms['EMAX']), NMaxFreq) + 1j*float(parms['BROADENING']); 

    # tight binding Hamiltonian
    HR, R = getHamiltonian(parms['RHAM'], 4);
    parms['NORB'] = len(HR[0])
    extra = { 'HR' : HR, 'R': R };
    if int(val_def(parms, 'FORCE_DIAGONAL', 0)) > 0:
        print 'FORCE_DIAGONAL is used';
        ind = nonzero(sum(R**2, 1)==0)[0][0];
        H0 = HR[ind];
    else: H0 = None;
    rot_mat = getRotationMatrix(N_LAYERS, FLAVORS, val_def(parms, 'ROT_MAT', None), H0);
 
    # prepare for k-integrate
    bp, wf = grule(int(parms['NUMK']));
    extra.update({
            'GaussianData' : [bp, wf],
            'rot_mat'      : rot_mat
            });
    delta = float(parms['DELTA']);
    mu    = float(parms['MU']);

    # running
    Gavg = averageGreen(delta, mu, w, se, parms, -1, -1, 0, extra)[1];
    # swap the Gavg to the format of my code
#    swap_vec = zeros((2, N_LAYERS*FLAVORS), dtype = int);
#    for L in range(N_LAYERS):
#        for f in range(FLAVORS): swap_vec[:,f*N_LAYERS+L] = array([f*N_LAYERS+L, L*FLAVORS+f]);
#    for s in range(SPINS): Gavg[s, :, swap_vec[1]] = Gavg[s, :, swap_vec[0]];

    spec = -1/pi * Gavg.imag;
    if SPINS == 1: savetxt('spec.dat', c_[w.real, spec[0]]);
    elif SPINS > 1: 
        savetxt('spec_up.dat', c_[w.real, spec[0]]);
        savetxt('spec_dn.dat', c_[w.real, spec[1]]);
Exemple #2
0
def getGavgFromSelfEnergy(parms, se_filename = None):
    N_LAYERS = int(parms['N_LAYERS'])
    FLAVORS  = int(parms['FLAVORS'])
    SPINS = int(parms['SPINS'])
    beta = float(parms['BETA'])

    # prepare data
    NMaxFreq = int(round((beta*float(parms['MAX_FREQ'])/pi - 1)/2.))
    iwn = 1j * (2*arange(NMaxFreq)+1)*pi/beta
    if se_filename is not None:
        print 'load self energy from file: ', se_filename;
        tmp = genfromtxt(se_filename);
        if NMaxFreq > len(tmp): NMaxFreq = len(tmp);
        tmp = tmp[:, 1:]
        tmp = tmp[:NMaxFreq, 0::2] + 1j*tmp[:NMaxFreq, 1::2]
        se = zeros((SPINS, NMaxFreq, N_LAYERS*FLAVORS), dtype = complex)
        for s in range(SPINS):
            for f in range(N_LAYERS*FLAVORS):
                se[s, :, f] = tmp[:NMaxFreq, SPINS*f+s]
    else: 
        se = zeros((SPINS, NMaxFreq, N_LAYERS*FLAVORS), dtype = complex)
        

    # tight binding Hamiltonian
    HR, R = getHamiltonian(parms['RHAM'], 4);
    parms['NORB'] = len(HR[0])
    extra = { 'HR' : HR, 'R': R };
    if int(val_def(parms, 'FORCE_DIAGONAL', 0)) > 0:
        print 'FORCE_DIAGONAL is used';
        ind = nonzero(sum(R**2, 1)==0)[0][0];
        H0 = HR[ind];
    else: H0 = None;
    rot_mat = getRotationMatrix(N_LAYERS, FLAVORS, val_def(parms, 'ROT_MAT', None), H0);
 
    # prepare for k-integrate
    bp, wf = grule(int(parms['NUMK']));
    extra.update({
            'GaussianData' : [bp, wf],
            'rot_mat'      : rot_mat
            });
    delta = float(parms['DELTA']);
    mu    = float(parms['MU']);

    # running
    SelfEnergy_rot = array([irotate(se[s], rot_mat) for s in range(SPINS)])
    SE = array([array([s.flatten() for s in SelfEnergy_rot[n]]) for n in range(SPINS)])
    Gavg = integrate(iwn, delta, mu, SE, parms, extra, parallel = False)
    g = array([rotate_green(Gavg, rot_mat, layer=L) for L in range(N_LAYERS)])

    return iwn, g
Exemple #3
0
def getSpectraFromSelfEnergy(h5, se_filename, rham, rotmat, numk = None, setail_filename = None, it = 0):
    
    # prepare data
    w, se_refreq = ProcessSelfEnergy(se_filename, emin = -5, emax = 5, NFreq = 500);

    it = h5['iter'][0] - it;
    parms = load_parms(h5, it);
    print 'work on iteration ', it;
    if rham is not None: print 'new path for rham file is: ', rham; parms['RHAM'] = rham;
    if rotmat is not None: print 'new path for rot_mat file is ', rotmat; parms['ROT_MAT'] = rotmat;
    BETA = float(parms['BETA']);
    N_LAYERS = int(parms['N_LAYERS']);
    FLAVORS  = int(parms['FLAVORS']);
    SPINS = int(parms['SPINS']);
    NORB  = int(parms['NORB']);
    dmft_id = system.getDMFTCorrIndex(parms, all = False);
    dmft_id_len = len(dmft_id);

    # get the se tails
    tmp = h5['SolverData/selfenergy_asymp_coeffs'][:];
    se_tail = tmp[tmp[:,0] == it, 1:].reshape(SPINS, 2, -1)[:, :, ::N_LAYERS];
    if setail_filename is not None:
        print 'use the tail from external source: ', setail_filename;
        tmp = genfromtxt(setail_filename);
        se_tail[:, :, dmft_id] = array([tmp[:, s::SPINS] for s in range(SPINS)]); 
    print se_tail;

    # restore SelfEnergy
    se = zeros((SPINS, len(se_refreq), N_LAYERS*FLAVORS), dtype = complex);
    for s in range(SPINS):
        for f in range(N_LAYERS*FLAVORS):
            if f/N_LAYERS not in dmft_id: se[s,:,f] = se_tail[s, 0, f/N_LAYERS];
            else: 
                f1 = nonzero(f/N_LAYERS == dmft_id)[0][0];
                se[s, :, f] = se_refreq[:, SPINS*f1+s]*se_tail[s, 1, f/N_LAYERS] + se_tail[s, 0, f/N_LAYERS]; 

    # tight binding Hamiltonian
    if 'RHAM' in parms: 
        HR, R = getHamiltonian(parms['RHAM'], 4);
        if parms['DTYPE'] == '3bands': FLAVORS = 3;
        extra = { 'HR' : HR, 'R': R };

    # rotation matrix
    if int(val_def(parms, 'FORCE_DIAGONAL', 0)) > 0:
        print 'FORCE_DIAGONAL is used';
        ind = nonzero(sum(R**2, 1)==0)[0][0];
        H0 = HR[ind];
    else: H0 = None;
    rot_mat = getRotationMatrix(N_LAYERS, FLAVORS, val_def(parms, 'ROT_MAT', None), H0);


    # prepare for k-integrate
    parms['NUMK'] = 16 if numk is None else numk;
    bp, wf = grule(int(parms['NUMK']));
    broadening = 0.01;
    extra.update({
            'GaussianData' : [bp, wf],
            'rot_mat'      : rot_mat
            });
    delta = float(parms['DELTA']);
    mu    = float(parms['MU']);

    # running
    print 'generating interacting DOS with parameters'
    for k, v in parms.iteritems(): print '%s = %s'%(k, v);

    Gr = averageGreen(delta, mu, w+1j*broadening, se, parms, float(parms['ND']), float(parms['DENSITY']), 0, extra)[1];
    if SPINS == 1: savetxt(parms['ID']+'.idos', c_[w, -1/pi*Gr[0].imag], fmt = '%g');
    elif SPINS == 2:
        savetxt(parms['ID']+'_up.idos', c_[w, -1/pi*Gr[0].imag], fmt = '%g'); 
        savetxt(parms['ID']+'_dn.idos', c_[w, -1/pi*Gr[1].imag], fmt = '%g'); 
    
    # calculate original G(iwn), only consider one "LAYERS"
    Giwn_orig = h5['ImpurityGreen/%d'%it][:,:,::N_LAYERS];
    NMatsubara = size(Giwn_orig, 1);
    wn = (2*arange(NMatsubara) + 1)*pi/BETA;
    Giwn = zeros((NMatsubara, 2*FLAVORS*SPINS), dtype = float); # 2 for real and imag
    for f in range(FLAVORS):
        for s in range(SPINS):
            Giwn[:, 2*(SPINS*f+s)] = Giwn_orig[s, :, f].real;
            Giwn[:, 2*(SPINS*f+s)+1] = Giwn_orig[s, :, f].imag;
    savetxt(parms['ID']+'.gmat', c_[wn, Giwn]);

    # calculate G(iwn) for reference, only consider one "LAYERS"
    NMatsubara = 200;
    wn = (2*arange(NMatsubara) + 1)*pi/BETA;
    Giwn = zeros((NMatsubara, 2*FLAVORS*SPINS), dtype = float); # 2 for real and imag
    for f in range(FLAVORS):
        for s in range(SPINS):
            A = -1/pi * Gr[s, :, f*N_LAYERS].imag;
            for n in range(NMatsubara):
                tck_re = splrep(w, real(A / (1j*wn[n] - w)));
                tck_im = splrep(w, imag(A / (1j*wn[n] - w)));
                Giwn[n, 2*(SPINS*f+s)] = splint(w[0], w[-1], tck_re);
                Giwn[n, 2*(SPINS*f+s)+1] = splint(w[0], w[-1], tck_im);
    savetxt(parms['ID']+'.gmat.ref', c_[wn, Giwn]);
emin = -1.5
emax = 1.5
broadening = 0.02
numk = 26

# parallelization: parallel
#   0: no parallelization
#   1: OpenMP with number of threads set by OMP_NUM_THREADS
#   2: MPI with number of processes from the input
parallel = 2
num_processes = 10
if len(sys.argv) > 1: num_processes = int(sys.argv[1])

HR, R = init.getHamiltonian(rham_file, 4)
NORB  = size(HR, 1)
rot_mat = init.getRotationMatrix(N_LAYERS, FLAVORS, 
                                 H0 = HR[nonzero(sum(R**2, 1)==0)[0][0]])
w = linspace(emin, emax, nbin)

# set zero self energy and convert it into the flattened format
SelfEnergy = zeros((SPINS, nbin, N_LAYERS*FLAVORS), dtype = 'c16')
SelfEnergy_rot = array([irotate(SelfEnergy[s], rot_mat)
                        for s in range(SPINS)])
SE = array([array([s.flatten() for s in SelfEnergy_rot[n]])
            for n in range(SPINS)])

# prepare the parameter dict
parms = {
        'H' : magnetic_field,
        'N_LAYERS' : N_LAYERS,
        'FLAVORS' : FLAVORS,
        'SPINS' : SPINS,