Example #1
0
def eval_cross_section(N_atoms_uc, csection, kaprange, qlist, tau_list, eig_list, kapvect, wtlist):    
    print "begin part 2"
    
    gamr0 = 2*0.2695e-12 #sp.Symbol('gamma', commutative = True)
    hbar = sp.S(1.0) # 1.05457148*10**(-34) #sp.Symbol('hbar', commutative = True)
    g = 2.#sp.Symbol('g', commutative = True)
    # Kappa vector
    kap = sp.Symbol('kappa', real = True)#spm.Matrix([sp.Symbol('kapx',real = True),sp.Symbol('kapy',real = True),sp.Symbol('kapz',real = True)])
    t = sp.Symbol('t', real = True)
    w = sp.Symbol('w', real = True)
    W = sp.Symbol('W', real = True)
    tau = sp.Symbol('tau', real = True)
    Q = sp.Symbol('q', real = True)
    L = sp.Symbol('L', real = True)
    lifetime=sp.Symbol('V',real=True)
    boltz = 8.617343e-2    
    kapxhat = sp.Symbol('kapxhat',real=True)
    kapyhat = sp.Symbol('kapyhat',real=True)
    kapzhat = sp.Symbol('kapzhat',real=True)    

    kapunit = kapvect.copy()
    kapunit[:,0]=kapvect[:,0]/kaprange
    kapunit[:,1]=kapvect[:,1]/kaprange
    kapunit[:,2]=kapvect[:,2]/kaprange    
    
    nkpts = len(kaprange)
    nqpts = 2*nkpts
    
    csdata=[]
    wq = sp.Symbol('wq', real = True)

    for k in range(len(tau_list)):
        temp1=[]
        for g in range(nqpts):
            temp2=[]
            for i in range(len(eig_list[k][g])):
                #temp = eval_it(k,g,i,nkpts,csection)
                temp=csection

                for num in range(N_atoms_uc):
                    nq = sp.Symbol('n%i'%(num,), real = True)
                    #n = sp.Pow( sp.exp(-np.abs(eig_list[k][g][i])/boltz/temperature) - 1 ,-1)
                    n=sp.S(0.0)
                    temp = temp.subs(nq,n)
                    
                #if g==0:
                if g<nkpts:
                    value = kapvect[g]-tau_list[k] - qlist[k][g]
                    if eq(value[0],0) == 0 and eq(value[1],0) == 0 and eq(value[2],0) == 0:
                        temp = temp.subs(sp.DiracDelta(kap-tau-Q),sp.S(1))
                        temp = temp.subs(sp.DiracDelta(-kap+tau+Q),sp.S(1)) # recall that the delta function is symmetric
                    else:
                        temp = temp.subs(sp.DiracDelta(kap-tau-Q),sp.S(0))
                        temp = temp.subs(sp.DiracDelta(-kap+tau+Q),sp.S(0))
                    temp = temp.subs(kapxhat,kapunit[g,0])
                    temp = temp.subs(kapyhat,kapunit[g,1])
                    temp = temp.subs(kapzhat,kapunit[g,2])
                #value =kapvect[g//2]- tau_list[k] + qlist[k][g] 
                #if g%2!=0:
                elif g>=nkpts:
                    value = kapvect[g-nkpts]-tau_list[k] - qlist[k][g]
                    if eq(value[0],0) == 0 and eq(value[1],0) == 0 and eq(value[2],0) == 0:
                        temp = temp.subs(sp.DiracDelta(kap-tau+Q),sp.S(1))
                        temp = temp.subs(sp.DiracDelta(-kap+tau-Q),sp.S(1))
                    else:
                        temp = temp.subs(sp.DiracDelta(kap-tau+Q),sp.S(0))
                        temp = temp.subs(sp.DiracDelta(-kap+tau-Q),sp.S(0))
                    temp = temp.subs(kapxhat,kapunit[g-nkpts,0])
                    temp = temp.subs(kapyhat,kapunit[g-nkpts,1])
                    temp = temp.subs(kapzhat,kapunit[g-nkpts,2])                    
                value=tau_list[k]      
                if eq(value[0],0) == 0 and eq(value[1],0) == 0 and eq(value[2],0) == 0:
                    temp = temp.subs(sp.DiracDelta(kap-tau-Q),sp.S(1))
                    temp = temp.subs(sp.DiracDelta(-kap+tau+Q),sp.S(1)) #
                    temp = temp.subs(sp.DiracDelta(kap-tau+Q),sp.S(1))
                    temp = temp.subs(sp.DiracDelta(-kap+tau-Q),sp.S(1))
                    
                #temp = temp.subs(kapxhat,kapunit[g//2,0])
                #temp = temp.subs(kapyhat,kapunit[g//2,1])
                #temp = temp.subs(kapzhat,kapunit[g//2,2])
                
                
                value = eig_list[k][g][i] - wtlist[g] 
                #print '1',temp
                temp = temp.subs(wq,eig_list[k][g][i])

                temp=temp.subs(w,wtlist[g])
                if 0:
                    if eq(value,0) == 0:
                        temp = temp.subs(sp.DiracDelta(wq - w), sp.S(1))
                    else: 
                        temp = temp.subs(sp.DiracDelta(wq - w), sp.S(0))
                if 0:
                    if eq(eig_list[k][g][i], wtlist[g]) == 0:
                        G=sp.Wild('G', exclude = [Q,kap,tau,w])
                        temp=sub_in(temp, sp.DiracDelta(G - A*w), sp.S(1))
                    elif eq(eig_list[k][g][i], -wtlist[g]) == 0:
                        G=sp.Wild('G', exclude = [Q,kap,tau,w])
                        temp=sub_in(temp, sp.DiracDelta(G - A*w), sp.S(1))
                    else:
                        temp = temp.subs(w,wtlist[g])

