Example #1
0
	def buildChildren(self, child_, nodeName_):
		if child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'beamCentreX':
			obj_ = XSDataLength()
			obj_.build(child_)
			self.setBeamCentreX(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'beamCentreY':
			obj_ = XSDataLength()
			obj_.build(child_)
			self.setBeamCentreY(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'distance':
			obj_ = XSDataLength()
			obj_.build(child_)
			self.setDistance(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'mosaicity':
			obj_ = XSDataAngle()
			obj_.build(child_)
			self.setMosaicity(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'selectedSolutionNumber':
			obj_ = XSDataInteger()
			obj_.build(child_)
			self.setSelectedSolutionNumber(obj_)
		elif child_.nodeType == Node.ELEMENT_NODE and \
			nodeName_ == 'labelitScreenSolution':
			obj_ = XSDataLabelitScreenSolution()
			obj_.build(child_)
			self.labelitScreenSolution.append(obj_)
		XSData.buildChildren(self, child_, nodeName_)
 def mergeTwoSubWedgesAdjascentInRotationAxis(self, _subWedge1, _subWedge2):
     """
     This method takes as input two sub wedges and merges them to an unique subwedge, if possible,
     and returns the resulting merged sub wedge. If the merge is not possible a None is returned.
     """
     EDVerbose.DEBUG(
         "EDPluginSubWedgeMergev1_1.mergeTwoSubWedgesAdjascentInRotationAxis"
     )
     xsDataSubWedgeMerged = None
     # First check that the two sub wedges have identical experimental conditions
     if (self.isSameExperimentalConditionInSubWedge(_subWedge1,
                                                    _subWedge2)):
         # Check if sub wedges are adjascent:
         dRoationAxisEnd1 = _subWedge1.getExperimentalCondition(
         ).getGoniostat().getRotationAxisEnd().getValue()
         dRoationAxisStart2 = _subWedge2.getExperimentalCondition(
         ).getGoniostat().getRotationAxisStart().getValue()
         #print dRoationAxisEnd1, dRoationAxisStart2
         if (self.compareTwoValues(dRoationAxisEnd1, dRoationAxisStart2,
                                   0.001)):
             # Same sub wedge! Let's merge them
             xsDataSubWedgeMerged = XSDataSubWedge.parseString(
                 _subWedge1.marshal())
             xsDataSubWedge2 = XSDataSubWedge.parseString(
                 _subWedge2.marshal())
             dRoationAxisEnd2 = xsDataSubWedge2.getExperimentalCondition(
             ).getGoniostat().getRotationAxisEnd().getValue()
             xsDataSubWedgeMerged.getExperimentalCondition().getGoniostat(
             ).setRotationAxisEnd(XSDataAngle(dRoationAxisEnd2))
             for xsDataImage in xsDataSubWedge2.getImage():
                 xsDataSubWedgeMerged.addImage(xsDataImage)
     return xsDataSubWedgeMerged
Example #3
0
    def testDefaultChemicalComposition(self):
        edPluginStrategy = self.createPlugin()

        xsDataSampleCrystalMM = XSDataSampleCrystalMM()
        xsDataCrystal = XSDataCrystal()
        xsDataCell = XSDataCell(angle_alpha=XSDataAngle(90.0),
                                 angle_beta=XSDataAngle(90.0),
                                 angle_gamma=XSDataAngle(90.0),
                                 length_a=XSDataLength(78.9),
                                 length_b=XSDataLength(95.162),
                                 length_c=XSDataLength(104.087))
        xsDataCrystal.setCell(xsDataCell)
        xsDataSampleCrystalMM.setCrystal(xsDataCrystal)
        inumOperators = 4

        xsDataSample2 = edPluginStrategy.getDefaultChemicalComposition(xsDataSampleCrystalMM, inumOperators)
        pyStrChainType = xsDataSample2.getStructure().getChain()[0].getType()
        EDAssert.equal("protein", pyStrChainType.getValue())
Example #4
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_)
Example #5
0
 def unitTestGetSIValue(self):
     """
     test the execution of unitTestGetSIValue static method
     """
     EDVerbose.DEBUG("EDTestCaseEDUtilsUnit.unitTestGetSIValue")
     xsd = XSDataLength(1.5)
     xsd.setUnit(XSDataString("mm"))
     EDAssert.equal(0.0015, EDUtilsUnit.getSIValue(xsd),
                    "Conversion mm to meter")
     xsd = XSDataAngle(90)
     xsd.setUnit(XSDataString("deg"))
     EDAssert.equal(math.pi / 2, EDUtilsUnit.getSIValue(xsd),
                    "Conversion deg to rad")
Example #6
0
    def testDefaultChemicalComposition(self):
        """
        """
        edPluginStrategy = self.createPlugin()

        from XSDataCommon import XSDataAngle
        from XSDataCommon import XSDataLength
        from XSDataMXv1 import XSDataSampleCrystalMM
        from XSDataMXv1 import XSDataCrystal
        from XSDataMXv1 import XSDataCell

        xsDataSampleCrystalMM = XSDataSampleCrystalMM()
        xsDataCrystal = XSDataCrystal()
        xsDataCell = XSDataCell(XSDataAngle(90.0), XSDataAngle(90.0),
                                XSDataAngle(90.0), XSDataLength(78.9),
                                XSDataLength(95.162), XSDataLength(104.087))
        xsDataCrystal.setCell(xsDataCell)
        xsDataSampleCrystalMM.setCrystal(xsDataCrystal)
        inumOperators = 4

        xsDataSample2 = edPluginStrategy.getDefaultChemicalComposition(
            xsDataSampleCrystalMM, inumOperators)
        strChainType = xsDataSample2.getStructure().getChain()[0].getType()
        EDAssert.equal("protein", strChainType.getValue())
Example #7
0
    def collectionRunItemListToCollectionRun(self, _xsCollectionRunItemList):
        """
        """
        xsDataCollectionRun = XSDataBestCollectionRun()

        xsItemExposureTime = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "exposure_time")
        fExposureTime = float(xsItemExposureTime.getValueOf_())
        xsDataCollectionRun.setExposureTime(XSDataTime(fExposureTime))

        xsItemDistance = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "distance")
        fDistance = float(xsItemDistance.getValueOf_())
        xsDataCollectionRun.setDistance(XSDataLength(fDistance))

        xsItemRotationAxisStart = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "phi_start")
        fRotationAxisStart = float(xsItemRotationAxisStart.getValueOf_())
        xsDataCollectionRun.setPhiStart(XSDataAngle(fRotationAxisStart))

        xsNumberOfImages = EDUtilsTable.getItemFromList(
            _xsCollectionRunItemList, "number_of_images")
        iNumberOfImages = int(xsNumberOfImages.getValueOf_())
        xsDataCollectionRun.setNumberOfImages(XSDataInteger(iNumberOfImages))

        xsItemPhiWidth = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "phi_width")
        fPhiWidth = float(xsItemPhiWidth.getValueOf_())
        xsDataCollectionRun.setPhiWidth(XSDataAngle(fPhiWidth))

        xsItemOverlaps = EDUtilsTable.getItemFromList(_xsCollectionRunItemList,
                                                      "overlaps")
        strOverlaps = xsItemOverlaps.getValueOf_()
        xsDataCollectionRun.setOverlaps(XSDataString(strOverlaps))

        return xsDataCollectionRun
Example #8
0
    def generateDataMOSFLMInputIndexing(self):
        """
        """
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(XSDataLength(102.5))
        xsDataMOSFLMBeamPosition.setY(XSDataLength(104.7))

        from XSDataMOSFLMv10 import XSDataMOSFLMDetector
        xsDataMOSFLMDetector = XSDataMOSFLMDetector()
        xsDataMOSFLMDetector.setType(XSDataString("ADSC"))

        from XSDataMOSFLMv10 import XSDataMOSFLMImage
        xsDataMOSFLMImage1 = XSDataMOSFLMImage()
        xsDataMOSFLMImage1.setNumber(XSDataInteger(1))
        xsDataMOSFLMImage1.setRotationAxisStart(XSDataAngle(0.0))
        xsDataMOSFLMImage1.setRotationAxisEnd(XSDataAngle(1.0))

        from XSDataMOSFLMv10 import XSDataMOSFLMImage
        xsDataMOSFLMImage2 = XSDataMOSFLMImage()
        xsDataMOSFLMImage2.setNumber(XSDataInteger(2))
        xsDataMOSFLMImage2.setRotationAxisStart(XSDataAngle(90.0))
        xsDataMOSFLMImage2.setRotationAxisEnd(XSDataAngle(91.0))

        from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing
        xsDataMOSFLMInputIndexing = XSDataMOSFLMInputIndexing()
        xsDataMOSFLMInputIndexing.setDistance(XSDataLength(198.4))
        xsDataMOSFLMInputIndexing.setWavelength(XSDataWavelength(0.9340))
        xsDataMOSFLMInputIndexing.setBeam(xsDataMOSFLMBeamPosition)
        xsDataMOSFLMInputIndexing.setDetector(xsDataMOSFLMDetector)
        xsDataMOSFLMInputIndexing.setDirectory(XSDataString(self.strDataImagePath))
        xsDataMOSFLMInputIndexing.setTemplate(XSDataString("ref-testscale_1_###.img"))
        xsDataMOSFLMInputIndexing.addImage(xsDataMOSFLMImage1)
        xsDataMOSFLMInputIndexing.addImage(xsDataMOSFLMImage2)

        return xsDataMOSFLMInputIndexing
Example #9
0
    def getXSDataStrategyResult(self, _xsDataBestOutput, _xsDataExperimentalCondition, _xsDataSample):
        xsDataStrategyResult = XSDataStrategyResult()


        #xsDataCollectionRunsBest = _xsDataBestOutput.getCollectionRun()
        xsDataCollectionPlansBest = _xsDataBestOutput.getCollectionPlan()

        for xsDataCollectionPlanBest in xsDataCollectionPlansBest:

            xsDataCollectionPlan = XSDataCollectionPlan()
            xsDataCollectionStrategy = XSDataCollection()

            for xsDataCollectionRunBest in xsDataCollectionPlanBest.getCollectionRun():
                xsDataSubWedge = XSDataSubWedge()
                strXmlStringDataExperimentalCondition = _xsDataExperimentalCondition.marshal()
                xsDataExperimentalCondition = XSDataExperimentalCondition.parseString(strXmlStringDataExperimentalCondition)
                xsDataExperimentalCondition.getBeam().setExposureTime(xsDataCollectionRunBest.getExposureTime())
                xsDataExperimentalCondition.getDetector().setDistance(xsDataCollectionRunBest.getDistance())
                xsDataExperimentalCondition.getGoniostat().setRotationAxisStart(xsDataCollectionRunBest.getPhiStart())
                xsDataExperimentalCondition.getGoniostat().setOscillationWidth(xsDataCollectionRunBest.getPhiWidth())
                fRotationAxisEnd = xsDataCollectionRunBest.getPhiStart().getValue() + xsDataCollectionRunBest.getNumberOfImages().getValue() * xsDataCollectionRunBest.getPhiWidth().getValue()
                xsDataExperimentalCondition.getGoniostat().setRotationAxisEnd(XSDataAngle(fRotationAxisEnd))
                xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
                xsDataCollectionStrategy.addSubWedge(xsDataSubWedge)

            xsDataCollectionStrategy.setSample(_xsDataSample)

            xsDataCollectionPlan.setCollectionStrategy(xsDataCollectionStrategy)
            xsDataStrategySummary = xsDataCollectionPlanBest.getStrategySummary()
            xsDataCollectionPlan.setStrategySummary(xsDataStrategySummary)

            xsDataStatistics = xsDataCollectionPlanBest.getStatisticalPrediction()
            xsDataCollectionPlan.setStatistics(xsDataStatistics)

            xsDataStrategyResult.addCollectionPlan(xsDataCollectionPlan)

        return xsDataStrategyResult
Example #10
0
    def getReferenceDataMOSFLMNewmat(self):

        xsDataMOSFLMNewmat = XSDataMOSFLMNewmat()

        XSDataMatrixDoubleA = XSDataMatrixDouble()
        XSDataMatrixDoubleA.setM11(-0.00826416)
        XSDataMatrixDoubleA.setM12(0.00885073)
        XSDataMatrixDoubleA.setM13(0.00937013)
        XSDataMatrixDoubleA.setM21(0.00126554)
        XSDataMatrixDoubleA.setM22(0.01251971)
        XSDataMatrixDoubleA.setM23(-0.00845341)
        XSDataMatrixDoubleA.setM31(-0.01484956)
        XSDataMatrixDoubleA.setM32(-0.00385867)
        XSDataMatrixDoubleA.setM33(-0.00593515)
        xsDataMOSFLMNewmat.setAMatrix(XSDataMatrixDoubleA)

        xsDataMOSFLMMissettingsAngles = XSDataMOSFLMMissettingsAngles()
        xsDataMOSFLMMissettingsAngles.setPhix(XSDataAngle(1.000))
        xsDataMOSFLMMissettingsAngles.setPhiy(XSDataAngle(2.000))
        xsDataMOSFLMMissettingsAngles.setPhiz(XSDataAngle(3.000))
        xsDataMOSFLMNewmat.setMissettingAngles(xsDataMOSFLMMissettingsAngles)

        XSDataMatrixDoubleU = XSDataMatrixDouble()
        XSDataMatrixDoubleU.setM11(-0.4849475)
        XSDataMatrixDoubleU.setM12(0.5598049)
        XSDataMatrixDoubleU.setM13(0.6718960)
        XSDataMatrixDoubleU.setM21(0.0742629)
        XSDataMatrixDoubleU.setM22(0.7918670)
        XSDataMatrixDoubleU.setM23(-0.6061614)
        XSDataMatrixDoubleU.setM31(-0.8713845)
        XSDataMatrixDoubleU.setM32(-0.2440595)
        XSDataMatrixDoubleU.setM33(-0.4255866)
        xsDataMOSFLMNewmat.setUMatrix(XSDataMatrixDoubleU)

        xsDataCellRefined = XSDataCell()
        xsDataCellRefined.setLength_a(XSDataLength(54.8079))
        xsDataCellRefined.setLength_b(XSDataLength(59.0751))
        xsDataCellRefined.setLength_c(XSDataLength(66.9736))
        xsDataCellRefined.setAngle_alpha(XSDataAngle(91.0000))
        xsDataCellRefined.setAngle_beta(XSDataAngle(92.0000))
        xsDataCellRefined.setAngle_gamma(XSDataAngle(93.0000))
        xsDataMOSFLMNewmat.setRefinedCell(xsDataCellRefined)

        return xsDataMOSFLMNewmat
