def checkConflicts(self): if self.params['sessionname'] is None: apDisplay.printError( "Enter a session name (e.g. --session=06jul12a)") if self.params['projectid'] is not None: projid = apProject.getProjectIdFromSessionName( self.params['sessionname']) if projid != self.params['projectid']: apDisplay.printError( "Project ID and Session name do not match") if self.params['description'] is None: apDisplay.printError("Enter a description of the initial model") if self.params['chimeraonly'] is True: self.params['commit'] = False if self.params['newbox'] is not None and self.params['newbox'] % 8 != 0: apDisplay.printWarning("Box size is not a multiple of 8") ### program requires either a model id or density id or filename checkvalue = int(self.params['file'] is not None) checkvalue += int(self.params['oldmodelid'] is not None) checkvalue += int(self.params['densityid'] is not None) if checkvalue != 1: apDisplay.printError( "Either provide a modelid or densityid or file, but not more than one of them" ) elif self.params[ 'oldmodelid'] is not None and self.params['newbox'] is None: apDisplay.printError( "Please specify either a new boxsize or scale for your model") elif self.params['densityid'] is not None: self.getDensityParams() elif self.params['oldmodelid'] is not None: self.getModelParams() elif self.params['file'] is not None: if not os.path.isfile(self.params['file']): apDisplay.printError("could not find file: " + self.params['file']) if self.params['file'][-4:] != ".mrc": apDisplay.printError("uploadModel.py only supports MRC files") self.params['file'] = os.path.abspath(self.params['file']) else: apDisplay.printError( "Please provide either a --modelid=112 or --file=initmodel.mrc" ) ### required only if now model id is provided if self.params['newapix'] is None: apDisplay.printError("Enter the pixel size of the model") if self.params['symmetry'] is None: apSymmetry.printSymmetries() apDisplay.printError("Enter a symmetry ID, e.g. --symm=19") self.params['symdata'] = apSymmetry.findSymmetry( self.params['symmetry']) if self.params['res'] is None: apDisplay.printError("Enter the resolution of the initial model") self.params['oldbox'] = apVolume.getModelDimensions( self.params['file']) if self.params['newbox'] is None: self.params['newbox'] = self.params['oldbox'] if self.params['oldapix'] is None: self.params['oldapix'] = self.params['newapix']
def start(self): mrcfile = self.params['file'] ### bin the volume if self.params['bin'] is not None and self.params['bin'] > 1: apDisplay.printMsg("Binning volume") newmrcfile = os.path.join(os.getcwd(), "binned.mrc") voldata = mrc.read(mrcfile) voldata = imagefun.bin3(voldata, self.params['bin']) mrc.write(voldata, newmrcfile) del voldata self.params['apix'] *= self.params['bin'] if os.path.isfile(newmrcfile): mrcfile = newmrcfile ### scale by mass if self.params['mass'] is not None: apDisplay.printMsg("Using scale by mass method") newmrcfile = os.path.join(os.getcwd(), "setmass.mrc") shutil.copy(self.params['file'], newmrcfile) apChimera.setVolumeMass(newmrcfile, apix=self.params['apix'], mass=self.params['mass']) self.params['contour'] = 1.0 if os.path.isfile(newmrcfile): mrcfile = newmrcfile ### print stats box = apVolume.getModelDimensions(mrcfile) apDisplay.printColor("Box: %d Apix: %.2f File: %s"% (box, self.params['apix'], os.path.basename(mrcfile)), "green") ### animation if self.params['type'] != "snapshot": apDisplay.printMsg("Creating animation") apChimera.renderAnimation(mrcfile, contour=self.params['contour'], zoom=self.params['zoom'], sym=self.params['sym'], color=self.params['color'], xvfb=self.params['xvfb'], name=self.params['file'], silhouette=self.params['silhouette']) ### snapshot if self.params['type'] != "animate": apDisplay.printMsg("Creating snapshots") apChimera.renderSnapshots(mrcfile, contour=self.params['contour'], zoom=self.params['zoom'], sym=self.params['sym'], color=self.params['color'], xvfb=self.params['xvfb'], pdb=self.params['pdb'], name=self.params['file'], silhouette=self.params['silhouette']) ### clean up if self.params['mass'] is not None or self.params['bin'] is not None: images = glob.glob(mrcfile+"*") for img in images: newimg = re.sub(mrcfile, self.params['file'], img) shutil.move(img, newimg) apFile.removeFile(mrcfile)
def checkConflicts(self): if self.params['sessionname'] is None: apDisplay.printError("Enter a session name (e.g. --session=06jul12a)") if self.params['projectid'] is not None: projid = apProject.getProjectIdFromSessionName(self.params['sessionname']) if projid != self.params['projectid']: apDisplay.printError("Project ID and Session name do not match") if self.params['description'] is None: apDisplay.printError("Enter a description of the initial model") if self.params['chimeraonly'] is True: self.params['commit'] = False if self.params['newbox'] is not None and self.params['newbox'] % 8 != 0: apDisplay.printWarning("Box size is not a multiple of 8") ### program requires either a model id or density id or filename checkvalue = int(self.params['file'] is not None) checkvalue += int(self.params['oldmodelid'] is not None) checkvalue += int(self.params['densityid'] is not None) if checkvalue != 1: apDisplay.printError("Either provide a modelid or densityid or file, but not more than one of them") elif self.params['oldmodelid'] is not None and self.params['newbox'] is None: apDisplay.printError("Please specify either a new boxsize or scale for your model") elif self.params['densityid'] is not None: self.getDensityParams() elif self.params['oldmodelid'] is not None: self.getModelParams() elif self.params['file'] is not None: if not os.path.isfile(self.params['file']): apDisplay.printError("could not find file: "+self.params['file']) if self.params['file'][-4:] != ".mrc": apDisplay.printError("uploadModel.py only supports MRC files") self.params['file'] = os.path.abspath(self.params['file']) else: apDisplay.printError("Please provide either a --modelid=112 or --file=initmodel.mrc") ### required only if now model id is provided if self.params['newapix'] is None: apDisplay.printError("Enter the pixel size of the model") if self.params['symmetry'] is None: apSymmetry.printSymmetries() apDisplay.printError("Enter a symmetry ID, e.g. --symm=19") self.params['symdata'] = apSymmetry.findSymmetry(self.params['symmetry']) if self.params['res'] is None: apDisplay.printError("Enter the resolution of the initial model") self.params['oldbox'] = apVolume.getModelDimensions(self.params['file']) if self.params['newbox'] is None: self.params['newbox'] = self.params['oldbox'] if self.params['oldapix'] is None: self.params['oldapix'] = self.params['newapix']
def start(self): ### start the outfile name fileroot = os.path.splitext(self.params['filename'])[0] fileroot += "-"+self.timestamp filename = self.params['file'].split('/')[-1] filepath = self.params['file'].strip(filename) self.params['box'] = apVolume.getModelDimensions(self.params['file']) if self.params['ampfile'] is not None: ### run amplitude correction spifile = apVolume.MRCtoSPI(self.params['file'], self.params['rundir']) tmpfile = apAmpCorrect.createAmpcorBatchFile(spifile, self.params) apAmpCorrect.runAmpcor() ### check if spider was successful fileroot += ".amp" if not os.path.isfile(tmpfile) : apDisplay.printError("amplitude correction failed") ### convert amplitude corrected file back to mrc fileroot += ".amp" a = spider.read(tmpfile) outfile = os.path.join( self.params['rundir'], "ampl-fix.mrc" ) mrc.write(a, outfile) curfile = outfile elif self.params['bfactor'] is True: outfile = os.path.join( self.params['rundir'], "bfactor-fix.mrc" ) outfile = apAmpCorrect.applyBfactor(self.params['file'], fscfile=self.params['fscfile'], apix=self.params['apix'], mass=self.params['mass'], outfile=outfile) curfile = outfile elif self.params['lrdw'] is True: lrdwcmd = "s_diffmap2 %s %s %s %s"%(self.params['filepath'],self.params['filename'],self.params['ampx'],self.params['resol']) proc = subprocess.Popen(lrdwcmd) print lrdwcmd else : ### just run proc3d curfile = self.params['file'] emancmd = "proc3d "+self.params['file']+" " emancmd = "proc3d "+curfile+" " if self.params['median'] is not None: data = mrc.read(curfile) data = ndimage.median_filter(data, size=self.params['median']) mrc.write(data, curfile) emancmd+="apix=%s " %self.params['apix'] if self.params['lp'] is not None: fileroot += (".lp%d" % ( int(self.params['lp']), )) emancmd += "lp=%d " %self.params['lp'] if self.params['yflip'] is True: fileroot += ".yflip" emancmd +="yflip " if self.params['invert'] is True: fileroot += ".inv" emancmd +="mult=-1 " if self.params['viper'] is True: fileroot += ".vip" emancmd +="icos5fTo2f " if self.params['mask'] is not None: # convert ang to pixels maskpix=int(self.params['mask']/self.params['apix']) fileroot += (".m%d" % ( int(self.params['mask']), )) emancmd += "mask=%d " %maskpix self.params['mask'] = maskpix if self.params['imask'] is not None: # convert ang to pixels maskpix=int(self.params['imask']/self.params['apix']) fileroot += (".im%d" % ( int(self.params['imask']), )) emancmd += "imask=%d " %maskpix self.params['imask'] = maskpix if self.params['norm'] is True: fileroot += ".norm" emancmd += "norm=0,1 " ### add output filename to emancmd string fileroot += ".mrc" self.params['name'] = fileroot outfile = os.path.join(self.params['rundir'], fileroot) emancmd = re.sub(" apix=",(" %s apix=" % outfile), emancmd) apEMAN.executeEmanCmd(emancmd) if self.params['description'] is None: self.params['description'] = "Volume from recon with amplitude adjustment" ### clean up files created during amp correction if self.params['ampfile'] is not None: apFile.removeFile(spifile) apFile.removeFile(tmpfile) if self.params['commit'] is True: symdata = apSymmetry.findSymmetry(self.params['sym']) print symdata symmetry = symdata['eman_name'] self.params['reconid'] = self.params['reconiterid'] self.insert3dDensity() ### render chimera images of model apChimera.filterAndChimera(outfile, res=self.params['res'], apix=self.params['apix'], box=self.params['box'], chimtype='snapshot', mass=self.params['mass'], contour=self.params['contour'], zoom=self.params['zoom'], sym=symmetry)
def start(self): self.params['outputstack'] = os.path.join(self.params['rundir'], self.params['stackname']) particles, self.params['refineiter'] = getParticleInfo( self.params['reconid'], self.params['iter']) stackdata = particles[0]['particle']['stack'] stack = os.path.join(stackdata['path']['path'], stackdata['name']) classes, cstats = determineClasses(particles) rejectlst = [] if self.params['sigma'] is not None: cutoff = cstats[ 'meanquality'] + self.params['sigma'] * cstats['stdquality'] apDisplay.printMsg("Cutoff = " + str(cutoff)) rejectlst = self.removePtclsByQualityFactor( particles, rejectlst, cutoff) if self.params['avgjump'] is not None: rejectlst = self.removePtclsByJumps(particles, rejectlst) if self.params['rejectlst']: rejectlst = removePtclsByLst(rejectlst, self.params) classkeys = classes.keys() classkeys.sort() classnum = 0 totalptcls = 0 keepfile = open('keep.lst', 'w') keepfile.write('#LST\n') reject = open('reject.lst', 'w') reject.write('#LST\n') apDisplay.printMsg("Processing classes") #loop through classes for key in classkeys: # file to hold particles of this class clsfile = open('clstmp.lst', 'w') clsfile.write('#LST\n') classnum += 1 if classnum % 10 == 1: apDisplay.printMsg( str(classnum) + " of " + (str(len(classkeys)))) images = EMAN.EMData() #loop through particles in class nptcls = 0 for ptcl in classes[key]['particles']: if ptcl['mirror']: mirror = 1 else: mirror = 0 rot = ptcl['euler3'] rot = rot * math.pi / 180 if ptcl['particle']['particleNumber'] not in rejectlst: l = '%d\t%s\t%f,\t%f,%f,%f,%d\n' % ( ptcl['particle']['particleNumber'] - 1, stack, ptcl['quality_factor'], rot, ptcl['shiftx'], ptcl['shifty'], mirror) keepfile.write(l) clsfile.write(l) totalptcls += 1 nptcls += 1 else: reject.write('%d\t%s\t%f,\t%f,%f,%f,%d\n' % (ptcl['particle']['particleNumber'] - 1, stack, ptcl['quality_factor'], rot, ptcl['shiftx'], ptcl['shifty'], mirror)) #if ptcl['quality_factor']>cstats['meanquality']+3*cstats['stdquality']: # high.write('%d\t%s\t%f,\t%f,%f,%f,%d\n' % (ptcl['particle']['particleNumber']-1, # stack,ptcl['quality_factor'],rot,ptcl['shiftx'],ptcl['shifty'],mirror)) clsfile.close() if nptcls < 1: continue if self.params['skipavg'] is False: makeClassAverages('clstmp.lst', self.params['outputstack'], classes[key], self.params) if self.params['eotest'] is True: self.makeEvenOddClasses('clstmp.lst', classes[key]) apDisplay.printMsg("\n") reject.close() keepfile.close() os.remove('clstmp.lst') # make 3d density file if specified: if self.params['make3d'] is not None: self.params['make3d'] = os.path.basename(self.params['make3d']) outfile = os.path.join(self.params['rundir'], self.params['make3d']) apEMAN.make3d(self.params['stackname'], outfile, sym=self.params['sym'], mode=self.params['mode'], hard=self.params['hard']) apEMAN.executeEmanCmd("proc3d %s %s mask=%d norm" % (outfile, outfile, self.params['mask'])) if self.params['eotest'] is True: apEMAN.make3d(self.params['oddstack'], "odd.mrc", sym=self.params['sym'], mode=self.params['mode'], hard=self.params['hard']) apEMAN.make3d(self.params['evenstack'], "even.mrc", sym=self.params['sym'], mode=self.params['mode'], hard=self.params['hard']) apEMAN.executeEmanCmd("proc3d odd.mrc even.mrc fsc=fsc.eotest") if os.path.exists(outfile): # run rmeasure apix = apStack.getStackPixelSizeFromStackId(self.params['stackid']) box = apVolume.getModelDimensions(outfile) apDisplay.printMsg('inserting density into database') symdata = apSymmetry.findSymmetry(self.params['sym']) if not symdata: apDisplay.printError('no symmetry associated with this model') modq = appiondata.Ap3dDensityData() modq['session'] = apStack.getSessionDataFromStackId( self.params['stackid']) modq['name'] = self.params['make3d'] modq['path'] = appiondata.ApPathData( path=os.path.abspath(self.params['rundir'])) modq['boxsize'] = box modq['mask'] = self.params['mask'] modq['pixelsize'] = apix fscres = apRecon.getResolutionFromFSCFile('fsc.eotest', box, apix, msg=True) modq['resolution'] = fscres modq['rmeasure'] = apRecon.runRMeasure(apix, outfile) modq['md5sum'] = apFile.md5sumfile(outfile) modq['maxjump'] = self.params['avgjump'] modq['sigma'] = self.params['sigma'] modq['hard'] = self.params['hard'] modq['symmetry'] = symdata modq['refineIter'] = self.params['refineiter'] if self.params['commit'] is True: modq.insert() apChimera.filterAndChimera(outfile, res=fscres, apix=apix, box=box, chimtype='snapshot', zoom=self.params['zoom'], sym=self.params['sym'], mass=self.params['mass']) else: apDisplay.printError( 'no 3d volume was generated - check the class averages:') apDisplay.printError(self.params['stackname']) apDisplay.printError( 'hard may be set too high, or avg euler jump set too low for the # of particles' ) stackstr = str(stackdata.dbid) reconstr = str(self.params['reconid']) apDisplay.printColor( "Make a new stack with only non-jumpers:\n" + "subStack.py --projectid=" + str(self.params['projectid']) + " -s " + stackstr + " \\\n " + " -k " + os.path.join(self.params['rundir'], "keep.lst") + " \\\n " + " -d 'recon " + reconstr + " sitters' -n sitters" + reconstr + " -C ", "purple")
def start(self): self.params["outputstack"] = os.path.join(self.params["rundir"], self.params["stackname"]) particles, self.params["refineiter"] = getParticleInfo(self.params["reconid"], self.params["iter"]) stackdata = particles[0]["particle"]["stack"] stack = os.path.join(stackdata["path"]["path"], stackdata["name"]) classes, cstats = determineClasses(particles) rejectlst = [] if self.params["sigma"] is not None: cutoff = cstats["meanquality"] + self.params["sigma"] * cstats["stdquality"] apDisplay.printMsg("Cutoff = " + str(cutoff)) rejectlst = self.removePtclsByQualityFactor(particles, rejectlst, cutoff) if self.params["avgjump"] is not None: rejectlst = self.removePtclsByJumps(particles, rejectlst) if self.params["rejectlst"]: rejectlst = removePtclsByLst(rejectlst, self.params) classkeys = classes.keys() classkeys.sort() classnum = 0 totalptcls = 0 keepfile = open("keep.lst", "w") keepfile.write("#LST\n") reject = open("reject.lst", "w") reject.write("#LST\n") apDisplay.printMsg("Processing classes") # loop through classes for key in classkeys: # file to hold particles of this class clsfile = open("clstmp.lst", "w") clsfile.write("#LST\n") classnum += 1 if classnum % 10 == 1: apDisplay.printMsg(str(classnum) + " of " + (str(len(classkeys)))) images = EMAN.EMData() # loop through particles in class nptcls = 0 for ptcl in classes[key]["particles"]: if ptcl["mirror"]: mirror = 1 else: mirror = 0 rot = ptcl["euler3"] rot = rot * math.pi / 180 if ptcl["particle"]["particleNumber"] not in rejectlst: l = "%d\t%s\t%f,\t%f,%f,%f,%d\n" % ( ptcl["particle"]["particleNumber"] - 1, stack, ptcl["quality_factor"], rot, ptcl["shiftx"], ptcl["shifty"], mirror, ) keepfile.write(l) clsfile.write(l) totalptcls += 1 nptcls += 1 else: reject.write( "%d\t%s\t%f,\t%f,%f,%f,%d\n" % ( ptcl["particle"]["particleNumber"] - 1, stack, ptcl["quality_factor"], rot, ptcl["shiftx"], ptcl["shifty"], mirror, ) ) # if ptcl['quality_factor']>cstats['meanquality']+3*cstats['stdquality']: # high.write('%d\t%s\t%f,\t%f,%f,%f,%d\n' % (ptcl['particle']['particleNumber']-1, # stack,ptcl['quality_factor'],rot,ptcl['shiftx'],ptcl['shifty'],mirror)) clsfile.close() if nptcls < 1: continue if self.params["skipavg"] is False: makeClassAverages("clstmp.lst", self.params["outputstack"], classes[key], self.params) if self.params["eotest"] is True: self.makeEvenOddClasses("clstmp.lst", classes[key]) apDisplay.printMsg("\n") reject.close() keepfile.close() os.remove("clstmp.lst") # make 3d density file if specified: if self.params["make3d"] is not None: self.params["make3d"] = os.path.basename(self.params["make3d"]) outfile = os.path.join(self.params["rundir"], self.params["make3d"]) apEMAN.make3d( self.params["stackname"], outfile, sym=self.params["sym"], mode=self.params["mode"], hard=self.params["hard"], ) apEMAN.executeEmanCmd("proc3d %s %s mask=%d norm" % (outfile, outfile, self.params["mask"])) if self.params["eotest"] is True: apEMAN.make3d( self.params["oddstack"], "odd.mrc", sym=self.params["sym"], mode=self.params["mode"], hard=self.params["hard"], ) apEMAN.make3d( self.params["evenstack"], "even.mrc", sym=self.params["sym"], mode=self.params["mode"], hard=self.params["hard"], ) apEMAN.executeEmanCmd("proc3d odd.mrc even.mrc fsc=fsc.eotest") if os.path.exists(outfile): # run rmeasure apix = apStack.getStackPixelSizeFromStackId(self.params["stackid"]) box = apVolume.getModelDimensions(outfile) apDisplay.printMsg("inserting density into database") symdata = apSymmetry.findSymmetry(self.params["sym"]) if not symdata: apDisplay.printError("no symmetry associated with this model") modq = appiondata.Ap3dDensityData() modq["session"] = self.params["sessionname"] modq["name"] = self.params["make3d"] modq["path"] = appiondata.ApPathData(path=os.path.abspath(self.params["rundir"])) modq["boxsize"] = box modq["mask"] = self.params["mask"] modq["pixelsize"] = apix fscres = apRecon.getResolutionFromFSCFile("fsc.eotest", box, apix, msg=True) modq["resolution"] = fscres modq["rmeasure"] = apRecon.runRMeasure(apix, outfile) modq["md5sum"] = apFile.md5sumfile(outfile) modq["maxjump"] = self.params["avgjump"] modq["sigma"] = self.params["sigma"] modq["hard"] = self.params["hard"] modq["symmetry"] = symdata modq["refineIter"] = self.params["refineiter"] if self.params["commit"] is True: modq.insert() apChimera.filterAndChimera( outfile, res=fscres, apix=apix, box=box, chimtype="snapshot", zoom=self.params["zoom"], sym=self.params["sym"], mass=self.params["mass"], ) else: apDisplay.printError("no 3d volume was generated - check the class averages:") apDisplay.printError(self.params["stackname"]) apDisplay.printError("hard may be set too high, or avg euler jump set too low for the # of particles") stackstr = str(stackdata.dbid) reconstr = str(self.params["reconid"]) apDisplay.printColor( "Make a new stack with only non-jumpers:\n" + "subStack.py --projectid=" + str(self.params["projectid"]) + " -s " + stackstr + " \\\n " + " -k " + os.path.join(self.params["rundir"], "keep.lst") + " \\\n " + " -d 'recon " + reconstr + " sitters' -n sitters" + reconstr + " -C ", "purple", )
def start(self): mrcfile = self.params['file'] ### bin the volume if self.params['bin'] is not None and self.params['bin'] > 1: apDisplay.printMsg("Binning volume") newmrcfile = os.path.join(os.getcwd(), "binned.mrc") voldata = mrc.read(mrcfile) voldata = imagefun.bin3(voldata, self.params['bin']) mrc.write(voldata, newmrcfile) del voldata self.params['apix'] *= self.params['bin'] if os.path.isfile(newmrcfile): mrcfile = newmrcfile ### scale by mass if self.params['mass'] is not None: apDisplay.printMsg("Using scale by mass method") newmrcfile = os.path.join(os.getcwd(), "setmass.mrc") shutil.copy(self.params['file'], newmrcfile) apChimera.setVolumeMass(newmrcfile, apix=self.params['apix'], mass=self.params['mass']) self.params['contour'] = 1.0 if os.path.isfile(newmrcfile): mrcfile = newmrcfile ### print stats box = apVolume.getModelDimensions(mrcfile) apDisplay.printColor( "Box: %d Apix: %.2f File: %s" % (box, self.params['apix'], os.path.basename(mrcfile)), "green") ### animation if self.params['type'] != "snapshot": apDisplay.printMsg("Creating animation") apChimera.renderAnimation(mrcfile, contour=self.params['contour'], zoom=self.params['zoom'], sym=self.params['sym'], color=self.params['color'], xvfb=self.params['xvfb'], name=self.params['file'], silhouette=self.params['silhouette']) ### snapshot if self.params['type'] != "animate": apDisplay.printMsg("Creating snapshots") apChimera.renderSnapshots(mrcfile, contour=self.params['contour'], zoom=self.params['zoom'], sym=self.params['sym'], color=self.params['color'], xvfb=self.params['xvfb'], pdb=self.params['pdb'], name=self.params['file'], silhouette=self.params['silhouette']) ### clean up if self.params['mass'] is not None or self.params['bin'] is not None: images = glob.glob(mrcfile + "*") for img in images: newimg = re.sub(mrcfile, self.params['file'], img) shutil.move(img, newimg) apFile.removeFile(mrcfile)