def _visualizeDisplayReconstruction(self): """ Visualize selected volumes per iterations. If show in slices, create a temporal single metadata for avoid opening multiple windows. """ prefixes = self._getPrefixes() if self._visualizeVolumesMode == 'slices': fn = self.getFilename('selected_volumes') if xmippExists(fn): deleteFile(None, fn) for it in self._visualizeIterations: volMd = MetaData() for prefix in prefixes: for ref3d in self._visualizeRef3Ds: volFn = self.getFilename('%svolume' % prefix, iter=it, ref3d=ref3d) volMd.setValue(MDL_IMAGE, volFn, volMd.addObject()) block = 'volumes_iter%06d@' % it volMd.write(block + fn, MD_APPEND) self.display2D(fn) else: for it in self._visualizeIterations: for prefix in prefixes: for ref3d in self._visualizeRef3Ds: self.display3D(self.getFilename('%svolume' % prefix, iter=it, ref3d=ref3d))
def runChimeraClient(inputFile,extraParams=""): from protlib_filesystem import xmippExists if which("chimera") and xmippExists(inputFile): from protlib_filesystem import hasSpiderExt os.system('xmipp_chimera_client --input "%s" %s &' % (inputFile,extraParams)) else: print "Error Chimera not available or inputFile %s does not exits."%inputFile
def visualizeReferences(self): refs = self.getFilename('iter_refs', iter=lastIteration(self)) if xmippExists(refs): try: runShowJ(refs, extraParams="--mode metadata --render first") except Exception, e: showError("Error launching java app", str(e), self.master)
def lastIteration(self, key='iter_logs'): ''' Find the last iteration number ''' iter = 0 while True: if not xmippExists(self.getFilename(key, iter=iter+1)): break iter = iter + 1 return iter
def display2D(self,fn, extraParams=''): if xmippExists(fn): try: # We use os.system to load the relion labels through showj os.system('xmipp_showj %(fn)s %(extraParams)s --dont_wrap &' % locals()) #runShowJ(fn, extraParams=extraParams + ' --dont_wrap') except Exception, e: showError("Error launching java app", str(e), self.master)
def getFilename(): if len(fileList) == 0: showError("Input error", "File list is empty", parent=gui.master) return None fn = FileName(fileList[0]) if not xmippExists(fn): showError("Input error", "Filename <%s> doesn't exists" % str(fn),parent=gui.master) return None return fn
def display3D(self, filename): if xmippExists(filename): #Chimera if self._visualizeVolumesMode == 'chimera': runChimeraClient(filename) else: try: runShowJ(filename, extraParams=' --dont_wrap ') except Exception, e: showError("Error launching xmipp_showj: ", str(e), self.master)
def _checkIterData(self): """ check that for last visualized iteration, the data is produced. """ dataStar = self.getFilename('data', iter=self._visualizeLastIteration) if not xmippExists(dataStar): message = "No data available for <iteration %d>, file <%s> not found." % (self._visualizeLastIteration, dataStar) showError("File not Found", message, self.master) return False return True
def _getIterAngularDist(self, it): """ Return the .star file with the classes angular distribution for this iteration. If the file not exists, it will be written. """ data_angularDist = self.getFilename('angularDist_xmipp', iter=it) addRelionLabels() if not xmippExists(data_angularDist): self._writeIterAngularDist(it) return data_angularDist
def _plotSSNR(self, a, file_name): if xmippExists(file_name): mdOut = MetaData(file_name) md = MetaData() # only cross by 1 is important md.importObjects(mdOut, MDValueGT(MDL_RESOLUTION_SSNR, 0.9)) md.operate("resolutionSSNR=log(resolutionSSNR)") resolution_inv = [md.getValue(MDL_RESOLUTION_FREQ, id) for id in md] frc = [md.getValue(MDL_RESOLUTION_SSNR, id) for id in md] a.plot(resolution_inv, frc) a.xaxis.set_major_formatter(self._plotFormatter)
def _getIterSortedData(self, it): """ Sort the it??.data.star file by the maximum likelihood. """ addRelionLabels() data_sorted = self.getFilename('data_sorted_xmipp', iter=it) if not xmippExists(data_sorted): print "Sorting particles by likelihood iteration %03d" % it fn = 'images@'+ self.getFilename('data', iter=it) md = MetaData(fn) md.sort(MDL_LL, False) md.write('images_sorted@' + data_sorted) return data_sorted
def _getIterClasses(self, it): """ Return the .star file with the classes for this iteration. If the file doesn't exists, it will be created. """ addRelionLabels() data_star = self.getFilename('data', iter=it) data_classes = self.getFilename('classes_xmipp', iter=it) if not xmippExists(data_classes): createClassesFromImages(data_star, data_classes, it, self.ClassLabel, self.ClassFnTemplate) return data_classes
def _plotFSC(self, a, model_star): if xmippExists(model_star): md = MetaData(model_star) resolution_inv = [md.getValue(MDL_RESOLUTION_FREQ, id) for id in md] frc = [md.getValue(MDL_RESOLUTION_FRC, id) for id in md] self.maxFrc = max(frc) self.minInv = min(resolution_inv) self.maxInv = max(resolution_inv) a.plot(resolution_inv, frc) a.xaxis.set_major_formatter(self._plotFormatter) a.set_ylim([-0.1, 1.1]) return True return False
def _validateInputSize(self, inputParam, inputLabel, mandatory, md, errors): """ Validate, if the mask value is non-empty, that the mask file exists and have the same dimensions than the input images. """ inputValue = getattr(self, inputParam, '') errMsg = "Param <%s> file should exists" % inputLabel if not mandatory: errMsg += " if not empty" if mandatory or inputValue.strip(): if not xmippExists(inputValue): errors.append(errMsg) else: validateInputSize([inputValue], self.ImgMd, md, errors, inputLabel)
def validatorPathExists(var): if not var.satisfiesCondition(): return None err = validatorNonEmpty(var) if not err: pathList = var.getTkValue().split() err = '' for p in pathList: if not xmippExists(p): err += "\n<%s>" % p if len(err): err = "Following path: %s\ndoesn't exist\nFor input <%s>" % (err, var.comment) else: err = None return err
def _checkIterData(self): """ check that for last visualized iteration, the data is produced. """ volumes = [] for prefix in self._getPrefixes(): volumes.append(self.getFilename(prefix + 'volume', iter=self._visualizeLastIteration, ref3d=self._visualizeLastRef3D)) for v in volumes: if not xmippExists(v): message = "No data available for <iteration %d> and <class %d>" % (self._visualizeLastIteration, self._visualizeLastRef3D) message += '\nVolume <%s> not found. ' % v showError("File not Found", message, self.master) return False return True
def readParams(self): self.readInputFiles() self.memory = self.getParam('--memory') files = [] missingFiles = [] for f in self.inputFiles: if xmippExists(f): files.append('"%s"' % f) # Escape with " for filenames containing spaces else: missingFiles.append(f) self.inputFiles = files if len(missingFiles): print "Missing files: \n %s" % ' \n'.join(missingFiles) self.args = "-i %s" % ' '.join(self.inputFiles) self.readOtherParams()
def run(self): volfile = self.getParam("-i") if not xmippExists(volfile): print "ERROR: File " + volfile + "does not exist\n" sys.exit(1) mode = self.getParam("-m") angulardistfile = self.getParam("-a") if angulardistfile == "none": angulardistfile = None else: if not exists(angulardistfile): # either file does not exists or has a blockname if not (existsBlockInMetaDataFile(angulardistfile)): # check blockname print "ERROR: File " + angulardistfile + "does not exist or block is missing\n" sys.exit(1) spheres_color = self.getParam("-a", 1) spheres_distance = self.getParam("-a", 2) spheres_maxradius = self.getParam("-a", 3) isprojector = mode == "projector" if isprojector: size = self.getParam("-m", 1) padding_factor = self.getDoubleParam("-m", 2) max_freq = self.getDoubleParam("-m", 3) spline_degree_str = self.getParam("-m", 4) if spline_degree_str.lower() == "NEAREST".lower(): spline_degree = NEAREST elif spline_degree_str.lower() == "LINEAR".lower(): spline_degree = LINEAR elif spline_degree_str.lower() == "BSPLINE2".lower(): spline_degree = BSPLINE2 elif spline_degree_str.lower() == "BSPLINE3".lower(): spline_degree = BSPLINE3 elif spline_degree_str.lower() == "BSPLINE4".lower(): spline_degree = BSPLINE4 # print spline_degree voxelSize = self.getParam("-s") if voxelSize == "none": voxelSize = None port = self.getFreePort() if not port: print "ERROR: Port is not available\n" sys.exit(1) chimera = which("chimera") if chimera is None: print "ERROR: Chimera is not available\n" sys.exit(1) serverfile = getXmippPath("libraries/bindings/chimera/xmipp_chimera_server.py") # command = "export XMIPP_CHIMERA_PORT=%d; chimera %s &" % (port,serverfile) command = "chimera --script '%s %s' &" % (serverfile, port) system(command) if isprojector: XmippProjectionExplorer( volfile, port, [angulardistfile, spheres_color, spheres_distance, spheres_maxradius], size, padding_factor, max_freq, spline_degree, voxelSize, ) # print 'created projection explorer' elif mode == "viewer": client = XmippChimeraClient( volfile, port, [angulardistfile, spheres_color, spheres_distance, spheres_maxradius], voxelSize )