Example #11
0
    def setup(self, _listInput=[], _mode="offline"):
        """Configure the various options"""

        bOK = False
        if _listInput == []:
            _listInput = [os.getcwd()]
        while not bOK:
            strtmp = raw_input(
                "What are the input directories (mandatory, space separated) %s: "
                % _listInput).strip()
            if len(strtmp) > 0:
                bAllExists = True
                lstTemp = shlex.split(strtmp)
                for oneDir in shlex.split(strtmp):
                    if not os.path.exists(oneDir):
                        EDVerbose.screen("No such file or directory: %s" %
                                         oneDir)
                        bAllExists = False
                if bAllExists is True:
                    self.listInput = lstTemp
                    bOK = True
            else:
                self.listInput = _listInput
                bOK = True
        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is operation mode [offline|online|all] (mandatory: %s): "
                % _mode).strip().lower()
            if len(strtmp) > 0:
                bOK = True
                if strtmp == "offline":
                    self.bNewerOnly = False
                    self.strMode = "OffLine"
                elif strtmp == "online":
                    self.bNewerOnly = True
                    self.strMode = "dirwatch"
                elif strtmp == "all":
                    self.bNewerOnly = False
                    self.strMode = "dirwatch"
                else:
                    bOK = False

        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is the destination directory (mandatory): ").strip()
            if os.path.isdir(strtmp):
                self.destinationDirectory = XSDataFile()
                self.destinationDirectory.setPath(
                    XSDataString(os.path.abspath(strtmp)))
                bOK = True

        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is the sinogram filename prefix  (mandatory): ").strip()
            if strtmp != "":
                self.sinogramFileNamePrefix = XSDataString(strtmp)
                bOK = True

        bOK = False
        while not bOK:
            strtmp = raw_input(
                "What is the powder diffraction subdirectory  (mandatory): "
            ).strip()
            if strtmp != "":
                self.powderDiffractionSubdirectory = XSDataString(strtmp)
                bOK = True

        strtmp = raw_input(
            "What is the powder diffraction output format (CHI or CIF, if any ): "
        ).strip().lower()
        if strtmp.find("cif") >= 0:
            self.powderDiffractionFormat = XSDataString("cif")
        elif strtmp.find("chi") >= 0:
            self.powderDiffractionFormat = XSDataString("chi")

        strtmp = raw_input("Process all files ending with: ").strip()
        if len(strtmp) > 0:
            for oneExt in shlex.split(strtmp):
                self.listExtensions.append(oneExt)

        strtmp = raw_input("Exclude all files starting with: ").strip()
        if len(strtmp) > 0:
            for oneExt in shlex.split(strtmp):
                self.listExcludedPrefix.append(oneExt)

        strtmp = raw_input(
            "Do you want to over-ride metadata from the headers [y|N]: "
        ).strip().lower()
        if len(strtmp) > 0 and strtmp[0] == "y":

            strtmp = raw_input("What is the flat field image: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                flatFieldImage = XSDataFile()
                flatFieldImage.setPath(XSDataString(os.path.abspath(strtmp)))
                self.forceImage.set_file_correction_image_flat_field(
                    flatFieldImage)

            strtmp = raw_input("What is the dark current image: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                darkCurrentImage = XSDataFile()
                darkCurrentImage.setPath(XSDataString(os.path.abspath(strtmp)))
                self.forceImage.set_file_correction_image_dark_current(
                    darkCurrentImage)

            strtmp = raw_input("What is the mask file: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                maskFile = XSDataFile()
                maskFile.setPath(XSDataString(strtmp))
                self.forceImage.set_file_correction_image_mask(maskFile)

            strtmp = raw_input("What is the spline file: ").strip()
            if os.path.isfile(strtmp):
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                splineFile = XSDataFile()
                splineFile.setPath(XSDataString(os.path.abspath(strtmp)))
                self.forceImage.set_file_correction_spline_spatial_distortion(
                    splineFile)

            strtmp = raw_input(
                "What is the wavelength (like 0.7 A): ").replace(
                    "(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                try:
                    f = float(w[0])
                except ValueError:
                    print("unable to understand what you said, skipping")
                else:
                    wavelength = XSDataWavelength()
                    wavelength.setValue(f)
                    if len(w) == 2:
                        wavelength.setUnit(XSDataString(w[1]))
                    if self.forceInstrument is None:
                        self.forceInstrument = XSDataDiffractionCTInstrument()
                    self.forceInstrument.set_diffrn_radiation_wavelength(
                        wavelength)

            strtmp = raw_input(
                "What is the distance between the sample and the detector along the beam: "
            ).replace("(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                try:
                    f = float(w[0])
                except ValueError:
                    print("unable to understand what you said, skipping")
                else:
                    distance = XSDataLength()
                    distance.setValue(f)
                    if len(w) == 2:
                        distance.setUnit(XSDataString(w[1]))
                    if self.forceInstrument is None:
                        self.forceInstrument = XSDataDiffractionCTInstrument()
                    self.forceInstrument.set_pd_instr_dist_spec_detc(distance)

            strtmp = raw_input(
                "What is the pixel size (like 52.8 um 53.2 um): ").replace(
                    "(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                xsdata1 = None
                xsdata2 = None
                if len(w) == 4:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[2])
                    except ValueError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata1.setUnit(XSDataString(w[1]))
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                        xsdata2.setUnit(XSDataString(w[3]))
                elif len(w) == 2:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[1])
                    except ValueError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                else:
                    print("unable to understand what you said, skipping")
                if (xsdata1 is not None) and (xsdata2 is not None):
                    if self.forceImage is None:
                        self.forceImage = XSDataDiffractionCTImage()
                    self.forceImage.set_array_element_size_1(xsdata1)
                    self.forceImage.set_array_element_size_2(xsdata2)

            strtmp = raw_input(
                "What is the beam center in distance, not pixels (like 53.5 mm 48.2 mm): "
            ).strip().replace("(", "").replace(")", "").strip()
            w = strtmp.split()
            if len(w) > 0:
                xsdata1 = None
                xsdata2 = None
                if len(w) == 4:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[2])
                    except ValueError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata1.setUnit(XSDataString(w[1]))
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                        xsdata2.setUnit(XSDataString(w[3]))
                elif len(w) == 2:
                    try:
                        f1 = float(w[0])
                        f2 = float(w[1])
                    except ValueError, IndexError:
                        print "Unable to convert to float !!! skipping"
                    else:
                        xsdata1 = XSDataLength()
                        xsdata1.setValue(f1)
                        xsdata2 = XSDataLength()
                        xsdata2.setValue(f2)
                else:
                    print("unable to understand what you said, skipping")
                if (xsdata1 is not None) and (xsdata2 is not None):
                    if self.forceImage is None:
                        self.forceImage = XSDataDiffractionCTImage()
                    self.forceImage.set_diffrn_detector_element_center_1(
                        xsdata1)
                    self.forceImage.set_diffrn_detector_element_center_2(
                        xsdata2)

            strtmp = raw_input("What is the detector tilt angle: ").strip()
            tiltAngle = None
            try:
                tiltAngle = XSDataAngle(float(strtmp))
            except ValueError:
                print("unable to understand what you said, skipping")
            else:
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                self.forceImage.set_pd_instr_special_details_tilt_angle(
                    tiltAngle)

            strtmp = raw_input("What is the tilt plan rotation: ").strip()
            tiltRotation = None
            try:
                tiltRotation = XSDataAngle(float(strtmp))
            except ValueError:
                print("unable to understand what you said, skipping")
            else:
                if self.forceImage is None:
                    self.forceImage = XSDataDiffractionCTImage()
                self.forceImage.set_pd_instr_special_details_tilt_rotation(
                    tiltRotation)

            strtmp = raw_input(
                "What is the number of fast motor steps (you will have n+1 points): "
            ).strip()
            try:
                self.fastMotorSteps = int(strtmp)
            except ValueError:
                fastMotorSteps = None
            else:
                if self.forceInstrument is None:
                    self.forceInstrument = XSDataDiffractionCTInstrument()
                self.forceInstrument.set_tomo_spec_displ_x_max(
                    XSDataLength(self.fastMotorSteps))
                self.forceInstrument.set_tomo_spec_displ_x_min(XSDataLength(0))
                self.forceInstrument.set_tomo_spec_displ_x_inc(XSDataLength(1))
                self.forceInstrument.set_tomo_scan_type(XSDataString("flat"))

            strtmp = raw_input(
                "What is the number of slow motor steps (you will have n+1 points): "
            ).strip()
            try:
                self.slowMotorSteps = int(strtmp)
            except ValueError:
                self.slowMotorSteps = None
            else:
                if self.forceInstrument is None:
                    self.forceInstrument = XSDataDiffractionCTInstrument()
                self.forceInstrument.set_tomo_scan_ampl(
                    XSDataLength(self.slowMotorSteps))
                self.forceInstrument.set_tomo_spec_displ_rotation_inc(
                    XSDataLength(1))
                self.forceInstrument.set_tomo_scan_type(XSDataString("flat"))

            strtmp = raw_input(
                "What is the index offset of your images: ").strip()
            try:
                self.indexOffset = int(strtmp)
            except ValueError:
                print("unable to understand what you said, skipping")
Example #12
0
 def createInputCharacterisationFromSubWedges(self):
     self.DEBUG(
         "EDPluginControlInterfacev1_3.createInputCharacterisationFromSubWedges"
     )
     xsDataResultSubWedgeAssemble = self.edPluginControlSubWedgeAssemble.getDataOutput(
     )
     self.xsDataInputCharacterisation = XSDataInputCharacterisation()
     xsDataCollection = XSDataCollection()
     # Default exposure time (for the moment, this value should be
     # possible to read from the command line)
     if self.xsDataDiffractionPlan is None:
         self.xsDataDiffractionPlan = XSDataDiffractionPlan()
     if (not xsDataResultSubWedgeAssemble is None):
         pyListSubWedge = xsDataResultSubWedgeAssemble.getSubWedge()
         xsDataCollection.setSubWedge(pyListSubWedge)
         for xsDataSubWedge in pyListSubWedge:
             if (self.strComplexity is not None):
                 self.xsDataDiffractionPlan.setComplexity(
                     XSDataString(self.strComplexity))
             if (self.fFlux is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setFlux(XSDataFlux(self.fFlux))
             if (self.fBeamSizeX is not None) and (self.fBeamSizeY
                                                   is not None):
                 xsDataSize = XSDataSize()
                 xsDataSize.setX(XSDataLength(self.fBeamSizeX))
                 xsDataSize.setY(XSDataLength(self.fBeamSizeY))
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setSize(xsDataSize)
             if (self.fApertureSize is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setApertureSize(XSDataLength(self.fApertureSize))
             if (self.fBeamPosX is not None):
                 xsDataSubWedge.getExperimentalCondition().getDetector(
                 ).setBeamPositionX(XSDataLength(self.fBeamPosX))
             if (self.fBeamPosY is not None):
                 xsDataSubWedge.getExperimentalCondition().getDetector(
                 ).setBeamPositionY(XSDataLength(self.fBeamPosY))
             if (self.fMinExposureTimePerImage is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setMinExposureTimePerImage(
                     XSDataTime(self.fMinExposureTimePerImage))
             if (self.fTransmission is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setTransmission(XSDataDouble(self.fTransmission))
             if (self.fWavelength is not None):
                 xsDataSubWedge.getExperimentalCondition().getBeam(
                 ).setWavelength(XSDataWavelength(self.fWavelength))
             if self.fMinOscillationWidth != None:
                 xsDataSubWedge.getExperimentalCondition().getGoniostat(
                 ).setMinOscillationWidth(
                     XSDataAngle(self.fMinOscillationWidth))
             if self.fMaxOscillationSpeed != None:
                 xsDataSubWedge.getExperimentalCondition().getGoniostat(
                 ).setMaxOscillationSpeed(
                     XSDataAngularSpeed(self.fMaxOscillationSpeed))
     if (self.strForcedSpaceGroup is not None):
         self.xsDataDiffractionPlan.setForcedSpaceGroup(
             XSDataString(self.strForcedSpaceGroup))
     self.xsDataDiffractionPlan.setAnomalousData(
         XSDataBoolean(self.bAnomalousData))
     self.xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(
         XSDataTime(self.fMaxExposureTimePerDataCollection))
     if (self.strStrategyOption is not None):
         self.xsDataDiffractionPlan.setStrategyOption(
             XSDataString(self.strStrategyOption))
     xsDataCollection.setDiffractionPlan(self.xsDataDiffractionPlan)
     if self.xsDataSample is not None:
         xsDataCollection.setSample(
             XSDataSampleCrystalMM.parseString(self.xsDataSample.marshal()))
     self.xsDataInputCharacterisation.setDataCollection(xsDataCollection)
    def generateXSDataMOSFLMInputIndexing(_xsDataIndexingInput):
        """
        Translation from XSDataIndexingInput to XSDataMOSFLMInputIndexing.
        """
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMInputIndexing
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMImage

        EDVerbose.DEBUG(
            "EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputIndexing")

        xsDataCollection = _xsDataIndexingInput.getDataCollection()
        xsDataExperimentalCondition = _xsDataIndexingInput.getExperimentalCondition(
        )
        xsDataCrystal = _xsDataIndexingInput.getCrystal()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()
        xsDataMOSFLMInputIndexing = XSDataMOSFLMInputIndexing()

        if (xsDataExperimentalCondition is None):
            xsDataExperimentalCondition = xsDataSubWedgeList[
                0].getExperimentalCondition()

        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataGoniostat = xsDataExperimentalCondition.getGoniostat()

        dWavelength = xsDataBeam.getWavelength().getValue()
        dDistance = xsDataDetector.getDistance().getValue()
        dBeamPositionX = xsDataDetector.getBeamPositionX().getValue()
        dBeamPositionY = xsDataDetector.getBeamPositionY().getValue()

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(XSDataLength(dBeamPositionX))
        xsDataMOSFLMBeamPosition.setY(XSDataLength(dBeamPositionY))
        xsDataMOSFLMInputIndexing.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(
            xsDataDetector)
        xsDataMOSFLMInputIndexing.setDetector(xsDataMOSFLMDetector)

        xsDataMOSFLMInputIndexing.setWavelength(XSDataWavelength(dWavelength))
        xsDataMOSFLMInputIndexing.setDistance(XSDataLength(dDistance))

        xsDataSubWedgeFirst = xsDataSubWedgeList[0]
        xsDataImageFirst = xsDataSubWedgeFirst.getImage()[0]
        strPath = xsDataImageFirst.getPath().getValue()
        strFileName = os.path.basename(strPath)
        strDirectory = os.path.dirname(strPath)

        if xsDataDetector.type.value == "eiger2_16m":
            strMOSFLMTemplate = EDUtilsImage.getH5MasterTemplate(
                strFileName, 1)
        else:
            strMOSFLMTemplate = EDUtilsImage.getTemplate(strFileName, "#")
        xsDataMOSFLMInputIndexing.setTemplate(XSDataString(strMOSFLMTemplate))
        xsDataMOSFLMInputIndexing.setDirectory(XSDataString(strDirectory))

        if (xsDataCrystal is not None):
            xsDataSpaceGroup = xsDataCrystal.getSpaceGroup()
            if (xsDataSpaceGroup is not None):
                xsDataStringName = xsDataSpaceGroup.getName()
                if (xsDataStringName is not None):
                    xsDataMOSFLMInputIndexing.setSymmetry(
                        XSDataString(xsDataStringName.getValue()))

        # Loop through the list of sub wedges

        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
            ).getGoniostat()
            fGonioStatOscillationStart = xsDataGoniostat.getRotationAxisStart(
            ).getValue()
            fGonioStatOscillationRange = xsDataGoniostat.getOscillationWidth(
            ).getValue()

            # First find the lowest image number
            iLowestImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                if (iLowestImageNumber is None):
                    iLowestImageNumber = iImageNumber
                elif (iImageNumber < iLowestImageNumber):
                    iLowestImageNumber = iImageNumber

            # Loop through the list of images

            for xsDataImage in xsDataImageList:
                # Create the MOSFLM image object

                xsDataMOSFLMImage = XSDataMOSFLMImage()

                iImageNumber = xsDataImage.getNumber().getValue()
                xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber))

                fImageOscillationStart = fGonioStatOscillationStart + (
                    iImageNumber -
                    iLowestImageNumber) * fGonioStatOscillationRange
                xsDataMOSFLMImage.setRotationAxisStart(
                    XSDataAngle(fImageOscillationStart))
                xsDataMOSFLMImage.setRotationAxisEnd(
                    XSDataAngle(fImageOscillationStart +
                                fGonioStatOscillationRange))

                xsDataMOSFLMInputIndexing.addImage(xsDataMOSFLMImage)

        return xsDataMOSFLMInputIndexing
    def generateXSDataMOSFLMInputGeneratePrediction(
            xsDataGeneratePredictionInput):
        """
        Translation from XSDataGeneratePredictionInput to XSDataMOSFLMInputGeneratePrediction.
        """
        EDVerbose.DEBUG(
            "EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputGeneratePrediction"
        )
        EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10")
        from XSDataMOSFLMv10 import XSDataMOSFLMBeamPosition
        from XSDataMOSFLMv10 import XSDataMOSFLMImage
        from XSDataMOSFLMv10 import XSDataMOSFLMNewmat
        from XSDataMOSFLMv10 import XSDataMOSFLMMissettingsAngles
        from XSDataMOSFLMv10 import XSDataMOSFLMInputGeneratePrediction

        xsDataIndexingSolutionSelected = xsDataGeneratePredictionInput.getSelectedIndexingSolution(
        )

        xsDataCollection = xsDataGeneratePredictionInput.getDataCollection()
        xsDataSubWedge = xsDataCollection.getSubWedge()[0]
        xsDataImageList = xsDataSubWedge.getImage()
        xsDataImageFirst = xsDataImageList[0]

        xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal()
        xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation()
        xsDataExperimentalCondition = xsDataIndexingSolutionSelected.getExperimentalConditionRefined(
        )
        xsDataDetector = xsDataExperimentalCondition.getDetector()
        xsDataBeam = xsDataExperimentalCondition.getBeam()
        xsDataMatrixA = xsDataOrientation.getMatrixA()
        xsDataMatrixU = xsDataOrientation.getMatrixU()
        xsDataCell = xsDataCrystal.getCell()

        xsDataMOSFLMInputGeneratePrediction = XSDataMOSFLMInputGeneratePrediction(
        )
        xsDataMOSFLMNewmat = XSDataMOSFLMNewmat()
        xsDataMOSFLMNewmat.setRefinedCell(xsDataCell)
        xsDataMOSFLMNewmat.setAMatrix(xsDataMatrixA)
        xsDataMOSFLMNewmat.setUMatrix(xsDataMatrixU)
        xsDataMOSFLMInputGeneratePrediction.setMatrix(xsDataMOSFLMNewmat)

        xsDataMOSFLMMissettingsAngles = XSDataMOSFLMMissettingsAngles()
        xsDataMOSFLMMissettingsAngles.setPhix(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiy(XSDataAngle(0.0))
        xsDataMOSFLMMissettingsAngles.setPhiz(XSDataAngle(0.0))
        xsDataMOSFLMNewmat.setMissettingAngles(xsDataMOSFLMMissettingsAngles)

        xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition()
        xsDataMOSFLMBeamPosition.setX(xsDataDetector.getBeamPositionX())
        xsDataMOSFLMBeamPosition.setY(xsDataDetector.getBeamPositionY())
        xsDataMOSFLMInputGeneratePrediction.setBeam(xsDataMOSFLMBeamPosition)

        xsDataMOSFLMInputGeneratePrediction.setMosaicity(
            xsDataCrystal.getMosaicity())
        xsDataMOSFLMInputGeneratePrediction.setSymmetry(
            xsDataCrystal.getSpaceGroup().getName())

        strPathFirst = xsDataImageFirst.getPath().getValue()
        strDirectoryFirst = os.path.dirname(strPathFirst)
        strFilenameFirst = os.path.basename(strPathFirst)

        xsDataMOSFLMInputGeneratePrediction.setWavelength(
            xsDataBeam.getWavelength())
        xsDataMOSFLMInputGeneratePrediction.setDistance(
            xsDataDetector.getDistance())
        xsDataMOSFLMInputGeneratePrediction.setDirectory(
            XSDataString(strDirectoryFirst))
        xsDataMOSFLMDetector = EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector(
            xsDataDetector)
        xsDataMOSFLMInputGeneratePrediction.setDetector(xsDataMOSFLMDetector)

        # The MOSFLM plugin can only handle one image

        xsDataImage = xsDataSubWedge.getImage()[0]
        xsDataGoniostat = xsDataSubWedge.getExperimentalCondition(
        ).getGoniostat()

        iImageNumber = xsDataImage.getNumber().getValue()

        if xsDataDetector.type.value == "eiger2_16m":
            strMOSFLMTemplate = EDUtilsImage.getH5MasterTemplate(
                strFilenameFirst, iImageNumber)
        else:
            strMOSFLMTemplate = EDUtilsImage.getTemplate(strFilenameFirst, "#")
        xsDataMOSFLMInputGeneratePrediction.setTemplate(
            XSDataString(strMOSFLMTemplate))

        xsDataMOSFLMImage = XSDataMOSFLMImage()
        xsDataMOSFLMImage.setNumber(XSDataInteger(iImageNumber))

        fOscillationStart = xsDataGoniostat.getRotationAxisStart().getValue()
        fOscillationRange = xsDataGoniostat.getOscillationWidth().getValue()
        xsDataMOSFLMImage.setRotationAxisStart(XSDataAngle(fOscillationStart))
        xsDataMOSFLMImage.setRotationAxisEnd(
            XSDataAngle(fOscillationStart + fOscillationRange))

        xsDataMOSFLMInputGeneratePrediction.setImage(xsDataMOSFLMImage)

        return xsDataMOSFLMInputGeneratePrediction
    def generateXSDataIndexingResult(_xsDataMOSFLMIndexingOutput,
                                     _xsDataExperimentalCondition=None):
        """
        Translation from XSDataMOSFLMIndexingOutput to XSDataIndexingResult.
        """
        EDVerbose.DEBUG(
            "EDHandlerXSDataMOSFLMv10.generateXSDataIndexingOutput")
        xsDataMOSFLMBeamPositionRefined = _xsDataMOSFLMIndexingOutput.getRefinedBeam(
        )
        xsDataMOSFLMBeamPositionShift = _xsDataMOSFLMIndexingOutput.getBeamShift(
        )
        dDeviationAngular = _xsDataMOSFLMIndexingOutput.getDeviationAngular(
        ).getValue()
        dDeviationPositional = _xsDataMOSFLMIndexingOutput.getDeviationPositional(
        ).getValue()
        dMosaicityEstimation = _xsDataMOSFLMIndexingOutput.getMosaicityEstimation(
        ).getValue()
        dDistanceRefined = _xsDataMOSFLMIndexingOutput.getRefinedDistance(
        ).getValue()
        iSelectedSolution = _xsDataMOSFLMIndexingOutput.getSelectedSolutionNumber(
        ).getValue()
        iSpotsTotal = _xsDataMOSFLMIndexingOutput.getSpotsTotal().getValue()
        iSpotsUsed = _xsDataMOSFLMIndexingOutput.getSpotsUsed().getValue()
        xsDataCellRefined = _xsDataMOSFLMIndexingOutput.getRefinedNewmat(
        ).getRefinedCell()
        xsDataMatrixA = _xsDataMOSFLMIndexingOutput.getRefinedNewmat(
        ).getAMatrix()
        xsDataMatrixU = _xsDataMOSFLMIndexingOutput.getRefinedNewmat(
        ).getUMatrix()
        strSelectedSpaceGroupName = _xsDataMOSFLMIndexingOutput.getSelectedSolutionSpaceGroup(
        ).getValue()
        iSelectedSpaceGroupNumber = _xsDataMOSFLMIndexingOutput.getSelectedSolutionSpaceGroupNumber(
        ).getValue()

        xsDataIndexingResult = XSDataIndexingResult()
        xsDataIndexingSolutionSelected = None

        for possibleSolutions in _xsDataMOSFLMIndexingOutput.getPossibleSolutions(
        ):
            xsDataCrystal = XSDataCrystal()
            xsDataSpaceGroup = XSDataSpaceGroup()
            xsDataSpaceGroup.setName(
                XSDataString(possibleSolutions.getLattice().getValue()))
            xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)
            xsDataCrystal.setCell(possibleSolutions.getCell())
            xsDataIndexingSolution = XSDataIndexingSolution()
            xsDataIndexingSolution.setCrystal(xsDataCrystal)
            iIndex = possibleSolutions.getIndex().getValue()
            xsDataIndexingSolution.setNumber(XSDataInteger(iIndex))
            xsDataIndexingSolution.setPenalty(
                XSDataFloat(possibleSolutions.getPenalty().getValue()))
            xsDataIndexingResult.addSolution(xsDataIndexingSolution)
            if (iIndex == iSelectedSolution):
                xsDataIndexingSolutionSelected = XSDataIndexingSolutionSelected(
                )
                xsDataIndexingSolutionSelected.setNumber(XSDataInteger(iIndex))
                xsDataIndexingSolutionSelected.setPenalty(
                    XSDataFloat(possibleSolutions.getPenalty().getValue()))

        xsDataCrystalSelected = XSDataCrystal()
        xsDataSpaceGroupSelected = XSDataSpaceGroup()
        xsDataSpaceGroupSelected.setName(
            XSDataString(strSelectedSpaceGroupName))
        xsDataSpaceGroupSelected.setITNumber(
            XSDataInteger(iSelectedSpaceGroupNumber))
        xsDataCrystalSelected.setSpaceGroup(xsDataSpaceGroupSelected)
        xsDataCrystalSelected.setCell(xsDataCellRefined)
        xsDataCrystalSelected.setMosaicity(XSDataDouble(dMosaicityEstimation))
        xsDataIndexingSolutionSelected.setCrystal(xsDataCrystalSelected)

        xsDataOrientation = XSDataOrientation()
        xsDataOrientation.setMatrixA(xsDataMatrixA)
        xsDataOrientation.setMatrixU(xsDataMatrixU)
        xsDataIndexingSolutionSelected.setOrientation(xsDataOrientation)

        xsDataStatisticsIndexing = XSDataStatisticsIndexing()

        xsDataStatisticsIndexing.setBeamPositionShiftX(
            XSDataLength(xsDataMOSFLMBeamPositionShift.getX().getValue()))
        xsDataStatisticsIndexing.setBeamPositionShiftY(
            XSDataLength(xsDataMOSFLMBeamPositionShift.getY().getValue()))
        xsDataStatisticsIndexing.setSpotDeviationAngular(
            XSDataAngle(dDeviationAngular))
        xsDataStatisticsIndexing.setSpotDeviationPositional(
            XSDataLength(dDeviationPositional))
        xsDataStatisticsIndexing.setSpotsUsed(XSDataInteger(iSpotsUsed))
        xsDataStatisticsIndexing.setSpotsTotal(XSDataInteger(iSpotsTotal))
        xsDataIndexingSolutionSelected.setStatistics(xsDataStatisticsIndexing)

        xsDataExperimentalConditionRefined = None
        if (_xsDataExperimentalCondition is None):
            xsDataExperimentalConditionRefined = XSDataExperimentalCondition()
        else:
            # Copy the incoming experimental condition
            xmlExperimentalCondition = _xsDataExperimentalCondition.marshal()
            xsDataExperimentalConditionRefined = XSDataExperimentalCondition.parseString(
                xmlExperimentalCondition)

        xsDataDetector = xsDataExperimentalConditionRefined.getDetector()
        if (xsDataDetector is None):
            xsDataDetector = XSDataDetector()

        xsDataDetector.setBeamPositionX(
            XSDataLength(xsDataMOSFLMBeamPositionRefined.getX().getValue()))
        xsDataDetector.setBeamPositionY(
            XSDataLength(xsDataMOSFLMBeamPositionRefined.getY().getValue()))
        xsDataDetector.setDistance(XSDataLength(dDistanceRefined))

        xsDataExperimentalConditionRefined.setDetector(xsDataDetector)
        xsDataIndexingSolutionSelected.setExperimentalConditionRefined(
            xsDataExperimentalConditionRefined)

        xsDataIndexingResult.setSelectedSolution(
            xsDataIndexingSolutionSelected)

        xsDataIndexingResult.setIndexingLogFile(
            _xsDataMOSFLMIndexingOutput.getPathToLogFile())

        return xsDataIndexingResult
    def getXSDataResultStrategy(self, _xsDataResultBest,
                                _xsDataExperimentalCondition, _xsDataSample):
        xsDataResultStrategy = XSDataResultStrategy()

        listXSDataBestCollectionPlan = _xsDataResultBest.getCollectionPlan()

        for xsDataBestCollectionPlan in listXSDataBestCollectionPlan:

            xsDataCollectionPlan = XSDataCollectionPlan()
            xsDataCollectionStrategy = XSDataCollection()

            xsDataBestStrategySummary = xsDataBestCollectionPlan.getStrategySummary(
            )

            xsDataDoubleTransmission = xsDataBestStrategySummary.getTransmission(
            )

            for xsDataBestCollectionRun in xsDataBestCollectionPlan.getCollectionRun(
            ):
                xsDataSubWedge = XSDataSubWedge()
                strXmlStringDataExperimentalCondition = _xsDataExperimentalCondition.marshal(
                )
                xsDataExperimentalCondition = XSDataExperimentalCondition.parseString(
                    strXmlStringDataExperimentalCondition)
                xsDataExperimentalCondition.getBeam().setExposureTime(
                    xsDataBestCollectionRun.getExposureTime())
                if (xsDataBestCollectionRun.getTransmission() is None):
                    xsDataExperimentalCondition.getBeam().setTransmission(
                        xsDataDoubleTransmission)
                else:
                    xsDataExperimentalCondition.getBeam().setTransmission(
                        xsDataBestCollectionRun.getTransmission())
                xsDataExperimentalCondition.getDetector().setDistance(
                    xsDataBestStrategySummary.getDistance())
                xsDataExperimentalCondition.getGoniostat(
                ).setRotationAxisStart(xsDataBestCollectionRun.getPhiStart())
                xsDataExperimentalCondition.getGoniostat().setOscillationWidth(
                    xsDataBestCollectionRun.getPhiWidth())
                fRotationAxisEnd = xsDataBestCollectionRun.getPhiStart(
                ).getValue(
                ) + xsDataBestCollectionRun.getNumberOfImages().getValue(
                ) * xsDataBestCollectionRun.getPhiWidth().getValue()
                xsDataExperimentalCondition.getGoniostat().setRotationAxisEnd(
                    XSDataAngle(fRotationAxisEnd))
                xsDataSubWedge.setExperimentalCondition(
                    xsDataExperimentalCondition)
                xsDataSubWedge.setSubWedgeNumber(
                    xsDataBestCollectionRun.getCollectionRunNumber())
                if xsDataBestCollectionRun.getCrystalPosition():
                    xsDataSubWedge.setAction(
                        XSDataString("Crystal position: %d" %
                                     xsDataBestCollectionRun.
                                     getCrystalPosition().getValue()))
                else:
                    xsDataSubWedge.setAction(
                        xsDataBestCollectionRun.getAction())
                xsDataCollectionStrategy.addSubWedge(xsDataSubWedge)

            xsDataCollectionStrategy.setSample(_xsDataSample)

            xsDataCollectionPlan.setCollectionStrategy(
                xsDataCollectionStrategy)

            xsDataStrategySummary = XSDataStrategySummary()
            xsDataStrategySummary.setCompleteness(
                xsDataBestStrategySummary.getCompleteness())
            xsDataStrategySummary.setISigma(
                xsDataBestStrategySummary.getISigma())
            xsDataStrategySummary.setRankingResolution(
                xsDataBestStrategySummary.getRankingResolution())
            xsDataStrategySummary.setRedundancy(
                xsDataBestStrategySummary.getRedundancy())
            xsDataStrategySummary.setResolution(
                xsDataBestStrategySummary.getResolution())
            xsDataStrategySummary.setResolutionReasoning(
                xsDataBestStrategySummary.getResolutionReasoning())
            xsDataStrategySummary.setTotalDataCollectionTime(
                xsDataBestStrategySummary.getTotalDataCollectionTime())
            xsDataStrategySummary.setTotalExposureTime(
                xsDataBestStrategySummary.getTotalExposureTime())
            xsDataCollectionPlan.setStrategySummary(xsDataStrategySummary)

            if xsDataBestCollectionPlan.getStatisticalPrediction() is not None:
                xsDataStatisticsStrategy = XSDataStatisticsStrategy.parseString(
                    xsDataBestCollectionPlan.getStatisticalPrediction(
                    ).marshal())
                xsDataCollectionPlan.setStatistics(xsDataStatisticsStrategy)

            xsDataCollectionPlan.setCollectionPlanNumber(
                xsDataBestCollectionPlan.getCollectionPlanNumber())

            xsDataResultStrategy.addCollectionPlan(xsDataCollectionPlan)

        if _xsDataResultBest.getPathToLogFile() != None:
            xsDataResultStrategy.setBestLogFile(
                _xsDataResultBest.getPathToLogFile())

        return xsDataResultStrategy
    def testSetDataModelInput(self):
        edPluginStrategy = self.createPlugin()
        strPathToTestConfigFile = os.path.join(self.getPluginTestsDataHome(),
                                               "XSConfiguration_ESRF.xml")
        edConfiguration = EDConfiguration(strPathToTestConfigFile)
        dictItem = edConfiguration.get(edPluginStrategy.getPluginName())
        edPluginStrategy.setConfig(dictItem)
        edPluginStrategy.configure()

        xsDataStrategy = XSDataInputStrategy()

        # Beam

        xsExperimentalCondition = XSDataExperimentalCondition()

        xsBeam = XSDataBeam()
        xsBeam.setFlux(XSDataFlux(1e+12))
        xsBeam.setWavelength(XSDataWavelength(2.41))
        xsBeam.setSize(XSDataSize(x=XSDataLength(0.1), y=XSDataLength(0.1)))
        xsBeam.setExposureTime(XSDataTime(1))

        xsExperimentalCondition.setBeam(xsBeam)

        # Detector and Exposure Time

        xsDataDetector = XSDataDetector()
        xsDataDetector.setType(XSDataString("q210-2x"))
        xsExperimentalCondition.setDetector(xsDataDetector)

        xsDataGoniostat = XSDataGoniostat()
        xsDataGoniostat.setRotationAxis(XSDataString("phi"))
        xsExperimentalCondition.setGoniostat(xsDataGoniostat)

        xsDataStrategy.setExperimentalCondition(xsExperimentalCondition)

        # Best Files
        bestFileContentDat = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile.dat"))
        xsDataStrategy.setBestFileContentDat(XSDataString(bestFileContentDat))
        bestFileContentPar = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile.par"))
        xsDataStrategy.setBestFileContentPar(XSDataString(bestFileContentPar))
        bestFileContentHKL = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile1.hkl"))
        xsDataStrategy.addBestFileContentHKL(XSDataString(bestFileContentHKL))

        # Crystal

        xsDataSampleCrystalMM = XSDataSampleCrystalMM()
        xsDataStructure = XSDataStructure()
        xsDataComposition = XSDataChemicalCompositionMM()

        xsDataChain = XSDataChain()
        xsDataChain.setType(XSDataString("protein"))
        xsDataChain.setNumberOfCopies(XSDataDouble(2))
        xsDataAtomicComposition = XSDataAtomicComposition()
        xsDataAtom1 = XSDataAtom()
        xsDataAtom1.setSymbol(XSDataString("Se"))
        xsDataAtom1.setNumberOf(XSDataDouble(4))
        xsDataAtomicComposition.addAtom(xsDataAtom1)

        xsDataChain.setHeavyAtoms(xsDataAtomicComposition)
        xsDataChain.setNumberOfMonomers(XSDataDouble(100))
        xsDataStructure.addChain(xsDataChain)

        xsDataChain2 = XSDataChain()
        xsDataChain2.setType(XSDataString("rna"))
        xsDataChain2.setNumberOfCopies(XSDataDouble(1))
        xsDataChain2.setNumberOfMonomers(XSDataDouble(60))
        xsDataStructure.addChain(xsDataChain2)

        xsDataLigand = XSDataLigand()
        xsDataLigand.setNumberOfCopies(XSDataDouble(2))
        xsDataLigand.setNumberOfLightAtoms(XSDataDouble(42))
        xsDataAtomicComposition = XSDataAtomicComposition()
        xsDataAtom2 = XSDataAtom()
        xsDataAtom2.setSymbol(XSDataString("Fe"))
        xsDataAtom2.setNumberOf(XSDataDouble(1))
        xsDataAtomicComposition.addAtom(xsDataAtom2)
        xsDataLigand.setHeavyAtoms(xsDataAtomicComposition)
        xsDataStructure.addLigand(xsDataLigand)
        xsDataStructure.setNumberOfCopiesInAsymmetricUnit(XSDataDouble(0.25))

        xsDataSolvent = XSDataSolvent()
        xsDataAtomicComposition = XSDataAtomicComposition()

        xsDataAtom3 = XSDataAtom()
        xsDataAtom3.setSymbol(XSDataString("Na"))
        xsDataAtom3.setConcentration(XSDataDouble(1000))
        xsDataAtom4 = XSDataAtom()
        xsDataAtom4.setSymbol(XSDataString("Cl"))
        xsDataAtom4.setConcentration(XSDataDouble(1000))

        xsDataAtomicComposition.addAtom(xsDataAtom3)
        xsDataAtomicComposition.addAtom(xsDataAtom4)
        xsDataSolvent.setAtoms(xsDataAtomicComposition)

        xsDataComposition.setStructure(xsDataStructure)
        xsDataComposition.setSolvent(xsDataSolvent)
        xsDataSampleCrystalMM.setChemicalComposition(xsDataComposition)

        xsDataSampleCrystalMM.setSize(
            XSDataSize(XSDataLength(0.1), XSDataLength(0.1),
                       XSDataLength(0.1)))

        xsDataCrystal = XSDataCrystal()
        xsDataCell = XSDataCell(angle_alpha=XSDataAngle(90.0),
                                angle_beta=XSDataAngle(90.0),
                                angle_gamma=XSDataAngle(90.0),
                                length_a=XSDataLength(78.9),
                                length_b=XSDataLength(95.162),
                                length_c=XSDataLength(104.087))
        xsDataCrystal.setCell(xsDataCell)

        xsDataSpaceGroup = XSDataSpaceGroup()
        xsDataSpaceGroup.setITNumber(XSDataInteger(16))
        xsDataCrystal.setSpaceGroup(xsDataSpaceGroup)

        xsDataSampleCrystalMM.setSusceptibility(XSDataDouble(1.5))

        xsDataStrategy.setCrystalRefined(xsDataCrystal)

        xsDataStrategy.setSample(xsDataSampleCrystalMM)

        xsDataStrategy.exportToFile(self.strObtainedInputFile)

        pyStrExpectedInput = self.readAndParseFile(self.strReferenceInputFile)
        pyStrObtainedInput = self.readAndParseFile(self.strObtainedInputFile)

        xsDataInputExpected = XSDataInputStrategy.parseString(
            pyStrExpectedInput)
        xsDataInputObtained = XSDataInputStrategy.parseString(
            pyStrObtainedInput)

        EDAssert.equal(xsDataInputExpected.marshal(),
                       xsDataInputObtained.marshal())
Example #18
0
    def testSetDataModelInput(self):
        edPluginBest = self.createPlugin()
        edConfigurationGood01 = EDConfiguration(
            os.path.join(self.strDataPath, "XSConfiguration.xml"))
        dictItemGood01 = edConfigurationGood01.get(self.getPluginName())
        edPluginBest.setConfig(dictItemGood01, _bLocal=True)
        edPluginBest.setScriptExecutable("cat")
        edPluginBest.configure()

        from XSDataBestv1_3 import XSDataInputBest
        xsDataInputBest = XSDataInputBest()

        from XSDataCommon import XSDataAbsorbedDoseRate
        from XSDataCommon import XSDataDouble
        from XSDataCommon import XSDataString
        from XSDataCommon import XSDataTime
        from XSDataCommon import XSDataFile
        from XSDataCommon import XSDataAngularSpeed
        from XSDataCommon import XSDataString
        from XSDataCommon import XSDataAngle
        from XSDataCommon import XSDataBoolean

        xsDataInputBest.setCrystalAbsorbedDoseRate(
            XSDataAbsorbedDoseRate(0.22E+06))
        xsDataInputBest.setCrystalShape(XSDataDouble(1))
        xsDataInputBest.setCrystalSusceptibility(XSDataDouble(1.5))
        xsDataInputBest.setDetectorType(XSDataString("q210-2x"))
        xsDataInputBest.setBeamExposureTime(XSDataTime(1))
        xsDataInputBest.setBeamMaxExposureTime(XSDataTime(10000))
        xsDataInputBest.setBeamMinExposureTime(XSDataTime(0.1))
        xsDataInputBest.setGoniostatMinRotationWidth(XSDataAngle(0.1))
        xsDataInputBest.setGoniostatMaxRotationSpeed(XSDataAngularSpeed(10))
        xsDataInputBest.setAimedResolution(XSDataDouble(2))
        xsDataInputBest.setAimedRedundancy(XSDataDouble(6.5))
        xsDataInputBest.setAimedCompleteness(XSDataDouble(0.9))
        xsDataInputBest.setAimedIOverSigma(XSDataDouble(3))
        xsDataInputBest.setComplexity(XSDataString("min"))
        xsDataInputBest.setAnomalousData(XSDataBoolean(False))
        fileDirectory = edPluginBest.getWorkingDirectory()

        bestFileContentDat = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile.dat"))
        xsDataInputBest.setBestFileContentDat(XSDataString(bestFileContentDat))

        bestFileContentPar = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile.par"))
        xsDataInputBest.setBestFileContentPar(XSDataString(bestFileContentPar))

        bestFileContentHKL = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile1.hkl"))
        xsDataInputBest.addBestFileContentHKL(XSDataString(bestFileContentHKL))

        xsDataInputBest.exportToFile(self.obtainedInputFile)

        pyStrExpectedInput = self.readAndParseFile(self.referenceInputFile)
        pyStrObtainedInput = self.readAndParseFile(self.obtainedInputFile)

        xsDataInputExpected = XSDataInputBest.parseString(pyStrExpectedInput)
        xsDataInputObtained = XSDataInputBest.parseString(pyStrObtainedInput)

        EDAssert.equal(xsDataInputExpected.marshal(),
                       xsDataInputObtained.marshal())
        EDUtilsFile.deleteFile(self.obtainedInputFile)

        self.cleanUp(edPluginBest)
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        EDVerbose.DEBUG("*** EDPluginExecReadImageHeaderADSCv10.process")
        xsDataInputReadImageHeader = self.getDataInput()
        xsDataFile = xsDataInputReadImageHeader.getImage()
        strPath = xsDataFile.getPath().getValue()
        strAbsolutePath = os.path.abspath(strPath)
        dictHeader = self.readHeaderADSC(strPath)
        if (dictHeader is None):
            strErrorMessage = "EDPluginExecReadImageHeaderADSCv10.process : error when reading header from %s" % strAbsolutePath
            EDVerbose.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
        else:
            xsDataExperimentalCondition = XSDataExperimentalCondition()
            xsDataDetector = XSDataDetector()

            xsDataDetector.setBeamPositionX(XSDataLength(float(dictHeader[ "BEAM_CENTER_X" ])))
            xsDataDetector.setBeamPositionY(XSDataLength(float(dictHeader[ "BEAM_CENTER_Y" ])))
            xsDataDetector.setDistance(XSDataLength(float(dictHeader[ "DISTANCE"   ])))
            fPixelSize = float(dictHeader[ "PIXEL_SIZE"   ])
            xsDataDetector.setPixelSizeX(XSDataLength(fPixelSize))
            xsDataDetector.setPixelSizeY(XSDataLength(fPixelSize))
            if "TWOTHETA" in dictHeader.keys():
                xsDataDetector.setTwoTheta(XSDataAngle(float(dictHeader[ "TWOTHETA"   ])))
            xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictHeader[ "HEADER_BYTES"   ])))
            xsDataDetector.setSerialNumber(XSDataString(dictHeader[ "DETECTOR_SN"   ]))
            xsDataDetector.setNumberPixelX(XSDataInteger(int(dictHeader[ "SIZE1"   ])))
            xsDataDetector.setNumberPixelY(XSDataInteger(int(dictHeader[ "SIZE2"   ])))
            xsDataDetector.setBin(XSDataString(dictHeader[ "BIN" ]))
            xsDataDetector.setDataType(XSDataString(dictHeader[ "TYPE" ]))
            xsDataDetector.setByteOrder(XSDataString(dictHeader[ "BYTE_ORDER" ]))
            if "CCD_IMAGE_SATURATION" in dictHeader.keys():
                xsDataDetector.setImageSaturation(XSDataInteger(int(dictHeader[ "CCD_IMAGE_SATURATION" ])))

            # Determine type of detector...
            iNoPixelsX = xsDataDetector.getNumberPixelX().getValue()
            iNoPixelsY = xsDataDetector.getNumberPixelY().getValue()
            if (iNoPixelsX == 2304 and iNoPixelsY == 2304):
                xsDataDetector.setName(XSDataString("ADSC Q4"))
                xsDataDetector.setType(XSDataString("q4"))
            elif (iNoPixelsX == 1152 and iNoPixelsY == 1152):
                xsDataDetector.setName(XSDataString("ADSC Q4 bin 2x2"))
                xsDataDetector.setType(XSDataString("q4-2x"))
            elif (iNoPixelsX == 4096 and iNoPixelsY == 4096):
                xsDataDetector.setName(XSDataString("ADSC Q210"))
                xsDataDetector.setType(XSDataString("q210"))
            elif (iNoPixelsX == 2048 and iNoPixelsY == 2048):
                xsDataDetector.setName(XSDataString("ADSC Q210 bin 2x2"))
                xsDataDetector.setType(XSDataString("q210-2x"))
            elif (iNoPixelsX == 6144 and iNoPixelsY == 6144):
                xsDataDetector.setName(XSDataString("ADSC Q315"))
                xsDataDetector.setType(XSDataString("q315"))
            elif (iNoPixelsX == 3072 and iNoPixelsY == 3072):
                xsDataDetector.setName(XSDataString("ADSC Q315 bin 2x2"))
                xsDataDetector.setType(XSDataString("q315-2x"))
            else:
                strErrorMessage = EDMessage.ERROR_DATA_HANDLER_02 % ("EDPluginExecReadImageHeaderADSCv10.process", "Unknown detector type")
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                raise RuntimeError, strErrorMessage

            xsDataExperimentalCondition.setDetector(xsDataDetector)

            # Beam object

            xsDataBeam = XSDataBeam()
            xsDataBeam.setWavelength(XSDataWavelength(float(dictHeader[ "WAVELENGTH" ])))
            xsDataBeam.setExposureTime(XSDataTime(float(dictHeader[ "TIME" ])))
            xsDataExperimentalCondition.setBeam(xsDataBeam)

            # Goniostat object
            xsDataGoniostat = XSDataGoniostat()
            fRotationAxisStart = float(dictHeader[ "OSC_START" ])
            fOscillationWidth = float(dictHeader[ "OSC_RANGE" ])
            xsDataGoniostat.setRotationAxisStart(XSDataAngle(fRotationAxisStart))
            xsDataGoniostat.setRotationAxisEnd(XSDataAngle(fRotationAxisStart + fOscillationWidth))
            xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth))
            strRotationAxis = None
            if ("AXIS" in dictHeader.keys()):
                strRotationAxis = dictHeader[ "AXIS" ]
            elif ("OSC_AXIS" in dictHeader.keys()):
                strRotationAxis = dictHeader[ "OSC_AXIS" ]
            else:
                strErrorMessage = "EDPluginExecReadImageHeaderADSCv10.process : Neither AXIS nor OSC_AXIS header item found."
                EDVerbose.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
            xsDataGoniostat.setRotationAxis(XSDataString(strRotationAxis))
            xsDataExperimentalCondition.setGoniostat(xsDataGoniostat)

            # Create the image object
            xsDataImage = XSDataImage()
            xsDataImage.setPath(XSDataString(strAbsolutePath))
            xsDataImage.setDate(XSDataString(dictHeader[ "DATE" ]))
            strFileName = os.path.basename(strPath)
            iImageNumber = EDUtilsImage.getImageNumber(strFileName)
            xsDataImage.setNumber(XSDataInteger(iImageNumber))

            xsDataSubWedge = XSDataSubWedge()
            xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
            xsDataSubWedge.addImage(xsDataImage)

            self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader()
            self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)