#                print '4',temp
                temp2.append(temp)
            temp1.append(temp2)
        csdata.append(temp1)


    #print csdata

    # Front constants and stuff for the cross-section
    front_constant = 1.0#(gamr0)**2#/(2*pi*hbar)
    front_func = (1./2.)*g#*F(k)
    debye_waller= 1. #exp(-2*W)
    
    cstemp=[]
    for g in range(nqpts):
        for k in range(len(tau_list)):
            cstemp.append(csdata[k][g][0].subs(lifetime,sp.S(.1)))
            
    print cstemp
    sys.exit()
    
    qtlist=np.array(qlist,'Float64').reshape((nqpts*len(tau_list),3))[:,0]
    xi=qtlist
    yi=wtlist
    zi=np.array(cstemp,'Float64')
    Z=matplotlib.mlab.griddata(xi,yi,zi,xi,yi)
    zmin, zmax = np.min(Z), np.max(Z)
    locator = ticker.MaxNLocator(10) # if you want no more than 10 contours
    locator.create_dummy_axis()
    locator.set_bounds(zmin, zmax)
    levs = locator()
    levs[0]=1.0
    print zmin, zmax
    #zm=ma.masked_where(Z<=0,Z)
    zm=Z
    print zm
    print levs
    plt.contourf(xi,yi,Z, levs)#, norm=matplotlib.colors.LogNorm(levs[0],levs[len(levs)-1]))
    l_f = ticker.LogFormatter(10, labelOnlyBase=False) 
    cbar = plt.colorbar(ticks = levs, format = l_f)
    plt.show()
Example #2
0
def generate_cross_section(interactionfile, spinfile, lattice, arg, 
                       tau_list, h_list, k_list, l_list, w_list, 
                       temperature, steps, eief, efixed = 14.7):
    """
    Calculates the cross_section given the following parameters:
    interactionfile, spinfile - files to get atom data
    lattice     - Lattice object from tripleaxisproject
    arg         - reduced list of operator combinations
    tau_list    - list of tau position
    w_list      - list of w's probed
    temp        - temperature
    kmin        - minimum value of k to scan
    kmax        - maximum value of k to scan
    steps       - number of steps between kmin, kmax
    eief        - True if fixed Ef
    efixed      - value of the fixed energy, either Ei or Ef
    """

    # Read files, get atom_list and such
    atom_list, jnums, jmats,N_atoms_uc=readFiles(interactionfile,spinfile)
    

    # Get Hsave to calculate its eigenvalues
    N_atoms = len(atom_list)
    Hsave = calculate_dispersion(atom_list,N_atoms_uc,N_atoms,jmats,showEigs=False)
    atom_list=atom_list[:N_atoms_uc]
    N_atoms = len(atom_list)
    N = N_atoms
    
    print "Calculated: Dispersion Relation"

    # Generate kappa's from (h,k,l)
    kaprange = []
    kapvect = []
    #if len(h_list) == len(k_list) == len(l_list):
        #for i in range(len(h_list)):
            #kappa = lattice.modvec(h_list[i],k_list[i],l_list[i], 'latticestar')
            #kaprange.append(kappa[0])
            #kapvect.append(np.array([h_list[i],k_list[i],l_list[i]]))
##            kapvect.append(np.array([h_list[i]/kappa,k_list[i]/kappa,l_list[i]/kappa]))
    #else:
        #raise Exception('h,k,l not same lengths')
    # Generate q's from kappa and tau
    kaprange=lattice.modvec(h_list,k_list,l_list, 'latticestar')
    nkpts=len(kaprange)
    kapvect=np.empty((nkpts,3),'Float64')
    kapvect[:,0]=h_list
    kapvect[:,1]=k_list
    kapvect[:,2]=l_list
#    print kapvect.shape
#    print kaprange.shape
    kapunit = kapvect.copy()
    kapunit[:,0]=kapvect[:,0]/kaprange
    kapunit[:,1]=kapvect[:,1]/kaprange
    kapunit[:,2]=kapvect[:,2]/kaprange
    #plusq=kappa-tau
    plusq=[]
    minusq=[]
    qlist=[]
    ones_list=np.ones((1,nkpts),'Float64')
    #wtlist=np.ones((1,nkpts*2),'Float64').flatten()
    wtlist=np.hstack([w_list,w_list])
    #weven=np.array(range(0,nkpts*2,2))
    #wodd=np.array(range(1,nkpts*2,2))
    #wtlist[wodd]=w_list
    #wtlist[weven]=w_list    
    qtlist=[]
    
    
    
    for tau in tau_list:
        taui=np.ones((nkpts,3),'Float64')
        taui[:,0]=ones_list*tau[0]
        taui[:,1]=ones_list*tau[1]
        taui[:,2]=ones_list*tau[2]
        kappa_minus_tau=kapvect-taui
        tau_minus_kappa=taui - kapvect
               
        qlist.append(np.vstack([kappa_minus_tau,tau_minus_kappa]))
    #calculate kfki
    nqpts=nkpts*2
    kfki=calc_kfki(w_list,eief,efixed)


    eig_list=[]
#    print qlist
    for q in qlist:
        #eigs = calc_eigs_direct(Hsave,q[:,0],q[:,1],q[:,2])
        eigs = Hsave.eigenvals().keys()
        eig_list.append(eigs)
    print "Calculated: Eigenvalues"
    
 #   print len(qlist)
 #   print len(eig_list[0])
#    sys.exit()
    # Grab Form Factors
#----Commented out 9/14/09 by Tom becuase of magnetic_ff error--------------
    #ff_list = []
    #s = sp.Symbol('s')
    #for i in range(N_atoms):
        #el = elements[atom_list[i].atomicNum]
        #val = atom_list[i].valence
        #if val != None:
            #Mq = el.magnetic_ff[val].M_Q(kaprange)
        #else:
            #Mq = el.magnetic_ff[0].M_Q(kaprange)
        #ff_list.append(Mq)
    #print "Calculated: Form Factors"
