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 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 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 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 add_spins(atoms, spins, atomlist): for atom1 in atomlist: for i in range(len(atoms)): xPos = atoms[i].pos[0] yPos = atoms[i].pos[1] zPos = atoms[i].pos[2] if (atom1.pos[0] == xPos and atom1.pos[1] == yPos and atom1.pos[2] == zPos): spin = spins[i] atom1.spin = spin rmat = findmat(spin) atom1.spinRmatrix = rmat break return atomlist
def GetResult(self): print "fit list: ", self.fit_list #Propagate any value changes through all tied parameters for i in range(len(self.fit_list)): group = self._paramGroupList[i] print "group: ", group for param in group: #This will change the values in the matrices param.value = self.fit_list[i] monteCarloMats = [] #Used later for spinwave calculation jnums = [] jmats = [] print "matrices[0]: ", self._matrices[0].tolist() for i in range(len(self._matrices)): j11 = self._matrices[i][0][0].value j12 = self._matrices[i][0][1].value j13 = self._matrices[i][0][2].value j21 = self._matrices[i][1][0].value j22 = self._matrices[i][1][1].value j23 = self._matrices[i][1][2].value j31 = self._matrices[i][2][0].value j32 = self._matrices[i][2][1].value j33 = self._matrices[i][2][2].value monteCarloMats.append(numpy.array([[j11,j12,j13], [j21,j22,j23], [j31,j32,j33]])) #Used later for spinwave calculation jij=sympy.matrices.Matrix([[j11,j12,j13], [j21,j22,j23], [j31,j32,j33]]) jnums.append(i) jmats.append(jij) #Run the monteCarlo simulation #temporary (bad) method of picking tMin/tMax # jAvg = 0 # for mat in monteCarloMats: # jSum = 0 # for i in range(3): # for j in range(3): # val = abs(mat[i][j]) # jSum += val # jAvg += jSum/9 # # self._tMax = jAvg*12 # self._tMin = jAvg/10000 # self._tMax = 10 # self._tMin = 1E-6 print "\n\n\nmonte Carlo Mats:\n", monteCarloMats if self._runMCeveryTime or self._run == 0: #self._handle.write("\n\n\n\n\n------------Get Ground State---------------\n\n") self.spins = get_ground_state(self._k, self._tMax, self._tMin, self._tFactor, self._simpleAtoms, monteCarloMats) else: #self._handle.write("\n\n\n\n\n------------Opt Aux---------------\n\n") self.spins = opt_aux(self._simpleAtoms, monteCarloMats, self.spins) #self.spins = opt_aux(self._simpleAtoms, monteCarloMats, self.spins) #print "\nspins:\n", self.spins #self._handle.write("\n\n\n\nparam:\n\n") #self._handle.write(str(self.fit_list)) #self._handle.write("\n\nSpins After:\n\n") #self._handle.write(str(self.spins)) #self._handle.flush() def inUnitCell(atom): """Returns true of the atom is in the unit cell at Na, Nb, Nc, where those are the dimensions of the interaction cell. That cell is being used to ensure that it is completely surrounded and no interactions are left out. Handles simpleAtom type""" if atom.pos[0] >= self._interactionCellDimensions[0] and atom.pos[0] < (self._interactionCellDimensions[0] + 1): if atom.pos[1] >= self._interactionCellDimensions[1] and atom.pos[1] < (self._interactionCellDimensions[1] + 1): if atom.pos[2] >= self._interactionCellDimensions[2] and atom.pos[2] < (self._interactionCellDimensions[2] + 1): return True return False def inInteractionCell(atoms, atom): """Handles simpleAtom type.""" #First check if the atom is in the first crystallographic cell # if atom.pos[0] < 1.0 and atom.pos[1] < 1.0 and atom.pos[2] < 1.0: # return True #Now the crystallographic unit cell being used is at Na, Nb, Nc, not 0,0,0 if inUnitCell(atom): return True #If not, check if it bonds to an atom that is for i in range(len(atom.interactions)): if inUnitCell(atoms[atom.interactions[i][0]]): return True return False #Do the spinwave calculation spinwave_atoms = [] first_cell_atoms = 0 for i in range(len(self._simpleAtoms)): atom = self._simpleAtoms[i] if inInteractionCell(self._simpleAtoms, atom): Dx = atom.anisotropy[0] Dy = atom.anisotropy[1] Dz = atom.anisotropy[2] spinwave_atom = SpinwaveAtom(pos=atom.pos, Dx=Dx,Dy=Dy,Dz=Dz, orig_Index = i) rmat = findmat(self.spins[i])#indices match up spinwave_atom.spinRmatrix = rmat for interaction in atom.interactions: spinwave_atom.neighbors.append(interaction[0]) spinwave_atom.interactions.append(interaction[1]) spinwave_atoms.append(spinwave_atom) #x,y,z = spinwave_atom.pos #if x<1 and y<1 and z<1: # first_cell_atoms +=1 #Find atoms in desired cell and organize list so they come first tmp = [] for i in range(len(spinwave_atoms)): if inUnitCell(spinwave_atoms[i]): first_cell_atoms += 1 tmp.append(spinwave_atoms.pop(i)) for a in spinwave_atoms: tmp.append(a) spinwave_atoms = tmp #change interaction indices to match indices in new list for a in spinwave_atoms: neighborList = a.neighbors i = 0 while i < len(neighborList): neighbor_index = neighborList[i] for atom_index in range(len(spinwave_atoms)): atom = spinwave_atoms[atom_index] if atom.origIndex == neighbor_index: a.neighbors[i] = atom_index i +=1 break else:#This neighbor index is not in the interaction cell neighborList.pop(i) a.interactions.pop(i) N_atoms=len(spinwave_atoms) Hsave=calculate_dispersion(spinwave_atoms,first_cell_atoms,N_atoms,jmats ,showEigs=False) qrange = [] wrange = [] q = 0 for point in self.spinwave_domain: #print "point:", point wrange.append(calc_eigs(Hsave,point[0], point[1], point[2])) qrange.append(q) q += 1 wrange=numpy.real(wrange) wrange=numpy.array(wrange) wrange=numpy.real(wrange.T) #for wrange1 in wrange: # pylab.plot(qrange,wrange1,'s') #pylab.show() self._run+=1 #self._handle.write("\n\ndispersion:\n\n") #self._handle.write(str(wrange[0])) return wrange[0]#for now just one set
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 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 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')