def _showVolumesSlices(self):
     # Write an sqlite with all volumes selected for visualization.
     sampling, setOfVolumes = self._createSetOfVolumes()
     # setOfVolumes.setSamplingRate(sampling)
     if len(setOfVolumes) == 1:
         if self.protocol.outputVolume.getHalfMaps():
             setOfVolumes = self.protocol._createSetOfVolumes(suffix='tmp')
             vol = emobj.Volume()
             vol.setFileName(self.protocol.outputVolume.getFileName())
             vol.setSamplingRate(sampling)
             setOfVolumes.append(vol)
             for halfMap in self.protocol.outputVolume.getHalfMaps().split(
                     ','):
                 volHalf = emobj.Volume()
                 volHalf.setSamplingRate(sampling)
                 if not halfMap.endswith(".mrc"):
                     volHalf.setFileName(halfMap.split(".")[0] + ".mrc")
                 else:
                     volHalf.setFileName(halfMap)
                 setOfVolumes.append(volHalf)
             setOfVolumes.write()
             return [self.objectView(setOfVolumes)]
         else:
             return [self.objectView(self.protocol.outputVolume)]
     return [self.objectView(setOfVolumes)]
Example #2
0
    def assignStep(self):
        # Create a Volume object
        self.inVol = self.inVolume.get()
        self.outVol = emobj.Volume()
        self.outVol.copy(self.inVol)

        # Set sampling Rate (or copy from input)
        if self.setSampling.get():
            samplingRate = self.samplingRate
        else:
            samplingRate = self.inVol.getSamplingRate()

        self.outVol.setSamplingRate(samplingRate)

        # set Origin
        if self.setOrigCoord.get():
            origin = emobj.Transform()
            origin.setShifts(self.x, self.y, self.z)
        else:
            origin = self.inVol.getOrigin()

        self.outVol.setOrigin(origin)

        # copy or link
        copyOrLink = self.getCopyOrLink()
        fileName = self.inVol.getFileName()
        fileName = fileName.replace(':mrc', '')
        imgBase = basename(fileName)
        imgDst = self._getExtraPath(imgBase)
        copyOrLink(os.path.abspath(fileName), imgDst)
        self.outVol.setLocation(imgDst)

        # save
        self._defineOutputs(outputVolume=self.outVol)
        self._defineSourceRelation(self.inVol, self.outVol)
    def assignStep(self):
        # Create a Volume object
        self.inVol = self.inVolume.get()
        self.outVol = emobj.Volume()
        self.outVol.copy(self.inVol)

        # Set sampling Rate (or copy from input)
        if self.setSampling.get():
            samplingRate = self.samplingRate.get()
        else:
            samplingRate = self.inVol.getSamplingRate()

        self.outVol.setSamplingRate(samplingRate)

        # set Origin
        if self.setOrigCoord.get():
            origin = emobj.Transform()
            origin.setShifts(self.x.get(), self.y.get(), self.z.get())
        else:
            origin = self.inVol.getOrigin()

        self.outVol.setOrigin(origin)

        # Files system stuff
        fileName = os.path.abspath(self.inVol.getFileName())
        fileName = fileName.replace(':mrc', '')

        # copy or link
        if self.copyFiles:
            imgBase = pwutils.replaceBaseExt(fileName, "mrc")
            imgDst = self._getExtraPath(imgBase)
            Ccp4Header.fixFile(fileName,
                               imgDst,
                               origin.getShifts(),
                               sampling=samplingRate)
        else:
            imgBase = basename(fileName)
            imgDst = self._getExtraPath(imgBase)
            pwutils.createAbsLink(fileName, imgDst)

        self.outVol.setLocation(imgDst)

        # save
        self._defineOutputs(outputVolume=self.outVol)
        self._defineSourceRelation(self.inVol, self.outVol)
