コード例 #1
0
 def act(self, element, a, b=None):
     shifted = lambda site, delta: site.family(*ta.add(site.tag, delta))
     delta = (self.period * element[0], ) + (len(a.tag) - 1) * (0, )
     if b is None:
         return shifted(a, delta)
     else:
         return shifted(a, delta), shifted(b, delta)
コード例 #2
0
ファイル: test_builder.py プロジェクト: jbweston/kwant
 def act(self, element, a, b=None):
     shifted = lambda site, delta: site.family(*ta.add(site.tag, delta))
     delta = (self.period * element[0],) + (len(a.tag) - 1) * (0,)
     if b is None:
         return shifted(a, delta)
     else:
         return shifted(a, delta), shifted(b, delta)
コード例 #3
0
def test_translational_symmetry():
    ts = lattice.TranslationalSymmetry
    f2 = lattice.general(np.identity(2), norbs=1)
    f3 = lattice.general(np.identity(3), norbs=1)
    shifted = lambda site, delta: site.family(*ta.add(site.tag, delta))

    raises(ValueError, ts, (0, 0, 4), (0, 5, 0), (0, 0, 2))
    sym = ts((3.3, 0))
    raises(ValueError, sym.add_site_family, f2)

    # Test lattices with dimension smaller than dimension of space.
    f2in3 = lattice.general([[4, 4, 0], [4, -4, 0]], norbs=1)
    sym = ts((8, 0, 0))
    sym.add_site_family(f2in3)
    sym = ts((8, 0, 1))
    raises(ValueError, sym.add_site_family, f2in3)

    # Test automatic fill-in of transverse vectors.
    sym = ts((1, 2))
    sym.add_site_family(f2)
    assert sym.site_family_data[f2][2] != 0
    sym = ts((1, 0, 2), (3, 0, 2))
    sym.add_site_family(f3)
    assert sym.site_family_data[f3][2] != 0

    transl_vecs = np.array([[10, 0], [7, 7]], dtype=int)
    sym = ts(*transl_vecs)
    assert sym.num_directions == 2
    sym2 = ts(*transl_vecs[:1, :])
    sym2.add_site_family(f2, transl_vecs[1:, :])
    for site in [f2(0, 0), f2(4, 0), f2(2, 1), f2(5, 5), f2(15, 6)]:
        assert sym.in_fd(site)
        assert sym2.in_fd(site)
        assert sym.which(site) == (0, 0)
        assert sym2.which(site) == (0, )
        for v in [(1, 0), (0, 1), (-1, 0), (0, -1), (5, 10), (-111, 573)]:
            site2 = shifted(site, np.dot(v, transl_vecs))
            assert not sym.in_fd(site2)
            assert (v[0] != 0) != sym2.in_fd(site2)
            assert sym.to_fd(site2) == site
            assert (v[1] == 0) == (sym2.to_fd(site2) == site)
            assert sym.which(site2) == v
            assert sym2.which(site2) == v[:1]

            for hop in [(0, 0), (100, 0), (0, 5), (-2134, 3213)]:
                assert (sym.to_fd(site2,
                                  shifted(site2,
                                          hop)) == (site, shifted(site, hop)))

    # Test act for hoppings belonging to different lattices.
    f2p = lattice.general(2 * np.identity(2), norbs=1)
    sym = ts(*(2 * np.identity(2)))
    assert sym.act((1, 1), f2(0, 0), f2p(0, 0)) == (f2(2, 2), f2p(1, 1))
    assert sym.act((1, 1), f2p(0, 0), f2(0, 0)) == (f2p(1, 1), f2(2, 2))

    # Test add_site_family on random lattices and symmetries by ensuring that
    # it's possible to add site groups that are compatible with a randomly
    # generated symmetry with proper vectors.
    rng = ensure_rng(30)
    vec = rng.randn(3, 5)
    lat = lattice.general(vec, norbs=1)
    total = 0
    for k in range(1, 4):
        for i in range(10):
            sym_vec = rng.randint(-10, 10, size=(k, 3))
            if np.linalg.matrix_rank(sym_vec) < k:
                continue
            total += 1
            sym_vec = np.dot(sym_vec, vec)
            sym = ts(*sym_vec)
            sym.add_site_family(lat)
    assert total > 20
