def test_hbond(self): """Calculates real-life coordinates""" vec1 = Vector([33.48, 142.73, -25.44]) vec2 = Vector([33.24, 142.49, -24.16]) vec3 = Vector([33.00, 141.24, -23.75]) vec4 = build_coord(vec1, vec2, vec3, 1.1, 120.0, 33.0) self.assertEqual(str(vec4), '<Vector 33.49, 140.39, -24.25>')
def minimize_atoms(self): """Performs crude random minimization of dihedral angles.""" epsilon = 0.02 i = 0 maxcyc = 50 step = 120 delta = 100 + epsilon MAX_J = 5 MAX_K = 5 tor1, tor2 = 0.0, 0.0 matrix1 = get_ref_matrix(self.c4v, self.c3v, self.o3v) while delta > epsilon and i < maxcyc: old = (self.p.coord, self.o5.coord, tor1, tor2) # generate and check candidate positions j = 0 while j < MAX_J: # construct P atom t1 = self.get_random_torsion(tor1, step) d = build_coord(self.c4v, self.c3v, self.o3v, O3_P_DIST, A1, t1, matrix1) self.p.coord = array((d[0], d[1], d[2])) self.pv = self.p.get_vector() matrix2 = get_ref_matrix(self.c3v, self.o3v, self.pv) k = 0 while k < MAX_K: # construct O5 atom t2 = self.get_random_torsion(tor2, step) d = build_coord(self.c3v, self.o3v, self.pv, P_O5_DIST, A2, t2, matrix2) self.o5.coord = array((d[0], d[1], d[2])) self.o5v = self.o5.get_vector() # evaluate the candidate atoms score = self.get_score(delta) if score < delta: delta = score tor1, tor2 = t1, t2 j = MAX_J k = MAX_K k += 1 j += 1 if j == MAX_J: # old position is better self.p.coord, self.o5.coord, tor1, tor2 = old step = step * 0.5 i += 1
def _test_coord_samples(self, coord, examples): """ Runs the coord building on a set of dist, angle, torsion values. """ for dis, ang, tor in examples: vec1, vec2, vec3 = coord vec4 = build_coord(vec1, vec2, vec3, dis, ang, tor) result = self._measure(vec1, vec2, vec3, vec4) self.assertDistance(result, dis) self.assertAngle(result, ang) self.assertTorsion(result, tor)
def create_resi_from_torsions(self, torsions): """Creates residue with backbone atoms in different positions.""" resi2_copy = RNAResidue(self.resi2, \ alphabet_entry=self.resi2.alphabet_entry) epsilon, zeta, alpha, beta, gamma, delta = torsions c4c3 = self.resi2["C4'"] - self.resi2["C3'"] c3c2 = self.resi2["C3'"] - self.resi2["C2'"] at_p = build_coord(self.resi1["C4'"].get_vector(), \ self.resi1["C3'"].get_vector(), \ self.resi1["O3'"].get_vector(), O3_P_DIST, 109.0,epsilon) at_o5 = build_coord(self.resi1["C3'"].get_vector(), \ self.resi1["O3'"].get_vector(), \ at_p, P_O5_DIST, 109.0, zeta) at_c5 = build_coord(self.resi1["O3'"].get_vector(), \ at_p, at_o5, O5_C5_DIST, 109.0, alpha) at_c4 = build_coord(at_p, at_o5, at_c5, C5_C4_DIST, 109.0, beta) at_c3 = build_coord(at_o5, at_c5, at_c4, c4c3, 109.0, gamma) at_c2 = build_coord(at_c5, at_c4, at_c3, c3c2, 109.0, delta) resi2_copy['P'].coord = array((at_p[0], at_p[1], at_p[2])) resi2_copy["O5'"].coord = array((at_o5[0], at_o5[1], at_o5[2])) resi2_copy["C5'"].coord = array((at_c5[0], at_c5[1], at_c5[2])) resi2_copy["C4'"].coord = array((at_c4[0], at_c4[1], at_c4[2])) resi2_copy["C3'"].coord = array((at_c3[0], at_c3[1], at_c3[2])) resi2_copy["C2'"].coord = array((at_c2[0], at_c2[1], at_c2[2])) return resi2_copy
def __get_phosphate_atoms(self, beta): """ Creates atoms (P, OP1, OP2, OP3) based on values from given resi and given B angle. Returns list of 4 created atoms. """ p_coord = build_coord(self.c4v, self.c5v, self.o5v, P_O5_DIST, A3, beta) at_P = self.create_atom("P", "P", p_coord.get_array()) pv = at_P.get_vector() op1_coord = build_coord(self.c5v, self.o5v, pv, P_OP_DIST, P_OP_ANGLE, OP1_TORSION) op2_coord = build_coord(self.c5v, self.o5v, pv, P_OP_DIST, P_OP_ANGLE, OP2_TORSION) op3_coord = build_coord(self.c5v, self.o5v, pv, P_OP_DIST, P_OP_ANGLE, OP3_TORSION) at_OP1 = self.create_atom("OP1", "O", op1_coord.get_array()) at_OP2 = self.create_atom("OP2", "O", op2_coord.get_array()) at_OP3 = self.create_atom("OP3", "O", op3_coord.get_array()) # might be usful here? # from Bio.PDB import calc_angle, calc_dihedral # angle = calc_angle(at1.get_vector(), at2.get_vector(), at3.get_vector()) # dihedral = calc_dihedral(at1.get_vector(), at2.get_vector(), at3.get_vector(), at4.get_vector()) return [at_P, at_OP1, at_OP2, at_OP3]
def get_donor_hydrogens(self, donor): """ Returns a list of coord records of hypothetical hydrogen positions. If the donor has two neighbors, this will be a single position, if it has only one, a rotation will be performed in 10 degree steps. Atoms with 3 or more neighbors will be rejected. """ # TODO: refactor this out. if donor.name in self._donor_hydrogens: return self._donor_hydrogens[donor.name] hydrogens = [] neighbors = self.get_neighbors(donor) don_vec = donor.get_vector() sup_vec1 = None # coordinates next to donor sup_vec2 = None # coordinates to calc torsion if len(neighbors) == 1: sup_vec1 = neighbors[0].get_vector() neighbors2 = self.get_neighbors(neighbors[0]) sup_vec2 = None while neighbors2 and sup_vec2 is None: next = neighbors2.pop() if next != donor: sup_vec2 = next.get_vector() # bad case: no neighbors to construct 2nd support vec if sup_vec2 is None: sup_vec2 = (don_vec**sup_vec1) angle = H_ANGLE_ONE torsions = H_GENERATE_TORSIONS elif len(neighbors) == 2: sup_vec1 = neighbors[0].get_vector() sup_vec2 = neighbors[1].get_vector() angle = H_ANGLE_TWO torsions = [180.0] if sup_vec1 is not None and sup_vec2 is not None: # create hydrogen positions for torsion in torsions: h_pos = build_coord(sup_vec2, sup_vec1, don_vec, H_COVALENT_BOND, angle, torsion) h_pos = array([h_pos[0], h_pos[1], h_pos[2]]) hydrogens.append(h_pos) self._donor_hydrogens[donor.name] = hydrogens # self.write_hydrogens(hydrogens) return hydrogens
def test_build_coord(self): """Checks whether the P+O5' atoms are constructed.""" vec1, vec2, vec3 = self.sample_coord vec4 = build_coord(vec1, vec2, vec3, 1.0, 90.0, 0) self.assertTrue(isinstance(vec4, Vector))
def test_dihedral(self): """Checks whether the torsion angle is OK.""" vec1, vec2, vec3 = self.sample_coord vec4 = build_coord(vec1, vec2, vec3, 1.0, 90.0, 90.0) result = self._measure(vec1, vec2, vec3, vec4) self.assertTorsion(result, 90.0)
def test_angle(self): """Checks whether the angle is OK.""" vec1, vec2, vec3 = self.sample_coord vec4 = build_coord(vec1, vec2, vec3, 1.0, 90.0, 0.0) result = self._measure(vec1, vec2, vec3, vec4) self.assertAngle(result, 90.0)
def test_distance(self): """Checks whether the distance is OK.""" vec1, vec2, vec3 = self.sample_coord vec4 = build_coord(vec1, vec2, vec3, 2.34, 90.0, 0.0) result = self._measure(vec1, vec2, vec3, vec4) self.assertDistance(result, 2.34)