-
Notifications
You must be signed in to change notification settings - Fork 58
WIP Adapted Qt-relevant files to let Qt version work with the new AbstractDiffractometer #1659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
2652361
0c94b07
ba05133
9be1ad7
d6c556c
3fb2f98
78ad3fe
a82d468
7fc80ae
2142df8
90301c6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -147,9 +147,9 @@ def get_positions(self) -> dict[str, float]: | |||||
| Returns: | ||||||
| Centring motor positions as {role: position} | ||||||
| """ | ||||||
| motors_dict = {} | ||||||
| for key, val in self.centring_motors.items(): | ||||||
| motors_dict.update({key: val.motor.get_value()}) | ||||||
| motors_dict = dict( | ||||||
| (key, val.get_value()) for key, val in self.centring_motors.items() | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Do you really need to change this for the sake of a one line less? 😄 |
||||||
| ) | ||||||
| return motors_dict | ||||||
|
|
||||||
| def get_centred_point_from_coord(self, x, y, return_by_names=None): | ||||||
|
|
@@ -246,7 +246,7 @@ def motor_positions_to_screen( | |||||
| inv_rot_matrix, | ||||||
| ) | ||||||
|
|
||||||
| chi_angle = math.radians(self.chi_angle) | ||||||
| chi_angle = math.radians(self.chi_angle) if self.chi_angle else 0.0 | ||||||
| chi_rot = np.matrix( | ||||||
| [ | ||||||
| [math.cos(chi_angle), -math.sin(chi_angle)], | ||||||
|
|
@@ -276,7 +276,7 @@ def start_manual_centring(self, nb_click: int = 3): | |||||
| diffr = HWR.beamline.diffractometer | ||||||
| pixels_per_mm = diffr.get_pixels_per_mm() | ||||||
| diffr.wait_status_ready(5) | ||||||
|
|
||||||
| print(f"self.centring_motors {self.centring_motors}") | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please Replace with log if the print is needed
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or remove it. |
||||||
| self.current_centring_procedure = sample_centring.start( | ||||||
| self.centring_motors, | ||||||
| pixels_per_mm[0], | ||||||
|
|
@@ -354,15 +354,18 @@ def accept_centring(self): | |||||
| """Accept the current centred position.""" | ||||||
| self.centring_status["valid"] = True | ||||||
| self.centring_status["accepted"] = True | ||||||
| self.emit("centringAccepted", (True, self.get_centring_status())) | ||||||
| args = (True, self.get_centring_status()) | ||||||
| self.emit("centringAccepted", args) | ||||||
| self.create_centring_point(*args) | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be done in the handler that listens to
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed only the signal emit is needed here. |
||||||
| logging.getLogger("user_level_log").info("Centring successful") | ||||||
|
|
||||||
| def reject_centring(self): | ||||||
| """Reject the current centred position.""" | ||||||
| if self.current_centring_procedure: | ||||||
| self.current_centring_procedure.kill(block=True) | ||||||
| self.centring_status["valid"] = False | ||||||
| self.emit("centringAccepted", (False, self.get_centring_status())) | ||||||
| args = (False, self.get_centring_status()) | ||||||
| self.emit("centringAccepted", args) | ||||||
|
Comment on lines
+367
to
+368
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What was the reason to define args? |
||||||
| logging.getLogger("user_level_log").info("Centring cancelled") | ||||||
|
|
||||||
| def cancel_centring(self): | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,6 +79,7 @@ | |
|
|
||
| from mxcubecore.BaseHardwareObjects import HardwareObject, HardwareObjectState | ||
| from mxcubecore import HardwareRepository as HWR | ||
| from mxcubecore.model import queue_model_objects | ||
|
|
||
|
|
||
| __copyright__ = """ Copyright © by the MXCuBE collaboration """ | ||
|
|
@@ -244,6 +245,9 @@ def init(self): | |
| self.connect(_hobj, "valueChanged", _hobj.update_value) | ||
| except KeyError: | ||
| self.log.warning("Diffractometer: No motors configured") | ||
| queue_model_objects.CentredPosition.set_diffractometer_motor_names( | ||
| list(self.motors_hwobj_dict) | ||
| ) | ||
|
Comment on lines
+248
to
+250
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything concerning the centring should be now in SampleView.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, the motor names are on the diffractometer, and they are needed in queue_model_objects as the code stands, so this was a quick fix (replacing a faulty fix that was in the PR previously). Still, I think the right conclusion is that this PR is not mature and we need some more thorough refactoring before we can use AbstractDiffractometer with the Qt branch. I shall take this up with Martin as soon as possible - meanwhile this is still WIP. |
||
|
|
||
| # nstate (discrete positions) equipment | ||
| for role in self.config.nstate_equipment: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -293,3 +293,6 @@ def motor_positions_to_screen(self, positions_dict: dict) -> tuple: | |
| """Get the motor positions according to the calibration""" | ||
|
|
||
| return () | ||
|
|
||
| def get_image_scale_list(self): | ||
| return [1] | ||
|
Comment on lines
+296
to
+298
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you, please, tell us what is this used for? |
||
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -66,7 +66,7 @@ def init(self): | |||||||||||
| self.update_state(HardwareObjectState.READY) | ||||||||||||
| for mot in self.motors_hwobj_dict.values(): | ||||||||||||
| mot.set_value(random.uniform(0.0, 8.8)) | ||||||||||||
| self.omega.set_value(random.uniform(0, 359.9)) | ||||||||||||
| self.omega.set_value(random.uniform(0, 360)) | ||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ? |
||||||||||||
|
|
||||||||||||
| def abort(self): | ||||||||||||
| self.update_state(HardwareObjectState.READY) | ||||||||||||
|
|
@@ -143,3 +143,12 @@ def _set_phase(self, value: DiffractometerPhase): | |||||||||||
|
|
||||||||||||
| def _set_constraint(self, value): | ||||||||||||
| self.current_constraint = value | ||||||||||||
|
|
||||||||||||
| def use_sample_changer(self): | ||||||||||||
| return True | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+146
to
+149
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really needed? |
||||||||||||
| def accept_centring(self): | ||||||||||||
| return True | ||||||||||||
|
|
||||||||||||
| def user_confirms_centring(self): | ||||||||||||
| return False | ||||||||||||
|
Comment on lines
+150
to
+154
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything concerning the centring is now in SampleView.
Suggested change
|
||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,13 +86,11 @@ def prepare(centring_motors_dict): | |
|
|
||
| motors_to_move = {} | ||
| for m in centring_motors_dict.values(): | ||
| if m.reference_position is not None: | ||
| motors_to_move[m.motor] = m.reference_position | ||
| if hasattr(m, "reference_position") and m.reference_position is not None: | ||
| motors_to_move[m] = m.reference_position | ||
| move_motors(motors_to_move) | ||
|
|
||
| SAVED_INITIAL_POSITIONS = { | ||
| m.motor: m.motor.get_value() for m in centring_motors_dict.values() | ||
| } | ||
| SAVED_INITIAL_POSITIONS = {m: m.get_value() for m in centring_motors_dict.values()} | ||
|
|
||
| omega = centring_motors_dict["omega"] | ||
| phiy = centring_motors_dict["phiy"] | ||
|
|
@@ -281,7 +279,7 @@ def centre_plate1Click( | |
| centred_pos = SAVED_INITIAL_POSITIONS.copy() | ||
|
|
||
| centred_pos.update( | ||
| {sampx.motor: float(sampx.get_value()), sampy.motor: float(sampy.get_value())} | ||
| {sampx: float(sampx.get_value()), sampy: float(sampy.get_value())} | ||
| ) | ||
|
|
||
| return centred_pos | ||
|
|
@@ -352,14 +350,14 @@ def centre_plate( | |
| centred_pos = SAVED_INITIAL_POSITIONS.copy() | ||
| centred_pos.update( | ||
| { | ||
| sampx.motor: float(sampx.get_value() + sampx.direction * dx), | ||
| sampy.motor: float(sampy.get_value() + sampy.direction * dy), | ||
| phiz.motor: ( | ||
| sampx: float(sampx.get_value() + sampx.direction * dx), | ||
| sampy: float(sampy.get_value() + sampy.direction * dy), | ||
| phiz: ( | ||
| float(phiz.get_value() + phiz.direction * d_vertical[0, 0]) | ||
| if phiz.__dict__.get("reference_position") is None | ||
| else phiz.reference_position | ||
| ), | ||
| phiy.motor: ( | ||
| phiy: ( | ||
| float(phiy.get_value() + phiy.direction * d_horizontal[0, 0]) | ||
| if phiy.__dict__.get("reference_position") is None | ||
| else phiy.reference_position | ||
|
|
@@ -383,13 +381,14 @@ def centre_plate( | |
|
|
||
|
|
||
| def ready(motor_list): | ||
| logging.getLogger("HWR").info([m.actuator_name for m in motor_list]) | ||
| logging.getLogger("HWR").info([m.name for m in motor_list]) | ||
| rstate = [m.is_ready() for m in motor_list] | ||
| logging.getLogger("HWR").info(rstate) | ||
| return all(rstate) | ||
|
|
||
|
|
||
| def wait_ready(motor_positions_dict, timeout=None): | ||
| print("motor_positions_dict", motor_positions_dict) | ||
| with gevent.Timeout(timeout): | ||
| while not ready(motor_positions_dict.keys()): | ||
| time.sleep(0.1) | ||
|
|
@@ -443,8 +442,8 @@ def center( | |
| pixelsPerMm_Ver, | ||
| beam_xc, | ||
| beam_yc, | ||
| chi_angle, | ||
| n_points, | ||
| chi_angle=0.0, | ||
| n_points=3, | ||
| omega_range=180, | ||
| ): | ||
| global USER_CLICKED_EVENT | ||
|
|
@@ -478,7 +477,7 @@ def center( | |
| raise RuntimeError("Exception while centring") | ||
|
|
||
| logging.getLogger("HWR").debug("X=%s,Y=%s", X, Y) | ||
| chi_angle = math.radians(chi_angle) | ||
| chi_angle = math.radians(chi_angle) if chi_angle else 0.0 | ||
| chiRotMatrix = numpy.matrix( | ||
| [ | ||
| [math.cos(chi_angle), -math.sin(chi_angle)], | ||
|
|
@@ -503,14 +502,14 @@ def center( | |
| centred_pos = SAVED_INITIAL_POSITIONS.copy() | ||
| centred_pos.update( | ||
| { | ||
| sampx.motor: float(sampx.get_value() + sampx.direction * dx), | ||
| sampy.motor: float(sampy.get_value() + sampy.direction * dy), | ||
| phiz.motor: ( | ||
| sampx: float(sampx.get_value() + sampx.direction * dx), | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about this one. The previous code used a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree with @marcus-oscarsson |
||
| sampy: float(sampy.get_value() + sampy.direction * dy), | ||
| phiz: ( | ||
| float(phiz.get_value() + phiz.direction * d_vertical[0, 0]) | ||
| if phiz.__dict__.get("reference_position") is None | ||
| else phiz.reference_position | ||
| ), | ||
| phiy.motor: ( | ||
| phiy: ( | ||
| float(phiy.get_value() + phiy.direction * d_horizontal[0, 0]) | ||
| if phiy.__dict__.get("reference_position") is None | ||
| else phiy.reference_position | ||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GenericDiffractometer should be replaced by AbstractDiffractometer.