Skip to content

Commit

Permalink
Merge pull request cctbx#699 from dials/set-distance-for-single-panel…
Browse files Browse the repository at this point in the history
…-detectors-with-hierarchy

Set distance for single panel detectors with hierarchy
  • Loading branch information
jbeilstenedmands authored Feb 26, 2024
2 parents 8f53e56 + babbcc3 commit 4251b75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 25 deletions.
1 change: 1 addition & 0 deletions newsfragments/699.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug when setting the distance for single panel detectors that have a hierarchy.
47 changes: 22 additions & 25 deletions src/dxtbx/model/detector_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,34 +303,31 @@ def set_detector_distance(detector, distance):
"""
Set detector origin from distance along normal
"""
# If the detector has a hierarchy, just update the root note
try:
h = detector.hierarchy()
normal = matrix.col(h.get_normal())
origin = matrix.col(h.get_origin())
panels = list(detector)
if len(panels) > 1:
# If a multi-panel detector has a hierarchy, we will just update the
# root note. Otherwise check that all panels are at the same distance
# and share the same normal vector
try:
panels = [
detector.hierarchy(),
]
except AttributeError:
dists = [p.get_distance() for p in panels]
norm_vecs = [p.get_normal() for p in panels]
assert all(v == norm_vecs[0] for v in norm_vecs[1:]) and all(
d == dists[0] for d in dists
)

for panel in panels:
normal = matrix.col(panel.get_normal())
origin = matrix.col(panel.get_origin())
d = origin.dot(normal)
x = origin - d * normal
origin = distance * normal + x
fast_axis = h.get_fast_axis()
slow_axis = h.get_slow_axis()
h.set_frame(fast_axis, slow_axis, origin)
except AttributeError:
# Check all panels are at the same distance and share the same normal
dists = [p.get_distance() for p in detector]
norm_vecs = [p.get_normal() for p in detector]
assert all(v == norm_vecs[0] for v in norm_vecs[1:]) and all(
d == dists[0] for d in dists
)

for panel in detector:
normal = matrix.col(panel.get_normal())
origin = matrix.col(panel.get_origin())
d = origin.dot(normal)
x = origin - d * normal
origin = distance * normal + x
fast_axis = panel.get_fast_axis()
slow_axis = panel.get_slow_axis()
panel.set_frame(fast_axis, slow_axis, origin)
fast_axis = panel.get_fast_axis()
slow_axis = panel.get_slow_axis()
panel.set_frame(fast_axis, slow_axis, origin)


def get_detector_projection_2d_axes(
Expand Down

0 comments on commit 4251b75

Please sign in to comment.