Пример #1
0
def test_make_grid():
    grid_centering = "prim"
    grid_consts = [1, 1, 1]
    grid_angles = [np.pi / 2] * 3
    grid_vecs = make_ptvecs(grid_centering, grid_consts, grid_angles)

    lat_centering = "prim"
    lat_consts = [2] * 3
    lat_angles = [np.pi / 2] * 3
    lat_vecs = make_ptvecs(lat_centering, lat_consts, lat_angles)

    offset = [0] * 3
    grid0 = [[0, 0, 0], [0, 0, 1], [0, 1, 0], [0, 1, 1], [1, 0, 0], [1, 0, 1],
             [1, 1, 0], [1, 1, 1]]
    grid1 = make_grid(lat_vecs, grid_vecs, offset)

    assert len(grid0) == len(grid1)

    for g0 in grid0:
        contained = False
        for g1 in grid1:
            if np.allclose(g0, g1):
                contained = True
        assert contained == True

    grid_centering = "body"
    grid_consts = [1.] * 3
    grid_angles = [np.pi / 2] * 3
    grid_vecs = make_ptvecs(grid_centering, grid_consts, grid_angles)

    lat_centering = "body"
    lat_consts = [2.] * 3
    lat_angles = [np.pi / 2] * 3
    lat_vecs = make_ptvecs(lat_centering, lat_consts, lat_angles)

    offset = [0] * 3

    a = 0.5
    grid0 = [[0, 0, 0], [-a, a, a], [a, -a, a], [0, 0, 2 * a], [a, a, -a],
             [0, 2 * a, 0], [2 * a, 0, 0], [a, a, a]]
    grid1 = make_grid(lat_vecs, grid_vecs, offset)

    assert len(grid0) == len(grid1)

    for g0 in grid0:
        contained = False
        for g1 in grid1:
            if np.allclose(g0, g1):
                contained = True
        assert contained == True
Пример #2
0
    def plot_grid(self, i, j):
        """Plot one of the grids in the convergence plot.
        """
        grid_vecs = make_ptvecs(self.grid_types[i], self.grid_constants[j])
        grid_pts = make_grid(self.rcell_vectors, gr_vecs, self.offset)

        PlotMesh(grid_pts, self.rcell_vectors, self.offset)
Пример #3
0
def test_make_grid():
    # 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, False)

    for g1 in grid_pts1:
        check = False
        for g2 in grid:
            if np.allclose(g1, g2) == True:
                check = True
        assert check == True

    lat_type_list = ["fcc", "bcc", "sc"]
    lat_centering_list = ["face", "body", "prim"]
    lat_const_list = [10, 10.1, 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], [11, 9, 8], [np.pi, np.pi, np.pi]]
    r_list = [1, 2.3, 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)
            lat_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:
                            contained = False
                            for g in grid:
                                if np.allclose(g, tg):
                                    contained = True
                            assert contained == True
Пример #4
0
def test_make_grid():
    """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", "body"]
    grid_constants = [1, 1.1, 12. / 11, .7]
    grid_consts_list = [[m] * 3 for m in grid_constants]
    grid_angles = [np.pi / 2] * 3
    cell_center_list = ["prim", "face", "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_grid(cell_vectors, grid_vectors, offset)
                        large_grid = make_large_grid(cell_vectors,
                                                     grid_vectors, offset)

                        # Verify all the points in the cell for the large grid
                        # are contained in grid.
                        for lg in large_grid[0]:
                            included = False
                            for g in grid:
                                if np.allclose(lg, g) == True:
                                    included = True
                            assert included == True
Пример #5
0
def test_rectangular():
    """This will test the rectangular methods of finding the total energy and the
    Fermi level.
    """

    degree_list = range(1,5)
    for degree in degree_list:
        # Verify the Fermi level of the free electron model.
        lat_angles =[np.pi/2]*3
        lat_consts = [1]*3
        lat_centering = "prim"
        lattice = Lattice(lat_centering, lat_consts, lat_angles)
        
        free = FreeElectronModel(lattice, degree)
        
        grid_consts = [40]*3
        grid_angles = [np.pi/2]*3
        grid_centering = "prim"
        grid_vecs = make_ptvecs(grid_centering, grid_consts, grid_angles)
        rgrid_vecs = make_rptvecs(grid_vecs)
        offset = -np.dot(np.linalg.inv(rgrid_vecs), 
                         np.dot(lattice.reciprocal_vectors, [.5]*3))
        grid = make_grid(free.lattice.reciprocal_vectors, rgrid_vecs, offset)
        weights = np.ones(len(grid))
        free.fermi_level, temp = rectangular_method(free, grid, weights)
        sphere_volume = 4./3*np.pi*free.fermi_level**(3./degree)
        occupied_volume = free.lattice.reciprocal_volume*free.nvalence_electrons/2
        fl_answer = (3*occupied_volume/(4*np.pi))**(degree/3.)

        print("degree ", degree)
        print("shere volume ", sphere_volume)
        print("occupied_volume ", occupied_volume)
        
        assert np.isclose(sphere_volume, occupied_volume, 1e-1, 1e-1)
        assert np.isclose(free.fermi_level, fl_answer, 1e-2,1e-2)

        weights = np.ones(len(grid))
        temp, total_energy = rectangular_method(free, grid, weights)
        rf = free.fermi_level**(1./degree)
        te_answer = 4*np.pi*(rf**(3 + degree)/(3. + degree))
        assert np.isclose(total_energy, te_answer, 1e-1, 1e-1)