def run(self, inData):
     outData = {}
     # First get the list of subWedges
     if "subWedge" in inData:
         list_sub_wedge = inData["subWedge"]
         directory_prefix = ""
     else:
         first_image = inData["imagePath"][0]
         last_image = inData["imagePath"][-1]
         prefix = UtilsImage.getPrefix(first_image)
         first_image_number = UtilsImage.getImageNumber((first_image))
         last_image_number = UtilsImage.getImageNumber((last_image))
         directory_prefix = "{0}_{1}_{2}".format(
             prefix, first_image_number, last_image_number
         )
         list_sub_wedge = self.getListSubWedge(inData)
     indata_xds_integration = {
         "subWedge": list_sub_wedge
     }
     xds_integration = XDSIndexAndIntegration(
         inData=indata_xds_integration,
         workingDirectorySuffix=directory_prefix,
     )
     xds_integration.execute()
     outData = xds_integration.outData
     return outData
Esempio n. 2
0
 def readImageHeaders(listImagePath):
     # Read the header(s)
     inDataReadImageHeader = {"imagePath": listImagePath}
     readImageHeader = ReadImageHeader(
         inData=inDataReadImageHeader,
         workingDirectorySuffix=UtilsImage.getPrefix(listImagePath[0]),
     )
     readImageHeader.execute()
     listSubWedge = readImageHeader.outData["subWedge"]
     return listSubWedge
Esempio n. 3
0
 def run(self, inData):
     outData = {}
     hdf5File = pathlib.Path(inData['hdf5File'])
     # Read the header
     inDataReadImageHeader = {
         "imagePath": [inData['hdf5File']],
         "isFastMesh": False
     }
     readImageHeader = ReadImageHeader(inData=inDataReadImageHeader)
     readImageHeader.execute()
     if readImageHeader.isSuccess():
         firstSubWedge = readImageHeader.outData["subWedge"][0]
         experimentalCondition = firstSubWedge["experimentalCondition"]
         detector = experimentalCondition["detector"]
         beam = experimentalCondition["beam"]
         goniostat = experimentalCondition["goniostat"]
         beamX = detector["beamPositionX"] / 2.0 / detector["pixelSizeX"]
         beamY = detector["beamPositionY"] / 2.0 / detector["pixelSizeY"]
         directory = hdf5File.parent
         prefix = UtilsImage.getPrefix(hdf5File)
         hdf5ImageNumber = 1
         if 'master' in str(hdf5File):
             masterFile = hdf5File
         else:
             if UtilsConfig.isEMBL():
                 fileName = '{0}_master.h5'.format(prefix)
             else:
                 fileName = '{0}_{1}_master.h5'.format(
                     prefix, hdf5ImageNumber)
             masterFile = directory / fileName
         image = fabio.open(str(masterFile))
         image.data = image.data.reshape(2181, 2, 2074, 2).sum(3).sum(1)
         cbfImage = image.convert("cbf")
         pilatus_headers = fabio.cbfimage.PilatusHeader(
             "Silicon sensor, thickness 0.000750 m")
         pilatus_headers["Start_angle"] = goniostat["rotationAxisStart"]
         pilatus_headers["Angle_increment"] = goniostat["oscillationWidth"]
         pilatus_headers["Detector"] = "Eiger2 16M binned to 4M"
         pilatus_headers["Pixel_size"] = (detector["pixelSizeY"] * 2,
                                          detector["pixelSizeX"] * 2)
         pilatus_headers["Exposure_time"] = beam["exposureTime"]
         pilatus_headers["Wavelength"] = beam["wavelength"]
         pilatus_headers[
             "Detector_distance"] = detector["distance"] / 1000.0
         pilatus_headers["Beam_xy"] = (beamY, beamX)
         pilatus_headers["Count_cutoff"] = 1009869
         cbfImage.pilatus_headers = pilatus_headers
         directory = inData.get("forcedOutputDirectory",
                                str(self.getWorkingDirectory()))
         cbfImagePath = os.path.join(
             directory,
             os.path.basename(inData['hdf5File']).replace(".h5", ".cbf"))
         cbfImage.save(cbfImagePath)
         outData["outputCBFFile"] = cbfImagePath
     return outData
