def _convertInputStep(self):
        self.info("Relion version:")
        self.runJob("relion_run_motioncorr --version", "", numberOfMpi=1)
        self.info("Detected version from config: %s" %
                  relion.Plugin.getActiveVersion())

        ProtAlignMovies._convertInputStep(self)
Ejemplo n.º 2
0
 def _convertInputStep(self):
     self.info("Relion version:")
     self.runJob("relion_convert_to_tiff --version", "", numberOfMpi=1)
     self.info("Detected version from config: %s" %
               relion.Plugin.getActiveVersion())
     # Create a local link to the input gain file if necessary
     inputGain = self.getInputGain()
     if inputGain:
         tmpGain = self._getTmpPath('gain_estimate.bin')
         pwutils.createLink(inputGain, tmpGain)
         pwutils.createLink(inputGain.replace('.bin', '_reliablity.bin'),
                            tmpGain.replace('.bin', '_reliablity.bin'))
     ProtAlignMovies._convertInputStep(self)
    def _updateOutputSet(self,
                         outputName,
                         outputSet,
                         state=pwobj.Set.STREAM_OPEN):
        """ Redefine this method to update optics info. """

        if outputName not in self.updatedSets:
            og = OpticsGroups.fromImages(outputSet)
            og.updateAll(rlnMicrographOriginalPixelSize=self.inputMovies.get().
                         getSamplingRate())
            og.toImages(outputSet)
            self.updatedSets.append(outputName)

        ProtAlignMovies._updateOutputSet(self,
                                         outputName,
                                         outputSet,
                                         state=state)
Ejemplo n.º 4
0
    def _validate(self):
        # Check base validation before the specific ones for Motioncor
        errors = ProtAlignMovies._validate(self)

        if not relion.Plugin.getActiveVersion():
            errors.append("Could not detect the current Relion version. \n"
                          "RELION_HOME='%s'" % relion.Plugin.getHome())

        return errors
Ejemplo n.º 5
0
    def _updateOutputSet(self,
                         outputName,
                         outputSet,
                         state=pwobj.Set.STREAM_OPEN):
        """ Redefine this method to set EER attrs. """
        first = getattr(self, '_firstUpdate', True)

        if first and outputName == 'outputMovies':
            og = OpticsGroups.fromImages(outputSet)
            if self.isEER:
                og.updateAll(rlnEERGrouping=self.eerGroup.get(),
                             rlnEERUpsampling=self.eerSampling.get() + 1)
            og.updateAll(rlnMicrographStartFrame=self.alignFrame0.get())
            og.toImages(outputSet)

        ProtAlignMovies._updateOutputSet(self,
                                         outputName,
                                         outputSet,
                                         state=state)
        self._firstUpdate = False
