|
import numpy as np |
|
import scipy |
|
import scipy.spatial |
|
from rfdiffusion.kinematics import get_dih |
|
|
|
|
|
def get_angles(a, b, c): |
|
|
|
v = a - b |
|
v /= np.linalg.norm(v, axis=-1)[:,None] |
|
|
|
w = c - b |
|
w /= np.linalg.norm(w, axis=-1)[:,None] |
|
|
|
x = np.sum(v*w, axis=1) |
|
|
|
|
|
return np.arccos(np.clip(x, -1.0, 1.0)) |
|
|
|
|
|
def get_coords6d(xyz, dmax): |
|
|
|
nres = xyz.shape[1] |
|
|
|
|
|
N = xyz[0] |
|
Ca = xyz[1] |
|
C = xyz[2] |
|
|
|
|
|
b = Ca - N |
|
c = C - Ca |
|
a = np.cross(b, c) |
|
Cb = -0.58273431*a + 0.56802827*b - 0.54067466*c + Ca |
|
|
|
|
|
|
|
kdCb = scipy.spatial.cKDTree(Cb) |
|
indices = kdCb.query_ball_tree(kdCb, dmax) |
|
|
|
|
|
idx = np.array([[i,j] for i in range(len(indices)) for j in indices[i] if i != j]).T |
|
idx0 = idx[0] |
|
idx1 = idx[1] |
|
|
|
|
|
dist6d = np.full((nres, nres),999.9, dtype=np.float32) |
|
dist6d[idx0,idx1] = np.linalg.norm(Cb[idx1]-Cb[idx0], axis=-1) |
|
|
|
|
|
omega6d = np.zeros((nres, nres), dtype=np.float32) |
|
omega6d[idx0,idx1] = get_dih(Ca[idx0], Cb[idx0], Cb[idx1], Ca[idx1]) |
|
|
|
theta6d = np.zeros((nres, nres), dtype=np.float32) |
|
theta6d[idx0,idx1] = get_dih(N[idx0], Ca[idx0], Cb[idx0], Cb[idx1]) |
|
|
|
|
|
phi6d = np.zeros((nres, nres), dtype=np.float32) |
|
phi6d[idx0,idx1] = get_angles(Ca[idx0], Cb[idx0], Cb[idx1]) |
|
|
|
mask = np.zeros((nres, nres), dtype=np.float32) |
|
mask[idx0, idx1] = 1.0 |
|
return dist6d, omega6d, theta6d, phi6d, mask |
|
|