def doSuccessIndicators(self, _edPlugin=None):
     self.DEBUG("EDPluginControlGridScreeningv1_0.doSuccessIndicators")
     #self.retrieveSuccessMessages(_edPlugin, "EDPluginControlGridScreeningv1_0.doSuccessIndexingIndicators")
     if self.edPluginControlIndicators.hasDataOutput():
         self.xsDataImageQualityIndicators = self.edPluginControlIndicators.getDataOutput(
         ).getImageQualityIndicators()[0]
         # Store results in ISPyB if requested
         if self.bStoreImageQualityIndicatorsInISPyB:
             xsDataInputStoreImageQualityIndicators = XSDataInputStoreImageQualityIndicators(
             )
             xsDataISPyBImageQualityIndicators = XSDataISPyBImageQualityIndicators.parseString(
                 self.xsDataImageQualityIndicators.marshal())
             xsDataInputStoreImageQualityIndicators.setImageQualityIndicators(
                 xsDataISPyBImageQualityIndicators)
             self.edPluginISPyBStoreImageQualityIndicators.setDataInput(
                 xsDataInputStoreImageQualityIndicators)
             self.edPluginISPyBStoreImageQualityIndicators.connectSUCCESS(
                 self.doSuccessISPyBStoreImageQualityIndicators)
             self.edPluginISPyBStoreImageQualityIndicators.connectFAILURE(
                 self.doFailureISPyBStoreImageQualityIndicators)
             self.edPluginISPyBStoreImageQualityIndicators.execute()
         # Continue only if requested
         if not self.bDoOnlyImageQualityIndicators:
             xsDataIndexingInput = XSDataIndexingInput()
             xsDataIndexingInput.setDataCollection(self.xsDataCollection)
             from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
             xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(
                 xsDataIndexingInput)
             self.edPluginMOSFLMIndexing.connectSUCCESS(
                 self.doSuccessIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.connectFAILURE(
                 self.doFailureIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.setDataInput(
                 xsDataMOSFLMIndexingInput)
             self.edPluginMOSFLMIndexing.executeSynchronous()
Exemple #2
0
 def doSuccessReadImageHeader(self, _edPlugin=None):
     self.DEBUG("EDPluginControlGridScreeningv1_0.doSuccessReadImageHeader")
     self.retrieveSuccessMessages(_edPlugin, "EDPluginControlGridScreeningv1_0.doSuccessReadImageHeader")
     xsDataResultReadImageHeader = self.edPluginControlReadImageHeader.getDataOutput()
     if xsDataResultReadImageHeader is not None:
         xsDataSubWedge = xsDataResultReadImageHeader.getSubWedge()
         self.xsDataCollection = XSDataCollection()
         self.xsDataCollection.addSubWedge(xsDataSubWedge)
         self.xsDataCollection.setDiffractionPlan(self.xsDataDiffractionPlan)
         if not self.bDoOnlyIntegrationWithXMLOutput:
             xsDataInputControlImageQualityIndicators = XSDataInputControlImageQualityIndicators()
             if self.bStoreImageQualityIndicatorsInISPyB:
                 xsDataInputControlImageQualityIndicators.doUploadToIspyb = XSDataBoolean(True)
             else:
                 xsDataInputControlImageQualityIndicators.doUploadToIspyb = XSDataBoolean(False)
             xsDataInputControlImageQualityIndicators.addImage(XSDataImage(path=XSDataString(self.strImageFile)))
             self.edPluginControlIndicators.setDataInput(xsDataInputControlImageQualityIndicators)
             self.edPluginControlIndicators.connectSUCCESS(self.doSuccessIndicators)
             self.edPluginControlIndicators.connectFAILURE(self.doFailureIndicators)
             self.executePluginSynchronous(self.edPluginControlIndicators)
         else:
             xsDataIndexingInput = XSDataIndexingInput()
             xsDataIndexingInput.setDataCollection(self.xsDataCollection)
             from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
             xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
             self.edPluginMOSFLMIndexing.connectSUCCESS(self.doSuccessIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.connectFAILURE(self.doFailureIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
             self.edPluginMOSFLMIndexing.executeSynchronous()
 def doSuccessReadImageHeader(self, _edPlugin=None):
     self.DEBUG("EDPluginControlGridScreeningv1_0.doSuccessReadImageHeader")
     self.retrieveSuccessMessages(_edPlugin, "EDPluginControlGridScreeningv1_0.doSuccessReadImageHeader")
     xsDataResultReadImageHeader = self.edPluginControlReadImageHeader.getDataOutput()
     if xsDataResultReadImageHeader is not None:
         xsDataSubWedge = xsDataResultReadImageHeader.getSubWedge()
         self.xsDataCollection = XSDataCollection()
         self.xsDataCollection.addSubWedge(xsDataSubWedge)
         self.xsDataCollection.setDiffractionPlan(self.xsDataDiffractionPlan)
         if not self.bDoOnlyIntegrationWithXMLOutput:
             xsDataInputControlImageQualityIndicators = XSDataInputControlImageQualityIndicators()
             if self.bStoreImageQualityIndicatorsInISPyB:
                 xsDataInputControlImageQualityIndicators.doUploadToIspyb = XSDataBoolean(True)
             else:
                 xsDataInputControlImageQualityIndicators.doUploadToIspyb = XSDataBoolean(False)
             xsDataInputControlImageQualityIndicators.addImage(XSDataImage(path=XSDataString(self.strImageFile)))
             self.edPluginControlIndicators.setDataInput(xsDataInputControlImageQualityIndicators)
             self.edPluginControlIndicators.connectSUCCESS(self.doSuccessIndicators)
             self.edPluginControlIndicators.connectFAILURE(self.doFailureIndicators)
             self.executePluginSynchronous(self.edPluginControlIndicators)
         else:
             xsDataIndexingInput = XSDataIndexingInput()
             xsDataIndexingInput.setDataCollection(self.xsDataCollection)
             from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
             xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
             self.edPluginMOSFLMIndexing.connectSUCCESS(self.doSuccessIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.connectFAILURE(self.doFailureIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
             self.edPluginMOSFLMIndexing.executeSynchronous()
 def doFailureIndexingIndicators(self, _edPlugin=None):
     self.DEBUG(
         "EDPluginControlCharacterisationv1_5.doFailureIndexingIndicators")
     # If more than two reference images try to index with MOSFLM:
     if self._edPluginControlIndexingIndicators.hasDataOutput(
             "indicatorsShortSummary"):
         indicatorsShortSummary = self._edPluginControlIndexingIndicators.getDataOutput(
             "indicatorsShortSummary")[0].getValue()
         self._strCharacterisationShortSummary += indicatorsShortSummary
         self.sendMessageToMXCuBE(indicatorsShortSummary)
     if self._iNoImagesWithDozorScore > 0:
         strWarningMessage = "Execution of Indexing and Indicators plugin failed - trying to index with MOSFLM."
         self.WARNING(strWarningMessage)
         self.sendMessageToMXCuBE(strWarningMessage, "warning")
         self.addWarningMessage(strWarningMessage)
         xsDataIndexingInput = XSDataIndexingInput()
         xsDataIndexingInput.dataCollection = self._xsDataCollection
         xsDataIndexingInput.experimentalCondition = self._xsDataCollection.subWedge[
             0].experimentalCondition
         xsDataIndexingInput.crystal = self._xsDataCrystal
         self._edPluginControlIndexingMOSFLM.dataInput = xsDataIndexingInput
         self.executePluginSynchronous(self._edPluginControlIndexingMOSFLM)
     else:
         strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
         self.ERROR(strErrorMessage)
         self.sendMessageToMXCuBE(strErrorMessage, "error")
         self.addErrorMessage(strErrorMessage)
         self.generateExecutiveSummary(self)
         if self._xsDataResultCharacterisation is not None:
             self.setDataOutput(self._xsDataResultCharacterisation)
         self.setFailure()
         if self._strStatusMessage != None:
             self.setDataOutput(XSDataString(self._strStatusMessage),
                                "statusMessage")
             self.writeDataOutput()
 def doFailureIndexingIndicators(self, _edPlugin=None):
     self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureIndexingIndicators")
     # If more than two reference images try to index with MOSFLM:
     if self._edPluginControlIndexingIndicators.hasDataOutput("indicatorsShortSummary"):
         indicatorsShortSummary = self._edPluginControlIndexingIndicators.getDataOutput("indicatorsShortSummary")[0].getValue()
         self._strCharacterisationShortSummary += indicatorsShortSummary
         self.sendMessageToMXCuBE(indicatorsShortSummary)
     if self._iNoImagesWithDozorScore > 0:
         strWarningMessage = "Execution of Indexing and Indicators plugin failed - trying to index with MOSFLM."
         self.WARNING(strWarningMessage)
         self.sendMessageToMXCuBE(strWarningMessage, "warning")
         self.addWarningMessage(strWarningMessage)
         xsDataIndexingInput = XSDataIndexingInput()
         xsDataIndexingInput.dataCollection = self._xsDataCollection
         xsDataIndexingInput.experimentalCondition = self._xsDataCollection.subWedge[0].experimentalCondition
         xsDataIndexingInput.crystal = self._xsDataCrystal
         self._edPluginControlIndexingMOSFLM.dataInput = xsDataIndexingInput
         self.executePluginSynchronous(self._edPluginControlIndexingMOSFLM)
     else:
         strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
         self.ERROR(strErrorMessage)
         self.sendMessageToMXCuBE(strErrorMessage, "error")
         self.addErrorMessage(strErrorMessage)
         self.generateExecutiveSummary(self)
         if self._xsDataResultCharacterisation is not None:
             self.setDataOutput(self._xsDataResultCharacterisation)
         self.setFailure()
         if self._strStatusMessage != None:
             self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
             self.writeDataOutput()
Exemple #6
0
    def doXdsIndexingIntegration(self, _xsDataCollection):
        # Load the plugin
        self._edPluginIndexing = self.loadPlugin(self._strIndexingPluginName,
                                                 "Indexing")
        # XDS Indexing
        xsDataIndexingInput = XSDataIndexingInput()
        xsDataIndexingInput.setDataCollection(_xsDataCollection)
        self._edPluginIndexing.dataInput = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIndexing(
            xsDataIndexingInput)
        self._edPluginIndexing.executeSynchronous()
        xsDataResultXDSIndexing = self._edPluginIndexing.dataOutput
        if xsDataResultXDSIndexing.spaceGroupNumber is not None:
            spaceGroupNumber = xsDataResultXDSIndexing.spaceGroupNumber.value
            unitCell = xsDataResultXDSIndexing.unitCell
            filePaths = xsDataResultXDSIndexing.filePaths
            index = 1
            for subWedge in _xsDataCollection.subWedge:
                xsDataCollection = XSDataCollection()
                xsDataCollection.addSubWedge(subWedge)
                xsDataIndexingInput = XSDataIndexingInput()
                xsDataIndexingInput.setDataCollection(xsDataCollection)

                xsDataInputXDSIntegration = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIntegration(
                    xsDataIndexingInput, spaceGroupNumber, unitCell, filePaths)
                edPluginIntegration = self.loadPlugin(
                    self._strIntegrationPluginName,
                    "Integration_{0}".format(index))
                edPluginIntegration.dataInput = xsDataInputXDSIntegration
                edPluginIntegration.executeSynchronous()
                # self._edPluginIntegration.dataInput = xsDataInputXDSIntegration
                index += 1
 def doSuccessEvaluationIndexingMOSFLM(self, _edPlugin=None):
     self.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexingMOSFLM")
     self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexing")
     # Retrieve status messages (if any)
     if self.__edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageImageQualityIndicators"):
         self.addStatusMessage(self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageImageQualityIndicators")[0].getValue())
     if self.__edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageIndexing"):
         self.addStatusMessage("MOSFLM: " + self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageIndexing")[0].getValue())
     # Check if indexing was successful
     bIndexWithLabelit = False
     bIndexingSuccess = self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingSuccess")[0].getValue()
     if bIndexingSuccess:
         xsDataIndexingResult = self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingResult")[0]
         self.__xsDataIndexingResultMOSFLM = xsDataIndexingResult
         # Check if space group is P1 - if yes run Labelit indexing
         xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution()
         xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
         xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
         strSpaceGroupName = xsDataSpaceGroup.getName().getValue().upper()
         # Check if MOSFLM has indexed in P1
         if strSpaceGroupName == "P1":
             # Check if the user maybe asked for P1!
             bIndexWithLabelit = True
             if self.__xsDataCollection.getDiffractionPlan() is not None:
                 if self.__xsDataCollection.getDiffractionPlan().getForcedSpaceGroup() is not None:
                     if self.__xsDataCollection.getDiffractionPlan().getForcedSpaceGroup().getValue().upper() == "P1":
                         self.screen("P1 space forced by diffraction plan")
                         bIndexWithLabelit = False
         if bIndexWithLabelit:
             self.screen("P1 space group choosed - reindexing with Labelit")
         else:
             self.screen("MOSFLM indexing successful!")
             if self.__edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
                 self.__strCharacterisationShortSummary += self.__edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
             # Generate prediction images
             xsDataCollection = self.__xsDataResultCharacterisation.getDataCollection()
             self.__xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
             xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
             xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
             xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(xsDataIndexingResult.getSelectedSolution().marshal()))
             self.__edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
             # Start the generation of prediction images - we synchronize in the post-process
             self.__edPluginControlGeneratePrediction.execute()
             # Then start the integration of the reference images
             self.indexingToIntegration()
     else:
         self.screen("Indexing with MOSFLM failed!")
         bIndexWithLabelit = True
     if bIndexWithLabelit:
         # Execute Labelit indexing
         self.screen("Now trying to index with Labelit - please be patient...")
         xsDataIndexingInput = XSDataIndexingInput()
         xsDataSubWedgeList = self.__xsDataCollection.getSubWedge()
         xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()
         xsDataIndexingInput.setDataCollection(self.__xsDataCollection)
         xsDataIndexingInput.setExperimentalCondition(xsDataExperimentalCondition)
         if self.__xsDataCrystal != None:
             xsDataIndexingInput.setCrystal(self.__xsDataCrystal)
         self.__edPluginControlIndexingLabelit.setDataInput(xsDataIndexingInput)
         self.__edPluginControlIndexingLabelit.executeSynchronous()
Exemple #8
0
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlIndexingIndicatorsv10.preProcess")
     # Load and prepare the execution plugin
     self.__edPluginMOSFLMIndexing = self.loadPlugin(
         self.__strMOSFLMIndexingPluginName)
     self.__edPluginMOSFLMIndexing.setUseWarningInsteadOfError(True)
     xsDataIndexingInput = XSDataIndexingInput()
     xsDataIndexingInput.setDataCollection(
         self.getDataInput("dataCollection")[0])
     if self.hasDataInput("crystal"):
         xsDataIndexingInput.setCrystal(self.getDataInput("crystal")[0])
     if self.hasDataInput("refinedExperimentalCondition"):
         xsDataIndexingInput.setExperimentalCondition(
             self.getDataInput("refinedExperimentalCondition")[0])
     from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
     xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(
         xsDataIndexingInput)
     self.__edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
     self.__edPluginControlIndicators = self.loadPlugin(
         self.__strControlledIndicatorsPluginName)
     # Extract the images from the data collections
     xsDataSubWedgeList = self.getDataInput(
         "dataCollection")[0].getSubWedge()
     xsDataInputControlImageQualityIndicators = XSDataInputControlImageQualityIndicators(
     )
     for xsDataSubWedge in xsDataSubWedgeList:
         xsDataImageList = xsDataSubWedge.getImage()
         for xsDataImage in xsDataImageList:
             xsDataInputControlImageQualityIndicators.addImage(xsDataImage)
     self.__edPluginControlIndicators.setDataInput(
         xsDataInputControlImageQualityIndicators)
 def doSuccessIndicators(self, _edPlugin=None):
     self.DEBUG("EDPluginControlGridScreeningv1_0.doSuccessIndicators")
     # self.retrieveSuccessMessages(_edPlugin, "EDPluginControlGridScreeningv1_0.doSuccessIndexingIndicators")
     if self.edPluginControlIndicators.hasDataOutput():
         self.xsDataImageQualityIndicators = self.edPluginControlIndicators.getDataOutput().getImageQualityIndicators()[0]
         # Continue only if requested
         if not self.bDoOnlyImageQualityIndicators:
             xsDataIndexingInput = XSDataIndexingInput()
             xsDataIndexingInput.setDataCollection(self.xsDataCollection)
             from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
             xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
             self.edPluginMOSFLMIndexing.connectSUCCESS(self.doSuccessIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.connectFAILURE(self.doFailureIndexingMOSFLM)
             self.edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
             self.edPluginMOSFLMIndexing.executeSynchronous()
 def doSuccessEvaluationIndexingLABELIT(self, _edPlugin=None):
     self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessEvaluationIndexingLABELIT")
     self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_5.doSuccessEvaluationIndexingLABELIT")
     # Retrieve status messages (if any)
     if self._edPluginExecEvaluationIndexingLABELIT.hasDataOutput("statusMessageIndexing"):
         self.addStatusMessage("Labelit: " + self._edPluginExecEvaluationIndexingLABELIT.getDataOutput("statusMessageIndexing")[0].getValue())
     # Check if indexing was successful
     bIndexingSuccess = self._edPluginExecEvaluationIndexingLABELIT.getDataOutput("indexingSuccess")[0].getValue()
     if bIndexingSuccess:
         xsDataIndexingResult = self._edPluginExecEvaluationIndexingLABELIT.getDataOutput("indexingResult")[0]
         self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
         if self._edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
             self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
         xsDataCollection = self._xsDataResultCharacterisation.getDataCollection()
         xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
         xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
         xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(xsDataIndexingResult.getSelectedSolution().marshal()))
         self._edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
         if self._edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
             indexingShortSummary = self._edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
             self._strCharacterisationShortSummary += indexingShortSummary
             self.sendMessageToMXCuBE(indexingShortSummary)
         # Start the generation of prediction images - we synchronize in the post-process
         self._edPluginControlGeneratePrediction.execute()
         # Then start the integration of the reference images
         self.indexingToIntegration()
     else:
         if self._iNoImagesWithDozorScore > 0:
             strWarningMessage = "Execution of Indexing and Indicators plugin failed - trying to index with MOSFLM."
             self.WARNING(strWarningMessage)
             self.sendMessageToMXCuBE(strWarningMessage, "warning")
             self.addWarningMessage(strWarningMessage)
             xsDataIndexingInput = XSDataIndexingInput()
             xsDataIndexingInput.dataCollection = self._xsDataCollection
             xsDataIndexingInput.experimentalCondition = self._xsDataCollection.subWedge[0].experimentalCondition
             xsDataIndexingInput.crystal = self._xsDataCrystal
             self._edPluginControlIndexingMOSFLM.setDataInput(xsDataIndexingInput)
             self.executePluginSynchronous(self._edPluginControlIndexingMOSFLM)
         else:
             strErrorMessage = "Execution of indexing with Labelit failed."
             self.ERROR(strErrorMessage)
             self.sendMessageToMXCuBE(strErrorMessage, "error")
             self.addErrorMessage(strErrorMessage)
             self.setFailure()
             self.generateExecutiveSummary(self)
             if self._strStatusMessage != None:
                 self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
                 self.writeDataOutput()
 def doSuccessEvaluationIndexingMOSFLM(self, _edPlugin=None):
     EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexingMOSFLM")
     self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexing")
     # Retrieve status messages (if any)
     if self.__edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageImageQualityIndicators"):
         self.addStatusMessage(self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageImageQualityIndicators")[0].getValue())
     if self.__edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageIndexing"):
         self.addStatusMessage("MOSFLM: " + self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageIndexing")[0].getValue())
     # Check if indexing was successful
     bIndexWithLabelit = False
     bIndexingSuccess = self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingSuccess")[0].getValue()
     if bIndexingSuccess:
         xsDataIndexingResult = self.__edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingResult")[0]
         self.__xsDataIndexingResultMOSFLM = xsDataIndexingResult
         # Check if space group is P1 - if yes run Labelit indexing
         xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution()
         xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
         xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
         strSpaceGroupName = xsDataSpaceGroup.getName().getValue().upper()
         # Check if MOSFLM has indexed in P1
         if strSpaceGroupName == "P1":
             # Check if the user maybe asked for P1!
             bIndexWithLabelit = True
             if self.__xsDataCollection.getDiffractionPlan() is not None:
                 if self.__xsDataCollection.getDiffractionPlan().getForcedSpaceGroup() is not None:
                     if self.__xsDataCollection.getDiffractionPlan().getForcedSpaceGroup().getValue().upper() == "P1":
                         EDVerbose.screen("P1 space forced by diffraction plan")
                         bIndexWithLabelit = False
         if bIndexWithLabelit:
             EDVerbose.screen("P1 space group choosed - reindexing with Labelit")
         else:
             EDVerbose.screen("MOSFLM indexing successful!")
             if self.__edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
                 self.__strCharacterisationShortSummary += self.__edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
             # Generate prediction images
             xsDataCollection = self.__xsDataResultCharacterisation.getDataCollection()
             self.__xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
             xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
             xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
             xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(xsDataIndexingResult.getSelectedSolution().marshal()))
             self.__edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
             # Start the generation of prediction images - we synchronize in the post-process
             self.__edPluginControlGeneratePrediction.execute()
             # Then start the integration of the reference images
             self.indexingToIntegration()
     else:
         EDVerbose.screen("Indexing with MOSFLM failed!")
         bIndexWithLabelit = True
     if bIndexWithLabelit:
         # Execute Labelit indexing
         EDVerbose.screen("Now trying to index with Labelit - please be patient...")
         xsDataIndexingInput = XSDataIndexingInput()
         xsDataSubWedgeList = self.__xsDataCollection.getSubWedge()
         xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()
         xsDataIndexingInput.setDataCollection(self.__xsDataCollection)
         xsDataIndexingInput.setExperimentalCondition(xsDataExperimentalCondition)
         if self.__xsDataCrystal != None:
             xsDataIndexingInput.setCrystal(self.__xsDataCrystal)
         self.__edPluginControlIndexingLabelit.setDataInput(xsDataIndexingInput)
         self.__edPluginControlIndexingLabelit.executeSynchronous()
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlIndexingIndicatorsv1_1.preProcess")
     # Load and prepare the execution plugin
     self.edPluginIndexingLabelit = self.loadPlugin(self.strPluginIndexingLabelit)
     self.edPluginIndexingLabelit.setUseWarningInsteadOfError(True)
     xsDataIndexingInput = XSDataIndexingInput()
     xsDataIndexingInput.setDataCollection(self.getDataInput("dataCollection")[0])
     if self.hasDataInput("crystal"):
         xsDataIndexingInput.setCrystal(self.getDataInput("crystal")[0])
     if self.hasDataInput("refinedExperimentalCondition"):
         self.xsDataExperimentalCondition = self.getDataInput("refinedExperimentalCondition")[0]
     else:
         self.xsDataExperimentalCondition = self.getDataInput("dataCollection")[0].getSubWedge()[0].getExperimentalCondition()
     xsDataIndexingInput.setExperimentalCondition(self.xsDataExperimentalCondition)
     from EDHandlerXSDataPhenixv1_1 import EDHandlerXSDataPhenixv1_1
     xsDataInputLabelitIndexing = EDHandlerXSDataPhenixv1_1.generateXSDataInputLabelitIndexing(xsDataIndexingInput)
     self.edPluginIndexingLabelit.setDataInput(xsDataInputLabelitIndexing)
     #
     if self.bDoLabelitIndexing:
         if (self.getControlledPluginName("indicatorsPlugin") is not None):
             self.strControlledIndicatorsPluginName = self.getControlledPluginName("indicatorsPlugin")
     self.edPluginControlIndicators = self.loadPlugin(self.strControlledIndicatorsPluginName)
     # Extract the images from the data collections
     xsDataSubWedgeList = self.getDataInput("dataCollection")[0].getSubWedge()
     xsDataInputControlImageQualityIndicators = XSDataInputControlImageQualityIndicators()
     for xsDataSubWedge in xsDataSubWedgeList:
         xsDataImageList = xsDataSubWedge.getImage()
         for xsDataImage in xsDataImageList:
             xsDataInputControlImageQualityIndicators.addImage(xsDataImage)
     self.edPluginControlIndicators.setDataInput(xsDataInputControlImageQualityIndicators)
Exemple #13
0
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.preProcess...")

        self.edPluginIndexing = self.loadPlugin(self.strPluginIndexingName,
                                                "Indexing")
        self.edPluginIntegration = self.loadPlugin(
            self.strPluginIntegrationName, "Integration")
        self.edPluginStrategy = self.loadPlugin(self.strPluginStrategyName,
                                                "Strategy")

        if (self.edPluginIndexing is not None):
            EDVerbose.DEBUG(
                "EDPluginControlCharacterisationv2_0.preProcess: " +
                self.strPluginIndexingName + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputStrategy = self.getDataInput(
                "mxv1InputCharacterisation")[0]
            xsDataCollection = xsDataInputStrategy.getDataCollection()
            #xsDataSample = xsDataCollection.getSample()
            xsDataSubWedgeList = xsDataCollection.getSubWedge()
            xsDataExperimentalCondition = xsDataSubWedgeList[
                0].getExperimentalCondition()

            xsDataIndexingInput = XSDataIndexingInput()
            xsDataIndexingInput.setDataCollection(xsDataCollection)
            xsDataIndexingInput.setExperimentalCondition(
                xsDataExperimentalCondition)

            xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
            xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup(
            )
            if (xsDataStringForcedSpaceGroup is not None):
                xsDataCrystal = XSDataCrystal()
                xsDataSpaceGroup = XSDataSpaceGroup()
                xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)
                xsDataIndexingInput.setCrystal(xsDataCrystal)

            self.edPluginIndexing.setDataInput(xsDataIndexingInput)

            # Populate characterisation object
            self.xsDataResultCharacterisationv2_0 = XSDataResultCharacterisationv2_0(
            )
            self.xsDataResultCharacterisation = XSDataResultCharacterisation()
            self.xsDataResultCharacterisationv2_0.setMxv1ResultCharacterisation(
                self.xsDataResultCharacterisation)
            self.xsDataResultCharacterisation.setDataCollection(
                XSDataCollection.parseString(xsDataCollection.marshal()))
    def doXdsIndexingIntegration(self, _xsDataCollection):
        # Load the plugin
        self._edPluginIndexing = self.loadPlugin(self._strIndexingPluginName, "Indexing")
        # XDS Indexing
        xsDataIndexingInput = XSDataIndexingInput()
        xsDataIndexingInput.setDataCollection(_xsDataCollection)
        self._edPluginIndexing.dataInput = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIndexing(xsDataIndexingInput)
        self._edPluginIndexing.executeSynchronous()
        xsDataResultXDSIndexing = self._edPluginIndexing.dataOutput
        if xsDataResultXDSIndexing.spaceGroupNumber is not None:
            spaceGroupNumber = xsDataResultXDSIndexing.spaceGroupNumber.value
            unitCell = xsDataResultXDSIndexing.unitCell
            filePaths = xsDataResultXDSIndexing.filePaths
            index = 1
            for subWedge in _xsDataCollection.subWedge:
                xsDataCollection = XSDataCollection()
                xsDataCollection.addSubWedge(subWedge)
                xsDataIndexingInput = XSDataIndexingInput()
                xsDataIndexingInput.setDataCollection(xsDataCollection)

                xsDataInputXDSIntegration = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIntegration(xsDataIndexingInput,
                                                                                                     spaceGroupNumber,
                                                                                                     unitCell,
                                                                                                     filePaths)
                edPluginIntegration = self.loadPlugin(self._strIntegrationPluginName, "Integration_{0}".format(index))
                edPluginIntegration.dataInput = xsDataInputXDSIntegration
                edPluginIntegration.executeSynchronous()
                # self._edPluginIntegration.dataInput = xsDataInputXDSIntegration
                index += 1
    def testGenerateXSDataInputXDSIndexing(self):
        filename = "XSDataIndexingInput_reference.xml"
        path = os.path.join(self.dataPath, filename)
        xmlIndexingInput = EDUtilsTest.readAndParseFile(path)
        from XSDataMXv1 import XSDataIndexingInput
        xsDataIndexingInput = XSDataIndexingInput.parseString(xmlIndexingInput)

        from EDHandlerXSDataXDSv1_0 import EDHandlerXSDataXDSv1_0
        xsDataInputXDSIndexing = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIndexing(xsDataIndexingInput)

        referenceFilename = "XSDataInputXDSIndexing_reference.xml"
        referencePath = os.path.join(self.dataPath, referenceFilename)
        xmlInputXDSIndexingReference = EDUtilsTest.readAndParseFile(referencePath)
        EDAssert.equal(xmlInputXDSIndexingReference, xsDataInputXDSIndexing.marshal())
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.preProcess...")

        self.__edPluginIndexing = self.loadPlugin(self.__strPluginIndexingName   , "Indexing")
        self.__edPluginIntegration = self.loadPlugin(self.__strPluginIntegrationName, "Integration")
        self.__edPluginStrategy = self.loadPlugin(self.__strPluginStrategyName   , "Strategy")

        if (self.__edPluginIndexing is not None):
            EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.preProcess: " + self.__strPluginIndexingName + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputStrategy = self.getDataInput()
            xsDataCollection = xsDataInputStrategy.getDataCollection()
            xsDataSample = xsDataCollection.getSample()
            xsDataSubWedgeList = xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
            	strError = "EDPluginControlCharacterisationv1_1.preProcess: No subwedges in input data."
            	EDVerbose.ERROR(strError)
                self.setFailure()
            else:
                xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()

                # Fix for bug 431: if the flux is zero raise an error
                xsDataDoubleFlux = xsDataExperimentalCondition.getBeam().getFlux()
                if (xsDataDoubleFlux is not None):
                    if (xsDataDoubleFlux.getValue() < 0.1):
                        pyStrErrorMessage = "EDPluginControlCharacterisationv1_1.preProcess ERROR: Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(pyStrErrorMessage)
                        self.addErrorMessage(pyStrErrorMessage)
                        self.setFailure()

                xsDataIndexingInput = XSDataIndexingInput()
                xsDataIndexingInput.setDataCollection(xsDataCollection)
                xsDataIndexingInput.setExperimentalCondition(xsDataExperimentalCondition)

                xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)
                    xsDataIndexingInput.setCrystal(xsDataCrystal)

                self.__edPluginIndexing.setDataInput(xsDataIndexingInput)

                # Populate characterisation object
                self.__xsDataResultCharacterisation = XSDataResultCharacterisation()
                self.__xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
    def testSetDataInput(self):
        edPluginControlIndexingv10 = self.createPlugin()
        xsPluginItemGood01 = self.getPluginConfiguration(os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml"))
        edPluginControlIndexingv10.setConfiguration(xsPluginItemGood01)
        edPluginControlIndexingv10.configure()

        xmlInput = self.readAndParseFile(self.__strReferenceInputFile)
        edPluginControlIndexingv10.setDataInput(xmlInput)

        xsDataIndexingv01Input = edPluginControlIndexingv10.getDataInput()

        xsDataIndexingInputReference = XSDataIndexingInput.parseString(xmlInput)
        EDAssert.equal(xsDataIndexingInputReference.marshal(), xsDataIndexingv01Input.marshal())

        self.cleanUp(edPluginControlIndexingv10)
 def testGenerateXSDataMOSFLMInputIndexing(self):
     strFilename = "XSDataIndexingInput_reference.xml"
     strPath = os.path.join(self.m_strDataPath, strFilename)
     strXMLIndexingInput = EDUtilsTest.readAndParseFile(strPath)
     from XSDataMXv1 import XSDataIndexingInput
     xsDataIndexingInput = XSDataIndexingInput.parseString(strXMLIndexingInput)
     from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
     xsDataMOSFLMInputIndexing = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
     xsDataMOSFLMInputIndexing.outputFile("XSDataMOSFLMInputIndexing_reference.xml")
     strReferenceFilename = "XSDataMOSFLMInputIndexing_reference.xml"
     strReferencePath = os.path.join(self.m_strDataPath, strReferenceFilename)
     strXMLMOSFLMInputIndexingReference = EDUtilsTest.readAndParseFile(strReferencePath)
     EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
     from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing
     xsDataMOSFLMInputIndexingReference = XSDataMOSFLMInputIndexing.parseString(strXMLMOSFLMInputIndexingReference)
     EDAssert.equal(xsDataMOSFLMInputIndexingReference.marshal(), xsDataMOSFLMInputIndexing.marshal())
    def testGenerateXSDataInputXDSIndexing(self):
        filename = "XSDataIndexingInput_reference.xml"
        path = os.path.join(self.dataPath, filename)
        xmlIndexingInput = EDUtilsTest.readAndParseFile(path)
        from XSDataMXv1 import XSDataIndexingInput
        xsDataIndexingInput = XSDataIndexingInput.parseString(xmlIndexingInput)

        from EDHandlerXSDataXDSv1_0 import EDHandlerXSDataXDSv1_0
        xsDataInputXDSIndexing = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIndexing(
            xsDataIndexingInput)

        referenceFilename = "XSDataInputXDSIndexing_reference.xml"
        referencePath = os.path.join(self.dataPath, referenceFilename)
        xmlInputXDSIndexingReference = EDUtilsTest.readAndParseFile(
            referencePath)
        EDAssert.equal(xmlInputXDSIndexingReference,
                       xsDataInputXDSIndexing.marshal())
    def testGenerateXSDataInputXDSIndexing(self):
        pyStrFilename = "XSDataIndexingInput_reference.xml"
        pyStrPath = os.path.join(self.m_pyStrDataPath, pyStrFilename)
        pyStrXMLIndexingInput = self.readAndParseFile(pyStrPath)
        from XSDataMXv1 import XSDataIndexingInput
        xsDataIndexingInput = XSDataIndexingInput.parseString(pyStrXMLIndexingInput)

        from EDHandlerXSDataXDSv1_0 import EDHandlerXSDataXDSv1_0
        xsDataInputXDSIndexing = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIndexing(xsDataIndexingInput)

        xsDataInputXDSIndexing.outputFile("XSDataInputXDSIndexing_reference.xml")

        pyStrReferenceFilename = "XSDataInputXDSIndexing_reference.xml"
        pyStrReferencePath = os.path.join(self.m_pyStrDataPath, pyStrReferenceFilename)
        xsDataInputXDSIndexing.outputFile("XSDataInputXDSIndexing.xml")
        pyStrXMLInputXDSIndexingReference = self.readAndParseFile(pyStrReferencePath)
        EDAssert.equal(pyStrXMLInputXDSIndexingReference, xsDataInputXDSIndexing.marshal())
    def testSetDataInput(self):
        edPluginControlIndexingv10 = self.createPlugin()
        strPathToTestConfigFile = os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml")
        edConfiguration = EDConfiguration(strPathToTestConfigFile)
        dictItem = edConfiguration.get(edPluginControlIndexingv10.getPluginName())
        edPluginControlIndexingv10.setConfig(dictItem)
        edPluginControlIndexingv10.configure()

        xmlInput = self.readAndParseFile(self.__strReferenceInputFile)
        edPluginControlIndexingv10.setDataInput(xmlInput)

        xsDataIndexingv01Input = edPluginControlIndexingv10.getDataInput()

        xsDataIndexingInputReference = XSDataIndexingInput.parseString(xmlInput)
        EDAssert.equal(xsDataIndexingInputReference.marshal(), xsDataIndexingv01Input.marshal())

        self.cleanUp(edPluginControlIndexingv10)
 def testGenerateXSDataInputLabelit(self, _strFileNameXSDataIndexingInput_reference,
                                           _strFileNameXSDataLabelitInput_reference):
     """
     This method is testing the generation of the XSDataInputLabelit object given a XSDataIndexingInput object.
     """
     strPath = os.path.join(self.strDataPath, _strFileNameXSDataIndexingInput_reference)
     strXMLIndexingInput = EDUtilsTest.readAndParseFile(strPath)
     from XSDataMXv1 import XSDataIndexingInput
     xsDataIndexingInput = XSDataIndexingInput.parseString(strXMLIndexingInput)
     from EDHandlerXSDataLabelitv10 import EDHandlerXSDataLabelitv10
     xsDataInputLabelit = EDHandlerXSDataLabelitv10.generateXSDataInputLabelit(xsDataIndexingInput)
     strReferencePath = os.path.join(self.strDataPath, _strFileNameXSDataLabelitInput_reference)
     strXMLInputLabelitReference = EDUtilsTest.readAndParseFile(strReferencePath)
     EDFactoryPluginStatic.loadModule("XSDataLabelitv10")
     from XSDataLabelitv10 import XSDataInputLabelit
     xsDataInputLabelitReference = XSDataInputLabelit.parseString(strXMLInputLabelitReference)
     EDAssert.equal(xsDataInputLabelitReference.marshal(), xsDataInputLabelit.marshal())
Exemple #23
0
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlIndexingIndicatorsv1_1.preProcess")
     # Load and prepare the execution plugin
     self.edPluginIndexingLabelit = self.loadPlugin(
         self.strPluginIndexingLabelit)
     self.edPluginIndexingLabelit.setUseWarningInsteadOfError(True)
     xsDataIndexingInput = XSDataIndexingInput()
     xsDataIndexingInput.setDataCollection(
         self.getDataInput("dataCollection")[0])
     if self.hasDataInput("crystal"):
         xsDataIndexingInput.setCrystal(self.getDataInput("crystal")[0])
     if self.hasDataInput("refinedExperimentalCondition"):
         self.xsDataExperimentalCondition = self.getDataInput(
             "refinedExperimentalCondition")[0]
     else:
         self.xsDataExperimentalCondition = self.getDataInput(
             "dataCollection")[0].getSubWedge()[0].getExperimentalCondition(
             )
     xsDataIndexingInput.setExperimentalCondition(
         self.xsDataExperimentalCondition)
     from EDHandlerXSDataPhenixv1_1 import EDHandlerXSDataPhenixv1_1
     xsDataInputLabelitIndexing = EDHandlerXSDataPhenixv1_1.generateXSDataInputLabelitIndexing(
         xsDataIndexingInput)
     self.edPluginIndexingLabelit.setDataInput(xsDataInputLabelitIndexing)
     #
     if self.bDoLabelitIndexing:
         if (self.getControlledPluginName("indicatorsPlugin") is not None):
             self.strControlledIndicatorsPluginName = self.getControlledPluginName(
                 "indicatorsPlugin")
     self.edPluginControlIndicators = self.loadPlugin(
         self.strControlledIndicatorsPluginName)
     # Extract the images from the data collections
     xsDataSubWedgeList = self.getDataInput(
         "dataCollection")[0].getSubWedge()
     xsDataInputControlImageQualityIndicators = XSDataInputControlImageQualityIndicators(
     )
     for xsDataSubWedge in xsDataSubWedgeList:
         xsDataImageList = xsDataSubWedge.getImage()
         for xsDataImage in xsDataImageList:
             xsDataInputControlImageQualityIndicators.addImage(xsDataImage)
     self.edPluginControlIndicators.setDataInput(
         xsDataInputControlImageQualityIndicators)
Exemple #24
0
    def testSetDataInput(self):
        edPluginControlIndexingv10 = self.createPlugin()
        xsPluginItemGood01 = self.getPluginConfiguration(
            os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml"))
        edPluginControlIndexingv10.setConfiguration(xsPluginItemGood01)
        edPluginControlIndexingv10.configure()

        xmlInput = self.readAndParseFile(self.__strReferenceInputFile)
        edPluginControlIndexingv10.setDataInput(xmlInput)

        xsDataIndexingv01Input = edPluginControlIndexingv10.getDataInput()

        xsDataIndexingInputReference = XSDataIndexingInput.parseString(
            xmlInput)
        EDAssert.equal(xsDataIndexingInputReference.marshal(),
                       xsDataIndexingv01Input.marshal())

        self.cleanUp(edPluginControlIndexingv10)
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.preProcess...")

        self.edPluginIndexing = self.loadPlugin(self.strPluginIndexingName, "Indexing")
        self.edPluginIntegration = self.loadPlugin(self.strPluginIntegrationName, "Integration")
        self.edPluginStrategy = self.loadPlugin(self.strPluginStrategyName, "Strategy")

        if self.edPluginIndexing is not None:
            EDVerbose.DEBUG(
                "EDPluginControlCharacterisationv2_0.preProcess: "
                + self.strPluginIndexingName
                + " Found... setting Data Input"
            )
            # create Data Input for indexing
            xsDataInputStrategy = self.getDataInput("mxv1InputCharacterisation")[0]
            xsDataCollection = xsDataInputStrategy.getDataCollection()
            # xsDataSample = xsDataCollection.getSample()
            xsDataSubWedgeList = xsDataCollection.getSubWedge()
            xsDataExperimentalCondition = xsDataSubWedgeList[0].getExperimentalCondition()

            xsDataIndexingInput = XSDataIndexingInput()
            xsDataIndexingInput.setDataCollection(xsDataCollection)
            xsDataIndexingInput.setExperimentalCondition(xsDataExperimentalCondition)

            xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
            xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
            if xsDataStringForcedSpaceGroup is not None:
                xsDataCrystal = XSDataCrystal()
                xsDataSpaceGroup = XSDataSpaceGroup()
                xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)
                xsDataIndexingInput.setCrystal(xsDataCrystal)

            self.edPluginIndexing.setDataInput(xsDataIndexingInput)

            # Populate characterisation object
            self.xsDataResultCharacterisationv2_0 = XSDataResultCharacterisationv2_0()
            self.xsDataResultCharacterisation = XSDataResultCharacterisation()
            self.xsDataResultCharacterisationv2_0.setMxv1ResultCharacterisation(self.xsDataResultCharacterisation)
            self.xsDataResultCharacterisation.setDataCollection(
                XSDataCollection.parseString(xsDataCollection.marshal())
            )
Exemple #26
0
 def testGenerateXSDataMOSFLMInputIndexing(self):
     strFilename = "XSDataIndexingInput_reference.xml"
     strPath = os.path.join(self.m_strDataPath, strFilename)
     strXMLIndexingInput = EDUtilsTest.readAndParseFile(strPath)
     from XSDataMXv1 import XSDataIndexingInput
     xsDataIndexingInput = XSDataIndexingInput.parseString(
         strXMLIndexingInput)
     from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
     xsDataMOSFLMInputIndexing = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(
         xsDataIndexingInput)
     xsDataMOSFLMInputIndexing.exportToFile(
         "XSDataMOSFLMInputIndexing_reference.xml")
     strReferenceFilename = "XSDataMOSFLMInputIndexing_reference.xml"
     strReferencePath = os.path.join(self.m_strDataPath,
                                     strReferenceFilename)
     strXMLMOSFLMInputIndexingReference = EDUtilsTest.readAndParseFile(
         strReferencePath)
     EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
     from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing
     xsDataMOSFLMInputIndexingReference = XSDataMOSFLMInputIndexing.parseString(
         strXMLMOSFLMInputIndexingReference)
     EDAssert.equal(xsDataMOSFLMInputIndexingReference.marshal(),
                    xsDataMOSFLMInputIndexing.marshal())
    def testGenerateXSDataInputXDSIndexing(self):
        pyStrFilename = "XSDataIndexingInput_reference.xml"
        pyStrPath = os.path.join(self.m_pyStrDataPath, pyStrFilename)
        pyStrXMLIndexingInput = self.readAndParseFile(pyStrPath)
        from XSDataMXv1 import XSDataIndexingInput
        xsDataIndexingInput = XSDataIndexingInput.parseString(
            pyStrXMLIndexingInput)

        from EDHandlerXSDataXDSv1_0 import EDHandlerXSDataXDSv1_0
        xsDataInputXDSIndexing = EDHandlerXSDataXDSv1_0.generateXSDataInputXDSIndexing(
            xsDataIndexingInput)

        xsDataInputXDSIndexing.exportToFile(
            "XSDataInputXDSIndexing_reference.xml")

        pyStrReferenceFilename = "XSDataInputXDSIndexing_reference.xml"
        pyStrReferencePath = os.path.join(self.m_pyStrDataPath,
                                          pyStrReferenceFilename)
        xsDataInputXDSIndexing.exportToFile("XSDataInputXDSIndexing.xml")
        pyStrXMLInputXDSIndexingReference = self.readAndParseFile(
            pyStrReferencePath)
        EDAssert.equal(pyStrXMLInputXDSIndexingReference,
                       xsDataInputXDSIndexing.marshal())
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     EDVerbose.DEBUG("EDPluginControlIndexingIndicatorsv10.preProcess")
     # Load and prepare the execution plugin
     self.__edPluginMOSFLMIndexing = self.loadPlugin(self.__strMOSFLMIndexingPluginName)
     xsDataIndexingInput = XSDataIndexingInput()
     xsDataIndexingInput.setDataCollection(self.getDataInput("dataCollection")[0])
     if self.hasDataInput("crystal"):
         xsDataIndexingInput.setCrystal(self.getDataInput("crystal")[0])
     if self.hasDataInput("refinedExperimentalCondition"):
         xsDataIndexingInput.setExperimentalCondition(self.getDataInput("refinedExperimentalCondition")[0])
     from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
     xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
     self.__edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
     self.__edPluginControlIndicators = self.loadPlugin(self.__strControlledIndicatorsPluginName)
     # Extract the images from the data collections
     xsDataSubWedgeList = self.getDataInput("dataCollection")[0].getSubWedge()
     xsDataInputControlImageQualityIndicators = XSDataInputControlImageQualityIndicators()
     for xsDataSubWedge in xsDataSubWedgeList:
         xsDataImageList = xsDataSubWedge.getImage()
         for xsDataImage in xsDataImageList:
             xsDataInputControlImageQualityIndicators.addImage(xsDataImage)
     self.__edPluginControlIndicators.setDataInput(xsDataInputControlImageQualityIndicators)
Exemple #29
0
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_3.process")
        EDUtilsParallel.initializeNbThread()
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                bDoIndexing = True
        # Loop through all the incoming reference images
        listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators(
        )
        listPlugin = []
        for xsDataImage in listXSDataImage:
            self.edPluginMXWaitFile = self.loadPlugin(
                self.strPluginMXWaitFileName)
            xsDataInputMXWaitFile.file = XSDataFile(xsDataImage.path)
            xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
            xsDataInputMXWaitFile.setTimeOut(
                XSDataTime(self.fMXWaitFileTimeOut))
            self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
            self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
            self.edPluginMXWaitFile.executeSynchronous()
            if not os.path.exists(xsDataImage.path.value):
                self.edPluginMXWaitFile = self.loadPlugin(
                    self.strPluginMXWaitFileName)
                xsDataInputMXWaitFile.file = XSDataFile(xsDataImage.path)
                xsDataInputMXWaitFile.setSize(XSDataInteger(5000000))
                xsDataInputMXWaitFile.setTimeOut(
                    XSDataTime(self.fMXWaitFileTimeOut))
                self.DEBUG("Wait file timeOut set to %f" %
                           self.fMXWaitFileTimeOut)
                self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                self.edPluginMXWaitFile.executeSynchronous()
            if not os.path.exists(xsDataImage.path.value):
                strError = "Time-out while waiting for image %s" % xsDataImage.path.value
                self.error(strError)
                self.addErrorMessage(strError)
                self.setFailure()
            else:
                if self.bUseThinClient:
                    strPluginName = self.strPluginNameThinClient
                else:
                    strPluginName = self.strPluginName
                edPluginPluginExecImageQualityIndicator = self.loadPlugin(
                    strPluginName)
                self.listPluginExecImageQualityIndicator.append(
                    edPluginPluginExecImageQualityIndicator)
                xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength(
                )
                xsDataInputDistlSignalStrength.setReferenceImage(xsDataImage)
                edPluginPluginExecImageQualityIndicator.setDataInput(
                    xsDataInputDistlSignalStrength)
                edPluginPluginExecImageQualityIndicator.execute()
                edPluginControlBackground3D = self.loadPlugin(
                    self.strPluginNameControlBackground3D)
                listPlugin.append([
                    edPluginPluginExecImageQualityIndicator,
                    edPluginControlBackground3D
                ])
                xsDataInputControlBackground3D = XSDataInputControlBackground3D(
                )
                xsDataInputControlBackground3D.addImage(
                    XSDataFile(xsDataImage.path))
                edPluginControlBackground3D.dataInput = xsDataInputControlBackground3D
                edPluginControlBackground3D.execute()
        listIndexing = []
        # Synchronize all image quality indicator plugins and upload to ISPyB
        xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators(
        )
        for pluginPair in listPlugin:
            edPluginPluginExecImageQualityIndicator = pluginPair[0]
            edPluginControlBackground3D = pluginPair[1]
            edPluginPluginExecImageQualityIndicator.synchronize()
            edPluginControlBackground3D.synchronize()
            xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\
                                             edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
            if edPluginControlBackground3D.dataOutput.imageBackground != []:
                xsDataImageQualityIndicators.background3D_estimate = edPluginControlBackground3D.dataOutput.imageBackground[
                    0].estimate
            self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(
                xsDataImageQualityIndicators)
            xsDataISPyBImageQualityIndicators = \
                XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
            xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(
                xsDataISPyBImageQualityIndicators)
#        print xsDataInputStoreListOfImageQualityIndicators.marshal()
        if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
            self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
            self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
            self.edPluginISPyB.execute()
        #
        if bDoIndexing:
            # Find the 5 most intensive images (TIS):
            listImage = []
            # Check that we have background3D_estimate from all images:
            has_background3D_estimate = True
            for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                if imageQualityIndicators.background3D_estimate is None:
                    has_background3D_estimate = False
            if has_background3D_estimate:
                listSorted = sorted(
                    self.xsDataResultControlImageQualityIndicators.
                    imageQualityIndicators,
                    key=lambda imageQualityIndicators: imageQualityIndicators.
                    background3D_estimate.value)
            else:
                listSorted = sorted(
                    self.xsDataResultControlImageQualityIndicators.
                    imageQualityIndicators,
                    key=lambda imageQualityIndicators: imageQualityIndicators.
                    totalIntegratedSignal.value)
            for xsDataResultControlImageQualityIndicator in listSorted[-5:]:
                if xsDataResultControlImageQualityIndicator.goodBraggCandidates.value > 30:
                    xsDataInputReadImageHeader = XSDataInputReadImageHeader()
                    xsDataInputReadImageHeader.image = XSDataFile(
                        xsDataResultControlImageQualityIndicator.image.path)
                    self.edPluginReadImageHeader = self.loadPlugin(
                        self.strPluginReadImageHeaderName)
                    self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                    self.edPluginReadImageHeader.executeSynchronous()
                    xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                    if xsDataResultReadImageHeader is not None:
                        xsDataSubWedge = xsDataResultReadImageHeader.subWedge
                        self.xsDataCollection = XSDataCollection()
                        self.xsDataCollection.addSubWedge(xsDataSubWedge)
                        xsDataIndexingInput = XSDataIndexingInput()
                        xsDataIndexingInput.setDataCollection(
                            self.xsDataCollection)
                        xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(
                            xsDataIndexingInput)
                        edPluginMOSFLMIndexing = self.loadPlugin(
                            self.strIndexingMOSFLMPluginName)
                        self.listPluginMOSFLM.append([
                            edPluginMOSFLMIndexing,
                            xsDataResultControlImageQualityIndicator
                        ])
                        edPluginMOSFLMIndexing.setDataInput(
                            xsDataMOSFLMIndexingInput)
                        edPluginMOSFLMIndexing.execute()
            for tupleMOSFLM in self.listPluginMOSFLM:
                edPluginMOSFLMIndexing = tupleMOSFLM[0]
                xsDataResultControlImageQualityIndicator = tupleMOSFLM[1]
                edPluginMOSFLMIndexing.synchronize()
                if not edPluginMOSFLMIndexing.isFailure():
                    xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput
                    xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(
                        xsDataMOSFLMOutput)
                    selectedSolution = xsDataIndexingResult.selectedSolution
                    if selectedSolution is not None:
                        xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_2.process")
        EDUtilsParallel.initializeNbThread()
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                bDoIndexing = True
        # Loop through all the incoming reference images
        listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators(
        )
        listPlugin = []
        for xsDataImage in listXSDataImage:
            self.edPluginMXWaitFile = self.loadPlugin(
                self.strPluginMXWaitFileName)
            xsDataInputMXWaitFile.file = XSDataFile(xsDataImage.path)
            xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
            xsDataInputMXWaitFile.setTimeOut(
                XSDataTime(self.fMXWaitFileTimeOut))
            self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
            self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
            self.edPluginMXWaitFile.executeSynchronous()
            if not os.path.exists(xsDataImage.path.value):
                strError = "Time-out while waiting for image %s" % xsDataImage.path.value
                self.error(strError)
                self.addErrorMessage(strError)
                self.setFailure()
            else:
                if self.bUseThinClient:
                    strPluginName = self.strPluginNameThinClient
                else:
                    strPluginName = self.strPluginName
                edPluginPluginExecImageQualityIndicator = self.loadPlugin(
                    strPluginName)
                listPlugin.append(edPluginPluginExecImageQualityIndicator)
                self.listPluginExecImageQualityIndicator.append(
                    edPluginPluginExecImageQualityIndicator)
                xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength(
                )
                xsDataInputDistlSignalStrength.setReferenceImage(xsDataImage)
                edPluginPluginExecImageQualityIndicator.setDataInput(
                    xsDataInputDistlSignalStrength)
                edPluginPluginExecImageQualityIndicator.execute()
        listIndexing = []
        # Synchronize all image quality indicator plugins and upload to ISPyB
        xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators(
        )
        for edPluginPluginExecImageQualityIndicator in listPlugin:
            edPluginPluginExecImageQualityIndicator.synchronize()
            xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString( \
                                             edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
            self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(
                xsDataImageQualityIndicators)
            xsDataISPyBImageQualityIndicators = \
                XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
            xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(
                xsDataISPyBImageQualityIndicators)
#        print xsDataInputStoreListOfImageQualityIndicators.marshal()
        if self.bDoISPyBUpload:
            self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
            self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
            self.edPluginISPyB.execute()
        #
        if bDoIndexing:
            # Find the 5 most intensive images (TIS):
            listImage = []
            listSorted = sorted(
                self.xsDataResultControlImageQualityIndicators.
                imageQualityIndicators,
                key=
                lambda imageQualityIndicators: imageQualityIndicators.totalIntegratedSignal.value
            )
            for xsDataResultControlImageQualityIndicator in listSorted[-5:]:
                if xsDataResultControlImageQualityIndicator.goodBraggCandidates.value > 30:
                    xsDataInputReadImageHeader = XSDataInputReadImageHeader()
                    xsDataInputReadImageHeader.image = XSDataFile(
                        xsDataResultControlImageQualityIndicator.image.path)
                    self.edPluginReadImageHeader = self.loadPlugin(
                        self.strPluginReadImageHeaderName)
                    self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                    self.edPluginReadImageHeader.executeSynchronous()
                    xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                    if xsDataResultReadImageHeader is not None:
                        xsDataSubWedge = xsDataResultReadImageHeader.subWedge
                        self.xsDataCollection = XSDataCollection()
                        self.xsDataCollection.addSubWedge(xsDataSubWedge)
                        xsDataIndexingInput = XSDataIndexingInput()
                        xsDataIndexingInput.setDataCollection(
                            self.xsDataCollection)
                        xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(
                            xsDataIndexingInput)
                        edPluginMOSFLMIndexing = self.loadPlugin(
                            self.strIndexingMOSFLMPluginName)
                        self.listPluginMOSFLM.append([
                            edPluginMOSFLMIndexing,
                            xsDataResultControlImageQualityIndicator
                        ])
                        edPluginMOSFLMIndexing.setDataInput(
                            xsDataMOSFLMIndexingInput)
                        edPluginMOSFLMIndexing.execute()
            for tupleMOSFLM in self.listPluginMOSFLM:
                edPluginMOSFLMIndexing = tupleMOSFLM[0]
                xsDataResultControlImageQualityIndicator = tupleMOSFLM[1]
                edPluginMOSFLMIndexing.synchronize()
                if not edPluginMOSFLMIndexing.isFailure():
                    xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput
                    xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(
                        xsDataMOSFLMOutput)
                    selectedSolution = xsDataIndexingResult.selectedSolution
                    if selectedSolution is not None:
                        xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
Exemple #31
0
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_4.process")
        EDUtilsParallel.initializeNbThread()
        # Check batch size
        if self.dataInput.batchSize is None:
            batchSize = 1
        else:
            batchSize = self.dataInput.batchSize.value
        self.screen(
            "Image quality indicators batch size: {0}".format(batchSize))
        # Check if we should do distlSignalStrength:
        bDoDistlSignalStrength = True
        if self.dataInput.doDistlSignalStrength is not None:
            if not self.dataInput.doDistlSignalStrength.value:
                bDoDistlSignalStrength = False
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                bDoIndexing = True
        # Check if fast mesh (for HDF5)
        isFastMesh = False
        if self.dataInput.fastMesh:
            isFastMesh = self.dataInput.fastMesh.value
        # Loop through all the incoming reference images
        if len(self.dataInput.image) == 0:
            directory = self.dataInput.directory.path.value
            template = self.dataInput.template.value
            startNo = self.dataInput.startNo.value
            endNo = self.dataInput.endNo.value
            listXSDataImage = []
            for index in range(startNo, endNo + 1):
                imageName = template.replace("####", "{0:04d}".format(index))
                imagePath = os.path.join(directory, imageName)
                xsDataImage = XSDataImage(path=XSDataString(imagePath),
                                          number=XSDataInteger(index))
                listXSDataImage.append(xsDataImage)
        else:
            listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators(
        )
        listPluginDistl = []
        listPluginDozor = []
        listOfImagesInBatch = []
        listOfAllBatches = []
        indexBatch = 0
        listH5FilePath = []
        # Process data in batches
        for xsDataImage in listXSDataImage:
            listOfImagesInBatch.append(xsDataImage.copy())
            if len(listOfImagesInBatch) == batchSize:
                listOfAllBatches.append(listOfImagesInBatch)
                listOfImagesInBatch = []
        if len(listOfImagesInBatch) > 0:
            listOfAllBatches.append(listOfImagesInBatch)
            listOfImagesInBatch = []
        # Loop over batches
        for listOfImagesInBatch in listOfAllBatches:
            # First wait for images
            for image in listOfImagesInBatch:
                strPathToImage = image.path.value
                # If Eiger, just wait for the h5 file
                if strPathToImage.endswith(".h5"):
                    h5MasterFilePath, h5DataFilePath, hdf5ImageNumber = self.getH5FilePath(
                        strPathToImage,
                        batchSize=batchSize,
                        isFastMesh=isFastMesh)
                    #                print(h5FilePath)
                    #                print(hdf5ImageNumber)
                    if not h5DataFilePath in listH5FilePath:
                        self.screen(
                            "ID30a3 Eiger data, waiting for master and data files..."
                        )
                        listH5FilePath.append(h5DataFilePath)
                        self.edPluginMXWaitFile = self.loadPlugin(
                            self.strPluginMXWaitFileName)
                        xsDataInputMXWaitFile.file = XSDataFile(
                            XSDataString(h5DataFilePath))
                        xsDataInputMXWaitFile.setSize(
                            XSDataInteger(self.minImageSize))
                        xsDataInputMXWaitFile.setTimeOut(
                            XSDataTime(self.fMXWaitFileTimeOut))
                        self.screen(
                            "Waiting for file {0}".format(h5DataFilePath))
                        self.DEBUG("Wait file timeOut set to %f" %
                                   self.fMXWaitFileTimeOut)
                        self.edPluginMXWaitFile.setDataInput(
                            xsDataInputMXWaitFile)
                        self.edPluginMXWaitFile.executeSynchronous()
                        #                    hdf5FilePath = strPathToImage.replace(".cbf", ".h5")
                        time.sleep(1)
                    if not os.path.exists(h5DataFilePath):
                        strError = "Time-out while waiting for image %s" % h5DataFilePath
                        self.error(strError)
                        self.addErrorMessage(strError)
                        self.setFailure()
                else:
                    if not os.path.exists(strPathToImage):
                        # self.screen("Waiting for file {0}".format(strPathToImage))
                        self.edPluginMXWaitFile = self.loadPlugin(
                            self.strPluginMXWaitFileName)
                        xsDataInputMXWaitFile.file = XSDataFile(
                            XSDataString(strPathToImage))
                        xsDataInputMXWaitFile.setSize(
                            XSDataInteger(self.minImageSize))
                        xsDataInputMXWaitFile.setTimeOut(
                            XSDataTime(self.fMXWaitFileTimeOut))
                        self.screen("Wait file timeOut set to %.0f s" %
                                    self.fMXWaitFileTimeOut)
                        self.edPluginMXWaitFile.setDataInput(
                            xsDataInputMXWaitFile)
                        self.edPluginMXWaitFile.executeSynchronous()
                    if not os.path.exists(strPathToImage):
                        strError = "Time-out while waiting for image %s" % strPathToImage
                        self.error(strError)
                        self.addErrorMessage(strError)
                        self.setFailure()
            if not self.isFailure():
                strPathToFirstImage = listOfImagesInBatch[0].path.value
                if strPathToImage.endswith(".h5"):
                    indexLoop = 1
                    continueLoop = True
                    while continueLoop:
                        directory = os.path.dirname(strPathToFirstImage)
                        firstImage = EDUtilsImage.getImageNumber(
                            listOfImagesInBatch[0].path.value)
                        lastImage = EDUtilsImage.getImageNumber(
                            listOfImagesInBatch[-1].path.value)
                        xsDataInputH5ToCBF = XSDataInputH5ToCBF()
                        xsDataInputH5ToCBF.hdf5File = XSDataFile(
                            listOfImagesInBatch[0].path)
                        xsDataInputH5ToCBF.hdf5ImageNumber = XSDataInteger(1)
                        xsDataInputH5ToCBF.startImageNumber = XSDataInteger(
                            firstImage)
                        xsDataInputH5ToCBF.endImageNumber = XSDataInteger(
                            lastImage)
                        xsDataInputH5ToCBF.forcedOutputDirectory = XSDataFile(
                            XSDataString(directory))
                        edPluginH5ToCBF = self.loadPlugin(
                            "EDPluginH5ToCBFv1_1")
                        edPluginH5ToCBF.dataInput = xsDataInputH5ToCBF
                        edPluginH5ToCBF.execute()
                        edPluginH5ToCBF.synchronize()
                        outputCBFFileTemplate = edPluginH5ToCBF.dataOutput.outputCBFFileTemplate
                        if outputCBFFileTemplate is not None:
                            lastCbfFile = outputCBFFileTemplate.path.value.replace(
                                "######", "{0:06d}".format(
                                    EDUtilsImage.getImageNumber(
                                        listOfImagesInBatch[-1].path.value)))
                            strPathToImage = os.path.join(
                                directory, lastCbfFile)
                            #                        print(cbfFile.path.value)
                            if os.path.exists(strPathToImage):
                                # Rename all images
                                for image in listOfImagesInBatch:
                                    image.path.value = image.path.value.replace(
                                        ".h5", ".cbf")
                                    imageNumber = EDUtilsImage.getImageNumber(
                                        image.path.value)
                                    oldPath = os.path.join(
                                        directory,
                                        outputCBFFileTemplate.path.value.
                                        replace("######",
                                                "{0:06d}".format(imageNumber)))
                                    newPath = os.path.join(
                                        directory,
                                        outputCBFFileTemplate.path.value.
                                        replace("######",
                                                "{0:04d}".format(imageNumber)))
                                    os.rename(oldPath, newPath)
                                lastCbfFile = outputCBFFileTemplate.path.value.replace(
                                    "######", "{0:04d}".format(
                                        EDUtilsImage.getImageNumber(
                                            listOfImagesInBatch[-1].path.value)
                                    ))
                                strPathToImage = os.path.join(
                                    directory, lastCbfFile)
                                self.screen(
                                    "Image has been converted to CBF file: {0}"
                                    .format(strPathToImage))
                                continueLoop = False
    #                    print(continueLoop)
                        if continueLoop:
                            self.screen(
                                "Still waiting for converting to CBF file: {0}"
                                .format(strPathToImage))
                            indexLoop += 1
                            time.sleep(5)
                            if indexLoop > 10:
                                continueLoop = False

                for image in listOfImagesInBatch:
                    strPathToImage = image.path.value
                    # Check if we should run distl.signalStrength
                    xsDataImageNew = XSDataImage(XSDataString(strPathToImage))
                    xsDataImageNew.number = XSDataInteger(
                        EDUtilsImage.getImageNumber(image.path.value))
                    edPluginPluginExecImageQualityIndicator = None
                    if bDoDistlSignalStrength:
                        if self.bUseThinClient:
                            strPluginName = self.strPluginNameThinClient
                        else:
                            strPluginName = self.strPluginName
                        edPluginPluginExecImageQualityIndicator = self.loadPlugin(
                            strPluginName)
                        self.listPluginExecImageQualityIndicator.append(
                            edPluginPluginExecImageQualityIndicator)
                        xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength(
                        )
                        xsDataInputDistlSignalStrength.setReferenceImage(
                            xsDataImageNew)
                        edPluginPluginExecImageQualityIndicator.setDataInput(
                            xsDataInputDistlSignalStrength)
                        edPluginPluginExecImageQualityIndicator.execute()
                    listPluginDistl.append(
                        (xsDataImageNew.copy(),
                         edPluginPluginExecImageQualityIndicator))

                edPluginControlDozor = self.loadPlugin(
                    self.strPluginNameControlDozor, "ControlDozor_{0}".format(
                        os.path.splitext(
                            os.path.basename(strPathToFirstImage))[0]))
                xsDataInputControlDozor = XSDataInputControlDozor()
                for image in listOfImagesInBatch:
                    xsDataInputControlDozor.addImage(XSDataFile(image.path))
                xsDataInputControlDozor.batchSize = XSDataInteger(
                    len(listOfImagesInBatch))
                edPluginControlDozor.dataInput = xsDataInputControlDozor
                edPluginControlDozor.execute()
                listPluginDozor.append(
                    (edPluginControlDozor, list(listOfImagesInBatch)))

        if not self.isFailure():
            listIndexing = []
            # Synchronize all image quality indicator plugins and upload to ISPyB
            xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators(
            )

            for (xsDataImage,
                 edPluginPluginExecImageQualityIndicator) in listPluginDistl:
                xsDataImageQualityIndicators = XSDataImageQualityIndicators()
                xsDataImageQualityIndicators.image = xsDataImage.copy()
                if edPluginPluginExecImageQualityIndicator is not None:
                    edPluginPluginExecImageQualityIndicator.synchronize()
                    if edPluginPluginExecImageQualityIndicator.dataOutput is not None:
                        if edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators is not None:
                            xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\
                                    edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
                self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(
                    xsDataImageQualityIndicators)

            for (edPluginControlDozor, listBatch) in listPluginDozor:
                edPluginControlDozor.synchronize()
                # Check that we got at least one result
                if len(edPluginControlDozor.dataOutput.imageDozor) == 0:
                    # Run the dozor plugin again, this time synchronously
                    firstImage = os.path.basename(listBatch[0].path.value)
                    lastImage = os.path.basename(listBatch[-1].path.value)
                    self.screen(
                        "No dozor results! Re-executing Dozor for images {0} to {1}"
                        .format(firstImage, lastImage))
                    time.sleep(5)
                    edPluginControlDozor = self.loadPlugin(
                        self.strPluginNameControlDozor,
                        "ControlDozor_reexecution_{0}".format(
                            os.path.splitext(firstImage)[0]))
                    xsDataInputControlDozor = XSDataInputControlDozor()
                    for image in listBatch:
                        xsDataInputControlDozor.addImage(XSDataFile(
                            image.path))
                    xsDataInputControlDozor.batchSize = XSDataInteger(
                        batchSize)
                    edPluginControlDozor.dataInput = xsDataInputControlDozor
                    edPluginControlDozor.executeSynchronous()
                for imageDozor in edPluginControlDozor.dataOutput.imageDozor:
                    for xsDataImageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                        if xsDataImageQualityIndicators.image.path.value == imageDozor.image.path.value:
                            xsDataImageQualityIndicators.dozor_score = imageDozor.mainScore
                            xsDataImageQualityIndicators.dozorSpotFile = imageDozor.spotFile
                            if imageDozor.spotFile is not None:
                                if os.path.exists(
                                        imageDozor.spotFile.path.value):
                                    numpyArray = numpy.loadtxt(
                                        imageDozor.spotFile.path.value,
                                        skiprows=3)
                                    xsDataImageQualityIndicators.dozorSpotList = XSDataString(
                                        base64.b64encode(
                                            numpyArray.tostring()))
                                    xsDataImageQualityIndicators.addDozorSpotListShape(
                                        XSDataInteger(numpyArray.shape[0]))
                                    if len(numpyArray.shape) > 1:
                                        xsDataImageQualityIndicators.addDozorSpotListShape(
                                            XSDataInteger(numpyArray.shape[1]))
                            xsDataImageQualityIndicators.dozorSpotsIntAver = imageDozor.spotsIntAver
                            xsDataImageQualityIndicators.dozorSpotsResolution = imageDozor.spotsResolution
                            xsDataImageQualityIndicators.dozorVisibleResolution = imageDozor.visibleResolution
                            if self.xsDataResultControlImageQualityIndicators.inputDozor is None:
                                if edPluginControlDozor.dataOutput.inputDozor is not None:
                                    self.xsDataResultControlImageQualityIndicators.inputDozor = XSDataDozorInput(
                                    ).parseString(
                                        edPluginControlDozor.dataOutput.
                                        inputDozor.marshal())
                if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                    xsDataISPyBImageQualityIndicators = \
                        XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
                    xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(
                        xsDataISPyBImageQualityIndicators)

    #        print xsDataInputStoreListOfImageQualityIndicators.marshal()
            if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
                self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
                self.edPluginISPyB.execute()
            #
            if bDoIndexing:
                # Find the 5 most intensive images (TIS):
                listImage = []
                # Check that we have dozor_score from all images:
                has_dozor_score = True
                for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                    if imageQualityIndicators.dozor_score is None:
                        has_dozor_score = False
                if has_dozor_score:
                    listSorted = sorted(
                        self.xsDataResultControlImageQualityIndicators.
                        imageQualityIndicators,
                        key=lambda imageQualityIndicators:
                        imageQualityIndicators.dozor_score.value)
                else:
                    listSorted = sorted(
                        self.xsDataResultControlImageQualityIndicators.
                        imageQualityIndicators,
                        key=lambda imageQualityIndicators:
                        imageQualityIndicators.totalIntegratedSignal.value)
                for xsDataResultControlImageQualityIndicator in listSorted[
                        -5:]:
                    if xsDataResultControlImageQualityIndicator.dozor_score.value > 1:
                        xsDataInputReadImageHeader = XSDataInputReadImageHeader(
                        )
                        xsDataInputReadImageHeader.image = XSDataFile(
                            xsDataResultControlImageQualityIndicator.image.path
                        )
                        self.edPluginReadImageHeader = self.loadPlugin(
                            self.strPluginReadImageHeaderName)
                        self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                        self.edPluginReadImageHeader.executeSynchronous()
                        xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                        if xsDataResultReadImageHeader is not None:
                            xsDataSubWedge = xsDataResultReadImageHeader.subWedge
                            self.xsDataCollection = XSDataCollection()
                            self.xsDataCollection.addSubWedge(xsDataSubWedge)
                            xsDataIndexingInput = XSDataIndexingInput()
                            xsDataIndexingInput.setDataCollection(
                                self.xsDataCollection)
                            xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(
                                xsDataIndexingInput)
                            edPluginMOSFLMIndexing = self.loadPlugin(
                                self.strIndexingMOSFLMPluginName)
                            self.listPluginMOSFLM.append([
                                edPluginMOSFLMIndexing,
                                xsDataResultControlImageQualityIndicator
                            ])
                            edPluginMOSFLMIndexing.setDataInput(
                                xsDataMOSFLMIndexingInput)
                            edPluginMOSFLMIndexing.execute()
                for tupleMOSFLM in self.listPluginMOSFLM:
                    edPluginMOSFLMIndexing = tupleMOSFLM[0]
                    xsDataResultControlImageQualityIndicator = tupleMOSFLM[1]
                    edPluginMOSFLMIndexing.synchronize()
                    if not edPluginMOSFLMIndexing.isFailure():
                        xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput
                        xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(
                            xsDataMOSFLMOutput)
                        selectedSolution = xsDataIndexingResult.selectedSolution
                        if selectedSolution is not None:
                            xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.preProcess...")

        self.__edPluginIndexing = self.loadPlugin(self.__strPluginIndexingName,
                                                  "Indexing")
        self.__edPluginIntegration = self.loadPlugin(
            self.__strPluginIntegrationName, "Integration")
        self.__edPluginStrategy = self.loadPlugin(self.__strPluginStrategyName,
                                                  "Strategy")

        if (self.__edPluginIndexing is not None):
            EDVerbose.DEBUG(
                "EDPluginControlCharacterisationv1_1.preProcess: " +
                self.__strPluginIndexingName + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputStrategy = self.getDataInput()
            xsDataCollection = xsDataInputStrategy.getDataCollection()
            xsDataSample = xsDataCollection.getSample()
            xsDataSubWedgeList = xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_1.preProcess: No subwedges in input data."
                EDVerbose.ERROR(strError)
                self.setFailure()
            else:
                xsDataExperimentalCondition = xsDataSubWedgeList[
                    0].getExperimentalCondition()

                # Fix for bug 431: if the flux is zero raise an error
                xsDataDoubleFlux = xsDataExperimentalCondition.getBeam(
                ).getFlux()
                if (xsDataDoubleFlux is not None):
                    if (xsDataDoubleFlux.getValue() < 0.1):
                        pyStrErrorMessage = "EDPluginControlCharacterisationv1_1.preProcess ERROR: Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(pyStrErrorMessage)
                        self.addErrorMessage(pyStrErrorMessage)
                        self.setFailure()

                xsDataIndexingInput = XSDataIndexingInput()
                xsDataIndexingInput.setDataCollection(xsDataCollection)
                xsDataIndexingInput.setExperimentalCondition(
                    xsDataExperimentalCondition)

                xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup(
                )
                if (xsDataStringForcedSpaceGroup is not None):
                    xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)
                    xsDataIndexingInput.setCrystal(xsDataCrystal)

                self.__edPluginIndexing.setDataInput(xsDataIndexingInput)

                # Populate characterisation object
                self.__xsDataResultCharacterisation = XSDataResultCharacterisation(
                )
                self.__xsDataResultCharacterisation.setDataCollection(
                    XSDataCollection.parseString(xsDataCollection.marshal()))
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_4.process")
        EDUtilsParallel.initializeNbThread()
        # Check batch size
        if self.dataInput.batchSize is None:
            batchSize = 1
        else:
            batchSize = self.dataInput.batchSize.value
        self.screen("Batch size: {0}".format(batchSize))
        # Check if we should do distlSignalStrength:
        bDoDistlSignalStrength = True
        if self.dataInput.doDistlSignalStrength is not None:
            if not self.dataInput.doDistlSignalStrength.value:
                bDoDistlSignalStrength = False
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                 bDoIndexing = True
        # Loop through all the incoming reference images
        listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators()
        listPluginDistl = []
        listPluginDozor = []
        listBatch = []
        indexBatch = 0
        listH5FilePath = []
        ispybDataCollection = None
        for xsDataImage in listXSDataImage:
            strPathToImage = xsDataImage.path.value
            # If Eiger, just wait for the h5 file
            if "id30a3" in strPathToImage:
                h5MasterFilePath, h5DataFilePath, hdf5ImageNumber = self.getH5FilePath(strPathToImage, batchSize)
#                print(h5FilePath)
#                print(hdf5ImageNumber)
                if not h5DataFilePath in listH5FilePath:
                    self.screen("ID30a3 Eiger data, waiting for master and data files...")
                    listH5FilePath.append(h5DataFilePath)
                    self.edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                    xsDataInputMXWaitFile.file = XSDataFile(XSDataString(h5DataFilePath))
                    xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                    xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                    self.screen("Waiting for file {0}".format(h5DataFilePath))
                    self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
                    self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                    self.edPluginMXWaitFile.executeSynchronous()
#                    hdf5FilePath = strPathToImage.replace(".cbf", ".h5")
                    ispybDataCollection = None
                    time.sleep(1)
                indexLoop = 1
                continueLoop = True
                while continueLoop:
                    xsDataInputControlH5ToCBF = XSDataInputControlH5ToCBF()
                    xsDataInputControlH5ToCBF.hdf5File = XSDataFile(XSDataString(strPathToImage))
                    imageNumber = EDUtilsImage.getImageNumber(strPathToImage)
                    xsDataInputControlH5ToCBF.imageNumber = XSDataInteger(imageNumber)
                    xsDataInputControlH5ToCBF.hdf5ImageNumber = XSDataInteger(hdf5ImageNumber)
                    xsDataInputControlH5ToCBF.ispybDataCollection = ispybDataCollection
                    edPluginControlH5ToCBF = self.loadPlugin(self.strPluginControlH5ToCBF, "ControlH5ToCBF_%04d_%02d" % (imageNumber, indexLoop))
                    edPluginControlH5ToCBF.dataInput = xsDataInputControlH5ToCBF
                    edPluginControlH5ToCBF.executeSynchronous()
                    cbfFile = edPluginControlH5ToCBF.dataOutput.outputCBFFile
#                    print(cbfFile)
#                    print(indexLoop)
                    if cbfFile is not None:
                        strPathToImage = cbfFile.path.value
#                        print(cbfFile.path.value)
                        if os.path.exists(strPathToImage):
                            self.screen("Image has been converted to CBF file: {0}".format(strPathToImage))
                            continueLoop = False
#                    print(continueLoop)
                    if continueLoop:
                        self.screen("Still waiting for converting to CBF file: {0}".format(strPathToImage))
                        indexLoop += 1
                        time.sleep(5)
                        if indexLoop > 10:
                            continueLoop = False

                ispybDataCollection = edPluginControlH5ToCBF.dataOutput.ispybDataCollection


            elif not os.path.exists(strPathToImage):
                self.screen("Waiting for file {0}".format(strPathToImage))
                self.edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                xsDataInputMXWaitFile.file = XSDataFile(XSDataString(strPathToImage))
                xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
                self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                self.edPluginMXWaitFile.executeSynchronous()
            if not os.path.exists(strPathToImage):
                strError = "Time-out while waiting for image %s" % strPathToImage
                self.error(strError)
                self.addErrorMessage(strError)
                self.setFailure()
            else:
                # Check if we should run distl.signalStrength
                xsDataImageNew = XSDataImage(XSDataString(strPathToImage))
                edPluginPluginExecImageQualityIndicator = None
                if bDoDistlSignalStrength:
                    if self.bUseThinClient:
                        strPluginName = self.strPluginNameThinClient
                    else:
                        strPluginName = self.strPluginName
                    edPluginPluginExecImageQualityIndicator = self.loadPlugin(strPluginName)
                    self.listPluginExecImageQualityIndicator.append(edPluginPluginExecImageQualityIndicator)
                    xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength()
                    xsDataInputDistlSignalStrength.setReferenceImage(xsDataImageNew)
                    edPluginPluginExecImageQualityIndicator.setDataInput(xsDataInputDistlSignalStrength)
                    edPluginPluginExecImageQualityIndicator.execute()
                listPluginDistl.append((xsDataImageNew.copy(), edPluginPluginExecImageQualityIndicator))
                listBatch.append(xsDataImageNew.copy())
                if len(listBatch) == batchSize:
                    edPluginControlDozor = self.loadPlugin(self.strPluginNameControlDozor)
                    xsDataInputControlDozor = XSDataInputControlDozor()
                    for image in listBatch:
                        xsDataInputControlDozor.addImage(XSDataFile(image.path))
                    xsDataInputControlDozor.batchSize = XSDataInteger(batchSize)
                    edPluginControlDozor.dataInput = xsDataInputControlDozor
                    edPluginControlDozor.execute()
                    listPluginDozor.append((edPluginControlDozor, listBatch))
                    listBatch = []
        if len(listBatch) > 0:
            # Process the remaining images...
            edPluginControlDozor = self.loadPlugin(self.strPluginNameControlDozor)
            xsDataInputControlDozor = XSDataInputControlDozor()
            for image in listBatch:
                xsDataInputControlDozor.addImage(XSDataFile(image.path))
            xsDataInputControlDozor.batchSize = XSDataInteger(batchSize)
            edPluginControlDozor.dataInput = xsDataInputControlDozor
            edPluginControlDozor.execute()
            listPluginDozor.append([edPluginControlDozor, listBatch])
        listIndexing = []
        # Synchronize all image quality indicator plugins and upload to ISPyB
        xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators()

        for (xsDataImage, edPluginPluginExecImageQualityIndicator) in listPluginDistl:
            xsDataImageQualityIndicators = XSDataImageQualityIndicators()
            xsDataImageQualityIndicators.image = xsDataImage.copy()
            if edPluginPluginExecImageQualityIndicator is not None:
                edPluginPluginExecImageQualityIndicator.synchronize()
                if edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators is not None:
                    xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\
                            edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
            self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(xsDataImageQualityIndicators)

        for (edPluginControlDozor, listBatch) in listPluginDozor:
            edPluginControlDozor.synchronize()
            for imageDozor in edPluginControlDozor.dataOutput.imageDozor:
                for xsDataImageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                    if xsDataImageQualityIndicators.image.path.value == imageDozor.image.path.value:
                        xsDataImageQualityIndicators.dozor_score = imageDozor.mainScore
                        xsDataImageQualityIndicators.dozorSpotFile = imageDozor.spotFile
                        if imageDozor.spotFile is not None:
                            if os.path.exists(imageDozor.spotFile.path.value):
                                numpyArray = numpy.loadtxt(imageDozor.spotFile.path.value, skiprows=3)
                                xsDataImageQualityIndicators.dozorSpotList = XSDataString(base64.b64encode(numpyArray.tostring()))
                                xsDataImageQualityIndicators.addDozorSpotListShape(XSDataInteger(numpyArray.shape[0]))
                                if len(numpyArray.shape) > 1:
                                    xsDataImageQualityIndicators.addDozorSpotListShape(XSDataInteger(numpyArray.shape[1]))
                        xsDataImageQualityIndicators.dozorSpotsIntAver = imageDozor.spotsIntAver
                        xsDataImageQualityIndicators.dozorSpotsResolution = imageDozor.spotsResolution
                        if self.xsDataResultControlImageQualityIndicators.inputDozor is None:
                            if edPluginControlDozor.dataOutput.inputDozor is not None:
                                self.xsDataResultControlImageQualityIndicators.inputDozor = XSDataDozorInput().parseString(
                                               edPluginControlDozor.dataOutput.inputDozor.marshal())
            if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                xsDataISPyBImageQualityIndicators = \
                    XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
                xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(xsDataISPyBImageQualityIndicators)
#        print xsDataInputStoreListOfImageQualityIndicators.marshal()
        if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
            self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
            self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
            self.edPluginISPyB.execute()
        #
        if bDoIndexing:
            # Find the 5 most intensive images (TIS):
            listImage = []
            # Check that we have dozor_score from all images:
            has_dozor_score = True
            for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                if imageQualityIndicators.dozor_score is None:
                    has_dozor_score = False
            if has_dozor_score:
                listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators,
                                    key=lambda imageQualityIndicators: imageQualityIndicators.dozor_score.value)
            else:
                listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators,
                                    key=lambda imageQualityIndicators: imageQualityIndicators.totalIntegratedSignal.value)
            for xsDataResultControlImageQualityIndicator in listSorted[-5:]:
                if xsDataResultControlImageQualityIndicator.goodBraggCandidates.value > 30:
                    xsDataInputReadImageHeader = XSDataInputReadImageHeader()
                    xsDataInputReadImageHeader.image = XSDataFile(xsDataResultControlImageQualityIndicator.image.path)
                    self.edPluginReadImageHeader = self.loadPlugin(self.strPluginReadImageHeaderName)
                    self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                    self.edPluginReadImageHeader.executeSynchronous()
                    xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                    if xsDataResultReadImageHeader is not None:
                        xsDataSubWedge = xsDataResultReadImageHeader.subWedge
                        self.xsDataCollection = XSDataCollection()
                        self.xsDataCollection.addSubWedge(xsDataSubWedge)
                        xsDataIndexingInput = XSDataIndexingInput()
                        xsDataIndexingInput.setDataCollection(self.xsDataCollection)
                        xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
                        edPluginMOSFLMIndexing = self.loadPlugin(self.strIndexingMOSFLMPluginName)
                        self.listPluginMOSFLM.append([edPluginMOSFLMIndexing, xsDataResultControlImageQualityIndicator])
                        edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
                        edPluginMOSFLMIndexing.execute()
            for tupleMOSFLM in self.listPluginMOSFLM:
                edPluginMOSFLMIndexing = tupleMOSFLM[0]
                xsDataResultControlImageQualityIndicator = tupleMOSFLM[1]
                edPluginMOSFLMIndexing.synchronize()
                if not edPluginMOSFLMIndexing.isFailure():
                    xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput
                    xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(xsDataMOSFLMOutput)
                    selectedSolution = xsDataIndexingResult.selectedSolution
                    if selectedSolution is not None:
                        xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution
Exemple #34
0
 def doSuccessEvaluationIndexingLABELIT(self, _edPlugin=None):
     self.DEBUG(
         "EDPluginControlCharacterisationv1_4.doSuccessEvaluationIndexingLABELIT"
     )
     self.retrieveSuccessMessages(
         _edPlugin,
         "EDPluginControlCharacterisationv1_4.doSuccessEvaluationIndexingLABELIT"
     )
     # Retrieve status messages (if any)
     if self._edPluginExecEvaluationIndexingLABELIT.hasDataOutput(
             "statusMessageIndexing"):
         self.addStatusMessage(
             "Labelit: " +
             self._edPluginExecEvaluationIndexingLABELIT.getDataOutput(
                 "statusMessageIndexing")[0].getValue())
     # Check if indexing was successful
     bIndexingSuccess = self._edPluginExecEvaluationIndexingLABELIT.getDataOutput(
         "indexingSuccess")[0].getValue()
     if bIndexingSuccess:
         xsDataIndexingResult = self._edPluginExecEvaluationIndexingLABELIT.getDataOutput(
             "indexingResult")[0]
         self._xsDataResultCharacterisation.setIndexingResult(
             xsDataIndexingResult)
         xsDataCollection = self._xsDataResultCharacterisation.getDataCollection(
         )
         xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
         xsDataGeneratePredictionInput.setDataCollection(
             XSDataCollection.parseString(xsDataCollection.marshal()))
         xsDataGeneratePredictionInput.setSelectedIndexingSolution(
             XSDataIndexingSolutionSelected.parseString(
                 xsDataIndexingResult.getSelectedSolution().marshal()))
         self._edPluginControlGeneratePrediction.setDataInput(
             xsDataGeneratePredictionInput)
         if self._edPluginControlIndexingIndicators.hasDataOutput(
                 "indexingShortSummary"):
             indexingShortSummary = self._edPluginControlIndexingIndicators.getDataOutput(
                 "indexingShortSummary")[0].getValue()
             self._strCharacterisationShortSummary += indexingShortSummary
             self.sendMessageToMXCuBE(indexingShortSummary)
         # Start the generation of prediction images - we synchronize in the post-process
         self._edPluginControlGeneratePrediction.execute()
         # Then start the integration of the reference images
         self.indexingToIntegration()
     else:
         if self._iNoImagesWithDozorScore > 0:
             if not self._bDoOnlyMoslmfIndexing:
                 strWarningMessage = "Execution of Indexing and Indicators plugin failed - trying to index with MOSFLM."
                 self.WARNING(strWarningMessage)
                 self.sendMessageToMXCuBE(strWarningMessage, "warning")
                 self.addWarningMessage(strWarningMessage)
             xsDataIndexingInput = XSDataIndexingInput()
             xsDataIndexingInput.dataCollection = self._xsDataCollection
             xsDataIndexingInput.experimentalCondition = self._xsDataCollection.subWedge[
                 0].experimentalCondition
             xsDataIndexingInput.crystal = self._xsDataCrystal
             self._edPluginControlIndexingMOSFLM.setDataInput(
                 xsDataIndexingInput)
             self.executePluginSynchronous(
                 self._edPluginControlIndexingMOSFLM)
         else:
             strErrorMessage = "Execution of indexing with Labelit failed."
             self.ERROR(strErrorMessage)
             self.sendMessageToMXCuBE(strErrorMessage, "error")
             self.addErrorMessage(strErrorMessage)
             self.setFailure()
             self.generateExecutiveSummary(self)
             if self._strStatusMessage != None:
                 self.setDataOutput(XSDataString(self._strStatusMessage),
                                    "statusMessage")
                 self.writeDataOutput()
    def process(self, _edPlugin=None):
        """
        Executes the execution plugins
        """
        EDPluginControl.process(self, _edPlugin)
        self.DEBUG("EDPluginControlImageQualityIndicatorsv1_4.process")
        EDUtilsParallel.initializeNbThread()
        # Check batch size
        if self.dataInput.batchSize is None:
            batchSize = 1
        else:
            batchSize = self.dataInput.batchSize.value
        self.screen("Image quality indicators batch size: {0}".format(batchSize))
        # Check if we should do distlSignalStrength:
        bDoDistlSignalStrength = True
        if self.dataInput.doDistlSignalStrength is not None:
            if not self.dataInput.doDistlSignalStrength.value:
                bDoDistlSignalStrength = False
        # Check if we should do indexing:
        bDoIndexing = False
        if self.dataInput.doIndexing is not None:
            if self.dataInput.doIndexing.value:
                 bDoIndexing = True
        # Check if fast mesh (for HDF5)
        isFastMesh = False
        if self.dataInput.fastMesh:
            isFastMesh = self.dataInput.fastMesh.value
        # Loop through all the incoming reference images
        if len(self.dataInput.image) == 0:
            directory = self.dataInput.directory.path.value
            template = self.dataInput.template.value
            startNo = self.dataInput.startNo.value
            endNo = self.dataInput.endNo.value
            listXSDataImage = []
            for index in range(startNo, endNo + 1):
                imageName = template.replace("####", "{0:04d}".format(index))
                imagePath = os.path.join(directory, imageName)
                xsDataImage = XSDataImage(path=XSDataString(imagePath), number=XSDataInteger(index))
                listXSDataImage.append(xsDataImage)
        else:
            listXSDataImage = self.dataInput.image
        xsDataInputMXWaitFile = XSDataInputMXWaitFile()
        self.xsDataResultControlImageQualityIndicators = XSDataResultControlImageQualityIndicators()
        listPluginDistl = []
        listPluginDozor = []
        listOfImagesInBatch = []
        listOfAllBatches = []
        indexBatch = 0
        listH5FilePath = []
        # Process data in batches
        for xsDataImage in listXSDataImage:
            listOfImagesInBatch.append(xsDataImage.copy())
            if len(listOfImagesInBatch) == batchSize:
                listOfAllBatches.append(listOfImagesInBatch)
                listOfImagesInBatch = []
        if len(listOfImagesInBatch) > 0:
            listOfAllBatches.append(listOfImagesInBatch)
            listOfImagesInBatch = []
        # Loop over batches
        for listOfImagesInBatch in listOfAllBatches:
            # First wait for images
            for image in listOfImagesInBatch:
                strPathToImage = image.path.value
                # If Eiger, just wait for the h5 file
                if strPathToImage.endswith(".h5"):
                    h5MasterFilePath, h5DataFilePath, hdf5ImageNumber = self.getH5FilePath(strPathToImage,
                                                                                           batchSize=batchSize,
                                                                                           isFastMesh=isFastMesh)
    #                print(h5FilePath)
    #                print(hdf5ImageNumber)
                    if not h5DataFilePath in listH5FilePath:
                        self.screen("ID30a3 Eiger data, waiting for master and data files...")
                        listH5FilePath.append(h5DataFilePath)
                        self.edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                        xsDataInputMXWaitFile.file = XSDataFile(XSDataString(h5DataFilePath))
                        xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                        xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                        self.screen("Waiting for file {0}".format(h5DataFilePath))
                        self.DEBUG("Wait file timeOut set to %f" % self.fMXWaitFileTimeOut)
                        self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                        self.edPluginMXWaitFile.executeSynchronous()
    #                    hdf5FilePath = strPathToImage.replace(".cbf", ".h5")
                        time.sleep(1)
                    if not os.path.exists(h5DataFilePath):
                        strError = "Time-out while waiting for image %s" % h5DataFilePath
                        self.error(strError)
                        self.addErrorMessage(strError)
                        self.setFailure()
                else:
                    if not os.path.exists(strPathToImage):
                        # self.screen("Waiting for file {0}".format(strPathToImage))
                        self.edPluginMXWaitFile = self.loadPlugin(self.strPluginMXWaitFileName)
                        xsDataInputMXWaitFile.file = XSDataFile(XSDataString(strPathToImage))
                        xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize))
                        xsDataInputMXWaitFile.setTimeOut(XSDataTime(self.fMXWaitFileTimeOut))
                        self.screen("Wait file timeOut set to %.0f s" % self.fMXWaitFileTimeOut)
                        self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile)
                        self.edPluginMXWaitFile.executeSynchronous()
                    if not os.path.exists(strPathToImage):
                        strError = "Time-out while waiting for image %s" % strPathToImage
                        self.error(strError)
                        self.addErrorMessage(strError)
                        self.setFailure()
            if not self.isFailure():
                strPathToFirstImage = listOfImagesInBatch[0].path.value
                if strPathToImage.endswith(".h5"):
                    indexLoop = 1
                    continueLoop = True
                    while continueLoop:
                        directory = os.path.dirname(strPathToFirstImage)
                        firstImage = EDUtilsImage.getImageNumber(listOfImagesInBatch[0].path.value)
                        lastImage = EDUtilsImage.getImageNumber(listOfImagesInBatch[-1].path.value)
                        xsDataInputH5ToCBF = XSDataInputH5ToCBF()
                        xsDataInputH5ToCBF.hdf5File = XSDataFile(listOfImagesInBatch[0].path)
                        xsDataInputH5ToCBF.hdf5ImageNumber = XSDataInteger(1)
                        xsDataInputH5ToCBF.startImageNumber = XSDataInteger(firstImage)
                        xsDataInputH5ToCBF.endImageNumber = XSDataInteger(lastImage)
                        xsDataInputH5ToCBF.forcedOutputDirectory = XSDataFile(XSDataString(directory))
                        edPluginH5ToCBF = self.loadPlugin("EDPluginH5ToCBFv1_1")
                        edPluginH5ToCBF.dataInput = xsDataInputH5ToCBF
                        edPluginH5ToCBF.execute()
                        edPluginH5ToCBF.synchronize()
                        outputCBFFileTemplate = edPluginH5ToCBF.dataOutput.outputCBFFileTemplate
                        if outputCBFFileTemplate is not None:
                            lastCbfFile = outputCBFFileTemplate.path.value.replace("######", "{0:06d}".format(EDUtilsImage.getImageNumber(listOfImagesInBatch[-1].path.value)))
                            strPathToImage = os.path.join(directory, lastCbfFile)
    #                        print(cbfFile.path.value)
                            if os.path.exists(strPathToImage):
                                # Rename all images
                                for image in listOfImagesInBatch:
                                    image.path.value = image.path.value.replace(".h5", ".cbf")
                                    imageNumber = EDUtilsImage.getImageNumber(image.path.value)
                                    oldPath = os.path.join(directory, outputCBFFileTemplate.path.value.replace("######", "{0:06d}".format(imageNumber)))
                                    newPath = os.path.join(directory, outputCBFFileTemplate.path.value.replace("######", "{0:04d}".format(imageNumber)))
                                    os.rename(oldPath, newPath)
                                lastCbfFile = outputCBFFileTemplate.path.value.replace("######", "{0:04d}".format(EDUtilsImage.getImageNumber(listOfImagesInBatch[-1].path.value)))
                                strPathToImage = os.path.join(directory, lastCbfFile)
                                self.screen("Image has been converted to CBF file: {0}".format(strPathToImage))
                                continueLoop = False
    #                    print(continueLoop)
                        if continueLoop:
                            self.screen("Still waiting for converting to CBF file: {0}".format(strPathToImage))
                            indexLoop += 1
                            time.sleep(5)
                            if indexLoop > 10:
                                continueLoop = False

                for image in listOfImagesInBatch:
                    strPathToImage = image.path.value
                    # Check if we should run distl.signalStrength
                    xsDataImageNew = XSDataImage(XSDataString(strPathToImage))
                    xsDataImageNew.number = XSDataInteger(EDUtilsImage.getImageNumber(image.path.value))
                    edPluginPluginExecImageQualityIndicator = None
                    if bDoDistlSignalStrength:
                        if self.bUseThinClient:
                            strPluginName = self.strPluginNameThinClient
                        else:
                            strPluginName = self.strPluginName
                        edPluginPluginExecImageQualityIndicator = self.loadPlugin(strPluginName)
                        self.listPluginExecImageQualityIndicator.append(edPluginPluginExecImageQualityIndicator)
                        xsDataInputDistlSignalStrength = XSDataInputDistlSignalStrength()
                        xsDataInputDistlSignalStrength.setReferenceImage(xsDataImageNew)
                        edPluginPluginExecImageQualityIndicator.setDataInput(xsDataInputDistlSignalStrength)
                        edPluginPluginExecImageQualityIndicator.execute()
                    listPluginDistl.append((xsDataImageNew.copy(), edPluginPluginExecImageQualityIndicator))

                edPluginControlDozor = self.loadPlugin(self.strPluginNameControlDozor,
                                                       "ControlDozor_{0}".format(os.path.splitext(os.path.basename(strPathToFirstImage))[0]))
                xsDataInputControlDozor = XSDataInputControlDozor()
                for image in listOfImagesInBatch:
                    xsDataInputControlDozor.addImage(XSDataFile(image.path))
                xsDataInputControlDozor.batchSize = XSDataInteger(len(listOfImagesInBatch))
                edPluginControlDozor.dataInput = xsDataInputControlDozor
                edPluginControlDozor.execute()
                listPluginDozor.append((edPluginControlDozor, list(listOfImagesInBatch)))

        if not self.isFailure():
            listIndexing = []
            # Synchronize all image quality indicator plugins and upload to ISPyB
            xsDataInputStoreListOfImageQualityIndicators = XSDataInputStoreListOfImageQualityIndicators()

            for (xsDataImage, edPluginPluginExecImageQualityIndicator) in listPluginDistl:
                xsDataImageQualityIndicators = XSDataImageQualityIndicators()
                xsDataImageQualityIndicators.image = xsDataImage.copy()
                if edPluginPluginExecImageQualityIndicator is not None:
                    edPluginPluginExecImageQualityIndicator.synchronize()
                    if edPluginPluginExecImageQualityIndicator.dataOutput is not None:
                        if edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators is not None:
                            xsDataImageQualityIndicators = XSDataImageQualityIndicators.parseString(\
                                    edPluginPluginExecImageQualityIndicator.dataOutput.imageQualityIndicators.marshal())
                self.xsDataResultControlImageQualityIndicators.addImageQualityIndicators(xsDataImageQualityIndicators)

            for (edPluginControlDozor, listBatch) in listPluginDozor:
                edPluginControlDozor.synchronize()
                # Check that we got at least one result
                if len(edPluginControlDozor.dataOutput.imageDozor) == 0:
                    # Run the dozor plugin again, this time synchronously
                    firstImage = os.path.basename(listBatch[0].path.value)
                    lastImage = os.path.basename(listBatch[-1].path.value)
                    self.screen("No dozor results! Re-executing Dozor for images {0} to {1}".format(firstImage, lastImage))
                    time.sleep(5)
                    edPluginControlDozor = self.loadPlugin(self.strPluginNameControlDozor, "ControlDozor_reexecution_{0}".format(os.path.splitext(firstImage)[0]))
                    xsDataInputControlDozor = XSDataInputControlDozor()
                    for image in listBatch:
                        xsDataInputControlDozor.addImage(XSDataFile(image.path))
                    xsDataInputControlDozor.batchSize = XSDataInteger(batchSize)
                    edPluginControlDozor.dataInput = xsDataInputControlDozor
                    edPluginControlDozor.executeSynchronous()
                for imageDozor in edPluginControlDozor.dataOutput.imageDozor:
                    for xsDataImageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                        if xsDataImageQualityIndicators.image.path.value == imageDozor.image.path.value:
                            xsDataImageQualityIndicators.dozor_score = imageDozor.mainScore
                            xsDataImageQualityIndicators.dozorSpotFile = imageDozor.spotFile
                            if imageDozor.spotFile is not None:
                                if os.path.exists(imageDozor.spotFile.path.value):
                                    numpyArray = numpy.loadtxt(imageDozor.spotFile.path.value, skiprows=3)
                                    xsDataImageQualityIndicators.dozorSpotList = XSDataString(base64.b64encode(numpyArray.tostring()))
                                    xsDataImageQualityIndicators.addDozorSpotListShape(XSDataInteger(numpyArray.shape[0]))
                                    if len(numpyArray.shape) > 1:
                                        xsDataImageQualityIndicators.addDozorSpotListShape(XSDataInteger(numpyArray.shape[1]))
                            xsDataImageQualityIndicators.dozorSpotsIntAver = imageDozor.spotsIntAver
                            xsDataImageQualityIndicators.dozorSpotsResolution = imageDozor.spotsResolution
                            xsDataImageQualityIndicators.dozorVisibleResolution = imageDozor.visibleResolution
                            if self.xsDataResultControlImageQualityIndicators.inputDozor is None:
                                if edPluginControlDozor.dataOutput.inputDozor is not None:
                                    self.xsDataResultControlImageQualityIndicators.inputDozor = XSDataDozorInput().parseString(
                                                   edPluginControlDozor.dataOutput.inputDozor.marshal())
                if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                    xsDataISPyBImageQualityIndicators = \
                        XSDataISPyBImageQualityIndicators.parseString(xsDataImageQualityIndicators.marshal())
                    xsDataInputStoreListOfImageQualityIndicators.addImageQualityIndicators(xsDataISPyBImageQualityIndicators)
    #        print xsDataInputStoreListOfImageQualityIndicators.marshal()
            if self.dataInput.doUploadToIspyb is not None and self.dataInput.doUploadToIspyb.value:
                self.edPluginISPyB = self.loadPlugin(self.strISPyBPluginName)
                self.edPluginISPyB.dataInput = xsDataInputStoreListOfImageQualityIndicators
                self.edPluginISPyB.execute()
            #
            if bDoIndexing:
                # Find the 5 most intensive images (TIS):
                listImage = []
                # Check that we have dozor_score from all images:
                has_dozor_score = True
                for imageQualityIndicators in self.xsDataResultControlImageQualityIndicators.imageQualityIndicators:
                    if imageQualityIndicators.dozor_score is None:
                        has_dozor_score = False
                if has_dozor_score:
                    listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators,
                                        key=lambda imageQualityIndicators: imageQualityIndicators.dozor_score.value)
                else:
                    listSorted = sorted(self.xsDataResultControlImageQualityIndicators.imageQualityIndicators,
                                        key=lambda imageQualityIndicators: imageQualityIndicators.totalIntegratedSignal.value)
                for xsDataResultControlImageQualityIndicator in listSorted[-5:]:
                    if xsDataResultControlImageQualityIndicator.dozor_score.value > 1:
                        xsDataInputReadImageHeader = XSDataInputReadImageHeader()
                        xsDataInputReadImageHeader.image = XSDataFile(xsDataResultControlImageQualityIndicator.image.path)
                        self.edPluginReadImageHeader = self.loadPlugin(self.strPluginReadImageHeaderName)
                        self.edPluginReadImageHeader.dataInput = xsDataInputReadImageHeader
                        self.edPluginReadImageHeader.executeSynchronous()
                        xsDataResultReadImageHeader = self.edPluginReadImageHeader.dataOutput
                        if xsDataResultReadImageHeader is not None:
                            xsDataSubWedge = xsDataResultReadImageHeader.subWedge
                            self.xsDataCollection = XSDataCollection()
                            self.xsDataCollection.addSubWedge(xsDataSubWedge)
                            xsDataIndexingInput = XSDataIndexingInput()
                            xsDataIndexingInput.setDataCollection(self.xsDataCollection)
                            xsDataMOSFLMIndexingInput = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing(xsDataIndexingInput)
                            edPluginMOSFLMIndexing = self.loadPlugin(self.strIndexingMOSFLMPluginName)
                            self.listPluginMOSFLM.append([edPluginMOSFLMIndexing, xsDataResultControlImageQualityIndicator])
                            edPluginMOSFLMIndexing.setDataInput(xsDataMOSFLMIndexingInput)
                            edPluginMOSFLMIndexing.execute()
                for tupleMOSFLM in self.listPluginMOSFLM:
                    edPluginMOSFLMIndexing = tupleMOSFLM[0]
                    xsDataResultControlImageQualityIndicator = tupleMOSFLM[1]
                    edPluginMOSFLMIndexing.synchronize()
                    if not edPluginMOSFLMIndexing.isFailure():
                        xsDataMOSFLMOutput = edPluginMOSFLMIndexing.dataOutput
                        xsDataIndexingResult = EDHandlerXSDataMOSFLMv10.generateXSDataIndexingResult(xsDataMOSFLMOutput)
                        selectedSolution = xsDataIndexingResult.selectedSolution
                        if selectedSolution is not None:
                            xsDataResultControlImageQualityIndicator.selectedIndexingSolution = selectedSolution