def process(self, _edObject=None):
        """
        Sends store requests with the screening objects to the dbserver. Returns success or failure.
        
        Note that:
        * Any objects referred to by the object returned by self.getDataInput("inputISPyB")[0] will be stored. 
        * Primary key attributes should not be set.
        * If a foreign key attribute is not set, this method will attempt to find the foreign object among the 
        input objects, and then use the primary key attribute of this object when it has been stored. If such 
        an object is not found, the method fails.
        * If an error is encountered, the method will immediately fail and will not attempt to store any more 
        objects. 
        """

        EDPluginExec.process(self)
        EDVerbose.DEBUG("*** EDPluginISPyBv1_2.process")

        # Basic sanity check of inputs:
        if (self.hasDataInput("screening")):
            if (len(self.getDataInput("screening")) > 1):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2", "process", "There should only be one input 'screening'.")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

        if (self.hasDataInput("screeningRankSet")):
            if (len(self.getDataInput("screeningRankSet")) > 1):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2", "process", "There should only be one input 'screeningRankSet'.")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

        # Get the inputs
        xsDataISPyBScreenings = None
        xsDataISPyBScreeningInputs = None
        xsDataISPyBScreeningOutputContainers = None
        xsDataISPyBScreeningRanks = None
        xsDataISPyBScreeningRankSets = None
        xsDataISPyBImages = None
        xsDataISPyBScreeningFiles = None

        if self.hasDataInput("screening"):
            xsDataISPyBScreenings = self.getDataInput("screening")
        if self.hasDataInput("screeningInput"):
            xsDataISPyBScreeningInputs = self.getDataInput("screeningInput")
        if self.hasDataInput("screeningOutputContainer"):
            xsDataISPyBScreeningOutputContainers = self.getDataInput("screeningOutputContainer")
        if self.hasDataInput("screeningRank"):
            xsDataISPyBScreeningRanks = self.getDataInput("screeningRank")
        if self.hasDataInput("screeningRankSet"):
            xsDataISPyBScreeningRankSets = self.getDataInput("screeningRankSet")
        if self.hasDataInput("image"):
            xsDataISPyBImages = self.getDataInput("image")
        if self.hasDataInput("screeningFile"):
            xsDataISPyBScreeningFiles = self.getDataInput("screeningFile")

        self.__xsDataResultISPyB = XSDataResultISPyB()

        if (xsDataISPyBScreenings is None):
            xsDataISPyBScreening = XSDataISPyBScreening()
        else:
            xsDataISPyBScreening = xsDataISPyBScreenings[0]

        if (xsDataISPyBImages is None):
            xsDataISPyBImage = None
        else:
            xsDataISPyBImage = xsDataISPyBImages[0]

        # Another sanity check:
        if xsDataISPyBScreening.getDataCollectionId() == None:
            if ((xsDataISPyBImage == None) or (xsDataISPyBImage.getFileName() == None) or (xsDataISPyBImage.getFileLocation() == None)):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2", "process", \
                                                                     "Neither a dataCollectionId nor an image filename + path are provided.")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                return

            strXML = EDUtilsXML.dnaMarshal(xsDataISPyBImage)

            # Send the XML to request the dataCollectionId from the dbserver:
            strResponse = self.httpPost(self.getDbserverHost(), self.getDbserverPort(), "/get_datacollectionid", strXML)

            if strResponse != None:
                # Handle response:
                xsDatadbstatus = XSDatadbstatus.parseString(strResponse)
                strCode = xsDatadbstatus.getCode()
                strMessage = xsDatadbstatus.getMessage()
                EDVerbose.DEBUG("dbserver returns code: " + strCode)
                EDVerbose.DEBUG("dbserver returns message: " + strMessage)

                if (strCode == "error") or (xsDatadbstatus.getDataCollectionId() == -1):
                    if xsDatadbstatus.getDataCollectionId() == -1:
                        strMessage = "An image corresponding to the given fileName and fileLocation was not found."
                    strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2", "process", strMessage)
                    EDVerbose.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    return

                if xsDatadbstatus.getDataCollectionId() != -1:
                    xsDataISPyBScreening.setDataCollectionId(XSDataInteger(xsDatadbstatus.getDataCollectionId()))
                    self.__xsDataResultISPyB.setDataCollectionId(XSDataInteger(xsDatadbstatus.getDataCollectionId()))

        if (xsDataISPyBScreeningRankSets is None):
            xsDataISPyBScreeningRankSet = None
        else:
            xsDataISPyBScreeningRankSet = xsDataISPyBScreeningRankSets[0]

        # Store all the different screening* objects:
        xsDataIntegerScreeningId = self.store(xsDataISPyBScreening)

        if xsDataISPyBScreeningInputs != None:
            for xsDataISPyBScreeningInput in xsDataISPyBScreeningInputs:
                xsDataISPyBScreeningInput.setScreeningId(xsDataIntegerScreeningId)
                self.store(xsDataISPyBScreeningInput)

        if xsDataISPyBScreeningRankSet != None:
            xsDataIntegerScreeningRankSetId = self.store(xsDataISPyBScreeningRankSet)

            for xsDataISPyBScreeningRank in xsDataISPyBScreeningRanks:
                xsDataISPyBScreeningRank.setScreeningId(xsDataIntegerScreeningId)
                xsDataISPyBScreeningRank.setScreeningRankSetId(xsDataIntegerScreeningRankSetId)
                self.store(xsDataISPyBScreeningRank)

        if xsDataISPyBScreeningOutputContainers != None:
            for xsDataISPyBScreeningOutputContainer in xsDataISPyBScreeningOutputContainers:
                xsDataISPyBScreeningOutput = xsDataISPyBScreeningOutputContainer.getScreeningOutput()
                xsDataISPyBScreeningOutput.setScreeningId(xsDataIntegerScreeningId)
                xsDataIntegerScreeningOutputId = self.store(xsDataISPyBScreeningOutput)

            xsDataISPyBScreeningOutputLattices = xsDataISPyBScreeningOutputContainer.getScreeningOutputLattice()
            if xsDataISPyBScreeningOutputLattices != None:
                for xsDataISPyBScreeningOutputLattice in xsDataISPyBScreeningOutputLattices:
                    xsDataISPyBScreeningOutputLattice.setScreeningOutputId(xsDataIntegerScreeningOutputId)
                    self.store(xsDataISPyBScreeningOutputLattice)

            xsDataISPyBScreeningStrategyContainers = xsDataISPyBScreeningOutputContainer.getScreeningStrategyContainer()
            if xsDataISPyBScreeningStrategyContainers != None:
                for xsDataISPyBScreeningStrategyContainer in xsDataISPyBScreeningStrategyContainers:
                    xsDataISPyBScreeningStrategy = xsDataISPyBScreeningStrategyContainer.getScreeningStrategy()
                    if xsDataISPyBScreeningStrategy != None:
                        xsDataISPyBScreeningStrategy.setScreeningOutputId(xsDataIntegerScreeningOutputId)
                        xsDataIntegerScreeningStrategyId = self.store(xsDataISPyBScreeningStrategy)

                        xsDataISPyBScreeningStrategyWedgeContainers = xsDataISPyBScreeningStrategyContainer.getScreeningStrategyWedgeContainer()
                        if xsDataISPyBScreeningStrategyWedgeContainers != None:
                            for xsDataISPyBScreeningStrategyWedgeContainer in xsDataISPyBScreeningStrategyWedgeContainers:
                                xsDataISPyBScreeningStrategyWedge = xsDataISPyBScreeningStrategyWedgeContainer.getScreeningStrategyWedge()
                                xsDataISPyBScreeningStrategyWedge.setScreeningStrategyId(xsDataIntegerScreeningStrategyId)
                                xsDataIntegerScreeningStrategyWedgeId = self.store(xsDataISPyBScreeningStrategyWedge)

                                xsDataISPyBScreeningStrategySubWedges = xsDataISPyBScreeningStrategyWedgeContainer.getScreeningStrategySubWedge()
                                if xsDataISPyBScreeningStrategySubWedges != None:
                                    for xsDataISPyBScreeningStrategySubWedge in xsDataISPyBScreeningStrategySubWedges:
                                        xsDataISPyBScreeningStrategySubWedge.setScreeningStrategyWedgeId(xsDataIntegerScreeningStrategyWedgeId)
                                        self.store(xsDataISPyBScreeningStrategySubWedge)
    def testSetDataModelInput(self):
        """
        A test for whether we can obtain the expected XML by setting a certain input for the plugin. 
        """
        edPluginISPyB = self.createPlugin()
        xsPluginItemISPyB = self.getPluginConfiguration(os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml"))
        edPluginISPyB.setConfiguration(xsPluginItemISPyB)
        edPluginISPyB.configure()

        # Create XSDataISPyB objects

        xsDataISPyBImage = XSDataISPyBImage()
        xsDataISPyBImage.setFileName(XSDataString("test.img"))
        xsDataISPyBImage.setFileLocation(XSDataString("/tmp"))

        xsDataISPyBScreening = XSDataISPyBScreening()
        xsDataISPyBScreening.setProgramVersion(XSDataString("EDNA Prototype"))

        xsDataISPyBScreeningInput = XSDataISPyBScreeningInput()
        xsDataISPyBScreeningInput.setBeamX(XSDataDouble(10.4))
        xsDataISPyBScreeningInput.setBeamY(XSDataDouble(2.31))
        xsDataISPyBScreeningInput.setRmsErrorLimits(XSDataDouble(0.8))
        xsDataISPyBScreeningInput.setMinimumFractionIndexed(XSDataDouble(0.4))
        xsDataISPyBScreeningInput.setMaximumFractionRejected(XSDataDouble(0.45))
        xsDataISPyBScreeningInput.setMinimumSignalToNoise(XSDataDouble(0.56))

        xsDataISPyBScreeningOutput = XSDataISPyBScreeningOutput()
        xsDataISPyBScreeningOutput.setStatusDescription(XSDataString("It's just fine."))
        xsDataISPyBScreeningOutput.setMosaicity(XSDataDouble(0.25))
        xsDataISPyBScreeningOutput.setBeamShiftX(XSDataDouble (0.141))
        xsDataISPyBScreeningOutput.setBeamShiftY(XSDataDouble (0.156))

        xsDataISPyBScreeningOutputLattice = XSDataISPyBScreeningOutputLattice()
        xsDataISPyBScreeningOutputLattice.setSpaceGroup(XSDataString("P222"))

        xsDataISPyBScreeningStrategy = XSDataISPyBScreeningStrategy()
        xsDataISPyBScreeningStrategy.setPhiStart(XSDataDouble(0))
        xsDataISPyBScreeningStrategy.setPhiEnd(XSDataDouble(20))
        xsDataISPyBScreeningStrategy.setRotation(XSDataDouble(1))
        xsDataISPyBScreeningStrategy.setProgram(XSDataString("EDNA"))
        xsDataISPyBScreeningStrategy.setAnomalous(XSDataBoolean(1))

        xsDataISPyBScreeningStrategyWedge = XSDataISPyBScreeningStrategyWedge()
        xsDataISPyBScreeningStrategyWedge.setWedgeNumber(XSDataInteger(1))
        xsDataISPyBScreeningStrategyWedge.setResolution(XSDataDouble(2.1))
        xsDataISPyBScreeningStrategyWedge.setCompleteness(XSDataDouble(90))
        xsDataISPyBScreeningStrategyWedge.setMultiplicity(XSDataDouble(1.5))
        xsDataISPyBScreeningStrategyWedge.setDoseTotal(XSDataDouble(40.5))
        xsDataISPyBScreeningStrategyWedge.setNumberOfImages(XSDataInteger(130))

        xsDataISPyBScreeningStrategySubWedge = XSDataISPyBScreeningStrategySubWedge()
        xsDataISPyBScreeningStrategySubWedge.setSubWedgeNumber(XSDataInteger(1))
        xsDataISPyBScreeningStrategySubWedge.setRotationAxis(XSDataString("Omega"))
        xsDataISPyBScreeningStrategySubWedge.setAxisStart(XSDataDouble(0.0))
        xsDataISPyBScreeningStrategySubWedge.setAxisEnd(XSDataDouble(90.0))
        xsDataISPyBScreeningStrategySubWedge.setExposureTime(XSDataDouble(0.5))
        xsDataISPyBScreeningStrategySubWedge.setTransmission(XSDataDouble(100.0))
        xsDataISPyBScreeningStrategySubWedge.setNumberOfImages(XSDataInteger(130))

        xsDataISPyBScreeningStrategyWedgeContainer = XSDataISPyBScreeningStrategyWedgeContainer()
        xsDataISPyBScreeningStrategyWedgeContainer.setScreeningStrategyWedge(xsDataISPyBScreeningStrategyWedge)
        xsDataISPyBScreeningStrategyWedgeContainer.getScreeningStrategySubWedge().append(xsDataISPyBScreeningStrategySubWedge)

        xsDataISPyBScreeningStrategyContainer = XSDataISPyBScreeningStrategyContainer()
        xsDataISPyBScreeningStrategyContainer.setScreeningStrategy(xsDataISPyBScreeningStrategy)
        xsDataISPyBScreeningStrategyContainer.getScreeningStrategyWedgeContainer().append(xsDataISPyBScreeningStrategyWedgeContainer)

        xsDataISPyBScreeningOutputContainer = XSDataISPyBScreeningOutputContainer()
        xsDataISPyBScreeningOutputContainer.setScreeningOutput(xsDataISPyBScreeningOutput)
        xsDataISPyBScreeningOutputContainer.getScreeningOutputLattice().append(xsDataISPyBScreeningOutputLattice)
        xsDataISPyBScreeningOutputContainer.getScreeningStrategyContainer().append(xsDataISPyBScreeningStrategyContainer)

        xsDataISPyBScreeningRank = XSDataISPyBScreeningRank()
        xsDataISPyBScreeningRank.setRankValue(XSDataDouble(1.4))
        xsDataISPyBScreeningRank.setRankInformation(XSDataString("This is the only one"))

        xsDataISPyBScreeningRankSet = XSDataISPyBScreeningRankSet()
        xsDataISPyBScreeningRankSet.setRankEngine(XSDataString("ISPyB"))

        xsDataISPyBScreeningFile = XSDataISPyBScreeningFile()
        xsDataISPyBScreeningFile.setFileType(XSDataString("log"))
        xsDataISPyBScreeningFile.setDescription(XSDataString("Output log file"))

        # Write XSDataISPyB objects to files
        xsDataISPyBScreening.outputFile(self.__strObtainedScreening)
        xsDataISPyBScreeningInput.outputFile(self.__strObtainedScreeningInput)
        xsDataISPyBScreeningOutputContainer.outputFile(self.__strObtainedScreeningOutputContainer)
        xsDataISPyBScreeningRank.outputFile(self.__strObtainedScreeningRank)
        xsDataISPyBScreeningRankSet.outputFile(self.__strObtainedScreeningRankSet)
        xsDataISPyBScreeningFile.outputFile(self.__strObtainedScreeningFile)

        # Compare screening
        strInputScreeningExpected = self.readAndParseFile(self.__strReferenceInputScreening)
        xsDataScreeningExpected = XSDataInputISPyB.parseString(strInputScreeningExpected)
        strXMLScreeningExpected = xsDataScreeningExpected.marshal()

        strScreeningObtained = self.readAndParseFile(self.__strObtainedScreening)
        xsDataScreeningObtained = XSDataInputISPyB.parseString(strScreeningObtained)
        strXMLScreeningObtained = xsDataScreeningObtained.marshal()

        EDAssert.equal(strXMLScreeningExpected, strXMLScreeningObtained)

        #Compare screeningInput
        strInputScreeningInputExpected = self.readAndParseFile(self.__strReferenceInputScreeningInput)
        xsDataScreeningInputExpected = XSDataInputISPyB.parseString(strInputScreeningInputExpected)
        strXMLScreeningInputExpected = xsDataScreeningInputExpected.marshal()

        strScreeningInputObtained = self.readAndParseFile(self.__strObtainedScreeningInput)
        xsDataScreeningInputObtained = XSDataInputISPyB.parseString(strScreeningInputObtained)
        strXMLScreeningInputObtained = xsDataScreeningInputObtained.marshal()

        EDAssert.equal(strXMLScreeningInputExpected, strXMLScreeningInputObtained)

        #Compare screeningOutputContainer
        strInputScreeningOutputContainerExpected = self.readAndParseFile(self.__strReferenceInputScreeningOutputContainer)
        xsDataScreeningOutputContainerExpected = XSDataInputISPyB.parseString(strInputScreeningOutputContainerExpected)
        strXMLScreeningOutputContainerExpected = xsDataScreeningOutputContainerExpected.marshal()

        strScreeningOutputContainerObtained = self.readAndParseFile(self.__strObtainedScreeningOutputContainer)
        xsDataScreeningOutputContainerObtained = XSDataInputISPyB.parseString(strScreeningOutputContainerObtained)
        strXMLScreeningOutputContainerObtained = xsDataScreeningOutputContainerObtained.marshal()

        EDAssert.equal(strXMLScreeningOutputContainerExpected, strXMLScreeningOutputContainerObtained)

        #Compare screeningRank
        strInputScreeningRankExpected = self.readAndParseFile(self.__strReferenceInputScreeningRank)
        xsDataScreeningRankExpected = XSDataInputISPyB.parseString(strInputScreeningRankExpected)
        strXMLScreeningRankExpected = xsDataScreeningRankExpected.marshal()

        strScreeningRankObtained = self.readAndParseFile(self.__strObtainedScreeningRank)
        xsDataScreeningRankObtained = XSDataInputISPyB.parseString(strScreeningRankObtained)
        strXMLScreeningRankObtained = xsDataScreeningRankObtained.marshal()

        EDAssert.equal(strXMLScreeningRankExpected, strXMLScreeningRankObtained)

        #Compare screeningRankSet
        strInputScreeningRankSetExpected = self.readAndParseFile(self.__strReferenceInputScreeningRankSet)
        xsDataScreeningRankSetExpected = XSDataInputISPyB.parseString(strInputScreeningRankSetExpected)
        strXMLScreeningRankSetExpected = xsDataScreeningRankSetExpected.marshal()

        strScreeningRankSetObtained = self.readAndParseFile(self.__strObtainedScreeningRankSet)
        xsDataScreeningRankSetObtained = XSDataInputISPyB.parseString(strScreeningRankSetObtained)
        strXMLScreeningRankSetObtained = xsDataScreeningRankSetObtained.marshal()

        EDAssert.equal(strXMLScreeningRankSetExpected, strXMLScreeningRankSetObtained)

        #Compare screeningFile
        strInputScreeningFileExpected = self.readAndParseFile(self.__strReferenceInputScreeningFile)
        xsDataScreeningFileExpected = XSDataInputISPyB.parseString(strInputScreeningFileExpected)
        strXMLScreeningFileExpected = xsDataScreeningFileExpected.marshal()

        strScreeningFileObtained = self.readAndParseFile(self.__strObtainedScreeningFile)
        xsDataScreeningFileObtained = XSDataInputISPyB.parseString(strScreeningFileObtained)
        strXMLScreeningFileObtained = xsDataScreeningFileObtained.marshal()

        EDAssert.equal(strXMLScreeningFileExpected, strXMLScreeningFileObtained)

        self.cleanUp(edPluginISPyB)
    def generateXSDataISPyBScreening(_xsDataInputControlISPyB,
                                     _strShortComments=None,
                                     _strComments=None):
        """
        """
        EDFactoryPluginStatic.loadModule("XSDataISPyBv1_2")
        from XSDataISPyBv1_2 import XSDataString
        from XSDataISPyBv1_2 import XSDataISPyBScreening

        xsDataIntegerDataCollectionId = _xsDataInputControlISPyB.getDataCollectionId(
        )

        # General information
        xsDataISPyBScreening = XSDataISPyBScreening()
        xsDataISPyBScreening.setProgramVersion(XSDataString("EDNA MXv1"))
        pyStrTimeStamp = time.strftime("%Y-%m-%d %H:%M:%S")
        xsDataISPyBScreening.setTimeStamp(XSDataString(pyStrTimeStamp))
        if (not _strShortComments is None):
            xsDataISPyBScreening.setShortComments(
                XSDataString(_strShortComments))
        if (not _strComments is None):
            xsDataISPyBScreening.setComments(XSDataString(_strComments))

        # Use dataCollectionId if provided in the input
        if (xsDataIntegerDataCollectionId is not None):
            xsDataISPyBScreening.setDataCollectionId(
                xsDataIntegerDataCollectionId)

        return xsDataISPyBScreening
    def generateXSDataISPyBScreening(_xsDataInputControlISPyB, _strShortComments=None, _strComments=None):
        """
        """
        EDFactoryPluginStatic.loadModule("XSDataISPyBv1_2")
        from XSDataISPyBv1_2 import XSDataString
        from XSDataISPyBv1_2 import XSDataISPyBScreening

        xsDataIntegerDataCollectionId = _xsDataInputControlISPyB.getDataCollectionId()

        # General information
        xsDataISPyBScreening = XSDataISPyBScreening()
        xsDataISPyBScreening.setProgramVersion(XSDataString("EDNA MXv1"))
        pyStrTimeStamp = time.strftime("%Y-%m-%d %H:%M:%S")
        xsDataISPyBScreening.setTimeStamp(XSDataString(pyStrTimeStamp))
        if (not _strShortComments is None):
            xsDataISPyBScreening.setShortComments(XSDataString(_strShortComments))
        if (not _strComments is None):
            xsDataISPyBScreening.setComments(XSDataString(_strComments))

        # Use dataCollectionId if provided in the input
        if (xsDataIntegerDataCollectionId is not None):
            xsDataISPyBScreening.setDataCollectionId(xsDataIntegerDataCollectionId)

        return xsDataISPyBScreening
示例#5
0
    def testSetDataModelInput(self):
        """
        A test for whether we can obtain the expected XML by setting a certain input for the plugin. 
        """
        edPluginISPyB = self.createPlugin()
        xsPluginItemISPyB = self.getPluginConfiguration(
            os.path.join(self.getPluginTestsDataHome(), "XSConfiguration.xml"))
        edPluginISPyB.setConfiguration(xsPluginItemISPyB)
        edPluginISPyB.configure()

        # Create XSDataISPyB objects

        xsDataISPyBImage = XSDataISPyBImage()
        xsDataISPyBImage.setFileName(XSDataString("test.img"))
        xsDataISPyBImage.setFileLocation(XSDataString("/tmp"))

        xsDataISPyBScreening = XSDataISPyBScreening()
        xsDataISPyBScreening.setProgramVersion(XSDataString("EDNA Prototype"))

        xsDataISPyBScreeningInput = XSDataISPyBScreeningInput()
        xsDataISPyBScreeningInput.setBeamX(XSDataDouble(10.4))
        xsDataISPyBScreeningInput.setBeamY(XSDataDouble(2.31))
        xsDataISPyBScreeningInput.setRmsErrorLimits(XSDataDouble(0.8))
        xsDataISPyBScreeningInput.setMinimumFractionIndexed(XSDataDouble(0.4))
        xsDataISPyBScreeningInput.setMaximumFractionRejected(
            XSDataDouble(0.45))
        xsDataISPyBScreeningInput.setMinimumSignalToNoise(XSDataDouble(0.56))

        xsDataISPyBScreeningOutput = XSDataISPyBScreeningOutput()
        xsDataISPyBScreeningOutput.setStatusDescription(
            XSDataString("It's just fine."))
        xsDataISPyBScreeningOutput.setMosaicity(XSDataDouble(0.25))
        xsDataISPyBScreeningOutput.setBeamShiftX(XSDataDouble(0.141))
        xsDataISPyBScreeningOutput.setBeamShiftY(XSDataDouble(0.156))

        xsDataISPyBScreeningOutputLattice = XSDataISPyBScreeningOutputLattice()
        xsDataISPyBScreeningOutputLattice.setSpaceGroup(XSDataString("P222"))

        xsDataISPyBScreeningStrategy = XSDataISPyBScreeningStrategy()
        xsDataISPyBScreeningStrategy.setPhiStart(XSDataDouble(0))
        xsDataISPyBScreeningStrategy.setPhiEnd(XSDataDouble(20))
        xsDataISPyBScreeningStrategy.setRotation(XSDataDouble(1))
        xsDataISPyBScreeningStrategy.setProgram(XSDataString("EDNA"))
        xsDataISPyBScreeningStrategy.setAnomalous(XSDataBoolean(1))

        xsDataISPyBScreeningStrategyWedge = XSDataISPyBScreeningStrategyWedge()
        xsDataISPyBScreeningStrategyWedge.setWedgeNumber(XSDataInteger(1))
        xsDataISPyBScreeningStrategyWedge.setResolution(XSDataDouble(2.1))
        xsDataISPyBScreeningStrategyWedge.setCompleteness(XSDataDouble(90))
        xsDataISPyBScreeningStrategyWedge.setMultiplicity(XSDataDouble(1.5))
        xsDataISPyBScreeningStrategyWedge.setDoseTotal(XSDataDouble(40.5))
        xsDataISPyBScreeningStrategyWedge.setNumberOfImages(XSDataInteger(130))

        xsDataISPyBScreeningStrategySubWedge = XSDataISPyBScreeningStrategySubWedge(
        )
        xsDataISPyBScreeningStrategySubWedge.setSubWedgeNumber(
            XSDataInteger(1))
        xsDataISPyBScreeningStrategySubWedge.setRotationAxis(
            XSDataString("Omega"))
        xsDataISPyBScreeningStrategySubWedge.setAxisStart(XSDataDouble(0.0))
        xsDataISPyBScreeningStrategySubWedge.setAxisEnd(XSDataDouble(90.0))
        xsDataISPyBScreeningStrategySubWedge.setExposureTime(XSDataDouble(0.5))
        xsDataISPyBScreeningStrategySubWedge.setTransmission(
            XSDataDouble(100.0))
        xsDataISPyBScreeningStrategySubWedge.setNumberOfImages(
            XSDataInteger(130))

        xsDataISPyBScreeningStrategyWedgeContainer = XSDataISPyBScreeningStrategyWedgeContainer(
        )
        xsDataISPyBScreeningStrategyWedgeContainer.setScreeningStrategyWedge(
            xsDataISPyBScreeningStrategyWedge)
        xsDataISPyBScreeningStrategyWedgeContainer.getScreeningStrategySubWedge(
        ).append(xsDataISPyBScreeningStrategySubWedge)

        xsDataISPyBScreeningStrategyContainer = XSDataISPyBScreeningStrategyContainer(
        )
        xsDataISPyBScreeningStrategyContainer.setScreeningStrategy(
            xsDataISPyBScreeningStrategy)
        xsDataISPyBScreeningStrategyContainer.getScreeningStrategyWedgeContainer(
        ).append(xsDataISPyBScreeningStrategyWedgeContainer)

        xsDataISPyBScreeningOutputContainer = XSDataISPyBScreeningOutputContainer(
        )
        xsDataISPyBScreeningOutputContainer.setScreeningOutput(
            xsDataISPyBScreeningOutput)
        xsDataISPyBScreeningOutputContainer.getScreeningOutputLattice().append(
            xsDataISPyBScreeningOutputLattice)
        xsDataISPyBScreeningOutputContainer.getScreeningStrategyContainer(
        ).append(xsDataISPyBScreeningStrategyContainer)

        xsDataISPyBScreeningRank = XSDataISPyBScreeningRank()
        xsDataISPyBScreeningRank.setRankValue(XSDataDouble(1.4))
        xsDataISPyBScreeningRank.setRankInformation(
            XSDataString("This is the only one"))

        xsDataISPyBScreeningRankSet = XSDataISPyBScreeningRankSet()
        xsDataISPyBScreeningRankSet.setRankEngine(XSDataString("ISPyB"))

        xsDataISPyBScreeningFile = XSDataISPyBScreeningFile()
        xsDataISPyBScreeningFile.setFileType(XSDataString("log"))
        xsDataISPyBScreeningFile.setDescription(
            XSDataString("Output log file"))

        # Write XSDataISPyB objects to files
        xsDataISPyBScreening.outputFile(self.__strObtainedScreening)
        xsDataISPyBScreeningInput.outputFile(self.__strObtainedScreeningInput)
        xsDataISPyBScreeningOutputContainer.outputFile(
            self.__strObtainedScreeningOutputContainer)
        xsDataISPyBScreeningRank.outputFile(self.__strObtainedScreeningRank)
        xsDataISPyBScreeningRankSet.outputFile(
            self.__strObtainedScreeningRankSet)
        xsDataISPyBScreeningFile.outputFile(self.__strObtainedScreeningFile)

        # Compare screening
        strInputScreeningExpected = self.readAndParseFile(
            self.__strReferenceInputScreening)
        xsDataScreeningExpected = XSDataInputISPyB.parseString(
            strInputScreeningExpected)
        strXMLScreeningExpected = xsDataScreeningExpected.marshal()

        strScreeningObtained = self.readAndParseFile(
            self.__strObtainedScreening)
        xsDataScreeningObtained = XSDataInputISPyB.parseString(
            strScreeningObtained)
        strXMLScreeningObtained = xsDataScreeningObtained.marshal()

        EDAssert.equal(strXMLScreeningExpected, strXMLScreeningObtained)

        #Compare screeningInput
        strInputScreeningInputExpected = self.readAndParseFile(
            self.__strReferenceInputScreeningInput)
        xsDataScreeningInputExpected = XSDataInputISPyB.parseString(
            strInputScreeningInputExpected)
        strXMLScreeningInputExpected = xsDataScreeningInputExpected.marshal()

        strScreeningInputObtained = self.readAndParseFile(
            self.__strObtainedScreeningInput)
        xsDataScreeningInputObtained = XSDataInputISPyB.parseString(
            strScreeningInputObtained)
        strXMLScreeningInputObtained = xsDataScreeningInputObtained.marshal()

        EDAssert.equal(strXMLScreeningInputExpected,
                       strXMLScreeningInputObtained)

        #Compare screeningOutputContainer
        strInputScreeningOutputContainerExpected = self.readAndParseFile(
            self.__strReferenceInputScreeningOutputContainer)
        xsDataScreeningOutputContainerExpected = XSDataInputISPyB.parseString(
            strInputScreeningOutputContainerExpected)
        strXMLScreeningOutputContainerExpected = xsDataScreeningOutputContainerExpected.marshal(
        )

        strScreeningOutputContainerObtained = self.readAndParseFile(
            self.__strObtainedScreeningOutputContainer)
        xsDataScreeningOutputContainerObtained = XSDataInputISPyB.parseString(
            strScreeningOutputContainerObtained)
        strXMLScreeningOutputContainerObtained = xsDataScreeningOutputContainerObtained.marshal(
        )

        EDAssert.equal(strXMLScreeningOutputContainerExpected,
                       strXMLScreeningOutputContainerObtained)

        #Compare screeningRank
        strInputScreeningRankExpected = self.readAndParseFile(
            self.__strReferenceInputScreeningRank)
        xsDataScreeningRankExpected = XSDataInputISPyB.parseString(
            strInputScreeningRankExpected)
        strXMLScreeningRankExpected = xsDataScreeningRankExpected.marshal()

        strScreeningRankObtained = self.readAndParseFile(
            self.__strObtainedScreeningRank)
        xsDataScreeningRankObtained = XSDataInputISPyB.parseString(
            strScreeningRankObtained)
        strXMLScreeningRankObtained = xsDataScreeningRankObtained.marshal()

        EDAssert.equal(strXMLScreeningRankExpected,
                       strXMLScreeningRankObtained)

        #Compare screeningRankSet
        strInputScreeningRankSetExpected = self.readAndParseFile(
            self.__strReferenceInputScreeningRankSet)
        xsDataScreeningRankSetExpected = XSDataInputISPyB.parseString(
            strInputScreeningRankSetExpected)
        strXMLScreeningRankSetExpected = xsDataScreeningRankSetExpected.marshal(
        )

        strScreeningRankSetObtained = self.readAndParseFile(
            self.__strObtainedScreeningRankSet)
        xsDataScreeningRankSetObtained = XSDataInputISPyB.parseString(
            strScreeningRankSetObtained)
        strXMLScreeningRankSetObtained = xsDataScreeningRankSetObtained.marshal(
        )

        EDAssert.equal(strXMLScreeningRankSetExpected,
                       strXMLScreeningRankSetObtained)

        #Compare screeningFile
        strInputScreeningFileExpected = self.readAndParseFile(
            self.__strReferenceInputScreeningFile)
        xsDataScreeningFileExpected = XSDataInputISPyB.parseString(
            strInputScreeningFileExpected)
        strXMLScreeningFileExpected = xsDataScreeningFileExpected.marshal()

        strScreeningFileObtained = self.readAndParseFile(
            self.__strObtainedScreeningFile)
        xsDataScreeningFileObtained = XSDataInputISPyB.parseString(
            strScreeningFileObtained)
        strXMLScreeningFileObtained = xsDataScreeningFileObtained.marshal()

        EDAssert.equal(strXMLScreeningFileExpected,
                       strXMLScreeningFileObtained)

        self.cleanUp(edPluginISPyB)
示例#6
0
    def process(self, _edObject=None):
        """
        Sends store requests with the screening objects to the dbserver. Returns success or failure.
        
        Note that:
        * Any objects referred to by the object returned by self.getDataInput("inputISPyB")[0] will be stored. 
        * Primary key attributes should not be set.
        * If a foreign key attribute is not set, this method will attempt to find the foreign object among the 
        input objects, and then use the primary key attribute of this object when it has been stored. If such 
        an object is not found, the method fails.
        * If an error is encountered, the method will immediately fail and will not attempt to store any more 
        objects. 
        """

        EDPluginExec.process(self)
        self.DEBUG("*** EDPluginISPyBv1_2.process")

        # Basic sanity check of inputs:
        if (self.hasDataInput("screening")):
            if (len(self.getDataInput("screening")) > 1):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                    "EDPluginISPyBv1_2", "process",
                    "There should only be one input 'screening'.")
                self.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

        if (self.hasDataInput("screeningRankSet")):
            if (len(self.getDataInput("screeningRankSet")) > 1):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                    "EDPluginISPyBv1_2", "process",
                    "There should only be one input 'screeningRankSet'.")
                self.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

        # Get the inputs
        xsDataISPyBScreenings = None
        xsDataISPyBScreeningInputs = None
        xsDataISPyBScreeningOutputContainers = None
        xsDataISPyBScreeningRanks = None
        xsDataISPyBScreeningRankSets = None
        xsDataISPyBImages = None
        xsDataISPyBScreeningFiles = None

        if self.hasDataInput("screening"):
            xsDataISPyBScreenings = self.getDataInput("screening")
        if self.hasDataInput("screeningInput"):
            xsDataISPyBScreeningInputs = self.getDataInput("screeningInput")
        if self.hasDataInput("screeningOutputContainer"):
            xsDataISPyBScreeningOutputContainers = self.getDataInput(
                "screeningOutputContainer")
        if self.hasDataInput("screeningRank"):
            xsDataISPyBScreeningRanks = self.getDataInput("screeningRank")
        if self.hasDataInput("screeningRankSet"):
            xsDataISPyBScreeningRankSets = self.getDataInput(
                "screeningRankSet")
        if self.hasDataInput("image"):
            xsDataISPyBImages = self.getDataInput("image")
        if self.hasDataInput("screeningFile"):
            xsDataISPyBScreeningFiles = self.getDataInput("screeningFile")

        self.__xsDataResultISPyB = XSDataResultISPyB()

        if (xsDataISPyBScreenings is None):
            xsDataISPyBScreening = XSDataISPyBScreening()
        else:
            xsDataISPyBScreening = xsDataISPyBScreenings[0]

        if (xsDataISPyBImages is None):
            xsDataISPyBImage = None
        else:
            xsDataISPyBImage = xsDataISPyBImages[0]

        # Another sanity check:
        if xsDataISPyBScreening.getDataCollectionId() == None:
            if ((xsDataISPyBImage == None)
                    or (xsDataISPyBImage.getFileName() == None)
                    or (xsDataISPyBImage.getFileLocation() == None)):
                strErrorMessage = EDMessage.ERROR_EXECUTION_03 % ("EDPluginISPyBv1_2", "process", \
                                                                     "Neither a dataCollectionId nor an image filename + path are provided.")
                self.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                return

            strXML = EDUtilsXML.dnaMarshal(xsDataISPyBImage)

            # Send the XML to request the dataCollectionId from the dbserver:
            strResponse = self.httpPost(self.getDbserverHost(),
                                        self.getDbserverPort(),
                                        "/get_datacollectionid", strXML)

            if strResponse != None:
                # Handle response:
                xsDatadbstatus = XSDatadbstatus.parseString(strResponse)
                strCode = xsDatadbstatus.getCode()
                strMessage = xsDatadbstatus.getMessage()
                self.DEBUG("dbserver returns code: " + strCode)
                self.DEBUG("dbserver returns message: " + strMessage)

                if (strCode
                        == "error") or (xsDatadbstatus.getDataCollectionId()
                                        == -1):
                    if xsDatadbstatus.getDataCollectionId() == -1:
                        strMessage = "An image corresponding to the given fileName and fileLocation was not found."
                    strErrorMessage = EDMessage.ERROR_EXECUTION_03 % (
                        "EDPluginISPyBv1_2", "process", strMessage)
                    self.error(strErrorMessage)
                    self.addErrorMessage(strErrorMessage)
                    return

                if xsDatadbstatus.getDataCollectionId() != -1:
                    xsDataISPyBScreening.setDataCollectionId(
                        XSDataInteger(xsDatadbstatus.getDataCollectionId()))
                    self.__xsDataResultISPyB.setDataCollectionId(
                        XSDataInteger(xsDatadbstatus.getDataCollectionId()))

        if (xsDataISPyBScreeningRankSets is None):
            xsDataISPyBScreeningRankSet = None
        else:
            xsDataISPyBScreeningRankSet = xsDataISPyBScreeningRankSets[0]

        # Store all the different screening* objects:
        xsDataIntegerScreeningId = self.store(xsDataISPyBScreening)

        if xsDataISPyBScreeningInputs != None:
            for xsDataISPyBScreeningInput in xsDataISPyBScreeningInputs:
                xsDataISPyBScreeningInput.setScreeningId(
                    xsDataIntegerScreeningId)
                self.store(xsDataISPyBScreeningInput)

        if xsDataISPyBScreeningRankSet != None:
            xsDataIntegerScreeningRankSetId = self.store(
                xsDataISPyBScreeningRankSet)

            for xsDataISPyBScreeningRank in xsDataISPyBScreeningRanks:
                xsDataISPyBScreeningRank.setScreeningId(
                    xsDataIntegerScreeningId)
                xsDataISPyBScreeningRank.setScreeningRankSetId(
                    xsDataIntegerScreeningRankSetId)
                self.store(xsDataISPyBScreeningRank)

        if xsDataISPyBScreeningOutputContainers != None:
            for xsDataISPyBScreeningOutputContainer in xsDataISPyBScreeningOutputContainers:
                xsDataISPyBScreeningOutput = xsDataISPyBScreeningOutputContainer.getScreeningOutput(
                )
                xsDataISPyBScreeningOutput.setScreeningId(
                    xsDataIntegerScreeningId)
                xsDataIntegerScreeningOutputId = self.store(
                    xsDataISPyBScreeningOutput)

            xsDataISPyBScreeningOutputLattices = xsDataISPyBScreeningOutputContainer.getScreeningOutputLattice(
            )
            if xsDataISPyBScreeningOutputLattices != None:
                for xsDataISPyBScreeningOutputLattice in xsDataISPyBScreeningOutputLattices:
                    xsDataISPyBScreeningOutputLattice.setScreeningOutputId(
                        xsDataIntegerScreeningOutputId)
                    self.store(xsDataISPyBScreeningOutputLattice)

            xsDataISPyBScreeningStrategyContainers = xsDataISPyBScreeningOutputContainer.getScreeningStrategyContainer(
            )
            if xsDataISPyBScreeningStrategyContainers != None:
                for xsDataISPyBScreeningStrategyContainer in xsDataISPyBScreeningStrategyContainers:
                    xsDataISPyBScreeningStrategy = xsDataISPyBScreeningStrategyContainer.getScreeningStrategy(
                    )
                    if xsDataISPyBScreeningStrategy != None:
                        xsDataISPyBScreeningStrategy.setScreeningOutputId(
                            xsDataIntegerScreeningOutputId)
                        xsDataIntegerScreeningStrategyId = self.store(
                            xsDataISPyBScreeningStrategy)

                        xsDataISPyBScreeningStrategyWedgeContainers = xsDataISPyBScreeningStrategyContainer.getScreeningStrategyWedgeContainer(
                        )
                        if xsDataISPyBScreeningStrategyWedgeContainers != None:
                            for xsDataISPyBScreeningStrategyWedgeContainer in xsDataISPyBScreeningStrategyWedgeContainers:
                                xsDataISPyBScreeningStrategyWedge = xsDataISPyBScreeningStrategyWedgeContainer.getScreeningStrategyWedge(
                                )
                                xsDataISPyBScreeningStrategyWedge.setScreeningStrategyId(
                                    xsDataIntegerScreeningStrategyId)
                                xsDataIntegerScreeningStrategyWedgeId = self.store(
                                    xsDataISPyBScreeningStrategyWedge)

                                xsDataISPyBScreeningStrategySubWedges = xsDataISPyBScreeningStrategyWedgeContainer.getScreeningStrategySubWedge(
                                )
                                if xsDataISPyBScreeningStrategySubWedges != None:
                                    for xsDataISPyBScreeningStrategySubWedge in xsDataISPyBScreeningStrategySubWedges:
                                        xsDataISPyBScreeningStrategySubWedge.setScreeningStrategyWedgeId(
                                            xsDataIntegerScreeningStrategyWedgeId
                                        )
                                        self.store(
                                            xsDataISPyBScreeningStrategySubWedge
                                        )