示例#1
0
def test_refine_square():

    lattice_basis = make2D_lattice_basis([1,1], np.pi/2)
    ndivs = 6

    grid_basis = make2D_lattice_basis([1/ndivs,1/ndivs], np.pi/2)
    offset = np.dot(inv(grid_basis), np.dot(lattice_basis, [-.5]*2))

    grid = make_cell_points2D(lattice_basis, grid_basis, offset,
        grid_type="closed")

    args = {"lattice_basis": lattice_basis,
            "degree": 2,
            "prefactor":1,
            "nvalence_electrons": 3}

    free_2D = FreeElectron2D(**args)

    weights = np.ones(len(grid))
    fermi_level, band_energy = rectangular_integration2D(free_2D,
                                                         grid,
                                                         weights)
    free_2D.fermi_level = fermi_level
    free_2D.band_energy = band_energy

    tess = square_tesselation(grid)

    all_squares, areas = refine_square(tess[2], free_2D, method="interpolate",
                                       ndivisions=2, derivative_tol=1e1)

    nsquares = int(np.prod(np.shape(all_squares))/2)
    all_pts = np.reshape(all_squares, (nsquares, 2))

    unique_pts = make_unique(all_pts)

    all_squares2 = [[[1/3,0],[5/12, 0],[5/12, 1/12],[1/3, 1/12]],
                    [[5/12, 0],[1/2, 0],[1/2, 1/12],[5/12, 1/12]],
                    [[5/12, 1/12],[1/2, 1/12],[1/2, 1/6],[5/12, 1/6]],
                    [[1/3, 1/12],[5/12, 1/12],[5/12, 1/6],[1/3, 1/6]]]

    unique_pts2 = [[1/3, 0],[5/12, 0],[1/2, 0],[1/3, 1/12],[5/12, 1/12],
                   [1/2, 1/12],[1/3, 1/6],[5/12, 1/6],[1/2, 1/6]]


    assert (check_contained(unique_pts2, unique_pts) and
            check_contained(unique_pts, unique_pts2))

    assert (check_contained(all_squares, all_squares2) and
            check_contained(all_squares2, all_squares))
示例#2
0
def test_make_grid2():
    # This unit test doesn't pass because the primitive translation vectors
    # changed when I updated the code (I think).

    grid_pts1 = [[0, 0, 0], [1, 1, 1], [0, 0, 2], [0, 2, 0], [0, 2, 2],
                 [2, 0, 0], [0, 2, 2], [2, 0, 2], [2, 2, 0], [2, 2, 2],
                 [1, 3, 3], [3, 1, 3], [3, 1, 1], [1, 1, 3], [1, 3, 1],
                 [3, 1, 1]]
    grid_pts1 = np.asarray(grid_pts1) * 1. / 4

    cell_centering = "prim"
    cell_const = 1.
    cell_const_list = [cell_const] * 3
    cell_angles = [np.pi / 2] * 3
    cell_vecs = make_ptvecs(cell_centering, cell_const_list, cell_angles)

    grid_centering = "body"
    grid_const = cell_const / 2
    grid_const_list = [grid_const] * 3
    grid_angles = [np.pi / 2] * 3
    grid_vecs = make_ptvecs(grid_centering, grid_const_list, grid_angles)
    offset = np.asarray([0., 0., 0.])
    grid = make_grid(cell_vecs, grid_vecs, offset, coords="lat")

    for g1 in grid_pts1:
        assert check_contained(g1, grid)

    lat_type_list = ["fcc"]
    lat_centering_list = ["face"]
    lat_const_list = [3 * np.pi]
    lat_consts_list = [[l] * 3 for l in lat_const_list]
    lat_angles = [np.pi / 2] * 3
    offset_list = [[1.3, 1.1, 1.7]]
    r_list = [np.pi]

    for lat_centering in lat_centering_list:
        for lat_consts in lat_consts_list:
            lat_vecs = make_ptvecs(lat_centering, lat_consts, lat_angles)
            rlat_vecs = make_rptvecs(lat_vecs)
            for offset in offset_list:
                offset = np.asarray(offset)
                for r in r_list:
                    total_grid = large_sphere_pts(lat_vecs, r, offset)
                    grid = sphere_pts(lat_vecs, r, offset)
                    contained = False
                    for tg in total_grid:
                        if np.dot(tg - offset, tg - offset) <= r:
                            assert check_contained(tg, grid)