#--------------------------------------------------------------------------

    # Other Constants
    gamr0 = 2*0.2695e-12 #sp.Symbol('gamma', commutative = True)
    hbar = sp.S(1.0) # 1.05457148*10**(-34) #sp.Symbol('hbar', commutative = True)
    g = 2.#sp.Symbol('g', commutative = True)
    # Kappa vector
    kap = sp.Symbol('kappa', real = True)#spm.Matrix([sp.Symbol('kapx',real = True),sp.Symbol('kapy',real = True),sp.Symbol('kapz',real = True)])
    t = sp.Symbol('t', real = True)
    w = sp.Symbol('w', real = True)
    W = sp.Symbol('W', real = True)
    tau = sp.Symbol('tau', real = True)
    Q = sp.Symbol('q', real = True)
    L = sp.Symbol('L', real = True)
    lifetime=sp.Symbol('V',real=True)
    boltz = 8.617343e-2
    
    # Wilds for sub_in method
    A = sp.Wild('A',exclude = [0,t])
    B = sp.Wild('B',exclude = [0,t])
    C = sp.Wild('C')
    D = sp.Wild('D')
    K = sp.Wild('K')
    
    # Grabs the unit vectors from the back of the lists. 
    unit_vect = []
    kapxhat = sp.Symbol('kapxhat',real=True)
    kapyhat = sp.Symbol('kapyhat',real=True)
    kapzhat = sp.Symbol('kapzhat',real=True)
    for i in range(len(arg)):
        unit_vect.append(arg[i].pop())
    #print unit_vect
    unit_vect = sum(unit_vect)
    print unit_vect
    
    csection=0
    for i in range(len(arg)):
        for j in range(len(arg[i])):
            csection=csection+arg[i][j]*unit_vect
    
    print csection
    
 
    
    csection=sp.powsimp(csection)
    csection = (csection * exp(-I*w*t) * exp(I*kap*L)).expand(deep = False)
    print 'intermediate'
    #print csection
    csection= sp.powsimp(csection)
    csection = sub_in(csection,exp(I*t*A + I*t*B + I*C + I*D + I*K),sp.DiracDelta(A*t + B*t + C + D + K))
    csection = sub_in(csection,sp.DiracDelta(A*t + B*t + C*L + D*L ),sp.DiracDelta(A*hbar + B*hbar)*sp.simplify(sp.DiracDelta(C + D  - tau)))  #This is correct
    #csection = sub_in(csection,sp.DiracDelta(A*t + B*t + C*L + D*L ),sp.simplify(lifetime*sp.DiracDelta(C + D  - tau)*
                                                                                 #sp.Pow((A-B)**2+lifetime**2,-1)))
    print "Applied: Delta Function Conversion"
   # print csection
    print 'done'

    ## First the exponentials are turned into delta functions:
    #for i in range(len(arg)):
        #for j in range(N):
##            print '1', arg[i][j]
            #arg[i][j] = sp.powsimp(arg[i][j])#sp.powsimp(arg[i][j], deep = True, combine = 'all')
            #arg[i][j] = (arg[i][j] * exp(-I*w*t) * exp(I*kap*L)).expand()# * exp(I*inner_prod(spm.Matrix(atom_list[j].pos).T,kap))
            #arg[i][j] = sp.powsimp(arg[i][j])#sp.powsimp(arg[i][j], deep = True, combine = 'all')
##            print '2', arg[i][j]
            #arg[i][j] = sub_in(arg[i][j],exp(I*t*A + I*t*B + I*C + I*D + I*K),sp.DiracDelta(A*t + B*t + C + D + K))#*sp.DiracDelta(C))
##            print '3', arg[i][j]
            #arg[i][j] = sub_in(arg[i][j],sp.DiracDelta(A*t + B*t + C*L + D*L + K*L),sp.DiracDelta(A*hbar + B*hbar)*sp.simplify(sp.DiracDelta(C + D + K + tau)))
##            print '4', arg[i][j]
            #arg[i][j] = sub_in(arg[i][j],sp.DiracDelta(-A - B)*sp.DiracDelta(C),sp.DiracDelta(A + B)*sp.DiracDelta(C))
##            arg[i][j] = arg[i][j].subs(-w - wq, w + wq)
##            print '5', arg[i][j]
            
    print "Applied: Delta Function Conversion"

    # Subs the actual values for kx,ky,kz, omega_q and n_q into the operator combos
    # The result is basically a nested list:
    #
    #    csdata     = [ op combos ]
    #    op combos  = [ one combo per atom ]
    #    1 per atom = [ evaluated exp ]
    #
    csection=sub_in(csection,sp.DiracDelta(-A - B)*sp.DiracDelta(C),sp.DiracDelta(A + B)*sp.DiracDelta(C))

    print "end part 1"
    #print csection
    return (N_atoms_uc, csection, kaprange, qlist, tau_list, eig_list, kapvect, wtlist)