Example #20
0
    def preProcess(self, _edObject=None):
        """
        Gets the Configuration Parameters, if found, overrides default parameters
        """
        EDPluginControl.preProcess(self, _edObject)
        EDVerbose.DEBUG("EDPluginControlGeneratePredictionv10.preProcess...")

        xsDataGeneratePredictionInput = self.getDataInput()

        xsDataSelectedIndexingSolution = xsDataGeneratePredictionInput.getSelectedIndexingSolution(
        )
        xsDataExperimentalConditionRefined = xsDataSelectedIndexingSolution.getExperimentalConditionRefined(
        )
        xsDataCollection = xsDataGeneratePredictionInput.getDataCollection()
        xsDataSubWedgeList = xsDataCollection.getSubWedge()

        # List containing instances of all the generate prediction plugins
        self.__listPluginGeneratePrediction = []

        # Loop through all subwedges
        iIndex = 0
        for xsDataSubWedge in xsDataSubWedgeList:

            xsDataImageList = xsDataSubWedge.getImage()
            # First find the lowest image number
            iLowestImageNumber = None
            for xsDataImage in xsDataImageList:
                iImageNumber = xsDataImage.getNumber().getValue()
                if (iLowestImageNumber is None):
                    iLowestImageNumber = iImageNumber
                elif (iImageNumber < iLowestImageNumber):
                    iLowestImageNumber = iImageNumber
            # Then loop through all images in a sub wedge
            for xsDataImage in xsDataImageList:
                iIndex += 1
                edPluginGeneratePrediction = self.loadPlugin(
                    self.__strPluginGeneratePredictionName, "%s-%02d" %
                    (self.__strPluginGeneratePredictionName, iIndex))
                xsDataGeneratePredictionInput = XSDataGeneratePredictionInput()
                xsDataGeneratePredictionInput.setSelectedIndexingSolution(
                    XSDataIndexingSolutionSelected.parseString(
                        xsDataSelectedIndexingSolution.marshal()))
                xsDataCollectionNew = XSDataCollection()
                xsDataSubWedgeNew = XSDataSubWedge()
                xsDataSubWedgeNew.addImage(
                    XSDataImage.parseString(xsDataImage.marshal()))
                xsDataSubWedgeNew.setExperimentalCondition(
                    XSDataExperimentalCondition.parseString(
                        xsDataSubWedge.getExperimentalCondition().marshal()))
                # We must modify the rotationOscillationStart for the new subwedge
                xsDataGoniostatNew = xsDataSubWedgeNew.getExperimentalCondition(
                ).getGoniostat()
                fGoniostatRotationAxisStart = xsDataGoniostatNew.getRotationAxisStart(
                ).getValue()
                fGonioStatOscillationRange = xsDataGoniostatNew.getOscillationWidth(
                ).getValue()
                iImageNumber = xsDataImage.getNumber().getValue()
                fGoniostatRotationAxisStartNew = fGoniostatRotationAxisStart + (
                    iImageNumber -
                    iLowestImageNumber) * fGonioStatOscillationRange
                xsDataGoniostatNew.setRotationAxisStart(
                    XSDataAngle(fGoniostatRotationAxisStartNew))
                #
                xsDataCollectionNew.addSubWedge(xsDataSubWedgeNew)
                xsDataGeneratePredictionInput.setDataCollection(
                    xsDataCollectionNew)
                from EDHandlerXSDataMOSFLMv10 import EDHandlerXSDataMOSFLMv10
                xsDataMOSFLMInputGeneratePrediction = EDHandlerXSDataMOSFLMv10.generateXSDataMOSFLMInputGeneratePrediction(
                    xsDataGeneratePredictionInput)
                edPluginGeneratePrediction.setDataInput(
                    xsDataMOSFLMInputGeneratePrediction)
                self.__listPluginGeneratePrediction.append(
                    edPluginGeneratePrediction)
    def createDataMOSFLMOutputIndexing(self):
        self.DEBUG("EDPluginMOSFLMIndexingv10.createDataMOSFLMOutputIndexing")
        xsDataMOSFLMOutputIndexing = XSDataMOSFLMOutputIndexing()
        # Read Newmat file
        xsDataMOSFLMNewmat = self.getDataMOSFLMNewmat()
        if (xsDataMOSFLMNewmat is None):
            strError = "MOSFLM indexing error : No solution was obtained!"
            self.ERROR(strError)
            self.setFailure()
        else:
            xsDataMOSFLMOutputIndexing.setRefinedNewmat(xsDataMOSFLMNewmat)
            # Then read the XML file
            strDnaTablesXML = self.readProcessFile(self.getScriptBaseName() +
                                                   "_dnaTables.xml")
            xsDataDnaTables = dna_tables.parseString(strDnaTablesXML)

            listXSTableMosaicityEstimation = EDUtilsTable.getTableListFromTables(
                xsDataDnaTables, "mosaicity_estimation")
            dMosaicityValueSum = 0.0
            nValues = 0
            for xsTableMosaicityEstimation in listXSTableMosaicityEstimation:
                for xsListMosaicity in EDUtilsTable.getListsFromTable(
                        xsTableMosaicityEstimation, "mosaicity"):
                    dMosaicityValue = float(
                        EDUtilsTable.getItemFromList(xsListMosaicity,
                                                     "value").getValueOf_())
                    dMosaicityValueSum += dMosaicityValue
                    nValues += 1
            xsDataFloatMosaicityEstimation = XSDataFloat()
            xsDataFloatMosaicityEstimation.setValue(dMosaicityValueSum /
                                                    nValues)
            xsDataMOSFLMOutputIndexing.setMosaicityEstimation(
                xsDataFloatMosaicityEstimation)

            xsTableRefinement = EDUtilsTable.getTableFromTables(
                xsDataDnaTables, "refinement")
            if (xsTableRefinement is None):
                strError = "MOSFLM indexing error : No solution was refined!"
                self.ERROR(strError)
                self.setFailure()
            else:
                xsListDeviations = EDUtilsTable.getListsFromTable(
                    xsTableRefinement, "deviations")[0]
                dDeviationAngular = float(
                    EDUtilsTable.getItemFromList(xsListDeviations,
                                                 "angular").getValueOf_())
                dDeviationPositional = float(
                    EDUtilsTable.getItemFromList(xsListDeviations,
                                                 "positional").getValueOf_())
                xsDataMOSFLMOutputIndexing.setDeviationAngular(
                    XSDataAngle(dDeviationAngular))
                xsDataMOSFLMOutputIndexing.setDeviationPositional(
                    XSDataLength(dDeviationPositional))
                xsListResults = EDUtilsTable.getListsFromTable(
                    xsTableRefinement, "results")[0]
                dDetectorDistance = float(
                    EDUtilsTable.getItemFromList(
                        xsListResults, "detector_distance").getValueOf_())
                xsDataMOSFLMOutputIndexing.setRefinedDistance(
                    XSDataLength(dDetectorDistance))
                xsListParameters = EDUtilsTable.getListsFromTable(
                    xsTableRefinement, "parameters")[0]
                iSpotsUsed = int(
                    EDUtilsTable.getItemFromList(xsListParameters,
                                                 "used").getValueOf_())
                iSpotsTotal = int(
                    EDUtilsTable.getItemFromList(xsListParameters,
                                                 "out_of").getValueOf_())
                xsDataMOSFLMOutputIndexing.setSpotsUsed(
                    XSDataInteger(iSpotsUsed))
                xsDataMOSFLMOutputIndexing.setSpotsTotal(
                    XSDataInteger(iSpotsTotal))

                xsTableSolutionRefinement = EDUtilsTable.getTableFromTables(
                    xsDataDnaTables, "solution_refinement")
                xsListParameters = EDUtilsTable.getListsFromTable(
                    xsTableSolutionRefinement, "selection")[0]
                iSelectedSolutionNumber = int(
                    EDUtilsTable.getItemFromList(xsListParameters,
                                                 "number").getValueOf_())
                xsDataMOSFLMOutputIndexing.setSelectedSolutionNumber(
                    XSDataInteger(iSelectedSolutionNumber))
                strSelectedSolutionSpaceGroup = (EDUtilsTable.getItemFromList(
                    xsListParameters, "spacegroup").getValueOf_())
                xsDataMOSFLMOutputIndexing.setSelectedSolutionSpaceGroup(
                    XSDataString(strSelectedSolutionSpaceGroup))
                iSelectedSolutionSpaceGroupNumber = int(
                    EDUtilsTable.getItemFromList(
                        xsListParameters, "spacegroup_number").getValueOf_())
                xsDataMOSFLMOutputIndexing.setSelectedSolutionSpaceGroupNumber(
                    XSDataInteger(iSelectedSolutionSpaceGroupNumber))

                xsTableAutoIndexSolutions = EDUtilsTable.getTableFromTables(
                    xsDataDnaTables, "autoindex_solutions")
                xsListsSolution = xsTableAutoIndexSolutions.getList()
                for xsListSolution in xsListsSolution:
                    xsDataMOSFLMIndexingSolution = XSDataMOSFLMIndexingSolution(
                    )
                    xsDataCell = XSDataCell()
                    iSolutionNumber = int(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "index").getValueOf_())
                    xsDataMOSFLMIndexingSolution.setIndex(
                        XSDataInteger(iSolutionNumber))
                    iPenalty = int(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "penalty").getValueOf_())
                    xsDataMOSFLMIndexingSolution.setPenalty(
                        XSDataInteger(iPenalty))
                    strLattice = (EDUtilsTable.getItemFromList(
                        xsListSolution, "lattice").getValueOf_())
                    xsDataMOSFLMIndexingSolution.setLattice(
                        XSDataString(strLattice))
                    dA = float(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "a").getValueOf_())
                    xsDataCell.setLength_a(XSDataLength(dA))
                    dB = float(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "b").getValueOf_())
                    xsDataCell.setLength_b(XSDataLength(dB))
                    dC = float(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "c").getValueOf_())
                    xsDataCell.setLength_c(XSDataLength(dC))
                    dAlpha = float(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "alpha").getValueOf_())
                    xsDataCell.setAngle_alpha(XSDataAngle(dAlpha))
                    dBeta = float(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "beta").getValueOf_())
                    xsDataCell.setAngle_beta(XSDataAngle(dBeta))
                    dGamma = float(
                        EDUtilsTable.getItemFromList(xsListSolution,
                                                     "gamma").getValueOf_())
                    xsDataCell.setAngle_gamma(XSDataAngle(dGamma))
                    xsDataMOSFLMIndexingSolution.setCell(xsDataCell)
                    xsDataMOSFLMOutputIndexing.addPossibleSolutions(
                        xsDataMOSFLMIndexingSolution)

                xsTableBeamRefinement = EDUtilsTable.getTableFromTables(
                    xsDataDnaTables, "beam_refinement")
                xsDataMOSFLMBeamPositionRefined = XSDataMOSFLMBeamPosition()
                xsDataMOSFLMBeamPositionShift = XSDataMOSFLMBeamPosition()
                dInitialBeamX = 0.0
                dInitialBeamY = 0.0
                dRefinedBeamX = 0.0
                dRefinedBeamY = 0.0
                xsListInitialBeam = EDUtilsTable.getListsFromTable(
                    xsTableBeamRefinement, "initial_beam")[0]
                fInitialBeamPositionX = float(
                    EDUtilsTable.getItemFromList(xsListInitialBeam,
                                                 "x").getValueOf_())
                fInitialBeamPositionY = float(
                    EDUtilsTable.getItemFromList(xsListInitialBeam,
                                                 "y").getValueOf_())
                xsListRefinedBeam = EDUtilsTable.getListsFromTable(
                    xsTableBeamRefinement, "refined_beam")[0]
                fRefinedBeamPositionX = float(
                    EDUtilsTable.getItemFromList(xsListRefinedBeam,
                                                 "x").getValueOf_())
                fRefinedBeamPositionY = float(
                    EDUtilsTable.getItemFromList(xsListRefinedBeam,
                                                 "y").getValueOf_())
                xsDataMOSFLMBeamPositionRefined.setX(
                    XSDataLength(fRefinedBeamPositionX))
                xsDataMOSFLMBeamPositionRefined.setY(
                    XSDataLength(fRefinedBeamPositionY))
                xsDataMOSFLMBeamPositionShift.setX(
                    XSDataLength(fInitialBeamPositionX -
                                 fRefinedBeamPositionX))
                xsDataMOSFLMBeamPositionShift.setY(
                    XSDataLength(fInitialBeamPositionY -
                                 fRefinedBeamPositionY))
                xsDataMOSFLMOutputIndexing.setRefinedBeam(
                    xsDataMOSFLMBeamPositionRefined)
                xsDataMOSFLMOutputIndexing.setBeamShift(
                    xsDataMOSFLMBeamPositionShift)
        # Path to log file
        xsDataMOSFLMOutputIndexing.setPathToLogFile(
            XSDataFile(
                XSDataString(
                    os.path.join(self.getWorkingDirectory(),
                                 self.getScriptLogFileName()))))
        return xsDataMOSFLMOutputIndexing
    def testSetDataModelInput(self):
        # Crystal
        from XSDataRaddosev10 import XSDataRaddoseInput
        xsDataRaddoseInput = XSDataRaddoseInput()

        from XSDataCommon import XSDataString
        from XSDataCommon import XSDataDouble
        from XSDataCommon import XSDataAngle
        from XSDataCommon import XSDataLength
        from XSDataCommon import XSDataSize
        from XSDataCommon import XSDataInteger
        from XSDataRaddosev10 import XSDataCell
        from XSDataRaddosev10 import XSDataAtom
        from XSDataRaddosev10 import XSDataAtomicComposition

        xsDataAtomSulfur = XSDataAtom()
        xsDataAtomSulfur.setNumberOf(XSDataDouble(4))
        xsDataAtomSulfur.setSymbol(XSDataString("S"))
        xsDataAtomSelenium = XSDataAtom()
        xsDataAtomSelenium.setNumberOf(XSDataDouble(4))
        xsDataAtomSelenium.setSymbol(XSDataString("Se"))

        xsDataAtomicComposition = XSDataAtomicComposition()
        xsDataAtomicComposition.addAtom(xsDataAtomSulfur)
        xsDataAtomicComposition.addAtom(xsDataAtomSelenium)
        xsDataRaddoseInput.setCrystalPATM(xsDataAtomicComposition)
        xsDataRaddoseInput.setCrystalNRES(XSDataInteger(295))
        xsDataRaddoseInput.setCrystalNMON(XSDataInteger(8))
        xsDataCell = XSDataCell(angle_alpha=XSDataAngle(90.0),
                                angle_beta=XSDataAngle(90.0),
                                angle_gamma=XSDataAngle(90.0),
                                length_a=XSDataLength(78.9),
                                length_b=XSDataLength(95.162),
                                length_c=XSDataLength(104.087))

        xsDataSizeCrystal = XSDataSize(XSDataLength(0.1), XSDataLength(0.1),
                                       XSDataLength(0.1))

        xsDataRaddoseInput.setCrystalCell(xsDataCell)
        xsDataRaddoseInput.setCrystalSize(xsDataSizeCrystal)

        # Beam
        from XSDataCommon import XSDataFlux
        from XSDataCommon import XSDataWavelength
        from XSDataCommon import XSDataTime

        xsDataSize = XSDataSize(x=XSDataLength(0.1), y=XSDataLength(0.1))

        xsDataRaddoseInput.setBeamSize(xsDataSize)
        xsDataRaddoseInput.setBeamFlux(XSDataFlux(1e+12))
        xsDataRaddoseInput.setBeamWavelength(XSDataWavelength(2.41))
        xsDataRaddoseInput.setBeamExposureTime(XSDataTime(1))

        xsDataRaddoseInput.setNumberOfImages(XSDataInteger(1))

        xsDataRaddoseInput.exportToFile(self.strObtainedInputFile)

        strExpectedInput = self.readAndParseFile(self.strReferenceInputFile)
        strObtainedInput = self.readAndParseFile(self.strObtainedInputFile)

        xsDataRaddoseInputExpected = XSDataRaddoseInput.parseString(
            strExpectedInput)
        xsDataRaddoseInputObtained = XSDataRaddoseInput.parseString(
            strObtainedInput)

        EDAssert.equal(xsDataRaddoseInputExpected.marshal(),
                       xsDataRaddoseInputObtained.marshal())
    def process(self, _edObject=None):
        EDPluginControl.process(self)
        self.DEBUG("EDPluginControlDozorv1_0.process")
        self.sendMessageToMXCuBE("Processing started...", "info")
        EDUtilsParallel.initializeNbThread()
        xsDataResultControlDozor = XSDataResultControlDozor()
        # Check if connection to ISPyB needed
        if self.dataInput.dataCollectionId is not None:
            edPluginRetrieveDataCollection = self.loadPlugin("EDPluginISPyBRetrieveDataCollectionv1_4")
            xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection()
            xsDataInputRetrieveDataCollection.dataCollectionId = self.dataInput.dataCollectionId
            edPluginRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection
            edPluginRetrieveDataCollection.executeSynchronous()
            ispybDataCollection = edPluginRetrieveDataCollection.dataOutput.dataCollection
            if self.batchSize is None:
                batchSize = ispybDataCollection.numberOfImages
            else:
                batchSize = self.batchSize
            if batchSize > self.maxBatchSize:
                batchSize = self.maxBatchSize
            if abs(ispybDataCollection.overlap) > 1:
                self.hasOverlap = True
                self.overlap = ispybDataCollection.overlap
            dictImage = self.createImageDictFromISPyB(ispybDataCollection)
        else:
            # No connection to ISPyB, take parameters from input
            if self.dataInput.batchSize is None:
                batchSize = self.maxBatchSize
            else:
                batchSize = self.dataInput.batchSize.value
            dictImage = self.createImageDict(self.dataInput)
        self.screen("Dozor batch size: {0}".format(batchSize))
        if self.dataInput.hdf5BatchSize is not None:
            self.hdf5BatchSize = self.dataInput.hdf5BatchSize.value
        listAllBatches = self.createListOfBatches(dictImage.keys(), batchSize)
        if dictImage[listAllBatches[0][0]].path.value.endswith("h5"):
            # Convert HDF5 images to CBF
            self.screen("HDF5 converter batch size: {0}".format(self.batchSize))
            if self.doRadiationDamage:
                self.cbfTempDir = None
            else:
                self.cbfTempDir = tempfile.mkdtemp(prefix="CbfTemp_")
            listHdf5Batches = self.createListOfBatches(dictImage.keys(), self.batchSize)
            dictImage, self.hasHdf5Prefix = self.convertToCBF(dictImage, listHdf5Batches, self.doRadiationDamage)
        for listBatch in listAllBatches:
            # Read the header from the first image in the batch
            xsDataFile = dictImage[listBatch[0]]
            edPluginControlReadImageHeader = self.loadPlugin(self.strEDPluginControlReadImageHeaderName)
            xsDataInputReadImageHeader = XSDataInputReadImageHeader()
            xsDataInputReadImageHeader.image = xsDataFile
            edPluginControlReadImageHeader.dataInput = xsDataInputReadImageHeader
            edPluginControlReadImageHeader.executeSynchronous()
            subWedge = edPluginControlReadImageHeader.dataOutput.subWedge
            xsDataInputDozor = XSDataInputDozor()
            beam = subWedge.experimentalCondition.beam
            detector = subWedge.experimentalCondition.detector
            goniostat = subWedge.experimentalCondition.goniostat
            xsDataInputDozor.detectorType = detector.type
            xsDataInputDozor.exposureTime = XSDataDouble(beam.exposureTime.value)
            xsDataInputDozor.spotSize = XSDataInteger(3)
            xsDataInputDozor.detectorDistance = XSDataDouble(detector.distance.value)
            xsDataInputDozor.wavelength = XSDataDouble(beam.wavelength.value)