コード例 #4
0
ファイル: test_lattice.py プロジェクト: gitter-badger/kwant
def test_translational_symmetry():
    ts = lattice.TranslationalSymmetry
    f2 = lattice.general(np.identity(2))
    f3 = lattice.general(np.identity(3))
    shifted = lambda site, delta: site.family(*ta.add(site.tag, delta))

    assert_raises(ValueError, ts, (0, 0, 4), (0, 5, 0), (0, 0, 2))
    sym = ts((3.3, 0))
    assert_raises(ValueError, sym.add_site_family, f2)

    # Test lattices with dimension smaller than dimension of space.
    f2in3 = lattice.general([[4, 4, 0], [4, -4, 0]])
    sym = ts((8, 0, 0))
    sym.add_site_family(f2in3)
    sym = ts((8, 0, 1))
    assert_raises(ValueError, sym.add_site_family, f2in3)

    # Test automatic fill-in of transverse vectors.
    sym = ts((1, 2))
    sym.add_site_family(f2)
    assert_not_equal(sym.site_family_data[f2][2], 0)
    sym = ts((1, 0, 2), (3, 0, 2))
    sym.add_site_family(f3)
    assert_not_equal(sym.site_family_data[f3][2], 0)

    transl_vecs = np.array([[10, 0], [7, 7]], dtype=int)
    sym = ts(*transl_vecs)
    assert_equal(sym.num_directions, 2)
    sym2 = ts(*transl_vecs[:1, :])
    sym2.add_site_family(f2, transl_vecs[1:, :])
    for site in [f2(0, 0), f2(4, 0), f2(2, 1), f2(5, 5), f2(15, 6)]:
        assert sym.in_fd(site)
        assert sym2.in_fd(site)
        assert_equal(sym.which(site), (0, 0))
        assert_equal(sym2.which(site), (0,))
        for v in [(1, 0), (0, 1), (-1, 0), (0, -1), (5, 10), (-111, 573)]:
            site2 = shifted(site, np.dot(v, transl_vecs))
            assert not sym.in_fd(site2)
            assert (v[0] != 0) != sym2.in_fd(site2)
            assert_equal(sym.to_fd(site2), site)
            assert (v[1] == 0) == (sym2.to_fd(site2) == site)
            assert_equal(sym.which(site2), v)
            assert_equal(sym2.which(site2), v[:1])

            for hop in [(0, 0), (100, 0), (0, 5), (-2134, 3213)]:
                assert_equal(sym.to_fd(site2, shifted(site2, hop)), (site, shifted(site, hop)))

    # Test act for hoppings belonging to different lattices.
    f2p = lattice.general(2 * np.identity(2))
    sym = ts(*(2 * np.identity(2)))
    assert sym.act((1, 1), f2(0, 0), f2p(0, 0)) == (f2(2, 2), f2p(1, 1))
    assert sym.act((1, 1), f2p(0, 0), f2(0, 0)) == (f2p(1, 1), f2(2, 2))

    # Test add_site_family on random lattices and symmetries by ensuring that
    # it's possible to add site groups that are compatible with a randomly
    # generated symmetry with proper vectors.
    np.random.seed(30)
    vec = np.random.randn(3, 5)
    lat = lattice.general(vec)
    total = 0
    for k in range(1, 4):
        for i in range(10):
            sym_vec = np.random.randint(-10, 10, size=(k, 3))
            if np.linalg.matrix_rank(sym_vec) < k:
                continue
            total += 1
            sym_vec = np.dot(sym_vec, vec)
            sym = ts(*sym_vec)
            sym.add_site_family(lat)
    assert total > 20