def predict(self, posTestDict, negTestDict, predictDict): """ posTestDict, negTestDict, predictDict: { fnameToMetadata: { weight:int } """ netDataPath = self._getExtraPath('nnetData') if not os.path.isdir(netDataPath) and self.doContinue.get(): prevRunPath = self.continueRun.get()._getExtraPath('nnetData') copyTree(prevRunPath, netDataPath) if self.usesGpu(): numberOfThreads = None gpuToUse = self.getGpuList()[0] else: numberOfThreads = self.numberOfThreads.get() gpuToUse = None outParticlesPath = self._getPath("particles.xmd") fnamesPred, weightsPred = self.__dataDict_toStrs(predictDict) args = " -n %s --mode score -i %s -o %s " % (netDataPath, fnamesPred, outParticlesPath) if posTestDict and negTestDict: fnamesPosTest, weightsPosTest = self.__dataDict_toStrs(posTestDict) fnamesNegTest, weightsNegTest = self.__dataDict_toStrs(negTestDict) args += " --testingTrue %s --testingFalse %s " % (fnamesPosTest, fnamesNegTest) if not gpuToUse is None: args += " -g %s" % (gpuToUse) if not numberOfThreads is None: args += " -t %s" % (numberOfThreads) self.runJob('xmipp_deep_consensus', args, numberOfMpi=1)
def polishStep(self, params): """ Create the input file in STAR format as expected by Relion. If the input particles comes from Relion, just link the file. """ from pyworkflow.utils.path import copyTree copyTree(self.refineRun.get()._getExtraPath(), self._getExtraPath()) self.runJob(self._getProgram('relion_particle_polish'), params)
def train(self, posTrainDict, negTrainDict): """ posTrainDict, negTrainDict: { fnameToMetadata: weight (int) } """ nEpochs = self.nEpochs.get() netDataPath = self._getExtraPath('nnetData') if self.doContinue.get(): prevRunPath = self.continueRun.get()._getExtraPath('nnetData') copyTree(prevRunPath, netDataPath) if not self.keepTraining.get(): nEpochs = 0 if self.usesGpu(): numberOfThreads = None gpuToUse = self.getGpuList()[0] else: numberOfThreads = self.numberOfThreads.get() gpuToUse = None fnamesPos, weightsPos = self.__dataDict_toStrs(posTrainDict) fnamesNeg, weightsNeg = self.__dataDict_toStrs(negTrainDict) args = " -n %s --mode train -p %s -f %s --trueW %s --falseW %s" % ( netDataPath, fnamesPos, fnamesNeg, weightsPos, weightsNeg) args += " -e %s -l %s -r %s -m %s " % (nEpochs, self.learningRate.get( ), self.l2RegStrength.get(), self.nModels.get()) if not self.auto_stopping.get(): args += " -s" if not gpuToUse is None: args += " -g %s" % (gpuToUse) if not numberOfThreads is None: args += " -t %s" % (numberOfThreads) self.runJob('xmipp_deep_consensus', args, numberOfMpi=1)
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 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 _preprocessMicrographRow(self, img, imgRow): if self._imgPath: # Create a link or copy files to extraPath # and update the Row properly micFile = imgRow.getValue(md.MDL_MICROGRAPH) micBase = basename(micFile) micDst = self.protocol._getExtraPath(micBase) self.copyOrLink(join(self._imgPath, micFile), micDst) imgRow.setValue(md.MDL_MICROGRAPH, micDst) self._fillMicName(img, micBase) if self._ctfPath: # Read Xmipp ctfModel parameters and add # to the original micrograph row ctfFile = imgRow.getValue(md.MDL_CTF_MODEL) ctfPath = join(self._imgPath, ctfFile) ctfRow = md.Row() ctfRow.readFromFile(ctfPath) imgRow.copyFromRow(ctfRow) # Also copy or link to the result micrograph # folder output by Xmipp containing the PSD and other images ctfSrcDir = dirname(ctfPath) ctfBaseDir = basename(ctfSrcDir) ctfDstDir = self.protocol._getExtraPath(ctfBaseDir) if self.copyOrLink == createLink: createLink(ctfSrcDir, ctfDstDir) else: # use copyTree instead of copyFile copyTree(ctfSrcDir, ctfDstDir) # Fix the path to psd files for label in CTF_PSD_DICT.values(): filePath = imgRow.getValue(label) # Take the last part of the path including # the filename and the folder up to that fileName = basename(filePath) newFilePath = join(ctfDstDir, fileName) imgRow.setValue(label, newFilePath)
def copyMicAssessOutput(self, numPass): copyTree(self._getTmpPath('output%s' % numPass), self._getExtraPath('MicAssess'))