Example #3
0
def generate_cross_section(interactionfile, spinfile, lattice, arg, 
                       tau_list, h_list, k_list, l_list, w_list):
    """
    Calculates the cross_section given the following parameters:
    interactionfile, spinfile - files to get atom data
    lattice     - Lattice object from tripleaxisproject
    arg         - reduced list of operator combinations
    tau_list    - list of tau position
    w_list      - list of w's probed
    """

    # Read files, get atom_list and such
    atom_list, jnums, jmats,N_atoms_uc=readFiles(interactionfile,spinfile)
    
    # Get Hsave to calculate its eigenvalues
    N_atoms = len(atom_list)
    Hsave,poly,heigs = calculate_dispersion(atom_list,N_atoms_uc,N_atoms,jmats,showEigs=True)
    atom_list=atom_list[:N_atoms_uc]
    N_atoms = len(atom_list)
    N = N_atoms
    print "Calculated: Dispersion Relation"

    kaprange=lattice.modvec(h_list,k_list,l_list, 'latticestar')
    nkpts=len(kaprange)
    kapvect=np.empty((nkpts,3),'Float64')
    kapvect[:,0]=h_list
    kapvect[:,1]=k_list
    kapvect[:,2]=l_list

    kapunit = kapvect.copy()
    kapunit[:,0]=kapvect[:,0]/kaprange
    kapunit[:,1]=kapvect[:,1]/kaprange
    kapunit[:,2]=kapvect[:,2]/kaprange

    plusq=[]
    minusq=[]
    qlist=[]
    ones_list=np.ones((1,nkpts),'Float64')
    wtlist=w_list
    qtlist=[]
    
    for tau in tau_list:
        taui=np.ones((nkpts,3),'Float64')
        taui[:,0]=ones_list*tau[0]
        taui[:,1]=ones_list*tau[1]
        taui[:,2]=ones_list*tau[2]
        kappa_minus_tau=kapvect-taui
        tau_minus_kappa=taui - kapvect
               
        qlist.append(np.vstack([kappa_minus_tau,tau_minus_kappa]))

    eig_list=[]
    eigs = Hsave.eigenvals().keys()
    for q in qlist:
        eig_list.append(eigs)
    eig_list = np.array(eig_list)
    print "Calculated: Eigenvalues"

    # Other Constants
    kap = sp.Symbol('kappa', real = True)
    t = sp.Symbol('t', real = True)
    w = sp.Symbol('w', real = True)
    W = sp.Symbol('W', real = True)
    tau = sp.Symbol('tau', real = True)
    Q = sp.Symbol('q', real = True)
    L = sp.Symbol('L', real = True)
    lifetime=0.5

    # Form Factor
    ff_list = []
    for i in range(N_atoms_uc):
        el = elements[atom_list[i].atomicNum]
        val = atom_list[i].valence
        if val != None:
            Mq = el.magnetic_ff[val].M_Q(kaprange)
        else:
            Mq = el.magnetic_ff[0].M_Q(kaprange)
        ff_list = Mq #ff_list.append(Mq)
    print "Calculated: Form Factors"
  
    # Wilds for sub_in method
    A = sp.Wild('A',exclude = [0,t])
    B = sp.Wild('B',exclude = [0,t])
    C = sp.Wild('C')
    D = sp.Wild('D')
    
    # Grabs the unit vectors from the back of the lists. 
    unit_vect = []
    kapxhat = sp.Symbol('kapxhat',real=True)
    kapyhat = sp.Symbol('kapyhat',real=True)
    kapzhat = sp.Symbol('kapzhat',real=True)
    for i in range(len(arg)):
        unit_vect.append(arg[i].pop())
    unit_vect = sum(unit_vect)
    
    csection=0
    for i in range(len(arg)):
        for j in range(len(arg[i])):
            csection = (csection + arg[i][j]*unit_vect)
                
    for i in range(N):
        ni = sp.Symbol('n%i'%(i,), real = True)
        np1i = sp.Symbol('np1%i'%(i,), Real = True)
        csection.subs(ni+1,np1i)

    csection = csection.expand()
        
    csection = csection.subs(kapxhat*kapyhat,0)
    csection = csection.subs(kapxhat*kapzhat,0)
    csection = csection.subs(kapyhat*kapzhat,0)
    csection = csection.subs(kapzhat*kapyhat,0)
    csection = csection.subs(kapzhat*kapxhat,0)
    csection = csection.subs(kapyhat*kapxhat,0)
        
    csection = (csection * exp(-I*w*t) * exp(I*kap*L)).expand(deep=False)
    csection = sp.powsimp(csection, deep=True)
    print 'beginning delta conversion'
    print csection
    csection = sp.powsimp(csection)
    csection = sub_in(csection,exp(I*t*A + I*t*B + I*C + I*D + I*K),sp.DiracDelta(A*t + B*t + C + D + K))
    print 'intermediate'
    print csection
#    csection = sub_in(csection,sp.DiracDelta(A*t + B*t + C*L + D*L ),(1./hbar)*sp.DiracDelta(A + B)*sp.simplify(sp.DiracDelta(C + D  - tau)))  #This is correct
    csection = sub_in(csection,sp.DiracDelta(A*t + B*t + C*L + D*L ),sp.Pow(pi,-1)*(lifetime*0.5)*sp.Pow((A+B)**2+(lifetime*0.5)**2,-1)*sp.simplify(sp.DiracDelta(C + D  - tau)))
    print 'ending  delta conversion'
    print csection
    

    csection = sub_in(csection,sp.DiracDelta(-A - B),sp.DiracDelta(A + B))
    csection = sub_in(csection,(-A - B)**2,(A + B)**2)
    csection = csection.subs(sp.DiracDelta(Q+tau-kap),sp.DiracDelta(kap-Q-tau))
    csection = csection.subs(sp.DiracDelta(tau-kap-Q),sp.DiracDelta(kap+Q-tau))
    print "Applied: Delta Function Conversion"

    print "end part 1"
    #print csection
    return (N_atoms_uc, csection, kaprange, tau_list, eig_list, kapvect, wtlist, ff_list)
