예제 #1
0
def test_build_min_neighbors():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    shape = Circle([0, 0], radius=5)
    latt.build(shape, min_neighbors=2)
    assert_array_equal(latt.data.get_limits(), [[-4.0, -4.0], [4.0, 4.0]])
예제 #2
0
def test_hash():
    latt = Lattice(np.eye(2))
    latt.add_atom(atom=atom)
    latt.add_connections()
    latt.build((5, 5))
    hash1 = latt.__hash__()
    latt.build((6, 5))
    assert latt.__hash__() != hash1
예제 #3
0
def test_superindex_from_index():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    latt.build((4, 4), primitive=False)
    for i in range(latt.num_sites):
        ind = latt.indices[i]
        assert latt.superindex_from_index(ind) == i
예제 #4
0
def test_superindex_from_position():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    latt.build((4, 4), primitive=False)
    for i in range(latt.num_sites):
        pos = latt.position(i)
        assert latt.superindex_from_pos(pos) == i
예제 #5
0
def test_append():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    latt.build((4, 4), primitive=False)
    latt2 = latt.copy()
    latt.append(latt2)

    assert_elements_equal1d(latt.nearest_neighbors(20), [15, 21, 25])
    assert_elements_equal1d(latt.nearest_neighbors(21), [16, 20, 22, 26])
    assert_elements_equal1d(latt.nearest_neighbors(22), [17, 21, 23, 27])
    assert_elements_equal1d(latt.nearest_neighbors(23), [18, 22, 24, 28])
    assert_elements_equal1d(latt.nearest_neighbors(24), [19, 23, 29])
예제 #6
0
def test_build_exceptions():
    latt = Lattice(np.eye(2))
    latt.add_atom()

    with pytest.raises(NoConnectionsError):
        latt.build((5, 5))

    latt.add_connections(analyze=False)
    with pytest.raises(NotAnalyzedError):
        latt.build((5, 5))

    latt.analyze()
    with pytest.raises(ValueError):
        latt.build((5, 5, 5))
예제 #7
0
def test_to_dict():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    latt.build((5, 5))
    d = latt.todict()

    expected = [[1.0, 0.0], [0.0, 1.0]]
    assert_array_equal(d["vectors"], expected)

    expected = [[0.0, 0.0]]
    assert_array_equal(d["positions"], expected)

    expected = [[1]]
    assert_array_equal(d["connections"], expected)

    expected = [5.0, 5.0]
    assert_array_equal(d["shape"], expected)
예제 #8
0
def test_compute_connections():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    latt.build((4, 4), primitive=False)

    latt2 = Lattice(np.eye(2))
    latt2.add_atom()
    latt2.add_connections()
    latt2.build((4, 4), pos=(5, 0), primitive=False)

    pairs, dists = latt.compute_connections(latt2)
    expected = [[20, 0], [21, 1], [22, 2], [23, 3], [24, 4]]
    assert_array_equal(pairs, expected)
    assert np.all(dists) == 1

    latt2.build((4, 4), pos=(5, 1), primitive=False)

    pairs, dists = latt.compute_connections(latt2)
    expected = [[21, 0], [22, 1], [23, 2], [24, 3]]
    assert_array_equal(pairs, expected)
    assert np.all(dists) == 1
예제 #9
0
def test_volume():
    latt = Lattice(np.eye(2))
    latt.add_atom()
    latt.add_connections()
    latt.build((4, 4), primitive=False)
    assert latt.volume() == 25