def getStackRunParams(self): stackdata = self.getOriginalStackMadeByMakeStack() stackruns = apStack.getStackRunsFromStack(stackdata) # To Do: need to handle combined stack stackrun = stackruns[0] self.originalStackParamData = stackrun['stackParams'] self.stackrunlogparams = apScriptLog.getScriptParamValuesFromRunname(stackrun['stackRunName'],stackdata['path'],jobdata=None)
def convertToRefineStack(self): ''' The stack is remaked without ctf correction and without invertion (ccd) ''' newstackroot = os.path.join(self.params['rundir'], os.path.basename(self.stack['file'])[:-4]) if self.params['paramonly'] is True: print 'newstackroot', newstackroot self.setFrealignStack(newstackroot) return # copy existing refined stack if possible existing_refine_stack = apStack.getExistingRefineStack( self.stack['data'], 'frealign', False, self.params['last'], self.params['bin'], lowpass=self.params['lowpass'], highpass=self.params['highpass']) try: if existing_refine_stack: if existing_refine_stack != os.path.join( self.params['rundir'], newstackroot + '.mrc'): shutil.copyfile(existing_refine_stack, newstackroot + '.mrc') new_partorderfile = os.path.join(self.params['rundir'], 'stackpartorder.list') existing_partorderfile = os.path.join( os.path.dirname(existing_refine_stack), 'stackpartorder.list') # particle order list also need to be copied if not os.path.isfile(new_partorderfile) and os.path.isfile( existing_partorderfile): shutil.copyfile(existing_partorderfile, new_partorderfile) self.setFrealignStack(newstackroot) return except: # make one from scratch if there is error apDisplay.printMsg( 'Error copying existing refine stack, will regenerate') if self.no_ctf_correction: self.ImagicStackToFrealignMrcStack(self.stack['file']) self.setFrealignStack(newstackroot) return # stack need to be remade without ctf correction apDisplay.printWarning( 'Frealign needs a stack without ctf correction. A new stack is being made....' ) stackdata = self.stack['data'] madestackdata = self.getOriginalStackMadeByMakeStack() stackid = stackdata.dbid stackruns = apStack.getStackRunsFromStack(madestackdata) # To Do: need to handle combined stack stackrun = stackruns[0] stackpathname = os.path.basename(stackdata['path']['path']) totalpart = apStack.getNumberStackParticlesFromId(stackid) if not self.params['last']: numpart = totalpart else: numpart = min(self.params['last'], totalpart) newstackrunname = self.params['runname'] newstackrundir = self.params['rundir'] newstackimagicfile = os.path.join(newstackrundir, 'temp.hed') # use first particle image to get presetname oneparticle = apStack.getOneParticleFromStackId(stackid, particlenumber=1) preset = oneparticle['particle']['image']['preset'] if preset: presetname = preset['name'] else: presetname = 'manual' # use first stack run to get parameters paramdata = stackrun['stackParams'] # binning is combination of the original binning of the stack and the preparation binnning bin = paramdata['bin'] * self.params['bin'] unbinnedboxsize = self.stack['boxsize'] * paramdata['bin'] lowpasstext = self.setArgText( 'lowpass', (self.params['lowpass'], paramdata['lowpass']), False) highpasstext = self.setArgText( 'highpass', (self.params['highpass'], paramdata['highpass']), True) partlimittext = self.setArgText('partlimit', (numpart, ), False) #normalization normtext = '' if 'xmipp-norm' in paramdata.keys(): # myami-3.1 or before normtext = self.setArgText('xmipp-normalize', (paramdata['xmipp-norm'], ), True) normtext = '--normalized ' + normtext elif 'normalizemethod' in paramdata.keys(): # myami-3.2 or newer normtext = '--normalize-method=%s' % ( paramdata['normalizemethod'], ) sessionid = int(self.params['expid']) sessiondata = apDatabase.getSessionDataFromSessionId(sessionid) sessionname = sessiondata['name'] projectid = self.params['projectid'] # The assumption is that the image is from ice grid and digital camera (black particles on white background if 'reverse' in self.stackrunlogparams.keys(): reversetext = '--reverse' else: reversetext = '' if 'defocpair' in self.stackrunlogparams.keys(): defoctext = '--defocpair' else: defoctext = '' cmd = ''' makestack2.py --single=%s --fromstackid=%d %s %s %s %s %s --no-invert %s --boxsize=%d --bin=%d --description="frealign refinestack based on %s(id=%d)" --projectid=%d --preset=%s --runname=%s --rundir=%s --no-wait --no-commit --no-continue --session=%s --expId=%d --jobtype=makestack2 ''' % (os.path.basename(newstackimagicfile), stackid, lowpasstext, highpasstext, partlimittext, reversetext, defoctext, normtext, unbinnedboxsize, bin, stackpathname, stackid, projectid, presetname, newstackrunname, newstackrundir, sessionname, sessionid) logfilepath = os.path.join(newstackrundir, 'frealignstackrun.log') returncode = self.runAppionScriptInSubprocess(cmd, logfilepath) if returncode > 0: apDisplay.printError('Error in Frealign specific stack making') self.ImagicStackToFrealignMrcStack(newstackimagicfile) os.rename(newstackimagicfile[:-4] + '.mrc', newstackroot + '.mrc') self.setFrealignStack(newstackroot) # use the same complex equation as in eman clip clipsize = self.calcClipSize(self.stack['boxsize'], self.params['bin']) self.stack['boxsize'] = clipsize / self.params['bin'] self.stack['apix'] = self.stack['apix'] * self.params['bin'] #clean up rmfiles = glob.glob("*.box") for rmfile in rmfiles: apFile.removeFile(rmfile)
def convertToRefineStack(self): ''' The stack is remaked without ctf correction and without invertion (ccd) ''' newstackroot = os.path.join(self.params['rundir'],os.path.basename(self.stack['file'])[:-4]) if self.params['paramonly'] is True: print 'newstackroot',newstackroot self.setFrealignStack(newstackroot) return # copy existing refined stack if possible existing_refine_stack = apStack.getExistingRefineStack(self.stack['data'],'frealign',False,self.params['last'],self.params['bin'],lowpass=self.params['lowpass'],highpass=self.params['highpass']) if existing_refine_stack: if existing_refine_stack != os.path.join(self.params['rundir'],newstackroot+'.mrc'): shutil.copyfile(existing_refine_stack,newstackroot+'.mrc') new_partorderfile = os.path.join(self.params['rundir'],'stackpartorder.list') existing_partorderfile = os.path.join(os.path.dirname(existing_refine_stack),'stackpartorder.list') # particle order list also need to be copied if not os.path.isfile(new_partorderfile) and os.path.isfile(existing_partorderfile): shutil.copyfile(existing_partorderfile,new_partorderfile) self.setFrealignStack(newstackroot) return if self.no_ctf_correction: self.ImagicStackToFrealignMrcStack(self.stack['file']) self.setFrealignStack(newstackroot) return # stack need to be remade without ctf correction apDisplay.printWarning('Frealign needs a stack without ctf correction. A new stack is being made....') stackdata = self.stack['data'] madestackdata = self.getOriginalStackMadeByMakeStack() stackid = stackdata.dbid stackruns = apStack.getStackRunsFromStack(madestackdata) # To Do: need to handle combined stack stackrun = stackruns[0] stackpathname = os.path.basename(stackdata['path']['path']) totalpart = apStack.getNumberStackParticlesFromId(stackid) if not self.params['last']: numpart = totalpart else: numpart = min(self.params['last'],totalpart) newstackrunname = self.params['runname'] newstackrundir = self.params['rundir'] newstackimagicfile = os.path.join(newstackrundir,'temp.hed') # use first particle image to get presetname oneparticle = apStack.getOneParticleFromStackId(stackid, particlenumber=1) preset =oneparticle['particle']['image']['preset'] if preset: presetname = preset['name'] else: presetname = 'manual' # use first stack run to get parameters paramdata = stackrun['stackParams'] # binning is combination of the original binning of the stack and the preparation binnning bin = paramdata['bin']*self.params['bin'] unbinnedboxsize = self.stack['boxsize']*paramdata['bin'] lowpasstext = self.setArgText('lowpass',(self.params['lowpass'],paramdata['lowpass']),False) highpasstext = self.setArgText('highpass',(self.params['highpass'],paramdata['highpass']),True) partlimittext = self.setArgText('partlimit',(numpart,),False) xmipp_normtext = self.setArgText('xmipp-normalize',(paramdata['xmipp-norm'],),True) sessionid = int(self.params['expid']) sessiondata = apDatabase.getSessionDataFromSessionId(sessionid) sessionname = sessiondata['name'] projectid = self.params['projectid'] # The assumption is that the image is from ice grid and digital camera (black particles on white background if 'reverse' in self.stackrunlogparams.keys(): reversetext = '--reverse' else: reversetext = '' if 'defocpair' in self.stackrunlogparams.keys(): defoctext = '--defocpair' else: defoctext = '' cmd = ''' makestack2.py --single=%s --fromstackid=%d %s %s %s %s %s --no-invert --normalized %s --boxsize=%d --bin=%d --description="frealign refinestack based on %s(id=%d)" --projectid=%d --preset=%s --runname=%s --rundir=%s --no-wait --no-commit --no-continue --session=%s --expId=%d --jobtype=makestack2 ''' % (os.path.basename(newstackimagicfile),stackid,lowpasstext,highpasstext,partlimittext,reversetext,defoctext,xmipp_normtext,unbinnedboxsize,bin,stackpathname,stackid,projectid,presetname,newstackrunname,newstackrundir,sessionname,sessionid) logfilepath = os.path.join(newstackrundir,'frealignstackrun.log') returncode = self.runAppionScriptInSubprocess(cmd,logfilepath) if returncode > 0: apDisplay.printError('Error in Frealign specific stack making') self.ImagicStackToFrealignMrcStack(newstackimagicfile) os.rename(newstackimagicfile[:-4]+'.mrc',newstackroot+'.mrc') self.setFrealignStack(newstackroot) # use the same complex equation as in eman clip clipsize = self.calcClipSize(self.stack['boxsize'],self.params['bin']) self.stack['boxsize'] = clipsize / self.params['bin'] self.stack['apix'] = self.stack['apix'] * self.params['bin'] #clean up rmfiles = glob.glob("*.box") for rmfile in rmfiles: apFile.removeFile(rmfile)