def test_number_nn(): s = site.SpinHalfSite('Sz') chain = lattice.Chain(2, s) assert chain.number_nearest_neighbors() == 2 assert chain.number_next_nearest_neighbors() == 2 ladd = lattice.Ladder(2, s) assert ladd.number_nearest_neighbors(0) == 3 assert ladd.number_nearest_neighbors(1) == 3 assert ladd.number_next_nearest_neighbors(0) == 2 assert ladd.number_next_nearest_neighbors(1) == 2 square = lattice.Square(2, 2, s) assert square.number_nearest_neighbors() == 4 assert square.number_next_nearest_neighbors() == 4 triang = lattice.Triangular(2, 2, s) assert triang.number_nearest_neighbors() == 6 assert triang.number_next_nearest_neighbors() == 6 hc = lattice.Honeycomb(2, 2, s) assert hc.number_nearest_neighbors(0) == 3 assert hc.number_nearest_neighbors(1) == 3 assert hc.number_next_nearest_neighbors(0) == 6 assert hc.number_next_nearest_neighbors(1) == 6 kag = lattice.Kagome(2, 2, s) assert kag.number_nearest_neighbors(0) == 4 assert kag.number_nearest_neighbors(1) == 4 assert kag.number_nearest_neighbors(2) == 4 assert kag.number_next_nearest_neighbors(0) == 4 assert kag.number_next_nearest_neighbors(1) == 4 assert kag.number_next_nearest_neighbors(2) == 4
def test_pairs(): lattices = [ lattice.Chain(2, None), lattice.Ladder(2, None), lattice.Square(2, 2, None), lattice.Triangular(2, 2, None), lattice.Honeycomb(2, 2, None), lattice.Kagome(2, 2, None) ] for lat in lattices: print(lat.__class__.__name__) found_dist_pairs = lat.find_coupling_pairs(5, 3.) dists = sorted(found_dist_pairs.keys()) for i, name in enumerate([ 'nearest_neighbors', 'next_nearest_neighbors', 'next_next_nearest_neighbors', 'fourth_nearest_neighbors', 'fifth_nearest_neighbors' ]): if name not in lat.pairs: assert i > 2 # all of them should define up to next_next_nearest_neighbors continue print(name) defined_pairs = lat.pairs[name] found_pairs = found_dist_pairs[dists[i]] assert len(defined_pairs) == len(found_pairs) defined_pairs = pairs_with_reversed(defined_pairs) found_pairs = pairs_with_reversed(found_pairs) assert defined_pairs == found_pairs
def test_lattice_order(): s = site.SpinHalfSite('Sz') # yapf: disable chain = lattice.Chain(4, s) order_default = np.array([[0, 0], [1, 0], [2, 0], [3, 0]]) npt.assert_equal(chain.order, order_default) chain = lattice.Chain(4, s, order='folded') order_folded = np.array([[0, 0], [3, 0], [1, 0], [2, 0]]) npt.assert_equal(chain.order, order_folded) chain = lattice.Chain(5, s, order='folded') order_folded = np.array([[0, 0], [4, 0], [1, 0], [3, 0], [2, 0]]) ladder = lattice.Ladder(3, s, order='folded') order_folded = np.array([[0, 0], [0, 1], [2, 0], [2, 1], [1, 0], [1, 1]]) npt.assert_equal(ladder.order, order_folded) square = lattice.Square(2, 2, s, order='default') order_default = np.array([[0, 0, 0], [0, 1, 0], [1, 0, 0], [1, 1, 0]]) npt.assert_equal(square.order, order_default) square = lattice.Square(4, 3, s, order='snake') order_snake = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [1, 1, 0], [1, 0, 0], [2, 0, 0], [2, 1, 0], [2, 2, 0], [3, 2, 0], [3, 1, 0], [3, 0, 0]]) npt.assert_equal(square.order, order_snake) square = lattice.Square(2, 3, s, order=("standard", (True, False), (1, 0))) order_Fsnake = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0]]) npt.assert_equal(square.order, order_Fsnake) hc = lattice.Honeycomb(2, 3, s, order='default') order_hc_def = np.array([[0, 0, 0], [0, 1, 0], [0, 2, 0], [0, 0, 1], [0, 1, 1], [0, 2, 1], [1, 0, 0], [1, 1, 0], [1, 2, 0], [1, 0, 1], [1, 1, 1], [1, 2, 1]]) npt.assert_equal(hc.order, order_hc_def) hc = lattice.Honeycomb(2, 3, s, order=('standard', (True, False, False), (0.3, 0.1, -1.))) order_hc_mix = np.array([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 2, 0], [1, 2, 0], [0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 2, 1], [1, 2, 1]]) npt.assert_equal(hc.order, order_hc_mix) kag = lattice.Kagome(2, 3, s, order=('grouped', [[1], [0, 2]])) order_kag_gr = np.array([[0, 0, 1], [0, 1, 1], [0, 2, 1], [0, 0, 0], [0, 0, 2], [0, 1, 0], [0, 1, 2], [0, 2, 0], [0, 2, 2], [1, 0, 1], [1, 1, 1], [1, 2, 1], [1, 0, 0], [1, 0, 2], [1, 1, 0], [1, 1, 2], [1, 2, 0], [1, 2, 2]]) npt.assert_equal(kag.order, order_kag_gr) kag = lattice.Kagome(2, 4, s, order=('grouped', [[0], [2, 1]], [1, 0, 2])) order_kag_gr = np.array([[0, 0, 0], [1, 0, 0], [0, 0, 2], [0, 0, 1], [1, 0, 2], [1, 0, 1], [0, 1, 0], [1, 1, 0], [0, 1, 2], [0, 1, 1], [1, 1, 2], [1, 1, 1], [0, 2, 0], [1, 2, 0], [0, 2, 2], [0, 2, 1], [1, 2, 2], [1, 2, 1], [0, 3, 0], [1, 3, 0], [0, 3, 2], [0, 3, 1], [1, 3, 2], [1, 3, 1]]) npt.assert_equal(kag.order, order_kag_gr)
def test_number_nn(): s = site.SpinHalfSite('Sz') chain = lattice.Chain(2, s) assert chain.count_neighbors() == 2 assert chain.count_neighbors(key='next_nearest_neighbors') == 2 ladd = lattice.Ladder(2, s) for u in [0, 1]: assert ladd.count_neighbors(u) == 3 assert ladd.count_neighbors(u, key='next_nearest_neighbors') == 2 square = lattice.Square(2, 2, s) assert square.count_neighbors() == 4 assert square.count_neighbors(key='next_nearest_neighbors') == 4 triang = lattice.Triangular(2, 2, s) assert triang.count_neighbors() == 6 assert triang.count_neighbors(key='next_nearest_neighbors') == 6 hc = lattice.Honeycomb(2, 2, s) for u in [0, 1]: assert hc.count_neighbors(u) == 3 assert hc.count_neighbors(u, key='next_nearest_neighbors') == 6 kag = lattice.Kagome(2, 2, s) for u in [0, 1, 2]: assert kag.count_neighbors(u) == 4 assert kag.count_neighbors(u, key='next_nearest_neighbors') == 4