diff --git a/reader/SMV.cpp b/reader/SMV.cpp index db520b463..1d6eedea7 100644 --- a/reader/SMV.cpp +++ b/reader/SMV.cpp @@ -266,7 +266,11 @@ Header Parse(const std::map &kv, const std::string &pa std::transform(a.begin(), a.end(), a.begin(), [](unsigned char c) { return std::tolower(c); }); h.axis_name = a; } - if (kv.count("DETECTOR_NAMES")) + // Only Rigaku's own d*TREK headers (Data_type= in place of ADSC's TYPE=) are read as d*TREK, as + // dxtbx decides it. Some ADSC Quantum beamlines append a d*TREK block to a complete ADSC header, + // and its vectors mirror the image: read that way the sweep indexes with the hand inverted, which + // R-free cannot see but the anomalous map at the heavy-atom sites shows as negative peaks. + if (kv.count("DETECTOR_NAMES") && kv.count("DATA_TYPE")) ParseDtrek(kv, path, h); return h; } diff --git a/tests/JFJochReaderTest.cpp b/tests/JFJochReaderTest.cpp index 29869adb0..c4bd5ed20 100644 --- a/tests/JFJochReaderTest.cpp +++ b/tests/JFJochReaderTest.cpp @@ -4929,6 +4929,7 @@ namespace { std::string byte_order = "little_endian"; int saturation = 65535; // CCD_IMAGE_SATURATION; 0 leaves the line out bool write_header = true; + std::string extra; // further header lines, written after the ADSC ones std::vector pixels; // empty: all zero }; @@ -4944,6 +4945,7 @@ namespace { << "BEAM_CENTER_X=" << f.beam_x_mm << ";\nBEAM_CENTER_Y=" << f.beam_y_mm << ";\n"; if (f.saturation > 0) h << "CCD_IMAGE_SATURATION=" << f.saturation << ";\n"; + h << f.extra; } else { h << "SOMETHING_ELSE=1;\n"; // a brace block that is not an image header } @@ -5017,6 +5019,38 @@ TEST_CASE("JFJochSMVReader_Geometry", "[HDF5][Full][portable]") { RemoveSMVSweep("smv_", ".img"); } + SECTION("an ADSC header with a d*TREK block appended is read as ADSC") { + // Some ADSC Quantum beamlines append a d*TREK block (no Data_type=) to a complete ADSC header. + // Its translation names are not ones the d*TREK path knows, and its vectors mirror the image; + // the ADSC fields are what the file is read by. + WriteSMVSweep("smvplain_", ".img"); + JFJochSMVReader plain; + REQUIRE_NOTHROW(plain.ReadFiles("smvplain_001.img")); + const auto p = plain.GetDataset()->experiment; + + SMVFields f; + f.extra = "DETECTOR_NAMES=ADSC_;\nADSC_GONIO_NAMES=RotZ RotX/Swing RotY TransX TransY TransZ/Dist;\n" + "ROTATION_VECTOR=-1 0 0;\n"; + WriteSMVSweep("smvdtrek_", ".img", f); + JFJochSMVReader reader; + REQUIRE_NOTHROW(reader.ReadFiles("smvdtrek_001.img")); + const auto x = reader.GetDataset()->experiment; + CHECK(x.GetDetectorDistance_mm() == Catch::Approx(250.0)); + CHECK(x.GetBeamX_pxl() == Catch::Approx(12.0)); + CHECK(x.GetBeamY_pxl() == Catch::Approx(8.0)); + CHECK(x.GetDiffractionGeometry().GetOrientation().IsMirrorY() + == p.GetDiffractionGeometry().GetOrientation().IsMirrorY()); + CHECK(x.GetDiffractionGeometry().GetOrientation().GetQuarterTurns() + == p.GetDiffractionGeometry().GetOrientation().GetQuarterTurns()); + REQUIRE(x.GetGoniometer().has_value()); + CHECK((x.GetGoniometer()->GetAxis() - p.GetGoniometer()->GetAxis()).Length() < 1e-5f); + CHECK(x.GetGoniometer()->GetStart_deg() == Catch::Approx(5.0)); + plain.Close(); + reader.Close(); + RemoveSMVSweep("smvplain_", ".img"); + RemoveSMVSweep("smvdtrek_", ".img"); + } + SECTION("a d*TREK header: vectors, a swung arm, a counted wavelength and encoded overflows") { // The vocabulary Rigaku's CrystalClear writes for a Saturn: the detector as named circles with // their vectors in the imgCIF frame, the beam position in pixels, and the wavelength behind a