示例#1
0
def test_with_scale(case_data):
    """
    Test :meth:`.Edge.with_scale`.

    Parameters
    ----------
    case_data : :class:`.CaseData`
        A test case. Holds the starting position, the scale to apply
        and the target position.

    Returns
    -------
    None : :class:`NoneType`

    """

    edge = stk.Edge(
        id=0,
        vertex1=stk.Vertex(0, [0, 0, 0]),
        vertex2=stk.Vertex(1, [10, 0, 0]),
        position=case_data.start,
    )
    # Save a clone to check immutability.
    clone = edge.clone()
    _test_with_scale(edge, case_data.scale, case_data.target)
    is_clone(edge, clone)
示例#2
0
def building_block_vertices(building_block1, building_block2):
    return {
        building_block1: (
            stk.Vertex(0, [0, 0, 0]),
            stk.Vertex(1, [10, 0, 0]),
        ),
        building_block2: (
            stk.Vertex(2, [20, 0, 0]),
            stk.Vertex(3, [30, 0, 0]),
        ),
    }
示例#3
0
def get_edges(vertex):
    vertex2 = stk.Vertex(1, vertex.get_position() + [-1, -1, 0])
    yield stk.Edge(id=0,
                   vertex1=vertex,
                   vertex2=vertex2,
                   position=vertex.get_position() + [-1, 0, 0])
    yield stk.Edge(id=1,
                   vertex1=vertex,
                   vertex2=vertex2,
                   position=vertex.get_position() + [0, -1, 0])
示例#4
0
def get_nonlinear_edges(num_edges, vertex):
    """
    Yield edges placed in a circle around `vertex`.

    Parameters
    ----------
    num_edges : :class:`int`
        The number of edges to yield.

    vertex : :class:`.Vertex`
        The vertex which needs edges.

    Yields
    ------
    :class:`.Edge`
        An edge connected to `vertex`.

    """

    for id_, point in enumerate(
            get_points(center=vertex.get_position(), num_points=num_edges)):
        yield stk.Edge(id_, vertex, stk.Vertex(id_ + 1, point))
示例#5
0
def get_linear_edges(vertex):
    vertex2 = stk.Vertex(1, vertex.get_position() + [-10, 0, 0])
    vertex3 = stk.Vertex(2, vertex.get_position() + [10, 0, 0])
    yield Edge(0, 0, vertex, vertex2)
    yield Edge(1, 1, vertex, vertex3)
示例#6
0
def get_edge(vertex):
    vertex2 = stk.Vertex(1, vertex.get_position() + [-1, 0, 0])
    yield stk.Edge(0, vertex, vertex2)
示例#7
0
def get_angled_edges(vertex: stk.Vertex) -> stk.Edge:
    vertex2 = stk.Vertex(1, vertex.get_position() + [0, 10, 0])
    vertex3 = stk.Vertex(2, vertex.get_position() + [10, 0, 0])
    yield stk.Edge(0, vertex, vertex2)
    yield stk.Edge(1, vertex, vertex3)
示例#8
0
def get_edges(vertex, angle):
    position1, position2 = get_points(vertex.get_position(), angle)
    vertex2 = stk.Vertex(1, position1)
    vertex3 = stk.Vertex(2, position2)
    yield stk.Edge(0, vertex, vertex2)
    yield stk.Edge(1, vertex, vertex3)
示例#9
0
        vertices,
        cell_shifts,
        lattice_constants,
        position,
    ):
        self.vertices = vertices
        self.cell_shifts = cell_shifts
        self.lattice_constants = lattice_constants
        self.position = position


