def buildChildren(self, child_, nodeName_):
		if child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'characterisationResult':
			obj_ = XSDataResultCharacterisation()
			obj_.build(child_)
			self.setCharacterisationResult(obj_)
		XSDataInput.buildChildren(self, child_, nodeName_)
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_2.preProcess")
        # Load the plugins
        self.__edPluginControlIndexingIndicators = self.loadPlugin(self.__strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self.__edPluginControlIndexingLabelit = self.loadPlugin(self.__strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self.__edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self.__strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self.__edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self.__strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self.__edPluginControlGeneratePrediction = self.loadPlugin(self.__strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self.__edPluginControlIntegration = self.loadPlugin(self.__strPluginControlIntegration, \
                                                            "Integration")
        self.__edPluginControlStrategy = self.loadPlugin(self.__strPluginControlStrategy, \
                                                         "Strategy")
        if (self.__edPluginControlIndexingIndicators is not None):
            self.DEBUG("EDPluginControlCharacterisationv1_2.preProcess: " + self.__strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self.__xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            xsDataCrystal = None
            xsDataSubWedgeList = self.__xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_2.preProcess: No subwedges in input data."
                self.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        self.ERROR(strErrorMessage)
                        self.addErrorMessage("EDPluginControlCharacterisationv1_2.preProcess ERROR: " + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self.__xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self.__xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self.__xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self.__edPluginControlIndexingIndicators.setDataInput(self.__xsDataCollection, "dataCollection")
                if self.__xsDataCrystal is not None:
                    self.__edPluginControlIndexingIndicators.setDataInput(self.__xsDataCrystal, "crystal")

                # Populate characterisation object
                self.__xsDataResultCharacterisation = XSDataResultCharacterisation()
                self.__xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self.__xsDataCollection.marshal()))
示例#3
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 preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.preProcess")
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginControlIndexingLabelit = self.loadPlugin(self._strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if (self._edPluginControlIndexingIndicators is not None):
            EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.preProcess: " + self._strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_3.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage("EDPluginControlCharacterisationv1_3.preProcess ERROR: " + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation = XSDataResultCharacterisation()
                self._xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self._xsDataCollection.marshal()))
 def testCheckParameters(self):
     xsDataInputControlISPyB = XSDataInputControlISPyB()
     xsDataResultCharacterisation = XSDataResultCharacterisation()
     xsDataInputControlISPyB.setCharacterisationResult(
         xsDataResultCharacterisation)
     edPluginControlISPyB = self.createPlugin()
     edPluginControlISPyB.setDataInput(xsDataInputControlISPyB)
     edPluginControlISPyB.checkParameters()
示例#6
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'characterisationResult':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setCharacterisationResult(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'characterisationResultv2_0':
         obj_ = XSDataResultCharacterisationv2_0()
         obj_.build(child_)
         self.setCharacterisationResultv2_0(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'fileGraph':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.fileGraph.append(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
    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()))
示例#8
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'resultCharacterisation':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setResultCharacterisation(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'resultControlISPyB':
         obj_ = XSDataResultControlISPyB()
         obj_.build(child_)
         self.setResultControlISPyB(obj_)
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'characterisationResult':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setCharacterisationResult(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'characterisationResultv2_0':
         obj_ = XSDataResultCharacterisationv2_0()
         obj_.build(child_)
         self.setCharacterisationResultv2_0(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'fileGraph':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.fileGraph.append(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
示例#10
0
	def buildChildren(self, child_, nodeName_):
		if child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'resultCharacterisation':
			obj_ = XSDataResultCharacterisation()
			obj_.build(child_)
			self.setResultCharacterisation(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'resultControlISPyB':
			obj_ = XSDataResultControlISPyB()
			obj_.build(child_)
			self.setResultControlISPyB(obj_)
    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())
            )
示例#12
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv1InputCharacterisation':
         obj_ = XSDataInputCharacterisation()
         obj_.build(child_)
         self.setMxv1InputCharacterisation(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv1ResultCharacterisation_Reference':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setMxv1ResultCharacterisation_Reference(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv2DataCollection':
         obj_ = XSDataCollection()
         obj_.build(child_)
         self.setMxv2DataCollection(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv2DataCollection_Reference':
         obj_ = XSDataCollection()
         obj_.build(child_)
         self.setMxv2DataCollection_Reference(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'possibleOrientations':
         obj_ = kappa_alignment_response()
         obj_.build(child_)
         self.setPossibleOrientations(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'omega':
         obj_ = XSDataAngle()
         obj_.build(child_)
         self.setOmega(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'kappa':
         obj_ = XSDataAngle()
         obj_.build(child_)
         self.setKappa(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'phi':
         obj_ = XSDataAngle()
         obj_.build(child_)
         self.setPhi(obj_)
     XSDataInputInterface.buildChildren(self, child_, nodeName_)
class EDPluginControlCharacterisationv1_1(EDPluginControl):
    """
    The Plugin that controls the whole characterisation.
    """
    def __init__(self):
        """
        """
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self.__strPluginIndexingName = "EDPluginControlIndexingv10"
        self.__edPluginIndexing = None
        self.__strPluginIntegrationName = "EDPluginControlIntegrationv10"
        self.__edPluginIntegration = None
        self.__strPluginStrategyName = "EDPluginControlStrategyv1_1"
        self.__edPluginStrategy = None
        self.__xsDataResultCharacterisation = None
        self.__strPluginKappaStrategyName = "EDPluginControlKappaStrategyv1_1"
        self.__strPluginIntegrationPointlessName = "EDPluginControlIntegrationPointlessv10"

    def checkParameters(self):
        """
        Checks the mandatory parameters
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(),
                                      "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(),
                                      "dataCollection")
        self.checkMandatoryParameters(
            self.getDataInput().getDataCollection().getDiffractionPlan(),
            "diffractionPlan")

    def configure(self):
        """
        Gets the configuration parameters (if any).
        """
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.configure")
        pluginConfiguration = self.getConfiguration()

        if (pluginConfiguration is None):
            EDVerbose.DEBUG(
                "No plugin configuration found for EDPluginControlCharacterisationv1_1."
            )
        else:
            if (self.getControlledPluginName("indexingPlugin") is not None):
                self.__strPluginIndexingName = self.getControlledPluginName(
                    "indexingPlugin")
            if (self.getControlledPluginName("integrationPlugin") is not None):
                self.__strPluginIntegrationName = self.getControlledPluginName(
                    "integrationPlugin")
            if (self.getControlledPluginName("strategyPlugin") is not None):
                self.__strPluginStrategyName = self.getControlledPluginName(
                    "strategyPlugin")
            if (self.getControlledPluginName("kappaStrategyPlugin")
                    is not None):
                self.__strPluginKappaStrategyName = self.getControlledPluginName(
                    "kappaStrategyPlugin")
            if (self.getControlledPluginName("integrationPointlessPlugin")
                    is not None):
                self.__strPluginIntegrationPoitlessName = self.getControlledPluginName(
                    "integrationPointlessPlugin")

            pyStrKappa = EDConfiguration.getStringParamValue(
                pluginConfiguration, "KAPPA")
            if (pyStrKappa == "ON"):
                self.__strPluginStrategyName = self.__strPluginKappaStrategyName

            pyStrPointless = EDConfiguration.getStringParamValue(
                pluginConfiguration, "POINTLESS")
            if (pyStrPointless == "ON"):
                self.__strPluginIntegrationName = self.__strPluginIntegrationPointlessName

    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, _edObject=None):
        EDPluginControl.process(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.process")
        self.connectProcess(self.__edPluginIndexing.executeSynchronous)
        self.__edPluginIndexing.connectSUCCESS(
            self.doIndexingToIntegrationTransition)
        self.__edPluginIndexing.connectFAILURE(self.doFailureActionIndexing)
        self.__edPluginIntegration.connectSUCCESS(
            self.doIntegrationToStrategyTransition)
        self.__edPluginIntegration.connectFAILURE(
            self.doFailureActionIntegration)
        self.__edPluginStrategy.connectFAILURE(self.doFailureActionStrategy)
        self.__edPluginStrategy.connectSUCCESS(self.doSuccessActionStrategy)

    def postProcess(self, _edObject=None):
        EDPluginControl.postProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.postProcess")
        if (self.__xsDataResultCharacterisation is not None):
            self.setDataOutput(self.__xsDataResultCharacterisation)

    def doIndexingToIntegrationTransition(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.doIndexingToIntegrationTransition"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_1.doIntegrationToStrategyTransition"
        )
        xsDataIndexingResult = self.__edPluginIndexing.getDataOutput()
        self.__xsDataResultCharacterisation.setIndexingResult(
            xsDataIndexingResult)
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(
            self.__xsDataResultCharacterisation.getDataCollection())
        xsDataIntegrationInput.setExperimentalConditionRefined(
            xsDataIndexingResult.getSelectedSolution(
            ).getExperimentalConditionRefined())
        xsDataIntegrationInput.setSelectedIndexingSolution(
            xsDataIndexingResult.getSelectedSolution())
        self.__edPluginIntegration.setDataInput(xsDataIntegrationInput)
        self.__edPluginIntegration.executeSynchronous()

    def doIntegrationToStrategyTransition(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.doIntegrationToStrategyTransition"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_1.doIntegrationToStrategyTransition"
        )

        xsDataIntegrationOutput = self.__edPluginIntegration.getDataOutput()
        self.__xsDataResultCharacterisation.setIntegrationResult(
            xsDataIntegrationOutput)
        #EDVerbose.DEBUG( self.__xsDataExperimentCharacterisation.marshal() )
        xsDataInputStrategy = XSDataInputStrategy()

        xsDataSolutionSelected = self.__xsDataResultCharacterisation.getIndexingResult(
        ).getSelectedSolution()

        xsDataInputStrategy.setCrystalRefined(
            xsDataSolutionSelected.getCrystal())
        xsDataInputStrategy.setSample(self.__xsDataResultCharacterisation.
                                      getDataCollection().getSample())

        xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult(
        )

        xsDataInputStrategy.setBestFileContentDat(
            xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
        xsDataInputStrategy.setBestFileContentPar(
            xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
        xsDataInputStrategy.setExperimentalCondition(
            xsDataIntegrationSubWedgeResultList[0].
            getExperimentalConditionRefined())

        for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
            xsDataInputStrategy.addBestFileContentHKL(
                xsDataIntegrationSubWedgeResult.getBestfileHKL())

        xsDataInputStrategy.setDiffractionPlan(
            self.__xsDataResultCharacterisation.getDataCollection(
            ).getDiffractionPlan())

        #print xsDataInputStrategy.marshal()
        self.__edPluginStrategy.setDataInput(xsDataInputStrategy)
        self.__edPluginStrategy.executeSynchronous()

    def doFailureActionIndexing(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.doFailureActionIndexing")
        self.retrieveFailureMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_1.doFailureActionIndexing")
        # If indexing fails all processing should stop
        self.generateExecutiveSummary(self)
        self.setFailure()

    def doFailureActionIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.doFailureActionIntegration")
        self.retrieveFailureMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_1.doFailureActionIntegration")

    def doFailureActionStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.doFailureActionStrategy")
        self.retrieveFailureMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_1.doFailureActionStrategy")

    def doSuccessActionStrategy(self, _edPlugin):
        """
        retrieve the potential warning messages
        """
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.doSuccessActionStrategy")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_1.doSuccessActionStrategy")
        xsDataResultStrategy = self.__edPluginStrategy.getDataOutput()
        self.__xsDataResultCharacterisation.setStrategyResult(
            xsDataResultStrategy)

    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_1.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        self.addErrorWarningMessagesToExecutiveSummary(
            "Characterisation failure! Error messages: ")
        self.addExecutiveSummarySeparator()
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine(
                "BEST complexity                       : %s" %
                xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Aimed completeness                    : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Required completeness                 : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution()
                is not None):
            self.addExecutiveSummaryLine(
                "Aimed I/sigma at highest resolution   : %6.1f" %
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution(
                ).getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine(
                "Aimed resolution                      : %6.1f [A]" %
                xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine(
                "Required resolution                   : %6.1f [A]" %
                xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Aimed multiplicity                    : %6.1f" %
                xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Required multiplicity                 : %6.1f" %
                xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine(
                "Forced space group                    : %6s" %
                xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection()
                is not None):
            self.addExecutiveSummaryLine(
                "Max exposure time per data collection : %6.1f [s]" %
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
                ).getValue())
        self.addExecutiveSummarySeparator()
        if (self.__edPluginIndexing is not None):
            self.appendExecutiveSummary(self.__edPluginIndexing, "Indexing : ")
        if (self.__edPluginIntegration is not None):
            self.appendExecutiveSummary(self.__edPluginIntegration,
                                        "Integration : ")
        if (self.__edPluginStrategy is not None):
            self.appendExecutiveSummary(self.__edPluginStrategy, "Strategy : ")

    def getPluginStrategyName(self):
        return self.__strPluginStrategyName
示例#14
0
def dna_execute_collection3(
    dna_start,
    dna_range,
    dna_number_of_images,
    dna_exptime,
    dna_directory,
    prefix,
    start_image_number,
    overlap,
    dna_run_num,
    charRequest,
):
    global collect_and_characterize_success, dna_have_strategy_results, dna_have_index_results, picture_taken
    global dna_strategy_exptime, dna_strategy_start, dna_strategy_range, dna_strategy_end, dna_strat_dist
    global screeningoutputid

    characterizationParams = charRequest["request_obj"]["characterizationParams"]
    dna_res = float(characterizationParams["aimed_resolution"])
    print "dna_res = " + str(dna_res)
    dna_filename_list = []
    print "number of images " + str(dna_number_of_images) + " overlap = " + str(overlap) + " dna_start " + str(
        dna_start
    ) + " dna_range " + str(dna_range) + " prefix " + prefix + " start number " + str(start_image_number) + "\n"
    collect_and_characterize_success = 0
    dna_have_strategy_results = 0
    dna_have_index_results = 0
    dg2rd = 3.14159265 / 180.0
    if daq_utils.detector_id == "ADSC-Q315":
        det_radius = 157.5
    elif daq_utils.detector_id == "ADSC-Q210":
        det_radius = 105.0
    elif daq_utils.detector_id == "PILATUS-6":
        det_radius = 212.0
    else:  # default Pilatus
        det_radius = 212.0
    #####  theta_radians = daq_lib.get_field("theta") * dg2rd
    theta_radians = 0.0
    wave = 12398.5 / beamline_lib.get_mono_energy()  # for now
    dx = det_radius / (tan(2.0 * (asin(wave / (2.0 * dna_res))) - theta_radians))
    print "distance = ", dx
    # skinner - could move distance and wave and scan axis here, leave wave alone for now
    print "skinner about to take reference images."
    for i in range(0, int(dna_number_of_images)):
        print "skinner prefix7 = " + prefix[0:7] + " " + str(start_image_number) + "\n"
        if len(prefix) > 8:
            if (prefix[0:7] == "postref") and (start_image_number == 1):
                print "skinner postref bail\n"
                time.sleep(float(dna_number_of_images * float(dna_exptime)))
                break
        # skinner roi - maybe I can measure and use that for dna_start so that first image is face on.
        dna_start = daq_lib.get_field("datum_omega")
        colstart = float(dna_start) + (i * (abs(overlap) + float(dna_range)))
        dna_prefix = "ref-" + prefix + "_" + str(dna_run_num)
        image_number = start_image_number + i
        dna_prefix_long = dna_directory + "/" + dna_prefix
        filename = daq_utils.create_filename(dna_prefix_long, image_number)
        beamline_lib.mva("Omega", float(colstart))
        #####    daq_lib.move_axis_absolute(daq_lib.get_field("scan_axis"),colstart)
        #####    daq_lib.take_image(colstart,dna_range,dna_exptime,filename,daq_lib.get_field("scan_axis"),0,1)
        daq_utils.take_crystal_picture(reqID=charRequest["request_id"])
        ######### BECAUSE I FAKE IT    imagesAttempted = collect_detector_seq(dna_range,dna_range,dna_exptime,dna_prefix,dna_directory,image_number)
        if i == 0:
            commFake = "ln -sf /h/pxuser/skinner/testdata/B1GGTApo_9_00001.cbf " + filename
        else:
            commFake = "ln -sf /h/pxuser/skinner/testdata/B1GGTApo_9_00181.cbf " + filename
        os.system(commFake)
        dna_filename_list.append(filename)
        diffImgJpegData = daq_utils.diff2jpeg(filename, reqID=charRequest["request_id"])  # returns a dictionary
        #    diffImgJpegData["timestamp"] = time.time()
        #    imgRef = db_lib.addFile(diffImgJpegData["data"])
        #    diffImgJpegData["data"] = imgRef
        #    imgRef = db_lib.addFile(diffImgJpegData["thumbData"])
        #    diffImgJpegData["thumbData"] = imgRef
        picture_taken = 1
    #                xml_from_file_list(flux,x_beamsize,y_beamsize,max_exptime_per_dc,aimed_completeness,file_list):
    edna_energy_ev = (12.3985 / wave) * 1000.0
    #####  xbeam_size = beamline_lib.get_motor_pos("slitHum")
    #####  ybeam_size = beamline_lib.get_motor_pos("slitVum")
    #  if (xbeam_size == 0.0 or ybeam_size == 0.0): #don't know where to get these from yet
    if 1:
        xbeam_size = 0.1
        ybeam_size = 0.16
    else:
        xbeam_size = xbeam_size / 1000
        ybeam_size = ybeam_size / 1000
    aimed_completeness = characterizationParams["aimed_completeness"]
    aimed_multiplicity = characterizationParams["aimed_multiplicity"]
    aimed_resolution = characterizationParams["aimed_resolution"]
    aimed_ISig = characterizationParams["aimed_ISig"]
    timeout_check = 0
    #####  while(not os.path.exists(dna_filename_list[len(dna_filename_list)-1])): #this waits for edna images
    if 0:
        timeout_check = timeout_check + 1
        time.sleep(1.0)
        if timeout_check > 10:
            break
    print "generating edna input\n"
    #  edna_input_filename = edna_input_xml.xml_from_file_list(edna_energy_ev,xbeam_size,ybeam_size,1000000,aimed_completness,aimed_ISig,aimed_multiplicity,aimed_resolution,dna_filename_list)
    #####  flux = 10000000000 * beamline_lib.get_epics_pv("flux","VAL")
    flux = 600000000.0  # for now
    edna_input_filename = dna_directory + "/adsc1_in.xml"
    edna_input_xml_command = (
        "/h/data/backed-up/pxsys/skinner/edna_header_code/makeAnEDNAXML-bnl.sh 1232 %s %s none %f %f 4000 0.01 0.01 0 xh1223_2_ %f %f %f > %s"
        % (dna_directory, dna_prefix, 3, aimed_ISig, flux, xbeam_size, ybeam_size, edna_input_filename)
    )
    #####  edna_input_xml_command = "ssh swill \"/h/data/backed-up/pxsys/skinner/edna_header_code/makeAnEDNAXML-bnl.sh 1232 %s %s none %f %f 4000 0.01 0.01 0 xh1223_2_ %f %f %f\" > %s" % (daq_lib.data_directory_name,dna_prefix,3,aimed_ISig,flux,xbeam_size,ybeam_size,edna_input_filename)
    print edna_input_xml_command
    comm_sss = "echo " + edna_input_xml_command + "> edna_comm.txt"
    os.system(comm_sss)
    os.system(edna_input_xml_command)

    print "done generating edna input\n"
    #  command_string = "cd %s; /usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data %s" % (dna_directory,edna_input_filename)
    command_string = "/usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data %s" % (
        edna_input_filename
    )
    #  command_string = "/usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data /img11/data1/pxuser/staff/skinner/edna_run/adsc1_in.xml"
    # old  command_string = "$EDNA_HOME/mxv1/bin/edna-mxv1-characterisation --data " + edna_input_filename
    print command_string
    #  for i in range (0,len(dna_filename_list)):
    #    command_string = command_string + " " + dna_filename_list[i]
    broadcast_output("\nProcessing with EDNA. Please stand by.\n")
    if os.path.exists("edna.log"):
        os.remove("edna.log")
    if os.path.exists("edna.err"):
        os.remove("edna.err")
    edna_execution_status = os.system("%s > edna.log 2> edna.err" % command_string)
    #####  fEdnaLogFile = open(daq_lib.get_misc_dir_name() + "/edna.log", "r" )
    fEdnaLogFile = open("./edna.log", "r")
    ednaLogLines = fEdnaLogFile.readlines()
    fEdnaLogFile.close()
    for outline in ednaLogLines:
        # for outline in os.popen(command_string,'r',0).readlines():
        ####skinner6/11 seg faults?    broadcast_output(outline)
        if string.find(outline, "EdnaDir") != -1:
            (param, dirname) = string.split(outline, "=")
            strXMLFileName = (
                dirname[0 : len(dirname) - 1]
                + "/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_3_dataOutput.xml"
            )
        #####      strXMLFileName = dirname[0:len(dirname)-1]+"/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_1_dataOutput.xml"
        if string.find(outline, "characterisation successful!") != -1:
            collect_and_characterize_success = 1
    if not collect_and_characterize_success:
        dna_comment = "Indexing Failure"
        #####    pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment)
        return 0
    xsDataCharacterisation = XSDataResultCharacterisation.parseFile(strXMLFileName)
    xsDataIndexingResult = xsDataCharacterisation.getIndexingResult()
    xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution()
    xsDataStatisticsIndexing = xsDataIndexingSolutionSelected.getStatistics()
    numSpotsFound = xsDataStatisticsIndexing.getSpotsTotal().getValue()
    numSpotsUsed = xsDataStatisticsIndexing.getSpotsUsed().getValue()
    numSpotsRejected = numSpotsFound - numSpotsUsed
    beamShiftX = xsDataStatisticsIndexing.getBeamPositionShiftX().getValue()
    beamShiftY = xsDataStatisticsIndexing.getBeamPositionShiftY().getValue()
    spotDeviationR = xsDataStatisticsIndexing.getSpotDeviationPositional().getValue()
    try:
        spotDeviationTheta = xsDataStatisticsIndexing.getSpotDeviationAngular().getValue()
    except AttributeError:
        spotDeviationTheta = 0.0
    diffractionRings = 0  # for now, don't see this in xml except message string
    reflections_used = 0  # for now
    reflections_used_in_indexing = 0  # for now
    rejectedReflections = 0  # for now
    xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation()
    xsDataMatrixA = xsDataOrientation.getMatrixA()
    rawOrientationMatrix_a_x = xsDataMatrixA.getM11()
    rawOrientationMatrix_a_y = xsDataMatrixA.getM12()
    rawOrientationMatrix_a_z = xsDataMatrixA.getM13()
    rawOrientationMatrix_b_x = xsDataMatrixA.getM21()
    rawOrientationMatrix_b_y = xsDataMatrixA.getM22()
    rawOrientationMatrix_b_z = xsDataMatrixA.getM23()
    rawOrientationMatrix_c_x = xsDataMatrixA.getM31()
    rawOrientationMatrix_c_y = xsDataMatrixA.getM32()
    rawOrientationMatrix_c_z = xsDataMatrixA.getM33()
    xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
    xsDataCell = xsDataCrystal.getCell()
    unitCell_alpha = xsDataCell.getAngle_alpha().getValue()
    unitCell_beta = xsDataCell.getAngle_beta().getValue()
    unitCell_gamma = xsDataCell.getAngle_gamma().getValue()
    unitCell_a = xsDataCell.getLength_a().getValue()
    unitCell_b = xsDataCell.getLength_b().getValue()
    unitCell_c = xsDataCell.getLength_c().getValue()
    mosaicity = xsDataCrystal.getMosaicity().getValue()
    xsSpaceGroup = xsDataCrystal.getSpaceGroup()
    spacegroup_name = xsSpaceGroup.getName().getValue()
    pointGroup = spacegroup_name  # for now
    bravaisLattice = pointGroup  # for now
    statusDescription = "ok"  # for now
    try:
        spacegroup_number = xsSpaceGroup.getITNumber().getValue()
    except AttributeError:
        spacegroup_number = 0
    xsStrategyResult = xsDataCharacterisation.getStrategyResult()
    resolutionObtained = -999
    if xsStrategyResult != None:
        dna_have_strategy_results = 1
        xsCollectionPlan = xsStrategyResult.getCollectionPlan()
        xsStrategySummary = xsCollectionPlan[0].getStrategySummary()
        resolutionObtained = xsStrategySummary.getRankingResolution().getValue()
        xsCollectionStrategy = xsCollectionPlan[0].getCollectionStrategy()
        xsSubWedge = xsCollectionStrategy.getSubWedge()
        for i in range(0, len(xsSubWedge)):
            xsExperimentalCondition = xsSubWedge[i].getExperimentalCondition()
            xsGoniostat = xsExperimentalCondition.getGoniostat()
            xsDetector = xsExperimentalCondition.getDetector()
            xsBeam = xsExperimentalCondition.getBeam()
            dna_strategy_start = xsGoniostat.getRotationAxisStart().getValue()
            dna_strategy_start = dna_strategy_start - (dna_strategy_start % 0.1)
            dna_strategy_range = xsGoniostat.getOscillationWidth().getValue()
            dna_strategy_range = dna_strategy_range - (dna_strategy_range % 0.1)
            dna_strategy_end = xsGoniostat.getRotationAxisEnd().getValue()
            dna_strategy_end = (dna_strategy_end - (dna_strategy_end % 0.1)) + dna_strategy_range
            dna_strat_dist = xsDetector.getDistance().getValue()
            dna_strat_dist = dna_strat_dist - (dna_strat_dist % 1)
            dna_strategy_exptime = xsBeam.getExposureTime().getValue()
    # wtf?      dna_strategy_exptime = dna_strategy_exptime-(dna_strategy_exptime%.2)
    program = "edna-1.0"  # for now
    #####  screeningoutputid = pxdb_lib.insert_dna_index_results(daq_lib.sweep_seq_id,daq_lib.get_field("xtal_id"),program,statusDescription,rejectedReflections,resolutionObtained,spotDeviationR,spotDeviationTheta,beamShiftX,beamShiftY,numSpotsFound,numSpotsUsed,numSpotsRejected,mosaicity,diffractionRings,spacegroup_name,pointGroup,bravaisLattice,rawOrientationMatrix_a_x,rawOrientationMatrix_a_y,rawOrientationMatrix_a_z,rawOrientationMatrix_b_x,rawOrientationMatrix_b_y,rawOrientationMatrix_b_z,rawOrientationMatrix_c_x,rawOrientationMatrix_c_y,rawOrientationMatrix_c_z,unitCell_a,unitCell_b,unitCell_c,unitCell_alpha,unitCell_beta,unitCell_gamma)
    dna_comment = (
        "spacegroup = "
        + str(spacegroup_name)
        + " mosaicity = "
        + str(mosaicity)
        + " resolutionHigh = "
        + str(resolutionObtained)
        + " cell_a = "
        + str(unitCell_a)
        + " cell_b = "
        + str(unitCell_b)
        + " cell_c = "
        + str(unitCell_c)
        + " cell_alpha = "
        + str(unitCell_alpha)
        + " cell_beta = "
        + str(unitCell_beta)
        + " cell_gamma = "
        + str(unitCell_gamma)
        + " status = "
        + str(statusDescription)
    )
    #####  print "\n\n skinner " + dna_comment + "\n" +str(daq_lib.sweep_seq_id) + "\n"
    print "\n\n skinner " + dna_comment + "\n"
    #####  pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment)
    if dna_have_strategy_results:
        #####    pxdb_lib.insert_to_screening_strategy_table(screeningoutputid,dna_strategy_start,dna_strategy_end,dna_strategy_range,dna_strategy_exptime,resolutionObtained,program)
        dna_strat_comment = (
            "\ndna Strategy results: Start="
            + str(dna_strategy_start)
            + " End="
            + str(dna_strategy_end)
            + " Width="
            + str(dna_strategy_range)
            + " Time="
            + str(dna_strategy_exptime)
            + " Dist="
            + str(dna_strat_dist)
        )
        #    characterizationResult = {}
        characterizationResultObj = {}
        #    characterizationResult["type"] = "characterizationStrategy"
        #   characterizationResult["timestamp"] = time.time()
        characterizationResultObj = {
            "strategy": {
                "start": dna_strategy_start,
                "end": dna_strategy_end,
                "width": dna_strategy_range,
                "exptime": dna_strategy_exptime,
                "detDist": dna_strat_dist,
            }
        }
        #    characterizationResult["resultObj"] = characterizationResultObj
        db_lib.addResultforRequest("characterizationStrategy", charRequest["request_id"], characterizationResultObj)
        #####    pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_strat_comment)
        xsStrategyStatistics = xsCollectionPlan[0].getStatistics()
        xsStrategyResolutionBins = xsStrategyStatistics.getResolutionBin()
        now = time.time()
        #  edna_isig_plot_filename = dirname[0:len(dirname)-1] + "/edna_isig_res_" + str(now) + ".txt"
        edna_isig_plot_filename = dirname[0 : len(dirname) - 1] + "/edna_isig_res.txt"
        isig_plot_file = open(edna_isig_plot_filename, "w")
        for i in range(0, len(xsStrategyResolutionBins) - 1):
            i_over_sigma_bin = xsStrategyResolutionBins[i].getIOverSigma().getValue()
            maxResolution_bin = xsStrategyResolutionBins[i].getMaxResolution().getValue()
            print str(maxResolution_bin) + " " + str(i_over_sigma_bin)
            isig_plot_file.write(str(maxResolution_bin) + " " + str(i_over_sigma_bin) + "\n")
        isig_plot_file.close()
    if dna_have_strategy_results:
        broadcast_output(dna_strat_comment)

    return 1
示例#15
0
class EDPluginControlCharacterisationv2_0(EDPluginControl):
    """
    The Plugin that controls the whole characterisation: Indexing-Integration-(Kappa)Strategy    
    Indexing-Integration is the same as mxv1 characterisation.
    KappaStrategy:
    Preferred Strategy is given at the initial orientation, but if KAPPA features are enabled,
    strategies are calculated to some alignments.
    """
    def __init__(self):
        """
        """
        EDPluginControl.__init__(self)
        #self.setXSDataInputClass( XSDataInputCharacterisation )
        #self.setXSDataInputClass(EDList)
        #self.strPluginIndexingName = "EDPluginControlIndexingv2_0"
        self.strPluginIndexingName = "EDPluginControlIndexingv10"
        self.edPluginIndexing = None
        self.strPluginIntegrationName = "EDPluginControlIntegrationv10"
        self.edPluginIntegration = None
        self.xsDataResultCharacterisationv2_0 = None
        self.xsDataResultCharacterisation = None
        self.xsDataInputStrategy = None

        self.setXSDataInputClass(XSDataInputCharacterisationv2_0)

        EDFactoryPluginStatic.loadModule("XSDataMXv1")
        import XSDataMXv1
        self.setXSDataInputClass(XSDataMXv1.XSDataInputCharacterisation,
                                 "mxv1InputCharacterisation")
        EDFactoryPluginStatic.loadModule("XSDataMXv2")
        import XSDataMXv2
        self.setXSDataInputClass(XSDataMXv2.XSDataCollection,
                                 "mxv2DataCollection")

    def checkParameters(self):
        """
        Checks the mandatory parameters
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.checkParameters")
        # Check for mxv1InputCharacterisation:
        if self.hasDataInput():
            if self.hasDataInput("mxv1InputCharacterisation"
                                 ) or self.hasDataInput("mxv2DataCollection"):
                EDVerbose.WARNING(
                    "Ambiguous input! Both XSDataInputCharacterisatiov2_0 input, and mxv1InputCharacterisation or mxv2DataCollection input(s), are given"
                )
            self.setDataInput(
                self.getDataInput().getMxv1InputCharacterisation().marshal(),
                "mxv1InputCharacterisation")
            self.setDataInput(
                self.getDataInput().getMxv2DataCollection().marshal(),
                "mxv2DataCollection")
        # Check for mxv1InputCharacterisation
        self.checkMandatoryParameters(
            self.getDataInput("mxv1InputCharacterisation"),
            "Data Input is None")
        self.checkMandatoryParameters(
            self.getDataInput("mxv1InputCharacterisation")
            [0].getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(
            self.getDataInput("mxv1InputCharacterisation")
            [0].getDataCollection().getDiffractionPlan(), "diffractionPlan")

    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 process(self, _edObject=None):
        EDPluginControl.process(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.process")
        self.connectProcess(self.edPluginIndexing.executeSynchronous)
        self.edPluginIndexing.connectSUCCESS(
            self.doIndexingToIntegrationTransition)
        self.edPluginIndexing.connectFAILURE(self.doFailureActionIndexing)
        self.edPluginIntegration.connectSUCCESS(
            self.doIntegrationToStrategyTransition)
        self.edPluginIntegration.connectFAILURE(
            self.doFailureActionIntegration)
        self.edPluginStrategy.connectFAILURE(self.doFailureActionStrategy)
        self.edPluginStrategy.connectSUCCESS(self.doSuccessActionStrategy)

    def postProcess(self, _edObject=None):
        """
        """
        EDPluginControl.postProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.postProcess")
        if (self.xsDataResultCharacterisationv2_0 is not None):
            self.setDataOutput(self.xsDataResultCharacterisationv2_0)

    def doIndexingToIntegrationTransition(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doIndexingToIntegrationTransition"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition"
        )
        xsDataIndexingResult = self.edPluginIndexing.getDataOutput()
        self.xsDataResultCharacterisation.setIndexingResult(
            xsDataIndexingResult)
        from XSDataMXv1 import XSDataIntegrationInput
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(
            self.xsDataResultCharacterisation.getDataCollection())
        xsDataIntegrationInput.setExperimentalConditionRefined(
            xsDataIndexingResult.getSelectedSolution(
            ).getExperimentalConditionRefined())
        xsDataIntegrationInput.setSelectedIndexingSolution(
            xsDataIndexingResult.getSelectedSolution())
        self.edPluginIntegration.setDataInput(xsDataIntegrationInput)
        self.edPluginIntegration.executeSynchronous()

    def doIntegrationToStrategyTransition(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition"
        )

        xsDataIntegrationOutput = self.edPluginIntegration.getDataOutput()
        self.xsDataResultCharacterisation.setIntegrationResult(
            xsDataIntegrationOutput)
        #EDVerbose.DEBUG( self.xsDataExperimentCharacterisation.marshal() )
        from XSDataMXv1 import XSDataInputStrategy
        xsDataInputStrategyOLD = XSDataInputStrategy()

        xsDataSolutionSelected = self.xsDataResultCharacterisation.getIndexingResult(
        ).getSelectedSolution()

        xsDataInputStrategyOLD.setCrystalRefined(
            xsDataSolutionSelected.getCrystal())
        xsDataInputStrategyOLD.setSample(
            self.xsDataResultCharacterisation.getDataCollection().getSample())

        xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult(
        )

        xsDataInputStrategyOLD.setBestFileContentDat(
            xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
        xsDataInputStrategyOLD.setBestFileContentPar(
            xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
        xsDataInputStrategyOLD.setExperimentalCondition(
            xsDataIntegrationSubWedgeResultList[0].
            getExperimentalConditionRefined())

        for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
            xsDataInputStrategyOLD.addBestFileContentHKL(
                xsDataIntegrationSubWedgeResult.getBestfileHKL())

        xsDataInputStrategyOLD.setDiffractionPlan(
            self.xsDataResultCharacterisation.getDataCollection(
            ).getDiffractionPlan())
        xsDataInputStrategyOLD.setXdsBackgroundImage(
            self.xsDataResultCharacterisation.getXdsBackgroundImage())

        #print xsDataInputStrategy.marshal()
        self.edPluginStrategy.setDataInput(xsDataInputStrategyOLD,
                                           "mxv1InputStrategy")
        if self.hasDataInput("mxv2DataCollection"):
            self.edPluginStrategy.setDataInput(
                self.getDataInput("mxv2DataCollection")[0],
                "mxv2DataCollection")
        self.edPluginStrategy.setDataInput(
            self.xsDataResultCharacterisation.getIndexingResult(),
            "mxv1IndexingResult")

        #            xsDataInputStrategy= EDList()
        #            xsDataInputStrategy.add(xsDataInputStrategyOLD)
        #            xsDataInputStrategy.add(self.getDataInput()[1])
        #            xsDataInputStrategy.add(self.xsDataResultCharacterisationv2_0.getIndexingResult())
        #            self.edPluginStrategy.setDataInput( xsDataInputStrategy )
        self.edPluginStrategy.executeSynchronous()

    def doFailureActionIndexing(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doFailureActionIndexing")
        self.retrieveFailureMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doFailureActionIndexing")

    def doFailureActionIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doFailureActionIntegration")
        self.retrieveFailureMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doFailureActionIntegration")

    def doFailureActionStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doFailureActionStrategy")
        self.retrieveFailureMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doFailureActionStrategy")

    def doSuccessActionStrategy(self, _edPlugin):
        """
        retrieve the potential warning messages
        """
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.doSuccessActionStrategy")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv2_0.doSuccessActionStrategy")
        xsDataResultStrategy = self.edPluginStrategy.getDataOutput()
        self.xsDataResultCharacterisation.setStrategyResult(
            xsDataResultStrategy)

    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.configure")
        pluginConfiguration = self.getConfiguration()

        if (pluginConfiguration != None):
            strPointlessOn = EDConfiguration.getStringParamValue(
                pluginConfiguration, "POINTLESS")
            if (strPointlessOn == None or strPointlessOn != "True"):
                self.strPluginIntegrationName = "EDPluginControlIntegrationv10"
            else:
                self.strPluginIntegrationName = "EDPluginControlIntegrationPointlessv10"

    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv2_0.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        self.addErrorWarningMessagesToExecutiveSummary(
            "Characterisation failure! Error messages: ")
        self.addExecutiveSummarySeparator()
        xsDataInputStrategy = self.getDataInput("mxv1InputCharacterisation")[0]
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine(
                "BEST complexity                       : %s" %
                xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Aimed completeness                    : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Required completeness                 : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution()
                is not None):
            self.addExecutiveSummaryLine(
                "Aimed I/sigma at highest resolution   : %6.1f" %
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution(
                ).getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine(
                "Aimed resolution                      : %6.1f [A]" %
                xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine(
                "Required resolution                   : %6.1f [A]" %
                xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Aimed multiplicity                    : %6.1f" %
                xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Required multiplicity                 : %6.1f" %
                xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine(
                "Forced space group                    : %6s" %
                xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection()
                is not None):
            self.addExecutiveSummaryLine(
                "Max exposure time per data collection : %6.1f [s]" %
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
                ).getValue())
        self.addExecutiveSummarySeparator()
        if (self.edPluginIndexing is not None):
            self.appendExecutiveSummary(self.edPluginIndexing, "Indexing : ")
        if (self.edPluginIntegration is not None):
            self.appendExecutiveSummary(self.edPluginIntegration,
                                        "Integration : ")
        if (self.edPluginStrategy is not None):
            self.appendExecutiveSummary(self.edPluginStrategy, "Strategy : ")
class EDPluginControlCharacterisationv1_1(EDPluginControl):
    """
    The Plugin that controls the whole characterisation.
    """

    def __init__ (self):
        """
        """
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self.__strPluginIndexingName = "EDPluginControlIndexingv10"
        self.__edPluginIndexing = None
        self.__strPluginIntegrationName = "EDPluginControlIntegrationv10"
        self.__edPluginIntegration = None
        self.__strPluginStrategyName = "EDPluginControlStrategyv1_1"
        self.__edPluginStrategy = None
        self.__xsDataResultCharacterisation = None
        self.__strPluginKappaStrategyName = "EDPluginControlKappaStrategyv1_1"
        self.__strPluginIntegrationPointlessName = "EDPluginControlIntegrationPointlessv10"


    def checkParameters(self):
        """
        Checks the mandatory parameters
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection().getDiffractionPlan(), "diffractionPlan")


    def configure(self):
        """
        Gets the configuration parameters (if any).
        """
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.configure")
        pluginConfiguration = self.getConfiguration()

        if(pluginConfiguration is None):
            EDVerbose.DEBUG("No plugin configuration found for EDPluginControlCharacterisationv1_1.")
        else:
            if (self.getControlledPluginName("indexingPlugin") is not None):
                self.__strPluginIndexingName = self.getControlledPluginName("indexingPlugin")
            if (self.getControlledPluginName("integrationPlugin") is not None):
                self.__strPluginIntegrationName = self.getControlledPluginName("integrationPlugin")
            if (self.getControlledPluginName("strategyPlugin") is not None):
                self.__strPluginStrategyName = self.getControlledPluginName("strategyPlugin")
            if (self.getControlledPluginName("kappaStrategyPlugin") is not None):
                self.__strPluginKappaStrategyName = self.getControlledPluginName("kappaStrategyPlugin")
            if (self.getControlledPluginName("integrationPointlessPlugin") is not None):
                self.__strPluginIntegrationPoitlessName = self.getControlledPluginName("integrationPointlessPlugin")

            pyStrKappa = EDConfiguration.getStringParamValue(pluginConfiguration, "KAPPA")
            if(pyStrKappa == "ON"):
                self.__strPluginStrategyName = self.__strPluginKappaStrategyName

            pyStrPointless = EDConfiguration.getStringParamValue(pluginConfiguration, "POINTLESS")
            if(pyStrPointless == "ON"):
                self.__strPluginIntegrationName = self.__strPluginIntegrationPointlessName



    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, _edObject=None):
        EDPluginControl.process(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.process")
        self.connectProcess(self.__edPluginIndexing.executeSynchronous)
        self.__edPluginIndexing.connectSUCCESS(self.doIndexingToIntegrationTransition)
        self.__edPluginIndexing.connectFAILURE(self.doFailureActionIndexing)
        self.__edPluginIntegration.connectSUCCESS(self.doIntegrationToStrategyTransition)
        self.__edPluginIntegration.connectFAILURE(self.doFailureActionIntegration)
        self.__edPluginStrategy.connectFAILURE(self.doFailureActionStrategy)
        self.__edPluginStrategy.connectSUCCESS(self.doSuccessActionStrategy)


    def postProcess(self, _edObject=None):
        EDPluginControl.postProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.postProcess")
        if (self.__xsDataResultCharacterisation is not None):
            self.setDataOutput(self.__xsDataResultCharacterisation)


    def doIndexingToIntegrationTransition(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.doIndexingToIntegrationTransition")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_1.doIntegrationToStrategyTransition")
        xsDataIndexingResult = self.__edPluginIndexing.getDataOutput()
        self.__xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(self.__xsDataResultCharacterisation.getDataCollection())
        xsDataIntegrationInput.setExperimentalConditionRefined(xsDataIndexingResult.getSelectedSolution().getExperimentalConditionRefined())
        xsDataIntegrationInput.setSelectedIndexingSolution(xsDataIndexingResult.getSelectedSolution())
        self.__edPluginIntegration.setDataInput(xsDataIntegrationInput)
        self.__edPluginIntegration.executeSynchronous()


    def doIntegrationToStrategyTransition(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.doIntegrationToStrategyTransition")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_1.doIntegrationToStrategyTransition")

        xsDataIntegrationOutput = self.__edPluginIntegration.getDataOutput()
        self.__xsDataResultCharacterisation.setIntegrationResult(xsDataIntegrationOutput)
        #EDVerbose.DEBUG( self.__xsDataExperimentCharacterisation.marshal() )
        xsDataInputStrategy = XSDataInputStrategy()

        xsDataSolutionSelected = self.__xsDataResultCharacterisation.getIndexingResult().getSelectedSolution()

        xsDataInputStrategy.setCrystalRefined(xsDataSolutionSelected.getCrystal())
        xsDataInputStrategy.setSample(self.__xsDataResultCharacterisation.getDataCollection().getSample())

        xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult()

        xsDataInputStrategy.setBestFileContentDat(xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
        xsDataInputStrategy.setBestFileContentPar(xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
        xsDataInputStrategy.setExperimentalCondition(xsDataIntegrationSubWedgeResultList[0].getExperimentalConditionRefined())

        for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
            xsDataInputStrategy.addBestFileContentHKL(xsDataIntegrationSubWedgeResult.getBestfileHKL())

        xsDataInputStrategy.setDiffractionPlan(self.__xsDataResultCharacterisation.getDataCollection().getDiffractionPlan())

        #print xsDataInputStrategy.marshal()
        self.__edPluginStrategy.setDataInput(xsDataInputStrategy)
        self.__edPluginStrategy.executeSynchronous()



    def doFailureActionIndexing(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.doFailureActionIndexing")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlCharacterisationv1_1.doFailureActionIndexing")
        # If indexing fails all processing should stop
        self.generateExecutiveSummary(self)
        self.setFailure()


    def doFailureActionIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.doFailureActionIntegration")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlCharacterisationv1_1.doFailureActionIntegration")


    def doFailureActionStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.doFailureActionStrategy")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlCharacterisationv1_1.doFailureActionStrategy")


    def doSuccessActionStrategy(self, _edPlugin):
        """
        retrieve the potential warning messages
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.doSuccessActionStrategy")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_1.doSuccessActionStrategy")
        xsDataResultStrategy = self.__edPluginStrategy.getDataOutput()
        self.__xsDataResultCharacterisation.setStrategyResult(xsDataResultStrategy)







    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_1.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        self.addErrorWarningMessagesToExecutiveSummary("Characterisation failure! Error messages: ")
        self.addExecutiveSummarySeparator()
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine("BEST complexity                       : %s" % xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine("Aimed completeness                    : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine("Required completeness                 : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution() is not None):
            self.addExecutiveSummaryLine("Aimed I/sigma at highest resolution   : %6.1f" % xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution().getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine("Aimed resolution                      : %6.1f [A]" % xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine("Required resolution                   : %6.1f [A]" % xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine("Aimed multiplicity                    : %6.1f" % xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine("Required multiplicity                 : %6.1f" % xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine("Forced space group                    : %6s" % xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection() is not None):
            self.addExecutiveSummaryLine("Max exposure time per data collection : %6.1f [s]" % xsDataDiffractionPlan.getMaxExposureTimePerDataCollection().getValue())
        self.addExecutiveSummarySeparator()
        if (self.__edPluginIndexing is not None):
            self.appendExecutiveSummary(self.__edPluginIndexing, "Indexing : ")
        if (self.__edPluginIntegration is not None):
            self.appendExecutiveSummary(self.__edPluginIntegration, "Integration : ")
        if (self.__edPluginStrategy is not None):
            self.appendExecutiveSummary(self.__edPluginStrategy, "Strategy : ")


    def getPluginStrategyName(self):
        return self.__strPluginStrategyName
示例#17
0
class EDPluginControlCharacterisationv1_3(EDPluginControl):
    """
    [To be replaced with a description of EDPluginControlTemplatev10]
    """
    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self._strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv10"
        self._strPluginControlIndexingLabelit = "EDPluginControlIndexingLabelitv10"
        self._strPluginExecEvaluationIndexing = "EDPluginExecEvaluationIndexingv10"
        self._strPluginControlGeneratePrediction = "EDPluginControlGeneratePredictionv10"
        self._strPluginControlIntegration = "EDPluginControlIntegrationv10"
        self._strPluginControlXDSGenerateBackgroundImage = "EDPluginControlXDSGenerateBackgroundImagev1_0"
        self._strPluginControlStrategy = "EDPluginControlStrategyv1_2"
        self._edPluginControlIndexingIndicators = None
        self._edPluginControlIndexingLabelit = None
        self._edPluginExecEvaluationIndexingMOSFLM = None
        self._edPluginExecEvaluationIndexingLABELIT = None
        self._edPluginControlGeneratePrediction = None
        self._edPluginControlIntegration = None
        self._edPluginControlXDSGenerateBackgroundImage = None
        self._edPluginControlStrategy = None
        self._xsDataCollection = None
        self._xsDataResultCharacterisation = None
        self._xsDataIndexingResultMOSFLM = None
        self._xsDataCrystal = None
        self._strCharacterisationShortSummary = ""
        self._strStatusMessage = ""
        self._xsDataFileXdsBackgroundImage = None
        self._bDoStrategyCalculation = True

    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(),
                                      "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(),
                                      "dataCollection")
        self.checkMandatoryParameters(
            self.getDataInput().getDataCollection().getDiffractionPlan(),
            "diffractionPlan")

    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.preProcess")
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginControlIndexingLabelit = self.loadPlugin(self._strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if (self._edPluginControlIndexingIndicators is not None):
            EDVerbose.DEBUG(
                "EDPluginControlCharacterisationv1_3.preProcess: " +
                self._strPluginControlIndexingIndicators +
                " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection(
            )
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_3.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage(
                            "EDPluginControlCharacterisationv1_3.preProcess ERROR: "
                            + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan(
                )
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup(
                )
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(
                    self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(
                        self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation = XSDataResultCharacterisation(
                )
                self._xsDataResultCharacterisation.setDataCollection(
                    XSDataCollection.parseString(
                        self._xsDataCollection.marshal()))

    def process(self, _edObject=None):
        EDPluginControl.process(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.process")
        self._edPluginControlIndexingIndicators.connectSUCCESS(
            self.doSuccessIndexingIndicators)
        self._edPluginControlIndexingIndicators.connectFAILURE(
            self.doFailureIndexingIndicators)
        self._edPluginControlIndexingLabelit.connectSUCCESS(
            self.doSuccessIndexingLabelit)
        self._edPluginControlIndexingLabelit.connectFAILURE(
            self.doFailureIndexingLabelit)
        self._edPluginExecEvaluationIndexingMOSFLM.connectSUCCESS(
            self.doSuccessEvaluationIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingMOSFLM.connectFAILURE(
            self.doFailureEvaluationIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingLABELIT.connectSUCCESS(
            self.doSuccessEvaluationIndexingLABELIT)
        self._edPluginExecEvaluationIndexingLABELIT.connectFAILURE(
            self.doFailureEvaluationIndexingLABELIT)
        self._edPluginControlGeneratePrediction.connectSUCCESS(
            self.doSuccessGeneratePrediction)
        self._edPluginControlGeneratePrediction.connectFAILURE(
            self.doFailureGeneratePrediction)
        self._edPluginControlIntegration.connectSUCCESS(
            self.doSuccessIntegration)
        self._edPluginControlIntegration.connectFAILURE(
            self.doFailureIntegration)
        self._edPluginControlXDSGenerateBackgroundImage.connectSUCCESS(
            self.doSuccessXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.connectFAILURE(
            self.doFailureXDSGenerateBackgroundImage)
        self._edPluginControlStrategy.connectSUCCESS(self.doSuccessStrategy)
        self._edPluginControlStrategy.connectFAILURE(self.doFailureStrategy)
        self.executePluginSynchronous(self._edPluginControlIndexingIndicators)

    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.finallyProcess")
        if self._edPluginControlGeneratePrediction.isRunning():
            self._edPluginControlGeneratePrediction.synchronize()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage),
                               "statusMessage")
            self._xsDataResultCharacterisation.setStatusMessage(
                XSDataString(self._strStatusMessage))
        if self._strCharacterisationShortSummary != None:
            self.setDataOutput(
                XSDataString(self._strCharacterisationShortSummary),
                "shortSummary")
            self._xsDataResultCharacterisation.setShortSummary(
                XSDataString(self._strCharacterisationShortSummary))
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)

    def doSuccessIndexingIndicators(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessIndexingIndicators")
        #self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessIndexingIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput(
                "indexingResult"):
            xsDataIndexingResult = self._edPluginControlIndexingIndicators.getDataOutput(
                "indexingResult")[0]
            #self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
            self._edPluginExecEvaluationIndexingMOSFLM.setDataInput(
                xsDataIndexingResult, "indexingResult")
        if self._edPluginControlIndexingIndicators.hasDataOutput(
                "imageQualityIndicators"):
            listXSDataImageQualityIndicators = self._edPluginControlIndexingIndicators.getDataOutput(
                "imageQualityIndicators")
            for xsDataImageQualityIndicators in listXSDataImageQualityIndicators:
                self._xsDataResultCharacterisation.addImageQualityIndicators(
                    xsDataImageQualityIndicators)
                self._edPluginExecEvaluationIndexingMOSFLM.setDataInput(
                    xsDataImageQualityIndicators, "imageQualityIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput(
                "indicatorsShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput(
                "indicatorsShortSummary")[0].getValue()
        self.executePluginSynchronous(
            self._edPluginExecEvaluationIndexingMOSFLM)

    def doFailureIndexingIndicators(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureIndexingIndicators")
        strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
        EDVerbose.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        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 doSuccessIndexingLabelit(self, _edPlugin=None):
#        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
#        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
#        # Retrieve the indexing result
#        xsDataIndexingResult = self._edPluginControlIndexingLabelit.getDataOutput()
#        self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
#        if self._edPluginControlIndexingLabelit.hasDataOutput("indexingShortSummary"):
#            self._strCharacterisationShortSummary += self._edPluginControlIndexingLabelit.getDataOutput("indexingShortSummary")[0].getValue()
#        # Then start the integration of the reference images
#        self.indexingToIntegration()

    def doSuccessIndexingLabelit(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
        if self._edPluginControlIndexingLabelit.hasDataOutput(
                "indexingShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlIndexingLabelit.getDataOutput(
                "indexingShortSummary")[0].getValue()
        # Check the indexing results
        xsDataIndexingResult = self._edPluginControlIndexingLabelit.getDataOutput(
        )
        self._edPluginExecEvaluationIndexingLABELIT.setDataInput(
            xsDataIndexingResult, "indexingResult")
        xsDataImageQualityIndicators = self._xsDataResultCharacterisation.getImageQualityIndicators(
        )[0]
        self._edPluginExecEvaluationIndexingLABELIT.setDataInput(
            xsDataImageQualityIndicators, "imageQualityIndicators")
        self.executePluginSynchronous(
            self._edPluginExecEvaluationIndexingLABELIT)

    def doFailureIndexingLabelit(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureIndexingLabelit")
        self.addStatusMessage("Labelit: Indexing FAILURE.")
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        if self._xsDataIndexingResultMOSFLM == None:
            strErrorMessage = "Execution of indexing with both MOSFLM and Labelit failed. Execution of characterisation aborted."
            EDVerbose.ERROR(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.generateExecutiveSummary(self)
            self.setFailure()
            if self._strStatusMessage != None:
                self.setDataOutput(XSDataString(self._strStatusMessage),
                                   "statusMessage")
                self.writeDataOutput()
        else:
            # Use the MOSFLM indexing results - even if it's P1
            self._xsDataResultCharacterisation.setIndexingResult(
                self._xsDataIndexingResultMOSFLM)
            xsDataCollection = self._xsDataResultCharacterisation.getDataCollection(
            )
            xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
            xsDataGeneratePredictionInput.setDataCollection(
                XSDataCollection.parseString(xsDataCollection.marshal()))
            xsDataGeneratePredictionInput.setSelectedIndexingSolution(
                XSDataIndexingSolutionSelected.parseString(
                    self._xsDataIndexingResultMOSFLM.getSelectedSolution(
                    ).marshal()))
            self._edPluginControlGeneratePrediction.setDataInput(
                xsDataGeneratePredictionInput)
            if self._edPluginControlIndexingIndicators.hasDataOutput(
                    "indexingShortSummary"):
                self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput(
                    "indexingShortSummary")[0].getValue()
            # 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()

    def doSuccessEvaluationIndexingMOSFLM(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessEvaluationIndexingMOSFLM"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_3.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.executePluginSynchronous(self._edPluginControlIndexingLabelit)

    def doSuccessEvaluationIndexingLABELIT(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessEvaluationIndexingLABELIT"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_3.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)
            # Then start the integration of the reference images
            self.indexingToIntegration()
        else:
            EDVerbose.screen("Indexing with LABELIT failed!")
            self.setFailure()

    def indexingToIntegration(self, _edPlugin=None):
        # Create the XDS background image
        xsDataInputControlXDSGenerateBackgroundImage = XSDataInputControlXDSGenerateBackgroundImage(
        )
        xsDataInputControlXDSGenerateBackgroundImage.setDataCollection(
            self._xsDataCollection)
        self._edPluginControlXDSGenerateBackgroundImage.setDataInput(
            xsDataInputControlXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.execute()
        # Integrate the reference images
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(
            self._xsDataResultCharacterisation.getDataCollection())
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult(
        )
        xsDataExperimentalConditionRefinded = xsDataIndexingResult.getSelectedSolution(
        ).getExperimentalConditionRefined()
        xsDataIntegrationInput.setExperimentalConditionRefined(
            xsDataExperimentalConditionRefinded)
        xsDataIntegrationInput.setSelectedIndexingSolution(
            xsDataIndexingResult.getSelectedSolution())
        self._edPluginControlIntegration.setDataInput(xsDataIntegrationInput)
        self.executePluginSynchronous(self._edPluginControlIntegration)

    def doFailureEvaluationIndexingMOSFLM(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureEvaluationIndexing")
        strWarningMessage = "Execution of indexing evaluation plugin failed."
        EDVerbose.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)

    def doFailureEvaluationIndexingLABELIT(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureEvaluationIndexing")
        strWarningMessage = "Execution of indexing evaluation plugin failed."
        EDVerbose.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)

    def doSuccessGeneratePrediction(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessGeneratePrediction")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_3.doSuccessGeneratePrediction")
        xsDataGeneratePredictionResult = _edPlugin.getDataOutput()
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult(
        )
        xsDataIndexingResult.setPredictionResult(
            xsDataGeneratePredictionResult)

    def doFailureGeneratePrediction(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureGeneratePrediction")
        strWarningMessage = "Execution of generate prediction plugin failed."
        EDVerbose.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        #self.addComment("warning: no prediction images")

    def doSuccessIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessIntegration")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_3.doSuccessIntegration")
        # Wait for XDS plugin if necessary
        self._edPluginControlXDSGenerateBackgroundImage.synchronize()
        self.addStatusMessage("Integration successful.")
        xsDataIntegrationOutput = self._edPluginControlIntegration.getDataOutput(
        )
        self._xsDataResultCharacterisation.setIntegrationResult(
            xsDataIntegrationOutput)
        # Integration short summary
        if self._edPluginControlIntegration.hasDataOutput(
                "integrationShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlIntegration.getDataOutput(
                "integrationShortSummary")[0].getValue()
        #EDVerbose.DEBUG( self._xsDataExperimentCharacterisation.marshal() )
        if self._bDoStrategyCalculation:
            xsDataInputStrategy = XSDataInputStrategy()
            xsDataSolutionSelected = self._xsDataResultCharacterisation.getIndexingResult(
            ).getSelectedSolution()
            xsDataInputStrategy.setCrystalRefined(
                xsDataSolutionSelected.getCrystal())
            xsDataInputStrategy.setSample(self._xsDataResultCharacterisation.
                                          getDataCollection().getSample())
            xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult(
            )
            xsDataInputStrategy.setBestFileContentDat(
                xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
            xsDataInputStrategy.setBestFileContentPar(
                xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
            xsDataInputStrategy.setExperimentalCondition(
                xsDataIntegrationSubWedgeResultList[0].
                getExperimentalConditionRefined())
            xsDataInputStrategy.setXdsBackgroundImage(
                self._xsDataFileXdsBackgroundImage)
            for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
                xsDataInputStrategy.addBestFileContentHKL(
                    xsDataIntegrationSubWedgeResult.getBestfileHKL())
            xsDataInputStrategy.setDiffractionPlan(
                self._xsDataResultCharacterisation.getDataCollection(
                ).getDiffractionPlan())
            self._edPluginControlStrategy.setDataInput(xsDataInputStrategy)
            self.executePluginSynchronous(self._edPluginControlStrategy)

    def doFailureIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureIntegration")
        strErrorMessage = "Execution of integration plugin failed."
        self.addStatusMessage("Integration FAILURE.")
        EDVerbose.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        #self.addComment("integration failure")
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.generateExecutiveSummary(self)
        self.setFailure()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage),
                               "statusMessage")
            self.writeDataOutput()

    def doSuccessXDSGenerateBackgroundImage(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessXDSGenerateBackgroundImage"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_3.doSuccessXDSGenerateBackgroundImage"
        )
        self._xsDataFileXdsBackgroundImage = self._edPluginControlXDSGenerateBackgroundImage.getDataOutput(
        ).getXdsBackgroundImage()
        self._xsDataResultCharacterisation.setXdsBackgroundImage(
            self._xsDataFileXdsBackgroundImage)

    def doFailureXDSGenerateBackgroundImage(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureXDSGenerateBackgroundImage"
        )

    def doSuccessStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doSuccessStrategy")
        self.retrieveSuccessMessages(
            self._edPluginControlStrategy,
            "EDPluginControlCharacterisationv1_3.doSuccessStrategy")
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(
            xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlStrategy.getDataOutput(
                "strategyShortSummary")[0].getValue()
        self.addStatusMessage("Strategy calculation successful.")

    def doFailureStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.doFailureStrategy")
        strErrorMessage = "Execution of strategy plugin failed."
        EDVerbose.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.addStatusMessage("Strategy calculation FAILURE.")
        self.generateExecutiveSummary(self)
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage),
                               "statusMessage")
            self.writeDataOutput()
        self.setFailure()

    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        EDVerbose.DEBUG(
            "EDPluginControlCharacterisationv1_3.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine(
                "BEST complexity                       : %s" %
                xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Aimed completeness                    : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Required completeness                 : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution()
                is not None):
            self.addExecutiveSummaryLine(
                "Aimed I/sigma at highest resolution   : %6.1f" %
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution(
                ).getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine(
                "Aimed resolution                      : %6.1f [A]" %
                xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine(
                "Required resolution                   : %6.1f [A]" %
                xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Aimed multiplicity                    : %6.1f" %
                xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Required multiplicity                 : %6.1f" %
                xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine(
                "Forced space group                    : %6s" %
                xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection()
                is not None):
            self.addExecutiveSummaryLine(
                "Max exposure time per data collection : %6.1f [s]" %
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
                ).getValue())
        self.addExecutiveSummarySeparator()
        if self._edPluginControlIndexingIndicators is not None:
            self.appendExecutiveSummary(
                self._edPluginControlIndexingIndicators, "")
        if self._edPluginControlIndexingLabelit is not None:
            self.appendExecutiveSummary(self._edPluginControlIndexingLabelit,
                                        "")
        if self._edPluginControlIntegration is not None:
            self.appendExecutiveSummary(self._edPluginControlIntegration, "")
        if self._edPluginControlStrategy is not None:
            self.appendExecutiveSummary(self._edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self._strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self._strStatusMessage != None:
                for strLine in self._strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine + ".")
            self.addExecutiveSummaryLine("")
            for strLine in self._strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary(
            "Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()

    def getPluginStrategyName(self):
        return self._strPluginControlStrategy

    def addStatusMessage(self, _strStatusMessage):
        if self._strStatusMessage != "":
            self._strStatusMessage += " "
        self._strStatusMessage += _strStatusMessage

    def doStrategyCalculation(self, _bValue):
        self._bDoStrategyCalculation = _bValue
示例#18
0
class EDPluginControlCharacterisationv1_6(EDPluginControl):
    """
    Characterisation based on XDS
    """
    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self._strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv1_1"
        self._fMinTransmission = 10  # %
        self._listPluginGenerateThumbnail = []
        self._strCharacterisationShortSummary = ""
        self._strStatusMessage = ""
        self._strIndexingPluginName = "EDPluginXDSIndexingv1_0"
        self._strIntegrationPluginName = "EDPluginXDSIntegrationv1_0"
        self._edPluginIndexing = None

    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_6.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(),
                                      "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(),
                                      "dataCollection")
        self.checkMandatoryParameters(
            self.getDataInput().getDataCollection().getDiffractionPlan(),
            "diffractionPlan")

    def configure(self):
        """
        Gets the configuration parameters (if any).
        """
        EDPluginControl.configure(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.configure")
        self._strMxCuBE_URI = self.config.get("mxCuBE_URI", None)
        if self._strMxCuBE_URI is not None and "mxCuBE_XMLRPC_log" in os.environ.keys(
        ):
            self.DEBUG(
                "Enabling sending messages to mxCuBE via URI {0}".format(
                    self._strMxCuBE_URI))
            self._oServerProxy = xmlrpclib.ServerProxy(self._strMxCuBE_URI)
        self._runKappa = self.config.get("runKappa", False)
        self._fMinTransmission = self.config.get("minTransmissionWarning",
                                                 self._fMinTransmission)

    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.preProcess")
        self._xsDataResultCharacterisation = XSDataResultCharacterisation()

    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.process")
        self.doXdsIndexingIntegration(self.dataInput.dataCollection)

    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.finallyProcess")
        # Synchronize thumbnail plugins
        for tuplePlugin in self._listPluginGenerateThumbnail:
            image = tuplePlugin[0]
            tuplePlugin[1].synchronize()
            jpegImage = image.copy()
            jpegImage.path = tuplePlugin[1].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addJpegImage(jpegImage)
            tuplePlugin[2].synchronize()
            thumbnailImage = image.copy()
            thumbnailImage.path = tuplePlugin[2].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addThumbnailImage(
                thumbnailImage)
#        if self._edPluginControlGeneratePrediction.isRunning():
#            self._edPluginControlGeneratePrediction.synchronize()
#        if self._strStatusMessage != None:
#            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
#            self._xsDataResultCharacterisation.setStatusMessage(XSDataString(self._strStatusMessage))
#        if self._strCharacterisationShortSummary != None:
#            self.setDataOutput(XSDataString(self._strCharacterisationShortSummary), "shortSummary")
#            self._xsDataResultCharacterisation.setShortSummary(XSDataString(self._strCharacterisationShortSummary))
#        if self._xsDataResultCharacterisation is not None:
#            self.setDataOutput(self._xsDataResultCharacterisation)
        if self.isFailure():
            self.sendMessageToMXCuBE("Ended with error messages", "error")

    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 generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        self.DEBUG(
            "EDPluginControlCharacterisationv1_6.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
        xsDataFirstSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
        if xsDataBeam.getTransmission() is not None:
            fTransmission = xsDataBeam.getTransmission().getValue()
            if fTransmission < self._fMinTransmission:
                self.addExecutiveSummaryLine("^" * 80)
                self.addExecutiveSummaryLine("^" * 80)
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine(
                    "WARNING! Transmission for characterisation set to %.1f %%"
                    % fTransmission)
                self.addExecutiveSummaryLine(
                    "Please consider re-characterising with transmission set to 100 %"
                )
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("^" * 80)
                self.addExecutiveSummaryLine("^" * 80)
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine(
                "BEST complexity                       : %s" %
                xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Aimed completeness                    : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Required completeness                 : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution()
                is not None):
            self.addExecutiveSummaryLine(
                "Aimed I/sigma at highest resolution   : %6.1f" %
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution(
                ).getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine(
                "Aimed resolution                      : %6.1f [A]" %
                xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine(
                "Required resolution                   : %6.1f [A]" %
                xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Aimed multiplicity                    : %6.1f" %
                xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Required multiplicity                 : %6.1f" %
                xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine(
                "Forced space group                    : %6s" %
                xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection()
                is not None):
            self.addExecutiveSummaryLine(
                "Max exposure time per data collection : %6.1f [s]" %
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
                ).getValue())
        self.addExecutiveSummarySeparator()
        #        if self._edPluginControlIndexingIndicators is not None:
        #            self.appendExecutiveSummary(self._edPluginControlIndexingIndicators, "")
        #        if self._edPluginControlIntegration is not None:
        #            self.appendExecutiveSummary(self._edPluginControlIntegration, "")
        #        if self._edPluginControlStrategy is not None:
        #            self.appendExecutiveSummary(self._edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self._strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self._strStatusMessage != None:
                for strLine in self._strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine + ".")
            self.addExecutiveSummaryLine("")
            for strLine in self._strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary(
            "Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()

    def getPluginStrategyName(self):
        return self._strPluginControlStrategy

    def addStatusMessage(self, _strStatusMessage):
        if self._strStatusMessage != "":
            self._strStatusMessage += " "
        self._strStatusMessage += _strStatusMessage
        self.sendMessageToMXCuBE(_strStatusMessage)

    def doStrategyCalculation(self, _bValue):
        self._bDoStrategyCalculation = _bValue

    def sendMessageToMXCuBE(self, _strMessage, level="info"):
        # Only for mxCuBE
        if self._strMxCuBE_URI is not None:
            self.DEBUG("Sending message to mxCuBE: {0}".format(_strMessage))
            try:
                for strMessage in _strMessage.split("\n"):
                    if strMessage != "":
                        self._oServerProxy.log_message(
                            "Characterisation: " + strMessage, level)
            except:
                self.DEBUG("Sending message to mxCuBE failed!")
示例#19
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.preProcess")
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginControlIndexingLabelit = self.loadPlugin(self._strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if (self._edPluginControlIndexingIndicators is not None):
            EDVerbose.DEBUG(
                "EDPluginControlCharacterisationv1_3.preProcess: " +
                self._strPluginControlIndexingIndicators +
                " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection(
            )
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition(
            ).getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^" * 80
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %"
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_3.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage(
                            "EDPluginControlCharacterisationv1_3.preProcess ERROR: "
                            + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan(
                )
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup(
                )
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(
                    self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(
                        self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation = XSDataResultCharacterisation(
                )
                self._xsDataResultCharacterisation.setDataCollection(
                    XSDataCollection.parseString(
                        self._xsDataCollection.marshal()))
class EDPluginControlCharacterisationv1_3(EDPluginControl):
    """
    [To be replaced with a description of EDPluginControlTemplatev10]
    """


    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self._strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv10"
        self._strPluginControlIndexingLabelit = "EDPluginControlIndexingLabelitv10"
        self._strPluginExecEvaluationIndexing = "EDPluginExecEvaluationIndexingv10"
        self._strPluginControlGeneratePrediction = "EDPluginControlGeneratePredictionv10"
        self._strPluginControlIntegration = "EDPluginControlIntegrationv10"
        self._strPluginControlXDSGenerateBackgroundImage = "EDPluginControlXDSGenerateBackgroundImagev1_0"
        self._strPluginControlStrategy = "EDPluginControlStrategyv1_2"
        self._strPluginGenerateThumbnailName = "EDPluginMXThumbnailv1_1"
        self._listPluginGenerateThumbnail = []
        self._edPluginControlIndexingIndicators = None
        self._edPluginControlIndexingLabelit = None
        self._edPluginExecEvaluationIndexingMOSFLM = None
        self._edPluginExecEvaluationIndexingLABELIT = None
        self._edPluginControlGeneratePrediction = None
        self._edPluginControlIntegration = None
        self._edPluginControlXDSGenerateBackgroundImage = None
        self._edPluginControlStrategy = None
        self._xsDataCollection = None
        self._xsDataResultCharacterisation = None
        self._xsDataIndexingResultMOSFLM = None
        self._xsDataCrystal = None
        self._strCharacterisationShortSummary = ""
        self._strStatusMessage = ""
        self._xsDataFileXdsBackgroundImage = None
        self._bDoStrategyCalculation = True
        self._fMinTransmission = 10 # %


    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_3.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection().getDiffractionPlan(), "diffractionPlan")


    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_3.preProcess")
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginControlIndexingLabelit = self.loadPlugin(self._strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if (self._edPluginControlIndexingIndicators is not None):
            self.DEBUG("EDPluginControlCharacterisationv1_3.preProcess: " + self._strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^"*80 
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %" 
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_3.preProcess: No subwedges in input data."
                self.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        self.ERROR(strErrorMessage)
                        self.addErrorMessage("EDPluginControlCharacterisationv1_3.preProcess ERROR: " + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation = XSDataResultCharacterisation()
                self._xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self._xsDataCollection.marshal()))
            # Load the thumbnail plugins
            for subWedge in xsDataInputCharacterisation.dataCollection.subWedge:
                for image in subWedge.image:
                    edPluginJpeg = self.loadPlugin(self._strPluginGenerateThumbnailName)
                    xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                    xsDataInputMXThumbnail.image = XSDataFile(image.path)
                    xsDataInputMXThumbnail.height = XSDataInteger(1024)
                    xsDataInputMXThumbnail.width = XSDataInteger(1024)
                    jpegFilename = os.path.splitext(os.path.basename(image.path.value))[0]+".jpg"
                    xsDataInputMXThumbnail.outputPath = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), jpegFilename)))
                    edPluginJpeg.dataInput = xsDataInputMXThumbnail
                    edPluginThumnail = self.loadPlugin(self._strPluginGenerateThumbnailName)
                    xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                    xsDataInputMXThumbnail.image = XSDataFile(image.path)
                    xsDataInputMXThumbnail.height = XSDataInteger(256)
                    xsDataInputMXThumbnail.width = XSDataInteger(256)
                    thumbnailFilename = os.path.splitext(os.path.basename(image.path.value))[0]+".thumbnail.jpg"
                    xsDataInputMXThumbnail.outputPath = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), thumbnailFilename)))
                    edPluginThumnail.dataInput = xsDataInputMXThumbnail
                    self._listPluginGenerateThumbnail.append((image, edPluginJpeg, edPluginThumnail))


    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlCharacterisationv1_3.process")
        self._edPluginControlIndexingIndicators.connectSUCCESS(self.doSuccessIndexingIndicators)
        self._edPluginControlIndexingIndicators.connectFAILURE(self.doFailureIndexingIndicators)
        self._edPluginControlIndexingLabelit.connectSUCCESS(self.doSuccessIndexingLabelit)
        self._edPluginControlIndexingLabelit.connectFAILURE(self.doFailureIndexingLabelit)
        self._edPluginExecEvaluationIndexingMOSFLM.connectSUCCESS(self.doSuccessEvaluationIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingMOSFLM.connectFAILURE(self.doFailureEvaluationIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingLABELIT.connectSUCCESS(self.doSuccessEvaluationIndexingLABELIT)
        self._edPluginExecEvaluationIndexingLABELIT.connectFAILURE(self.doFailureEvaluationIndexingLABELIT)
        self._edPluginControlGeneratePrediction.connectSUCCESS(self.doSuccessGeneratePrediction)
        self._edPluginControlGeneratePrediction.connectFAILURE(self.doFailureGeneratePrediction)
        self._edPluginControlIntegration.connectSUCCESS(self.doSuccessIntegration)
        self._edPluginControlIntegration.connectFAILURE(self.doFailureIntegration)
        self._edPluginControlXDSGenerateBackgroundImage.connectSUCCESS(self.doSuccessXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.connectFAILURE(self.doFailureXDSGenerateBackgroundImage)
        self._edPluginControlStrategy.connectSUCCESS(self.doSuccessStrategy)
        self._edPluginControlStrategy.connectFAILURE(self.doFailureStrategy)
        self.executePluginSynchronous(self._edPluginControlIndexingIndicators)


    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_3.finallyProcess")
        # Synchronize thumbnail plugins
        for tuplePlugin in self._listPluginGenerateThumbnail:
            image = tuplePlugin[0]
            tuplePlugin[1].synchronize()
            jpegImage = image.copy()
            jpegImage.path = tuplePlugin[1].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addJpegImage(jpegImage)        
            tuplePlugin[2].synchronize()
            thumbnailImage = image.copy()
            thumbnailImage.path = tuplePlugin[2].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addThumbnailImage(thumbnailImage)        
        if self._edPluginControlGeneratePrediction.isRunning():
            self._edPluginControlGeneratePrediction.synchronize()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
            self._xsDataResultCharacterisation.setStatusMessage(XSDataString(self._strStatusMessage))
        if self._strCharacterisationShortSummary != None:
            self.setDataOutput(XSDataString(self._strCharacterisationShortSummary), "shortSummary")
            self._xsDataResultCharacterisation.setShortSummary(XSDataString(self._strCharacterisationShortSummary))
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)


    def doSuccessIndexingIndicators(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessIndexingIndicators")
        #self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessIndexingIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput("indexingResult"):
            xsDataIndexingResult = self._edPluginControlIndexingIndicators.getDataOutput("indexingResult")[0]
            #self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
            self._edPluginExecEvaluationIndexingMOSFLM.setDataInput(xsDataIndexingResult, "indexingResult")
        if self._edPluginControlIndexingIndicators.hasDataOutput("imageQualityIndicators"):
            listXSDataImageQualityIndicators = self._edPluginControlIndexingIndicators.getDataOutput("imageQualityIndicators")
            for xsDataImageQualityIndicators in listXSDataImageQualityIndicators:
                self._xsDataResultCharacterisation.addImageQualityIndicators(xsDataImageQualityIndicators)
                self._edPluginExecEvaluationIndexingMOSFLM.setDataInput(xsDataImageQualityIndicators, "imageQualityIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput("indicatorsShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput("indicatorsShortSummary")[0].getValue()
        for tuplePlugin in self._listPluginGenerateThumbnail:
            tuplePlugin[1].execute()
            tuplePlugin[2].execute()
        self.executePluginSynchronous(self._edPluginExecEvaluationIndexingMOSFLM)


    def doFailureIndexingIndicators(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureIndexingIndicators")
        strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
        self.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        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 doSuccessIndexingLabelit(self, _edPlugin=None):
#        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
#        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
#        # Retrieve the indexing result
#        xsDataIndexingResult = self._edPluginControlIndexingLabelit.getDataOutput()
#        self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
#        if self._edPluginControlIndexingLabelit.hasDataOutput("indexingShortSummary"):
#            self._strCharacterisationShortSummary += self._edPluginControlIndexingLabelit.getDataOutput("indexingShortSummary")[0].getValue()
#        # Then start the integration of the reference images
#        self.indexingToIntegration()


    def doSuccessIndexingLabelit(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessIndexingLabelit")
        if self._edPluginControlIndexingLabelit.hasDataOutput("indexingShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlIndexingLabelit.getDataOutput("indexingShortSummary")[0].getValue()
        # Check the indexing results
        xsDataIndexingResult = self._edPluginControlIndexingLabelit.getDataOutput()
        self._edPluginExecEvaluationIndexingLABELIT.setDataInput(xsDataIndexingResult, "indexingResult")
        xsDataImageQualityIndicators = self._xsDataResultCharacterisation.getImageQualityIndicators()[0]
        self._edPluginExecEvaluationIndexingLABELIT.setDataInput(xsDataImageQualityIndicators, "imageQualityIndicators")
        self.executePluginSynchronous(self._edPluginExecEvaluationIndexingLABELIT)


    def doFailureIndexingLabelit(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureIndexingLabelit")
        self.addStatusMessage("Labelit: Indexing FAILURE.")
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        if self._xsDataIndexingResultMOSFLM == None:
            strErrorMessage = "Execution of indexing with both MOSFLM and Labelit failed. Execution of characterisation aborted."
            self.ERROR(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.generateExecutiveSummary(self)
            self.setFailure()
            if self._strStatusMessage != None:
                self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
                self.writeDataOutput()
        else:
            # Use the MOSFLM indexing results - even if it's P1
            self._xsDataResultCharacterisation.setIndexingResult(self._xsDataIndexingResultMOSFLM)
            xsDataCollection = self._xsDataResultCharacterisation.getDataCollection()
            xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
            xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
            xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(self._xsDataIndexingResultMOSFLM.getSelectedSolution().marshal()))
            self._edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
            if self._edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
                self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
            # 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()



    def doSuccessEvaluationIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessEvaluationIndexingMOSFLM")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.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.executePluginSynchronous(self._edPluginControlIndexingLabelit)


    def doSuccessEvaluationIndexingLABELIT(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessEvaluationIndexingLABELIT")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.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)
            # Then start the integration of the reference images
            self.indexingToIntegration()
        else:
            self.screen("Indexing with LABELIT failed!")
            self.setFailure()


    def indexingToIntegration(self, _edPlugin=None):
        # Create the XDS background image
        xsDataInputControlXDSGenerateBackgroundImage = XSDataInputControlXDSGenerateBackgroundImage()
        xsDataInputControlXDSGenerateBackgroundImage.setDataCollection(self._xsDataCollection)
        self._edPluginControlXDSGenerateBackgroundImage.setDataInput(xsDataInputControlXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.execute()
        # Integrate the reference images 
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(self._xsDataResultCharacterisation.getDataCollection())
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult()
        xsDataExperimentalConditionRefinded = xsDataIndexingResult.getSelectedSolution().getExperimentalConditionRefined()
        xsDataIntegrationInput.setExperimentalConditionRefined(xsDataExperimentalConditionRefinded)
        xsDataIntegrationInput.setSelectedIndexingSolution(xsDataIndexingResult.getSelectedSolution())
        self._edPluginControlIntegration.setDataInput(xsDataIntegrationInput)
        self.executePluginSynchronous(self._edPluginControlIntegration)


    def doFailureEvaluationIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureEvaluationIndexing")
        strWarningMessage = "Execution of indexing evaluation plugin failed."
        self.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)


    def doFailureEvaluationIndexingLABELIT(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureEvaluationIndexing")
        strWarningMessage = "Execution of indexing evaluation plugin failed."
        self.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)


    def doSuccessGeneratePrediction(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessGeneratePrediction")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessGeneratePrediction")
        xsDataGeneratePredictionResult = _edPlugin.getDataOutput()
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult()
        xsDataIndexingResult.setPredictionResult(xsDataGeneratePredictionResult)


    def doFailureGeneratePrediction(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureGeneratePrediction")
        strWarningMessage = "Execution of generate prediction plugin failed."
        self.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        #self.addComment("warning: no prediction images")


    def doSuccessIntegration(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessIntegration")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessIntegration")
        # Wait for XDS plugin if necessary
        self._edPluginControlXDSGenerateBackgroundImage.synchronize()
        self.addStatusMessage("Integration successful.")
        xsDataIntegrationOutput = self._edPluginControlIntegration.getDataOutput()
        self._xsDataResultCharacterisation.setIntegrationResult(xsDataIntegrationOutput)
        # Integration short summary
        if self._edPluginControlIntegration.hasDataOutput("integrationShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlIntegration.getDataOutput("integrationShortSummary")[0].getValue()
        #self.DEBUG( self._xsDataExperimentCharacterisation.marshal() )
        if self._bDoStrategyCalculation:
            xsDataInputStrategy = XSDataInputStrategy()
            xsDataSolutionSelected = self._xsDataResultCharacterisation.getIndexingResult().getSelectedSolution()
            xsDataInputStrategy.setCrystalRefined(xsDataSolutionSelected.getCrystal())
            xsDataInputStrategy.setSample(self._xsDataResultCharacterisation.getDataCollection().getSample())
            xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult()
            xsDataInputStrategy.setBestFileContentDat(xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
            xsDataInputStrategy.setBestFileContentPar(xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
            xsDataInputStrategy.setExperimentalCondition(xsDataIntegrationSubWedgeResultList[0].getExperimentalConditionRefined())
            xsDataInputStrategy.setXdsBackgroundImage(self._xsDataFileXdsBackgroundImage)
            xsDataInputStrategy.setDataCollection(self._xsDataCollection)
            for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
                xsDataInputStrategy.addBestFileContentHKL(xsDataIntegrationSubWedgeResult.getBestfileHKL())
            xsDataInputStrategy.setDiffractionPlan(self._xsDataResultCharacterisation.getDataCollection().getDiffractionPlan())
            self._edPluginControlStrategy.setDataInput(xsDataInputStrategy)
            self.executePluginSynchronous(self._edPluginControlStrategy)



    def doFailureIntegration(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureIntegration")
        strErrorMessage = "Execution of integration plugin failed."
        self.addStatusMessage("Integration FAILURE.")
        self.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        #self.addComment("integration failure")
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.generateExecutiveSummary(self)
        self.setFailure()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
            self.writeDataOutput()


    def doSuccessXDSGenerateBackgroundImage(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessXDSGenerateBackgroundImage")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_3.doSuccessXDSGenerateBackgroundImage")
        self._xsDataFileXdsBackgroundImage = self._edPluginControlXDSGenerateBackgroundImage.getDataOutput().getXdsBackgroundImage()
        self._xsDataResultCharacterisation.setXdsBackgroundImage(self._xsDataFileXdsBackgroundImage)


    def doFailureXDSGenerateBackgroundImage(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureXDSGenerateBackgroundImage")


    def doSuccessStrategy(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doSuccessStrategy")
        self.retrieveSuccessMessages(self._edPluginControlStrategy, "EDPluginControlCharacterisationv1_3.doSuccessStrategy")
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlStrategy.getDataOutput("strategyShortSummary")[0].getValue()
        self.addStatusMessage("Strategy calculation successful.")


    def doFailureStrategy(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_3.doFailureStrategy")
        strErrorMessage = "Strategy calculation FAILURE."
        self.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            self._strCharacterisationShortSummary += self._edPluginControlStrategy.getDataOutput("strategyShortSummary")[0].getValue()
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.addStatusMessage("Strategy calculation FAILURE.")
        self.generateExecutiveSummary(self)
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
            self.writeDataOutput()
        self.setFailure()


    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_3.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
        xsDataFirstSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
        if xsDataBeam.getTransmission() is not None:
            fTransmission = xsDataBeam.getTransmission().getValue()
            if fTransmission < self._fMinTransmission:
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("WARNING! Transmission for characterisation set to %.1f %%" % fTransmission)
                self.addExecutiveSummaryLine("Please consider re-characterising with transmission set to 100 %")
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("^"*80)                
                self.addExecutiveSummaryLine("^"*80)                
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine("BEST complexity                       : %s" % xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine("Aimed completeness                    : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine("Required completeness                 : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution() is not None):
            self.addExecutiveSummaryLine("Aimed I/sigma at highest resolution   : %6.1f" % xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution().getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine("Aimed resolution                      : %6.1f [A]" % xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine("Required resolution                   : %6.1f [A]" % xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine("Aimed multiplicity                    : %6.1f" % xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine("Required multiplicity                 : %6.1f" % xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine("Forced space group                    : %6s" % xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection() is not None):
            self.addExecutiveSummaryLine("Max exposure time per data collection : %6.1f [s]" % xsDataDiffractionPlan.getMaxExposureTimePerDataCollection().getValue())
        self.addExecutiveSummarySeparator()
        if self._edPluginControlIndexingIndicators is not None:
            self.appendExecutiveSummary(self._edPluginControlIndexingIndicators, "")
        if self._edPluginControlIndexingLabelit is not None:
            self.appendExecutiveSummary(self._edPluginControlIndexingLabelit, "")
        if self._edPluginControlIntegration is not None:
            self.appendExecutiveSummary(self._edPluginControlIntegration, "")
        if self._edPluginControlStrategy is not None:
            self.appendExecutiveSummary(self._edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self._strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self._strStatusMessage != None:
                for strLine in self._strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine + ".")
            self.addExecutiveSummaryLine("")
            for strLine in self._strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary("Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()


    def getPluginStrategyName(self):
        return self._strPluginControlStrategy


    def addStatusMessage(self, _strStatusMessage):
        if self._strStatusMessage != "":
            self._strStatusMessage += " "
        self._strStatusMessage += _strStatusMessage
        
    def doStrategyCalculation(self, _bValue):
        self._bDoStrategyCalculation = _bValue
示例#21
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv1ResultCharacterisation':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setMxv1ResultCharacterisation(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv1ResultCharacterisation_Reference':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setMxv1ResultCharacterisation_Reference(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv2DataCollection':
         obj_ = XSDataCollection()
         obj_.build(child_)
         self.setMxv2DataCollection(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'mxv2DataCollection_Reference':
         obj_ = XSDataCollection()
         obj_.build(child_)
         self.setMxv2DataCollection_Reference(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'suggestedStrategy':
         obj_ = XSDataResultStrategy()
         obj_.build(child_)
         self.setSuggestedStrategy(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
      nodeName_ == 'possibleOrientations':
         obj_ = kappa_alignment_response()
         obj_.build(child_)
         self.setPossibleOrientations(obj_)
     XSDataResultInterface.buildChildren(self, child_, nodeName_)
示例#22
0
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'characterisationResult':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setCharacterisationResult(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'fileGraph':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.fileGraph.append(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'helicalDistance':
         obj_ = XSDataDouble()
         obj_.build(child_)
         self.setHelicalDistance(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'logFile':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.setLogFile(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
 def buildChildren(self, child_, nodeName_):
     if child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'characterisationResult':
         obj_ = XSDataResultCharacterisation()
         obj_.build(child_)
         self.setCharacterisationResult(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'fileGraph':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.fileGraph.append(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'helicalDistance':
         obj_ = XSDataDouble()
         obj_.build(child_)
         self.setHelicalDistance(obj_)
     elif child_.nodeType == Node.ELEMENT_NODE and \
         nodeName_ == 'logFile':
         obj_ = XSDataFile()
         obj_.build(child_)
         self.setLogFile(obj_)
     XSDataInput.buildChildren(self, child_, nodeName_)
示例#24
0
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlCharacterisationv1_6.preProcess")
     self._xsDataResultCharacterisation = XSDataResultCharacterisation()
示例#25
0
class EDPluginControlCharacterisationv1_4(EDPluginControl):
    """
    [To be replaced with a description of EDPluginControlTemplatev10]
    """
    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self._strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv1_1"
        self._strPluginExecEvaluationIndexing = "EDPluginExecEvaluationIndexingv10"
        self._strPluginControlIndexingMOSFLM = "EDPluginControlIndexingMOSFLMv10"
        self._strPluginControlGeneratePrediction = "EDPluginControlGeneratePredictionv10"
        self._strPluginControlIntegration = "EDPluginControlIntegrationv10"
        self._strPluginControlXDSGenerateBackgroundImage = "EDPluginControlXDSGenerateBackgroundImagev1_0"
        self._strPluginControlStrategy = "EDPluginControlStrategyv1_2"
        self._strPluginGenerateThumbnailName = "EDPluginMXThumbnailv1_1"
        self._strPluginControlKappaName = "EDPluginControlKappav1_0"
        self._listPluginGenerateThumbnail = []
        self._edPluginControlIndexingIndicators = None
        self._edPluginExecEvaluationIndexingMOSFLM = None
        self._edPluginExecEvaluationIndexingLABELIT = None
        self._edPluginControlGeneratePrediction = None
        self._edPluginControlIntegration = None
        self._edPluginControlXDSGenerateBackgroundImage = None
        self._edPluginControlStrategy = None
        self._edPluginControlKappa = None
        self._xsDataCollection = None
        self._xsDataResultCharacterisation = None
        self._xsDataIndexingResultMOSFLM = None
        self._xsDataCrystal = None
        self._strCharacterisationShortSummary = ""
        self._strStatusMessage = ""
        self._xsDataFileXdsBackgroundImage = None
        self._bDoStrategyCalculation = True
        self._fMinTransmission = 10  # %
        self._iNoReferenceImages = None
        self._iNoImagesWithDozorScore = None
        self._strMxCuBE_URI = None
        self._oServerProxy = None
        self._runKappa = False
        self._bDoOnlyMoslmfIndexing = False

    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_4.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(),
                                      "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(),
                                      "dataCollection")
        self.checkMandatoryParameters(
            self.getDataInput().getDataCollection().getDiffractionPlan(),
            "diffractionPlan")

    def configure(self):
        """
        Gets the configuration parameters (if any).
        """
        EDPluginControl.configure(self)
        self.DEBUG("EDPluginControlCharacterisationv1_4.configure")
        self._strMxCuBE_URI = self.config.get("mxCuBE_URI", None)
        if self._strMxCuBE_URI is not None and "mxCuBE_XMLRPC_log" in os.environ.keys(
        ):
            self.DEBUG(
                "Enabling sending messages to mxCuBE via URI {0}".format(
                    self._strMxCuBE_URI))
            self._oServerProxy = ServerProxy(self._strMxCuBE_URI)
        self._runKappa = self.config.get("runKappa", False)
        self._fMinTransmission = self.config.get("minTransmissionWarning",
                                                 self._fMinTransmission)
        self._bDoOnlyMoslmfIndexing = self.config.get("doOnlyMosflmIndexing",
                                                      False)

    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_4.preProcess")
        self._xsDataResultCharacterisation = XSDataResultCharacterisation()
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlIndexingMOSFLM = self.loadPlugin(self._strPluginControlIndexingMOSFLM, \
                                                                   "IndexingMOSFLM")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if self._runKappa:
            self._edPluginControlKappa = self.loadPlugin(
                self._strPluginControlKappaName, "Kappa")
        if (self._edPluginControlIndexingIndicators is not None):
            self.DEBUG("EDPluginControlCharacterisationv1_4.preProcess: " +
                       self._strPluginControlIndexingIndicators +
                       " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection(
            )
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition(
            ).getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^" * 80
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %"
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.sendMessageToMXCuBE(strWarningMessage1, "warning")
                    self.sendMessageToMXCuBE(strWarningMessage2, "warning")
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_4.preProcess: No subwedges in input data."
                self.ERROR(strError)
                self.setFailure()
            else:
                # Load the thumbnail plugins
                self._iNoReferenceImages = 0
                for subWedge in xsDataInputCharacterisation.dataCollection.subWedge:
                    for image in subWedge.image:
                        self._iNoReferenceImages += 1
                        edPluginJpeg = self.loadPlugin(
                            self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(1024)
                        xsDataInputMXThumbnail.width = XSDataInteger(1024)
                        jpegFilename = os.path.splitext(
                            os.path.basename(image.path.value))[0] + ".jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(
                            XSDataString(
                                os.path.join(self.getWorkingDirectory(),
                                             jpegFilename)))
                        edPluginJpeg.dataInput = xsDataInputMXThumbnail
                        edPluginThumnail = self.loadPlugin(
                            self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(256)
                        xsDataInputMXThumbnail.width = XSDataInteger(256)
                        thumbnailFilename = os.path.splitext(
                            os.path.basename(
                                image.path.value))[0] + ".thumbnail.jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(
                            XSDataString(
                                os.path.join(self.getWorkingDirectory(),
                                             thumbnailFilename)))
                        edPluginThumnail.dataInput = xsDataInputMXThumbnail
                        self._listPluginGenerateThumbnail.append(
                            (image, edPluginJpeg, edPluginThumnail))
                        edPluginJpeg.execute()
                        edPluginThumnail.execute()
                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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        self.ERROR(strErrorMessage)
                        self.sendMessageToMXCuBE(strErrorMessage, "error")
                        self.addErrorMessage(
                            "EDPluginControlCharacterisationv1_4.preProcess ERROR: "
                            + strErrorMessage)
                        # self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan(
                )
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup(
                )
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(
                    self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(
                        self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation.setDataCollection(
                    XSDataCollection.parseString(
                        self._xsDataCollection.marshal()))

    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlCharacterisationv1_4.process")
        self._edPluginControlIndexingIndicators.connectSUCCESS(
            self.doSuccessIndexingIndicators)
        self._edPluginControlIndexingIndicators.connectFAILURE(
            self.doFailureIndexingIndicators)
        self._edPluginExecEvaluationIndexingLABELIT.connectSUCCESS(
            self.doSuccessEvaluationIndexingLABELIT)
        self._edPluginExecEvaluationIndexingLABELIT.connectFAILURE(
            self.doFailureEvaluationIndexingLABELIT)
        self._edPluginControlIndexingMOSFLM.connectSUCCESS(
            self.doSuccessIndexingMOSFLM)
        self._edPluginControlIndexingMOSFLM.connectFAILURE(
            self.doFailureIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingMOSFLM.connectSUCCESS(
            self.doSuccessEvaluationIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingMOSFLM.connectFAILURE(
            self.doFailureEvaluationIndexingMOSFLM)
        self._edPluginControlGeneratePrediction.connectSUCCESS(
            self.doSuccessGeneratePrediction)
        self._edPluginControlGeneratePrediction.connectFAILURE(
            self.doFailureGeneratePrediction)
        self._edPluginControlIntegration.connectSUCCESS(
            self.doSuccessIntegration)
        self._edPluginControlIntegration.connectFAILURE(
            self.doFailureIntegration)
        self._edPluginControlXDSGenerateBackgroundImage.connectSUCCESS(
            self.doSuccessXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.connectFAILURE(
            self.doFailureXDSGenerateBackgroundImage)
        self._edPluginControlStrategy.connectSUCCESS(self.doSuccessStrategy)
        self._edPluginControlStrategy.connectFAILURE(self.doFailureStrategy)
        self.executePluginSynchronous(self._edPluginControlIndexingIndicators)

    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_4.finallyProcess")
        # Synchronize thumbnail plugins
        for tuplePlugin in self._listPluginGenerateThumbnail:
            image = tuplePlugin[0]
            tuplePlugin[1].synchronize()
            jpegImage = image.copy()
            jpegImage.path = tuplePlugin[1].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addJpegImage(jpegImage)
            tuplePlugin[2].synchronize()
            thumbnailImage = image.copy()
            thumbnailImage.path = tuplePlugin[2].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addThumbnailImage(
                thumbnailImage)
        if self._edPluginControlGeneratePrediction.isRunning():
            self._edPluginControlGeneratePrediction.synchronize()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage),
                               "statusMessage")
            self._xsDataResultCharacterisation.setStatusMessage(
                XSDataString(self._strStatusMessage))
        if self._strCharacterisationShortSummary != None:
            self.setDataOutput(
                XSDataString(self._strCharacterisationShortSummary),
                "shortSummary")
            self._xsDataResultCharacterisation.setShortSummary(
                XSDataString(self._strCharacterisationShortSummary))
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        if self.isFailure():
            self.sendMessageToMXCuBE("Ended with error messages", "error")

    def doSuccessIndexingIndicators(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doSuccessIndexingIndicators")
        # self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_4.doSuccessIndexingIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput(
                "indexingResult"):
            xsDataIndexingResult = self._edPluginControlIndexingIndicators.getDataOutput(
                "indexingResult")[0]
            # self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
            self._edPluginExecEvaluationIndexingLABELIT.setDataInput(
                xsDataIndexingResult, "indexingResult")
        if self._edPluginControlIndexingIndicators.hasDataOutput(
                "imageQualityIndicators"):
            listXSDataImageQualityIndicators = self._edPluginControlIndexingIndicators.getDataOutput(
                "imageQualityIndicators")
            for xsDataImageQualityIndicators in listXSDataImageQualityIndicators:
                if xsDataImageQualityIndicators.dozor_score:
                    if self._iNoImagesWithDozorScore is None:
                        self._iNoImagesWithDozorScore = 0
                    if xsDataImageQualityIndicators.dozor_score.value > 0.001:
                        self._iNoImagesWithDozorScore += 1
                self._xsDataResultCharacterisation.addImageQualityIndicators(
                    xsDataImageQualityIndicators)
                self._edPluginExecEvaluationIndexingLABELIT.setDataInput(
                    xsDataImageQualityIndicators, "imageQualityIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput(
                "indicatorsShortSummary"):
            indicatorsShortSummary = self._edPluginControlIndexingIndicators.getDataOutput(
                "indicatorsShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += indicatorsShortSummary
            self.sendMessageToMXCuBE(indicatorsShortSummary)
        self.executePluginSynchronous(
            self._edPluginExecEvaluationIndexingLABELIT)

    def doFailureIndexingIndicators(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.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:
            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.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 doSuccessIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doSuccessIndexingMOSFLM")
        xsDataIndexingResult = self._edPluginControlIndexingMOSFLM.dataOutput
        self._edPluginExecEvaluationIndexingMOSFLM.setDataInput(
            xsDataIndexingResult, "indexingResult")
        self.executePluginSynchronous(
            self._edPluginExecEvaluationIndexingMOSFLM)

    def doFailureIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doFailureIndexingMOSFLM")
        strErrorMessage = "Indexing with MOSFLM failed."
        self.ERROR(strErrorMessage)
        self.sendMessageToMXCuBE(strErrorMessage, "error")
        self.executePluginSynchronous(
            self._edPluginExecEvaluationIndexingMOSFLM)

    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 doSuccessEvaluationIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doSuccessEvaluationIndexingMOSFLM"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_4.doSuccessEvaluationIndexingMOSFLM"
        )
        # Retrieve status messages (if any)
        if self._edPluginExecEvaluationIndexingMOSFLM.hasDataOutput(
                "statusMessageIndexing"):
            self.addStatusMessage(
                "MOSFLM: " +
                self._edPluginExecEvaluationIndexingMOSFLM.getDataOutput(
                    "statusMessageIndexing")[0].getValue())
        # Check if indexing was successful
        bIndexingSuccess = self._edPluginExecEvaluationIndexingMOSFLM.getDataOutput(
            "indexingSuccess")[0].getValue()
        if bIndexingSuccess:
            xsDataIndexingResult = self._edPluginExecEvaluationIndexingMOSFLM.getDataOutput(
                "indexingResult")[0]
            self._xsDataResultCharacterisation.setIndexingResult(
                xsDataIndexingResult)
            self._strCharacterisationShortSummary += self.generateIndexingShortSummary(
                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"):
                self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput(
                    "indexingShortSummary")[0].getValue()
            # 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:
            strErrorMessage = "Execution of indexing with MOSFLM 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 generateIndexingShortSummary(self, _xsDataIndexingResult):
        """
        Generates a very short summary of the indexing
        """
        strIndexingShortSummary = ""
        if self.hasDataInput("crystal"):
            xsDataCrystal = self.getDataInput("crystal")[0]
            if xsDataCrystal.getSpaceGroup() is not None:
                strForcedSpaceGroup = xsDataCrystal.getSpaceGroup().getName(
                ).getValue().upper()
                if xsDataCrystal.getSpaceGroup().getName().getValue() != "":
                    strIndexingShortSummary += "Forced space group: %s\n" % strForcedSpaceGroup
        if _xsDataIndexingResult is not None:
            # Indexing solution
            xsDataSelectedSolution = _xsDataIndexingResult.getSelectedSolution(
            )
            xsDataCrystal = xsDataSelectedSolution.getCrystal()
            # Refined cell parameters
            xsDataCell = xsDataCrystal.getCell()
            fA = xsDataCell.getLength_a().getValue()
            fB = xsDataCell.getLength_b().getValue()
            fC = xsDataCell.getLength_c().getValue()
            fAlpha = xsDataCell.getAngle_alpha().getValue()
            fBeta = xsDataCell.getAngle_beta().getValue()
            fGamma = xsDataCell.getAngle_gamma().getValue()
            # Estimated mosaicity
            fEstimatedMosaicity = xsDataCrystal.getMosaicity().getValue()
            # Space group
            strSpaceGroup = xsDataCrystal.getSpaceGroup().getName().getValue()
            # Spot deviation
            xsDataStatisticsIndexing = xsDataSelectedSolution.getStatistics()
            fSpotDeviationPositional = xsDataStatisticsIndexing.getSpotDeviationPositional(
            ).getValue()
            strIndexingShortSummary += "Indexing: laue/space group %s, mosaicity %.2f [degree], " % (
                strSpaceGroup, fEstimatedMosaicity)
            strIndexingShortSummary += "RMS dev pos %.2f [mm]" % fSpotDeviationPositional
            if xsDataStatisticsIndexing.getSpotDeviationAngular() is not None:
                fSpotDeviationAngular = xsDataStatisticsIndexing.getSpotDeviationAngular(
                ).getValue()
                strIndexingShortSummary += " ang %.2f [degree]" % fSpotDeviationAngular
            strIndexingShortSummary += "\n"
            strIndexingShortSummary += "Indexing: refined Cell: %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n" % (
                fA, fB, fC, fAlpha, fBeta, fGamma)
        else:
            strIndexingShortSummary += "Indexing failed."
        return strIndexingShortSummary

    def indexingToIntegration(self, _edPlugin=None):
        # Run Kappa if configured
        if self._runKappa:
            xsDataInputControlKappa = XSDataInputControlKappa()
            xsDataInputControlKappa.dataCollection = self._xsDataCollection
            xsDataInputControlKappa.selectedSolution = self._xsDataResultCharacterisation.indexingResult.selectedSolution
            self._edPluginControlKappa.dataInput = xsDataInputControlKappa
            self.executePluginSynchronous(self._edPluginControlKappa)
            if not self._edPluginControlKappa.isFailure():
                self._xsDataResultCharacterisation.kappaReorientation = self._edPluginControlKappa.dataOutput
        # Create the XDS background image
        xsDataInputControlXDSGenerateBackgroundImage = XSDataInputControlXDSGenerateBackgroundImage(
        )
        xsDataInputControlXDSGenerateBackgroundImage.setDataCollection(
            self._xsDataCollection)
        self._edPluginControlXDSGenerateBackgroundImage.setDataInput(
            xsDataInputControlXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.execute()
        # Integrate the reference images
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(
            self._xsDataResultCharacterisation.getDataCollection())
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult(
        )
        xsDataExperimentalConditionRefinded = xsDataIndexingResult.getSelectedSolution(
        ).getExperimentalConditionRefined()
        xsDataIntegrationInput.setExperimentalConditionRefined(
            xsDataExperimentalConditionRefinded)
        xsDataIntegrationInput.setSelectedIndexingSolution(
            xsDataIndexingResult.getSelectedSolution())
        self._edPluginControlIntegration.setDataInput(xsDataIntegrationInput)
        self.executePluginSynchronous(self._edPluginControlIntegration)

    def doFailureEvaluationIndexingLABELIT(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doFailureEvaluationIndexing")
        strErrorMessage = "Execution of indexing evaluation plugin failed."
        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 doFailureEvaluationIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doFailureEvaluationIndexingMOSFLM"
        )
        strErrorMessage = "Execution of indexing evaluation plugin failed."
        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 doSuccessGeneratePrediction(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doSuccessGeneratePrediction")
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_4.doSuccessGeneratePrediction")
        xsDataGeneratePredictionResult = _edPlugin.getDataOutput()
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult(
        )
        xsDataIndexingResult.setPredictionResult(
            xsDataGeneratePredictionResult)

    def doFailureGeneratePrediction(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doFailureGeneratePrediction")
        strWarningMessage = "Execution of generate prediction plugin failed."
        self.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        # self.addComment("warning: no prediction images")

    def doSuccessIntegration(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_4.doSuccessIntegration")
        self.retrieveSuccessMessages(
            self._edPluginControlIntegration,
            "EDPluginControlCharacterisationv1_4.doSuccessIntegration")
        # Wait for XDS plugin if necessary
        self._edPluginControlXDSGenerateBackgroundImage.synchronize()
        self.addStatusMessage("Integration successful.")
        xsDataIntegrationOutput = self._edPluginControlIntegration.getDataOutput(
        )
        self._xsDataResultCharacterisation.setIntegrationResult(
            xsDataIntegrationOutput)
        # Integration short summary
        if self._edPluginControlIntegration.hasDataOutput(
                "integrationShortSummary"):
            integrationShortSummary = self._edPluginControlIntegration.getDataOutput(
                "integrationShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += integrationShortSummary
            self.sendMessageToMXCuBE(integrationShortSummary)
        # self.DEBUG( self._xsDataExperimentCharacterisation.marshal() )
        if self._bDoStrategyCalculation:
            xsDataInputStrategy = XSDataInputStrategy()
            xsDataSolutionSelected = self._xsDataResultCharacterisation.getIndexingResult(
            ).getSelectedSolution()
            xsDataInputStrategy.setCrystalRefined(
                xsDataSolutionSelected.getCrystal())
            xsDataInputStrategy.setSample(self._xsDataResultCharacterisation.
                                          getDataCollection().getSample())
            xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult(
            )
            bFirst = True
            for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
                if xsDataIntegrationSubWedgeResult.getBestfileHKL(
                ) is not None:
                    xsDataInputStrategy.addBestFileContentHKL(
                        xsDataIntegrationSubWedgeResult.getBestfileHKL())
                    if bFirst:
                        xsDataInputStrategy.setBestFileContentDat(
                            xsDataIntegrationSubWedgeResult.getBestfileDat())
                        xsDataInputStrategy.setBestFileContentPar(
                            xsDataIntegrationSubWedgeResult.getBestfilePar())
                        xsDataInputStrategy.setExperimentalCondition(
                            xsDataIntegrationSubWedgeResult.
                            getExperimentalConditionRefined())
                        bFirst = False
            xsDataInputStrategy.setXdsBackgroundImage(
                self._xsDataFileXdsBackgroundImage)
            xsDataInputStrategy.setDataCollection(self._xsDataCollection)
            xsDataInputStrategy.setDiffractionPlan(
                self._xsDataResultCharacterisation.getDataCollection(
                ).getDiffractionPlan())
            self._edPluginControlStrategy.setDataInput(xsDataInputStrategy)
            self.executePluginSynchronous(self._edPluginControlStrategy)

    def doFailureIntegration(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_4.doFailureIntegration")
        strErrorMessage = "Execution of integration failed."
        self.addStatusMessage("Integration FAILURE.")
        self.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        # self.addComment("integration failure")
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.generateExecutiveSummary(self)
        self.setFailure()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage),
                               "statusMessage")
            self.writeDataOutput()

    def doSuccessXDSGenerateBackgroundImage(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doSuccessXDSGenerateBackgroundImage"
        )
        self.retrieveSuccessMessages(
            _edPlugin,
            "EDPluginControlCharacterisationv1_4.doSuccessXDSGenerateBackgroundImage"
        )
        self._xsDataFileXdsBackgroundImage = self._edPluginControlXDSGenerateBackgroundImage.getDataOutput(
        ).getXdsBackgroundImage()
        self._xsDataResultCharacterisation.setXdsBackgroundImage(
            self._xsDataFileXdsBackgroundImage)

    def doFailureXDSGenerateBackgroundImage(self, _edPlugin=None):
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.doFailureXDSGenerateBackgroundImage"
        )

    def doSuccessStrategy(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_4.doSuccessStrategy")
        self.retrieveSuccessMessages(
            self._edPluginControlStrategy,
            "EDPluginControlCharacterisationv1_4.doSuccessStrategy")
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(
            xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            strategyShortSummary = self._edPluginControlStrategy.getDataOutput(
                "strategyShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += strategyShortSummary
            self.sendMessageToMXCuBE(strategyShortSummary)
        self.addStatusMessage("Strategy calculation successful.")

    def doFailureStrategy(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_4.doFailureStrategy")
        strErrorMessage = "Strategy calculation FAILURE."
        self.ERROR(strErrorMessage)
        self.sendMessageToMXCuBE(strErrorMessage, "error")
        self.addErrorMessage(strErrorMessage)
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(
            xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            strategyShortSummary = self._edPluginControlStrategy.getDataOutput(
                "strategyShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += strategyShortSummary
            self.sendMessageToMXCuBE(strategyShortSummary)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.addStatusMessage("Strategy calculation FAILURE.")
        self.generateExecutiveSummary(self)
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage),
                               "statusMessage")
            self.writeDataOutput()
        self.setFailure()

    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        self.DEBUG(
            "EDPluginControlCharacterisationv1_4.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
        xsDataFirstSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
        if xsDataBeam.getTransmission() is not None:
            fTransmission = xsDataBeam.getTransmission().getValue()
            if fTransmission < self._fMinTransmission:
                self.addExecutiveSummaryLine("^" * 80)
                self.addExecutiveSummaryLine("^" * 80)
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine(
                    "WARNING! Transmission for characterisation set to %.1f %%"
                    % fTransmission)
                self.addExecutiveSummaryLine(
                    "Please consider re-characterising with transmission set to 100 %"
                )
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("^" * 80)
                self.addExecutiveSummaryLine("^" * 80)
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine(
                "BEST complexity                       : %s" %
                xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Aimed completeness                    : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine(
                "Required completeness                 : %6.1f [%%]" %
                (100.0 *
                 xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution()
                is not None):
            self.addExecutiveSummaryLine(
                "Aimed I/sigma at highest resolution   : %6.1f" %
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution(
                ).getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine(
                "Aimed resolution                      : %6.1f [A]" %
                xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine(
                "Required resolution                   : %6.1f [A]" %
                xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Aimed multiplicity                    : %6.1f" %
                xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine(
                "Required multiplicity                 : %6.1f" %
                xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine(
                "Forced space group                    : %6s" %
                xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection()
                is not None):
            self.addExecutiveSummaryLine(
                "Max exposure time per data collection : %6.1f [s]" %
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection(
                ).getValue())
        self.addExecutiveSummarySeparator()
        if self._edPluginControlIndexingIndicators is not None:
            self.appendExecutiveSummary(
                self._edPluginControlIndexingIndicators, "")
        if self._edPluginControlIntegration is not None:
            self.appendExecutiveSummary(self._edPluginControlIntegration, "")
        if self._edPluginControlStrategy is not None:
            self.appendExecutiveSummary(self._edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self._strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self._strStatusMessage != None:
                for strLine in self._strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine + ".")
            self.addExecutiveSummaryLine("")
            for strLine in self._strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary(
            "Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()

    def getPluginStrategyName(self):
        return self._strPluginControlStrategy

    def addStatusMessage(self, _strStatusMessage):
        if self._strStatusMessage != "":
            self._strStatusMessage += " "
        self._strStatusMessage += _strStatusMessage
        self.sendMessageToMXCuBE(_strStatusMessage)

    def doStrategyCalculation(self, _bValue):
        self._bDoStrategyCalculation = _bValue

    def sendMessageToMXCuBE(self, _strMessage, level="info"):
        # Only for mxCuBE
        if self._strMxCuBE_URI is not None:
            self.DEBUG("Sending message to mxCuBE: {0}".format(_strMessage))
            try:
                for strMessage in _strMessage.split("\n"):
                    if strMessage != "":
                        self._oServerProxy.log_message(
                            "Characterisation: " + strMessage, level)
            except:
                self.DEBUG("Sending message to mxCuBE failed!")
示例#26
0
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_4.preProcess")
        self._xsDataResultCharacterisation = XSDataResultCharacterisation()
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlIndexingMOSFLM = self.loadPlugin(self._strPluginControlIndexingMOSFLM, \
                                                                   "IndexingMOSFLM")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if self._runKappa:
            self._edPluginControlKappa = self.loadPlugin(
                self._strPluginControlKappaName, "Kappa")
        if (self._edPluginControlIndexingIndicators is not None):
            self.DEBUG("EDPluginControlCharacterisationv1_4.preProcess: " +
                       self._strPluginControlIndexingIndicators +
                       " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection(
            )
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition(
            ).getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^" * 80
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %"
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.sendMessageToMXCuBE(strWarningMessage1, "warning")
                    self.sendMessageToMXCuBE(strWarningMessage2, "warning")
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_4.preProcess: No subwedges in input data."
                self.ERROR(strError)
                self.setFailure()
            else:
                # Load the thumbnail plugins
                self._iNoReferenceImages = 0
                for subWedge in xsDataInputCharacterisation.dataCollection.subWedge:
                    for image in subWedge.image:
                        self._iNoReferenceImages += 1
                        edPluginJpeg = self.loadPlugin(
                            self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(1024)
                        xsDataInputMXThumbnail.width = XSDataInteger(1024)
                        jpegFilename = os.path.splitext(
                            os.path.basename(image.path.value))[0] + ".jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(
                            XSDataString(
                                os.path.join(self.getWorkingDirectory(),
                                             jpegFilename)))
                        edPluginJpeg.dataInput = xsDataInputMXThumbnail
                        edPluginThumnail = self.loadPlugin(
                            self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(256)
                        xsDataInputMXThumbnail.width = XSDataInteger(256)
                        thumbnailFilename = os.path.splitext(
                            os.path.basename(
                                image.path.value))[0] + ".thumbnail.jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(
                            XSDataString(
                                os.path.join(self.getWorkingDirectory(),
                                             thumbnailFilename)))
                        edPluginThumnail.dataInput = xsDataInputMXThumbnail
                        self._listPluginGenerateThumbnail.append(
                            (image, edPluginJpeg, edPluginThumnail))
                        edPluginJpeg.execute()
                        edPluginThumnail.execute()
                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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        self.ERROR(strErrorMessage)
                        self.sendMessageToMXCuBE(strErrorMessage, "error")
                        self.addErrorMessage(
                            "EDPluginControlCharacterisationv1_4.preProcess ERROR: "
                            + strErrorMessage)
                        # self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan(
                )
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup(
                )
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(
                    self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(
                        self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation.setDataCollection(
                    XSDataCollection.parseString(
                        self._xsDataCollection.marshal()))
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_5.preProcess")
        self._xsDataResultCharacterisation = XSDataResultCharacterisation()
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlIndexingMOSFLM = self.loadPlugin(self._strPluginControlIndexingMOSFLM, \
                                                                   "IndexingMOSFLM")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if self._runKappa:
            self._edPluginControlKappa = self.loadPlugin(self._strPluginControlKappaName, "Kappa")
        if (self._edPluginControlIndexingIndicators is not None):
            self.DEBUG("EDPluginControlCharacterisationv1_5.preProcess: " + self._strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^"*80
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %"
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.sendMessageToMXCuBE(strWarningMessage1, "warning")
                    self.sendMessageToMXCuBE(strWarningMessage2, "warning")
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_5.preProcess: No subwedges in input data."
                self.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        self.ERROR(strErrorMessage)
                        self.sendMessageToMXCuBE(strErrorMessage, "error")
                        self.addErrorMessage("EDPluginControlCharacterisationv1_5.preProcess ERROR: " + strErrorMessage)
                        # self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self._xsDataCollection.marshal()))
            # Load the thumbnail plugins
            self._iNoReferenceImages = 0
            if not self.isFailure():
                for subWedge in xsDataInputCharacterisation.dataCollection.subWedge:
                    for image in subWedge.image:
                        self._iNoReferenceImages += 1
                        edPluginJpeg = self.loadPlugin(self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(1024)
                        xsDataInputMXThumbnail.width = XSDataInteger(1024)
                        jpegFilename = os.path.splitext(os.path.basename(image.path.value))[0] + ".jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), jpegFilename)))
                        edPluginJpeg.dataInput = xsDataInputMXThumbnail
                        edPluginThumnail = self.loadPlugin(self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(256)
                        xsDataInputMXThumbnail.width = XSDataInteger(256)
                        thumbnailFilename = os.path.splitext(os.path.basename(image.path.value))[0] + ".thumbnail.jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), thumbnailFilename)))
                        edPluginThumnail.dataInput = xsDataInputMXThumbnail
                        self._listPluginGenerateThumbnail.append((image, edPluginJpeg, edPluginThumnail))
class EDPluginControlCharacterisationv1_5(EDPluginControl):
    """
    [To be replaced with a description of EDPluginControlTemplatev10]
    """


    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self._strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv1_1"
        self._strPluginExecEvaluationIndexing = "EDPluginExecEvaluationIndexingv10"
        self._strPluginControlIndexingMOSFLM = "EDPluginControlIndexingMOSFLMv10"
        self._strPluginControlGeneratePrediction = "EDPluginControlGeneratePredictionv10"
        self._strPluginControlIntegration = "EDPluginControlIntegrationv10"
        self._strPluginControlXDSGenerateBackgroundImage = "EDPluginControlXDSGenerateBackgroundImagev1_0"
        self._strPluginControlStrategy = "EDPluginControlStrategyv1_3"
        self._strPluginGenerateThumbnailName = "EDPluginMXThumbnailv1_1"
        self._strPluginControlKappaName = "EDPluginControlKappav1_0"
        self._listPluginGenerateThumbnail = []
        self._edPluginControlIndexingIndicators = None
        self._edPluginExecEvaluationIndexingMOSFLM = None
        self._edPluginExecEvaluationIndexingLABELIT = None
        self._edPluginControlGeneratePrediction = None
        self._edPluginControlIntegration = None
        self._edPluginControlXDSGenerateBackgroundImage = None
        self._edPluginControlStrategy = None
        self._edPluginControlKappa = None
        self._xsDataCollection = None
        self._xsDataResultCharacterisation = None
        self._xsDataIndexingResultMOSFLM = None
        self._xsDataCrystal = None
        self._strCharacterisationShortSummary = ""
        self._strStatusMessage = ""
        self._xsDataFileXdsBackgroundImage = None
        self._bDoStrategyCalculation = True
        self._fMinTransmission = 10  # %
        self._iNoReferenceImages = None
        self._iNoImagesWithDozorScore = None
        self._strMxCuBE_URI = None
        self._oServerProxy = None
        self._runKappa = False


    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_5.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection().getDiffractionPlan(), "diffractionPlan")

    def configure(self):
        """
        Gets the configuration parameters (if any).
        """
        EDPluginControl.configure(self)
        self.DEBUG("EDPluginControlCharacterisationv1_5.configure")
        self._strMxCuBE_URI = self.config.get("mxCuBE_URI", None)
        if self._strMxCuBE_URI is not None and "mxCuBE_XMLRPC_log" in os.environ.keys():
            self.DEBUG("Enabling sending messages to mxCuBE via URI {0}".format(self._strMxCuBE_URI))
            self._oServerProxy = xmlrpclib.ServerProxy(self._strMxCuBE_URI)
        self._runKappa = self.config.get("runKappa", False)
        self._fMinTransmission = self.config.get("minTransmissionWarning", self._fMinTransmission)



    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_5.preProcess")
        self._xsDataResultCharacterisation = XSDataResultCharacterisation()
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlIndexingMOSFLM = self.loadPlugin(self._strPluginControlIndexingMOSFLM, \
                                                                   "IndexingMOSFLM")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if self._runKappa:
            self._edPluginControlKappa = self.loadPlugin(self._strPluginControlKappaName, "Kappa")
        if (self._edPluginControlIndexingIndicators is not None):
            self.DEBUG("EDPluginControlCharacterisationv1_5.preProcess: " + self._strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^"*80
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %"
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.sendMessageToMXCuBE(strWarningMessage1, "warning")
                    self.sendMessageToMXCuBE(strWarningMessage2, "warning")
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_5.preProcess: No subwedges in input data."
                self.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        self.ERROR(strErrorMessage)
                        self.sendMessageToMXCuBE(strErrorMessage, "error")
                        self.addErrorMessage("EDPluginControlCharacterisationv1_5.preProcess ERROR: " + strErrorMessage)
                        # self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self._xsDataCollection.marshal()))
            # Load the thumbnail plugins
            self._iNoReferenceImages = 0
            if not self.isFailure():
                for subWedge in xsDataInputCharacterisation.dataCollection.subWedge:
                    for image in subWedge.image:
                        self._iNoReferenceImages += 1
                        edPluginJpeg = self.loadPlugin(self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(1024)
                        xsDataInputMXThumbnail.width = XSDataInteger(1024)
                        jpegFilename = os.path.splitext(os.path.basename(image.path.value))[0] + ".jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), jpegFilename)))
                        edPluginJpeg.dataInput = xsDataInputMXThumbnail
                        edPluginThumnail = self.loadPlugin(self._strPluginGenerateThumbnailName)
                        xsDataInputMXThumbnail = XSDataInputMXThumbnail()
                        xsDataInputMXThumbnail.image = XSDataFile(image.path)
                        xsDataInputMXThumbnail.height = XSDataInteger(256)
                        xsDataInputMXThumbnail.width = XSDataInteger(256)
                        thumbnailFilename = os.path.splitext(os.path.basename(image.path.value))[0] + ".thumbnail.jpg"
                        xsDataInputMXThumbnail.outputPath = XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), thumbnailFilename)))
                        edPluginThumnail.dataInput = xsDataInputMXThumbnail
                        self._listPluginGenerateThumbnail.append((image, edPluginJpeg, edPluginThumnail))


    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlCharacterisationv1_5.process")
        self._edPluginControlIndexingIndicators.connectSUCCESS(self.doSuccessIndexingIndicators)
        self._edPluginControlIndexingIndicators.connectFAILURE(self.doFailureIndexingIndicators)
        self._edPluginExecEvaluationIndexingLABELIT.connectSUCCESS(self.doSuccessEvaluationIndexingLABELIT)
        self._edPluginExecEvaluationIndexingLABELIT.connectFAILURE(self.doFailureEvaluationIndexingLABELIT)
        self._edPluginControlIndexingMOSFLM.connectSUCCESS(self.doSuccessIndexingMOSFLM)
        self._edPluginControlIndexingMOSFLM.connectFAILURE(self.doFailureIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingMOSFLM.connectSUCCESS(self.doSuccessEvaluationIndexingMOSFLM)
        self._edPluginExecEvaluationIndexingMOSFLM.connectFAILURE(self.doFailureEvaluationIndexingMOSFLM)
        self._edPluginControlGeneratePrediction.connectSUCCESS(self.doSuccessGeneratePrediction)
        self._edPluginControlGeneratePrediction.connectFAILURE(self.doFailureGeneratePrediction)
        self._edPluginControlIntegration.connectSUCCESS(self.doSuccessIntegration)
        self._edPluginControlIntegration.connectFAILURE(self.doFailureIntegration)
        self._edPluginControlXDSGenerateBackgroundImage.connectSUCCESS(self.doSuccessXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.connectFAILURE(self.doFailureXDSGenerateBackgroundImage)
        self._edPluginControlStrategy.connectSUCCESS(self.doSuccessStrategy)
        self._edPluginControlStrategy.connectFAILURE(self.doFailureStrategy)
        self.executePluginSynchronous(self._edPluginControlIndexingIndicators)


    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_5.finallyProcess")
        # Synchronize thumbnail plugins
        for tuplePlugin in self._listPluginGenerateThumbnail:
            image = tuplePlugin[0]
            tuplePlugin[1].synchronize()
            jpegImage = image.copy()
            jpegImage.path = tuplePlugin[1].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addJpegImage(jpegImage)
            tuplePlugin[2].synchronize()
            thumbnailImage = image.copy()
            thumbnailImage.path = tuplePlugin[2].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addThumbnailImage(thumbnailImage)
        if self._edPluginControlGeneratePrediction.isRunning():
            self._edPluginControlGeneratePrediction.synchronize()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
            self._xsDataResultCharacterisation.setStatusMessage(XSDataString(self._strStatusMessage))
        if self._strCharacterisationShortSummary != None:
            self.setDataOutput(XSDataString(self._strCharacterisationShortSummary), "shortSummary")
            self._xsDataResultCharacterisation.setShortSummary(XSDataString(self._strCharacterisationShortSummary))
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        if self.isFailure():
            self.sendMessageToMXCuBE("Ended with error messages", "error")


    def doSuccessIndexingIndicators(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessIndexingIndicators")
        # self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_5.doSuccessIndexingIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput("indexingResult"):
            xsDataIndexingResult = self._edPluginControlIndexingIndicators.getDataOutput("indexingResult")[0]
            # self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
            self._edPluginExecEvaluationIndexingLABELIT.setDataInput(xsDataIndexingResult, "indexingResult")
        if self._edPluginControlIndexingIndicators.hasDataOutput("imageQualityIndicators"):
            listXSDataImageQualityIndicators = self._edPluginControlIndexingIndicators.getDataOutput("imageQualityIndicators")
            for xsDataImageQualityIndicators in listXSDataImageQualityIndicators:
                if xsDataImageQualityIndicators.dozor_score:
                    if self._iNoImagesWithDozorScore is None:
                        self._iNoImagesWithDozorScore = 0
                    if xsDataImageQualityIndicators.dozor_score.value > 0.001:
                        self._iNoImagesWithDozorScore += 1
                self._xsDataResultCharacterisation.addImageQualityIndicators(xsDataImageQualityIndicators)
                self._edPluginExecEvaluationIndexingLABELIT.setDataInput(xsDataImageQualityIndicators, "imageQualityIndicators")
        if self._edPluginControlIndexingIndicators.hasDataOutput("indicatorsShortSummary"):
            indicatorsShortSummary = self._edPluginControlIndexingIndicators.getDataOutput("indicatorsShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += indicatorsShortSummary
            self.sendMessageToMXCuBE(indicatorsShortSummary)
        for tuplePlugin in self._listPluginGenerateThumbnail:
            tuplePlugin[1].execute()
            tuplePlugin[2].execute()
        self.executePluginSynchronous(self._edPluginExecEvaluationIndexingLABELIT)


    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 doSuccessIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessIndexingMOSFLM")
        xsDataIndexingResult = self._edPluginControlIndexingMOSFLM.dataOutput
        self._edPluginExecEvaluationIndexingMOSFLM.setDataInput(xsDataIndexingResult, "indexingResult")
        self.executePluginSynchronous(self._edPluginExecEvaluationIndexingMOSFLM)


    def doFailureIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureIndexingMOSFLM")
        strErrorMessage = "Indexing with MOSFLM failed."
        self.ERROR(strErrorMessage)
        self.sendMessageToMXCuBE(strErrorMessage, "error")
        self.executePluginSynchronous(self._edPluginExecEvaluationIndexingMOSFLM)




    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):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessEvaluationIndexingMOSFLM")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_5.doSuccessEvaluationIndexingMOSFLM")
        # Retrieve status messages (if any)
        if self._edPluginExecEvaluationIndexingMOSFLM.hasDataOutput("statusMessageIndexing"):
            self.addStatusMessage("MOSFLM: " + self._edPluginExecEvaluationIndexingMOSFLM.getDataOutput("statusMessageIndexing")[0].getValue())
        # Check if indexing was successful
        bIndexingSuccess = self._edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingSuccess")[0].getValue()
        if bIndexingSuccess:
            xsDataIndexingResult = self._edPluginExecEvaluationIndexingMOSFLM.getDataOutput("indexingResult")[0]
            self._xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
            self._strCharacterisationShortSummary += self.generateIndexingShortSummary(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"):
                self._strCharacterisationShortSummary += self._edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
            # 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:
            strErrorMessage = "Execution of indexing with MOSFLM 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 generateIndexingShortSummary(self, _xsDataIndexingResult):
        """
        Generates a very short summary of the indexing
        """
        strIndexingShortSummary = ""
        if self.hasDataInput("crystal"):
            xsDataCrystal = self.getDataInput("crystal")[0]
            if xsDataCrystal.getSpaceGroup() is not None:
                strForcedSpaceGroup = xsDataCrystal.getSpaceGroup().getName().getValue().upper()
                if xsDataCrystal.getSpaceGroup().getName().getValue() != "":
                    strIndexingShortSummary += "Forced space group: %s\n" % strForcedSpaceGroup
        if _xsDataIndexingResult is not None:
            # Indexing solution
            xsDataSelectedSolution = _xsDataIndexingResult.getSelectedSolution()
            xsDataCrystal = xsDataSelectedSolution.getCrystal()
            # Refined cell parameters
            xsDataCell = xsDataCrystal.getCell()
            fA = xsDataCell.getLength_a().getValue()
            fB = xsDataCell.getLength_b().getValue()
            fC = xsDataCell.getLength_c().getValue()
            fAlpha = xsDataCell.getAngle_alpha().getValue()
            fBeta = xsDataCell.getAngle_beta().getValue()
            fGamma = xsDataCell.getAngle_gamma().getValue()
            # Estimated mosaicity
            fEstimatedMosaicity = xsDataCrystal.getMosaicity().getValue()
            # Space group
            strSpaceGroup = xsDataCrystal.getSpaceGroup().getName().getValue()
            # Spot deviation
            xsDataStatisticsIndexing = xsDataSelectedSolution.getStatistics()
            fSpotDeviationPositional = xsDataStatisticsIndexing.getSpotDeviationPositional().getValue()
            strIndexingShortSummary += "Indexing: laue/space group %s, mosaicity %.2f [degree], " % (strSpaceGroup, fEstimatedMosaicity)
            strIndexingShortSummary += "RMS dev pos %.2f [mm]" % fSpotDeviationPositional
            if xsDataStatisticsIndexing.getSpotDeviationAngular() is not None:
                fSpotDeviationAngular = xsDataStatisticsIndexing.getSpotDeviationAngular().getValue()
                strIndexingShortSummary += " ang %.2f [degree]" % fSpotDeviationAngular
            strIndexingShortSummary += "\n"
            strIndexingShortSummary += "Indexing: refined Cell: %7.2f %7.2f %7.2f %7.2f %7.2f %7.2f\n" % (fA, fB, fC, fAlpha, fBeta, fGamma)
        else:
            strIndexingShortSummary += "Indexing failed."
        return strIndexingShortSummary


    def indexingToIntegration(self, _edPlugin=None):
        # Run Kappa if configured
        if self._runKappa:
            xsDataInputControlKappa = XSDataInputControlKappa()
            xsDataInputControlKappa.dataCollection = self._xsDataCollection
            xsDataInputControlKappa.selectedSolution = self._xsDataResultCharacterisation.indexingResult.selectedSolution
            self._edPluginControlKappa.dataInput = xsDataInputControlKappa
            self.executePluginSynchronous(self._edPluginControlKappa)
            if not self._edPluginControlKappa.isFailure():
                self._xsDataResultCharacterisation.kappaReorientation = self._edPluginControlKappa.dataOutput
        # Create the XDS background image
        xsDataInputControlXDSGenerateBackgroundImage = XSDataInputControlXDSGenerateBackgroundImage()
        xsDataInputControlXDSGenerateBackgroundImage.setDataCollection(self._xsDataCollection)
        self._edPluginControlXDSGenerateBackgroundImage.setDataInput(xsDataInputControlXDSGenerateBackgroundImage)
        self._edPluginControlXDSGenerateBackgroundImage.execute()
        # Integrate the reference images
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(self._xsDataResultCharacterisation.getDataCollection())
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult()
        xsDataExperimentalConditionRefinded = xsDataIndexingResult.getSelectedSolution().getExperimentalConditionRefined()
        xsDataIntegrationInput.setExperimentalConditionRefined(xsDataExperimentalConditionRefinded)
        xsDataIntegrationInput.setSelectedIndexingSolution(xsDataIndexingResult.getSelectedSolution())
        self._edPluginControlIntegration.setDataInput(xsDataIntegrationInput)
        self.executePluginSynchronous(self._edPluginControlIntegration)



    def doFailureEvaluationIndexingLABELIT(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureEvaluationIndexing")
        strErrorMessage = "Execution of indexing evaluation plugin failed."
        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 doFailureEvaluationIndexingMOSFLM(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureEvaluationIndexingMOSFLM")
        strErrorMessage = "Execution of indexing evaluation plugin failed."
        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 doSuccessGeneratePrediction(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessGeneratePrediction")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_5.doSuccessGeneratePrediction")
        xsDataGeneratePredictionResult = _edPlugin.getDataOutput()
        xsDataIndexingResult = self._xsDataResultCharacterisation.getIndexingResult()
        xsDataIndexingResult.setPredictionResult(xsDataGeneratePredictionResult)


    def doFailureGeneratePrediction(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureGeneratePrediction")
        strWarningMessage = "Execution of generate prediction plugin failed."
        self.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        # self.addComment("warning: no prediction images")


    def doSuccessIntegration(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessIntegration")
        self.retrieveSuccessMessages(self._edPluginControlIntegration, "EDPluginControlCharacterisationv1_5.doSuccessIntegration")
        # Wait for XDS plugin if necessary
        self._edPluginControlXDSGenerateBackgroundImage.synchronize()
        self.addStatusMessage("Integration successful.")
        xsDataIntegrationOutput = self._edPluginControlIntegration.getDataOutput()
        self._xsDataResultCharacterisation.setIntegrationResult(xsDataIntegrationOutput)
        # Integration short summary
        if self._edPluginControlIntegration.hasDataOutput("integrationShortSummary"):
            integrationShortSummary = self._edPluginControlIntegration.getDataOutput("integrationShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += integrationShortSummary
            self.sendMessageToMXCuBE(integrationShortSummary)
        # self.DEBUG( self._xsDataExperimentCharacterisation.marshal() )
        if self._bDoStrategyCalculation:
            xsDataInputStrategy = XSDataInputStrategy()
            xsDataSolutionSelected = self._xsDataResultCharacterisation.getIndexingResult().getSelectedSolution()
            xsDataInputStrategy.setCrystalRefined(xsDataSolutionSelected.getCrystal())
            xsDataInputStrategy.setSample(self._xsDataResultCharacterisation.getDataCollection().getSample())
            xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult()
            bFirst = True
            for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
                if xsDataIntegrationSubWedgeResult.getBestfileHKL() is not None:
                    xsDataInputStrategy.addBestFileContentHKL(xsDataIntegrationSubWedgeResult.getBestfileHKL())
                    if bFirst:
                        xsDataInputStrategy.setBestFileContentDat(xsDataIntegrationSubWedgeResult.getBestfileDat())
                        xsDataInputStrategy.setBestFileContentPar(xsDataIntegrationSubWedgeResult.getBestfilePar())
                        xsDataInputStrategy.setExperimentalCondition(xsDataIntegrationSubWedgeResult.getExperimentalConditionRefined())
                        bFirst = False
            xsDataInputStrategy.setXdsBackgroundImage(self._xsDataFileXdsBackgroundImage)
            xsDataInputStrategy.setDataCollection(self._xsDataCollection)
            xsDataInputStrategy.setDiffractionPlan(self._xsDataResultCharacterisation.getDataCollection().getDiffractionPlan())
            self._edPluginControlStrategy.setDataInput(xsDataInputStrategy)
            self.executePluginSynchronous(self._edPluginControlStrategy)



    def doFailureIntegration(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureIntegration")
        strErrorMessage = "Execution of integration failed."
        self.addStatusMessage("Integration FAILURE.")
        self.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        # self.addComment("integration failure")
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.generateExecutiveSummary(self)
        self.setFailure()
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
            self.writeDataOutput()


    def doSuccessXDSGenerateBackgroundImage(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessXDSGenerateBackgroundImage")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_5.doSuccessXDSGenerateBackgroundImage")
        self._xsDataFileXdsBackgroundImage = self._edPluginControlXDSGenerateBackgroundImage.getDataOutput().getXdsBackgroundImage()
        self._xsDataResultCharacterisation.setXdsBackgroundImage(self._xsDataFileXdsBackgroundImage)


    def doFailureXDSGenerateBackgroundImage(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureXDSGenerateBackgroundImage")


    def doSuccessStrategy(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doSuccessStrategy")
        self.retrieveSuccessMessages(self._edPluginControlStrategy, "EDPluginControlCharacterisationv1_5.doSuccessStrategy")
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            strategyShortSummary = self._edPluginControlStrategy.getDataOutput("strategyShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += strategyShortSummary
            self.sendMessageToMXCuBE(strategyShortSummary)
        self.addStatusMessage("Strategy calculation successful.")


    def doFailureStrategy(self, _edPlugin=None):
        self.DEBUG("EDPluginControlCharacterisationv1_5.doFailureStrategy")
        strErrorMessage = "Strategy calculation FAILURE."
        self.ERROR(strErrorMessage)
        self.sendMessageToMXCuBE(strErrorMessage, "error")
        self.addErrorMessage(strErrorMessage)
        xsDataStrategyResult = self._edPluginControlStrategy.getDataOutput()
        self._xsDataResultCharacterisation.setStrategyResult(xsDataStrategyResult)
        if self._edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            strategyShortSummary = self._edPluginControlStrategy.getDataOutput("strategyShortSummary")[0].getValue()
            self._strCharacterisationShortSummary += strategyShortSummary
            self.sendMessageToMXCuBE(strategyShortSummary)
        if self._xsDataResultCharacterisation is not None:
            self.setDataOutput(self._xsDataResultCharacterisation)
        self.addStatusMessage("Strategy calculation FAILURE.")
        self.generateExecutiveSummary(self)
        if self._strStatusMessage != None:
            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
            self.writeDataOutput()
        self.setFailure()


    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_5.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
        xsDataFirstSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
        if xsDataBeam.getTransmission() is not None:
            fTransmission = xsDataBeam.getTransmission().getValue()
            if fTransmission < self._fMinTransmission:
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("WARNING! Transmission for characterisation set to %.1f %%" % fTransmission)
                self.addExecutiveSummaryLine("Please consider re-characterising with transmission set to 100 %")
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("^"*80)
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine("BEST complexity                       : %s" % xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine("Aimed completeness                    : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine("Required completeness                 : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution() is not None):
            self.addExecutiveSummaryLine("Aimed I/sigma at highest resolution   : %6.1f" % xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution().getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine("Aimed resolution                      : %6.1f [A]" % xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine("Required resolution                   : %6.1f [A]" % xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine("Aimed multiplicity                    : %6.1f" % xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine("Required multiplicity                 : %6.1f" % xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine("Forced space group                    : %6s" % xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection() is not None):
            self.addExecutiveSummaryLine("Max exposure time per data collection : %6.1f [s]" % xsDataDiffractionPlan.getMaxExposureTimePerDataCollection().getValue())
        self.addExecutiveSummarySeparator()
        if self._edPluginControlIndexingIndicators is not None:
            self.appendExecutiveSummary(self._edPluginControlIndexingIndicators, "")
        if self._edPluginControlIntegration is not None:
            self.appendExecutiveSummary(self._edPluginControlIntegration, "")
        if self._edPluginControlStrategy is not None:
            self.appendExecutiveSummary(self._edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self._strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self._strStatusMessage != None:
                for strLine in self._strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine + ".")
            self.addExecutiveSummaryLine("")
            for strLine in self._strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary("Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()


    def getPluginStrategyName(self):
        return self._strPluginControlStrategy


    def addStatusMessage(self, _strStatusMessage):
        if self._strStatusMessage != "":
            self._strStatusMessage += " "
        self._strStatusMessage += _strStatusMessage
        self.sendMessageToMXCuBE(_strStatusMessage)


    def doStrategyCalculation(self, _bValue):
        self._bDoStrategyCalculation = _bValue


    def sendMessageToMXCuBE(self, _strMessage, level="info"):
        # Only for mxCuBE
        if self._strMxCuBE_URI is not None:
            self.DEBUG("Sending message to mxCuBE: {0}".format(_strMessage))
            try:
                for strMessage in _strMessage.split("\n"):
                    if strMessage != "":
                        self._oServerProxy.log_message("Characterisation: " + strMessage, level)
            except:
                self.DEBUG("Sending message to mxCuBE failed!")
示例#29
0
	def buildChildren(self, child_, nodeName_):
		if child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'mxv1ResultCharacterisation':
			obj_ = XSDataResultCharacterisation()
			obj_.build(child_)
			self.setMxv1ResultCharacterisation(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'mxv1ResultCharacterisation_Reference':
			obj_ = XSDataResultCharacterisation()
			obj_.build(child_)
			self.setMxv1ResultCharacterisation_Reference(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'mxv2DataCollection':
			obj_ = XSDataCollection()
			obj_.build(child_)
			self.setMxv2DataCollection(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'mxv2DataCollection_Reference':
			obj_ = XSDataCollection()
			obj_.build(child_)
			self.setMxv2DataCollection_Reference(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'suggestedStrategy':
			obj_ = XSDataResultStrategy()
			obj_.build(child_)
			self.setSuggestedStrategy(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'possibleOrientations':
			obj_ = kappa_alignment_response()
			obj_.build(child_)
			self.setPossibleOrientations(obj_)
		XSDataResultInterface.buildChildren(self, child_, nodeName_)
 def preProcess(self, _edObject=None):
     EDPluginControl.preProcess(self)
     self.DEBUG("EDPluginControlCharacterisationv1_6.preProcess")
     self._xsDataResultCharacterisation = XSDataResultCharacterisation()
class EDPluginControlCharacterisationv1_6(EDPluginControl):
    """
    Characterisation based on XDS
    """


    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self._strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv1_1"
        self._fMinTransmission = 10  # %
        self._listPluginGenerateThumbnail = []
        self._strCharacterisationShortSummary = ""
        self._strStatusMessage = ""
        self._strIndexingPluginName = "EDPluginXDSIndexingv1_0"
        self._strIntegrationPluginName = "EDPluginXDSIntegrationv1_0"
        self._edPluginIndexing = None


    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_6.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection().getDiffractionPlan(), "diffractionPlan")

    def configure(self):
        """
        Gets the configuration parameters (if any).
        """
        EDPluginControl.configure(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.configure")
        self._strMxCuBE_URI = self.config.get("mxCuBE_URI", None)
        if self._strMxCuBE_URI is not None and "mxCuBE_XMLRPC_log" in os.environ.keys():
            self.DEBUG("Enabling sending messages to mxCuBE via URI {0}".format(self._strMxCuBE_URI))
            self._oServerProxy = xmlrpclib.ServerProxy(self._strMxCuBE_URI)
        self._runKappa = self.config.get("runKappa", False)
        self._fMinTransmission = self.config.get("minTransmissionWarning", self._fMinTransmission)



    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.preProcess")
        self._xsDataResultCharacterisation = XSDataResultCharacterisation()


    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.process")
        self.doXdsIndexingIntegration(self.dataInput.dataCollection)


    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        self.DEBUG("EDPluginControlCharacterisationv1_6.finallyProcess")
        # Synchronize thumbnail plugins
        for tuplePlugin in self._listPluginGenerateThumbnail:
            image = tuplePlugin[0]
            tuplePlugin[1].synchronize()
            jpegImage = image.copy()
            jpegImage.path = tuplePlugin[1].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addJpegImage(jpegImage)
            tuplePlugin[2].synchronize()
            thumbnailImage = image.copy()
            thumbnailImage.path = tuplePlugin[2].dataOutput.thumbnail.path
            self._xsDataResultCharacterisation.addThumbnailImage(thumbnailImage)
#        if self._edPluginControlGeneratePrediction.isRunning():
#            self._edPluginControlGeneratePrediction.synchronize()
#        if self._strStatusMessage != None:
#            self.setDataOutput(XSDataString(self._strStatusMessage), "statusMessage")
#            self._xsDataResultCharacterisation.setStatusMessage(XSDataString(self._strStatusMessage))
#        if self._strCharacterisationShortSummary != None:
#            self.setDataOutput(XSDataString(self._strCharacterisationShortSummary), "shortSummary")
#            self._xsDataResultCharacterisation.setShortSummary(XSDataString(self._strCharacterisationShortSummary))
#        if self._xsDataResultCharacterisation is not None:
#            self.setDataOutput(self._xsDataResultCharacterisation)
        if self.isFailure():
            self.sendMessageToMXCuBE("Ended with error messages", "error")



    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 generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        self.DEBUG("EDPluginControlCharacterisationv1_6.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
        xsDataFirstSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
        if xsDataBeam.getTransmission() is not None:
            fTransmission = xsDataBeam.getTransmission().getValue()
            if fTransmission < self._fMinTransmission:
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("WARNING! Transmission for characterisation set to %.1f %%" % fTransmission)
                self.addExecutiveSummaryLine("Please consider re-characterising with transmission set to 100 %")
                self.addExecutiveSummaryLine("")
                self.addExecutiveSummaryLine("^"*80)
                self.addExecutiveSummaryLine("^"*80)
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine("BEST complexity                       : %s" % xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine("Aimed completeness                    : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine("Required completeness                 : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution() is not None):
            self.addExecutiveSummaryLine("Aimed I/sigma at highest resolution   : %6.1f" % xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution().getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine("Aimed resolution                      : %6.1f [A]" % xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine("Required resolution                   : %6.1f [A]" % xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine("Aimed multiplicity                    : %6.1f" % xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine("Required multiplicity                 : %6.1f" % xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine("Forced space group                    : %6s" % xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection() is not None):
            self.addExecutiveSummaryLine("Max exposure time per data collection : %6.1f [s]" % xsDataDiffractionPlan.getMaxExposureTimePerDataCollection().getValue())
        self.addExecutiveSummarySeparator()
#        if self._edPluginControlIndexingIndicators is not None:
#            self.appendExecutiveSummary(self._edPluginControlIndexingIndicators, "")
#        if self._edPluginControlIntegration is not None:
#            self.appendExecutiveSummary(self._edPluginControlIntegration, "")
#        if self._edPluginControlStrategy is not None:
#            self.appendExecutiveSummary(self._edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self._strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self._strStatusMessage != None:
                for strLine in self._strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine + ".")
            self.addExecutiveSummaryLine("")
            for strLine in self._strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary("Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()


    def getPluginStrategyName(self):
        return self._strPluginControlStrategy


    def addStatusMessage(self, _strStatusMessage):
        if self._strStatusMessage != "":
            self._strStatusMessage += " "
        self._strStatusMessage += _strStatusMessage
        self.sendMessageToMXCuBE(_strStatusMessage)


    def doStrategyCalculation(self, _bValue):
        self._bDoStrategyCalculation = _bValue


    def sendMessageToMXCuBE(self, _strMessage, level="info"):
        # Only for mxCuBE
        if self._strMxCuBE_URI is not None:
            self.DEBUG("Sending message to mxCuBE: {0}".format(_strMessage))
            try:
                for strMessage in _strMessage.split("\n"):
                    if strMessage != "":
                        self._oServerProxy.log_message("Characterisation: " + strMessage, level)
            except:
                self.DEBUG("Sending message to mxCuBE failed!")
示例#32
0
fEdnaLogFile = open("./edna.log", "r" )
ednaLogLines = fEdnaLogFile.readlines()
fEdnaLogFile.close()
for outline in ednaLogLines: 
  if (outline.find("EdnaDir")!= -1):
    (param,dirname) = outline.split('=')
    strXMLFileName = dirname[0:len(dirname)-1]+"/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_3_dataOutput.xml"
#####    strXMLFileName = dirname[0:len(dirname)-1]+"/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_1_dataOutput.xml"
  if (outline.find("characterisation successful!")!= -1):
    collect_and_characterize_success = 1
if (not collect_and_characterize_success):
  dna_comment =  "Indexing Failure"
#####  pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment)  
  exit(0)
else:
  xsDataCharacterisation = XSDataResultCharacterisation.parseFile( strXMLFileName )
  xsDataIndexingResult = xsDataCharacterisation.getIndexingResult()
  xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution()
  xsDataStatisticsIndexing = xsDataIndexingSolutionSelected.getStatistics()
  numSpotsFound  = xsDataStatisticsIndexing.getSpotsTotal().getValue()
  numSpotsUsed  = xsDataStatisticsIndexing.getSpotsUsed().getValue()
  numSpotsRejected = numSpotsFound-numSpotsUsed
  beamShiftX = xsDataStatisticsIndexing.getBeamPositionShiftX().getValue()
  beamShiftY = xsDataStatisticsIndexing.getBeamPositionShiftY().getValue()
  spotDeviationR = xsDataStatisticsIndexing.getSpotDeviationPositional().getValue()
  try:
    spotDeviationTheta = xsDataStatisticsIndexing.getSpotDeviationAngular().getValue()
  except AttributeError:
    spotDeviationTheta = 0.0
  diffractionRings = 0 #for now, don't see this in xml except message string        
  reflections_used = 0 #for now
class EDPluginControlCharacterisationv2_0(EDPluginControl):
    """
    The Plugin that controls the whole characterisation: Indexing-Integration-(Kappa)Strategy    
    Indexing-Integration is the same as mxv1 characterisation.
    KappaStrategy:
    Preferred Strategy is given at the initial orientation, but if KAPPA features are enabled,
    strategies are calculated to some alignments.
    """

    def __init__ (self):
        """
        """
        EDPluginControl.__init__(self)
        #self.setXSDataInputClass( XSDataInputCharacterisation )
        #self.setXSDataInputClass(EDList)
        #self.strPluginIndexingName = "EDPluginControlIndexingv2_0"
        self.strPluginIndexingName = "EDPluginControlIndexingv10"
        self.edPluginIndexing = None
        self.strPluginIntegrationName = "EDPluginControlIntegrationv10"
        self.edPluginIntegration = None
        self.xsDataResultCharacterisationv2_0 = None
        self.xsDataResultCharacterisation = None
        self.xsDataInputStrategy = None

        self.setXSDataInputClass(XSDataInputCharacterisationv2_0)
        
        EDFactoryPluginStatic.loadModule("XSDataMXv1")
        import XSDataMXv1
        self.setXSDataInputClass(XSDataMXv1.XSDataInputCharacterisation, "mxv1InputCharacterisation")
        EDFactoryPluginStatic.loadModule("XSDataMXv2")
        import XSDataMXv2
        self.setXSDataInputClass(XSDataMXv2.XSDataCollection, "mxv2DataCollection")


    def checkParameters(self):
        """
        Checks the mandatory parameters
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.checkParameters")
        # Check for mxv1InputCharacterisation:
        if self.hasDataInput():
            if self.hasDataInput("mxv1InputCharacterisation") or self.hasDataInput("mxv2DataCollection"):
                EDVerbose.WARNING("Ambiguous input! Both XSDataInputCharacterisatiov2_0 input, and mxv1InputCharacterisation or mxv2DataCollection input(s), are given")
            self.setDataInput(self.getDataInput().getMxv1InputCharacterisation().marshal(), "mxv1InputCharacterisation")
            self.setDataInput(self.getDataInput().getMxv2DataCollection().marshal(), "mxv2DataCollection")
        # Check for mxv1InputCharacterisation
        self.checkMandatoryParameters(self.getDataInput("mxv1InputCharacterisation"), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput("mxv1InputCharacterisation")[0].getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(self.getDataInput("mxv1InputCharacterisation")[0].getDataCollection().getDiffractionPlan(), "diffractionPlan")



    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 process(self, _edObject=None):
        EDPluginControl.process(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.process")
        self.connectProcess(self.edPluginIndexing.executeSynchronous)
        self.edPluginIndexing.connectSUCCESS(self.doIndexingToIntegrationTransition)
        self.edPluginIndexing.connectFAILURE(self.doFailureActionIndexing)
        self.edPluginIntegration.connectSUCCESS(self.doIntegrationToStrategyTransition)
        self.edPluginIntegration.connectFAILURE(self.doFailureActionIntegration)
        self.edPluginStrategy.connectFAILURE(self.doFailureActionStrategy)
        self.edPluginStrategy.connectSUCCESS(self.doSuccessActionStrategy)


    def postProcess(self, _edObject=None):
        """
        """
        EDPluginControl.postProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.postProcess")
        if (self.xsDataResultCharacterisationv2_0 is not None):
            self.setDataOutput(self.xsDataResultCharacterisationv2_0)


    def doIndexingToIntegrationTransition(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.doIndexingToIntegrationTransition")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition")
        xsDataIndexingResult = self.edPluginIndexing.getDataOutput()
        self.xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
        from XSDataMXv1 import XSDataIntegrationInput
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(self.xsDataResultCharacterisation.getDataCollection())
        xsDataIntegrationInput.setExperimentalConditionRefined(xsDataIndexingResult.getSelectedSolution().getExperimentalConditionRefined())
        xsDataIntegrationInput.setSelectedIndexingSolution(xsDataIndexingResult.getSelectedSolution())
        self.edPluginIntegration.setDataInput(xsDataIntegrationInput)
        self.edPluginIntegration.executeSynchronous()


    def doIntegrationToStrategyTransition(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv2_0.doIntegrationToStrategyTransition")

        xsDataIntegrationOutput = self.edPluginIntegration.getDataOutput()
        self.xsDataResultCharacterisation.setIntegrationResult(xsDataIntegrationOutput)
        #EDVerbose.DEBUG( self.xsDataExperimentCharacterisation.marshal() )
        from XSDataMXv1 import XSDataInputStrategy
        xsDataInputStrategyOLD = XSDataInputStrategy()

        xsDataSolutionSelected = self.xsDataResultCharacterisation.getIndexingResult().getSelectedSolution()

        xsDataInputStrategyOLD.setCrystalRefined(xsDataSolutionSelected.getCrystal())
        xsDataInputStrategyOLD.setSample(self.xsDataResultCharacterisation.getDataCollection().getSample())

        xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult()

        xsDataInputStrategyOLD.setBestFileContentDat(xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
        xsDataInputStrategyOLD.setBestFileContentPar(xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
        xsDataInputStrategyOLD.setExperimentalCondition(xsDataIntegrationSubWedgeResultList[0].getExperimentalConditionRefined())

        for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
            xsDataInputStrategyOLD.addBestFileContentHKL(xsDataIntegrationSubWedgeResult.getBestfileHKL())

        xsDataInputStrategyOLD.setDiffractionPlan(self.xsDataResultCharacterisation.getDataCollection().getDiffractionPlan())
        xsDataInputStrategyOLD.setXdsBackgroundImage(self.xsDataResultCharacterisation.getXdsBackgroundImage())

        #print xsDataInputStrategy.marshal()
        self.edPluginStrategy.setDataInput(xsDataInputStrategyOLD, "mxv1InputStrategy")
        if self.hasDataInput("mxv2DataCollection"):
            self.edPluginStrategy.setDataInput(self.getDataInput("mxv2DataCollection")[0], "mxv2DataCollection")
        self.edPluginStrategy.setDataInput(self.xsDataResultCharacterisation.getIndexingResult(), "mxv1IndexingResult")

#            xsDataInputStrategy= EDList()
#            xsDataInputStrategy.add(xsDataInputStrategyOLD)
#            xsDataInputStrategy.add(self.getDataInput()[1])
#            xsDataInputStrategy.add(self.xsDataResultCharacterisationv2_0.getIndexingResult())
#            self.edPluginStrategy.setDataInput( xsDataInputStrategy )
        self.edPluginStrategy.executeSynchronous()



    def doFailureActionIndexing(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.doFailureActionIndexing")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlCharacterisationv2_0.doFailureActionIndexing")


    def doFailureActionIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.doFailureActionIntegration")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlCharacterisationv2_0.doFailureActionIntegration")


    def doFailureActionStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.doFailureActionStrategy")
        self.retrieveFailureMessages(_edPlugin, "EDPluginControlCharacterisationv2_0.doFailureActionStrategy")


    def doSuccessActionStrategy(self, _edPlugin):
        """
        retrieve the potential warning messages
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.doSuccessActionStrategy")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv2_0.doSuccessActionStrategy")
        xsDataResultStrategy = self.edPluginStrategy.getDataOutput()
        self.xsDataResultCharacterisation.setStrategyResult(xsDataResultStrategy)


    def configure(self):
        EDPluginControl.configure(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.configure")
        pluginConfiguration = self.getConfiguration()

        if(pluginConfiguration != None):
            strPointlessOn = EDConfiguration.getStringParamValue(pluginConfiguration, "POINTLESS")
            if(strPointlessOn == None or strPointlessOn != "True"):
                self.strPluginIntegrationName = "EDPluginControlIntegrationv10"
            else:
                self.strPluginIntegrationName = "EDPluginControlIntegrationPointlessv10"




    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv2_0.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        self.addErrorWarningMessagesToExecutiveSummary("Characterisation failure! Error messages: ")
        self.addExecutiveSummarySeparator()
        xsDataInputStrategy = self.getDataInput("mxv1InputCharacterisation")[0]
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine("BEST complexity                       : %s" % xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine("Aimed completeness                    : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine("Required completeness                 : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution() is not None):
            self.addExecutiveSummaryLine("Aimed I/sigma at highest resolution   : %6.1f" % xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution().getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine("Aimed resolution                      : %6.1f [A]" % xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine("Required resolution                   : %6.1f [A]" % xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine("Aimed multiplicity                    : %6.1f" % xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine("Required multiplicity                 : %6.1f" % xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine("Forced space group                    : %6s" % xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection() is not None):
            self.addExecutiveSummaryLine("Max exposure time per data collection : %6.1f [s]" % xsDataDiffractionPlan.getMaxExposureTimePerDataCollection().getValue())
        self.addExecutiveSummarySeparator()
        if (self.edPluginIndexing is not None):
            self.appendExecutiveSummary(self.edPluginIndexing, "Indexing : ")
        if (self.edPluginIntegration is not None):
            self.appendExecutiveSummary(self.edPluginIntegration, "Integration : ")
        if (self.edPluginStrategy is not None):
            self.appendExecutiveSummary(self.edPluginStrategy, "Strategy : ")
    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.preProcess")
        # Load the plugins
        self._edPluginControlIndexingIndicators = self.loadPlugin(self._strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self._edPluginControlIndexingLabelit = self.loadPlugin(self._strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self._edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self._edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self._strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self._edPluginControlGeneratePrediction = self.loadPlugin(self._strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self._edPluginControlIntegration = self.loadPlugin(self._strPluginControlIntegration, \
                                                            "Integration")
        self._edPluginControlXDSGenerateBackgroundImage = self.loadPlugin(self._strPluginControlXDSGenerateBackgroundImage, \
                                                            "ControlXDSGenerateBackgroundImage")
        self._edPluginControlStrategy = self.loadPlugin(self._strPluginControlStrategy, \
                                                         "Strategy")
        if (self._edPluginControlIndexingIndicators is not None):
            EDVerbose.DEBUG("EDPluginControlCharacterisationv1_3.preProcess: " + self._strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self._xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            # MXSUP-1445: Check if transmission is less than 10% and warn if it's the case
            xsDataFirstSubWedge = self._xsDataCollection.getSubWedge()[0]
            xsDataBeam = xsDataFirstSubWedge.getExperimentalCondition().getBeam()
            if xsDataBeam.getTransmission() is not None:
                fTransmission = xsDataBeam.getTransmission().getValue()
                if fTransmission < self._fMinTransmission:
                    strWarningMessageBanner = "^"*80 
                    strWarningMessage1 = "WARNING! Transmission for characterisation set to %.1f %%" % fTransmission
                    strWarningMessage2 = "Please consider re-characterising with transmission set to 100 %" 
                    self.warning(strWarningMessageBanner)
                    self.warning(strWarningMessage1)
                    self.warning(strWarningMessage2)
                    self.warning(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessageBanner)
                    self.addWarningMessage(strWarningMessage1)
                    self.addWarningMessage(strWarningMessage2)
                    self.addWarningMessage(strWarningMessageBanner)
            xsDataCrystal = None
            xsDataSubWedgeList = self._xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_3.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage("EDPluginControlCharacterisationv1_3.preProcess ERROR: " + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self._xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self._xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self._xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCollection, "dataCollection")
                if self._xsDataCrystal is not None:
                    self._edPluginControlIndexingIndicators.setDataInput(self._xsDataCrystal, "crystal")

                # Populate characterisation object
                self._xsDataResultCharacterisation = XSDataResultCharacterisation()
                self._xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self._xsDataCollection.marshal()))
class EDPluginControlCharacterisationv1_2(EDPluginControl):
    """
    [To be replaced with a description of EDPluginControlTemplatev10]
    """


    def __init__(self):
        EDPluginControl.__init__(self)
        self.setXSDataInputClass(XSDataInputCharacterisation)
        self.__strPluginControlIndexingIndicators = "EDPluginControlIndexingIndicatorsv10"
        self.__strPluginControlIndexingLabelit = "EDPluginControlIndexingLabelitv10"
        self.__strPluginExecEvaluationIndexing = "EDPluginExecEvaluationIndexingv10"
        self.__strPluginControlGeneratePrediction = "EDPluginControlGeneratePredictionv10"
        self.__strPluginControlIntegration = "EDPluginControlIntegrationv10"
        self.__strPluginControlStrategy = "EDPluginControlStrategyv1_2"
        self.__edPluginControlIndexingIndicators = None
        self.__edPluginControlIndexingLabelit = None
        self.__edPluginExecEvaluationIndexingMOSFLM = None
        self.__edPluginExecEvaluationIndexingLABELIT = None
        self.__edPluginControlGeneratePrediction = None
        self.__edPluginControlIntegration = None
        self.__edPluginControlStrategy = None
        self.__xsDataCollection = None
        self.__xsDataResultCharacterisation = None
        self.__xsDataIndexingResultMOSFLM = None
        self.__xsDataCrystal = None
        self.__strCharacterisationShortSummary = ""
        self.__strStatusMessage = ""
        self.__bDoStrategyCalculation = True



    def checkParameters(self):
        """
        Checks the mandatory parameters.
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.checkParameters")
        self.checkMandatoryParameters(self.getDataInput(), "Data Input is None")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection(), "dataCollection")
        self.checkMandatoryParameters(self.getDataInput().getDataCollection().getDiffractionPlan(), "diffractionPlan")


    def preProcess(self, _edObject=None):
        EDPluginControl.preProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.preProcess")
        # Load the plugins
        self.__edPluginControlIndexingIndicators = self.loadPlugin(self.__strPluginControlIndexingIndicators, \
                                                                   "Indexing")
        self.__edPluginControlIndexingLabelit = self.loadPlugin(self.__strPluginControlIndexingLabelit, \
                                                                   "IndexingLabelit")
        self.__edPluginExecEvaluationIndexingMOSFLM = self.loadPlugin(self.__strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionMOSFLM")
        self.__edPluginExecEvaluationIndexingLABELIT = self.loadPlugin(self.__strPluginExecEvaluationIndexing, \
                                                                   "IndexingEvalualtionLABELIT")
        self.__edPluginControlGeneratePrediction = self.loadPlugin(self.__strPluginControlGeneratePrediction, \
                                                                   "GeneratePrediction")
        self.__edPluginControlIntegration = self.loadPlugin(self.__strPluginControlIntegration, \
                                                            "Integration")
        self.__edPluginControlStrategy = self.loadPlugin(self.__strPluginControlStrategy, \
                                                         "Strategy")
        if (self.__edPluginControlIndexingIndicators is not None):
            EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.preProcess: " + self.__strPluginControlIndexingIndicators + " Found... setting Data Input")
            # create Data Input for indexing
            xsDataInputCharacterisation = self.getDataInput()
            self.__xsDataCollection = xsDataInputCharacterisation.getDataCollection()
            xsDataCrystal = None
            xsDataSubWedgeList = self.__xsDataCollection.getSubWedge()
            if ((xsDataSubWedgeList is None) or (xsDataSubWedgeList == [])):
                strError = "EDPluginControlCharacterisationv1_2.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):
                        strErrorMessage = "Input flux is negative or close to zero. Execution of characterisation aborted."
                        EDVerbose.ERROR(strErrorMessage)
                        self.addErrorMessage("EDPluginControlCharacterisationv1_2.preProcess ERROR: " + strErrorMessage)
                        #self.addComment(strErrorMessage)
                        self.setFailure()

                xsDataDiffractionPlan = self.__xsDataCollection.getDiffractionPlan()
                xsDataStringForcedSpaceGroup = xsDataDiffractionPlan.getForcedSpaceGroup()
                if (xsDataStringForcedSpaceGroup is not None):
                    self.__xsDataCrystal = XSDataCrystal()
                    xsDataSpaceGroup = XSDataSpaceGroup()
                    xsDataSpaceGroup.setName(xsDataStringForcedSpaceGroup)
                    self.__xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

                self.__edPluginControlIndexingIndicators.setDataInput(self.__xsDataCollection, "dataCollection")
                if self.__xsDataCrystal is not None:
                    self.__edPluginControlIndexingIndicators.setDataInput(self.__xsDataCrystal, "crystal")

                # Populate characterisation object
                self.__xsDataResultCharacterisation = XSDataResultCharacterisation()
                self.__xsDataResultCharacterisation.setDataCollection(XSDataCollection.parseString(self.__xsDataCollection.marshal()))


    def process(self, _edObject=None):
        EDPluginControl.process(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.process")
        self.__edPluginControlIndexingIndicators.connectSUCCESS(self.doSuccessIndexingIndicators)
        self.__edPluginControlIndexingIndicators.connectFAILURE(self.doFailureIndexingIndicators)
        self.__edPluginControlIndexingLabelit.connectSUCCESS(self.doSuccessIndexingLabelit)
        self.__edPluginControlIndexingLabelit.connectFAILURE(self.doFailureIndexingLabelit)
        self.__edPluginExecEvaluationIndexingMOSFLM.connectSUCCESS(self.doSuccessEvaluationIndexingMOSFLM)
        self.__edPluginExecEvaluationIndexingMOSFLM.connectFAILURE(self.doFailureEvaluationIndexingMOSFLM)
        self.__edPluginExecEvaluationIndexingLABELIT.connectSUCCESS(self.doSuccessEvaluationIndexingLABELIT)
        self.__edPluginExecEvaluationIndexingLABELIT.connectFAILURE(self.doFailureEvaluationIndexingLABELIT)
        self.__edPluginControlGeneratePrediction.connectSUCCESS(self.doSuccessGeneratePrediction)
        self.__edPluginControlGeneratePrediction.connectFAILURE(self.doFailureGeneratePrediction)
        self.__edPluginControlIntegration.connectSUCCESS(self.doSuccessIntegration)
        self.__edPluginControlIntegration.connectFAILURE(self.doFailureIntegration)
        self.__edPluginControlStrategy.connectSUCCESS(self.doSuccessStrategy)
        self.__edPluginControlStrategy.connectFAILURE(self.doFailureStrategy)
        self.__edPluginControlIndexingIndicators.executeSynchronous()


    def finallyProcess(self, _edObject=None):
        EDPluginControl.finallyProcess(self)
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.finallyProcess")
        if self.__edPluginControlGeneratePrediction.isRunning():
            self.__edPluginControlGeneratePrediction.synchronize()
        if self.__strStatusMessage != None:
            self.setDataOutput(XSDataString(self.__strStatusMessage), "statusMessage")
            self.__xsDataResultCharacterisation.setStatusMessage(XSDataString(self.__strStatusMessage))
        if self.__strCharacterisationShortSummary != None:
            self.setDataOutput(XSDataString(self.__strCharacterisationShortSummary), "shortSummary")
            self.__xsDataResultCharacterisation.setShortSummary(XSDataString(self.__strCharacterisationShortSummary))
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)


    def doSuccessIndexingIndicators(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessIndexingIndicators")
        #self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessIndexingIndicators")
        if self.__edPluginControlIndexingIndicators.hasDataOutput("indexingResult"):
            xsDataIndexingResult = self.__edPluginControlIndexingIndicators.getDataOutput("indexingResult")[0]
            #self.__xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
            self.__edPluginExecEvaluationIndexingMOSFLM.setDataInput(xsDataIndexingResult, "indexingResult")
        if self.__edPluginControlIndexingIndicators.hasDataOutput("imageQualityIndicators"):
            listXSDataImageQualityIndicators = self.__edPluginControlIndexingIndicators.getDataOutput("imageQualityIndicators")
            for xsDataImageQualityIndicators in listXSDataImageQualityIndicators:
                self.__xsDataResultCharacterisation.addImageQualityIndicators(xsDataImageQualityIndicators)
                self.__edPluginExecEvaluationIndexingMOSFLM.setDataInput(xsDataImageQualityIndicators, "imageQualityIndicators")
        if self.__edPluginControlIndexingIndicators.hasDataOutput("indicatorsShortSummary"):
            self.__strCharacterisationShortSummary += self.__edPluginControlIndexingIndicators.getDataOutput("indicatorsShortSummary")[0].getValue()
        self.__edPluginExecEvaluationIndexingMOSFLM.executeSynchronous()


    def doFailureIndexingIndicators(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureIndexingIndicators")
        strErrorMessage = "Execution of Indexing and Indicators plugin failed. Execution of characterisation aborted."
        EDVerbose.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        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 doSuccessIndexingLabelit(self, _edPlugin=None):
#        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessIndexingLabelit")
#        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessIndexingLabelit")
#        # Retrieve the indexing result
#        xsDataIndexingResult = self.__edPluginControlIndexingLabelit.getDataOutput()
#        self.__xsDataResultCharacterisation.setIndexingResult(xsDataIndexingResult)
#        if self.__edPluginControlIndexingLabelit.hasDataOutput("indexingShortSummary"):
#            self.__strCharacterisationShortSummary += self.__edPluginControlIndexingLabelit.getDataOutput("indexingShortSummary")[0].getValue()
#        # Then start the integration of the reference images
#        self.indexingToIntegration()


    def doSuccessIndexingLabelit(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessIndexingLabelit")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessIndexingLabelit")
        if self.__edPluginControlIndexingLabelit.hasDataOutput("indexingShortSummary"):
            self.__strCharacterisationShortSummary += self.__edPluginControlIndexingLabelit.getDataOutput("indexingShortSummary")[0].getValue()
        # Check the indexing results
        xsDataIndexingResult = self.__edPluginControlIndexingLabelit.getDataOutput()
        self.__edPluginExecEvaluationIndexingLABELIT.setDataInput(xsDataIndexingResult, "indexingResult")
        xsDataImageQualityIndicators = self.__xsDataResultCharacterisation.getImageQualityIndicators()[0]
        self.__edPluginExecEvaluationIndexingLABELIT.setDataInput(xsDataImageQualityIndicators, "imageQualityIndicators")
        self.__edPluginExecEvaluationIndexingLABELIT.executeSynchronous()


    def doFailureIndexingLabelit(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureIndexingLabelit")
        self.addStatusMessage("Labelit: Indexing FAILURE.")
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)
        if self.__xsDataIndexingResultMOSFLM == None:
            strErrorMessage = "Execution of indexing with both MOSFLM and Labelit failed. Execution of characterisation aborted."
            EDVerbose.ERROR(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.generateExecutiveSummary(self)
            self.setFailure()
            if self.__strStatusMessage != None:
                self.setDataOutput(XSDataString(self.__strStatusMessage), "statusMessage")
                self.writeDataOutput()
        else:
            # Use the MOSFLM indexing results - even if it's P1
            self.__xsDataResultCharacterisation.setIndexingResult(self.__xsDataIndexingResultMOSFLM)
            xsDataCollection = self.__xsDataResultCharacterisation.getDataCollection()
            xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
            xsDataGeneratePredictionInput.setDataCollection(XSDataCollection.parseString(xsDataCollection.marshal()))
            xsDataGeneratePredictionInput.setSelectedIndexingSolution(XSDataIndexingSolutionSelected.parseString(self.__xsDataIndexingResultMOSFLM.getSelectedSolution().marshal()))
            self.__edPluginControlGeneratePrediction.setDataInput(xsDataGeneratePredictionInput)
            if self.__edPluginControlIndexingIndicators.hasDataOutput("indexingShortSummary"):
                self.__strCharacterisationShortSummary += self.__edPluginControlIndexingIndicators.getDataOutput("indexingShortSummary")[0].getValue()
            # 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()



    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 doSuccessEvaluationIndexingLABELIT(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessEvaluationIndexingLABELIT")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.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)
            # Then start the integration of the reference images
            self.indexingToIntegration()
        else:
            EDVerbose.screen("Indexing with LABELIT failed!")
            self.setFailure()


    def indexingToIntegration(self, _edPlugin=None):
        # Integrate the reference images 
        xsDataIntegrationInput = XSDataIntegrationInput()
        xsDataIntegrationInput.setDataCollection(self.__xsDataResultCharacterisation.getDataCollection())
        xsDataIndexingResult = self.__xsDataResultCharacterisation.getIndexingResult()
        xsDataExperimentalConditionRefinded = xsDataIndexingResult.getSelectedSolution().getExperimentalConditionRefined()
        xsDataIntegrationInput.setExperimentalConditionRefined(xsDataExperimentalConditionRefinded)
        xsDataIntegrationInput.setSelectedIndexingSolution(xsDataIndexingResult.getSelectedSolution())
        self.__edPluginControlIntegration.setDataInput(xsDataIntegrationInput)
        self.__edPluginControlIntegration.executeSynchronous()


    def doFailureEvaluationIndexingMOSFLM(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureEvaluationIndexing")
        strWarningMessage = "Execution of indexing evaluation plugin failed."
        EDVerbose.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)


    def doFailureEvaluationIndexingLABELIT(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureEvaluationIndexing")
        strWarningMessage = "Execution of indexing evaluation plugin failed."
        EDVerbose.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)


    def doSuccessGeneratePrediction(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessGeneratePrediction")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessGeneratePrediction")
        xsDataGeneratePredictionResult = _edPlugin.getDataOutput()
        xsDataIndexingResult = self.__xsDataResultCharacterisation.getIndexingResult()
        xsDataIndexingResult.setPredictionResult(xsDataGeneratePredictionResult)


    def doFailureGeneratePrediction(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureGeneratePrediction")
        strWarningMessage = "Execution of generate prediction plugin failed."
        EDVerbose.WARNING(strWarningMessage)
        self.addWarningMessage(strWarningMessage)
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)
        #self.addComment("warning: no prediction images")


    def doSuccessIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessIntegration")
        self.retrieveSuccessMessages(_edPlugin, "EDPluginControlCharacterisationv1_2.doSuccessIntegration")
        self.addStatusMessage("Integration successful.")
        xsDataIntegrationOutput = self.__edPluginControlIntegration.getDataOutput()
        self.__xsDataResultCharacterisation.setIntegrationResult(xsDataIntegrationOutput)
        # Integration short summary
        if self.__edPluginControlIntegration.hasDataOutput("integrationShortSummary"):
            self.__strCharacterisationShortSummary += self.__edPluginControlIntegration.getDataOutput("integrationShortSummary")[0].getValue()
        #EDVerbose.DEBUG( self.__xsDataExperimentCharacterisation.marshal() )
        if self.__bDoStrategyCalculation:
            xsDataInputStrategy = XSDataInputStrategy()
            xsDataSolutionSelected = self.__xsDataResultCharacterisation.getIndexingResult().getSelectedSolution()
            xsDataInputStrategy.setCrystalRefined(xsDataSolutionSelected.getCrystal())
            xsDataInputStrategy.setSample(self.__xsDataResultCharacterisation.getDataCollection().getSample())
            xsDataIntegrationSubWedgeResultList = xsDataIntegrationOutput.getIntegrationSubWedgeResult()
            xsDataInputStrategy.setBestFileContentDat(xsDataIntegrationSubWedgeResultList[0].getBestfileDat())
            xsDataInputStrategy.setBestFileContentPar(xsDataIntegrationSubWedgeResultList[0].getBestfilePar())
            xsDataInputStrategy.setExperimentalCondition(xsDataIntegrationSubWedgeResultList[0].getExperimentalConditionRefined())
            for xsDataIntegrationSubWedgeResult in xsDataIntegrationSubWedgeResultList:
                xsDataInputStrategy.addBestFileContentHKL(xsDataIntegrationSubWedgeResult.getBestfileHKL())
            xsDataInputStrategy.setDiffractionPlan(self.__xsDataResultCharacterisation.getDataCollection().getDiffractionPlan())
            self.__edPluginControlStrategy.setDataInput(xsDataInputStrategy)
            self.__edPluginControlStrategy.executeSynchronous()



    def doFailureIntegration(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureIntegration")
        strErrorMessage = "Execution of integration plugin failed."
        self.addStatusMessage("Integration FAILURE.")
        EDVerbose.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        #self.addComment("integration failure")
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)
        self.generateExecutiveSummary(self)
        self.setFailure()
        if self.__strStatusMessage != None:
            self.setDataOutput(XSDataString(self.__strStatusMessage), "statusMessage")
            self.writeDataOutput()


    def doSuccessStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doSuccessStrategy")
        self.retrieveSuccessMessages(self.__edPluginControlStrategy, "EDPluginControlCharacterisationv1_2.doSuccessStrategy")
        xsDataStrategyResult = self.__edPluginControlStrategy.getDataOutput()
        self.__xsDataResultCharacterisation.setStrategyResult(xsDataStrategyResult)
        if self.__edPluginControlStrategy.hasDataOutput("strategyShortSummary"):
            self.__strCharacterisationShortSummary += self.__edPluginControlStrategy.getDataOutput("strategyShortSummary")[0].getValue()
        self.addStatusMessage("Strategy calculation successful.")


    def doFailureStrategy(self, _edPlugin=None):
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.doFailureStrategy")
        strErrorMessage = "Execution of strategy plugin failed."
        EDVerbose.ERROR(strErrorMessage)
        self.addErrorMessage(strErrorMessage)
        if self.__xsDataResultCharacterisation is not None:
            self.setDataOutput(self.__xsDataResultCharacterisation)
        self.addStatusMessage("Strategy calculation FAILURE.")
        self.generateExecutiveSummary(self)
        if self.__strStatusMessage != None:
            self.setDataOutput(XSDataString(self.__strStatusMessage), "statusMessage")
            self.writeDataOutput()
        self.setFailure()


    def generateExecutiveSummary(self, _edPlugin):
        """
        Generates a summary of the execution of the plugin.
        """
        EDVerbose.DEBUG("EDPluginControlCharacterisationv1_2.generateExecutiveSummary")
        self.addExecutiveSummaryLine("Summary of characterisation:")
        xsDataInputStrategy = self.getDataInput()
        xsDataCollection = xsDataInputStrategy.getDataCollection()
        xsDataDiffractionPlan = xsDataCollection.getDiffractionPlan()
        self.addExecutiveSummaryLine("Diffraction plan:")
        if (xsDataDiffractionPlan.getComplexity() is not None):
            self.addExecutiveSummaryLine("BEST complexity                       : %s" % xsDataDiffractionPlan.getComplexity().getValue())
        if (xsDataDiffractionPlan.getAimedCompleteness() is not None):
            self.addExecutiveSummaryLine("Aimed completeness                    : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getAimedCompleteness().getValue()))
        if (xsDataDiffractionPlan.getRequiredCompleteness() is not None):
            self.addExecutiveSummaryLine("Required completeness                 : %6.1f [%%]" % (100.0 * xsDataDiffractionPlan.getRequiredCompleteness().getValue()))
        if (xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution() is not None):
            self.addExecutiveSummaryLine("Aimed I/sigma at highest resolution   : %6.1f" % xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution().getValue())
        if (xsDataDiffractionPlan.getAimedResolution() is not None):
            self.addExecutiveSummaryLine("Aimed resolution                      : %6.1f [A]" % xsDataDiffractionPlan.getAimedResolution().getValue())
        if (xsDataDiffractionPlan.getRequiredResolution() is not None):
            self.addExecutiveSummaryLine("Required resolution                   : %6.1f [A]" % xsDataDiffractionPlan.getRequiredResolution().getValue())
        if (xsDataDiffractionPlan.getAimedMultiplicity() is not None):
            self.addExecutiveSummaryLine("Aimed multiplicity                    : %6.1f" % xsDataDiffractionPlan.getAimedMultiplicity().getValue())
        if (xsDataDiffractionPlan.getRequiredMultiplicity() is not None):
            self.addExecutiveSummaryLine("Required multiplicity                 : %6.1f" % xsDataDiffractionPlan.getRequiredMultiplicity().getValue())
        if (xsDataDiffractionPlan.getForcedSpaceGroup() is not None):
            self.addExecutiveSummaryLine("Forced space group                    : %6s" % xsDataDiffractionPlan.getForcedSpaceGroup().getValue())
        if (xsDataDiffractionPlan.getMaxExposureTimePerDataCollection() is not None):
            self.addExecutiveSummaryLine("Max exposure time per data collection : %6.1f [s]" % xsDataDiffractionPlan.getMaxExposureTimePerDataCollection().getValue())
        self.addExecutiveSummarySeparator()
        if self.__edPluginControlIndexingIndicators is not None:
            self.appendExecutiveSummary(self.__edPluginControlIndexingIndicators, "")
        if self.__edPluginControlIndexingLabelit is not None:
            self.appendExecutiveSummary(self.__edPluginControlIndexingLabelit, "")
        if self.__edPluginControlIntegration is not None:
            self.appendExecutiveSummary(self.__edPluginControlIntegration, "")
        if self.__edPluginControlStrategy is not None:
            self.appendExecutiveSummary(self.__edPluginControlStrategy, "")
        self.addExecutiveSummarySeparator()
        if self.__strCharacterisationShortSummary is not None:
            self.addExecutiveSummaryLine("Characterisation short summary:")
            self.addExecutiveSummaryLine("")
            if self.__strStatusMessage != None:
                for strLine in self.__strStatusMessage.split(". "):
                    if strLine.endswith("."):
                        self.addExecutiveSummaryLine(strLine)
                    else:
                        self.addExecutiveSummaryLine(strLine+".")
            self.addExecutiveSummaryLine("")
            for strLine in self.__strCharacterisationShortSummary.split("\n"):
                if strLine != "\n":
                    self.addExecutiveSummaryLine(strLine)
        self.addErrorWarningMessagesToExecutiveSummary("Characterisation error and warning messages: ")
        self.addExecutiveSummarySeparator()


    def getPluginStrategyName(self):
        return self.__strPluginControlStrategy


    def addStatusMessage(self, _strStatusMessage):
        if self.__strStatusMessage != "":
            self.__strStatusMessage += " "
        self.__strStatusMessage += _strStatusMessage

        
    def doStrategyCalculation(self, _bValue):
        self.__bDoStrategyCalculation = _bValue
    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()))