示例#1
0
def test_conversion_to_fraction(len_a, len_b, len_c, alpha, beta, gamma, x, y,
                                z):
    box = struc.vectors_from_unitcell(len_a, len_b, len_c, np.deg2rad(alpha),
                                      np.deg2rad(beta), np.deg2rad(gamma))
    coord = np.array([x, y, z])

    fractions = struc.coord_to_fraction(coord, box)
    if struc.is_orthogonal(box):
        assert fractions.tolist() == pytest.approx(coord / np.diagonal(box))
    new_coord = struc.fraction_to_coord(fractions, box)
    assert np.allclose(coord, new_coord)

    coords = np.stack([coord, coord])
    boxes = np.stack([box, box])
    fractions = struc.coord_to_fraction(coords, boxes)
    new_coords = struc.fraction_to_coord(fractions, boxes)
    assert np.allclose(coords, new_coords)
示例#2
0
def test_move_into_box(len_a, len_b, len_c, alpha, beta, gamma, x, y, z):
    box = struc.vectors_from_unitcell(len_a, len_b, len_c, np.deg2rad(alpha),
                                      np.deg2rad(beta), np.deg2rad(gamma))
    coord = np.array([x, y, z])

    moved_coord = struc.move_inside_box(coord, box)
    fractions = struc.coord_to_fraction(moved_coord, box)
    assert ((fractions >= 0) & (fractions <= 1)).all()