Skip to content

Instantly share code, notes, and snippets.

@benjaminhwilliams
Last active April 5, 2024 13:28
Show Gist options
  • Save benjaminhwilliams/d91d042248f5a5f3143a76e82ccabb89 to your computer and use it in GitHub Desktop.
Save benjaminhwilliams/d91d042248f5a5f3143a76e82ccabb89 to your computer and use it in GitHub Desktop.
DXTBX format class for DLS I19-2 Eiger data, with custom DAC opening angle
import math
from dxtbx.format.FormatNXmxDLSI19_2 import FormatNXmxDLSI19_2
from dxtbx.masking import GoniometerMaskerFactory
class FormatNXmxDLSI19_2_CustomDAC(FormatNXmxDLSI19_2):
"""
Read NXmx-flavour data from beamline I19-2 at Diamond Light Source.
Include the option of dynamic shadowing of the standard I19-2 diamond anvil
pressure cell with a 120° conical aperture.
"""
def get_goniometer_shadow_masker(self, goniometer=None):
"""Apply the dynamic mask for a diamond anvil cell with a 120° aperture."""
return GoniometerMaskerFactory.diamond_anvil_cell(
goniometer or self.get_goniometer(), cone_opening_angle=math.radians(120)
)
@benjaminhwilliams
Copy link
Author

benjaminhwilliams commented Apr 5, 2024

About

This Gist provides a custom 'format class' (the mechanism for reading and interpreting a specific data format from a particular instrument into DIALS and xia2) for data from EH2 on beamline I19 at Diamond Light Source, using a custom opening angle for masking the shadow of the conical aperture of a diamond anvil pressure cell. By default, I19-2 DAC data are assumed to use a 76° conical aperture. This alternative format class allows for a 120° opening angle and can be configured with the angle of your choice.

Instructions

To use this, you need to have a working DIALS build (e.g. module load dials at Diamond). Then you can either download the Gist as a file (if you think you might need to modify the 120° opening angle, for example), or load the format class directly with just the Gist URL. In either case, you'll use dxtbx.install_format -u, which will create a directory .dxtbx in your home directory (i.e. ~/.dxtbx), containing the custom format class.

This custom format class will only be available to you. Other users will have to repeat these instructions themselves if they want to make use of the custom format class.

Installing

Option 1 (easy, fixed 120° opening angle)

To load directly from the Gist, if you know you want a 120° opening angle and only a 120° opening angle:

$ module load dials
​$ dxtbx.install_format -u https://gist.github.com/benjaminhwilliams/d91d042248f5a5f3143a76e82ccabb89

Option 2 (editable opening angle)

Alternatively, you can download the Gist as a file. If you've previously loaded straight from the Gist URL (option 1), you'll first need to delete the installed format class with

$ rm ~/.dxtbx/d91d042248f5a5f3143a76e82ccabb89.py

or even, if there's nothing else in ~/.dxtbx that you care about (be very careful with rm -r),

$ rm -r ~/.dxtbx

Now download the Gist. Suppose you save it as some/directory/format_nxmx_dls_i19_2_custom_dac.py. Then you can edit the file with the opening angle of your choice and install the format class with

$ module load dials
$ dxtbx.install_format -u some/directory/format_nxmx_dls_i19_2_custom_dac.py

Using the new format class

Just do your normal dials.import dynamic_shadowing=True or xia2 dynamic_shadowing=True, as usual. For data from the EH2 Eiger on I19, the 120° opening angle (or whatever you've configured in a modified format class) will be used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment