def vector_move(t_s,vecRequest): #I think t_s is a fraction of the total vector, so "1" would do the whole thing global x_vec_end, y_vec_end, z_vec_end, x_vec, y_vec, z_vec, x_vec_start, y_vec_start, z_vec_start # print "vec t = " + str(t_s) t = float(t_s) reqObj = vecRequest["request_obj"] trans_total = reqObj["vectorParams"]["trans_total"] trans_done = trans_total*t percent_done = t*100.0 vec_s = "translation total = %f, translation done = %f, translation percent done = %f\n" % (trans_total,trans_done,percent_done) print vec_s # daq_utils.broadcast_output(vec_s) x_vec_start=reqObj["vectorParams"]["vecStart"]["x"] y_vec_start=reqObj["vectorParams"]["vecStart"]["y"] z_vec_start=reqObj["vectorParams"]["vecStart"]["z"] x_vec = reqObj["vectorParams"]["x_vec"] y_vec = reqObj["vectorParams"]["y_vec"] z_vec = reqObj["vectorParams"]["z_vec"] new_x = x_vec_start + (x_vec*t) new_y = y_vec_start + (y_vec*t) new_z = z_vec_start + (z_vec*t) beamline_lib.mva("X",new_x,"Y",new_y,"Z",new_z)
def dna_execute_collection3( dna_start, dna_range, dna_number_of_images, dna_exptime, dna_directory, prefix, start_image_number, overlap, dna_run_num, charRequest, ): global collect_and_characterize_success, dna_have_strategy_results, dna_have_index_results, picture_taken global dna_strategy_exptime, dna_strategy_start, dna_strategy_range, dna_strategy_end, dna_strat_dist global screeningoutputid characterizationParams = charRequest["request_obj"]["characterizationParams"] dna_res = float(characterizationParams["aimed_resolution"]) print "dna_res = " + str(dna_res) dna_filename_list = [] print "number of images " + str(dna_number_of_images) + " overlap = " + str(overlap) + " dna_start " + str( dna_start ) + " dna_range " + str(dna_range) + " prefix " + prefix + " start number " + str(start_image_number) + "\n" collect_and_characterize_success = 0 dna_have_strategy_results = 0 dna_have_index_results = 0 dg2rd = 3.14159265 / 180.0 if daq_utils.detector_id == "ADSC-Q315": det_radius = 157.5 elif daq_utils.detector_id == "ADSC-Q210": det_radius = 105.0 elif daq_utils.detector_id == "PILATUS-6": det_radius = 212.0 else: # default Pilatus det_radius = 212.0 ##### theta_radians = daq_lib.get_field("theta") * dg2rd theta_radians = 0.0 wave = 12398.5 / beamline_lib.get_mono_energy() # for now dx = det_radius / (tan(2.0 * (asin(wave / (2.0 * dna_res))) - theta_radians)) print "distance = ", dx # skinner - could move distance and wave and scan axis here, leave wave alone for now print "skinner about to take reference images." for i in range(0, int(dna_number_of_images)): print "skinner prefix7 = " + prefix[0:7] + " " + str(start_image_number) + "\n" if len(prefix) > 8: if (prefix[0:7] == "postref") and (start_image_number == 1): print "skinner postref bail\n" time.sleep(float(dna_number_of_images * float(dna_exptime))) break # skinner roi - maybe I can measure and use that for dna_start so that first image is face on. dna_start = daq_lib.get_field("datum_omega") colstart = float(dna_start) + (i * (abs(overlap) + float(dna_range))) dna_prefix = "ref-" + prefix + "_" + str(dna_run_num) image_number = start_image_number + i dna_prefix_long = dna_directory + "/" + dna_prefix filename = daq_utils.create_filename(dna_prefix_long, image_number) beamline_lib.mva("Omega", float(colstart)) ##### daq_lib.move_axis_absolute(daq_lib.get_field("scan_axis"),colstart) ##### daq_lib.take_image(colstart,dna_range,dna_exptime,filename,daq_lib.get_field("scan_axis"),0,1) daq_utils.take_crystal_picture(reqID=charRequest["request_id"]) ######### BECAUSE I FAKE IT imagesAttempted = collect_detector_seq(dna_range,dna_range,dna_exptime,dna_prefix,dna_directory,image_number) if i == 0: commFake = "ln -sf /h/pxuser/skinner/testdata/B1GGTApo_9_00001.cbf " + filename else: commFake = "ln -sf /h/pxuser/skinner/testdata/B1GGTApo_9_00181.cbf " + filename os.system(commFake) dna_filename_list.append(filename) diffImgJpegData = daq_utils.diff2jpeg(filename, reqID=charRequest["request_id"]) # returns a dictionary # diffImgJpegData["timestamp"] = time.time() # imgRef = db_lib.addFile(diffImgJpegData["data"]) # diffImgJpegData["data"] = imgRef # imgRef = db_lib.addFile(diffImgJpegData["thumbData"]) # diffImgJpegData["thumbData"] = imgRef picture_taken = 1 # xml_from_file_list(flux,x_beamsize,y_beamsize,max_exptime_per_dc,aimed_completeness,file_list): edna_energy_ev = (12.3985 / wave) * 1000.0 ##### xbeam_size = beamline_lib.get_motor_pos("slitHum") ##### ybeam_size = beamline_lib.get_motor_pos("slitVum") # if (xbeam_size == 0.0 or ybeam_size == 0.0): #don't know where to get these from yet if 1: xbeam_size = 0.1 ybeam_size = 0.16 else: xbeam_size = xbeam_size / 1000 ybeam_size = ybeam_size / 1000 aimed_completeness = characterizationParams["aimed_completeness"] aimed_multiplicity = characterizationParams["aimed_multiplicity"] aimed_resolution = characterizationParams["aimed_resolution"] aimed_ISig = characterizationParams["aimed_ISig"] timeout_check = 0 ##### while(not os.path.exists(dna_filename_list[len(dna_filename_list)-1])): #this waits for edna images if 0: timeout_check = timeout_check + 1 time.sleep(1.0) if timeout_check > 10: break print "generating edna input\n" # edna_input_filename = edna_input_xml.xml_from_file_list(edna_energy_ev,xbeam_size,ybeam_size,1000000,aimed_completness,aimed_ISig,aimed_multiplicity,aimed_resolution,dna_filename_list) ##### flux = 10000000000 * beamline_lib.get_epics_pv("flux","VAL") flux = 600000000.0 # for now edna_input_filename = dna_directory + "/adsc1_in.xml" edna_input_xml_command = ( "/h/data/backed-up/pxsys/skinner/edna_header_code/makeAnEDNAXML-bnl.sh 1232 %s %s none %f %f 4000 0.01 0.01 0 xh1223_2_ %f %f %f > %s" % (dna_directory, dna_prefix, 3, aimed_ISig, flux, xbeam_size, ybeam_size, edna_input_filename) ) ##### edna_input_xml_command = "ssh swill \"/h/data/backed-up/pxsys/skinner/edna_header_code/makeAnEDNAXML-bnl.sh 1232 %s %s none %f %f 4000 0.01 0.01 0 xh1223_2_ %f %f %f\" > %s" % (daq_lib.data_directory_name,dna_prefix,3,aimed_ISig,flux,xbeam_size,ybeam_size,edna_input_filename) print edna_input_xml_command comm_sss = "echo " + edna_input_xml_command + "> edna_comm.txt" os.system(comm_sss) os.system(edna_input_xml_command) print "done generating edna input\n" # command_string = "cd %s; /usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data %s" % (dna_directory,edna_input_filename) command_string = "/usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data %s" % ( edna_input_filename ) # command_string = "/usr/local/crys/edna-mx/mxv1/bin/edna-mxv1-characterisation.py --verbose --data /img11/data1/pxuser/staff/skinner/edna_run/adsc1_in.xml" # old command_string = "$EDNA_HOME/mxv1/bin/edna-mxv1-characterisation --data " + edna_input_filename print command_string # for i in range (0,len(dna_filename_list)): # command_string = command_string + " " + dna_filename_list[i] broadcast_output("\nProcessing with EDNA. Please stand by.\n") if os.path.exists("edna.log"): os.remove("edna.log") if os.path.exists("edna.err"): os.remove("edna.err") edna_execution_status = os.system("%s > edna.log 2> edna.err" % command_string) ##### fEdnaLogFile = open(daq_lib.get_misc_dir_name() + "/edna.log", "r" ) fEdnaLogFile = open("./edna.log", "r") ednaLogLines = fEdnaLogFile.readlines() fEdnaLogFile.close() for outline in ednaLogLines: # for outline in os.popen(command_string,'r',0).readlines(): ####skinner6/11 seg faults? broadcast_output(outline) if string.find(outline, "EdnaDir") != -1: (param, dirname) = string.split(outline, "=") strXMLFileName = ( dirname[0 : len(dirname) - 1] + "/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_3_dataOutput.xml" ) ##### strXMLFileName = dirname[0:len(dirname)-1]+"/ControlInterfacev1_2/Characterisation/ControlCharacterisationv1_1_dataOutput.xml" if string.find(outline, "characterisation successful!") != -1: collect_and_characterize_success = 1 if not collect_and_characterize_success: dna_comment = "Indexing Failure" ##### pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment) return 0 xsDataCharacterisation = XSDataResultCharacterisation.parseFile(strXMLFileName) xsDataIndexingResult = xsDataCharacterisation.getIndexingResult() xsDataIndexingSolutionSelected = xsDataIndexingResult.getSelectedSolution() xsDataStatisticsIndexing = xsDataIndexingSolutionSelected.getStatistics() numSpotsFound = xsDataStatisticsIndexing.getSpotsTotal().getValue() numSpotsUsed = xsDataStatisticsIndexing.getSpotsUsed().getValue() numSpotsRejected = numSpotsFound - numSpotsUsed beamShiftX = xsDataStatisticsIndexing.getBeamPositionShiftX().getValue() beamShiftY = xsDataStatisticsIndexing.getBeamPositionShiftY().getValue() spotDeviationR = xsDataStatisticsIndexing.getSpotDeviationPositional().getValue() try: spotDeviationTheta = xsDataStatisticsIndexing.getSpotDeviationAngular().getValue() except AttributeError: spotDeviationTheta = 0.0 diffractionRings = 0 # for now, don't see this in xml except message string reflections_used = 0 # for now reflections_used_in_indexing = 0 # for now rejectedReflections = 0 # for now xsDataOrientation = xsDataIndexingSolutionSelected.getOrientation() xsDataMatrixA = xsDataOrientation.getMatrixA() rawOrientationMatrix_a_x = xsDataMatrixA.getM11() rawOrientationMatrix_a_y = xsDataMatrixA.getM12() rawOrientationMatrix_a_z = xsDataMatrixA.getM13() rawOrientationMatrix_b_x = xsDataMatrixA.getM21() rawOrientationMatrix_b_y = xsDataMatrixA.getM22() rawOrientationMatrix_b_z = xsDataMatrixA.getM23() rawOrientationMatrix_c_x = xsDataMatrixA.getM31() rawOrientationMatrix_c_y = xsDataMatrixA.getM32() rawOrientationMatrix_c_z = xsDataMatrixA.getM33() xsDataCrystal = xsDataIndexingSolutionSelected.getCrystal() xsDataCell = xsDataCrystal.getCell() unitCell_alpha = xsDataCell.getAngle_alpha().getValue() unitCell_beta = xsDataCell.getAngle_beta().getValue() unitCell_gamma = xsDataCell.getAngle_gamma().getValue() unitCell_a = xsDataCell.getLength_a().getValue() unitCell_b = xsDataCell.getLength_b().getValue() unitCell_c = xsDataCell.getLength_c().getValue() mosaicity = xsDataCrystal.getMosaicity().getValue() xsSpaceGroup = xsDataCrystal.getSpaceGroup() spacegroup_name = xsSpaceGroup.getName().getValue() pointGroup = spacegroup_name # for now bravaisLattice = pointGroup # for now statusDescription = "ok" # for now try: spacegroup_number = xsSpaceGroup.getITNumber().getValue() except AttributeError: spacegroup_number = 0 xsStrategyResult = xsDataCharacterisation.getStrategyResult() resolutionObtained = -999 if xsStrategyResult != None: dna_have_strategy_results = 1 xsCollectionPlan = xsStrategyResult.getCollectionPlan() xsStrategySummary = xsCollectionPlan[0].getStrategySummary() resolutionObtained = xsStrategySummary.getRankingResolution().getValue() xsCollectionStrategy = xsCollectionPlan[0].getCollectionStrategy() xsSubWedge = xsCollectionStrategy.getSubWedge() for i in range(0, len(xsSubWedge)): xsExperimentalCondition = xsSubWedge[i].getExperimentalCondition() xsGoniostat = xsExperimentalCondition.getGoniostat() xsDetector = xsExperimentalCondition.getDetector() xsBeam = xsExperimentalCondition.getBeam() dna_strategy_start = xsGoniostat.getRotationAxisStart().getValue() dna_strategy_start = dna_strategy_start - (dna_strategy_start % 0.1) dna_strategy_range = xsGoniostat.getOscillationWidth().getValue() dna_strategy_range = dna_strategy_range - (dna_strategy_range % 0.1) dna_strategy_end = xsGoniostat.getRotationAxisEnd().getValue() dna_strategy_end = (dna_strategy_end - (dna_strategy_end % 0.1)) + dna_strategy_range dna_strat_dist = xsDetector.getDistance().getValue() dna_strat_dist = dna_strat_dist - (dna_strat_dist % 1) dna_strategy_exptime = xsBeam.getExposureTime().getValue() # wtf? dna_strategy_exptime = dna_strategy_exptime-(dna_strategy_exptime%.2) program = "edna-1.0" # for now ##### screeningoutputid = pxdb_lib.insert_dna_index_results(daq_lib.sweep_seq_id,daq_lib.get_field("xtal_id"),program,statusDescription,rejectedReflections,resolutionObtained,spotDeviationR,spotDeviationTheta,beamShiftX,beamShiftY,numSpotsFound,numSpotsUsed,numSpotsRejected,mosaicity,diffractionRings,spacegroup_name,pointGroup,bravaisLattice,rawOrientationMatrix_a_x,rawOrientationMatrix_a_y,rawOrientationMatrix_a_z,rawOrientationMatrix_b_x,rawOrientationMatrix_b_y,rawOrientationMatrix_b_z,rawOrientationMatrix_c_x,rawOrientationMatrix_c_y,rawOrientationMatrix_c_z,unitCell_a,unitCell_b,unitCell_c,unitCell_alpha,unitCell_beta,unitCell_gamma) dna_comment = ( "spacegroup = " + str(spacegroup_name) + " mosaicity = " + str(mosaicity) + " resolutionHigh = " + str(resolutionObtained) + " cell_a = " + str(unitCell_a) + " cell_b = " + str(unitCell_b) + " cell_c = " + str(unitCell_c) + " cell_alpha = " + str(unitCell_alpha) + " cell_beta = " + str(unitCell_beta) + " cell_gamma = " + str(unitCell_gamma) + " status = " + str(statusDescription) ) ##### print "\n\n skinner " + dna_comment + "\n" +str(daq_lib.sweep_seq_id) + "\n" print "\n\n skinner " + dna_comment + "\n" ##### pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_comment) if dna_have_strategy_results: ##### pxdb_lib.insert_to_screening_strategy_table(screeningoutputid,dna_strategy_start,dna_strategy_end,dna_strategy_range,dna_strategy_exptime,resolutionObtained,program) dna_strat_comment = ( "\ndna Strategy results: Start=" + str(dna_strategy_start) + " End=" + str(dna_strategy_end) + " Width=" + str(dna_strategy_range) + " Time=" + str(dna_strategy_exptime) + " Dist=" + str(dna_strat_dist) ) # characterizationResult = {} characterizationResultObj = {} # characterizationResult["type"] = "characterizationStrategy" # characterizationResult["timestamp"] = time.time() characterizationResultObj = { "strategy": { "start": dna_strategy_start, "end": dna_strategy_end, "width": dna_strategy_range, "exptime": dna_strategy_exptime, "detDist": dna_strat_dist, } } # characterizationResult["resultObj"] = characterizationResultObj db_lib.addResultforRequest("characterizationStrategy", charRequest["request_id"], characterizationResultObj) ##### pxdb_lib.update_sweep(2,daq_lib.sweep_seq_id,dna_strat_comment) xsStrategyStatistics = xsCollectionPlan[0].getStatistics() xsStrategyResolutionBins = xsStrategyStatistics.getResolutionBin() now = time.time() # edna_isig_plot_filename = dirname[0:len(dirname)-1] + "/edna_isig_res_" + str(now) + ".txt" edna_isig_plot_filename = dirname[0 : len(dirname) - 1] + "/edna_isig_res.txt" isig_plot_file = open(edna_isig_plot_filename, "w") for i in range(0, len(xsStrategyResolutionBins) - 1): i_over_sigma_bin = xsStrategyResolutionBins[i].getIOverSigma().getValue() maxResolution_bin = xsStrategyResolutionBins[i].getMaxResolution().getValue() print str(maxResolution_bin) + " " + str(i_over_sigma_bin) isig_plot_file.write(str(maxResolution_bin) + " " + str(i_over_sigma_bin) + "\n") isig_plot_file.close() if dna_have_strategy_results: broadcast_output(dna_strat_comment) return 1
def collectData(currentRequest): global data_directory_name logMxRequestParams(currentRequest) reqObj = currentRequest["request_obj"] data_directory_name = str(reqObj["directory"]) if not (os.path.isdir(data_directory_name)): comm_s = "mkdir -p " + data_directory_name os.system(comm_s) print reqObj["protocol"] prot = str(reqObj["protocol"]) if (prot == "raster"): daq_macros.snakeRaster(currentRequest["request_id"]) # return elif (prot == "vector"): daq_macros.vectorScan(currentRequest) # return else: #standard, screening, or edna - these may require autoalign, checking first if (reqObj["pos_x"] != 0): beamline_lib.mva("X",reqObj["pos_x"]) beamline_lib.mva("Y",reqObj["pos_y"]) beamline_lib.mva("Z",reqObj["pos_z"]) else: print "autoRaster" daq_macros.autoRasterLoop(currentRequest["sample_id"]) exposure_period = reqObj["exposure_time"] wavelength = reqObj["wavelength"] resolution = reqObj["resolution"] slit_height = reqObj["slit_height"] slit_width = reqObj["slit_width"] attenuation = reqObj["attenuation"] img_width = reqObj["img_width"] file_prefix = str(reqObj["file_prefix"]) if (reqObj["protocol"] == "screen"): screenImages = 2 screenRange = 90 range_degrees = img_width for i in range (0,screenImages): sweep_start = reqObj["sweep_start"]+(i*screenRange) sweep_end = reqObj["sweep_end"]+(i*screenRange) file_prefix = str(reqObj["file_prefix"]+"_"+str(i*screenRange)) data_directory_name = str(reqObj["directory"]) # for now file_number_start = reqObj["file_number_start"] beamline_lib.mva("Omega",sweep_start) imagesAttempted = collect_detector_seq(range_degrees,img_width,exposure_period,file_prefix,data_directory_name,file_number_start) elif (reqObj["protocol"] == "characterize"): characterizationParams = reqObj["characterizationParams"] index_success = daq_macros.dna_execute_collection3(0.0,img_width,2,exposure_period,data_directory_name+"/",file_prefix,1,-89.0,1,currentRequest) if (index_success): resultsList = db_lib.getResultsforRequest(currentRequest["request_id"]) # because for testing I keep running the same request. Probably not in usual use. results = resultsList[len(resultsList)-1] strategyResults = results["result_obj"]["strategy"] stratStart = strategyResults["start"] stratEnd = strategyResults["end"] stratWidth = strategyResults["width"] stratExptime = strategyResults["exptime"] stratDetDist = strategyResults["detDist"] sampleID = currentRequest["sample_id"] tempnewStratRequest = daq_utils.createDefaultRequest(sampleID) newReqObj = tempnewStratRequest["request_obj"] newReqObj["sweep_start"] = stratStart newReqObj["sweep_end"] = stratEnd newReqObj["img_width"] = stratWidth newReqObj["exposure_time"] = stratExptime newReqObj["detDist"] = stratDetDist newReqObj["directory"] = data_directory_name runNum = db_lib.incrementSampleRequestCount(sampleID) reqObj["runNum"] = runNum newStratRequest = db_lib.addRequesttoSample(sampleID,newReqObj["protocol"],newReqObj,priority=0) else: #standard sweep_start = reqObj["sweep_start"] sweep_end = reqObj["sweep_end"] file_prefix = str(reqObj["file_prefix"]) file_number_start = reqObj["file_number_start"] range_degrees = abs(sweep_end-sweep_start) beamline_lib.mva("Omega",sweep_start) imagesAttempted = collect_detector_seq(range_degrees,img_width,exposure_period,file_prefix,data_directory_name,file_number_start) if (reqObj["fastDP"]): if (reqObj["fastEP"]): fastEPFlag = 1 else: fastEPFlag = 0 comm_s = os.environ["CBHOME"] + "/runFastDP.py " + data_directory_name + " " + file_prefix + " " + str(file_number_start) + " " + str(int(round(range_degrees/img_width))) + " " + str(currentRequest["request_id"]) + " " + str(fastEPFlag) + "&" print comm_s os.system(comm_s) if (reqObj["xia2"]): comm_s = os.environ["CBHOME"] + "/runXia2.py " + data_directory_name + " " + file_prefix + " " + str(file_number_start) + " " + str(int(round(range_degrees/img_width))) + " " + str(currentRequest["request_id"]) + "&" os.system(comm_s) db_lib.updatePriority(currentRequest["request_id"],-1) refreshGuiTree()