def iface_rms(self, pose0, prov, **kw): if self.origin_seg is None: # print('WARNING: iface_rms not implemented for simple cyclic') return -1 else: same_as_last = list() for i, pr in enumerate(prov[:-1]): if pr[2] is prov[-1][2]: same_as_last.append(i) if len(same_as_last) < 2: print( 'iface_rms ERROR, not 3 merge subs! same_as_last:', same_as_last ) # for i, (lb, ub, src, slb, sub) in enumerate(prov): # print(i, lb, ub, id(src), len(src), slb, sub) return 9e9 i1, i2 = same_as_last[-2:] i3 = -1 a1 = util.subpose(pose0, prov[i1][0], prov[i1][1]) a2 = util.subpose(pose0, prov[i2][0], prov[i2][1]) a3 = util.subpose(pose0, prov[i3][0], prov[i3][1]) b1 = util.subpose(prov[i1][2], prov[i1][3], prov[i1][4]) b2 = util.subpose(prov[i2][2], prov[i2][3], prov[i2][4]) b3 = util.subpose(prov[i3][2], prov[i3][3], prov[i3][4]) forward = hrot([0, 0, 1], 360.0 / self.nfold) backward = hrot([0, 0, 1], -720.0 / self.nfold) util.xform_pose(forward, a1) # a1.dump_pdb('a3_forward.pdb') fdist = a1.residue(1).xyz(2).distance(a3.residue(1).xyz(2)) util.xform_pose(backward, a1) # a1.dump_pdb('a3_backward.pdb') bdist = a1.residue(1).xyz(2).distance(a3.residue(1).xyz(2)) if bdist > fdist: util.xform_pose(forward, a1) util.xform_pose(forward, a1) # pose0.dump_pdb('pose0.pdb') # a1.dump_pdb('a1.pdb') # a2.dump_pdb('a2.pdb') # a3.dump_pdb('a3.pdb') # prov[-1][2].dump_pdb('src.pdb') # b1.dump_pdb('b1.pdb') # b2.dump_pdb('b2.pdb') # b3.dump_pdb('b3.pdb') ros.core.pose.append_pose_to_pose(a1, a2, True) ros.core.pose.append_pose_to_pose(a1, a3, True) ros.core.pose.append_pose_to_pose(b1, b2, True) ros.core.pose.append_pose_to_pose(b1, b3, True) # a1.dump_pdb('a.pdb') # b1.dump_pdb('b.pdb') rms = ros.core.scoring.CA_rmsd(a1, b1) # assert 0, 'debug iface rms ' + str(rms) return rms
def P432_D4_C3(d4=0, c3=-1): return DihedralCyclicLattice3D( "P432_D4_C3_2", d_nfold=4, c_nfold=3, c_tgt_axis_isect=[ [[+1, +1, 0], [+1, +1, +1]], [[+1, +1, 0], [+1, +1, -1]], [[+1, -1, 0], [+1, -1, +1]], [[+1, -1, 0], [+1, -1, -1]], [[-1, +1, 0], [-1, +1, +1]], [[-1, +1, 0], [-1, +1, -1]], [[-1, -1, 0], [-1, -1, +1]], [[-1, -1, 0], [-1, -1, -1]], # trips up align_vectors ], aligners=[ np.eye(4), hm.hrot([1, 1, 0], 180), hm.hrot([0, 0, 1], 90), hm.hrot([1, 1, 0], 180) @ hm.hrot([0, 0, 1], 90), hm.hrot([0, 0, 1], -90), hm.hrot([1, 1, 0], 180) @ hm.hrot([0, 0, 1], -90), hm.hrot([0, 0, 1], 180), hm.hrot([1, 1, 0], 180) @ hm.hrot([0, 0, 1], 180), ], from_seg=d4, to_seg=c3, to_origin=[0.5, 0.5, 0], space_group_str="P 4 3 2", )
def _get_hash_lossfunc_data(nfold): rots = np.stack(( hg.hrot([0, 0, 1, 0], np.pi * 2. / nfold), hg.hrot([0, 0, 1, 0], -np.pi * 2. / nfold), )).astype(np.float32) assert rots.shape == (2, 4, 4) irots = (0, 1) if nfold > 2 else (0, ) return rots, irots
def _get_has_lossfunc_data(nfold): rots = np.stack(( hrot([0, 0, 1, 0], np.pi * 2. / nfold), hrot([0, 0, 1, 0], -np.pi * 2. / nfold), )) assert rots.shape == (2, 4, 4) irots = (0, 1) if nfold > 2 else (0, ) return rots, irots
def residue_sym_err(p, ang, ir, jr, n=1, axis=[0, 0, 1], verbose=0): mxdist = 0 for i in range(n): xyz0 = residue_coords(p, ir + i) xyz1 = residue_coords(p, jr + i) xyz3 = hrot(axis, ang) @ xyz1.T xyz4 = hrot(axis, -ang) @ xyz1.T if verbose: print(i, xyz0) print(i, xyz1) print(i, xyz3.T) print(i, xyz4.T) print() mxdist = max( mxdist, min(np.max(np.sum((xyz0 - xyz3.T)**2, axis=1)), np.max(np.sum((xyz0 - xyz4.T)**2, axis=1)))) return np.sqrt(mxdist)
def test_geom_check(): SX = Cyclic I = np.identity(4) rotx1rad = hrot([1, 0, 0], 1) transx10 = htrans([10, 0, 0]) randaxes = np.random.randn(1, 3) assert 0 == SX('c1').score([I, I]) assert 0.001 > abs(50 - SX('c1').score([I, rotx1rad])) assert 1e-5 > abs(SX('c2').score([I, hrot([1, 0, 0], np.pi)])) score = Cyclic('c2').score([I, hrot(randaxes, np.pi)]) assert np.allclose(0, score, atol=1e-5, rtol=1) score = Cyclic('c3').score([I, hrot(randaxes, np.pi * 2 / 3)]) assert np.allclose(0, score, atol=1e-5, rtol=1) score = Cyclic('c4').score([I, hrot(randaxes, np.pi / 2)]) assert np.allclose(0, score, atol=1e-5, rtol=1)
def alignment(self, segpos, out_cell_spacing=False, **kw): ax = segpos[self.to_seg, :3, 2] cn = segpos[self.to_seg, :3, 3] origin = np.array([0, 0, 0]) if self.d_nfold > 2 and self.c_nfold > 2: mn, mni = 9e9, None for i, _ in enumerate(self.c_tgt_axis_isect): c_axis_isects, c_tgt_axis = _ d = hm.numba_line_line_distance_pa(cn, ax, origin, c_axis_isects) a = np.arccos(abs(np.sum(c_tgt_axis * ax))) err = np.sqrt(d**2 + (a * self.lever)**2) if err < mn: mn = err mni = i c_axis_isects, c_tgt_axis = self.c_tgt_axis_isect[mni] p, q = hm.line_line_closest_points_pa(cn, ax, origin, c_axis_isects) cell_spacing = np.linalg.norm(p + q) / np.sqrt(2) # 2x from p+q xalign = np.eye(4) if np.sum(c_axis_isects * q) > 0: xalign = hm.hrot(hm.hcross(c_axis_isects, c_tgt_axis), 180) @ xalign xalign = self.aligners[mni] @ xalign xalign[:3, 3] = self.to_origin * cell_spacing d = np.linalg.norm(p - q) a = np.arccos(abs(np.sum(c_tgt_axis * ax))) carterr2 = d**2 angerr2 = (a * self.lever)**2 if np.sum(c_axis_isects * q) > 0: print() print("alignment", d, a * self.lever, self.lever) print("ax", ax, xalign[:3, :3] @ ax) print("cn", cn, xalign @ [cn[0], cn[1], cn[2], 1]) print("isect", p) print("isect", q) print("cell_spacing", cell_spacing) print("xalign", hm.axis_angle_of(xalign)) print(xalign) else: raise NotImplementedError if out_cell_spacing: return xalign, cell_spacing else: return xalign
def __init__(self, xindex, binner, nfold, from_seg=-1): """TODO: Summary Args: xindex (TYPE): Description binner (TYPE): Description nfold (TYPE): Description from_seg (TYPE, optional): Description """ self.xindex_set = set(xindex.keys()) self.binner = binner self.from_seg = from_seg self.cyclic_xform = hrot([0, 0, 1], 360 / nfold)
def __init__(self, segments, tail, splitpoint, head, xindex, binner, nfold, from_seg, to_seg, max_tmp_size=1024, max_results=100000): self.segments = segments self.tail = tail self.splitpoint = splitpoint self.head = head self.xindex = xindex self.binner = binner self.from_seg = from_seg self.to_seg = to_seg self.cyclic_xform = hrot([0, 0, 1], 360 / nfold) self.max_tmp_size = max_tmp_size self.max_results = max_results self.temporary = []
def alignment(self, segpos, **kwargs): if self.origin_seg is not None: return inv(segpos[self.origin_seg]) x_from = segpos[self.from_seg] x_to = segpos[self.to_seg] xhat = x_to @ inv(x_from) axis, ang, cen = hm.axis_ang_cen_of(xhat) # print('aln', axis) # print('aln', ang * 180 / np.pi) # print('aln', cen) # print('aln', xhat[..., :, 3]) dotz = hm.hdot(axis, Uz)[..., None] tgtaxis = np.where(dotz > 0, [0, 0, 1, 0], [0, 0, -1, 0]) align = hm.hrot((axis + tgtaxis) / 2, np.pi, cen) align[..., :3, 3] -= cen[..., :3] return align
def test_pose_alignment_0(c1pose): helix = Spliceable(c1pose, sites=[(1, 'N'), ('-4:', 'C')]) segments = ([ Segment([helix], exit='C'), ] + [Segment([helix], 'N', 'C')] * 3 + [Segment([helix], entry='N')]) w = grow(segments, Cyclic('c2'), thresh=1) assert len(w) print(w.indices) for i in range(4): assert tuple(w.indices[i]) in ((0, 2, 1, 2, 0), (2, 1, 2, 0, 0), (1, 2, 0, 2, 0), (2, 0, 2, 1, 0)) pose = w.pose(0, align=1, end=1) assert util.no_overlapping_residues(pose) # vis.showme(pose) xyz0 = np.array([pose.residue(1).xyz(2)[i] for i in (0, 1, 2)] + [1]) # resid 43 happens to be the symmetrically related one for this solution xyz1 = np.array([pose.residue(42).xyz(2)[i] for i in (0, 1, 2)] + [1]) xyz1 = hrot([0, 0, 1], 180) @ xyz1 assert np.sum((xyz1 - xyz0)**2) < 0.1
def __init__( self, segments, tail, splitpoint, head, xindex, binner, nfold, from_seg, to_seg, max_tmp_size=1024, max_results=100000, ): """TODO: Summary Args: segments (TYPE): Description tail (TYPE): Description splitpoint (TYPE): Description head (TYPE): Description xindex (TYPE): Description binner (TYPE): Description nfold (TYPE): Description from_seg (TYPE): Description to_seg (TYPE): Description max_tmp_size (int, optional): Description max_results (int, optional): Description """ self.segments = segments self.tail = tail self.splitpoint = splitpoint self.head = head self.xindex = xindex self.binner = binner self.from_seg = from_seg self.to_seg = to_seg self.cyclic_xform = hrot([0, 0, 1], 360 / nfold) self.max_tmp_size = max_tmp_size self.max_results = max_results self.temporary = []
def D9_22(c2=0, c2b=-1, **kw): return AxesIntersect("D9", (2, Ux), (2, hm.hrot(Uz, 180 / 9)[0]), c2, to_seg=c2b, nondistinct_axes=True, **kw)
def D8_22(c2=0, c2b=-1, **kw): return AxesIntersect("D8", (2, Ux), (2, hm.hrot(Uz, 180 / 8)[0]), c2, to_seg=c2b, **kw)
def __init__(self, xindex, binner, nfold, from_seg=-1): self.xindex_set = set(xindex.keys()) self.binner = binner self.from_seg = from_seg self.cyclic_xform = hrot([0, 0, 1], 360 / nfold)