Skip to content

Commit bceacf8

Browse files
authored
Register strategies as autoproc program (#325)
Enables strategy pipeline status to be tracked by creating a linked autoProcProgramId that can be updated via calls to the ISPyB service.
1 parent 6b3ed37 commit bceacf8

File tree

5 files changed

+123
-106
lines changed

5 files changed

+123
-106
lines changed

src/dlstbx/mimas/core.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,14 @@ def handle_eiger_screening(
163163
**kwargs,
164164
) -> List[mimas.Invocation]:
165165
return [
166-
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe=recipe)
167-
for recipe in (
168-
"strategy-align-crystal",
169-
"strategy-mosflm",
170-
"strategy-edna-eiger",
171-
)
166+
mimas.MimasISPyBJobInvocation(
167+
DCID=scenario.DCID,
168+
autostart=True,
169+
recipe="strategy-align-crystal",
170+
source="automatic",
171+
displayname="align_crystal",
172+
),
173+
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe="strategy-mosflm"),
172174
]
173175

174176

@@ -177,10 +179,15 @@ def handle_characterization(
177179
scenario: mimas.MimasScenario,
178180
**kwargs,
179181
) -> List[mimas.Invocation]:
180-
tasks: List[mimas.Invocation] = [
181-
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe="strategy-align-crystal")
182+
return [
183+
mimas.MimasISPyBJobInvocation(
184+
DCID=scenario.DCID,
185+
autostart=True,
186+
recipe="strategy-align-crystal",
187+
source="automatic",
188+
displayname="align_crystal",
189+
),
182190
]
183-
return tasks
184191

185192

186193
@mimas.match_specification(
@@ -191,11 +198,14 @@ def handle_pilatus_screening(
191198
**kwargs,
192199
) -> List[mimas.Invocation]:
193200
return [
194-
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe=recipe)
195-
for recipe in (
196-
"strategy-mosflm",
197-
"strategy-edna",
198-
)
201+
mimas.MimasISPyBJobInvocation(
202+
DCID=scenario.DCID,
203+
autostart=True,
204+
recipe="strategy-align-crystal",
205+
source="automatic",
206+
displayname="align_crystal",
207+
),
208+
mimas.MimasRecipeInvocation(DCID=scenario.DCID, recipe="strategy-mosflm"),
199209
]
200210

201211

src/dlstbx/services/ispybsvc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ def do_store_per_image_analysis_results(self, parameters, **kwargs):
539539

540540
def do_insert_screening(self, parameters, **kwargs):
541541
"""Write entry to the Screening table."""
542-
# screening_params: ['id', 'dcgid', 'dcid', 'programversion', 'shortcomments', 'comments']
542+
# screening_params: ['id', 'dcgid', 'dcid', 'programversion', 'shortcomments', 'comments', 'autoprocprogramid']
543543
screening_params = self.ispyb.mx_screening.get_screening_params()
544544
for k in screening_params.keys():
545545
screening_params[k] = parameters(k)

src/dlstbx/wrapper/dials_align_crystal.py

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -64,73 +64,76 @@ def insert_dials_align_strategies(self, dcid, crystal_symmetry, results):
6464
chi = "%.2f" % chi
6565
phi = "%.2f" % phi
6666

67-
# Step 1: Add new record to Screening table, keep the ScreeningId
68-
d = {
69-
"dcid": dcid,
70-
"programversion": "xia2-dials+dials.align_crystal",
71-
"comments": settings_str,
72-
"shortcomments": f"solution {solution_id}",
73-
"ispyb_command": "insert_screening",
74-
"store_result": "ispyb_screening_id_%i" % solution_id,
75-
}
76-
ispyb_command_list.append(d)
77-
78-
# Step 2: Store screeningOutput results, linked to the screeningId
67+
# Step 1: Store screeningOutput results, linked to the screeningId
7968
# Keep the screeningOutputId
8069
d = {
8170
"program": "dials.align_crystal",
8271
"indexingsuccess": 1,
8372
"strategysuccess": 1,
8473
"alignmentsuccess": 1,
8574
"ispyb_command": "insert_screening_output",
86-
"screening_id": "$ispyb_screening_id_%i" % solution_id,
87-
"store_result": "ispyb_screening_output_id_%i" % solution_id,
75+
"screening_id": "$ispyb_screening_id",
76+
"store_result": f"ispyb_screening_output_id_{solution_id}",
8877
}
8978
ispyb_command_list.append(d)
9079