Example #4
0
    def testLocation(self):
        fn = self.mic1
        mic = emobj.Micrograph()
        mic.setFileName(fn)

        # Check that setFileName-getFileName is working properly
        self.assertEqual(fn, mic.getFileName())

        # Check the location is accepted from constructor
        mic2 = emobj.Micrograph(fn)
        self.assertEqual(fn, mic2.getFileName())

        volStk = '/data/current/volumes/all_volumes.stk'
        vol1 = emobj.Volume((1, volStk))
        self.assertEqual(1, vol1.getIndex())
        self.assertEqual(volStk, vol1.getFileName())

        self.assertEqual('all_volumes.stk', vol1.getBaseName())
Example #5
0
    def createVolumesSqlite(self,
                            files,
                            path,
                            samplingRate,
                            updateItemCallback=None):
        pwutils.cleanPath(path)
        volSet = emobj.SetOfVolumes(filename=path)
        volSet.setSamplingRate(samplingRate)

        for volFn in files:
            vol = emobj.Volume()
            vol.setFileName(volFn)
            if updateItemCallback:
                updateItemCallback(vol)
            volSet.append(vol)
        volSet.write()
        volSet.close()

        return volSet
Example #6
0
    def show(self, form, *params):
        protocol = form.protocol
        filesPath = protocol.filesPath.get()
        filesPattern = protocol.filesPattern.get()
        if filesPattern:
            fullPattern = os.path.join(filesPath, filesPattern)
        else:
            fullPattern = filesPath

        sampling = protocol.samplingRate.get()
        for fileName, fileId in protocol.iterFiles():
            inputVol = emobj.Volume()
            inputVol.setFileName(fileName)
            if ((str(fullPattern)).endswith('mrc')
                    or (str(fullPattern)).endswith('map')):
                ccp4header = emconv.Ccp4Header(fileName, readHeader=True)
                x, y, z = ccp4header.getOrigin(changeSign=True)  # In Angstroms
            else:
                x, y, z = self._halfOriginCoordinates(inputVol, sampling)

            form.setVar('x', x)
            form.setVar('y', y)
            form.setVar('z', z)
Example #7
0
    def importVolumesStep(self, pattern, samplingRate, setOrigCoord=False):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        volSet = self._createSetOfVolumes()
        vol = emobj.Volume()

        if self.importFrom == self.IMPORT_FROM_FILES:
            self.info("Using pattern: '%s'" % pattern)

            # Create a Volume template object
            vol.setSamplingRate(samplingRate)

            imgh = emlib.image.ImageHandler()

            volSet.setSamplingRate(samplingRate)

            for fileName, fileId in self.iterFiles():
                x, y, z, n = imgh.getDimensions(fileName)
                if fileName.endswith('.mrc') or fileName.endswith('.map'):
                    fileName += ':mrc'
                    if z == 1 and n != 1:
                        zDim = n
                        n = 1
                    else:
                        zDim = z
                else:
                    zDim = z
                origin = emobj.Transform()
                if setOrigCoord:
                    origin.setShiftsTuple(self._getOrigCoord())
                else:
                    origin.setShifts(x / -2. * samplingRate,
                                     y / -2. * samplingRate,
                                     zDim / -2. * samplingRate)

                vol.setOrigin(origin)  # read origin from form

                if self.copyFiles or setOrigCoord:
                    newFileName = abspath(
                        self._getVolumeFileName(fileName, "mrc"))
                    emconv.Ccp4Header.fixFile(fileName, newFileName,
                                              origin.getShifts(), samplingRate,
                                              emconv.Ccp4Header.ORIGIN)
                    if self.setHalfMaps.get():
                        newFileName1 = abspath(
                            self._getVolumeFileName(self.half1map.get(),
                                                    "mrc"))
                        emconv.Ccp4Header.fixFile(self.half1map.get(),
                                                  newFileName1,
                                                  origin.getShifts(),
                                                  samplingRate,
                                                  emconv.Ccp4Header.ORIGIN)
                        newFileName2 = abspath(
                            self._getVolumeFileName(self.half2map.get(),
                                                    "mrc"))
                        emconv.Ccp4Header.fixFile(self.half2map.get(),
                                                  newFileName2,
                                                  origin.getShifts(),
                                                  samplingRate,
                                                  emconv.Ccp4Header.ORIGIN)

                        vol.setHalfMaps(
                            [relpath(newFileName1),
                             relpath(newFileName2)])
                else:
                    newFileName = abspath(self._getVolumeFileName(fileName))

                    if fileName.endswith(':mrc'):
                        fileName = fileName[:-4]

                    pwutils.createAbsLink(fileName, newFileName)
                    if self.setHalfMaps.get():
                        pwutils.createAbsLink(
                            self.half1map.get(),
                            abspath(
                                self._getVolumeFileName(self.half1map.get())))
                        pwutils.createAbsLink(
                            self.half2map.get(),
                            abspath(
                                self._getVolumeFileName(self.half2map.get())))

                        vol.setHalfMaps([
                            relpath(
                                self._getVolumeFileName(self.half1map.get())),
                            relpath(
                                self._getVolumeFileName(self.half2map.get()))
                        ])

                # Make newFileName relative
                # https://github.com/I2PC/scipion/issues/1935
                newFileName = relpath(newFileName)
                if n == 1:
                    vol.cleanObjId()
                    vol.setFileName(newFileName)
                    volSet.append(vol)
                else:
                    for index in range(1, n + 1):
                        vol.cleanObjId()
                        vol.setLocation(index, newFileName)
                        volSet.append(vol)
        else:  # import from EMDB
            self.info("Downloading map with ID = %s" % self.emdbId)
            try:
                localFileName, sampling, origin = \
                    fetch_emdb_map(self.emdbId,
                                   self._getExtraPath(),
                                   self._getTmpPath())
            except Exception as e:
                print(e)
                return
            # open volume and fill sampling and origin
            vol.setSamplingRate(sampling)
            vol.setFileName(localFileName)
            from pwem.objects.data import Transform
            originMat = Transform()
            originMat.setShifts(origin[0], origin[1], origin[2])
            vol.setOrigin(originMat)

        if volSet.getSize() > 1:
            self._defineOutputs(outputVolumes=volSet)
        else:
            self._defineOutputs(outputVolume=vol)
