Example #1
0
    def on_mx_image_selected(self, event, lc):
        #		self.arc_anim_points = None
        get_application().setOverrideCursor(Qt.BusyCursor)
        if lc != None: self.sel = lc[0]

        if self.average != None:
            included = []
            if self.average.has_attr("class_ptcl_idxs"):
                included = self.average["class_ptcl_idxs"]
            excluded = []
            if self.average.has_attr("exc_class_ptcl_idxs"):
                excluded = self.average["exc_class_ptcl_idxs"]

            all = included + excluded
            #all.sort()

            bdata = []
            data = []
            idx_included = []
            running_idx = 0
            from eman2_gui.emimagemx import ApplyAttribute
            for val in included:
                bdata.append(
                    [self.particle_file, val, [ApplyAttribute("Img #", val)]])
                idx_included.append(running_idx)
                running_idx += 1

            idx_excluded = []
            for val in excluded:
                bdata.append(
                    [self.particle_file, val, [ApplyAttribute("Img #", val)]])
                idx_excluded.append(running_idx)
                running_idx += 1

            data = EMLightWeightParticleCache(bdata)

            first = False
            if self.particle_viewer == None:
                first = True
                self.particle_viewer = EMImageMXWidget(
                    data=None, application=get_application())
                self.particle_viewer.set_mouse_mode("App")
                self.particle_viewer.module_closed.connect(
                    self.on_particle_mx_view_closed)
                self.particle_viewer.mx_image_selected.connect(
                    self.particle_selected)
                get_application().show_specific(self.particle_viewer)

            self.check_images_in_memory()

            if self.sel == 0 or self.alignment_file == None:
                self.particle_viewer.set_data(data)
            else:

                for i, [name, idx, f] in enumerate(bdata):
                    index = -1
                    if self.classes.get_xsize() == 1:
                        index = 0  # just assume it's the first one - this is potentially fatal assumption, but in obscure situations only
                    else:
                        for j in range(self.classes.get_xsize()):
                            if int(self.classes.get(j, idx)) == self.class_idx:
                                index = j
                                break
                    if index == -1:
                        print("couldn't find")
                        get_application().setOverrideCursor(Qt.ArrowCursor)
                        return

                    x = self.dx.get(index, idx)
                    y = self.dy.get(index, idx)
                    a = self.da.get(index, idx)
                    m = self.dflip.get(index, idx)

                    t = Transform({"type": "2d", "alpha": a, "mirror": int(m)})
                    t.set_trans(x, y)
                    from eman2_gui.emimagemx import ApplyTransform
                    f.append(ApplyTransform(t))
                    #data[i].transform(t)
                self.particle_viewer.set_data(data)

            if first:
                self.particle_viewer.updateGL()
                self.particle_viewer.optimally_resize()

            self.particle_viewer.clear_sets(False)
            self.particle_viewer.enable_set("Excluded", idx_excluded, True,
                                            False)
            self.particle_viewer.enable_set("Included", idx_included, False,
                                            False)
            self.particle_viewer.updateGL()

            get_application().setOverrideCursor(Qt.ArrowCursor)

            self.updateGL()
Example #2
0
    def on_au_selected(self, refine_dir, cls):
        refine_dir = str(refine_dir)
        cls = str(cls)
        self.refine_dir = refine_dir
        get_application().setOverrideCursor(Qt.BusyCursor)
        data = []
        for d in self.au_data[refine_dir]:
            if d[0] == cls:
                data = d
                break

        if len(data) == 0:
            error("error, no data for %s %s, returning" % (refine_dir, cls))
            #			print "error, no data for",au,cls,"returning"
            self.events_handlers["inspect"].reset()
            get_application().setOverrideCursor(Qt.ArrowCursor)
            return

        if not self.readfrom:
            try:
                self.particle_file = js_open_dict(
                    refine_dir + "/0_refine_parms.json")["input"]
            except:
                error("No data in " + refine_dir)
                self.events_handlers["inspect"].reset()
                get_application().setOverrideCursor(Qt.ArrowCursor)
                return

        self.average_file = cls
        self.projection_file = data[4]
        self.alignment_file = data[2]
        self.clsdb = data[1]

        self.dx = None
        self.dy = None
        self.da = None
        self.dflip = None
        self.classes = None

        eulers = get_eulers_from(self.average_file)
        #s = Symmetries.get("d7")
        #eulers = s.gen_orientations("rand",{"n":EMUtil.get_image_count(self.average_file)})

        self.specify_eulers(eulers)
        #from eman2_gui.emimagemx import EMDataListCache
        #a = EMData.read_images(self.average_file)
        #a = [test_image() for i in range(EMUtil.get_image_count(self.average_file))]
        #print len(a),len(eulers)
        #b = [a[i].set_attr("xform.projection",eulers[i]) for i in range(len(eulers))]
        #b = [a[i].set_attr("ptcl_repr",1) for i in range(len(eulers))]

        self.set_emdata_list_as_data(
            EMLightWeightParticleCache.from_file(self.average_file),
            "ptcl_repr")
        #self.set_emdata_list_as_data(EMDataListCache(self.average_file),"ptcl_repr")
        #		self.set_emdata_list_as_data(a,"ptcl_repr")
        self.force_update = True
        self.au_point_selected(self.class_idx, None)
        # if we have the same number of Eulers we can update everything
        #		if self.previous_len == len(eulers) : self.events_handlers["inspect"].repeat_event()
        #		else:self.events_handlers["inspect"].reset()
        self.previous_len = len(eulers)
        if not self.init_lock: self.updateGL()
        get_application().setOverrideCursor(Qt.ArrowCursor)