cctbx / dxtbx

Diffraction Experiment Toolbox
BSD 3-Clause "New" or "Revised" License
2 stars 18 forks source link

Dectris file writer writes inverted beam; won't fix #542

Open graeme-winter opened 2 years ago

graeme-winter commented 2 years ago

Problem comes from SLS where they are using a newer version of the file writer which writes very nearly nexus which looks like NXmx but has inverted beam direction according to how we read.

dials.import ../*master*
DIALS (2018) Acta Cryst. D74, 85-97. https://doi.org/10.1107/S2059798317017235
DIALS 3.dev.826-g065cefa75-release
The following parameters have been modified:

input {
  experiments = <image files>
}

--------------------------------------------------------------------------------
  format: <class 'dxtbx.format.FormatNXmx.FormatNXmx'>
  num images: 3600
  sequences:
    still:    0
    sweep:    1
  num stills: 0
--------------------------------------------------------------------------------
Writing experiments to imported.expt

This reads as NXmx but

dials.show imported.expt 
DIALS (2018) Acta Cryst. D74, 85-97. https://doi.org/10.1107/S2059798317017235
The following parameters have been modified:

input {
  experiments = imported.expt
}

Experiment 0:
Experiment identifier: bc46c317-0dee-71e0-bccb-57c7493f65f2
Image template: /dls/mx-scratch/gw56/m4/testlyso_D5-4_1_master.h5
Detector:
Panel:
-----8<-----
  origin: {-154.41,163.627,150}
  distance: -150
  pixel to millimeter strategy: ParallaxCorrectedPxMmStrategy
    mu: 4.20852
    t0: 0.45

Max resolution (at corners): 0.563470
Max resolution (inscribed):  0.637169

Beam:
    wavelength: 1.00004
    sample to source direction : {0,0,1}
-----8<-----

yes the effective distance is -150mm

graeme-winter commented 2 years ago

Aha! Simples just invert the direction for that instrument serial number

h5ls -rvd ../testlyso_D5-4_1_master.h5/entry/instrument/detector/detector_number
Opened "../testlyso_D5-4_1_master.h5" with sec2 driver.
entry/instrument/detector/detector_number Dataset {SCALAR}
    Location:  1:271771
    Links:     1
    Modified:  2022-08-17 11:05:00 BST
    Storage:   1 logical byte, 1 allocated byte, 100.00% utilization
    Type:      1-byte null-terminated ASCII string
    Data:
        (0) ""

nope

graeme-winter commented 2 years ago

OK, an afternoon of hacking later I think I have a reasonable logical check to see if your detector is upstream of the beam:

from dxtbx.model.experiment_list import ExperimentList

def is_detector_in_the_way(e):
    d = e.detector

    if len(d) != 1:
        return False
    b = e.beam
    p = d[0]

    n = p.get_normal()
    x = b.get_sample_to_source_direction()

    dot = sum(_n * _x for _n, _x in zip(n, x))

    if abs(dot) > 0.99 and (b.get_wavelength() / d.get_max_resolution(b.get_s0())) > 1:
        return True

    return False

el = ExperimentList.from_file("imported.expt")
print(is_detector_in_the_way(el[0]))
graeme-winter commented 2 years ago

Hang on, maybe I am not so happy with that solution after all 🤔

graeme-winter commented 2 years ago

This one I am happy with -> now need to work out how to edit the detector model to compensate -

from dxtbx.model.experiment_list import ExperimentList

def is_detector_in_the_way(e):
    d = e.detector
    if len(d) != 1:
        return False
    b = e.beam
    p = d[0]

    n = p.get_normal()
    o = p.get_origin()
    x = b.get_sample_to_source_direction()

    dot = sum(_n * _x for _n, _x in zip(n, x))
    doto = sum(_o * _x for _o, _x in zip(o, x))

    if abs(dot) > 0.99 and doto > 0:
        return True

    return False

el = ExperimentList.from_file("imported.expt")
print(is_detector_in_the_way(el[0]))
gebauer commented 1 year ago

What is the best way to get around this issue? I have data from the SLS / PXI and it took me quite some time to figure out why it didn't work 😬

Currently, I just invert the last value in the "origin" array manually, and then it seems to work.

graeme-winter commented 1 year ago

What is the best way to get around this issue? I have data from the SLS / PXI and it took me quite some time to figure out why it didn't work 😬

Currently, I just invert the last value in the "origin" array manually, and then it seems to work.

OK, I could have sworn that a fix went out for this along the lines described above. Digging through the history to verify.

What version of DIALS are you using?

graeme-winter commented 1 year ago

OK - @gebauer I added a fix for this in 8916daf88ce94144c5f2d7d585e0c909a79286ce which should have been in releases for last ~ 11 months? I am pretty sure it was back ported to pick up the CCP4 release series as well...

graeme-winter commented 1 year ago

If you could confirm that this is indeed fixed I will close this issue (since it has been fixed, but seems impolite to close an issue when a user has just reported the problem)