示例#1
0
class TestGrid(object):
    def setUp(self):
        alat = 1.42
        sq3h = 3.**.5 * 0.5
        self.sc = SuperCell(np.array(
            [[1.5, sq3h, 0.], [1.5, -sq3h, 0.], [0., 0., 10.]], np.float64) *
                            alat,
                            nsc=[3, 3, 1])
        self.g = Grid([10, 10, 100], sc=self.sc)

    def tearDown(self):
        del self.sc
        del self.g

    def test_append(self):
        g = self.g.append(self.g, 0)
        assert_true(np.allclose(g.grid.shape, [20, 10, 100]))
        g = self.g.append(self.g, 1)
        assert_true(np.allclose(g.grid.shape, [10, 20, 100]))
        g = self.g.append(self.g, 2)
        assert_true(np.allclose(g.grid.shape, [10, 10, 200]))

    def test_size(self):
        assert_true(np.allclose(self.g.grid.shape, [10, 10, 100]))

    def test_item(self):
        assert_true(
            np.allclose(self.g[1:2, 1:2, 2:3], self.g.grid[1:2, 1:2, 2:3]))

    def test_dcell(self):
        assert_true(np.all(self.g.dcell * self.g.cell >= 0))

    def test_dvol(self):
        assert_true(self.g.dvol > 0)

    def test_shape(self):
        assert_true(np.all(self.g.shape == self.g.grid.shape))

    def test_dtype(self):
        assert_true(self.g.dtype == self.g.grid.dtype)

    def test_copy(self):
        assert_true(self.g.copy() == self.g)

    def test_swapaxes(self):
        g = self.g.swapaxes(0, 1)
        assert_true(np.allclose(self.g.cell[0, :], g.cell[1, :]))
        assert_true(np.allclose(self.g.cell[1, :], g.cell[0, :]))

    def test_interp(self):
        shape = np.array(self.g.shape, np.int32)
        g = self.g.interp(shape * 2)
        g1 = g.interp(shape)
        assert_true(np.allclose(self.g.grid, g1.grid))

    def test_index1(self):
        mid = np.array(self.g.shape, np.int32) // 2
        idx = self.g.index(self.sc.center())
        print(mid, idx)
        assert_true(np.all(mid == idx))

    def test_sum(self):
        for i in range(3):
            assert_true(self.g.sum(i).shape[i] == 1)

    def test_mean(self):
        for i in range(3):
            assert_true(self.g.mean(i).shape[i] == 1)

    def test_cross_section(self):
        for i in range(3):
            assert_true(self.g.cross_section(1, i).shape[i] == 1)

    def test_remove_part(self):
        for i in range(3):
            assert_true(self.g.remove_part(1, i, above=True).shape[i] == 1)

    def test_sub_part(self):
        for i in range(3):
            assert_true(self.g.sub_part(1, i, above=False).shape[i] == 1)

    def test_sub(self):
        for i in range(3):
            assert_true(self.g.sub(1, i).shape[i] == 1)
        for i in range(3):
            assert_true(self.g.sub([1, 2], i).shape[i] == 2)

    def test_remove(self):
        for i in range(3):
            assert_true(self.g.remove(1, i).shape[i] == self.g.shape[i] - 1)
        for i in range(3):
            assert_true(
                self.g.remove([1, 2], i).shape[i] == self.g.shape[i] - 2)

    def test_argumentparser(self):
        self.g.ArgumentParser()