Esempio n. 4
0
 def test_generateCommands_withImageRange(self):
     referenceDataPath = self.dataPath / 'H5ToCBF_withImageRange.json'
     inData = UtilsTest.loadAndSubstitueTestData(referenceDataPath,
                                                 loadTestImages=False)
     hdf5File = pathlib.Path(inData['hdf5File'])
     directory = hdf5File.parent
     prefix = UtilsImage.getPrefix(hdf5File)
     commandLine, template = H5ToCBFTask.generateCommandsWithImageRange(
         inData, directory, prefix, hdf5File)
     self.assertTrue(commandLine is not None)
     self.assertTrue(template is not None)
Esempio n. 5
0
 def run(self, inData):
     outData = {}
     hdf5File = pathlib.Path(inData['hdf5File'])
     directory = hdf5File.parent
     prefix = UtilsImage.getPrefix(hdf5File)
     if 'imageNumber' in inData:
         commandLine, cbfFile = self.generateCommandsWithImageNumber(
             inData, directory, prefix, hdf5File)
         outData['outputCBFFile'] = str(cbfFile)
     elif 'startImageNumber' in inData and 'endImageNumber' in inData:
         commandLine, template = self.generateCommandsWithImageRange(
             inData, directory, prefix, hdf5File)
         outData['outputCBFFileTemplate'] = template
     self.setLogFileName('h5ToCBF.log')
     self.runCommandLine('eiger2cbf ' + commandLine, ignoreErrors=True)
     return outData
Esempio n. 6
0
 def getH5FilePath(cls, filePath, batchSize=1, isFastMesh=False):
     imageNumber = UtilsImage.getImageNumber(filePath)
     prefix = UtilsImage.getPrefix(filePath)
     if isFastMesh:
         h5ImageNumber = int((imageNumber - 1) / 100) + 1
         h5FileNumber = 1
     else:
         h5ImageNumber = 1
         h5FileNumber = int((imageNumber - 1) / batchSize) * batchSize + 1
     h5MasterFileName = "{prefix}_{h5FileNumber}_master.h5".format(
         prefix=prefix, h5FileNumber=h5FileNumber)
     h5MasterFilePath = filePath.parent / h5MasterFileName
     h5DataFileName = \
         "{prefix}_{h5FileNumber}_data_{h5ImageNumber:06d}.h5".format(
             prefix=prefix, h5FileNumber=h5FileNumber, h5ImageNumber=h5ImageNumber)
     h5DataFilePath = filePath.parent / h5DataFileName
     return h5MasterFilePath, h5DataFilePath, h5FileNumber
Esempio n. 7
0
def findDataCollectionFromFileLocationAndFileName(imagePath, client=None):
    logger = UtilsLogging.getLogger()
    dataCollectionWS3VO = None
    noTrials = 10
    fileLocation = os.path.dirname(imagePath)
    fileName = os.path.basename(imagePath)
    if fileName.endswith(".h5"):
        prefix = UtilsImage.getPrefix(fileName)
        imageNumber = UtilsImage.getImageNumber(fileName)
        fileName = "{0}_{1:04d}.h5".format(prefix, imageNumber)
    try:
        if client is None:
            client = getCollectionWebService()
        if client is None:
            logger.error(
                "No web service client available, cannot contact findDataCollectionFromFileLocationAndFileName web service."
            )
        elif fileLocation is None:
            logger.error(
                "No fileLocation given, cannot contact findDataCollectionFromFileLocationAndFileName web service."
            )
        elif fileName is None:
            logger.error(
                "No fileName given, cannot contact findDataCollectionFromFileLocationAndFileName web service."
            )
        else:
            dataCollectionWS3VO = client.service.findDataCollectionFromFileLocationAndFileName(
                fileLocation, fileName)
    except Exception as e:
        logger.error(
            "ISPyB error for findDataCollectionFromFileLocationAndFileName: {0}, {1} trials left"
            .format(e, noTrials))
        raise e
    if dataCollectionWS3VO is None:
        time.sleep(1)
        if noTrials == 0:
            raise RuntimeError(
                "ISPyB error for findDataCollectionFromFileLocationAndFileName - no data collections found for path {0}"
                .format(imagePath))
        else:
            logger.warning(
                "Cannot find {0} in ISPyB - retrying, {1} trials left".format(
                    imagePath, noTrials))
    return dataCollectionWS3VO
