Example #1
0
    def object_picked(self, object_number):
        if object_number == self.current_projection: return
        self.current_projection = object_number
        resize_necessary = False
        if self.mx_display == None:
            self.mx_display = EMImageMXModule()
            QtCore.QObject.connect(self.mx_display,
                                   QtCore.SIGNAL("module_closed"),
                                   self.on_mx_display_closed)
            resize_necessary = True

        #if self.frc_display == None:
        #self.frc_display = EMPlot2DModule()
#			QtCore.QObject.connect(self.frc_display,QtCore.SIGNAL("module_closed"),self.on_frc_display_closed)

        self.update_display(False)

        if resize_necessary:
            get_application().show_specific(self.mx_display)
            self.mx_display.optimally_resize()
#			get_application().show_specific(self.frc_display)
#			self.frc_display.optimally_resize()
        else:
            self.mx_display.updateGL()
#			self.frc_display.updateGL()

        if object_number != self.special_euler:
            self.special_euler = object_number
            self.regen_dl()
Example #2
0
	def object_picked(self,object_number):
		if object_number == self.current_projection: return
		self.current_projection = object_number
		resize_necessary = False
		if self.mx_display == None:
			self.mx_display = EMImageMXModule()
			QtCore.QObject.connect(self.mx_display,QtCore.SIGNAL("module_closed"),self.on_mx_display_closed)
			resize_necessary = True

		#if self.frc_display == None:
			#self.frc_display = EMPlot2DModule()
#			QtCore.QObject.connect(self.frc_display,QtCore.SIGNAL("module_closed"),self.on_frc_display_closed)

		self.update_display(False)

		if resize_necessary:
			get_application().show_specific(self.mx_display)
			self.mx_display.optimally_resize()
#			get_application().show_specific(self.frc_display)
#			self.frc_display.optimally_resize()
		else:
			self.mx_display.updateGL()
#			self.frc_display.updateGL()
			
		if object_number != self.special_euler:
			self.special_euler = object_number
			self.regen_dl()
Example #3
0
	def set_shrink(self,shrink):
		"""This actually loads the data ..."""
		
		self.shrink=shrink
		# Deal with particles
		n=min(EMUtil.get_image_count(self.particle_file),800)
		self.ptcl_data=[i for i in EMData.read_images(self.particle_file,range(n)) if i!=None]
		if self.shrink>1 :
			for i in self.ptcl_data : i.process_inplace("math.meanshrink",{"n":self.shrink})
		for i in self.ptcl_data : i.process_inplace("normalize.edgemean",{})

		if self.ptcl_display==None : 
			self.ptcl_display = EMImageMXModule()
			self.ptcl_display.set_mouse_mode("App")
			QtCore.QObject.connect(self.ptcl_display,QtCore.SIGNAL("mx_image_selected"),self.ptcl_selected)		
			QtCore.QObject.connect(self.ptcl_display,QtCore.SIGNAL("module_closed"),self.on_mx_display_closed)
		self.ptcl_display.set_data(self.ptcl_data)

		# deal with projections
		self.proj_data=EMData.read_images(self.projection_file)
		if self.shrink>1 :
			for i in self.proj_data : i.process_inplace("math.meanshrink",{"n":self.shrink})
		for i in self.proj_data : i.process_inplace("normalize.edgemean",{})

		eulers = [i["xform.projection"] for i in self.proj_data]
		self.specify_eulers(eulers)
		
		for i in self.proj_data : i["cmp"]=0.0
		self.set_emdata_list_as_data(self.proj_data,"cmp")