Example #4
0
def eval_cross_section(N_atoms_uc, csection, kaprange, qlist, tau_list,
                       eig_list, kapvect, wtlist):
    print "begin part 2"

    gamr0 = 2 * 0.2695e-12  #sp.Symbol('gamma', commutative = True)
    hbar = sp.S(
        1.0)  # 1.05457148*10**(-34) #sp.Symbol('hbar', commutative = True)
    g = 2.  #sp.Symbol('g', commutative = True)
    # Kappa vector
    kap = sp.Symbol(
        'kappa', real=True
    )  #spm.Matrix([sp.Symbol('kapx',real = True),sp.Symbol('kapy',real = True),sp.Symbol('kapz',real = True)])
    t = sp.Symbol('t', real=True)
    w = sp.Symbol('w', real=True)
    W = sp.Symbol('W', real=True)
    tau = sp.Symbol('tau', real=True)
    Q = sp.Symbol('q', real=True)
    L = sp.Symbol('L', real=True)
    lifetime = sp.Symbol('V', real=True)
    boltz = 8.617343e-2
    kapxhat = sp.Symbol('kapxhat', real=True)
    kapyhat = sp.Symbol('kapyhat', real=True)
    kapzhat = sp.Symbol('kapzhat', real=True)

    kapunit = kapvect.copy()
    kapunit[:, 0] = kapvect[:, 0] / kaprange
    kapunit[:, 1] = kapvect[:, 1] / kaprange
    kapunit[:, 2] = kapvect[:, 2] / kaprange

    nkpts = len(kaprange)
    nqpts = 2 * nkpts

    csdata = []
    wq = sp.Symbol('wq', real=True)

    for k in range(len(tau_list)):
        temp1 = []
        for g in range(nqpts):
            temp2 = []
            for i in range(len(eig_list[k][g])):
                #temp = eval_it(k,g,i,nkpts,csection)
                temp = csection

                for num in range(N_atoms_uc):
                    nq = sp.Symbol('n%i' % (num, ), real=True)
                    #n = sp.Pow( sp.exp(-np.abs(eig_list[k][g][i])/boltz/temperature) - 1 ,-1)
                    n = sp.S(0.0)
                    temp = temp.subs(nq, n)

                #if g==0:
                if g < nkpts:
                    value = kapvect[g] - tau_list[k] - qlist[k][g]
                    if eq(value[0], 0) == 0 and eq(value[1], 0) == 0 and eq(
                            value[2], 0) == 0:
                        temp = temp.subs(sp.DiracDelta(kap - tau - Q), sp.S(1))
                        temp = temp.subs(sp.DiracDelta(-kap + tau + Q), sp.S(
                            1))  # recall that the delta function is symmetric
                    else:
                        temp = temp.subs(sp.DiracDelta(kap - tau - Q), sp.S(0))
                        temp = temp.subs(sp.DiracDelta(-kap + tau + Q),
                                         sp.S(0))
                    temp = temp.subs(kapxhat, kapunit[g, 0])
                    temp = temp.subs(kapyhat, kapunit[g, 1])
                    temp = temp.subs(kapzhat, kapunit[g, 2])
                #value =kapvect[g//2]- tau_list[k] + qlist[k][g]
                #if g%2!=0:
                elif g >= nkpts:
                    value = kapvect[g - nkpts] - tau_list[k] - qlist[k][g]
                    if eq(value[0], 0) == 0 and eq(value[1], 0) == 0 and eq(
                            value[2], 0) == 0:
                        temp = temp.subs(sp.DiracDelta(kap - tau + Q), sp.S(1))
                        temp = temp.subs(sp.DiracDelta(-kap + tau - Q),
                                         sp.S(1))
                    else:
                        temp = temp.subs(sp.DiracDelta(kap - tau + Q), sp.S(0))
                        temp = temp.subs(sp.DiracDelta(-kap + tau - Q),
                                         sp.S(0))
                    temp = temp.subs(kapxhat, kapunit[g - nkpts, 0])
                    temp = temp.subs(kapyhat, kapunit[g - nkpts, 1])
                    temp = temp.subs(kapzhat, kapunit[g - nkpts, 2])
                value = tau_list[k]
                if eq(value[0], 0) == 0 and eq(value[1], 0) == 0 and eq(
                        value[2], 0) == 0:
                    temp = temp.subs(sp.DiracDelta(kap - tau - Q), sp.S(1))
                    temp = temp.subs(sp.DiracDelta(-kap + tau + Q), sp.S(1))  #
                    temp = temp.subs(sp.DiracDelta(kap - tau + Q), sp.S(1))
                    temp = temp.subs(sp.DiracDelta(-kap + tau - Q), sp.S(1))

                #temp = temp.subs(kapxhat,kapunit[g//2,0])
                #temp = temp.subs(kapyhat,kapunit[g//2,1])
                #temp = temp.subs(kapzhat,kapunit[g//2,2])

                value = eig_list[k][g][i] - wtlist[g]
                #print '1',temp
                temp = temp.subs(wq, eig_list[k][g][i])

                temp = temp.subs(w, wtlist[g])
                if 0:
                    if eq(value, 0) == 0:
                        temp = temp.subs(sp.DiracDelta(wq - w), sp.S(1))
                    else:
                        temp = temp.subs(sp.DiracDelta(wq - w), sp.S(0))
                if 0:
                    if eq(eig_list[k][g][i], wtlist[g]) == 0:
                        G = sp.Wild('G', exclude=[Q, kap, tau, w])
                        temp = sub_in(temp, sp.DiracDelta(G - A * w), sp.S(1))
                    elif eq(eig_list[k][g][i], -wtlist[g]) == 0:
                        G = sp.Wild('G', exclude=[Q, kap, tau, w])
                        temp = sub_in(temp, sp.DiracDelta(G - A * w), sp.S(1))
                    else:
                        temp = temp.subs(w, wtlist[g])

