Esempio n. 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]]);
Esempio n. 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
from int_2dhopping import *
from numpy import *
from share_fun import grule
from functions import rotate_all

nflavors = 3

nbin = 500
emin = -6.
emax = 6.
broadening = 0.05

mu = 0.
double_counting = 0.        # unused in models containing only correlated orbitals

magnetic_field  = 0.0
numk = 100
bp, wf = grule(numk)        # the Gaussian points and weights

w = linspace(emin, emax, nbin) + 1j*broadening
self_energy = zeros((nbin, 1, nflavors, nflavors), dtype = complex)
self_energy = array([s.flatten() for s in self_energy], dtype = complex)
tight_binding_parameters = array([1.,0.3])

Gavg = calc_Gavg(w, double_counting, mu, self_energy, tight_binding_parameters, 
                 magnetic_field, bp, wf, 0).reshape(nbin, nflavors, nflavors)
G = rotate_all(Gavg, [matrix(eye(nflavors))])
dos = -1/pi*G.imag
savetxt('dos_tight_binding.out', c_[w.real, dos], fmt='%.6f')
Esempio n. 4
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]);
import sys
# directory for the main code
sys.path.append('..')

from int_bethe_lattice import *
from numpy import *
from share_fun import grule
from functions import rotate_all

nflavors = 3

emin = -3
emax = 3
nbin = 500
broadening = 0.005

double_counting = 0.
mu = 0.
magnetic_field  = 0.0
bp, wf = grule(1000)

w = linspace(emin, emax, nbin) + 1j*broadening
self_energy = zeros((nbin, nflavors*nflavors), dtype = 'c16')
quarter_bandwidth = array([1.,0])

Gavg = calc_Gavg(w, double_counting, mu, self_energy, quarter_bandwidth, 
                 magnetic_field, bp, wf, 0).reshape(nbin, nflavors, nflavors)
G = rotate_all(Gavg, [matrix(eye(nflavors))])
dos = -1/pi*G.imag
savetxt('dos_bethe_lattice.out', c_[w.real, dos])
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,
        'NORB' : NORB,
        'INTEGRATE_MOD' : 'int_donly_tilted_3bands',
        'np' : num_processes,
        }

extra = {
        'HR' : HR,
        'R' : R,
        'GaussianData' : grule(numk),
        }

# calculate the k-integral
Gavg = average_green.integrate(w+1j*broadening, double_counting, mu, SE,
                               parms, extra, parallel)
Gavg = array([rotate_all(Gavg[s], rot_mat, need_extra = True) for s in range(SPINS)])

dos = -1/pi*Gavg[0].imag 
savetxt('dos_dft_mlwf.mpi', c_[w, dos], fmt='%.6f')