Example #4
0
    def set_shrink(self, shrink):
        """This actually loads the data ..."""

        self.shrink = shrink
        # Deal with particles
        n = min(EMUtil.get_image_count(self.particle_file), 800)
        self.ptcl_data = [
            i for i in EMData.read_images(self.particle_file, range(n))
            if i != None
        ]
        if self.shrink > 1:
            for i in self.ptcl_data:
                i.process_inplace("math.meanshrink", {"n": self.shrink})
        for i in self.ptcl_data:
            i.process_inplace("normalize.edgemean", {})

        if self.ptcl_display == None:
            self.ptcl_display = EMImageMXModule()
            self.ptcl_display.set_mouse_mode("App")
            QtCore.QObject.connect(self.ptcl_display,
                                   QtCore.SIGNAL("mx_image_selected"),
                                   self.ptcl_selected)
            QtCore.QObject.connect(self.ptcl_display,
                                   QtCore.SIGNAL("module_closed"),
                                   self.on_mx_display_closed)
        self.ptcl_display.set_data(self.ptcl_data)

        # deal with projections
        self.proj_data = EMData.read_images(self.projection_file)
        if self.shrink > 1:
            for i in self.proj_data:
                i.process_inplace("math.meanshrink", {"n": self.shrink})
        for i in self.proj_data:
            i.process_inplace("normalize.edgemean", {})

        eulers = [i["xform.projection"] for i in self.proj_data]
        self.specify_eulers(eulers)

        for i in self.proj_data:
            i["cmp"] = 0.0
        self.set_emdata_list_as_data(self.proj_data, "cmp")
Example #5
0
class EMCmpExplorer(EM3DSymModel):
    def __init__(self,
                 gl_widget,
                 projection_file=None,
                 simmx_file=None,
                 particle_file=None):
        self.init_lock = True  # a lock indicated that we are still in the __init__ function
        self.au_data = None  # This will be a dictionary, keys will be refinement directories, values will be something like available iterations for visual study
        EM3DSymModel.__init__(self, gl_widget)
        self.window_title = "SimmxXplor"
        #InputEventsManager.__init__(self)

        self.projection_file = projection_file  # a projection file produced by e2project3d
        self.particle_file = particle_file  # A file containing particles to be examined

        self.current_particle = -1  # keep track of the current particle
        self.current_projection = None  # keep track of the current projection

        self.ptcl_display = None  # display all particles
        self.mx_display = None  # mx display module for displaying projection and aligned particle
        self.lay = None  # 2d plot for displaying comparison between particle and projection

        self.simcmp = "dot:normalize=1"
        self.align = "rotate_translate_flip"
        self.aligncmp = "dot"
        self.refine = "refine"
        self.refinecmp = "dot:normalize=1"
        self.shrink = 1

    def set_data(self, projections, particles):
        '''
		Initialize data
		'''
        if not file_exists(projections):
            raise RuntimeError("%s does not exist" % self.projection_file)
        if not file_exists(particles):
            raise RuntimeError("%s does not exist" % self.particle_file)

        self.projection_file = projections  # a projection file produced by e2project3d
        self.particle_file = particles  # A file containing particles to be examined
        self.set_shrink(self.shrink)

    def set_shrink(self, shrink):
        """This actually loads the data ..."""

        self.shrink = shrink
        # Deal with particles
        n = min(EMUtil.get_image_count(self.particle_file), 800)
        self.ptcl_data = [
            i for i in EMData.read_images(self.particle_file, range(n))
            if i != None
        ]
        if self.shrink > 1:
            for i in self.ptcl_data:
                i.process_inplace("math.meanshrink", {"n": self.shrink})
        for i in self.ptcl_data:
            i.process_inplace("normalize.edgemean", {})

        if self.ptcl_display == None:
            self.ptcl_display = EMImageMXModule()
            self.ptcl_display.set_mouse_mode("App")
            QtCore.QObject.connect(self.ptcl_display,
                                   QtCore.SIGNAL("mx_image_selected"),
                                   self.ptcl_selected)
            QtCore.QObject.connect(self.ptcl_display,
                                   QtCore.SIGNAL("module_closed"),
                                   self.on_mx_display_closed)
        self.ptcl_display.set_data(self.ptcl_data)

        # deal with projections
        self.proj_data = EMData.read_images(self.projection_file)
        if self.shrink > 1:
            for i in self.proj_data:
                i.process_inplace("math.meanshrink", {"n": self.shrink})
        for i in self.proj_data:
            i.process_inplace("normalize.edgemean", {})

        eulers = [i["xform.projection"] for i in self.proj_data]
        self.specify_eulers(eulers)

        for i in self.proj_data:
            i["cmp"] = 0.0
        self.set_emdata_list_as_data(self.proj_data, "cmp")

    def get_num_particles(self):
        if self.ptcl_data == None: return 0
        return len(self.ptcl_data)

    def render(self):
        if self.inspector == None: self.get_inspector()

        EM3DSymModel.render(self)

    def object_picked(self, object_number):
        if object_number == self.current_projection: return
        self.current_projection = object_number
        resize_necessary = False
        if self.mx_display == None:
            self.mx_display = EMImageMXModule()
            QtCore.QObject.connect(self.mx_display,
                                   QtCore.SIGNAL("module_closed"),
                                   self.on_mx_display_closed)
            resize_necessary = True

        #if self.frc_display == None:
        #self.frc_display = EMPlot2DModule()