91-
# Step 3: Store screeningOutputLattice results, linked to the screeningOutputId
80+
# Step 2: Store screeningOutputLattice results, linked to the screeningOutputId
9281
# Keep the screeningOutputLatticeId
9382
d = {
9483
"ispyb_command": "insert_screening_output_lattice",
95-
"screening_output_id": "$ispyb_screening_output_id_%i" % solution_id,
96-
"store_result": "ispyb_screening_output_lattice_id_%i" % solution_id,
84+
"screening_output_id": f"$ispyb_screening_output_id_{solution_id}",
85+
"store_result": f"ispyb_screening_output_lattice_id_{solution_id}",
9786
}
9887
uc_params = crystal_symmetry.unit_cell().parameters()
9988
for i, p in enumerate(("a", "b", "c", "alpha", "beta", "gamma")):
10089
d["unitcell%s" % p] = uc_params[i]
10190
d["spacegroup"] = crystal_symmetry.space_group_info().type().lookup_symbol()
10291
ispyb_command_list.append(d)
10392

104-
# Step 4: Store screeningStrategy results, linked to the screeningOutputId
93+
# Step 3: Store screeningStrategy results, linked to the screeningOutputId
10594
# Keep the screeningStrategyId
10695
d = {
107-
"program": "dials.align_crystal %i" % solution_id,
96+
"program": "dials.align_crystal",
10897
"ispyb_command": "insert_screening_strategy",
109-
"screening_output_id": "$ispyb_screening_output_id_%i" % solution_id,
110-
"store_result": "ispyb_screening_strategy_id_%i" % solution_id,
98+
"screening_output_id": f"$ispyb_screening_output_id_{solution_id}",
99+
"store_result": f"ispyb_screening_strategy_id_{solution_id}",
111100
}
112101
ispyb_command_list.append(d)
113102

114-
# Step 5: Store screeningStrategyWedge results, linked to the screeningStrategyId
103+
# Step 4: Store screeningStrategyWedge results, linked to the screeningStrategyId
115104
# Keep the screeningStrategyWedgeId
116105
d = {
117106
"wedgenumber": 1,
118107
"phi": phi,
119108
"chi": chi,
120109
"comments": settings_str,
121110
"ispyb_command": "insert_screening_strategy_wedge",
122-
"screening_strategy_id": "$ispyb_screening_strategy_id_%i"
123-
% solution_id,
124-
"store_result": "ispyb_screening_strategy_wedge_id_%i" % solution_id,
111+
"screening_strategy_id": f"$ispyb_screening_strategy_id_{solution_id}",
112+
"store_result": f"ispyb_screening_strategy_wedge_id_{solution_id}",
125113
}
126114
ispyb_command_list.append(d)
127115

128116
if ispyb_command_list:
129-
self.log.debug("Sending %s", json.dumps(ispyb_command_list, indent=2))
130-
self.recwrap.send_to("ispyb", {"ispyb_command_list": ispyb_command_list})
131-
self.log.info("Sent %d commands to ISPyB", len(ispyb_command_list))
117+
d = {
118+
"ispyb_command": "update_processing_status",
119+
"program_id": "$ispyb_autoprocprogram_id",
120+
"message": "Processing successful",
121+
"status": "success",
122+
}
123+
ispyb_command_list.append(d)
132124
else:
133-
self.log.info("There is no valid dials.align_crystal strategy here")
125+
d = {
126+
"ispyb_command": "update_processing_status",
127+
"program_id": "$ispyb_autoprocprogram_id",
128+
"message": "No achievable alignment within range of goniometer",
129+
"status": "failure",
130+
}
131+
ispyb_command_list.append(d)
132+
self.log.info("No achievable alignment within range of goniometer")
133+
134+
self.recwrap.send_to("ispyb", {"ispyb_command_list": ispyb_command_list})
135+
self.log.info("Sent %d commands to ISPyB", len(ispyb_command_list))
136+
self.log.debug("Sending %s", json.dumps(ispyb_command_list, indent=2))
134137

135138
def run(self):
136139
assert hasattr(self, "recwrap"), "No recipewrapper object found"

src/dlstbx/wrapper/dlstbx_align_crystal.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,73 +62,77 @@ def insert_dials_align_strategies(self, dcid, crystal_symmetry, results):
6262
chi = "%.2f" % chi
6363
phi = "%.2f" % phi
6464

65-
# Step 1: Add new record to Screening table, keep the ScreeningId
66-
d = {
67-
"dcid": dcid,
68-
"programversion": "dials.align_crystal",
69-
"comments": settings_str,
70-
"shortcomments": "dials.align_crystal %i" % solution_id,
71-
"ispyb_command": "insert_screening",
72-
"store_result": "ispyb_screening_id_%i" % solution_id,
73-
}
74-
ispyb_command_list.append(d)
75-
76-
# Step 2: Store screeningOutput results, linked to the screeningId
65+
# Step 1: Store screeningOutput results, linked to the screeningId
7766
# Keep the screeningOutputId
7867
d = {
7968
"program": "dials.align_crystal",
8069
"indexingsuccess": 1,
8170
"strategysuccess": 1,
8271
"alignmentsuccess": 1,
8372
"ispyb_command": "insert_screening_output",
84-
"screening_id": "$ispyb_screening_id_%i" % solution_id,
85-
"store_result": "ispyb_screening_output_id_%i" % solution_id,
73+
"screening_id": "$ispyb_screening_id",
74+
"store_result": f"ispyb_screening_output_id_{solution_id}",
8675
}
8776
ispyb_command_list.append(d)
8877

