def test_shape(): def in_circle(pos): return pos[0]**2 + pos[1]**2 < 3 lat = lattice.honeycomb(norbs=1) sites = list(lat.shape(in_circle, (0, 0))()) sites_alt = list() sl0, sl1 = lat.sublattices for x in range(-2, 3): for y in range(-2, 3): tag = (x, y) for site in (sl0(*tag), sl1(*tag)): if in_circle(site.pos): sites_alt.append(site) assert len(sites) == len(sites_alt) assert set(sites) == set(sites_alt) raises(ValueError, lat.shape(in_circle, (10, 10))().__next__) # Check if narrow ribbons work. for period in (0, 1), (1, 0), (1, -1): vec = lat.vec(period) sym = lattice.TranslationalSymmetry(vec) def shape(pos): return abs(pos[0] * vec[1] - pos[1] * vec[0]) < 10 sites = list(lat.shape(shape, (0, 0))(sym)) assert len(sites) > 35
def test_shape(): def in_circle(pos): return pos[0] ** 2 + pos[1] ** 2 < 3 lat = lattice.honeycomb() sites = list(lat.shape(in_circle, (0, 0))()) sites_alt = list() sl0, sl1 = lat.sublattices for x in xrange(-2, 3): for y in xrange(-2, 3): tag = (x, y) for site in (sl0(*tag), sl1(*tag)): if in_circle(site.pos): sites_alt.append(site) assert len(sites) == len(sites_alt) assert_equal(set(sites), set(sites_alt)) assert_raises(ValueError, lat.shape(in_circle, (10, 10))().next) # Check if narrow ribbons work. for period in (0, 1), (1, 0), (1, -1): vec = lat.vec(period) sym = lattice.TranslationalSymmetry(vec) def shape(pos): return abs(pos[0] * vec[1] - pos[1] * vec[0]) < 10 sites = list(lat.shape(shape, (0, 0))(sym)) assert len(sites) > 35
def test_neighbors(): lat = lattice.honeycomb(1e-10, norbs=1) num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] assert num_nth_nearest == [2, 3, 6, 3, 6] lat = lattice.general([(0, 1e8, 0, 0), (0, 0, 1e8, 0)], norbs=1) num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] assert num_nth_nearest == [1, 2, 2, 2, 4] lat = lattice.chain(1e-10, norbs=1) num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] assert num_nth_nearest == 5 * [1]
def test_neighbors(): lat = lattice.honeycomb(1e-10) num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] assert num_nth_nearest == [2, 3, 6, 3, 6] lat = lattice.square(1e8) num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] assert num_nth_nearest == [1, 2, 2, 2, 4] lat = lattice.chain(1e-10) num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)] assert num_nth_nearest == 5 * [1]
def test_error_minus_9(r=10): """Test if MUMPSError -9 is properly caught by increasing memory""" graphene = honeycomb(norbs=1) a, b = graphene.sublattices def circle(pos): x, y = pos return x**2 + y**2 < r**2 syst = Builder() syst[graphene.shape(circle, (0, 0))] = -0.0001 for kind in [((0, 0), b, a), ((0, 1), b, a), ((-1, 1), b, a)]: syst[HoppingKind(*kind)] = -1 ham = syst.finalized().hamiltonian_submatrix(sparse=True) # No need to check result, it's enough if no exception is raised MUMPSContext().factor(ham)
def test_error_minus_9(r=10): """Test if MUMPSError -9 is properly caught by increasing memory""" graphene = honeycomb() a, b = graphene.sublattices def circle(pos): x, y = pos return x**2 + y**2 < r**2 sys = Builder() sys[graphene.shape(circle, (0,0))] = -0.0001 for kind in [((0, 0), b, a), ((0, 1), b, a), ((-1, 1), b, a)]: sys[HoppingKind(*kind)] = - 1 ham = sys.finalized().hamiltonian_submatrix(sparse=True) # No need to check result, it's enough if no exception is raised MUMPSContext().factor(ham)