#            xsDataInputDozor.fractionPolatization : XSDataDouble optional
            orgx = detector.beamPositionY.value / detector.pixelSizeY.value
            orgy = detector.beamPositionX.value / detector.pixelSizeX.value
            xsDataInputDozor.orgx = XSDataDouble(orgx)
            xsDataInputDozor.orgy = XSDataDouble(orgy)
            xsDataInputDozor.oscillationRange = XSDataDouble(goniostat.oscillationWidth.value)
#            xsDataInputDozor.imageStep : XSDataDouble optional
            xsDataInputDozor.startingAngle = XSDataDouble(goniostat.rotationAxisStart.value)
            xsDataInputDozor.firstImageNumber = subWedge.image[0].number
            xsDataInputDozor.numberImages = XSDataInteger(len(listBatch))
            if self.hasOverlap:
                xsDataInputDozor.overlap = XSDataAngle(self.overlap)
            strFileName = subWedge.image[0].path.value
            strPrefix = EDUtilsImage.getPrefix(strFileName)
            strSuffix = EDUtilsImage.getSuffix(strFileName)
            if EDUtilsPath.isEMBL():
                strXDSTemplate = "%s_?????.%s" % (strPrefix, strSuffix)
            elif self.hasHdf5Prefix and not self.hasOverlap:
                strXDSTemplate = "%s_??????.%s" % (strPrefix, strSuffix)
            else:
                strXDSTemplate = "%s_????.%s" % (strPrefix, strSuffix)
            xsDataInputDozor.nameTemplateImage = XSDataString(os.path.join(os.path.dirname(strFileName), strXDSTemplate))
            xsDataInputDozor.wedgeNumber = self.dataInput.wedgeNumber
            xsDataInputDozor.radiationDamage = self.dataInput.radiationDamage
            edPluginDozor = self.loadPlugin(self.strEDPluginDozorName, "Dozor_%05d" % subWedge.image[0].number.value)
            edPluginDozor.dataInput = xsDataInputDozor
            edPluginDozor.execute()
            edPluginDozor.synchronize()
            indexImage = 0
            imageDozorBatchList = []

            for xsDataResultDozor in edPluginDozor.dataOutput.imageDozor:
                xsDataControlImageDozor = XSDataControlImageDozor()
                xsDataControlImageDozor.number = xsDataResultDozor.number
                xsDataControlImageDozor.image = dictImage[listBatch[indexImage]]
                xsDataControlImageDozor.spotsNumOf = xsDataResultDozor.spotsNumOf
                xsDataControlImageDozor.spotsIntAver = xsDataResultDozor.spotsIntAver
                xsDataControlImageDozor.spotsResolution = xsDataResultDozor.spotsResolution
                xsDataControlImageDozor.powderWilsonScale = xsDataResultDozor.powderWilsonScale
                xsDataControlImageDozor.powderWilsonBfactor = xsDataResultDozor.powderWilsonBfactor
                xsDataControlImageDozor.powderWilsonResolution = xsDataResultDozor.powderWilsonResolution
                xsDataControlImageDozor.powderWilsonCorrelation = xsDataResultDozor.powderWilsonCorrelation
                xsDataControlImageDozor.powderWilsonRfactor = xsDataResultDozor.powderWilsonRfactor
                xsDataControlImageDozor.mainScore = xsDataResultDozor.mainScore
                xsDataControlImageDozor.spotScore = xsDataResultDozor.spotScore
                xsDataControlImageDozor.visibleResolution = xsDataResultDozor.visibleResolution
                xsDataControlImageDozor.spotFile = xsDataResultDozor.spotFile
                xsDataControlImageDozor.angle = xsDataResultDozor.angle
                xsDataResultControlDozor.addImageDozor(xsDataControlImageDozor)
                if xsDataResultControlDozor.inputDozor is None:
                    xsDataResultControlDozor.inputDozor = XSDataDozorInput().parseString(xsDataInputDozor.marshal())
                indexImage += 1

                dozorSpotListShape = []
                dozorSpotList = []
                spotFile = None
                if xsDataControlImageDozor.spotFile is not None:
                    spotFile = xsDataControlImageDozor.spotFile.path.value
                    if os.path.exists(spotFile):
                        numpyArray = numpy.loadtxt(spotFile, skiprows=3)
                        dozorSpotList = base64.b64encode(numpyArray.tostring())
                        dozorSpotListShape.append(numpyArray.shape[0])
                        if len(numpyArray.shape) > 1:
                            dozorSpotListShape.append(numpyArray.shape[1])

                imageDozorDict = {"index": xsDataControlImageDozor.number.value,
                                  "imageName": xsDataControlImageDozor.image.path.value,
                                  "dozor_score": xsDataControlImageDozor.mainScore.value,
                                  "dozorSpotsNumOf" : xsDataControlImageDozor.spotsNumOf.value,
                                  "dozorSpotFile": spotFile,
                                  "dozorSpotList" : dozorSpotList,
                                  "dozorSpotListShape": dozorSpotListShape,
                                  "dozorSpotsIntAver": xsDataControlImageDozor.spotsIntAver.value,
                                  "dozorSpotsResolution": xsDataControlImageDozor.spotsResolution.value
                                  }
                imageDozorBatchList.append(imageDozorDict)

            xsDataResultControlDozor.halfDoseTime = edPluginDozor.dataOutput.halfDoseTime
            xsDataResultControlDozor.pngPlots = edPluginDozor.dataOutput.pngPlots

            self.sendResultToMXCuBE(imageDozorBatchList)
            self.sendMessageToMXCuBE("Batch processed")
        self.dataOutput = xsDataResultControlDozor
        if self.cbfTempDir is not None:
            if self.dataInput.keepCbfTmpDirectory is not None and self.dataInput.keepCbfTmpDirectory.value:
                self.dataOutput.pathToCbfDirectory = XSDataFile(XSDataString(self.cbfTempDir))
            else:
                shutil.rmtree(self.cbfTempDir)
    def testSetDataModelInput(self):
        from XSDataCCP4iv1_1 import XSDataInputCCP4i
        xsDataInputCCP4i = XSDataInputCCP4i()

        # Beam
        from XSDataCommon import XSDataFlux
        from XSDataCommon import XSDataSize
        from XSDataCommon import XSDataLength
        from XSDataCommon import XSDataFloat

        from XSDataMXv1 import XSDataBeam
        from XSDataMXv1 import XSDataExperimentalCondition

        xsExperimentalCondition = XSDataExperimentalCondition()

        xsBeam = XSDataBeam()
        xsBeam.setFlux(XSDataFlux(1e+12))
        xsBeam.setSize(XSDataSize(XSDataLength(0.1), XSDataLength(0.1)))
        xsBeam.setMinExposureTimePerImage(XSDataFloat(0.1))
        xsExperimentalCondition.setBeam(xsBeam)

        # Goniostat
        from XSDataCommon import XSDataSpeed
        from XSDataCommon import XSDataAngle

        from XSDataMXv1 import XSDataGoniostat

        xsDataGoniostat = XSDataGoniostat()
        xsDataGoniostat.setMaxOscillationSpeed(XSDataSpeed(0.2))
        xsDataGoniostat.setMinOscillationWidth(XSDataAngle(0.1))
        xsExperimentalCondition.setGoniostat(xsDataGoniostat)
        xsDataInputCCP4i.setExperimentalCondition(xsExperimentalCondition)

        # Sample
        from XSDataCommon import XSDataString
        from XSDataCommon import XSDataFloat
        from XSDataCommon import XSDataString

        from XSDataMXv1 import XSDataStructure
        from XSDataMXv1 import XSDataChain
        from XSDataMXv1 import XSDataAtom
        from XSDataMXv1 import XSDataLigand
        from XSDataMXv1 import XSDataSampleCrystalMM
        from XSDataMXv1 import XSDataChemicalCompositionMM
        from XSDataMXv1 import XSDataAtomicComposition
        from XSDataMXv1 import XSDataSolvent

        xsDataSampleCrystalMM = XSDataSampleCrystalMM()
        xsDataStructure = XSDataStructure()
        xsDataComposition = XSDataChemicalCompositionMM()

        xsDataChain = XSDataChain()
        xsDataChain.setType(XSDataString("protein"))
        xsDataChain.setNumberOfCopies(XSDataFloat(2))
        xsDataAtomicComposition = XSDataAtomicComposition()
        xsDataAtom1 = XSDataAtom()
        xsDataAtom1.setSymbol(XSDataString("Se"))
        xsDataAtom1.setNumberOf(XSDataFloat(4))
        xsDataAtomicComposition.addAtom(xsDataAtom1)

        xsDataChain.setHeavyAtoms(xsDataAtomicComposition)
        xsDataChain.setNumberOfMonomers(XSDataFloat(100))
        xsDataStructure.addChain(xsDataChain)

        xsDataChain2 = XSDataChain()
        xsDataChain2.setType(XSDataString("rna"))
        xsDataChain2.setNumberOfCopies(XSDataFloat(1))
        xsDataChain2.setNumberOfMonomers(XSDataFloat(60))
        xsDataStructure.addChain(xsDataChain2)

        xsDataLigand = XSDataLigand()
        xsDataLigand.setNumberOfCopies(XSDataFloat(2))
        xsDataLigand.setNumberOfLightAtoms(XSDataFloat(42))
        xsDataAtomicComposition = XSDataAtomicComposition()
        xsDataAtom2 = XSDataAtom()
        xsDataAtom2.setSymbol(XSDataString("Fe"))
        xsDataAtom2.setNumberOf(XSDataFloat(1))
        xsDataAtomicComposition.addAtom(xsDataAtom2)
        xsDataLigand.setHeavyAtoms(xsDataAtomicComposition)
        xsDataStructure.addLigand(xsDataLigand)
        xsDataStructure.setNumberOfCopiesInAsymmetricUnit(XSDataFloat(0.25))

        xsDataSolvent = XSDataSolvent()
        xsDataAtomicComposition = XSDataAtomicComposition()

        xsDataAtom3 = XSDataAtom()
        xsDataAtom3.setSymbol(XSDataString("Na"))
        xsDataAtom3.setConcentration(XSDataFloat(1000))
        xsDataAtom4 = XSDataAtom()
        xsDataAtom4.setSymbol(XSDataString("Cl"))
        xsDataAtom4.setConcentration(XSDataFloat(1000))

        xsDataAtomicComposition.addAtom(xsDataAtom3)
        xsDataAtomicComposition.addAtom(xsDataAtom4)
        xsDataSolvent.setAtoms(xsDataAtomicComposition)

        xsDataComposition.setStructure(xsDataStructure)
        xsDataComposition.setSolvent(xsDataSolvent)
        xsDataSampleCrystalMM.setChemicalComposition(xsDataComposition)

        xsDataSampleCrystalMM.setSize(XSDataSize(XSDataLength(0.2), XSDataLength(0.2), XSDataLength(0.2)))
        xsDataSampleCrystalMM.setSusceptibility(XSDataFloat(1.5))
        xsDataSampleCrystalMM.setShape(XSDataFloat(2))

        xsDataInputCCP4i.setSample(xsDataSampleCrystalMM)

        from XSDataMXv1 import XSDataDiffractionPlan

        xsDataDiffractionPlan = XSDataDiffractionPlan()

        xsDataDiffractionPlan.setAimedCompleteness(XSDataFloat(95.5))
        xsDataDiffractionPlan.setAimedIOverSigmaAtHighestResolution(XSDataFloat(2.5))
        xsDataDiffractionPlan.setAimedMultiplicity(XSDataFloat(95.5))
        xsDataDiffractionPlan.setAimedResolution(XSDataFloat(3))
        xsDataDiffractionPlan.setComplexity(XSDataString("full"))
        xsDataDiffractionPlan.setForcedSpaceGroup(XSDataString("P222"))
        xsDataDiffractionPlan.setMaxExposureTimePerDataCollection(XSDataFloat(10000))

        xsDataInputCCP4i.setDiffractionPlan(xsDataDiffractionPlan)

        from XSDataCommon import XSDataFile

        listInputDataFile = []
        xsDataFile = XSDataFile(XSDataString(self.strXSDataGenerateTemplateFile))
        listInputDataFile.append(xsDataFile)
        xsDataInputCCP4i.setDataFile(listInputDataFile)
