From 1ee52fc32925093e5efc4ad06e01ffb2e18a654c Mon Sep 17 00:00:00 2001 From: Edanderson5 Date: Mon, 23 Sep 2024 18:14:06 -0500 Subject: [PATCH 1/6] ouput_shape fix --- programs/e2tomoseg_convnet.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/programs/e2tomoseg_convnet.py b/programs/e2tomoseg_convnet.py index b5988429ed..6f679c4fa2 100755 --- a/programs/e2tomoseg_convnet.py +++ b/programs/e2tomoseg_convnet.py @@ -337,7 +337,7 @@ def min_act(x): self.model=tf.keras.Sequential(layers) self.imgsz=imgsz - self.outsz=self.model.get_layer(index=-1).output_shape[1] + self.outsz=self.model.get_layer(index=-1).output.shape[1] self.batchsize=batchsz self.kernels=kernels self.meanout=meanout From 58f8b1a93d4cbda943c5a3980fb702164d83ccdf Mon Sep 17 00:00:00 2001 From: landang14 Date: Wed, 25 Sep 2024 12:16:06 -0500 Subject: [PATCH 2/6] minor fix for template matching --- programs/e2tomo_annotate.py | 355 +++++++++++++++--------------------- 1 file changed, 150 insertions(+), 205 deletions(-) diff --git a/programs/e2tomo_annotate.py b/programs/e2tomo_annotate.py index a8750d86d9..0a4f87d8ba 100755 --- a/programs/e2tomo_annotate.py +++ b/programs/e2tomo_annotate.py @@ -2839,11 +2839,6 @@ def predict_unet(self,test_data, test_labels,test_label_outfile,weights_in,pred_ print('Predicting masks on test data...') print('-'*30) imgs_label_test = model.predict(test_data, verbose=1) - #print(model.evaluate(test_data,test_labels)) - # np.save(test_label_outfile, imgs_label_test) - # print('-' * 30) - # print('Saving predicted masks to files...') - # print('-' * 30) return imgs_label_test @@ -4148,6 +4143,9 @@ def __init__(self,target) : #self.draw_peaks_bt = QtWidgets.QPushButton("Draw Peaks") self.apply_mw = QtWidgets.QCheckBox("Apply MW on Tempt") self.apply_mw.setChecked(False) + self.local_norm_cb = QtWidgets.QCheckBox("Local normalization") + self.local_norm_cb.setChecked(True) + #self.apply_mw = QtWidgets.QCheckBox("Apply MW on Tempt") self.tmplt_npeaks_le = QtWidgets.QLineEdit() @@ -4177,17 +4175,13 @@ def __init__(self,target) : templ_gbl.addWidget(self.tmplt_nshrink_le,3,1,1,1) templ_gbl.addWidget(QtWidgets.QLabel("threads"),3,2,1,1) templ_gbl.addWidget(self.tmplt_nthrds_le,3,3,1,1) - - #templ_gbl.addWidget(self.create_template_bt,1,0,1,2) - #templ_gbl.addWidget(self.apply_mw,4,0,1,2) - #templ_gbl.addWidget(self.show_initxf_bt,4,0,1,2) templ_gbl.addWidget(QtWidgets.QLabel("npeaks"),4,2,1,1) templ_gbl.addWidget(self.tmplt_npeaks_le,4,3,1,1) #templ_gbl.addWidget(QtWidgets.QLabel("ccc thr"),4,2,1,1) + templ_gbl.addWidget(self.local_norm_cb,4,0,1,1) templ_gbl.addWidget(self.tmplt_cccthr_vs,5,0,1,4) - #templ_gbl.addWidget(QtWidgets.QLabel("dist thr"),4,2,1,1) - #templ_gbl.addWidget(self.tmplt_dthr_le,4,3,1,1) - #templ_gbl.addWidget(self.tmplt_minvol_vs,5,0,1,4) + + templ_gbl.addWidget(self.calc_ccm_bt,2,4,1,1) templ_gbl.addWidget(self.show_ccm_bt,3,4,1,1) @@ -4214,12 +4208,8 @@ def __init__(self,target) : # self.calc_ccm_bt.clicked[bool].connect(self.calc_ccm) self.calc_ccm_bt.clicked[bool].connect(self.calc_ccm_test) self.show_ccm_bt.clicked[bool].connect(self.show_ccm) - #self.find_peaks_bt.clicked[bool].connect(self.find_peaks_amp) self.find_peaks_bt.clicked[bool].connect(self.find_peaks_to_show) - #self.draw_peaks_bt.clicked[bool].connect(self.draw_peaks_on_tomo) - self.show_peaks_bt.clicked[bool].connect(self.show_peaks) - #self.do_local_search_bt.clicked[bool].connect(self.do_local_search_thrds) self.do_local_search_bt.clicked[bool].connect(self.do_local_search_test) self.test_function_bt.clicked[bool].connect(self.test_search_function) @@ -4334,6 +4324,7 @@ def do_match(jsd, xfs): self.xfs = [] def compute(self,jsd,targetf,template,phi,alt,n): + print("test compute") nx,ny,nz=targetf["nx"]-2,targetf["ny"],targetf["nz"] clp=template["nx"] trot=template.process("xform",{"transform":Transform({"type":"eman","phi":phi,"alt":alt})}).get_clip(Region((clp-nx)//2,(clp-ny)//2,(clp-nz)//2,nx,ny,nz)) @@ -4345,6 +4336,7 @@ def compute(self,jsd,targetf,template,phi,alt,n): # standard CCF with local normalization def compute_local(self,jsd,targetf,template,targetsqf,templatemask,phi,alt,n): + print("test compute local") nx,ny,nz=targetf["nx"]-2,targetf["ny"],targetf["nz"] clp=template["nx"] @@ -4387,46 +4379,25 @@ def calc_ccm_test(self): print("Running test calc_ccm") try: sym=parsesym(self.tmplt_sym_le.text()) #c1 - #dt=int(self.tmplt_delta_le.text())#25-45 - ang_step=int(self.tmplt_delta_le.text()) + dt=int(self.tmplt_delta_le.text())#25-45 target = self.target.get_data().copy() template = EMData(self.tmplt_le.text()) shrink = int(self.tmplt_nshrink_le.text()) + nthreads=int(self.tmplt_nthrds_le.text()) + except: - print("Specify template to calc cross correlation.") + print("Specify parameters to calc cross correlation.") return - #oris=sym.gen_orientations("eman",{"delta":dt, "phitoo":dt,"inc_mirror":1}) #prefer fraction of 360 #minimum rotation : number of degree to rotate for 1 pixel shift at nyquist - 4.4 in this case of microtubule with boxsz=25 - - if shrink > 1: target.process_inplace("math.fft.resample",{'n':shrink}) - # mbin=tomo["apix_x"]/ref["apix_x"] - # print("Will shrink reference by {:.1f} to match apix of tomogram".format(mbin)) - # ref.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.4}) #do it first then math.fft.resample #get rid of lowres peak of ice gradient - # ref.process_inplace("math.fft.resample",{'n':mbin}) - # ref.process_inplace("filter.highpass.gauss",{"cutoff_pixels":4}) - # ref.process_inplace('normalize.edgemean') - # ref.mult(-1) - #boxsz=ref["nx"]//2 - - #self.test_do_search(tomo, tempt,tasks[0][:20]) - nthreads=int(self.tmplt_nthrds_le.text()) - #print("test_search_function_begin") - - #target=EMData("lamella_3_1_03262024_crop__bin2.hdf",0) - #target = self.target.get_data() target.mult(-1.0) nx,ny,nz=target["nx"],target["ny"],target["nz"] targetf=target.do_fft() targetsq=target.process("math.squared") targetsqf=targetsq.do_fft() - # template=EMData("long_tmplt.hdf",0) - # template=EMData("long_tmplt_fromtomo.hdf",0)emd_26214_actin.hdf - #template=EMData(self.tmplt_le.text()) - templatesca=template.process("math.fft.resample",{"n":target["apix_x"]/template["apix_x"]}) nxt1=templatesca["nx"] templatemask=templatesca.process("mask.auto3d",{"nmaxseed":8,"nshells":2,"radius":nxt1//10,"return_mask":True,"sigma":1.5}) @@ -4435,14 +4406,15 @@ def calc_ccm_test(self): orts=[] jsd=queue.Queue(0) - # these start as arguments, but get replaced with actual threads thrds=[] i=0 - for alt in range(0,90,ang_step): - for phi in range(0,360,ang_step): - # thrds.append((jsd,targetf,templatesca,phi,alt,i)) - thrds.append((jsd,targetf,templatesca,targetsqf,templatemask,phi,alt,i)) + for alt in range(0,90,dt): + for phi in range(0,360,dt): + if self.local_norm_cb.isChecked(): + thrds.append((jsd,targetf,templatesca,targetsqf,templatemask,phi,alt,i)) + else: + thrds.append((jsd,targetf,templatesca,phi,alt,i)) i+=1 thrtolaunch=0 @@ -4451,7 +4423,10 @@ def calc_ccm_test(self): while (threading.active_count()>=nthreads) : time.sleep(0.1) print("\r Starting thread {}/{} ".format(thrtolaunch,len(thrds)), end=' ',flush=True) # thrds[thrtolaunch]=threading.Thread(target=compute,args=thrds[thrtolaunch]) # replace args - thrds[thrtolaunch]=threading.Thread(target=self.compute_local,args=thrds[thrtolaunch]) # replace args + if self.local_norm_cb.isChecked(): + thrds[thrtolaunch]=threading.Thread(target=self.compute_local,args=thrds[thrtolaunch]) # replace args + else: + thrds[thrtolaunch]=threading.Thread(target=self.compute,args=thrds[thrtolaunch]) # replace args thrds[thrtolaunch].start() thrtolaunch+=1 else: time.sleep(0.1) @@ -4468,8 +4443,6 @@ def calc_ccm_test(self): peaks=avg.finish() #global base - #base="test_long_template" - #peaks.write_image(f"{base}.hdf:-1",0) peaks.write_image(self.ccc_file,0) owner.write_image(self.owner_id_file,0) #owner.write_image(f"{base}_own.hdf:-1",0) @@ -4485,6 +4458,134 @@ def calc_ccm_test(self): self.pts = [] self.xfs = [] + def find_peaks_amp_test(self,npks=200,ccc_file="",own_file="",orts_file=""): + n_peaks= npks + nbin=int(self.tmplt_nshrink_le.text()) + ccc_hdr=EMData(ccc_file, 0,True) + cx,cy,cz = ccc_hdr.get_sizes() + + #rx = template.get_sizes()[0] + #bsz = rx + #ccc = EMData(ccc_file).process("mask.zeroedge3d",{"x0":bsz//2,"x1":bsz//2,"y0":bsz//2,"y1":bsz//2,"z0":bsz//2,"z1":bsz//2}) + ccc = EMData(ccc_file) + print("Shape",ccc.get_sizes()) + + #ccc.process_inplace("filter.lowpass.gauss",{"cutoff_abs":0.1}) + #print("Set border of ccc matrix to zero to avoid peaks too close to the border") + mean=float(ccc.get_attr("mean")) + sig=float(ccc.get_attr("sigma")) + #ccc.process_inplace("threshold.belowtozero",{"minval":mean+sig}) + ccc.process_inplace("mask.onlypeaks",{"npeaks":2}) #before threshold + ccc.process_inplace("threshold.belowtozero",{"minval":mean+sig}) + + ccc_fac = float(self.tmplt_cccthr_vs.value) + peaks = ccc.calc_highest_locations(mean+ccc_fac*sig) + peaks.sort(key=lambda peak: -peak.value) + pts = [(nbin*peak.x,nbin*peak.y,nbin*peak.z) for peak in peaks] + orts_f=open(orts_file,"r") + oris = [] + for ort in orts_f.readlines(): + angles = ort.split("\t") + xf = Transform({'az':0,'alt':int(angles[2]),'phi':int(angles[1]),'tx':0.00,'ty':0.00,'tz':0.00,'mirror':0,'scale':1.0000,'type':'eman'}) + oris.append(xf) + + initxf = EMData(own_file) + xfs = [oris[int(initxf[(peak.x,peak.y,peak.z)])] for peak in peaks] + if len(pts) > n_peaks: + print("Find total {} peaks. Highest score {} peaks at {}".format(len(pts),n_peaks,pts[:n_peaks])) + self.pts = pts[:n_peaks] + self.xfs = xfs[:n_peaks] + else: + print("Find {} peaks at {}".format(len(pts),pts)) + self.pts = pts + self.xfs = xfs + + #Do local search at putative locations + def do_search_test(self,tomo,tempt,jsd, px_l): + for pt_xf in px_l: + p = pt_xf[0] + initxf = pt_xf[1] + x,y,z= (int(i) for i in p) + bs = tempt["nx"] + subvol = tomo.get_clip(Region(x-bs//2,y-bs//2,z-bs//2,bs,bs,bs)) + #nbest = tempt.xform_align_nbest('rotate_translate_3d', subvol, {'sym':'c1'}, 2, 'ccc.tomo',{}) + #initxfs = [n["xform.align3d"] for n in nbest[1:]] + # tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"initxform":[nbest[0]["xform.align3d"],nbest[1]["xform.align3d"],nbest[2]["xform.align3d"]],"sym":"c1"},'ccc.tomo') + tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"initxform":[initxf],"sym":"c1"},'ccc.tomo') + #tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"sym":"c1"},'ccc.tomo') + cf = subvol.calc_ccf(tempt_a) + cf_score = np.max(cf.numpy()) + jsd.put((p,tempt_a["xform.align3d"],cf_score)) + + + def do_local_search_test(self): + n_peaks = int(self.tmplt_npeaks_le.text()) + self.find_peaks_amp_test(npks=n_peaks*5,ccc_file=self.ccc_file,own_file=self.owner_id_file,orts_file=self.orts_file) + + nthrds = int(self.tmplt_nthrds_le.text()) + tomo = self.target.get_data().copy() + tempt = EMData(self.tmplt_le.text()) + mbin=tomo["apix_x"]/tempt["apix_x"] + + print("Will shrink reference by {:.1f} to match apix of tomogram for local search".format(mbin)) + tempt.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.4}) #do it first then math.fft.resample #get rid of lowres peak of ice gradient + tempt.process_inplace("math.fft.resample",{'n':mbin}) + #tempt.process_inplace("filter.highpass.gauss",{"cutoff_pixels":4}) #might still be useful, not this aggressive, 1 or 2 first + tempt.process_inplace('normalize.edgemean') + tempt.mult(-1) + good_szs=[good_size(tempt["nx"]),good_size(tempt["ny"]),good_size(tempt["nz"])] + tempt.clip_inplace(Region(0,0,0,good_szs[0],good_szs[1],good_szs[2])) + + #boxsz=tempt["nx"]//2 + #tomo.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.4}) + # tomo.process_inplace("filter.highpass.gauss",{"cutoff_pixels":boxsz}) #different fixed value + tomo.process_inplace('normalize.edgemean') + + pts_xfs_l = list(zip(self.pts,self.xfs)) + start = time.time() + tasks=[pts_xfs_l[i::nthrds] for i in range(nthrds)] + + #print(tasks) + jsd=queue.Queue(0) + thrds=[threading.Thread(target=self.do_search_test,args=(tomo, tempt, jsd, px_l)) for px_l in tasks] + + thrtolaunch=0 + tsleep=threading.active_count() + + ndone=0 + for t in thrds: + t.start() + p_xf_l = [] + print("Start local searching at {} location".format(len(self.pts))) + while threading.active_count()>tsleep or not jsd.empty(): + while not jsd.empty(): + p,xf,cf=jsd.get() + p_xf_l.append((p,xf,cf)) + ndone+=1 + sys.stdout.write("\r{}/{} finished.".format(ndone, len(self.pts))) + sys.stdout.flush() + time.sleep(.5) + print("") + print("Finish in {}s".format(time.time()-start)) + p_xf_l.sort(key = lambda x: -x[2]) + try: + pt_cf_l = [] + for i in range(len(p_xf_l)): + pt = list(p_xf_l[i][0]) + pt.append(p_xf_l[i][2]) + pt_cf_l.append(pt) + from_numpy(np.array(pt_cf_l)).write_image("tmplt_match_local_pks.hdf") + print("All peaks saved to tmplt_match_local_pks.hdf") + except Exception as e: + print(e) + pass + p_xf_l=p_xf_l[:n_peaks] + self.pts = [p_xf[0] for p_xf in p_xf_l] + self.xfs = [p_xf[1] for p_xf in p_xf_l] + cfs = [p_xf[2] for p_xf in p_xf_l] + self.cfs = [cf/max(cfs) for cf in cfs] + + #Simulated missing wedge effect on template def determine_cut_off_thres(self,amplitude,preserve_ratio=0.95,n_pts=101): @@ -4580,9 +4681,6 @@ def find_peaks_to_show(self): #Find local max from CCM and initial xf associate with those peaks def find_peaks_amp(self,npks=100): try: - # if npks == -1: - #n_peaks = int(self.tmplt_npeaks_le.text()) - # else: n_peaks = npks nbin = int(self.tmplt_nshrink_le.text()) #ccc_fac = float(self.tmplt_cccthr_vs.value) @@ -4625,75 +4723,6 @@ def find_peaks_amp(self,npks=100): self.pts = pts self.xfs = xfs - def find_peaks_amp_test(self,npks=200,ccc_file="",own_file="",orts_file=""): - n_peaks= npks - nbin=int(self.tmplt_nshrink_le.text()) - ccc_hdr=EMData(ccc_file, 0,True) - cx,cy,cz = ccc_hdr.get_sizes() - - #rx = template.get_sizes()[0] - #bsz = rx - #ccc = EMData(ccc_file).process("mask.zeroedge3d",{"x0":bsz//2,"x1":bsz//2,"y0":bsz//2,"y1":bsz//2,"z0":bsz//2,"z1":bsz//2}) - ccc = EMData(ccc_file) - ccc.process_inplace("filter.lowpass.gauss",{"cutoff_abs":0.1}) - #ccc.process_inplace("filter.lowpass.gauss",{"cutoff_abs":0.1}) - #print("Set border of ccc matrix to zero to avoid peaks too close to the border") - mean=float(ccc.get_attr("mean")) - sig=float(ccc.get_attr("sigma")) - #ccc.process_inplace("threshold.belowtozero",{"minval":mean+sig}) - ccc.process_inplace("mask.onlypeaks",{"npeaks":2}) #before threshold - ccc.process_inplace("threshold.belowtozero",{"minval":mean+sig}) - - ccc_fac = float(self.tmplt_cccthr_vs.value) - #ccc_fac=1 - peaks = ccc.calc_highest_locations(mean+ccc_fac*sig) - peaks.sort(key=lambda peak: -peak.value) - pts = [(nbin*peak.x,nbin*peak.y,nbin*peak.z) for peak in peaks] - orts_f=open(orts_file,"r") - oris = [] - for ort in orts_f.readlines(): - angles = ort.split("\t") - xf = Transform({'az':0,'alt':int(angles[2]),'phi':int(angles[1]),'tx':0.00,'ty':0.00,'tz':0.00,'mirror':0,'scale':1.0000,'type':'eman'}) - oris.append(xf) - - initxf = EMData(own_file) - xfs = [oris[int(initxf[(peak.x,peak.y,peak.z)])] for peak in peaks] - if len(pts) > n_peaks: - #print("Find total {} peaks. Highest score {} peaks at {}".format(len(pts),n_peaks,pts[:n_peaks])) - print("Find total {} peaks. Highest score {} peaks at {}".format(len(pts),n_peaks,pts[:n_peaks])) - self.pts = pts[:n_peaks] - self.xfs = xfs[:n_peaks] - - else: - print("Find {} peaks at {}".format(len(pts),pts)) - self.pts = pts - self.xfs = xfs - - def save_peaks(self,ccc,pts): - outfile = "tmplt_match_ccc_pks.hdf" - peak_holder_vol = ccc.copy_head() - #peak_holder_vol.to_zero() - peak_holder_vol.write_image(outfile) - vol = test_image_3d(4,(10,10,10)) - for i,loc in enumerate(pts): - x,y,z = [int(i) for i in loc] - bs = 10 - reg = Region(x-bs//2,y-bs//2,z-bs//2,bs,bs,bs) - try: - current_vol = self.target.get_annotation().get_clip(reg) - insert_vol=vol.process("math.max",{"with":current_vol}) - except: - insert_vol = vol - try: - insert_vol.write_image(outfile, 0, IMAGE_HDF, False, reg) - sys.stdout.write("\r{}/{} finished.".format(i, len(pts))) - sys.stdout.flush() - #print("Insert vol at location",x,y,z,"") - except: - print("Invalid region at location",x,y,z,".Skip.") - continue - - #Do local search at putative locations def do_search(self,tomo,tempt,jsd, px_l): for pt_xf in px_l: @@ -4703,93 +4732,12 @@ def do_search(self,tomo,tempt,jsd, px_l): x,y,z= (int(i) for i in p) bs = tempt["nx"] subvol = tomo.get_clip(Region(x-bs//2,y-bs//2,z-bs//2,bs,bs,bs)) - #nbest = tempt.xform_align_nbest('rotate_translate_3d', subvol, {'sym':'c1'}, 2, 'ccc.tomo',{}) - #initxfs = [n["xform.align3d"] for n in nbest[1:]] - #initxfs = [] - #initxfs.append(initxf) - # #tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"initxform":[nbest[0]["xform.align3d"],nbest[1]["xform.align3d"],nbest[2]["xform.align3d"]],"sym":"c1"},'ccc.tomo') tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"initxform":[initxf],"sym":"c1"},'ccc.tomo') - #tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"sym":"c1"},'ccc.tomo') - - # # #tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"sym":"c1"},'ccc.tomo') - # cf = subvol.calc_ccf(tempt_a) - # cf_score = np.max(cf.numpy()) - #tempt_a = tempt.process("xform",{"transform":n["xform.align3d"]}) cf = subvol.calc_ccf(tempt_a) cf_score = np.max(cf.numpy()) - # for n in nbest: - # tempt_a = tempt.process("xform",{"transform":n["xform.align3d"]}) - # cf = subvol.calc_ccf(tempt_a) - # cf_score = np.max(cf.numpy()) - # jsd.put((p,tempt_a["xform.align3d"],cf_score)) - #cf.process_inplace("normalize") - #print(p,"new xf", tempt_a["xform.align3d"]) jsd.put((p,tempt_a["xform.align3d"],cf_score)) - def do_local_search_test(self): - - n_peaks = int(self.tmplt_npeaks_le.text()) - self.find_peaks_amp_test(npks=n_peaks*5,ccc_file=self.ccc_file,own_file=self.owner_id_file,orts_file=self.orts_file) - - nthrds = int(self.tmplt_nthrds_le.text()) - tomo = self.target.get_data().copy() - tempt = EMData(self.tmplt_le.text()) - mbin=tomo["apix_x"]/tempt["apix_x"] - - print("Will shrink reference by {:.1f} to match apix of tomogram for local search".format(mbin)) - tempt.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.4}) #do it first then math.fft.resample #get rid of lowres peak of ice gradient - tempt.process_inplace("math.fft.resample",{'n':mbin}) - #tempt.process_inplace("filter.highpass.gauss",{"cutoff_pixels":4}) #might still be useful, not this aggressive, 1 or 2 first - tempt.process_inplace('normalize.edgemean') - tempt.mult(-1) - good_szs=[good_size(tempt["nx"]),good_size(tempt["ny"]),good_size(tempt["nz"])] - tempt.clip_inplace(Region(0,0,0,good_szs[0],good_szs[1],good_szs[2])) - - tomo.process_inplace('normalize.edgemean') - pts_xfs_l = list(zip(self.pts,self.xfs)) - start = time.time() - tasks=[pts_xfs_l[i::nthrds] for i in range(nthrds)] - - #print(tasks) - jsd=queue.Queue(0) - thrds=[threading.Thread(target=self.do_search,args=(tomo, tempt, jsd, px_l)) for px_l in tasks] - - thrtolaunch=0 - tsleep=threading.active_count() - - ndone=0 - for t in thrds: - t.start() - p_xf_l = [] - print("Start local searching at {} location".format(len(self.pts))) - while threading.active_count()>tsleep or not jsd.empty(): - while not jsd.empty(): - p,xf,cf=jsd.get() - p_xf_l.append((p,xf,cf)) - ndone+=1 - sys.stdout.write("\r{}/{} finished.".format(ndone, len(self.pts))) - sys.stdout.flush() - time.sleep(.5) - print("") - print("Finish in {}s".format(time.time()-start)) - p_xf_l.sort(key = lambda x: -x[2]) - try: - pt_cf_l = [] - for i in range(len(p_xf_l)): - pt = list(p_xf_l[i][0]) - pt.append(p_xf_l[i][2]) - pt_cf_l.append(pt) - from_numpy(np.array(pt_cf_l)).write_image("tmplt_match_local_pks.hdf") - print("All peaks saved to tmplt_match_local_pks.hdf") - except Exception as e: - print(e) - pass - p_xf_l=p_xf_l[:n_peaks] - self.pts = [p_xf[0] for p_xf in p_xf_l] - self.xfs = [p_xf[1] for p_xf in p_xf_l] - cfs = [p_xf[2] for p_xf in p_xf_l] - self.cfs = [cf/max(cfs) for cf in cfs] def do_local_search_thrds(self): @@ -4810,9 +4758,6 @@ def do_local_search_thrds(self): good_szs=[good_size(tempt["nx"]),good_size(tempt["ny"]),good_size(tempt["nz"])] tempt.clip_inplace(Region(0,0,0,good_szs[0],good_szs[1],good_szs[2])) - #boxsz=tempt["nx"]//2 - #tomo.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.4}) - # tomo.process_inplace("filter.highpass.gauss",{"cutoff_pixels":boxsz}) #different fixed value tomo.process_inplace('normalize.edgemean') #tomo.process_inplace('threshold.clampminmax.nsigma', {"nsigma":3}) #may not necessary From 029b91ef15a882bdfe6f49aa120ee27772cd8bb4 Mon Sep 17 00:00:00 2001 From: landang14 Date: Mon, 30 Sep 2024 12:48:58 -0500 Subject: [PATCH 3/6] current implementation of e3spt_template.py --- programs/e3spt_template.py | 408 +++++++++++++++++++++++++++++++++++++ 1 file changed, 408 insertions(+) create mode 100644 programs/e3spt_template.py diff --git a/programs/e3spt_template.py b/programs/e3spt_template.py new file mode 100644 index 0000000000..48d8cb86e4 --- /dev/null +++ b/programs/e3spt_template.py @@ -0,0 +1,408 @@ +#!/usr/bin/env python +# Author: Lan Dang, 03/17/2022 (dlan@bcm.edu) +from math import * +from EMAN2 import * +import queue +import time +import numpy as np + + +def main(): + usage="""a program to run template matching on a tomogram. + """ + parser = EMArgumentParser(usage=usage,version=EMANVERSION) + parser.add_argument("--tomos",type=str,help="tomogram(s) for template matching",default="") + parser.add_argument("--template",type=str,help="template",default="") + parser.add_argument("--nbin",type=int, help="nbin to downsample tomogram for coarse search. Default=1", default=1) + parser.add_argument("--nthreads",type=int, help="number of threads. Default=4", default=4) + + parser.add_argument("--dt",type=int, help="angular step for coarse search", default=45) + parser.add_argument("--local_norm",action="store_true", help="Coarse search with local normalization", default=False) + parser.add_argument("--ccc_fac",type=int, help="threshold to filter ccc: mean+ccc_fac*std. Default = 3", default=3) + parser.add_argument("--npks",type=int, help="number of peaks to locally search. Default = 200", default=200) + parser.add_argument("--insert_mask",type=str,help="mask to insert back for annotation ",default="") + parser.add_argument("--insert_density",type=str,help="density to reconstitute into volume with weights",default="") + parser.add_argument("--insert_thresh",type=float,help="threshold to binary insert mask before annotation ",default=0.5) + parser.add_argument("--ppid", type=int, help="Set the PID of the parent process, used for cross platform PPID",default=-1) + + + (options, args) = parser.parse_args() + logid=E2init(sys.argv,options.ppid) + + if len(options.tomos)==0 or len(options.template)==0: + print("ERROR: Must specify tomogram and template for template matching") + sys.exit(1) + + template=EMData(options.template) + for tomo in options.tomos.split(","): + target=EMData(tomo) + base_out="{}_{}".format(base_name(tomo),base_name(options.template)) + print(base_out) + calc_ccm(target,template,dt=options.dt,shrink=options.nbin,nthreads=options.nthreads,base_out=base_out,local_norm=options.local_norm) + do_local_search_test(target,template,options.npks,options.nbin,options.nthreads,options.ccc_fac,base_out) + if len(options.insert_mask) > 0: + try: + insert_im = EMData(options.insert_mask) + except: + print("ERROR: invalid mask file") + sys.exit(1) + #d = json.load(open(f"{base_out}_local_pks.json","r")) + js=js_open_dict(f"{base_out}_local_pks.json") + pts = js["pts"] + xfs = js["xfs"] + # pts = d["pts"] + # xfs = [] + # for xfm in d["xfs"]: + # xf = Transform() + # xf.set_matrix(xfm) + # xfs.append(xf) + vol_out = EMData(tomo,0,True) + outfile = f"{base_out}_tmplt_seg.hdf" + vol_out.write_image(outfile) + + insert_vol(vol_out,insert_im,pts,xfs,outfile) + #js.close() + if len(options.insert_density) > 0: + try: + insert_im = EMData(options.insert_density) + except: + print("ERROR: invalid mask file") + sys.exit(1) + #d = json.load(open(f"{base_out}_local_pks.json","r")) + js=js_open_dict(f"{base_out}_local_pks.json") + pts = js["pts"] + xfs = js["xfs"] + cfs = js["cfs"] + # pts = d["pts"] + # xfs = [] + # for xfm in d["xfs"]: + # xf = Transform() + # xf.set_matrix(xfm) + # xfs.append(xf) + vol_out = EMData(tomo,0,True) + outfile = f"{base_out}_tmplt_dens.hdf" + vol_out.write_image(outfile) + insert_vol(vol_out,insert_im,pts,xfs,outfile,cfs) + + +def compute_local(jsd,targetf,template,targetsqf,templatemask,phi,alt,n): + print("test compute local") + nx,ny,nz=targetf["nx"]-2,targetf["ny"],targetf["nz"] + clp=template["nx"] + + # rotate template, pad, fft + trot=template.process("xform",{"transform":Transform({"type":"eman","phi":phi,"alt":alt})}).get_clip(Region((clp-nx)//2,(clp-ny)//2,(clp-nz)//2,nx,ny,nz)) + trot.process_inplace("xform.phaseorigin.tocorner") + trotf=trot.do_fft() + + # actual CCF + ccf=targetf.calc_ccf(trotf) + + # rotate, pad, fft for mask + mrot=templatemask.process("xform",{"transform":Transform({"type":"eman","phi":phi,"alt":alt})}).get_clip(Region((clp-nx)//2,(clp-ny)//2,(clp-nz)//2,nx,ny,nz)) + mrot.process_inplace("xform.phaseorigin.tocorner") + mrotf=mrot.do_fft() + + # CCF of mask with squared volume + ccfn=targetsqf.calc_ccf(mrotf) + ccfn.process_inplace("math.sqrt") + ccf.div(ccfn) + jsd.put((ccf,phi,alt,n)) + +def compute(jsd,targetf,template,phi,alt,n): + print("test compute") + nx,ny,nz=targetf["nx"]-2,targetf["ny"],targetf["nz"] + clp=template["nx"] + trot=template.process("xform",{"transform":Transform({"type":"eman","phi":phi,"alt":alt})}).get_clip(Region((clp-nx)//2,(clp-ny)//2,(clp-nz)//2,nx,ny,nz)) + trot.process_inplace("xform.phaseorigin.tocorner") + trotf=trot.do_fft() + ccf=targetf.calc_ccf(trotf) + jsd.put((ccf,phi,alt,n)) + +def calc_ccm(target,template,dt,shrink,nthreads,base_out,local_norm=False): + print("Running test calc_ccm") + + #minimum rotation : number of degree to rotate for 1 pixel shift at nyquist - 4.4 in this case of microtubule with boxsz=25 + if shrink > 1: + target.process_inplace("math.fft.resample",{'n':shrink}) + + target.mult(-1.0) + nx,ny,nz=target["nx"],target["ny"],target["nz"] + targetf=target.do_fft() + targetsq=target.process("math.squared") + targetsqf=targetsq.do_fft() + + templatesca=template.process("math.fft.resample",{"n":target["apix_x"]/template["apix_x"]}) + nxt1=templatesca["nx"] + templatemask=templatesca.process("mask.auto3d",{"nmaxseed":8,"nshells":2,"radius":nxt1//10,"return_mask":True,"sigma":1.5}) + owner=EMData(target["nx"],target["ny"],target["nz"]) + avg=Averagers.get("minmax",{"max":True,"owner":owner}) + orts=[] + + jsd=queue.Queue(0) + thrds=[] + i=0 + + for alt in range(0,90,dt): + for phi in range(0,360,dt): + if local_norm: + thrds.append((jsd,targetf,templatesca,targetsqf,templatemask,phi,alt,i)) + else: + thrds.append((jsd,targetf,templatesca,phi,alt,i)) + i+=1 + + thrtolaunch=0 + while thrtolaunch1 or not jsd.empty(): + if thrtolaunch=nthreads) : time.sleep(0.1) + print("\r Starting thread {}/{} ".format(thrtolaunch,len(thrds)), end=' ',flush=True) +# thrds[thrtolaunch]=threading.Thread(target=compute,args=thrds[thrtolaunch]) # replace args + if local_norm: + thrds[thrtolaunch]=threading.Thread(target=compute_local,args=thrds[thrtolaunch]) # replace args + else: + thrds[thrtolaunch]=threading.Thread(target=compute,args=thrds[thrtolaunch]) # replace args + thrds[thrtolaunch].start() + thrtolaunch+=1 + else: time.sleep(0.1) + + # return is [N,dict] a dict of image# keyed processed images + while not jsd.empty(): + ccf,phi,alt,i=jsd.get() + ccf["ortid"]=len(orts) + orts.append((phi,alt)) + ccf.process_inplace("normalize") + avg.add_image(ccf) + thrds[i].join() + print(f"\n{phi},{alt} done {thrtolaunch} {threading.active_count()}/{nthreads}") + + peaks=avg.finish() + + + peaks.write_image(f"{base_out}_ccc.hdf:-1",0) + owner.write_image(f"{base_out}_owner_id.hdf:-1",0) + #owner.write_image(f"{base}_own.hdf:-1",0) + #target.write_image(f"{base}_targ.hdf:12") + #templatesca.write_image(f"{base}_tmpl.hdf:12",0) + out=open(f"{base_out}_orts.txt","w") + for i,phialt in enumerate(orts): out.write(f"{i}\t{phialt[0]}\t{phialt[1]}\n") + +def find_peaks_amp_test(npks,nbin,ccc_fac=3,ccc_file="",own_file="",orts_file=""): + n_peaks= npks + ccc_hdr=EMData(ccc_file, 0,True) + cx,cy,cz = ccc_hdr.get_sizes() + + #rx = template.get_sizes()[0] + #bsz = rx + #ccc = EMData(ccc_file).process("mask.zeroedge3d",{"x0":bsz//2,"x1":bsz//2,"y0":bsz//2,"y1":bsz//2,"z0":bsz//2,"z1":bsz//2}) + ccc = EMData(ccc_file) + print("Shape",ccc.get_sizes()) + + #ccc.process_inplace("filter.lowpass.gauss",{"cutoff_abs":0.1}) + #print("Set border of ccc matrix to zero to avoid peaks too close to the border") + mean=float(ccc.get_attr("mean")) + sig=float(ccc.get_attr("sigma")) + #ccc.process_inplace("threshold.belowtozero",{"minval":mean+sig}) + ccc.process_inplace("mask.onlypeaks",{"npeaks":2}) #before threshold + ccc.process_inplace("threshold.belowtozero",{"minval":mean+sig}) + + + peaks = ccc.calc_highest_locations(mean+ccc_fac*sig) + peaks.sort(key=lambda peak: -peak.value) + pts = [(nbin*peak.x,nbin*peak.y,nbin*peak.z) for peak in peaks] + orts_f=open(orts_file,"r") + oris = [] + for ort in orts_f.readlines(): + angles = ort.split("\t") + xf = Transform({'az':0,'alt':int(angles[2]),'phi':int(angles[1]),'tx':0.00,'ty':0.00,'tz':0.00,'mirror':0,'scale':1.0000,'type':'eman'}) + oris.append(xf) + + initxf = EMData(own_file) + xfs = [oris[int(initxf[(peak.x,peak.y,peak.z)])] for peak in peaks] + if len(pts) > n_peaks: + print("Find total {} peaks. Highest score {} peaks at {}".format(len(pts),n_peaks,pts[:n_peaks])) + return pts[:n_peaks],xfs[:n_peaks] + else: + print("Find {} peaks at {}".format(len(pts),pts)) + return pts,xfs + +def do_search_test(tomo,tempt,jsd, px_l): + for pt_xf in px_l: + p = pt_xf[0] + initxf = pt_xf[1] + x,y,z= (int(i) for i in p) + bs = tempt["nx"] + subvol = tomo.get_clip(Region(x-bs//2,y-bs//2,z-bs//2,bs,bs,bs)) + tempt_a = tempt.align("rotate_translate_3d_tree",subvol,{"initxform":[initxf],"sym":"c1"},'ccc.tomo') + #tempt.process_inplace("xform.phaseorigin.tocorner") + subvolf =subvol.do_fft() + tempt_af = tempt_a.do_fft() + cf = subvolf.calc_ccf(tempt_af) + #print(tempt_a.numpy().shape,cf.numpy().shape) + cf_score = np.max(abs(cf.numpy())) + jsd.put((p,tempt_a["xform.align3d"],cf_score)) + +def do_local_search_test(tomo,tempt,n_peaks,nbin,nthrds,ccc_fac=3,base_out=""): + ccc_file = f"{base_out}_ccc.hdf" + own_file =f"{base_out}_owner_id.hdf" + orts_file = f"{base_out}_orts.txt" + pts,xfs = find_peaks_amp_test(npks=n_peaks*3,nbin=nbin,ccc_file=ccc_file,own_file=own_file,orts_file=orts_file) + mbin=tomo["apix_x"]/tempt["apix_x"] + print("Will shrink reference by {:.1f} to match apix of tomogram for local search".format(mbin)) + tempt.process_inplace("filter.lowpass.gauss",{"cutoff_abs":.4}) #do it first then math.fft.resample #get rid of lowres peak of ice gradient + tempt.process_inplace("math.fft.resample",{'n':mbin}) + tempt.process_inplace('normalize.edgemean') + tempt.mult(-1) + good_szs=[good_size(tempt["nx"]),good_size(tempt["ny"]),good_size(tempt["nz"])] + tempt.clip_inplace(Region(0,0,0,good_szs[0],good_szs[1],good_szs[2])) + tomo.process_inplace('normalize.edgemean') + + pts_xfs_l = list(zip(pts,xfs)) + start = time.time() + tasks=[pts_xfs_l[i::nthrds] for i in range(nthrds)] + + #print(tasks) + jsd=queue.Queue(0) + thrds=[threading.Thread(target=do_search_test,args=(tomo, tempt, jsd, px_l)) for px_l in tasks] + + thrtolaunch=0 + tsleep=threading.active_count() + + ndone=0 + for t in thrds: + t.start() + p_xf_l = [] + print("Start local searching at {} location".format(len(pts))) + while threading.active_count()>tsleep or not jsd.empty(): + while not jsd.empty(): + p,xf,cf=jsd.get() + p_xf_l.append((p,xf,cf)) + ndone+=1 + sys.stdout.write("\r{}/{} finished.".format(ndone, len(pts))) + sys.stdout.flush() + time.sleep(.5) + print("") + print("Finish in {}s".format(time.time()-start)) + + p_xf_l.sort(key = lambda x: -x[2]) + # try: + # pt_cf_l = [] + # for i in range(len(p_xf_l)): + # pt = list(p_xf_l[i][0]) + # pt.append(p_xf_l[i][2]) + # pt_cf_l.append(pt) + # #from_numpy(np.array(pt_cf_l)).write_image("tmplt_match_local_pks.hdf") + # # from_numpy(np.array(pt_cf_l)).write_image(f"{base_out}_local_pks.hdf:-1",0) + # # print("All peaks saved to"+base_out+"_local_pks.hdf") + # except Exception as e: + # print(e) + # pass + p_xf_l=p_xf_l[:n_peaks] + pts = [p_xf[0] for p_xf in p_xf_l] + #xfs = [p_xf[1].get_matrix() for p_xf in p_xf_l] + xfs = [p_xf[1] for p_xf in p_xf_l] + cfs = [p_xf[2] for p_xf in p_xf_l] + if max(cfs) != 0: + cfs = [cf/max(cfs)+0.01 for cf in cfs] + + #cfs = [p_xf[3].numpy().flatten() for p_xf in p_xf_l] + d = {"pts" : pts,"xfs" : xfs, "cfs": cfs} + js=js_open_dict(f"{base_out}_local_pks.json") + js.update(d) + js.close() + #js.dump(d,open(f"{base_out}_local_pks.json","w")) + + + #for i in range(len(pts)): + #local_out.write(",".join(pts[i])+","+",".join(xfs[i].get_matrix())) + #for i,phialt in enumerate(orts): local_out.write(f"{i}\t{phialt[0]}\t{phialt[1]}\n") + #cfs_temp = [p_xf[2] for p_xf in p_xf_l] + #cfs = [cf/max(cfs_temp) for cf in cfs_temp] + #return pts,xfs + + +def insert_vol(target,insert_im,pts,xfs,outfile,cfs=[]): + # outfile = f"{base_out}_tmplt_seg.hdf" + #target.write_image(outfile) + + + # if self.target.get_annotation() is not None: + # anno_head = self.target.get_annotation().copy() + # anno_head.write_image(outfile) + # tomo_head = self.target.get_data().copy_head() + tomo_apix = target["apix_x"] + # else: + # tomo_head = self.target.get_data().copy_head() + # tomo_head.write_image(outfile) + # tomo_apix = tomo_head["apix_x"] + + # if self.insert_vol_le.text() == 0: + # if self.tmplt_le.text() > 0: + # insert_im = EMData(self.tmplt_le.text()) + # print("Filter template to use as insert mask. ") + # else: + # print("Specify mask to put in the tomogram") + # return + # else: + # try: + # insert_im = EMData(self.insert_vol_le.text()) + # except: + # print("Cannot read insert vol data in. Abort") + + + mbin=tomo_apix/insert_im["apix_x"] + insert_im.process_inplace("math.fft.resample",{'n':mbin}) + print("Will shrink insert vol by {:.1f} to match apix of tomogram".format(mbin)) + good_szs=[good_size(insert_im["nx"]),good_size(insert_im["ny"]),good_size(insert_im["nz"])] + insert_im.clip_inplace(Region(0,0,0,good_szs[0],good_szs[1],good_szs[2])) + print("Vol of insert im is {}".format(insert_im.get_sizes())) + + + + #annotate = self.target.get_annotation() + #annotate = EMData("tmplt_match_temp_vol.hdf") + + for i,loc in enumerate(pts): + if cfs[i] == 0: + print("Cf score reach 0. Finish segmentation") + break + vol = insert_im.copy() + #vol.process_inplace("filter.lowpass.gauss",{"cutoff_freq":0.033}) + vol.process_inplace("xform", {"transform":xfs[i]}) + vol.process_inplace("normalize.edgemean") + # vol.process_inplace("threshold.binary",{"value":thres}) + + #vol.mult(val) + x,y,z = [int(i) for i in loc] + # bs = vol["nx"] + # reg = Region(x-bs//2,y-bs//2,z-bs//2,bs,bs,bs) + reg = Region(x-good_szs[0]//2,y-good_szs[1]//2,z-good_szs[2]//2,good_szs[0],good_szs[1],good_szs[2]) + #reg = Region(x,y,z,good_szs[0],good_szs[1],good_szs[2]) + + try: + #current_vol = self.target.get_annotation().get_clip(reg) + #current_vol = annotate.get_clip(reg) + current_vol = EMData(outfile, 0, False, reg) + #current_vol=annotate.get_rotated_clip(Transform(),reg) + if len(cfs) > 0: + insert_vol=current_vol + cfs[i]*vol + else: + insert_vol=current_vol.process("math.max",{"with":vol}) + except: + insert_vol = vol + try: + #annotate.set_rotated_clip(Transform(),insert_vol) + insert_vol.write_image(outfile, 0, IMAGE_HDF, False, reg) + sys.stdout.write("\r{}/{} finished.".format(i+1, len(pts))) + sys.stdout.flush() + #print("Insert vol at location",x,y,z,"") + except Exception as e: + print(e) + print("Invalid region at location",x,y,z,".Skip.") + continue + #annotate = EMData(outfile) + # self.target.img_view.set_data(self.target.data,EMData(outfile)) + # self.target.img_view.updateGL() + print("Finishing segmentation") + +if __name__ == '__main__': + main() From e66510292c14d0ed18aba4690cb3276b78a370d9 Mon Sep 17 00:00:00 2001 From: sludtke42 Date: Mon, 30 Sep 2024 16:25:36 -0500 Subject: [PATCH 4/6] Return shininess --- libpyEM/qtgui/em3Dfonts.py | 2 +- libpyEM/qtgui/emannotate2d.py | 2 +- libpyEM/qtgui/emglobjects.py | 10 +++++----- libpyEM/qtgui/emimage2d.py | 2 +- libpyEM/qtgui/emimage3diso.py | 2 +- libpyEM/qtgui/emimage3dsym.py | 8 ++++---- libpyEM/qtgui/emimagemx.py | 4 ++-- libpyEM/qtgui/emlights.py | 14 +++++++------- libpyEM/qtgui/empdbitem3d.py | 8 ++++---- libpyEM/qtgui/empdbviewer.py | 2 +- libpyEM/qtgui/emshapeitem3d.py | 16 ++++++++-------- libpyEM/qtgui/valslider.py | 2 +- 12 files changed, 36 insertions(+), 36 deletions(-) diff --git a/libpyEM/qtgui/em3Dfonts.py b/libpyEM/qtgui/em3Dfonts.py index 9a11435f53..336020f48f 100644 --- a/libpyEM/qtgui/em3Dfonts.py +++ b/libpyEM/qtgui/em3Dfonts.py @@ -149,7 +149,7 @@ def render(self): glMaterial(GL_FRONT, GL_AMBIENT, self.colors[self.currentcolor]["ambient"]) glMaterial(GL_FRONT, GL_DIFFUSE, self.colors[self.currentcolor]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors[self.currentcolor]["specular"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors[self.currentcolor]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors[self.currentcolor]["shininess"]) glColor(self.colors[self.currentcolor]["diffuse"]) glClearColor(self.bgR,self.bgG,self.bgB,self.bg_a) diff --git a/libpyEM/qtgui/emannotate2d.py b/libpyEM/qtgui/emannotate2d.py index be6274fb07..7183f07c78 100644 --- a/libpyEM/qtgui/emannotate2d.py +++ b/libpyEM/qtgui/emannotate2d.py @@ -1838,7 +1838,7 @@ def __draw_hud(self): glMaterial(GL_FRONT,GL_AMBIENT,(0.2, 1.0, 0.2,1.0)) glMaterial(GL_FRONT,GL_DIFFUSE,(0.2, 1.0, 0.9,1.0)) glMaterial(GL_FRONT,GL_SPECULAR,(1.0, 0.5, 0.2,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,20.0) + glMaterial(GL_FRONT,GL_SHININESS,20.0) enable_depth = glIsEnabled(GL_DEPTH_TEST) glDisable(GL_DEPTH_TEST) glColor(1.0,1.0,1.0) diff --git a/libpyEM/qtgui/emglobjects.py b/libpyEM/qtgui/emglobjects.py index cef80ca149..1329ee3c61 100644 --- a/libpyEM/qtgui/emglobjects.py +++ b/libpyEM/qtgui/emglobjects.py @@ -355,7 +355,7 @@ def draw_frame(self, ftest=False): # and is the default color of the frame glMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,(.2,.2,.8,1.0)) glMaterial(GL_FRONT,GL_SPECULAR,(.8,.8,.8,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,50.0) + glMaterial(GL_FRONT,GL_SHININESS,50.0) glMatrixMode(GL_PROJECTION) glPushMatrix() @@ -371,7 +371,7 @@ def draw_frame(self, ftest=False): # and is the default color of the frame glMaterial(GL_FRONT,GL_AMBIENT,(.2,.2,.8,1.0)) glMaterial(GL_FRONT,GL_SPECULAR,(.8,.8,.8,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,50.0) + glMaterial(GL_FRONT,GL_SHININESS,50.0) #draw the cylinders around the edges of the frame glPushMatrix() @@ -724,7 +724,7 @@ def draw_frame(self, ftest=False): # and is the default color of the frame glMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,(.2,.2,.8,1.0)) glMaterial(GL_FRONT,GL_SPECULAR,(.8,.8,.8,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,50.0) + glMaterial(GL_FRONT,GL_SHININESS,50.0) glMatrixMode(GL_PROJECTION) glPushMatrix() @@ -740,7 +740,7 @@ def draw_frame(self, ftest=False): # and is the default color of the frame glMaterial(GL_FRONT,GL_AMBIENT,(.2,.2,.8,1.0)) glMaterial(GL_FRONT,GL_SPECULAR,(.8,.8,.8,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,50.0) + glMaterial(GL_FRONT,GL_SHININESS,50.0) #draw the cylinders around the edges of the frame glPushMatrix() @@ -1757,7 +1757,7 @@ def draw_volume_bounds(width,height,depth,color=True): glMaterial(GL_FRONT, GL_AMBIENT, [1, 1, 1,1.0]) glMaterial(GL_FRONT, GL_DIFFUSE, [1, 1, 1,1.0]) glMaterial(GL_FRONT, GL_SPECULAR, [0.774597, 0.774597, 0.774597,1.0]) -# glMaterial(GL_FRONT, GL_SHININESS, 128.0) + glMaterial(GL_FRONT, GL_SHININESS, 128.0) glNormal(0,1,0) diff --git a/libpyEM/qtgui/emimage2d.py b/libpyEM/qtgui/emimage2d.py index 3dc07e012c..017f93a180 100644 --- a/libpyEM/qtgui/emimage2d.py +++ b/libpyEM/qtgui/emimage2d.py @@ -1979,7 +1979,7 @@ def __draw_hud(self): glMaterial(GL_FRONT,GL_AMBIENT,(0.2, 1.0, 0.2,1.0)) glMaterial(GL_FRONT,GL_DIFFUSE,(0.2, 1.0, 0.9,1.0)) glMaterial(GL_FRONT,GL_SPECULAR,(1.0 , 0.5, 0.2,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,20.0) + glMaterial(GL_FRONT,GL_SHININESS,20.0) enable_depth = glIsEnabled(GL_DEPTH_TEST) glDisable(GL_DEPTH_TEST) glColor(1.0,1.0,1.0) diff --git a/libpyEM/qtgui/emimage3diso.py b/libpyEM/qtgui/emimage3diso.py index 9867b9bbf5..cc499fc91d 100644 --- a/libpyEM/qtgui/emimage3diso.py +++ b/libpyEM/qtgui/emimage3diso.py @@ -154,7 +154,7 @@ def render(self): glMaterial(GL_FRONT, GL_AMBIENT, self.colors[self.isocolor]["ambient"]) glMaterial(GL_FRONT, GL_DIFFUSE, self.colors[self.isocolor]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors[self.isocolor]["specular"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors[self.isocolor]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors[self.isocolor]["shininess"]) glMaterial(GL_FRONT, GL_EMISSION, self.colors[self.isocolor]["emission"]) glColor(self.colors[self.isocolor]["ambient"]) glPushMatrix() diff --git a/libpyEM/qtgui/emimage3dsym.py b/libpyEM/qtgui/emimage3dsym.py index f05202185a..91d7ca4b68 100644 --- a/libpyEM/qtgui/emimage3dsym.py +++ b/libpyEM/qtgui/emimage3dsym.py @@ -162,7 +162,7 @@ def load_gl_color(self,frac): glMaterial(GL_FRONT,GL_DIFFUSE,diffuse) glMaterial(GL_FRONT,GL_SPECULAR,specular) glMaterial(GL_FRONT,GL_EMISSION,emission) -# glMaterial(GL_FRONT,GL_SHININESS,shininess) + glMaterial(GL_FRONT,GL_SHININESS,shininess) def load_color_2(self): glColor(self.a2) @@ -170,7 +170,7 @@ def load_color_2(self): glMaterial(GL_FRONT,GL_DIFFUSE,self.d2) glMaterial(GL_FRONT,GL_SPECULAR,self.s2) glMaterial(GL_FRONT,GL_EMISSION,self.e2) -# glMaterial(GL_FRONT,GL_SHININESS,self.h2) + glMaterial(GL_FRONT,GL_SHININESS,self.h2) class EulerData(object): @@ -570,14 +570,14 @@ def load_gl_color(self,name): glMaterial(GL_FRONT,GL_DIFFUSE,color["diffuse"]) glMaterial(GL_FRONT,GL_SPECULAR,color["specular"]) glMaterial(GL_FRONT,GL_EMISSION,color["emission"]) -# glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) + glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) def gl_color(self,color): glColor(*color) glMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,color) glMaterial(GL_FRONT,GL_SPECULAR,[0,0,0,1]) glMaterial(GL_FRONT,GL_EMISSION,(0,0,0,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,64.0) + glMaterial(GL_FRONT,GL_SHININESS,64.0) def trace_great_arcs(self, points): diff --git a/libpyEM/qtgui/emimagemx.py b/libpyEM/qtgui/emimagemx.py index 66cd8643b2..d6c11f82ed 100644 --- a/libpyEM/qtgui/emimagemx.py +++ b/libpyEM/qtgui/emimagemx.py @@ -1286,7 +1286,7 @@ def load_set_color(self,set): c = [color[0],color[1],color[2],1.0] glMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,c) glMaterial(GL_FRONT,GL_SPECULAR,c) -# glMaterial(GL_FRONT,GL_SHININESS,100.0) + glMaterial(GL_FRONT,GL_SHININESS,100.0) # if set == 0: # glMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,(.2,.2,.8,1.0)) # glMaterial(GL_FRONT,GL_SPECULAR,(.2,.2,.8,1.0)) @@ -2118,7 +2118,7 @@ def draw(self): glNormal(0,0,1) # this normal is fine for everything that is drawn here # this provides some defaults for specular and shininess glMaterial(GL_FRONT,GL_SPECULAR,(.8,1,1,1.0)) -# glMaterial(GL_FRONT,GL_SHININESS,20.0) + glMaterial(GL_FRONT,GL_SHININESS,20.0) # The scroll bar - the long bar that defines the extent glBegin(GL_QUADS) diff --git a/libpyEM/qtgui/emlights.py b/libpyEM/qtgui/emlights.py index 61a2f9058c..8226118f7b 100644 --- a/libpyEM/qtgui/emlights.py +++ b/libpyEM/qtgui/emlights.py @@ -130,13 +130,13 @@ def cylinder_to_from(self,next,prev): glMaterial(GL_FRONT, GL_AMBIENT, self.colors["emerald"]["ambient"]) glMaterial(GL_FRONT, GL_DIFFUSE, self.colors["emerald"]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors["emerald"]["specular"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors["emerald"]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors["emerald"]["shininess"]) glutSolidTorus(.05,0.25,16,16) glScalef(0.2,0.2,length) glMaterial(GL_FRONT, GL_AMBIENT, self.colors["ruby"]["ambient"]) glMaterial(GL_FRONT, GL_DIFFUSE, self.colors["ruby"]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors["ruby"]["specular"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors["ruby"]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors["ruby"]["shininess"]) glCallList(self.cylinderdl) #FIXME: this cylinder isn't visible on Mac OS glPopMatrix() @@ -170,7 +170,7 @@ def draw_lights(self): glMaterial(GL_FRONT, GL_DIFFUSE, self.colors["obsidian"]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors["obsidian"]["specular"]) glMaterial(GL_FRONT, GL_EMISSION, self.colors["obsidian"]["emission"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors["obsidian"]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors["obsidian"]["shininess"]) glPushMatrix() n = 12 @@ -183,7 +183,7 @@ def draw_lights(self): glMaterial(GL_FRONT, GL_DIFFUSE, self.colors[color]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors[color]["specular"]) glMaterial(GL_FRONT, GL_EMISSION, self.colors[color]["emission"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors[color]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors[color]["shininess"]) rot = 180.0*i/(n-1) glPushMatrix() glTranslate(0,0,-.5) @@ -292,7 +292,7 @@ def draw_light_cocoon(self): glMaterial(GL_FRONT, GL_DIFFUSE, yellow) glMaterial(GL_FRONT, GL_SPECULAR, yellow) glMaterial(GL_FRONT, GL_EMISSION, [0,0,0,0]) -# glMaterial(GL_FRONT, GL_SHININESS, 32) + glMaterial(GL_FRONT, GL_SHININESS, 32.0) glColor(*yellow) glEnable(GL_BLEND) @@ -354,7 +354,7 @@ def draw_inside_light(self): glMaterial(GL_FRONT, GL_DIFFUSE, yellow) glMaterial(GL_FRONT, GL_SPECULAR, yellow) glMaterial(GL_FRONT, GL_EMISSION, [0,0,0,0]) -# glMaterial(GL_FRONT, GL_SHININESS, 32) + glMaterial(GL_FRONT, GL_SHININESS, 32.0) glColor(*yellow) glEnable(GL_BLEND) @@ -597,7 +597,7 @@ def render(self): glMaterial(GL_FRONT, GL_DIFFUSE, self.colors[self.currentcolor]["diffuse"]) glMaterial(GL_FRONT, GL_SPECULAR, self.colors[self.currentcolor]["specular"]) glMaterial(GL_FRONT, GL_EMISSION, self.colors[self.currentcolor]["emission"]) -# glMaterial(GL_FRONT, GL_SHININESS, self.colors[self.currentcolor]["shininess"]) + glMaterial(GL_FRONT, GL_SHININESS, self.colors[self.currentcolor]["shininess"]) glColor(self.colors[self.currentcolor]["ambient"]) glEnable(GL_NORMALIZE) diff --git a/libpyEM/qtgui/empdbitem3d.py b/libpyEM/qtgui/empdbitem3d.py index 25c9635d71..9e89d7d0e7 100644 --- a/libpyEM/qtgui/empdbitem3d.py +++ b/libpyEM/qtgui/empdbitem3d.py @@ -291,7 +291,7 @@ def load_gl_color(self,name): glMaterial(GL_FRONT,GL_DIFFUSE,color["diffuse"]) glMaterial(GL_FRONT,GL_SPECULAR,color["specular"]) glMaterial(GL_FRONT,GL_EMISSION,color["emission"]) -# glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) + glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) def setLabel(self, label): self.label = label def current_text(self): return self.text @@ -519,7 +519,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) if self.first_render_flag: self.first_render_flag = False glPushMatrix() @@ -1102,7 +1102,7 @@ def load_gl_color(self,name): glMaterial(GL_FRONT,GL_DIFFUSE,color["diffuse"]) glMaterial(GL_FRONT,GL_SPECULAR,color["specular"]) glMaterial(GL_FRONT,GL_EMISSION,color["emission"]) -# glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) + glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) def getEvalString(self): return "EMSphereModel()" @@ -1169,7 +1169,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) if self.first_render_flag: self.first_render_flag = False glPushMatrix() diff --git a/libpyEM/qtgui/empdbviewer.py b/libpyEM/qtgui/empdbviewer.py index b029b66e4c..280ef73726 100644 --- a/libpyEM/qtgui/empdbviewer.py +++ b/libpyEM/qtgui/empdbviewer.py @@ -947,7 +947,7 @@ def load_gl_color(self,name): glMaterial(GL_FRONT,GL_DIFFUSE,color["diffuse"]) glMaterial(GL_FRONT,GL_SPECULAR,color["specular"]) glMaterial(GL_FRONT,GL_EMISSION,color["emission"]) -# glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) + glMaterial(GL_FRONT,GL_SHININESS,color["shininess"]) def makeStick (self, res, index1, index2): #draws a cylinder between two atoms once the index for start and stop is given n = [0,0,0] p = [0,0,0] diff --git a/libpyEM/qtgui/emshapeitem3d.py b/libpyEM/qtgui/emshapeitem3d.py index 7e03cf271e..3bae9e3b17 100644 --- a/libpyEM/qtgui/emshapeitem3d.py +++ b/libpyEM/qtgui/emshapeitem3d.py @@ -228,7 +228,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) glEnable(GL_BLEND) @@ -310,7 +310,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) # The box itself along with normal vectors @@ -411,7 +411,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) quadratic = gluNewQuadric() @@ -481,7 +481,7 @@ def renderShape(self): #glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) #glColor(1.0,1.0,1.0) if len(self.data)>3: @@ -581,7 +581,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) glPushMatrix() @@ -782,7 +782,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) glPushMatrix() @@ -865,7 +865,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) glPushMatrix() @@ -983,7 +983,7 @@ def renderShape(self): glDisable(GL_COLOR_MATERIAL) glMaterialfv(GL_FRONT, GL_DIFFUSE, self.diffuse) glMaterialfv(GL_FRONT, GL_SPECULAR, self.specular) -# glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) + glMaterialf(GL_FRONT, GL_SHININESS, self.shininess) glMaterialfv(GL_FRONT, GL_AMBIENT, self.ambient) glEnable(GL_NORMALIZE) diff --git a/libpyEM/qtgui/valslider.py b/libpyEM/qtgui/valslider.py index 2c18a3054e..d997cb0fc0 100644 --- a/libpyEM/qtgui/valslider.py +++ b/libpyEM/qtgui/valslider.py @@ -975,7 +975,7 @@ def paintGL(self): glMaterialfv(GL_FRONT, GL_DIFFUSE, [1.0,1.0,1.0,1.0]) glMaterialfv(GL_FRONT, GL_SPECULAR, [1.0,1.0,1.0,1.0]) glLightfv(self.light, GL_POSITION, self.lightposition) -# glMaterialf(GL_FRONT, GL_SHININESS, 25.0) + glMaterialf(GL_FRONT, GL_SHININESS, 25.0) quad = GLU.gluNewQuadric() GLU.gluQuadricDrawStyle(quad, GLU.GLU_FILL) GLU.gluQuadricNormals(quad, GLU.GLU_SMOOTH) From 159b6d7a3944e3b24efddd9b8d64f3f58991b2a7 Mon Sep 17 00:00:00 2001 From: shadow_walker Date: Thu, 3 Oct 2024 09:01:53 -0500 Subject: [PATCH 5/6] trigger build [ci build] From 0e77802ab0c2ee6f919c0f2a7dc4f58e12d8ab54 Mon Sep 17 00:00:00 2001 From: eman-bot Date: Thu, 3 Oct 2024 14:02:49 +0000 Subject: [PATCH 6/6] v2.99.64 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8580b8f1e9..81a1c82239 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.14) PROJECT(EMAN - VERSION 2.99.63 + VERSION 2.99.64 LANGUAGES CXX )