def printCtfData(self, ctfvalue): if ctfvalue is None: return defocusratio = ctfvalue['defocus2']/ctfvalue['defocus1'] if 'acerun' in ctfvalue: method = getCtfMethod(ctfvalue) runname = ctfvalue['acerun']['name'] sys.stderr.write("[%s] method: %s | runname %s\n"% (apDisplay.colorString("CTF run", "blue"), method, runname)) sys.stderr.write("[%s] def1: %.2e | def2: %.2e | angle: %.1f | ampcontr %.2f | defratio %.3f\n"% (apDisplay.colorString("CTF param", "blue"), ctfvalue['defocus1'], ctfvalue['defocus2'], ctfvalue['angle_astigmatism'], ctfvalue['amplitude_contrast'], defocusratio)) if 'resolution_80_percent' in ctfvalue.keys() and ctfvalue['resolution_80_percent'] is not None: sys.stderr.write("[%s] conf_30-10: %s | conf_5peak: %s | res_0.8: %.1fA | res_0.5 %.1fA\n"% (apDisplay.colorString("CTF stats", "blue"), apDisplay.colorProb(ctfvalue['confidence_30_10']), apDisplay.colorProb(ctfvalue['confidence_5_peak']), ctfvalue['resolution_80_percent'], ctfvalue['resolution_50_percent'])) #sys.stderr.write("[%s] conf: %s | conf_d: %s\n"% # (apDisplay.colorString("CTF stats", "blue"), apDisplay.colorProb(ctfvalue['confidence']), # apDisplay.colorProb(ctfvalue['confidence_d']))) #apDisplay.colorProb(numlist[i]) #time.sleep(3) return
def printCtfData(ctfvalue): if ctfvalue is None: return defocusratio = ctfvalue['defocus2'] / ctfvalue['defocus1'] method = getCtfMethod(ctfvalue) if 'acerun' in ctfvalue: method = getCtfMethod(ctfvalue) runname = ctfvalue['acerun']['name'] sys.stderr.write( "[%s] method: %s | runname %s\n" % (apDisplay.colorString("CTF run", "blue"), method, runname)) sys.stderr.write( "[%s] def1: %.2e | def2: %.2e | angle: %.1f | ampcontr %.2f | defratio %.3f\n" % (apDisplay.colorString("CTF param", "blue"), ctfvalue['defocus1'], ctfvalue['defocus2'], ctfvalue['angle_astigmatism'], ctfvalue['amplitude_contrast'], defocusratio)) if 'resolution_80_percent' in ctfvalue.keys( ) and ctfvalue['resolution_80_percent'] is not None: sys.stderr.write( "[%s] conf_30-10: %s | conf_5peak: %s | res_0.8: %.1fA | res_0.5 %.1fA\n" % (apDisplay.colorString("CTF stats", "blue"), apDisplay.colorProb(ctfvalue['confidence_30_10']), apDisplay.colorProb(ctfvalue['confidence_5_peak']), ctfvalue['resolution_80_percent'], ctfvalue['resolution_50_percent'])) #sys.stderr.write("[%s] conf: %s | conf_d: %s\n"% # (apDisplay.colorString("CTF stats", "blue"), apDisplay.colorProb(ctfvalue['confidence']), # apDisplay.colorProb(ctfvalue['confidence_d']))) #apDisplay.colorProb(numlist[i]) #time.sleep(3) return
def runAce(matlab, imgdata, params, showprev=True): imgname = imgdata['filename'] if showprev is True: bestctfvalue, bestconf = ctfdb.getBestCtfValueForImage(imgdata) if bestctfvalue: print ( "Prev best: '"+bestctfvalue['acerun']['name']+"', conf="+ apDisplay.colorProb(bestconf)+", defocus="+str(round(-1.0*abs(bestctfvalue['defocus1']*1.0e6),2))+ " microns" ) if params['uncorrected']: tmpname='temporaryCorrectedImage.mrc' imgarray = apDBImage.correctImage(imgdata) imgpath = os.path.join(params['rundir'],tmpname) apImage.arrayToMrc(imgarray, imgpath) print "processing", imgpath else: imgpath = os.path.join(imgdata['session']['image path'], imgname+'.mrc') nominal = None if params['nominal'] is not None: nominal=params['nominal'] elif params['newnominal'] is True: nominal = ctfdb.getBestDefocusForImage(imgdata, msg=True) if nominal is None: nominal = imgdata['scope']['defocus'] if nominal is None or nominal > 0 or nominal < -15e-6: apDisplay.printWarning("Nominal should be of the form nominal=-1.2e-6"+\ " for -1.2 microns NOT:"+str(nominal)) #Neil's Hack #if 'autosample' in params and params['autosample']: # x = abs(nominal*1.0e6) # val = 1.585 + 0.057587 * x - 0.044106 * x**2 + 0.010877 * x**3 # resamplefr_override = round(val,3) # print "resamplefr_override=",resamplefr_override # pymat.eval(matlab, "resamplefr="+str(resamplefr_override)+";") pymat.eval(matlab,("dforig = %e;" % nominal)) if params['stig'] == 0: plist = (imgpath, params['outtextfile'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/") acecmd = makeMatlabCmd("ctfparams = ace(",");",plist) else: plist = (imgname, imgpath, params['outtextfile'], params['opimagedir'], \ params['matdir'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/", params['resamplefr']) acecmd = makeMatlabCmd("ctfparams = measureAstigmatism(",");",plist) #print acecmd pymat.eval(matlab,acecmd) matfile = os.path.join(params['matdir'], imgname+".mrc.mat") if params['stig']==0: savematcmd = "save('"+matfile+"','ctfparams','scopeparams', 'dforig');" pymat.eval(matlab,savematcmd) ctfvalue = pymat.get(matlab, 'ctfparams') ctfvalue=ctfvalue[0] ctfdb.printResults(params, nominal, ctfvalue) return ctfvalue
def runAce(matlab, imgdata, params, showprev=True): imgname = imgdata['filename'] if showprev is True: bestctfvalue = ctfdb.getBestCtfByResolution(imgdata) if bestctfvalue: bestconf = ctfdb.calculateConfidenceScore(bestctfvalue) print ( "Prev best: '"+bestctfvalue['acerun']['name']+"', conf="+ apDisplay.colorProb(bestconf)+", defocus="+str(round(-1.0*abs(bestctfvalue['defocus1']*1.0e6),2))+ " microns" ) if params['uncorrected']: tmpname='temporaryCorrectedImage.mrc' imgarray = apDBImage.correctImage(imgdata) imgpath = os.path.join(params['rundir'],tmpname) apImage.arrayToMrc(imgarray, imgpath) print "processing", imgpath else: imgpath = os.path.join(imgdata['session']['image path'], imgname+'.mrc') nominal = None if params['nominal'] is not None: nominal=params['nominal'] elif params['newnominal'] is True: bestctfvalue = ctfdb.getBestCtfByResolution(imgdata) nominal = bestctfvalue['defocus1'] if nominal is None: nominal = imgdata['scope']['defocus'] if nominal is None or nominal > 0 or nominal < -15e-6: apDisplay.printWarning("Nominal should be of the form nominal=-1.2e-6"+\ " for -1.2 microns NOT:"+str(nominal)) #Neil's Hack #if 'autosample' in params and params['autosample']: # x = abs(nominal*1.0e6) # val = 1.585 + 0.057587 * x - 0.044106 * x**2 + 0.010877 * x**3 # resamplefr_override = round(val,3) # print "resamplefr_override=",resamplefr_override # pymat.eval(matlab, "resamplefr="+str(resamplefr_override)+";") pymat.eval(matlab,("dforig = %e;" % nominal)) if params['stig'] == 0: plist = (imgpath, params['outtextfile'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/") acecmd = makeMatlabCmd("ctfparams = ace(",");",plist) else: plist = (imgname, imgpath, params['outtextfile'], params['opimagedir'], \ params['matdir'], params['display'], params['stig'],\ params['medium'], -nominal, params['tempdir']+"/", params['resamplefr']) acecmd = makeMatlabCmd("ctfparams = measureAstigmatism(",");",plist) #print acecmd pymat.eval(matlab,acecmd) matfile = os.path.join(params['matdir'], imgname+".mrc.mat") if params['stig']==0: savematcmd = "save('"+matfile+"','ctfparams','scopeparams', 'dforig');" pymat.eval(matlab,savematcmd) ctfvalue = pymat.get(matlab, 'ctfparams') ctfvalue=ctfvalue[0] printResults(params, nominal, ctfvalue) return ctfvalue