Example #25
0
    def getDataMOSFLMNewmat(self, _strNewmatFileName=None):
        self.DEBUG("EDPluginMOSFLMv10.getDataMOSFLMNewmat")
        xsDataMOSFLMNewmat = None
        strNewmatFileName = None
        listOfListOfFloat = []
        if (_strNewmatFileName == None):
            strNewmatFileName = self.getNewmatFileName()
        else:
            strNewmatFileName = _strNewmatFileName
        strNewmat = None
        try:
            strNewmat = self.readProcessFile(strNewmatFileName)
        except:
            strError = self.readProcessErrorLogFile()
            if (strError is not None) and (strError != ""):
                strErrorMessage = "EDPluginMOSFLMv10.getDataMOSFLMNewmat: %s : error reading newmat file : %s" % \
                                (self.getClassName(), strError)
                self.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
            else:
                strErrorMessage = "EDPluginMOSFLMv10.getDataMOSFLMNewmat : Cannot read MOSFLM NEWMAT file : " + strNewmatFileName
                self.error(strErrorMessage)
                self.addErrorMessage(strErrorMessage)
                self.setFailure()
        # print strNewmat
        if (strNewmat is not None):
            listLine = strNewmat.split("\n")
            # Convert into list of lists of float
            for strLine in listLine:
                if not strLine.startswith("SYMM"):
                    listOfListOfFloat.append(
                        self.splitStringIntoListOfFloats(strLine))
            # Fill in the data
            xsDataMOSFLMNewmat = XSDataMOSFLMNewmat()

            XSDataMatrixDoubleA = XSDataMatrixDouble()
            XSDataMatrixDoubleA.setM11(listOfListOfFloat[0][0])
            XSDataMatrixDoubleA.setM12(listOfListOfFloat[0][1])
            XSDataMatrixDoubleA.setM13(listOfListOfFloat[0][2])
            XSDataMatrixDoubleA.setM21(listOfListOfFloat[1][0])
            XSDataMatrixDoubleA.setM22(listOfListOfFloat[1][1])
            XSDataMatrixDoubleA.setM23(listOfListOfFloat[1][2])
            XSDataMatrixDoubleA.setM31(listOfListOfFloat[2][0])
            XSDataMatrixDoubleA.setM32(listOfListOfFloat[2][1])
            XSDataMatrixDoubleA.setM33(listOfListOfFloat[2][2])
            xsDataMOSFLMNewmat.setAMatrix(XSDataMatrixDoubleA)

            xsDataMOSFLMMissettingsAngles = XSDataMOSFLMMissettingsAngles()
            xsDataMOSFLMMissettingsAngles.setPhix(
                XSDataAngle(listOfListOfFloat[3][0]))
            xsDataMOSFLMMissettingsAngles.setPhiy(
                XSDataAngle(listOfListOfFloat[3][1]))
            xsDataMOSFLMMissettingsAngles.setPhiz(
                XSDataAngle(listOfListOfFloat[3][2]))
            xsDataMOSFLMNewmat.setMissettingAngles(
                xsDataMOSFLMMissettingsAngles)

            XSDataMatrixDoubleU = XSDataMatrixDouble()
            XSDataMatrixDoubleU.setM11(listOfListOfFloat[4][0])
            XSDataMatrixDoubleU.setM12(listOfListOfFloat[4][1])
            XSDataMatrixDoubleU.setM13(listOfListOfFloat[4][2])
            XSDataMatrixDoubleU.setM21(listOfListOfFloat[5][0])
            XSDataMatrixDoubleU.setM22(listOfListOfFloat[5][1])
            XSDataMatrixDoubleU.setM23(listOfListOfFloat[5][2])
            XSDataMatrixDoubleU.setM31(listOfListOfFloat[6][0])
            XSDataMatrixDoubleU.setM32(listOfListOfFloat[6][1])
            XSDataMatrixDoubleU.setM33(listOfListOfFloat[6][2])
            xsDataMOSFLMNewmat.setUMatrix(XSDataMatrixDoubleU)

            xsDataCellRefined = XSDataCell()
            xsDataCellRefined.setLength_a(XSDataLength(
                listOfListOfFloat[7][0]))
            xsDataCellRefined.setLength_b(XSDataLength(
                listOfListOfFloat[7][1]))
            xsDataCellRefined.setLength_c(XSDataLength(
                listOfListOfFloat[7][2]))
            xsDataCellRefined.setAngle_alpha(
                XSDataAngle(listOfListOfFloat[7][3]))
            xsDataCellRefined.setAngle_beta(
                XSDataAngle(listOfListOfFloat[7][4]))
            xsDataCellRefined.setAngle_gamma(
                XSDataAngle(listOfListOfFloat[7][5]))
            xsDataMOSFLMNewmat.setRefinedCell(xsDataCellRefined)

        return xsDataMOSFLMNewmat
