def rotateVectorAroundNormal(point, n, angle, turnAroundPoint = [0.0, 0.0, 0.0]): p = matrices.Matrix(4, 1,(point[0],point[1],point[2],1.0)) mul = matrices.Matrix(( [n[0]*n[0] + (n[1]*n[1] + n[2]*n[2])*math.cos(angle), n[0]*n[1]*(1.0-math.cos(angle)) - n[2]*math.sin(angle), n[0]*n[2]*(1.0-math.cos(angle)) + n[1]*math.sin(angle), 0.0], [n[0]*n[1]*(1.0 - math.cos(angle)) + n[2]*math.sin(angle), n[1]*n[1] + (n[0]*n[0] + n[2]*n[2])*math.cos(angle), n[1]*n[2]*(1.0-math.cos(angle)) - n[0]*math.sin(angle), 0.0], [n[0]*n[2]*(1.0 - math.cos(angle)) - n[1]*math.sin(angle), n[1]*n[2]*(1.0 - math.cos(angle)) - n[0]*math.sin(angle), n[2]*n[2] + (n[0]*n[0]+n[1]*n[1])*math.cos(angle), 0.0], [0.0, 0.0, 0.0, 1.0])) res = mul.multiply(p) return res[:3]
def generate_Sx_Sy_Sz_operators(atom_list, Sa_list, Sb_list, Sn_list): """Generates Sx, Sy and Sz operators""" Sx_list = [] Sy_list = [] Sz_list = [] N = len(atom_list) S = sp.Symbol('S', commutative=True) for i in range(N): rotmat = sp.Matrix(atom_list[i].spinRmatrix) loc_vect = spm.Matrix([Sa_list[i], Sb_list[i], Sn_list[i]]) loc_vect = loc_vect.reshape(3, 1) glo_vect = rotmat * loc_vect Sx = sp.powsimp(glo_vect[0].expand()) Sy = sp.powsimp(glo_vect[1].expand()) Sz = sp.powsimp(glo_vect[2].expand()) Sx_list.append(Sx) Sy_list.append(Sy) Sz_list.append(Sz) #Unit vector markers kapxhat = sp.Symbol('kapxhat', commutative=False) #spm.Matrix([1,0,0])# kapyhat = sp.Symbol('kapyhat', commutative=False) #spm.Matrix([0,1,0])# kapzhat = sp.Symbol('kapzhat', commutative=False) #spm.Matrix([0,0,1])# Sx_list.append(kapxhat) Sy_list.append(kapyhat) Sz_list.append(kapzhat) print "Operators Generated: Sx, Sy, Sz" return (Sx_list, Sy_list, Sz_list)
def inner_prod(vect1, vect2, ten=spm.Matrix([[1, 0, 0], [0, 1, 0], [0, 0, 1]])): # For column vectors - make sure vectors match eachother as well as # of rows in tensor if vect1.shape == vect2.shape == (3, 1) == (ten.lines, 1): return (vect1.T * ten * vect2)[0] # For row vectors - make sure vectors match eachother as well as # of cols in tensor elif vect1.shape == vect2.shape == (1, 3) == (1, ten.cols): return (vect1 * ten * vect2.T)[0] # Everything else else: return None
def run_cross_section(interactionfile, spinfile): start = clock() # Generate Inputs atom_list, jnums, jmats, N_atoms_uc = readFiles(interactionfile, spinfile) atom1 = atom(pos=[0.00, 0, 0], neighbors=[1], interactions=[0], int_cell=[0], atomicNum=26, valence=3) atom2 = atom(pos=[0.25, 0, 0], neighbors=[0, 2], interactions=[0], int_cell=[0], atomicNum=26, valence=3) atom3 = atom(pos=[0.50, 0, 0], neighbors=[1, 3], interactions=[0], int_cell=[0], atomicNum=26, valence=3) atom4 = atom(pos=[0.75, 0, 0], neighbors=[2], interactions=[0], int_cell=[0], atomicNum=26, valence=3) # atom_list,N_atoms_uc = ([atom1, atom2, atom3, atom4],1) N_atoms = len(atom_list) print N_atoms if 1: kx = sp.Symbol('kx', real=True, commutative=True) ky = sp.Symbol('ky', real=True, commutative=True) kz = sp.Symbol('kz', real=True, commutative=True) k = spm.Matrix([kx, ky, kz]) (b, bd) = generate_b_bd_operators(atom_list) # list_print(b) (a, ad) = generate_a_ad_operators(atom_list, k, b, bd) list_print(a) (Sp, Sm) = generate_Sp_Sm_operators(atom_list, a, ad) list_print(Sp) (Sa, Sb, Sn) = generate_Sa_Sb_Sn_operators(atom_list, Sp, Sm) # list_print(Sa) (Sx, Sy, Sz) = generate_Sx_Sy_Sz_operators(atom_list, Sa, Sb, Sn) list_print(Sx) print '' #Ham = generate_Hamiltonian(N_atoms, atom_list, b, bd) ops = generate_possible_combinations(atom_list, [Sx, Sy, Sz]) # list_print(ops) ops = holstein(atom_list, ops) # list_print(ops) ops = apply_commutation(atom_list, ops) # list_print(ops) ops = replace_bdb(atom_list, ops) # list_print(ops) ops = reduce_options(atom_list, ops) list_print(ops) # Old Method #cross_sect = generate_cross_section(atom_list, ops, 1, real, recip) #print '\n', cross_sect if 1: aa = bb = cc = np.array([2.0 * np.pi], 'Float64') alpha = beta = gamma = np.array([np.pi / 2.0], 'Float64') vect1 = np.array([[1, 0, 0]]) vect2 = np.array([[0, 0, 1]]) lattice = Lattice(aa, bb, cc, alpha, beta, gamma, Orientation(vect1, vect2)) data = {} data['kx'] = 1. data['ky'] = 0. data['kz'] = 0. direction = data temperature = 100.0 min = 0 max = 2 * sp.pi steps = 25 tau_list = [] for i in range(1): tau_list.append(np.array([0, 0, 0], 'Float64')) h_list = np.linspace(0, 2, 100) k_list = np.zeros(h_list.shape) l_list = np.zeros(h_list.shape) w_list = np.linspace(-4, 4, 100) efixed = 14.7 #meV eief = True eval_cross_section(interactionfile, spinfile, lattice, ops, tau_list, h_list, k_list, l_list, w_list, data, temperature, min, max, steps, eief, efixed) end = clock() print "\nFinished %i atoms in %.2f seconds" % (N_atoms, end - start)
def generate_cross_section(atom_list, arg, q, real_list, recip_list): """Generates the Cross-Section Formula for the one magnon case""" N = len(atom_list) gam = 1.913 #sp.Symbol('gamma', commutative = True) r = sp.Symbol('r0', commutative=True) h = 1. # 1.05457148*10**(-34) #sp.Symbol('hbar', commutative = True) k = sp.Symbol('k', commutative=True) kp = sp.Symbol('kp', commutative=True) g = sp.Symbol('g', commutative=True) F = sp.Function('F') def FF(arg): F = sp.Function('F') if arg.shape == (3, 1) or arg.shape == (1, 3): return sp.Symbol("%r" % (F(arg.tolist()), ), commutative=False) kap = spm.Matrix([ sp.Symbol('kapx', commutative=False), sp.Symbol('kapy', commutative=False), sp.Symbol('kapz', commutative=False) ]) t = sp.Symbol('t', commutative=True) w = sp.Symbol('w', commutative=True) W = sp.Symbol('W', commutative=False) kappa = sp.Symbol('kappa', commutative=False) tau = sp.Symbol('tau', commutative=False) # Wilds for sub_in method A = sp.Wild('A', exclude=[0]) B = sp.Wild('B', exclude=[0]) C = sp.Wild('C') D = sp.Wild('D') front_constant = (gam * r)**2 / (2 * pi * h) * (kp / k) * N front_func = (1. / 2.) * g #*F(k) vanderwaals = exp(-2 * W) temp2 = [] temp3 = [] temp4 = [] # Grabs the unit vectors from the back of the lists. unit_vect = [] kapx = sp.Symbol('kapxhat', ) kapy = sp.Symbol('kapyhat', commutative=False) kapz = sp.Symbol('kapzhat', commutative=False) for i in range(len(arg)): unit_vect.append(arg[i].pop()) # for ele in unit_vect: # ele = ele.subs(kapx,spm.Matrix([1,0,0])) # ele = ele.subs(kapy,spm.Matrix([0,1,0])) # ele = ele.subs(kapz,spm.Matrix([0,0,1])) # This is were the heart of the calculation comes in. # First the exponentials are turned into delta functions: for i in range(len(arg)): for j in range(N): arg[i][j] = sp.powsimp(arg[i][j], deep=True, combine='all') arg[i][j] = arg[i][j] * exp(-I * w * t) * exp( I * inner_prod(spm.Matrix(atom_list[j].pos).T, kap)) arg[i][j] = sp.powsimp(arg[i][j], deep=True, combine='all') arg[i][j] = sub_in(arg[i][j], exp(I * t * A + I * t * B + C), sp.DiracDelta(A * t + B * t + C / I)) #*sp.DiracDelta(C)) arg[i][j] = sub_in( arg[i][j], sp.DiracDelta(A * t + B * t + C), sp.DiracDelta(A * h + B * h) * sp.DiracDelta(C + tau)) arg[i][j] = sub_in(arg[i][j], sp.DiracDelta(-A - B), sp.DiracDelta(A + B)) print arg[i][j] print "Applied: Delta Function Conversion" # for ele in arg: # for subele in ele: # temp2.append(subele) # temp3.append(sum(temp2)) # # for i in range(len(temp3)): # temp4.append(unit_vect[i] * temp3[i]) for k in range(len(arg)): temp4.append(arg[k][q]) dif = (front_func**2 * front_constant * vanderwaals * sum(temp4) ) #.expand()#sp.simplify(sum(temp4))).expand() print "Complete: Cross-section Calculation" return dif
import sympy as sy import sympy.matrices as syma d = 2 rho = sy.Symbol("rho") rhouvec = [sy.Symbol("rho" + chr(ord("u") + i)) for i in range(d)] uvec = [rhou_i / rho for rhou_i in rhouvec] E = sy.Symbol("E") p = sy.Symbol("p") gamma = sy.Symbol("gamma") p_solved = sy.solve( -E + p / (gamma - 1) + rho / 2 * sum(uvec[i]**2 for i in range(d)), p)[0] print p_solved flux_rho = syma.Matrix(1, d, [rho * uvec[i] for i in range(d)]) flux_E = syma.Matrix(1, d, [(E + p_solved) * uvec[i] for i in range(d)]) flux_rho_u = syma.Matrix(1, d, [(E + p_solved) * uvec[i] for i in range(d)]) print flux_E
def P(tp, pi, ti): p0 = smm.Matrix([1, 0, 0]) R_i = R(0, -ti, -pi) * R_z(tp) return R_i * p0
def R_z(alpha): return smm.Matrix([[sm.cos(alpha), -sm.sin(alpha), 0], [sm.sin(alpha), sm.cos(alpha), 0], [0, 0, 1]])
def R_y(alpha): return smm.Matrix([[sm.cos(alpha), 0, sm.sin(alpha)], [0, 1, 0], [-sm.sin(alpha), 0, sm.cos(alpha)]])
def R_x(alpha): return smm.Matrix([[1, 0, 0], [0, sm.cos(alpha), -sm.sin(alpha)], [0, sm.sin(alpha), sm.cos(alpha)]])
import mpmath import sys import numpy as np import matplotlib.pyplot as plt init_printing(use_unicode=True, wrap_line=False) sys.modules['sympy.mpmath'] = mpmath component = 'VH' a, b, c, d, p, t = sm.symbols(r'a b c d \phi \theta') # symbol matrices # si A_1 = smm.Matrix([[a, 0, 0], [0, a, 0], [0, 0, a]]) E1 = smm.Matrix([[b, 0, 0], [0, b, 0], [0, 0, -2 * b]]) E2 = smm.Matrix([[-sm.sqrt(3) * b, 0, 0], [0, sm.sqrt(3) * b, 0], [0, 0, 0]]) T_2x = smm.Matrix([[0, 0, 0], [0, 0, d], [0, d, 0]]) T_2y = smm.Matrix([[0, 0, d], [0, 0, 0], [d, 0, 0]]) T_2z = smm.Matrix([[0, d, 0], [d, 0, 0], [0, 0, 0]]) # grf/hbn A1g = smm.Matrix([[a, 0, 0], [0, a, 0], [0, 0, b]]) E2g1 = smm.Matrix([[0, -d, 0], [-d, 0, 0], [0, 0, 0]])