Example #8
0
    def assignStep(self):
        # Create a Volume object
        self.inVol = self.inVolume.get()
        self.outVol = emobj.Volume()
        self.outVol.copy(self.inVol)

        # Set sampling Rate (or copy from input)
        if self.setSampling.get():
            samplingRate = self.samplingRate
        else:
            samplingRate = self.inVol.getSamplingRate()

        self.outVol.setSamplingRate(samplingRate)

        # set Origin
        # get location of the subparticles (px)
        # this is a string with 3 coor
        inputProtocol = self.inputProtocol.get()
        if inputProtocol.defineVector == CMM:
            cmmFn = inputProtocol.vectorFile.get()
            vector = " "
        else:
            cmmFn = ""
            vector = inputProtocol.vector.get()

        length = inputProtocol.length.get()
        pxSize = inputProtocol.inputParticles.get().getSamplingRate()

        subpartVectorList = load_vectors(cmmFn, vector, length, pxSize)

        vector = subpartVectorList[0]
        # coordinates with origin as defined in localrec
        # convert from string to array
        length = vector.get_length()
        x = vector.vector[0] * length
        y = vector.vector[1] * length
        z = vector.vector[2] * length
        # 0.0        107.3775 281.1066 pixel
        # get subvolume
        vol = self.inVolume.get()
        shifts = vol.getOrigin(force=True).getShifts()
        sampling = vol.getSamplingRate()

        # 100 100 100
        x += shifts[0] / sampling
        y += shifts[1] / sampling
        z += shifts[2] / sampling

        self.origin = emobj.Transform()
        samplingRate = samplingRate.get()
        self.origin.setShifts(x * samplingRate, y * samplingRate,
                              z * samplingRate)
        self.outVol.setOrigin(self.origin)

        # copy or link
        copyOrLink = self.getCopyOrLink()
        fileName = self.inVol.getFileName()
        fileName = fileName.replace(':mrc', '')
        imgBase = basename(fileName)
        imgDst = self._getExtraPath(imgBase)
        copyOrLink(os.path.abspath(fileName), imgDst)
        self.outVol.setLocation(imgDst)

        # save
        self._defineOutputs(outputVolume=self.outVol)
        self._defineSourceRelation(self.inVol, self.outVol)