Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/dlstbx/mimas/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
mimas.MimasISPyBParameter(key="ice_rings.filter", value="true"),
)

XIA2_DIALS_VMXM_SPOTFINDING_PARAMS: Tuple[mimas.MimasISPyBParameter, ...] = (
mimas.MimasISPyBParameter(key="spotfinder.filter.max_separation", value="8"),
mimas.MimasISPyBParameter(
key="spotfinder.threshold.dispersion.kernel_size", value="6,6"
),
mimas.MimasISPyBParameter(
key="spotfinder.threshold.dispersion.sigma_background", value="3"
),
mimas.MimasISPyBParameter(
key="spotfinder.threshold.dispersion.sigma_strong", value="1"
),
)


def xia2_dials_absorption_params(
scenario: mimas.MimasScenario,
Expand Down Expand Up @@ -298,6 +311,8 @@ def handle_rotation_end(
xia2_dials_beamline_extra_params = (
*XIA2_DIALS_COPPER_RINGS_PARAMS,
mimas.MimasISPyBParameter(key="failover", value="true"),
mimas.MimasISPyBParameter(key="remove_blanks", value="true"),
*XIA2_DIALS_VMXM_SPOTFINDING_PARAMS,
)

triggervars_pref: Tuple[mimas.MimasISPyBTriggerVariable, ...] = ()
Expand Down
21 changes: 18 additions & 3 deletions src/dlstbx/wrapper/xia2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ def construct_commandline(
"unit_cell": "xia2.settings.unit_cell",
}
for param, value in params["ispyb_parameters"].items():
command.append(translation.get(param, param) + "=" + value)
if param.startswith("spotfinder"):
if "find_spots.phil_file=spots.phil" not in command:
Comment on lines +59 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit nit-picky but I think this would be more readable as an if and statement rather than nested if statements

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thoughts, if you keep the nested if statement, you could create a list of the spotfinder commands and use that later on to create the phil file, rhater than looping through all of the parameters again.

command.append("find_spots.phil_file=spots.phil")
else:
command.append(translation.get(param, param) + "=" + value)

return command

Expand Down Expand Up @@ -195,11 +199,22 @@ def run_xia2(self, working_directory: Path, params: dict):
f"Could not create run_xia2.sh script file in the working directory {working_directory}"
)
return False
command = ["sh", f"{working_directory}/run_xia2.sh"]
run_command = ["sh", f"{working_directory}/run_xia2.sh"]
else:
run_command = command

subprocess_directory = working_directory / params["program_name"]
subprocess_directory.mkdir(parents=True, exist_ok=True)

# Write out spot finding parameters that are not directly accessible in xia2 to phil file

if "find_spots.phil_file=spots.phil" in command:
with open(subprocess_directory / "spots.phil", "w") as phil:
for param, value in params["ispyb_parameters"].items():
if "spotfinder" in param:
phil.write(f"{param}={value}\n")
self.log.info(f"Created spots.phil in {subprocess_directory}")

Comment on lines +209 to +217
Copy link
Contributor

@pblowey pblowey Feb 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you moved the block that creates the find_spots phil file before the xia2_script you wouldn't need to distinguish run_command and command and I think the code would be more readable as a result

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add to the comment I made on the earlier code block, if you created a list of spotfinder params, you could just do if spotfinder_params: and write the list to file, rather than looping over all of the parameters again. This would also still save you having to distinguish command and run command.

if "dials.integrate.phil_file" in params["xia2"]:
dials_integrate_phil_file = subprocess_directory / params["xia2"].get(
"dials.integrate.phil_file"
Expand All @@ -219,7 +234,7 @@ def run_xia2(self, working_directory: Path, params: dict):
try:
start_time = time.perf_counter()
result = subprocess.run(
command,
run_command,
timeout=params.get("timeout"),
cwd=subprocess_directory,
)
Expand Down