@pytest.fixture(
    params=(
        ShiftParams(
            vertices=(
                stk.Vertex(1, [-1, 1, 2]),
                stk.Vertex(2, [1, -1, -2]),
            ),
            cell_shifts=(
                np.array([0, 0, 0]),
                np.array([0, 0, 0]),
            ),
            lattice_constants=(
                np.array([1, 0, 0]),
                np.array([0, 1, 0]),
                np.array([0, 0, 1]),
            ),
            position=np.array([0., 0., 0.]),
        ),
        ShiftParams(
            vertices=(
示例#10
0
        id=id,
        vertex1_id=vertex1.get_id(),
        vertex2_id=vertex2.get_id(),
        periodicity=periodicity,
        is_periodic=any(i != 0 for i in periodicity),
    )


@pytest.fixture
def edge(case_data):
    return case_data.edge


@pytest.fixture(
    params=(
        lambda: stk.Vertex(0, [1, 2, 3]),
        lambda: stk.Vertex(3, [4, 2, 1]),
    ),
)
def vertex(request) -> stk.Vertex:
    return request.param()


@pytest.fixture
def vertex1(vertex):
    return vertex.clone()


@pytest.fixture
def vertex2(vertex):
    return vertex.clone()
示例#11
0
import stk

from .utilities import is_clone


@pytest.mark.skip
def test_with_vertices(construction_state, vertices):
    clone = construction_state.clone()
    _test_with_vertices(construction_state, vertices)
    # Test immutability.
    is_clone(construction_state, clone)


def _test_with_vertices(construction_state, vertices):
    clone = construction_state.with_vertices(vertices)
    assert clone.get_num_vertices() == len(vertices)
    for vertex_id in range(len(vertices)):
        assert clone.get_vertex(vertex_id) is vertices[vertex_id]


@pytest.fixture(
    scope='session',
    params=((
        lambda: stk.Vertex(0, [0, 0, 0]),
        lambda: stk.Vertex(1, [10, 0, 0]),
        lambda: stk.Vertex(2, [20, 0, 0]),
    ), ),
)
def vertices(request) -> tuple[stk.Vertex, ...]:
    return request.param()
示例#12
0
        id=id,
        vertex1_id=vertex1.get_id(),
        vertex2_id=vertex2.get_id(),
        periodicity=periodicity,
        is_periodic=any(i != 0 for i in periodicity),
    )


@pytest.fixture
def edge(case_data):
    return case_data.edge


@pytest.fixture(
    params=(
        stk.Vertex(0, [1, 2, 3]),
        stk.Vertex(3, [4, 2, 1]),
    ), )
def vertex(request):
    return request.param


@pytest.fixture
def vertex1(vertex):
    return vertex.clone()


@pytest.fixture
def vertex2(vertex):
    return vertex.clone()
示例#13
0
def position(request):
    return np.array(request.param, dtype=np.float64)


@pytest.fixture(
    params=(
        vertices._LinearCageVertex,
        vertices._NonLinearCageVertex,
    ), )
def cls(request):
    return request.param


@pytest.fixture(
    params=(
        vertices._LinearCageVertex.init_at_center,
        vertices._NonLinearCageVertex.init_at_center,
        vertices._UnaligningVertex.init_at_center,
    ), )
def init_at_center(request):
    return request.param


@pytest.fixture(
    params=(
        (stk.Vertex(0, [1, 2, 3]), ),
        (stk.Vertex(0, [1, 2, 3]), stk.Vertex(1, [-1, 2, -32])),
    ), )
def vertices_(request):
    return request.param
示例#14
0
文件: cof2.py 项目: lukasturcani/stk
        id=id,
        position=(
            sum(v.get_position() for v in vertices_)/len(vertices_)
        ),
        cell=cell,
    )


@pytest.fixture(
    params=(
        stk.cof.LinearVertex.init_at_center,
        stk.cof.NonLinearVertex.init_at_center,
        stk.cof.UnaligningVertex.init_at_center,
    ),
)
def init_at_center(request):
    return request.param


@pytest.fixture(
    params=(
        lambda: (stk.Vertex(0, [1, 2, 3]), ),
        lambda: (
            stk.Vertex(0, [1, 2, 3]),
            stk.Vertex(1, [-1, 2, -32]),
        ),
    ),
)
def vertices_(request) -> tuple[stk.Vertex, ...]:
    return request.param()
示例#15
0
from .utilities import is_clone


@pytest.mark.skip
def test_with_vertices(construction_state, vertices):
    clone = construction_state.clone()
    _test_with_vertices(construction_state, vertices)
    # Test immutability.
    is_clone(construction_state, clone)


def _test_with_vertices(construction_state, vertices):
    clone = construction_state.with_vertices(vertices)
    assert clone.get_num_vertices() == len(vertices)
    for vertex_id in range(len(vertices)):
        assert clone.get_vertex(vertex_id) is vertices[vertex_id]


@pytest.fixture(
    params=(
        (
            stk.Vertex(0, [0, 0, 0]),
            stk.Vertex(1, [10, 0, 0]),
            stk.Vertex(2, [20, 0, 0]),
        ),
    ),
)
def vertices(request):
    return request.param