def check_gauss(self): # Function to check if gaussian algorithm was used to pick and is so # ask user if she wants to perform an automatic picking for the remaining micrographs gaussJsonFile = join("e2boxercache", "gauss_box_DB.json") # Check if gauss json file exists and load it if os.path.exists(gaussJsonFile): jsonGaussDict = loadJson(gaussJsonFile) gaussParsDict = None micList = [os.path.relpath(mic.getFileName(), self.workingDir.get()) for mic in self.inputMics] # Go over the list of input micrographs and see if gaussian was used to pick any of them for mic in micList: if mic in jsonGaussDict: gaussParsDict = jsonGaussDict[mic] break if gaussParsDict is not None: # If found ask user if she wats to perform an automatic gaussian picking for the rest of mics # if askYesNo(Message.TITLE_PICK_GAUSS, Message.LABEL_PICK_GAUSS, None): self._params['boxSize'] = gaussParsDict['boxsize'] # Run sxprocess.py to store parameters program = eman2.getEmanProgram("sxprocess.py") argsList = ["'%s'=%s:" %(key, val) for (key, val) in gaussParsDict.iteritems()] args = 'demoparms --makedb ' + "".join(argsList) # Remove last ":" to avoid error args = args[:-1] # Run the command with formatted parameters self._log.info('Launching: ' + program + ' ' + args) self.runJob(program, args) # Now run e2boxer.py with stored parameters #arguments = "--gauss_autoboxer=demoparms --write_ptcl --boxsize=%(boxSize)s --norm=normalize.ramp.normvar" + arguments arguments = "--gauss_autoboxer=demoparms --write_dbbox --boxsize=%(boxSize)s " + "%(inputMics)s" program = eman2.getEmanProgram("e2boxer.py") self._log.info('Launching: ' + program + ' ' + arguments % self._params) self.runJob(program, arguments % self._params)
def importCoordinates(self, fileName, addCoordinate): if exists(fileName): ext = getExt(fileName) if ext == ".json": jsonPosDict = loadJson(fileName) if jsonPosDict.has_key("boxes"): boxes = jsonPosDict["boxes"] for box in boxes: x, y = box[:2] coord = Coordinate() coord.setPosition(x, y) addCoordinate(coord) elif ext == ".box": md = MetaData() md.readPlain(fileName, "xcoor ycoor particleSize") size = md.getValue(MDL_PICKING_PARTICLE_SIZE, md.firstObject()) if size is None: print ">>> WARNING: Error parsing coordinate file: %s" % fileName print " Skipping this file." else: half = size / 2 for objId in md: x = md.getValue(MDL_XCOOR, objId) y = md.getValue(MDL_YCOOR, objId) coord = Coordinate() coord.setPosition(x+half, y+half) addCoordinate(coord) else: raise Exception('Unknown extension "%s" to import Eman coordinates' % ext)
def getBoxSize(self, coordFile): """ Try to infer the box size from the given coordinate file. In the case of .box files, the size is the 3rd column In the case of .json files, we will look for file e2boxercache/base.json """ if coordFile.endswith('.box'): md = MetaData() md.readPlain(coordFile, "xcoor ycoor particleSize") return md.getValue(MDL_PICKING_PARTICLE_SIZE, md.firstObject()) elif coordFile.endswith('.json'): infoDir = dirname(coordFile) # Still go one level up of info dir jsonBase = join(dirname(infoDir), 'e2boxercache', 'base.json') if exists(jsonBase): jsonDict = loadJson(jsonBase) if jsonDict.has_key('box_size'): return int(jsonDict["box_size"]) return None