def main(): args = get_parser().parse_args() projName = args.project # Create a manager and load the project manager = Manager() cwd = os.getcwd() # Keep current directory to restore it later project = manager.loadProject(projName) # Export protocols as a dict jsonDict = project.getProtocolsDict() os.chdir(cwd) # Restore after project load if args.output: print("Writing workflow to file: ", args.output) with open(args.output, 'w') as f: json.dump(list(jsonDict.values()), f, indent=4, separators=(',', ': ')) else: print( json.dumps(list(jsonDict.values()), indent=4, separators=(',', ': ')))
def __init__(self): projName = self.__class__.__name__ manager = Manager() if manager.hasProject(projName): self.project = manager.loadProject(projName) else: self.project = manager.createProject(projName) # Use graph view as default settings = self.project.getSettings() settings.setRunsView(1) # graph view settings.write() self.loadWorkflow()
def main(): if len(sys.argv) != 3: usage("Incorrect number of input parameters") projName = sys.argv[1] searchDir = os.path.abspath(sys.argv[2]) # Create a new project manager = Manager() if not manager.hasProject(projName): usage("Nonexistent project: %s" % pwutils.red(projName)) if not os.path.exists(searchDir): usage("Nonexistent SEARCH_DIR: %s" % pwutils.red(searchDir)) project = manager.loadProject(projName) project.fixLinks(searchDir)
def _writeSubset(self, subset): """ Generated the output of this subset. """ newSubsetName = 'outputParticles_%03d' % self._counter self.info("Creating new subset: %s" % newSubsetName) subset.write() self._defineOutputs(**{newSubsetName: subset}) self._defineTransformRelation(self.inputParticles, subset) # The following is required to commit the changes to the database self._store(subset) subset.close() manager = Manager() project = manager.loadProject(self.getProject().getName()) input2D = self.input2dProtocol.get() copyProt = project.copyProtocol(project.getProtocol(input2D.getObjId())) copyProt.inputParticles.set(project.getProtocol(self.getObjId())) copyProt.inputParticles.setExtended(newSubsetName) project.scheduleProtocol(copyProt, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(copyProt.getObjId())
Use readOnly=True (or False) to set/unset read only property Use lifeTime=X for setting X hours or None to unset life time of the project. """ % error sys.exit(1) n = len(sys.argv) if n < 2 or n > 4: usage("Incorrect number of input parameters") # Load the given project projectsDir = os.path.join(pw.Config.SCIPION_USER_DATA, 'projects') projName = sys.argv[1] manager = Manager() project = manager.loadProject(projName) if project is None: usage("Project '%s' does not exist in: \n %s" % (projName, projectsDir)) setReadOnly = False setLifeTime = False for arg in sys.argv: if arg.startswith('readOnly='): setReadOnly = True value = arg.split('readOnly=')[1] b = Boolean(value=value) readOnlyValue = b.get() elif arg.startswith('lifeTime='): setLifeTime = True
def monitorStep(self): self._runPrerequisites = [] manager = Manager() project = manager.loadProject(self.getProject().getName()) percentage = [1.14, 2.29, 3.44, 5.74, 9.19, 14.94, 24.13, 39.08] numGlobalIters = len(percentage) + 2 self.consecutiveBimodal = 2 self.listConsecutiveBimodal = [] targetResolution = self.minimumTargetResolution.get() #Global iterations for i in range(numGlobalIters): self.convertInputStep(percentage, i) print("Target resolution - group %s: %f " % (chr(65 + i), float(targetResolution))) sys.stdout.flush() if i == 0: previousProtVol = self namePreviousVol = 'outputVolumesInit' else: previousProtVol = newHighRes namePreviousVol = 'outputVolume' newHighRes = project.newProtocol( XmippProtReconstructHighRes, objLabel='HighRes - group %s' % chr(65 + i), symmetryGroup=self.symmetryGroup.get(), numberOfIterations=1, particleRadius=self.particleRadius.get(), maximumTargetResolution=targetResolution, alignmentMethod=XmippProtReconstructHighRes.GLOBAL_ALIGNMENT, angularMaxShift=self.maxShift.get(), angularMinTilt=self.angularMinTilt.get(), angularMaxTilt=self.angularMaxTilt.get(), postAdHocMask=self.postAdHocMask.get(), postSymmetryWithinMask=self.postSymmetryWithinMask.get(), postSymmetryWithinMaskType=self.postSymmetryWithinMaskType.get( ), postSymmetryWithinMaskMask=self.postSymmetryWithinMaskMask.get( ), postSymmetryHelical=self.postSymmetryHelical.get(), postSymmetryHelicalRadius=self.postSymmetryHelicalRadius.get(), postSymmetryHelicalDihedral=self.postSymmetryHelicalDihedral. get(), postSymmetryHelicalMinRot=self.postSymmetryHelicalMinRot.get(), postSymmetryHelicalMaxRot=self.postSymmetryHelicalMaxRot.get(), postSymmetryHelicalMinZ=self.postSymmetryHelicalMinZ.get(), postSymmetryHelicalMaxZ=self.postSymmetryHelicalMaxZ.get(), postScript=self.postScript.get(), postSignificantDenoise=self.postSignificantDenoise.get(), postFilterBank=self.postFilterBank.get(), postLaplacian=self.postLaplacian.get(), postDeconvolve=self.postDeconvolve.get(), postSoftNeg=self.postSoftNeg.get(), postSoftNegK=self.postSoftNegK.get(), postDifference=self.postDifference.get(), numberOfMpi=self.numberOfMpi.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get()) previousProtPart = self namePreviousParticles = 'outputParticles%s' % chr(65 + i) newHighRes.inputParticles.set(previousProtPart) newHighRes.inputParticles.setExtended(namePreviousParticles) newHighRes.inputVolumes.set(previousProtVol) newHighRes.inputVolumes.setExtended(namePreviousVol) project.scheduleProtocol(newHighRes) # Next schedule will be after this one self._runPrerequisites.append(newHighRes.getObjId()) self.childs.append(newHighRes) finishedIter = False while finishedIter == False: time.sleep(15) newHighRes = self._updateProtocol(newHighRes) if newHighRes.isFailed() or newHighRes.isAborted(): raise Exception('XmippProtReconstructHighRes has failed') if newHighRes.isFinished(): finishedIter = True fnDir = newHighRes._getExtraPath("Iter%03d" % 1) fnFSCs = open(self._getExtraPath('fnFSCs.txt'), 'a') fnFSCs.write(join(fnDir, "fsc.xmd") + " \n") fnFSCs.close() targetResolution = self.checkOutputsStep(newHighRes, i, False) targetResolution = max(targetResolution, self.maximumTargetResolution.get()) if i >= 7: #We are in the last three iterations #Check the output particles and remove all the disabled ones fnOutParticles = newHighRes._getPath('angles.xmd') params = '-i %s --query select "enabled==1"' % (fnOutParticles) self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1) fnFinal = self._getExtraPath('inputLocalHighRes1.xmd') if i == 7: copy(fnOutParticles, fnFinal) else: params = ' -i %s --set union %s -o %s' % ( fnFinal, fnOutParticles, fnFinal) self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1) if i == 9: outputinputSetOfParticles = self._createSetOfParticles( ) outputinputSetOfParticles.copyInfo( self.inputParticles.get()) readSetOfParticles(fnFinal, outputinputSetOfParticles) self._defineOutputs( outputParticlesLocal1=outputinputSetOfParticles) self._store(outputinputSetOfParticles) #Local iterations numLocalIters = 5 for i in range(numLocalIters): if i > 2: minPrevRes = prevTargetResolution if targetResolution > minPrevRes: print("Target resolution is stuck") sys.stdout.flush() break prevTargetResolution = targetResolution print("Target resolution - INPUT local %d: %f " % ((i + 1), float(targetResolution))) sys.stdout.flush() previousProtVol = newHighRes namePreviousVol = 'outputVolume' #calling highres local with the new input set newHighRes = project.newProtocol( XmippProtReconstructHighRes, objLabel='HighRes - local %d' % (i + 1), symmetryGroup=self.symmetryGroup.get(), numberOfIterations=1, particleRadius=self.particleRadius.get(), maximumTargetResolution=targetResolution, alignmentMethod=XmippProtReconstructHighRes.LOCAL_ALIGNMENT, angularMaxShift=self.maxShift.get(), angularMinTilt=self.angularMinTilt.get(), angularMaxTilt=self.angularMaxTilt.get(), postAdHocMask=self.postAdHocMask.get(), postSymmetryWithinMask=self.postSymmetryWithinMask.get(), postSymmetryWithinMaskType=self.postSymmetryWithinMaskType.get( ), postSymmetryWithinMaskMask=self.postSymmetryWithinMaskMask.get( ), postSymmetryHelical=self.postSymmetryHelical.get(), postSymmetryHelicalRadius=self.postSymmetryHelicalRadius.get(), postSymmetryHelicalDihedral=self.postSymmetryHelicalDihedral. get(), postSymmetryHelicalMinRot=self.postSymmetryHelicalMinRot.get(), postSymmetryHelicalMaxRot=self.postSymmetryHelicalMaxRot.get(), postSymmetryHelicalMinZ=self.postSymmetryHelicalMinZ.get(), postSymmetryHelicalMaxZ=self.postSymmetryHelicalMaxZ.get(), postScript=self.postScript.get(), postSignificantDenoise=self.postSignificantDenoise.get(), postFilterBank=self.postFilterBank.get(), postLaplacian=self.postLaplacian.get(), postDeconvolve=self.postDeconvolve.get(), postSoftNeg=self.postSoftNeg.get(), postSoftNegK=self.postSoftNegK.get(), postDifference=self.postDifference.get(), numberOfMpi=self.numberOfMpi.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get()) newHighRes.inputParticles.set(self) namePreviousParticles = 'outputParticlesLocal%d' % (i + 1) newHighRes.inputParticles.setExtended(namePreviousParticles) newHighRes.inputVolumes.set(previousProtVol) newHighRes.inputVolumes.setExtended(namePreviousVol) project.scheduleProtocol(newHighRes, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(newHighRes.getObjId()) self.childs.append(newHighRes) finishedIter = False while finishedIter == False: time.sleep(15) newHighRes = self._updateProtocol(newHighRes) if newHighRes.isFailed() or newHighRes.isAborted(): raise Exception('XmippProtReconstructHighRes has failed') if newHighRes.isFinished(): finishedIter = True fnDir = newHighRes._getExtraPath("Iter%03d" % 1) fnFSCs = open(self._getExtraPath('fnFSCs.txt'), 'a') fnFSCs.write(join(fnDir, "fsc.xmd") + " \n") fnFSCs.close() targetResolution = self.checkOutputsStep(newHighRes, numGlobalIters + i, True) targetResolution = max(targetResolution, self.maximumTargetResolution.get()) #Check the output particles and remove all the disabled ones fnOutParticles = newHighRes._getPath('angles.xmd') params = '-i %s --query select "enabled==1"' % (fnOutParticles) self.runJob("xmipp_metadata_utilities", params, numberOfMpi=1) fnFinal = self._getExtraPath('inputLocalHighRes%d.xmd' % (i + 2)) copy(fnOutParticles, fnFinal) if i > 1: #including the number of particles as stoppping criteria mdFinal = emlib.MetaData(fnFinal) Nfinal = mdFinal.size() Ninit = self.inputParticles.get().getSize() if Nfinal < Ninit * 0.3: print("Image set size too small", Nfinal, Ninit) sys.stdout.flush() break outputinputSetOfParticles = self._createSetOfParticles() outputinputSetOfParticles.copyInfo(self.inputParticles.get()) readSetOfParticles(fnFinal, outputinputSetOfParticles) result = { 'outputParticlesLocal%d' % (i + 2): outputinputSetOfParticles } self._defineOutputs(**result) self._store(outputinputSetOfParticles) #self = self._updateProtocol(self) self.createOutputStep(project)
class ProjectsView(tk.Frame): def __init__(self, parent, windows, **args): tk.Frame.__init__(self, parent, bg='white', **args) self.windows = windows self.manager = windows.manager self.root = windows.root #tkFont.Font(size=12, family='verdana', weight='bold') bigSize = pwgui.cfgFontSize + 2 smallSize = pwgui.cfgFontSize - 2 fontName = pwgui.cfgFontName self.projNameFont = tkFont.Font(size=bigSize, family=fontName, weight='bold') self.projDateFont = tkFont.Font(size=smallSize, family=fontName) self.projDelFont = tkFont.Font(size=smallSize, family=fontName, weight='bold') self.manager = Manager() # Add the create project button btnFrame = tk.Frame(self, bg='white') btn = HotButton(btnFrame, text=Message.LABEL_CREATE_PROJECT, font=self.projNameFont, command=self._onCreateProject) btn.grid(row=0, column=0, sticky='nw', padx=10, pady=10) # Add the Import project button btn = Button(btnFrame, text=Message.LABEL_IMPORT_PROJECT, font=self.projNameFont, command=self._onImportProject) btn.grid(row=0, column=1, sticky='nw', padx=10, pady=10) btnFrame.grid(row=0, column=0, sticky='nw') self.columnconfigure(0, weight=1) self.rowconfigure(1, weight=1) text = TaggedText(self, width=40, height=15, bd=0, bg='white') text.grid(row=1, columnspan=2, column=0, sticky='news') self.createProjectList(text) text.setReadOnly(True) self.text = text def createProjectList(self, text): """Load the list of projects""" r = 0 text.setReadOnly(False) text.clear() parent = tk.Frame(text, bg='white') parent.columnconfigure(0, weight=1) colors = ['white', '#EAEBFF'] for i, p in enumerate(self.manager.listProjects()): try: project = self.manager.loadProject(p.getName(), chdir=False, loadAllConfig=False) # Add creation time to project info p.cTime = project.getCreationTime() # Add if it's a link p.isLink = project.isLink() # If it's a link, get the linked folder if p.isLink: p.linkedFolder = os.path.realpath(project.path) frame = self.createProjectLabel(parent, p, color=colors[i % 2]) frame.grid(row=r, column=0, padx=10, pady=5, sticky='new') r += 1 except Exception, ex: print "ERROR loading project: %s" % p.getName() print ex text.window_create(tk.INSERT, window=parent) text.bindWidget(parent) text.setReadOnly(True)
def monitorStep(self): self._runPrerequisites = [] manager = Manager() project = manager.loadProject(self.getProject().getName()) self.numIter = self.maxNumClasses.get() for iter in range(1, self.numIter): if iter == 1: self.convertInputStep() newSplitProt = project.newProtocol( XmippProtSplitVolumeHierarchical, objLabel='split volume hierarchical - iter %d' % iter, symmetryGroup=self.symmetryGroup.get(), angularSampling=self.angularSampling.get(), angularDistance=self.angularDistance.get(), maxShift=self.maxShift.get(), directionalClasses=self.directionalClasses.get(), homogeneize=self.homogeneize.get(), targetResolution=self.targetResolution.get(), class2dIterations=self.class2dIterations.get(), splitVolume=self.splitVolume.get(), Niter=self.Niter.get(), Nrec=self.Nrec.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get()) previousSplitProt = self newSubsetNameSplitVol = 'outputVolumesInit' newSplitProt.inputVolume.set(previousSplitProt) newSplitProt.inputVolume.setExtended(newSubsetNameSplitVol) newSubsetNameSplitParts = 'outputParticlesInit' newSplitProt.inputParticles.set(previousSplitProt) newSplitProt.inputParticles.setExtended( newSubsetNameSplitParts) project.scheduleProtocol(newSplitProt, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(newSplitProt.getObjId()) self.childs.append(newSplitProt) newSignificantProt = project.newProtocol( XmippProtReconstructHeterogeneous, objLabel='significant heterogeneity - iter %d' % iter, symmetryGroup=self.symmetryGroup.get(), particleRadius=self.particleRadius.get(), targetResolution=self.targetResolution.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get(), numberOfIterations=self.numberOfIterations.get(), nxtMask=self.nextMask.get(), angularMinTilt=self.angularMinTilt.get(), angularMaxTilt=self.angularMaxTilt.get(), numberOfReplicates=self.numberOfReplicates.get(), angularMaxShift=self.angularMaxShift.get(), numberVotes=self.numberVotes.get(), stochastic=self.stochastic.get(), stochasticAlpha=self.stochasticAlpha.get(), stochasticN=self.stochasticN.get()) previousSignifProt = newSplitProt newSubsetNameSignifParts = 'outputParticlesInit' newSignificantProt.inputParticles.set(previousSplitProt) newSignificantProt.inputParticles.setExtended( newSubsetNameSignifParts) newSubsetNameSignifVol = 'outputVolumes' newSignificantProt.inputVolumes.set(previousSignifProt) newSignificantProt.inputVolumes.setExtended( newSubsetNameSignifVol) project.scheduleProtocol(newSignificantProt, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(newSignificantProt.getObjId()) self.childs.append(newSignificantProt) elif iter > 1 and not self.finished: newSplitProt = project.newProtocol( XmippProtSplitVolumeHierarchical, objLabel='split volume hierarchical - iter %d' % iter, symmetryGroup=self.symmetryGroup.get(), angularSampling=self.angularSampling.get(), angularDistance=self.angularDistance.get(), maxShift=self.maxShift.get(), directionalClasses=self.directionalClasses.get(), homogeneize=self.homogeneize.get(), targetResolution=self.targetResolution.get(), class2dIterations=self.class2dIterations.get(), splitVolume=self.splitVolume.get(), Niter=self.Niter.get(), Nrec=self.Nrec.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get()) newSubsetNameSplitVol = 'outputAuxVolumes' newSplitProt.inputVolume.set(previousSplitProt) newSplitProt.inputVolume.setExtended(newSubsetNameSplitVol) newSubsetNameSplitParts = 'outputAuxParticles' newSplitProt.inputParticles.set(previousSplitProt) newSplitProt.inputParticles.setExtended( newSubsetNameSplitParts) project.scheduleProtocol(newSplitProt, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(newSplitProt.getObjId()) self.childs.append(newSplitProt) newSignificantProt = project.newProtocol( XmippProtReconstructHeterogeneous, objLabel='significant heterogeneity - iter %d' % iter, symmetryGroup=self.symmetryGroup.get(), particleRadius=self.particleRadius.get(), targetResolution=self.targetResolution.get(), useGpu=self.useGpu.get(), gpuList=self.gpuList.get(), numberOfIterations=self.numberOfIterations.get(), nxtMask=self.nextMask.get(), angularMinTilt=self.angularMinTilt.get(), angularMaxTilt=self.angularMaxTilt.get(), numberOfReplicates=self.numberOfReplicates.get(), angularMaxShift=self.angularMaxShift.get(), numberVotes=self.numberVotes.get(), stochastic=self.stochastic.get(), stochasticAlpha=self.stochasticAlpha.get(), stochasticN=self.stochasticN.get()) previousSignifProt = newSplitProt newSubsetNameSignifParts = 'outputAuxParticles' newSignificantProt.inputParticles.set(previousSplitProt) newSignificantProt.inputParticles.setExtended( newSubsetNameSignifParts) newSubsetNameSignifVol = 'outputVolumes' newSignificantProt.inputVolumes.set(previousSignifProt) newSignificantProt.inputVolumes.setExtended( newSubsetNameSignifVol) project.scheduleProtocol(newSignificantProt, self._runPrerequisites) # Next schedule will be after this one self._runPrerequisites.append(newSignificantProt.getObjId()) self.childs.append(newSignificantProt) if not self.finished: finishedIter = False while finishedIter == False: time.sleep(15) newSplitProt = self._updateProtocol(newSplitProt) newSignificantProt = self._updateProtocol( newSignificantProt) if newSplitProt.isFailed() or newSplitProt.isAborted(): raise Exception( 'XmippProtSplitVolumeHierarchical has failed') if newSignificantProt.isFailed( ) or newSignificantProt.isAborted(): raise Exception( 'XmippProtReconstructHeterogeneous has failed') if newSignificantProt.isFinished(): finishedIter = True for classItem in newSignificantProt.outputClasses: self.classListSizes.append(classItem.getSize()) self.classListIds.append(classItem.getObjId()) self.classListProtocols.append(newSignificantProt) finishedSubset = False finishedLast = False if iter != self.numIter - 1: subsetProt = self.checkOutputsStep(project, iter) while finishedSubset == False and not self.finished: time.sleep(5) subsetProt = self._updateProtocol(subsetProt) if subsetProt.isFailed() or subsetProt.isAborted(): raise Exception( 'XmippMetaProtCreateSubset has failed') if subsetProt.isFinished(): finishedSubset = True previousSplitProt = subsetProt elif iter == self.numIter - 1: outputMetaProt = self.createOutputStep(project) while finishedLast == False: time.sleep(5) outputMetaProt = self._updateProtocol(outputMetaProt) if outputMetaProt.isFailed(): raise Exception( 'XmippMetaProtCreateOutput has failed') if outputMetaProt.isFinished(): finishedLast = True if self.finished and iter == self.numIter - 1: finishedLast = False outputMetaProt = self.createOutputStep(project) while finishedLast == False: time.sleep(5) outputMetaProt = self._updateProtocol(outputMetaProt) if outputMetaProt.isFailed(): raise Exception('XmippMetaProtCreateOutput has failed') if outputMetaProt.isFinished(): finishedLast = True if self.finished and iter < self.numIter - 1: continue