#			QtCore.QObject.connect(self.frc_display,QtCore.SIGNAL("module_closed"),self.on_frc_display_closed)

        self.update_display(False)

        if resize_necessary:
            get_application().show_specific(self.mx_display)
            self.mx_display.optimally_resize()
#			get_application().show_specific(self.frc_display)
#			self.frc_display.optimally_resize()
        else:
            self.mx_display.updateGL()
#			self.frc_display.updateGL()

        if object_number != self.special_euler:
            self.special_euler = object_number
            self.regen_dl()

    def update_display(self, update=True):
        '''
		Uses self.current_particle and self.current_projection to udpate the self.mx_display
		'''
        if self.mx_display == None: return

        if self.current_particle < 0 or self.current_projection == None: return

        dlist = []
        dlist.append(self.proj_data[
            self.current_projection].copy())  # aligned projection
        dlist[0].transform(dlist[0]["ptcl.align2d"])
        tmp = dlist[0].process("threshold.notzero")
        dlist.append(
            self.ptcl_data[self.current_particle].copy())  # original particle
        dlist[1].process_inplace("normalize.toimage", {"to": dlist[0]})
        dlist.append(self.proj_data[
            self.current_projection].copy())  # filtered projection
        dlist[2].process_inplace("filter.matchto", {"to": dlist[1]})
        dlist[2].mult(tmp)
        dlist[2].process_inplace("normalize.toimage", {"to": dlist[1]})
        dlist.append(dlist[2].copy())  # particle with projection subtracted
        dlist[3].sub(dlist[1])

        #dlist.append(self.ptcl_data[self.current_particle].copy())		# same as 1 and 2 above, but with a mask
        #tmp=dlist[0].process("threshold.notzero")
        #dlist[4].mult(tmp)
        #dlist[4].process_inplace("filter.matchto",{"to":dlist[0]})
        #dlist[4].mult(tmp)
        #dlist[4].process_inplace("normalize.toimage",{"to":dlist[0]})
        #dlist.append(dlist[3].copy())
        #dlist[5].sub(dlist[0])

        self.mx_display.set_data(dlist)

        if update: self.mx_display.updateGL()

    def on_mx_display_closed(self):
        self.mx_display = None

    def get_inspector(self):
        if not self.inspector:
            self.inspector = EMSimmxXplorInspector(self)
        return self.inspector

    def ptcl_selected(self, event, lc):
        """slot for image selection events from image mx"""
        self.set_ptcl_idx(lc[0])

    def set_alignment(self, align, aligncmp, refine, refinecmp):
        """sets alignment algorithms and recomputes"""
        self.align = str(align)
        self.aligncmp = str(aligncmp)
        self.refine = str(refine)
        self.refinecmp = str(refinecmp)

        self.update_align()

    def set_ptcl_idx(self, idx):
        """Select the index of the current particle to use for comparisons"""
        if self.current_particle != idx:
            self.current_particle = idx
            self.update_align()

    def update_align(self):
        if self.current_particle < 0: return
        ptcl = self.ptcl_data[self.current_particle]

        progress = QtGui.QProgressDialog("Computing alignments", "Abort", 0,
                                         len(self.proj_data), None)
        progress.show()
        # redetermines particle alignments
        # then we can quickly compute a series of different similarity values
        aopt = parsemodopt(self.align)
        acmp = parsemodopt(self.aligncmp)
        ropt = parsemodopt(self.refine)
        rcmp = parsemodopt(self.refinecmp)
        for i, p in enumerate(self.proj_data):
            try:
                ali = p.align(aopt[0], ptcl, aopt[1], acmp[0], acmp[1])
                if self.refine != "":
                    ropt[1]["xform.align2d"] = ali["xform.align2d"]
                    ali = p.align(ropt[0], ptcl, ropt[1], rcmp[0], rcmp[1])
            except:
                print traceback.print_exc()
                QtGui.QMessageBox.warning(None, "Error",
                                          "Problem with alignment parameters")
                progress.close()
                return
            p["ptcl.align2d"] = ali["xform.align2d"]
            progress.setValue(i)
            QtCore.QCoreApplication.instance().processEvents()

        progress.close()
        self.update_cmp()


