예제 #1
0
파일: kpath.py 프로젝트: elcorto/pwtools
def kpath(vecs, N=10):
    """Simple k-path. Given a set of K vectors (special points in the BZ),
    generate a "fine path" of N*(K-1)+1 vectors along the path defined by the
    vectors in `vecs`. The K vectors are the "vertices" of the k-path and we
    construct the fine path by connecting the vertices by their distance
    vectors and placing N points on each connection edge.

    Parameters
    ----------
    vecs : array (K,M) 
        Array with K vectors of the Brillouin zone (so M = 3 usually :)
    N : int

    Returns
    -------
    new_vecs : array (N*(K-1)+1,M) 
        Array with a fine grid of vectors along the path 
        defined by `vecs`.
    
    Notes
    -----
    This is the simplest method one can think of. Points on the "fine path" are
    not equally distributed. The distance between 2 vertices (k-points) doesn't
    matter, you will always get N points between them. For a smooth dispersion
    plot, you need N=20 or more.
    """
    K = vecs.shape[0]
    new_vecs = np.empty(((K - 1) * N + 1, vecs.shape[1]), dtype=float)
    for i in range(1, K):
        new_vecs[(i - 1) * N : i * N, :] = num.vlinspace(vecs[i - 1, :], vecs[i, :], N, endpoint=False)

    new_vecs[-1, :] = vecs[-1, :]
    return new_vecs
예제 #2
0
def test_vlinspace():
    aa = np.array([0,0,0]) 
    bb = np.array([1,1,1])
    
    np.testing.assert_array_equal(vlinspace(aa,bb,1), aa[None,:])
    
    np.testing.assert_array_equal(vlinspace(aa,bb,2),
                                  np.array([aa,bb]))
    
    tgt = np.array([aa, [0.5,0.5,0.5], bb])
    np.testing.assert_array_equal(vlinspace(aa,bb,3), tgt)
    
    tgt = np.array([aa, [1/3.]*3, [2/3.]*3, bb])
    np.testing.assert_array_almost_equal(vlinspace(aa,bb,4), tgt)
    
    tgt = np.array([[ 0.  ,  0.  ,  0.  ],
                 [ 0.25,  0.25,  0.25],
                 [ 0.5 ,  0.5 ,  0.5 ],
                 [ 0.75,  0.75,  0.75]])
    np.testing.assert_array_equal(vlinspace(aa,bb,4,endpoint=False), 
                                  tgt)
    
    aa = np.array([-1,-1,-1]) 
    bb = np.array([1,1,1])
    tgt = np.array([[ -1.  ,  -1.  ,  -1.  ],
                    [ 0,  0,  0],
                    [ 1,  1,  1]])
    np.testing.assert_array_equal(vlinspace(aa,bb,3), 
                                  tgt)
예제 #3
0
파일: kpath.py 프로젝트: zari277/pwtools
def kpath(vecs, N=10):
    """Simple k-path. Given a set of K vectors (special points in the BZ),
    generate a "fine path" of N*(K-1)+1 vectors along the path defined by the
    vectors in `vecs`. The K vectors are the "vertices" of the k-path and we
    construct the fine path by connecting the vertices by their distance
    vectors and placing N points on each connection edge.

    Parameters
    ----------
    vecs : array (K,M) 
        Array with K vectors of the Brillouin zone (so M = 3 usually :)
    N : int

    Returns
    -------
    new_vecs : array (N*(K-1)+1,M) 
        Array with a fine grid of vectors along the path 
        defined by `vecs`.
    
    Notes
    -----
    This is the simplest method one can think of. Points on the "fine path" are
    not equally distributed. The distance between 2 vertices (k-points) doesn't
    matter, you will always get N points between them. For a smooth dispersion
    plot, you need N=20 or more.
    """
    K = vecs.shape[0]
    new_vecs = np.empty(((K - 1) * N + 1, vecs.shape[1]), dtype=float)
    for i in range(1, K):
        new_vecs[(i - 1) * N:i * N, :] = num.vlinspace(vecs[i - 1, :],
                                                       vecs[i, :],
                                                       N,
                                                       endpoint=False)

    new_vecs[-1, :] = vecs[-1, :]
    return new_vecs
예제 #4
0
def test_vlinspace():
    aa = np.array([0, 0, 0])
    bb = np.array([1, 1, 1])

    np.testing.assert_array_equal(vlinspace(aa, bb, 1), aa[None, :])

    np.testing.assert_array_equal(vlinspace(aa, bb, 2), np.array([aa, bb]))

    tgt = np.array([aa, [0.5, 0.5, 0.5], bb])
    np.testing.assert_array_equal(vlinspace(aa, bb, 3), tgt)

    tgt = np.array([aa, [1 / 3.] * 3, [2 / 3.] * 3, bb])
    np.testing.assert_array_almost_equal(vlinspace(aa, bb, 4), tgt)

    tgt = np.array([[0., 0., 0.], [0.25, 0.25, 0.25], [0.5, 0.5, 0.5],
                    [0.75, 0.75, 0.75]])
    np.testing.assert_array_equal(vlinspace(aa, bb, 4, endpoint=False), tgt)

    aa = np.array([-1, -1, -1])
    bb = np.array([1, 1, 1])
    tgt = np.array([[-1., -1., -1.], [0, 0, 0], [1, 1, 1]])
    np.testing.assert_array_equal(vlinspace(aa, bb, 3), tgt)