Esempio n. 8
0
 def run(self, inData):
     outData = {}
     # First get the list of subWedges
     if "subWedge" in inData:
         listSubWedge = inData["subWedge"]
     else:
         listSubWedge = self.getListSubWedge(inData)
     # Get list of spots from Dozor
     listOutDataControlDozor = self.runControlDozor(listSubWedge)
     listDozorSpotFile = []
     for outDataControlDozor in listOutDataControlDozor:
         if "dozorSpotFile" in outDataControlDozor["imageQualityIndicators"][0]:
             dozorSpotFile = outDataControlDozor["imageQualityIndicators"][0]["dozorSpotFile"]
             listDozorSpotFile.append(dozorSpotFile)
     imageDict = listSubWedge[0]
     listXdsIndexingTask = []
     listResult = []
     listSpaceGroup = []
     # Run XDS indexing
     xdsIndexinInData = {
         "subWedge": listSubWedge,
         "dozorSpotFile": listDozorSpotFile
     }
     xdsIndexingTask = XDSIndexing(
         inData=xdsIndexinInData,
         workingDirectorySuffix=UtilsImage.getPrefix(imageDict["image"][0]["path"])
     )
     xdsIndexingTask.execute()
     xparmXdsPath = None
     if xdsIndexingTask.isSuccess():
         xdsIndexingOutData = xdsIndexingTask.outData
         xparmXdsPath = xdsIndexingOutData["xparmXdsPath"]
         resultIndexing = ControlIndexing.getResultIndexingFromXds(xdsIndexingOutData)
     outData = {
         "resultIndexing": resultIndexing,
         "resultDozor": listOutDataControlDozor,
         "xparmXdsPath": xparmXdsPath
     }
     return outData
Esempio n. 9
0
 def test_getPrefixH5(self):
     prefix = UtilsImage.getPrefix(self.imageFileNameH5)
     self.assertEqual(prefix, "mesh-local-user_0_1")
Esempio n. 10
0
 def test_getPrefix(self):
     prefix = UtilsImage.getPrefix(self.imageFileName)
     self.assertEqual(prefix, "ref-testscale_1")