#                print '4',temp
                temp2.append(temp)
            temp1.append(temp2)
        csdata.append(temp1)

    #print csdata

    # Front constants and stuff for the cross-section
    front_constant = 1.0  #(gamr0)**2#/(2*pi*hbar)
    front_func = (1. / 2.) * g  #*F(k)
    debye_waller = 1.  #exp(-2*W)

    cstemp = []
    for g in range(nqpts):
        for k in range(len(tau_list)):
            cstemp.append(csdata[k][g][0].subs(lifetime, sp.S(.1)))

    print cstemp
    sys.exit()

    qtlist = np.array(qlist, 'Float64').reshape((nqpts * len(tau_list), 3))[:,
                                                                            0]
    xi = qtlist
    yi = wtlist
    zi = np.array(cstemp, 'Float64')
    Z = matplotlib.mlab.griddata(xi, yi, zi, xi, yi)
    zmin, zmax = np.min(Z), np.max(Z)
    locator = ticker.MaxNLocator(10)  # if you want no more than 10 contours
    locator.create_dummy_axis()
    locator.set_bounds(zmin, zmax)
    levs = locator()
    levs[0] = 1.0
    print zmin, zmax
    #zm=ma.masked_where(Z<=0,Z)
    zm = Z
    print zm
    print levs
    plt.contourf(
        xi, yi, Z,
        levs)  #, norm=matplotlib.colors.LogNorm(levs[0],levs[len(levs)-1]))
    l_f = ticker.LogFormatter(10, labelOnlyBase=False)
    cbar = plt.colorbar(ticks=levs, format=l_f)
    plt.show()