示例#3
0
def test_square_tesselation():

    ndivs = 2
    grid_basis = make2D_lattice_basis([1/ndivs,1/ndivs], np.pi/2)

    lattice_basis = make2D_lattice_basis([1,1], np.pi/2)

    offset = [0,0]
    grid = make_cell_points2D(lattice_basis, grid_basis, offset,
                              grid_type="closed")

    square_tess = square_tesselation(grid)

    subsquares_list = [[[0, 0], [.5, 0], [.5, .5], [0, .5]],
                       [[0, .5], [.5, .5], [.5, 1], [0, 1]],
                       [[.5, 0], [1, 0], [1, .5], [.5, .5]],
                       [[.5, .5], [1, .5], [1, 1], [.5, 1]]]

    assert (check_contained(square_tess, subsquares_list) and
            check_contained(subsquares_list, square_tess))
示例#4
0
def test_get_circle_pts():

    lattice_constants = [1]*2
    lattice_angle = np.pi/2
    lattice_basis = make2D_lattice_basis(lattice_constants, lattice_angle)

    radius = 2

    pts = [ [0, 0], [1, 0], [0, 1], [1, 1], [-1, 0], [0, -1], [-1, -1], [-1, 1],
            [1, -1]]
    circle_pts = get_circle_pts(lattice_basis, radius)

    assert check_contained(pts, circle_pts)
    assert len(pts) == len(circle_pts)
示例#5
0
def get_unique_planes(BZ, rtol=1e-5, atol=1e-8):
    """Find the unique planes that form the boundaries of a Brillouin zone.

    Args:
        BZ (scipy.spatial.ConvexHull): a convex hull object

    Returns:
        unique_plane (numpy.ndarray): an array of unique planes in general form.
    """

    unique_planes = []
    for plane in BZ.equations:
        if not check_contained([plane], unique_planes, rtol=rtol, atol=atol):
            unique_planes.append(plane)

    return np.array(unique_planes)
示例#6
0
def test_make_cell_points():
    """Verify the grid satisfies various properties, such as verifying
    the neighbors of each point are withing the grid as long as the 
    neighbors lie within the unit cell. Also verify none of the points
    lie outside the unit cell.
    """

    # At the moment it only tests the cubic lattices.
    grid_center_list = ["prim", "face"]
    grid_constants = np.array([1. / 2, 1. / 4]) * 2 * np.sqrt(2)
    grid_consts_list = [[m] * 3 for m in grid_constants]
    grid_angles = [np.pi / 2] * 3
    cell_center_list = ["prim", "body"]
    cell_constants = [2 * np.sqrt(2)]
    cell_consts_list = [[c] * 3 for c in cell_constants]
    cell_angles = [np.pi / 2] * 3
    offsets = [[0., 0., 0.], [1. / 2, 1. / 2, 1. / 2]]

    # for grid_constant in grid_constants:
    for grid_consts in grid_consts_list:
        for grid_center in grid_center_list:
            grid_vectors = make_ptvecs(grid_center, grid_consts, grid_angles)
            grid_lengths = [np.linalg.norm(lv) for lv in grid_vectors]
            for cell_consts in cell_consts_list:
                for cell_center in cell_center_list:
                    cell_vectors = make_ptvecs(cell_center, cell_consts,
                                               cell_angles)
                    cell_lengths = [np.linalg.norm(cv) for cv in cell_vectors]
                    for offset in offsets:
                        grid = make_cell_points(cell_vectors, grid_vectors,
                                                offset)
                        grid2, null_grid = make_large_grid(
                            cell_vectors, grid_vectors, offset)

                        # Verify all the points in the cell for the large grid
                        # are contained in grid.
                        assert check_contained(grid, grid2)