Exemplo n.º 1
0
    def getXSDataInputBest(self, _xsDataInputStrategy):
        xsDataBeam = _xsDataInputStrategy.getExperimentalCondition().getBeam()
        xsDataSample = _xsDataInputStrategy.getSample()
        xsDataDetector = _xsDataInputStrategy.getExperimentalCondition(
        ).getDetector()
        xsDataGoniostat = _xsDataInputStrategy.getExperimentalCondition(
        ).getGoniostat()
        xsDataDiffractionPlan = _xsDataInputStrategy.getDiffractionPlan()
        xsDataStringBestFileContentDat = _xsDataInputStrategy.getBestFileContentDat(
        )
        xsDataStringBestFileContentPar = _xsDataInputStrategy.getBestFileContentPar(
        )
        xsDataFileXdsBackgroundImage = _xsDataInputStrategy.getXdsBackgroundImage(
        )
        listXSDataStringBestFileContentHKL = _xsDataInputStrategy.getBestFileContentHKL(
        )
        xsDataInputBest = XSDataInputBest()

        # Sample
        xsDataAbsorbedDose = None
        xsDataSusceptibility = None

        # Could be None if sample has not been set
        # It could be not None in case Raddose has calculated an absorbed dose with default sample values
        if (xsDataSample is not None):
            xsDataAbsorbedDose = xsDataSample.getAbsorbedDoseRate()
            xsDataSusceptibility = xsDataSample.getSusceptibility()
            # crystalShape
            # Default value is 1 (We assume that Xtal is smaller than beam)
            if xsDataSample.size is not None and xsDataSample.omegaMin is not None:
                xsDataInputBest.crystalSize = XSDataSize().parseString(
                    xsDataSample.size.marshal())
                xsDataInputBest.omegaMin = xsDataSample.omegaMin
            else:
                xsDataDoubleCrystalShape = xsDataSample.getShape()
                if (xsDataDoubleCrystalShape is None):
                    if (xsDataSample.getSize() is
                            None) or (xsDataBeam.getSize() is None):
                        xsDataDoubleCrystalShape = XSDataDouble(1)
                    else:
                        fCrystalSizeY = xsDataSample.getSize().getY().getValue(
                        )
                        fCrystalSizeZ = xsDataSample.getSize().getZ().getValue(
                        )
                        fDiagonal = math.sqrt(fCrystalSizeY**2 +
                                              fCrystalSizeZ**2)
                        fBeamSizeY = xsDataBeam.getSize().getY().getValue()
                        fCrystalShape = None
                        if fBeamSizeY > fDiagonal:
                            fCrystalShape = 1.0
                        else:
                            fCrystalShape = int(
                                10 * fDiagonal / fBeamSizeY) / 10.0
                        xsDataDoubleCrystalShape = XSDataDouble(fCrystalShape)
                xsDataInputBest.setCrystalShape(xsDataDoubleCrystalShape)
            # Radiation damage model parameters
            xsDataInputBest.setRadiationDamageModelBeta(
                xsDataSample.getRadiationDamageModelBeta())
            xsDataInputBest.setRadiationDamageModelGamma(
                xsDataSample.getRadiationDamageModelGamma())

        # Could be None if Raddose failed to calculate the absorbed dose
        if (xsDataAbsorbedDose is not None):
            xsDataInputBest.setCrystalAbsorbedDoseRate(
                xsDataSample.getAbsorbedDoseRate())

        xsDataInputBest.setCrystalSusceptibility(xsDataSusceptibility)

        # Detector
        xsDataInputBest.setDetectorType(xsDataDetector.getType())

        # Minimum exposure time per image
        xsDataTimeMinExposureTimePerImage = None
        if xsDataBeam:
            xsDataTimeMinExposureTimePerImage = xsDataBeam.getMinExposureTimePerImage(
            )
        if xsDataTimeMinExposureTimePerImage == None:
            xsDataTimeMinExposureTimePerImage = xsDataDiffractionPlan.getMinExposureTimePerImage(
            )
        xsDataInputBest.setBeamMinExposureTime(
            xsDataTimeMinExposureTimePerImage)

        # Max rotation speed
        xsDataAngularSpeedMax = None
        if xsDataGoniostat:
            xsDataAngularSpeedMax = xsDataGoniostat.getMaxOscillationSpeed()
        if xsDataDiffractionPlan and xsDataAngularSpeedMax == None:
            xsDataAngularSpeedMax = xsDataDiffractionPlan.getGoniostatMaxOscillationSpeed(
            )
        xsDataInputBest.setGoniostatMaxRotationSpeed(xsDataAngularSpeedMax)

        # Min rotation width
        xsDataAngleMin = None
        if xsDataGoniostat:
            xsDataAngleMin = xsDataGoniostat.getMinOscillationWidth()
        if xsDataDiffractionPlan and xsDataAngleMin == None:
            xsDataAngleMin = xsDataDiffractionPlan.getGoniostatMinOscillationWidth(
            )
        xsDataInputBest.setGoniostatMinRotationWidth(xsDataAngleMin)

        # Other beam parameters
        if xsDataBeam:
            xsDataInputBest.setBeamExposureTime(xsDataBeam.getExposureTime())
            if xsDataBeam.getTransmission():
                # Fix for bug 741: if the transmission is zero don't set it and warn the user
                fTransmission = xsDataBeam.getTransmission().getValue()
                if (abs(fTransmission) < 0.1):
                    EDVerbose.warning(
                        "Input transmission to BEST ignored because it is zero or close to zero: %f"
                        % fTransmission)
                else:
                    xsDataInputBest.setTransmission(
                        xsDataBeam.getTransmission())
            if xsDataBeam.getApertureSize():
                xsDataInputBest.setApertureSize(xsDataBeam.getApertureSize())
            if xsDataBeam.size:
                xsDataInputBest.setBeamSize(xsDataBeam.size)
            if xsDataBeam.flux:
                xsDataInputBest.setBeamFlux(xsDataBeam.flux)

        # Other diffraction plan parameters
        if xsDataDiffractionPlan:
            xsDataInputBest.setAimedResolution(
                xsDataDiffractionPlan.getAimedResolution())
            xsDataInputBest.setAimedRedundancy(
                xsDataDiffractionPlan.getAimedMultiplicity())
            xsDataInputBest.setAimedCompleteness(
                xsDataDiffractionPlan.getAimedCompleteness())
            xsDataInputBest.setAimedIOverSigma(
                xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution())
            xsDataInputBest.setBeamMaxExposureTime(
                xsDataDiffractionPlan.getMaxExposureTimePerDataCollection())
            xsDataInputBest.setComplexity(
                xsDataDiffractionPlan.getComplexity())
            xsDataInputBest.setAnomalousData(
                xsDataDiffractionPlan.getAnomalousData())
            xsDataInputBest.setStrategyOption(
                xsDataDiffractionPlan.getStrategyOption())
            xsDataInputBest.setMinTransmission(
                xsDataDiffractionPlan.getMinTransmission())
            xsDataInputBest.setNumberOfCrystalPositions(
                xsDataDiffractionPlan.getNumberOfPositions())
            xsDataInputBest.setDetectorDistanceMin(
                xsDataDiffractionPlan.getDetectorDistanceMin())
            xsDataInputBest.setDetectorDistanceMax(
                xsDataDiffractionPlan.getDetectorDistanceMax())
            xsDataInputBest.setUserDefinedRotationStart(
                xsDataDiffractionPlan.getUserDefinedRotationStart())
            xsDataInputBest.setUserDefinedRotationRange(
                xsDataDiffractionPlan.getUserDefinedRotationRange())
            xsDataInputBest.doseLimit = xsDataDiffractionPlan.doseLimit
            xsDataInputBest.rFriedel = xsDataDiffractionPlan.rFriedel

        # Best Files
        xsDataInputBest.setBestFileContentDat(xsDataStringBestFileContentDat)
        xsDataInputBest.setBestFileContentPar(xsDataStringBestFileContentPar)
        xsDataInputBest.setBestFileContentHKL(
            listXSDataStringBestFileContentHKL)
        xsDataInputBest.setXdsBackgroundImage(xsDataFileXdsBackgroundImage)

        return xsDataInputBest
    def getXSDataInputBest(self, _xsDataInputStrategy):
        xsDataBeam = _xsDataInputStrategy.getExperimentalCondition().getBeam()
        xsDataSample = _xsDataInputStrategy.getSample()
        xsDataDetector = _xsDataInputStrategy.getExperimentalCondition().getDetector()
        xsDataGoniostat = _xsDataInputStrategy.getExperimentalCondition().getGoniostat()
        xsDataDiffractionPlan = _xsDataInputStrategy.getDiffractionPlan()
        xsDataStringBestFileContentDat = _xsDataInputStrategy.getBestFileContentDat()
        xsDataStringBestFileContentPar = _xsDataInputStrategy.getBestFileContentPar()
        xsDataFileXdsBackgroundImage = _xsDataInputStrategy.getXdsBackgroundImage()
        listXSDataStringBestFileContentHKL = _xsDataInputStrategy.getBestFileContentHKL()
        xsDataInputBest = XSDataInputBest()

        # Sample
        xsDataAbsorbedDose = None
        xsDataSusceptibility = None

        # Could be None if sample has not been set
        # It could be not None in case Raddose has calculated an absorbed dose with default sample values
        if xsDataSample is not None:
            xsDataAbsorbedDose = xsDataSample.getAbsorbedDoseRate()
            xsDataSusceptibility = xsDataSample.getSusceptibility()
            # crystalShape
            # Default value is 1 (We assume that Xtal is smaller than beam)
            if xsDataSample.size is not None and xsDataSample.omegaMin is not None:
                xsDataInputBest.crystalSize = XSDataSize().parseString(xsDataSample.size.marshal())
                xsDataInputBest.omegaMin = xsDataSample.omegaMin
            else:
                xsDataDoubleCrystalShape = xsDataSample.getShape()
                if xsDataDoubleCrystalShape is None:
                    if (xsDataSample.getSize() is None) or (xsDataBeam.getSize() is None):
                        xsDataDoubleCrystalShape = XSDataDouble(1)
                    else:
                        fCrystalSizeY = xsDataSample.getSize().getY().getValue()
                        fCrystalSizeZ = xsDataSample.getSize().getZ().getValue()
                        fDiagonal = math.sqrt(fCrystalSizeY ** 2 + fCrystalSizeZ ** 2)
                        fBeamSizeY = xsDataBeam.getSize().getY().getValue()
                        fCrystalShape = None
                        if fBeamSizeY > fDiagonal:
                            fCrystalShape = 1.0
                        else:
                            fCrystalShape = int(10 * fDiagonal / fBeamSizeY) / 10.0
                        xsDataDoubleCrystalShape = XSDataDouble(fCrystalShape)
                xsDataInputBest.setCrystalShape(xsDataDoubleCrystalShape)
            # Radiation damage model parameters
            xsDataInputBest.setRadiationDamageModelBeta(xsDataSample.getRadiationDamageModelBeta())
            xsDataInputBest.setRadiationDamageModelGamma(xsDataSample.getRadiationDamageModelGamma())

        # Could be None if Raddose failed to calculate the absorbed dose
        if xsDataAbsorbedDose is not None:
            xsDataInputBest.setCrystalAbsorbedDoseRate(xsDataSample.getAbsorbedDoseRate())

        xsDataInputBest.setCrystalSusceptibility(xsDataSusceptibility)

        # Detector
        xsDataInputBest.setDetectorType(xsDataDetector.getType())

        # Minimum exposure time per image
        xsDataTimeMinExposureTimePerImage = None
        if xsDataBeam:
            xsDataTimeMinExposureTimePerImage = xsDataBeam.getMinExposureTimePerImage()
        if xsDataTimeMinExposureTimePerImage == None:
            xsDataTimeMinExposureTimePerImage = xsDataDiffractionPlan.getMinExposureTimePerImage()
        xsDataInputBest.setBeamMinExposureTime(xsDataTimeMinExposureTimePerImage)

        # Max rotation speed
        xsDataAngularSpeedMax = None
        if xsDataGoniostat:
            xsDataAngularSpeedMax = xsDataGoniostat.getMaxOscillationSpeed()
        if xsDataDiffractionPlan and xsDataAngularSpeedMax == None:
            xsDataAngularSpeedMax = xsDataDiffractionPlan.getGoniostatMaxOscillationSpeed()
        xsDataInputBest.setGoniostatMaxRotationSpeed(xsDataAngularSpeedMax)

        # Min rotation width
        xsDataAngleMin = None
        if xsDataGoniostat:
            xsDataAngleMin = xsDataGoniostat.getMinOscillationWidth()
        if xsDataDiffractionPlan and xsDataAngleMin == None:
            xsDataAngleMin = xsDataDiffractionPlan.getGoniostatMinOscillationWidth()
        xsDataInputBest.setGoniostatMinRotationWidth(xsDataAngleMin)

        # Other beam parameters
        if xsDataBeam:
            xsDataInputBest.setBeamExposureTime(xsDataBeam.getExposureTime())
            if xsDataBeam.getTransmission():
                # Fix for bug 741: if the transmission is zero don't set it and warn the user
                fTransmission = xsDataBeam.getTransmission().getValue()
                if abs(fTransmission) < 0.1:
                    EDVerbose.warning(
                        "Input transmission to BEST ignored because it is zero or close to zero: %f" % fTransmission
                    )
                else:
                    xsDataInputBest.setTransmission(xsDataBeam.getTransmission())
            if xsDataBeam.getApertureSize():
                xsDataInputBest.setApertureSize(xsDataBeam.getApertureSize())
            if xsDataBeam.size:
                xsDataInputBest.setBeamSize(xsDataBeam.size)
            if xsDataBeam.flux:
                xsDataInputBest.setBeamFlux(xsDataBeam.flux)

        # Other diffraction plan parameters
        if xsDataDiffractionPlan:
            xsDataInputBest.setAimedResolution(xsDataDiffractionPlan.getAimedResolution())
            xsDataInputBest.setAimedRedundancy(xsDataDiffractionPlan.getAimedMultiplicity())
            xsDataInputBest.setAimedCompleteness(xsDataDiffractionPlan.getAimedCompleteness())
            xsDataInputBest.setAimedIOverSigma(xsDataDiffractionPlan.getAimedIOverSigmaAtHighestResolution())
            xsDataInputBest.setBeamMaxExposureTime(xsDataDiffractionPlan.getMaxExposureTimePerDataCollection())
            xsDataInputBest.setComplexity(xsDataDiffractionPlan.getComplexity())
            xsDataInputBest.setAnomalousData(xsDataDiffractionPlan.getAnomalousData())
            xsDataInputBest.setStrategyOption(xsDataDiffractionPlan.getStrategyOption())
            xsDataInputBest.setMinTransmission(xsDataDiffractionPlan.getMinTransmission())
            xsDataInputBest.setNumberOfCrystalPositions(xsDataDiffractionPlan.getNumberOfPositions())
            xsDataInputBest.setDetectorDistanceMin(xsDataDiffractionPlan.getDetectorDistanceMin())
            xsDataInputBest.setDetectorDistanceMax(xsDataDiffractionPlan.getDetectorDistanceMax())
            xsDataInputBest.setUserDefinedRotationStart(xsDataDiffractionPlan.getUserDefinedRotationStart())
            xsDataInputBest.setUserDefinedRotationRange(xsDataDiffractionPlan.getUserDefinedRotationRange())
            xsDataInputBest.doseLimit = xsDataDiffractionPlan.doseLimit
            xsDataInputBest.rFriedel = xsDataDiffractionPlan.rFriedel

        # Best Files
        xsDataInputBest.setBestFileContentDat(xsDataStringBestFileContentDat)
        xsDataInputBest.setBestFileContentPar(xsDataStringBestFileContentPar)
        xsDataInputBest.setBestFileContentHKL(listXSDataStringBestFileContentHKL)
        xsDataInputBest.setXdsBackgroundImage(xsDataFileXdsBackgroundImage)

        return xsDataInputBest