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 = EMImage2DWidget() # self.mx_display = EMImageMXWidget() 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 = EMPlot2DWidget() # 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 closeEvent(self,event): if self.inspector !=None: self.inspector.close() if self.proj_class_viewer !=None: self.proj_class_viewer.close() if self.proj_class_single !=None: self.proj_class_single.close() if self.particle_viewer != None: self.particle_viewer.close() get_application().close_specific(self) self.emit(QtCore.SIGNAL("module_closed")) # this signal is
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 run_form(self): from emform import EMTableFormWidget self.form = EMTableFormWidget(self.get_params()) self.form.resize(*self.preferred_size) self.form.setWindowTitle(self.window_title) get_application().show_specific(self.form) from PyQt4 import QtCore QtCore.QObject.connect(self.form,QtCore.SIGNAL("emform_ok"),self.on_form_ok) QtCore.QObject.connect(self.form,QtCore.SIGNAL("emform_cancel"),self.on_form_cancel) QtCore.QObject.connect(self.form,QtCore.SIGNAL("emform_close"),self.on_form_close)
def run_form(self): from emform import EMTableFormWidget self.form = EMTableFormWidget(self.get_params()) self.form.resize(*self.preferred_size) self.form.setWindowTitle(self.window_title) get_application().show_specific(self.form) from PyQt4 import QtCore QtCore.QObject.connect(self.form, QtCore.SIGNAL("emform_ok"), self.on_form_ok) QtCore.QObject.connect(self.form, QtCore.SIGNAL("emform_cancel"), self.on_form_cancel) QtCore.QObject.connect(self.form, QtCore.SIGNAL("emform_close"), self.on_form_close)
def au_selected(self,refine_dir,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 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)
def __init__(self): QtGui.QWidget.__init__(self) self.pdb_model = None # will eventually be a EMPDBModel self.iso_model = None # will eventually be a EMIsosurfaceModel self.viewer_window = EMImage3DWidget() self.__init_gui() self.validate_button.clicked.connect(self.run_validate) self.pdb_browse_button.clicked.connect(self.browse_pdb) self.pdb_line_edit.textChanged.connect(self.update_pdb_file) self.volume_browse_button.clicked.connect(self.browse_iso) self.volume_line_edit.textChanged.connect(self.update_iso_file) get_application().attach_child(self)
def on_em_validate_requested( self, mrc_file, pdb_file, trans, iso_thresh ): #if signal given to validate, creates emplot3d and displays graph vals = {} rotList = [] data = [] initPoint = [] try: #block user from view transforms from files that don't exist f = open(pdb_file) f.close() except IOError: print( "Sorry, this pdb is only in temporary memory. Please write the transform to the hard drive to validate." ) return print(" ") print(" ") print( "This process can take a few minutes depending on the number of transformations requested" ) vals, rotList, b, data, initPoint = self.fh_stat.gen_data( mrc_file, pdb_file, trans, iso_thresh) if self.plot3d: get_application().close_specific(self.plot3d) self.plot3d = None if self.plot3d == None: #creates the emplot3d module after the data has been generated by fh_stat self.__init_plot3d() print("Note: The original probe is displayed by a cube") print(" ") get_application().show() self.plot3d.plot_model.set_Vals(vals) self.plot3d.plot_model.set_Rotations(rotList) self.plot3d.plot_model.set_Probe(b) self.plot3d.plot_model.set_data(data, "Results for Fit Validation") self.plot3d.plot_model.set_data( initPoint, "Original Probe", shape="Cube") #note: original probe is displayed with a cube self.plot2d(vals["score_1"], vals["score_2"], vals["score_3"], rotList)
def __regenerate_rotor(self): for widget in self.rotor.get_widgets(): get_application().deregister_qt_emitter(widget.get_drawable().get_drawable()) self.rotor.clear_widgets() # self.parent.updateGL() # i can't figure out why I have to do this (when this function is called from set_mxs num_per_view = self.mx_rows*self.mx_cols for idx in range(self.start_mx,self.start_mx+self.visible_mxs): n = idx panel = n if panel != 0: panel %= self.get_num_panels() start_idx = panel*num_per_view image_offset = start_idx if image_offset != 0: image_offset %= self.emdata_list_cache.get_max_idx() #print idx,panel,image_offset d = [] if image_offset > (self.emdata_list_cache.get_max_idx()-num_per_view): num_visible = self.emdata_list_cache.get_max_idx() - image_offset num_none = num_per_view - num_visible #print num_visible,num_none for i in range(start_idx,start_idx+num_visible): d.append(self.emdata_list_cache[i]) for i in range(num_none): d.append(None) else: for i in range(start_idx,start_idx+num_per_view): d.append(self.emdata_list_cache[i]) e = EM2DGLView(self,d) e.get_drawable().set_app(get_application()) get_application().register_qt_emitter(e.get_drawable(),get_application().get_qt_emitter(self)) x = EM2DGLWindow(self,e) x.decoration.draw_x_enabled = False x.decoration.color_flag = "black" self.rotor.add_widget(x) w = e.get_drawable() w.set_use_display_list(True) # saves HEAPS of time, makes interaction much smoother w.set_reroute_delete_target(self) w.set_draw_background(True) w.set_mouse_mode(self.mmode) w.set_display_values(self.vals_to_display,False) w.set_img_num_offset(image_offset) w.set_max_idx(self.emdata_list_cache.get_max_idx()) e = self.rotor[0] w = e.get_drawable().get_drawable() self.minden = w.get_density_min() self.maxden = w.get_density_max() self.hist = w.get_hist() self.mindeng = self.minden self.maxdeng = self.maxden self.gamma = w.get_gamma() self.update_min_max_gamma(False) self.__refresh_rotor_size()
def on_em_validate_requested(self, mrc_file, pdb_file, trans, iso_thresh): #if signal given to validate, creates emplot3d and displays graph vals = {} rotList = [] data = [] initPoint = [] try: #block user from view transforms from files that don't exist f = open(pdb_file) f.close() except IOError: print "Sorry, this pdb is only in temporary memory. Please write the transform to the hard drive to validate." return print " " print " " print "This process can take a few minutes depending on the number of transformations requested" vals, rotList, b, data, initPoint = self.fh_stat.gen_data(mrc_file, pdb_file, trans, iso_thresh) if self.plot3d: get_application().close_specific(self.plot3d) self.plot3d = None if self.plot3d == None: #creates the emplot3d module after the data has been generated by fh_stat self.__init_plot3d() print "Note: The original probe is displayed by a cube" print " " get_application().show() self.plot3d.plot_model.set_Vals(vals) self.plot3d.plot_model.set_Rotations(rotList) self.plot3d.plot_model.set_Probe(b) self.plot3d.plot_model.set_data(data,"Results for Fit Validation") self.plot3d.plot_model.set_data(initPoint, "Original Probe",shape="Cube") #note: original probe is displayed with a cube self.plot2d(vals["score_1"], vals["score_2"], vals["score_3"], rotList)
def 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 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" ) QtCore.QObject.connect(self.particle_viewer,QtCore.SIGNAL("module_closed"),self.on_particle_mx_view_closed) QtCore.QObject.connect(self.particle_viewer,QtCore.SIGNAL("mx_image_selected"), 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 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()
def start(self): #program starts here, inits the empdbvaltool module if self.em_val == None: self.__init_em_val() get_application().show()
def au_point_selected(self,i,event=None): if i == None: if event != None and event.modifiers()&Qt.ShiftModifier: if self.special_euler != None: self.special_euler = None if not self.init_lock:self.regen_dl() return # self.arc_anim_points = None self.projection = None if self.euler_data: # db = db_open_dict(self.average_file) # a = db.get(i) # print a["nx"] # print self.average_file,i # self.average = EMData(self.average_file,i) # self.average["nx"] self.average = self.euler_data[i]# self.projection = EMData(self.projection_file,self.average.get_attr("projection_image_idx")) self.average.process_inplace("normalize.toimage",{"to":self.projection}) try: self.class_idx = self.average.get_attr("projection_image_idx") print "%d (%d)"%(self.class_idx,self.average["ptcl_repr"]) except: self.class_idx = -1 else: return #if self.projection == None and self.average == None: return first = False if self.proj_class_viewer == None: first = True self.proj_class_viewer = EMImageMXWidget(data=None,application=get_application()) # self.proj_class_viewer = EMImage2DWidget(image=None,application=get_application()) QtCore.QObject.connect(self.proj_class_viewer,QtCore.SIGNAL("module_closed"),self.on_mx_view_closed) # self.proj_class_viewer.set_mouse_mode("App" ) QtCore.QObject.connect(self.proj_class_viewer,QtCore.SIGNAL("mx_image_selected"), self.mx_image_selected) get_application().show_specific(self.proj_class_viewer) self.proj_class_single = EMImage2DWidget(image=None,application=get_application()) QtCore.QObject.connect(self.proj_class_single,QtCore.SIGNAL("module_closed"),self.on_mx_view_closed) # QtCore.QObject.connect(self.proj_class_single,QtCore.SIGNAL("mx_image_selected"), self.mx_image_selected) get_application().show_specific(self.proj_class_single) disp = [] if self.projection != None: disp.append(self.projection) if self.average != None and self.projection!=None: # ok, this really should be put into its own processor #dataf = self.projection.do_fft() #apix=self.projection["apix_x"] #curve = dataf.calc_radial_dist(dataf["ny"], 0, 0.5,True) #curve=[i/(dataf["nx"]*dataf["ny"])**2 for i in curve] #xcurve=[i/(apix*2.0*dataf["ny"]) for i in range(len(curve))] #xyd=XYData() #xyd.set_xy_list(xcurve,curve) #filt=self.average.process("filter.setstrucfac",{"apix":apix,"strucfac":xyd}) #filt.process_inplace("normalize.toimage",{"to":self.average}) self.projection["apix_x"]=self.average["apix_x"] self.projection["apix_y"]=self.average["apix_y"] self.projection["apix_z"]=self.average["apix_z"] filt=self.projection.process("threshold.notzero") filt.mult(self.average) filt.process_inplace("filter.matchto",{"to":self.projection}) disp.append(filt) if self.average!=None: disp.append(self.average) self.proj_class_viewer.set_data(disp) self.proj_class_single.set_data(disp) self.proj_class_viewer.updateGL() self.proj_class_single.updateGL() if self.particle_viewer != None: self.mx_image_selected(None,None) if first: self.proj_class_viewer.optimally_resize() if i != self.special_euler: self.special_euler = i self.force_update = True if not self.init_lock: self.updateGL()
def 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 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" ) QtCore.QObject.connect(self.particle_viewer,QtCore.SIGNAL("module_closed"),self.on_particle_mx_view_closed) QtCore.QObject.connect(self.particle_viewer,QtCore.SIGNAL("mx_image_selected"), 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 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()
def on_view_transform_requested(self, new_pdb_file): if self.em_val == None: self.__init_em_val() get_application().show() self.em_val.set_pdb_file(str(new_pdb_file)) os.remove(str(new_pdb_file))
def au_point_selected(self,i,event=None): if self.readfrom: return if i == None: if event != None and event.modifiers()&Qt.ShiftModifier: if self.special_euler != None: self.special_euler = None if not self.init_lock:self.regen_dl() return # self.arc_anim_points = None self.projection = None if self.euler_data: # db = db_open_dict(self.average_file) # a = db.get(i) # print a["nx"] # print self.average_file,i # self.average = EMData(self.average_file,i) # self.average["nx"] self.average = self.euler_data[i]# self.projection = EMData(self.projection_file,self.average.get_attr("projection_image_idx")) self.average.process_inplace("normalize.toimage",{"to":self.projection}) try: self.class_idx = self.average.get_attr("projection_image_idx") print("%d (%d)"%(self.class_idx,self.average["ptcl_repr"])) except: self.class_idx = -1 else: return #if self.projection == None and self.average == None: return first = False if self.proj_class_viewer == None: first = True self.proj_class_viewer = EMImageMXWidget(data=None,application=get_application()) # self.proj_class_viewer = EMImage2DWidget(image=None,application=get_application()) QtCore.QObject.connect(self.proj_class_viewer,QtCore.SIGNAL("module_closed"),self.on_mx_view_closed) # self.proj_class_viewer.set_mouse_mode("App" ) QtCore.QObject.connect(self.proj_class_viewer,QtCore.SIGNAL("mx_image_selected"), self.mx_image_selected) get_application().show_specific(self.proj_class_viewer) self.proj_class_single = EMImage2DWidget(image=None,application=get_application()) QtCore.QObject.connect(self.proj_class_single,QtCore.SIGNAL("module_closed"),self.on_mx_view_closed) # QtCore.QObject.connect(self.proj_class_single,QtCore.SIGNAL("mx_image_selected"), self.mx_image_selected) get_application().show_specific(self.proj_class_single) disp = [] if self.projection != None: disp.append(self.projection) if self.average != None and self.projection!=None: # ok, this really should be put into its own processor #dataf = self.projection.do_fft() #apix=self.projection["apix_x"] #curve = dataf.calc_radial_dist(dataf["ny"], 0, 0.5,True) #curve=[i/(dataf["nx"]*dataf["ny"])**2 for i in curve] #xcurve=[i/(apix*2.0*dataf["ny"]) for i in range(len(curve))] #xyd=XYData() #xyd.set_xy_list(xcurve,curve) #filt=self.average.process("filter.setstrucfac",{"apix":apix,"strucfac":xyd}) #filt.process_inplace("normalize.toimage",{"to":self.average}) self.projection["apix_x"]=self.average["apix_x"] self.projection["apix_y"]=self.average["apix_y"] self.projection["apix_z"]=self.average["apix_z"] filt=self.projection.process("threshold.notzero") filt.mult(self.average) filt.process_inplace("filter.matchto",{"to":self.projection}) disp.append(filt) if self.average!=None: disp.append(self.average) self.proj_class_viewer.set_data(disp) self.proj_class_single.set_data(disp) self.proj_class_viewer.updateGL() self.proj_class_single.updateGL() if self.particle_viewer != None: self.mx_image_selected(None,None) if first: self.proj_class_viewer.optimally_resize() if i != self.special_euler: self.special_euler = i self.force_update = True if not self.init_lock: self.updateGL()
def browse_iso(self): em_selector = EMSelectorDialog() file_path = em_selector.exec_() get_application().detach_child(em_selector) self.volume_line_edit.setText(file_path)
def __del__(self): for widget in self.rotor.get_widgets(): get_application().deregister_qt_emitter(widget.get_drawable().get_drawable())