def test_junction_virtual_atom_distance_minimalMultiloop(self): distance1 = ftug.junction_virtual_atom_distance( self.minimal_multiloop, "m0") self.assertLess( distance1, 4., msg="{} is not < {} for {}".format(distance1, 4., "m0")) distance2 = ftug.junction_virtual_atom_distance( self.minimal_multiloop, "m1") self.assertLess( distance2, 4., msg="{} is not < {} for {}".format(distance2, 4., "m1"))
def test_junction_virtual_atom_distance_minimalMultiloop(self): distance1 = ftug.junction_virtual_atom_distance( self.minimal_multiloop, "m0") self.assertLess(distance1, 4., msg="{} is not < {} for {}".format( distance1, 4., "m0")) distance2 = ftug.junction_virtual_atom_distance( self.minimal_multiloop, "m1") self.assertLess(distance2, 4., msg="{} is not < {} for {}".format( distance2, 4., "m1"))
def test_junction_virtual_atom_distance_realPDB(self): distance = ftug.junction_virtual_atom_distance(self.rs_random_281, "m3") self.assertLess(distance, 4.) #This should always hold! self.assertAlmostEqual( distance, 3.4294889373610675 ) #This value might change, if we change the virtual atom calculation
def bulge_virtual_atom_distance(bg, ld): ''' Calculate the distance between the O3' atom and the P atom of the two strands that need to be closed. @param bg: The BulgeGraph data structure @param ld: The name of the bulge region @return: The distance between the O3' and P' virtual atoms of the flanking residues ''' if len(bg.edges[ld]) == 2: dist2 = cgg.junction_virtual_atom_distance(bg, ld) else: dist2 = 0. return dist2
def describe_ml_segments(cg): data = defaultdict(list) loops = cg.find_mlonly_multiloops() for loop in it.chain(loops, [[i] for i in cg.iloop_iterator()]): print(loop) if loop[0][0] == "i": description = ["interior_loop"] else: description = cg.describe_multiloop(loop) try: j3_roles = cg._assign_loop_roles(loop) except ValueError: j3_roles = None if j3_roles: j3_familyFlat = cg._junction_family_westhof1(j3_roles) j3_family3D = cg._junction_family_3d(j3_roles) j3_familyPerp = cg._junction_family_is_perpenticular(j3_roles) j3_Delta = cg.get_length(j3_roles["J23"]) - cg.get_length( j3_roles["J31"]) else: j3_family3D = None j3_familyFlat = None j3_familyPerp = None j3_Delta = None loop_start = float("inf") for segment in loop: if cg.define_a(segment)[0] < loop_start: loop_start = cg.define_a(segment)[0] for segment in loop: if segment[0] not in "mi": continue data["loop_start_after"].append(loop_start) data["segment_start_after"].append(cg.define_a(segment)[0]) data["segment"].append(segment) data["junction_length"].append(len(loop)) data["segment_length"].append(cg.get_length(segment)) if segment[0] == "i": dims = list(sorted(cg.get_bulge_dimensions(segment))) else: dims = [-1, -1] data["iloop_length_1"].append(dims[0]) data["iloop_length_2"].append(dims[1]) data["loops_largest_segment_length"].append( max(cg.get_length(x) for x in loop)) data["loops_shortest_segment_length"].append( min(cg.get_length(x) for x in loop)) data["sum_of_loops_segment_lengths"].append( sum(cg.get_length(x) for x in loop)) data["loop_segment_lengths"].append(",".join( map(str, sorted(cg.get_length(x) for x in loop)))) data["angle_type"].append( abs(cg.get_angle_type(segment, allow_broken=True))) s1, s2 = cg.connections(segment) vec1 = cg.coords.get_direction(s1) if cg.get_sides(s1, segment) == (1, 0): vec1 = -vec1 else: assert cg.get_sides(s1, segment) == (0, 1) vec2 = cg.coords.get_direction(s2) if cg.get_sides(s2, segment) == (1, 0): vec2 = -vec2 else: assert cg.get_sides(s2, segment) == (0, 1) data["angle_between_stems"].append(ftuv.vec_angle(vec1, vec2)) data["offset1"].append( ftuv.point_line_distance( cg.coords[s1][cg.get_sides(s1, segment)[0]], cg.coords[s2][0], cg.coords.get_direction(s2))) data["offset2"].append( ftuv.point_line_distance( cg.coords[s2][cg.get_sides(s2, segment)[0]], cg.coords[s1][0], cg.coords.get_direction(s1))) closer1, far1 = cg.coords[s1][cg.get_sides( s1, segment)[0]], cg.coords[s1][cg.get_sides(s1, segment)[1]] closer2, far2 = cg.coords[s2][cg.get_sides( s2, segment)[0]], cg.coords[s2][cg.get_sides(s2, segment)[1]] data["offset"].append( ftuv.vec_distance(*ftuv.line_segment_distance( closer1, closer1 + (closer1 - far1) * 100000, closer2, closer2 + (closer2 - far2) * 100000))) data["junction_va_distance"].append( ftug.junction_virtual_atom_distance(cg, segment)) data["is_external_multiloop"].append("open" in description) data["is_pseudoknotted_multiloop"].append( "pseudoknot" in description) data["is_regular_multiloop"].append( "regular_multiloop" in description) data["is_interior_loop"].append("interior_loop" in description) if j3_roles is not None: elem_role, = [ x[0] for x in j3_roles.items() if x[1] == segment ] else: elem_role = "?" data["j3_role"].append(elem_role) data["j3_familyFlat"].append(j3_familyFlat) data["j3_family3D"].append(j3_family3D) data["j3_familyPerp"].append(j3_familyPerp) data["j3_Delta_j23_j31"].append(j3_Delta) dssr_stacking = False if "dssr_stacks" in cg.infos: if segment in cg.infos["dssr_stacks"]: dssr_stacking = True data["dssr_stacking"].append(dssr_stacking) kh_stem_angle = float("nan") if abs(cg.get_angle_type(segment, allow_broken=True)) == 5: next_ml = cg.get_next_ml_segment(segment) if isinstance(next_ml, str) and next_ml[0] == "m" and abs( cg.get_angle_type(next_ml, allow_broken=True)) == 5: stems1 = cg.edges[segment] stems2 = cg.edges[next_ml] try: s1, s2 = (stems1 | stems2) - (stems1 & stems2) except ValueError: pass else: vec1 = cg.coords.get_direction(s1) vec2 = cg.coords.get_direction(s2) angle = ftuv.vec_angle(vec1, vec2) if angle > math.pi / 2: angle = math.pi - angle kh_stem_angle = angle data["kh_stem_angle"].append(kh_stem_angle) if data: data["pk_number"] = number_by(data, "loop_start_after", "is_pseudoknotted_multiloop") data["loop_number"] = number_by(data, "loop_start_after", None) data["reguler_multiloop_number"] = number_by(data, "loop_start_after", "is_regular_multiloop") return data
sm.sample_stats() possible_sstats=sm.conf_stats.sample_stats(cg, "s1") for sstat in possible_sstats: if sstat.pdb_name.startswith("ideal"): break maxdist=0 sm.elem_defs["s1"] = sstat possible_stats=sm.conf_stats.sample_stats(cg, "m0") for i, stat in enumerate(possible_stats): #if i%1000 == 0: # print(i, "/", len(possible_stats), end="") sm.elem_defs["m0"] = stat sm.traverse_and_build() e=energy.eval_energy(sm) dist = ftug.junction_virtual_atom_distance(cg, "m0") if dist>maxdist: maxdist=dist if e>0: print ("\nSampled stats do not match energy:") print (stat) print( dist, ">", cutoff_distance) print(sm.elem_defs["s0"]) print(sm.elem_defs["s1"]) print( "Maxdist", maxdist, "<", cutoff_distance)
def describe_ml_segments(cg): data = defaultdict(list) loops = cg.find_mlonly_multiloops() for loop in loops: description = cg.describe_multiloop(loop) try: j3_roles = cg.assign_loop_roles(loop) except ValueError: j3_roles = None if j3_roles: j3_familyFlat = cg.junction_family_westhof1(j3_roles) j3_family3D = cg.junction_family_3d(j3_roles) j3_familyPerp = cg.junction_family_is_perpenticular(j3_roles) j3_Delta = cg.get_length(j3_roles["J23"]) - cg.get_length( j3_roles["J31"]) else: j3_family3D = None j3_familyFlat = None j3_familyPerp = None j3_Delta = None loop_start = float("inf") for segment in loop: if cg.define_a(segment)[0] < loop_start: loop_start = cg.define_a(segment)[0] for segment in loop: if segment[0] != "m": continue data["loop_start_after"].append(loop_start) data["segment_start_after"].append(cg.define_a(segment)[0]) data["segment"].append(segment) data["junction_length"].append(len(loop)) data["segment_length"].append(cg.get_length(segment)) data["loops_largest_segment_length"].append( max(cg.get_length(x) for x in loop)) data["loops_shortest_segment_length"].append( min(cg.get_length(x) for x in loop)) data["sum_of_loops_segment_lengths"].append( sum(cg.get_length(x) for x in loop)) data["loop_segment_lengths"].append(",".join( map(str, sorted(cg.get_length(x) for x in loop)))) data["angle_type"].append( abs(cg.get_angle_type(segment, allow_broken=True))) s1, s2 = cg.connections(segment) vec1 = cg.coords.get_direction(s1) if cg.get_sides(s1, segment) == (1, 0): vec1 = -vec1 else: assert cg.get_sides(s1, segment) == (0, 1) vec2 = cg.coords.get_direction(s2) if cg.get_sides(s2, segment) == (1, 0): vec2 = -vec2 else: assert cg.get_sides(s2, segment) == (0, 1) data["angle_between_stems"].append(ftuv.vec_angle(vec1, vec2)) data["junction_va_distance"].append( ftug.junction_virtual_atom_distance(cg, segment)) data["is_external_multiloop"].append("open" in description) data["is_pseudoknotted_multiloop"].append( "pseudoknot" in description) data["is_regular_multiloop"].append( "regular_multiloop" in description) if j3_roles is not None: elem_role, = [ x[0] for x in j3_roles.items() if x[1] == segment ] else: elem_role = "?" data["j3_role"].append(elem_role) data["j3_familyFlat"].append(j3_familyFlat) data["j3_family3D"].append(j3_family3D) data["j3_familyPerp"].append(j3_familyPerp) data["j3_Delta_j23_j31"].append(j3_Delta) if data: data["pk_number"] = number_by(data, "loop_start_after", "is_pseudoknotted_multiloop") data["loop_number"] = number_by(data, "loop_start_after", None) data["reguler_multiloop_number"] = number_by(data, "loop_start_after", "is_regular_multiloop") return data
def test_junction_virtual_atom_distance_realPDB(self): distance = ftug.junction_virtual_atom_distance( self.rs_random_281, "m3") self.assertLess(distance, 4.) # This should always hold! # This value might change, if we change the virtual atom calculation self.assertAlmostEqual(distance, 3.486261134885911)
def test_junction_virtual_atom_distance_realPDB(self): distance=ftug.junction_virtual_atom_distance(self.rs_random_281, "m4") self.assertLess(distance, 4.)
def describe_ml_segments(cg): data = defaultdict(list) loops = cg.find_mlonly_multiloops() for loop in it.chain(loops, [[i] for i in cg.iloop_iterator()]): print(loop) if loop[0][0] == "i": description = ["interior_loop"] else: description = cg.describe_multiloop(loop) try: j3_roles = cg._assign_loop_roles(loop) except ValueError: j3_roles = None if j3_roles: j3_familyFlat = cg._junction_family_westhof1(j3_roles) j3_family3D = cg._junction_family_3d(j3_roles) j3_familyPerp = cg._junction_family_is_perpenticular(j3_roles) j3_Delta = cg.get_length( j3_roles["J23"]) - cg.get_length(j3_roles["J31"]) else: j3_family3D = None j3_familyFlat = None j3_familyPerp = None j3_Delta = None loop_start = float("inf") for segment in loop: if cg.define_a(segment)[0] < loop_start: loop_start = cg.define_a(segment)[0] for segment in loop: if segment[0] not in "mi": continue data["loop_start_after"].append(loop_start) data["segment_start_after"].append(cg.define_a(segment)[0]) data["segment"].append(segment) data["junction_length"].append(len(loop)) data["segment_length"].append(cg.get_length(segment)) if segment[0] == "i": dims = list(sorted(cg.get_bulge_dimensions(segment))) else: dims = [-1, -1] data["iloop_length_1"].append(dims[0]) data["iloop_length_2"].append(dims[1]) data["loops_largest_segment_length"].append( max(cg.get_length(x) for x in loop)) data["loops_shortest_segment_length"].append( min(cg.get_length(x) for x in loop)) data["sum_of_loops_segment_lengths"].append( sum(cg.get_length(x) for x in loop)) data["loop_segment_lengths"].append( ",".join(map(str, sorted(cg.get_length(x) for x in loop)))) data["angle_type"].append( abs(cg.get_angle_type(segment, allow_broken=True))) s1, s2 = cg.connections(segment) vec1 = cg.coords.get_direction(s1) if cg.get_sides(s1, segment) == (1, 0): vec1 = -vec1 else: assert cg.get_sides(s1, segment) == (0, 1) vec2 = cg.coords.get_direction(s2) if cg.get_sides(s2, segment) == (1, 0): vec2 = -vec2 else: assert cg.get_sides(s2, segment) == (0, 1) data["angle_between_stems"].append(ftuv.vec_angle(vec1, vec2)) data["offset1"].append(ftuv.point_line_distance(cg.coords[s1][cg.get_sides(s1, segment)[0]], cg.coords[s2][0], cg.coords.get_direction( s2) )) data["offset2"].append(ftuv.point_line_distance(cg.coords[s2][cg.get_sides(s2, segment)[0]], cg.coords[s1][0], cg.coords.get_direction( s1) )) closer1, far1 = cg.coords[s1][cg.get_sides( s1, segment)[0]], cg.coords[s1][cg.get_sides(s1, segment)[1]] closer2, far2 = cg.coords[s2][cg.get_sides( s2, segment)[0]], cg.coords[s2][cg.get_sides(s2, segment)[1]] data["offset"].append(ftuv.vec_distance(*ftuv.line_segment_distance(closer1, closer1 + (closer1 - far1) * 100000, closer2, closer2 + (closer2 - far2) * 100000))) data["junction_va_distance"].append( ftug.junction_virtual_atom_distance(cg, segment)) data["is_external_multiloop"].append("open" in description) data["is_pseudoknotted_multiloop"].append( "pseudoknot" in description) data["is_regular_multiloop"].append( "regular_multiloop" in description) data["is_interior_loop"].append("interior_loop" in description) if j3_roles is not None: elem_role, = [x[0] for x in j3_roles.items() if x[1] == segment] else: elem_role = "?" data["j3_role"].append(elem_role) data["j3_familyFlat"].append(j3_familyFlat) data["j3_family3D"].append(j3_family3D) data["j3_familyPerp"].append(j3_familyPerp) data["j3_Delta_j23_j31"].append(j3_Delta) dssr_stacking = False if "dssr_stacks" in cg.infos: if segment in cg.infos["dssr_stacks"]: dssr_stacking = True data["dssr_stacking"].append(dssr_stacking) kh_stem_angle = float("nan") if abs(cg.get_angle_type(segment, allow_broken=True)) == 5: next_ml = cg.get_next_ml_segment(segment) if isinstance(next_ml, str) and next_ml[0] == "m" and abs(cg.get_angle_type(next_ml, allow_broken=True)) == 5: stems1 = cg.edges[segment] stems2 = cg.edges[next_ml] try: s1, s2 = (stems1 | stems2) - (stems1 & stems2) except ValueError: pass else: vec1 = cg.coords.get_direction(s1) vec2 = cg.coords.get_direction(s2) angle = ftuv.vec_angle(vec1, vec2) if angle > math.pi / 2: angle = math.pi - angle kh_stem_angle = angle data["kh_stem_angle"].append(kh_stem_angle) if data: data["pk_number"] = number_by(data, "loop_start_after", "is_pseudoknotted_multiloop") data["loop_number"] = number_by(data, "loop_start_after", None) data["reguler_multiloop_number"] = number_by(data, "loop_start_after", "is_regular_multiloop") return data
def test_junction_virtual_atom_distance_realPDB(self): distance=ftug.junction_virtual_atom_distance(self.rs_random_281, "m4") self.assertLess(distance, 4.) self.assertAlmostEqual(distance, 3.4765561271716967)
if __name__ == "__main__": next_id = defaultdict(int) args = parser.parse_args() cgs = fuc.cgs_from_args(args, "only_cg") for cg in cgs: if sys.stderr.isatty(): print(cg.name, file=sys.stderr) for elem in cg.defines.keys(): if elem in cg.incomplete_elements: print("Skipping element", elem, file=sys.stderr) continue base_name = "{}:{}_".format(cg.name, elem[0]) for stat in cg.get_stats(elem): idnr = next_id[base_name] next_id[base_name] += 1 name = base_name + str(idnr) stat.pdb_name = name if elem.startswith("m"): try: dist = ftug.junction_virtual_atom_distance(cg, elem) stat_dist = stat.get_virtual_atom_distance() except: print(stat) #raise else: print( stat, "# distance: {}. stat_dist {}".format( dist, stat_dist)) else: print(stat)