get_dih
函数计算任意四个连续原子之间的二面角(dihedral angle),它描述了主链和侧链原子的三维空间排布。
源代码:
def get_dih(a, b, c, d):"""calculate dihedral angles for all consecutive quadruples (a[i],b[i],c[i],d[i])given Cartesian coordinates of four sets of atoms a,b,c,dParameters----------a,b,c,d : pytorch tensors or numpy array of shape [batch,nres,3]store Cartesian coordinates of four sets of atomsReturns-------dih : pytorch tensor or numpy array of shape [batch,nres]stores resulting dihedrals"""convert_to_torch = lambda *arrays: [torch.from_numpy(arr) for arr in arrays]output_np=Falseif isinstance(a, np.ndarray):output_np=Truea,b,c,d = convert_to_torch(a,b,c,d)b0 = a - bb1 = c - bb2 = d - cb1 /= torch.norm(b1, dim=-1, keepdim=True)