Exemplo n.º 1
0
    def _get_segments(self, path):

        direction = [0, 0, 0]
        new_direction = None
        segments = []
        segment = []
        for i, p in enumerate(path):
            if i < 2:
                segment.append(p)
                if i == 1:
                    direction = util.normalize(segment[0] - segment[1])
                continue

            new_direction = util.normalize(segment[-1] - p)
            if util.distance(new_direction, direction) > 0.1:
                segments.append(segment)
                segment = [p]
                direction = new_direction
            else:
                segment.append(p)

        if len(segment) > 0:
            segments.append(segment)

        return segments
Exemplo n.º 2
0
    def _get_segments(self, path):

        direction = [0, 0, 0]
        new_direction = None
        segments = []
        segment = []
        for i, p in enumerate(path):
            if i < 2:
                segment.append(p)
                if i == 1:
                    direction = util.normalize(segment[0] - segment[1])
                continue

            new_direction = util.normalize(segment[-1] - p)
            if util.distance(new_direction, direction) > 0.1:
                segments.append(segment)
                segment = [p]
                direction = new_direction
            else:
                segment.append(p)

        if len(segment) > 0:
            segments.append(segment)

        return segments
Exemplo n.º 3
0
    def listen(self):
        self.state.key = self.listen_for_keys()
        self.state.m_event = self.listen_for_mouse()

        if self.state.update_center:
            self._center_view()
            self.state.update_center = 0

        if self.dragging:
            vec1 = util.normalize(self.scene.mouse.pos - self.lastpos)

            if util.distance(vec1, [0, 0, 0]) > 0.1:
                vec2 = self.scene.forward
                rotation = cross(vec1, vec2)
                mag = util.distance(self.scene.mouse.pos - self.lastpos,
                                    [0, 0, 0])
                self.scene.forward = self.scene.forward.rotate(angle=0.0007 *
                                                               mag,
                                                               axis=rotation)

                if self.scene.forward.y > 0.90:
                    self.scene.forward.y = 0.90
                if self.scene.forward.y < -0.90:
                    self.scene.forward.y = -0.90

        if self.zooming:
            vec1 = util.normalize(self.scene.mouse.pos - self.lastpos)

            if util.distance(vec1, [0, 0, 0]) > 0.1:

                mag = util.distance(self.scene.mouse.pos - self.lastpos,
                                    [0, 0, 0])
                if vec1[1] > 0:
                    self.scene.range = self.range / (1.000 + 0.0005 * mag)
                    self.range = self.range / (1.000 + 0.0005 * mag)
                if vec1[1] < 0:
                    self.scene.range = self.range / (1.000 - 0.0005 * mag)
                    self.range = self.range / (1.000 - 0.0005 * mag)

        val = self.tc.GetValue()
        spl = val.split("\n")

        if len(spl) > 1:
            self._parse_commands(spl[0])
            self.tc.SetValue("")

        for f in self.functions:
            if not f.activated:
                continue
            f.listen(self.state)
Exemplo n.º 4
0
    def listen(self):
        self.state.key = self.listen_for_keys()
        self.state.m_event = self.listen_for_mouse()

        if self.state.update_center:
            self._center_view()
            self.state.update_center = 0

        if self.dragging:
            vec1 = util.normalize(self.scene.mouse.pos - self.lastpos)

            if util.distance(vec1, [0, 0, 0]) > 0.1:
                vec2 = self.scene.forward
                rotation = cross(vec1, vec2)
                mag = util.distance(self.scene.mouse.pos - self.lastpos, [0,0,0])
                self.scene.forward = self.scene.forward.rotate(angle=0.0007*mag,
                                                               axis=rotation)

                if self.scene.forward.y > 0.90:
                    self.scene.forward.y = 0.90
                if self.scene.forward.y < -0.90:
                    self.scene.forward.y = -0.90

        if self.zooming:
            vec1 = util.normalize(self.scene.mouse.pos - self.lastpos)

            if util.distance(vec1, [0, 0, 0]) > 0.1:

                mag = util.distance(self.scene.mouse.pos - self.lastpos, [0,0,0])
                if vec1[1] > 0:
                    self.scene.range = self.range/(1.000 + 0.0005*mag)
                    self.range = self.range/(1.000 + 0.0005*mag)
                if vec1[1] < 0:
                    self.scene.range = self.range/(1.000 - 0.0005*mag)
                    self.range = self.range/(1.000 - 0.0005*mag)


        val = self.tc.GetValue()
        spl = val.split("\n")

        if len(spl) > 1:
            self._parse_commands(spl[0])
            self.tc.SetValue("")

        for f in self.functions:
            if not f.activated:
                continue
            f.listen(self.state)
Exemplo n.º 5
0
    def draw_base_cartoon(self, indices, pos1, pos2):
        points = []
        for i in indices:
            points.append(self.atoms[i].coords)


        dir1 = points[0] - points[pos1]
        dir2 = points[0] - points[pos2]
        norm = util.normalize(np.cross(dir1, dir2))*0.25

        self.cartoons.append(self.draw_cartoon(points, norm))
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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
Exemplo n.º 8
0
    def draw(self, view_mode=0):
        self.view_mode = view_mode
        self.drawn = 1
        for va in self.atoms:
            if va is not None:
                va.draw(view_mode)

        if view_mode == 0:
            self.draw_bonds()

        if view_mode == 1:
            beads = self.get_beads()
            pos_i = beads[1].center
            pos_j = beads[2].center
            axis = pos_j - pos_i
            self.rod = cylinder(pos=pos_i, axis=axis, radius=1.0,
                                color=color.blue)

        if view_mode == 2:
            sugar_points = []
            sugar_points.append( self.atoms[5].coords)
            sugar_points.append( self.atoms[6].coords)
            sugar_points.append( self.atoms[9].coords)
            sugar_points.append( self.atoms[10].coords)
            sugar_points.append( self.atoms[7].coords)

            dir1 = self.atoms[5].coords - self.atoms[9].coords
            dir2 = self.atoms[5].coords - self.atoms[10].coords
            norm = util.normalize(np.cross(dir1, dir2))*0.25
            if len(self.cartoons) > 0:
                return

            self.cartoons = [ self.draw_cartoon(sugar_points, norm) ]

            if self.rtype.name == "ADE":
                self.draw_base_cartoon([21, 20, 19, 16, 15], 3, 2)
                self.draw_base_cartoon([17, 16, 15, 14, 13, 12], 3, 2)
                self.draw_bond(21, 9)

            elif self.rtype.name == "GUA":
                self.draw_base_cartoon([22, 21, 20, 17, 16], 3, 2)
                self.draw_base_cartoon([17, 16, 18, 12, 13, 15], 3, 2)
                self.draw_bond(22, 9)

            else:
                self.draw_base_cartoon([12, 13, 15, 16, 18, 19], 3, 2)
                self.draw_bond(12, 9)