#		self.update_display(True)

    def set_cmp(self, cmpstring):
        """Select the comparator. Passed as a standard name:attr=value:attr=value string"""
        self.simcmp = str(cmpstring)
        self.update_cmp()

    def update_cmp(self):
        cmpopt = parsemodopt(self.simcmp)

        progress = QtGui.QProgressDialog("Computing similarities", "Abort", 0,
                                         len(self.proj_data), None)
        progress.show()
        ptcl = self.ptcl_data[self.current_particle]
        for i, p in enumerate(self.proj_data):
            ali = p.copy()
            ali.transform(p["ptcl.align2d"])
            try:
                p["cmp"] = -ptcl.cmp(cmpopt[0], ali, cmpopt[1])
            except:
                print traceback.print_exc()
                QtGui.QMessageBox.warning(
                    None, "Error",
                    "Invalid similarity metric string, or other comparison error"
                )
                progress.close()
                return
            progress.setValue(i)
            QtGui.qApp.processEvents()

        progress.close()
        self.set_emdata_list_as_data(self.proj_data, "cmp")
        #		self.regen_dl(True)
        EM3DSymModel.render(self)
Example #6
0
class EMCmpExplorer(EM3DSymModel):
	def __init__(self, gl_widget, projection_file=None,simmx_file=None,particle_file=None):
		self.init_lock = True # a lock indicated that we are still in the __init__ function
		self.au_data = None # This will be a dictionary, keys will be refinement directories, values will be something like available iterations for visual study	
		EM3DSymModel.__init__(self,gl_widget)
		self.window_title = "SimmxXplor"
		#InputEventsManager.__init__(self)
	
		self.projection_file = projection_file 	# a projection file produced by e2project3d
		self.particle_file = particle_file 		# A file containing particles to be examined

		self.current_particle = -1 				# keep track of the current particle
		self.current_projection = None 			# keep track of the current projection

		self.ptcl_display = None			# display all particles
		self.mx_display = None 					# mx display module for displaying projection and aligned particle
		self.lay = None 						# 2d plot for displaying comparison between particle and projection
		
		self.simcmp = "dot:normalize=1"
		self.align = "rotate_translate_flip"
		self.aligncmp = "dot"
		self.refine = "refine"
		self.refinecmp = "dot:normalize=1"
		self.shrink=1
		
		
	def set_data(self,projections,particles):
		'''
		Initialize data
		'''
		if not file_exists(projections): raise RuntimeError("%s does not exist" %self.projection_file)
		if not file_exists(particles): raise RuntimeError("%s does not exist" %self.particle_file)
		
		self.projection_file = projections 	# a projection file produced by e2project3d
		self.particle_file = particles 		# A file containing particles to be examined
		self.set_shrink(self.shrink)
		
	def set_shrink(self,shrink):
		"""This actually loads the data ..."""
		
		self.shrink=shrink
		# Deal with particles
		n=min(EMUtil.get_image_count(self.particle_file),800)
		self.ptcl_data=[i for i in EMData.read_images(self.particle_file,range(n)) if i!=None]
		if self.shrink>1 :
			for i in self.ptcl_data : i.process_inplace("math.meanshrink",{"n":self.shrink})
		for i in self.ptcl_data : i.process_inplace("normalize.edgemean",{})

		if self.ptcl_display==None : 
			self.ptcl_display = EMImageMXModule()
			self.ptcl_display.set_mouse_mode("App")
			QtCore.QObject.connect(self.ptcl_display,QtCore.SIGNAL("mx_image_selected"),self.ptcl_selected)		
			QtCore.QObject.connect(self.ptcl_display,QtCore.SIGNAL("module_closed"),self.on_mx_display_closed)
		self.ptcl_display.set_data(self.ptcl_data)

		# deal with projections
		self.proj_data=EMData.read_images(self.projection_file)
		if self.shrink>1 :
			for i in self.proj_data : i.process_inplace("math.meanshrink",{"n":self.shrink})
		for i in self.proj_data : i.process_inplace("normalize.edgemean",{})

		eulers = [i["xform.projection"] for i in self.proj_data]
		self.specify_eulers(eulers)
		
		for i in self.proj_data : i["cmp"]=0.0
		self.set_emdata_list_as_data(self.proj_data,"cmp")

	def get_num_particles(self):
		if self.ptcl_data==None : return 0
		return len(self.ptcl_data)
		
	def render(self):
		if self.inspector == None: self.get_inspector()
			
		EM3DSymModel.render(self)
	
	def object_picked(self,object_number):
		if object_number == self.current_projection: return
		self.current_projection = object_number
		resize_necessary = False
		if self.mx_display == None:
			self.mx_display = EMImageMXModule()
			QtCore.QObject.connect(self.mx_display,QtCore.SIGNAL("module_closed"),self.on_mx_display_closed)
			resize_necessary = True

		#if self.frc_display == None:
			#self.frc_display = EMPlot2DModule()