Example #26
0
    def populateXSDataInputSPDCake(self, _inputDict=None):
        self.DEBUG("EDPluginControlID11v1_0.populateXSDataInputSPDCake")
        xsDataInputSPDCake = XSDataInputSPDCake()
        if isinstance(_inputDict, dict):
            self.__dictID11 = _inputDict

    # Angle of tilt
        if "ANGLE OF TILT" in self.__dictID11:
            xsDataTilt = XSDataAngle()
            xsDataTilt.setValue(float(self.__dictID11["ANGLE OF TILT"]))
            xsDataTilt.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setAngleOfTilt(xsDataTilt)

        if "TILT ROTATION" in self.__dictID11:
            xsDataTiltRot = XSDataAngle()
            xsDataTiltRot.setValue(float(self.__dictID11["TILT ROTATION"]))
            xsDataTiltRot.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setTiltRotation(xsDataTiltRot)

        if "X-PIXEL SIZE" in self.__dictID11:
            xsDataXPixel = XSDataLength()
            xsDataXPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"]))
            xsDataXPixel.setUnit(XSDataString("micron"))
            xsDataInputSPDCake.setPixelSizeX(xsDataXPixel)

        if "Y-PIXEL SIZE" in self.__dictID11:
            xsDataYPixel = XSDataLength()
            xsDataYPixel.setValue(float(self.__dictID11["Y-PIXEL SIZE"]))
            xsDataYPixel.setUnit(XSDataString("micron"))
            xsDataInputSPDCake.setPixelSizeY(xsDataYPixel)

        if "DISTANCE" in self.__dictID11:
            xsDataDistance = XSDataLength()
            xsDataDistance.setValue(float(self.__dictID11["DISTANCE"]))
            xsDataDistance.setUnit(XSDataString("mm"))
            xsDataInputSPDCake.setSampleToDetectorDistance(xsDataDistance)

        if "WAVELENGTH" in self.__dictID11:
            xsDataWaweLength = XSDataWavelength()
            xsDataWaweLength.setValue(float(self.__dictID11["WAVELENGTH"]))
            xsDataWaweLength.setUnit(XSDataString("A"))
            xsDataInputSPDCake.setWavelength(xsDataWaweLength)

        if "DIM1_DATA" in self.__dictID11:
            xsDataBufferSizeX = XSDataInteger(int(
                self.__dictID11["DIM1_DATA"]))
            xsDataInputSPDCake.setBufferSizeX(xsDataBufferSizeX)

        if "DIM2_DATA" in self.__dictID11:
            xsDataBufferSizeY = XSDataInteger(int(
                self.__dictID11["DIM2_DATA"]))
            xsDataInputSPDCake.setBufferSizeY(xsDataBufferSizeY)

    # Dark current
        if ("DARK CURRENT"
                in self.__dictID11) and (self.__dictID11["DARK CURRENT"]
                                         == "YES"):
            if ("DC FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["DC FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["DC FILE"]))
                xsDataInputSPDCake.setDarkCurrentImageFile(xsDataFile)
            else:
                self.warning(
                    "Asked for DC Current correction but no DC current file")

        if ("FLAT-FIELD" in self.__dictID11) and (self.__dictID11["FLAT-FIELD"]
                                                  == "YES"):
            if ("FF FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["FF FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["FF FILE"]))
                xsDataInputSPDCake.setFlatFieldImageFile(xsDataFile)
            else:
                self.warning(
                    "Asked for FLAT-FIELD correction but no FLAT-FIELD file")

        if ("MASK FILE" in self.__dictID11) and (self.__dictID11["USE MASK"]
                                                 == "YES"):
            if ("MASK FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["MASK FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["MASK FILE"]))
                xsDataInputSPDCake.setMaskFile(xsDataFile)
            else:
                self.warning(
                    "Asked for DC Current correction but no DC current file")

        if ("FF SCALE" in self.__dictID11) and (self.__dictID11["FF SCALE"]
                                                == "YES"):
            if ("FF MULTIPLIER" in self.__dictID11):
                try:
                    value = float(self.__dictID11["FF MULTIPLIER"])
                except Exception:
                    self.warning(
                        "Asked for FF SCALE correction but FF MULTIPLIER provided (%s) in not float !"
                        % (self.__dictID11["FF MULTIPLIER"]))
                else:
                    xsDataInputSPDCake.setIntensityScaleFactor(
                        XSDataDouble(1 / value))
            else:
                self.warning(
                    "Asked for FF SCALE correction but no FF MULTIPLIER provided"
                )

        if ("SPATIAL DIS."
                in self.__dictID11) and (self.__dictID11["SPATIAL DIS."]
                                         == "YES"):
            if ("SD FILE" in self.__dictID11) and os.path.isfile(
                    self.__dictID11["SD FILE"]):
                xsDataFile = XSDataFile()
                xsDataFile.setPath(XSDataString(self.__dictID11["SD FILE"]))
                xsDataInputSPDCake.setSpatialDistortionFile(xsDataFile)
            else:
                self.warning(
                    "Asked for SPATIAL DISTORSION correction but no SPATIAL DISTORSION file"
                )

        if "START AZIMUTH" in self.__dictID11:
            xsDataAzimuthStart = XSDataAngle()
            xsDataAzimuthStart.setValue(float(
                self.__dictID11["START AZIMUTH"]))
            xsDataAzimuthStart.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStartAzimuth(xsDataAzimuthStart)

        if "END AZIMUTH" in self.__dictID11:
            xsDataAzimuthStop = XSDataAngle()
            xsDataAzimuthStop.setValue(float(self.__dictID11["END AZIMUTH"]))
            xsDataAzimuthStop.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStopAzimuth(xsDataAzimuthStop)

        if "AZIMUTH BINS" in self.__dictID11:
            xsDataAzimuthStep = XSDataAngle()
            xsDataAzimuthStep.setValue(
                (float(self.__dictID11["END AZIMUTH"]) -
                 float(self.__dictID11["START AZIMUTH"])) /
                float(self.__dictID11["AZIMUTH BINS"]))
            xsDataAzimuthStep.setUnit(XSDataString("deg"))
            xsDataInputSPDCake.setStepAzimuth(xsDataAzimuthStep)

        if "INNER RADIUS" in self.__dictID11:
            xsDataInnerRadius = XSDataDouble()
            xsDataInnerRadius.setValue(float(self.__dictID11["INNER RADIUS"]))
            xsDataInputSPDCake.setInnerRadius(xsDataInnerRadius)

        if "OUTER RADIUS" in self.__dictID11:
            xsDataOuterRadius = XSDataDouble()
            xsDataOuterRadius.setValue(float(self.__dictID11["OUTER RADIUS"]))
            xsDataInputSPDCake.setOuterRadius(xsDataOuterRadius)

        if "X-BEAM CENTRE" in self.__dictID11:
            xsDataXBeamCentre = XSDataDouble()
            xsDataXBeamCentre.setValue(float(self.__dictID11["X-BEAM CENTRE"]))
            xsDataInputSPDCake.setBeamCentreInPixelsX(xsDataXBeamCentre)

        if "Y-BEAM CENTRE" in self.__dictID11:
            xsDataYBeamCentre = XSDataDouble()
            xsDataYBeamCentre.setValue(float(self.__dictID11["Y-BEAM CENTRE"]))
            xsDataInputSPDCake.setBeamCentreInPixelsY(xsDataYBeamCentre)