Esempio n. 11
0
    def generateImageLinks(in_data, working_directory=None):
        first_sub_wedge = in_data["subWedge"][0]
        first_image_path = first_sub_wedge["image"][0]["path"]
        prefix = UtilsImage.getPrefix(first_image_path)
        suffix = UtilsImage.getSuffix(first_image_path)
        if suffix == "h5":
            lowest_xds_image_number = 1
            highest_xds_image_number = 1
            h5MasterFilePath, h5DataFilePath, h5FileNumber = UtilsImage.getH5FilePath(
                first_image_path, hasOverlap=True, isFastMesh=False)
            h5MasterFile = os.path.basename((str(h5MasterFilePath)))
            h5DataFile = os.path.basename((str(h5DataFilePath)))
            list_image_link = [
                [str(h5MasterFilePath), h5MasterFile],
                [str(h5DataFilePath), h5DataFile],
            ]
            if working_directory is not None:
                os.symlink(str(h5MasterFilePath), h5MasterFile)
                os.symlink(str(h5DataFilePath), h5DataFile)
            template = h5MasterFile.replace("master", "??????")
            lowest_xds_image_number = None
            highest_xds_image_number = None
            for subwedge in in_data["subWedge"]:
                image_list = subwedge["image"]
                for image_dict in image_list:
                    image_path = image_dict["path"]
                    image_number = UtilsImage.getImageNumber(image_path)
                    if lowest_xds_image_number is None or lowest_xds_image_number > image_number:
                        lowest_xds_image_number = image_number
                    if highest_xds_image_number is None or highest_xds_image_number < image_number:
                        highest_xds_image_number = image_number
        else:
            template = "%s_xdslink_?????.%s" % (prefix, suffix)
            xds_lowest_image_number_global = 1
            # First we have to find the smallest goniostat rotation axis start:
            oscillation_start_min = 0

            # Loop through the list of sub wedges
            list_of_list = []
            lowest_xds_image_number = None
            highest_xds_image_number = None
            list_spot_range = []
            for sub_wedge in in_data["subWedge"]:
                list_image_link = []
                image_list = sub_wedge["image"]
                goniostat = sub_wedge["experimentalCondition"]["goniostat"]
                oscillation_start = goniostat["rotationAxisStart"]
                oscillation_range = goniostat["oscillationWidth"]

                # First find the lowest and highest image numbers
                lowest_image_number = None
                for image in image_list:
                    image_number = image["number"]
                    if lowest_image_number is None or image_number < lowest_image_number:
                        lowest_image_number = image_number

                # Loop through the list of images
                spot_range_min = None
                spot_range_max = None
                for image in image_list:
                    image_number = image["number"]
                    image_oscillation_start = (
                        oscillation_start +
                        (image_number - lowest_image_number) *
                        oscillation_range)
                    # if xdsLowestImageNumberGlobal is None:
                    #     xdsLowestImageNumberGlobal = 1 + int((imageOscillationStart - oscillationStartMin) / oscillationRange)
                    xds_image_number = xds_lowest_image_number_global + int(
                        (image_oscillation_start - oscillation_start_min) /
                        oscillation_range + 0.5)
                    print(
                        xds_image_number,
                        image_oscillation_start,
                        oscillation_start_min,
                        oscillation_range,
                    )
                    source_path = image["path"]
                    target = "%s_xdslink_%05d.%s" % (prefix, xds_image_number,
                                                     suffix)
                    print([source_path, target])
                    list_image_link.append([source_path, target])
                    if working_directory is not None and not os.path.exists(
                            target):
                        os.symlink(source_path, target)
                    if (lowest_xds_image_number is None
                            or lowest_xds_image_number > xds_image_number):
                        lowest_xds_image_number = xds_image_number
                    if (highest_xds_image_number is None
                            or highest_xds_image_number < xds_image_number):
                        highest_xds_image_number = xds_image_number
                    if spot_range_min is None or spot_range_min > xds_image_number:
                        spot_range_min = xds_image_number
                    if spot_range_max is None or spot_range_max < xds_image_number:
                        spot_range_max = xds_image_number
                list_spot_range.append([spot_range_min, spot_range_max])
                list_of_list.append(list_image_link)
        previous_exclude_data_range_max = 1
        list_exclude_data_range = []
        for spot_range_min, spot_range_max in list_spot_range:
            if spot_range_min > previous_exclude_data_range_max + 1:
                list_exclude_data_range.append(
                    [previous_exclude_data_range_max, spot_range_min - 1])
            previous_exclude_data_range_max = spot_range_max + 1
        dictImageLinks = {
            "imageLink": list_of_list,
            "spotRange": list_spot_range,
            "dataRange": [lowest_xds_image_number, highest_xds_image_number],
            "excludeDataRange": list_exclude_data_range,
            "template": template,
        }
        return dictImageLinks
