def testSetDataOutput(self): """ Test the setDataOutput method with different arguments """ # Test 1: default output edPlugin = EDPlugin() xsDataStringTest = XSDataString("Test") edPlugin.setDataOutput(xsDataStringTest) EDAssert.equal(xsDataStringTest.marshal(), edPlugin.getDataOutput().marshal(), "Test 1: default output") # Test 2: named output edPlugin = EDPlugin() xsDataStringTest = XSDataString("Test") edPlugin.setDataOutput(xsDataStringTest, "testData") EDAssert.equal(xsDataStringTest.marshal(), edPlugin.getDataOutput("testData")[0].marshal(), "Test 2: named output") # Test 3: several inputs with the same name edPlugin = EDPlugin() xsDataStringTest1 = XSDataString("Test1") xsDataStringTest2 = XSDataString("Test2") edPlugin.setDataOutput(xsDataStringTest1, "testData") edPlugin.setDataOutput(xsDataStringTest2, "testData") pyListDataOutput = edPlugin.getDataOutput("testData") EDAssert.equal(xsDataStringTest1.marshal(), pyListDataOutput[0].marshal(), "Test 3: several inputs with the same name, 1") EDAssert.equal(xsDataStringTest2.marshal(), pyListDataOutput[1].marshal(), "Test 3: several inputs with the same name, 2") # Test 6: test of delDataOutput edPlugin = EDPlugin() xsDataStringTest = XSDataString("Test") edPlugin.setDataOutput(xsDataStringTest.marshal()) edPlugin.delDataOutput() EDAssert.equal(None, edPlugin.getDataOutput(), "Test 6: test of delDataOutput")
def characteriseWithXmlInput(self, data_collection_id, sampleCharacteriseIndex, beamsize): if data_collection_id is not None: self.ednaInput.setDataCollectionId(XSDataInteger(data_collection_id)) else: self.ednaInput.setDataCollectionId(None) logging.getLogger().warning("The data collection ID is not known for this characterisation. Therefore the EDNA results cannot be put into the database") # build data set imageSuffix = self.beamlinePars["BCM_PARS"].getProperty("FileSuffix") dataSetObj = XSDataMXCuBEDataSet() self.ednaInput.setDataSet([]) methodDCNo = len(self.current_method[1]) for methodIndex in range(methodDCNo): number_of_images = self.current_method[1][methodIndex]['number_of_images'] imageNameIdx = self.current_method[0] listIndex = sampleCharacteriseIndex * methodDCNo + methodIndex for imageno in range(int(number_of_images)): imageFileObj = XSDataFile() pathStrObj = XSDataString() pathStrObj.setValue(('%s/%s_%d_%04d.%s' % (self.collectSeqList[listIndex]['fileinfo']['directory'],\ self.collectSeqList[listIndex]['fileinfo']['prefix'],\ int(self.collectSeqList[listIndex]['fileinfo']['run_number']),\ imageno+1,imageSuffix))) imageFileObj.setPath(pathStrObj) dataSetObj.addImageFile(imageFileObj) self.ednaInput.addDataSet(dataSetObj) if TEST: self.ednaInput.getDataSet()[0].getImageFile()[0].getPath().setValue("/opt/pxsoft/DNA/TestCase/ref-testscale_1_001.img") self.ednaInput.getDataSet()[0].getImageFile()[1].getPath().setValue("/opt/pxsoft/DNA/TestCase/ref-testscale_1_002.img") path = self.process_dir suffix = '_%s.xml' % (self.ednaInput.getDataCollectionId().getValue() or id(self.ednaInput)) ednaResultsFile = os.path.join(path, 'EDNAOutput%s' % suffix) ednaInputXMLFile = os.path.join(path, 'EDNAInput%s' % suffix) if not os.path.isdir(path): os.makedirs(path) beamObj = self.ednaInput.getExperimentalCondition().getBeam() beamObj.setSize(XSDataSize(x=XSDataLength(float(beamsize[0])),y=XSDataLength(float(beamsize[1])))) """ create an edna input file using the ednainput model """ ednaInputXML = self.ednaInput.exportToFile(ednaInputXMLFile) logging.getLogger().info("Starting Edna using xml file, %s" % ednaInputXMLFile) # use an intermediate script to run edna with its command line options edna_args = "%s %s %s" % (ednaInputXMLFile,ednaResultsFile,path) edna_cmd=self.StartEdnaCommand+" "+edna_args if self.ednaPollTimer is None: self.ednaPollTimer = qt.QTimer() qt.QObject.connect(self.ednaPollTimer,qt.SIGNAL("timeout()"), self.pollEDNA) logging.getLogger().debug(edna_cmd) EDNA_PROCESSES.append(EnhancedPopen.Popen(edna_cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True,universal_newlines=True)) self.EDNAResultsFiles[id(EDNA_PROCESSES[-1])]=ednaResultsFile # save image prefix,etc. for next step # only take first image, since we just want to have image prefix, run number, etc. : # it is the same within the whole collectSeqList (hopefully) imagePrefix = self.collectSeqList[0]['fileinfo']['prefix'][4:] #remove ref- self.imagePathProperties[id(EDNA_PROCESSES[-1])]={"imagePrefix":imagePrefix, "imageDir": self.collectSeqList[0]['fileinfo']['directory'], "lRunN": int(self.collectSeqList[0]['fileinfo']['run_number'])} self.ednaPollTimer.start(100)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'xds_hkl': obj_ = XSDataString() obj_.build(child_) self.setXds_hkl(obj_) XSDataResult.buildChildren(self, child_, nodeName_)
def writeFullPath(self, xsDataFile): """ Add path to the data file directory """ dataInputPath = XSDataString() dataInputName = xsDataFile.getPath().getValue() dataInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), dataInputName)) xsDataFile.setPath(dataInputPath)
def testExecute(self): """ """ dataInputPath = XSDataString() # Add path to the input data file dataInputName = self.getPlugin().getDataInput().getGnomOutputFile().getPath().getValue() dataInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), dataInputName)) self.getPlugin().getDataInput().getGnomOutputFile().setPath(dataInputPath) self.run()
def testExecute(self): """ """ inputPdbPath = XSDataString() # Add path to the input data file inputPdbName = self.getPlugin().getDataInput().getInputPdbFile().getPath().getValue() inputPdbPath.setValue(os.path.join(self.getPluginTestsDataHome(), inputPdbName)) self.getPlugin().getDataInput().getInputPdbFile().setPath(inputPdbPath) self.run()
def testWriteDataInput(self): # Test 1: default input with XML edPlugin = EDPlugin() edPlugin.configure() edPlugin.setXSDataInputClass(XSDataString) xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal()) edPlugin.writeDataInput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_dataInput.xml")), "Test 1: default input with XML") # Test 2: named input with XML edPlugin = EDPlugin() edPlugin.configure() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal(), "testData") edPlugin.writeDataInput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_0_dataInput.xml")), "Test 2: named input with XML") # Test 3: several inputs with the same name, XML input edPlugin = EDPlugin() edPlugin.configure() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest1 = XSDataString("Test1") xsDataStringTest2 = XSDataString("Test2") edPlugin.setDataInput(xsDataStringTest1.marshal(), "testData") edPlugin.setDataInput(xsDataStringTest2.marshal(), "testData") edPlugin.writeDataInput() EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_0_dataInput.xml")), "Test 3: several inputs with the same name, XML input, 1") EDAssert.equal(True, os.path.exists(os.path.join(edPlugin.getWorkingDirectory(), "_testData_1_dataInput.xml")), "Test 3: several inputs with the same name, XML input, 2")
def postProcess(self, _edObject=None): EDPluginExecProcessScript.postProcess(self) EDVerbose.DEBUG("EDPluginExecDammifv0_1.postProcess") # Create some output data pathLogFile = XSDataString(os.path.join(self.getWorkingDirectory(), "dammif.log")) pathFitFile = XSDataString(os.path.join(self.getWorkingDirectory(), "dammif.fit")) pathMoleculeFile = XSDataString(os.path.join(self.getWorkingDirectory(), "dammif-1.pdb")) pathSolventFile = XSDataString(os.path.join(self.getWorkingDirectory(), "dammif-0.pdb")) xsLogFile = XSDataFile(pathLogFile) xsFitFile = XSDataFile(pathFitFile) xsMoleculeFile = XSDataFile(pathMoleculeFile) xsSolventFile = XSDataFile(pathSolventFile) xsDataResult = XSDataResultDammif() if os.path.exists(pathLogFile.getValue()): xsDataResult.setLogFile(xsLogFile) if os.path.exists(pathFitFile.getValue()): xsDataResult.setFitFile(xsFitFile) if os.path.exists(pathMoleculeFile.getValue()): xsDataResult.setPdbMoleculeFile(xsMoleculeFile) if os.path.exists(pathSolventFile.getValue()): xsDataResult.setPdbSolventFile(xsSolventFile) xsDataResult.setChiSqrt(self.returnDammifChiSqrt()) xsDataResult.setRfactor(self.returnDammifRFactor()) self.setDataOutput(xsDataResult)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and nodeName_ == "options": obj_ = XSDataString() obj_.build(child_) self.setOptions(obj_) elif child_.nodeType == Node.ELEMENT_NODE and nodeName_ == "source": obj_ = XSDataFile() obj_.build(child_) self.setSource(obj_) elif child_.nodeType == Node.ELEMENT_NODE and nodeName_ == "destination": obj_ = XSDataFile() obj_.build(child_) self.setDestination(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'job': obj_ = XSDataString() obj_.build(child_) self.job.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'subWedge': obj_ = XSDataXDSSubWedge() obj_.build(child_) self.setSubWedge(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'detector': obj_ = XSDataXDSDetector() obj_.build(child_) self.setDetector(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def prepare_edna_input(self, edna_input): # used for strategy calculation (characterization) using data analysis cluster # ALBA specific firstImage = None for dataSet in edna_input.getDataSet(): for imageFile in dataSet.imageFile: if imageFile.getPath() is None: continue firstImage = imageFile.path.value break listImageName = os.path.basename(firstImage).split("_") prefix = "_".join(listImageName[:-2]) run_number = listImageName[-2] i = 1 if hasattr(edna_input, "process_directory"): edna_directory = os.path.join( edna_input.process_directory, "characterisation_%s_run%s_%d" % (prefix, run_number, i), ) while os.path.exists(edna_directory): i += 1 edna_directory = os.path.join( edna_input.process_directory, "characterisation_%s_run%s_%d" % (prefix, run_number, i), ) os.makedirs(edna_directory) else: raise RuntimeError("No process directory specified in edna_input") edna_input.process_directory = edna_directory output_dir = XSDataFile() path = XSDataString() path.setValue(edna_directory) output_dir.setPath(path) edna_input.setOutputFileDirectory(output_dir)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'geomFile': obj_ = XSDataString() obj_.build(child_) self.setGeomFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'cellFile': obj_ = XSDataString() obj_.build(child_) self.setCellFile(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'imagesFullPathFile': obj_ = XSDataString() obj_.build(child_) self.setImagesFullPathFile(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def postProcess(self, _edObject=None): """ Postprocess of the plugin: * set output of the plugin * free some memory from large arrays """ EDPluginExec.postProcess(self) EDVerbose.DEBUG("EDPluginExecThumbnailv10.postProcess") # Create some output data xsDataResult = XSDataResultExecThumbnail() if os.path.isfile(self.output): xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(self.output)) xsDataResult.setThumbnailPath(xsDataFile) xsDataString = XSDataString() xsDataString.setValue(self.format) xsDataResult.setThumbnailType(xsDataString) self.setDataOutput(xsDataResult) self.npaImage = None
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'item': obj_ = XSDataString() obj_.build(child_) self.item.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'removeItems': obj_ = XSDataBoolean() obj_.build(child_) self.setRemoveItems(obj_) XSData.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'elementName': obj_ = XSDataString() obj_.build(child_) self.setElementName(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'inputFile': obj_ = XSDataFile() obj_.build(child_) self.setInputFile(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def outputDamaverPdbFiles(self): pathDamaverFile = XSDataString(os.path.join(self.getWorkingDirectory(), "damaver.pdb")) xsDamaverFile = XSDataFile(pathDamaverFile) if os.path.exists(pathDamaverFile.getValue()): self.__xsDataResult.setDamaverPdbFile(xsDamaverFile) if self.__bAutomatic: pathDamfilterFile = XSDataString(os.path.join(self.getWorkingDirectory(), "damfilt.pdb")) pathDamstartFile = XSDataString(os.path.join(self.getWorkingDirectory(), "damstart.pdb")) xsDamfilterFile = XSDataFile(pathDamfilterFile) xsDamstartFile = XSDataFile(pathDamstartFile) if os.path.exists(pathDamfilterFile.getValue()): self.__xsDataResult.setDamfilterPdbFile(xsDamfilterFile) if os.path.exists(pathDamstartFile.getValue()): self.__xsDataResult.setDamstartPdbFile(xsDamstartFile)
def testExecute(self): """ """ templateInputPath = XSDataString() supimposeInputPath = XSDataString() # Add path to the input data file templateInputName = self.getPlugin().getDataInput().getTemplateFile().getPath().getValue() templateInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), templateInputName)) self.getPlugin().getDataInput().getTemplateFile().setPath(templateInputPath) supimposeInputName = self.getPlugin().getDataInput().getSuperimposeFile().getPath().getValue() supimposeInputPath.setValue(os.path.join(self.getPluginTestsDataHome(), supimposeInputName)) self.getPlugin().getDataInput().getSuperimposeFile().setPath(supimposeInputPath) self.run()
def testDataInputOutputProperties(self): # Test dataInput property with XSDataObject edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString) edPlugin.configure() xsDataStringTest = XSDataString("Test1") edPlugin.dataInput = xsDataStringTest EDAssert.equal(xsDataStringTest.marshal(), edPlugin.dataInput.marshal(), "Test dataInput property with XSDataObject") # Test dataInput property with XML edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString) edPlugin.configure() xsDataStringTest = XSDataString("Test1") edPlugin.dataInput = xsDataStringTest.marshal() EDAssert.equal(xsDataStringTest.marshal(), edPlugin.dataInput.marshal(), "Test dataInput property with XML") # Test dataOutput property with XSDataObject edPlugin = EDPlugin() edPlugin.configure() xsDataStringTest = XSDataString("Test1") edPlugin.dataOutput = xsDataStringTest EDAssert.equal(xsDataStringTest.marshal(), edPlugin.dataOutput.marshal(), "Test dataOutput property with XSDataObject")
def getXSDataMOSFLMDetector(_xsDataDetector): """ Translates an XSDataDetector object to XSDataMOSFLMv10. """ EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10") from XSDataMOSFLMv10 import XSDataMOSFLMDetector xsDataMOSFLMDetector = XSDataMOSFLMDetector() strDetectorType = _xsDataDetector.getType().getValue() if (strDetectorType == "q4") or \ (strDetectorType == "q4-2x") or \ (strDetectorType == "q210") or \ (strDetectorType == "q210-2x") or \ (strDetectorType == "q315") or \ (strDetectorType == "q315-2x"): xsDataMOSFLMDetector.setType(XSDataString("ADSC")) elif (strDetectorType == "mar165") or \ (strDetectorType == "mar225"): xsDataMOSFLMDetector.setType(XSDataString("MARCCD")) elif (strDetectorType == "pilatus6m" or strDetectorType == "pilatus2m"): xsDataMOSFLMDetector.setType(XSDataString("PILATUS")) elif strDetectorType.startswith("eiger2"): xsDataMOSFLMDetector.setType(XSDataString("EIGER2")) elif strDetectorType.startswith("eiger"): xsDataMOSFLMDetector.setType(XSDataString("EIGER")) elif (strDetectorType == "raxis4"): xsDataMOSFLMDetector.setType(XSDataString("RAXISIV")) else: # This is a temporary solution for the exception problem pointed out in bug #43. # Instead of raising an exception with a known type we send the error message as a string. strErrorMessage = "EDHandlerXSDataMOSFLMv10.getXSDataMOSFLMDetector: Unknown detector type : " + strDetectorType raise BaseException(strErrorMessage) if (_xsDataDetector.getNumberPixelX() is not None): xsDataMOSFLMDetector.setNumberPixelX( _xsDataDetector.getNumberPixelX()) if (_xsDataDetector.getNumberPixelY() is not None): xsDataMOSFLMDetector.setNumberPixelY( _xsDataDetector.getNumberPixelY()) if (_xsDataDetector.getPixelSizeX() is not None): xsDataMOSFLMDetector.setPixelSizeX(_xsDataDetector.getPixelSizeX()) if (_xsDataDetector.getPixelSizeY() is not None): xsDataMOSFLMDetector.setPixelSizeY(_xsDataDetector.getPixelSizeY()) return xsDataMOSFLMDetector
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
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsFlushHPLCv1_1.process") if self.runId in EDPluginBioSaxsHPLCv1_1.dictHPLC: self.processRun(EDPluginBioSaxsHPLCv1_1.dictHPLC[self.runId]) edpluginIsPyB = self.loadPlugin(self.strControlledPluginISPyB) edpluginIsPyB.dataInput=XSDataInputBioSaxsISPyB_HPLCv1_0(sample=self.dataInput.sample, hdf5File=self.xsDataResult.hplcFile, jsonFile=XSDataFile(XSDataString(self.json)), hplcPlot=self.xsDataResult.hplcImage) edpluginIsPyB.executeSynchronous()
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 from_params(self, data_collection, char_params): edna_input = XSDataInputMXCuBE.parseString(EDNA_DEFAULT_INPUT) if data_collection.id: edna_input.setDataCollectionId(XSDataInteger(data_collection.id)) #Beam object beam = edna_input.getExperimentalCondition().getBeam() try: beam.setTransmission(XSDataDouble(self.collect_obj.get_transmission())) except AttributeError: pass try: beam.setWavelength(XSDataWavelength(self.collect_obj.get_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() diff_plan.setAimedIOverSigmaAtHighestResolution(\ XSDataDouble(char_params.aimed_i_sigma)) diff_plan.setAimedCompleteness(XSDataDouble(char_params.\ aimed_completness)) if char_params.use_aimed_multiplicity: diff_plan.setAimedMultiplicity(XSDataDouble(char_params.\ aimed_multiplicity)) if char_params.use_aimed_resolution: diff_plan.setAimedResolution(XSDataDouble(char_params.aimed_resolution)) diff_plan.setComplexity(XSDataString(\ queue_model_enumerables.STRATEGY_COMPLEXITY[char_params.strategy_complexity])) if char_params.use_permitted_rotation: diff_plan.setUserDefinedRotationStart(XSDataAngle(char_params.\ permitted_phi_start)) diff_plan.setUserDefinedRotationRange(XSDataAngle(char_params.permitted_phi_end -\ char_params.permitted_phi_start)) #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: diff_plan.setMaxExposureTimePerDataCollection(XSDataTime(char_params.\ min_time)) # Account for radiation damage if char_params.induce_burn: diff_plan.setStrategyOption(XSDataString("-DamPar")) # What is -DamPar ? else: diff_plan.setStrategyOption(None) # Characterisation type - SAD if queue_model_enumerables.EXPERIMENT_TYPE[char_params.experiment_type] is \ queue_model_enumerables.EXPERIMENT_TYPE.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_str = os.path.join(data_collection.acquisitions[0].path_template.directory, data_collection.acquisitions[0].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 = data_collection.acquisitions[0].path_template.process_directory return edna_input
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'symmetry': obj_ = XSDataString() obj_.build(child_) self.setSymmetry(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'orientation': obj_ = XSDataXOalignOrientation() obj_.build(child_) self.setOrientation(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'cell': obj_ = XSDataXOalignCell() obj_.build(child_) self.setCell(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_) XSDataInput.buildChildren(self, child_, nodeName_)
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 process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlRunXdsv1_0.process") # First run is vanilla without any modification params = XSDataMinimalXdsIn() params.input_file = self.dataInput.input_file self.first_run.dataInput = params self.first_run.executeSynchronous() EDVerbose.DEBUG('first run completed...') if self.first_run.dataOutput is not None and self.first_run.dataOutput.succeeded.value: EDVerbose.DEBUG('... and it worked') self.successful_run = self.first_run else: EDVerbose.DEBUG('... and it failed') if not self.successful_run: # second run w/ JOB set to DEFPIX INTEGRATE CORRECT self.second_run = self.loadPlugin(self.controlled_plugin_name) params = XSDataMinimalXdsIn() params.input_file = self.dataInput.input_file params.jobs = 'DEFPIX INTEGRATE CORRECT' self.second_run.dataInput = params self.second_run.executeSynchronous() EDVerbose.DEBUG('second run completed') if self.second_run.dataOutput is not None and self.second_run.dataOutput.succeeded.value: EDVerbose.DEBUG('... and it worked') self.successful_run = self.second_run else: EDVerbose.DEBUG('... and it failed') if not self.successful_run: # third run with JOB set to ALL and mxaprocs = 4 and maxjobs = 1 self.third_run = self.loadPlugin(self.controlled_plugin_name) params = XSDataMinimalXdsIn() params.input_file = self.dataInput.input_file params.jobs = 'ALL' params.maxprocs = 4 params.maxjobs = 1 self.third_run.dataInput = params self.third_run.executeSynchronous() EDVerbose.DEBUG('third run completed') if self.third_run.dataOutput is not None and self.third_run.dataOutput.succeeded.value: EDVerbose.DEBUG('... and it worked') self.successful_run = self.third_run else: EDVerbose.DEBUG('... and it failed') if not self.successful_run: # final run with parallelism like 3 but JOB like 2 self.final_run = self.loadPlugin(self.controlled_plugin_name) params = XSDataMinimalXdsIn() params.input_file = self.dataInput.input_file params.jobs = 'DEFPIX INTEGRATE CORRECT' params.maxprocs = 4 params.maxjobs = 1 self.final_run.dataInput = params self.final_run.executeSynchronous() EDVerbose.DEBUG('final run completed') if self.final_run.dataOutput is not None and self.final_run.dataOutput.succeeded: EDVerbose.DEBUG('... and it worked') self.successful_run = self.final_run else: EDVerbose.DEBUG('... and it failed') if not self.successful_run: # all runs failed so bail out ... strErrorMessage = "All XDS run failed" self.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() else: # use the xds parser plugin to parse the xds output file... parser = self.loadPlugin("EDPluginParseXdsOutputv1_0") wd = self.successful_run.getWorkingDirectory() parser_input = XSDataXdsOutputFile() correct_lp_path = XSDataFile() correct_lp_path.path = XSDataString(os.path.join(wd, 'CORRECT.LP')) parser_input.correct_lp = correct_lp_path gxparm_path = os.path.join(wd, 'GXPARM.XDS') if os.path.isfile(gxparm_path): gxparm = XSDataFile() gxparm.path = XSDataString(os.path.join(wd, 'GXPARM.XDS')) parser_input.gxparm = gxparm parser.dataInput = parser_input parser.executeSynchronous() if parser.isFailure(): # that should not happen strErrorMessage = "Parser failure in control run XDS" self.ERROR(strErrorMessage) self.addErrorMessage(strErrorMessage) self.setFailure() return self.dataOutput = parser.dataOutput
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")
def createDataMOSFLMOutputIntegration(self): self.DEBUG("EDPluginMOSFLMIntegrationv10.createDataMOSFLMOutputIntegration") xsDataMOSFLMOutputIntegration = XSDataMOSFLMOutputIntegration() # Read bestfile.par, bestfile.hkl and bestfile.dat strBestfilePar = self.readBestFile("bestfile.par") bContinue = True if (strBestfilePar is not None): xsDataMOSFLMOutputIntegration.setBestfilePar(XSDataString(strBestfilePar)) else: bContinue = False if bContinue: strBestfileHKL = self.readBestFile("bestfile.hkl") if (strBestfileHKL is not None): xsDataMOSFLMOutputIntegration.setBestfileHKL(XSDataString(strBestfileHKL)) else: bContinue = False if bContinue: strBestfileDat = self.readBestFile("bestfile.dat") if (strBestfileDat is not None): xsDataMOSFLMOutputIntegration.setBestfileDat(XSDataString(strBestfileDat)) else: bContinue = False if bContinue: strDnaTablesXML = self.readProcessFile(self.getBaseName() + "_dnaTables.xml") xsDataDnaTables = dna_tables.parseString(strDnaTablesXML) xsTableIntegrationResults = EDUtilsTable.getTableFromTables(xsDataDnaTables, "integration_results") xsListFinalResiduals = EDUtilsTable.getListsFromTable(xsTableIntegrationResults, "final_residuals")[0] strRMSSpotDeviation = EDUtilsTable.getItemFromList(xsListFinalResiduals, "rms").getValueOf_() xsDataMOSFLMOutputIntegration.setRMSSpotDeviation(XSDataLength(float(strRMSSpotDeviation))) strBeamPositionX = EDUtilsTable.getItemFromList(xsListFinalResiduals, "xcen").getValueOf_() strBeamPositionY = EDUtilsTable.getItemFromList(xsListFinalResiduals, "ycen").getValueOf_() xsDataMOSFLMBeamPosition = XSDataMOSFLMBeamPosition() xsDataMOSFLMBeamPosition.setX(XSDataLength(float(strBeamPositionX))) xsDataMOSFLMBeamPosition.setY(XSDataLength(float(strBeamPositionY))) xsDataMOSFLMOutputIntegration.setRefinedBeam(xsDataMOSFLMBeamPosition) xsDataMOSFLMNewmatMatrix = self.getDataMOSFLMMatrix() xsDataMOSFLMOutputIntegration.setRefinedNewmat(xsDataMOSFLMNewmatMatrix) # New results (described in bug #63) xsTableIntegrationOutput = EDUtilsTable.getTableFromTables(xsDataDnaTables, "integration_output") xsListOutputFiles = EDUtilsTable.getListsFromTable(xsTableIntegrationOutput, "output_files")[0] strMTZFilename = EDUtilsTable.getItemFromList(xsListOutputFiles, "hklout").getValueOf_() strMTZPath = os.path.join(self.getWorkingDirectory(), strMTZFilename) xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(strMTZPath)) xsDataMOSFLMOutputIntegration.setGeneratedMTZFile(xsDataFile) xsTableSummaryInformation = EDUtilsTable.getTableFromTables(xsDataDnaTables, "summary_information") xsListSummary = EDUtilsTable.getListsFromTable(xsTableSummaryInformation, "summary")[0] xsListSpots = EDUtilsTable.getListsFromTable(xsTableSummaryInformation, "spots")[0] strDistance = EDUtilsTable.getItemFromList(xsListSummary, "distance").getValueOf_() xsDataMOSFLMOutputIntegration.setRefinedDistance(XSDataLength(float(strDistance))) strYScale = EDUtilsTable.getItemFromList(xsListSummary, "yscale").getValueOf_() xsDataMOSFLMOutputIntegration.setRefinedYScale(XSDataFloat(float(strYScale))) strOverallIOverSigma = EDUtilsTable.getItemFromList(xsListSummary, "isigall").getValueOf_() xsDataMOSFLMOutputIntegration.setOverallIOverSigma(XSDataFloat(float(strOverallIOverSigma))) strHighestResolutionIOverSigma = EDUtilsTable.getItemFromList(xsListSummary, "isigout").getValueOf_() xsDataMOSFLMOutputIntegration.setHighestResolutionIOverSigma(XSDataFloat(float(strHighestResolutionIOverSigma))) strNumberOfBadReflections = EDUtilsTable.getItemFromList(xsListSpots, "bad_spots").getValueOf_() xsDataMOSFLMOutputIntegration.setNumberOfBadReflections(XSDataInteger(int(strNumberOfBadReflections))) strNumberOfFullyRecordedReflections = EDUtilsTable.getItemFromList(xsListSpots, "full").getValueOf_() xsDataMOSFLMOutputIntegration.setNumberOfFullyRecordedReflections(XSDataInteger(int(strNumberOfFullyRecordedReflections))) strNumberOfNegativeReflections = EDUtilsTable.getItemFromList(xsListSpots, "negative").getValueOf_() xsDataMOSFLMOutputIntegration.setNumberOfNegativeReflections(XSDataInteger(int(strNumberOfNegativeReflections))) strNumberOfOverlappedReflections = EDUtilsTable.getItemFromList(xsListSpots, "overlap").getValueOf_() xsDataMOSFLMOutputIntegration.setNumberOfOverlappedReflections(XSDataInteger(int(strNumberOfOverlappedReflections))) strNumberOfPartialReflections = EDUtilsTable.getItemFromList(xsListSpots, "partial").getValueOf_() xsDataMOSFLMOutputIntegration.setNumberOfPartialReflections(XSDataInteger(int(strNumberOfPartialReflections))) # Fill in the statistics xsDataMOSFLMOutputIntegration.setOverallStatistics(self.getMOSFLMIntegrationStatisticsPerResolutionBin(xsDataDnaTables, "bin_0")) iIndex = 1 bContinue = True fMinResolution = None while (bContinue == True): strBin = "bin_%d" % iIndex # I don't know how many intensity bins there are. Since the EDUtilsTable.getListsFromTable # method crashes if the list is not present, I had to wrap the calls to this method in # try - except: try: xsDataMOSFLMIntegrationStatisticsPerResolutionBin = self.getMOSFLMIntegrationStatisticsPerResolutionBin(xsDataDnaTables, strBin, fMinResolution) fMinResolution = xsDataMOSFLMIntegrationStatisticsPerResolutionBin.getMaxResolution().getValue() xsDataMOSFLMOutputIntegration.addStatisticsPerResolutionBin(xsDataMOSFLMIntegrationStatisticsPerResolutionBin) iIndex += 1 except: bContinue = False # Path to log file xsDataMOSFLMOutputIntegration.setPathToLogFile(XSDataFile(XSDataString(os.path.join(self.getWorkingDirectory(), self.getScriptLogFileName())))) return xsDataMOSFLMOutputIntegration
strPathToTempDir = tempfile.mkdtemp( prefix="edna-image-quality-indicators_") os.chdir(strPathToTempDir) EDVerbose.setLogFileName(os.path.join(strPathToTempDir, "edna.log")) # Popolate input data EDVerbose.screen("Starting EDNA image quality indicators processing") EDVerbose.screen("Arguments: %r" % sys.argv) bVerbose = False bDebug = False listPaths = [] for iIndex, strArg in enumerate(sys.argv[1:]): strarg = strArg.lower() if strarg == "--verbose": EDVerbose.setVerboseOn() elif strarg == "--debug": EDVerbose.setVerboseDebugOn() if os.path.exists(strArg): listPaths.append(os.path.abspath(strArg)) for strPath in listPaths: xsDataInputGridScreening = XSDataInputGridScreening() xsDataFile = XSDataFile() xsDataFile.setPath(XSDataString(strPath)) xsDataInputGridScreening.setImageFile(xsDataFile) xsDataInputGridScreening.setDoOnlyImageQualityIndicators( XSDataBoolean(True)) xsDataInputGridScreening.setStoreImageQualityIndicatorsInISPyB( XSDataBoolean(True)) edPluginGridScreening = EDFactoryPluginStatic.loadPlugin( "EDPluginControlGridScreeningv1_0") edPluginGridScreening.setDataInput(xsDataInputGridScreening) edPluginGridScreening.executeSynchronous()
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'nexusFileName': obj_ = XSDataString() obj_.build(child_) self.setNexusFileName(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'instrument': obj_ = XSDataString() obj_.build(child_) self.setInstrument(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'energy': obj_ = XSDataArray() obj_.build(child_) self.setEnergy(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'dataArray': obj_ = XSDataArray() obj_.build(child_) self.setDataArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'pathToEnergyArray': obj_ = XSDataFile() obj_.build(child_) self.setPathToEnergyArray(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'pathToDataArray': obj_ = XSDataFile() obj_.build(child_) self.setPathToDataArray(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def create_input_files(self, xds_dir, mosflm_dir, dc_pars): fileinfo = dc_pars["fileinfo"] osc_seq = dc_pars["oscillation_sequence"][0] prefix = fileinfo["prefix"] runno = fileinfo["run_number"] exp_time = osc_seq["exposure_time"] start_angle = osc_seq["start"] nb_images = osc_seq["number_of_images"] start_img_num = osc_seq["start_image_number"] angle_increment = osc_seq["range"] wavelength = osc_seq.get("wavelength", 0) xds_template_name = "XDS_TEMPLATE.INP" mosflm_template_name = "mosflm_template.dat" xds_template_path = os.path.join(self.template_dir, xds_template_name) mosflm_template_path = os.path.join(self.template_dir, mosflm_template_name) xds_file = os.path.join(xds_dir, "XDS.INP") mosflm_file = os.path.join(mosflm_dir, "mosflm.dat") t = datetime.now() # PREPARE VARIABLES detsamdis = self.var_ds.detsamdis beamx, beamy = self.var_ds.beamx, self.var_ds.beamy mbeamx, mbeamy = beamy * 0.172, beamx * 0.172 datarangestartnum = start_img_num datarangefinishnum = start_img_num + nb_images - 1 backgroundrangestartnum = start_img_num spotrangestartnum = start_img_num if angle_increment != 0: minimumrange = int(round(20 / angle_increment)) elif angle_increment == 0: minimumrange = 1 if nb_images >= minimumrange: backgroundrangefinishnum = start_img_num + minimumrange - 1 if nb_images >= minimumrange: spotrangefinishnum = start_img_num + minimumrange - 1 if nb_images < minimumrange: backgroundrangefinishnum = start_img_num + nb_images - 1 if nb_images < minimumrange: spotrangefinishnum = start_img_num + nb_images - 1 testlowres = 8.0 largestvector = ( 0.172 * ((max(beamx, 2463 - beamx)) ** 2 + (max(beamy, 2527 - beamy)) ** 2) ** 0.5 ) testhighres = round( wavelength / (2 * math.sin(0.5 * math.atan(largestvector / detsamdis))), 2 ) lowres = 50.0 highres = testhighres datafilename = prefix + "_" + str(runno) + "_????" mdatafilename = prefix + "_" + str(runno) + "_####.cbf" seconds = 5 * exp_time if angle_increment < 1 and not angle_increment == 0: seconds = 5 * exp_time / angle_increment # DEFINE SG/UNIT CELL spacegroupnumber = "" unitcellconstants = "" datapath_dir = os.path.abspath(xds_file).replace("PROCESS_DATA", "RAW_DATA") datapath_dir = os.path.dirname(os.path.dirname(datapath_dir)) + os.path.sep # CREATE XDS.INP FILE xds_templ = open(xds_template_path, "r").read() xds_templ = xds_templ.replace("###BEAMX###", str(round(beamx, 2))) xds_templ = xds_templ.replace("###BEAMY###", str(round(beamy, 2))) xds_templ = xds_templ.replace("###DETSAMDIS###", str(round(detsamdis, 2))) xds_templ = xds_templ.replace("###ANGLEINCREMENT###", str(angle_increment)) xds_templ = xds_templ.replace("###WAVELENGTH###", str(wavelength)) xds_templ = xds_templ.replace("###DATARANGESTARTNUM###", str(datarangestartnum)) xds_templ = xds_templ.replace( "###DATARANGEFINISHNUM###", str(datarangefinishnum) ) xds_templ = xds_templ.replace( "###BACKGROUNDRANGESTART###", str(backgroundrangestartnum) ) xds_templ = xds_templ.replace( "###BACKGROUNDRANGEFINISHNUM###", str(backgroundrangefinishnum) ) xds_templ = xds_templ.replace("###SPOTRANGESTARTNUM###", str(spotrangestartnum)) xds_templ = xds_templ.replace( "###SPOTRANGEFINISHNUM###", str(spotrangefinishnum) ) xds_templ = xds_templ.replace("###TESTLOWRES###", str(testlowres)) xds_templ = xds_templ.replace("###TESTHIGHRES###", str(testhighres)) xds_templ = xds_templ.replace("###LOWRES###", str(lowres)) xds_templ = xds_templ.replace("###HIGHRES###", str(highres)) xds_templ = xds_templ.replace("###DIRECTORY###", str(datapath_dir)) xds_templ = xds_templ.replace("###FILENAME###", str(datafilename)) xds_templ = xds_templ.replace("###SECONDS###", str(int(seconds))) xds_templ = xds_templ.replace( "###LYSOZYME_SPACE_GROUP_NUMBER###", str(spacegroupnumber) ) xds_templ = xds_templ.replace( "###LYSOZYME_UNIT_CELL_CONSTANTS###", str(unitcellconstants) ) open(xds_file, "w").write(xds_templ) # CREATE MOSFLM.DAT FILE mosflm_templ = open(mosflm_template_path, "r").read() mosflm_templ = mosflm_templ.replace("###DETSAMDIS###", str(round(detsamdis, 2))) mosflm_templ = mosflm_templ.replace("###BEAMX###", str(round(mbeamx, 2))) mosflm_templ = mosflm_templ.replace("###BEAMY###", str(round(mbeamy, 2))) mosflm_templ = mosflm_templ.replace("###DIRECTORY###", str(datapath_dir)) mosflm_templ = mosflm_templ.replace("###FILENAME###", str(mdatafilename)) mosflm_templ = mosflm_templ.replace("###WAVELENGTH###", str(wavelength)) mosflm_templ = mosflm_templ.replace( "###DATARANGESTARTNUM###", str(datarangestartnum) ) open(mosflm_file, "w").write(mosflm_templ) # CREATE EDNAPROC XML FILE collection_id = dc_pars["collection_id"] output_dir = dc_pars["ednaproc_dir"] ednaproc_input_file = os.path.join( output_dir, "EDNAprocInput_%d.xml" % collection_id ) ednaproc_input = XSDataAutoprocInput() input_file = XSDataFile() path = XSDataString() path.setValue(xds_file) input_file.setPath(path) ednaproc_input.setInput_file(input_file) ednaproc_input.setData_collection_id(XSDataInteger(collection_id)) # output_dir = XSDataFile() # outpath = XSDataString() # outpath.setValue(output_dir) # output_dir.setPath(path) # ednaproc_input.setOutput_directory( output_dir ) ednaproc_input.exportToFile(ednaproc_input_file) self.input_file = ednaproc_input_file
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)
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 buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'title': obj_ = XSDataString() obj_.build(child_) self.setTitle(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'long_name': obj_ = XSDataString() obj_.build(child_) self.setLong_name(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'axis': obj_ = XSDataNexusAxis() obj_.build(child_) self.axis.append(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'data': obj_ = XSDataArray() obj_.build(child_) self.setData(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'signal': obj_ = XSDataInteger() obj_.build(child_) self.setSignal(obj_) XSData.buildChildren(self, child_, nodeName_)
def create_input_files(self, xds_dir, mosflm_dir, dc_pars): fileinfo = dc_pars["fileinfo"] osc_seq = dc_pars["oscillation_sequence"][0] prefix = fileinfo["prefix"] runno = fileinfo["run_number"] exp_time = osc_seq["exposure_time"] start_angle = osc_seq["start"] nb_images = osc_seq["number_of_images"] start_img_num = osc_seq["start_image_number"] angle_increment = osc_seq["range"] wavelength = osc_seq.get("wavelength", 0) xds_template_name = "XDS_TEMPLATE.INP" mosflm_template_name = "mosflm_template.dat" xds_template_path = os.path.join(self.template_dir, xds_template_name) mosflm_template_path = os.path.join(self.template_dir, mosflm_template_name) xds_file = os.path.join(xds_dir, "XDS.INP") mosflm_file = os.path.join(mosflm_dir, "mosflm.dat") t = datetime.now() # PREPARE VARIABLES detsamdis = self.var_ds.detsamdis beamx, beamy = self.var_ds.beamx, self.var_ds.beamy mbeamx, mbeamy = beamy * 0.172, beamx * 0.172 datarangestartnum = start_img_num datarangefinishnum = start_img_num + nb_images - 1 backgroundrangestartnum = start_img_num spotrangestartnum = start_img_num if angle_increment != 0: minimumrange = int(round(20 / angle_increment)) elif angle_increment == 0: minimumrange = 1 if nb_images >= minimumrange: backgroundrangefinishnum = start_img_num + minimumrange - 1 if nb_images >= minimumrange: spotrangefinishnum = start_img_num + minimumrange - 1 if nb_images < minimumrange: backgroundrangefinishnum = start_img_num + nb_images - 1 if nb_images < minimumrange: spotrangefinishnum = start_img_num + nb_images - 1 testlowres = 8.0 largestvector = (0.172 * ((max(beamx, 2463 - beamx))**2 + (max(beamy, 2527 - beamy))**2)**0.5) testhighres = round( wavelength / (2 * math.sin(0.5 * math.atan(largestvector / detsamdis))), 2) lowres = 50.0 highres = testhighres datafilename = prefix + "_" + str(runno) + "_????" mdatafilename = prefix + "_" + str(runno) + "_####.cbf" seconds = 5 * exp_time if angle_increment < 1 and not angle_increment == 0: seconds = 5 * exp_time / angle_increment # DEFINE SG/UNIT CELL spacegroupnumber = "" unitcellconstants = "" datapath_dir = os.path.abspath(xds_file).replace( "PROCESS_DATA", "RAW_DATA") datapath_dir = os.path.dirname( os.path.dirname(datapath_dir)) + os.path.sep # CREATE XDS.INP FILE xds_templ = open(xds_template_path, "r").read() xds_templ = xds_templ.replace("###BEAMX###", str(round(beamx, 2))) xds_templ = xds_templ.replace("###BEAMY###", str(round(beamy, 2))) xds_templ = xds_templ.replace("###DETSAMDIS###", str(round(detsamdis, 2))) xds_templ = xds_templ.replace("###ANGLEINCREMENT###", str(angle_increment)) xds_templ = xds_templ.replace("###WAVELENGTH###", str(wavelength)) xds_templ = xds_templ.replace("###DATARANGESTARTNUM###", str(datarangestartnum)) xds_templ = xds_templ.replace("###DATARANGEFINISHNUM###", str(datarangefinishnum)) xds_templ = xds_templ.replace("###BACKGROUNDRANGESTART###", str(backgroundrangestartnum)) xds_templ = xds_templ.replace("###BACKGROUNDRANGEFINISHNUM###", str(backgroundrangefinishnum)) xds_templ = xds_templ.replace("###SPOTRANGESTARTNUM###", str(spotrangestartnum)) xds_templ = xds_templ.replace("###SPOTRANGEFINISHNUM###", str(spotrangefinishnum)) xds_templ = xds_templ.replace("###TESTLOWRES###", str(testlowres)) xds_templ = xds_templ.replace("###TESTHIGHRES###", str(testhighres)) xds_templ = xds_templ.replace("###LOWRES###", str(lowres)) xds_templ = xds_templ.replace("###HIGHRES###", str(highres)) xds_templ = xds_templ.replace("###DIRECTORY###", str(datapath_dir)) xds_templ = xds_templ.replace("###FILENAME###", str(datafilename)) xds_templ = xds_templ.replace("###SECONDS###", str(int(seconds))) xds_templ = xds_templ.replace("###LYSOZYME_SPACE_GROUP_NUMBER###", str(spacegroupnumber)) xds_templ = xds_templ.replace("###LYSOZYME_UNIT_CELL_CONSTANTS###", str(unitcellconstants)) open(xds_file, "w").write(xds_templ) # CREATE MOSFLM.DAT FILE mosflm_templ = open(mosflm_template_path, "r").read() mosflm_templ = mosflm_templ.replace("###DETSAMDIS###", str(round(detsamdis, 2))) mosflm_templ = mosflm_templ.replace("###BEAMX###", str(round(mbeamx, 2))) mosflm_templ = mosflm_templ.replace("###BEAMY###", str(round(mbeamy, 2))) mosflm_templ = mosflm_templ.replace("###DIRECTORY###", str(datapath_dir)) mosflm_templ = mosflm_templ.replace("###FILENAME###", str(mdatafilename)) mosflm_templ = mosflm_templ.replace("###WAVELENGTH###", str(wavelength)) mosflm_templ = mosflm_templ.replace("###DATARANGESTARTNUM###", str(datarangestartnum)) open(mosflm_file, "w").write(mosflm_templ) # CREATE EDNAPROC XML FILE collection_id = dc_pars["collection_id"] output_dir = dc_pars["ednaproc_dir"] ednaproc_input_file = os.path.join( output_dir, "EDNAprocInput_%d.xml" % collection_id) ednaproc_input = XSDataAutoprocInput() input_file = XSDataFile() path = XSDataString() path.set_value(xds_file) input_file.setPath(path) ednaproc_input.setInput_file(input_file) ednaproc_input.setData_collection_id(XSDataInteger(collection_id)) # output_dir = XSDataFile() # outpath = XSDataString() # outpath.set_value(output_dir) # output_dir.setPath(path) # ednaproc_input.setOutput_directory( output_dir ) ednaproc_input.exportToFile(ednaproc_input_file) self.input_file = ednaproc_input_file
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'motorPosition1': obj_ = XSDataString() obj_.build(child_) self.setMotorPosition1(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'motorPosition2': obj_ = XSDataString() obj_.build(child_) self.setMotorPosition2(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'scanId1': obj_ = XSDataString() obj_.build(child_) self.setScanId1(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'scanId2': obj_ = XSDataString() obj_.build(child_) self.setScanId2(obj_) XSData.buildChildren(self, child_, nodeName_)
def testExecute(self): pyarchPath = tempfile.mkdtemp( prefix="EDTestCasePluginControlRunDimplev1_0_") xsDataPyarchPath = XSDataFile(XSDataString(pyarchPath)) self._edPlugin.dataInput.pyarchPath = xsDataPyarchPath self.run()
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 create_autoproc_input(self, event, params): """ Descript. : """ WAIT_XDS_TIMEOUT = 20 WAIT_XDS_RESOLUTION = 1 file_name_timestamp = time.strftime("%Y%m%d_%H%M%S") autoproc_path = params.get("xds_dir") autoproc_xds_filename = os.path.join(autoproc_path, "XDS.INP") autoproc_input_filename = os.path.join( autoproc_path, "edna-autoproc-input-%s" % file_name_timestamp ) autoproc_output_file_name = os.path.join( autoproc_path, "edna-autoproc-results-%s" % file_name_timestamp ) autoproc_input = XSDataAutoprocInput() autoproc_xds_file = XSDataFile() autoproc_xds_file.setPath(XSDataString(autoproc_xds_filename)) autoproc_input.setInput_file(autoproc_xds_file) autoproc_output_file = XSDataFile() autoproc_output_file.setPath(XSDataString(autoproc_output_file_name)) autoproc_input.setOutput_file(autoproc_output_file) autoproc_input.setData_collection_id(XSDataInteger(params.get("collection_id"))) residues_num = float(params.get("residues", 0)) if residues_num != 0: autoproc_input.setNres(XSDataDouble(residues_num)) space_group = params.get("sample_reference").get("spacegroup", "") if not isinstance(space_group, int) and len(space_group) > 0: autoproc_input.setSpacegroup(XSDataString(space_group)) unit_cell = params.get("sample_reference").get("cell", "") if len(unit_cell) > 0: autoproc_input.setUnit_cell(XSDataString(unit_cell)) autoproc_input.setCc_half_cutoff(XSDataDouble(18.0)) # Maybe we have to check if directory is there. Maybe create dir with mxcube xds_appeared = False wait_xds_start = time.time() logging.info( "MAXIVAutoprocessing: Waiting for XDS.INP file: %s" % autoproc_xds_filename ) while not xds_appeared and time.time() - wait_xds_start < WAIT_XDS_TIMEOUT: if ( os.path.exists(autoproc_xds_filename) and os.stat(autoproc_xds_filename).st_size > 0 ): xds_appeared = True logging.debug( "MAXIVAutoprocessing: XDS.INP file is there, size={0}".format( os.stat(autoproc_xds_filename).st_size ) ) else: os.system("ls %s> /dev/null" % (os.path.dirname(autoproc_path))) gevent.sleep(WAIT_XDS_RESOLUTION) if not xds_appeared: logging.error( "MAXIVAutoprocessing: XDS.INP file ({0}) failed to appear after {1} seconds".format( autoproc_xds_filename, WAIT_XDS_TIMEOUT ) ) return None, False autoproc_input.exportToFile(autoproc_input_filename) return autoproc_input_filename, True
def preProcess(self, _edObject=None): EDPluginControl.preProcess(self) EDVerbose.DEBUG("EDPluginControlPyarchThumbnailGeneratorv1_0.preProcess") # Check that the input image exists and is of the expected type strPathToDiffractionImage = self.getDataInput().getDiffractionImage().getPath().getValue() strImageFileNameExtension = os.path.splitext(strPathToDiffractionImage)[1] if not strImageFileNameExtension in [".img", ".marccd", ".mccd", ".cbf"]: print strImageFileNameExtension EDVerbose.error("Unknown image file name extension for pyarch thumbnail generator: %s" % strPathToDiffractionImage) self.setFailure() else: # Load the waitFile plugin xsDataInputWaitFile = XSDataInputWaitFile() xsDataInputWaitFile.setExpectedSize(XSDataInteger(self.__iExpectedSize)) xsDataInputWaitFile.setExpectedFile(self.getDataInput().getDiffractionImage()) if self.getDataInput().getWaitForFileTimeOut(): xsDataInputWaitFile.setTimeOut(self.getDataInput().getWaitForFileTimeOut()) self.__edPluginWaitFile = EDPluginWaitFile() self.__edPluginWaitFile.setDataInput(xsDataInputWaitFile) # Load the execution plugin self.__edPluginExecThumbnail = self.loadPlugin(self.__strExecThumbnailPluginName) xsDataInputExecThumbnail = XSDataInputExecThumbnail() xsDataInputExecThumbnail.setInputImagePath(self.getDataInput().getDiffractionImage()) xsDataInputExecThumbnail.setLevelsInvert(XSDataBoolean(True)) xsDataInputExecThumbnail.setLevelsMin(XSDataDoubleWithUnit(0.0)) xsDataDoubleWithUnitLevelsMax = XSDataDoubleWithUnit(99.95) xsDataDoubleWithUnitLevelsMax.setUnit(XSDataString("%")) xsDataInputExecThumbnail.setLevelsMax(xsDataDoubleWithUnitLevelsMax) xsDataInputExecThumbnail.setFilterDilatation([XSDataInteger(4)]) xsDataInputExecThumbnail.setLevelsColorize(XSDataBoolean(False)) xsDataInputExecThumbnail.setThumbHeight(XSDataInteger(1024)) xsDataInputExecThumbnail.setThumbWidth(XSDataInteger(1024)) xsDataInputExecThumbnail.setKeepRatio(XSDataBoolean(False)) # 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): EDVerbose.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 BaseException, e: EDVerbose.WARNING("Couldn't create the directory %s" % strOutputDirname) elif os.access(strOutputDirname, os.W_OK): bIsOk = True if not bIsOk: EDVerbose.warning("Cannot write to pyarch directory: %s" % strOutputDirname) strOutputDirname = tempfile.mkdtemp("", "EDPluginPyarchThumbnailv10_", "/tmp") EDVerbose.warning("Writing thumbnail images to: %s" % strOutputDirname) self.strOutputPathWithoutExtension = os.path.join(strOutputDirname, strImageNameWithoutExt) self.strOutputPath = os.path.join(self.strOutputPathWithoutExtension + ".jpeg") xsDataInputExecThumbnail.setOutputPath(XSDataFile(XSDataString(self.strOutputPath))) self.__edPluginExecThumbnail.setDataInput(xsDataInputExecThumbnail)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'title': obj_ = XSDataString() obj_.build(child_) self.setTitle(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'axis': obj_ = XSDataInteger() obj_.build(child_) self.setAxis(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'primary': obj_ = XSDataInteger() obj_.build(child_) self.setPrimary(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'units': obj_ = XSDataString() obj_.build(child_) self.setUnits(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'long_name': obj_ = XSDataString() obj_.build(child_) self.setLong_name(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'axisData': obj_ = XSDataArray() obj_.build(child_) self.setAxisData(obj_) XSData.buildChildren(self, child_, nodeName_)
yappi = None else: yappi.start() else: yappi = None if options.verbose: reprocess.setVerboseDebugOn() keys = [ os.path.abspath(onefile) for onefile in args if os.path.exists(onefile)] keys.sort() working_dir = "analyse-modeling-%s" % time.strftime("%Y%m%d-%H%M%S") base_dir = os.getcwd() os.makedirs(working_dir) os.chdir(working_dir) for run in keys: xsd = XSDataInputSaxsAnalysisModeling(scatterCurve=XSDataFile(XSDataString(run)), graphFormat=XSDataString("png")) reprocess.startJob(xsd) print("All %i jobs queued after %.3fs" % (len(args), time.time() - reprocess.startTime)) reprocess.join() if yappi: yappi.stop() print("All %i jobs processed after %.3fs" % (len(args), time.time() - reprocess.startTime)) print reprocess.statistics() if yappi: stat = yappi.get_stats(sort_type=yappi.SORTTYPE_TTOT) res = {} for i in stat.func_stats: if i[0] in res: res[i[0]][0] += i[1] res[i[0]][1] += i[2] else:
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'instrument': obj_ = XSDataString() obj_.build(child_) self.setInstrument(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'outputFileName': obj_ = XSDataString() obj_.build(child_) self.setOutputFileName(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'outputFileDirectory': obj_ = XSDataFile() obj_.build(child_) self.setOutputFileDirectory(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'nexusGroup': obj_ = XSDataNexusArrayGroup() obj_.build(child_) self.nexusGroup.append(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def create_autoproc_input(self, event, params): """Creates processing input xml :param event: processing type (after, before, image) :type event: str :param params: collection parameters :type params: dict """ xds_input_file_wait_timeout = 20 xds_input_file_wait_resolution = 1 file_name_timestamp = time.strftime("%Y%m%d_%H%M%S") autoproc_path = params.get("xds_dir") autoproc_xds_filename = os.path.join(autoproc_path, "XDS.INP") autoproc_input_filename = os.path.join(\ autoproc_path, "edna-autoproc-input-%s.xml" % \ file_name_timestamp) autoproc_output_file_name = os.path.join(\ autoproc_path, "edna-autoproc-results-%s.xml" % \ file_name_timestamp) autoproc_input = XSDataAutoprocInput() autoproc_xds_file = XSDataFile() autoproc_xds_file.setPath(XSDataString(autoproc_xds_filename)) autoproc_input.setInput_file(autoproc_xds_file) autoproc_output_file = XSDataFile() autoproc_output_file.setPath(XSDataString(autoproc_output_file_name)) autoproc_input.setOutput_file(autoproc_output_file) autoproc_input.setData_collection_id(\ XSDataInteger(params.get("collection_id"))) residues_num = float(params.get("residues", 0)) if residues_num != 0: autoproc_input.setNres(XSDataDouble(residues_num)) space_group = params.get("sample_reference").get("spacegroup", "") if len(space_group) > 0: autoproc_input.setSpacegroup(XSDataString(space_group)) unit_cell = params.get("sample_reference").get("cell", "") if len(unit_cell) > 0: autoproc_input.setUnit_cell(XSDataString(unit_cell)) autoproc_input.setCc_half_cutoff(XSDataDouble(18.0)) #Maybe we have to check if directory is there. #Maybe create dir with mxcube xds_appeared = False wait_xds_start = time.time() logging.debug("EMBLAutoprocessing: Waiting for XDS.INP " +\ "file: %s" % autoproc_xds_filename) while not xds_appeared and time.time( ) - wait_xds_start < xds_input_file_wait_timeout: if os.path.exists(autoproc_xds_filename) and \ os.stat(autoproc_xds_filename).st_size > 0: xds_appeared = True logging.debug('EMBLAutoprocessing: XDS.INP file is there, size={0}'.\ format(os.stat(autoproc_xds_filename).st_size)) else: os.system("ls %s> /dev/null" % (os.path.dirname(autoproc_path))) gevent.sleep(xds_input_file_wait_resolution) if not xds_appeared: logging.error("EMBLAutoprocessing: XDS.INP file ({0}) failed " +\ "to appear after {1} seconds".\ format(autoproc_xds_filename, xds_input_file_wait_timeout)) return None, False autoproc_input.exportToFile(autoproc_input_filename) return autoproc_input_filename, True
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginAutoSubv1_0.process") basename = os.path.splitext(os.path.basename(self.sampleCurve))[0] self.bestBuffer = os.path.join(self.outdir, "%s_bestbuffer.dat" % basename) self.averBuffer = os.path.join(self.outdir, "%s_averbuffer.dat" % basename) for idx, name in enumerate(self.buffers): copy(name, os.path.join(self.outdir, "%s_buf%i.dat" % (basename, idx))) if len(self.buffers) == 1: self.actualBestBuffer = self.buffers[0] else: self.__edPluginDataver.dataInput = XSDataInputDataver( inputCurve=self.dataInput.buffers, outputCurve=XSDataFile(XSDataString(self.averBuffer))) self.__edPluginDataver.connectSUCCESS(self.doSuccessExecDataver) self.__edPluginDataver.connectFAILURE(self.doFailureExecDataver) self.__edPluginDataver.execute() if len(self.buffers) == 2: edPluginDatcmp = self.loadPlugin(self.__strPluginDatcmp) edPluginDatcmp.dataInput = XSDataInputDatcmp( inputCurve=self.dataInput.buffers) edPluginDatcmp.connectSUCCESS(self.doSuccessExecDatcmp) edPluginDatcmp.connectFAILURE(self.doFailureExecDatcmp) edPluginDatcmp.executeSynchronous() if self.isFailure() or (self.fidelity is None): return if self.fidelity < self.BUFFER_SIMILARITY: #buffer are not the same: keeping the one with lowest Rg/I0 edpluginRg = self.loadPlugin(self.__strPluginAutoRg) edpluginRg.dataInput = XSDataInputAutoRg( inputCurve=self.dataInput.buffers) edpluginRg.connectSUCCESS(self.doSuccessExecAutoRg) edpluginRg.connectFAILURE(self.doFailureExecAutoRg) edpluginRg.executeSynchronous() self.actualBestBuffer = self.dictRg.keys()[ self.dictRg.values().index(min(self.dictRg.values()))] else: self.actualBestBuffer = self.averBuffer else: self.synchronizePlugins() strError = "You should specify exactly 2 buffers for guessing best buffer, I got: " + ", ".join( self.buffers) self.WARNING(strError) self.lstProcessLog.append(strError) self.actualBestBuffer = self.averBuffer copy(self.actualBestBuffer, self.bestBuffer) self.lstProcessLog.append("Best buffer is %s" % self.actualBestBuffer) if self.isFailure() or not os.path.exists( self.bestBuffer) or not os.path.exists(self.sampleCurve): return edPluginDatop = self.loadPlugin(self.__strPluginDatop) edPluginDatop.dataInput = XSDataInputDatop( operation=XSDataString("SUB"), outputCurve=XSDataFile(XSDataString(self.subtractedCurve)), inputCurve=[ XSDataFile(XSDataString(self.sampleCurve)), XSDataFile(XSDataString(self.bestBuffer)) ]) edPluginDatop.connectSUCCESS(self.doSuccessExecDatop) edPluginDatop.connectFAILURE(self.doFailureExecDatop) edPluginDatop.executeSynchronous() if self.isFailure() or not os.path.exists(self.subtractedCurve): return self.headers = self.parseHeaders(self.sampleCurve) edpluginRg = self.loadPlugin(self.__strPluginAutoRg) edpluginRg.dataInput = XSDataInputAutoRg( inputCurve=[XSDataFile(XSDataString(self.subtractedCurve))]) edpluginRg.connectSUCCESS(self.doSuccessExecAutoRg) edpluginRg.connectFAILURE(self.doFailureExecAutoRg) edpluginRg.executeSynchronous()
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: import traceback logging.getLogger("HWR").debug("DataAnalysis. transmission not saved ") logging.getLogger("HWR").debug(traceback.format_exc()) 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: min_exp_time = self.collect_obj.detector_hwobj.get_exposure_time_limits()[0] beam.setMinExposureTimePerImage(XSDataTime(min_exp_time)) except AttributeError: pass try: beamsize = self.get_beam_size() if None not 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) if char_params.aimed_i_sigma: diff_plan.setAimedIOverSigmaAtHighestResolution(aimed_i_sigma) if char_params.aimed_completness: 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: self.modify_strategy_option(diff_plan, "-DamPar") # Characterisation type - SAD if char_params.opt_sad: if char_params.auto_res: diff_plan.setAnomalousData(XSDataBoolean(True)) else: diff_plan.setAnomalousData(XSDataBoolean(False)) self.modify_strategy_option(diff_plan, "-SAD yes") diff_plan.setAimedResolution(XSDataDouble(char_params.sad_res)) 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
def finallyProcess(self, _edObject=None): EDPluginControl.finallyProcess(self) executiveSummary = os.linesep.join(self.lstExecutiveSummary) self.xsDataResult.status = XSDataStatus(executiveSummary=XSDataString(executiveSummary)) self.dataOutput = self.xsDataResult
def doSuccessExecMeasureOffset(self, _edPlugin=None): with self.semMeasure: self.DEBUG( "EDPluginControlAlignStackv1_0.doSuccessExecMeasureOffset") self.retrieveSuccessMessages( _edPlugin, "EDPluginControlAlignStackv1_0.doSuccessExecMeasureOffset") listIndex = [i.getValue() for i in _edPlugin.dataInput.index] listIndex.sort() dataOutput = _edPlugin.dataOutput if self.bAlwaysMOvsRef: if min(listIndex) < EDPluginControlAlignStackv1_0.__iRefFrame: iToShift, iRef = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictAbsShift[ iToShift] = tuple( [-i.getValue() for i in dataOutput.getOffset()]) else: iRef, iToShift = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictAbsShift[ iToShift] = tuple( [i.getValue() for i in dataOutput.getOffset()]) self.screen( "Frame number %i has absolute offset of %.3f,%.3f" % (iToShift, EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift][0], EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift][1]) ) edPluginExecShift = self.loadPlugin( self.__strControlledPluginShift) xsdata = XSDataInputShiftImage( index=XSDataInteger(iToShift), offset=[ XSDataDouble(i) for i in EDPluginControlAlignStackv1_0.__dictAbsShift[iToShift] ], inputImage=self.getFrameRef(iToShift), outputImage=XSDataImageExt( shared=XSDataString("Shifted-%06i" % iToShift))) edPluginExecShift.setDataInput(xsdata) edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) else: if min(listIndex) < EDPluginControlAlignStackv1_0.__iRefFrame: iToShift, iRef = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictRelShift[ iToShift] = tuple( [-i.value for i in dataOutput.offset]) else: iRef, iToShift = tuple(listIndex) EDPluginControlAlignStackv1_0.__dictRelShift[ iToShift] = tuple([i.value for i in dataOutput.offset]) self.screen( "Frame number %i has relative offset of %.3f,%.3f" % (iToShift, EDPluginControlAlignStackv1_0.__dictRelShift[iToShift][0], EDPluginControlAlignStackv1_0.__dictRelShift[iToShift][1]) ) xsdata = XSDataInputAccumulator( item=[XSDataString("shift %04i" % iToShift)]) edPluginExecAccumulator = self.loadPlugin( self.__strControlledPluginAccumulator) edPluginExecAccumulator.setDataInput(xsdata) edPluginExecAccumulator.connectSUCCESS( self.doSuccessExecAccumultor) edPluginExecAccumulator.connectFAILURE( self.doFailureExecAccumulator) self.queue.put(edPluginExecAccumulator)
def postProcess(self, _edObject=None): """ postProcess of the plugin EDPluginSPDCakev1_5.py: - convert to HDF if needed (to be implemented) - convert to chiplot or xye or cif if needed - move images (if needed) or delete .cor image - set result XML """ EDPluginSPDCorrectv10.postProcess(self) self.DEBUG("EDPluginSPDCakev1_5.postProcess") if not os.path.isdir(self.dictGeometry["OutputDirCake"]): os.makedirs(self.dictGeometry["OutputDirCake"]) strInputImagePathNoSfx = os.path.splitext( os.path.basename(self.pathToInputFile))[0] strSpdoutCake = strInputImagePathNoSfx + self.dictGeometry[ "OutputFileType"] strOutputCakeFilePath = os.path.join( self.dictGeometry["OutputDirCake"], strSpdoutCake) xsDataResultSPD = XSDataResultSPDCake() if not self.getFireAndForget(): strTempFilePath = None if "corrected" in self.dictRes: strSpdoutCor = self.dictRes["corrected"] if "regrouped" in self.dictRes: strTempFilePath = self.dictRes["regrouped"] if self.dictGeometry["OutputFileType"].lower() in [ ".hdf5", ".nexus", ".h5", ".nx" ]: self.WARNING( "HDF5/Nexus output is not yet implemented in the SPD plugin." ) if strTempFilePath is None: self.WARNING( "Cannot copy output to %s as there is not input: %s " % (strOutputCakeFilePath, self.dictRes)) elif os.path.exists(strOutputCakeFilePath): self.WARNING( "Destination file exists, I will leave result file in %s." % strTempFilePath) strOutputCakeFilePath = strTempFilePath else: shutil.move(strTempFilePath, strOutputCakeFilePath) strOutputCorFilePath = os.path.join(self.dictGeometry["OutputDir"], os.path.split(strSpdoutCor)[1]) if self.bDeleteCorImg: if os.path.isfile(strSpdoutCor): os.remove(strSpdoutCor) else: self.WARNING("Corrected file vanished before removal %s" % strSpdoutCor) else: strTempFilePathCor = os.path.join(self.getWorkingDirectory(), strSpdoutCor) if self.dictGeometry["OutputFileType"].lower() in [ ".hdf5", ".nexus", ".h5", ".nx" ]: self.WARNING( "HDF5/Nexus output is not yet implemented in the SPD plugin." ) elif self.dictGeometry["OutputFileType"].lower() not in [ ".edf", ".azim", ".cor" ]: self.WARNING( "Output file format %s is not yet implemented in the SPD plugin." % self.dictGeometry["OutputFileType"]) if os.path.exists(strOutputCorFilePath): self.WARNING( "Destination file exists, I will leave result file in %s." % strTempFilePathCor) strOutputCorFilePath = os.path.abspath(strTempFilePathCor) else: shutil.move(strTempFilePath, strOutputCorFilePath) xsDataFileCorr = XSDataFile() xsDataFileCorr.setPath(XSDataString(strOutputCorFilePath)) xsDataResultSPD.setcorrectedFile(xsDataFileCorr) # # Create the output data xsDataFileCake = XSDataFile() xsDataFileCake.setPath(XSDataString(strOutputCakeFilePath)) xsDataResultSPD.setCakedFile(xsDataFileCake) self.setDataOutput(xsDataResultSPD)
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 processMerges(self, run): # run analysis of merges for merge in run.merge_curves: if os.path.exists(merge): xsdSubtractedCurve = XSDataFile(XSDataString(merge)) self.__edPluginSaxsAnalysis = self.loadPlugin( self.__strControlledPluginSaxsAnalysis) self.__edPluginSaxsAnalysis.dataInput = XSDataInputSaxsAnalysis( scatterCurve=xsdSubtractedCurve, autoRg=run.merge_Rg[merge], graphFormat=XSDataString("png")) self.__edPluginSaxsAnalysis.connectSUCCESS( self.doSuccessSaxsAnalysis) self.__edPluginSaxsAnalysis.connectFAILURE( self.doFailureSaxsAnalysis) self.__edPluginSaxsAnalysis.executeSynchronous() xsdBuffer = XSDataFile(XSDataString(run.buffer)) xsdStartFrame = XSDataString(run.merge_framesDIC[merge][0]) xsdEndFrame = XSDataString(run.merge_framesDIC[merge][-1]) self.__edPluginISPyBAnalysis = self.loadPlugin( self.__strControlledPluginISPyBAnalysis) try: inputBioSaxsISPyB = XSDataInputBioSaxsISPyBv1_0( sample=self.dataOutputBioSaxsISPyB_HPLC.getSample(), autoRg=run.merge_analysis[merge].autoRg, gnom=run.merge_analysis[merge].gnom, volume=run.merge_analysis[merge].volume, bestBuffer=xsdBuffer, scatterPlot=run.merge_analysis[merge].scatterPlot, guinierPlot=run.merge_analysis[merge].guinierPlot, kratkyPlot=run.merge_analysis[merge].kratkyPlot, densityPlot=run.merge_analysis[merge].densityPlot) xsdISPyBin = XSDataInputBioSaxsISPyBHPLCv1_0( experimentId=self.dataOutputBioSaxsISPyB_HPLC. getExperimentId(), startFrame=xsdStartFrame, endFrame=xsdEndFrame, dataInputBioSaxs=inputBioSaxsISPyB) self.__edPluginISPyBAnalysis.dataInput = xsdISPyBin self.__edPluginISPyBAnalysis.connectSUCCESS( self.doSuccessISPyBAnalysis) self.__edPluginISPyBAnalysis.connectFAILURE( self.doFailureISPyBAnalysis) self.__edPluginISPyBAnalysis.executeSynchronous() except Exception as error: traceback.print_stack() self.ERROR( "EDPluginBioSaxsFlushHPLCv1_3 calling to EDPluginHPLCPrimayDataISPyBv1_0: %s" % error) # There were some recurring issues with dammin slowing down slavia, therefore I commented this out for the time being # Martha, 11.7.2014 # mergeNumber = 1 # for merge in run.merge_curves: # try: # xsdSubtractedCurve = XSDataFile(XSDataString(merge)) # xsdGnomFile = XSDataFile(XSDataString(run.merge_analysis[merge].gnom.gnomFile.path.value)) # destination = XSDataFile(XSDataString(os.path.join(os.path.dirname(os.path.dirname(merge)), "ednaSAS"))) # self.__edPluginSaxsToSAS = self.loadPlugin(self.__strControlledPluginSaxsModeling) # print "Changing measurentID by runMerge" # #In order to keep dammin models in different folder a measurementId should be given # self.__edPluginISPyBAnalysis.xsDataResult.dataInputBioSaxs.sample.measurementID.value = mergeNumber # print "------------> MeasurementId changed " + str(self.__edPluginISPyBAnalysis.xsDataResult.dataInputBioSaxs.sample.measurementID.value) # self.__edPluginSaxsToSAS.dataInput = XSDataInputBioSaxsToSASv1_0( # sample=self.__edPluginISPyBAnalysis.xsDataResult.dataInputBioSaxs.sample, # subtractedCurve=xsdSubtractedCurve, # gnomFile=xsdGnomFile, # destinationDirectory=destination) # self.__edPluginSaxsToSAS.connectSUCCESS(self.doSuccessSaxsToSAS) # self.__edPluginSaxsToSAS.connectFAILURE(self.doFailureSaxsToSAS) # mergeNumber = mergeNumber + 1; # self.__edPluginSaxsToSAS.executeSynchronous() # except Exception as error: # traceback.print_stack() # self.ERROR("EDPluginBioSaxsFlushHPLCv1_3 calling to EDPluginBioSaxsToSASv1_1: %s" % error) self.synchronizePlugins()
def testSetDataInput(self): """ Test the setDataInput method with different inputs """ # Test 1: default input with XML edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString) xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal()) EDAssert.equal(xsDataStringTest.marshal(), edPlugin.getDataInput().marshal(), "Test 1: default input with XML") # Test 2: default input with object edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString) xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest) EDAssert.equal(xsDataStringTest.marshal(), edPlugin.getDataInput().marshal(), "Test 2: default input with object") # Test 3: named input with XML edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal(), "testData") EDAssert.equal(xsDataStringTest.marshal(), edPlugin.getDataInput("testData")[0].marshal(), "Test 3: named input with XML") # Test 4: named input with object edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest, "testData") EDAssert.equal(xsDataStringTest.marshal(), edPlugin.getDataInput("testData")[0].marshal(), "Test 4: named input with object") # Test 4: several inputs with the same name, XML input edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest1 = XSDataString("Test1") xsDataStringTest2 = XSDataString("Test2") edPlugin.setDataInput(xsDataStringTest1.marshal(), "testData") edPlugin.setDataInput(xsDataStringTest2.marshal(), "testData") pyListDataInput = edPlugin.getDataInput("testData") EDAssert.equal(xsDataStringTest1.marshal(), pyListDataInput[0].marshal(), "Test 4: several inputs with the same name, XML input, 1") EDAssert.equal(xsDataStringTest2.marshal(), pyListDataInput[1].marshal(), "Test 4: several inputs with the same name, XML input, 2") # Test 5: several inputs with the same name, object input edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString, "testData") xsDataStringTest1 = XSDataString("Test1") xsDataStringTest2 = XSDataString("Test2") edPlugin.setDataInput(xsDataStringTest1, "testData") edPlugin.setDataInput(xsDataStringTest2, "testData") pyListDataInput = edPlugin.getDataInput("testData") EDAssert.equal(xsDataStringTest1.marshal(), pyListDataInput[0].marshal(), "Test 5: several inputs with the same name, object input, 1") EDAssert.equal(xsDataStringTest2.marshal(), pyListDataInput[1].marshal(), "Test 5: several inputs with the same name, object input, 2") # Test 6: test of delDataInput edPlugin = EDPlugin() edPlugin.setXSDataInputClass(XSDataString) xsDataStringTest = XSDataString("Test") edPlugin.setDataInput(xsDataStringTest.marshal()) edPlugin.delDataInput() EDAssert.equal(None, edPlugin.getDataInput(), "Test 6: test of delDataInput")
def process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginBioSaxsSmartMergev1_3.process") xsdwf = XSDataInputWaitMultiFile(timeOut=XSDataTime(30), expectedSize=XSDataInteger(10000), expectedFile=[XSDataFile(i.path) for i in self.lstInput]) self.__edPluginExecWaitFile.setDataInput(xsdwf) self.__edPluginExecWaitFile.connectFAILURE(self.doFailureExecWait) self.__edPluginExecWaitFile.connectSUCCESS(self.doSuccessExecWait) self.__edPluginExecWaitFile.executeSynchronous() if self.isFailure(): return if len(self.lstInput) == 1: inp = self.lstInput[0].path.value dst = self.dataInput.mergedCurve.path.value if not os.path.isdir(os.path.dirname(dst)): self.error("Output directory for %s does not exist"%dst) os.makedirs(os.path.dirname(dst)) if not os.path.exists(inp): self.warning("Input %s does not (yet?) exist"%inp) time.sleep(1.0) shutil.copyfile(inp, dst) else: self.lstMerged = [] if (self.absoluteFidelity is not None) or (self.relativeFidelity is not None): if self.absoluteFidelity is not None : for idx, oneFile in enumerate(self.lstInput[1:]): self.DEBUG("Calculating similarity of 0 and %s" % idx) edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp) xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], oneFile]) edPluginExecAbsoluteFidelity.setDataInput(xsd) edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp) edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp) edPluginExecAbsoluteFidelity.execute() if (self.relativeFidelity is not None): if (self.absoluteFidelity is None): self.DEBUG("Calculating similarity of 0 and 1") edPluginExecAbsoluteFidelity = self.loadPlugin(self.__strControlledPluginDatcmp) xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[0], self.lstInput[1] ]) edPluginExecAbsoluteFidelity.setDataInput(xsd) edPluginExecAbsoluteFidelity.connectFAILURE(self.doFailureExecDatcmp) edPluginExecAbsoluteFidelity.connectSUCCESS(self.doSuccessExecDatcmp) edPluginExecAbsoluteFidelity.execute() if (len(self.lstInput) > 2): for idx, oneFile in enumerate(self.lstInput[2:]): self.DEBUG("Calculating similarity of %s and %s" % (idx, idx + 1)) edPluginExecRelativeFidelity = self.loadPlugin(self.__strControlledPluginDatcmp) xsd = XSDataInputDatcmp(inputCurve=[self.lstInput[idx + 1], oneFile]) edPluginExecRelativeFidelity.setDataInput(xsd) edPluginExecRelativeFidelity.connectFAILURE(self.doFailureExecDatcmp) edPluginExecRelativeFidelity.connectSUCCESS(self.doSuccessExecDatcmp) edPluginExecRelativeFidelity.execute() self.synchronizePlugins() for idx, oneFile in enumerate(self.lstInput): if idx == 0: self.lstMerged.append(oneFile) elif (self.absoluteFidelity is not None) and (self.relativeFidelity is not None): if (idx - 1, idx) not in self.dictSimilarities: self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities])) if (0, idx) not in self.dictSimilarities: self.ERROR("dict missing %i,%i: \n" % (0, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities])) if (self.dictSimilarities[(0, idx)] >= self.absoluteFidelity) and (self.dictSimilarities[(idx - 1, idx)] >= self.relativeFidelity): self.lstMerged.append(oneFile) else: break elif (self.absoluteFidelity is not None) : if (0, idx) not in self.dictSimilarities: self.ERROR("dict missing %i,%i: \n" % (0, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities])) if (self.dictSimilarities[(0, idx)] >= self.absoluteFidelity): self.lstMerged.append(oneFile) else: break elif (self.relativeFidelity is not None) : if (idx - 1, idx) not in self.dictSimilarities: self.ERROR("dict missing %i,%i: \n" % (idx - 1, idx) + "\n".join([ "%s: %s" % (key, self.dictSimilarities[key]) for key in self.dictSimilarities])) if (self.dictSimilarities[(idx - 1, idx)] >= self.relativeFidelity): self.lstMerged.append(oneFile) else: break else: self.lstMerged.append(oneFile) self.lstMerged.sort(cmp) if len(self.lstMerged) != len(self.lstInput): self.strRadiationDamage = "Radiation damage detected, merged %i curves" % len(self.lstMerged) self.WARNING(self.strRadiationDamage) self.lstSummary.append("WARNING: " + self.strRadiationDamage) self.lstSummary.append("Merging files: " + " ".join([os.path.basename(i.path.value) for i in self.lstMerged])) if len(self.lstMerged) == 1: self.rewriteHeader(self.lstMerged[0].path.value, self.strMergedFile) else: self.__edPluginExecDataver = self.loadPlugin(self.__strControlledPluginDataver) xsd = XSDataInputDataver(inputCurve=self.lstMerged) #outputCurve=self.dataInput.mergedCurve, self.__edPluginExecDataver.setDataInput(xsd) self.__edPluginExecDataver.connectSUCCESS(self.doSuccessExecDataver) self.__edPluginExecDataver.connectFAILURE(self.doFailureExecDataver) self.__edPluginExecDataver.executeSynchronous() if (self.fConcentration == 0) and (self.strSubFile is not None): if (self.__class__.lastBuffer is not None) and (self.__class__.lastSample is not None): self.__edPluginExecAutoSub = self.loadPlugin(self.__strControlledPluginAutoSub) base = "_".join(os.path.basename(self.__class__.lastSample.path.value).split("_")[:-1]) suff = os.path.basename(self.strSubFile).split("_")[-1] sub = os.path.join(os.path.dirname(self.strSubFile), base + "_" + suff) xsd = XSDataInputAutoSub(sampleCurve=self.__class__.lastSample, buffers=[self.__class__.lastBuffer, self.dataInput.mergedCurve], subtractedCurve=XSDataFile(XSDataString(sub)) ) self.__edPluginExecAutoSub.setDataInput(xsd) self.__edPluginExecAutoSub.connectSUCCESS(self.doSuccessExecAutoSub) self.__edPluginExecAutoSub.connectFAILURE(self.doFailureExecAutoSub) self.__edPluginExecAutoSub.executeSynchronous() self.__class__.lastBuffer = self.dataInput.mergedCurve self.__class__.lastSample = None else: self.__class__.lastSample = self.dataInput.mergedCurve
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'detectorType': obj_ = XSDataString() obj_.build(child_) self.setDetectorType(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'exposureTime': obj_ = XSDataDouble() obj_.build(child_) self.setExposureTime(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'spotSize': obj_ = XSDataDouble() obj_.build(child_) self.setSpotSize(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'detectorDistance': obj_ = XSDataDouble() obj_.build(child_) self.setDetectorDistance(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'wavelength': obj_ = XSDataDouble() obj_.build(child_) self.setWavelength(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'fractionPolarization': obj_ = XSDataDouble() obj_.build(child_) self.setFractionPolarization(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'orgx': obj_ = XSDataDouble() obj_.build(child_) self.setOrgx(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'orgy': obj_ = XSDataDouble() obj_.build(child_) self.setOrgy(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'oscillationRange': obj_ = XSDataDouble() obj_.build(child_) self.setOscillationRange(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'imageStep': obj_ = XSDataDouble() obj_.build(child_) self.setImageStep(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'startingAngle': obj_ = XSDataDouble() obj_.build(child_) self.setStartingAngle(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'firstImageNumber': obj_ = XSDataInteger() obj_.build(child_) self.setFirstImageNumber(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'numberImages': obj_ = XSDataInteger() obj_.build(child_) self.setNumberImages(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'nameTemplateImage': obj_ = XSDataString() obj_.build(child_) self.setNameTemplateImage(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
def buildChildren(self, child_, nodeName_): if child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'input_file': obj_ = XSDataString() obj_.build(child_) self.setInput_file(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'space_group': obj_ = XSDataInteger() obj_.build(child_) self.setSpace_group(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'unit_cell_a': obj_ = XSDataDouble() obj_.build(child_) self.setUnit_cell_a(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'unit_cell_b': obj_ = XSDataDouble() obj_.build(child_) self.setUnit_cell_b(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'unit_cell_c': obj_ = XSDataDouble() obj_.build(child_) self.setUnit_cell_c(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'unit_cell_alpha': obj_ = XSDataDouble() obj_.build(child_) self.setUnit_cell_alpha(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'unit_cell_beta': obj_ = XSDataDouble() obj_.build(child_) self.setUnit_cell_beta(obj_) elif child_.nodeType == Node.ELEMENT_NODE and \ nodeName_ == 'unit_cell_gamma': obj_ = XSDataDouble() obj_.build(child_) self.setUnit_cell_gamma(obj_) XSDataInput.buildChildren(self, child_, nodeName_)
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 process(self, _edObject=None): EDPluginControl.process(self) self.DEBUG("EDPluginControlAlignStackv1_0.process") for iFrame in self.iFrames: edPluginExecAccumulator = self.loadPlugin( self.__strControlledPluginAccumulator) queryRaw = XSDataQuery() queryShift = XSDataQuery() queryRaw.setRemoveItems(XSDataBoolean(False)) queryShift.setRemoveItems(XSDataBoolean(False)) xsdataAcc = XSDataInputAccumulator() if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame) or (self.bDoAlign == False): EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame] = (0.0, 0.0) EDPluginControlAlignStackv1_0.__dictRelShift[iFrame] = (0.0, 0.0) self.hdf5_offset(index=iFrame, offset=[0.0, 0.0]) edPluginExecShift = self.loadPlugin( self.__strControlledPluginShift) xsdata = XSDataInputShiftImage( index=XSDataInteger(iFrame), offset=[ XSDataDouble(i) for i in EDPluginControlAlignStackv1_0.__dictAbsShift[iFrame] ], inputImage=self.getFrameRef(iFrame), outputImage=XSDataImageExt( shared=XSDataString("Shifted-%06i" % iFrame))) edPluginExecShift.setDataInput(xsdata) edPluginExecShift.connectSUCCESS(self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE(self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) if (self.bDoAlign == False): self.executeControlledPlugins() return elif EDPluginControlAlignStackv1_0.__iRefFrame < iFrame: if self.bAlwaysMOvsRef: queryRaw.setItem([ XSDataString( "raw %04i" % (EDPluginControlAlignStackv1_0.__iRefFrame)), XSDataString("raw %04i" % iFrame) ]) xsdataAcc.setQuery([queryRaw]) else: queryRaw.setItem([ XSDataString("raw %04i" % (iFrame - 1)), XSDataString("raw %04i" % iFrame) ]) queryShift.setItem([ XSDataString("shift %04i" % i) for i in range( EDPluginControlAlignStackv1_0.__iRefFrame + 1, iFrame + 1) ]) xsdataAcc.setQuery([queryRaw, queryShift]) elif EDPluginControlAlignStackv1_0.__iRefFrame > iFrame: if self.bAlwaysMOvsRef: queryRaw.setItem([ XSDataString("raw %04i" % iFrame), XSDataString( "raw %04i" % (EDPluginControlAlignStackv1_0.__iRefFrame)) ]) xsdataAcc.setQuery([queryRaw]) else: queryRaw.setItem([ XSDataString("raw %04i" % (iFrame + 1)), XSDataString("raw %04i" % iFrame) ]) queryShift.setItem([ XSDataString("shift %04i" % i) for i in range( EDPluginControlAlignStackv1_0.__iRefFrame - 1, iFrame - 1, -1) ]) xsdataAcc.setQuery([queryRaw, queryShift]) if (EDPluginControlAlignStackv1_0.__iRefFrame == iFrame): self.saveReferenceFrame(iFrame) xsdataAcc.setItem([XSDataString("raw %04i" % iFrame)]) edPluginExecAccumulator.setDataInput(xsdataAcc) edPluginExecAccumulator.connectSUCCESS( self.doSuccessExecAccumultor) edPluginExecAccumulator.connectFAILURE( self.doFailureExecAccumulator) self.queue.put(edPluginExecAccumulator) self.executeControlledPlugins()
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 doSuccessExecAccumultor(self, _edPlugin=None): with self.semAccumulator: self.DEBUG("EDPluginControlAlignStackv1_0.doSuccessExecAccumultor") self.retrieveSuccessMessages( _edPlugin, "EDPluginControlAlignStackv1_0.doSuccessExecAccumultor") for query in _edPlugin.dataOutput.getQuery(): self.addExtraTime(60) _edPlugin.addExtraTime(60) accType = query.getItem()[0].getValue().split()[0] listInt = [ int(i.getValue().split()[1]) for i in query.getItem() ] if accType == "raw": listFrame = [self.getFrameRef(i) for i in listInt] xsdata = XSDataInputMeasureOffset(image=listFrame) doSIFT = False if self.xsdMeasureOffset is not None: xsdata.setCropBorders( self.xsdMeasureOffset.getCropBorders()) xsdata.setSmoothBorders( self.xsdMeasureOffset.getSmoothBorders()) xsdata.setBackgroundSubtraction( self.xsdMeasureOffset.getRemoveBackground()) if self.xsdMeasureOffset.useSift is not None: doSIFT = self.xsdMeasureOffset.useSift.value if max(listInt ) > EDPluginControlAlignStackv1_0.__iRefFrame: listInt.sort() else: listInt.sort(reverse=True) xsdata.setIndex([XSDataInteger(i) for i in listInt]) if doSIFT: edPluginExecMeasure = self.loadPlugin( self.__strControlledPluginMeasureSIFT) else: edPluginExecMeasure = self.loadPlugin( self.__strControlledPluginMeasureFFT) edPluginExecMeasure.setDataInput(xsdata) edPluginExecMeasure.connectSUCCESS( self.doSuccessExecMeasureOffset) edPluginExecMeasure.connectFAILURE( self.doFailureExecMeasureOffset) self.queue.put(edPluginExecMeasure) elif accType == "shift": shift_1 = 0.0 shift_2 = 0.0 for frame in listInt: shift_1 += EDPluginControlAlignStackv1_0.__dictRelShift[ frame][0] shift_2 += EDPluginControlAlignStackv1_0.__dictRelShift[ frame][1] if listInt[0] > EDPluginControlAlignStackv1_0.__iRefFrame: iFrameShift = max(listInt) else: iFrameShift = min(listInt) EDPluginControlAlignStackv1_0.__dictAbsShift[ iFrameShift] = (shift_1, shift_2) self.screen( "Frame number %i has absolute offset of %.3f,%.3f" % (iFrameShift, shift_1, shift_2)) edPluginExecShift = self.loadPlugin( self.__strControlledPluginShift) edPluginExecShift.dataInput = XSDataInputShiftImage( index=XSDataInteger(iFrameShift), offset=[XSDataDouble(shift_1), XSDataDouble(shift_2)], inputImage=self.getFrameRef(iFrameShift), outputImage=XSDataImageExt( shared=XSDataString("Shifted-%06i" % iFrameShift))) edPluginExecShift.connectSUCCESS( self.doSuccessExecShiftImage) edPluginExecShift.connectFAILURE( self.doFailureExecShiftImage) self.queue.put(edPluginExecShift) self.DEBUG("Items: %s" % EDPluginAccumulatorv1_0.getItems()) self.DEBUG("Queries: %s" % EDPluginAccumulatorv1_0.getQueries())
def generateXSDataIntegrationSubWedgeResult( _xsDataMOSFLMOutputIntegration, _xsDataExperimentalCondition=None): """ Translation from XSDataMOSFLMOutputIntegration to XSDataIntegrationSubWedgeResult. """ EDVerbose.DEBUG( "EDHandlerXSDataMOSFLMv10.generateXSDataIntegrationInput") EDFactoryPluginStatic.loadModule("XSDataMOSFLMv10") xsDataIntegrationSubWedgeResult = XSDataIntegrationSubWedgeResult() 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() if _xsDataMOSFLMOutputIntegration.getBestfilePar() is not None: xsDataIntegrationSubWedgeResult.setBestfilePar( XSDataString(_xsDataMOSFLMOutputIntegration.getBestfilePar(). getValue())) xsDataIntegrationSubWedgeResult.setBestfileDat( XSDataString(_xsDataMOSFLMOutputIntegration.getBestfileDat(). getValue())) xsDataIntegrationSubWedgeResult.setBestfileHKL( XSDataString(_xsDataMOSFLMOutputIntegration.getBestfileHKL(). getValue())) xsDataLengthRefinedDistance = _xsDataMOSFLMOutputIntegration.getRefinedDistance( ) if (xsDataLengthRefinedDistance is not None): xsDataDetector.setDistance(xsDataLengthRefinedDistance) xsDataMOSFLMBeamPositionRefined = _xsDataMOSFLMOutputIntegration.getRefinedBeam( ) if (xsDataMOSFLMBeamPositionRefined is not None): xsDataDetector.setBeamPositionX( XSDataLength( xsDataMOSFLMBeamPositionRefined.getX().getValue())) xsDataDetector.setBeamPositionY( XSDataLength( xsDataMOSFLMBeamPositionRefined.getY().getValue())) xsDataExperimentalConditionRefined.setDetector(xsDataDetector) xsDataIntegrationSubWedgeResult.setExperimentalConditionRefined( xsDataExperimentalConditionRefined) if (_xsDataMOSFLMOutputIntegration.getGeneratedMTZFile() is not None): xsDataIntegrationSubWedgeResult.setGeneratedMTZFile( _xsDataMOSFLMOutputIntegration.getGeneratedMTZFile()) xsDataStatisticsIntegration = XSDataStatisticsIntegration() if (_xsDataMOSFLMOutputIntegration.getOverallIOverSigma() is not None): xsDataStatisticsIntegration.setIOverSigmaOverall( XSDataDouble(_xsDataMOSFLMOutputIntegration. getOverallIOverSigma().getValue())) if (_xsDataMOSFLMOutputIntegration.getHighestResolutionIOverSigma() is not None): xsDataStatisticsIntegration.setIOverSigmaAtHighestResolution( XSDataDouble(_xsDataMOSFLMOutputIntegration. getHighestResolutionIOverSigma().getValue())) if (_xsDataMOSFLMOutputIntegration.getRMSSpotDeviation() is not None): xsDataStatisticsIntegration.setRMSSpotDeviation( XSDataLength(_xsDataMOSFLMOutputIntegration. getRMSSpotDeviation().getValue())) if (_xsDataMOSFLMOutputIntegration.getNumberOfBadReflections() is not None): xsDataStatisticsIntegration.setNumberOfBadReflections( XSDataInteger(_xsDataMOSFLMOutputIntegration. getNumberOfBadReflections().getValue())) if (_xsDataMOSFLMOutputIntegration.getNumberOfFullyRecordedReflections( ) is not None): xsDataStatisticsIntegration.setNumberOfFullyRecordedReflections( XSDataInteger( _xsDataMOSFLMOutputIntegration. getNumberOfFullyRecordedReflections().getValue())) if (_xsDataMOSFLMOutputIntegration.getNumberOfNegativeReflections() is not None): xsDataStatisticsIntegration.setNumberOfNegativeReflections( XSDataInteger(_xsDataMOSFLMOutputIntegration. getNumberOfNegativeReflections().getValue())) if (_xsDataMOSFLMOutputIntegration.getNumberOfOverlappedReflections() is not None): xsDataStatisticsIntegration.setNumberOfOverlappedReflections( XSDataInteger(_xsDataMOSFLMOutputIntegration. getNumberOfOverlappedReflections().getValue())) if (_xsDataMOSFLMOutputIntegration.getNumberOfPartialReflections() is not None): xsDataStatisticsIntegration.setNumberOfPartialReflections( XSDataInteger(_xsDataMOSFLMOutputIntegration. getNumberOfPartialReflections().getValue())) if (_xsDataMOSFLMOutputIntegration.getNumberOfReflectionsGenerated() is not None): xsDataStatisticsIntegration.setNumberOfReflectionsGenerated( XSDataInteger(_xsDataMOSFLMOutputIntegration. getNumberOfReflectionsGenerated().getValue())) xsDataIntegrationSubWedgeResult.setStatistics( xsDataStatisticsIntegration) xsDataIntegrationSubWedgeResult.setExperimentalConditionRefined( xsDataExperimentalConditionRefined) for xsDataMOSFLMIntegrationStatisticsPerResolutionBin in _xsDataMOSFLMOutputIntegration.getStatisticsPerResolutionBin( ): xsDataStatisticsIntegrationPerResolutionBin = XSDataStatisticsIntegrationPerResolutionBin( ) if (xsDataMOSFLMIntegrationStatisticsPerResolutionBin. getMaxResolution() is not None): xsDataStatisticsIntegrationPerResolutionBin.setMaxResolution( XSDataDouble( xsDataMOSFLMIntegrationStatisticsPerResolutionBin. getMaxResolution().getValue())) if (xsDataMOSFLMIntegrationStatisticsPerResolutionBin. getMinResolution() is not None): xsDataStatisticsIntegrationPerResolutionBin.setMinResolution( XSDataDouble( xsDataMOSFLMIntegrationStatisticsPerResolutionBin. getMinResolution().getValue())) xsDataStatisticsIntegrationPerResolutionBin.setProfileFitted( EDHandlerXSDataMOSFLMv10. generateXSDataIntegrationStatisticsPerReflectionType( xsDataMOSFLMIntegrationStatisticsPerResolutionBin. getProfileFitted())) xsDataStatisticsIntegrationPerResolutionBin.setSummation( EDHandlerXSDataMOSFLMv10. generateXSDataIntegrationStatisticsPerReflectionType( xsDataMOSFLMIntegrationStatisticsPerResolutionBin. getSummation())) xsDataIntegrationSubWedgeResult.addStatisticsPerResolutionBin( xsDataStatisticsIntegrationPerResolutionBin) xsDataIntegrationSubWedgeResult.setIntegrationLogFile( _xsDataMOSFLMOutputIntegration.getPathToLogFile()) return xsDataIntegrationSubWedgeResult