def runIMAGICclassify(self): bfile = "msaclassify.job" outfile = "classes" apFile.removeStack(outfile) numIters = int(self.params['numpart']*self.params['itermult']) decrement = self.params['start']-self.params['end'] if self.params['iter']>0: decrement /= float(self.params['iter']) numClasses = self.params['start']-(decrement*self.params['currentiter']) stackfile = self.params['alignedstack'] self.params['currentnumclasses'] = numClasses f = open(bfile,'w') f.write("#!/bin/csh -f\n") f.write("setenv IMAGIC_BATCH 1\n") f.write("%s/msa/classify.e <<EOF\n" % self.imagicroot) f.write("IMAGES\n") f.write("%s\n"%stackfile) f.write("0\n") f.write("%i\n"%self.params['activeeigen']) f.write("YES\n") f.write("%i\n"%numClasses) f.write("classes_start\n") f.write("EOF\n") f.write("%s/msa/classum.e <<EOF\n" % self.imagicroot) f.write("%s\n"%stackfile) f.write("classes_start\n") f.write("%s\n"%outfile) f.write("YES\n") f.write("NONE\n") f.write("0\n") if int(self.imagicversion) >= 120619: f.write("NONE\n") # Mode of summing statistics f.write("EOF\n") ## make eigenimage stack appion-compatible f.write("proc2d eigenim.hed eigenim.hed inplace\n") f.write("touch msaclassify_done.txt\n") f.write("exit\n") f.close() ## execute the batch file aligntime0 = time.time() apEMAN.executeEmanCmd("chmod 755 "+bfile) apDisplay.printColor("Running IMAGIC .batch file: %s"%(os.path.abspath(bfile)), "cyan") apIMAGIC.executeImagicBatchFile(os.path.abspath(bfile)) os.remove("msaclassify_done.txt") if not os.path.exists(outfile+".hed"): apDisplay.printError("ERROR IN IMAGIC SUBROUTINE") apDisplay.printColor("finished IMAGIC in "+apDisplay.timeString(time.time()-aligntime0), "cyan")
def start(self): ### get analysis paramteres self.analysisdata = appiondata.ApAlignAnalysisRunData.direct_query(self.params['analysisId']) pixelsize = self.analysisdata['alignstack']['pixelsize'] boxsize = self.analysisdata['alignstack']['boxsize'] bin = self.analysisdata['imagicMSArun']['bin'] self.params['apix'] = float(pixelsize) * int(bin) self.params['boxsize'] = int(boxsize) / int(bin) self.params['num_particles'] = self.analysisdata['alignstack']['num_particles'] starttime=time.time() print self.params print "... stack pixel size: "+str(self.params['apix']) print "... stack box size: "+str(self.params['boxsize']) apDisplay.printColor("Running IMAGIC .batch file: See imagicMSAcluster log file(s) corresponding to # of classes for details", "cyan") ### insert run into database self.insertClusterRun() ### split the cluster numbers numclasslist = self.params['num_classes'].split(",") for item in numclasslist: numclusters = int(item) apDisplay.printColor("\n==========================\nprocessing class averages for " +str(numclusters)+" classes\n==========================\n", "green") ### create IMAGIC batch file batchfile = self.createImagicBatchFile(numclusters) ### execute IMAGIC batch file clustertime0 = time.time() proc = subprocess.Popen("chmod 775 "+str(batchfile), shell=True) proc.wait() apIMAGIC.executeImagicBatchFile(batchfile) logfile = open(os.path.join(self.params['rundir'], "imagicMSAcluster_classes_"+str(numclusters)+".log")) loglines = logfile.readlines() for line in loglines: if re.search("ERROR in program", line): apDisplay.printError("ERROR IN IMAGIC SUBROUTINE, please check the logfile: imagicMSAcluster_classes_"\ +str(numclusters)+".log") apDisplay.printColor("finished IMAGIC in "+apDisplay.timeString(time.time()-clustertime0), "cyan") ### normalize classfile = os.path.join(self.params['rundir'], self.params['classumfile']) emancmd = "proc2d "+classfile+" "+classfile+".norm.hed norm" while os.path.isfile(classfile+".norm.img"): apStack.removeStack(alignstack+".norm.img") apParam.runCmd(emancmd, "EMAN") os.rename(classfile+".norm.hed", classfile) os.rename(classfile+".norm.img", classfile[:-4]+".img") ### connect to database self.insertClusterStack(numclusters)
def runIMAGICmsa(self): bfile = "msa.job" outfile = "msaout" apFile.removeStack(outfile) stackfile = self.params['alignedstack'] # convert mask to fraction for imagic maskfrac = self.workingmask*2/self.workingboxsize ## make an msa mask file imagicFilters.mask2D(self.workingboxsize, maskfrac, maskfile='msamask') f = open(bfile,'w') f.write("#!/bin/csh -f\n") f.write("setenv IMAGIC_BATCH 1\n") if self.params['msaproc'] > 1: f.write("mpirun -np %i -x IMAGIC_BATCH %s/msa/msa.e_mpi << EOF\n" %(self.params['msaproc'],self.imagicroot)) if int(self.imagicversion) != 110119: f.write("YES\n") f.write("%i\n"%self.params['msaproc']) else: f.write("%s/msa/msa.e <<EOF\n" % self.imagicroot) if int(self.imagicversion) != 110326: f.write("NO\n") if int(self.imagicversion) != 110119 and int(self.imagicversion) != 100312: f.write("NO\n") f.write("FRESH_MSA\n") f.write("MODULATION\n") f.write("%s\n"%stackfile) if int(self.imagicversion) <= 100312: f.write("NO\n") f.write("msamask\n") f.write("eigenim\n") if int(self.imagicversion) < 120619: f.write("my_pixcoos\n") f.write("my_eigenpix\n") else: f.write("NO\n") f.write("%i\n"%self.params['msaiter']) f.write("%i\n"%self.params['numeigen']) if int(self.imagicversion) >= 120619: f.write("1\n") f.write("%.02f\n"%self.params['overcorrection']) f.write("%s\n"%outfile) f.write("EOF\n") f.write("touch msa_done.txt\n") f.write("exit\n") f.close() ## execute the batch file aligntime0 = time.time() apEMAN.executeEmanCmd("chmod 755 "+bfile) apDisplay.printColor("Running IMAGIC .batch file: %s"%(os.path.abspath(bfile)), "cyan") apIMAGIC.executeImagicBatchFile(os.path.abspath(bfile)) os.remove("msa_done.txt") if not os.path.exists(outfile+".plt"): apDisplay.printError("ERROR IN IMAGIC SUBROUTINE") apDisplay.printColor("finished IMAGIC in "+apDisplay.timeString(time.time()-aligntime0), "cyan") ## run classification & class averaging self.runIMAGICclassify() # align resulting classes self.alignClasses()
def runIMAGICmra(self): bfile = "mralign.job" outfile = "mrastack" apFile.removeStack(outfile) f = open(bfile,'w') f.write("#!/bin/csh -f\n") f.write("setenv IMAGIC_BATCH 1\n") if self.params['nproc'] > 1: f.write("mpirun -np %i -x IMAGIC_BATCH %s/align/mralign.e_mpi << EOF\n" %(self.params['nproc'],self.imagicroot)) if int(self.imagicversion) != 110119: f.write("YES\n") f.write("%i\n"%self.params['nproc']) else: f.write("%s/align/mralign.e <<EOF\n" % self.imagicroot) f.write("NO\n") f.write("FRESH\n") f.write("ALL\n") # 091120 or higher version 4D options: if int(self.imagicversion) >= 91120: f.write("ALIGNMENT\n") f.write("ALL\n") f.write("ROTATION_FIRST\n") f.write("CCF\n") f.write(self.params['alignedstack']+"\n") f.write(outfile+"\n") f.write(os.path.splitext(self.params['localstack'])[0]+"\n") f.write(self.params['currentcls']+"\n") f.write("NO_FILTER\n") # lower than 091120 version of imagic asks for mirrors: if int(self.imagicversion) < 91120: f.write("NO\n") f.write("0.31\n") # check if there are any rotations stored in the header #TEMPORARY HACK hasRots=False if self.params['currentiter'] > 1: hasRots=True # don't ask Max shift (during this alignment) for first iteration: if hasRots is True: f.write("0.2\n") f.write("-180,180\n") # don't ask rotation (during this alignment) for first iteration: if hasRots is True: f.write("-180,180\n") f.write("MEDIUM\n") f.write("0.0,%.2f\n"%(self.workingmask*2/self.workingboxsize)) f.write("2\n") f.write("NO\n") f.write("EOF\n") f.write("\n") ### write out alignment parameters to file f.write("%s/stand/headers.e <<EOF\n" % self.imagicroot) if int(self.imagicversion) < 91120: f.write(outfile+"\n") f.write("PLT\n") f.write("SHIFT\n") f.write("outparams.plt\n") f.write("*\n") else: f.write("PLT\n") f.write("SHIFT\n") f.write(outfile+"\n") f.write("outparams.plt\n") f.write("EOF\n") f.write("touch mra_done.txt\n") f.write("exit\n") f.close() ## execute the batch file aligntime0 = time.time() apEMAN.executeEmanCmd("chmod 755 "+bfile) apDisplay.printColor("Running IMAGIC .batch file: %s"%(os.path.abspath(bfile)), "cyan") apIMAGIC.executeImagicBatchFile(os.path.abspath(bfile)) os.remove("mra_done.txt") if not os.path.exists(outfile+".hed"): apDisplay.printError("ERROR IN IMAGIC SUBROUTINE") apDisplay.printColor("finished IMAGIC in "+apDisplay.timeString(time.time()-aligntime0), "cyan") if self.params['currentiter'] > 1: apFile.removeStack(self.params['alignedstack']) self.params['alignedstack']=os.path.abspath(outfile) self.params['alignedstack'] = string.replace(self.params['alignedstack'],"/jetstor/APPION","")