Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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 = pwutils.dirname(coordFile)
            # Still go one level up of info dir
            jsonBase = pwutils.join(pwutils.dirname(infoDir), 'e2boxercache',
                                    'base.json')
            jsonBase2 = pwutils.join(infoDir, 'project.json')
            if pwutils.exists(jsonBase):
                jsonDict = loadJson(jsonBase)
                if jsonDict.has_key('box_size'):
                    return int(jsonDict["box_size"])
            elif pwutils.exists(jsonBase2):
                jsonDict = loadJson(jsonBase2)
                if jsonDict.has_key('global.boxsize'):
                    return int(jsonDict["global.boxsize"])

        return None
Ejemplo n.º 3
0
 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