Ejemplo n.º 1
0
 def test_isub(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.__isub__, other=lat)
     lat.get_lattice(n1=10, n2=10)
     self.assertRaises(TypeError, lat.__isub__, other=0)
     other = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.__isub__, other=other)
Ejemplo n.º 2
0
 def test_add(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.__add__, other=lat)
     lat.get_lattice(n1=10, n2=10)
     self.assertRaises(TypeError, lat.__add__, other=0)
     other = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.__add__, other=other)
Ejemplo n.º 3
0
 def test_shift_y(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.shift_y, 5)
     lat.get_lattice(n1=10, n2=1)
     self.assertRaises(TypeError, lat.shift_y, 0j)
Ejemplo n.º 4
0
 def test_shift_y(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.shift_y, 5)
     lat.get_lattice(n1=10, n2=1)
     self.assertRaises(TypeError, lat.shift_y, 0j)
Ejemplo n.º 5
0
 def test_boundary_line(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.boundary_line, cx=0, cy=0, co=0)
     lat.get_lattice(n1=10)
     self.assertRaises(TypeError, lat.boundary_line, cx=0j, cy=0, co=0)
     self.assertRaises(TypeError, lat.boundary_line, cx=0, cy=0j, co=0)
     self.assertRaises(TypeError, lat.boundary_line, cx=0, cy=0, co=0j)
Ejemplo n.º 6
0
 def test_remove_sites(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.remove_sites, 5)
     lat.get_lattice(n1=10)
     self.assertRaises(TypeError, lat.remove_sites, 0)
     self.assertRaises(ValueError, lat.remove_sites, [-1])
     self.assertRaises(ValueError, lat.remove_sites, [10])
Ejemplo n.º 7
0
 def test_remove_sites(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.remove_sites, 5)
     lat.get_lattice(n1=10)
     self.assertRaises(TypeError, lat.remove_sites, 0)
     self.assertRaises(ValueError, lat.remove_sites, [-1])
     self.assertRaises(ValueError, lat.remove_sites, [10])
