cells.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:muesr 作者: bonfus 项目源码 文件源码
def get_shortest_bases_from_extented_bases(extended_bases, tolerance):

    def mycmp(x, y):
        return cmp(np.vdot(x,x), np.vdot(y,y))

    basis = np.zeros((7,3), dtype=float)
    basis[:4] = extended_bases
    basis[4]  = extended_bases[0] + extended_bases[1]
    basis[5]  = extended_bases[1] + extended_bases[2]
    basis[6]  = extended_bases[2] + extended_bases[0]
    # Sort bases by the lengthes (shorter is earlier)
    basis = sorted(basis, cmp=mycmp)

    # Choose shortest and linearly independent three bases
    # This algorithm may not be perfect.
    for i in range(7):
        for j in range(i+1, 7):
            for k in range(j+1, 7):
                if abs(np.linalg.det([basis[i],basis[j],basis[k]])) > tolerance:
                    return np.array([basis[i],basis[j],basis[k]])

    print ("Delaunary reduction is failed.")
    return basis[:3]

#
# Other tiny tools
#
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号