diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index 1c5533de2..a35aa1429 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -49,7 +49,7 @@ either way. Eigen is header-only: only its headers reach the binaries, and no Ei ## Vendored directly in the repository -These live in the source tree (see the path) rather than being fetched; traccc and the GEMMI-, Ceres- and fast-feedback-indexer-derived files are the exceptions - code adapted into first-party files rather than a vendored directory, see the notes at the end of this file. +These live in the source tree (see the path) rather than being fetched; traccc, dxtbx and the GEMMI-, Ceres- and fast-feedback-indexer-derived files are the exceptions - code adapted into first-party files rather than a vendored directory, see the notes at the end of this file. | Component | Path | Copyright | License (SPDX) | License text | |---|---|---|---|---| @@ -77,6 +77,7 @@ These live in the source tree (see the path) rather than being fetched; traccc a | [fast-feedback-indexer](https://github.com/paulscherrerinstitute/fast-feedback-indexer) (adapted) | `image_analysis/indexing/FFBIDXIndexerCPU.cpp` | PSI | BSD-3-Clause | [fast-feedback-indexer.txt](licenses/fast-feedback-indexer.txt) | | [Ceres Solver](https://github.com/ceres-solver/ceres-solver) (adapted) | `image_analysis/geom_refinement/LMSolver.h`, `LMSolver.cpp` | Google Inc. | BSD-3-Clause | [ceres-solver.txt](licenses/ceres-solver.txt) | | [GEMMI](https://github.com/project-gemmi/gemmi) (adapted) | `image_analysis/structure_refinement/ModelScaling.cpp`, `ModelMaskGPU.cu`, `ModelStructureFactorsGPU.cpp`, `ModelDensityMetal.metal`, `AtomGradientMetal.metal` | Global Phasing Ltd. | MPL-2.0 | [gemmi.txt](licenses/gemmi.txt) | +| [dxtbx](https://github.com/cctbx/dxtbx) (followed) | `reader/SMV.cpp` | Diamond Light Source, Lawrence Berkeley National Laboratory and the Science and Technology Facilities Council | BSD-3-Clause | [dxtbx.txt](licenses/dxtbx.txt) | | [Durin](https://github.com/DiamondLightSource/durin) (adapted) | `xds-plugin/plugin.h`, `plugin.cpp` | Diamond Light Source Ltd.; Global Phasing Ltd. | BSD-3-Clause | [durin.txt](licenses/durin.txt) | | [xbflash.qspi](https://github.com/Xilinx/XRT) | `tools/xbflash.qspi/` | Xilinx / AMD | Apache-2.0 | [xbflash-qspi.txt](licenses/xbflash-qspi.txt) | | [wingetopt](https://github.com/alex85k/wingetopt) | `tools/wingetopt/` | Todd C. Miller; The NetBSD Foundation | ISC AND BSD-2-Clause | [wingetopt.txt](licenses/wingetopt.txt) | @@ -153,6 +154,12 @@ served frontend, so the shipped web UI carries its own attribution. `ModelStructureFactorsGPU.cpp`, `ModelDensityMetal.metal` and `AtomGradientMetal.metal` in `image_analysis/structure_refinement/` follow GEMMI's scaling, Levenberg-Marquardt, solvent-mask, reciprocal-grid and form-factor code. Each names the GEMMI source it follows and is covered by `licenses/gemmi.txt`. +* **dxtbx** (`reader/SMV.cpp`): the SMV reader's d\*TREK path interprets the header the way dxtbx's + `FormatSMVRigaku`, `FormatSMVRigakuSaturn` and `FormatSMVCMOS1` classes do, written from their + source: which headers count as d\*TREK, the image directions from the detector and distortion + vectors, the beam position and pixel size, the detector circles and the distance translation, and + the polarisation. No dxtbx code is copied (it is Python); the functions name dxtbx where they + follow it and are covered by `licenses/dxtbx.txt`. * **Durin** (`xds-plugin/plugin.h`/`.cpp`): the XDS plugin's entry points are based on the Durin plugin of Diamond Light Source and Global Phasing; both files name the origin at the top and are covered by `licenses/durin.txt`. diff --git a/docs/ACKNOWLEDGEMENT.md b/docs/ACKNOWLEDGEMENT.md index 2910d46d3..03110f3f9 100644 --- a/docs/ACKNOWLEDGEMENT.md +++ b/docs/ACKNOWLEDGEMENT.md @@ -899,8 +899,12 @@ C. Broennimann, "Bunch mode specific rate corrections for PILATUS3 detectors" (2 Rad. 22, 701-707 [doi:10.1107/S1600577515003288](https://doi.org/10.1107/S1600577515003288). **d\*TREK SMV** — the SMV reader reads the d\*TREK header vocabulary of Rigaku's CrystalClear from -the headers themselves, interpreting the detector vectors as dxtbx does; no d\*TREK or dxtbx code is -used. J. W. Pflugrath, "The finer things in X-ray diffraction data collection" (1999), Acta Cryst. +the headers themselves, following dxtbx's source for how to interpret them: its `FormatSMVRigaku`, +`FormatSMVRigakuSaturn` and `FormatSMVCMOS1` classes decide which headers are d\*TREK, how the +detector and distortion vectors give the image directions, and how the detector circles and the +distance translation place the detector. No d\*TREK or dxtbx code is copied; dxtbx's licence is +reproduced in `licenses/dxtbx.txt`. The results were also checked against dxtbx's own import of the +same files. J. W. Pflugrath, "The finer things in X-ray diffraction data collection" (1999), Acta Cryst. D55, 1718-1725 [doi:10.1107/S090744499900935X](https://doi.org/10.1107/S090744499900935X); [dxtbx](https://github.com/cctbx/dxtbx): J. M. Parkhurst, A. S. Brewster, L. Fuentes-Montero, D. G. Waterman et al., "dxtbx: the diffraction experiment toolbox" (2014), J. Appl. Cryst. 47, diff --git a/licenses/COLLECT.sh b/licenses/COLLECT.sh index e998098f8..99d08e242 100644 --- a/licenses/COLLECT.sh +++ b/licenses/COLLECT.sh @@ -98,6 +98,7 @@ copy_license Qt6-LGPL-3.0.txt /usr/share/common-licenses/LGPL-3 copy_license NVIDIA-CUDA-EULA.txt \ /usr/local/cuda/EULA.txt /usr/local/cuda-12.8/EULA.txt +# dxtbx.txt (followed by reader/SMV.cpp; dxtbx's LICENSE.txt, BSD-3-Clause) is kept by hand. # hpcn-uam.txt (fpga/hls/icmp.cpp, ip_header_checksum.h) and stb_sprintf.txt (gemmi_gph/stb/stb_sprintf.h) # are the licence comments of those files, kept by hand - re-extract them if the files change. -echo "Done. base64-macaron.txt, traccc.txt, rapidjson.txt, hpcn-uam.txt, stb_sprintf.txt, Qt6-NOTICE.txt and NVIDIA-CUDA-NOTICE.txt are maintained by hand." +echo "Done. base64-macaron.txt, dxtbx.txt, traccc.txt, rapidjson.txt, hpcn-uam.txt, stb_sprintf.txt, Qt6-NOTICE.txt and NVIDIA-CUDA-NOTICE.txt are maintained by hand." diff --git a/licenses/dxtbx.txt b/licenses/dxtbx.txt new file mode 100644 index 000000000..804d2d3e0 --- /dev/null +++ b/licenses/dxtbx.txt @@ -0,0 +1,27 @@ +Copyright (c) 2019 Diamond Light Source, Lawrence Berkeley National Laboratory and the Science and Technology Facilities Council. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +Redistributions in binary form must reproduce the above copyright notice, this +list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +Neither the name of the copyright holder nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/reader/SMV.cpp b/reader/SMV.cpp index 1d6eedea7..a1c5e7373 100644 --- a/reader/SMV.cpp +++ b/reader/SMV.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -144,11 +145,6 @@ void ParseDtrek(const std::map &kv, const std::string throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, path + ": d*TREK header does not describe the detector and the rotation"); - const auto type = kv.find("DATA_TYPE"); - if (type != kv.end() && type->second.find("short") == std::string::npos) - throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, - path + ": only 16-bit SMV images are supported (Data_type=" + type->second + ")"); - h.beam_x_px = info[0]; h.beam_y_px = info[1]; h.pixel_x_m = info[2] * 1e-3; @@ -172,8 +168,10 @@ void ParseDtrek(const std::map &kv, const std::string circle_vectors[3 * i + 2]}; if (units[i] == "deg") h.detector_circles.push_back({axis, values[i]}); - else if (names[i] == "Distance") - h.distance_m = values[i] * 1e-3; + // A translation is taken by its vector, not its name, as dxtbx's FormatSMVCMOS1 does: the one + // along the beam is the distance, "Distance" on a Saturn and "TransZ/Dist" on RDI's CMOS. + else if (std::abs(axis[2]) > 0.999) + h.distance_m = std::abs(values[i]) * 1e-3; else if (values[i] != 0.0) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, path + ": d*TREK detector translation " + names[i] + " is not supported"); @@ -227,10 +225,14 @@ Header Parse(const std::map &kv, const std::string &pa const auto order = kv.find("BYTE_ORDER"); h.little_endian = (order == kv.end()) || order->second.find("little") != std::string::npos; - const auto type = kv.find("TYPE"); + // The pixel type: d*TREK's Data_type= where there is one, since a d*TREK header's TYPE= can be + // something else entirely - "mad", the kind of experiment, on the SBC and RDI CMOS headers. + const bool dtrek_type = kv.count("DATA_TYPE") > 0; + const auto type = kv.find(dtrek_type ? "DATA_TYPE" : "TYPE"); if (type != kv.end() && type->second.find("short") == std::string::npos) throw JFJochException(JFJochExceptionCategory::InputParameterInvalid, - path + ": only 16-bit SMV images are supported (TYPE=" + type->second + ")"); + path + ": only 16-bit SMV images are supported (" + + (dtrek_type ? "Data_type=" : "TYPE=") + type->second + ")"); h.bytes_per_pixel = 2; // A single PIXEL_SIZE is the usual spelling; the split pair appears on a few writers. diff --git a/reader/SweepLayout.cpp b/reader/SweepLayout.cpp index 343fbd171..1e5712542 100644 --- a/reader/SweepLayout.cpp +++ b/reader/SweepLayout.cpp @@ -191,6 +191,21 @@ Layout Place(const std::vector &frames, const std::string &logger_name) { for (size_t i = 1; i < frames.size(); i++) slot[i] = slot[i - 1] + std::llround(Fold(angle[i] - angle[i - 1]) / guess); + // ---- one file too many at an end of the sweep + // + // Some ADSC and marCCD beamlines write an extra image as a collection starts or stops - an + // exposure cut short, taken while the spindle stood - and give it its neighbour's start angle. + // It cannot be placed, but the sweep beside it is sound, so that one file is left out rather than + // the whole series refused. A repeat anywhere else is still a series that went back, below. + const size_t n = frames.size(); + if (n > 2 && (slot[1] == slot[0] || slot[n - 1] == slot[n - 2])) { + const bool first = slot[1] == slot[0]; + logger.Warning("{} states the same start angle as the image next to it, at the {} of the sweep; " + "it is left out.", Name(frames[first ? 0 : n - 1].path), first ? "start" : "end"); + return Place(std::vector(frames.begin() + (first ? 1 : 0), frames.end() - (first ? 0 : 1)), + logger_name); + } + // ---- the step the whole series agrees on // // A straight line through (steps, angle): every frame's own header has a say, so the read-back diff --git a/reader/SweepLayout.h b/reader/SweepLayout.h index ab9880169..bfb064e29 100644 --- a/reader/SweepLayout.h +++ b/reader/SweepLayout.h @@ -48,7 +48,8 @@ struct Layout { // file names sort in) and must not be empty. // // Throws JFJochException, naming the frames, when the series is not one sweep: when the headers -// disagree about the instrument, when two frames claim the same angle, or when the angles do not sit +// disagree about the instrument, when two frames claim the same angle (except one extra file at either +// end, which is left out), or when the angles do not sit // on a single rotation step - a folder of screening images taken at scattered angles is not a sweep, // and silently averaging it into one is how such a set comes out as an indexing failure instead of a // clear refusal. diff --git a/tests/JFJochReaderTest.cpp b/tests/JFJochReaderTest.cpp index c4bd5ed20..d947ffc8f 100644 --- a/tests/JFJochReaderTest.cpp +++ b/tests/JFJochReaderTest.cpp @@ -5116,6 +5116,41 @@ TEST_CASE("JFJochSMVReader_Geometry", "[HDF5][Full][portable]") { remove("dtrek_0001.img"); } + SECTION("a d*TREK header whose TYPE= is the experiment and whose distance is TransZ/Dist") { + // The CMOS detector headers RDI's software writes: TYPE=mad names the kind of experiment, the + // pixel type is in Data_type=, and the distance is the translation along the beam, under a + // name of its own. + const int nx = 24, ny = 16; + std::ostringstream h; + h << "{\nHEADER_BYTES= 1024;\nDIM=2;\nTYPE=mad;\nSIZE1=" << nx << ";\nSIZE2=" << ny << ";\n" + << "BYTE_ORDER=little_endian;\nData_type=unsigned short int;\nDETECTOR_NAMES=RDI1_;\n" + << "RDI1_DETECTOR_VECTORS= -1 0 0 0 -1 0;\n" + << "RDI1_GONIO_NAMES=RotZ RotX/Swing RotY TransX TransY TransZ/Dist;\nRDI1_GONIO_NUM_VALUES=6;\n" + << "RDI1_GONIO_UNITS=deg deg deg mm mm mm;\n" + << "RDI1_GONIO_VECTORS=0 0 1 -1 0 0 0 1 0 1 0 0 0 1 0 0 0 -1;\n" + << "RDI1_GONIO_VALUES=0.000 0.000 0.000 0.000 0.000 250;\n" + << "RDI1_SPATIAL_DISTORTION_INFO= 10.0 7.0 0.1001 0.1001;\n" + << "ROTATION= 0.00 0.10 0.10 1.000 1.000 1.000 1.000 1.000 1.000 250.00;\n" + << "ROTATION_VECTOR= 1.000 0.000 0.000;\nSOURCE_WAVELENGTH=1.000 1.000;\nSATURATED_VALUE=14000;\n}\n"; + std::string head = h.str(); + head.resize(1024, ' '); + const std::vector pixels(static_cast(nx) * ny, 100); + { + std::ofstream out("rdi_0001.img", std::ios::binary); + out.write(head.data(), static_cast(head.size())); + out.write(reinterpret_cast(pixels.data()), + static_cast(pixels.size() * sizeof(uint16_t))); + } + JFJochSMVReader reader; + REQUIRE_NOTHROW(reader.ReadFiles("rdi_0001.img")); + const auto x = reader.GetDataset()->experiment; + CHECK(x.GetDetectorDistance_mm() == Catch::Approx(250.0)); + CHECK(x.GetPixelSize_mm() == Catch::Approx(0.1001)); + CHECK(x.GetWavelength_A() == Catch::Approx(1.0)); + reader.Close(); + remove("rdi_0001.img"); + } + SECTION("a brace block that is not an image header is refused") { SMVFields f; f.write_header = false; WriteSMVFrame("smvbare_001.img", f); diff --git a/tests/SweepLayoutTest.cpp b/tests/SweepLayoutTest.cpp index 88663dde5..4501fc7ad 100644 --- a/tests/SweepLayoutTest.cpp +++ b/tests/SweepLayoutTest.cpp @@ -154,6 +154,20 @@ TEST_CASE("SweepLayout_RepeatedAngleRefused") { CHECK_THROWS_AS(sweep::Place(Series({0.0, 0.1, 0.2, 0.1, 0.2}, 0.1), "test"), JFJochException); } +TEST_CASE("SweepLayout_ExtraFileAtAnEndLeftOut") { + // An image written as the collection stopped, or as it started, with its neighbour's angle. + const auto end = sweep::Place(Series({0.0, 1.0, 2.0, 3.0, 3.0}, 1.0), "test"); + REQUIRE(end.files.size() == 4); + CHECK(end.present == 4); + CHECK(end.start_deg == Catch::Approx(0.0)); + CHECK(end.files[3] == "f3.cbf"); + + const auto start = sweep::Place(Series({-90.0, -90.0, -89.0, -88.0}, 1.0), "test"); + REQUIRE(start.files.size() == 3); + CHECK(start.start_deg == Catch::Approx(-90.0)); + CHECK(start.files[0] == "f1.cbf"); +} + TEST_CASE("SweepLayout_StepFinerThanTheOscillationWidth") { // The header field is the oscillation WIDTH, and a series can step by far less than it exposes - // or, on some writers, hold the whole sweep's range in that field. Taking it for the step