89-
# Step 3: Store screeningOutputLattice results, linked to the screeningOutputId
78+
# Step 2: Store screeningOutputLattice results, linked to the screeningOutputId
9079
# Keep the screeningOutputLatticeId
9180
d = {
9281
"ispyb_command": "insert_screening_output_lattice",
93-
"screening_output_id": "$ispyb_screening_output_id_%i" % solution_id,
94-
"store_result": "ispyb_screening_output_lattice_id_%i" % solution_id,
82+
"screening_output_id": f"$ispyb_screening_output_id_{solution_id}",
83+
"store_result": f"ispyb_screening_output_lattice_id_{solution_id}",
9584
}
9685
uc_params = crystal_symmetry.unit_cell().parameters()
9786
for i, p in enumerate(("a", "b", "c", "alpha", "beta", "gamma")):
9887
d["unitcell%s" % p] = uc_params[i]
9988
d["spacegroup"] = crystal_symmetry.space_group_info().type().lookup_symbol()
10089
ispyb_command_list.append(d)
10190

102-
# Step 4: Store screeningStrategy results, linked to the screeningOutputId
91+
# Step 3: Store screeningStrategy results, linked to the screeningOutputId
10392
# Keep the screeningStrategyId
10493
d = {
105-
"program": "dials.align_crystal %i" % solution_id,
94+
"program": "dials.align_crystal",
10695
"ispyb_command": "insert_screening_strategy",
107-
"screening_output_id": "$ispyb_screening_output_id_%i" % solution_id,
108-
"store_result": "ispyb_screening_strategy_id_%i" % solution_id,
96+
"screening_output_id": f"$ispyb_screening_output_id_{solution_id}",
97+
"store_result": f"ispyb_screening_strategy_id_{solution_id}",
10998
}
11099
ispyb_command_list.append(d)
111100

112-
# Step 5: Store screeningStrategyWedge results, linked to the screeningStrategyId
101+
# Step 4: Store screeningStrategyWedge results, linked to the screeningStrategyId
113102
# Keep the screeningStrategyWedgeId
114103
d = {
115104
"wedgenumber": 1,
116105
"phi": phi,
117106
"chi": chi,
118107
"comments": settings_str,
119108
"ispyb_command": "insert_screening_strategy_wedge",
120-
"screening_strategy_id": "$ispyb_screening_strategy_id_%i"
121-
% solution_id,
122-
"store_result": "ispyb_screening_strategy_wedge_id_%i" % solution_id,
109+
"screening_strategy_id": f"$ispyb_screening_strategy_id_{solution_id}",
110+
"store_result": f"ispyb_screening_strategy_wedge_id_{solution_id}",
123111
}
124112
ispyb_command_list.append(d)
125113

126114
if ispyb_command_list:
127-
self.log.debug("Sending %s", json.dumps(ispyb_command_list, indent=2))
128-
self.recwrap.send_to("ispyb", {"ispyb_command_list": ispyb_command_list})
129-
self.log.info("Sent %d commands to ISPyB", len(ispyb_command_list))
115+
d = {
116+
"ispyb_command": "update_processing_status",
117+
"program_id": "$ispyb_autoprocprogram_id",
118+
"message": "Processing successful",
119+
"status": "success",
120+
}
121+
ispyb_command_list.append(d)
122+
130123
else:
131-
self.log.info("There is no valid dials.align_crystal strategy here")
124+
d = {
125+
"ispyb_command": "update_processing_status",
126+
"program_id": "$ispyb_autoprocprogram_id",
127+
"message": "No achievable alignment within range of goniometer",
128+
"status": "failure",
129+
}
130+
ispyb_command_list.append(d)
131+
self.log.info("No achievable alignment within range of goniometer")
132+
133+
self.log.debug("Sending %s", json.dumps(ispyb_command_list, indent=2))
134+
self.recwrap.send_to("ispyb", {"ispyb_command_list": ispyb_command_list})
135+
self.log.info("Sent %d commands to ISPyB", len(ispyb_command_list))
132136

133137
def construct_commandline(self, params):
134138
"""Construct dlstbx.align_crystal command line.
@@ -232,5 +236,6 @@ def run(self):
232236
)
233237
else:
234238
self.log.warning("Expected JSON output file missing")
239+
return False
235240

236241
return True

0 commit comments

Comments
 (0)