def animateModesStep(self, numberOfModes,amplitude,nFrames,downsample,pseudoAtomThreshold,pseudoAtomRadius): makePath(self._getExtraPath('animations')) self._enterWorkingDir() if self.structureEM: fn = "pseudoatoms.pdb" self.runJob("nma_animate_pseudoatoms.py","%s extra/vec_ani.pkl 7 %d %f extra/animations/animated_mode %d %d %f"%\ (fn,numberOfModes,amplitude,nFrames,downsample,pseudoAtomThreshold),env=getNMAEnviron()) else: fn="atoms.pdb" self.runJob("nma_animate_atoms.py","%s extra/vec_ani.pkl 7 %d %f extra/animations/animated_mode %d"%\ (fn,numberOfModes,amplitude,nFrames),env=getNMAEnviron()) for mode in range(7,numberOfModes+1): fnAnimation = join("extra", "animations", "animated_mode_%03d" % mode) fhCmd=open(fnAnimation+".vmd",'w') fhCmd.write("mol new %s.pdb\n" % self._getPath(fnAnimation)) fhCmd.write("animate style Loop\n") fhCmd.write("display projection Orthographic\n") if self.structureEM: fhCmd.write("mol modcolor 0 0 Beta\n") fhCmd.write("mol modstyle 0 0 Beads %f 8.000000\n"%(pseudoAtomRadius)) else: fhCmd.write("mol modcolor 0 0 Index\n") #fhCmd.write("mol modstyle 0 0 Beads 1.000000 8.000000\n") fhCmd.write("mol modstyle 0 0 NewRibbons 1.800000 6.000000 2.600000 0\n") fhCmd.write("animate speed 0.5\n") fhCmd.write("animate forward\n") fhCmd.close(); self._leaveWorkingDir()
def convertInputStep(self): """ Read the input metadatata. """ # Get the converted input micrographs in Xmipp format makePath(self._getExtraPath("untilted")) makePath(self._getExtraPath("tilted")) uSet = self.untiltedSet.get() tSet = self.tiltedSet.get() # Get the untilted and tilted coordinates, depending on the input type if isinstance(uSet, SetOfParticles): uCoords = uSet.getCoordinates() tCoords = tSet.getCoordinates() # If there are not Coordinates associated to particles # we need to create and fill the set of coordinates if uCoords is None or tCoords is None: micTiltedPairs = self.inputMicrographsTiltedPair.get() uCoords = self._coordsFromParts(micTiltedPairs.getUntilted(), uSet, '_untilted') tCoords = self._coordsFromParts(micTiltedPairs.getTilted(), tSet, '_tilted') else: uCoords = uSet tCoords = tSet writeSetOfCoordinates(self._getExtraPath("untilted"), uCoords) writeSetOfCoordinates(self._getExtraPath("tilted"), tCoords)
def computeAtomShiftsStep(self, numberOfModes): fnOutDir = self._getExtraPath("distanceProfiles") makePath(fnOutDir) maxShift = [] maxShiftMode = [] for n in range(7, numberOfModes + 1): fnVec = self._getPath("modes", "vec.%d" % n) if exists(fnVec): fhIn = open(fnVec) md = xmipp.MetaData() atomCounter = 0 for line in fhIn: x, y, z = map(float, line.split()) d = math.sqrt(x * x + y * y + z * z) if n == 7: maxShift.append(d) maxShiftMode.append(7) else: if d > maxShift[atomCounter]: maxShift[atomCounter] = d maxShiftMode[atomCounter] = n atomCounter += 1 md.setValue(xmipp.MDL_NMA_ATOMSHIFT, d, md.addObject()) md.write(join(fnOutDir, "vec%d.xmd" % n)) fhIn.close() md = xmipp.MetaData() for i, _ in enumerate(maxShift): fnVec = self._getPath("modes", "vec.%d" % (maxShiftMode[i] + 1)) if exists(fnVec): objId = md.addObject() md.setValue(xmipp.MDL_NMA_ATOMSHIFT, maxShift[i], objId) md.setValue(xmipp.MDL_NMA_MODEFILE, fnVec, objId) md.write(self._getExtraPath('maxAtomShifts.xmd'))
def reformatPdbOutputStep(self, numberOfModes): self._enterWorkingDir() makePath('modes') Natoms = self._countAtoms("atoms.pdb") fhIn = open('diagrtb.eigenfacs') fhAni = open('vec_ani.txt', 'w') for n in range(numberOfModes): # Skip two lines fhIn.readline() fhIn.readline() fhOut = open('modes/vec.%d' % (n + 1), 'w') for i in range(Natoms): line = fhIn.readline() fhOut.write(line) fhAni.write(line.rstrip().lstrip() + " ") fhOut.close() if n != (numberOfModes - 1): fhAni.write("\n") fhIn.close() fhAni.close() self.runJob("nma_prepare_for_animate.py", "", env=getNMAEnviron()) cleanPath("vec_ani.txt") moveFile('vec_ani.pkl', 'extra/vec_ani.pkl') self._leaveWorkingDir()
def symStep(self): inputVol = self.inputVol.get() fnVol = inputVol.getFileName() samplingRate = inputVol.getSamplingRate() volName = os.path.basename(fnVol) volName = os.path.splitext(volName)[0] tmpDir = self._getTmpPath(volName) fnVol = os.path.abspath(fnVol) makePath(tmpDir) maskRadius = self.mask.get() if maskRadius<0: Xdim = inputVol.getDim()[0] maskRadius=Xdim/2-1 lpCutoff = inputVol.getSamplingRate()/self.lp.get() paramsSym = ' prg=symmetry_test vol1=%s smpd=%f msk=%d lp=%f nthr=%d' \ %(fnVol, samplingRate, maskRadius, lpCutoff, self.numberOfThreads.get()) self.runJob(simple.Plugin.sim_exec(), 'prg=new_project projname=temp', cwd=os.path.abspath(tmpDir), env=simple.Plugin.getEnviron()) self.runJob(simple.Plugin.sim_exec(), paramsSym, cwd=os.path.abspath(tmpDir)+'/temp', env=simple.Plugin.getEnviron()) #Move output files to ExtraPath and rename them properly mvRoot1 = os.path.join(tmpDir+'/temp/1_symmetry_test', "symmetry_test_output.txt") moveFile(mvRoot1, self._getExtraPath('point_group_symmetry_.txt')) cleanPath(tmpDir)
def elasticAlignmentStep(self, nVoli, voli, nVolj): makePath(self._getExtraPath("modes%d"%nVoli)) for i in range(self.numberOfModes.get() + 1): if i == 0 : i += 1 copyFile (self._getPath("modes/vec.%d"%i), self._getExtraPath("modes%d/vec.%d"%(nVoli, i))) mdVol = xmipp.MetaData() fnOutMeta = self._getExtraPath('RigidAlignVol_%d_To_Vol_%d.xmd' % (nVolj, nVoli)) mdVol.setValue(xmipp.MDL_IMAGE, self._getPath('outputRigidAlignment_vol_%d_to_%d.vol' % (nVolj, nVoli)), mdVol.addObject()) mdVol.write(fnOutMeta) fnPseudo = self._getPath("pseudoatoms_%d.pdb"%nVoli) fnModes = self._getPath("modes_%d.xmd"%nVoli) Ts = voli.getSamplingRate() fnDeform = self._getExtraPath('compDeformVol_%d_To_Vol_%d.xmd' % (nVolj, nVoli)) sigma = Ts * self.pseudoAtomRadius.get() fnPseudoOut = self._getExtraPath('PseudoatomsDeformedPDB_Vol_%d_To_Vol_%d.pdb' % (nVolj, nVoli)) self.runJob('xmipp_nma_alignment_vol', "-i %s --pdb %s --modes %s --sampling_rate %s -o %s --fixed_Gaussian %s --opdb %s"%\ (fnOutMeta, fnPseudo, fnModes, Ts, fnDeform, sigma, fnPseudoOut)) fnVolOut = self._getExtraPath('DeformedVolume_Vol_%d_To_Vol_%d' % (nVolj, nVoli)) self.runJob('xmipp_volume_from_pdb', "-i %s -o %s --sampling %s --fixed_Gaussian %s" % (fnPseudoOut, fnVolOut, Ts, sigma))
def pickGoldBeadsStep(self, tsObjId): tomo = self.inputSetOfTomograms.get()[tsObjId] location = tomo.getLocation()[1] fileName, _ = os.path.splitext(location) extraPrefix = self._getExtraPath(os.path.basename(fileName)) path.makePath(extraPrefix) """ Run findbeads3d IMOD program """ paramsFindbeads3d = { 'inputFile': location, 'outputFile': os.path.join(extraPrefix, "%s.mod" % os.path.basename(fileName)), 'beadSize': self.beadDiameter.get(), 'minRelativeStrength': self.minRelativeStrength.get(), 'minSpacing': self.minSpacing.get(), } argsFindbeads3d = "-InputFile %(inputFile)s " \ "-OutputFile %(outputFile)s " \ "-BeadSize %(beadSize)d " \ "-MinRelativeStrength %(minRelativeStrength)f " \ "-MinSpacing %(minSpacing)d " if self.beadsColor.get() == 1: argsFindbeads3d += "-LightBeads " Plugin.runImod(self, 'findbeads3d', argsFindbeads3d % paramsFindbeads3d)
def classifyGroupsStep(self): fnNeighbours = self._getExtraPath("neighbours.xmd") gallery = self._getExtraPath("gallery.stk") for block in md.getBlocksInMetaDataFile(fnNeighbours): #creating a folder to each direction imgNo = int(block.split("_")[1]) fnDir = self._getExtraPath("direction_%05d" % imgNo) fnBlock = "%s@%s" % (block, fnNeighbours) if not exists(fnDir): pwpath.makePath(fnDir) if self.classMethod.get() == cmcons.CL2D: dirClasses = self.directionalClasses.get() nLevs = self._getCl2dLevels() fnOut = join(fnDir, "level_%02d/class_classes.stk" % nLevs) self._runClassifSteps(fnOut, fnBlock, fnDir, imgNo, gallery, callbackMethod=self._runCl2dStep) else: relPart = self._createSetOfParticles() relPart.copyInfo(self.inputParticles.get()) fnOut = join(fnDir, "class_") self._runClassifSteps(fnOut, fnBlock, fnDir, imgNo, gallery, callbackMethod=self._runRelionStep)
def alignabilityStep(self, volName,volDir,sym): nproc = self.numberOfMpi.get() nT=self.numberOfThreads.get() makePath(volDir) inputFile = self._getPath('input_particles.xmd') inputFileRef = self._getPath('reference_particles.xmd') aFile = self._getTmpPath('exp_particles.xmd') aFileRef =self._getTmpPath('ref_particles.xmd') aFileGallery =(volDir+'/gallery.doc') params = ' -i %s' % inputFile params += ' -i2 %s' % inputFileRef params += ' --volume %s' % volName params += ' --angles_file %s' % aFile params += ' --angles_file_ref %s' % aFileRef params += ' --gallery %s' % aFileGallery params += ' --odir %s' % volDir params += ' --sym %s' % sym params += ' --check_mirrors' if self.doNotUseWeights: params += ' --dontUseWeights' self.runJob('xmipp_multireference_aligneability', params,numberOfMpi=nproc,numberOfThreads=nT)
def processMovieStep(self, movieId, movieFn, *args): movieFolder = self._getMovieFolder(movieId) movieName = basename(movieFn) #export SCIPION_DEBUG=1 # passwd=a #startDebugger() if self._filterMovie(movieId, movieFn): makePath(movieFolder) createLink(movieFn, join(movieFolder, movieName)) toDelete = [movieName] if movieName.endswith('bz2'): movieMrc = movieName.replace('.bz2', '') # we assume that if compressed the name ends with .mrc.bz2 toDelete.append(movieMrc) if not exists(movieMrc): self.runJob('bzip2', '-d -f %s' % movieName, cwd=movieFolder) else: movieMrc = movieName self.info("Processing movie: %s" % movieMrc) if movieMrc.endswith('.em'): movieMrc = movieMrc + ":ems" self._processMovie(movieId, movieMrc, movieFolder, *args) if self.cleanMovieData: cleanPath(movieFolder) else: self.info('Clean movie data DISABLED. Movie folder will remain in disk!!!')
def applyAlignmentStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) path.makePath(extraPrefix) outputTsFileName = os.path.join(extraPrefix, "%s.mrc" % tsId) ts.applyTransform(outputTsFileName) outputInterpolatedSetOfTiltSeries = self.getOutputInterpolatedSetOfTiltSeries() newTs = tomoObj.TiltSeries(tsId=tsId) newTs.copyInfo(ts) outputInterpolatedSetOfTiltSeries.append(newTs) for index, tiltImage in enumerate(ts): newTi = tomoObj.TiltImage() newTi.copyInfo(tiltImage, copyId=True) newTi.setLocation(index + 1, outputTsFileName) newTs.append(newTi) ih = ImageHandler() x, y, z, _ = ih.getDimensions(newTs.getFirstItem().getFileName()) newTs.setDim((x, y, z)) newTs.write() outputInterpolatedSetOfTiltSeries.update(newTs) outputInterpolatedSetOfTiltSeries.updateDim() outputInterpolatedSetOfTiltSeries.write() self._store()
def processMovieStep(self, movieId, movieFn, *args): movieFolder = self._getMovieFolder(movieId) movieName = basename(movieFn) if self._filterMovie(movieId, movieFn): makePath(movieFolder) createLink(movieFn, join(movieFolder, movieName)) toDelete = [movieName] if movieName.endswith('bz2'): # We assume that if compressed the name ends with .mrc.bz2 movieMrc = movieName.replace('.bz2', '') toDelete.append(movieMrc) if not exists(movieMrc): self.runJob('bzip2', '-d -f %s' % movieName, cwd=movieFolder) elif movieName.endswith('tbz'): # We assume that if compressed the name ends with .tbz movieMrc = movieName.replace('.tbz', '.mrc') toDelete.append(movieMrc) if not exists(movieMrc): self.runJob('tar', 'jxf %s' % movieName, cwd=movieFolder) else: movieMrc = movieName self.info("Processing movie: %s" % movieMrc) self._processMovie(movieId, movieMrc, movieFolder, *args) if self.cleanMovieData: print "erasing.....movieFolder: ", movieFolder os.system('rm -rf %s' % movieFolder) # cleanPath(movieFolder) else: self.info('Clean movie data DISABLED. Movie folder will remain in disk!!!')
def splitTiltSeries(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() tsFileName = ts.getFirstItem().getFileName() path.makePath(self._getExtraPath(tsId)) tsFileNameOdd = pwutils.removeExt( os.path.basename(tsFileName)) + "_odd.xmd" tsFileNameEven = pwutils.removeExt( os.path.basename(tsFileName)) + "_even.xmd" paramsOddEven = { 'inputImg': tsFileName + ":mrcs", 'outputOdd': self._getExtraPath(os.path.join(tsId, tsFileNameOdd)), 'outputEven': self._getExtraPath(os.path.join(tsId, tsFileNameEven)), 'type': "images", } argsOddEven = "--img %(inputImg)s " \ "-o %(outputOdd)s " \ "-e %(outputEven)s " \ "--type %(type)s " self.runJob('xmipp_image_odd_even', argsOddEven % paramsOddEven)
def initializeStep(self): """ Create paths where data will be saved """ for i in range(len(self.inputCoordinatesTrue)): makePath(self._getExtraPath(self.PRE_PROC_MICs_PATH % i)) if self.doTesting.get() and self.testTrueSetOfParticles.get( ) and self.testFalseSetOfParticles.get(): writeSetOfParticles(self.testTrueSetOfParticles.get(), self._getExtraPath("testTrueParticlesSet.xmd")) writeSetOfParticles( self.testFalseSetOfParticles.get(), self._getExtraPath("testFalseParticlesSet.xmd")) if self.addTrainingData.get() == self.ADD_TRAIN_CUST: if self.trainTrueSetOfParticles.get(): writeSetOfParticles( self.trainTrueSetOfParticles.get(), self._getExtraPath("trainTrueParticlesSet.xmd")) if self.trainFalseSetOfParticles.get(): writeSetOfParticles( self.trainFalseSetOfParticles.get(), self._getExtraPath("trainFalseParticlesSet.xmd")) elif self.addTrainingData.get() == self.ADD_TRAIN_MODEL: writeSetOfParticles(self.retrieveTrainSets(), self._getTmpPath("addNegTrainParticles.xmd"))
def _insertInitialSteps(self): """ Override this function to insert some steps before the estimate ctfs steps. Should return a list of ids of the initial steps. """ makePath(self._getExtraPath('DONE')) return []
def init3DStep(self, partFile,SamplingRate): partName = os.path.basename(partFile) partName = os.path.splitext(partName)[0] tmpDir = self._getTmpPath(partName) makePath(tmpDir) params = self.getI3DParams(partFile, SamplingRate) self.runJob("simple_distr_exec", params, cwd=os.path.abspath(tmpDir)) #Move output files to ExtraPath and rename them properly folder = self._getExtraPath(partName) folder = os.path.abspath(folder) source_dir = os.path.abspath(tmpDir) files1 = glob.iglob(os.path.join(source_dir, "*.txt")) files2 = glob.iglob(os.path.join(source_dir, "*.mrc")) for file1, file2 in map(None, files1, files2): if (file1 != None): if os.path.isfile(file1): oldName = os.path.basename(file1) shutil.move(file1, folder + '_' + oldName) if (file2 != None): if os.path.isfile(file2): oldName = os.path.basename(file2) shutil.move(file2, folder + '_' + oldName) cleanPath(tmpDir)
def convertImagesStep(self): from pyworkflow.em.packages.eman2.convert import writeSetOfParticles strFn = "" partSet = self.inputParticles.get() partAlign = partSet.getAlignment() storePath = self._getExtraPath("particles") makePath(storePath) writeSetOfParticles(partSet, storePath, alignType=em.ALIGN_PROJ) if partSet.hasCTF(): program = getEmanProgram('e2ctf.py') acq = partSet.getAcquisition() args = " --voltage %3d" % acq.getVoltage() args += " --cs %f" % acq.getSphericalAberration() args += " --ac %f" % (100 * acq.getAmplitudeContrast()) if not partSet.isPhaseFlipped(): args += " --phaseflip" args += " --computesf --apix %f --allparticles --autofit --curdefocusfix --storeparm -v 8" % ( partSet.getSamplingRate()) self.runJob(program, args, cwd=self._getExtraPath()) program = getEmanProgram('e2buildsets.py') args = " --setname=inputSet --allparticles --minhisnr=-1" self.runJob(program, args, cwd=self._getExtraPath())
def projectTomogram(self, tomoObjId): tomo = self.inputSetOfTomograms.get()[tomoObjId] tomoId = os.path.splitext(os.path.basename(tomo.getFileName()))[0] extraPrefix = self._getExtraPath(tomoId) tmpPrefix = self._getTmpPath(tomoId) path.makePath(tmpPrefix) path.makePath(extraPrefix) paramsXYZproj = { 'input': tomo.getFileName(), 'output': os.path.join(extraPrefix, os.path.basename(tomo.getFileName())), 'axis': self.getRotationAxis(), 'angles': str(self.minAngle.get()) + ',' + str(self.maxAngle.get()) + ',' + str(self.stepAngle.get()), } argsXYZproj = "-input %(input)s " \ "-output %(output)s " \ "-axis %(axis)s " \ "-angles %(angles)s " Plugin.runImod(self, 'xyzproj', argsXYZproj % paramsXYZproj)
def computeAtomShiftsStep(self, numberOfModes): fnOutDir = self._getExtraPath("distanceProfiles") makePath(fnOutDir) maxShift=[] maxShiftMode=[] for n in range(7, numberOfModes+1): fnVec = self._getPath("modes", "vec.%d" % n) if exists(fnVec): fhIn = open(fnVec) md = xmipp.MetaData() atomCounter = 0 for line in fhIn: x, y, z = map(float, line.split()) d = math.sqrt(x*x+y*y+z*z) if n==7: maxShift.append(d) maxShiftMode.append(7) else: if d>maxShift[atomCounter]: maxShift[atomCounter]=d maxShiftMode[atomCounter]=n atomCounter+=1 md.setValue(xmipp.MDL_NMA_ATOMSHIFT,d,md.addObject()) md.write(join(fnOutDir,"vec%d.xmd" % n)) fhIn.close() md = xmipp.MetaData() for i, _ in enumerate(maxShift): fnVec = self._getPath("modes", "vec.%d" % (maxShiftMode[i]+1)) if exists(fnVec): objId = md.addObject() md.setValue(xmipp.MDL_NMA_ATOMSHIFT, maxShift[i],objId) md.setValue(xmipp.MDL_NMA_MODEFILE, fnVec, objId) md.write(self._getExtraPath('maxAtomShifts.xmd'))
def convertImagesStep(self): partSet = self._getInputParticles() partAlign = partSet.getAlignment() storePath = self._getExtraPath("particles") makePath(storePath) writeSetOfParticles(partSet, storePath, alignType=partAlign) if not self.skipctf: program = eman2.Plugin.getProgram('e2ctf.py') acq = partSet.getAcquisition() args = " --voltage %d" % acq.getVoltage() args += " --cs %f" % acq.getSphericalAberration() args += " --ac %f" % (100 * acq.getAmplitudeContrast()) args += " --threads=%d" % self.numberOfThreads.get() if not partSet.isPhaseFlipped(): args += " --phaseflip" args += " --computesf --apix %f" % partSet.getSamplingRate() args += " --allparticles --autofit --curdefocusfix --storeparm -v 8" self.runJob(program, args, cwd=self._getExtraPath(), numberOfMpi=1, numberOfThreads=1) program = eman2.Plugin.getProgram('e2buildsets.py') args = " --setname=inputSet --allparticles --minhisnr=-1" self.runJob(program, args, cwd=self._getExtraPath(), numberOfMpi=1, numberOfThreads=1)
def reformatPdbOutputStep(self, numberOfModes): self._enterWorkingDir() makePath('modes') Natoms = self._countAtoms("atoms.pdb") fhIn = open('diagrtb.eigenfacs') fhAni = open('vec_ani.txt','w') for n in range(numberOfModes): # Skip two lines fhIn.readline() fhIn.readline() fhOut=open('modes/vec.%d'%(n+1),'w') for i in range(Natoms): line=fhIn.readline() fhOut.write(line) fhAni.write(line.rstrip().lstrip()+" ") fhOut.close() if n!=(numberOfModes-1): fhAni.write("\n") fhIn.close() fhAni.close() self.runJob("nma_prepare_for_animate.py","",env=getNMAEnviron()) cleanPath("vec_ani.txt") moveFile('vec_ani.pkl', 'extra/vec_ani.pkl') self._leaveWorkingDir()
def alignabilityStep(self, volName, volDir, sym): nproc = self.numberOfMpi.get() nT = self.numberOfThreads.get() makePath(volDir) inputFile = self._getPath('input_particles.xmd') inputFileRef = self._getPath('reference_particles.xmd') aFile = self._getTmpPath('exp_particles.xmd') aFileRef = self._getTmpPath('ref_particles.xmd') aFileGallery = (volDir + '/gallery.doc') params = ' -i %s' % inputFile params += ' -i2 %s' % inputFileRef params += ' --volume %s' % volName params += ' --angles_file %s' % aFile params += ' --angles_file_ref %s' % aFileRef params += ' --gallery %s' % aFileGallery params += ' --odir %s' % volDir params += ' --sym %s' % sym params += ' --check_mirrors' if self.doNotUseWeights: params += ' --dontUseWeights' self.runJob('xmipp_multireference_aligneability', params, numberOfMpi=nproc, numberOfThreads=nT)
def generateFiducialModelStep(self, tsObjId): # TODO: check si es el landmark model correcto lm = self.inputSetOfLandmarkModels.get()[tsObjId] ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) tmpPrefix = self._getTmpPath(tsId) path.makePath(extraPrefix) path.makePath(tmpPrefix) landmarkTextFilePath = os.path.join( extraPrefix, ts.getFirstItem().parseFileName(suffix="_fid", extension=".txt")) landmarkModelPath = os.path.join( extraPrefix, ts.getFirstItem().parseFileName(suffix="_fid", extension=".mod")) # Generate the IMOD file containing the information from the landmark model utils.generateIMODFiducialTextFile(landmarkModel=lm, outputFilePath=landmarkTextFilePath) # Convert IMOD file into IMOD model paramsPoint2Model = { 'inputFile': landmarkTextFilePath, 'outputFile': landmarkModelPath, } argsPoint2Model = "-InputFile %(inputFile)s " \ "-OutputFile %(outputFile)s" Plugin.runImod(self, 'point2model', argsPoint2Model % paramsPoint2Model)
def unblurStep(self, mvF, samplingRate): #movieName = self._getMovieName(movie) mvName = os.path.basename(mvF) mvName = os.path.splitext(mvName)[0] tmpDir = self._getTmpPath(mvName) makePath(tmpDir) mvRoot = os.path.join(tmpDir, mvName) fnInput = os.path.abspath(mvRoot + '.txt') fhInput = open(fnInput, 'w') fhInput.write(os.path.abspath(mvF)) fhInput.close() params = self.getUnblurParams(fnInput, samplingRate, mvName) self.runJob(simple.Plugin.distr_exec(), params, cwd=os.path.abspath(tmpDir), env=simple.Plugin.getEnviron()) moveFile(mvRoot + "_intg1.mrc", self._getExtraPath(mvName + ".mrc")) moveFile(mvRoot + "_pspec1.mrc", self._getExtraPath(mvName + "_psd.mrc")) moveFile(mvRoot + "_thumb1.mrc", self._getExtraPath(mvName + "_thumb.mrc")) cleanPath(tmpDir)
def elasticAlignmentStep(self, nVoli, Ts, nVolj, fnAlignedVolj): fnVolOut = self._getExtraPath('DeformedVolume_Vol_%d_To_Vol_%d' % (nVolj, nVoli)) if os.path.exists(fnVolOut + ".pdb"): return makePath(self._getExtraPath("modes%d" % nVoli)) for i in range(self.numberOfModes.get() + 1): if i == 0: i += 1 copyFile(self._getPath("modes/vec.%d" % i), self._getExtraPath("modes%d/vec.%d" % (nVoli, i))) mdVol = xmippLib.MetaData() fnOutMeta = self._getExtraPath('RigidAlignVol_%d_To_Vol_%d.xmd' % (nVolj, nVoli)) mdVol.setValue(xmippLib.MDL_IMAGE, fnAlignedVolj, mdVol.addObject()) mdVol.write(fnOutMeta) fnPseudo = self._getPath("pseudoatoms_%d.pdb" % nVoli) fnModes = self._getPath("modes_%d.xmd" % nVoli) fnDeform = self._getExtraPath('compDeformVol_%d_To_Vol_%d.xmd' % (nVolj, nVoli)) sigma = Ts * self.pseudoAtomRadius.get() fnPseudoOut = self._getExtraPath( 'PseudoatomsDeformedPDB_Vol_%d_To_Vol_%d.pdb' % (nVolj, nVoli)) self.runJob('xmipp_nma_alignment_vol', "-i %s --pdb %s --modes %s --sampling_rate %s -o %s --fixed_Gaussian %s --opdb %s"%\ (fnOutMeta, fnPseudo, fnModes, Ts, fnDeform, sigma, fnPseudoOut)) self.runJob( 'xmipp_volume_from_pdb', "-i %s -o %s --sampling %s --fixed_Gaussian %s" % (fnPseudoOut, fnVolOut, Ts, sigma))
def exportData(emxDir, inputSet, ctfSet=None, xmlFile='data.emx', binaryFile=None): """ Export micrographs, coordinates or particles to EMX format. """ cleanPath(emxDir) makePath(emxDir) emxData = emxlib.EmxData() micSet=None if binaryFile is None: binaryFile = xmlFile.replace('.emx', '.mrc') if isinstance(inputSet, SetOfMicrographs): _micrographsToEmx(emxData, inputSet, emxDir, ctfSet) elif isinstance(inputSet, SetOfCoordinates): micSet = inputSet.getMicrographs() _micrographsToEmx(emxData, micSet, emxDir, ctfSet) _particlesToEmx(emxData, inputSet, None, micSet) elif isinstance(inputSet, SetOfParticles): print ("SetOfParticles-----------------------------------------") if inputSet.hasCoordinates(): micSet = inputSet.getCoordinates().getMicrographs() _micrographsToEmx(emxData, micSet, emxDir, writeData=False) fnMrcs = join(emxDir, binaryFile) _particlesToEmx(emxData, inputSet, fnMrcs, micSet) fnXml = join(emxDir, xmlFile) emxData.write(fnXml)
def convertInputStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) tmpPrefix = self._getTmpPath(tsId) path.makePath(tmpPrefix) path.makePath(extraPrefix) ctfTomoSeries = self.getCtfTomoSeriesFromTsId( self.inputSetOfCtfTomoSeries.get(), tsId) """Apply the transformation form the input tilt-series""" outputTsFileName = os.path.join(tmpPrefix, ts.getFirstItem().parseFileName()) ts.applyTransform(outputTsFileName) """Generate angle file""" angleFilePath = os.path.join( tmpPrefix, ts.getFirstItem().parseFileName(extension=".tlt")) ts.generateTltFile(angleFilePath) """Generate defocus file""" defocusFilePath = os.path.join( extraPrefix, ts.getFirstItem().parseFileName(extension=".defocus")) utils.generateDefocusIMODFileFromObject(ctfTomoSeries, defocusFilePath)
def createIterDirsStep(self, iterN): """ Create the necessary directory for a given iteration. """ iterDirs = [self._getFileName(k, iter=iterN) for k in ['iterDir', 'projMatchDirs', 'libraryDirs']] for d in iterDirs: makePath(d) return iterDirs
def validationStep(self, volName, volDir, sym): makePath(volDir) nproc = self.numberOfMpi.get() nT = self.numberOfThreads.get() params = " --volume %s" % volName params += " --odir %s" % volDir params += " --sym %s" % sym self.runJob("xmipp_validation_nontilt", params, numberOfMpi=nproc, numberOfThreads=nT)
def validationStep(self, volName, volDir,sym): makePath(volDir) nproc = self.numberOfMpi.get() nT=self.numberOfThreads.get() params = ' --volume %s' % volName params += ' --odir %s' % volDir params += ' --sym %s' % sym self.runJob('xmipp_validation_nontilt', params,numberOfMpi=nproc,numberOfThreads=nT)
def significantStep(self, volName, volDir, params): nproc = self.numberOfMpi.get() nT = self.numberOfThreads.get() makePath(volDir) params += " --initvolumes %s" % volName params += " --odir %s" % volDir params += " --iter %d" % 1 self.runJob("xmipp_reconstruct_significant", params, numberOfMpi=nproc, numberOfThreads=nT)
def generateTransformFileStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) path.makePath(extraPrefix) utils.formatTransformFile( ts, os.path.join(extraPrefix, ts.getFirstItem().parseFileName(extension=".prexg")))
def significantStep(self, volName, volDir, anglesPath, params): nproc = self.numberOfMpi.get() nT = self.numberOfThreads.get() makePath(volDir) params += " --initvolumes %s" % volName params += " --odir %s" % volDir params += " --iter %d" % 1 self.runJob("xmipp_reconstruct_significant", params, numberOfMpi=nproc, numberOfThreads=nT) copyfile(volDir + "/angles_iter001_00.xmd", self._getExtraPath(anglesPath))
def createOutput(self): smallDict = {} for small in self.inputLibrary.get(): fnSmall = small.getFileName() fnBase = os.path.splitext(os.path.split(fnSmall)[1])[0] if not fnBase in smallDict: smallDict[fnBase]=fnSmall grid = self.inputGrid.get() fnStruct = grid.structureFile.get() if hasattr(grid,"bindingSiteScore"): bindingSiteScore = grid.bindingSiteScore.get() else: bindingSiteScore = None if hasattr(grid,"bindingSiteDScore"): bindingSiteDScore = grid.bindingSiteDScore.get() else: bindingSiteDScore = None smallList = [] posesDir = self._getExtraPath('poses') makePath(posesDir) fhCsv = open(self._getPath('job_pv.csv')) fnPv = self._getPath('job_pv.maegz') i = 0 for line in fhCsv.readlines(): if i>1: tokens = line.split(',') small = SmallMolecule(smallMolFilename=smallDict[tokens[0]]) small.dockingScore = pwobj.Float(tokens[1]) small.ligandEfficiency = pwobj.Float(tokens[2]) small.ligandEfficiencySA = pwobj.Float(tokens[3]) small.ligandEfficiencyLn = pwobj.Float(tokens[4]) small.poseFile = pwobj.String("%d@%s"%(i,fnPv)) small.structFile = pwobj.String(fnStruct) if bindingSiteScore: small.bindingSiteScore = pwobj.Float(bindingSiteScore) if bindingSiteDScore: small.bindingSiteDScore = pwobj.Float(bindingSiteDScore) smallList.append(small) i+=1 fhCsv.close() idxSorted=sortDockingResults(smallList) outputSet = SetOfSmallMolecules().create(path=self._getPath()) for idx in idxSorted: small=smallList[idx] outputSet.append(small) self._defineOutputs(outputSmallMolecules=outputSet) self._defineSourceRelation(self.inputGrid, outputSet) self._defineSourceRelation(self.inputLibrary, outputSet) mae = SchrodingerPoses(filename=fnPv) self._defineOutputs(outputPoses=mae) self._defineSourceRelation(self.inputGrid, mae) self._defineSourceRelation(self.inputLibrary, mae)
def _estimateCTF(self, micFn, micDir, micName): """ Run the estimate CTF program """ localParams = self.__params.copy() if self.doInitialCTF: if self.ctfDict[micName]>0: localParams['defocusU'] = self.ctfDict[micName] localParams['defocus_range'] = 0.01*self.ctfDict[micName] else: localParams['defocusU']=(self._params['maxDefocus']+self._params['minDefocus'])/2 localParams['defocus_range']=(self._params['maxDefocus']-self._params['minDefocus'])/2 # Create micrograph dir under extra directory makePath(micDir) if not exists(micDir): raise Exception("No created dir: %s " % micDir) finalName = micFn ctfDownFactor = self.ctfDownFactor.get() downsampleList = [ctfDownFactor] if self.doCTFAutoDownsampling: downsampleList.append(ctfDownFactor+1) if ctfDownFactor >= 2: downsampleList.append(ctfDownFactor-1) else: if ctfDownFactor > 1: downsampleList.append((ctfDownFactor+1)/2) deleteTmp="" for downFactor in downsampleList: # Downsample if necessary if downFactor != 1: #Replace extension by 'mrc' cause there are some formats that cannot be written (such as dm3) finalName = self._getTmpPath(replaceBaseExt(micFn, 'mrc')) self.runJob("xmipp_transform_downsample","-i %s -o %s --step %f --method fourier" % (micFn, finalName, downFactor)) deleteTmp=finalName # Update _params dictionary with mic and micDir localParams['micFn'] = finalName localParams['micDir'] = self._getFileName('prefix', micDir=micDir) localParams['samplingRate'] = self.inputMics.getSamplingRate() * downFactor # CTF estimation with Xmipp try: self.runJob(self._program, self._args % localParams+" --downSamplingPerformed %f"%downFactor) # mdCTF = md.RowMetaData(self._getFileName('ctfparam', micDir=micDir)) except Exception: break # Check the quality of the estimation and reject it necessary if self.evaluateSingleMicrograph(micFn,micDir): break if deleteTmp != "": cleanPath(deleteTmp)
def convertInputStep(self, tsObjId): ts = self.inputSetOfTiltSeries.get()[tsObjId] tsId = ts.getTsId() extraPrefix = self._getExtraPath(tsId) tmpPrefix = self._getTmpPath(tsId) path.makePath(tmpPrefix) path.makePath(extraPrefix) """Apply the transformation form the input tilt-series""" outputTsFileName = os.path.join(tmpPrefix, ts.getFirstItem().parseFileName()) ts.applyTransform(outputTsFileName)
def projectionLibraryStep(self, volName, volDir, angularSampling): # Generate projections from this reconstruction nproc = self.numberOfMpi.get() nT=self.numberOfThreads.get() volName = self._getExtraPath("volume.vol") makePath(volDir) fnGallery= (volDir+'/gallery.stk') params = '-i %s -o %s --sampling_rate %f --sym %s --method fourier 1 0.25 bspline --compute_neighbors --angular_distance %f --experimental_images %s --max_tilt_angle %f --min_tilt_angle %f'\ %(volName,fnGallery, angularSampling, self.symmetryGroup.get(), -1, self._getExtraPath('scaled_particles.xmd'), self.maxTilt.get(), self.minTilt.get()) self.runJob("xmipp_angular_project_library", params, numberOfMpi=nproc, numberOfThreads=nT)
def dockStep(self, fnGridDir, fnSmall): fnReceptor = os.path.join(fnGridDir, "atomStruct.pdbqt") fnBase = os.path.splitext(os.path.split(fnSmall)[1])[0] fnSmallDir = self._getExtraPath(fnBase) makePath(fnSmallDir) fnDPF = os.path.join(fnSmallDir, fnBase + ".dpf") args = " -l %s -r %s -o %s" % (fnSmall, fnReceptor, fnDPF) args += " -p ga_pop_size=%d" % self.gaPop.get() args += " -p ga_num_evals=%d" % self.gaNumEvals.get() args += " -p ga_num_generations=%d" % self.gaNumGens.get() args += " -p ga_elitism=%d" % self.gaElitism.get() args += " -p ga_mutation_rate=%f" % self.gaMutationRate.get() args += " -p ga_crossover_rate=%f" % self.gaCrossOverRate.get() args += " -p ga_window_size=%d" % self.gaWindowSize.get() args += " -p sw_max_its=%d" % self.swMaxIts.get() args += " -p sw_max_succ=%d" % self.swMaxSucc.get() args += " -p sw_max_fail=%d" % self.swMaxFail.get() args += " -p sw_rho=%f" % self.swRho.get() args += " -p sw_lb_rho=%d" % self.swLbRho.get() args += " -p ls_search_freq=%f" % self.lsFreq.get() args += " -p ga_run=%d" % self.gaRun.get() args += " -p rmstol=%f" % self.rmsTol.get() self.runJob( bioinformatics_plugin.getMGLPath('bin/pythonsh'), bioinformatics_plugin.getADTPath('Utilities24/prepare_dpf42.py') + args) fnSmallLocal = os.path.split(fnSmall)[1] createLink(fnSmall, os.path.join(fnSmallDir, fnSmallLocal)) createLink(fnReceptor, os.path.join(fnSmallDir, "atomStruct.pdbqt")) args = " -r atomStruct.pdbqt -l %s -o library.gpf" % fnSmallLocal self.runJob( bioinformatics_plugin.getMGLPath('bin/pythonsh'), bioinformatics_plugin.getADTPath('Utilities24/prepare_gpf4.py') + args, cwd=fnSmallDir) args = "-p library.gpf -l library.glg" self.runJob(bioinformatics_plugin.getAutodockPath("autogrid4"), args, cwd=fnSmallDir) args = "-p %s.dpf -l %s.dlg" % (fnBase, fnBase) self.runJob(bioinformatics_plugin.getAutodockPath("autodock4"), args, cwd=fnSmallDir) # Clean a bit cleanPattern(os.path.join(fnSmallDir, "atomStruct.*.map"))
def copyMicDirectoryStep(self, id): """ Copy micrograph's directory tree for recalculation""" ctfModel = self.recalculateSet[id] mic = ctfModel.getMicrograph() prevDir = self._getPrevMicDir(ctfModel) micDir = self._getMicrographDir(mic) if not prevDir == micDir: # Create micrograph dir under extra directory makePath(micDir) if not exists(micDir): raise Exception("No created dir: %s " % micDir) copyTree(prevDir, micDir)
def copyMicDirectoryStep(self, micId): """ Copy micrograph's directory tree for recalculation""" ctfModel = self.recalculateSet[micId] mic = ctfModel.getMicrograph() prevDir = self._getPrevMicDir(ctfModel) micDir = self._getMicrographDir(mic) if not prevDir == micDir: # Create micrograph dir under extra directory makePath(micDir) if not exists(micDir): raise Exception("No created dir: %s " % micDir) copyTree(prevDir, micDir)
def _getCtfFile(self, tsId, coordCounter=None, fileExt=CTFSTAR, ctfMode=CTF3D_PER_VOLUME): ctfDir = join(self.getTSPath(tsId), CTFDIRBASENAME) pwutils.makePath(ctfDir) if ctfMode == CTF3D_PER_VOLUME: baseCtfFn = pwutils.removeBaseExt(tsId) + "_ctf" else: baseCtfFn = pwutils.removeBaseExt( tsId) + "_ctf_%06d" % coordCounter return join(ctfDir, baseCtfFn + fileExt)
def significantStep(self, volName, volDir, anglesPath, params): nproc = self.numberOfMpi.get() nT = self.numberOfThreads.get() makePath(volDir) params += ' --initvolumes %s' % volName params += ' --odir %s' % volDir params += ' --iter %d' % 1 self.runJob('xmipp_reconstruct_significant', params, numberOfMpi=nproc, numberOfThreads=nT) copyfile(volDir + '/angles_iter001_00.xmd', self._getExtraPath(anglesPath))
def reformatOutputStep(self,fnPseudoatoms): self._enterWorkingDir() n = self._countAtoms(fnPseudoatoms) self.runJob("nma_reformat_vector_foranimate.pl","%d fort.11" % n,env=getNMAEnviron()) self.runJob("cat","vec.1* > vec_ani.txt") self.runJob("rm","-f vec.1*") self.runJob("nma_reformat_vector.pl","%d fort.11" % n,env=getNMAEnviron()) fnModesDir="modes" makePath(fnModesDir) self.runJob("mv","-f vec.* %s"%fnModesDir) self.runJob("nma_prepare_for_animate.py","",env=getNMAEnviron()) self.runJob("rm","-f vec_ani.txt fort.11 matrice.sdijf") moveFile('vec_ani.pkl','extra/vec_ani.pkl') self._leaveWorkingDir()
def validationStep(self, volName, volDir, sym): makePath(volDir) aFile = self._getExtraPath("exp_particles.xmd") aFileRef = self._getExtraPath("ref_particles.xmd") params = " --volume %s" % volName params += " --angles_file %s" % aFile params += " --angles_file_ref %s" % aFileRef params += " --odir %s" % volDir params += " --sym %s" % sym if self.doNotUseWeights: params += " --dontUseWeights" self.runJob("xmipp_multireference_aligneability", params, numberOfMpi=1, numberOfThreads=1)
def analyzeOutOfCores(self,subset): """ Analyze which images are out of cores """ levelMdFiles = self._getAllLevelMdFiles(subset) for fn in levelMdFiles: mdAll=md.MetaData() blocks = md.getBlocksInMetaDataFile(fn) fnDir=dirname(fn) # Gather all images in block for block in blocks: if block.startswith('class0'): mdClass=md.MetaData(block+"@"+fn) mdAll.unionAll(mdClass) if mdAll.size()>0: # Compute difference to images fnSubset=join(fnDir,"images%s.xmd"%subset) mdAll.write(fnSubset) fnOutOfSubset=join(fnDir,"imagesOut.xmd") inputMd = self._getFileName('input_particles') args = "-i %s --set subtraction %s -o %s" % (inputMd, fnSubset, fnOutOfSubset) self.runJob("xmipp_metadata_utilities", args, numberOfMpi=1, numberOfThreads=1) # Remove disabled and intermediate files mdClass=md.MetaData(fnOutOfSubset) mdClass.removeDisabled() fnRejected="images_rejected@"+fn mdClass.write(fnRejected,md.MD_APPEND) cleanPath(fnOutOfSubset) cleanPath(fnSubset) # If enough images, make a small summary if mdClass.size()>100: from math import ceil fnRejectedDir=join(fnDir,"rejected%s"%subset) makePath(fnRejectedDir) Nclasses=int(ceil(mdClass.size()/300)) self.runJob("xmipp_classify_CL2D", "-i %s --nref0 1 --nref %d --iter 5 --distance " "correlation --classicalMultiref " "--classifyAllImages --odir %s" %( fnRejected, Nclasses, fnRejectedDir))
def _insertAllSteps(self): self._params = {} # diameter must be passed in Armstrongs and therefore should be converted self._params['diam'] = self.diameter.get() * self.getInputMicrographs().getSamplingRate() # self._params['num-slices'] = self.numberSizes.get() # self._params['size-range'] = self.sizeRange.get() self._params['apix'] = self.inputMicrographs.get().getSamplingRate() self._params['thresh'] = self.threshold.get() # self._params['max-thresh'] = self.maxThreshold.get() # self._params['max-area'] = self.maxArea.get() # self._params['max-peaks'] = self.maxPeaks.get() args = "" for par, val in self._params.iteritems(): args += " --%s=%s" % (par, str(val)) if self.invert: args += " --invert" args += " " + self.extraParams.get('') deps = [] # Store all steps ids, final step createOutput depends on all of them ih = ImageHandler() for mic in self.inputMicrographs.get(): # Create micrograph folder micName = mic.getFileName() micDir = self._getTmpPath(removeBaseExt(micName)) makePath(micDir) # If needed convert micrograph to mrc format, otherwise link it if getExt(micName) != ".mrc": fnMicBase = replaceBaseExt(micName, 'mrc') inputMic = join(micDir, fnMicBase) ih.convert(mic.getLocation(), inputMic) else: inputMic = join(micDir, basename(micName)) createLink(micName, inputMic) # Insert step to execute program stepId = self._insertFunctionStep('executeDogpickerStep', inputMic, args) deps.append(stepId) self._insertFinalSteps(deps)
def projectionLibraryStep(self, volId): # Generate projections from this reconstruction volDir = self._getVolDir(volId) makePath(volDir) params = {"inputVol" : self._getVolFiltered(volId), "gallery" : self._getGalleryStack(volId), "sampling" : self.partSet.getSamplingRate(), "symmetry" : self.symmetryGroup.get(), "angSampling" : self.angularSampling.get(), "expParticles" : self._getMdParticles() } args = '-i %(inputVol)s -o %(gallery)s --sampling_rate %(sampling)f --sym %(symmetry)s' args += ' --method fourier 1 0.25 bspline --compute_neighbors --angular_distance %(angSampling)f' args += ' --experimental_images %(expParticles)s --max_tilt_angle 90' self.runJob("xmipp_angular_project_library", args % params)
def convertInputStep(self): """ Read the input metadatata. """ # Get the converted input micrographs in Xmipp format makePath(self._getExtraPath("untilted")) makePath(self._getExtraPath("tilted")) if self.typeOfSet.get() == TYPE_PARTICLES: U_set = self.untiltPar.get().getCoordinates() T_set = self.tiltPar.get().getCoordinates() if (U_set or T_set) is None: U_set = self._createSetOfCoordinates(self.tiltpair.get().getUntilted(), suffix='_untilted') T_set = self._createSetOfCoordinates(self.tiltpair.get().getTilted(), suffix='_tilted') untiltPar = self.untiltPar.get() for particle_u in untiltPar: newCoord = particle_u.getCoordinate().clone() newCoord.copyObjId(particle_u) U_set.append(newCoord) # tiltPar = self.tiltPar.get() for particle_t in tiltPar: newCoord = particle_t.getCoordinate().clone() newCoord.copyObjId(particle_t) T_set.append(newCoord) aux = self.untiltPar.get() aux2 = aux[1] bos, y_, z_ = aux2.getDim() U_set.setBoxSize(bos) T_set.setBoxSize(bos) else: U_set = self.untiltCoor.get() T_set = self.tiltCoor.get() writeSetOfCoordinates(self._getExtraPath("untilted"), U_set) writeSetOfCoordinates(self._getExtraPath("tilted"), T_set)
def convertImagesStep(self): from pyworkflow.em.packages.eman2.convert import writeSetOfParticles partSet = self._getInputParticles() partAlign = partSet.getAlignment() storePath = self._getExtraPath("particles") makePath(storePath) writeSetOfParticles(partSet, storePath, alignType=partAlign) if partSet.hasCTF(): program = getEmanProgram('e2ctf.py') acq = partSet.getAcquisition() args = " --voltage %3d" % acq.getVoltage() args += " --cs %f" % acq.getSphericalAberration() args += " --ac %f" % (100 * acq.getAmplitudeContrast()) if not partSet.isPhaseFlipped(): args += " --phaseflip" args += " --computesf --apix %f --allparticles --autofit --curdefocusfix --storeparm -v 8" % (partSet.getSamplingRate()) self.runJob(program, args, cwd=self._getExtraPath()) program = getEmanProgram('e2buildsets.py') args = " --setname=inputSet --allparticles --minhisnr=-1" self.runJob(program, args, cwd=self._getExtraPath())
def createOutputStep(self): self.plotsDir = self._getExtraPath('plots') makePath(self.plotsDir) fnClassVectors = self._params['kvectors'].replace('xmd', 'vec') f = open(fnClassVectors) self.classArray = np.fromfile(f, dtype=np.float32) f.close() fnImgVectors = self._params['vectors'].replace('xmd', 'vec') f = open(fnImgVectors) self.imgArray = np.fromfile(f, dtype=np.float32) f.close() self.imgCount = 0 imgSet = self.inputParticles.get() classes2DSet = self._createSetOfClasses2D(imgSet) readSetOfClasses2D(classes2DSet, self._params['kclasses'], preprocessClass=self._preprocessClass, postprocessImageRow=self._postprocessImageRow) self._defineOutputs(outputClasses=classes2DSet) self._defineSourceRelation(self.inputParticles, classes2DSet)
def significantStep(self, isTilt): if isTilt == 1: params = ' -i %s' % self._getPath('input_tilted_particles.xmd') outputDir = self._getExtraPath("tilted") elif isTilt == 0: params = ' -i %s' % self._getPath('input_untilted_particles.xmd') outputDir = self._getExtraPath("untilted") firstImage = self.inputTiltPair.get().getUntilted().getFirstItem() maxShift = 0.35 * firstImage.getDim()[0] params += ' --sym %s' % self.symmetryGroup.get() params += ' --alpha0 %f --alphaF %f' % ((1-self.alpha.get())/100,(1-self.alpha.get())/100) params += ' --angularSampling %f' % self.angularSampling.get() params += ' --dontReconstruct' params += ' --iter 1' params += ' --initvolumes %s' % getImageLocation(self.inputVolume.get()) params += ' --useForValidation 3' params += ' --maxShift %f' % maxShift params += ' --odir %s' % outputDir makePath(outputDir) self.runJob('xmipp_reconstruct_significant', params)
def globalAssignment(self): iteration=1 fnDirCurrent=self._getExtraPath("Iter%03d"%iteration) makePath(fnDirCurrent) fnGlobal=join(fnDirCurrent,"globalAssignment") makePath(fnGlobal) targetResolution=self.significantMaxResolution.get() TsCurrent=max(self.TsOrig,targetResolution/3) self.prepareImages(fnGlobal,TsCurrent) self.prepareReferences(fnGlobal,TsCurrent,targetResolution) # Calculate angular step at this resolution ResolutionAlignment=targetResolution newXdim=self.readInfoField(fnGlobal,"size",xmipp.MDL_XSIZE) angleStep=self.calculateAngStep(newXdim, TsCurrent, ResolutionAlignment) self.writeInfoField(fnGlobal,"angleStep",xmipp.MDL_ANGLE_DIFF,float(angleStep)) # Significant alignment alpha=1-0.01*self.significantSignificance.get() fnDirSignificant=join(fnGlobal,"significant") fnImgs=join(fnGlobal,"images.xmd") makePath(fnDirSignificant) # Create defocus groups row=getFirstRow(fnImgs) if row.containsLabel(xmipp.MDL_CTF_MODEL) or row.containsLabel(xmipp.MDL_CTF_DEFOCUSU): self.runJob("xmipp_ctf_group","--ctfdat %s -o %s/ctf:stk --pad 2.0 --sampling_rate %f --phase_flipped --error 0.1 --resol %f"%\ (fnImgs,fnDirSignificant,TsCurrent,targetResolution),numberOfMpi=1) moveFile("%s/ctf_images.sel"%fnDirSignificant,"%s/ctf_groups.xmd"%fnDirSignificant) cleanPath("%s/ctf_split.doc"%fnDirSignificant) md = xmipp.MetaData("numberGroups@%s"%join(fnDirSignificant,"ctfInfo.xmd")) fnCTFs="%s/ctf_ctf.stk"%fnDirSignificant numberGroups=md.getValue(xmipp.MDL_COUNT,md.firstObject()) ctfPresent=True else: numberGroups=1 ctfPresent=False # Generate projections fnReferenceVol=join(fnGlobal,"volumeRef.vol") fnGallery=join(fnDirSignificant,"gallery.stk") fnGalleryMd=join(fnDirSignificant,"gallery.xmd") args="-i %s -o %s --sampling_rate %f --sym %s --min_tilt_angle %f --max_tilt_angle %f"%\ (fnReferenceVol,fnGallery,angleStep,self.symmetryGroup,self.angularMinTilt.get(),self.angularMaxTilt.get()) self.runJob("xmipp_angular_project_library",args) cleanPath(join(fnDirSignificant,"gallery_angles.doc")) moveFile(join(fnDirSignificant,"gallery.doc"), fnGalleryMd) fnAngles=join(fnGlobal,"anglesDisc.xmd") for j in range(1,numberGroups+1): fnAnglesGroup=join(fnDirSignificant,"angles_group%02d.xmd"%j) if not exists(fnAnglesGroup): if ctfPresent: fnGroup="ctfGroup%06d@%s/ctf_groups.xmd"%(j,fnDirSignificant) fnGalleryGroup=join(fnDirSignificant,"gallery_group%06d.stk"%j) fnGalleryGroupMd=join(fnDirSignificant,"gallery_group%06d.xmd"%j) self.runJob("xmipp_transform_filter", "-i %s -o %s --fourier binary_file %d@%s --save_metadata_stack %s --keep_input_columns"%\ (fnGalleryMd,fnGalleryGroup,j,fnCTFs,fnGalleryGroupMd)) else: fnGroup=fnImgs fnGalleryGroupMd=fnGalleryMd args='-i %s --initgallery %s --odir %s --sym %s --iter 1 --alpha0 %f --alphaF %f --angularSampling %f --maxShift %d '\ '--minTilt %f --maxTilt %f --useImed --angDistance %f --dontReconstruct'%\ (fnGroup,fnGalleryGroupMd,fnDirSignificant,self.symmetryGroup,alpha,alpha,angleStep,\ round(self.angularMaxShift.get()*newXdim/100),self.angularMinTilt.get(),self.angularMaxTilt.get(),2*angleStep) self.runJob('xmipp_reconstruct_significant',args,numberOfMpi=self.numberOfThreads.get()) moveFile(join(fnDirSignificant,"angles_iter001_00.xmd"),join(fnDirSignificant,"angles_group%02d.xmd"%j)) self.runJob("rm -f",fnDirSignificant+"/images_*iter00?_*.xmd",numberOfMpi=1) if j==1: copyFile(fnAnglesGroup, fnAngles) else: self.runJob("xmipp_metadata_utilities","-i %s --set union %s"%(fnAngles,fnAnglesGroup),numberOfMpi=1) if ctfPresent: self.runJob("rm -f",fnDirSignificant+"/gallery*",numberOfMpi=1)
def setupTestOutput(cls): """ Create the output folder for a give Test class. """ cls.outputPath = join(TESTS_OUTPUT, cls.__name__) cleanPath(cls.outputPath) makePath(cls.outputPath)
def classifyOneGroup(self, projNumber, projMdBlock, projRef, mdClasses, mdImages): """ Classify one of the neighbourhood groups if not empty. Class information will be stored in output metadata: mdOut """ blockSize = md.getSize(projMdBlock) Nclasses = self.directionalClasses.get() Nlevels = int(math.ceil(math.log(Nclasses) / math.log(2))) # Skip projection directions with not enough images to # create a given number of classes if blockSize / Nclasses < 10: return fnDir = self._getExtraPath("direction_%s" % projNumber) makePath(fnDir) # Run CL2D classification for the images assigned to one direction args = "-i %s " % projMdBlock args += "--odir %s " % fnDir args += "--ref0 %s --iter 1 --nref %d " % (projRef, Nclasses) args += "--distance correlation --classicalMultiref " args += "--maxShift %f " % self.maxShift try: self.runJob("xmipp_classify_CL2D", args) except: return # After CL2D the stk and xmd files should be produced classesXmd = join(fnDir, "level_%02d/class_classes.xmd" % Nlevels) classesStk = join(fnDir, "level_%02d/class_classes.stk" % Nlevels) # Let's check that the output was produced if not exists(classesStk): return # Run align of the class average and the projection representative fnAlignRoot = join(fnDir, "classes") args = "-i %s " % classesStk args += "--ref %s " % projRef args += " --oroot %s --iter 1" % fnAlignRoot self.runJob("xmipp_image_align", args, numberOfMpi=1) # Apply alignment args = "-i %s_alignment.xmd --apply_transform" % fnAlignRoot self.runJob("xmipp_transform_geometry", args, numberOfMpi=1) for classNo in range(1, Nclasses+1): localImagesMd = xmipp.MetaData("class%06d_images@%s" % (classNo, classesXmd)) # New class detected self.classCount += 1 # Check which images have not been assigned yet to any class # and assign them to this new class for objId in localImagesMd: imgId = localImagesMd.getValue(xmipp.MDL_ITEM_ID, objId) # Add images not classify yet and store their class number if imgId not in self.classImages: self.classImages.add(imgId) newObjId = mdImages.addObject() mdImages.setValue(xmipp.MDL_ITEM_ID, imgId, newObjId) mdImages.setValue(xmipp.MDL_REF2, self.classCount, newObjId) newClassId = mdClasses.addObject() mdClasses.setValue(xmipp.MDL_REF, projNumber, newClassId) mdClasses.setValue(xmipp.MDL_REF2, self.classCount, newClassId) mdClasses.setValue(xmipp.MDL_IMAGE, "%d@%s" % (classNo, classesStk), newClassId) mdClasses.setValue(xmipp.MDL_IMAGE1, projRef, newClassId) mdClasses.setValue(xmipp.MDL_CLASS_COUNT,localImagesMd.size(),newClassId)
def _generateAnimation(self): prot = self.protocol projectorFile = prot.getProjectorFile() animation = self.trajectoriesWindow.getAnimationName() animationPath = prot._getExtraPath('animation_%s' % animation) cleanPath(animationPath) makePath(animationPath) animationRoot = join(animationPath, 'animation_%s' % animation) trajectoryPoints = np.array([p.getData() for p in self.trajectoriesWindow.pathData]) if projectorFile: M = np.loadtxt(projectorFile) deformations = np.dot(trajectoryPoints, np.linalg.pinv(M)) np.savetxt(animationRoot + 'trajectory.txt', trajectoryPoints) else: Y = np.loadtxt(prot.getOutputMatrixFile()) X = np.loadtxt(prot.getDeformationFile()) # Find closest points in deformations deformations = [X[np.argmin(np.sum((Y - p)**2, axis=1))] for p in trajectoryPoints] pdb = prot.getInputPdb() pdbFile = pdb.getFileName() modesFn = prot.inputNMA.get()._getExtraPath('modes.xmd') for i, d in enumerate(deformations): atomsFn = animationRoot + 'atomsDeformed_%02d.pdb' % (i+1) cmd = '-o %s --pdb %s --nma %s --deformations %s' % (atomsFn, pdbFile, modesFn, str(d)[1:-1]) runJob(None, 'xmipp_pdb_nma_deform', cmd, env=prot._getEnviron()) # Join all deformations in a single pdb # iterating going up and down through all points # 1 2 3 ... n-2 n-1 n n-1 n-2 ... 3, 2 n = len(deformations) r1 = range(1, n+1) r2 = range(2, n) # Skip 1 at the end r2.reverse() loop = r1 + r2 trajFn = animationRoot + '.pdb' trajFile = open(trajFn, 'w') for i in loop: atomsFn = animationRoot + 'atomsDeformed_%02d.pdb' % i atomsFile = open(atomsFn) for line in atomsFile: trajFile.write(line) trajFile.write('TER\nENDMDL\n') atomsFile.close() trajFile.close() # Delete temporary atom files cleanPattern(animationRoot + 'atomsDeformed_??.pdb') # Generate the vmd script vmdFn = animationRoot + '.vmd' vmdFile = open(vmdFn, 'w') vmdFile.write(""" mol new %s animate style Loop display projection Orthographic mol modcolor 0 0 Index mol modstyle 0 0 Beads 1.000000 8.000000 animate speed 0.5 animate forward """ % trajFn) vmdFile.close() VmdView(' -e ' + vmdFn).show()