Example #5
0
def generate_cross_section(interactionfile,
                           spinfile,
                           lattice,
                           arg,
                           tau_list,
                           h_list,
                           k_list,
                           l_list,
                           w_list,
                           temperature,
                           steps,
                           eief,
                           efixed=14.7):
    """
    Calculates the cross_section given the following parameters:
    interactionfile, spinfile - files to get atom data
    lattice     - Lattice object from tripleaxisproject
    arg         - reduced list of operator combinations
    tau_list    - list of tau position
    w_list      - list of w's probed
    temp        - temperature
    kmin        - minimum value of k to scan
    kmax        - maximum value of k to scan
    steps       - number of steps between kmin, kmax
    eief        - True if fixed Ef
    efixed      - value of the fixed energy, either Ei or Ef
    """

    # Read files, get atom_list and such
    atom_list, jnums, jmats, N_atoms_uc = readFiles(interactionfile, spinfile)

    # Get Hsave to calculate its eigenvalues
    N_atoms = len(atom_list)
    Hsave = calculate_dispersion(atom_list,
                                 N_atoms_uc,
                                 N_atoms,
                                 jmats,
                                 showEigs=False)
    atom_list = atom_list[:N_atoms_uc]
    N_atoms = len(atom_list)
    N = N_atoms

    print "Calculated: Dispersion Relation"

    # Generate kappa's from (h,k,l)
    kaprange = []
    kapvect = []
    #if len(h_list) == len(k_list) == len(l_list):
    #for i in range(len(h_list)):
    #kappa = lattice.modvec(h_list[i],k_list[i],l_list[i], 'latticestar')
    #kaprange.append(kappa[0])
    #kapvect.append(np.array([h_list[i],k_list[i],l_list[i]]))
    ##            kapvect.append(np.array([h_list[i]/kappa,k_list[i]/kappa,l_list[i]/kappa]))
    #else:
    #raise Exception('h,k,l not same lengths')
    # Generate q's from kappa and tau
    kaprange = lattice.modvec(h_list, k_list, l_list, 'latticestar')
    nkpts = len(kaprange)
    kapvect = np.empty((nkpts, 3), 'Float64')
    kapvect[:, 0] = h_list
    kapvect[:, 1] = k_list
    kapvect[:, 2] = l_list
    #    print kapvect.shape
    #    print kaprange.shape
    kapunit = kapvect.copy()
    kapunit[:, 0] = kapvect[:, 0] / kaprange
    kapunit[:, 1] = kapvect[:, 1] / kaprange
    kapunit[:, 2] = kapvect[:, 2] / kaprange
    #plusq=kappa-tau
    plusq = []
    minusq = []
    qlist = []
    ones_list = np.ones((1, nkpts), 'Float64')
    #wtlist=np.ones((1,nkpts*2),'Float64').flatten()
    wtlist = np.hstack([w_list, w_list])
    #weven=np.array(range(0,nkpts*2,2))
    #wodd=np.array(range(1,nkpts*2,2))
    #wtlist[wodd]=w_list
    #wtlist[weven]=w_list
    qtlist = []

    for tau in tau_list:
        taui = np.ones((nkpts, 3), 'Float64')
        taui[:, 0] = ones_list * tau[0]
        taui[:, 1] = ones_list * tau[1]
        taui[:, 2] = ones_list * tau[2]
        kappa_minus_tau = kapvect - taui
        tau_minus_kappa = taui - kapvect

        qlist.append(np.vstack([kappa_minus_tau, tau_minus_kappa]))
    #calculate kfki
    nqpts = nkpts * 2
    kfki = calc_kfki(w_list, eief, efixed)

    eig_list = []
    #    print qlist
    for q in qlist:
        #eigs = calc_eigs_direct(Hsave,q[:,0],q[:,1],q[:,2])
        eigs = Hsave.eigenvals().keys()
        eig_list.append(eigs)
    print "Calculated: Eigenvalues"

    #   print len(qlist)
    #   print len(eig_list[0])
    #    sys.exit()
    # Grab Form Factors
    #----Commented out 9/14/09 by Tom becuase of magnetic_ff error--------------
    #ff_list = []
    #s = sp.Symbol('s')
    #for i in range(N_atoms):
    #el = elements[atom_list[i].atomicNum]
    #val = atom_list[i].valence
    #if val != None:
    #Mq = el.magnetic_ff[val].M_Q(kaprange)
    #else:
    #Mq = el.magnetic_ff[0].M_Q(kaprange)
    #ff_list.append(Mq)
    #print "Calculated: Form Factors"
    #--------------------------------------------------------------------------

    # Other Constants
    gamr0 = 2 * 0.2695e-12  #sp.Symbol('gamma', commutative = True)
    hbar = sp.S(
        1.0)  # 1.05457148*10**(-34) #sp.Symbol('hbar', commutative = True)
    g = 2.  #sp.Symbol('g', commutative = True)
    # Kappa vector
    kap = sp.Symbol(
        'kappa', real=True
    )  #spm.Matrix([sp.Symbol('kapx',real = True),sp.Symbol('kapy',real = True),sp.Symbol('kapz',real = True)])
    t = sp.Symbol('t', real=True)
    w = sp.Symbol('w', real=True)
    W = sp.Symbol('W', real=True)
    tau = sp.Symbol('tau', real=True)
    Q = sp.Symbol('q', real=True)
    L = sp.Symbol('L', real=True)
    lifetime = sp.Symbol('V', real=True)
    boltz = 8.617343e-2

    # Wilds for sub_in method
    A = sp.Wild('A', exclude=[0, t])
    B = sp.Wild('B', exclude=[0, t])
    C = sp.Wild('C')
    D = sp.Wild('D')
    K = sp.Wild('K')

    # Grabs the unit vectors from the back of the lists.
    unit_vect = []
    kapxhat = sp.Symbol('kapxhat', real=True)
    kapyhat = sp.Symbol('kapyhat', real=True)
    kapzhat = sp.Symbol('kapzhat', real=True)
    for i in range(len(arg)):
        unit_vect.append(arg[i].pop())
    #print unit_vect
    unit_vect = sum(unit_vect)
    print unit_vect

    csection = 0
    for i in range(len(arg)):
        for j in range(len(arg[i])):
            csection = csection + arg[i][j] * unit_vect

    print csection

    csection = sp.powsimp(csection)
    csection = (csection * exp(-I * w * t) *
                exp(I * kap * L)).expand(deep=False)
    print 'intermediate'
    #print csection
    csection = sp.powsimp(csection)
    csection = sub_in(csection,
                      exp(I * t * A + I * t * B + I * C + I * D + I * K),
                      sp.DiracDelta(A * t + B * t + C + D + K))
    csection = sub_in(
        csection, sp.DiracDelta(A * t + B * t + C * L + D * L),
        sp.DiracDelta(A * hbar + B * hbar) *
        sp.simplify(sp.DiracDelta(C + D - tau)))  #This is correct
    #csection = sub_in(csection,sp.DiracDelta(A*t + B*t + C*L + D*L ),sp.simplify(lifetime*sp.DiracDelta(C + D  - tau)*
    #sp.Pow((A-B)**2+lifetime**2,-1)))
    print "Applied: Delta Function Conversion"
    # print csection
    print 'done'

    ## First the exponentials are turned into delta functions:
    #for i in range(len(arg)):
    #for j in range(N):
    ##            print '1', arg[i][j]
    #arg[i][j] = sp.powsimp(arg[i][j])#sp.powsimp(arg[i][j], deep = True, combine = 'all')
    #arg[i][j] = (arg[i][j] * exp(-I*w*t) * exp(I*kap*L)).expand()# * exp(I*inner_prod(spm.Matrix(atom_list[j].pos).T,kap))
    #arg[i][j] = sp.powsimp(arg[i][j])#sp.powsimp(arg[i][j], deep = True, combine = 'all')
    ##            print '2', arg[i][j]
    #arg[i][j] = sub_in(arg[i][j],exp(I*t*A + I*t*B + I*C + I*D + I*K),sp.DiracDelta(A*t + B*t + C + D + K))#*sp.DiracDelta(C))
    ##            print '3', arg[i][j]
    #arg[i][j] = sub_in(arg[i][j],sp.DiracDelta(A*t + B*t + C*L + D*L + K*L),sp.DiracDelta(A*hbar + B*hbar)*sp.simplify(sp.DiracDelta(C + D + K + tau)))
    ##            print '4', arg[i][j]
    #arg[i][j] = sub_in(arg[i][j],sp.DiracDelta(-A - B)*sp.DiracDelta(C),sp.DiracDelta(A + B)*sp.DiracDelta(C))
    ##            arg[i][j] = arg[i][j].subs(-w - wq, w + wq)
    ##            print '5', arg[i][j]

    print "Applied: Delta Function Conversion"

    # Subs the actual values for kx,ky,kz, omega_q and n_q into the operator combos
    # The result is basically a nested list:
    #
    #    csdata     = [ op combos ]
    #    op combos  = [ one combo per atom ]
    #    1 per atom = [ evaluated exp ]
    #
    csection = sub_in(csection,
                      sp.DiracDelta(-A - B) * sp.DiracDelta(C),
                      sp.DiracDelta(A + B) * sp.DiracDelta(C))

    print "end part 1"
    #print csection
    return (N_atoms_uc, csection, kaprange, qlist, tau_list, eig_list, kapvect,
            wtlist)