#        if "saving_format" in self.__dictID11:
#            xsSaveFormat = XSDataString()
#            if self.__dictID11["saving_format"] == "SPREAD SHEET":
#                xsSaveFormat.setValue("spr")
#            elif self.__dictID11["saving_format"] == "CIF":
#                xsSaveFormat.setValue("cif")
#            elif self.__dictID11["saving_format"] == "CHIPLOT":
#                xsSaveFormat.setValue("chi")
#            else:
#                xsSaveFormat.setValue("edf")
#            xsDataInputSPDCake.setOutputFileType(xsSaveFormat)

        if "output_dir" in self.__dictID11:
            xsOutputDir = XSDataFile()
            xsOutputDir.setPath(XSDataString(self.__dictID11["output_dir"]))
            xsDataInputSPDCake.setOutputDir(xsOutputDir)

        #Default options to SPD
        xsDataInputSPDCake.setOutputFileType(XSDataString("azim"))
        xsDataInputSPDCake.setDeleteCorImg(
            XSDataBoolean(not self.isVerboseDebug()))
        xsDataInputSPDCake.setCorrectTiltMask(XSDataBoolean(self.bCorrectMask))
        return xsDataInputSPDCake
    def process(self, _edObject=None):
        EDPluginExec.process(self)
        self.DEBUG("EDPluginExecReadImageHeaderEiger4Mv10.process")
        xsDataInputReadImageHeader = self.getDataInput()
        xsDataFile = xsDataInputReadImageHeader.getImage()
        strPath = xsDataFile.getPath().getValue()
        dictEiger4MHeader = self.readHeaderEiger4M(strPath)
        if (dictEiger4MHeader is None):
            strErrorMessage = "EDPluginExecReadImageHeaderEiger4Mv10.process : Cannot read header : %s" % strPath
            self.error(strErrorMessage)
            self.addErrorMessage(strErrorMessage)
            self.setFailure()
        else:
            xsDataExperimentalCondition = XSDataExperimentalCondition()
            xsDataDetector = XSDataDetector()

            iNoPixelsX = 2070
            iNoPixelsY = 2167
            xsDataDetector.setNumberPixelX(XSDataInteger(iNoPixelsX))
            xsDataDetector.setNumberPixelY(XSDataInteger(iNoPixelsY))
            # Pixel size
            listPixelSizeXY = dictEiger4MHeader[ "Pixel_size"   ].split(" ")
            fPixelSizeX = float(listPixelSizeXY[0]) * 1000
            xsDataDetector.setPixelSizeX(XSDataLength(fPixelSizeX))
            fPixelSizeY = float(listPixelSizeXY[3]) * 1000
            xsDataDetector.setPixelSizeY(XSDataLength(fPixelSizeY))
            # Beam position
            listBeamPosition = dictEiger4MHeader["Beam_xy"].replace("(", " ").replace(")", " ").replace(",", " ").split()
            fBeamPositionX = float(listBeamPosition[1]) * fPixelSizeX
            fBeamPositionY = float(listBeamPosition[0]) * fPixelSizeY
            xsDataDetector.setBeamPositionX(XSDataLength(fBeamPositionX))
            xsDataDetector.setBeamPositionY(XSDataLength(fBeamPositionY))
            fDistance = float(dictEiger4MHeader[ "Detector_distance" ].split(" ")[0]) * 1000
            xsDataDetector.setDistance(XSDataLength(fDistance))