Esempio n. 12
0
    def run(self, inData):
        listImagePath = inData["imagePath"]
        prefix = UtilsImage.getPrefix(listImagePath[0])
        listSubWedge = self.getListSubWedge(inData)
        diffractionPlan = inData.get("diffractionPlan", {})
        sample = inData.get("sample", {})
        # Check if flux is present
        flux = None
        absorbedDoseRate = None
        experimentalCondition = inData.get("experimentalCondition", None)
        if experimentalCondition is not None:
            beam = experimentalCondition.get("beam", None)
            if beam is not None:
                flux = beam.get("flux", None)
                # if not "size" in beam:
                #     beam["size"] = listSubWedge[0]["experimentalCondition"]["beam"]["size"]
                beam["exposureTime"] = listSubWedge[0][
                    "experimentalCondition"]["beam"]["exposureTime"]
                beam["wavelength"] = listSubWedge[0]["experimentalCondition"][
                    "beam"]["wavelength"]
        # Convert images to CBF
        firstImage = listSubWedge[0]["image"][0]["path"]
        import os
        import pprint

        listH5ToCBF = []
        suffix = os.path.splitext(firstImage)[1]
        if suffix == ".h5":
            for subWedge in listSubWedge:
                imageList = subWedge["image"]
                for image in imageList:
                    imagePath = image["path"]
                    hdf5ImageNumber = UtilsImage.getImageNumber(imagePath)
                    inDataH5ToCBF = {
                        "hdf5File": imagePath,
                        "hdf5ImageNumber": hdf5ImageNumber,
                        "imageNumber": 1,
                        "forcedOutputDirectory":
                        str(self.getWorkingDirectory()),
                        "forcedOutputImageNumber": hdf5ImageNumber,
                    }
                    h5ToCBF = H5ToCBFTask(inData=inDataH5ToCBF)
                    h5ToCBF.start()
                    listH5ToCBF.append((image, h5ToCBF))
        # Join CBF creation
        for image, h5ToCBF in listH5ToCBF:
            h5ToCBF.join()
            image["path"] = h5ToCBF.outData["outputCBFFile"]
        pprint.pprint(listSubWedge)
        # Start indexing
        outDataIndexing, outDataGB, listSubWedge = self.indexing(
            prefix, listSubWedge, self.getWorkingDirectory())
        if outDataIndexing is not None and outDataGB is not None:
            listXdsAsciiHkl, correctLp, bkgpixCbf = self.integration(
                prefix, listSubWedge, outDataIndexing, outDataGB)
            if listXdsAsciiHkl is not None:
                # Check if Raddose should be run
                estimateRadiationDamage = self.checkEstimateRadiationDamage(
                    inData, flux)
                if estimateRadiationDamage:
                    # Check if forced space group
                    forcedSpaceGroup = None
                    numOperators = None
                    cell = None
                    if ("diffractionPlan" in inData and "forcedSpaceGroup"
                            in inData["diffractionPlan"]):
                        forcedSpaceGroup = inData["diffractionPlan"][
                            "forcedSpaceGroup"]
                        if forcedSpaceGroup is not None:
                            if forcedSpaceGroup != "":
                                forcedSpaceGroup = forcedSpaceGroup.replace(
                                    " ", "")
                                numOperators = UtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupName(
                                    forcedSpaceGroup)
                            else:
                                forcedSpaceGroup = None
                    if forcedSpaceGroup is None:
                        # Get indexing space group IT number
                        if "resultIndexing" in outDataIndexing:
                            resultIndexing = outDataIndexing["resultIndexing"]
                            cell = resultIndexing["cell"]
                            if "spaceGroupNumber" in resultIndexing:
                                spaceGroupNumber = resultIndexing[
                                    "spaceGroupNumber"]
                                numOperators = UtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupITNumber(
                                    spaceGroupNumber)
                    if numOperators is None:
                        raise RuntimeError(
                            "Error when trying to determine number of symmetry operators!"
                        )
                    chemicalComposition = self.getDefaultChemicalComposition(
                        cell, numOperators)
                    numberOfImages = self.getNumberOfImages(listSubWedge)
                    sample = inData["sample"]
                    inDataRaddose = {
                        "experimentalCondition": experimentalCondition,
                        "chemicalComposition": chemicalComposition,
                        "sample": sample,
                        "cell": cell,
                        "numberOfImages": numberOfImages,
                        "numOperators": numOperators,
                    }
                    # import pprint
                    # pprint.pprint(inDataRaddose)
                    raddose = Raddose(inData=inDataRaddose,
                                      workingDirectorySuffix=prefix)
                    raddose.execute()
                    if raddose.isSuccess():
                        absorbedDoseRate = raddose.outData["absorbedDoseRate"]
                inDataBest = {
                    "diffractionPlan": diffractionPlan,
                    "sample": sample,
                    "subWedge": listSubWedge,
                    "xdsAsciiHkl": listXdsAsciiHkl,
                    "bkgpixCbf": bkgpixCbf,
                    "correctLp": correctLp,
                    "crystalAbsorbedDoseRate": absorbedDoseRate,
                }
                bestTask = Best(inData=inDataBest,
                                workingDirectorySuffix=prefix)
                bestTask.execute()
