def R6a(coords, atmidx, dismat): '''resolve a fragment of protein: N1-C2-C3(=O)-N4-C5-C6(=O)-N7-C8-C9(=O) known the coords of p1, p2, p8, p9, and all the bond length and bond length and bond angles, to calculate the coords from p3 to p7 ''' r6sub = R6sub(coords, atmidx, dismat) i1, i2, i3, i4, i5, i6, i7, i8, i9 = atmidx steps = config.config.get('Mezei_R6_steps', 36) stepsize = 2 * math.pi / steps results = [r6sub(i*stepsize) for i in range(steps)] results[0] = tuple(results[0]) results.append(results[0]) d46ref = dismat[i4, i6] d46mat = [[getd46rela(ps[1], ps[3], d46ref) for ps in result] for result in results] results = [] for i in range(steps): for j in range(16): if d46mat[i][j] is not None \ and d46mat[i+1][j] is not None \ and d46mat[i][j] * d46mat[i+1][j] <= 0: try: angle = rtbis.rtbis(d46_Resolver(r6sub, j, d46ref), i * stepsize, (i+1) * stepsize, math.radians(1.0)) result = tuple(r6sub(angle))[j] yield {i3: result[0], i4: result[1], i5: result[2], i6: result[3], i7: result[4]} except rtbis.Error: pass
def __call__(self): result = [[] for i in range(16)] stepsize = math.pi * 2 / self.steps ref = self._dismatrix(5, 7) for i in range(self.steps): p2 = self.p2o \ + self.p2x * math.cos(stepsize * i) \ + self.p2y * math.sin(stepsize * i) tmps = list(self.get_p34567(p2)) assert len(tmps) == 16 for idx, tmp in enumerate(tmps): if tmp[0] is None: result[idx].append(None) else: result[idx].append(tools.length(tmp[2] - tmp[4]) - ref) for i in range(16): result[i].append(result[i][0]) for i in range(16): def _Func(x): try: return tuple(self.get_r57_from_theta(x))[i] - ref except TypeError: return None func = _Func for j in range(self.steps): if result[i][j] is None: continue if result[i][j+1] is None: continue if result[i][j] * result[i][j+1] > 0: continue try: tmp = rtbis.rtbis(func, j*stepsize, (j+1)*stepsize, self.acc) p2 = self._theta_to_p2(tmp) tmp2 = self.get_p34567(p2) for _k in range(i+1): tmp3 = tmp2.next() yield tuple([p2,] + list(tmp3)) except rtbis.Error: pass
def r6_base(self, points, len1, len2, error=0.1): """r6_base(points, len1, len2) -> iterator len(points) == 4 len(len1) == 4 len(len2) == 5 return all results fulfill following conditions in a iterator, len(result) will be 3. distance(points[1], result[0]) = len1[0]; distance(result[0], result[1]) = len1[1]; distance(result[1], result[2]) = len1[2]; distance(result[2], points[2]) = len1[3]; distance(points[0], result[0]) = len2[0]; distance(points[1], result[1]) = len2[1]; distance(result[0], result[2]) = len2[2]; distance(result[1], points[2]) = len2[3]; distance(result[2], points[3]) = len2[4]; """ assert(len(points) == 4 and len(len1) == 4 and len(len2) == 5) p0, p1, p5, p6 = tuple(points) d12, d23, d34, d45 = tuple(len1) d02, d13, d24, d35, d46 = tuple(len2) p3_result = self._calc_p3((p0, p1, p5), d13, d35) if p3_result is None: return p3o, p3x, p3y = p3_result steps = config.get('Mezei_R6_steps', 36) step = 2 * pi / steps d24s = numpy.zeros((4, steps+1), float) for i in range(steps): angle = i * step p24_result = self._calc_p2_p4(points, len1, len2, p3_result, angle) if p24_result: p2s, p4s = p24_result d24s[0][i] = tools.length(p2s[0] - p4s[0]) d24s[1][i] = tools.length(p2s[0] - p4s[1]) d24s[2][i] = tools.length(p2s[1] - p4s[0]) d24s[3][i] = tools.length(p2s[1] - p4s[1]) d24s[0][steps] = d24s[0][0] d24s[1][steps] = d24s[1][0] d24s[2][steps] = d24s[2][0] d24s[3][steps] = d24s[3][0] p24_res = self.p24_Resolver(points, len1, len2, p3_result) for i in range(4): p24_res.switch(i) for j in range(steps): if d24s[i][j] and d24s[i][j+1] and \ (d24s[i][j] - d24)*(d24s[i][j+1] - d24) <= 0: try: angle = rtbis.rtbis(p24_res, j*step, (j+1)*step, error) yield (i, angle, p24_res.p2, p24_res.p3, p24_res.p4) except rtbis.Error: pass