def _get_sub_pathes(self, segments): pathes = [] for i in range(len(segments)): if i == 0: continue p = [] if i == 1: p.extend(segments[0]) else: half = len(segments[i - 1]) / 2 p.extend(segments[i - 1][half - 1:]) if i == len(segments) - 1: p.extend(segments[i]) else: half = len(segments[i]) / 2 p.extend(segments[i][:half - 1]) pathes.append(p) for i, p in enumerate(pathes): basic_io.points_to_pdb("path." + str(i) + ".pdb", p) f = open("path." + str(i) + ".str", "w") f.write(basic_io.points_to_str(p)) f.close() return pathes
def _get_sub_pathes(self, segments): pathes = [] for i in range(len(segments)): if i == 0: continue p = [] if i == 1: p.extend(segments[0]) else: half = len(segments[i - 1]) / 2 p.extend(segments[i - 1][half - 1 :]) if i == len(segments) - 1: p.extend(segments[i]) else: half = len(segments[i]) / 2 p.extend(segments[i][: half - 1]) pathes.append(p) for i, p in enumerate(pathes): basic_io.points_to_pdb("path." + str(i) + ".pdb", p) f = open("path." + str(i) + ".str", "w") f.write(basic_io.points_to_str(p)) f.close() return pathes
def _run_path_finding(self, state): if self.built: state.vmg.remove_node_level(1) state.vmg.mg.decrease_level() all_points = [] reg_points = [] for p in self.points: reg_points.append(np.array(p.pos)) for i in range(len(reg_points) - 1): all_points.append(reg_points[i]) diff = reg_points[i + 1] - reg_points[i] unit_vector = util.normalize(diff) current = reg_points[i] + unit_vector * 5.0 while util.distance(reg_points[i + 1], current) > 5.0: all_points.append(current) current = current + unit_vector * 5.0 s = basic_io.points_to_str(all_points) f = open("all_points.str", "w") f.write(s) f.close() basic_io.points_to_pdb("all_points.pdb", all_points) f = open("mg.top", "w") f.write(state.vmg.mg.topology_to_str() + "\n") f.write( str(self.highlighted_ends[0][0]) + " " + self.highlighted_ends[0][1].name()) f.close() self.path_builder.build() f = open("mt_out.top") lines = f.readlines() f.close() mt = motif_tree.motif_tree_from_topology_str(lines[0]) state.vmg.mg.increase_level() state.vmg.add_motif_tree(mt, self.highlighted_ends[0][0], self.highlighted_ends[0][1].name()) for p in self.points: p.opacity = 0.5 for l in self.lines: l.opacity = 0.5 self.built = 1 state.update_center = 1
def _run_path_finding(self, state): if self.built: state.vmg.remove_node_level(1) state.vmg.mg.decrease_level() all_points = [] reg_points = [] for p in self.points: reg_points.append(np.array(p.pos)) for i in range(len(reg_points)-1): all_points.append(reg_points[i]) diff = reg_points[i+1] - reg_points[i] unit_vector = util.normalize(diff) current = reg_points[i] + unit_vector*5.0 while util.distance(reg_points[i+1], current) > 5.0: all_points.append(current) current = current + unit_vector*5.0 s = basic_io.points_to_str(all_points) f = open("all_points.str", "w") f.write(s) f.close() basic_io.points_to_pdb("all_points.pdb", all_points) f = open("mg.top", "w") f.write(state.vmg.mg.topology_to_str() + "\n") f.write(str(self.highlighted_ends[0][0]) + " " + self.highlighted_ends[0][1].name()) f.close() self.path_builder.build() f = open("mt_out.top") lines = f.readlines() f.close() mt = motif_tree.motif_tree_from_topology_str(lines[0]) state.vmg.mg.increase_level() state.vmg.add_motif_tree(mt, self.highlighted_ends[0][0], self.highlighted_ends[0][1].name()) for p in self.points: p.opacity = 0.5 for l in self.lines: l.opacity = 0.5 self.built = 1 state.update_center = 1
def listen_for_keys(self, state): if state.key == 'u': if len(self.previous_points) > 0: pos = self.previous_points.pop() for i, p in enumerate(self.points): p.pos = pos[i] self._update_path() if state.key == 'd': if len(self.points) == 0: return if len(self.highlighted_ends) == 2: dist = util.distance(self.points[-1].pos, self.highlighted_ends[1][1].d) if dist < 0.1: self.highlighted_ends.pop() for i in range(2): last = self.points.pop() last.visible = False del last for i in range(3): last = self.lines.pop() last.visible = False del last return last = self.points.pop() last.visible = False del last if len(self.lines) != 0: last_l = self.lines.pop() last_l.visible = False del last_l if len(self.lines) != 0: last_l = self.lines.pop() last_l.visible = False del last_l if len(self.points) == 1: last = self.points.pop() last.visible = False del last if state.key == 'r': self._run_path_finding(state) if state.key == 's': print "saving session: rnamake.save" f = open("rnamake.save", "w") f.write(state.vmg.mg.topology_to_str() + "\n") for n in state.vmg.mg.graph.nodes: f.write(str(n.level) + " ") f.write("\n") point_pos = [] for p in self.points: point_pos.append([p.pos.x, p.pos.y, p.pos.z]) f.write(basic_io.points_to_str(point_pos) + "\n") f.write( str(self.highlighted_ends[0][0]) + " " + self.highlighted_ends[0][1].name() + "\n") if len(self.highlighted_ends) > 1: f.write( str(self.highlighted_ends[1][0]) + " " + self.highlighted_ends[1][1].name() + "\n") f.close() if state.key == 'f': pass if state.key == 'p': print "printing structure: rnamake.pdb" state.vmg.mg.to_pdb("rnamake.pdb", close_chain=1, renumber=1)
def listen_for_keys(self, state): if state.key == 'u': if len(self.previous_points) > 0: pos = self.previous_points.pop() for i, p in enumerate(self.points): p.pos = pos[i] self._update_path() if state.key == 'd': if len(self.points) == 0: return if len(self.highlighted_ends) == 2: dist = util.distance(self.points[-1].pos, self.highlighted_ends[1][1].d) if dist < 0.1: self.highlighted_ends.pop() for i in range(2): last = self.points.pop() last.visible = False del last for i in range(3): last = self.lines.pop() last.visible = False del last return last = self.points.pop() last.visible = False del last if len(self.lines) != 0: last_l = self.lines.pop() last_l.visible = False del last_l if len(self.lines) != 0: last_l = self.lines.pop() last_l.visible = False del last_l if len(self.points) == 1: last = self.points.pop() last.visible = False del last if state.key == 'r': self._run_path_finding(state) if state.key == 's': print "saving session: rnamake.save" f = open("rnamake.save", "w") f.write(state.vmg.mg.topology_to_str() + "\n") for n in state.vmg.mg.graph.nodes: f.write(str(n.level) + " ") f.write("\n") point_pos = [] for p in self.points: point_pos.append([p.pos.x, p.pos.y, p.pos.z]) f.write(basic_io.points_to_str(point_pos) + "\n") f.write(str(self.highlighted_ends[0][0]) + " " + self.highlighted_ends[0][1].name() + "\n") if len(self.highlighted_ends) > 1: f.write(str(self.highlighted_ends[1][0]) + " " + self.highlighted_ends[1][1].name() + "\n") f.close() if state.key == 'f': pass if state.key == 'p': print "printing structure: rnamake.pdb" state.vmg.mg.to_pdb("rnamake.pdb", close_chain=1,renumber=1)