### get all particle data for this iteration particledata = self.readParticleFile(iteration, reference_number) self.insertRefinementParticleData(particledata, iterationParamsq, referenceParamsq) ### create euler freq map if self.params['commit'] is True: apDisplay.printMsg("creating euler frequency map") if self.package != 'EMAN': postrefine = True else: postrefine = False apEulerDraw.createEulerImages(self.refinerunq.dbid, iteration, path=self.params['rundir'], postrefine=postrefine) for f in glob.glob("euler**png"): shutil.move(f, os.path.join(self.resultspath, f)) return #================== def insertRefinementParticleData(self, particledata, iterationParamsq, referenceParamsq, euler_convention='zxz'): ''' inserts all particle data into database, based on parameters from text file ''' apDisplay.printMsg(
def insertIteration(self, iteration): refineparamsq = appiondata.ApEmanRefineIterData() refineparamsq['ang'] = iteration['ang'] refineparamsq['lpfilter'] = iteration['lpfilter'] refineparamsq['hpfilter'] = iteration['hpfilter'] refineparamsq['pad'] = iteration['pad'] refineparamsq['EMAN_maxshift'] = iteration['maxshift'] refineparamsq['EMAN_hard'] = iteration['hard'] refineparamsq['EMAN_classkeep'] = iteration['classkeep'] refineparamsq['EMAN_classiter'] = iteration['classiter'] refineparamsq['EMAN_filt3d'] = iteration['filt3d'] refineparamsq['EMAN_shrink'] = iteration['shrink'] refineparamsq['EMAN_euler2'] = iteration['euler2'] refineparamsq['EMAN_xfiles'] = iteration['xfiles'] refineparamsq['EMAN_median'] = iteration['median'] refineparamsq['EMAN_phasecls'] = iteration['phasecls'] refineparamsq['EMAN_fscls'] = iteration['fscls'] refineparamsq['EMAN_refine'] = iteration['refine'] refineparamsq['EMAN_goodbad'] = iteration['goodbad'] refineparamsq['EMAN_perturb'] = iteration['perturb'] refineparamsq['MsgP_cckeep'] = iteration['msgpasskeep'] refineparamsq['MsgP_minptls'] = iteration['msgpassminp'] #create Chimera snapshots fscfile = os.path.join(self.params['rundir'], "fsc.eotest." + iteration['num']) halfres = apRecon.calcRes(fscfile, self.params['boxsize'], self.params['apix']) if self.params['snapfilter']: halfres = self.params['snapfilter'] volumeDensity = 'threed.' + iteration['num'] + 'a.mrc' volDensPath = os.path.join(self.params['rundir'], volumeDensity) apChimera.filterAndChimera(volDensPath, halfres, self.params['apix'], self.params['boxsize'], 'snapshot', self.params['contour'], self.params['zoom'], sym=iteration['sym']['eman_name'], mass=self.params['mass']) ## uncommment this for chimera image only runs... if self.params['chimeraonly'] is True: return # insert resolution data if halfres != True: resData = self.getResolutionData(iteration) else: apDisplay.printWarning( "resolution reported as nan, not committing results to database" ) return if self.params['package'] == 'EMAN': refineclassavg = 'classes_eman.' + iteration['num'] + '.img' postrefineclassavg = None elif self.params['package'] == 'EMAN/SpiCoran': refineclassavg = 'classes_eman.' + iteration['num'] + '.img' postrefineclassavg = 'classes_coran.' + iteration['num'] + '.img' elif self.params['package'] == 'EMAN/MsgP': refineclassavg = 'classes_eman.' + iteration['num'] + '.img' postrefineclassavg = 'classes_msgp.' + iteration['num'] + '.img' else: apDisplay.printError("Refinement Package Not Valid") # insert refinement results refineq = appiondata.ApRefineIterData() refineq['refineRun'] = self.params['refineRun'] refineq['emanParams'] = refineparamsq refineq['iteration'] = iteration['num'] refineq['resolution'] = resData refineq['rMeasure'] = self.getRMeasureData(iteration) refineq['mask'] = iteration['mask'] refineq['imask'] = iteration['imask'] refineq['symmetry'] = iteration['sym'] refineq['exemplar'] = False classvar = 'classes.' + iteration['num'] + '.var.img' refineq['refineClassAverages'] = refineclassavg refineq['postRefineClassAverages'] = postrefineclassavg if classvar in self.params['classvars']: refineq['classVariance'] = classvar if volumeDensity in self.params['volumes']: refineq['volumeDensity'] = volumeDensity apDisplay.printMsg("inserting Refinement Data into database") if self.params['commit'] is True: refineq.insert() else: apDisplay.printWarning("not committing results to database") #insert FSC data fscfile = os.path.join(self.params['rundir'], "fsc.eotest." + iteration['num']) self.insertFSC(fscfile, refineq, self.params['commit']) halfres = apRecon.calcRes(fscfile, self.params['boxsize'], self.params['apix']) apDisplay.printColor("FSC 0.5 Resolution: " + str(halfres), "cyan") # get projections eulers for iteration: eulers = self.getEulersFromProj(iteration['num']) # get list of bad particles for this iteration badprtls = self.readParticleLog(self.params['rundir'], iteration['num']) # expand cls.*.tar into temp file clsf = os.path.join(self.params['rundir'], "cls." + iteration['num'] + ".tar") #print "reading",clsf clstar = tarfile.open(clsf) clslist = clstar.getmembers() clsnames = clstar.getnames() #print "extracting",clsf,"into temp directory" for clsfile in clslist: clstar.extract(clsfile, self.params['tmpdir']) clstar.close() # for each class, insert particle alignment info into database apDisplay.printColor( "Inserting Particle Classification Data for " + str(len(clsnames)) + " classes", "magenta") t0 = time.time() for cls in clsnames: self.insertRefineParticleData(cls, iteration, eulers, badprtls, refineq, len(clsnames)) apDisplay.printColor( "\nFinished in " + apDisplay.timeString(time.time() - t0), "magenta") # remove temp directory for file in os.listdir(self.params['tmpdir']): os.remove(os.path.join(self.params['tmpdir'], file)) os.rmdir(self.params['tmpdir']) #create euler freq map apDisplay.printMsg("creating euler frequency map") refrunid = int(self.params['refineRun'].dbid) iternum = int(iteration['num']) if self.params['package'] != 'EMAN': postrefine = True else: postrefine = False apEulerDraw.createEulerImages(refrunid, iternum, path=self.params['rundir'], postrefine=postrefine) return
apDisplay.printWarning("not committing results to database") ### get all particle data for this iteration particledata = self.readParticleFile(iteration, reference_number) self.insertRefinementParticleData(particledata, iterationParamsq, referenceParamsq) ### create euler freq map if self.params["commit"] is True: apDisplay.printMsg("creating euler frequency map") if self.package != "EMAN": postrefine = True else: postrefine = False apEulerDraw.createEulerImages( self.refinerunq.dbid, iteration, path=self.params["rundir"], postrefine=postrefine ) for f in glob.glob("euler**png"): shutil.move(f, os.path.join(self.resultspath, f)) return # ================== def insertRefinementParticleData(self, particledata, iterationParamsq, referenceParamsq, euler_convention="zxz"): """ inserts all particle data into database, based on parameters from text file """ apDisplay.printMsg("inserting particle data into database ... this may take some time") for i in range(len(particledata)): prtlq = appiondata.ApRefineParticleData()
def insertIteration(self, iteration): refineparamsq=appiondata.ApEmanRefineIterData() refineparamsq['ang']=iteration['ang'] refineparamsq['lpfilter']=iteration['lpfilter'] refineparamsq['hpfilter']=iteration['hpfilter'] refineparamsq['pad']=iteration['pad'] refineparamsq['EMAN_maxshift']=iteration['maxshift'] refineparamsq['EMAN_hard']=iteration['hard'] refineparamsq['EMAN_classkeep']=iteration['classkeep'] refineparamsq['EMAN_classiter']=iteration['classiter'] refineparamsq['EMAN_filt3d']=iteration['filt3d'] refineparamsq['EMAN_shrink']=iteration['shrink'] refineparamsq['EMAN_euler2']=iteration['euler2'] refineparamsq['EMAN_xfiles']=iteration['xfiles'] refineparamsq['EMAN_median']=iteration['median'] refineparamsq['EMAN_phasecls']=iteration['phasecls'] refineparamsq['EMAN_fscls']=iteration['fscls'] refineparamsq['EMAN_refine']=iteration['refine'] refineparamsq['EMAN_goodbad']=iteration['goodbad'] refineparamsq['EMAN_perturb']=iteration['perturb'] refineparamsq['MsgP_cckeep']=iteration['msgpasskeep'] refineparamsq['MsgP_minptls']=iteration['msgpassminp'] #create Chimera snapshots fscfile = os.path.join(self.params['rundir'], "fsc.eotest."+iteration['num']) halfres = apRecon.calcRes(fscfile, self.params['boxsize'], self.params['apix']) if self.params['snapfilter']: halfres = self.params['snapfilter'] volumeDensity = 'threed.'+iteration['num']+'a.mrc' volDensPath = os.path.join(self.params['rundir'], volumeDensity) apChimera.filterAndChimera(volDensPath, halfres, self.params['apix'], self.params['boxsize'], 'snapshot', self.params['contour'], self.params['zoom'], sym=iteration['sym']['eman_name'], mass=self.params['mass']) ## uncommment this for chimera image only runs... if self.params['chimeraonly'] is True: return # insert resolution data if halfres != True: resData = self.getResolutionData(iteration) else: apDisplay.printWarning("resolution reported as nan, not committing results to database") return if self.params['package']== 'EMAN': refineclassavg='classes_eman.'+iteration['num']+'.img' postrefineclassavg=None elif self.params['package']== 'EMAN/SpiCoran': refineclassavg='classes_eman.'+iteration['num']+'.img' postrefineclassavg='classes_coran.'+iteration['num']+'.img' elif self.params['package']== 'EMAN/MsgP': refineclassavg='classes_eman.'+iteration['num']+'.img' postrefineclassavg='classes_msgp.'+iteration['num']+'.img' else: apDisplay.printError("Refinement Package Not Valid") # insert refinement results refineq = appiondata.ApRefineIterData() refineq['refineRun'] = self.params['refineRun'] refineq['emanParams'] = refineparamsq refineq['iteration'] = iteration['num'] refineq['resolution'] = resData refineq['rMeasure'] = self.getRMeasureData(iteration) refineq['mask'] = iteration['mask'] refineq['imask'] = iteration['imask'] refineq['symmetry']=iteration['sym'] refineq['exemplar'] = False classvar = 'classes.'+iteration['num']+'.var.img' refineq['refineClassAverages'] = refineclassavg refineq['postRefineClassAverages'] = postrefineclassavg if classvar in self.params['classvars']: refineq['classVariance'] = classvar if volumeDensity in self.params['volumes']: refineq['volumeDensity'] = volumeDensity apDisplay.printMsg("inserting Refinement Data into database") if self.params['commit'] is True: refineq.insert() else: apDisplay.printWarning("not committing results to database") #insert FSC data fscfile = os.path.join(self.params['rundir'], "fsc.eotest."+iteration['num']) self.insertFSC(fscfile, refineq, self.params['commit']) halfres = apRecon.calcRes(fscfile, self.params['boxsize'], self.params['apix']) apDisplay.printColor("FSC 0.5 Resolution: "+str(halfres), "cyan") # get projections eulers for iteration: eulers = self.getEulersFromProj(iteration['num']) # get list of bad particles for this iteration badprtls = self.readParticleLog(self.params['rundir'], iteration['num']) # expand cls.*.tar into temp file clsf=os.path.join(self.params['rundir'], "cls."+iteration['num']+".tar") #print "reading",clsf clstar=tarfile.open(clsf) clslist=clstar.getmembers() clsnames=clstar.getnames() #print "extracting",clsf,"into temp directory" for clsfile in clslist: clstar.extract(clsfile,self.params['tmpdir']) clstar.close() # for each class, insert particle alignment info into database apDisplay.printColor("Inserting Particle Classification Data for " +str(len(clsnames))+" classes", "magenta") t0 = time.time() for cls in clsnames: self.insertRefineParticleData(cls, iteration, eulers, badprtls, refineq, len(clsnames)) apDisplay.printColor("\nFinished in "+apDisplay.timeString(time.time()-t0), "magenta") # remove temp directory for file in os.listdir(self.params['tmpdir']): os.remove(os.path.join(self.params['tmpdir'],file)) os.rmdir(self.params['tmpdir']) #create euler freq map apDisplay.printMsg("creating euler frequency map") refrunid = int(self.params['refineRun'].dbid) iternum = int(iteration['num']) if self.params['package'] != 'EMAN': postrefine = True else: postrefine = False apEulerDraw.createEulerImages(refrunid, iternum, path=self.params['rundir'], postrefine=postrefine) return