def average_structure(X):
"""
Calculate an average structure from an ensemble of structures
(i.e. X is a rank-3 tensor: X[i] is a (N,3) configuration matrix).
@param X: m x n x 3 input vector
@type X: numpy array
@return: average structure
@rtype: (n,3) numpy.array
"""
from numpy.linalg import eigh
B = csb.numeric.gower_matrix(X)
v, U = eigh(B)
if numpy.iscomplex(v).any():
v = v.real
if numpy.iscomplex(U).any():
U = U.real
indices = numpy.argsort(v)[-3:]
v = numpy.take(v, indices, 0)
U = numpy.take(U, indices, 1)
x = U * numpy.sqrt(v)
i = 0
while is_mirror_image(x, X[0]) and i < 2:
x[:, i] *= -1
i += 1
return x
评论列表
文章目录