Ejemplo n.º 8
0
 def test_get_lattice(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(TypeError, lat.get_lattice, n1='z', n2=1)
     self.assertRaises(TypeError, lat.get_lattice, n1=1, n2='z')
     self.assertRaises(ValueError, lat.get_lattice, n1=-1, n2=1)
     self.assertRaises(ValueError, lat.get_lattice, n1=1, n2=-1)
     self.assertRaises(ValueError, lat.get_lattice, n1=10, n2=10)
Ejemplo n.º 9
0
 def test_boundary_line(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.boundary_line, cx=0, cy=0, co=0)
     lat.get_lattice(n1=10)
     self.assertRaises(TypeError, lat.boundary_line, cx=0j, cy=0, co=0)
     self.assertRaises(TypeError, lat.boundary_line, cx=0, cy=0j, co=0)
     self.assertRaises(TypeError, lat.boundary_line, cx=0, cy=0, co=0j)
Ejemplo n.º 10
0
 def test_get_lattice(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(TypeError, lat.get_lattice, n1='z', n2=1)
     self.assertRaises(TypeError, lat.get_lattice, n1=1, n2='z')
     self.assertRaises(ValueError, lat.get_lattice, n1=-1, n2=1)
     self.assertRaises(ValueError, lat.get_lattice, n1=1, n2=-1)
     self.assertRaises(ValueError, lat.get_lattice, n1=10, n2=10)
Ejemplo n.º 11
0
 def test_ellipse(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.ellipse_in, rx=2, ry=2, x0=0., y0=0.)
     self.assertRaises(RuntimeError, lat.ellipse_out, rx=2, ry=2, x0=0., y0=0.)
     lat.get_lattice(n1=10, n2=10)
     self.assertRaises(TypeError, lat.ellipse_in, rx=2j, ry=2, x0=0., y0=0.)
     self.assertRaises(TypeError, lat.ellipse_in, rx=2, ry=2j, x0=0., y0=0.)
     self.assertRaises(ValueError, lat.ellipse_in, rx=0, ry=2, x0=0., y0=0.)
     self.assertRaises(ValueError, lat.ellipse_in, rx=2, ry=0, x0=0., y0=0.)
     self.assertRaises(TypeError, lat.ellipse_out, rx=2j, ry=2, x0=0., y0=0.)
     self.assertRaises(TypeError, lat.ellipse_out, rx=2, ry=2j, x0=0., y0=0.)
     self.assertRaises(ValueError, lat.ellipse_out, rx=0, ry=2, x0=0., y0=0.)
     self.assertRaises(ValueError, lat.ellipse_out, rx=2, ry=0, x0=0., y0=0.)
Ejemplo n.º 12
0
 def test_square(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     n1, n2 = 2, 2
     lat.get_lattice(n1=n1, n2=n2)
     lat.shift_x(1.)
     lat.shift_y(1.)
     coor = np.array([(1.0, 1.0, b'a'), (2.0, 1.0, b'a'), (1., 2.0, b'a'), (2.0, 2.0, b'a')], 
                               dtype=[('x', 'f8'), ('y', 'f8'), ('tag', 'S1')])
     tags = np.array([b'a'])
     sites = 4
     self.assertTrue(np.allclose(lat.coor['x'], coor['x']) == True)
     self.assertTrue(np.allclose(lat.coor['y'], coor['y']) == True)
     self.assertTrue(np.array_equal(lat.coor['tag'], coor['tag']) == True)
     self.assertTrue(np.array_equal(lat.tags, tags) == True)
     self.assertTrue(lat.sites == sites)
Ejemplo n.º 13
0
 def test_ellipse(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError,
                       lat.ellipse_in,
                       rx=2,
                       ry=2,
                       x0=0.,
                       y0=0.)
     self.assertRaises(RuntimeError,
                       lat.ellipse_out,
                       rx=2,
                       ry=2,
                       x0=0.,
                       y0=0.)
     lat.get_lattice(n1=10, n2=10)
     self.assertRaises(TypeError, lat.ellipse_in, rx=2j, ry=2, x0=0., y0=0.)
     self.assertRaises(TypeError, lat.ellipse_in, rx=2, ry=2j, x0=0., y0=0.)
     self.assertRaises(ValueError, lat.ellipse_in, rx=0, ry=2, x0=0., y0=0.)
     self.assertRaises(ValueError, lat.ellipse_in, rx=2, ry=0, x0=0., y0=0.)
     self.assertRaises(TypeError,
                       lat.ellipse_out,
                       rx=2j,
                       ry=2,
                       x0=0.,
                       y0=0.)
     self.assertRaises(TypeError,
                       lat.ellipse_out,
                       rx=2,
                       ry=2j,
                       x0=0.,
                       y0=0.)
     self.assertRaises(ValueError,
                       lat.ellipse_out,
                       rx=0,
                       ry=2,
                       x0=0.,
                       y0=0.)
     self.assertRaises(ValueError,
                       lat.ellipse_out,
                       rx=2,
                       ry=0,
                       x0=0.,
                       y0=0.)
Ejemplo n.º 14
0
 def test_square(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     n1, n2 = 2, 2
     lat.get_lattice(n1=n1, n2=n2)
     lat.shift_x(1.)
     lat.shift_y(1.)
     coor = np.array([(1.0, 1.0, b'a'), (2.0, 1.0, b'a'), (1., 2.0, b'a'),
                      (2.0, 2.0, b'a')],
                     dtype=[('x', 'f8'), ('y', 'f8'), ('tag', 'S1')])
     tags = np.array([b'a'])
     sites = 4
     self.assertTrue(np.allclose(lat.coor['x'], coor['x']) == True)
     self.assertTrue(np.allclose(lat.coor['y'], coor['y']) == True)
     self.assertTrue(np.array_equal(lat.coor['tag'], coor['tag']) == True)
     self.assertTrue(np.array_equal(lat.tags, tags) == True)
     self.assertTrue(lat.sites == sites)
Ejemplo n.º 15
0
 def test_plot(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.plot)
Ejemplo n.º 16
0
 def test_add_sites(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(TypeError, lat.add_sites,
                                 np.array([(0, 0)], dtype=[('x', 'f8'), ('y', 'f8')]))
Ejemplo n.º 17
0
 def test_add_sites(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(TypeError, lat.add_sites,
                       np.array([(0, 0)], dtype=[('x', 'f8'), ('y', 'f8')]))
Ejemplo n.º 18
0
 def test_plot(self):
     unit_cell = [{'tag': b'a', 'r0': (0, 0)}]
     prim_vec = [(1, 0), (0, 1)]
     lat = lattice(unit_cell=unit_cell, prim_vec=prim_vec)
     self.assertRaises(RuntimeError, lat.plot)