示例#2
0
class TestSuperCell(object):
    def setUp(self):
        alat = 1.42
        sq3h = 3.**.5 * 0.5
        self.sc = SuperCell(np.array(
            [[1.5, sq3h, 0.], [1.5, -sq3h, 0.], [0., 0., 10.]], np.float64) *
                            alat,
                            nsc=[3, 3, 1])

    def tearDown(self):
        del self.sc

    def test_repr(self):
        repr(self.sc)
        str(self.sc)
        assert_false(self.sc == 'Not a SuperCell')

    def test_nsc1(self):
        sc = self.sc.copy()
        sc.set_nsc([5, 5, 0])
        assert_true(np.allclose([5, 5, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))

    def test_nsc2(self):
        sc = self.sc.copy()
        sc.set_nsc([0, 1, 0])
        assert_true(np.allclose([1, 1, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))
        sc.set_nsc(a=3)
        assert_true(np.allclose([3, 1, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))
        sc.set_nsc(b=3)
        assert_true(np.allclose([3, 3, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))
        sc.set_nsc(c=5)
        assert_true(np.allclose([3, 3, 5], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))

    def test_nsc3(self):
        assert_raises(ValueError, self.sc.set_nsc, a=2)
        assert_raises(ValueError, self.sc.set_nsc, b=2)
        assert_raises(ValueError, self.sc.set_nsc, c=2)
        assert_raises(ValueError, self.sc.set_nsc, [1, 2, 3])

    def test_nsc4(self):
        assert_true(self.sc.sc_index([0, 0, 0]) == 0)
        for s in range(self.sc.n_s):
            assert_true(self.sc.sc_index(self.sc.sc_off[s, :]) == s)
        arng = np.arange(self.sc.n_s)
        np.random.shuffle(arng)
        sc_off = self.sc.sc_off[arng, :]
        assert_true(np.all(self.sc.sc_index(sc_off) == arng))

    def test_fill(self):
        sc = self.sc.swapaxes(1, 2)
        i = sc._fill([1, 1])
        assert_true(i.dtype == np.int32)
        i = sc._fill([1., 1.])
        assert_true(i.dtype == np.float64)
        for dt in [np.int32, np.int64, np.float32, np.float64, np.complex64]:
            i = sc._fill([1., 1.], dt)
            assert_true(i.dtype == dt)
            i = sc._fill(np.ones([2], dt))
            assert_true(i.dtype == dt)

    def test_add_vacuum1(self):
        sc = self.sc.copy()
        for i in range(3):
            s = sc.add_vacuum(10, i)
            ax = self.sc.cell[i, :]
            ax += ax / np.sum(ax**2)**.5 * 10
            assert_true(np.allclose(ax, s.cell[i, :]))

    def test_rotation1(self):
        rot = self.sc.rotate(180, [0, 0, 1])
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = self.sc.rotate(m.pi, [0, 0, 1], radians=True)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = rot.rotate(180, [0, 0, 1])
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(rot.cell, self.sc.cell))

    def test_rotation2(self):
        rot = self.sc.rotatec(180)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = self.sc.rotatec(m.pi, radians=True)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = rot.rotatec(180)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(rot.cell, self.sc.cell))

    def test_rotation3(self):
        rot = self.sc.rotatea(180)
        assert_true(np.allclose(rot.cell[0, :], self.sc.cell[0, :]))
        assert_true(np.allclose(-rot.cell[2, 2], self.sc.cell[2, 2]))

        rot = self.sc.rotateb(m.pi, radians=True)
        assert_true(np.allclose(rot.cell[1, :], self.sc.cell[1, :]))
        assert_true(np.allclose(-rot.cell[2, 2], self.sc.cell[2, 2]))

    def test_swapaxes1(self):
        sab = self.sc.swapaxes(0, 1)
        assert_true(np.allclose(sab.cell[0, :], self.sc.cell[1, :]))
        assert_true(np.allclose(sab.cell[1, :], self.sc.cell[0, :]))

    def test_swapaxes2(self):
        sab = self.sc.swapaxes(0, 2)
        assert_true(np.allclose(sab.cell[0, :], self.sc.cell[2, :]))
        assert_true(np.allclose(sab.cell[2, :], self.sc.cell[0, :]))

    def test_swapaxes3(self):
        sab = self.sc.swapaxes(1, 2)
        assert_true(np.allclose(sab.cell[1, :], self.sc.cell[2, :]))
        assert_true(np.allclose(sab.cell[2, :], self.sc.cell[1, :]))

    def test_offset1(self):
        off = self.sc.offset()
        assert_true(np.allclose(off, [0, 0, 0]))
        off = self.sc.offset([1, 1, 1])
        cell = self.sc.cell[:, :]
        assert_true(np.allclose(off, cell[0, :] + cell[1, :] + cell[2, :]))

    def test_sc_index1(self):
        sc_index = self.sc.sc_index([0, 0, 0])
        assert_equal(sc_index, 0)
        assert_raises(Exception, self.sc.sc_index, [100, 100, 100])
        sc_index = self.sc.sc_index([0, 0, None])
        assert_equal(len(sc_index), self.sc.nsc[2])

    def test_sc_index2(self):
        sc_index = self.sc.sc_index([[0, 0, 0], [1, 1, 0]])
        assert_equal(len(sc_index), 2)

    def test_cut1(self):
        cut = self.sc.cut(2, 0)
        assert_true(np.allclose(cut.cell[0, :] * 2, self.sc.cell[0, :]))
        assert_true(np.allclose(cut.cell[1, :], self.sc.cell[1, :]))

    def test_creation1(self):
        # full cell
        tmp1 = SuperCell([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        # diagonal cell
        tmp2 = SuperCell([1, 1, 1])
        # cell parameters
        tmp3 = SuperCell([1, 1, 1, 90, 90, 90])
        tmp4 = SuperCell([1])
        assert_true(np.allclose(tmp1.cell, tmp2.cell))
        assert_true(np.allclose(tmp1.cell, tmp3.cell))
        assert_true(np.allclose(tmp1.cell, tmp4.cell))

    def test_creation2(self):
        # full cell
        class P(SuperCellChild):
            def copy(self):
                a = P()
                a.set_supercell(self.sc)
                return a

        tmp1 = P()
        tmp1.set_supercell([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        # diagonal cell
        tmp2 = P()
        tmp2.set_supercell([1, 1, 1])
        # cell parameters
        tmp3 = P()
        tmp3.set_supercell([1, 1, 1, 90, 90, 90])
        tmp4 = P()
        tmp4.set_supercell([1])
        assert_true(np.allclose(tmp1.cell, tmp2.cell))
        assert_true(np.allclose(tmp1.cell, tmp3.cell))
        assert_true(np.allclose(tmp1.cell, tmp4.cell))
        assert_true(len(tmp1._fill([0, 0, 0])) == 3)
        assert_true(len(tmp1._fill_sc([0, 0, 0])) == 3)
        assert_true(tmp1.is_orthogonal())
        for i in range(3):
            t2 = tmp2.add_vacuum(10, i)
            assert_true(tmp1.cell[i, i] + 10 == t2.cell[i, i])

    def test_creation3(self):
        assert_raises(ValueError, self.sc.tocell, [3, 6])
        assert_raises(ValueError, self.sc.tocell, [3, 4, 5, 6])
        assert_raises(ValueError, self.sc.tocell, [3, 4, 5, 6, 7])
        assert_raises(ValueError, self.sc.tocell, [3, 4, 5, 6, 7, 6, 7])

    def test_rcell(self):
        # LAPACK inverse algorithm implicitly does
        # a transpose.
        rcell = sli.inv(self.sc.cell) * 2. * np.pi
        assert_true(np.allclose(rcell.T, self.sc.rcell))

    def test_translate1(self):
        sc = self.sc.translate([0, 0, 10])
        assert_true(np.allclose(sc.cell[2, :2], self.sc.cell[2, :2]))
        assert_true(np.allclose(sc.cell[2, 2], self.sc.cell[2, 2] + 10))

    def test_center1(self):
        assert_true(
            np.allclose(self.sc.center(),
                        np.sum(self.sc.cell, axis=0) / 2))
        for i in [0, 1, 2]:
            assert_true(np.allclose(self.sc.center(i), self.sc.cell[i, :] / 2))

    def test_pickle(self):
        import pickle as p
        s = p.dumps(self.sc)
        n = p.loads(s)
        assert_true(self.sc == n)
        assert_false(self.sc != n)
        s = SuperCell([1, 1, 1])
        assert_false(self.sc == s)

    def test_orthogonal(self):
        assert_false(self.sc.is_orthogonal())

    def test_fit1(self):
        g = graphene()
        gbig = g.repeat(40, 0).repeat(40, 1)
        gbig.xyz[:, :] += (np.random.rand(len(gbig), 3) - 0.5) * 0.01
        sc = g.sc.fit(gbig)
        assert_true(np.allclose(sc.cell, gbig.cell))

    def test_fit2(self):
        g = graphene(orthogonal=True)
        gbig = g.repeat(40, 0).repeat(40, 1)
        gbig.xyz[:, :] += (np.random.rand(len(gbig), 3) - 0.5) * 0.01
        sc = g.sc.fit(gbig)
        assert_true(np.allclose(sc.cell, gbig.cell))

    def test_fit3(self):
        g = graphene(orthogonal=True)
        gbig = g.repeat(40, 0).repeat(40, 1)
        gbig.xyz[:, :] += (np.random.rand(len(gbig), 3) - 0.5) * 0.01
        sc = g.sc.fit(gbig, axis=0)
        assert_true(np.allclose(sc.cell[0, :], gbig.cell[0, :]))
        assert_true(np.allclose(sc.cell[1:, :], g.cell[1:, :]))

    def test_fit4(self):
        g = graphene(orthogonal=True)
        gbig = g.repeat(40, 0).repeat(40, 1)
        gbig.xyz[:, :] += (np.random.rand(len(gbig), 3) - 0.5) * 0.01
        sc = g.sc.fit(gbig, axis=[0, 1])
        assert_true(np.allclose(sc.cell[0:2, :], gbig.cell[0:2, :]))
        assert_true(np.allclose(sc.cell[2, :], g.cell[2, :]))

    def test_parallel1(self):
        g = graphene(orthogonal=True)
        gbig = g.repeat(40, 0).repeat(40, 1)
        assert_true(g.sc.parallel(gbig.sc))
        assert_true(gbig.sc.parallel(g.sc))
        g = g.rotatea(90)
        assert_false(g.sc.parallel(gbig.sc))
示例#3
0
class TestGrid(object):
    def setUp(self):
        alat = 1.42
        sq3h = 3.**.5 * 0.5
        self.sc = SuperCell(np.array(
            [[1.5, sq3h, 0.], [1.5, -sq3h, 0.], [0., 0., 10.]], np.float64) *
                            alat,
                            nsc=[3, 3, 1])
        self.g = Grid([10, 10, 100], sc=self.sc)
        self.g[:, :, :] = 2.
        g = Grid(sc=self.sc)

    def tearDown(self):
        del self.sc
        del self.g

    def test_append(self):
        g = self.g.append(self.g, 0)
        assert_true(np.allclose(g.grid.shape, [20, 10, 100]))
        g = self.g.append(self.g, 1)
        assert_true(np.allclose(g.grid.shape, [10, 20, 100]))
        g = self.g.append(self.g, 2)
        assert_true(np.allclose(g.grid.shape, [10, 10, 200]))

    def test_set(self):
        v = self.g[0, 0, 0]
        self.g[0, 0, 0] = 3
        assert_true(self.g.grid[0, 0, 0] == 3)
        assert_true(self.g[0, 0, 0] == 3)
        self.g[0, 0, 0] = v
        assert_true(self.g[0, 0, 0] == v)

    def test_size(self):
        assert_true(np.allclose(self.g.grid.shape, [10, 10, 100]))

    def test_item(self):
        assert_true(
            np.allclose(self.g[1:2, 1:2, 2:3], self.g.grid[1:2, 1:2, 2:3]))

    def test_dcell(self):
        assert_true(np.all(self.g.dcell * self.g.cell >= 0))

    def test_dvol(self):
        assert_true(self.g.dvol > 0)

    def test_shape(self):
        assert_true(np.all(self.g.shape == self.g.grid.shape))

    def test_dtype(self):
        assert_true(self.g.dtype == self.g.grid.dtype)

    def test_copy(self):
        assert_true(self.g.copy() == self.g)
        assert_false(self.g.copy() != self.g)

    def test_add(self):
        g = self.g + self.g
        assert_true(np.allclose(g.grid, (self.g * 2).grid))
        g = self.g.copy()
        g *= 2
        assert_true(np.allclose(g.grid, (self.g * 2).grid))
        g = self.g.copy()
        g /= 2
        assert_true(np.allclose(g.grid, (self.g / 2).grid))

    def test_swapaxes(self):
        g = self.g.swapaxes(0, 1)
        assert_true(np.allclose(self.g.cell[0, :], g.cell[1, :]))
        assert_true(np.allclose(self.g.cell[1, :], g.cell[0, :]))

    def test_interp(self):
        shape = np.array(self.g.shape, np.int32)
        g = self.g.interp(shape * 2)
        g1 = g.interp(shape)
        # Sadly the interpolation does not work as it really
        # should...
        # One cannot interp down/up and retrieve the same
        # grid... Perhaps this is ok, but not good... :(
        assert_true(np.allclose(self.g.grid, g1.grid))

    def test_index1(self):
        mid = np.array(self.g.shape, np.int32) // 2
        idx = self.g.index(self.sc.center())
        assert_true(np.all(mid == idx))

    def test_sum(self):
        for i in range(3):
            assert_true(self.g.sum(i).shape[i] == 1)

    def test_mean(self):
        for i in range(3):
            assert_true(self.g.mean(i).shape[i] == 1)

    def test_cross_section(self):
        for i in range(3):
            assert_true(self.g.cross_section(1, i).shape[i] == 1)

    def test_remove_part(self):
        for i in range(3):
            assert_true(self.g.remove_part(1, i, above=True).shape[i] == 1)

    def test_sub_part(self):
        for i in range(3):
            assert_true(self.g.sub_part(1, i, above=False).shape[i] == 1)
            assert_true(
                self.g.sub_part(1, i, above=True).shape[i] == self.g.shape[i] -
                1)

    def test_sub(self):
        for i in range(3):
            assert_true(self.g.sub(1, i).shape[i] == 1)
        for i in range(3):
            assert_true(self.g.sub([1, 2], i).shape[i] == 2)

    def test_remove(self):
        for i in range(3):
            assert_true(self.g.remove(1, i).shape[i] == self.g.shape[i] - 1)
        for i in range(3):
            assert_true(
                self.g.remove([1, 2], i).shape[i] == self.g.shape[i] - 2)

    def test_argumentparser(self):
        self.g.ArgumentParser()
示例#4
0
文件: test_grid.py 项目: zerothi/sisl
class TestGrid(object):

    def setUp(self):
        alat = 1.42
        sq3h = 3.**.5 * 0.5
        self.sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                      [1.5, -sq3h, 0.],
                                      [0., 0., 10.]], np.float64) * alat, nsc=[3, 3, 1])
        self.g = Grid([10, 10, 100], sc=self.sc)

    def tearDown(self):
        del self.sc
        del self.g

    def test_append(self):
        g = self.g.append(self.g, 0)
        assert_true(np.allclose(g.grid.shape, [20, 10, 100]))
        g = self.g.append(self.g, 1)
        assert_true(np.allclose(g.grid.shape, [10, 20, 100]))
        g = self.g.append(self.g, 2)
        assert_true(np.allclose(g.grid.shape, [10, 10, 200]))

    def test_size(self):
        assert_true(np.allclose(self.g.grid.shape, [10, 10, 100]))
        
    def test_item(self):
        assert_true(np.allclose(self.g[1:2, 1:2, 2:3], self.g.grid[1:2, 1:2, 2:3]))

    def test_dcell(self):
        assert_true(np.all(self.g.dcell*self.g.cell >= 0))

    def test_dvol(self):
        assert_true(self.g.dvol > 0)

    def test_shape(self):
        assert_true(np.all(self.g.shape == self.g.grid.shape))

    def test_dtype(self):
        assert_true(self.g.dtype == self.g.grid.dtype)

    def test_copy(self):
        assert_true(self.g.copy() == self.g)

    def test_swapaxes(self):
        g = self.g.swapaxes(0, 1)
        assert_true(np.allclose(self.g.cell[0,:], g.cell[1,:]))
        assert_true(np.allclose(self.g.cell[1,:], g.cell[0,:]))

    def test_interp(self):
        shape = np.array(self.g.shape, np.int32)
        g = self.g.interp(shape * 2)
        g1 = g.interp(shape)
        assert_true(np.allclose(self.g.grid, g1.grid))

    def test_index1(self):
        mid = np.array(self.g.shape, np.int32) // 2
        idx = self.g.index(self.sc.center())
        print(mid, idx)
        assert_true(np.all(mid == idx))

    def test_sum(self):
        for i in range(3):
            assert_true(self.g.sum(i).shape[i] == 1)

    def test_mean(self):
        for i in range(3):
            assert_true(self.g.mean(i).shape[i] == 1)

    def test_cross_section(self):
        for i in range(3):
            assert_true(self.g.cross_section(1, i).shape[i] == 1)

    def test_remove_part(self):
        for i in range(3):
            assert_true(self.g.remove_part(1, i, above=True).shape[i] == 1)

    def test_sub_part(self):
        for i in range(3):
            assert_true(self.g.sub_part(1, i, above=False).shape[i] == 1)

    def test_sub(self):
        for i in range(3):
            assert_true(self.g.sub(1, i).shape[i] == 1)
        for i in range(3):
            assert_true(self.g.sub([1,2], i).shape[i] == 2)

    def test_remove(self):
        for i in range(3):
            assert_true(self.g.remove(1, i).shape[i] == self.g.shape[i]-1)
        for i in range(3):
            assert_true(self.g.remove([1,2], i).shape[i] == self.g.shape[i]-2)

    def test_argumentparser(self):
        self.g.ArgumentParser()
示例#5
0
class TestSuperCell(object):

    def setUp(self):
        alat = 1.42
        sq3h = 3.**.5 * 0.5
        self.sc = SuperCell(np.array([[1.5, sq3h, 0.],
                                      [1.5, -sq3h, 0.],
                                      [0., 0., 10.]], np.float64) * alat, nsc=[3, 3, 1])

    def tearDown(self):
        del self.sc

    def test_repr(self):
        print(self.sc)
        assert_false(self.sc == 'Not a SuperCell')

    def test_nsc1(self):
        sc = self.sc.copy()
        sc.set_nsc([5, 5, 0])
        assert_true(np.allclose([5, 5, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))

    def test_nsc2(self):
        sc = self.sc.copy()
        sc.set_nsc([0, 1, 0])
        assert_true(np.allclose([1, 1, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))
        sc.set_nsc(a=3)
        assert_true(np.allclose([3, 1, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))
        sc.set_nsc(b=3)
        assert_true(np.allclose([3, 3, 1], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))
        sc.set_nsc(c=5)
        assert_true(np.allclose([3, 3, 5], sc.nsc))
        assert_true(len(sc.sc_off) == np.prod(sc.nsc))

    def test_nsc3(self):
        assert_raises(ValueError, self.sc.set_nsc, a=2)
        assert_raises(ValueError, self.sc.set_nsc, b=2)
        assert_raises(ValueError, self.sc.set_nsc, c=2)
        assert_raises(ValueError, self.sc.set_nsc, [1, 2, 3])

    def test_nsc4(self):
        assert_true(self.sc.sc_index([0, 0, 0]) == 0)

    def test_rotation1(self):
        rot = self.sc.rotate(180, [0, 0, 1])
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = self.sc.rotate(m.pi, [0, 0, 1], radians=True)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = rot.rotate(180, [0, 0, 1])
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(rot.cell, self.sc.cell))

    def test_rotation2(self):
        rot = self.sc.rotatec(180)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = self.sc.rotatec(m.pi, radians=True)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(-rot.cell, self.sc.cell))

        rot = rot.rotatec(180)
        rot.cell[2, 2] *= -1
        assert_true(np.allclose(rot.cell, self.sc.cell))

    def test_rotation3(self):
        rot = self.sc.rotatea(180)
        assert_true(np.allclose(rot.cell[0, :], self.sc.cell[0, :]))
        assert_true(np.allclose(-rot.cell[2, 2], self.sc.cell[2, 2]))

        rot = self.sc.rotateb(m.pi, radians=True)
        assert_true(np.allclose(rot.cell[1, :], self.sc.cell[1, :]))
        assert_true(np.allclose(-rot.cell[2, 2], self.sc.cell[2, 2]))

    def test_swapaxes1(self):
        sab = self.sc.swapaxes(0, 1)
        assert_true(np.allclose(sab.cell[0, :], self.sc.cell[1, :]))
        assert_true(np.allclose(sab.cell[1, :], self.sc.cell[0, :]))

    def test_swapaxes2(self):
        sab = self.sc.swapaxes(0, 2)
        assert_true(np.allclose(sab.cell[0, :], self.sc.cell[2, :]))
        assert_true(np.allclose(sab.cell[2, :], self.sc.cell[0, :]))

    def test_swapaxes3(self):
        sab = self.sc.swapaxes(1, 2)
        assert_true(np.allclose(sab.cell[1, :], self.sc.cell[2, :]))
        assert_true(np.allclose(sab.cell[2, :], self.sc.cell[1, :]))

    def test_offset1(self):
        off = self.sc.offset()
        assert_true(np.allclose(off, [0, 0, 0]))
        off = self.sc.offset([1, 1, 1])
        cell = self.sc.cell[:, :]
        assert_true(np.allclose(off, cell[0, :] + cell[1, :] + cell[2, :]))

    def test_sc_index1(self):
        sc_index = self.sc.sc_index([0, 0, 0])
        assert_equal(sc_index, 0)
        assert_raises(Exception, self.sc.sc_index, [100, 100, 100])
        sc_index = self.sc.sc_index([0, 0, None])
        assert_equal(len(sc_index), self.sc.nsc[2])

    def test_cut1(self):
        cut = self.sc.cut(2, 0)
        assert_true(np.allclose(cut.cell[0, :] * 2, self.sc.cell[0, :]))
        assert_true(np.allclose(cut.cell[1, :], self.sc.cell[1, :]))

    def test_creation(self):
        # full cell
        tmp1 = SuperCell([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        # diagonal cell
        tmp2 = SuperCell([1, 1, 1])
        # cell parameters
        tmp3 = SuperCell([1, 1, 1, 90, 90, 90])
        tmp4 = SuperCell([1])
        assert_true(np.allclose(tmp1.cell, tmp2.cell))
        assert_true(np.allclose(tmp1.cell, tmp3.cell))
        assert_true(np.allclose(tmp1.cell, tmp4.cell))

    def test_creation2(self):
        # full cell
        class P(SuperCellChild):
            pass
        tmp1 = P()
        tmp1.set_supercell([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
        # diagonal cell
        tmp2 = P()
        tmp2.set_supercell([1, 1, 1])
        # cell parameters
        tmp3 = P()
        tmp3.set_supercell([1, 1, 1, 90, 90, 90])
        tmp4 = P()
        tmp4.set_supercell([1])
        assert_true(np.allclose(tmp1.cell, tmp2.cell))
        assert_true(np.allclose(tmp1.cell, tmp3.cell))
        assert_true(np.allclose(tmp1.cell, tmp4.cell))

    def test_creation3(self):
        assert_raises(ValueError, self.sc.tocell, [3, 6])
        assert_raises(ValueError, self.sc.tocell, [3, 4, 5, 6])
        assert_raises(ValueError, self.sc.tocell, [3, 4, 5, 6, 7])
        assert_raises(ValueError, self.sc.tocell, [3, 4, 5, 6, 7, 6, 7])

    def test_rcell(self):
        # LAPACK inverse algorithm implicitly does
        # a transpose.
        rcell = sli.inv(self.sc.cell) * 2. * np.pi
        assert_true(np.allclose(rcell.T, self.sc.rcell))

    def test_translate1(self):
        sc = self.sc.translate([0, 0, 10])
        assert_true(np.allclose(sc.cell[2, :2], self.sc.cell[2, :2]))
        assert_true(np.allclose(sc.cell[2, 2], self.sc.cell[2, 2]+10))

    def test_center1(self):
        assert_true(np.allclose(self.sc.center(), np.sum(self.sc.cell, axis=0) / 2))
        for i in [0, 1, 2]:
            assert_true(np.allclose(self.sc.center(i), self.sc.cell[i, :] / 2))

    def test_pickle(self):
        import pickle as p
        s = p.dumps(self.sc)
        n = p.loads(s)
        assert_true(self.sc == n)
        assert_false(self.sc != n)
        s = SuperCell([1, 1, 1])
        assert_false(self.sc == s)

    def test_orthogonal(self):
        assert_false(self.sc.is_orthogonal())