def start(self): self.setFileName() ### get pdb from web if self.params['pdbid'] is not None: pdbfile = self.fetchPDB() else: pdbfile = self.params['name']+".pdb" shutil.copy(self.params['pdbfile'], pdbfile) if not os.path.exists(pdbfile): apDisplay.printError("Could not retrieve/find PDB file") ### get mass of PDB structure if self.params['mass'] is None: self.getPDBMass(pdbfile) if self.params['boxsize'] is None: self.determineBoxSize(pdbfile) ### create density from pdb mrcname = self.convertPDBtoMRC(pdbfile) if not os.path.isfile(mrcname): apDisplay.printError("could not create density file: "+mrcname) ### chimera imaging apChimera.renderSnapshots(mrcname, contour=1.5, zoom=1.0, sym=self.params['symdata']['eman_name']) ### upload it self.uploadDensity(mrcname)
def start(self): self.setFileName() scale = float(self.params['oldapix'])/self.params['newapix'] mrcname = os.path.join(self.params['rundir'], self.params['name']+".mrc") origmodel = self.params['file'] if os.path.isfile(mrcname): apDisplay.printError("File exists") if (abs(self.params['oldapix'] - self.params['newapix']) > 1.0e-2 or abs(self.params['oldbox'] - self.params['newbox']) > 1.0e-1): ### rescale old model to a new size apDisplay.printWarning("rescaling original model to a new size") scale = float(self.params['oldapix'])/self.params['newapix'] apDisplay.printMsg("rescaling model by scale factor of %.4f"%(scale)) apVolume.rescaleVolume(origmodel, mrcname, self.params['oldapix'], self.params['newapix'], self.params['newbox']) else: ### simple upload, just copy file to models folder apDisplay.printMsg("copying original model to a new location: "+mrcname) shutil.copyfile(origmodel, mrcname) if self.params['viper2eman'] is True: apVolume.viper2eman(mrcname, mrcname, apix=self.params['newapix']) ### render chimera images of model contour = self.params['contour'] if self.params['mass'] is not None: apChimera.setVolumeMass(mrcname, self.params['newapix'], self.params['mass']) contour = 1.0 apChimera.renderSnapshots(mrcname, contour=contour, zoom=self.params['zoom'], sym=self.params['symdata']['eman_name']) self.insertModel(mrcname)
def processVolume(self, spivolfile, iternum=0): ### set values apix = apStack.getStackPixelSizeFromStackId( self.params['tiltstackid']) * self.params['tiltbin'] boxsize = self.getBoxSize() rawspifile = os.path.join( self.params['rundir'], "rawvolume%s-%03d.spi" % (self.timestamp, iternum)) mrcvolfile = os.path.join( self.params['rundir'], "volume%s-%03d.mrc" % (self.timestamp, iternum)) lowpass = self.params['lowpassvol'] ### copy original to raw file shutil.copy(spivolfile, rawspifile) ### convert to mrc emancmd = ("proc3d " + spivolfile + " " + mrcvolfile + " norm=0,1 apix=" + str(apix)) apEMAN.executeEmanCmd(emancmd, verbose=False) ### median filter rawvol = mrc.read(mrcvolfile) medvol = ndimage.median_filter(rawvol, size=self.params['median']) mrc.write(medvol, mrcvolfile) ### low pass filter emancmd = ("proc3d " + mrcvolfile + " " + mrcvolfile + " center norm=0,1 apix=" + str(apix) + " lp=" + str(lowpass)) apEMAN.executeEmanCmd(emancmd, verbose=False) ### set origin emancmd = "proc3d " + mrcvolfile + " " + mrcvolfile + " origin=0,0,0 " apEMAN.executeEmanCmd(emancmd, verbose=False) ### mask volume emancmd = "proc3d " + mrcvolfile + " " + mrcvolfile + " mask=" + str( self.params['radius']) apEMAN.executeEmanCmd(emancmd, verbose=False) ### convert to spider apFile.removeFile(spivolfile) emancmd = "proc3d " + mrcvolfile + " " + spivolfile + " spidersingle" apEMAN.executeEmanCmd(emancmd, verbose=False) ### image with chimera if self.params['skipchimera'] is False: if self.params['mass'] is not None: apDisplay.printMsg("Using scale by mass method") apChimera.setVolumeMass(mrcvolfile, apix=apix, mass=self.params['mass']) apChimera.renderSnapshots(mrcvolfile, self.params['contour'], self.params['zoom'], 'c1') return mrcvolfile
def processVolume(self, spivolfile, cnum, iternum=0): ### set values apix = apStack.getStackPixelSizeFromStackId( self.params['tiltstackid']) * self.params['bin'] boxsize = self.getBoxSize() volfilename = os.path.splitext(spivolfile)[0] rawspifile = volfilename + "-raw.spi" mrcvolfile = volfilename + ".mrc" lowpass = self.params['lowpassvol'] ### copy original to raw file shutil.copy(spivolfile, rawspifile) ### convert to mrc emancmd = ("proc3d " + spivolfile + " " + mrcvolfile + " norm=0,1 apix=" + str(apix)) apEMAN.executeEmanCmd(emancmd, verbose=False) ### median filter rawvol = mrc.read(mrcvolfile) medvol = ndimage.median_filter(rawvol, size=self.params['median']) mrc.write(medvol, mrcvolfile) ### low pass filter emancmd = ("proc3d " + mrcvolfile + " " + mrcvolfile + " center norm=0,1 apix=" + str(apix) + " lp=" + str(lowpass)) apEMAN.executeEmanCmd(emancmd, verbose=False) ### set origin emancmd = "proc3d " + mrcvolfile + " " + mrcvolfile + " origin=0,0,0 " apEMAN.executeEmanCmd(emancmd, verbose=False) ### mask volume emancmd = "proc3d " + mrcvolfile + " " + mrcvolfile + " mask=" + str( self.params['radius']) apEMAN.executeEmanCmd(emancmd, verbose=False) ### convert to spider apFile.removeFile(spivolfile) emancmd = "proc3d " + mrcvolfile + " " + spivolfile + " spidersingle" apEMAN.executeEmanCmd(emancmd, verbose=False) ### image with chimera if self.params['skipchimera'] is False: apChimera.renderSnapshots(mrcvolfile, self.params['contour'], self.params['zoom'], 'c1') animationthread = threading.Thread( target=apChimera.renderAnimation, args=(mrcvolfile, self.params['contour'], self.params['zoom'], 'c1')) animationthread.setDaemon(1) animationthread.start() return mrcvolfile
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 processVolume(self, spivolfile, cnum, iternum=0): ### set values apix = apStack.getStackPixelSizeFromStackId(self.params["tiltstackid"]) * self.params["bin"] boxsize = self.getBoxSize() volfilename = os.path.splitext(spivolfile)[0] rawspifile = volfilename + "-raw.spi" mrcvolfile = volfilename + ".mrc" lowpass = self.params["lowpassvol"] ### copy original to raw file shutil.copy(spivolfile, rawspifile) ### convert to mrc emancmd = "proc3d " + spivolfile + " " + mrcvolfile + " norm=0,1 apix=" + str(apix) apEMAN.executeEmanCmd(emancmd, verbose=False) ### median filter rawvol = mrc.read(mrcvolfile) medvol = ndimage.median_filter(rawvol, size=self.params["median"]) mrc.write(medvol, mrcvolfile) ### low pass filter emancmd = ( "proc3d " + mrcvolfile + " " + mrcvolfile + " center norm=0,1 apix=" + str(apix) + " lp=" + str(lowpass) ) apEMAN.executeEmanCmd(emancmd, verbose=False) ### set origin emancmd = "proc3d " + mrcvolfile + " " + mrcvolfile + " origin=0,0,0 " apEMAN.executeEmanCmd(emancmd, verbose=False) ### mask volume emancmd = "proc3d " + mrcvolfile + " " + mrcvolfile + " mask=" + str(self.params["radius"]) apEMAN.executeEmanCmd(emancmd, verbose=False) ### convert to spider apFile.removeFile(spivolfile) emancmd = "proc3d " + mrcvolfile + " " + spivolfile + " spidersingle" apEMAN.executeEmanCmd(emancmd, verbose=False) ### image with chimera if self.params["skipchimera"] is False: apChimera.renderSnapshots(mrcvolfile, self.params["contour"], self.params["zoom"], "c1") animationthread = threading.Thread( target=apChimera.renderAnimation, args=(mrcvolfile, self.params["contour"], self.params["zoom"], "c1") ) animationthread.setDaemon(1) animationthread.start() return mrcvolfile
def processVolume(self, spivolfile, iternum=0): ### set values apix = apStack.getStackPixelSizeFromStackId(self.params['tiltstackid'])*self.params['tiltbin'] boxsize = self.getBoxSize() rawspifile = os.path.join(self.params['rundir'], "rawvolume%s-%03d.spi"%(self.timestamp, iternum)) mrcvolfile = os.path.join(self.params['rundir'], "volume%s-%03d.mrc"%(self.timestamp, iternum)) lowpass = self.params['lowpassvol'] ### copy original to raw file shutil.copy(spivolfile, rawspifile) ### convert to mrc emancmd = ("proc3d "+spivolfile+" "+mrcvolfile+" norm=0,1 apix="+str(apix)) apEMAN.executeEmanCmd(emancmd, verbose=False) ### median filter rawvol = mrc.read(mrcvolfile) medvol = ndimage.median_filter(rawvol, size=self.params['median']) mrc.write(medvol, mrcvolfile) ### low pass filter emancmd = ("proc3d "+mrcvolfile+" "+mrcvolfile+" center norm=0,1 apix=" +str(apix)+" lp="+str(lowpass)) apEMAN.executeEmanCmd(emancmd, verbose=False) ### set origin emancmd = "proc3d "+mrcvolfile+" "+mrcvolfile+" origin=0,0,0 " apEMAN.executeEmanCmd(emancmd, verbose=False) ### mask volume emancmd = "proc3d "+mrcvolfile+" "+mrcvolfile+" mask="+str(self.params['radius']) apEMAN.executeEmanCmd(emancmd, verbose=False) ### convert to spider apFile.removeFile(spivolfile) emancmd = "proc3d "+mrcvolfile+" "+spivolfile+" spidersingle" apEMAN.executeEmanCmd(emancmd, verbose=False) ### image with chimera if self.params['skipchimera'] is False: if self.params['mass'] is not None: apDisplay.printMsg("Using scale by mass method") apChimera.setVolumeMass(mrcvolfile, apix=apix, mass=self.params['mass']) apChimera.renderSnapshots(mrcvolfile, self.params['contour'], self.params['zoom'], 'c1') return mrcvolfile
def start(self): self.setFileName() scale = float(self.params['oldapix']) / self.params['newapix'] mrcname = os.path.join(self.params['rundir'], self.params['name'] + ".mrc") origmodel = self.params['file'] if os.path.isfile(mrcname): apDisplay.printError("File exists") if (abs(self.params['oldapix'] - self.params['newapix']) > 1.0e-2 or abs(self.params['oldbox'] - self.params['newbox']) > 1.0e-1): ### rescale old model to a new size apDisplay.printWarning("rescaling original model to a new size") scale = float(self.params['oldapix']) / self.params['newapix'] apDisplay.printMsg("rescaling model by scale factor of %.4f" % (scale)) apVolume.rescaleVolume(origmodel, mrcname, self.params['oldapix'], self.params['newapix'], self.params['newbox']) else: ### simple upload, just copy file to models folder apDisplay.printMsg("copying original model to a new location: " + mrcname) shutil.copyfile(origmodel, mrcname) if self.params['viper2eman'] is True: apVolume.viper2eman(mrcname, mrcname, apix=self.params['newapix']) ### render chimera images of model contour = self.params['contour'] if self.params['mass'] is not None: apChimera.setVolumeMass(mrcname, self.params['newapix'], self.params['mass']) contour = 1.0 apChimera.renderSnapshots(mrcname, contour=contour, zoom=self.params['zoom'], sym=self.params['symdata']['eman_name']) self.insertModel(mrcname)
def start(self): self.apix = None self.mass = None self.setFileName() mrcname = self.params['name'] + ".mrc" ccp4name = self.params['name'] + ".ccp4" ### get emdb from web emdbfile = self.fetchEMDB(self.params['emdbid'], ccp4name) ### create density from emdb self.getXMLInfoFromEMDB(self.params['emdbid']) emancmd = ("proc3d " + ccp4name + " " + mrcname) apEMAN.executeEmanCmd(emancmd, verbose=False, showcmd=True) apFile.removeFile(ccp4name) if self.params['viper2eman'] is True: apVolume.viper2eman(mrcname, mrcname, apix=self.apix) ### lowpass filter, do both atan2 and Gaussian filter to sum up to requested lowpass ### total lowpass = sqrt( lp1^2 + lp2^2 ) if self.params['lowpass'] is not None: lp = self.params['lowpass'] / math.sqrt(2.0) emancmd = "proc3d %s %s apix=%.3f origin=0,0,0 norm=0,1 " % ( mrcname, mrcname, self.apix) if self.params['lowpass'] is not None: emancmd += "tlp=%.2f lp=%.2f" % (lp, lp) apEMAN.executeEmanCmd(emancmd, verbose=False, showcmd=True) if self.mass is not None: apChimera.setVolumeMass(mrcname, apix=self.apix, mass=self.mass) ### chimera imaging apChimera.renderSnapshots(mrcname, contour=1.0, zoom=1.0, sym=self.params['symdata']['eman_name']) ### upload it self.uploadDensity(mrcname)
def start(self): self.apix = None self.mass = None self.setFileName() mrcname = self.params['name']+".mrc" ccp4name = self.params['name']+".ccp4" ### get emdb from web emdbfile = self.fetchEMDB(self.params['emdbid'], ccp4name) ### create density from emdb self.getXMLInfoFromEMDB(self.params['emdbid']) emancmd = ("proc3d "+ccp4name+" "+mrcname) apEMAN.executeEmanCmd(emancmd, verbose=False, showcmd=True) apFile.removeFile(ccp4name) if self.params['viper2eman'] is True: apVolume.viper2eman(mrcname, mrcname, apix=self.apix) ### lowpass filter, do both atan2 and Gaussian filter to sum up to requested lowpass ### total lowpass = sqrt( lp1^2 + lp2^2 ) if self.params['lowpass'] is not None: lp = self.params['lowpass']/math.sqrt(2.0) emancmd = "proc3d %s %s apix=%.3f origin=0,0,0 norm=0,1 " %(mrcname, mrcname, self.apix) if self.params['lowpass'] is not None: emancmd += "tlp=%.2f lp=%.2f" % (lp, lp) apEMAN.executeEmanCmd(emancmd, verbose=False, showcmd=True) if self.mass is not None: apChimera.setVolumeMass(mrcname, apix=self.apix, mass=self.mass) ### chimera imaging apChimera.renderSnapshots(mrcname, contour=1.0, zoom=1.0, sym=self.params['symdata']['eman_name']) ### upload it self.uploadDensity(mrcname)
def start(self): if self.params['method'] == 'any': ### startAny uses class averages clusterstack, numimages = self.getClusterStack() else: ### starticos, startoct, startcsym uses individual particles clusterstack, numimages = self.getClusterParticles() if self.params['method'] != 'any': if self.params['numkeep'] is not None and numimages/10 < int(self.params['numkeep']): apDisplay.printWarning("particle number of "+ self.params['numkeep'] + " is greater than 10% of the number of selected classes") elif self.params['numkeep'] is None: self.params['numkeep'] = int(math.floor(numimages/20.0))+1 apDisplay.printWarning("numkeep was not defined, using %d particles"%(self.params['numkeep'])) nproc = apParam.getNumProcessors() #construct command for each of the EMAN commonline method if self.params['method'] == 'any': startcmd = "startAny "+clusterstack+" proc="+str(nproc) startcmd +=" sym="+self.symmdata['eman_name'] if self.params['mask'] is not None: startcmd +=" mask="+str(self.params['mask']) else: maskrad = math.floor(self.clusterstackdata['clusterrun']['boxsize']/2.0) startcmd +=" mask=%d"%(maskrad) if self.params['rounds'] is not None: startcmd +=" rounds="+str(self.params['rounds']) elif self.params['method'] == 'csym': startcmd = "startcsym "+clusterstack+" " startcmd +=" "+str(self.params['numkeep']) startcmd +=" sym="+self.symmdata['eman_name'] if self.params['imask'] is not None: startcmd +=" imask="+self.params['imask'] elif self.params['method'] == 'oct': startcmd = "startoct "+clusterstack+" " startcmd +=" "+str(self.params['numkeep']) elif self.params['method'] == 'icos': startcmd = "starticos "+clusterstack+" " startcmd +=" "+str(self.params['numkeep']) if self.params['imask'] is not None: startcmd +=" imask="+self.params['imask'] apDisplay.printMsg("Creating 3D model with EMAN function: start"+self.params['method']) apFile.removeFile("threed.0a.mrc") apFile.removeFile("eman.log") apEMAN.executeEmanCmd(startcmd, verbose=False, logfile="eman.log") #apEMAN.executeEmanCmd(startcmd, verbose=True) finalmodelname = "threed-%s-eman_start%s.mrc"%(self.timestamp, self.params['method']) finalmodelpath = os.path.join(self.params['rundir'], finalmodelname) apDisplay.printMsg("Final model name: "+finalmodelname) finalmodel = "threed.0a.mrc" if os.path.isfile(finalmodel): emancmd = "proc3d %s %s norm=0,1 origin=0,0,0"%(finalmodel, finalmodelpath) #shutil.move(finalmodel, finalmodelpath) apEMAN.executeEmanCmd(emancmd, verbose=True) if not apVolume.isValidVolume(finalmodelpath): apDisplay.printError("Created volume is not valid") else: apDisplay.printError("No 3d model was created") ### upload it self.uploadDensity(finalmodelpath) ### chimera imaging apChimera.renderSnapshots(finalmodelpath, contour=self.params['contour'], zoom=self.params['zoom'], sym=self.symmdata['eman_name']) apChimera.renderAnimation(finalmodelpath, contour=self.params['contour'], zoom=self.params['zoom'], sym=self.symmdata['eman_name']) ### remove stack if apFile.stackSize(clusterstack)/1024**2 > 10: ### file bigger than 10MB apFile.removeStack(clusterstack) apFile.removeFile("threed.0a.mrc")
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)