def square(anti = False): ats = [rf.atom() for i in range(5)] spin = rf.findmat(N.array([0,0,1])) # Positions # 0 1 2 3 4 pstn = [[0,0,0],[0,1,0],[1,0,0],[0,-1,0],[-1,0,0]] # Neighbors # 0 1 2 3 4 nbrs = [[1,2,3,4],[0],[0],[0],[0]] # Interactions # 0 1 2 3 4 ints = [[0,1,2,3],[0],[1],[2],[3]] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 if anti == True: spin = rf.findmat(N.array([0,0,-1])) ats[0].spinMagnitude = 1 ats[0].spinRmatrix = spin return ats
def square(anti=False): ats = [rf.atom() for i in range(5)] spin = rf.findmat(N.array([0, 0, 1])) # Positions # 0 1 2 3 4 pstn = [[0, 0, 0], [0, 1, 0], [1, 0, 0], [0, -1, 0], [-1, 0, 0]] # Neighbors # 0 1 2 3 4 nbrs = [[1, 2, 3, 4], [0], [0], [0], [0]] # Interactions # 0 1 2 3 4 ints = [[0, 1, 2, 3], [0], [1], [2], [3]] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 if anti == True: spin = rf.findmat(N.array([0, 0, -1])) ats[0].spinMagnitude = 1 ats[0].spinRmatrix = spin return ats
def gen_chain(num, anti = False): ats = [rf.atom(pos = [i,0,0]) for i in range(num)] spin = rf.findmat(N.array([0,0,1])) if num == 2: ints = [[0],[0]] nbrs = [[1],[0]] for i in range(num): ats[i].interactions = ints[i] ats[i].neighbors = nbrs[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 elif num == 3: ints = [[0],[0,1],[1]] nbrs = [[1],[0,2],[1]] for i in range(num): ats[i].interactions = ints[i] ats[i].neighbors = nbrs[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 if anti == True: spin = rf.findmat(N.array([0,0,-1])) for i in range(1,num,2): ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 for i in range(len(ats)): print ats[i].spinRmatrix return ats
def gen_chain(num, anti=False): ats = [rf.atom(pos=[i, 0, 0]) for i in range(num)] spin = rf.findmat(N.array([0, 0, 1])) if num == 2: ints = [[0], [0]] nbrs = [[1], [0]] for i in range(num): ats[i].interactions = ints[i] ats[i].neighbors = nbrs[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 elif num == 3: ints = [[0], [0, 1], [1]] nbrs = [[1], [0, 2], [1]] for i in range(num): ats[i].interactions = ints[i] ats[i].neighbors = nbrs[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 if anti == True: spin = rf.findmat(N.array([0, 0, -1])) for i in range(1, num, 2): ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 for i in range(len(ats)): print ats[i].spinRmatrix return ats
def testChain(self, num = 3, num_uc = 1): ats = [rf.atom(pos = [i,0,0]) for i in range(num)] spin = rf.findmat(N.array([0,0,1])) ints = [[0],[0,1],[1]] nbrs = [[1],[0,2],[1]] for i in range(num): ats[i].interactions = ints[i] ats[i].neighbors = nbrs[i] ats[i].spinRmatrix = spin inters = [item for atom in ats for item in atom.interactions] max_inter = max(inters) J = sp.Symbol('J', real = True) Jij = [N.matrix([[J,0,0],[0,J,0],[0,0,J]]) for i in range(max_inter+1)] (Hsave, charpoly, eigs) = calculate_dispersion(ats, num_uc, num, Jij, showEigs = True) eigs = eigs.keys() for item in eigs: item = item.expand(mul = True, multinomial=True) testeig = (-8.0*self.J**2*self.S**2*sp.cos(self.kx) + 4.0*self.J**2*self.S**2 + 4.0*self.J**2*self.S**2*sp.cos(self.kx)**2)**(0.5) self.assertAlmostEqual(Hsave.shape[0],2,4, 'H wrong shape') self.assertAlmostEqual(Hsave.shape[1],2,4, 'H wrong shape') self.assert_(len(eigs[0].args)==len(testeig.args), 'Eig.arg lengths are different sizes') f = sp.simplify(eigs[0].args[0].expand()) f = f.subs([(self.J,1),(self.S,2),(self.kx,3),(self.ky,4),(self.kz,5)]) g = sp.simplify(testeig.args[0].expand()) g = g.subs([(self.J,1),(self.S,2),(self.kx,3),(self.ky,4),(self.kz,5)]) myFlag = f-g self.assertAlmostEqual(myFlag,0,7, 'Eigs are wrong')
def testSquare(self, num=5, num_uc=1): ats = [rf.atom() for i in range(num)] spin = rf.findmat(N.array([0, 0, 1])) # Positions # 0 1 2 3 4 pstn = [[0, 0, 0], [0, 1, 0], [1, 0, 0], [0, -1, 0], [-1, 0, 0]] # Neighbors # 0 1 2 3 4 nbrs = [[1, 2, 3, 4], [0], [0], [0], [0]] # Interactions # 0 1 2 3 4 ints = [[0, 1, 2, 3], [0], [1], [2], [3]] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 inters = [item for atom in ats for item in atom.interactions] max_inter = max(inters) J = sp.Symbol('J', real=True) Jij = [ N.matrix([[J, 0, 0], [0, J, 0], [0, 0, J]]) for i in range(max_inter + 1) ] (Hsave, charpoly, eigs) = calculate_dispersion(ats, num_uc, num, Jij, showEigs=True) eigs = eigs.keys() for item in eigs: item = item.expand(mul=True, multinomial=True) testeig = ( -64.0 * self.J**2 * self.S**2 * sp.cos(self.kx) - 64.0 * self.J**2 * self.S**2 * sp.cos(self.ky) + 32.0 * self.J**2 * self.S**2 * sp.cos(self.kx) * sp.cos(self.ky) + 64.0 * self.J**2 * self.S**2 + 16.0 * self.J**2 * self.S**2 * sp.cos(self.kx)**2 + 16.0 * self.J**2 * self.S**2 * sp.cos(self.ky)**2)**(0.5) self.assertAlmostEqual(Hsave.shape[0], 2, 4, 'H wrong shape') self.assertAlmostEqual(Hsave.shape[1], 2, 4, 'H wrong shape') self.assert_( len(eigs[1].args) == len(testeig.args), 'Eig.arg lengths are different sizes') f = sp.simplify(eigs[1].args[0].expand()) f = f.subs([(self.J, 1), (self.S, 2), (self.kx, 3), (self.ky, 4), (self.kz, 5)]) g = sp.simplify(testeig.args[0].expand()) g = g.subs([(self.J, 1), (self.S, 2), (self.kx, 3), (self.ky, 4), (self.kz, 5)]) myFlag = f - g self.assertAlmostEqual(myFlag, 0, 7, 'Eigs are wrong')
def testFCC(self, num = 13, num_uc = 1): ats = [rf.atom() for i in range(num)] spin = rf.findmat(N.array([0,0,1])) aspin = rf.findmat(N.array([0,0,-1])) # Positions # 0 1 2 3 4 pstn = [[0,0,0], [0.5,0,0.5], [-0.5,0,0.5], [0.5,0,-0.5], [-0.5,0,-0.5], # 5 6 7 8 9 [0,0.5,0.5], [0,-0.5,0.5], [0,0.5,-0.5], [0,-0.5,-0.5], [0.5,0.5,0], # 10 11 12 [-0.5,0.5,0], [0.5,-0.5,0], [-0.5,-0.5,0]] # Neighbors # 0 1 2 3 4 nbrs = [[1,2,3,4,5,6,7,8,9,10,11,12], [], [], [], [], # 5 6 7 8 9 [], [], [], [], [], # 10 11 12 [], [], []] # Interactions # 0 1 2 3 4 ints = [[0,1,2,3,4,5,6,7,8,9,10,11], [], [], [], [], # 5 6 7 8 9 [], [], [], [], [], # 10 11 12 [], [], []] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 ats[0].spinMagnitude = 1 ats[0].spinRmatrix = aspin inters = [item for atom in ats for item in atom.interactions] max_inter = max(inters) J = sp.Symbol('J', real = True) Jij = [N.matrix([[J,0,0],[0,J,0],[0,0,J]]) for i in range(max_inter+1)] (Hsave, charpoly, eigs) = calculate_dispersion(ats, num_uc, num, Jij, showEigs = True) eigs = eigs.keys() for item in eigs: item = item.expand(mul = True, multinomial=True) testeig = (-128.0*self.J**2*self.S**2*sp.cos(0.5*self.kx)**2*sp.cos(0.5*self.ky)*sp.cos(0.5*self.kz) - 128.0*self.J**2*self.S**2*sp.cos(0.5*self.ky)**2*sp.cos(0.5*self.kx)*sp.cos(0.5*self.kz) - 128.0*self.J**2*self.S**2*sp.cos(0.5*self.kz)**2*sp.cos(0.5*self.kx)*sp.cos(0.5*self.ky) + 576.0*self.J**2*self.S**2 - 64.0*self.J**2*self.S**2*sp.cos(0.5*self.kx)**2*sp.cos(0.5*self.ky)**2 - 64.0*self.J**2*self.S**2*sp.cos(0.5*self.kx)**2*sp.cos(0.5*self.kz)**2 - 64.0*self.J**2*self.S**2*sp.cos(0.5*self.ky)**2*sp.cos(0.5*self.kz)**2)**(0.5) self.assertAlmostEqual(Hsave.shape[0],2,4, 'H wrong shape') self.assertAlmostEqual(Hsave.shape[1],2,4, 'H wrong shape') self.assert_(len(eigs[1].args)==len(testeig.args), 'Eig.arg lengths are different sizes') f = sp.simplify(eigs[1].args[0].expand()) f = f.subs([(self.J,1),(self.S,2),(self.kx,3),(self.ky,4),(self.kz,5)]) g = sp.simplify(testeig.args[0].expand()) g = g.subs([(self.J,1),(self.S,2),(self.kx,3),(self.ky,4),(self.kz,5)]) myFlag = f-g self.assertAlmostEqual(myFlag,0,7, 'Eigs are wrong')
def testChain(self, num=3, num_uc=1): ats = [rf.atom(pos=[i, 0, 0]) for i in range(num)] spin = rf.findmat(N.array([0, 0, 1])) aspin = rf.findmat(N.array([0, 0, -1])) ints = [[0], [0, 1], [1]] nbrs = [[1], [0, 2], [1]] for i in range(num): ats[i].interactions = ints[i] ats[i].neighbors = nbrs[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 for i in range(1, num, 2): ats[i].spinRmatrix = aspin ats[i].spinMagnitude = 1 inters = [item for atom in ats for item in atom.interactions] max_inter = max(inters) J = sp.Symbol('J', real=True) Jij = [ N.matrix([[J, 0, 0], [0, J, 0], [0, 0, J]]) for i in range(max_inter + 1) ] (Hsave, charpoly, eigs) = calculate_dispersion(ats, num_uc, num, Jij, showEigs=True) eigs = eigs.keys() for item in eigs: item = item.expand(mul=True, multinomial=True) testeig = (4 * self.J**2 * self.S**2 - 4.0 * self.J**2 * self.S**2 * sp.cos(self.kx)**2)**(0.5) self.assertAlmostEqual(Hsave.shape[0], 2, 4, 'H wrong shape') self.assertAlmostEqual(Hsave.shape[1], 2, 4, 'H wrong shape') self.assert_( len(eigs[0].args) == len(testeig.args), 'Eig.arg lengths are different sizes') f = sp.simplify(eigs[0].args[0].expand()) f = f.subs([(self.J, 1), (self.S, 2), (self.kx, 3), (self.ky, 4), (self.kz, 5)]) g = sp.simplify(testeig.args[0].expand()) g = g.subs([(self.J, 1), (self.S, 2), (self.kx, 3), (self.ky, 4), (self.kz, 5)]) myFlag = f - g self.assertAlmostEqual(myFlag, 0, 7, 'Eigs are wrong')
def create_matrix(atom_list, jnums, jmats, numCutOff, magCellSize, q): """Using hte Saenz technique. The matrix indeices, i and j refer to atoms in the magnetic unit cell, so M will be an N*N matrix, where N is the number of atoms in the magnetic cell. However, the l_vector is still in cyrstallographic unit cell units. -numCutOff is the number of atoms in the cutoff/interaction (or really magnetic, but we are assuming htey are the same) cell. -magCellSize is a length 3 np.array of the size of the magnetic cell in terms of crystallographic unit cells. ie. (1,1,1) for simple ferromagnet or (2,1,1) for simple antiferromagnetic chain along x direction. -q should also be a 3 element numpy array -atom_list, jums, and jmats come from readfiles. atom_list must contain all atoms in the interaction/magnetic cell as well as atoms that they bond to. Atoms in the magnetic cell should appear first in the list. """ min_diff = 1e-8 #he threshold for equality between floats(positions of atoms) #spin component to use: spin_comp = 2 #use z component of spins (assume they are aligned along z) #Loop through the atoms in the cutoff cell? natoms = numCutOff #We really want the magnetic cell, but we are assuming thats the same as the interaction cell. #natoms = N_atoms_uc if 0: #Hardcoded ferro and anit-ferro test cases #I'm hardcoding in this test case atom_list = [] #Ferro-magnet natoms = 1 jnums = [0] jmats = [np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])] atom_list.append( atom(pos=np.array([0, 0, 0]), spin=np.array([0, 0, 1]))) atom_list.append( atom(pos=np.array([1, 0, 0]), spin=np.array([0, 0, 1]))) #Add the ferro interaction atom_list[0].neighbors = [1] atom_list[0].interactions = [0] atom_list[1].neighbors = [0] atom_list[1].interactions = [0] #Adding interactions outside of the magnetic cell atom_list.append( atom(pos=np.array([-1, 0, 0]), spin=np.array([0, 0, 1]))) # atom_list.append(atom(pos = np.array([2,0,0]), spin = np.array([0,0,1]))) atom_list[0].neighbors = [1, 2] atom_list[0].interactions = [0, 0] #These are not necessary # atom_list[1].neighbors = [0,3] # atom_list[1].interactions = [0,0] magCellSize = np.array([1.0, 1.0, 1.0]) #anti-ferro if 0: atom_list = [] magCellSize = np.array([2, 1, 1], dtype=np.float64) natoms = 2 jnums = [0] jmats = [np.array([[-1, 0, 0], [0, -1, 0], [0, 0, -1]])] #Here the magnetic cell is the cut-off cell. This should be all I need. atom_list.append( atom(pos=np.array([0, 0, 0]), spin=np.array([0, 0, 1]))) atom_list.append( atom(pos=np.array([1, 0, 0]), spin=np.array([0, 0, -1]))) #These two are not in the magnetic cell atom_list.append( atom(pos=np.array([-1, 0, 0]), spin=np.array([0, 0, -1]))) atom_list.append( atom(pos=np.array([2, 0, 0]), spin=np.array([0, 0, 1]))) atom_list[0].neighbors = [1, 2] atom_list[0].interactions = [0, 0] atom_list[1].neighbors = [0, 3] atom_list[1].interactions = [0, 0] Mij = np.zeros((natoms, natoms), dtype=np.complex) #print "atoms in cell:" #for a in atom_list: # print a.pos #Choose a unit cell to use as a reference point for the l vector #firstCellPos = atom_list[0].pos.astype(int) #print "first cell position: " , firstCellPos for i in range(natoms): for j in range(natoms): term_ij = 0.0 + 0j #print "i: ", i, " j: ", j #print "atom_i pos: ", atom_list[i].pos if i == j: #delta_ij term (diaginal elements only) for lk in range(len(atom_list[i].neighbors)): #assuming Jij matrix is diagonal, take one of the diagonal terms: J = (get_Jij(jnums, jmats, atom_list[i].interactions[lk]))[1][1] spin_k = atom_list[ atom_list[i].neighbors[lk]].spin[spin_comp] term_ij += 2 * J * spin_k #*sigma_k*S_k S_i = np.abs(atom_list[i].spin[spin_comp]) spin_j = atom_list[j].spin[spin_comp] sigma_j = spin_j / np.abs(spin_j) S_j = np.abs(spin_j) #now for each atom correspondingto atom j in cell l sum J * exp(i*Q.l) #I'll loop through all the interactions, but only pick out those that bond #corresponding atoms in different(or the same) cells, ie. their positions - any integer #component are the same. atom_j = atom_list[j] for l in range(len(atom_list[i].neighbors)): atom_l = atom_list[atom_list[i].neighbors[l]] #Use unit cell lengtsh to construct l vecter l_pos = atom_l.pos #print "l_pos: ", l_pos #First we assumed it had to be a vector with integer components: #l_vec = l_pos.astype(int)-(atom_list[i].pos).astype(int)#firstCellPos #However, that ^ often produced imaginary numbers in the matrix l_vec = l_pos - atom_list[i].pos #use magnetic cell lengths to determine if atom_l is has the same position l_pos = l_pos / magCellSize l_pos = l_pos - l_pos.astype(int) #translate to first cell #in case l_pos is negative: l_pos = np.ceil(-l_pos) + l_pos #same for j_pos j_pos = atom_j.pos / magCellSize j_pos = j_pos - j_pos.astype(int) j_pos = np.ceil(-j_pos) + j_pos pos_diff = (l_pos) - (j_pos) #converted to magcell pos if ((np.abs(pos_diff) < min_diff).all()): #print "l_vec: ", l_vec J = (get_Jij(jnums, jmats, atom_list[i].interactions[l]) )[1][1] #taking a value from diagonal matrix #print "sinusoidal comp: ", 2*sigma_j*np.sqrt(S_i*S_j)*J*np.exp(1j*np.dot(q,l_vec)) term_ij -= 2 * sigma_j * np.sqrt(S_i * S_j) * J * np.exp( 1j * np.dot(q, l_vec)) #print "term[",i,"][",j,"]: ", term_ij # elif (i != j): #for testing: # print "" #print "\n\n\nOMG!!! I shouldn't be here for the simple ferro/antiferro cases!\n\n\n" #print "term_ij: ", term_ij Mij[i][j] = term_ij #print "Mij: ", Mij #print "Q: ", q #print "M:\n", Mij #this creates eigenvalues that are different from ours by a factor of 2. For now I'll #I'll just divide that out. return Mij / 2.0
def gen_cube(body = False, face = False, anti = False): ats = [] spin = rf.findmat(N.array([0,0,1])) # Cubic if not body and not face: ats = [rf.atom() for i in range(7)] # # Positions # # 0 1 2 3 4 5 6 # pstn = [[0,0,0], [1,0,0], [-1,0,0], [0,1,0], [0,-1,0], [0,0,1], [0,0,-1]] # # # Neighbors # # 0 1 2 3 4 5 6 # nbrs = [[1,2,3,4,5,6], [0], [0], [0], [0], [0], [0]] # # # Interactions # # 0 1 2 3 4 5 6 # ints = [[0,1,2,3,4,5], [0], [1], [2], [3], [4], [5]] # Positions # 0 1 2 3 4 5 6 pstn = [[0,0,0], [1,0,0], [-1,0,0], [0,1,0], [0,-1,0], [0,0,1], [0,0,-1]] # Neighbors # 0 1 2 3 4 5 6 nbrs = [[1,2,3,4,5,6], [0], [0], [0], [0], [0], [0]] # Interactions # 0 1 2 3 4 5 6 ints = [[0,0,0,0,0,0], [1], [2], [3], [4], [5], [6]] # Plug in values for positions and neighbors for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 # BCC - Body Centered Cubic elif body and not face: # Positions # 0 1 2 3 4 pstn = [[0,0,0], [-0.5,0.5,-0.5], [0.5,0.5,-0.5], [0.5,0.5,0.5], [-0.5,0.5,0.5], # 5 6 7 8 [-0.5,-0.5,-0.5], [0.5,-0.5,-0.5], [0.5,-0.5,0.5], [-0.5,-0.5,0.5]] # Neighbors # 0 1 2 3 4 nbrs = [[1,2,3,4,5,6,7,8], [], [], [], [], # 5 6 7 8 [], [], [], []] # Interactions # 0 1 2 3 4 ints = [[0,1,2,3,4,5,6,7], [], [], [], [], # 5 6 7 8 [], [], [], []] ats = [rf.atom() for i in range(len(pstn))] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 # FCC - Face Centered Cubic elif face and not body: # Positions # 0 1 2 3 4 pstn = [[0,0,0], [0.5,0,0.5], [-0.5,0,0.5], [0.5,0,-0.5], [-0.5,0,-0.5], # 5 6 7 8 9 [0,0.5,0.5], [0,-0.5,0.5], [0,0.5,-0.5], [0,-0.5,-0.5], [0.5,0.5,0], # 10 11 12 [-0.5,0.5,0], [0.5,-0.5,0], [-0.5,-0.5,0]] # Neighbors # 0 1 2 3 4 nbrs = [[1,2,3,4,5,6,7,8,9,10,11,12], [], [], [], [], # 5 6 7 8 9 [], [], [], [], [], # 10 11 12 [], [], []] # Interactions # 0 1 2 3 4 ints = [[0,1,2,3,4,5,6,7,8,9,10,11], [], [], [], [], # 5 6 7 8 9 [], [], [], [], [], # 10 11 12 [], [], []] ats = [rf.atom() for i in range(len(pstn))] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 if anti == True: spin = rf.findmat(N.array([0,0,-1])) ats[0].spinMagnitude = 1 ats[0].spinRmatrix = spin return ats
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 mcQueeny_case(interactionfile, spinfile, tau_list, temperature, direction={'kx':1,'ky':0,'kz':0}, hkl_interval=[1e-3,2*np.pi,100], omega_interval=[0,5,100], eig_eps = 0.001): initial_time = time.clock() #to plot eigenvector components # q1 = [] # q2 = [] #to plot w's #w1_list = [] #w2_list = [] #w3_list = [] #w4_list = [] #w5_list = [] #w6_list = [] #w7_list = [] #w8_list = [] # w_output_list = [] #plot the structure factor to compare with lovesey (In McQueeny Paper) # strfac_sums = [] # strfac1 = [] # strfac2 = [] atom_list, jnums, jmats, N_atoms_uc, numCutOff, magCellSize = readFiles(interactionfile,spinfile, rtn_cutOffInfo = True) #Hardcoding body-center cubic if 0: atom_list = [] jnums = [0] N_atom_uc = 1 numCutOff = 7 magCellSize = np.array([1,1,1]) jmats = [np.array([[-1,0,0],[0,-1,0],[0,0,-1]])] atom_list.append(atom(pos = np.array([0.5,0.5,0.5]), spin = np.array([0,0,1]), interactions = [0,0,0,0,0,0], neighbors = [1,2,3,4,5,6])) atom_list.append(atom(pos = np.array([0.,0.,0.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([1.,0.,0.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([1.,1.,0.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([1.,0.,1.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([1.,1.,1.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([0.,1.,0.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([0.,0.,1.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) atom_list.append(atom(pos = np.array([0.,1.,1.]), spin = np.array([0,0,-1]), interactions = [0], neighbors = [0])) h_list, k_list, l_list = generate_hkl(hkl_interval, direction) e = generate_wt(omega_interval) ff_list = generate_form_factors(N_atoms_uc, atom_list, hkl_interval) s = [] basis = [] for a in atom_list: s.append(a.spin[2])#z component of spin (assume aligned with z) #basis.append(a.pos) basis.append(a.pos - magCellSize) #translate back to 0,0,0 #normalize? NO! #basis.append([a.pos[0] - int(a.pos[0]), a.pos[1]-int(a.pos[1]), a.pos[2] - int(a.pos[2])]) #print "\n\nbasis vectors:\n" #mess with basis vectors and spin #basis[0] = [0.25,0,0] #basis[0] = [1.0,0,0] #tmp = s[0] #s[0] = s[1] #s[1] = tmp #for pos in basis: # print pos #print "\n\nspins:\n" #for spin in s: # print spin mesh = np.zeros((len(h_list), len(e))) #output q, w, and eigenvectors before and after normalization to compare with McQueeny's # f = open("/home/tom/Desktop/Python_Eigs.txt", 'w') # f.write("q w eigVec_before_norm T\n\n") # f2 = open("/home/tom/Desktop/Values.txt", 'w') # f2.write("Q w wvec (wvec norm) e^(-i*Q.d_i)\n\n") #create the T_ni matricies (eigenvector matrices) #This algorithm uses a differnt matrix: #evecs, mats = calc_eig_mats_numerically(Hsave, h_list,k_list,l_list) #eigvals = calc_eigs_numerically(Hsave, h_list, k_list, l_list)#This is innefficient, eigs already calculated and thrown away in calc_eig_mats_.. #w_list = gen_eigs_with_sign(Hsave, h_list, k_list, l_list, 0.001) for Qindex in range(len(h_list)): Q = (np.array([h_list,k_list,l_list]).transpose())[Qindex] # f2.write(str(Q)) #CALL SPINWAVE(q,w,evec) - get w, evec for given q M = create_matrix(atom_list, jnums, jmats, numCutOff, magCellSize, Q-np.array(tau_list)) w, evec = np.linalg.eig(M) # f2.write(" " + str(w)) # f2.write(" " + str(evec.flatten())) # evec = evecs[Qindex] # w = w_list[Qindex] # print "\nw = ", w #w1_list.append(w[0]) #w2_list.append(w[1]) #w3_list.append(w[1]) #w4_list.append(w[1]) #w5_list.append(w[1]) #w6_list.append(w[1]) #w7_list.append(w[1]) #w8_list.append(w[1]) # w_output_list.append(w) ff = ff_list[Qindex] #Get number of atoms numAtoms = numCutOff #numAtoms = np.sqrt(evec.size)#This should be the number of atoms that I need to loop through. #if int(numAtoms) != numAtoms:#I beleive t_mat should always be square, but lets check # raise Exception("t_mat not square!") #Normalize evec to get T_ni #for i in range(0, numAtoms): # normi = 0 # for j in range(0, numAtoms): # sigma_j = s[j]/np.abs(s[j]) # normi += sigma_j * np.abs(evec[j][i])**2 # for j in range(0, numAtoms): # evec[i][j] = evec[j][i]/np.sqrt(np.abs(normi)) evec2 = evec.copy() #I'm going to write this from scratch # print "evec before = ", evec T = evec sigma = [] for i in range(numAtoms): sigma.append(s[i]/np.abs(s[i])) for n in range(numAtoms): norm = 0 for i in range(numAtoms): norm += sigma[i]*(np.abs(evec2[n][i])**2) for i in range(numAtoms): # print "norm : ", norm # print "w sign: ", np.sign(w[n]) #T[n][i] = T[n][i]*np.sqrt((w[n]/np.abs(w[n]))/norm + 0j) T[n][i] = evec2[n][i]/np.sqrt(np.abs(norm)) evec = T # f2.write(" " + str(T.flatten())) #evec = evec2 # q1.append(evec[0][0]) # q2.append(evec[0][0]) #output eigs to file # f.write(str(Q)) # f.write(" w:" + str(w)) # f.write("\nmat: " + str(M))#the matrix for which the eigs were found # f.write("\nbefore_norm: " + str(evec2.flatten())) # f.write("\nafterNorm: " + str(evec.flatten()) + "\n\n") #evec = evec.transpose() #test = 0 #for i in range(numAtoms): # sigma_i = s[j]/np.abs(s[j]) # test += sigma_i * np.dot(evec[i],evec[i]) # print "sigma_i = ", sigma_i #print "\n\nsum{sigma_i * |T_ni|^2} = ", test, "\n\n" # print "evec = " , evec # print "sigma1: ", s[0]/np.abs(s[0]) # print "sigma2: ", s[1]/np.abs(s[1]) # print "sign lambda_0: ", (s[0]/np.abs(s[0]))*(evec[0][0]**2) + (s[1]/np.abs(s[1]))*(evec[0][1]**2) # print "sign lambda_1: ", (s[0]/np.abs(s[0]))*(evec[1][0]**2) + (s[1]/np.abs(s[1]))*(evec[1][1]**2) #using only positive eigenvalue #w = [w[0]] #evec = [evec[0]] #print "eigenvalues used: ", w #print "eigenvectors used: ", evec strfac = np.zeros(numAtoms) #for testing: ff = 1 for i in range(numAtoms): dum = 0 for j in range(numAtoms): dum += (s[j]/np.sqrt(np.abs(s[j]))) * ff * evec[j][i] #* np.exp(1.0j* #(-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2])) # print "\n\n\nwritting to f2:\n\n\n", np.exp(1.0j* # (-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2])) # print "j: ", j # print "basis: ", basis[j] # print "Q.di", (-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2]) exp = np.exp(1.0j*(-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2])) # f2.write(" " + str(exp)) strfac[i] = np.abs(dum)**2 # print "Q: ", Q, " strfac[",i,"]: ", strfac[i] # f2.write("\n\n") # strfac_sums.append(0.0); # strfac1.append(strfac[0]) # strfac2.append(strfac[1]) sqw = np.zeros(len(e)) for j in range(numAtoms): # strfac_sums[Qindex] +=strfac[j] for i in range(len(e)): y = LIFETIME_VALUE/2 lorentzian = (1/np.pi)*y/((e[i]- w[j])**2+y**2) #test #strfac[j] = ff*1 sqw[i] = sqw[i] + strfac[j] * lorentzian #he has some 'bose' factor in here #more test #sqw[i] = sqw[i] + strfac[j] mesh[Qindex] = sqw #* 0.5*(1 + Q[0]**2) #along x, Q_hat is just 1? #f.close() #f = open("/home/tom/Desktop/output.txt", 'w') #for q in range(0,len(h_list)): #for w in range(0,len(e)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(e[w])) #f.write(" ") #f.write(str(mesh[q][w])) #f.write("\n") #f.close() #f = open("/home/tom/Desktop/output2.txt", 'w') #for q in range(0,len(h_list)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(np.abs(q1[q]))) #f.write(" ") #f.write(str(np.abs(q2[q]))) #f.write("\n") #f.close() #f = open("/home/tom/Desktop/output3.txt", 'w') #for q in range(0,len(h_list)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(np.real(w1_list[q]))) #f.write(" ") #f.write(str(np.real(w2_list[q]))) #f.write(" ") #f.write(str(np.real(w3_list[q]))) #f.write(" ") #f.write(str(np.real(w4_list[q]))) #f.write(" ") #f.write(str(np.real(w5_list[q]))) #f.write(" ") #f.write(str(np.real(w6_list[q]))) #f.write(" ") #f.write(str(np.real(w7_list[q]))) #f.write(" ") #f.write(str(np.real(w8_list[q]))) #f.write("\n") #f.close() #f = open("/home/tom/Desktop/strfacs.txt", 'w') #for q in range(0,len(h_list)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(k_list[q])) #f.write(" ") #f.write(str(l_list[q])) #f.write(" ") #f.write(str(strfac1[q])) #f.write(" ") #f.write(str(strfac2[q])) #f.write(" ") #f.write(str(strfac_sums[q])) #f.write("\n") #f.close() #plt.plot(w1_list) #plt.plot(w2_list) #plt.show() print "Run Time: ", time.clock()-initial_time, " seconds"
def create_matrix(atom_list, jnums, jmats, numCutOff, magCellSize, q): """Using hte Saenz technique. The matrix indeices, i and j refer to atoms in the magnetic unit cell, so M will be an N*N matrix, where N is the number of atoms in the magnetic cell. However, the l_vector is still in cyrstallographic unit cell units. -numCutOff is the number of atoms in the cutoff/interaction (or really magnetic, but we are assuming htey are the same) cell. -magCellSize is a length 3 np.array of the size of the magnetic cell in terms of crystallographic unit cells. ie. (1,1,1) for simple ferromagnet or (2,1,1) for simple antiferromagnetic chain along x direction. -q should also be a 3 element numpy array -atom_list, jums, and jmats come from readfiles. atom_list must contain all atoms in the interaction/magnetic cell as well as atoms that they bond to. Atoms in the magnetic cell should appear first in the list. """ min_diff = 1e-8#he threshold for equality between floats(positions of atoms) #spin component to use: spin_comp = 2#use z component of spins (assume they are aligned along z) #Loop through the atoms in the cutoff cell? natoms = numCutOff #We really want the magnetic cell, but we are assuming thats the same as the interaction cell. #natoms = N_atoms_uc if 0: #Hardcoded ferro and anit-ferro test cases #I'm hardcoding in this test case atom_list = [] #Ferro-magnet natoms = 1 jnums = [0] jmats = [np.array([[1,0,0],[0,1,0],[0,0,1]])] atom_list.append(atom(pos = np.array([0,0,0]), spin = np.array([0,0,1]))) atom_list.append(atom(pos = np.array([1,0,0]), spin = np.array([0,0,1]))) #Add the ferro interaction atom_list[0].neighbors = [1] atom_list[0].interactions = [0] atom_list[1].neighbors = [0] atom_list[1].interactions = [0] #Adding interactions outside of the magnetic cell atom_list.append(atom(pos = np.array([-1,0,0]), spin = np.array([0,0,1]))) # atom_list.append(atom(pos = np.array([2,0,0]), spin = np.array([0,0,1]))) atom_list[0].neighbors = [1,2] atom_list[0].interactions = [0,0] #These are not necessary # atom_list[1].neighbors = [0,3] # atom_list[1].interactions = [0,0] magCellSize = np.array([1.0,1.0,1.0]) #anti-ferro if 0: atom_list = [] magCellSize = np.array([2,1,1],dtype = np.float64) natoms = 2 jnums = [0] jmats = [np.array([[-1,0,0],[0,-1,0],[0,0,-1]])] #Here the magnetic cell is the cut-off cell. This should be all I need. atom_list.append(atom(pos = np.array([0,0,0]), spin = np.array([0,0,1]))) atom_list.append(atom(pos = np.array([1,0,0]), spin = np.array([0,0,-1]))) #These two are not in the magnetic cell atom_list.append(atom(pos = np.array([-1,0,0]), spin = np.array([0,0,-1]))) atom_list.append(atom(pos = np.array([2,0,0]), spin = np.array([0,0,1]))) atom_list[0].neighbors = [1,2] atom_list[0].interactions = [0,0] atom_list[1].neighbors = [0,3] atom_list[1].interactions = [0,0] Mij = np.zeros((natoms,natoms), dtype = np.complex) #print "atoms in cell:" #for a in atom_list: # print a.pos #Choose a unit cell to use as a reference point for the l vector #firstCellPos = atom_list[0].pos.astype(int) #print "first cell position: " , firstCellPos for i in range(natoms): for j in range(natoms): term_ij = 0.0 +0j #print "i: ", i, " j: ", j #print "atom_i pos: ", atom_list[i].pos if i == j:#delta_ij term (diaginal elements only) for lk in range(len(atom_list[i].neighbors)): #assuming Jij matrix is diagonal, take one of the diagonal terms: J = (get_Jij(jnums, jmats,atom_list[i].interactions[lk]))[1][1] spin_k = atom_list[atom_list[i].neighbors[lk]].spin[spin_comp] term_ij += 2*J*spin_k#*sigma_k*S_k S_i = np.abs(atom_list[i].spin[spin_comp]) spin_j = atom_list[j].spin[spin_comp] sigma_j = spin_j/np.abs(spin_j) S_j = np.abs(spin_j) #now for each atom correspondingto atom j in cell l sum J * exp(i*Q.l) #I'll loop through all the interactions, but only pick out those that bond #corresponding atoms in different(or the same) cells, ie. their positions - any integer #component are the same. atom_j = atom_list[j] for l in range(len(atom_list[i].neighbors)): atom_l = atom_list[atom_list[i].neighbors[l]] #Use unit cell lengtsh to construct l vecter l_pos = atom_l.pos #print "l_pos: ", l_pos #First we assumed it had to be a vector with integer components: #l_vec = l_pos.astype(int)-(atom_list[i].pos).astype(int)#firstCellPos #However, that ^ often produced imaginary numbers in the matrix l_vec = l_pos - atom_list[i].pos #use magnetic cell lengths to determine if atom_l is has the same position l_pos = l_pos/magCellSize l_pos = l_pos - l_pos.astype(int) #translate to first cell #in case l_pos is negative: l_pos = np.ceil(-l_pos) + l_pos #same for j_pos j_pos = atom_j.pos/magCellSize j_pos = j_pos - j_pos.astype(int) j_pos = np.ceil(-j_pos) + j_pos pos_diff = (l_pos)-(j_pos)#converted to magcell pos if ((np.abs(pos_diff)<min_diff).all()): #print "l_vec: ", l_vec J = (get_Jij(jnums, jmats, atom_list[i].interactions[l]))[1][1]#taking a value from diagonal matrix #print "sinusoidal comp: ", 2*sigma_j*np.sqrt(S_i*S_j)*J*np.exp(1j*np.dot(q,l_vec)) term_ij -= 2*sigma_j*np.sqrt(S_i*S_j)*J*np.exp(1j*np.dot(q,l_vec)) #print "term[",i,"][",j,"]: ", term_ij # elif (i != j): #for testing: # print "" #print "\n\n\nOMG!!! I shouldn't be here for the simple ferro/antiferro cases!\n\n\n" #print "term_ij: ", term_ij Mij[i][j] = term_ij #print "Mij: ", Mij #print "Q: ", q #print "M:\n", Mij #this creates eigenvalues that are different from ours by a factor of 2. For now I'll #I'll just divide that out. return Mij/2.0
def read_files(interactionFileStr, allAtoms=False): """ MODIFIED FROM SPINWAVE CALC FILE TO ONLY READ INTERACTION FILE""" """modified from read_interactions. Originally this(read_interactions) read in the atoms from the interaction file and matched the spin rotation matrices with the appropriate atoms based on indices. Now it takes the interaction and spin file strings, reads in the atom information and matches it with spin rotation matrices based on coordinates""" #print interactionFileStr interactionFile = open(interactionFileStr, 'r') myFlag = True returnline = [''] jmats = [] jnums = [] atomlist = [] numcell = 0 Na, Nb, Nc = 0, 0, 0 while myFlag: tokenized = get_tokenized_line(interactionFile, returnline=returnline) if not (tokenized): break if tokenized == []: break if tokenized[0] == "#na": tokenized = get_tokenized_line(interactionFile, returnline=returnline) Na = int(tokenized[0]) Nb = int(tokenized[1]) Nc = int(tokenized[2]) if tokenized[0] == '#number': while 1: tokenized = get_tokenized_line(interactionFile, returnline=returnline) #print 'intoken ',tokenized if tokenized == []: break if tokenized[0] != '#atomnumber': #print tokenized[0] jnum = float(tokenized[0]) j11 = float(tokenized[1]) j12 = float(tokenized[2]) j13 = float(tokenized[3]) j21 = float(tokenized[4]) j22 = float(tokenized[5]) j23 = float(tokenized[6]) j31 = float(tokenized[7]) j32 = float(tokenized[8]) j33 = float(tokenized[9]) #jij=N.matrix([[j11,j12,j13],[j21,j22,j23],[j31,j32,j33]],'Float64') jij = sp.matrices.Matrix([[j11, j12, j13], [j21, j22, j23], [j31, j32, j33]]) jnums.append(jnum) jmats.append(jij) else: currnum = 0 while 1: tokenized = get_tokenized_line(interactionFile, returnline=returnline) if not (tokenized): break #print tokenized atom_num = int(tokenized[0]) if tokenized[ 5] == 'x' or allAtoms: #If it is in the first interaction cell print "atom in first interaction cell" x, y, z = float(tokenized[6]), float( tokenized[7]), float(tokenized[8]) print x, y, z Dx, Dy, Dz = float(tokenized[9]), float( tokenized[10]), float(tokenized[11]) #spin0=N.matrix([[1,0,0],[0,1,0],[0,0,1]],'float64') spinMagnitude = float(tokenized[12]) valence = int(tokenized[4]) massNum = int(tokenized[3]) label = tokenized[1].capitalize() pos0 = [x, y, z] atom0 = atom(spinMag=spinMagnitude, pos=pos0, label=label, Dx=Dx, Dy=Dy, Dz=Dz, orig_Index=atom_num, valence=valence, massNum=massNum) neighbors = [] interactions = [] for i in range(13, len(tokenized), 2): interacting_spin = int(tokenized[i]) #index number in export list not necessarily the same as index #in list of atoms in first interacting 'cell' interaction_matrix = int(tokenized[i + 1]) neighbors.append(interacting_spin) interactions.append(interaction_matrix) atom0.neighbors = neighbors atom0.interactions = interactions currnum = currnum + 1 atomlist.append(atom0) interactionFile.close() def inDesiredCell(atom): if atom.pos[0] >= Na and atom.pos[0] < (Na + 1): if atom.pos[1] >= Nb and atom.pos[1] < (Nb + 1): if atom.pos[2] >= Nc and atom.pos[2] < (Nc + 1): return True return False #Add atoms in desired cell to the beginning of the new list newAtomList = [] Flag = True i = 0 while Flag: #for i in range(len(atomlist)): if inDesiredCell(atomlist[i]): numcell += 1 newAtomList.append(atomlist.pop(i)) else: i = i + 1 if i == len(atomlist): Flag = False #Add remaining atoms to the new list for i in range(len(atomlist)): newAtomList.append(atomlist[i]) atomlist = newAtomList for a in atomlist: neighborList = a.neighbors i = 0 while i < len(neighborList): neighbor_index = neighborList[i] for atom_index in range(len(atomlist)): atom1 = atomlist[atom_index] if atom1.origIndex == neighbor_index: a.neighbors[i] = atom_index i += 1 break else: neighborList.pop(i) a.interactions.pop(i) for atom1 in atomlist: print atom1.pos, atom1.neighbors return atomlist, numcell
def gen_cube(body=False, face=False, anti=False): ats = [] spin = rf.findmat(N.array([0, 0, 1])) # Cubic if not body and not face: ats = [rf.atom() for i in range(7)] # # Positions # # 0 1 2 3 4 5 6 # pstn = [[0,0,0], [1,0,0], [-1,0,0], [0,1,0], [0,-1,0], [0,0,1], [0,0,-1]] # # # Neighbors # # 0 1 2 3 4 5 6 # nbrs = [[1,2,3,4,5,6], [0], [0], [0], [0], [0], [0]] # # # Interactions # # 0 1 2 3 4 5 6 # ints = [[0,1,2,3,4,5], [0], [1], [2], [3], [4], [5]] # Positions # 0 1 2 3 4 5 6 pstn = [[0, 0, 0], [1, 0, 0], [-1, 0, 0], [0, 1, 0], [0, -1, 0], [0, 0, 1], [0, 0, -1]] # Neighbors # 0 1 2 3 4 5 6 nbrs = [[1, 2, 3, 4, 5, 6], [0], [0], [0], [0], [0], [0]] # Interactions # 0 1 2 3 4 5 6 ints = [[0, 0, 0, 0, 0, 0], [1], [2], [3], [4], [5], [6]] # Plug in values for positions and neighbors for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 # BCC - Body Centered Cubic elif body and not face: # Positions # 0 1 2 3 4 pstn = [ [0, 0, 0], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5], # 5 6 7 8 [-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, 0.5], [-0.5, -0.5, 0.5] ] # Neighbors # 0 1 2 3 4 nbrs = [ [1, 2, 3, 4, 5, 6, 7, 8], [], [], [], [], # 5 6 7 8 [], [], [], [] ] # Interactions # 0 1 2 3 4 ints = [ [0, 1, 2, 3, 4, 5, 6, 7], [], [], [], [], # 5 6 7 8 [], [], [], [] ] ats = [rf.atom() for i in range(len(pstn))] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 # FCC - Face Centered Cubic elif face and not body: # Positions # 0 1 2 3 4 pstn = [ [0, 0, 0], [0.5, 0, 0.5], [-0.5, 0, 0.5], [0.5, 0, -0.5], [-0.5, 0, -0.5], # 5 6 7 8 9 [0, 0.5, 0.5], [0, -0.5, 0.5], [0, 0.5, -0.5], [0, -0.5, -0.5], [0.5, 0.5, 0], # 10 11 12 [-0.5, 0.5, 0], [0.5, -0.5, 0], [-0.5, -0.5, 0] ] # Neighbors # 0 1 2 3 4 nbrs = [ [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [], [], [], [], # 5 6 7 8 9 [], [], [], [], [], # 10 11 12 [], [], [] ] # Interactions # 0 1 2 3 4 ints = [ [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [], [], [], [], # 5 6 7 8 9 [], [], [], [], [], # 10 11 12 [], [], [] ] ats = [rf.atom() for i in range(len(pstn))] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 if anti == True: spin = rf.findmat(N.array([0, 0, -1])) ats[0].spinMagnitude = 1 ats[0].spinRmatrix = spin return ats
def mcQueeny_case(interactionfile, spinfile, tau_list, temperature, direction={ 'kx': 1, 'ky': 0, 'kz': 0 }, hkl_interval=[1e-3, 2 * np.pi, 100], omega_interval=[0, 5, 100], eig_eps=0.001): initial_time = time.clock() #to plot eigenvector components # q1 = [] # q2 = [] #to plot w's #w1_list = [] #w2_list = [] #w3_list = [] #w4_list = [] #w5_list = [] #w6_list = [] #w7_list = [] #w8_list = [] # w_output_list = [] #plot the structure factor to compare with lovesey (In McQueeny Paper) # strfac_sums = [] # strfac1 = [] # strfac2 = [] atom_list, jnums, jmats, N_atoms_uc, numCutOff, magCellSize = readFiles( interactionfile, spinfile, rtn_cutOffInfo=True) #Hardcoding body-center cubic if 0: atom_list = [] jnums = [0] N_atom_uc = 1 numCutOff = 7 magCellSize = np.array([1, 1, 1]) jmats = [np.array([[-1, 0, 0], [0, -1, 0], [0, 0, -1]])] atom_list.append( atom(pos=np.array([0.5, 0.5, 0.5]), spin=np.array([0, 0, 1]), interactions=[0, 0, 0, 0, 0, 0], neighbors=[1, 2, 3, 4, 5, 6])) atom_list.append( atom(pos=np.array([0., 0., 0.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([1., 0., 0.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([1., 1., 0.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([1., 0., 1.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([1., 1., 1.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([0., 1., 0.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([0., 0., 1.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) atom_list.append( atom(pos=np.array([0., 1., 1.]), spin=np.array([0, 0, -1]), interactions=[0], neighbors=[0])) h_list, k_list, l_list = generate_hkl(hkl_interval, direction) e = generate_wt(omega_interval) ff_list = generate_form_factors(N_atoms_uc, atom_list, hkl_interval) s = [] basis = [] for a in atom_list: s.append(a.spin[2]) #z component of spin (assume aligned with z) #basis.append(a.pos) basis.append(a.pos - magCellSize) #translate back to 0,0,0 #normalize? NO! #basis.append([a.pos[0] - int(a.pos[0]), a.pos[1]-int(a.pos[1]), a.pos[2] - int(a.pos[2])]) #print "\n\nbasis vectors:\n" #mess with basis vectors and spin #basis[0] = [0.25,0,0] #basis[0] = [1.0,0,0] #tmp = s[0] #s[0] = s[1] #s[1] = tmp #for pos in basis: # print pos #print "\n\nspins:\n" #for spin in s: # print spin mesh = np.zeros((len(h_list), len(e))) #output q, w, and eigenvectors before and after normalization to compare with McQueeny's # f = open("/home/tom/Desktop/Python_Eigs.txt", 'w') # f.write("q w eigVec_before_norm T\n\n") # f2 = open("/home/tom/Desktop/Values.txt", 'w') # f2.write("Q w wvec (wvec norm) e^(-i*Q.d_i)\n\n") #create the T_ni matricies (eigenvector matrices) #This algorithm uses a differnt matrix: #evecs, mats = calc_eig_mats_numerically(Hsave, h_list,k_list,l_list) #eigvals = calc_eigs_numerically(Hsave, h_list, k_list, l_list)#This is innefficient, eigs already calculated and thrown away in calc_eig_mats_.. #w_list = gen_eigs_with_sign(Hsave, h_list, k_list, l_list, 0.001) for Qindex in range(len(h_list)): Q = (np.array([h_list, k_list, l_list]).transpose())[Qindex] # f2.write(str(Q)) #CALL SPINWAVE(q,w,evec) - get w, evec for given q M = create_matrix(atom_list, jnums, jmats, numCutOff, magCellSize, Q - np.array(tau_list)) w, evec = np.linalg.eig(M) # f2.write(" " + str(w)) # f2.write(" " + str(evec.flatten())) # evec = evecs[Qindex] # w = w_list[Qindex] # print "\nw = ", w #w1_list.append(w[0]) #w2_list.append(w[1]) #w3_list.append(w[1]) #w4_list.append(w[1]) #w5_list.append(w[1]) #w6_list.append(w[1]) #w7_list.append(w[1]) #w8_list.append(w[1]) # w_output_list.append(w) ff = ff_list[Qindex] #Get number of atoms numAtoms = numCutOff #numAtoms = np.sqrt(evec.size)#This should be the number of atoms that I need to loop through. #if int(numAtoms) != numAtoms:#I beleive t_mat should always be square, but lets check # raise Exception("t_mat not square!") #Normalize evec to get T_ni #for i in range(0, numAtoms): # normi = 0 # for j in range(0, numAtoms): # sigma_j = s[j]/np.abs(s[j]) # normi += sigma_j * np.abs(evec[j][i])**2 # for j in range(0, numAtoms): # evec[i][j] = evec[j][i]/np.sqrt(np.abs(normi)) evec2 = evec.copy() #I'm going to write this from scratch # print "evec before = ", evec T = evec sigma = [] for i in range(numAtoms): sigma.append(s[i] / np.abs(s[i])) for n in range(numAtoms): norm = 0 for i in range(numAtoms): norm += sigma[i] * (np.abs(evec2[n][i])**2) for i in range(numAtoms): # print "norm : ", norm # print "w sign: ", np.sign(w[n]) #T[n][i] = T[n][i]*np.sqrt((w[n]/np.abs(w[n]))/norm + 0j) T[n][i] = evec2[n][i] / np.sqrt(np.abs(norm)) evec = T # f2.write(" " + str(T.flatten())) #evec = evec2 # q1.append(evec[0][0]) # q2.append(evec[0][0]) #output eigs to file # f.write(str(Q)) # f.write(" w:" + str(w)) # f.write("\nmat: " + str(M))#the matrix for which the eigs were found # f.write("\nbefore_norm: " + str(evec2.flatten())) # f.write("\nafterNorm: " + str(evec.flatten()) + "\n\n") #evec = evec.transpose() #test = 0 #for i in range(numAtoms): # sigma_i = s[j]/np.abs(s[j]) # test += sigma_i * np.dot(evec[i],evec[i]) # print "sigma_i = ", sigma_i #print "\n\nsum{sigma_i * |T_ni|^2} = ", test, "\n\n" # print "evec = " , evec # print "sigma1: ", s[0]/np.abs(s[0]) # print "sigma2: ", s[1]/np.abs(s[1]) # print "sign lambda_0: ", (s[0]/np.abs(s[0]))*(evec[0][0]**2) + (s[1]/np.abs(s[1]))*(evec[0][1]**2) # print "sign lambda_1: ", (s[0]/np.abs(s[0]))*(evec[1][0]**2) + (s[1]/np.abs(s[1]))*(evec[1][1]**2) #using only positive eigenvalue #w = [w[0]] #evec = [evec[0]] #print "eigenvalues used: ", w #print "eigenvectors used: ", evec strfac = np.zeros(numAtoms) #for testing: ff = 1 for i in range(numAtoms): dum = 0 for j in range(numAtoms): dum += (s[j] / np.sqrt(np.abs( s[j]))) * ff * evec[j][i] #* np.exp(1.0j* #(-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2])) # print "\n\n\nwritting to f2:\n\n\n", np.exp(1.0j* # (-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2])) # print "j: ", j # print "basis: ", basis[j] # print "Q.di", (-Q[0]*basis[j][0] -Q[1]*basis[j][1] -Q[2]*basis[j][2]) exp = np.exp(1.0j * (-Q[0] * basis[j][0] - Q[1] * basis[j][1] - Q[2] * basis[j][2])) # f2.write(" " + str(exp)) strfac[i] = np.abs(dum)**2 # print "Q: ", Q, " strfac[",i,"]: ", strfac[i] # f2.write("\n\n") # strfac_sums.append(0.0); # strfac1.append(strfac[0]) # strfac2.append(strfac[1]) sqw = np.zeros(len(e)) for j in range(numAtoms): # strfac_sums[Qindex] +=strfac[j] for i in range(len(e)): y = LIFETIME_VALUE / 2 lorentzian = (1 / np.pi) * y / ((e[i] - w[j])**2 + y**2) #test #strfac[j] = ff*1 sqw[i] = sqw[i] + strfac[ j] * lorentzian #he has some 'bose' factor in here #more test #sqw[i] = sqw[i] + strfac[j] mesh[Qindex] = sqw #* 0.5*(1 + Q[0]**2) #along x, Q_hat is just 1? #f.close() #f = open("/home/tom/Desktop/output.txt", 'w') #for q in range(0,len(h_list)): #for w in range(0,len(e)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(e[w])) #f.write(" ") #f.write(str(mesh[q][w])) #f.write("\n") #f.close() #f = open("/home/tom/Desktop/output2.txt", 'w') #for q in range(0,len(h_list)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(np.abs(q1[q]))) #f.write(" ") #f.write(str(np.abs(q2[q]))) #f.write("\n") #f.close() #f = open("/home/tom/Desktop/output3.txt", 'w') #for q in range(0,len(h_list)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(np.real(w1_list[q]))) #f.write(" ") #f.write(str(np.real(w2_list[q]))) #f.write(" ") #f.write(str(np.real(w3_list[q]))) #f.write(" ") #f.write(str(np.real(w4_list[q]))) #f.write(" ") #f.write(str(np.real(w5_list[q]))) #f.write(" ") #f.write(str(np.real(w6_list[q]))) #f.write(" ") #f.write(str(np.real(w7_list[q]))) #f.write(" ") #f.write(str(np.real(w8_list[q]))) #f.write("\n") #f.close() #f = open("/home/tom/Desktop/strfacs.txt", 'w') #for q in range(0,len(h_list)): #f.write(str(h_list[q])) #f.write(" ") #f.write(str(k_list[q])) #f.write(" ") #f.write(str(l_list[q])) #f.write(" ") #f.write(str(strfac1[q])) #f.write(" ") #f.write(str(strfac2[q])) #f.write(" ") #f.write(str(strfac_sums[q])) #f.write("\n") #f.close() #plt.plot(w1_list) #plt.plot(w2_list) #plt.show() print "Run Time: ", time.clock() - initial_time, " seconds"
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) atom_list=atom_list[:N_atoms_uc] N_atoms = len(atom_list) print N_atoms if 1: kx = sp.Symbol('kx', real = True) ky = sp.Symbol('ky', real = True) kz = sp.Symbol('kz', real = 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 = 1.0 kmin = 0 kmax = 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.1,12.0,200) k_list = np.zeros(h_list.shape) l_list = np.zeros(h_list.shape) w_list = np.linspace(0.1,10.0,200) efixed = 14.7 #meV eief = True N_atoms_uc,csection,kaprange,qlist,tau_list,eig_list,kapvect,wtlist = generate_cross_section(interactionfile, spinfile, lattice, ops, tau_list, h_list, k_list, l_list, w_list, temperature, steps, eief, efixed) print csection return N_atoms_uc,csection,kaprange,qlist,tau_list,eig_list,kapvect,wtlist end = clock() print "\nFinished %i atoms in %.2f seconds" %(N_atoms,end-start)
pylab.show() sys.exit() if 0: x,y = sp.symbols('xy') out = x*y print sp.latex(out) if 0: a = np.array([1,1,1]) b = 5 print b/a print a/b if 0: at1 = atom(pos=[0,0,0], atomicNum = 26, valence = 3) print at1.atomicNum el = elements[at1.atomicNum] print el Q=np.arange(0.,1.,1./100.) print Q Mq = el.magnetic_ff[at1.valence].M_Q(Q) print type(Mq) print type(Q) pylab.plot(Q,Mq) pylab.show() if 0: x,y = sp.symbols('xy') print (x+1)*y
pylab.show() sys.exit() if 0: x, y = sp.symbols('xy') out = x * y print sp.latex(out) if 0: a = np.array([1, 1, 1]) b = 5 print b / a print a / b if 0: at1 = atom(pos=[0, 0, 0], atomicNum=26, valence=3) print at1.atomicNum el = elements[at1.atomicNum] print el Q = np.arange(0., 1., 1. / 100.) print Q Mq = el.magnetic_ff[at1.valence].M_Q(Q) print type(Mq) print type(Q) pylab.plot(Q, Mq) pylab.show() if 0: x, y = sp.symbols('xy') print(x + 1) * y
def testBCC(self, num=9, num_uc=1): ats = [rf.atom() for i in range(num)] spin = rf.findmat(N.array([0, 0, 1])) # Positions # 0 1 2 3 4 pstn = [ [0, 0, 0], [-0.5, 0.5, -0.5], [0.5, 0.5, -0.5], [0.5, 0.5, 0.5], [-0.5, 0.5, 0.5], # 5 6 7 8 [-0.5, -0.5, -0.5], [0.5, -0.5, -0.5], [0.5, -0.5, 0.5], [-0.5, -0.5, 0.5] ] # Neighbors # 0 1 2 3 4 nbrs = [ [1, 2, 3, 4, 5, 6, 7, 8], [], [], [], [], # 5 6 7 8 [], [], [], [] ] # Interactions # 0 1 2 3 4 ints = [ [0, 1, 2, 3, 4, 5, 6, 7], [], [], [], [], # 5 6 7 8 [], [], [], [] ] for i in range(len(ats)): ats[i].pos = N.array(pstn[i]) ats[i].neighbors = nbrs[i] ats[i].interactions = ints[i] ats[i].spinRmatrix = spin ats[i].spinMagnitude = 1 inters = [item for atom in ats for item in atom.interactions] max_inter = max(inters) J = sp.Symbol('J', real=True) Jij = [ N.matrix([[J, 0, 0], [0, J, 0], [0, 0, J]]) for i in range(max_inter + 1) ] (Hsave, charpoly, eigs) = calculate_dispersion(ats, num_uc, num, Jij, showEigs=True) eigs = eigs.keys() for item in eigs: item = item.expand(mul=True, multinomial=True) testeig = (-2048.0 * self.J**2 * self.S**2 * sp.cos(0.5 * self.kx) * sp.cos(0.5 * self.ky) * sp.cos(0.5 * self.kz) + 1024.0 * self.J**2 * self.S**2 + 1024.0 * self.J**2 * self.S**2 * sp.cos(0.5 * self.kx)**2 * sp.cos(0.5 * self.ky)**2 * sp.cos(0.5 * self.kz)**2)**( 0.5) * 0.5 self.assertAlmostEqual(Hsave.shape[0], 2, 4, 'H wrong shape') self.assertAlmostEqual(Hsave.shape[1], 2, 4, 'H wrong shape') f = eigs[0].args[2].args[1].args[0].expand() f = f.subs([(self.J, 1), (self.S, 2), (self.kx, 3), (self.ky, 4), (self.kz, 5), (sp.I, 0)]) g = sp.simplify(testeig.args[1].args[0].expand()) g = g.subs([(self.J, 1), (self.S, 2), (self.kx, 3), (self.ky, 4), (self.kz, 5)]) myFlag = f - g self.assertAlmostEqual(myFlag, 0, 7, 'Eigs are wrong')