def value(self, xyz):
xyz = xyz.reshape(-1,3)
a = self.a
b = self.b
c = self.c
# vector from first atom to central atom
vector1 = xyz[a] - xyz[b]
# vector from last atom to central atom
vector2 = xyz[c] - xyz[b]
# norm of the two vectors
norm1 = np.sqrt(np.sum(vector1**2))
norm2 = np.sqrt(np.sum(vector2**2))
dot = np.dot(vector1, vector2)
# Catch the edge case that very rarely this number is -1.
if dot / (norm1 * norm2) <= -1.0:
if (np.abs(dot / (norm1 * norm2)) + 1.0) < -1e-6:
raise RuntimeError('Encountered invalid value in angle')
return np.pi
if dot / (norm1 * norm2) >= 1.0:
if (np.abs(dot / (norm1 * norm2)) - 1.0) > 1e-6:
raise RuntimeError('Encountered invalid value in angle')
return 0.0
return np.arccos(dot / (norm1 * norm2))
评论列表
文章目录