Ejemplo n.º 1
0
def test_lattice_old_interface():
    with pytest.warns(FutureWarning):
        _ = Lattice(basis_vectors=[[1.0]], atoms_coord=[[0.0], [0.5]], extent=[4])

    def check_alternative(method, alternative):
        with pytest.warns(FutureWarning):
            result = method()
        np.testing.assert_almost_equal(alternative(), result)

    for g in graphs + symmetric_graphs:
        if not isinstance(g, Lattice):
            continue
        check_alternative(lambda: g.atom_label(0), lambda: g.basis_coords[0, -1])
        check_alternative(lambda: g.site_to_vector(0), lambda: g.basis_coords[0, :-1])
        check_alternative(lambda: g.site_to_coord(0), lambda: g.positions[0])

        *cell1, label1 = g.basis_coords[1]
        check_alternative(
            lambda: g.vector_to_site(cell1),
            lambda: g.id_from_basis_coords([*cell1, 0]),
        )
        check_alternative(
            lambda: g.vector_to_coord(cell1, label1),
            lambda: g.position_from_basis_coords([*cell1, label1]),
        )

        check_alternative(lambda: g.coordinates, lambda: g.positions)
        check_alternative(lambda: g.atoms_coord, lambda: g.site_offsets)
Ejemplo n.º 2
0
def test_duplicate_atoms():
    lattice = Lattice(
        basis_vectors=[[1.0, 0.0], [1.0 / 2.0, math.sqrt(3) / 2.0]],
        extent=[10, 10],
        pbc=[False, False],
        site_offsets=[[0, 0], [0, 0]],
    )
    np.testing.assert_almost_equal(lattice.site_offsets, np.array([[0, 0]]))
Ejemplo n.º 3
0
def test_lattice_site_lookup():
    g = Lattice([[1]], [2])
    pos = [[0.0], [1.0]]
    ids = g.id_from_position(pos)
    np.testing.assert_almost_equal(ids, [0, 1])

    with pytest.raises(_lattice.InvalidSiteError):
        g.id_from_position([[0.5]])
    with pytest.raises(_lattice.InvalidSiteError):
        g.id_from_position([0.5])

    with pytest.raises(_lattice.InvalidSiteError):
        pos = g.position_from_basis_coords([2])
    with pytest.raises(_lattice.InvalidSiteError):
        pos = g.position_from_basis_coords([[2]])
Ejemplo n.º 4
0
pytestmark = common.skipif_mpi

graphs = [
    # star and tree
    Graph.from_igraph(ig.Graph.Star(5)),
    Graph.from_igraph(ig.Graph.Tree(n=3, children=2)),
    # Grid graphs
    Hypercube(length=10, n_dim=1, pbc=True),
    Hypercube(length=4, n_dim=2, pbc=True),
    Hypercube(length=5, n_dim=1, pbc=False),
    Grid([2, 2], pbc=False),
    Grid([4, 2], pbc=[True, False]),
    # lattice graphs
    Lattice(
        basis_vectors=[[1.0, 0.0], [1.0 / 2.0, math.sqrt(3) / 2.0]],
        extent=[3, 3],
        pbc=[False, False],
        site_offsets=[[0, 0]],
    ),
    Lattice(
        basis_vectors=[[1.5, math.sqrt(3) / 2.0], [0, math.sqrt(3)]],
        extent=[3, 5],
        site_offsets=[[0, 0], [1, 1]],
    ),
    Lattice(
        basis_vectors=[
            [1.0, 0.0, 0.0],
            [1.0 / 2.0, math.sqrt(3) / 2.0, 0.0],
            [0.0, 0.0, 1.0],
        ],
        extent=[2, 3, 4],
        site_offsets=[[0, 0, 0]],