Exemple #1
0
    def importTomogramsStep(self, pattern, samplingRate):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        self.info("Using pattern: '%s'" % pattern)

        # Create a Volume template object
        tomo = Tomogram()
        tomo.setSamplingRate(samplingRate)

        imgh = ImageHandler()

        tomoSet = self._createSetOfTomograms()
        tomoSet.setSamplingRate(samplingRate)

        self._parseAcquisitionData()
        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 = Transform()

            if self.setOrigCoord.get():
                origin.setShiftsTuple(self._getOrigCoord())
            else:
                origin.setShifts(x / -2. * samplingRate,
                                 y / -2. * samplingRate,
                                 zDim / -2. * samplingRate)

            tomo.setOrigin(origin)  # read origin from form

            newFileName = _getUniqueFileName(self.getPattern(),
                                             fileName.split(':')[0])
            tsId = removeExt(newFileName)
            tomo.setTsId(tsId)

            if fileName.endswith(':mrc'):
                fileName = fileName[:-4]
            createAbsLink(fileName, abspath(self._getExtraPath(newFileName)))
            tomo.setAcquisition(self._extractAcquisitionParameters(fileName))

            if n == 1:  # One volume per file
                tomo.cleanObjId()
                tomo.setFileName(self._getExtraPath(newFileName))
                tomoSet.append(tomo)
            else:  # A stack of volumes per file (not common)
                for index in range(1, n + 1):
                    tomo.cleanObjId()
                    tomo.setLocation(index, self._getExtraPath(newFileName))
                    tomoSet.append(tomo)

        self._defineOutputs(outputTomograms=tomoSet)
    def createOutputStep(self, tsObjId):
        ts = self.inputSetOfTiltSeries.get()[tsObjId]
        tsId = ts.getTsId()
        extraPrefix = self._getExtraPath(tsId)

        outputSetOfTomograms = self.getOutputSetOfTomograms()

        newTomogram = Tomogram()
        newTomogram.setLocation(os.path.join(extraPrefix, ts.getFirstItem().parseFileName(extension=".mrc")))

        # Set tomogram origin
        ih = ImageHandler()
        xDim, yDim, zDim, _ = \
            ih.getDimensions(os.path.join(extraPrefix, ts.getFirstItem().parseFileName(extension=".mrc")))

        origin = Transform()
        sr = self.inputSetOfTiltSeries.get().getSamplingRate()
        origin.setShifts(xDim / -2. * sr,
                         yDim / -2. * sr,
                         zDim / -2 * sr)
        newTomogram.setOrigin(origin)

        # Set tomogram acquisition
        acquisition = TomoAcquisition()
        acquisition.setAngleMin(ts.getFirstItem().getTiltAngle())
        acquisition.setAngleMax(ts[ts.getSize()].getTiltAngle())
        acquisition.setStep(self.getAngleStepFromSeries(ts))
        newTomogram.setAcquisition(acquisition)

        outputSetOfTomograms.append(newTomogram)
        outputSetOfTomograms.update(newTomogram)
        outputSetOfTomograms.write()
        self._store()
    def importSubTomogramsStep(self, pattern, samplingRate):
        """ Copy images matching the filename pattern
        Register other parameters.
        """
        self.info("Using pattern: '%s'" % pattern)

        # Create a Volume template object
        subtomo = SubTomogram()
        subtomo.setSamplingRate(samplingRate)

        imgh = ImageHandler()

        self.subtomoSet = self._createSetOfSubTomograms()
        self.subtomoSet.setSamplingRate(samplingRate)

        # if self.importCoordinates.get():
        #     self.coords = []
        #     for coord3D in self.importCoordinates.get().iterCoordinates():
        #         self.coords.append(coord3D.clone())
        #     self.subtomoSet.setCoordinates3D(self.importCoordinates)

        self._parseAcquisitionData()
        for fileName, fileId in self.iterFiles():

            x, y, z, n = imgh.getDimensions(fileName)
            if fileName.endswith('.map'):
                fileName += ':mrc'
            if fileName.endswith('.mrc') or fileName.endswith(':mrc'):
                if z == 1 and n != 1:
                    zDim = n
                    n = 1
                else:
                    zDim = z
            else:
                zDim = z
            origin = Transform()

            origin.setShifts(x / -2. * samplingRate, y / -2. * samplingRate,
                             zDim / -2. * samplingRate)

            subtomo.setOrigin(origin)  # read origin from form

            newFileName = _getUniqueFileName(self.getPattern(), fileName)
            # newFileName = abspath(self._getVolumeFileName(fileName))

            if fileName.endswith(':mrc'):
                fileName = fileName[:-4]
            createAbsLink(fileName, self._getExtraPath(newFileName))

            if n == 1:
                self._addSubtomogram(subtomo, self._getExtraPath(fileName),
                                     self._getExtraPath(newFileName))
            else:
                for index in range(1, n + 1):
                    self._addSubtomogram(subtomo,
                                         self._getExtraPath(fileName),
                                         self._getExtraPath(newFileName),
                                         index=index)
