def getACE2Path(self): unames = os.uname() if unames[-1].find('64') >= 0: exename = 'ace2.exe' else: exename = 'ace2_32.exe' ace2exe = subprocess.Popen("which "+exename, shell=True, stdout=subprocess.PIPE).stdout.read().strip() if not os.path.isfile(ace2exe): ace2exe = os.path.join(apParam.getAppionDirectory(), 'bin', exename) if not os.path.isfile(ace2exe): apDisplay.printError(exename+" was not found at: "+apParam.getAppionDirectory()) return ace2exe
def openFile(self): if not os.path.isfile(self.params['filename']): apDisplay.printError("Cound not find file "+self.params['filename']) if self.params['filename'][-4:].lower() == ".mrc": imgarray = mrc.read(self.params['filename']) else: try: ### assume file is of type spider imgarray = spider.read(self.params['filename']) except: apDisplay.printError("Cound not read file "+self.params['filename']) return imgarray """
def openFile(self): if not os.path.isfile(self.params['filename']): apDisplay.printError("Cound not find file " + self.params['filename']) if self.params['filename'][-4:].lower() == ".mrc": imgarray = mrc.read(self.params['filename']) else: try: ### assume file is of type spider imgarray = spider.read(self.params['filename']) except: apDisplay.printError("Cound not read file " + self.params['filename']) return imgarray """
def getACE2Path(self): unames = os.uname() if unames[-1].find('64') >= 0: exename = 'ace2.exe' else: exename = 'ace2_32.exe' ace2exe = subprocess.Popen( "which " + exename, shell=True, stdout=subprocess.PIPE).stdout.read().strip() if not os.path.isfile(ace2exe): ace2exe = os.path.join(apParam.getAppionDirectory(), 'bin', exename) if not os.path.isfile(ace2exe): apDisplay.printError(exename + " was not found at: " + apParam.getAppionDirectory()) return ace2exe
def processImage(self, imgfile, edgeblur=8, msg=False): ### make command line acecmd = ("%s -i %s -c %.2f -k %d -a %.3f -e %d,0.001 -b 1" % (self.ace2exe, imgfile, self.params['cs'], self.params['kv'], self.params['apix'], edgeblur)) ### run ace2 aceoutf = open("ace2.stdout", "w") #print acecmd ace2proc = subprocess.Popen(acecmd, shell=True, stdout=aceoutf, stderr=aceoutf) ace2proc.wait() ### check if ace2 worked imagelog = imgfile + ".ctf.txt" if not os.path.isfile(imagelog) and self.count <= 1: ### ace2 always crashes on first image??? .fft_wisdom file?? time.sleep(1) ace2proc = subprocess.Popen(acecmd, shell=True, stdout=aceoutf, stderr=aceoutf) ace2proc.wait() aceoutf.close() ### die if not os.path.isfile(imagelog): apDisplay.printError("ace2 did not run") ### parse log file ctfvalues = {} logf = open(imagelog, "r") for line in logf: sline = line.strip() if re.search("^Final Defocus:", sline): parts = sline.split() ctfvalues['defocus1'] = float(parts[2]) ctfvalues['defocus2'] = float(parts[3]) ### convert to degrees ctfvalues['angle_astigmatism'] = math.degrees(float(parts[4])) elif re.search("^Amplitude Contrast:", sline): parts = sline.split() ctfvalues['amplitude_contrast'] = float(parts[2]) elif re.search("^Confidence:", sline): parts = sline.split() ctfvalues['confidence'] = float(parts[1]) ctfvalues['confidence_d'] = float(parts[1]) logf.close() ### summary stats avgdf = (ctfvalues['defocus1'] + ctfvalues['defocus2']) / 2.0 ampconst = 100.0 * ctfvalues['amplitude_contrast'] pererror = 100.0 * (ctfvalues['defocus1'] - ctfvalues['defocus2']) / avgdf if msg is True: apDisplay.printMsg("============") apDisplay.printMsg("Defocus: %.3f x %.3f um (%.2f percent error)" % (ctfvalues['defocus1'] * 1.0e6, ctfvalues['defocus2'] * 1.0e6, pererror)) apDisplay.printMsg("Angle astigmatism: %.2f degrees" % (ctfvalues['angle_astigmatism'])) apDisplay.printMsg("Amplitude contrast: %.2f percent" % (ampconst)) apDisplay.printMsg("Final confidence: %.3f" % (ctfvalues['confidence'])) ### double check that the values are reasonable if avgdf < -1.0e-3 or avgdf > -1.0e-9: apDisplay.printWarning( "bad defocus estimate, not committing values to database") return None if ampconst < -0.01 or ampconst > 80.0: apDisplay.printWarning( "bad amplitude contrast, not committing values to database") return None if ctfvalues['confidence'] < 0.6: sys.stderr.write("c") #apDisplay.printWarning("bad confidence") return None return ctfvalues
def processImage(self, imgfile, edgeblur=8, msg=False): ### make command line acecmd = ("%s -i %s -c %.2f -k %d -a %.3f -e %d,0.001 -b 1" %(self.ace2exe, imgfile, self.params['cs'], self.params['kv'], self.params['apix'], edgeblur)) ### run ace2 aceoutf = open("ace2.stdout", "w") #print acecmd ace2proc = subprocess.Popen(acecmd, shell=True, stdout=aceoutf, stderr=aceoutf) ace2proc.wait() ### check if ace2 worked imagelog = imgfile+".ctf.txt" if not os.path.isfile(imagelog) and self.count <= 1: ### ace2 always crashes on first image??? .fft_wisdom file?? time.sleep(1) ace2proc = subprocess.Popen(acecmd, shell=True, stdout=aceoutf, stderr=aceoutf) ace2proc.wait() aceoutf.close() ### die if not os.path.isfile(imagelog): apDisplay.printError("ace2 did not run") ### parse log file ctfvalues = {} logf = open(imagelog, "r") for line in logf: sline = line.strip() if re.search("^Final Defocus:", sline): parts = sline.split() ctfvalues['defocus1'] = float(parts[2]) ctfvalues['defocus2'] = float(parts[3]) ### convert to degrees ctfvalues['angle_astigmatism'] = math.degrees(float(parts[4])) elif re.search("^Amplitude Contrast:",sline): parts = sline.split() ctfvalues['amplitude_contrast'] = float(parts[2]) elif re.search("^Confidence:",sline): parts = sline.split() ctfvalues['confidence'] = float(parts[1]) ctfvalues['confidence_d'] = float(parts[1]) logf.close() ### summary stats avgdf = (ctfvalues['defocus1']+ctfvalues['defocus2'])/2.0 ampconst = 100.0*ctfvalues['amplitude_contrast'] pererror = 100.0 * (ctfvalues['defocus1']-ctfvalues['defocus2']) / avgdf if msg is True: apDisplay.printMsg("============") apDisplay.printMsg("Defocus: %.3f x %.3f um (%.2f percent error)"% (ctfvalues['defocus1']*1.0e6, ctfvalues['defocus2']*1.0e6, pererror )) apDisplay.printMsg("Angle astigmatism: %.2f degrees"%(ctfvalues['angle_astigmatism'])) apDisplay.printMsg("Amplitude contrast: %.2f percent"%(ampconst)) apDisplay.printMsg("Final confidence: %.3f"%(ctfvalues['confidence'])) ### double check that the values are reasonable if avgdf < -1.0e-3 or avgdf > -1.0e-9: apDisplay.printWarning("bad defocus estimate, not committing values to database") return None if ampconst < -0.01 or ampconst > 80.0: apDisplay.printWarning("bad amplitude contrast, not committing values to database") return None if ctfvalues['confidence'] < 0.6: sys.stderr.write("c") #apDisplay.printWarning("bad confidence") return None return ctfvalues