class CreateCharWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, "Characterisation") if not name: self.setName("create_char_widget") # # Data attributes # self._current_selected_item = None self.init_models() self._char_params_mib = DataModelInputBinder(self._char_params) # # Layout # v_layout = qt.QVBoxLayout(self, 2, 6, "v_layout") self._acq_widget = AcquisitionWidgetSimple( self, acq_params=self._acquisition_parameters, path_template=self._path_template, ) # self._acq_widget.setFixedHeight(170) current_dir = os.path.dirname(__file__) ui_file = "ui_files/vertical_crystal_dimension_widget_layout.ui" widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) self._vertical_dimension_widget = widget ui_file = "ui_files/characterise_simple_widget_vertical_layout.ui" widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) self._char_widget = widget self._data_path_gbox = qt.QVGroupBox("Data location", self, "data_path_gbox") self._data_path_widget = DataPathWidget( self._data_path_gbox, data_model=self._path_template, layout="vertical" ) v_layout.addWidget(self._acq_widget) v_layout.addWidget(self._data_path_gbox) v_layout.addWidget(self._char_widget) v_layout.addWidget(self._vertical_dimension_widget) v_layout.addStretch(100) # # Logic # optimised_sad_cbx = self._char_widget.child("optimised_sad_cbx") account_rad_dmg_cbx = self._char_widget.child("account_rad_dmg_cbx") start_comp_cbox = self._char_widget.child("start_comp_cbox") # induced_burn_cbx = self._char_widget.child('induced_burn_cbx') max_vdim_ledit = self._vertical_dimension_widget.child("max_vdim_ledit") min_vdim_ledit = self._vertical_dimension_widget.child("min_vdim_ledit") min_vphi_ledit = self._vertical_dimension_widget.child("min_vphi_ledit") max_vphi_ledit = self._vertical_dimension_widget.child("max_vphi_ledit") space_group_ledit = self._vertical_dimension_widget.child("space_group_ledit") self._char_params_mib.bind_value_update( "opt_sad", optimised_sad_cbx, bool, None ) self._char_params_mib.bind_value_update( "account_rad_damage", account_rad_dmg_cbx, bool, None ) # self._char_params_mib.bind_value_update('determine_rad_params', # induced_burn_cbx, # bool, None) self._char_params_mib.bind_value_update( "strategy_complexity", start_comp_cbox, int, None ) self._char_params_mib.bind_value_update( "max_crystal_vdim", max_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self), ) self._char_params_mib.bind_value_update( "min_crystal_vdim", min_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self), ) self._char_params_mib.bind_value_update( "min_crystal_vphi", min_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self), ) self._char_params_mib.bind_value_update( "max_crystal_vphi", max_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self), ) space_group_ledit.insertStrList(queue_model_enumerables.XTAL_SPACEGROUPS) prefix_ledit = self._data_path_widget.data_path_widget_layout.child( "prefix_ledit" ) run_number_ledit = self._data_path_widget.data_path_widget_layout.child( "run_number_ledit" ) self.connect( prefix_ledit, qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change, ) self.connect( run_number_ledit, qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change, ) self.connect( space_group_ledit, qt.SIGNAL("activated(int)"), self._space_group_change ) self.connect( self._data_path_widget, qt.PYSIGNAL("path_template_changed"), self.handle_path_conflict, ) # self.connect(induced_burn_cbx, qt.SIGNAL("toggled(bool)"), # self.use_induced_burn) def use_induced_burn(self, state): self._acquisition_parameters.induce_burn = state def _space_group_change(self, index): self._char_params.space_group = queue_model_enumerables.XTAL_SPACEGROUPS[index] def _set_space_group(self, space_group): index = 0 if space_group in queue_model_enumerables.XTAL_SPACEGROUPS: index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group) self._space_group_change(index) self._vertical_dimension_widget.child("space_group_ledit").setCurrentItem(index) def init_models(self): CreateTaskBase.init_models(self) self._init_models() def _init_models(self): self._char = queue_model_objects.Characterisation() self._char_params = self._char.characterisation_parameters self._processing_parameters = queue_model_objects.ProcessingParameters() if self._beamline_setup_hwobj is not None: self._acquisition_parameters = ( self._beamline_setup_hwobj.get_default_char_acq_parameters() ) self._char_params = ( self._beamline_setup_hwobj.get_default_characterisation_parameters() ) try: transmission = ( self._beamline_setup_hwobj.transmission_hwobj.getAttFactor() ) transmission = round(float(transmission), 1) except AttributeError: transmission = 0 try: resolution = self._beamline_setup_hwobj.resolution_hwobj.getPosition() resolution = round(float(resolution), 3) except AttributeError: resolution = 0 try: energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy() energy = round(float(energy), 4) except AttributeError: energy = 0 self._acquisition_parameters.resolution = resolution self._acquisition_parameters.energy = energy self._acquisition_parameters.transmission = transmission else: self._acquisition_parameters = queue_model_objects.AcquisitionParameters() self._path_template.reference_image_prefix = "ref" # The num images drop down default value is 1 # we would like it to be 2 self._acquisition_parameters.num_images = 2 self._char.characterisation_software = ( queue_model_enumerables.COLLECTION_ORIGIN.EDNA ) self._path_template.num_files = 2 self._acquisition_parameters.shutterless = False def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): self._init_models() self._set_space_group(self._char_params.space_group) self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) self._char_params_mib.set_model(self._char_params) # self._char_params = copy.deepcopy(self._char_params) # self._acquisition_parameters = copy.deepcopy(self._acquisition_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.CharacterisationQueueItem): if tree_item.get_model().is_executed(): self.setDisabled(True) else: self.setDisabled(False) self._char = tree_item.get_model() if self._char.get_path_template(): self._path_template = self._char.get_path_template() self._data_path_widget.update_data_model(self._path_template) data_collection = self._char.reference_image_collection self._char_params = self._char.characterisation_parameters self._char_params_mib.set_model(self._char_params) self._acquisition_parameters = data_collection.acquisitions[ 0 ].acquisition_parameters self._acq_widget.update_data_model( self._acquisition_parameters, self._path_template ) self.get_acquisition_widget().use_osc_start(True) if len(data_collection.acquisitions) == 1: self.select_shape_with_cpos( self._acquisition_parameters.centred_position ) self._processing_parameters = data_collection.processing_parameters else: self.setDisabled(True) def update_processing_parameters(self, crystal): self._processing_parameters.space_group = crystal.space_group self._char_params.space_group = crystal.space_group self._processing_parameters.cell_a = crystal.cell_a self._processing_parameters.cell_alpha = crystal.cell_alpha self._processing_parameters.cell_b = crystal.cell_b self._processing_parameters.cell_beta = crystal.cell_beta self._processing_parameters.cell_c = crystal.cell_c self._processing_parameters.cell_gamma = crystal.cell_gamma def approve_creation(self): return CreateTaskBase.approve_creation(self) selected_shapes = self._shape_history.selected_shapes for shape in selected_shapes: if isinstance(shape, shape_history.Line): result = False return result # Called by the owning widget (task_toolbox_widget) to create # a collection. when a data collection group is selected. def _create_task(self, sample, shape): tasks = [] if not shape: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = self._shape_history.get_snapshot([]) else: # Shapes selected and sample is mounted, get the # centred positions for the shapes if isinstance(shape, shape_history.Point): snapshot = self._shape_history.get_snapshot([shape.qub_point]) # cpos = shape.get_centred_positions()[0] cpos = copy.deepcopy(shape.get_centred_positions()[0]) cpos.snapshot_image = snapshot char_params = copy.deepcopy(self._char_params) acq = self._create_acq(sample) dc = queue_model_objects.DataCollection( [acq], sample.crystals[0], self._processing_parameters ) # Reference images for characterisations should be taken 90 deg apart # this is achived by setting overap to -89 acq.acquisition_parameters.overlap = -89 acq.acquisition_parameters.centred_position = cpos dc.acquisitions[0] = acq dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF char = queue_model_objects.Characterisation(dc, char_params) char.set_name(dc.acquisitions[0].path_template.get_prefix()) char.set_number(dc.acquisitions[0].path_template.run_number) tasks.append(char) self._path_template.run_number += 1 return tasks
class ProcessingWidget(qt.QWidget): def __init__(self, parent = None, name = None, fl = 0, data_model = None): qt.QWidget.__init__(self, parent, name, fl) if data_model is None: self._model = queue_model_objects.ProcessingParameters() else: self._model = data_model self._model_mib = DataModelInputBinder(self._model) h_layout = qt.QHBoxLayout(self) widget = self.acq_widget_layout = qtui.QWidgetFactory.\ create(os.path.join(os.path.dirname(__file__), 'ui_files/processing_widget_vertical_layout.ui')) widget.reparent(self, qt.QPoint(0,0)) self.layout_widget = widget h_layout.addWidget(self.layout_widget) self.layout_widget.child('space_group_ledit').\ insertStrList(queue_model_enumerables.XTAL_SPACEGROUPS) self._model_mib.bind_value_update('cell_a', self.layout_widget.child('a_ledit'), float, None) self._model_mib.bind_value_update('cell_alpha', self.layout_widget.child('alpha_ledit'), float, None) self._model_mib.bind_value_update('cell_b', self.layout_widget.child('b_ledit'), float, None) self._model_mib.bind_value_update('cell_beta', self.layout_widget.child('beta_ledit'), float, None) self._model_mib.bind_value_update('cell_c', self.layout_widget.child('c_ledit'), float, None) self._model_mib.bind_value_update('cell_gamma', self.layout_widget.child('gamma_ledit'), float, None) self._model_mib.bind_value_update('num_residues', self.layout_widget.child('num_residues_ledit'), float, None) self._model_mib.bind_value_update('process_data', self.layout_widget.child('use_processing'), bool, None) self._model_mib.bind_value_update('anomalous', self.layout_widget.child('use_anomalous'), bool, None) self.connect(self.layout_widget.child('space_group_ledit'), qt.SIGNAL("activated(int)"), self._space_group_change) def _space_group_change(self, index): self._model.space_group = queue_model_enumerables.\ XTAL_SPACEGROUPS[index] def _set_space_group(self, space_group): index = 0 if space_group in queue_model_enumerables.XTAL_SPACEGROUPS: index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group) self._space_group_change(index) self.layout_widget.child('space_group_ledit').setCurrentItem(index) def update_data_model(self, model): self._model = model self._model_mib.set_model(model) self._set_space_group(model.space_group)
class AcquisitionWidget(qt.QWidget): def __init__( self, parent=None, name=None, fl=0, acq_params=None, path_template=None, layout="horizontal", ): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # self._beamline_setup = None self.previous_energy = 0 self.layout_type = layout if acq_params is None: self._acquisition_parameters = queue_model_objects.AcquisitionParameters() else: self._acquisition_parameters = acq_params if path_template is None: self._path_template = queue_model_objects.PathTemplate() else: self._path_template = path_template self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters) # self._path_template_mib = DataModelInputBinder(self._path_template) # # Layout # h_layout = qt.QHBoxLayout(self) if layout == "vertical": widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/acquisition_widget_vertical_layout.ui", ) ) elif layout == "horizontal": widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/acquisition_widget_horizontal_layout.ui", ) ) widget.child("inverse_beam_cbx").hide() widget.child("subwedge_size_label").hide() widget.child("subwedge_size_ledit").hide() else: widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/acquisition_widget_vertical_layout.ui", ) ) widget.reparent(self, qt.QPoint(0, 0)) self.acq_widget_layout = widget h_layout.addWidget(self.acq_widget_layout) # # Logic # qt.QObject.connect( self.acq_widget_layout.child("energies_combo"), qt.SIGNAL("activated(int)"), self.energy_selected, ) qt.QObject.connect( self.acq_widget_layout.child("mad_cbox"), qt.SIGNAL("toggled(bool)"), self.use_mad, ) qt.QObject.connect( self.acq_widget_layout.child("inverse_beam_cbx"), qt.SIGNAL("toggled(bool)"), self.set_use_inverse_beam, ) qt.QObject.connect( self.acq_widget_layout.child("first_image_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.first_image_ledit_change, ) qt.QObject.connect( self.acq_widget_layout.child("num_images_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.num_images_ledit_change, ) overlap_ledit = self.acq_widget_layout.child("overlap_ledit") if overlap_ledit: qt.QObject.connect( self.acq_widget_layout.child("overlap_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.overlap_changed, ) qt.QObject.connect( self.acq_widget_layout.child("subwedge_size_ledit"), qt.SIGNAL("textChanged(const QString &)"), self.subwedge_size_ledit_change, ) qt.QObject.connect( self.acq_widget_layout.child("osc_start_cbox"), qt.SIGNAL("toggled(bool)"), self.osc_start_cbox_click, ) self.acq_widget_layout.child("subwedge_size_ledit").setDisabled(True) self.acq_widget_layout.child("energies_combo").setDisabled(True) self.acq_widget_layout.child("energies_combo").insertStrList( ["ip: -", "pk: -", "rm1: -", "rm2: -"] ) self.acq_widget_layout.child("osc_start_ledit").setEnabled(False) self.acq_widget_layout.child("kappa_ledit").setEnabled(False) self.acq_widget_layout.child("kappa_phi_ledit").setEnabled(False) self.acq_widget_layout.child("detector_mode_label").setEnabled(False) self.acq_widget_layout.child("detector_mode_combo").setEnabled(False) def osc_start_cbox_click(self, state): self.update_osc_start(self._beamline_setup._get_omega_axis_position()) self.acq_widget_layout.child("osc_start_ledit").setEnabled(state) def update_osc_start(self, new_value): if not self.acq_widget_layout.child("osc_start_cbox").isChecked(): osc_start_ledit = self.acq_widget_layout.child("osc_start_ledit") osc_start_value = 0 try: osc_start_value = round(float(new_value), 2) except TypeError: pass osc_start_ledit.setText("%.2f" % osc_start_value) self._acquisition_parameters.osc_start = osc_start_value def update_kappa(self, new_value): self.acq_widget_layout.child("kappa_ledit").setText("%.2f" % float(new_value)) def update_kappa_phi(self, new_value): self.acq_widget_layout.child("kappa_phi_ledit").setText( "%.2f" % float(new_value) ) def use_osc_start(self, state): self.acq_widget_layout.child("osc_start_cbox").setChecked(state) self.acq_widget_layout.child("osc_start_cbox").setDisabled(state) def use_kappa(self, state): if self.layout_type == "vertical": self.acq_widget_layout.child("kappa_ledit").setEnabled(state) def use_kappa_phi(self, state): if self.layout_type == "vertical": self.acq_widget_layout.child("kappa_phi_ledit").setEnabled(state) def set_beamline_setup(self, beamline_setup): self._beamline_setup = beamline_setup limits_dict = self._beamline_setup.get_acquisition_limit_values() if "osc_range" in limits_dict: limits = tuple(map(float, limits_dict["osc_range"].split(","))) (lower, upper) = limits osc_start_validator = qt.QDoubleValidator(lower, upper, 4, self) osc_range_validator = qt.QDoubleValidator(lower, upper, 4, self) else: osc_start_validator = qt.QDoubleValidator(-10000, 10000, 4, self) osc_range_validator = qt.QDoubleValidator(-10000, 10000, 4, self) osc_start_ledit = self.acq_widget_layout.child("osc_start_ledit") self._acquisition_mib.bind_value_update( "osc_start", osc_start_ledit, float, osc_start_validator ) osc_range_ledit = self.acq_widget_layout.child("osc_range_ledit") self._acquisition_mib.bind_value_update( "osc_range", osc_range_ledit, float, osc_range_validator ) kappa_validator = qt.QDoubleValidator(0, 360, 2, self) kappa_ledit = self.acq_widget_layout.child("kappa_ledit") self._acquisition_mib.bind_value_update( "kappa", kappa_ledit, float, kappa_validator ) kappa_phi_validator = qt.QDoubleValidator(0, 360, 2, self) kappa_phi_ledit = self.acq_widget_layout.child("kappa_phi_ledit") self._acquisition_mib.bind_value_update( "kappa_phi", kappa_phi_ledit, float, kappa_phi_validator ) if "exposure_time" in limits_dict: limits = tuple(map(float, limits_dict["exposure_time"].split(","))) (lower, upper) = limits exp_time_valdidator = qt.QDoubleValidator(lower, upper, 5, self) else: exp_time_valdidator = qt.QDoubleValidator(-0.003, 6000, 5, self) exp_time_ledit = self.acq_widget_layout.child("exp_time_ledit") self._acquisition_mib.bind_value_update( "exp_time", exp_time_ledit, float, exp_time_valdidator ) if "number_of_images" in limits_dict: limits = tuple(map(int, limits_dict["number_of_images"].split(","))) (lower, upper) = limits num_img_valdidator = qt.QIntValidator(lower, upper, self) first_img_valdidator = qt.QIntValidator(lower, upper, self) else: num_img_valdidator = qt.QIntValidator(1, 9999, self) first_img_valdidator = qt.QIntValidator(1, 9999, self) first_img_ledit = self.acq_widget_layout.child("first_image_ledit") self._acquisition_mib.bind_value_update( "first_image", first_img_ledit, int, first_img_valdidator ) num_img_ledit = self.acq_widget_layout.child("num_images_ledit") self._acquisition_mib.bind_value_update( "num_images", num_img_ledit, int, num_img_valdidator ) num_passes = self.acq_widget_layout.child("num_passes_ledit") if num_passes: self._acquisition_mib.bind_value_update( "num_passes", num_passes, int, qt.QIntValidator(1, 1000, self) ) overlap_ledit = self.acq_widget_layout.child("overlap_ledit") if overlap_ledit: self._acquisition_mib.bind_value_update( "overlap", overlap_ledit, float, qt.QDoubleValidator(-1000, 1000, 2, self), ) self._acquisition_mib.bind_value_update( "energy", self.acq_widget_layout.child("energy_ledit"), float, qt.QDoubleValidator(0, 1000, 4, self), ) self._acquisition_mib.bind_value_update( "transmission", self.acq_widget_layout.child("transmission_ledit"), float, qt.QDoubleValidator(0, 1000, 2, self), ) self._acquisition_mib.bind_value_update( "resolution", self.acq_widget_layout.child("resolution_ledit"), float, qt.QDoubleValidator(0, 1000, 3, self), ) self._acquisition_mib.bind_value_update( "inverse_beam", self.acq_widget_layout.child("inverse_beam_cbx"), bool, None ) self._acquisition_mib.bind_value_update( "shutterless", self.acq_widget_layout.child("shutterless_cbx"), bool, None ) te = beamline_setup.tunable_wavelength() self.set_tunable_energy(te) has_shutter_less = self._beamline_setup.detector_has_shutterless() self.acq_widget_layout.child("shutterless_cbx").setEnabled(has_shutter_less) self.acq_widget_layout.child("shutterless_cbx").setChecked(has_shutter_less) if self._beamline_setup.disable_num_passes(): num_passes = self.acq_widget_layout.child("num_passes_ledit") if num_passes: self.acq_widget_layout.child("num_passes_ledit").setDisabled(True) has_aperture = self._beamline_setup.has_aperture() self.hide_aperture(has_aperture) def first_image_ledit_change(self, new_value): if str(new_value).isdigit(): self._path_template.start_num = int(new_value) widget = self.acq_widget_layout.child("first_image_ledit") self.emit(qt.PYSIGNAL("path_template_changed"), (widget, new_value)) def num_images_ledit_change(self, new_value): if str(new_value).isdigit(): self._path_template.num_files = int(new_value) widget = self.acq_widget_layout.child("num_images_ledit") self.emit(qt.PYSIGNAL("path_template_changed"), (widget, new_value)) def overlap_changed(self, new_value): if self._beamline_setup: has_shutter_less = self._beamline_setup.detector_has_shutterless() else: has_shutter_less = True if has_shutter_less: try: new_value = float(new_value) except ValueError: pass if new_value != 0: self.acq_widget_layout.child("shutterless_cbx").setEnabled(False) self.acq_widget_layout.child("shutterless_cbx").setChecked(False) self._acquisition_parameters.shutterless = False else: self.acq_widget_layout.child("shutterless_cbx").setEnabled(True) self.acq_widget_layout.child("shutterless_cbx").setChecked(True) self._acquisition_parameters.shutterless = True def use_mad(self, state): self.acq_widget_layout.child("energies_combo").setEnabled(state) if state: (name, energy) = self.get_mad_energy() if energy != 0: self.set_energy(energy, 0) self.emit(qt.PYSIGNAL("mad_energy_selected"), (name, energy, state)) else: self.set_energy(self.previous_energy, 0) energy = self._beamline_setup.energy_hwobj.getCurrentEnergy() self.emit( qt.PYSIGNAL("mad_energy_selected"), ("", self.previous_energy, state) ) def set_use_inverse_beam(self, state): if state: self.acq_widget_layout.child("subwedge_size_ledit").setEnabled(True) else: self.acq_widget_layout.child("subwedge_size_ledit").setDisabled(True) def use_inverse_beam(self): return self.acq_widget_layout.child("inverse_beam_cbx").isOn() def get_num_subwedges(self): return int(self.acq_widget_layout.child("subwedge_size_ledit").text()) def subwedge_size_ledit_change(self, new_value): widget = self.acq_widget_layout.child("subwedge_size_ledit") if int(new_value) > self._acquisition_parameters.num_images: widget.setPaletteBackgroundColor(widget_colors.LIGHT_RED) else: widget.setPaletteBackgroundColor(widget_colors.WHITE) def get_mad_energy(self): energy_str = str(self.acq_widget_layout.child("energies_combo").currentText()) (name, value) = energy_str.split(":") name = name.strip() value = value.strip() value = 0 if (value == "-") else value return (name, value) def set_energies(self, energy_scan_result): self.acq_widget_layout.child("energies_combo").clear() inflection = ( ("ip: %.4f" % energy_scan_result.inflection) if energy_scan_result.inflection else "ip: -" ) peak = ( ("pk: %.4f" % energy_scan_result.peak) if energy_scan_result.peak else "pk: -" ) first_remote = ( ("rm1: %.4f" % energy_scan_result.first_remote) if energy_scan_result.first_remote else "rm1: -" ) second_remote = ( ("rm2: %.4f" % energy_scan_result.second_remote) if energy_scan_result.second_remote else "rm2: -" ) self.acq_widget_layout.child("energies_combo").insertStrList( [inflection, peak, first_remote, second_remote] ) def energy_selected(self, index): if self.acq_widget_layout.child("mad_cbox").isChecked(): (name, energy) = self.get_mad_energy() if energy != 0: self.set_energy(energy, 0) self.emit(qt.PYSIGNAL("mad_energy_selected"), (name, energy, True)) def set_energy(self, energy, wav): self._acquisition_parameters.energy = energy self.acq_widget_layout.child("energy_ledit").setText("%.4f" % float(energy)) def update_transmission(self, transmission): self.acq_widget_layout.child("transmission_ledit").setText( "%.2f" % float(transmission) ) # self._acquisition_parameters.transmission = float(transmission) def update_resolution(self, resolution): self.acq_widget_layout.child("resolution_ledit").setText( "%.3f" % float(resolution) ) # self._acquisition_parameters.resolution = float(resolution) def update_data_model(self, acquisition_parameters, path_template): self._acquisition_parameters = acquisition_parameters self._path_template = path_template self._acquisition_mib.set_model(acquisition_parameters) # Update mad widgets mad = True if self._path_template.mad_prefix != "" else False if mad: mad_prefix = self._path_template.mad_prefix index = MAD_ENERGY_COMBO_NAMES[mad_prefix] self.acq_widget_layout.child("energies_combo").setCurrentItem(index) self.acq_widget_layout.child("mad_cbox").setChecked(True) self.acq_widget_layout.child("energies_combo").setEnabled(True) else: self.acq_widget_layout.child("mad_cbox").setChecked(False) self.acq_widget_layout.child("energies_combo").setEnabled(False) self.acq_widget_layout.child("energies_combo").setCurrentItem(0) def set_tunable_energy(self, state): self.acq_widget_layout.child("energy_ledit").setEnabled(state) self.acq_widget_layout.child("mad_cbox").setEnabled(state) self.acq_widget_layout.child("energies_combo").setEnabled(state) def disable_inverse_beam(self, state): if state: self.acq_widget_layout.child("inverse_beam_cbx").hide() self.acq_widget_layout.child("subwedge_size_label").hide() self.acq_widget_layout.child("subwedge_size_ledit").hide() else: self.acq_widget_layout.child("inverse_beam_cbx").show() self.acq_widget_layout.child("subwedge_size_label").show() self.acq_widget_layout.child("subwedge_size_ledit").show() def hide_aperture(self, state): pass # if state: # self.acq_widget_layout.child('aperture_ledit').show() # self.acq_widget_layout.child('aperture_cbox').show() # else: # self.acq_widget_layout.child('aperture_ledit').hide() # self.acq_widget_layout.child('aperture_cbox').hide() def check_parameter_conflict(self): return len(self._acquisition_mib.validate_all()) > 0
class CharParametersWidget(qt.QWidget): def __init__(self, parent = None, name = "parameter_widget"): qt.QWidget.__init__(self, parent, name) # # Private members # self._char = None self._char_params = queue_model_objects.CharacterisationParameters() self._char_params_mib = DataModelInputBinder(self._char_params) self._tree_view_item = None self.previous_energy = None self.add_dc_cb = None self.char_type_widget = CharTypeWidget(self) self.routine_dc_widget = self.char_type_widget.routine_dc_page self.sad_widget = self.char_type_widget.sad_page self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page self.reference_img_widget = ReferenceImageWidget(self) self.acq_widget = self.reference_img_widget.acq_widget self.path_widget = self.reference_img_widget.path_widget self.opt_parameters_widget = OptimisationParametersWidgetLayout(self) self.rad_dmg_widget = RadiationDamageModelWidgetLayout(self) self.position_widget = SnapshotWidgetLayout(self) self.vertical_dimension_widget = VerticalCrystalDimensionWidgetLayout(self) # Fix the widths of the widgets to make the layout look nicer, # and beacuse the qt layout engine is so tremendosly good. self.opt_parameters_widget.setFixedWidth(600) self.reference_img_widget.setFixedWidth(772) # # Layout # v_layout = qt.QVBoxLayout(self, 11, 15, "main_layout") rone_hlayout = qt.QHBoxLayout(v_layout, 15, "rone" ) rone_cone_vlayout = qt.QVBoxLayout(rone_hlayout, 15, "rone_cone") rtwo_hlayout = qt.QHBoxLayout(v_layout, 15, "rtwo") rthree_hlayout = qt.QHBoxLayout(v_layout, 15, "rtwo") rone_hlayout.addWidget(self.position_widget) rone_cone_vlayout.addWidget(self.reference_img_widget) rone_hlayout.addStretch() rtwo_hlayout.addWidget(self.char_type_widget) rtwo_hlayout.addWidget(self.opt_parameters_widget) rtwo_hlayout.addStretch(10) v_layout.addStretch(10) rthree_hlayout.addWidget(self.rad_dmg_widget) rthree_hlayout.addWidget(self.vertical_dimension_widget) rthree_hlayout.addStretch(10) v_layout.addStretch(10) # # Widget logic # self.toggle_permitted_range(self.\ opt_parameters_widget.permitted_range_cbx.isOn()) qt.QObject.connect(self.opt_parameters_widget.permitted_range_cbx, qt.SIGNAL("toggled(bool)"), self.toggle_permitted_range) self._char_params_mib.bind_value_update('min_dose', self.routine_dc_widget.dose_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('min_time', self.routine_dc_widget.time_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('use_min_dose', self.routine_dc_widget.min_dose_radio, bool, None) self._char_params_mib.bind_value_update('use_min_time', self.routine_dc_widget.min_time_radio, bool, None) self._char_params_mib.bind_value_update('account_rad_damage', self.routine_dc_widget.radiation_damage_cbx, bool, None) self._char_params_mib.bind_value_update('auto_res', self.sad_widget.automatic_resolution_radio, bool, None) self._char_params_mib.bind_value_update('opt_sad', self.sad_widget.optimal_sad_radio, bool, None) self._char_params_mib.bind_value_update('determine_rad_params', self.rad_dmg_char_widget.rad_damage_cbx, bool, None) self._char_params_mib.bind_value_update('burn_osc_start', self.rad_dmg_char_widget.burn_osc_start_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('burn_osc_interval', self.rad_dmg_char_widget.burn_osc_interval_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('use_aimed_resolution', self.opt_parameters_widget.maximum_res_cbx, bool, None) self._char_params_mib.bind_value_update('use_aimed_multiplicity', self.opt_parameters_widget.aimed_mult_cbx, bool, None) self._char_params_mib.bind_value_update('aimed_resolution', self.opt_parameters_widget.maximum_res_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update('aimed_multiplicity', self.opt_parameters_widget.aimed_mult_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update('aimed_i_sigma', self.opt_parameters_widget.i_over_sigma_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update('aimed_completness', self.opt_parameters_widget.aimed_comp_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update('strategy_complexity', self.opt_parameters_widget.start_comp_cbox, int, None) self._char_params_mib.bind_value_update('use_permitted_rotation', self.opt_parameters_widget.permitted_range_cbx, bool, None) self._char_params_mib.bind_value_update('permitted_phi_start', self.opt_parameters_widget.phi_start_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('permitted_phi_end', self.opt_parameters_widget.phi_end_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('low_res_pass_strat', self.opt_parameters_widget.low_res_pass_cbx, bool, None) self._char_params_mib.bind_value_update('rad_suscept', self.rad_dmg_widget.sensetivity_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('beta', self.rad_dmg_widget.beta_over_gray_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('gamma', self.rad_dmg_widget.gamma_over_gray_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('max_crystal_vdim', self.vertical_dimension_widget.max_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('min_crystal_vdim', self.vertical_dimension_widget.min_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('min_crystal_vphi', self.vertical_dimension_widget.min_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update('max_crystal_vphi', self.vertical_dimension_widget.max_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) #self._char_params_mib.bind_value_update('space_group', # self.vertical_dimension_widget.space_group_ledit, # str, # None) self.vertical_dimension_widget.space_group_ledit.\ insertStrList(queue_model_enumerables.XTAL_SPACEGROUPS) qt.QObject.connect(self.char_type_widget.charact_type_tbox, qt.SIGNAL("currentChanged(int)"), self.update_char_type) qt.QObject.connect(self.rad_dmg_char_widget.rad_damage_cbx, qt.SIGNAL("toggled(bool)"), self.enable_opt_parameters_widget) qt.QObject.connect(self.opt_parameters_widget.maximum_res_cbx, qt.SIGNAL("toggled(bool)"), self.enable_maximum_res_ledit) qt.QObject.connect(self.opt_parameters_widget.aimed_mult_cbx, qt.SIGNAL("toggled(bool)"), self.enable_aimed_mult_ledit) qt.QObject.connect(self.path_widget.data_path_widget_layout.prefix_ledit, qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change) qt.QObject.connect(self.path_widget.data_path_widget_layout.run_number_ledit, qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change) qt.QObject.connect(self.vertical_dimension_widget.space_group_ledit, qt.SIGNAL("activated(int)"), self._space_group_change) qt.QObject.connect(qt.qApp, qt.PYSIGNAL('tab_changed'), self.tab_changed) def _space_group_change(self, index): self._char_params.space_group = queue_model_enumerables.\ XTAL_SPACEGROUPS[index] def _set_space_group(self, space_group): index = 0 if space_group in queue_model_enumerables.XTAL_SPACEGROUPS: index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group) self._space_group_change(index) self.vertical_dimension_widget.space_group_ledit.setCurrentItem(index) def _prefix_ledit_change(self, new_value): prefix = self._data_collection.acquisitions[0].\ path_template.get_prefix() self._char.set_name(prefix) self._tree_view_item.setText(0, self._char.get_name()) def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self._char.set_number(int(new_value)) self._tree_view_item.setText(0, self._char.get_name()) def enable_aimed_mult_ledit(self, state): self.opt_parameters_widget.aimed_mult_ledit.setEnabled(state) def enable_maximum_res_ledit(self, state): self.opt_parameters_widget.maximum_res_ledit.setEnabled(state) def update_char_type(self, index): self._char_params.experiment_type = index def toggle_permitted_range(self, status): self.opt_parameters_widget.phi_start_ledit.setEnabled(status) self.opt_parameters_widget.phi_end_ledit.setEnabled(status) def enable_opt_parameters_widget(self, state): self.opt_parameters_widget.setEnabled(not state) def tab_changed(self): if self._tree_view_item: self.populate_parameter_widget(self._tree_view_item) def populate_parameter_widget(self, tree_view_item): self._tree_view_item = tree_view_item self._char = tree_view_item.get_model() self._data_collection = self._char.reference_image_collection self._char_params = self._char.characterisation_parameters self._char_params_mib.set_model(self._char.characterisation_parameters) self._set_space_group(self._char_params.space_group) self.acq_widget.update_data_model(self._char.reference_image_collection.\ acquisitions[0].acquisition_parameters, self._char.reference_image_collection.\ acquisitions[0].path_template) self.path_widget.update_data_model(self._char.reference_image_collection.\ acquisitions[0].path_template) if self._data_collection.acquisitions[0].acquisition_parameters.\ centred_position.snapshot_image: image = self._data_collection.acquisitions[0].\ acquisition_parameters.centred_position.snapshot_image image = image.scale(427, 320) self.position_widget.svideo.setPixmap(qt.QPixmap(image)) self.toggle_permitted_range(self._char_params.use_permitted_rotation) self.enable_opt_parameters_widget(self._char_params.determine_rad_params) self.enable_maximum_res_ledit(self._char_params.use_aimed_resolution) self.enable_aimed_mult_ledit(self._char_params.use_aimed_multiplicity) item = self.char_type_widget.charact_type_tbox.\ item(self._char_params.experiment_type) self.char_type_widget.charact_type_tbox.setCurrentItem(item) self.char_type_widget.toggle_time_dose() crystal = self._char.reference_image_collection.crystal self.acq_widget.set_energies(crystal.energy_scan_result)
class AcquisitionWidgetSimple(qt.QWidget): def __init__(self, parent=None, name=None, fl=0, acq_params=None, path_template=None, layout=None): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # if acq_params is None: self._acquisition_parameters = queue_model_objects.AcquisitionParameters( ) else: self._acquisition_parameters = acq_params if path_template is None: self._path_template = queue_model_objects.PathTemplate() else: self._path_template = path_template self._acquisition_mib = DataModelInputBinder( self._acquisition_parameters) # # Layout # h_layout = qt.QHBoxLayout(self) current_dir = os.path.dirname(__file__) ui_file = 'ui_files/acquisition_widget_vertical_simple_layout.ui' widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) h_layout.addWidget(widget) self.acq_widget_layout = widget # # Logic # self.acq_widget_layout.child('kappa_ledit').setEnabled(False) self.acq_widget_layout.child('kappa_phi_ledit').setEnabled(False) self.acq_widget_layout.child('osc_start_ledit').setEnabled(False) # Default to 2-images self.acq_widget_layout.child('num_images_cbox').setCurrentItem(1) qt.QObject.connect(self.acq_widget_layout.child('num_images_cbox'), qt.SIGNAL("activated(int)"), self.update_num_images) def osc_start_cbox_click(self, state): self.update_osc_start(self._beamline_setup._get_omega_axis_position()) self.acq_widget_layout.child('osc_start_ledit').setEnabled(state) def update_osc_start(self, new_value): if not self.acq_widget_layout.child('osc_start_cbox').isChecked(): osc_start_ledit = self.acq_widget_layout.child('osc_start_ledit') osc_start_value = 0 try: osc_start_value = round(float(new_value), 2) except TypeError: pass osc_start_ledit.setText("%.2f" % osc_start_value) self._acquisition_parameters.osc_start = osc_start_value def update_kappa(self, new_value): self.acq_widget_layout.child('kappa_ledit').\ setText("%.2f" % float(new_value)) def update_kappa_phi(self, new_value): self.acq_widget_layout.child('kappa_phi_ledit').\ setText("%.2f" % float(new_value)) def use_kappa(self, state): self.acq_widget_layout.child('kappa_ledit').setDisabled(state) def use_kappa_phi(self, state): self.acq_widget_layout.child('kappa_phi_ledit').setDisabled(state) def update_num_images(self, index=None, num_images=None): if index is not None: if index is 0: self._acquisition_parameters.num_images = 1 self._path_template.num_files = 1 elif index is 1: self._acquisition_parameters.num_images = 2 self._path_template.num_files = 2 elif index is 2: self._acquisition_parameters.num_images = 4 self._path_template.num_files = 4 if num_images: if self.acq_widget_layout.child('num_images_cbox').count() > 3: self.acq_widget_layout.child('num_images_cbox').removeItem(4) if num_images is 1: self.acq_widget_layout.child('num_images_cbox').setCurrentItem( 0) elif num_images is 2: self.acq_widget_layout.child('num_images_cbox').setCurrentItem( 1) elif num_images is 4: self.acq_widget_layout.child('num_images_cbox').setCurrentItem( 2) else: self.acq_widget_layout.child('num_images_cbox').insertItem( str(num_images)) self.acq_widget_layout.child('num_images_cbox').setCurrentItem( 3) self._path_template.num_files = num_images def use_mad(self, state): pass def get_mad_energy(self): pass def set_energies(self, energy_scan_result): pass def energy_selected(self, index): pass def set_beamline_setup(self, beamline_setup): self._beamline_setup = beamline_setup limits_dict = self._beamline_setup.get_acquisition_limit_values() if 'osc_range' in limits_dict: limits = tuple(map(float, limits_dict['osc_range'].split(','))) (lower, upper) = limits osc_start_validator = qt.QDoubleValidator(lower, upper, 4, self) osc_range_validator = qt.QDoubleValidator(lower, upper, 4, self) else: osc_start_validator = qt.QDoubleValidator(-10000, 10000, 4, self) osc_range_validator = qt.QDoubleValidator(-10000, 10000, 4, self) osc_start_ledit = self.acq_widget_layout.child('osc_start_ledit') self._acquisition_mib.bind_value_update('osc_start', osc_start_ledit, float, osc_start_validator) osc_range_ledit = self.acq_widget_layout.child('osc_range_ledit') self._acquisition_mib.bind_value_update('osc_range', osc_range_ledit, float, osc_range_validator) if 'exposure_time' in limits_dict: limits = tuple(map(float, limits_dict['exposure_time'].split(','))) (lower, upper) = limits exp_time_valdidator = qt.QDoubleValidator(lower, upper, 5, self) else: exp_time_valdidator = qt.QDoubleValidator(-0.003, 6000, 5, self) exp_time_ledit = self.acq_widget_layout.child('exp_time_ledit') self._acquisition_mib.bind_value_update('exp_time', exp_time_ledit, float, exp_time_valdidator) self._acquisition_mib.\ bind_value_update('energy', self.acq_widget_layout.child('energy_ledit'), float, qt.QDoubleValidator(0, 1000, 4, self)) self._acquisition_mib.\ bind_value_update('transmission', self.acq_widget_layout.child('transmission_ledit'), float, qt.QDoubleValidator(0, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('resolution', self.acq_widget_layout.child('resolution_ledit'), float, qt.QDoubleValidator(0, 1000, 3, self)) qt.QObject.connect(self.acq_widget_layout.child('osc_start_cbox'), qt.SIGNAL("toggled(bool)"), self.osc_start_cbox_click) te = beamline_setup.tunable_wavelength() self.set_tunable_energy(te) has_aperture = self._beamline_setup.has_aperture() self.hide_aperture(has_aperture) def set_energy(self, energy, wav): self._acquisition_parameters.energy = energy self.acq_widget_layout.child('energy_ledit').setText("%.4f" % float(energy)) def update_transmission(self, transmission): self.acq_widget_layout.child('transmission_ledit').\ setText("%.2f" % float(transmission)) self._acquisition_parameters.transmission = float(transmission) def update_resolution(self, resolution): self.acq_widget_layout.child('resolution_ledit').\ setText("%.3f" % float(resolution)) self._acquisition_parameters.resolution = float(resolution) def update_data_model(self, acquisition_parameters, path_template): self._acquisition_parameters = acquisition_parameters self._acquisition_mib.set_model(acquisition_parameters) self._path_template = path_template self.update_num_images(None, acquisition_parameters.num_images) def set_tunable_energy(self, state): self.acq_widget_layout.child('energy_ledit').setEnabled(state) def hide_aperture(self, state): if state: self.acq_widget_layout.child('aperture_ledit').show() self.acq_widget_layout.child('aperture_cbox').show() else: self.acq_widget_layout.child('aperture_ledit').hide() self.acq_widget_layout.child('aperture_cbox').hide() def use_osc_start(self, state): self.acq_widget_layout.child('osc_start_cbox').setChecked(state) self.acq_widget_layout.child('osc_start_cbox').setDisabled(state) def check_parameter_conflict(self): return len(self._acquisition_mib.validate_all()) > 0
class SampleDetailsBrick(BaseComponents.BlissWidget): def __init__(self, *args): BaseComponents.BlissWidget.__init__(self, *args) # # Data attributes # self.sample = queue_model_objects.Sample() self.crystal = self.sample.crystals[0] self.sample_mib = DataModelInputBinder(self.sample) self.crystal_mib = DataModelInputBinder(self.crystal) # # Qt - Signals/Slots # self.defineSlot("populate_sample_details", ({})) # # Layout # main_layout = qt.QHBoxLayout(self, 11, 15, "main_layout") self.crystal_widget = CrystalWidgetLayout(self) self.sample_info_widget = SampleInfoWidgetLayout(self) main_layout.addWidget(self.sample_info_widget) main_layout.addWidget(self.crystal_widget) main_layout.addStretch(10) self.crystal_mib.bind_value_update( "space_group", self.crystal_widget.space_group_value_label, str, None ) self.crystal_mib.bind_value_update( "protein_acronym", self.crystal_widget.protein_acronym_value_label, str, None, ) self.crystal_mib.bind_value_update( "cell_a", self.crystal_widget.a_value_label, str, None ) self.crystal_mib.bind_value_update( "cell_alpha", self.crystal_widget.alpha_value_label, str, None ) self.crystal_mib.bind_value_update( "cell_b", self.crystal_widget.b_value_label, str, None ) self.crystal_mib.bind_value_update( "cell_beta", self.crystal_widget.beta_value_label, str, None ) self.crystal_mib.bind_value_update( "cell_c", self.crystal_widget.c_value_label, str, None ) self.crystal_mib.bind_value_update( "cell_gamma", self.crystal_widget.gamma_value_label, str, None ) self.sample_mib.bind_value_update( "name", self.sample_info_widget.name_value_label, str, None ) self.sample_mib.bind_value_update( "code", self.sample_info_widget.data_matrix_value_label, str, None ) self.sample_mib.bind_value_update( "holder_length", self.sample_info_widget.holder_length_value_label, str, None, ) self.sample_mib.bind_value_update( "lims_sample_location", self.sample_info_widget.sample_location_value_label, str, None, ) self.sample_mib.bind_value_update( "lims_container_location", self.sample_info_widget.basket_location_value_label, str, None, ) def populate_sample_details(self, sample): self.sample = sample self.crystal = sample.crystals[0] self.crystal_mib.set_model(self.crystal) self.sample_mib.set_model(sample)
class AcquisitionWidgetSimple(qt.QWidget): def __init__(self, parent = None, name = None, fl = 0, acq_params = None, path_template = None, layout = None): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # if acq_params is None: self._acquisition_parameters = queue_model_objects.AcquisitionParameters() else: self._acquisition_parameters = acq_params if path_template is None: self._path_template = queue_model_objects.PathTemplate() else: self._path_template = path_template self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters) # # Layout # h_layout = qt.QHBoxLayout(self) current_dir = os.path.dirname(__file__) ui_file = 'ui_files/acquisition_widget_vertical_simple_layout.ui' widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0,0)) h_layout.addWidget(widget) self.acq_widget_layout = widget # # Logic # self._acquisition_mib.\ bind_value_update('exp_time', self.acq_widget_layout.child('exp_time_ledit'), float, qt.QDoubleValidator(0.001, 6000, 3, self)) self._acquisition_mib.\ bind_value_update('osc_range', self.acq_widget_layout.child('osc_range_ledit'), float, qt.QDoubleValidator(0.001, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('osc_start', self.acq_widget_layout.child('osc_start_ledit'), float, qt.QDoubleValidator(-1000, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('energy', self.acq_widget_layout.child('energy_ledit'), float, qt.QDoubleValidator(0, 1000, 4, self)) self._acquisition_mib.\ bind_value_update('transmission', self.acq_widget_layout.child('transmission_ledit'), float, qt.QDoubleValidator(0, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('resolution', self.acq_widget_layout.child('resolution_ledit'), float, qt.QDoubleValidator(0, 1000, 3, self)) qt.QObject.connect(self.acq_widget_layout.child('osc_start_cbox'), qt.SIGNAL("toggled(bool)"), self.osc_start_cbox_click) self.acq_widget_layout.child('osc_start_ledit').setEnabled(False) # Default to 2-images self.acq_widget_layout.child('num_images_cbox').setCurrentItem(1) qt.QObject.connect(self.acq_widget_layout.child('num_images_cbox'), qt.SIGNAL("activated(int)"), self.update_num_images) def osc_start_cbox_click(self, state): self.update_osc_start(self._beamline_setup._get_omega_axis_position()) self.acq_widget_layout.child('osc_start_ledit').setEnabled(state) def update_osc_start(self, new_value): if not self.acq_widget_layout.child('osc_start_cbox').isChecked(): osc_start_ledit = self.acq_widget_layout.child('osc_start_ledit') osc_start_value = 0 try: osc_start_value = round(float(new_value),2) except TypeError: pass osc_start_ledit.setText("%.2f" % osc_start_value) self._acquisition_parameters.osc_start = osc_start_value def update_num_images(self, index = None, num_images = None): if index is not None: if index is 0: self._acquisition_parameters.num_images = 1 self._path_template.num_files = 1 elif index is 1: self._acquisition_parameters.num_images = 2 self._path_template.num_files = 2 elif index is 2: self._acquisition_parameters.num_images = 4 self._path_template.num_files = 4 if num_images: if self.acq_widget_layout.child('num_images_cbox').count() > 3: self.acq_widget_layout.child('num_images_cbox').removeItem(4) if num_images is 1: self.acq_widget_layout.child('num_images_cbox').setCurrentItem(0) elif num_images is 2: self.acq_widget_layout.child('num_images_cbox').setCurrentItem(1) elif num_images is 4: self.acq_widget_layout.child('num_images_cbox').setCurrentItem(2) else: self.acq_widget_layout.child('num_images_cbox').insertItem(str(num_images)) self.acq_widget_layout.child('num_images_cbox').setCurrentItem(3) self._path_template.num_files = num_images def use_mad(self, state): pass def get_mad_energy(self): pass def set_energies(self, energy_scan_result): pass def energy_selected(self, index): pass def set_beamline_setup(self, beamline_setup): self._beamline_setup = beamline_setup te = beamline_setup.tunable_wavelength() self.set_tunable_energy(te) has_aperture = self._beamline_setup.has_aperture() self.hide_aperture(has_aperture) def set_energy(self, energy, wav): self._acquisition_parameters.energy = energy self.acq_widget_layout.child('energy_ledit').setText("%.4f" % float(energy)) def update_transmission(self, transmission): self.acq_widget_layout.child('transmission_ledit').\ setText("%.2f" % float(transmission)) self._acquisition_parameters.transmission = float(transmission) def update_resolution(self, resolution): self.acq_widget_layout.child('resolution_ledit').\ setText("%.3f" % float(resolution)) self._acquisition_parameters.resolution = float(resolution) def update_data_model(self, acquisition_parameters, path_template): self._acquisition_parameters = acquisition_parameters self._acquisition_mib.set_model(acquisition_parameters) self._path_template = path_template self.update_num_images(None, acquisition_parameters.num_images) def set_tunable_energy(self, state): self.acq_widget_layout.child('energy_ledit').setEnabled(state) def hide_aperture(self, state): if state: self.acq_widget_layout.child('aperture_ledit').show() self.acq_widget_layout.child('aperture_cbox').show() else: self.acq_widget_layout.child('aperture_ledit').hide() self.acq_widget_layout.child('aperture_cbox').hide() def use_osc_start(self, state): self.acq_widget_layout.child('osc_start_cbox').setChecked(state) self.acq_widget_layout.child('osc_start_cbox').setDisabled(state)
class CreateXRFSpectrumWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, "XRF-spectrum") self.count_time = None # Data attributes self.init_models() xrfspectrum_model = queue_model_objects.XRFSpectrum() self.xrfspectrum_mib = DataModelInputBinder(xrfspectrum_model) # Layout v_layout = qt.QVBoxLayout(self, 2, 6, "main_v_layout") self._data_path_gbox = qt.QVGroupBox("Data location", self, "data_path_gbox") self._data_path_widget = DataPathWidget( self._data_path_gbox, data_model=self._path_template, layout="vertical" ) parameters_hor_gbox = qt.QHGroupBox("Parameters", self) self.count_time_label = qt.QLabel("Count time", parameters_hor_gbox) self.count_time_label.setFixedWidth(83) self.count_time_ledit = qt.QLineEdit( "1.0", parameters_hor_gbox, "count_time_ledit" ) self.count_time_ledit.setFixedWidth(50) self.xrfspectrum_mib.bind_value_update( "count_time", self.count_time_ledit, float ) # , spacer = qt.QWidget(parameters_hor_gbox) spacer.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) v_layout.addWidget(self._data_path_gbox) v_layout.addWidget(parameters_hor_gbox) v_layout.addStretch() self.connect( self._data_path_widget.data_path_widget_layout.child("run_number_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change, ) self.connect( self._data_path_widget.data_path_widget_layout.child("prefix_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change, ) self.connect( self._data_path_widget, qt.PYSIGNAL("path_template_changed"), self.handle_path_conflict, ) def init_models(self): CreateTaskBase.init_models(self) self._path_template.start_num = 1 self._path_template.num_files = 1 self._path_template.suffix = "raw" def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.XRFSpectrumQueueItem): xrfspectrum_model = tree_item.get_model() self.xrfspectrum_mib.set_model(xrfspectrum_model) if xrfspectrum_model.is_executed(): self.setDisabled(True) else: self.setDisabled(False) if xrfspectrum_model.get_path_template(): self._path_template = xrfspectrum_model.get_path_template() self._data_path_widget.update_data_model(self._path_template) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif not ( isinstance(tree_item, queue_item.SampleQueueItem) or isinstance(tree_item, queue_item.DataCollectionGroupQueueItem) ): self.setDisabled(True) def approve_creation(self): result = CreateTaskBase.approve_creation(self) selected_shapes = self._shape_history.selected_shapes for shape in selected_shapes: if isinstance(shape, shape_history.Line) or isinstance( shape, shape_history.CanvasGrid ): result = False self.count_time = None try: self.count_time = float(str(self.count_time_ledit.text())) except BaseException: logging.getLogger("user_level_log").info("Incorrect count time value.") return result and self.count_time # Called by the owning widget (task_toolbox_widget) to create # a collection. When a data collection group is selected. def _create_task(self, sample, shape): data_collections = [] if self.count_time is not None: if not shape: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = self._shape_history.get_snapshot([]) else: # Shapes selected and sample is mounted, get the # centred positions for the shapes if isinstance(shape, shape_history.Point): snapshot = self._shape_history.get_snapshot([shape.qub_point]) cpos = copy.deepcopy(shape.get_centred_positions()[0]) cpos.snapshot_image = snapshot path_template = self._create_path_template(sample, self._path_template) xrf_spectrum = queue_model_objects.XRFSpectrum(sample, path_template, cpos) xrf_spectrum.set_name(path_template.get_prefix()) xrf_spectrum.set_number(path_template.run_number) xrf_spectrum.count_time = self.count_time data_collections.append(xrf_spectrum) self._path_template.run_number += 1 else: logging.getLogger("user_level_log").info("Incorrect count time value") return data_collections # Called by the owning widget (task_toolbox_widget) when # one or several centred positions are selected. def centred_position_selection(self, positions): self._selected_positions = positions if len(self._current_selected_items) == 1 and len(positions) == 1: item = self._current_selected_items[0] pos = positions[0] if isinstance(pos, shape_history.Point): if isinstance(item, queue_item.XRFSpectrumQueueItem): cpos = pos.get_centred_positions()[0] snapshot = self._shape_history.get_snapshot([pos.qub_point]) cpos.snapshot_image = snapshot item.get_model().centred_position = cpos
class CreateXRFScanWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, 'XRF-scan') self.count_time = None # Data attributes self.init_models() xrfscan_model = queue_model_objects.XRFScan() self.xrfscan_mib = DataModelInputBinder(xrfscan_model) #Layout v_layout = qt.QVBoxLayout(self, 2, 6, "main_v_layout") self._data_path_gbox = qt.QVGroupBox('Data location', self, 'data_path_gbox') self._data_path_widget = DataPathWidget(self._data_path_gbox, data_model=self._path_template, layout='vertical') parameters_hor_gbox = qt.QHGroupBox('Parameters', self) self.count_time_label = qt.QLabel("Count time", parameters_hor_gbox) self.count_time_label.setFixedWidth(83) self.count_time_ledit = qt.QLineEdit("1.0", parameters_hor_gbox, "count_time_ledit") self.count_time_ledit.setFixedWidth(50) self.xrfscan_mib.bind_value_update('count_time', self.count_time_ledit, float) #, spacer = qt.QWidget(parameters_hor_gbox) spacer.setSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Fixed) v_layout.addWidget(self._data_path_gbox) v_layout.addWidget(parameters_hor_gbox) v_layout.addStretch() self.connect( self._data_path_widget.data_path_widget_layout.child( 'run_number_ledit'), qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change) self.connect( self._data_path_widget.data_path_widget_layout.child( 'prefix_ledit'), qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change) self.connect(self._data_path_widget, qt.PYSIGNAL("path_template_changed"), self.handle_path_conflict) def init_models(self): CreateTaskBase.init_models(self) self._path_template.start_num = 1 self._path_template.num_files = 1 self._path_template.suffix = 'raw' def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.XRFScanQueueItem): xrfscan_model = tree_item.get_model() self.xrfscan_mib.set_model(xrfscan_model) if xrfscan_model.is_executed(): self.setDisabled(True) else: self.setDisabled(False) if xrfscan_model.get_path_template(): self._path_template = xrfscan_model.get_path_template() self._data_path_widget.update_data_model(self._path_template) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif not(isinstance(tree_item, queue_item.SampleQueueItem) or \ isinstance(tree_item, queue_item.DataCollectionGroupQueueItem)): self.setDisabled(True) def approve_creation(self): result = CreateTaskBase.approve_creation(self) selected_shapes = self._shape_history.selected_shapes for shape in selected_shapes: if (isinstance(shape, shape_history.Line) or isinstance(shape, shape_history.CanvasGrid)): result = False self.count_time = None try: self.count_time = float(str(self.count_time_ledit.text())) except: logging.getLogger("user_level_log").\ info("Incorrect count time value.") return result and self.count_time # Called by the owning widget (task_toolbox_widget) to create # a collection. When a data collection group is selected. def _create_task(self, sample, shape): data_collections = [] if self.count_time is not None: if not shape: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = self._shape_history.get_snapshot([]) else: # Shapes selected and sample is mounted, get the # centred positions for the shapes if isinstance(shape, shape_history.Point): snapshot = self._shape_history.\ get_snapshot([shape.qub_point]) cpos = copy.deepcopy(shape.get_centred_positions()[0]) cpos.snapshot_image = snapshot path_template = self._create_path_template(sample, self._path_template) xrf_scan = queue_model_objects.XRFScan(sample, path_template, cpos) xrf_scan.set_name(path_template.get_prefix()) xrf_scan.set_number(path_template.run_number) xrf_scan.count_time = self.count_time data_collections.append(xrf_scan) self._path_template.run_number += 1 else: logging.getLogger("user_level_log").\ info("Incorrect count time value") return data_collections # Called by the owning widget (task_toolbox_widget) when # one or several centred positions are selected. def centred_position_selection(self, positions): self._selected_positions = positions if len(self._current_selected_items) == 1 and len(positions) == 1: item = self._current_selected_items[0] pos = positions[0] if isinstance(pos, shape_history.Point): if isinstance(item, queue_item.XRFScanQueueItem): cpos = pos.get_centred_positions()[0] snapshot = self._shape_history.get_snapshot( [pos.qub_point]) cpos.snapshot_image = snapshot item.get_model().centred_position = cpos
class AcquisitionWidget(qt.QWidget): def __init__(self, parent=None, name=None, fl=0, acq_params=None, path_template=None, layout='horizontal'): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # self._beamline_setup = None self.previous_energy = 0 if acq_params is None: self._acquisition_parameters = queue_model_objects.\ AcquisitionParameters() else: self._acquisition_parameters = acq_params if path_template is None: self._path_template = queue_model_objects.PathTemplate() else: self._path_template = path_template self._acquisition_mib = DataModelInputBinder(self._acquisition_parameters) #self._path_template_mib = DataModelInputBinder(self._path_template) # # Layout # h_layout = qt.QHBoxLayout(self) if layout == 'vertical': widget = qtui.QWidgetFactory.\ create(os.path.join(os.path.dirname(__file__), 'ui_files/acquisition_widget_vertical_layout.ui')) elif layout == 'horizontal': widget = qtui.QWidgetFactory.\ create(os.path.join(os.path.dirname(__file__), 'ui_files/acquisition_widget_horizontal_layout.ui')) widget.child('inverse_beam_cbx').hide() widget.child('subwedge_size_label').hide() widget.child('subwedge_size_ledit').hide() else: widget = qtui.QWidgetFactory.\ create(os.path.join(os.path.dirname(__file__), 'ui_files/acquisition_widget_vertical_layout.ui')) widget.reparent(self, qt.QPoint(0, 0)) self.acq_widget_layout = widget h_layout.addWidget(self.acq_widget_layout) # # Logic # self._acquisition_mib.\ bind_value_update('osc_start', self.acq_widget_layout.child('osc_start_ledit'), float, qt.QDoubleValidator(-10000, 10000, 2, self)) self._acquisition_mib.\ bind_value_update('first_image', self.acq_widget_layout.child('first_image_ledit'), int, qt.QIntValidator(1, 9999, self)) self._acquisition_mib.\ bind_value_update('exp_time', self.acq_widget_layout.child('exp_time_ledit'), float, qt.QDoubleValidator(0.003, 6000, 3, self)) self._acquisition_mib.\ bind_value_update('osc_range', self.acq_widget_layout.child('osc_range_ledit'), float, qt.QDoubleValidator(0.001, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('num_images', self.acq_widget_layout.child('num_images_ledit'), int, qt.QIntValidator(1, 9999, self)) self._acquisition_mib.\ bind_value_update('num_passes', self.acq_widget_layout.child('num_passes_ledit'), int, qt.QIntValidator(1, 1000, self)) self._acquisition_mib.\ bind_value_update('overlap', self.acq_widget_layout.child('overlap_ledit'), float, qt.QDoubleValidator(-1000, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('energy', self.acq_widget_layout.child('energy_ledit'), float, qt.QDoubleValidator(0, 1000, 4, self)) self._acquisition_mib.\ bind_value_update('transmission', self.acq_widget_layout.child('transmission_ledit'), float, qt.QDoubleValidator(0, 1000, 2, self)) self._acquisition_mib.\ bind_value_update('resolution', self.acq_widget_layout.child('resolution_ledit'), float, qt.QDoubleValidator(0, 1000, 3, self)) self._acquisition_mib.\ bind_value_update('inverse_beam', self.acq_widget_layout.child('inverse_beam_cbx'), bool, None) self._acquisition_mib.\ bind_value_update('shutterless', self.acq_widget_layout.child('shutterless_cbx'), bool, None) qt.QObject.connect(self.acq_widget_layout.child('energies_combo'), qt.SIGNAL("activated(int)"), self.energy_selected) qt.QObject.connect(self.acq_widget_layout.child('mad_cbox'), qt.SIGNAL("toggled(bool)"), self.use_mad) qt.QObject.connect(self.acq_widget_layout.child('inverse_beam_cbx'), qt.SIGNAL("toggled(bool)"), self.set_use_inverse_beam) qt.QObject.connect(self.acq_widget_layout.child('first_image_ledit'), qt.SIGNAL("textChanged(const QString &)"), self.first_image_ledit_change) qt.QObject.connect(self.acq_widget_layout.child('num_images_ledit'), qt.SIGNAL("textChanged(const QString &)"), self.num_images_ledit_change) qt.QObject.connect(self.acq_widget_layout.child('overlap_ledit'), qt.SIGNAL("textChanged(const QString &)"), self.overlap_changed) qt.QObject.connect(self.acq_widget_layout.child('subwedge_size_ledit'), qt.SIGNAL("textChanged(const QString &)"), self.subwedge_size_ledit_change) qt.QObject.connect(self.acq_widget_layout.child('osc_start_cbox'), qt.SIGNAL("toggled(bool)"), self.osc_start_cbox_click) self.acq_widget_layout.child('subwedge_size_ledit').setDisabled(True) self.acq_widget_layout.child('energies_combo').setDisabled(True) self.acq_widget_layout.child('energies_combo').\ insertStrList(['ip: -', 'pk: -', 'rm1: -', 'rm2: -']) self.acq_widget_layout.child('osc_start_ledit').setEnabled(False) def osc_start_cbox_click(self, state): self.update_osc_start(self._beamline_setup._get_omega_axis_position()) self.acq_widget_layout.child('osc_start_ledit').setEnabled(state) def update_osc_start(self, new_value): if not self.acq_widget_layout.child('osc_start_cbox').isChecked(): osc_start_ledit = self.acq_widget_layout.child('osc_start_ledit') osc_start_value = 0 try: osc_start_value = round(float(new_value),2) except TypeError: pass osc_start_ledit.setText("%.2f" % osc_start_value) self._acquisition_parameters.osc_start = osc_start_value def use_osc_start(self, state): self.acq_widget_layout.child('osc_start_cbox').setChecked(state) self.acq_widget_layout.child('osc_start_cbox').setDisabled(state) def set_beamline_setup(self, beamline_setup): self._beamline_setup = beamline_setup te = beamline_setup.tunable_wavelength() self.set_tunable_energy(te) has_shutter_less = self._beamline_setup.detector_has_shutterless() self.acq_widget_layout.child('shutterless_cbx').\ setEnabled(has_shutter_less) self.acq_widget_layout.child('shutterless_cbx').setChecked(has_shutter_less) if self._beamline_setup.disable_num_passes(): self.acq_widget_layout.child('num_passes_ledit').setDisabled(True) has_aperture = self._beamline_setup.has_aperture() self.hide_aperture(has_aperture) def first_image_ledit_change(self, new_value): if str(new_value).isdigit(): self._path_template.start_num = int(new_value) widget = self.acq_widget_layout.child('first_image_ledit') self.emit(qt.PYSIGNAL('path_template_changed'), (widget, new_value)) def num_images_ledit_change(self, new_value): if str(new_value).isdigit(): self._path_template.num_files = int(new_value) widget = self.acq_widget_layout.child('num_images_ledit') self.emit(qt.PYSIGNAL('path_template_changed'), (widget, new_value)) def overlap_changed(self, new_value): if self._beamline_setup: has_shutter_less = self._beamline_setup.detector_has_shutterless() else: has_shutter_less = True if has_shutter_less: try: new_value = float(new_value) except ValueError: pass if new_value != 0: self.acq_widget_layout.child('shutterless_cbx').\ setEnabled(False) self.acq_widget_layout.child('shutterless_cbx').setChecked(False) self._acquisition_parameters.shutterless = False else: self.acq_widget_layout.child('shutterless_cbx').setEnabled(True) self.acq_widget_layout.child('shutterless_cbx').setChecked(True) self._acquisition_parameters.shutterless = True def use_mad(self, state): self.acq_widget_layout.child('energies_combo').setEnabled(state) if state: (name, energy) = self.get_mad_energy() if energy != 0: self.set_energy(energy, 0) self.emit(qt.PYSIGNAL('mad_energy_selected'), (name, energy, state)) else: self.set_energy(self.previous_energy, 0) energy = self._beamline_setup.energy_hwobj.getCurrentEnergy() self.emit(qt.PYSIGNAL('mad_energy_selected'), ('', self.previous_energy, state)) def set_use_inverse_beam(self, state): if state: self.acq_widget_layout.child('subwedge_size_ledit').setEnabled(True) else: self.acq_widget_layout.child('subwedge_size_ledit').\ setDisabled(True) def use_inverse_beam(self): return self.acq_widget_layout.child('inverse_beam_cbx').isOn() def get_num_subwedges(self): return int(self.acq_widget_layout.child('subwedge_size_ledit').text()) def subwedge_size_ledit_change(self, new_value): widget = self.acq_widget_layout.child('subwedge_size_ledit') if int(new_value) > self._acquisition_parameters.num_images: widget.setPaletteBackgroundColor(widget_colors.LIGHT_RED) else: widget.setPaletteBackgroundColor(widget_colors.WHITE) def get_mad_energy(self): energy_str = str(self.acq_widget_layout.\ child('energies_combo').currentText()) (name, value) = energy_str.split(':') name = name.strip() value = value.strip() value = 0 if (value == '-') else value return (name, value) def set_energies(self, energy_scan_result): self.acq_widget_layout.child('energies_combo').clear() inflection = ('ip: %.4f' % energy_scan_result.inflection) if \ energy_scan_result.inflection else 'ip: -' peak = ('pk: %.4f' % energy_scan_result.peak) if \ energy_scan_result.peak else 'pk: -' first_remote = ('rm1: %.4f' % energy_scan_result.first_remote) if \ energy_scan_result.first_remote else 'rm1: -' second_remote = ('rm2: %.4f' % energy_scan_result.second_remote) if \ energy_scan_result.second_remote else 'rm2: -' self.acq_widget_layout.child('energies_combo').\ insertStrList([inflection, peak, first_remote, second_remote]) def energy_selected(self, index): if self.acq_widget_layout.child('mad_cbox').isChecked(): (name, energy) = self.get_mad_energy() if energy != 0: self.set_energy(energy, 0) self.emit(qt.PYSIGNAL('mad_energy_selected'), (name, energy, True)) def set_energy(self, energy, wav): self._acquisition_parameters.energy = energy self.acq_widget_layout.child('energy_ledit').setText("%.4f" % float(energy)) def update_transmission(self, transmission): self.acq_widget_layout.child('transmission_ledit').\ setText("%.2f" % float(transmission)) self._acquisition_parameters.transmission = float(transmission) def update_resolution(self, resolution): self.acq_widget_layout.child('resolution_ledit').\ setText("%.3f" % float(resolution)) self._acquisition_parameters.resolution = float(resolution) def update_data_model(self, acquisition_parameters, path_template): self._acquisition_parameters = acquisition_parameters self._path_template = path_template self._acquisition_mib.set_model(acquisition_parameters) #Update mad widgets mad = True if self._path_template.mad_prefix != '' else False if mad: mad_prefix = self._path_template.mad_prefix index = MAD_ENERGY_COMBO_NAMES[mad_prefix] self.acq_widget_layout.child('energies_combo').setCurrentItem(index) self.acq_widget_layout.child('mad_cbox').setChecked(True) self.acq_widget_layout.child('energies_combo').setEnabled(True) else: self.acq_widget_layout.child('mad_cbox').setChecked(False) self.acq_widget_layout.child('energies_combo').setEnabled(False) self.acq_widget_layout.child('energies_combo').setCurrentItem(0) def set_tunable_energy(self, state): self.acq_widget_layout.child('energy_ledit').setEnabled(state) self.acq_widget_layout.child('mad_cbox').setEnabled(state) self.acq_widget_layout.child('energies_combo').setEnabled(state) def disable_inverse_beam(self, state): if state: self.acq_widget_layout.child('inverse_beam_cbx').hide() self.acq_widget_layout.child('subwedge_size_label').hide() self.acq_widget_layout.child('subwedge_size_ledit').hide() else: self.acq_widget_layout.child('inverse_beam_cbx').show() self.acq_widget_layout.child('subwedge_size_label').show() self.acq_widget_layout.child('subwedge_size_ledit').show() def hide_aperture(self, state): pass
class DataPathWidget(qt.QWidget): def __init__(self, parent = None, name = '', fl = 0, data_model = None, layout = None): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # self._session_hwobj = None if data_model is None: self._data_model = queue_model_objects.PathTemplate() else: self._data_model = data_model self._data_model_pm = DataModelInputBinder(self._data_model) # # Layout # h_layout = qt.QHBoxLayout(self) if layout is DataPathWidgetHorizontalLayout: self.data_path_widget_layout = layout(self, name) elif layout is DataPathWidgetVerticalLayout: self.data_path_widget_layout = layout(self, name) else: self.data_path_widget_layout = DataPathWidgetHorizontalLayout(self) h_layout.addWidget(self.data_path_widget_layout) # # Logic # self._data_model_pm.bind_value_update('base_prefix', self.data_path_widget_layout.prefix_ledit, str, None) #self._data_model_pm.bind_value_update('directory', # self.data_path_widget_layout.folder_ledit, # str, # None) self._data_model_pm.bind_value_update('run_number', self.data_path_widget_layout.run_number_ledit, int, qt.QIntValidator(0, 1000, self)) qt.QObject.connect(self.data_path_widget_layout.prefix_ledit, qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change) qt.QObject.connect(self.data_path_widget_layout.run_number_ledit, qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change) qt.QObject.connect(self.data_path_widget_layout.browse_button, qt.SIGNAL("clicked()"), self._browse_clicked) qt.QObject.connect(self.data_path_widget_layout.folder_ledit, qt.SIGNAL("textChanged(const QString &)"), self._folder_ledit_change) def set_session(self, session_hwobj): self._session_hwobj = session_hwobj def _browse_clicked(self): get_dir = qt.QFileDialog(self) given_dir = self._session_hwobj.get_base_image_directory() d = str(get_dir.getExistingDirectory(given_dir, self, "", "Select a directory", True, False)) d = os.path.dirname(d) if d is not None and len(d) > 0: self.set_directory(d) def _prefix_ledit_change(self, new_value): self.set_prefix(new_value) self.emit(qt.PYSIGNAL('path_template_changed'), (self.data_path_widget_layout.prefix_ledit, new_value)) def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self.set_run_number(new_value) self.emit(qt.PYSIGNAL('path_template_changed'), (self.data_path_widget_layout.run_number_ledit, new_value)) def _folder_ledit_change(self, new_value): base_image_dir = self._session_hwobj.get_base_image_directory() base_proc_dir = self._session_hwobj.get_base_process_directory() new_sub_dir = str(new_value) if len(new_sub_dir) > 0: if new_sub_dir[0] == '/': new_sub_dir = new_sub_dir[1:] new_image_directory = os.path.join(base_image_dir, str(new_sub_dir)) new_proc_dir = os.path.join(base_proc_dir, str(new_sub_dir)) else: new_image_directory = base_image_dir new_proc_dir = base_proc_dir self._data_model.directory = new_image_directory self._data_model.process_directory = new_proc_dir self.data_path_widget_layout.folder_ledit.\ setPaletteBackgroundColor(widget_colors.WHITE) self.emit(qt.PYSIGNAL('path_template_changed'), (self.data_path_widget_layout.folder_ledit, new_value)) def set_data_path(self, path): (dir_name, file_name) = os.path.split(path) self.set_directory(dir_name) file_name = file_name.replace('%' + self._data_model.precision + 'd', int(self._data_model.precision) * '#' ) self.data_path_widget_layout.file_name_value_label.setText(file_name) def set_directory(self, directory): base_image_dir = self._session_hwobj.get_base_image_directory() dir_parts = directory.split(base_image_dir) if len(dir_parts) > 1: sub_dir = dir_parts[1] self._data_model.directory = directory self.data_path_widget_layout.folder_ledit.setText(sub_dir) #self.data_path_widget_layout.folder_ledit.\ # setPaletteBackgroundColor(widget_colors.WHITE) else: self.data_path_widget_layout.folder_ledit.setText('') #self.data_path_widget_layout.folder_ledit.\ # setPaletteBackgroundColor(widget_colors.LIGHT_RED) self._data_model.directory = base_image_dir #logging.getLogger('user_level_log').\ # info("The selected data location is invalid, please select" \ # " a directory within: " + base_image_dir) self.data_path_widget_layout.base_path_label.setText(base_image_dir) def set_run_number(self, run_number): self._data_model.run_number = int(run_number) self.data_path_widget_layout.run_number_ledit.\ setText(str(run_number)) def set_prefix(self, base_prefix): self._data_model.base_prefix = str(base_prefix) self.data_path_widget_layout.prefix_ledit.setText(str(base_prefix)) file_name = self._data_model.get_image_file_name() file_name = file_name.replace('%' + self._data_model.precision + 'd', int(self._data_model.precision) * '#' ) self.data_path_widget_layout.file_name_value_label.setText(file_name) def update_data_model(self, data_model): self._data_model = data_model self.set_data_path(data_model.get_image_path()) self._data_model_pm.set_model(data_model)
class CharParametersWidget(qt.QWidget): def __init__(self, parent=None, name="parameter_widget"): qt.QWidget.__init__(self, parent, name) # # Private members # self._char = None self._char_params = queue_model_objects.CharacterisationParameters() self._char_params_mib = DataModelInputBinder(self._char_params) self._tree_view_item = None self.previous_energy = None self.add_dc_cb = None self.char_type_widget = CharTypeWidget(self) self.routine_dc_widget = self.char_type_widget.routine_dc_page self.sad_widget = self.char_type_widget.sad_page self.rad_dmg_char_widget = self.char_type_widget.rad_damage_page self.reference_img_widget = ReferenceImageWidget(self) self.acq_widget = self.reference_img_widget.acq_widget self.path_widget = self.reference_img_widget.path_widget self.opt_parameters_widget = OptimisationParametersWidgetLayout(self) self.rad_dmg_widget = RadiationDamageModelWidgetLayout(self) self.position_widget = SnapshotWidgetLayout(self) self.vertical_dimension_widget = VerticalCrystalDimensionWidgetLayout( self) # Fix the widths of the widgets to make the layout look nicer, # and beacuse the qt layout engine is so tremendosly good. self.opt_parameters_widget.setFixedWidth(600) self.reference_img_widget.setFixedWidth(772) # # Layout # v_layout = qt.QVBoxLayout(self, 11, 15, "main_layout") rone_hlayout = qt.QHBoxLayout(v_layout, 15, "rone") rone_cone_vlayout = qt.QVBoxLayout(rone_hlayout, 15, "rone_cone") rtwo_hlayout = qt.QHBoxLayout(v_layout, 15, "rtwo") rthree_hlayout = qt.QHBoxLayout(v_layout, 15, "rtwo") rone_hlayout.addWidget(self.position_widget) rone_cone_vlayout.addWidget(self.reference_img_widget) rone_hlayout.addStretch() rtwo_hlayout.addWidget(self.char_type_widget) rtwo_hlayout.addWidget(self.opt_parameters_widget) rtwo_hlayout.addStretch(10) v_layout.addStretch(10) rthree_hlayout.addWidget(self.rad_dmg_widget) rthree_hlayout.addWidget(self.vertical_dimension_widget) rthree_hlayout.addStretch(10) v_layout.addStretch(10) # # Widget logic # self.toggle_permitted_range(self.\ opt_parameters_widget.permitted_range_cbx.isOn()) qt.QObject.connect(self.opt_parameters_widget.permitted_range_cbx, qt.SIGNAL("toggled(bool)"), self.toggle_permitted_range) self._char_params_mib.bind_value_update( 'min_dose', self.routine_dc_widget.dose_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'min_time', self.routine_dc_widget.time_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'use_min_dose', self.routine_dc_widget.min_dose_radio, bool, None) self._char_params_mib.bind_value_update( 'use_min_time', self.routine_dc_widget.min_time_radio, bool, None) self._char_params_mib.bind_value_update( 'account_rad_damage', self.routine_dc_widget.radiation_damage_cbx, bool, None) self._char_params_mib.bind_value_update( 'auto_res', self.sad_widget.automatic_resolution_radio, bool, None) self._char_params_mib.bind_value_update( 'opt_sad', self.sad_widget.optimal_sad_radio, bool, None) self._char_params_mib.bind_value_update( 'determine_rad_params', self.rad_dmg_char_widget.rad_damage_cbx, bool, None) self._char_params_mib.bind_value_update( 'burn_osc_start', self.rad_dmg_char_widget.burn_osc_start_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'burn_osc_interval', self.rad_dmg_char_widget.burn_osc_interval_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'use_aimed_resolution', self.opt_parameters_widget.maximum_res_cbx, bool, None) self._char_params_mib.bind_value_update( 'use_aimed_multiplicity', self.opt_parameters_widget.aimed_mult_cbx, bool, None) self._char_params_mib.bind_value_update( 'aimed_resolution', self.opt_parameters_widget.maximum_res_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update( 'aimed_multiplicity', self.opt_parameters_widget.aimed_mult_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update( 'aimed_i_sigma', self.opt_parameters_widget.i_over_sigma_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update( 'aimed_completness', self.opt_parameters_widget.aimed_comp_ledit, float, qt.QDoubleValidator(0.01, 1000, 2, self)) self._char_params_mib.bind_value_update( 'strategy_complexity', self.opt_parameters_widget.start_comp_cbox, int, None) self._char_params_mib.bind_value_update( 'use_permitted_rotation', self.opt_parameters_widget.permitted_range_cbx, bool, None) self._char_params_mib.bind_value_update( 'permitted_phi_start', self.opt_parameters_widget.phi_start_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'permitted_phi_end', self.opt_parameters_widget.phi_end_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'low_res_pass_strat', self.opt_parameters_widget.low_res_pass_cbx, bool, None) self._char_params_mib.bind_value_update( 'rad_suscept', self.rad_dmg_widget.sensetivity_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'beta', self.rad_dmg_widget.beta_over_gray_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'gamma', self.rad_dmg_widget.gamma_over_gray_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'max_crystal_vdim', self.vertical_dimension_widget.max_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'min_crystal_vdim', self.vertical_dimension_widget.min_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'min_crystal_vphi', self.vertical_dimension_widget.min_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.bind_value_update( 'max_crystal_vphi', self.vertical_dimension_widget.max_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) #self._char_params_mib.bind_value_update('space_group', # self.vertical_dimension_widget.space_group_ledit, # str, # None) self.vertical_dimension_widget.space_group_ledit.\ insertStrList(queue_model_enumerables.XTAL_SPACEGROUPS) qt.QObject.connect(self.char_type_widget.charact_type_tbox, qt.SIGNAL("currentChanged(int)"), self.update_char_type) qt.QObject.connect(self.rad_dmg_char_widget.rad_damage_cbx, qt.SIGNAL("toggled(bool)"), self.enable_opt_parameters_widget) qt.QObject.connect(self.opt_parameters_widget.maximum_res_cbx, qt.SIGNAL("toggled(bool)"), self.enable_maximum_res_ledit) qt.QObject.connect(self.opt_parameters_widget.aimed_mult_cbx, qt.SIGNAL("toggled(bool)"), self.enable_aimed_mult_ledit) qt.QObject.connect( self.path_widget.data_path_widget_layout.child('prefix_ledit'), qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change) qt.QObject.connect( self.path_widget.data_path_widget_layout.child('run_number_ledit'), qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change) qt.QObject.connect(self.vertical_dimension_widget.space_group_ledit, qt.SIGNAL("activated(int)"), self._space_group_change) qt.QObject.connect(qt.qApp, qt.PYSIGNAL('tab_changed'), self.tab_changed) def _space_group_change(self, index): self._char_params.space_group = queue_model_enumerables.\ XTAL_SPACEGROUPS[index] def _set_space_group(self, space_group): index = 0 if space_group in queue_model_enumerables.XTAL_SPACEGROUPS: index = queue_model_enumerables.XTAL_SPACEGROUPS.index(space_group) self._space_group_change(index) self.vertical_dimension_widget.space_group_ledit.setCurrentItem(index) def _prefix_ledit_change(self, new_value): prefix = self._data_collection.acquisitions[0].\ path_template.get_prefix() self._char.set_name(prefix) self._tree_view_item.setText(0, self._char.get_name()) def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self._char.set_number(int(new_value)) self._tree_view_item.setText(0, self._char.get_name()) def enable_aimed_mult_ledit(self, state): self.opt_parameters_widget.aimed_mult_ledit.setEnabled(state) def enable_maximum_res_ledit(self, state): self.opt_parameters_widget.maximum_res_ledit.setEnabled(state) def update_char_type(self, index): self._char_params.experiment_type = index def toggle_permitted_range(self, status): self.opt_parameters_widget.phi_start_ledit.setEnabled(status) self.opt_parameters_widget.phi_end_ledit.setEnabled(status) def enable_opt_parameters_widget(self, state): if not self._char.is_executed(): self.opt_parameters_widget.setEnabled(not state) else: self.opt_parameters_widget.setEnabled(False) def tab_changed(self): if self._tree_view_item: self.populate_parameter_widget(self._tree_view_item) def set_enabled(self, state): self.char_type_widget.setEnabled(state) self.routine_dc_widget.setEnabled(state) self.sad_widget.setEnabled(state) self.rad_dmg_char_widget.setEnabled(state) self.reference_img_widget.setEnabled(state) self.acq_widget.setEnabled(state) self.path_widget.setEnabled(state) self.opt_parameters_widget.setEnabled(state) self.rad_dmg_widget.setEnabled(state) self.vertical_dimension_widget.setEnabled(state) def populate_parameter_widget(self, tree_view_item): self._tree_view_item = tree_view_item self._char = tree_view_item.get_model() self._data_collection = self._char.reference_image_collection self._char_params = self._char.characterisation_parameters self._char_params_mib.set_model(self._char.characterisation_parameters) self._set_space_group(self._char_params.space_group) self.acq_widget.update_data_model(self._char.reference_image_collection.\ acquisitions[0].acquisition_parameters, self._char.reference_image_collection.\ acquisitions[0].path_template) self.path_widget.update_data_model(self._char.reference_image_collection.\ acquisitions[0].path_template) if self._data_collection.acquisitions[0].acquisition_parameters.\ centred_position.snapshot_image: image = self._data_collection.acquisitions[0].\ acquisition_parameters.centred_position.snapshot_image image = image.scale(427, 320) self.position_widget.svideo.setPixmap(qt.QPixmap(image)) self.toggle_permitted_range(self._char_params.use_permitted_rotation) self.enable_opt_parameters_widget( self._char_params.determine_rad_params) self.enable_maximum_res_ledit(self._char_params.use_aimed_resolution) self.enable_aimed_mult_ledit(self._char_params.use_aimed_multiplicity) item = self.char_type_widget.charact_type_tbox.\ item(self._char_params.experiment_type) self.char_type_widget.charact_type_tbox.setCurrentItem(item) self.char_type_widget.toggle_time_dose() crystal = self._char.reference_image_collection.crystal self.acq_widget.set_energies(crystal.energy_scan_result)
class SampleDetailsBrick(BaseComponents.BlissWidget): def __init__(self, *args): BaseComponents.BlissWidget.__init__(self, *args) # # Data attributes # self.sample = queue_model_objects.Sample() self.crystal = self.sample.crystals[0] self.sample_mib = DataModelInputBinder(self.sample) self.crystal_mib = DataModelInputBinder(self.crystal) # # Qt - Signals/Slots # self.defineSlot("populate_sample_details", ({})) # # Layout # main_layout = qt.QHBoxLayout(self, 11, 15, "main_layout") self.crystal_widget = CrystalWidgetLayout(self) self.sample_info_widget = SampleInfoWidgetLayout(self) main_layout.addWidget(self.sample_info_widget) main_layout.addWidget(self.crystal_widget) main_layout.addStretch(10) self.crystal_mib.bind_value_update( "space_group", self.crystal_widget.space_group_value_label, str, None) self.crystal_mib.bind_value_update( "protein_acronym", self.crystal_widget.protein_acronym_value_label, str, None, ) self.crystal_mib.bind_value_update("cell_a", self.crystal_widget.a_value_label, str, None) self.crystal_mib.bind_value_update( "cell_alpha", self.crystal_widget.alpha_value_label, str, None) self.crystal_mib.bind_value_update("cell_b", self.crystal_widget.b_value_label, str, None) self.crystal_mib.bind_value_update( "cell_beta", self.crystal_widget.beta_value_label, str, None) self.crystal_mib.bind_value_update("cell_c", self.crystal_widget.c_value_label, str, None) self.crystal_mib.bind_value_update( "cell_gamma", self.crystal_widget.gamma_value_label, str, None) self.sample_mib.bind_value_update( "name", self.sample_info_widget.name_value_label, str, None) self.sample_mib.bind_value_update( "code", self.sample_info_widget.data_matrix_value_label, str, None) self.sample_mib.bind_value_update( "holder_length", self.sample_info_widget.holder_length_value_label, str, None, ) self.sample_mib.bind_value_update( "lims_sample_location", self.sample_info_widget.sample_location_value_label, str, None, ) self.sample_mib.bind_value_update( "lims_container_location", self.sample_info_widget.basket_location_value_label, str, None, ) def populate_sample_details(self, sample): self.sample = sample self.crystal = sample.crystals[0] self.crystal_mib.set_model(self.crystal) self.sample_mib.set_model(sample)
class CreateCharWidget(CreateTaskBase): def __init__(self,parent = None,name = None, fl = 0): CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation') if not name: self.setName("create_char_widget") # # Data attributes # self._current_selected_item = None self.init_models() self._char_params_mib = DataModelInputBinder(self._char_params) # # Layout # v_layout = qt.QVBoxLayout(self, 2, 6, "v_layout") self._acq_widget = \ AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters, path_template = self._path_template) current_dir = os.path.dirname(__file__) ui_file = 'ui_files/vertical_crystal_dimension_widget_layout.ui' widget = qtui.QWidgetFactory.\ create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0,0)) self._vertical_dimension_widget = widget ui_file = 'ui_files/characterise_simple_widget_vertical_layout.ui' widget = qtui.QWidgetFactory.\ create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0,0)) self._char_widget = widget self._data_path_gbox = \ qt.QVGroupBox('Data location', self, 'data_path_gbox') self._data_path_widget = \ DataPathWidget(self._data_path_gbox, data_model = self._path_template, layout = DataPathWidgetVerticalLayout) v_layout.addWidget(self._acq_widget) v_layout.addWidget(self._char_widget) v_layout.addWidget(self._vertical_dimension_widget) v_layout.addWidget(self._data_path_gbox) v_layout.addStretch(10) # # Logic # optimised_sad_cbx = self._char_widget.\ child('optimised_sad_cbx') account_rad_dmg_cbx = self._char_widget.\ child('account_rad_dmg_cbx') start_comp_cbox = self._char_widget.child('start_comp_cbox') induced_burn_cbx = self._char_widget.child('induced_burn_cbx') max_vdim_ledit = self._vertical_dimension_widget.\ child('max_vdim_ledit') min_vdim_ledit = self._vertical_dimension_widget.\ child('min_vdim_ledit') min_vphi_ledit = self._vertical_dimension_widget.\ child('min_vphi_ledit') max_vphi_ledit = self._vertical_dimension_widget.\ child('max_vphi_ledit') space_group_ledit = self._vertical_dimension_widget.\ child('space_group_ledit') self._char_params_mib.bind_value_update('opt_sad', optimised_sad_cbx, bool, None) self._char_params_mib.bind_value_update('account_rad_damage', account_rad_dmg_cbx, bool, None) self._char_params_mib.bind_value_update('determine_rad_params', induced_burn_cbx, bool, None) self._char_params_mib.bind_value_update('strategy_complexity', start_comp_cbox, int, None) self._char_params_mib.\ bind_value_update('max_crystal_vdim', max_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.\ bind_value_update('min_crystal_vdim', min_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.\ bind_value_update('min_crystal_vphi', min_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.\ bind_value_update('max_crystal_vphi', max_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) space_group_ledit.insertStrList(XTAL_SPACEGROUPS) prefix_ledit = self._data_path_widget.\ data_path_widget_layout.prefix_ledit run_number_ledit = self._data_path_widget.\ data_path_widget_layout.run_number_ledit self.connect(prefix_ledit, qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change) self.connect(run_number_ledit, qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change) self.connect(space_group_ledit, qt.SIGNAL("activated(int)"), self._space_group_change) self.connect(self._data_path_widget, qt.PYSIGNAL("path_template_changed"), self.handle_path_conflict) self.connect(induced_burn_cbx, qt.SIGNAL("toggled(bool)"), self.use_induced_burn) def use_induced_burn(self, state): self._acquisition_parameters.induce_burn = state def _space_group_change(self, index): self._char_params.space_group = queue_model_enumerables.\ XTAL_SPACEGROUPS[index] def _set_space_group(self, space_group): index = 0 if space_group in XTAL_SPACEGROUPS: index = XTAL_SPACEGROUPS.index(space_group) self._space_group_change(index) self._vertical_dimension_widget.\ child('space_group_ledit').setCurrentItem(index) def init_models(self): CreateTaskBase.init_models(self) self._char = queue_model_objects.Characterisation() self._char_params = self._char.characterisation_parameters self._char_params.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.OSC self._processing_parameters = queue_model_objects.ProcessingParameters() if self._beamline_setup_hwobj is not None: self._acquisition_parameters = self._beamline_setup_hwobj.\ get_default_characterisation_parameters() try: transmission = self._beamline_setup_hwobj.transmission_hwobj.getAttFactor() transmission = round(float(transmission), 1) except AttributeError: transmission = 0 try: resolution = self._beamline_setup_hwobj.resolution_hwobj.getPosition() resolution = round(float(resolution), 4) except AttributeError: resolution = 0 try: energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy() energy = round(float(energy), 2) except AttributeError: energy = 0 self._acquisition_parameters.resolution = resolution self._acquisition_parameters.energy = energy self._acquisition_parameters.transmission = transmission else: self._acquisition_parameters = queue_model_objects.AcquisitionParameters() self._path_template.reference_image_prefix = 'ref' # The num images drop down default value is 1 # we would like it to be 2 self._acquisition_parameters.num_images = 2 self._char.characterisation_software =\ queue_model_enumerables.COLLECTION_ORIGIN.EDNA self._path_template.num_files = 2 self._acquisition_parameters.shutterless = False def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem) or \ isinstance(tree_item, queue_item.DataCollectionGroupQueueItem): self._char_params = copy.deepcopy(self._char_params) self._acquisition_parameters = copy.deepcopy(self._acquisition_parameters) elif isinstance(tree_item, queue_item.CharacterisationQueueItem): self.setDisabled(False) self._char = tree_item.get_model() if self._char.get_path_template(): self._path_template = self._char.get_path_template() self._data_path_widget.update_data_model(self._path_template) data_collection = self._char.reference_image_collection self._char_params = self._char.characterisation_parameters self._acquisition_parameters = data_collection.acquisitions[0].\ acquisition_parameters if len(data_collection.acquisitions) == 1: self.select_shape_with_cpos(self._acquisition_parameters.\ centred_position) self._processing_parameters = data_collection.processing_parameters else: self.setDisabled(True) if isinstance(tree_item, queue_item.SampleQueueItem) or \ isinstance(tree_item, queue_item.DataCollectionGroupQueueItem) or \ isinstance(tree_item, queue_item.CharacterisationQueueItem): self._set_space_group(self._char_params.space_group) self._acq_widget.update_data_model(self._acquisition_parameters, self._path_template) self._char_params_mib.set_model(self._char_params) def update_processing_parameters(self, crystal): self._processing_parameters.space_group = crystal.space_group self._char_params.space_group = crystal.space_group self._processing_parameters.cell_a = crystal.cell_a self._processing_parameters.cell_alpha = crystal.cell_alpha self._processing_parameters.cell_b = crystal.cell_b self._processing_parameters.cell_beta = crystal.cell_beta self._processing_parameters.cell_c = crystal.cell_c self._processing_parameters.cell_gamma = crystal.cell_gamma def approve_creation(self): return CreateTaskBase.approve_creation(self) # Called by the owning widget (task_toolbox_widget) to create # a collection. when a data collection group is selected. def _create_task(self, sample, shape): tasks = [] if not shape: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = self._shape_history.get_snapshot([]) else: # Shapes selected and sample is mounted, get the # centred positions for the shapes if isinstance(shape, shape_history.Point): snapshot = self._shape_history.\ get_snapshot([shape.qub_point]) cpos = shape.get_centred_positions()[0] cpos.snapshot_image = snapshot char_params = copy.deepcopy(self._char_params) # Acquisition for start position acq = queue_model_objects.Acquisition() acq.acquisition_parameters = \ copy.deepcopy(self._acquisition_parameters) acq.acquisition_parameters.collect_agent = \ queue_model_enumerables.COLLECTION_ORIGIN.MXCUBE acq.acquisition_parameters.centred_position = cpos acq.path_template = copy.deepcopy(self._path_template) if '<sample_name>' in acq.path_template.directory: name = sample.get_name().replace(':', '-') acq.path_template.directory = acq.path_template.directory.\ replace('<sample_name>', name) acq.path_template.process_directory = acq.path_template.process_directory.\ replace('<sample_name>', name) if '<acronym>-<name>' in acq.path_template.base_prefix: acq.path_template.base_prefix = self.get_default_prefix(sample) acq.path_template.run_numer = self._beamline_setup_hwobj.queue_model_hwobj.\ get_next_run_number(acq.path_template) processing_parameters = copy.deepcopy(self._processing_parameters) data_collection = queue_model_objects.\ DataCollection([acq], sample.crystals[0], processing_parameters) # Referance images for characterisations should be taken 90 deg apart # this is achived by setting overap to -89 acq.acquisition_parameters.overlap = -89 data_collection.acquisitions[0] = acq data_collection.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF char = queue_model_objects.Characterisation(data_collection, char_params) char.set_name(data_collection.acquisitions[0].\ path_template.get_prefix()) char.set_number(data_collection.acquisitions[0].\ path_template.run_number) tasks.append(char) self._path_template.run_number += 1 return tasks
class CreateCharWidget(CreateTaskBase): def __init__(self, parent=None, name=None, fl=0): CreateTaskBase.__init__(self, parent, name, fl, 'Characterisation') if not name: self.setName("create_char_widget") # # Data attributes # self._current_selected_item = None self.init_models() self._char_params_mib = DataModelInputBinder(self._char_params) # # Layout # v_layout = qt.QVBoxLayout(self, 2, 6, "v_layout") self._acq_widget = \ AcquisitionWidgetSimple(self, acq_params = self._acquisition_parameters, path_template = self._path_template) #self._acq_widget.setFixedHeight(170) current_dir = os.path.dirname(__file__) ui_file = 'ui_files/vertical_crystal_dimension_widget_layout.ui' widget = qtui.QWidgetFactory.create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) self._vertical_dimension_widget = widget ui_file = 'ui_files/characterise_simple_widget_vertical_layout.ui' widget = qtui.QWidgetFactory.\ create(os.path.join(current_dir, ui_file)) widget.reparent(self, qt.QPoint(0, 0)) self._char_widget = widget self._data_path_gbox = \ qt.QVGroupBox('Data location', self, 'data_path_gbox') self._data_path_widget = \ DataPathWidget(self._data_path_gbox, data_model = self._path_template, layout = 'vertical') v_layout.addWidget(self._acq_widget) v_layout.addWidget(self._data_path_gbox) v_layout.addWidget(self._char_widget) v_layout.addWidget(self._vertical_dimension_widget) v_layout.addStretch(100) # # Logic # optimised_sad_cbx = self._char_widget.\ child('optimised_sad_cbx') account_rad_dmg_cbx = self._char_widget.\ child('account_rad_dmg_cbx') start_comp_cbox = self._char_widget.child('start_comp_cbox') #induced_burn_cbx = self._char_widget.child('induced_burn_cbx') max_vdim_ledit = self._vertical_dimension_widget.\ child('max_vdim_ledit') min_vdim_ledit = self._vertical_dimension_widget.\ child('min_vdim_ledit') min_vphi_ledit = self._vertical_dimension_widget.\ child('min_vphi_ledit') max_vphi_ledit = self._vertical_dimension_widget.\ child('max_vphi_ledit') space_group_ledit = self._vertical_dimension_widget.\ child('space_group_ledit') self._char_params_mib.bind_value_update('opt_sad', optimised_sad_cbx, bool, None) self._char_params_mib.bind_value_update('account_rad_damage', account_rad_dmg_cbx, bool, None) #self._char_params_mib.bind_value_update('determine_rad_params', # induced_burn_cbx, # bool, None) self._char_params_mib.bind_value_update('strategy_complexity', start_comp_cbox, int, None) self._char_params_mib.\ bind_value_update('max_crystal_vdim', max_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.\ bind_value_update('min_crystal_vdim', min_vdim_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.\ bind_value_update('min_crystal_vphi', min_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) self._char_params_mib.\ bind_value_update('max_crystal_vphi', max_vphi_ledit, float, qt.QDoubleValidator(0.0, 1000, 2, self)) space_group_ledit.insertStrList(XTAL_SPACEGROUPS) prefix_ledit = self._data_path_widget.\ data_path_widget_layout.child('prefix_ledit') run_number_ledit = self._data_path_widget.\ data_path_widget_layout.child('run_number_ledit') self.connect(prefix_ledit, qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change) self.connect(run_number_ledit, qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change) self.connect(space_group_ledit, qt.SIGNAL("activated(int)"), self._space_group_change) self.connect(self._data_path_widget, qt.PYSIGNAL("path_template_changed"), self.handle_path_conflict) #self.connect(induced_burn_cbx, qt.SIGNAL("toggled(bool)"), # self.use_induced_burn) def use_induced_burn(self, state): self._acquisition_parameters.induce_burn = state def _space_group_change(self, index): self._char_params.space_group = queue_model_enumerables.\ XTAL_SPACEGROUPS[index] def _set_space_group(self, space_group): index = 0 if space_group in XTAL_SPACEGROUPS: index = XTAL_SPACEGROUPS.index(space_group) self._space_group_change(index) self._vertical_dimension_widget.\ child('space_group_ledit').setCurrentItem(index) def init_models(self): CreateTaskBase.init_models(self) self._init_models() def _init_models(self): self._char = queue_model_objects.Characterisation() self._char_params = self._char.characterisation_parameters self._processing_parameters = queue_model_objects.ProcessingParameters( ) if self._beamline_setup_hwobj is not None: self._acquisition_parameters = self._beamline_setup_hwobj.\ get_default_char_acq_parameters() self._char_params = self._beamline_setup_hwobj.\ get_default_characterisation_parameters() try: transmission = self._beamline_setup_hwobj.transmission_hwobj.getAttFactor( ) transmission = round(float(transmission), 1) except AttributeError: transmission = 0 try: resolution = self._beamline_setup_hwobj.resolution_hwobj.getPosition( ) resolution = round(float(resolution), 3) except AttributeError: resolution = 0 try: energy = self._beamline_setup_hwobj.energy_hwobj.getCurrentEnergy( ) energy = round(float(energy), 4) except AttributeError: energy = 0 self._acquisition_parameters.resolution = resolution self._acquisition_parameters.energy = energy self._acquisition_parameters.transmission = transmission else: self._acquisition_parameters = queue_model_objects.AcquisitionParameters( ) self._path_template.reference_image_prefix = 'ref' # The num images drop down default value is 1 # we would like it to be 2 self._acquisition_parameters.num_images = 2 self._char.characterisation_software =\ queue_model_enumerables.COLLECTION_ORIGIN.EDNA self._path_template.num_files = 2 self._acquisition_parameters.shutterless = False def single_item_selection(self, tree_item): CreateTaskBase.single_item_selection(self, tree_item) if isinstance(tree_item, queue_item.SampleQueueItem): self._init_models() self._set_space_group(self._char_params.space_group) self._acq_widget.update_data_model(self._acquisition_parameters, self._path_template) self._char_params_mib.set_model(self._char_params) #self._char_params = copy.deepcopy(self._char_params) #self._acquisition_parameters = copy.deepcopy(self._acquisition_parameters) elif isinstance(tree_item, queue_item.BasketQueueItem): self.setDisabled(False) elif isinstance(tree_item, queue_item.CharacterisationQueueItem): if tree_item.get_model().is_executed(): self.setDisabled(True) else: self.setDisabled(False) self._char = tree_item.get_model() if self._char.get_path_template(): self._path_template = self._char.get_path_template() self._data_path_widget.update_data_model(self._path_template) data_collection = self._char.reference_image_collection self._char_params = self._char.characterisation_parameters self._char_params_mib.set_model(self._char_params) self._acquisition_parameters = data_collection.acquisitions[0].\ acquisition_parameters self._acq_widget.update_data_model(self._acquisition_parameters, self._path_template) self.get_acquisition_widget().use_osc_start(True) if len(data_collection.acquisitions) == 1: self.select_shape_with_cpos(self._acquisition_parameters.\ centred_position) self._processing_parameters = data_collection.processing_parameters else: self.setDisabled(True) def update_processing_parameters(self, crystal): self._processing_parameters.space_group = crystal.space_group self._char_params.space_group = crystal.space_group self._processing_parameters.cell_a = crystal.cell_a self._processing_parameters.cell_alpha = crystal.cell_alpha self._processing_parameters.cell_b = crystal.cell_b self._processing_parameters.cell_beta = crystal.cell_beta self._processing_parameters.cell_c = crystal.cell_c self._processing_parameters.cell_gamma = crystal.cell_gamma def approve_creation(self): return CreateTaskBase.approve_creation(self) selected_shapes = self._shape_history.selected_shapes for shape in selected_shapes: if isinstance(shape, shape_history.Line): result = False return result # Called by the owning widget (task_toolbox_widget) to create # a collection. when a data collection group is selected. def _create_task(self, sample, shape): tasks = [] if not shape: cpos = queue_model_objects.CentredPosition() cpos.snapshot_image = self._shape_history.get_snapshot([]) else: # Shapes selected and sample is mounted, get the # centred positions for the shapes if isinstance(shape, shape_history.Point): snapshot = self._shape_history.\ get_snapshot([shape.qub_point]) #cpos = shape.get_centred_positions()[0] cpos = copy.deepcopy(shape.get_centred_positions()[0]) cpos.snapshot_image = snapshot char_params = copy.deepcopy(self._char_params) acq = self._create_acq(sample) dc = queue_model_objects.\ DataCollection([acq], sample.crystals[0], self._processing_parameters) # Reference images for characterisations should be taken 90 deg apart # this is achived by setting overap to -89 acq.acquisition_parameters.overlap = -89 acq.acquisition_parameters.centred_position = cpos dc.acquisitions[0] = acq dc.experiment_type = queue_model_enumerables.EXPERIMENT_TYPE.EDNA_REF char = queue_model_objects.Characterisation(dc, char_params) char.set_name(dc.acquisitions[0].\ path_template.get_prefix()) char.set_number(dc.acquisitions[0].\ path_template.run_number) tasks.append(char) self._path_template.run_number += 1 return tasks
class DataPathWidget(qt.QWidget): def __init__(self, parent=None, name="", fl=0, data_model=None, layout=None): qt.QWidget.__init__(self, parent, name, fl) # # Attributes # self._base_image_dir = None self._base_process_dir = None self.path_conflict_state = False if data_model is None: self._data_model = queue_model_objects.PathTemplate() else: self._data_model = data_model self._data_model_pm = DataModelInputBinder(self._data_model) # # Layout # h_layout = qt.QHBoxLayout(self) if layout == "vertical": widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/data_path_widget_vertical_layout.ui", ) ) elif layout == "horizontal": widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/data_path_widget_horizontal_layout.ui", ) ) else: widget = qtui.QWidgetFactory.create( os.path.join( os.path.dirname(__file__), "ui_files/data_path_widget_horizontal_layout.ui", ) ) self.data_path_widget_layout = widget widget.reparent(self, qt.QPoint(0, 0)) h_layout.addWidget(self.data_path_widget_layout) # # Logic # self._data_model_pm.bind_value_update( "base_prefix", self.data_path_widget_layout.child("prefix_ledit"), str, None ) self._data_model_pm.bind_value_update( "run_number", self.data_path_widget_layout.child("run_number_ledit"), int, qt.QIntValidator(0, 1000, self), ) qt.QObject.connect( self.data_path_widget_layout.child("prefix_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._prefix_ledit_change, ) qt.QObject.connect( self.data_path_widget_layout.child("run_number_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._run_number_ledit_change, ) qt.QObject.connect( self.data_path_widget_layout.child("browse_button"), qt.SIGNAL("clicked()"), self._browse_clicked, ) qt.QObject.connect( self.data_path_widget_layout.child("folder_ledit"), qt.SIGNAL("textChanged(const QString &)"), self._folder_ledit_change, ) def _browse_clicked(self): get_dir = qt.QFileDialog(self) given_dir = self._base_image_dir d = str( get_dir.getExistingDirectory( given_dir, self, "", "Select a directory", True, False ) ) d = os.path.dirname(d) if d is not None and len(d) > 0: self.set_directory(d) def _prefix_ledit_change(self, new_value): self._data_model.base_prefix = str(new_value) file_name = self._data_model.get_image_file_name() file_name = file_name.replace( "%" + self._data_model.precision + "d", int(self._data_model.precision) * "#", ) file_name = file_name.strip(" ") self.data_path_widget_layout.child("file_name_value_label").setText(file_name) self.emit( qt.PYSIGNAL("path_template_changed"), (self.data_path_widget_layout.child("prefix_ledit"), new_value), ) def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self.set_run_number(new_value) self.emit( qt.PYSIGNAL("path_template_changed"), (self.data_path_widget_layout.child("run_number_ledit"), new_value), ) def _folder_ledit_change(self, new_value): base_image_dir = self._base_image_dir base_proc_dir = self._base_process_dir new_sub_dir = str(new_value).strip(" ") if len(new_sub_dir) > 0: if new_sub_dir[0] == os.path.sep: new_sub_dir = new_sub_dir[1:] new_image_directory = os.path.join(base_image_dir, str(new_sub_dir)) new_proc_dir = os.path.join(base_proc_dir, str(new_sub_dir)) else: new_image_directory = base_image_dir new_proc_dir = base_proc_dir self._data_model.directory = new_image_directory self._data_model.process_directory = new_proc_dir self.data_path_widget_layout.child("folder_ledit").setPaletteBackgroundColor( widget_colors.WHITE ) self.emit( qt.PYSIGNAL("path_template_changed"), (self.data_path_widget_layout.child("folder_ledit"), new_value), ) def set_data_path(self, path): (dir_name, file_name) = os.path.split(path) self.set_directory(dir_name) file_name = file_name.replace( "%" + self._data_model.precision + "d", int(self._data_model.precision) * "#", ) self.data_path_widget_layout.child("file_name_value_label").setText(file_name) def set_directory(self, directory): base_image_dir = self._base_image_dir dir_parts = directory.split(base_image_dir) if len(dir_parts) > 1: sub_dir = dir_parts[1] self._data_model.directory = directory self.data_path_widget_layout.child("folder_ledit").setText(sub_dir) else: self.data_path_widget_layout.child("folder_ledit").setText("") self._data_model.directory = base_image_dir self.data_path_widget_layout.child("base_path_label").setText(base_image_dir) def set_run_number(self, run_number): self._data_model.run_number = int(run_number) self.data_path_widget_layout.child("run_number_ledit").setText(str(run_number)) def set_prefix(self, base_prefix): self._data_model.base_prefix = str(base_prefix) self.data_path_widget_layout.child("prefix_ledit").setText(str(base_prefix)) file_name = self._data_model.get_image_file_name() file_name = file_name.replace( "%" + self._data_model.precision + "d", int(self._data_model.precision) * "#", ) self.data_path_widget_layout.child("file_name_value_label").setText(file_name) def update_data_model(self, data_model): self._data_model = data_model self.set_data_path(data_model.get_image_path()) self._data_model_pm.set_model(data_model) def indicate_path_conflict(self, conflict): if conflict: self.data_path_widget_layout.child( "prefix_ledit" ).setPaletteBackgroundColor(widget_colors.LIGHT_RED) self.data_path_widget_layout.child( "run_number_ledit" ).setPaletteBackgroundColor(widget_colors.LIGHT_RED) self.data_path_widget_layout.child( "folder_ledit" ).setPaletteBackgroundColor(widget_colors.LIGHT_RED) logging.getLogger("user_level_log").error( "The current path settings will overwrite data" + " from another task. Correct the problem before adding to queue" ) else: # We had a conflict previous, but its corrected now ! if self.path_conflict_state: logging.getLogger("user_level_log").info("Path valid") self.data_path_widget_layout.child( "prefix_ledit" ).setPaletteBackgroundColor(widget_colors.WHITE) self.data_path_widget_layout.child( "run_number_ledit" ).setPaletteBackgroundColor(widget_colors.WHITE) self.data_path_widget_layout.child( "folder_ledit" ).setPaletteBackgroundColor(widget_colors.WHITE) self.path_conflict_state = conflict