Exemple #4
0
    def generateOutputStackStep(self, tomoObjId):
        tomo = self.inputSetOfTomograms.get()[tomoObjId]

        tomoId = os.path.splitext(os.path.basename(tomo.getFileName()))[0]

        extraPrefix = self._getExtraPath(tomoId)

        outputProjectedSetOfTiltSeries = self.getOutputProjectedSetOfTiltSeries(
        )

        newTs = tomoObj.TiltSeries(tsId=tomoId)
        newTs.copyInfo(tomo)
        newTs.setTsId(tomoId)

        # Add origin to output tilt-series
        origin = Transform()

        outputProjectedSetOfTiltSeries.append(newTs)

        tiltAngleList = self.getTiltAngleList()

        for index in range(self.getProjectionRange()):
            newTi = tomoObj.TiltImage()
            newTi.setTiltAngle(tiltAngleList[index])
            newTi.setTsId(tomoId)
            newTi.setLocation(
                index + 1,
                os.path.join(extraPrefix,
                             os.path.basename(tomo.getFileName())))
            newTi.setSamplingRate(
                self.inputSetOfTomograms.get().getSamplingRate())
            newTs.append(newTi)

        ih = ImageHandler()
        x, y, z, _ = ih.getDimensions(newTs.getFirstItem().getFileName())
        newTs.setDim((x, y, z))

        # Set origin to output tilt-series
        origin.setShifts(
            x / -2. * self.inputSetOfTomograms.get().getSamplingRate(),
            y / -2. * self.inputSetOfTomograms.get().getSamplingRate(), 0)
        newTs.setOrigin(origin)

        newTs.write(properties=False)

        outputProjectedSetOfTiltSeries.update(newTs)
        outputProjectedSetOfTiltSeries.updateDim()
        outputProjectedSetOfTiltSeries.write()
        self._store()
Exemple #5
0
    def _createCoordinate3D(self):
        # Tomogram associated to Coordinate3D
        self.Tomo = Tomogram()
        self.Tomo.setSamplingRate(1)
        self.Tomo.setLocation(self.TomogramPath)
        x, y, z = self.Tomo.getDim()
        origin = Transform()
        origin.setShifts(x / -2., y / -2., z / -2.)
        self.Tomo.setOrigin(origin)

        # Coordinate3D
        self.coord = Coordinate3D()
        self.coord.setBoxSize(32)
        self.coord.setVolume(self.Tomo)
        self.coord.setPosition(0, 0, 0, const.BOTTOM_LEFT_CORNER)
        self.coord.setMatrix(np.eye(4))
    def createOutputStep(self):
        vol = Volume()
        vol.setLocation(self._getOutputVol())
        sampling = self.inputVolumes.get().getSamplingRate()
        vol.setSamplingRate(sampling)
        #

        ccp4header = Ccp4Header(self._getOutputVol(), readHeader=True)
        t = Transform()

        x, y, z = ccp4header.getOrigin()  # origin output vol
        # coordinates

        t.setShifts(x, y, z)
        vol.setOrigin(t)
        #
        self._defineOutputs(outputVolume=vol)
        self._defineSourceRelation(self.inputVolumes, self.outputVolume)
Exemple #7
0
    def createOutputStep(self):
        inputVol = self.inputStructure.get()
        samplingRate = inputVol.getSamplingRate()
        volume = Volume()
        volume.setFileName(self._getExtraPath("pseudoatoms_approximation.vol"))
        volume.setSamplingRate(samplingRate)
        x, y, z = volume.getDim()
        xv, yv, zv = inputVol.getOrigin(force=True).getShifts()
        t = Transform()
        t.setShifts((x / 2. * samplingRate) - xv, (y / 2. * samplingRate) - yv,
                    (z / 2. * samplingRate) - zv)
        volume.setOrigin(inputVol.getOrigin())

        self._defineOutputs(outputVolume=volume)
        self._defineSourceRelation(self.inputStructure.get(), volume)

        pdb = AtomStruct(self._getPath('pseudoatoms.pdb'), pseudoatoms=True)
        pdb.setVolume(volume)
        pdb.setOrigin(t)
        self.createChimeraScript(inputVol, pdb)
        self._defineOutputs(outputPdb=pdb)
        self._defineSourceRelation(self.inputStructure, pdb)