Esempio n. 13
0
    def generateImageLinks(inData, workingDirectory=None):
        listImageLink = []
        firstSubWedge = inData["subWedge"][0]
        firstImagePath = firstSubWedge["image"][0]["path"]
        prefix = UtilsImage.getPrefix(firstImagePath)
        suffix = UtilsImage.getSuffix(firstImagePath)
        template = "%s_xdslink_?????.%s" % (prefix, suffix)
        xdsLowestImageNumberGlobal = 1
        # First we have to find the smallest goniostat rotation axis start:
        oscillationStartMin = 0
        # for subWedge in inData["subWedge"]:
        #     goniostat = subWedge["experimentalCondition"]["goniostat"]
        #     oscillationStart = goniostat["rotationAxisStart"]
        #     if oscillationStartMin is None or \
        #         oscillationStartMin > oscillationStart:
        #         oscillationStartMin = oscillationStart

        # Loop through the list of sub wedges

        for subWedge in inData["subWedge"]:
            imageList = subWedge["image"]
            xsDataGoniostat = subWedge["experimentalCondition"]["goniostat"]
            oscillationStart = xsDataGoniostat["rotationAxisStart"]
            oscillationRange = xsDataGoniostat["oscillationWidth"]

            # First find the lowest and highest image numbers
            lowestImageNumber = None
            for dictImage in imageList:
                imageNumber = dictImage["number"]
                if lowestImageNumber is None or imageNumber < lowestImageNumber:
                    lowestImageNumber = imageNumber

            # Loop through the list of images
            lowestXDSImageNumber = None
            highestXDSImageNumber = None
            for dictImage in imageList:
                imageNumber = dictImage["number"]
                imageOscillationStart = \
                    oscillationStart + (imageNumber - lowestImageNumber) * oscillationRange
                # if xdsLowestImageNumberGlobal is None:
                #     xdsLowestImageNumberGlobal = 1 + int((imageOscillationStart - oscillationStartMin) / oscillationRange)
                xdsImageNumber = xdsLowestImageNumberGlobal + \
                                 int((imageOscillationStart - oscillationStartMin) / oscillationRange)
                print(xdsImageNumber, imageOscillationStart,
                      oscillationStartMin, oscillationRange)
                sourcePath = dictImage["path"]
                target = "%s_xdslink_%05d.%s" % (prefix, xdsImageNumber,
                                                 suffix)
                print([sourcePath, target])
                listImageLink.append([sourcePath, target])
                if workingDirectory is not None:
                    os.symlink(sourcePath, target)
                if lowestXDSImageNumber is None or \
                        lowestXDSImageNumber > xdsImageNumber:
                    lowestXDSImageNumber = xdsImageNumber
                if highestXDSImageNumber is None or \
                        highestXDSImageNumber < xdsImageNumber:
                    highestXDSImageNumber = xdsImageNumber
        dictImageLinks = {
            "imageLink": listImageLink,
            "dataRange": [lowestXDSImageNumber, highestXDSImageNumber],
            "template": template
        }
        return dictImageLinks
