def preLoopFunctions(self): self.powerspecdir = os.path.join(self.params['rundir'], "opimages") apParam.createDirectory(self.powerspecdir, warning=False) self.acerunq = None self.params['matdir'] = os.path.join(self.params['rundir'], "matfiles") self.params['tempdir'] = os.path.join(self.params['rundir'], "temp") apParam.createDirectory(os.path.join(self.params['matdir']), warning=False) apParam.createDirectory(os.path.join(self.params['tempdir']), warning=False) if self.params['sessionname'] is not None: self.params['outtextfile'] = os.path.join( self.params['rundir'], self.params['sessionname'] + ".txt") if self.params['xvfb'] is True: apParam.resetVirtualFrameBuffer() apMatlab.checkMatlabPath(self.params) acepath = os.path.join(os.getcwd(), self.functionname + ".py") #if not os.path.isfile(acepath): # apDisplay.printWarning("'"+self.functionname+".py' usually needs to be run in the "+\ # "same directory as all of its matlab files") print "Connecting to matlab ... " if self.params['xvfb'] is True: apParam.resetVirtualFrameBuffer() try: self.matlab = pymat.open() #self.matlab = pymat.open('matlab -nodisplay') except: apDisplay.environmentError() raise apMatlab.setAceConfig(self.matlab, self.params)
def checkMatlabPath(params=None): ''' Return immediately if MATLABPATH environment variable is already set. Searches for ace.m and adds its directory to matlab path. ''' if os.environ.get("MATLABPATH") is None: #TRY LOCAL DIRECTORY FIRST matlabpath = os.path.abspath(".") if os.path.isfile(os.path.join(matlabpath,"ace.m")): updateMatlabPath(matlabpath) return #TRY APPIONDIR/ace if params is not None and 'appiondir' in params: matlabpath = os.path.join(params['appiondir'],"ace") if os.path.isdir(matlabpath) and os.path.isfile(os.path.join(matlabpath,"ace.m")): updateMatlabPath(matlabpath) return #TRY sibling dir of this script libdir = os.path.dirname(__file__) libdir = os.path.abspath(libdir) appiondir = os.path.dirname(libdir) acedir = os.path.join(appiondir, 'ace') if os.path.isdir(acedir) and os.path.isfile(os.path.join(acedir,"ace.m")): updateMatlabPath(acedir) return apDisplay.environmentError() raise RuntimeError('Could not find ace.m. Check MATLABPATH environment variable.')
def runAceCorrect(imgdict,params): imgname = imgdict['filename'] imgpath = os.path.join(imgdict['session']['image path'], imgname+'.mrc') voltage = (imgdict['scope']['high tension']) apix = apDatabase.getPixelSize(imgdict) ctfvalues, conf = ctfdb.getBestCtfValueForImage(imgdict) ctdimname = imgname ctdimpath = os.path.join(params['rundir'],ctdimname) print "Corrected Image written to " + ctdimpath #pdb.set_trace() acecorrectcommand=("ctfcorrect1('%s', '%s', '%.32f', '%.32f', '%f', '%f', '%f');" % \ (imgpath, ctdimpath, ctfvalues['defocus1'], ctfvalues['defocus2'], -ctfvalues['angle_astigmatism'], voltage, apix)) print acecorrectcommand try: matlab = pymat.open("matlab -nosplash") except: apDisplay.environmentError() raise pymat.eval(matlab, acecorrectcommand) pymat.close(matlab) return
def preLoopFunctions(self): self.powerspecdir = os.path.join(self.params['rundir'], "opimages") apParam.createDirectory(self.powerspecdir, warning=False) self.acerunq = None self.params['matdir'] = os.path.join(self.params['rundir'],"matfiles") self.params['tempdir'] = os.path.join(self.params['rundir'],"temp") apParam.createDirectory(os.path.join(self.params['matdir']), warning=False) apParam.createDirectory(os.path.join(self.params['tempdir']), warning=False) if self.params['sessionname'] is not None: self.params['outtextfile']=os.path.join(self.params['rundir'], self.params['sessionname']+".txt") if self.params['xvfb'] is True: apParam.resetVirtualFrameBuffer() apMatlab.checkMatlabPath(self.params) acepath = os.path.join(os.getcwd(), self.functionname+".py") #if not os.path.isfile(acepath): # apDisplay.printWarning("'"+self.functionname+".py' usually needs to be run in the "+\ # "same directory as all of its matlab files") print "Connecting to matlab ... " if self.params['xvfb'] is True: apParam.resetVirtualFrameBuffer() try: self.matlab = pymat.open() #self.matlab = pymat.open('matlab -nodisplay') except: apDisplay.environmentError() raise apMatlab.setAceConfig(self.matlab, self.params)
def runAceCorrect(imgdict,params): imgname = imgdict['filename'] imgpath = os.path.join(imgdict['session']['image path'], imgname+'.mrc') voltage = (imgdict['scope']['high tension']) apix = apDatabase.getPixelSize(imgdict) ctfvalues = ctfdb.getBestCtfByResolution(imgdata) conf = ctfdb.calculateConfidenceScore(bestctfvalue) ctdimname = imgname ctdimpath = os.path.join(params['rundir'],ctdimname) print "Corrected Image written to " + ctdimpath #pdb.set_trace() acecorrectcommand=("ctfcorrect1('%s', '%s', '%.32f', '%.32f', '%f', '%f', '%f');" % \ (imgpath, ctdimpath, ctfvalues['defocus1'], ctfvalues['defocus2'], -ctfvalues['angle_astigmatism'], voltage, apix)) print acecorrectcommand try: matlab = pymat.open("matlab -nosplash") except: apDisplay.environmentError() raise pymat.eval(matlab, acecorrectcommand) pymat.close(matlab) return