def generate_cross_section(interactionfile, spinfile, lattice, arg, 
                       tau_list, h_list, k_list, l_list, w_list):
    """
    Calculates the cross_section given the following parameters:
    interactionfile, spinfile - files to get atom data
    lattice     - Lattice object from tripleaxisproject
    arg         - reduced list of operator combinations
    tau_list    - list of tau position
    w_list      - list of w's probed
    """

    # Read files, get atom_list and such
    atom_list, jnums, jmats,N_atoms_uc=readFiles(interactionfile,spinfile)

    # Get Hsave to calculate its eigenvalues
    N_atoms = len(atom_list)
    Hsave,poly,heigs = calculate_dispersion(atom_list,N_atoms_uc,N_atoms,jmats,showEigs=True)
    atom_list=atom_list[:N_atoms_uc]
    N_atoms = len(atom_list)
    N = N_atoms
    
    print "Calculated: Dispersion Relation"

    # Generate kappas from (h,k,l)
    kaprange=lattice.modvec(h_list,k_list,l_list, 'latticestar')
    nkpts=len(kaprange)
    kapvect=np.empty((nkpts,3),'Float64')
    kapvect[:,0]=h_list
    kapvect[:,1]=k_list
    kapvect[:,2]=l_list

    # Grabs the unit vectors from the back of the lists. 
    kapunit = kapvect.copy()
    kapunit[:,0]=kapvect[:,0]/kaprange
    kapunit[:,1]=kapvect[:,1]/kaprange
    kapunit[:,2]=kapvect[:,2]/kaprange

    unit_vect = []
    for i in range(len(arg)):
        unit_vect.append(arg[i].pop())
    #print unit_vect
    unit_vect = sum(unit_vect)

    # Generate qs from kappas and taus
    qlist=[]
    ones_list=np.ones((1,nkpts),'Float64')
    
    for tau in tau_list:
        taui=np.ones((nkpts,3),'Float64')
        taui[:,0]=ones_list*tau[0]
        taui[:,1]=ones_list*tau[1]
        taui[:,2]=ones_list*tau[2]
        kappa_minus_tau=kapvect-taui
        tau_minus_kappa=taui - kapvect
               
        qlist.append(np.vstack([kappa_minus_tau,tau_minus_kappa]))

    # Eigenvalues and omegas
    wtlist=w_list
    eig_list=[]

    eigs = Hsave.eigenvals().keys()
    for q in qlist:
        eig_list.append(eigs)
    eig_list = np.array(eig_list)
    print "Calculated: Eigenvalues"

    # Form Factor
    ff_list = []
    for i in range(N_atoms_uc):
        el = elements[atom_list[i].atomicNum]
        val = atom_list[i].valence
        if val != None:
            Mq = el.magnetic_ff[val].M_Q(kaprange)
        else:
            Mq = el.magnetic_ff[0].M_Q(kaprange)
        ff_list = Mq #ff_list.append(Mq)
    print "Calculated: Form Factors"
    
    # Generate most general form of csection
    csection=0
    for i in range(len(arg)):
        for j in range(len(arg[i])):
            csection = (csection + arg[i][j]*unit_vect)
                
    for i in range(N):
        ni = sp.Symbol('n%i'%(i,), real = True)
        np1i = sp.Symbol('np1%i'%(i,), Real = True)
        csection.subs(ni+1,np1i)

    csection = csection.expand()

    csection = csection.subs(KAPXHAT_SYM*KAPYHAT_SYM,0)
    csection = csection.subs(KAPXHAT_SYM*KAPZHAT_SYM,0)
    csection = csection.subs(KAPYHAT_SYM*KAPZHAT_SYM,0)
    csection = csection.subs(KAPZHAT_SYM*KAPYHAT_SYM,0)
    csection = csection.subs(KAPZHAT_SYM*KAPXHAT_SYM,0)
    csection = csection.subs(KAPYHAT_SYM*KAPXHAT_SYM,0)
        
    csection = (csection * exp(-I * W_SYM * T_SYM) * exp(I * KAP_SYM * L_SYM)).expand(deep=False)
    csection = sp.powsimp(csection, deep=True)
    print 'beginning'
#    print csection
    csection = sp.powsimp(csection)
    csection = sub_in(csection,exp(I*T_SYM*A_WILD + I*T_SYM*B_WILD + I*C_WILD + I*D_WILD + I*K_WILD),sp.DiracDelta(A_WILD*T_SYM + B_WILD*T_SYM + C_WILD + D_WILD + K_WILD))
    print 'intermediate'
#    print csection
#    csection = sub_in(csection,sp.DiracDelta(A*t + B*t + C*L + D*L ),(1./hbar)*sp.DiracDelta(A + B)*sp.simplify(sp.DiracDelta(C + D  - tau)))  #This is correct
    csection = sub_in(csection,sp.DiracDelta(A_WILD*T_SYM + B_WILD*T_SYM + C_WILD*L_SYM + D_WILD*L_SYM ),sp.Pow(pi,-1)*(LIFETIME_VALUE*0.5)*sp.Pow((A_WILD+B_WILD)**2+(LIFETIME_VALUE*0.5)**2,-1)*sp.simplify(sp.DiracDelta(C_WILD + D_WILD  - TAU_SYM)))
    print 'ending'
#    print csection
    
    # Do some associative clean up to make it easier for later substitutions
    csection = sub_in(csection,sp.DiracDelta(-A_WILD - B_WILD),sp.DiracDelta(A_WILD + B_WILD))
    csection = sub_in(csection,(-A_WILD - B_WILD)**2,(A_WILD + B_WILD)**2)
    csection = csection.subs(sp.DiracDelta(Q_SYM + TAU_SYM - KAP_SYM),sp.DiracDelta(KAP_SYM - Q_SYM - TAU_SYM))
    csection = csection.subs(sp.DiracDelta(TAU_SYM - KAP_SYM - Q_SYM),sp.DiracDelta(KAP_SYM + Q_SYM - TAU_SYM))

    csection = csection.subs(sp.DiracDelta(KAP_SYM - Q_SYM - TAU_SYM),DD_KTMQ_SYM)
    csection = csection.subs(sp.DiracDelta(KAP_SYM + Q_SYM - TAU_SYM),DD_KTPQ_SYM)
    print "Applied: Delta Function Conversion"
    
    print csection
    
    print "Generated: Analytic Cross-Section Expression"
    return (N_atoms_uc, csection, kaprange, tau_list, eig_list, kapvect, wtlist, ff_list)