forked from mxcube/HardwareObjects
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MultiCollectMockup.py
296 lines (222 loc) · 9.18 KB
/
MultiCollectMockup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
from HardwareRepository.BaseHardwareObjects import HardwareObject
from AbstractMultiCollect import *
import logging
import time
import os
import http.client
import math
import gevent
class MultiCollectMockup(AbstractMultiCollect, HardwareObject):
def __init__(self, name):
AbstractMultiCollect.__init__(self)
HardwareObject.__init__(self, name)
self._centring_status = None
self.ready_event = None
self.actual_frame_num = 0
def execute_command(self, command_name, *args, **kwargs):
return
def init(self):
self.setControlObjects(diffractometer = self.getObjectByRole("diffractometer"),
sample_changer = self.getObjectByRole("sample_changer"),
lims = self.getObjectByRole("dbserver"),
safety_shutter = self.getObjectByRole("safety_shutter"),
machine_current = self.getObjectByRole("machine_current"),
cryo_stream = self.getObjectByRole("cryo_stream"),
energy = self.getObjectByRole("energy"),
resolution = self.getObjectByRole("resolution"),
detector_distance = self.getObjectByRole("detector_distance"),
transmission = self.getObjectByRole("transmission"),
undulators = self.getObjectByRole("undulators"),
flux = self.getObjectByRole("flux"),
detector = self.getObjectByRole("detector"),
beam_info = self.getObjectByRole("beam_info"))
self.emit("collectConnected", (True,))
self.emit("collectReady", (True, ))
@task
def loop(self, owner, data_collect_parameters_list):
failed_msg = "Data collection failed!"
failed = True
collections_analyse_params = []
self.emit("collectReady", (False, ))
self.emit("collectStarted", (owner, 1))
for data_collect_parameters in data_collect_parameters_list:
logging.debug("collect parameters = %r", data_collect_parameters)
failed = False
data_collect_parameters["status"]='Data collection successful'
osc_id, sample_id, sample_code, sample_location = self.update_oscillations_history(data_collect_parameters)
self.emit('collectOscillationStarted', (owner, sample_id, sample_code, sample_location, data_collect_parameters, osc_id))
data_collect_parameters["status"]='Running'
data_collect_parameters["status"]='Data collection successful'
self.emit("collectOscillationFinished", (owner, True, data_collect_parameters["status"], "12345", osc_id, data_collect_parameters))
self.emit("collectEnded", owner, not failed, failed_msg if failed else "Data collection successful")
logging.getLogger('HWR').info("data collection successful in loop")
self.emit("collectReady", (True, ))
@task
def take_crystal_snapshots(self, number_of_snapshots):
self.bl_control.diffractometer.takeSnapshots(number_of_snapshots, wait=True)
@task
def data_collection_hook(self, data_collect_parameters):
return
def do_prepare_oscillation(self, start, end, exptime, npass):
self.actual_frame_num = 0
@task
def oscil(self, start, end, exptime, npass):
return
@task
def set_transmission(self, transmission_percent):
return
def set_wavelength(self, wavelength):
return
def set_energy(self, energy):
return
@task
def set_resolution(self, new_resolution):
return
@task
def move_detector(self, detector_distance):
return
@task
def data_collection_cleanup(self):
return
@task
def close_fast_shutter(self):
return
@task
def open_fast_shutter(self):
return
@task
def move_motors(self, motor_position_dict):
return
@task
def open_safety_shutter(self):
return
def safety_shutter_opened(self):
return
@task
def close_safety_shutter(self):
return
@task
def prepare_intensity_monitors(self):
return
def prepare_acquisition(self, take_dark, start, osc_range, exptime, npass, number_of_images, comment=""):
return
def set_detector_filenames(self, frame_number, start, filename, jpeg_full_path, jpeg_thumbnail_full_path):
return
def prepare_oscillation(self, start, osc_range, exptime, npass):
return (start, start+osc_range)
def do_oscillation(self, start, end, exptime, npass):
gevent.sleep(exptime)
def start_acquisition(self, exptime, npass, first_frame):
return
def write_image(self, last_frame):
self.actual_frame_num += 1
return
def last_image_saved(self):
return self.actual_frame_num
def stop_acquisition(self):
return
def reset_detector(self):
return
def prepare_input_files(self, files_directory, prefix, run_number, process_directory):
self.actual_frame_num = 0
i = 1
while True:
xds_input_file_dirname = "xds_%s_run%s_%d" % (prefix, run_number, i)
xds_directory = os.path.join(process_directory, xds_input_file_dirname)
if not os.path.exists(xds_directory):
break
i+=1
mosflm_input_file_dirname = "mosflm_%s_run%s_%d" % (prefix, run_number, i)
mosflm_directory = os.path.join(process_directory, mosflm_input_file_dirname)
hkl2000_dirname = "hkl2000_%s_run%s_%d" % (prefix, run_number, i)
hkl2000_directory = os.path.join(process_directory, hkl2000_dirname)
self.raw_data_input_file_dir = os.path.join(files_directory, "process", xds_input_file_dirname)
self.mosflm_raw_data_input_file_dir = os.path.join(files_directory, "process", mosflm_input_file_dirname)
self.raw_hkl2000_dir = os.path.join(files_directory, "process", hkl2000_dirname)
return xds_directory, mosflm_directory, hkl2000_directory
@task
def write_input_files(self, collection_id):
return
def get_wavelength(self):
return
def get_detector_distance(self):
return
def get_resolution(self):
if self.bl_control.resolution is not None:
return self.bl_control.resolution.getPosition()
def get_transmission(self):
if self.bl_control.transmission is not None:
return self.bl_control.transmission.getAttFactor()
def get_undulators_gaps(self):
return []
def get_resolution_at_corner(self):
return
def get_beam_size(self):
return None, None
def get_slit_gaps(self):
return None, None
def get_beam_shape(self):
return
def get_measured_intensity(self):
return
def get_machine_current(self):
if self.bl_control.machine_current is not None:
return self.bl_control.machine_current.getCurrent()
else:
return 0
def get_machine_message(self):
if self.bl_control.machine_current is not None:
return self.bl_control.machine_current.getMessage()
else:
return ''
def get_machine_fill_mode(self):
if self.bl_control.machine_current is not None:
return self.bl_control.machine_current.getFillMode()
else:
''
def get_cryo_temperature(self):
if self.bl_control.cryo_stream is not None:
return self.bl_control.cryo_stream.getTemperature()
def getCurrentEnergy(self):
return
def get_beam_centre(self):
return None, None
def getBeamlineConfiguration(self, *args):
return self.bl_config._asdict()
def isConnected(self):
return True
def isReady(self):
return True
def sampleChangerHO(self):
return self.bl_control.sample_changer
def diffractometer(self):
return self.bl_control.diffractometer
def sanityCheck(self, collect_params):
return
def setBrick(self, brick):
return
def directoryPrefix(self):
return self.bl_config.directory_prefix
def store_image_in_lims(self, frame, first_frame, last_frame):
return True
def get_flux(self):
if self.bl_control.flux is not None:
return self.bl_control.flux.getCurrentFlux()
def getOscillation(self, oscillation_id):
return self.oscillations_history[oscillation_id - 1]
def sampleAcceptCentring(self, accepted, centring_status):
self.sample_centring_done(accepted, centring_status)
def setCentringStatus(self, centring_status):
self._centring_status = centring_status
def getOscillations(self,session_id):
return []
def set_helical(self, helical_on):
return
def set_helical_pos(self, helical_oscil_pos):
return
def get_archive_directory(self, directory):
archive_dir = os.path.join(directory, 'archive')
return archive_dir
@task
def generate_image_jpeg(self, filename, jpeg_path, jpeg_thumbnail_path):
pass