cctbx / dxtbx

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

The `Beam` model should not allow non-orthogonal polarization normal #454

Open dagewa opened 2 years ago

dagewa commented 2 years ago

I have a beam model:

In [9]: print(self.experiment.beam)
Beam:
    wavelength: 0.0250824
    sample to source direction : {-0,0.0269665,0.999636}
    divergence: 0
    sigma divergence: 0
    polarization normal: {0,1,0}
    polarization fraction: 0.5

that will not rotate:

In [10]: self.experiment.beam.rotate_around_origin(axis, angle, deg=False)
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
~/sw/cctbx/modules/dials/util/export_pets.py in <module>
----> 1 self.experiment.beam.rotate_around_origin(axis, angle, deg=False)

RuntimeError: dxtbx Internal Error: /home/fcx32934/sw/cctbx/modules/dxtbx/src/dxtbx/model/beam.h(436): DXTBX_ASSERT(std::abs(direction_ * polarization_normal_) < EPS) failure.
dagewa commented 2 years ago

I'm not sure what the point of the assert is here. It seems to be checking that the polarisation normal and the direction is orthogonal, but why do that here and not when creating the beam. Also, this is an unpolarised beam model.

dagewa commented 2 years ago

Further to this, when dials.refine changes a beam model it does so through the set_s0 method. This does not update the polarisation vector, which is probably how we can get into the above situation in the first place.

dagewa commented 2 years ago

Keeping this open, because there is a dxtbx issue in that using set_s0 allows one to set an inconsistent beam model, by not adjusting the polarisation normal vector.

dagewa commented 2 years ago

In general, the Beam constructors allow setting the s0 vector arbitrarily, while setting the polarisation normal along +Y https://github.com/cctbx/dxtbx/blob/20d4cf201afe4465e0d01bbfb50dfb688b33b463/src/dxtbx/model/beam.h#L115-L125 This allows for the construction of physically inconsistent models.

dagewa commented 2 years ago

Note this problem affects files used in tests. Loading experiments from $(dials.data get -q l_cysteine_4_sweeps_scaled)/scaled_35.expt, then the beam cannot be rotated:

>>> beam.rotate_around_origin((1,0,0), 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: dxtbx Internal Error: /home/fcx32934/sw/cctbx/modules/dxtbx/src/dxtbx/model/beam.h(373): DXTBX_ASSERT(std::abs(direction_ * polarization_normal_) < EPS) failure.

this is because that file dates from before when #1939 was merged.