def get_r57_from_theta(self, theta): p2 = self._theta_to_p2(theta) for p3, p4, p5, p6, p7 in self.get_p34567(p2): if p3 is None: yield None else: yield tools.length(p5 - p7)
def testsidechain(self): import StringIO mol = read.readxyz(StringIO.StringIO(test_in)) coords1 = mol.coords coords2 = coords1.copy() coords2[1] = coords1[3] coords2[2] = coords1[4] coords2[3] = coords1[1] coords2[4] = coords1[2] newcoords = sidechain.movesidechain(coords1, coords2, (0, 1, 2), (3, 4)) for key in newcoords: coord = newcoords[key] assert isinstance(coord, numpy.ndarray) and coord.shape == (3,) and coord.dtype == float, (coord, coord.shape, coord.dtype) self.assertAlmostEqual(tools.length(newcoords[3] - coords2[3]), 0, 4) self.assertAlmostEqual(tools.length(newcoords[4] - coords2[4]), 0, 4)
def _test(): mol = ''' 17 molden generated tinker .xyz (mm3 param.) 1 N+ 0.000000 0.000000 0.000000 39 2 2 C 0.000000 0.000000 1.460000 1 1 3 3 C 1.403962 0.000000 2.015868 3 2 4 5 4 N 2.195124 -0.904100 1.422348 9 3 6 5 O 1.755111 0.752517 2.909631 7 3 6 C 3.591293 -1.058240 1.820536 1 4 7 7 C 4.358438 0.233498 1.668879 3 6 8 9 8 N 4.140177 0.829026 0.488494 9 7 10 9 O 5.091799 0.666773 2.542294 7 7 10 C 4.792149 2.091022 0.151005 1 8 11 11 C 4.466440 3.170859 1.154979 3 10 12 13 12 N 3.158394 3.235806 1.438521 9 11 14 13 O 5.320944 3.893369 1.640987 7 11 14 C 2.642777 4.216977 2.388806 1 12 15 15 C 3.289555 4.070161 3.745355 3 14 16 17 16 O 3.401864 2.975815 4.272794 47 15 17 O 3.724636 5.023075 4.370703 47 15 ''' import StringIO mol = StringIO.StringIO(mol) from itcc.molecule import read mol = read.readxyz(mol) from itcc.molecule import tools distmat = tools.distmat(mol) idxs = [2,3,4,6,7,8,10,11,12,14] idxs = [x - 1 for x in idxs] import sys for x in idxs[2:-2]: sys.stdout.write('%10.6f %10.6f %10.6f\n' % tuple(mol.coords[x])) mezeipro2 = Mezeipro2(mol.coords, distmat, idxs) results = list(mezeipro2()) print len(results) for result in results: _print_result(sys.stdout, result) if result[3] is not None: print tools.length(result[3]-result[5]), mezeipro2._dismatrix(5, 7)
def R6(self, 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 ''' self.dismat = dismat self.atmidx = atmidx r1 = coords[0] r2 = coords[1] r8 = coords[7] r9 = coords[8] i1, i2, i3, i4, i5, i6, i7, i8, i9 = tuple(atmidx) r27 = 0.0 while r27 <= 10.0: print r27, r7s = pyramid(r2, r8, r9, r27, self.r(7,8), self.r(7,9)) # print 'r7s =', r7s for r7 in r7s: r5s = pyramid(r2, r7, r8, self.r(2,5), self.r(5,7), self.r(5,8)) # print 'r5s =', r5s for r5 in r5s: r6s = pyramid(r5, r7, r8, self.r(6,5), self.r(6,7), self.r(6,8)) # print 'r6s =', r6s r3s = pyramid(r1, r2, r5, self.r(3,1), self.r(3,2), self.r(3,5)) # print 'r3s =', r3s for r3 in r3s: r4s = pyramid(r2, r3, r5, self.r(4,2), self.r(4,3), self.r(4,5)) for r4 in r4s: for r6 in r6s: if r4 is None or r6 is None: print 0.0, else: print tools.length(r4-r6), print r27 += 0.1
def rg(mol): center = molecule.CoordType() mass = 0.0 for i in range(len(mol)): thismass = mol.atoms[i].mass mass += thismass center += mol.coords[i] * thismass center /= mass result = 0.0 for i in range(len(mol)): result += tools.length(mol.coords[i] - center) ** 2 * mol.atoms[i].mass result /= mass return result
def __call__(self, angle): self.p3 = self.p3o + self.p3x * cos(angle) + self.p3y * sin(angle) p2s, z2s = pyramid(self.p0, self.p1, self.p3, self.d02, self.d12, self.d23) if z2s < self.threshold: return None p4s, z4s = pyramid(self.p6, self.p5, self.p3, self.d46, self.d45, self.d34) if z4s < self.threshold: return None if self.mode == -1: return (p2s, p4s) else: i2 = self.mode / 2 i4 = self.mode % 2 self.p2 = p2s[i2] self.p4 = p4s[i4] return tools.length(self.p2-self.p4) - self.d24
def _calc_p3(self, points, d13, d35): p0 = points[0] p1 = points[1] p5 = points[2] V15 = p5 - p1 d15 = tools.length(V15) if d13 + d35 < d15 or d13 + d15 < d35 or d15 + d35 < d13: return None c = (d13 * d13 - d35 * d35) / ( 2 * d15 * d15) + 0.5 r = sqrt(d13 * d13 - c * c * d15 * d15) p3o = p1 + c * V15 Oz = tools.normal(V15) p3y = tools.normal(numpy.cross(Oz, p0-p1)) * r p3x = numpy.cross(p3y, Oz) return (p3o, p3x, p3y)
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 pyramid2(A, B, rAX, rBX): '''pyramid2(A, B, rAX, rBX) -> (O, OXx, OXy) known the coords of A, B and rAX, rBX, then X will be on a circle. return the circle center and 2 vertical axis. ''' AB = B - A rAB = tools.length(AB) if rAX + rBX < rAB or abs(rAX - rBX) > rAB: return (None, None, None) c = (rAX * rAX - rBX * rBX) / ( 2 * rAB * rAB) + 0.5 rAO = c * rAB rXO = math.sqrt(rAX * rAX - rAO * rAO) O = A + c * AB ABn = _normal(AB) if abs(ABn[0]) < 0.7071: OXx = _normal(cross(ABn, numpy.array([1.0, 0.0, 0.0]))) * rXO else: OXx = _normal(cross(ABn, numpy.array([0.0, 1.0, 0.0]))) * rXO OXy = cross(OXx, ABn) return (O, OXx, OXy)
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
def __call__(self, angle): result = tuple(self.r6sub(angle))[self.mode] if result[1] is None: return None return tools.length(result[1] - result[3]) - self.d46ref
def getd46rela(p4, p6, d46ref): if p4 is None or p6 is None: return None return tools.length(p4 - p6) - d46ref
def shake3(r1, r2, new_dis): dr = r2 - r1 dr = (new_dis / tools.length(dr) - 1.0) / 2.0 * dr return r1 - dr, r2 + dr