def test_iterator(self): cell = swg.Cell() test = swg.Sublattice() test.setMoment(2.0, np.pi / 2.0, np.pi) test.setName("SL1") test.setType("Fe3") test2 = swg.Sublattice() test2.setMoment(2.0, np.pi / 2.0, np.pi) test2.setName("SL2") test2.setType("Fe3") cell.addSublattice(test) cell.addSublattice(test2) foundSL1 = False foundSL2 = False foundBlank = False for elem in cell: if elem.getName() == "SL1": foundSL1 = True elif elem.getName() == "SL2": foundSL2 = True elif elem.getName() == "": foundBlank = True self.assertTrue(foundSL1) self.assertTrue(foundSL2) self.assertFalse(foundBlank)
def test_add_atom(self): cell = swg.Cell() cell.setBasisVectors(2.0, 2.0, 2.0, 90.0, 90.0, 90.0) test = swg.Sublattice() test.setMoment(2.0, np.pi / 2.0, np.pi) test.setName("SL1") test.setType("Fe3") cell.addSublattice(test) cell.addAtom("SL1", 0.0, 0.0, 0.0) cell.addAtom("SL1", 0.5, 0.5, 0.5) self.assertEqual(len(cell.getSublattice("SL1")), 2) atom0 = np.array([0.0, 0.0, 0.0]) FoundAtom0 = False atom1 = np.array([1.0, 1.0, 1.0]) FoundAtom1 = False for point in cell.getSublattice("SL1"): test0 = point - atom0 test1 = point - atom1 if np.linalg.norm(test0) < 0.01: FoundAtom0 = True if np.linalg.norm(test1) < 0.01: FoundAtom1 = True self.assertTrue(FoundAtom0) self.assertTrue(FoundAtom1)
def test_(self): cell = swg.Cell() cell.setBasisVectors(1.0, 10.0, 10.0, 90.0, 90.0, 90.0) J = 1.0 S = 1.0 spin = swg.Sublattice() name = "Spin0" spin.setName(name) spin.setType("NONE") spin.setMoment(S, 0.0, 0.0) cell.addSublattice(spin) cell.addAtom(name, 0.0, 0.0, 0.0) factory = swg.InteractionFactory() exchange = factory.getExchange("J", J, name, name, 0.9, 1.1) builder = swg.SpinWaveBuilder(cell) builder.addInteraction(exchange) genie = builder.createElement() for k in np.linspace(0.0, 3.0, num=61): genie.createMatrix(k, 0.0, 0.0) genie.calculate() pts = genie.getPoints() #analytical solution for frequency and intensity frequency = 2.0 * J * S * (1.0 - np.cos(2.0 * np.pi * k)) intensity = S / 4.0 self.assertEqual(len(pts), 1) self.assertAlmostEqual(pts[0].frequency, frequency) if np.abs(pts[0].frequency) > 1.0e-5: self.assertAlmostEqual(pts[0].intensity, intensity)
def test_add_sublattice(self): test = swg.Sublattice() test.setMoment(2.0, np.pi / 2.0, np.pi) test.setName("SL1") test.setType("Fe3") SLtest = swg.Cell() SLtest.addSublattice(test) self.assertEqual(len(SLtest), 1)
def createMnBiCell(): cell = swg.Cell() cell.setBasisVectors(4.2827, 4.2827, 6.1103, 90.0, 90.0, 120.0) Spin0 = swg.Sublattice() Spin0.setName("Spin0") Spin0.setType("MN2") Spin0.setMoment(2.0, np.pi / 2.0, 0.0) cell.addSublattice(Spin0) cell.addAtom("Spin0", 0.0, 0.0, 0.0) cell.addAtom("Spin0", 0.0, 0.0, 0.5) return cell
def test_getExchange(self): factory = swg.InteractionFactory() exchange = factory.getExchange("J", 1.0, "SA", "SB", 2.0, 2.1) self.assertEqual(exchange.getName(), "J") sl = exchange.sublattices() self.assertEqual(sl[0], "SA") self.assertEqual(sl[1], "SB")
def test_eight_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 8.45, 8.65) self.assertEqual(len(neighborList), 6) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 8.5654, places=6)
def test_seventh_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 7.9, 8.1) self.assertEqual(len(neighborList), 12) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 8.022375, places=6)
def test_sixth_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 7.44, 7.49) self.assertEqual(len(neighborList), 12) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 7.46172134, places=6)
def test_fifth_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 7.40, 7.42) self.assertEqual(len(neighborList), 6) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 7.41785399, places=6)
def test_third_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 5.2, 5.3) self.assertEqual(len(neighborList), 12) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 5.260747, places=6)
def test_second_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 4.2, 4.3) self.assertEqual(len(neighborList), 6) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 4.2827, places=6)
def test_first_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 3.0, 3.1) self.assertEqual(len(neighborList), 2) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 3.05515, places=6)
def test_constructor(self): test = swg.Sublattice() self.assertEqual(test.getName(), "") self.assertEqual(test.getType(), "None") self.assertAlmostEqual(test.getMoment(), 0.0) self.assertAlmostEqual(test.getTheta(), 0.0) self.assertAlmostEqual(test.getPhi(), 0.0)
def test_tenth_neighbors(self): cell = createMnBiCell() neighborList = swg.Neighbors() neighborList.findNeighbors(cell, "Spin0", "Spin0", 9.1, 9.2) self.assertEqual(len(neighborList), 2) for pt in neighborList: self.assertAlmostEqual(np.linalg.norm(pt), 9.16545, places=6)
def test_getAnisotropy(self): factory = swg.InteractionFactory() anisotropy = factory.getAnisotropy("K", 1.0, [0.0, 0.0, 1.0], "SA") self.assertEqual(anisotropy.getName(), "K") sl = anisotropy.sublattices() self.assertEqual(sl[0], "SA") self.assertEqual(sl[1], "SA")
def test_getMagneticField(self): factory = swg.InteractionFactory() magnetic_field = factory.getMagneticField("B",1.0,[0.0,0.0,1.0],"SA") self.assertEqual(magnetic_field.getName(),"B") sl = magnetic_field.sublattices() self.assertEqual(sl[0],"SA") self.assertEqual(sl[1],"SA")
def test_sublattice_position(self): test = swg.Sublattice() test.setMoment(2.0, np.pi / 2.0, np.pi) test.setName("SL1") test.setType("Fe3") test2 = swg.Sublattice() test2.setMoment(2.0, np.pi / 2.0, np.pi) test2.setName("SL2") test2.setType("Fe3") SLtest = swg.Cell() SLtest.addSublattice(test) SLtest.addSublattice(test2) self.assertEqual(SLtest.getPosition("SL1"), 0) self.assertEqual(SLtest.getPosition("SL2"), 1)
def test_getDzyaloshinskiiMoriya(self): factory = swg.InteractionFactory() dm = factory.getDzyaloshinskiiMoriya("D",1.0,[1.0,0.0,0.0],"SA","SB",2.0,2.1) self.assertEqual(dm.getName(),"D") sl = dm.sublattices() self.assertEqual(sl[0],"SA") self.assertEqual(sl[1],"SB")
def test_clear(self): doubleTest = swg.ThreeVectors() doubleTest.insert(1.0, 1.0, 1.0) self.assertEquals(len(doubleTest), 1) doubleTest.clear() self.assertEquals(len(doubleTest), 0)
def test_insert(self): doubleTest = swg.UniqueThreeVectors() doubleTest.insert(1.0, 1.0, 1.0) self.assertEquals(len(doubleTest), 1) it = iter(doubleTest) value = next(it) self.assertAlmostEquals(value[0], 1.0) self.assertAlmostEquals(value[1], 1.0) self.assertAlmostEquals(value[2], 1.0)
def test_cubic_basis_vectors(self): ActualBasisVectors = 2.0 * np.identity(3) ActualReciprocalVectors = np.pi * np.identity(3) test = swg.Cell() test.setBasisVectors(2.0, 2.0, 2.0, 90.0, 90.0, 90.0) CalculatedBasisVectors = test.getBasisVectors() for actual, calc in zip(ActualBasisVectors.flatten(), test.getBasisVectors().flatten()): self.assertAlmostEquals(calc, actual) for actual, calc in zip(ActualReciprocalVectors.flatten(), test.getReciprocalVectors().flatten()): self.assertAlmostEquals(calc, actual)
def test_iterator(self): doubleTest = swg.ThreeVectors() doubleTest.insert(1.0, 1.0, 1.0) doubleTest.insert(2.0, 2.0, 2.0) self.assertEquals(len(doubleTest), 2) it = iter(doubleTest) value = next(it) self.assertAlmostEquals(value[0], 1.0) self.assertAlmostEquals(value[1], 1.0) self.assertAlmostEquals(value[2], 1.0) value = next(it) self.assertAlmostEquals(value[1], 2.0) self.assertAlmostEquals(value[2], 2.0)
def test_hexagonal_basis_vectors(self): ActualBasisVectors = np.array([[1.0, 0.0, 0.0], [-0.5, 0.5 * np.sqrt(3.0), 0.0], [0.0, 0.0, 1.0]]) ActualReciprocalVectors = np.array( [[2.0 * np.pi, 2.0 * np.pi / np.sqrt(3.0), 0.0], [0.0, 4.0 * np.pi / np.sqrt(3.0), 0.0], [0.0, 0.0, 2.0 * np.pi]]) test = swg.Cell() test.setBasisVectors(1.0, 1.0, 1.0, 90.0, 90.0, 120.0) for actual, calc in zip(ActualBasisVectors.flatten(), test.getBasisVectors().flatten()): self.assertAlmostEquals(calc, actual) for actual, calc in zip(ActualReciprocalVectors.flatten(), test.getReciprocalVectors().flatten()): self.assertAlmostEquals(calc, actual)
def test_atoms(self): test = swg.Sublattice() test.addAtom(0.0, 0.0, 0.0) test.addAtom(0.5, 0.5, 0.5) self.assertEqual(len(test), 2) atom0 = np.array([0.0, 0.0, 0.0]) FoundAtom0 = False atom1 = np.array([0.25, 0.25, 0.25]) FoundAtom1 = False for point in test: test0 = point - atom0 test1 = point - atom1 if np.linalg.norm(test0) < 0.01: FoundAtom0 = True if np.linalg.norm(test1) < 0.01: FoundAtom1 = True self.assertTrue(FoundAtom0) self.assertFalse(FoundAtom1)
import SpinWaveGenie as swg import numpy as np cell = swg.Cell() cell.setBasisVectors(1.0, 10.0, 10.0, 90.0, 90.0, 90.0) S = 1.0 J = -1.0 D = 0.1 xhat = np.array([1., 0., 0.]) spin0 = swg.Sublattice() name0 = "Spin0" spin0.setName(name0) spin0.setType("NONE") spin0.setMoment(S, 0.0, 0.0) cell.addSublattice(spin0) cell.addAtom(name0, 0.0, 0.0, 0.0) spin1 = swg.Sublattice() name1 = "Spin1" spin1.setName(name1) spin1.setType("NONE") spin1.setMoment(S, np.pi, 0.0) cell.addSublattice(spin1) cell.addAtom(name1, 0.5, 0.0, 0.0) factory = swg.InteractionFactory() exchange = factory.getExchange("J", J, name0, name1, 0.45, 0.55) anisotropy0 = factory.getAnisotropy("D", D, xhat, name0) anisotropy1 = factory.getAnisotropy("D", D, xhat, name1) builder = swg.SpinWaveBuilder(cell)
def test_rotation_matrices(self): test = swg.Sublattice() RotationMatrix = test.getRotationMatrix() InverseMatrix = test.getInverseMatrix() self.assertTrue((RotationMatrix == np.identity(3)).all()) self.assertTrue((InverseMatrix == np.identity(3)).all())
while np.prod(abs(mm)) < 1: nnnidxs = get_neighbor_idx(at_num, mn, 1, max_radii=3.) mm[nnnidxs] = -mm[at_num] at_num += 1 mn.set_initial_magnetic_moments(mm) inpos = mn.get_scaled_positions() #Define spin direction as in the plane # component perp to plane Sx_vec = np.cross(inpos[1, :], inpos[2, :]) / np.linalg.norm( np.cross(inpos[1, :], inpos[2, :])) # component in plane and perpendicular to moment direction. Sy_vec = inpos[1, :] / np.linalg.norm(inpos[1, :]) # Moment direction Sz_vec = np.cross(Sx_vec, Sy_vec) # start setting up spin wave genie cell = swg.Cell() # use unit cell from ase incell = mn.get_cell_lengths_and_angles() cell.setBasisVectors(*incell) # generate sublattice with + spin direction Mn1 = swg.Sublattice() Mn1.setName("Mn1") Mn1.setType("MN2") Mn1.setMoment(2.5, 1.15026, 5.8195) #Mn1.setMoment(2.5,0,0) #generate sublattice with - spin direction Mn2 = swg.Sublattice() Mn2.setName("Mn2") Mn2.setType("MN2") Mn2.setMoment(2.5, 1.99133, 2.6779) # add the subblatices to the cells
def test_moment(self): test = swg.Sublattice() test.setMoment(2.0, np.pi / 2.0, np.pi) self.assertAlmostEqual(test.getMoment(), 2.0) self.assertAlmostEqual(test.getTheta(), np.pi / 2.0) self.assertAlmostEqual(test.getPhi(), np.pi)