def wrmsd(X, Y, w):
"""
Calculate the weighted root mean squared deviation (wRMSD) using Kabsch'
formula.
@param X: (n, d) input vector
@type X: numpy array
@param Y: (n, d) input vector
@type Y: numpy array
@param w: input weights
@type w: numpy array
@return: rmsd value between the input vectors
@rtype: float
"""
from numpy import sum, dot, sqrt, clip, average
from numpy.linalg import svd
## normalize weights
w = w / w.sum()
X = X - dot(w, X)
Y = Y - dot(w, Y)
R_x = sum(X.T ** 2 * w)
R_y = sum(Y.T ** 2 * w)
L = svd(dot(Y.T * w, X))[1]
return sqrt(clip(R_x + R_y - 2 * sum(L), 0., 1e300))
评论列表
文章目录