Ejemplo n.º 6
0
    def _convertInputStep(self):
        inputMovies = self.getInputMovies()
        # parse EER gain file before its conversion to mrc
        if self.isEER and inputMovies.getGain():
            defects = parseEERDefects(inputMovies.getGain())
            if defects:
                with open(self._getExtraPath("defects_eer.txt"), "w") as f:
                    for d in defects:
                        f.write(" ".join(str(i) for i in d) + "\n")

        ProtAlignMovies._convertInputStep(self)
        if self.isEER:
            # write FmIntFile
            _, numbOfFrames, _ = inputMovies.getFramesRange()
            if self.doApplyDoseFilter:
                _, dose = self._getCorrectedDose(inputMovies)
            else:
                dose = 0.0
            with open(self._getExtraPath("FmIntFile.txt"), "w") as f:
                f.write("%d %d %f" % (numbOfFrames, self.eerGroup.get(), dose))
    def _validate(self):
        # Check base validation before the specific ones for Motioncor
        errors = ProtAlignMovies._validate(self)

        if not relion.Plugin.getActiveVersion():
            errors.append("Could not detect the current Relion version. \n"
                          "RELION_HOME='%s'" % relion.Plugin.getHome())

        acq = self.inputMovies.get().getAcquisition()
        if self.doDW:
            dose = acq.getDosePerFrame()
            if dose is None or dose < 0.001:
                errors.append(
                    "Input movies do not contain the dose per frame, "
                    "dose-weighting can not be performed. ")

        return errors
 def _createOutputMovie(self, movie):
     """ Overwrite this function to store the Relion's specific
     Motion model coefficients.
     """
     m = ProtAlignMovies._createOutputMovie(self, movie)
     # Load local motion values only if the patches are more than one
     if self.patchX.get() > 2 and self.patchY.get() > 2:
         try:
             table = md.Table(fileName=self._getMovieExtraFn(
                 movie, '.star'),
                              tableName='local_motion_model')
             coeffs = [row.rlnMotionModelCoeff for row in table]
         except:
             print("Failed to parse local motion from: %s" %
                   os.path.abspath(self._getMovieExtraFn(movie, '.star')))
             coeffs = []  # Failed to parse the local motion
         m._rlnMotionModelCoeff = pwobj.String(json.dumps(coeffs))
     return m
    def _validate(self):
        if self.autoControlPoints.get():
            self._setControlPoints()  # make sure we work with proper values
        # check execution issues
        errors = ProtAlignMovies._validate(self)
        errors.extend(self._validateBinary())
        errors.extend(self._validateParallelProcessing())
        if errors:
            return errors

        # check settings issues
        if self.doLocalAlignment.get() and not self.useGpu.get():
            errors.append("GPU is needed to do local alignment.")
        if (self.controlPointX < 3):
            errors.append("You have to use at least 3 control points in X dim")
        if (self.controlPointY < 3):
            errors.append("You have to use at least 3 control points in Y dim")
        if (self.controlPointT < 3):
            errors.append("You have to use at least 3 control points in T dim")

        return errors
Ejemplo n.º 10
0
    def _validate(self):
        # Check base validation before the specific ones
        errors = ProtAlignMovies._validate(self)

        if self.doApplyDoseFilter and self.inputMovies.get():
            inputMovies = self.inputMovies.get()
            doseFrame = inputMovies.getAcquisition().getDosePerFrame()

            if doseFrame == 0.0 or doseFrame is None:
                errors.append('Dose per frame for input movies is 0 or not '
                              'set. You cannot apply dose filter.')

        if self.doComputeMicThumbnail or self.doComputePSD:
            try:
                from pwem import Domain
                eman2 = Domain.importFromPlugin('eman2', doRaise=True)
            except:
                errors.append(
                    "EMAN2 plugin not found!\nComputing thumbnails "
                    "or PSD requires EMAN2 plugin and binaries installed.")

        return errors