#            xsDataDetector.setNumberBytesInHeader(XSDataInteger(float(dictEiger4MHeader[ "header_size"   ])))
            xsDataDetector.setSerialNumber(XSDataString(dictEiger4MHeader[ "Detector:"   ]))
#            #xsDataDetector.setBin(                 XSDataString(   dictEiger4MHeader[ "BIN" ] ) ) )
#            #xsDataDetector.setDataType(            XSDataString(   dictEiger4MHeader[ "TYPE" ] ) ) )
#            #xsDataDetector.setByteOrder(           XSDataString(   dictEiger4MHeader[ "BYTE_ORDER" ] ) ) )
#            xsDataDetector.setImageSaturation(XSDataInteger(int(dictEiger4MHeader[ "saturation_level" ])))
            xsDataDetector.setName(XSDataString("EIGER 4M"))
            xsDataDetector.setType(XSDataString("eiger4m"))
            xsDataExperimentalCondition.setDetector(xsDataDetector)

            # Beam object

            xsDataBeam = XSDataBeam()
            xsDataBeam.setWavelength(XSDataWavelength(float(dictEiger4MHeader[ "Wavelength" ].split(" ")[0])))
            xsDataBeam.setExposureTime(XSDataTime(float(dictEiger4MHeader[ "Exposure_time" ].split(" ")[0])))
            xsDataExperimentalCondition.setBeam(xsDataBeam)

            # Goniostat object
            xsDataGoniostat = XSDataGoniostat()
            fRotationAxisStart = float(dictEiger4MHeader[ "Start_angle" ].split(" ")[0])
            fOscillationWidth = float(dictEiger4MHeader[ "Angle_increment" ].split(" ")[0])
            xsDataGoniostat.setRotationAxisStart(XSDataAngle(fRotationAxisStart))
            xsDataGoniostat.setRotationAxisEnd(XSDataAngle(fRotationAxisStart + fOscillationWidth))
            xsDataGoniostat.setOscillationWidth(XSDataAngle(fOscillationWidth))
            xsDataExperimentalCondition.setGoniostat(xsDataGoniostat)
#
            # Create the image object
            xsDataImage = XSDataImage()
            xsDataImage.setPath(XSDataString(strPath))
            if "DateTime" in dictEiger4MHeader:
                strTimeStamp = dictEiger4MHeader[ "DateTime" ]
                xsDataImage.setDate(XSDataString(strTimeStamp))
            iImageNumber = EDUtilsImage.getImageNumber(strPath)
            xsDataImage.setNumber(XSDataInteger(iImageNumber))

            xsDataSubWedge = XSDataSubWedge()
            xsDataSubWedge.setExperimentalCondition(xsDataExperimentalCondition)
            xsDataSubWedge.addImage(xsDataImage)

            self.__xsDataResultReadImageHeader = XSDataResultReadImageHeader()
            self.__xsDataResultReadImageHeader.setSubWedge(xsDataSubWedge)
 def testIsSameExperimentalCondition(self):
     edPluginSubWedgeMergev10 = self.createPlugin()
     xsDataExperimentalConditionReference = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionSameAsReference = self.getTestExperimentalCondition(
     )
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionSameAsReference), True)
     xsDataExperimentalConditionDifferentExposureTime = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentExposureTime.getBeam(
     ).setExposureTime(XSDataTime(10.0))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentExposureTime), False)
     xsDataExperimentalConditionDifferentWavelength = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentWavelength.getBeam().setWavelength(
         XSDataWavelength(1.5))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentWavelength), False)
     xsDataExperimentalConditionDifferentBeamPositionX = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentBeamPositionX.getDetector(
     ).setBeamPositionX(XSDataLength(20.0))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentBeamPositionX), False)
     xsDataExperimentalConditionDifferentBeamPositionY = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentBeamPositionY.getDetector(
     ).setBeamPositionY(XSDataLength(20.0))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentBeamPositionY), False)
     xsDataExperimentalConditionDifferentDistance = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentDistance.getDetector().setDistance(
         XSDataLength(220.0))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentDistance), False)
     xsDataExperimentalConditionDifferentName = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentName.getDetector().setName(
         XSDataString(u"EDNA"))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentName), False)
     xsDataExperimentalConditionDifferentNumberPixelX = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentNumberPixelX.getDetector(
     ).setNumberPixelX(XSDataInteger(2))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentNumberPixelX), False)
     xsDataExperimentalConditionDifferentNumberPixelY = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentNumberPixelY.getDetector(
     ).setNumberPixelY(XSDataInteger(2))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentNumberPixelY), False)
     xsDataExperimentalConditionDifferentSerialNumber = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentSerialNumber.getDetector(
     ).setSerialNumber(XSDataString(u"EDNA"))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentSerialNumber), False)
     xsDataExperimentalConditionDifferentTwoTheta = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentTwoTheta.getDetector().setTwoTheta(
         XSDataAngle(90.0))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentTwoTheta), False)
     xsDataExperimentalConditionDifferentOscillationWidth = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentOscillationWidth.getGoniostat(
     ).setOscillationWidth(XSDataAngle(2.0))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentOscillationWidth), False)
     xsDataExperimentalConditionDifferentRotationAxis = self.getTestExperimentalCondition(
     )
     xsDataExperimentalConditionDifferentRotationAxis.getGoniostat(
     ).setRotationAxis(XSDataString(u"EDNA"))
     EDAssert.equal(
         edPluginSubWedgeMergev10.isSameExperimentalCondition(
             xsDataExperimentalConditionReference,
             xsDataExperimentalConditionDifferentRotationAxis), False)
Example #29
0
    def from_params(self, data_collection, char_params):
        edna_input = XSDataInputMXCuBE.parseString(self.edna_default_input)

        if data_collection.id:
            edna_input.setDataCollectionId(XSDataInteger(data_collection.id))

        #Beam object
        beam = edna_input.getExperimentalCondition().getBeam()

        try:
            transmission = self.collect_obj.get_transmission()
            beam.setTransmission(XSDataDouble(transmission))
        except AttributeError:
            pass

        try:
            wavelength = self.collect_obj.get_wavelength()
            beam.setWavelength(XSDataWavelength(wavelength))
        except AttributeError:
            pass

        try:
            beam.setFlux(XSDataFlux(self.collect_obj.get_measured_intensity()))
        except AttributeError:
            pass

        try:
            beamsize = self.get_beam_size()
            if not None in beamsize:
                beam.setSize(
                    XSDataSize(x=XSDataLength(float(beamsize[0])),
                               y=XSDataLength(float(beamsize[1]))))
        except AttributeError:
            pass

        #Optimization parameters
        diff_plan = edna_input.getDiffractionPlan()

        aimed_i_sigma = XSDataDouble(char_params.aimed_i_sigma)
        aimed_completness = XSDataDouble(char_params.aimed_completness)
        aimed_multiplicity = XSDataDouble(char_params.aimed_multiplicity)
        aimed_resolution = XSDataDouble(char_params.aimed_resolution)

        complexity = char_params.strategy_complexity
        complexity = XSDataString(qme.STRATEGY_COMPLEXITY[complexity])

        permitted_phi_start = XSDataAngle(char_params.permitted_phi_start)
        _range = char_params.permitted_phi_end - char_params.permitted_phi_start
        rotation_range = XSDataAngle(_range)

        diff_plan.setAimedIOverSigmaAtHighestResolution(aimed_i_sigma)
        diff_plan.setAimedCompleteness(aimed_completness)

        if char_params.use_aimed_multiplicity:
            diff_plan.setAimedMultiplicity(aimed_multiplicity)

        if char_params.use_aimed_resolution:
            diff_plan.setAimedResolution(aimed_resolution)

        diff_plan.setComplexity(complexity)

        if char_params.use_permitted_rotation:
            diff_plan.setUserDefinedRotationStart(permitted_phi_start)
            diff_plan.setUserDefinedRotationRange(rotation_range)

        #Vertical crystal dimension
        sample = edna_input.getSample()
        sample.getSize().setY(XSDataLength(char_params.max_crystal_vdim))
        sample.getSize().setZ(XSDataLength(char_params.min_crystal_vdim))

        #Radiation damage model
        sample.setSusceptibility(XSDataDouble(char_params.rad_suscept))
        sample.setChemicalComposition(None)
        sample.setRadiationDamageModelBeta(XSDataDouble(char_params.beta /
                                                        1e6))
        sample.setRadiationDamageModelGamma(
            XSDataDouble(char_params.gamma / 1e6))

        diff_plan.setForcedSpaceGroup(XSDataString(char_params.space_group))

        # Characterisation type - Routine DC
        if char_params.use_min_dose:
            pass

        if char_params.use_min_time:
            time = XSDataTime(char_params.min_time)
            diff_plan.setMaxExposureTimePerDataCollection(time)

        # Account for radiation damage
        if char_params.induce_burn:
            diff_plan.setStrategyOption(XSDataString("-DamPar"))
        else:
            diff_plan.setStrategyOption(None)

        # Characterisation type - SAD
        if char_params.opt_sad:
            diff_plan.setAnomalousData(XSDataBoolean(True))
        else:
            diff_plan.setAnomalousData(XSDataBoolean(False))

        #Data set
        data_set = XSDataMXCuBEDataSet()
        acquisition_parameters = data_collection.acquisitions[
            0].acquisition_parameters
        path_template = data_collection.acquisitions[0].path_template
        path_str = os.path.join(path_template.directory,
                                path_template.get_image_file_name())

        for img_num in range(int(acquisition_parameters.num_images)):
            image_file = XSDataFile()
            path = XSDataString()
            path.setValue(path_str % (img_num + 1))
            image_file.setPath(path)
            data_set.addImageFile(image_file)

        edna_input.addDataSet(data_set)
        edna_input.process_directory = path_template.process_directory

        return edna_input
Example #30
0
    def testSetDataModelInput(self):
        """
        """
        edPluginBest = self.createPlugin()
        xsPluginItemGood01 = self.getPluginConfiguration(
            os.path.join(self.strDataPath, "XSConfiguration.xml"))
        edPluginBest.setConfiguration(xsPluginItemGood01)
        edPluginBest.setScriptExecutable("cat")
        edPluginBest.configure()

        from XSDataBestv10 import XSDataBestInput
        xsDataBestInput = XSDataBestInput()

        from XSDataCommon import XSDataAbsorbedDoseRate
        from XSDataCommon import XSDataFloat
        from XSDataCommon import XSDataString
        from XSDataCommon import XSDataTime
        from XSDataCommon import XSDataFile
        from XSDataCommon import XSDataSpeed
        from XSDataCommon import XSDataString
        from XSDataCommon import XSDataAngle

        xsDataBestInput.setCrystalAbsorbedDoseRate(
            XSDataAbsorbedDoseRate(0.22E+06))
        xsDataBestInput.setCrystalShape(XSDataFloat(1))
        xsDataBestInput.setCrystalSusceptibility(XSDataFloat(1.5))
        xsDataBestInput.setDetectorType(XSDataString("q210-2x"))
        xsDataBestInput.setBeamExposureTime(XSDataTime(1))
        xsDataBestInput.setBeamMaxExposureTime(XSDataTime(10000))
        xsDataBestInput.setBeamMinExposureTime(XSDataTime(0.1))
        xsDataBestInput.setGoniostatMinRotationWidth(XSDataAngle(0.1))
        xsDataBestInput.setGoniostatMaxRotationSpeed(XSDataSpeed(10))
        xsDataBestInput.setAimedResolution(XSDataFloat(2))
        xsDataBestInput.setAimedRedundancy(XSDataFloat(6.5))
        xsDataBestInput.setAimedCompleteness(XSDataFloat(0.9))
        xsDataBestInput.setAimedIOverSigma(XSDataFloat(3))
        xsDataBestInput.setComplexity(XSDataString("min"))
        fileDirectory = edPluginBest.getWorkingDirectory()

        bestFileContentDat = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile.dat"))
        xsDataBestInput.setBestFileContentDat(XSDataString(bestFileContentDat))

        bestFileContentPar = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile.par"))
        xsDataBestInput.setBestFileContentPar(XSDataString(bestFileContentPar))

        bestFileContentHKL = EDUtilsFile.readFile(
            os.path.join(self.strDataPath, "bestfile1.hkl"))
        listBestFileContentHKL = []
        listBestFileContentHKL.append(XSDataString(bestFileContentHKL))
        xsDataBestInput.setBestFileContentHKL(listBestFileContentHKL)

        xsDataBestInput.outputFile(self.strObtainedInputFile)

        strExpectedInput = self.readAndParseFile(self.strReferenceInputFile)
        strObtainedInput = self.readAndParseFile(self.strObtainedInputFile)

        xsDataInputExpected = XSDataBestInput.parseString(strExpectedInput)
        xsDataInputObtained = XSDataBestInput.parseString(strObtainedInput)

        EDAssert.equal(xsDataInputExpected.marshal(),
                       xsDataInputObtained.marshal())

        self.cleanUp(edPluginBest)