#			QtCore.QObject.connect(self.frc_display,QtCore.SIGNAL("module_closed"),self.on_frc_display_closed)

		self.update_display(False)

		if resize_necessary:
			get_application().show_specific(self.mx_display)
			self.mx_display.optimally_resize()
#			get_application().show_specific(self.frc_display)
#			self.frc_display.optimally_resize()
		else:
			self.mx_display.updateGL()
#			self.frc_display.updateGL()
			
		if object_number != self.special_euler:
			self.special_euler = object_number
			self.regen_dl()
			
	def update_display(self,update=True):
		'''
		Uses self.current_particle and self.current_projection to udpate the self.mx_display
		'''
		if self.mx_display == None : return
		
		if self.current_particle<0 or self.current_projection==None : return
		
		dlist=[]
		dlist.append(self.proj_data[self.current_projection].copy())	# aligned projection
		dlist[0].transform(dlist[0]["ptcl.align2d"])					
		tmp=dlist[0].process("threshold.notzero")
		dlist.append(self.ptcl_data[self.current_particle].copy())		# original particle
		dlist[1].process_inplace("normalize.toimage",{"to":dlist[0]})
		dlist.append(self.proj_data[self.current_projection].copy())	# filtered projection
		dlist[2].process_inplace("filter.matchto",{"to":dlist[1]})
		dlist[2].mult(tmp)
		dlist[2].process_inplace("normalize.toimage",{"to":dlist[1]})
		dlist.append(dlist[2].copy())									# particle with projection subtracted
		dlist[3].sub(dlist[1])
		
		#dlist.append(self.ptcl_data[self.current_particle].copy())		# same as 1 and 2 above, but with a mask
		#tmp=dlist[0].process("threshold.notzero")
		#dlist[4].mult(tmp)
		#dlist[4].process_inplace("filter.matchto",{"to":dlist[0]})
		#dlist[4].mult(tmp)
		#dlist[4].process_inplace("normalize.toimage",{"to":dlist[0]})
		#dlist.append(dlist[3].copy())
		#dlist[5].sub(dlist[0])
		
		self.mx_display.set_data(dlist)
		

		if update: self.mx_display.updateGL()
			
	def on_mx_display_closed(self):
		self.mx_display = None
		
	def get_inspector(self):
		if not self.inspector : 
			self.inspector=EMSimmxXplorInspector(self)
		return self.inspector
	
	def ptcl_selected(self,event,lc):
		"""slot for image selection events from image mx"""
		self.set_ptcl_idx(lc[0])
	
	def set_alignment(self,align,aligncmp,refine,refinecmp):
		"""sets alignment algorithms and recomputes"""
		self.align = str(align)
		self.aligncmp = str(aligncmp)
		self.refine = str(refine)
		self.refinecmp = str(refinecmp)

		self.update_align()



	def set_ptcl_idx(self,idx):
		"""Select the index of the current particle to use for comparisons"""
		if self.current_particle != idx:
			self.current_particle = idx
			self.update_align()

	def update_align(self):
		if self.current_particle<0 : return
		ptcl=self.ptcl_data[self.current_particle]
		
		progress = QtGui.QProgressDialog("Computing alignments", "Abort", 0, len(self.proj_data),None)
		progress.show()
		# redetermines particle alignments
		# then we can quickly compute a series of different similarity values
		aopt=parsemodopt(self.align)
		acmp=parsemodopt(self.aligncmp)
		ropt=parsemodopt(self.refine)
		rcmp=parsemodopt(self.refinecmp)
		for i,p in enumerate(self.proj_data):
			try:
				ali=p.align(aopt[0],ptcl,aopt[1],acmp[0],acmp[1])
				if self.refine!="" :
					ropt[1]["xform.align2d"]=ali["xform.align2d"]
					ali=p.align(ropt[0],ptcl,ropt[1],rcmp[0],rcmp[1])
			except:
				print traceback.print_exc()
				QtGui.QMessageBox.warning(None,"Error","Problem with alignment parameters")
				progress.close()
				return
			p["ptcl.align2d"]=ali["xform.align2d"]
			progress.setValue(i)
			QtCore.QCoreApplication.instance().processEvents()
		
		progress.close()
		self.update_cmp()
#		self.update_display(True)
	
	def set_cmp(self,cmpstring):
		"""Select the comparator. Passed as a standard name:attr=value:attr=value string"""
		self.simcmp=str(cmpstring)
		self.update_cmp()
		
	def update_cmp(self):
		cmpopt=parsemodopt(self.simcmp)
		
		progress = QtGui.QProgressDialog("Computing similarities", "Abort", 0, len(self.proj_data),None)
		progress.show()
		ptcl=self.ptcl_data[self.current_particle]
		for i,p in enumerate(self.proj_data):
			ali=p.copy()
			ali.transform(p["ptcl.align2d"])
			try : p["cmp"]=-ptcl.cmp(cmpopt[0],ali,cmpopt[1])
			except:
				print traceback.print_exc()
				QtGui.QMessageBox.warning(None,"Error","Invalid similarity metric string, or other comparison error")
				progress.close()
				return
			progress.setValue(i)
			QtGui.qApp.processEvents()
			
		progress.close()
		self.set_emdata_list_as_data(self.proj_data,"cmp")
#		self.regen_dl(True)
		EM3DSymModel.render(self)