Esempio n. 14
0
 def run(self, inData):
     outData = {}
     listImagePath = inData["imagePath"]
     prefix = UtilsImage.getPrefix(listImagePath[0])
     listSubWedge = self.getListSubWedge(inData)
     diffractionPlan = inData.get("diffractionPlan", {})
     sample = inData.get("sample", {})
     # Check if flux is present
     flux = None
     absorbedDoseRate = None
     experimentalCondition = inData.get("experimentalCondition", None)
     if experimentalCondition is not None:
         beam = experimentalCondition.get("beam", None)
         if beam is not None:
             flux = beam.get("flux", None)
             # if not "size" in beam:
             #     beam["size"] = listSubWedge[0]["experimentalCondition"]["beam"]["size"]
             beam["exposureTime"] = listSubWedge[0]["experimentalCondition"]["beam"]["exposureTime"]
             beam["wavelength"] = listSubWedge[0]["experimentalCondition"]["beam"]["wavelength"]
     # Start indexing
     outDataIndexing, outDataGB = self.indexing(prefix, listSubWedge)
     if outDataIndexing is not None and outDataGB is not None:
         listXdsAsciiHkl, correctLp, bkgpixCbf = self.integration(
             prefix, listSubWedge, outDataIndexing, outDataGB)
         if listXdsAsciiHkl is not None:
             # Check if Raddose should be run
             estimateRadiationDamage = self.checkEstimateRadiationDamage(inData, flux)
             if estimateRadiationDamage:
                 # Check if forced space group
                 forcedSpaceGroup = None
                 numOperators = None
                 cell = None
                 if "diffractionPlan" in inData and "forcedSpaceGroup" in inData["diffractionPlan"]:
                     forcedSpaceGroup = inData["diffractionPlan"]["forcedSpaceGroup"]
                     if forcedSpaceGroup is not None:
                         if forcedSpaceGroup != "":
                             forcedSpaceGroup = forcedSpaceGroup.replace(" ", "")
                             numOperators = UtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupName(forcedSpaceGroup)
                         else:
                             forcedSpaceGroup = None
                 if forcedSpaceGroup is None:
                     # Get indexing space group IT number
                     if "resultIndexing" in outDataIndexing:
                         resultIndexing = outDataIndexing["resultIndexing"]
                         cell = resultIndexing["cell"]
                         if "spaceGroupNumber" in resultIndexing:
                             spaceGroupNumber = resultIndexing["spaceGroupNumber"]
                             numOperators = UtilsSymmetry.getNumberOfSymmetryOperatorsFromSpaceGroupITNumber(spaceGroupNumber)
                 if numOperators is None:
                     raise RuntimeError("Error when trying to determine number of symmetry operators!")
                 chemicalComposition = self.getDefaultChemicalComposition(cell, numOperators)
                 numberOfImages = self.getNumberOfImages(listSubWedge)
                 sample = inData["sample"]
                 inDataRaddose = {
                     "experimentalCondition": experimentalCondition,
                     "chemicalComposition": chemicalComposition,
                     "sample": sample,
                     "cell": cell,
                     "numberOfImages": numberOfImages,
                     "numOperators": numOperators
                 }
                 # import pprint
                 # pprint.pprint(inDataRaddose)
                 raddose = Raddose(
                     inData=inDataRaddose,
                     workingDirectorySuffix=prefix)
                 raddose.execute()
                 if raddose.isSuccess():
                     absorbedDoseRate = raddose.outData["absorbedDoseRate"]
             inDataBest = {
                 "diffractionPlan": diffractionPlan,
                 "sample": sample,
                 "subWedge": listSubWedge,
                 "xdsAsciiHkl": listXdsAsciiHkl,
                 "bkgpixCbf": bkgpixCbf,
                 "correctLp": correctLp,
                 "crystalAbsorbedDoseRate": absorbedDoseRate
             }
             bestTask = Best(
                 inData=inDataBest,
                 workingDirectorySuffix=prefix
             )
             bestTask.execute()