Exemple #8
0
    def extractunitCell(self, sym, offset=0, cropZ=False):
        # FlexProtConvertToPseudoAtoms = Domain.importFromPlugin("continuousflex.protocols",
        #                                                        "FlexProtConvertToPseudoAtoms",
        #                                                         doRaise=True)
        # NMA_MASK_THRE = Domain.importFromPlugin("continuousflex.protocols.pdb.protocol_pseudoatoms_base",
        #                                         "NMA_MASK_THRE",
        #                                         doRaise=True)
        """ extract unit cell from icosahedral phantom
            using xmipp_i2 symmetry
        """
        # create phantom (3D map)
        _samplingRate = 1.34
        _, outputFile1 = mkstemp(suffix=".mrc")
        command = "xmipp_phantom_create "
        args = " -i %s" % self.filename[sym]
        args += " -o %s" % outputFile1
        runJob(None, command, args, env=Plugin.getEnviron())
        ccp4header = Ccp4Header(outputFile1, readHeader=True)
        x, y, z = ccp4header.getDims()
        t = Transform()

        if cropZ:
            _, outputFile2 = mkstemp(suffix=".mrc")
            args = "-i %s -o %s" % (outputFile1, outputFile2)
            args += " --corners "
            args += " %d " % (-x / 2.)
            args += " %d " % (-y / 2.)
            args += " %d " % (0.)
            args += " %d " % (+x / 2.)
            args += " %d " % (+y / 2.)
            args += " %d " % (+z / 2.)
            runJob(None,
                   "xmipp_transform_window",
                   args,
                   env=Plugin.getEnviron())
            t.setShifts(0, 0, 0)
            outputFile = outputFile2
            ccp4header = Ccp4Header(outputFile2, readHeader=True)

        else:
            t.setShifts(0, 0, 0)
            outputFile = outputFile1

        ccp4header.setSampling(_samplingRate)
        ccp4header.setOrigin(t.getShifts())
        ccp4header.writeHeader()

        # import volume
        if cropZ:
            args = {
                'filesPath': outputFile,
                'filesPattern': '',
                'samplingRate': _samplingRate,
                'copyFiles': True,
                'setOrigCoord': True,
                'x': 90. * _samplingRate,
                'y': 90. * _samplingRate,
                'z': 0.
                # x, y, z in Angstroms
            }
        else:
            args = {
                'filesPath': outputFile,
                'filesPattern': '',
                'samplingRate': _samplingRate,
                'copyFiles': True,
                'setDefaultOrigin': False,
            }
        prot = self.newProtocol(ProtImportVolumes, **args)
        prot.setObjLabel('import volume(%s)' % XMIPP_SYM_NAME[sym])
        self.launchProtocol(prot)
        # execute protocol extract unitCell

        args = {
            'inputVolumes': prot.outputVolume,
            'symmetryGroup': sym,
            'symmetryOrder': self.symOrder,
            'innerRadius': self.innerRadius,
            'outerRadius': self.outerRadius,
            'expandFactor': .2,
            'offset': offset
        }

        prot = self.newProtocol(XmippProtExtractUnit, **args)
        prot.setObjLabel('extract unit cell')
        self.launchProtocol(prot)

        # check results
        ih = ImageHandler()
        xdim, ydim, zdim, ndim = \
            ih.getDimensions(prot.outputVolume.getFileName())
        self.assertTrue(abs(xdim - self.box[sym][0]) < 2)
        self.assertTrue(abs(ydim - self.box[sym][1]) < 2)
        self.assertTrue(abs(zdim - self.box[sym][2]) < 2)

        # create pdb fileoutput
        # args = {'inputStructure': prot.outputVolume,
        #         'maskMode': NMA_MASK_THRE,
        #         'maskThreshold': 0.5,
        #         'pseudoAtomRadius': 1.5
        #         }
        # prot = self.newProtocol(FlexProtConvertToPseudoAtoms, **args)
        # prot.setObjLabel('get pdb')
        # self.launchProtocol(prot)

        # check results
        # filenamePdb = prot._getPath('pseudoatoms.pdb')
        # self.assertTrue(os.path.isfile(filenamePdb))
        # delete temporary files
        os.remove(self.filename[sym])
        os.remove(outputFile)