Ejemplo n.º 11
0
 def __init__(self, **args):
     ProtAlignMovies.__init__(self, **args)
     self.stepsExecutionMode = STEPS_PARALLEL
 def _getFrameRange(self, n, prefix):
     # Reimplement this method to ignore prefix (called from base class)
     # and always use 'sum' as prefix
     return ProtAlignMovies._getFrameRange(self, n, 'sum')
    def __init__(self, **kwargs):

        ProtAlignMovies.__init__(self, **kwargs)
        self.stepsExecutionMode = STEPS_SERIAL
        self.updatedSets = []
    def _defineAlignmentParams(self, form):
        ProtAlignMovies._defineAlignmentParams(self, form)

        form.addParam('splineOrder',
                      params.EnumParam,
                      condition="doSaveAveMic or doSaveMovie",
                      default=self.INTERP_CUBIC,
                      choices=['linear', 'cubic'],
                      expertLevel=cons.LEVEL_ADVANCED,
                      label='Interpolation',
                      help="linear (faster but lower quality), "
                      "cubic (slower but more accurate).")

        form.addHidden(
            params.USE_GPU,
            params.BooleanParam,
            default=True,
            label="Use GPU for execution",
            help="This protocol has both CPU and GPU implementation.\
                       Select the one you want to use.")

        form.addHidden(params.GPU_LIST,
                       params.StringParam,
                       default='0',
                       expertLevel=cons.LEVEL_ADVANCED,
                       label="Choose GPU IDs",
                       help="Add a list of GPU devices that can be used")

        form.addParam(
            'maxResForCorrelation',
            params.FloatParam,
            default=30,
            label='Maximal resolution (A)',
            help=
            "Maximal resolution in A that will be preserved during correlation."
        )

        form.addParam('doComputePSD',
                      params.BooleanParam,
                      default=True,
                      label="Compute PSD (before/after)?",
                      help="If Yes, the protocol will compute for each movie "
                      "the PSD of the average micrograph (without CC "
                      "alignement) and after that, to compare each PSDs")

        form.addParam('maxShift',
                      params.IntParam,
                      default=30,
                      expertLevel=cons.LEVEL_ADVANCED,
                      label="Maximum shift (pixels)",
                      help='Maximum allowed distance (in pixels) that each '
                      'frame can be shifted with respect to the next.')

        form.addParam('outsideMode',
                      params.EnumParam,
                      choices=['Wrapping', 'Average', 'Value'],
                      default=self.OUTSIDE_WRAP,
                      expertLevel=cons.LEVEL_ADVANCED,
                      label="How to fill borders",
                      help='How to fill the borders when shifting the frames')

        # this must stay together with the outside mode
        form.addParam('outsideValue',
                      params.FloatParam,
                      default=0.0,
                      expertLevel=cons.LEVEL_ADVANCED,
                      condition="outsideMode==2",
                      label='Fill value',
                      help="Fixed value for filling borders")

        #Local alignment params
        group = form.addGroup('Local alignment')

        group.addParam(
            'doLocalAlignment',
            params.BooleanParam,
            default=True,
            label="Compute local alignment?",
            help=
            "If Yes, the protocol will try to determine local shifts, similarly to MotionCor2."
        )

        group.addParam(
            'autoControlPoints',
            params.BooleanParam,
            default=True,
            label="Auto control points",
            expertLevel=cons.LEVEL_ADVANCED,
            condition='doLocalAlignment',
            help=
            "If on, protocol will automatically determine necessary number of control points."
        )
        line = group.addLine('Number of control points',
                             expertLevel=cons.LEVEL_ADVANCED,
                             help='Number of control points use for BSpline.',
                             condition='not autoControlPoints')
        line.addParam('controlPointX', params.IntParam, default=6, label='X')
        line.addParam('controlPointY', params.IntParam, default=6, label='Y')
        line.addParam('controlPointT', params.IntParam, default=5, label='t')

        group.addParam('minLocalRes',
                       params.FloatParam,
                       default=500,
                       expertLevel=cons.LEVEL_ADVANCED,
                       label='Min size of the patch (A)',
                       help="How many A should contain each patch?")

        group.addParam(
            'skipAutotuning',
            params.BooleanParam,
            default=False,
            expertLevel=cons.LEVEL_ADVANCED,
            label='Skip autotuning',
            help=
            "We try to faster settings of for the FFT library. This takes some time, "
            "but consecutive executions will be faster and use less memory."
            "Set to True (autotuning will be turned off) if you process just few movies"
        )

        group.addParam(
            'groupNFrames',
            params.IntParam,
            default=3,
            expertLevel=cons.LEVEL_ADVANCED,
            label='Group N frames',
            help=
            'Group every specified number of frames by adding them together. \
                        The alignment is then performed on the summed frames.',
            condition='doLocalAlignment')

        form.addSection(label="Gain orientation")
        form.addParam('gainRot',
                      params.EnumParam,
                      choices=[
                          'no rotation', '90 degrees', '180 degrees',
                          '270 degrees'
                      ],
                      label="Rotate gain reference:",
                      default=self.NO_ROTATION,
                      display=params.EnumParam.DISPLAY_COMBO,
                      help="Rotate gain reference counter-clockwise.")

        form.addParam(
            'gainFlip',
            params.EnumParam,
            choices=['no flip', 'upside down', 'left right'],
            label="Flip gain reference:",
            default=self.NO_FLIP,
            display=params.EnumParam.DISPLAY_COMBO,
            help="Flip gain reference after rotation. "
            "For tiff movies, gain is automatically upside-down flipped")

        form.addParallelSection(threads=1, mpi=1)
 def _createOutputMovie(self, movie):
     alignedMovie = ProtAlignMovies._createOutputMovie(self, movie)
     self._setAlignmentInfo(movie, alignedMovie)
     return alignedMovie
Ejemplo n.º 16
0
 def __init__(self, **kwargs):
     ProtAlignMovies.__init__(self, **kwargs)
     self.stepsExecutionMode = STEPS_PARALLEL
     self.isEER = False