Esempio n. 15
0
    def exeIndexing(self, inData):
        doCBFtoH5 = inData.get('doCBFtoH5', False)
        in_for_crystfel = dict()

        if 'listH5FilePath' in inData.keys():
            tmp = UtilsImage.getPrefix(inData['listH5FilePath'][0])
            FirstImage = tmp.replace('data', 'master.h5')
            Image = Im(FirstImage)
            in_for_crystfel['detectorType'] = Image.imobject.headers['detector_name'][0] + \
                                              Image.imobject.headers['detector_name'][1]
            in_for_crystfel['prefix'] = tmp.strip('data')
            in_for_crystfel['suffix'] = UtilsImage.getSuffix(inData['listH5FilePath'][0])
            in_for_crystfel['image_directory'] = str(pathlib.Path(inData['listH5FilePath'][0]).parent)
            in_for_crystfel['maxchunksize'] = 10

        elif 'cbfFileInfo' in inData.keys():
            in_for_crystfel['maxchunksize'] = inData['cbfFileInfo'].get('batchSize', 10)
            in_for_crystfel['listofImages'] = inData['cbfFileInfo'].get('listofImages', [])
            in_for_crystfel['image_directory'] = inData['cbfFileInfo']['directory']
            in_for_crystfel['prefix'] = inData['cbfFileInfo']['template'].strip('####.cbf')
            in_for_crystfel['suffix'] = UtilsImage.getSuffix(inData['cbfFileInfo']['template'])
            if len(in_for_crystfel['listofImages']) == 0:
                in_for_crystfel['ImageRange'] = (inData['cbfFileInfo']['startNo'], inData['cbfFileInfo']['endNo'])
                FirstImage = os.path.join(inData['cbfFileInfo']['directory'], inData['cbfFileInfo']['template'].
                                          replace('####', '0001'))
            else:
                FirstImage = in_for_crystfel['listofImages'][0]

            Image = Im(FirstImage)
            in_for_crystfel['detectorType'] = Image.imobject.headers['detector_name'][0] + \
                                              Image.imobject.headers['detector_name'][1]
        else:
            logger.error("input json must have either listH5FilePath or cbfFileInfo")

        if doCBFtoH5:
            cxi_all = list(self.getWorkingDirectory().glob('dozor*cxi'))
            current = len(cxi_all) - 1
            in_for_crystfel['image_directory'] = self.getWorkingDirectory()
            in_for_crystfel['prefix'] = 'dozor_%d.' % current
            in_for_crystfel['suffix'] = 'cxi'
            in_for_crystfel['peak_search'] = 'cxi'
            in_for_crystfel['peak_info'] = '/data/peakinfo'
            in_for_crystfel['maxchunksize'] = 10

        crysttask = run_crystfel.AutoCrystFEL(in_for_crystfel)
        outstream = None
        try:
            jsonschema.validate(instance=crysttask.jshandle, schema=crysttask.getInDataSchema())
            crysttask.datafinder()
            crysttask.makeOutputDirectory()
            kk = {}
            if crysttask.jshandle['suffix'] == 'cxi':
                kk['cxi'] = """dim0 = %\ndim1 = ss\ndim2 = fs\ndata = /data/data\n"""
                geomfile = crysttask.make_geometry_file(**kk)
            else:
                geomfile = crysttask.make_geometry_file(**kk)

            crysttask.make_list_events(str(geomfile))
            infile = str(crysttask.getOutputDirectory() / 'input.lst')
            outname = datetime.now().strftime('%H-%M-%S.stream')
            outstream = str(crysttask.getOutputDirectory() / outname)

            ofh = open(infile, 'w')
            for fname in crysttask.filelist:
                ofh.write(fname)
                ofh.write('\n')
            ofh.close()
            crystfel_cmd = crysttask.indexamajig_cmd(infile, outstream, geomfile)
            self.runCommandLine(crystfel_cmd, doSubmit=inData.get('doSubmit', True))

        except Exception as err:
            self.setFailure()
            logger.error(err)

        return outstream, crysttask