def preProcess(self): EDPluginExecProcessScript.preProcess(self) self.DEBUG('Pointless: preprocess') if self.output_file is not None and self.input_file is not None: if EDUtilsPath.isEMBL() or EDUtilsPath.isALBA(): options = '''-c xdsin {0} hklout {1}'''.format( self.input_file, self.output_file) else: options = '''xdsin {0} hklout {1}'''.format( self.input_file, self.output_file) self.setScriptCommandline(options) self.DEBUG('command line options set to {0}'.format(options)) self.addListCommandExecution('setting symmetry-based') if self.dataInput.choose_spacegroup is not None: self.addListCommandExecution('choose spacegroup {0}'.format( self.dataInput.choose_spacegroup.value))
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlRunXdsFastProcv1_0.preProcess") # Load the execution plugin self.first_run = self.loadPlugin(self.controlled_plugin_name) cfg = parse_xds_file(self.dataInput.input_file.value) spot_range = cfg.get('SPOT_RANGE=') if spot_range is None: if EDUtilsPath.isEMBL() or EDUtilsPath.isALBA(): # GB: add a default here - it is nothing worthe then the # one in autogenerated XDS.INP pass else: strErrorMessage = "No SPOT_RANGE parameter" self.addErrorMessage(strErrorMessage) self.ERROR(strErrorMessage) self.setFailure() else: self.spot_range = spot_range # we will use this value to constrain the upper bound of # spot_range so it does not get past the last image number, so # we use a default value that cannot be a constraint in case # we cannot find it in the xds input file self.end_image_no = sys.maxsize data_range = cfg.get('DATA_RANGE=') if data_range is not None: self.start_image_no = data_range[0] self.end_image_no = data_range[1] # GB: repair the above.... but why spot_range should be a list of lists? if spot_range is None: self.spot_range = [[max(1, data_range[0]), min(data_range[0] + 99, data_range[1])]] else: # Check that spot ranges is within data range new_spot_range = [] for spot_range in self.spot_range: if spot_range[0] >= self.start_image_no and spot_range[1] <= self.end_image_no: new_spot_range.append(spot_range) self.spot_range = new_spot_range
def __init__(self): EDLogging.__init__(self) Thread.__init__(self) self.__edSlotPreProcess = EDSlot() self.__edSlotProcess = EDSlot() self.__edSlotPostProcess = EDSlot() self.__edSlotSUCCESS = EDSlot() self.__edSlotFAILURE = EDSlot() self.__edSlotFinallyProcess = EDSlot() self.__bIsFailure = False self.__bIsTimeOut = False self.__fTimeOutInSeconds = None if EDUtilsPath.isEMBL() or EDUtilsPath.isALBA(): self.__fDefaultTimeOutInSeconds = 3600.0 else: self.__fDefaultTimeOutInSeconds = 600.0 self.__bIsAbort = False # Reference to the object which calls execute or executeSynchronous self.__edObject = None self.__lExtraTime = [ ] # list of extra allowed time for execution (in second) self.__bLogTiming = False
def finallyProcess(self, _edPlugin=None): EDPluginExec.finallyProcess(self, _edPlugin) self.DEBUG("EDPluginExecSimpleHTMLPagev2_1.finallyProcess...") xsDataResultSimpleHTMLPage = XSDataResultSimpleHTMLPage() xsDataResultSimpleHTMLPage.setPathToHTMLFile( XSDataFile( XSDataString( os.path.join(self.getWorkingDirectory(), self.strHtmlFileName)))) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory( XSDataFile(XSDataString(self.getWorkingDirectory()))) # Write workflowStepReport HTML page pathToIndexFile = self.workflowStepReport.renderHtml( self.getWorkingDirectory(), nameOfIndexFile=self.strHtmlFileName) pathToJsonFile = self.workflowStepReport.renderJson( self.getWorkingDirectory()) # Store in Pyarch if EDUtilsPath.isESRF() or EDUtilsPath.isEMBL() or EDUtilsPath.isALBA( ) or EDUtilsPath.isMAXIV(): strPyarchPath = None if self.xsDataResultCharacterisation is not None: strPyarchPath = EDHandlerESRFPyarchv1_0.createPyarchHtmlDirectoryPath( self.xsDataResultCharacterisation.getDataCollection()) if strPyarchPath is None: # For debugging purposes strPyarchPath = EDUtilsPath.getEdnaUserTempFolder() EDHandlerESRFPyarchv1_0.copyHTMLDir( _strPathToHTMLDir=os.path.dirname(self.strPath), _strPathToPyarchDirectory=strPyarchPath) xsDataResultSimpleHTMLPage.setPathToHTMLDirectory( XSDataFile(XSDataString(strPyarchPath))) shutil.copy(pathToJsonFile, strPyarchPath) pathToJsonFile = os.path.join(strPyarchPath, os.path.basename(pathToJsonFile)) # Write json file xsDataResultSimpleHTMLPage.pathToJsonFile = XSDataFile( XSDataString(pathToJsonFile)) self.setDataOutput(xsDataResultSimpleHTMLPage)
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) self.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess") # Check that the input image exists and is of the expected type strPathToDiffractionImage = self.dataInput.diffractionImage.path.value strImageFileNameExtension = os.path.splitext( strPathToDiffractionImage)[1] if not strImageFileNameExtension in [ ".img", ".marccd", ".mccd", ".cbf", ".h5" ]: self.error( "Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage) self.setFailure() else: # Load the MXWaitFile plugin xsDataInputMXWaitFile = XSDataInputMXWaitFile() pathToImageFile = strPathToDiffractionImage # Quite ugly hack to avoid lag problems at the ESRF: if EDUtilsPath.isESRF() or EDUtilsPath.isALBA(): if any(beamline in strPathToDiffractionImage for beamline in ["id23eh1", "id29", "id30b"]): # Pilatus 6M self.minImageSize = 6000000 elif any(beamline in strPathToDiffractionImage for beamline in ["id23eh2", "id30a1"]): # Pilatus3 2M self.minImageSize = 2000000 elif strImageFileNameExtension == ".h5": self.h5MasterFilePath, self.h5DataFilePath, self.h5FileNumber = self.getH5FilePath( pathToImageFile) pathToImageFile = self.h5DataFilePath self.isH5 = True elif EDUtilsPath.isEMBL(): self.minImageSize = 10000 xsDataInputMXWaitFile.setSize(XSDataInteger(self.minImageSize)) xsDataInputMXWaitFile.setFile( XSDataFile(XSDataString(pathToImageFile))) if self.getDataInput().getWaitForFileTimeOut(): xsDataInputMXWaitFile.setTimeOut( self.getDataInput().getWaitForFileTimeOut()) self.edPluginMXWaitFile = self.loadPlugin( self.strMXWaitFilePluginName) self.edPluginMXWaitFile.setDataInput(xsDataInputMXWaitFile) # Load the execution plugin self.edPluginExecThumbnail = self.loadPlugin( self.strExecThumbnailPluginName) xsDataInputMXThumbnail = XSDataInputMXThumbnail() xsDataInputMXThumbnail.image = self.getDataInput( ).getDiffractionImage() xsDataInputMXThumbnail.height = XSDataInteger(1024) xsDataInputMXThumbnail.width = XSDataInteger(1024) xsDataInputMXThumbnail.format = self.dataInput.format # Output path strImageNameWithoutExt = os.path.basename( os.path.splitext(strPathToDiffractionImage)[0]) strImageDirname = os.path.dirname(strPathToDiffractionImage) if self.getDataInput().getForcedOutputDirectory(): strForcedOutputDirectory = self.getDataInput( ).getForcedOutputDirectory().getPath().getValue() if not os.access(strForcedOutputDirectory, os.W_OK): self.error("Cannot write to forced output directory : %s" % strForcedOutputDirectory) self.setFailure() else: self.strOutputPathWithoutExtension = os.path.join( strForcedOutputDirectory, strImageNameWithoutExt) else: # Try to store in the ESRF pyarch directory strOutputDirname = EDHandlerESRFPyarchv1_0.createPyarchFilePath( strImageDirname) # Check that output pyarch path exists and is writeable: bIsOk = False if strOutputDirname: if not os.path.exists(strOutputDirname): # Try to create the directory try: os.makedirs(strOutputDirname) bIsOk = True except Exception as e: self.WARNING("Couldn't create the directory %s" % strOutputDirname) elif os.access(strOutputDirname, os.W_OK): bIsOk = True if not bIsOk: self.warning("Cannot write to pyarch directory: %s" % strOutputDirname) strTmpUser = os.path.join("/tmp", os.environ["USER"]) if not os.path.exists(strTmpUser): os.mkdir(strTmpUser, 0o755) strOutputDirname = tempfile.mkdtemp( prefix="EDPluginPyarchThumbnailv10_", dir=strTmpUser) os.chmod(strOutputDirname, 0o755) self.warning("Writing thumbnail images to: %s" % strOutputDirname) self.strOutputPathWithoutExtension = os.path.join( strOutputDirname, strImageNameWithoutExt) if self.dataInput.format is not None: self.strSuffix = self.dataInput.format.value.lower() self.strImageFormat = self.dataInput.format.value.upper() self.strOutputPath = os.path.join( self.strOutputPathWithoutExtension + "." + self.strSuffix) xsDataInputMXThumbnail.setOutputPath( XSDataFile(XSDataString(self.strOutputPath))) self.edPluginExecThumbnail.setDataInput(xsDataInputMXThumbnail)
def process(self): self.DEBUG('FileConversion: process') EDPluginControl.process(self) # first we generate the intermediary file name pointless_in = XSDataPointless() pointless_in.input_file = self.dataInput.input_file pointless_out = os.path.join(os.path.dirname(self.dataInput.output_file.value), self.pointless_out) pointless_in.output_file = XSDataString(pointless_out) if self.dataInput.choose_spacegroup is not None: pointless_in.choose_spacegroup = self.dataInput.choose_spacegroup self.pointless.dataInput = pointless_in self.screen("Pointless run " + self.strAnomSuffix) self.pointless.executeSynchronous() if self.pointless.isFailure(): strErrorMessage = "Pointless {0} failed".format(self.strAnomSuffix) self.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() return aimless_in = XSDataAimless() aimless_in.input_file = pointless_in.output_file aimless_in.output_file = XSDataString(os.path.join(self.results_dir, self.aimless_out)) aimless_in.command_file = XSDataString(os.path.join(self.results_dir, self.aimless_commands_out)) aimless_in.dataCollectionID = self.dataInput.dataCollectionID aimless_in.start_image = self.dataInput.start_image aimless_in.end_image = self.dataInput.end_image aimless_in.res = self.dataInput.res aimless_in.anom = self.dataInput.anom self.aimless.dataInput = aimless_in self.screen("Aimless run " + self.strAnomSuffix) self.aimless.executeSynchronous() if self.aimless.isFailure(): strErrorMessage = "Aimless {0} failed".format(self.strAnomSuffix) self.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() return # copy the aimless log where the results files are source_log = os.path.join(self.aimless.getWorkingDirectory(), self.aimless.getScriptLogFileName()) self.aimless_log = source_log target_log = os.path.join(self.results_dir, 'ep_{0}aimless_{1}.log'.format(self.image_prefix, "anom" if self.dataInput.anom.value else "noanom")) try: shutil.copyfile(source_log, target_log) except IOError: self.ERROR('Could not copy aimless log file from {0} to {1}'.format(source_log, target_log)) # now truncate truncate_in = XSDataTruncate() truncate_in.input_file = self.aimless.dataInput.output_file temp_file = tempfile.NamedTemporaryFile(suffix='.mtz', prefix='tmp2-', dir=self.aimless.getWorkingDirectory(), delete=False) truncate_out = temp_file.name temp_file.close() os.chmod(truncate_out, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) truncate_in.output_file = XSDataString(truncate_out) truncate_in.nres = self.dataInput.nres truncate_in.anom = self.dataInput.anom truncate_in.res = self.dataInput.res self.truncate.dataInput = truncate_in self.screen("Truncate run " + self.strAnomSuffix) self.truncate.executeSynchronous() if self.truncate.isFailure(): strErrorMessage = "Truncate {0} failed".format(self.strAnomSuffix) self.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() return # copy the truncate log where the results files are source_log = os.path.join(self.truncate.getWorkingDirectory(), self.truncate.getScriptLogFileName()) target_log = os.path.join(self.results_dir, 'ep_{0}truncate_{1}.log'.format(self.image_prefix, "anom" if self.dataInput.anom.value else "noanom")) try: shutil.copyfile(source_log, target_log) except IOError: self.ERROR('Could not copy truncate log file from {0} to {1}'.format(source_log, target_log)) # and finally uniqueify uniqueify_in = XSDataUniqueify() uniqueify_in.input_file = truncate_in.output_file uniqueify_out = os.path.join(self.results_dir, self.truncate_out) uniqueify_in.output_file = XSDataString(uniqueify_out) self.uniqueify.dataInput = uniqueify_in if EDUtilsPath.isEMBL() or EDUtilsPath.isALBA(): # GB: skipping misteriously failing uniqueify run - # which is useless anyway. # copying temp truncate output to results directly shutil.copyfile(uniqueify_in.input_file.value, uniqueify_out) return self.screen("Uniqueify run " + self.strAnomSuffix) self.uniqueify.executeSynchronous() if self.uniqueify.isFailure(): strErrorMessage = "Uniqueify {0} failed".format(self.strAnomSuffix) self.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() return
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG('EDPluginControlAutoPROCv1_0.process starting') directory = None template = None imageNoStart = None imageNoEnd = None pathToStartImage = None pathToEndImage = None userName = os.environ["USER"] beamline = "unknown" proposal = "unknown" # If we have a data collection id, use it if self.dataInput.dataCollectionId is not None: # Recover the data collection from ISPyB xsDataInputRetrieveDataCollection = XSDataInputRetrieveDataCollection() identifier = str(self.dataInput.dataCollectionId.value) xsDataInputRetrieveDataCollection.dataCollectionId = self.dataInput.dataCollectionId self.edPluginRetrieveDataCollection.dataInput = xsDataInputRetrieveDataCollection self.edPluginRetrieveDataCollection.executeSynchronous() ispybDataCollection = self.edPluginRetrieveDataCollection.dataOutput.dataCollection directory = ispybDataCollection.imageDirectory if EDUtilsPath.isEMBL(): template = ispybDataCollection.fileTemplate.replace("%05d", "#" * 5) elif EDUtilsPath.isMAXIV(): template = ispybDataCollection.fileTemplate else: template = ispybDataCollection.fileTemplate.replace("%04d", "####") if self.dataInput.fromN is None: imageNoStart = ispybDataCollection.startImageNumber else: imageNoStart = self.dataInput.fromN.value if self.dataInput.toN is None: imageNoEnd = imageNoStart + ispybDataCollection.numberOfImages - 1 else: imageNoEnd = self.dataInput.toN.value # # DEBUG we set the end image to 20 in order to speed up things # self.warning("End image set to 20 (was {0})".format(imageNoEnd)) # imageNoEnd = 20 pathToStartImage = os.path.join(directory, ispybDataCollection.fileTemplate % imageNoStart) pathToEndImage = os.path.join(directory, ispybDataCollection.fileTemplate % imageNoEnd) else: identifier = str(int(time.time())) directory = self.dataInput.dirN.path.value template = self.dataInput.templateN.value imageNoStart = self.dataInput.fromN.value imageNoEnd = self.dataInput.toN.value if EDUtilsPath.isEMBL(): fileTemplate = template.replace("#####", "%05d") else: fileTemplate = template.replace("####", "%04d") pathToStartImage = os.path.join(directory, fileTemplate % imageNoStart) pathToEndImage = os.path.join(directory, fileTemplate % imageNoEnd) # Try to get proposal from path if EDUtilsPath.isESRF(): listDirectory = directory.split(os.sep) try: if listDirectory[1] == "data": if listDirectory[2] == "visitor": beamline = listDirectory[4] proposal = listDirectory[3] else: beamline = listDirectory[2] proposal = listDirectory[4] except: beamline = "unknown" proposal = userName if imageNoEnd - imageNoStart < 8: error_message = "There are fewer than 8 images, aborting" self.addErrorMessage(error_message) self.ERROR(error_message) self.setFailure() return # Process directory if self.dataInput.processDirectory is not None: processDirectory = self.dataInput.processDirectory.path.value else: processDirectory = directory.replace("RAW_DATA", "PROCESSED_DATA") # Make results directory if EDUtilsPath.isALBA(): _processDirectory = "_".join(pathToStartImage.split('_')[:-1]) from datetime import datetime _id = datetime.now().strftime('%Y%m%d_%H%M%S') self.resultsDirectory = os.path.join(_processDirectory, "autoPROC_%s" % _id) else: self.resultsDirectory = os.path.join(processDirectory, "results") if not os.path.exists(self.resultsDirectory): os.makedirs(self.resultsDirectory, 0o755) # Create path to pyarch if self.dataInput.reprocess is not None and self.dataInput.reprocess.value: self.pyarchDirectory = EDHandlerESRFPyarchv1_0.createPyarchReprocessDirectoryPath(beamline, "autoPROC", self.dataInput.dataCollectionId.value) else: self.pyarchDirectory = EDHandlerESRFPyarchv1_0.createPyarchFilePath(self.resultsDirectory) if self.pyarchDirectory is not None: self.pyarchDirectory = self.pyarchDirectory.replace('PROCESSED_DATA', 'RAW_DATA') if not os.path.exists(self.pyarchDirectory): try: os.makedirs(self.pyarchDirectory, 0o755) except: self.pyarchDirectory = None # The resultsDirectory is not used at ALBA (only pyarchDirectory) if EDUtilsPath.isALBA(): self.resultsDirectory = None # Determine pyarch prefix if EDUtilsPath.isALBA(): listPrefix = template.split("_") self.pyarchPrefix = "ap_{0}_{1}".format("_".join(listPrefix[:-2]), listPrefix[-2]) else: listPrefix = template.split("_") self.pyarchPrefix = "ap_{0}_run{1}".format(listPrefix[-3], listPrefix[-2]) isH5 = False if any(beamline in pathToStartImage for beamline in ["id30b"]): minSizeFirst = 6000000 minSizeLast = 6000000 elif any(beamline in pathToStartImage for beamline in ["id23eh2", "id30a1"]): minSizeFirst = 2000000 minSizeLast = 2000000 elif any(beamline in pathToStartImage for beamline in ["id23eh1", "id30a3"]): minSizeFirst = 100000 minSizeLast = 100000 pathToStartImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoStart)) pathToEndImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoEnd)) isH5 = True else: minSizeFirst = 1000000 minSizeLast = 1000000 if EDUtilsPath.isMAXIV(): minSizeFirst = 100000 minSizeLast = 100000 pathToStartImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoStart)) pathToEndImage = os.path.join(directory, self.eiger_template_to_image(template, imageNoEnd)) isH5 = True if EDUtilsPath.isEMBL() or EDUtilsPath.isMAXIV(): fWaitFileTimeout = 60 # s else: fWaitFileTimeout = 3600 # s xsDataInputMXWaitFileFirst = XSDataInputMXWaitFile() xsDataInputMXWaitFileFirst.file = XSDataFile(XSDataString(pathToStartImage)) xsDataInputMXWaitFileFirst.timeOut = XSDataTime(fWaitFileTimeout) self.edPluginWaitFileFirst.size = XSDataInteger(minSizeFirst) self.edPluginWaitFileFirst.dataInput = xsDataInputMXWaitFileFirst self.edPluginWaitFileFirst.executeSynchronous() if self.edPluginWaitFileFirst.dataOutput.timedOut.value: strWarningMessage = "Timeout after %d seconds waiting for the first image %s!" % (fWaitFileTimeout, pathToStartImage) self.addWarningMessage(strWarningMessage) self.WARNING(strWarningMessage) xsDataInputMXWaitFileLast = XSDataInputMXWaitFile() xsDataInputMXWaitFileLast.file = XSDataFile(XSDataString(pathToEndImage)) xsDataInputMXWaitFileLast.timeOut = XSDataTime(fWaitFileTimeout) self.edPluginWaitFileLast.size = XSDataInteger(minSizeLast) self.edPluginWaitFileLast.dataInput = xsDataInputMXWaitFileLast self.edPluginWaitFileLast.executeSynchronous() if self.edPluginWaitFileLast.dataOutput.timedOut.value: strErrorMessage = "Timeout after %d seconds waiting for the last image %s!" % (fWaitFileTimeout, pathToEndImage) self.addErrorMessage(strErrorMessage) self.ERROR(strErrorMessage) self.setFailure() self.timeStart = time.localtime() if self.dataInput.dataCollectionId is not None: # Set ISPyB to running if self.doAnom: self.autoProcIntegrationIdAnom, self.autoProcProgramIdAnom = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgram, isAnom=True, timeStart=self.timeStart) self.autoProcIntegrationIdAnomStaraniso, self.autoProcProgramIdAnomStaraniso = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgramStaraniso, isAnom=True, timeStart=self.timeStart) if self.doNoanom: self.autoProcIntegrationIdNoanom, self.autoProcProgramIdNoanom = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgram, isAnom=False, timeStart=self.timeStart) self.autoProcIntegrationIdNoanomStaraniso, self.autoProcProgramIdNoanomStaraniso = \ EDHandlerXSDataISPyBv1_4.setIspybToRunning(self, dataCollectionId=self.dataInput.dataCollectionId.value, processingCommandLine=self.processingCommandLine, processingPrograms=self.processingProgramStaraniso, isAnom=False, timeStart=self.timeStart) # Prepare input to execution plugin if self.doAnom: xsDataInputAutoPROCAnom = XSDataInputAutoPROC() xsDataInputAutoPROCAnom.anomalous = XSDataBoolean(True) xsDataInputAutoPROCAnom.symm = self.dataInput.symm xsDataInputAutoPROCAnom.cell = self.dataInput.cell xsDataInputAutoPROCAnom.lowResolutionLimit = self.dataInput.lowResolutionLimit xsDataInputAutoPROCAnom.highResolutionLimit = self.dataInput.highResolutionLimit if self.doNoanom: xsDataInputAutoPROCNoanom = XSDataInputAutoPROC() xsDataInputAutoPROCNoanom.anomalous = XSDataBoolean(False) xsDataInputAutoPROCNoanom.symm = self.dataInput.symm xsDataInputAutoPROCNoanom.cell = self.dataInput.cell xsDataInputAutoPROCNoanom.lowResolutionLimit = self.dataInput.lowResolutionLimit xsDataInputAutoPROCNoanom.highResolutionLimit = self.dataInput.highResolutionLimit xsDataAutoPROCIdentifier = XSDataAutoPROCIdentifier() xsDataAutoPROCIdentifier.idN = XSDataString(identifier) xsDataAutoPROCIdentifier.dirN = XSDataFile(XSDataString(directory)) xsDataAutoPROCIdentifier.templateN = XSDataString(template) xsDataAutoPROCIdentifier.fromN = XSDataInteger(imageNoStart) xsDataAutoPROCIdentifier.toN = XSDataInteger(imageNoEnd) if self.doAnom: xsDataInputAutoPROCAnom.addIdentifier(xsDataAutoPROCIdentifier) if self.doNoanom: xsDataInputAutoPROCNoanom.addIdentifier(xsDataAutoPROCIdentifier.copy()) if isH5: masterFilePath = os.path.join(directory, self.eiger_template_to_master(template)) if self.doAnom: xsDataInputAutoPROCAnom.masterH5 = XSDataFile(XSDataString(masterFilePath)) if self.doNoanom: xsDataInputAutoPROCNoanom.masterH5 = XSDataFile(XSDataString(masterFilePath)) timeStart = time.localtime() if self.doAnom: self.edPluginExecAutoPROCAnom.dataInput = xsDataInputAutoPROCAnom self.edPluginExecAutoPROCAnom.execute() if self.doNoanom: self.edPluginExecAutoPROCNoanom.dataInput = xsDataInputAutoPROCNoanom self.edPluginExecAutoPROCNoanom.execute() if self.doAnom: self.edPluginExecAutoPROCAnom.synchronize() if self.doNoanom: self.edPluginExecAutoPROCNoanom.synchronize() timeEnd = time.localtime() # Upload to ISPyB if self.doAnom: self.uploadToISPyB(self.edPluginExecAutoPROCAnom, True, False, proposal, timeStart, timeEnd) self.uploadToISPyB(self.edPluginExecAutoPROCAnom, True, True, proposal, timeStart, timeEnd) if self.doNoanom: self.uploadToISPyB(self.edPluginExecAutoPROCNoanom, False, False, proposal, timeStart, timeEnd) self.uploadToISPyB(self.edPluginExecAutoPROCNoanom, False, True, proposal, timeStart, timeEnd)
def generateCommandLine(self, _xsDataInputAutoPROC): """ This method creates the input command line for autoPROC """ self.DEBUG("EDPluginExecAutoPROCv1_0.generateCommands") strCommandText = "-B -xml -nthreads {0} -M ReportingInlined autoPROC_HIGHLIGHT=\"no\"".format(self.maxNoProcessors) if self.doScaleWithXscale: strCommandText += " autoPROC_ScaleWithXscale='yes'" if self.rotationAxis is not None: strCommandText += " autoPROC_XdsKeyword_ROTATION_AXIS=\"{0}\"".format(self.rotationAxis) # Master H5 file masterH5 = _xsDataInputAutoPROC.masterH5 if masterH5 is None: # Identifier(s) for identifier in _xsDataInputAutoPROC.identifier: if EDUtilsPath.isEMBL() or EDUtilsPath.isALBA(): identifier.templateN.value = identifier.templateN.value.replace(\ '%' + '05' + 'd', 5 * '#') strCommandText += " -Id {idN},{dirN},{templateN},{fromN},{toN}".format( idN=identifier.idN.value, dirN=identifier.dirN.path.value, templateN=identifier.templateN.value, fromN=identifier.fromN.value, toN=identifier.toN.value) else: strCommandText += " -h5 {0}".format(masterH5.path.value) if self.pathToNeggiaPlugin is not None: strCommandText += " autoPROC_XdsKeyword_LIB={0}".format(self.pathToNeggiaPlugin) # Resolution lowResolutionLimit = _xsDataInputAutoPROC.lowResolutionLimit highResolutionLimit = _xsDataInputAutoPROC.highResolutionLimit if lowResolutionLimit is not None or highResolutionLimit is not None: # See https://www.globalphasing.com/autoproc/manual/autoPROC4.html#processcli if lowResolutionLimit is None: low = 1000.0 # autoPROC default value else: low = lowResolutionLimit.value if highResolutionLimit is None: high = 0.1 # autoPROC default value else: high = highResolutionLimit.value strCommandText += " -R {0} {1}".format(low, high) # Anomalous anomalous = _xsDataInputAutoPROC.anomalous if anomalous is not None: if anomalous.value: strCommandText += " -ANO" # Reference MTZ file refMTZ = _xsDataInputAutoPROC.refMTZ if refMTZ is not None: strCommandText += " -ref {0}".format(refMTZ.path.value) # Forced space group if _xsDataInputAutoPROC.symm is not None: strCommandText += " symm=\"{0}\"".format(_xsDataInputAutoPROC.symm.value) # Forced cell if _xsDataInputAutoPROC.cell is not None: strCommandText += " cell=\"{0}\"".format(_xsDataInputAutoPROC.cell.value) return strCommandText
def generateCommands(self, _xsDataInputH5ToCBF): """ This method creates a list of commands for the converter """ self.DEBUG("EDPluginH5ToCBFv1_1.generateCommands") hdf5File = _xsDataInputH5ToCBF.hdf5File.path.value directory = os.path.dirname(hdf5File) prefix = EDUtilsImage.getPrefix(hdf5File) if _xsDataInputH5ToCBF.imageNumber is not None: imageNumber = _xsDataInputH5ToCBF.imageNumber.value if _xsDataInputH5ToCBF.hdf5ImageNumber is None: hdf5ImageNumber = imageNumber else: hdf5ImageNumber = _xsDataInputH5ToCBF.hdf5ImageNumber.value if "master" in hdf5File: masterFile = hdf5File else: if EDUtilsPath.isEMBL() or EDUtilsPath.isALBA(): masterFile = os.path.join( directory, prefix + "_master.h5".format(hdf5ImageNumber)) else: masterFile = os.path.join( directory, prefix + "_{0}_master.h5".format(hdf5ImageNumber)) if _xsDataInputH5ToCBF.forcedOutputImageNumber is not None: CBFFileName = prefix + "_%04d" % _xsDataInputH5ToCBF.forcedOutputImageNumber.value + ".cbf" imageNumberInHdf5File = imageNumber else: CBFFileName = prefix + "_%04d" % imageNumber + ".cbf" imageNumberInHdf5File = imageNumber - hdf5ImageNumber + 1 tmpCBFFileName = "tmp_" + CBFFileName if _xsDataInputH5ToCBF.forcedOutputDirectory is None: self.CBFFile = os.path.join(directory, CBFFileName) else: forcedOutputDirectory = self.dataInput.forcedOutputDirectory.path.value if not os.path.exists(forcedOutputDirectory): os.makedirs(forcedOutputDirectory, 0o755) self.CBFFile = os.path.join(forcedOutputDirectory, CBFFileName) scriptCommandLine = "{0} {1} {2}".format(masterFile, imageNumberInHdf5File, self.CBFFile) elif _xsDataInputH5ToCBF.startImageNumber is not None and _xsDataInputH5ToCBF.endImageNumber is not None: startImageNumber = _xsDataInputH5ToCBF.startImageNumber.value endImageNumber = _xsDataInputH5ToCBF.endImageNumber.value if _xsDataInputH5ToCBF.hdf5ImageNumber is None: hdf5ImageNumber = startImageNumber else: hdf5ImageNumber = _xsDataInputH5ToCBF.hdf5ImageNumber.value if "master" in hdf5File: masterFile = hdf5File else: masterFile = os.path.join( directory, prefix + "_{0}_master.h5".format(hdf5ImageNumber)) CBFFileNamePrefix = prefix + "_" if _xsDataInputH5ToCBF.forcedOutputDirectory is None: CBFFilePath = os.path.join(directory, CBFFileNamePrefix) else: forcedOutputDirectory = self.dataInput.forcedOutputDirectory.path.value if not os.path.exists(forcedOutputDirectory): os.makedirs(forcedOutputDirectory, 0o755) CBFFilePath = os.path.join(forcedOutputDirectory, CBFFileNamePrefix) scriptCommandLine = "{0} {1}:{2} {3}".format( masterFile, startImageNumber, endImageNumber, CBFFilePath) self.CBFFileTemplate = CBFFilePath + "######.cbf" return scriptCommandLine
def createPyarchFilePath(_strESRFPath): """ This method translates from an ESRF "visitor" path to a "pyarch" path: /data/visitor/mx415/id14eh1/20100209 -> /data/pyarch/2010/id14eh1/mx415/20100209 """ strPyarchDNAFilePath = None listOfDirectories = _strESRFPath.split(os.sep) if EDUtilsPath.isALBA(): return EDHandlerESRFPyarchv1_0.translateToIspybALBAPath( _strESRFPath) if EDUtilsPath.isEMBL(): if 'p13' in listOfDirectories[0:3] or 'P13' in listOfDirectories[ 0:3]: strPyarchDNAFilePath = os.path.join('/data/ispyb/p13', *listOfDirectories[4:]) else: strPyarchDNAFilePath = os.path.join('/data/ispyb/p14', *listOfDirectories[4:]) return strPyarchDNAFilePath if EDUtilsPath.isMAXIV(): strPyarchDNAFilePath = _strESRFPath.replace( "/data", "/mxn/groups/ispybstorage", 1) return strPyarchDNAFilePath listBeamlines = [ "bm07", "id14eh1", "id14eh2", "id14eh3", "id14eh4", "id23eh1", "id23eh2", "id29", "id30a1", "id30a2", "id30a3", "id30b", "simulator_mxcube" ] # Check that we have at least four levels of directories: if (len(listOfDirectories) > 5): strDataDirectory = listOfDirectories[1] strSecondDirectory = listOfDirectories[2] strThirdDirectory = listOfDirectories[3] strFourthDirectory = listOfDirectories[4] strFifthDirectory = listOfDirectories[5] year = strFifthDirectory[0:4] strProposal = None strBeamline = None if (strDataDirectory == "data") and (strSecondDirectory == "gz"): if strThirdDirectory == "visitor": strProposal = strFourthDirectory strBeamline = strFifthDirectory elif strFourthDirectory == "inhouse": strProposal = strFifthDirectory strBeamline = strThirdDirectory else: raise RuntimeError( "Illegal path for EDHandlerESRFPyarchv1_0.createPyarchFilePath: {0}" .format(_strESRFPath)) listOfRemainingDirectories = listOfDirectories[6:] elif (strDataDirectory == "data") and (strSecondDirectory == "visitor"): strProposal = listOfDirectories[3] strBeamline = listOfDirectories[4] listOfRemainingDirectories = listOfDirectories[5:] elif ((strDataDirectory == "data") and (strSecondDirectory in listBeamlines)): strBeamline = strSecondDirectory strProposal = listOfDirectories[4] listOfRemainingDirectories = listOfDirectories[5:] if (strProposal != None) and (strBeamline != None): strPyarchDNAFilePath = os.path.join(os.sep, "data") strPyarchDNAFilePath = os.path.join(strPyarchDNAFilePath, "pyarch") strPyarchDNAFilePath = os.path.join(strPyarchDNAFilePath, year) strPyarchDNAFilePath = os.path.join(strPyarchDNAFilePath, strBeamline) strPyarchDNAFilePath = os.path.join(strPyarchDNAFilePath, strProposal) for strDirectory in listOfRemainingDirectories: strPyarchDNAFilePath = os.path.join( strPyarchDNAFilePath, strDirectory) if (strPyarchDNAFilePath is None): EDVerbose.WARNING( "EDHandlerESRFPyarchv1_0.createPyArchFilePath: path not converted for pyarch: %s " % _strESRFPath) return strPyarchDNAFilePath