Gemmi C++ API
Loading...
Searching...
No Matches
mtz.hpp
Go to the documentation of this file.
1// Copyright 2019 Global Phasing Ltd.
2//
3// MTZ reflection file format.
4
5#ifndef GEMMI_MTZ_HPP_
6#define GEMMI_MTZ_HPP_
7
8#include <cassert>
9#include <cmath> // for isnan
10#include <cstdint> // for int32_t
11#include <algorithm> // for copy
12#include <array>
13#include <initializer_list>
14#include <string>
15#include <vector>
16#include "fail.hpp" // for fail
17#include "input.hpp" // for AnyStream, FileStream, CharArray
18#include "iterator.hpp" // for StrideIter
19#include "logger.hpp" // for Logger
20#include "math.hpp" // for rad, Mat33
21#include "symmetry.hpp" // for find_spacegroup_by_name, SpaceGroup
22#include "unitcell.hpp" // for UnitCell
23#include "util.hpp" // for ialpha4_id, rtrim_str, ialpha3_id, ...
24
25namespace gemmi {
26
27// Unmerged MTZ files always store in-asu hkl indices and symmetry operation
28// encoded in the M/ISYM column. Here is a helper for writing such files.
30 UnmergedHklMover(const SpaceGroup* spacegroup) : asu_(spacegroup) {
31 if (spacegroup)
32 group_ops_ = spacegroup->operations();
33 }
34
35 // Modifies hkl and returns ISYM value for M/ISYM
36 int move_to_asu(std::array<int, 3>& hkl) {
37 std::pair<Miller, int> hkl_isym = asu_.to_asu(hkl, group_ops_);
38 hkl = hkl_isym.first;
39 return hkl_isym.second;
40 }
41
42private:
43 ReciprocalAsu asu_;
44 GroupOps group_ops_;
45};
46
48 std::string source_path; // input file path, if known
49 bool same_byte_order = true;
51 std::int64_t header_offset = 0;
52 std::string version_stamp;
53 std::string title;
54 int nreflections = 0;
55 std::array<int, 5> sort_order = {};
56 double min_1_d2 = NAN;
57 double max_1_d2 = NAN;
58 float valm = NAN;
59 int nsymop = 0;
62 std::string spacegroup_name;
63 std::vector<Op> symops;
64 const SpaceGroup* spacegroup = nullptr;
65 std::vector<std::string> history;
66 std::string appended_text;
67 // used to report non-critical problems when reading a file (also used in mtz2cif)
69};
70
71struct GEMMI_DLL Mtz : public MtzMetadata {
72 struct Dataset {
73 int id;
74 std::string project_name;
75 std::string crystal_name;
76 std::string dataset_name;
78 double wavelength; // 0 means not set
79 };
80
81 struct Column {
83 char type;
84 std::string label;
85 float min_value = NAN;
86 float max_value = NAN;
87 std::string source; // from COLSRC
89 std::size_t idx;
90
91 Dataset& dataset() { return parent->dataset(dataset_id); }
92 const Dataset& dataset() const { return parent->dataset(dataset_id); }
93 bool has_data() const { return parent->has_data(); }
94 int size() const { return has_data() ? parent->nreflections : 0; }
95 size_t stride() const { return parent->columns.size(); }
96 float& operator[](std::size_t n) { return parent->data[idx + n * stride()]; }
97 float operator[](std::size_t n) const { return parent->data[idx + n * stride()]; }
98 float& at(std::size_t n) { return parent->data.at(idx + n * stride()); }
99 float at(std::size_t n) const { return parent->data.at(idx + n * stride()); }
100 bool is_integer() const {
101 return type == 'H' || type == 'B' || type == 'Y' || type == 'I';
102 }
103
105 if (idx + 1 < parent->columns.size()) {
106 const Column& next_col = parent->columns[idx + 1];
107 if (next_col.dataset_id == dataset_id && next_col.type == next_type)
108 return &next_col;
109 }
110 return nullptr;
111 }
112
115 assert(parent);
116 assert(&parent->columns[idx] == this);
117 return iterator({parent->data.data(), idx, stride()});
118 }
120 return iterator({parent->data.data() + parent->data.size(), idx,
121 stride()});
122 }
124 const_iterator begin() const { return const_cast<Column*>(this)->begin(); }
125 const_iterator end() const { return const_cast<Column*>(this)->end(); }
126 };
127
128 struct Batch {
130 ints.resize(29, 0);
131 floats.resize(156, 0.);
132 // write the same values that are written by CCP4 progs such as COMBAT
133 ints[0] = 29 + 156;
134 ints[1] = 29;
135 ints[2] = 156;
136 // COMBAT sets BSCALE=1, but Pointless sets it to 0.
137 //floats[43] = 1.f; // batch scale
138 }
139 int number = 0;
140 std::string title;
141 std::vector<int> ints;
142 std::vector<float> floats;
143 std::vector<std::string> axes;
144
146 return UnitCell(floats[0], floats[1], floats[2],
147 floats[3], floats[4], floats[5]);
148 }
149 void set_cell(const UnitCell& uc) {
150 floats[0] = (float) uc.a;
151 floats[1] = (float) uc.b;
152 floats[2] = (float) uc.c;
153 floats[3] = (float) uc.alpha;
154 floats[4] = (float) uc.beta;
155 floats[5] = (float) uc.gamma;
156 }
157
158 int dataset_id() const { return ints[20]; }
159 void set_dataset_id(int id) { ints[20] = id; }
160 float wavelength() const { return floats[86]; }
161 void set_wavelength(float lambda) { floats[86] = lambda; }
162 float phi_start() const { return floats[36]; }
163 float phi_end() const { return floats[37]; }
164 Mat33 matrix_U() const {
165 return Mat33(floats[6], floats[9], floats[12],
166 floats[7], floats[10], floats[13],
167 floats[8], floats[11], floats[14]);
168 }
169 };
170
171 std::vector<Dataset> datasets;
172 std::vector<Column> columns;
173 std::vector<Batch> batches;
174 std::vector<float> data;
175
176 explicit Mtz(bool with_base=false) {
177 if (with_base)
178 add_base();
179 }
180 Mtz(Mtz&& o) noexcept { *this = std::move(o); }
181 Mtz& operator=(Mtz&& o) noexcept {
182 MtzMetadata::operator=(std::move(o));
183 datasets = std::move(o.datasets);
184 columns = std::move(o.columns);
185 batches = std::move(o.batches);
186 data = std::move(o.data);
187 for (Mtz::Column& col : columns)
188 col.parent = this;
189 return *this;
190 }
191
192 // explicit to be aware where we make copies
193 explicit Mtz(const Mtz& o) : MtzMetadata(o) {
194 datasets = o.datasets;
195 columns = o.columns;
196 batches = o.batches;
197 data = o.data;
198 for (Mtz::Column& col : columns)
199 col.parent = this;
200 }
201
202 Mtz& operator=(Mtz const&) = delete;
203
204 void add_base() {
205 datasets.push_back({0, "HKL_base", "HKL_base", "HKL_base", cell, 0.});
206 for (int i = 0; i != 3; ++i)
207 add_column(std::string(1, "HKL"[i]), 'H', 0, i, false);
208 }
209
210 // Functions to use after MTZ headers (and data) is read.
211
212 double resolution_high() const { return std::sqrt(1.0 / max_1_d2); }
213 double resolution_low() const { return std::sqrt(1.0 / min_1_d2); }
214
215 UnitCell& get_cell(int dataset=-1) {
216 for (Dataset& ds : datasets)
217 if (ds.id == dataset && ds.cell.is_crystal() && ds.cell.a > 0)
218 return ds.cell;
219 return cell;
220 }
221
222 const UnitCell& get_cell(int dataset=-1) const {
223 return const_cast<Mtz*>(this)->get_cell(dataset);
224 }
225
227 cell = new_cell;
228 cell.set_cell_images_from_spacegroup(spacegroup); // probably not needed
229 for (Dataset& ds : datasets)
230 ds.cell = cell;
231 }
232
234
236 spacegroup = new_sg;
237 spacegroup_number = new_sg ? spacegroup->ccp4 : 0;
238 spacegroup_name = new_sg ? spacegroup->hm : "";
239 }
240
242 if (datasets.empty())
243 fail("MTZ dataset not found (missing DATASET header line?).");
244 return datasets.back();
245 }
246
247 Dataset& dataset(int id) {
248 if ((size_t)id < datasets.size() && datasets[id].id == id)
249 return datasets[id];
250 for (Dataset& d : datasets)
251 if (d.id == id)
252 return d;
253 fail("MTZ file has no dataset with ID " + std::to_string(id));
254 }
255 const Dataset& dataset(int id) const {
256 return const_cast<Mtz*>(this)->dataset(id);
257 }
258
259 Dataset* dataset_with_name(const std::string& name) {
260 for (Dataset& d : datasets)
261 if (d.dataset_name == name)
262 return &d;
263 return nullptr;
264 }
265 const Dataset* dataset_with_name(const std::string& label) const {
266 return const_cast<Mtz*>(this)->dataset_with_name(label);
267 }
268
269 int count(const std::string& label) const {
270 int n = 0;
271 for (const Column& col : columns)
272 if (col.label == label)
273 ++n;
274 return n;
275 }
276
277 int count_type(char type) const {
278 int n = 0;
279 for (const Column& col : columns)
280 if (col.type == type)
281 ++n;
282 return n;
283 }
284
285 Column* column_with_label(const std::string& label, const Dataset* ds=nullptr, char type='*') {
286 for (Column& col : columns)
287 if (col.label == label && (!ds || ds->id == col.dataset_id)
288 && (type == '*' || type == col.type))
289 return &col;
290 return nullptr;
291 }
292 const Column* column_with_label(const std::string& label, const Dataset* ds=nullptr,
293 char type='*') const {
294 return const_cast<Mtz*>(this)->column_with_label(label, ds, type);
295 }
296
297 const Column& get_column_with_label(const std::string& label, const Dataset* ds=nullptr) const {
298 if (const Column* col = column_with_label(label, ds))
299 return *col;
300 fail("Column label not found: " + label);
301 }
302
303 std::vector<const Column*> columns_with_type(char type) const {
304 std::vector<const Column*> cols;
305 for (const Column& col : columns)
306 if (col.type == type)
307 cols.push_back(&col);
308 return cols;
309 }
310
311 std::vector<int> positions_of_columns_with_type(char col_type) const {
312 std::vector<int> cols;
313 for (int i = 0; i < (int) columns.size(); ++i)
314 if (columns[i].type == col_type)
315 cols.push_back(i);
316 return cols;
317 }
318
319 // F(+)/(-) pairs should have type G (and L for sigma),
320 // I(+)/(-) -- K (M for sigma), but E(+)/(-) has no special column type,
321 // so here we use column labels not types.
322 std::vector<std::pair<int,int>> positions_of_plus_minus_columns() const {
323 std::vector<std::pair<int,int>> r;
324 for (int i = 0; i < (int) columns.size(); ++i) {
325 const Column& col = columns[i];
326 size_t sign_pos = col.label.find("(+)");
327 if (sign_pos != std::string::npos) {
328 std::string minus_label = columns[i].label;
329 minus_label[sign_pos+1] = '-';
330 for (int j = 0; j < (int) columns.size(); ++j)
331 if (columns[j].label == minus_label &&
332 columns[j].type == col.type &&
333 columns[j].dataset_id == col.dataset_id) {
334 r.emplace_back(i, j);
335 break;
336 }
337 }
338 }
339 return r;
340 }
341
343 const Column* column_with_one_of_labels(std::initializer_list<const char*> labels,
344 char type='*') const {
345 for (const char* label : labels)
346 if (const Column* col = column_with_label(label, nullptr, type))
347 return col;
348 return nullptr;
349 }
350
352 Column* column_with_type_and_any_of_labels(char type, std::initializer_list<const char*> labels) {
353 for (Column& col : columns)
354 if (col.type == type) {
355 for (const char* label : labels)
356 if (col.label == label)
357 return &col;
358 }
359 return nullptr;
360 }
361
363 // cf. MtzToCif::default_spec in mtz2cif.hpp
364 return column_with_type_and_any_of_labels('I',
365 {"FREE", "RFREE", "FREER", "FreeR_flag", "R-free-flags", "FreeRflag", "R_FREE_FLAGS"});
366 }
367 const Column* rfree_column() const {
368 return const_cast<Mtz*>(this)->rfree_column();
369 }
370
372 return column_with_type_and_any_of_labels('J', {"IMEAN", "I", "IOBS", "I-obs"});
373 }
374 const Column* imean_column() const {
375 return const_cast<Mtz*>(this)->imean_column();
376 }
377
379 return column_with_type_and_any_of_labels('K', {"I(+)", "IOBS(+)", "I-obs(+)", "Iplus"});
380 }
381 const Column* iplus_column() const {
382 return const_cast<Mtz*>(this)->iplus_column();
383 }
384
386 return column_with_type_and_any_of_labels('K', {"I(-)", "IOBS(-)", "I-obs(-)", "Iminus"});
387 }
388 const Column* iminus_column() const {
389 return const_cast<Mtz*>(this)->iminus_column();
390 }
391
392 bool has_data() const {
393 return data.size() == columns.size() * nreflections;
394 }
395
396 bool is_merged() const { return batches.empty(); }
397
400 std::array<double,2> calculate_min_max_1_d2() const;
401
402 void update_reso() {
403 std::array<double,2> reso = calculate_min_max_1_d2();
404 min_1_d2 = reso[0];
405 max_1_d2 = reso[1];
406 }
407
408 // Functions for reading MTZ headers and data.
409
411 same_byte_order = !same_byte_order;
412 swap_eight_bytes(&header_offset);
413 }
414
416
418 void read_main_headers(AnyStream& stream, std::vector<std::string>* save_headers);
419
422
424
426
428
430
431 void read_file(const std::string& path) {
432 try {
433 source_path = path;
434 FileStream stream(path.c_str(), "rb");
435 read_stream(stream, true);
436 } catch (std::system_error&) {
437 throw; // system_error::what() includes path, don't add anything
438 } catch (std::runtime_error& e) {
439 fail(std::string(e.what()) + ": " + path);
440 }
441 }
442
443 template<typename Input>
445 source_path = input.path();
446 read_stream(*input.create_stream(), with_data);
447 }
448
450 void read_file_gz(const std::string& path, bool with_data=true);
451
452 std::vector<int> sorted_row_indices(int use_first=3) const;
453 bool sort(int use_first=3);
454
455 Miller get_hkl(size_t offset) const {
456 return {{(int)data[offset], (int)data[offset+1], (int)data[offset+2]}};
457 }
458 void set_hkl(size_t offset, const Miller& hkl) {
459 for (int i = 0; i != 3; ++i)
460 data[offset + i] = static_cast<float>(hkl[i]);
461 }
462
464 size_t find_offset_of_hkl(const Miller& hkl, size_t start=0) const;
465
467 void ensure_asu(bool tnt_asu=false);
468
470 void reindex(const Op& op);
471
475
478
481
482 Dataset& add_dataset(const std::string& name) {
483 int id = 0;
484 for (const Dataset& d : datasets)
485 if (d.id >= id)
486 id = d.id + 1;
487 datasets.push_back({id, name, name, name, cell, 0.0});
488 return datasets.back();
489 }
490
491 Column& add_column(const std::string& label, char type,
492 int dataset_id, int pos, bool expand_data);
493
494 // extra_col are columns right after src_col that are also copied.
496 const std::vector<std::string>& trailing_cols={});
497
498 // If dest_idx < 0 - columns are appended at the end
499 // append new column(s), otherwise overwrite existing ones.
501 const std::vector<std::string>& trailing_cols={});
502
503 void remove_column(size_t idx);
504
505 template <typename Func>
507 if (!has_data())
508 fail("No data.");
509 auto out = data.begin();
510 size_t width = columns.size();
511 for (auto r = data.begin(); r < data.end(); r += width)
512 if (!condition(&*r)) {
513 if (r != out)
514 std::copy(r, r + width, out);
515 out += width;
516 }
517 data.erase(out, data.end());
518 nreflections = int(data.size() / width);
519 }
520
521 void expand_data_rows(size_t added, int pos_=-1) {
522 size_t old_row_size = columns.size() - added;
523 if (data.size() != old_row_size * nreflections)
524 fail("Internal error");
525 size_t pos = pos_ == -1 ? old_row_size : (size_t) pos_;
526 if (pos > old_row_size)
527 fail("expand_data_rows(): pos out of range");
528 vector_insert_columns(data, old_row_size, (size_t)nreflections, added, pos, NAN);
529 }
530
531 void set_data(const float* new_data, size_t n) {
532 size_t ncols = columns.size();
533 if (n % ncols != 0)
534 fail("Mtz.set_data(): expected " + std::to_string(ncols) + " columns.");
535 nreflections = int(n / ncols);
536 data.assign(new_data, new_data + n);
537 }
538
539 // Function for writing MTZ file
540 void write_to_cstream(std::FILE* stream) const;
541 void write_to_string(std::string& str) const;
542 void write_to_file(const std::string& path) const;
543 size_t size_to_write() const;
544 size_t write_to_buffer(char* buf, size_t maxlen) const;
545
546private:
547 template<typename Write> void write_to_stream(Write write) const;
548};
549
550
551inline Mtz read_mtz_file(const std::string& path) {
552 Mtz mtz;
553 mtz.read_file(path);
554 return mtz;
555}
556
557template<typename Input>
559 Mtz mtz;
560 mtz.read_input(std::forward<Input>(input), with_data);
561 return mtz;
562}
563
564// Abstraction of data source, cf. ReflnDataProxy.
566 const Mtz& mtz_;
567 size_t stride() const { return mtz_.columns.size(); }
568 size_t size() const { return mtz_.data.size(); }
570 float get_num(size_t n) const { return mtz_.data[n]; }
571 const UnitCell& unit_cell() const { return mtz_.cell; }
572 const SpaceGroup* spacegroup() const { return mtz_.spacegroup; }
573 Miller get_hkl(size_t offset) const { return mtz_.get_hkl(offset); }
574
575 size_t column_index(const std::string& label) const {
576 if (const Mtz::Column* col = mtz_.column_with_label(label))
577 return col->idx;
578 fail("MTZ file has no column with label: " + label);
579 }
580};
581
582// Like above, but here the data is stored outside of the Mtz class
584 const float* data_;
585 MtzExternalDataProxy(const Mtz& mtz, const float* data)
586 : MtzDataProxy{mtz}, data_(data) {}
587 size_t size() const { return mtz_.columns.size() * mtz_.nreflections; }
588 float get_num(size_t n) const { return data_[n]; }
589 Miller get_hkl(size_t offset) const {
590 return {{(int)data_[offset + 0],
591 (int)data_[offset + 1],
592 (int)data_[offset + 2]}};
593 }
594};
595
596inline MtzDataProxy data_proxy(const Mtz& mtz) { return {mtz}; }
597
598} // namespace gemmi
599
600#endif
fail(), unreachable() and __declspec/__attribute__ macros
#define GEMMI_DLL
Definition fail.hpp:53
Input abstraction. Used to decouple file reading and decompression.
Bidirectional iterators (over elements of any container) that can filter, uniquify,...
Logger - a tiny utility for passing messages through a callback.
Math utilities. 3D linear algebra.
void swap_eight_bytes(void *start)
Definition fileutil.hpp:100
MtzDataProxy data_proxy(const Mtz &mtz)
Definition mtz.hpp:596
std::array< int, 3 > Miller
A synonym for convenient passing of hkl.
Definition unitcell.hpp:129
Mtz read_mtz_file(const std::string &path)
Definition mtz.hpp:551
void vector_insert_columns(std::vector< T > &data, size_t old_width, size_t length, size_t n, size_t pos, const T &new_value)
Definition util.hpp:274
void fail(const std::string &msg)
Definition fail.hpp:59
Mtz read_mtz(Input &&input, bool with_data)
Definition mtz.hpp:558
Passes messages (including warnings/errors) to a callback function.
Definition logger.hpp:23
const SpaceGroup * spacegroup() const
Definition mtz.hpp:572
size_t column_index(const std::string &label) const
Definition mtz.hpp:575
const UnitCell & unit_cell() const
Definition mtz.hpp:571
Miller get_hkl(size_t offset) const
Definition mtz.hpp:573
size_t stride() const
Definition mtz.hpp:567
float get_num(size_t n) const
Definition mtz.hpp:570
size_t size() const
Definition mtz.hpp:568
MtzExternalDataProxy(const Mtz &mtz, const float *data)
Definition mtz.hpp:585
Miller get_hkl(size_t offset) const
Definition mtz.hpp:589
size_t size() const
Definition mtz.hpp:587
float get_num(size_t n) const
Definition mtz.hpp:588
std::string appended_text
Definition mtz.hpp:66
std::string version_stamp
Definition mtz.hpp:52
double min_1_d2
Definition mtz.hpp:56
std::vector< Op > symops
Definition mtz.hpp:63
const SpaceGroup * spacegroup
Definition mtz.hpp:64
bool indices_switched_to_original
Definition mtz.hpp:50
bool same_byte_order
Definition mtz.hpp:49
std::vector< std::string > history
Definition mtz.hpp:65
int spacegroup_number
Definition mtz.hpp:61
std::string source_path
Definition mtz.hpp:48
UnitCell cell
Definition mtz.hpp:60
std::string title
Definition mtz.hpp:53
double max_1_d2
Definition mtz.hpp:57
std::int64_t header_offset
Definition mtz.hpp:51
std::string spacegroup_name
Definition mtz.hpp:62
Logger logger
Definition mtz.hpp:68
std::array< int, 5 > sort_order
Definition mtz.hpp:55
std::vector< int > ints
Definition mtz.hpp:141
std::vector< float > floats
Definition mtz.hpp:142
Mat33 matrix_U() const
Definition mtz.hpp:164
int dataset_id() const
Definition mtz.hpp:158
std::vector< std::string > axes
Definition mtz.hpp:143
std::string title
Definition mtz.hpp:140
float phi_end() const
Definition mtz.hpp:163
void set_wavelength(float lambda)
Definition mtz.hpp:161
UnitCell get_cell() const
Definition mtz.hpp:145
float phi_start() const
Definition mtz.hpp:162
void set_cell(const UnitCell &uc)
Definition mtz.hpp:149
float wavelength() const
Definition mtz.hpp:160
void set_dataset_id(int id)
Definition mtz.hpp:159
bool is_integer() const
Definition mtz.hpp:100
float & operator[](std::size_t n)
Definition mtz.hpp:96
float at(std::size_t n) const
Definition mtz.hpp:99
size_t stride() const
Definition mtz.hpp:95
Dataset & dataset()
Definition mtz.hpp:91
std::size_t idx
Definition mtz.hpp:89
const Column * get_next_column_if_type(char next_type) const
Definition mtz.hpp:104
int size() const
Definition mtz.hpp:94
float operator[](std::size_t n) const
Definition mtz.hpp:97
const_iterator begin() const
Definition mtz.hpp:124
float & at(std::size_t n)
Definition mtz.hpp:98
iterator begin()
Definition mtz.hpp:114
const_iterator end() const
Definition mtz.hpp:125
iterator end()
Definition mtz.hpp:119
const Dataset & dataset() const
Definition mtz.hpp:92
std::string source
Definition mtz.hpp:87
std::string label
Definition mtz.hpp:84
bool has_data() const
Definition mtz.hpp:93
std::string dataset_name
Definition mtz.hpp:76
std::string project_name
Definition mtz.hpp:74
std::string crystal_name
Definition mtz.hpp:75
UnitCell cell
Definition mtz.hpp:77
double wavelength
Definition mtz.hpp:78
const Column * column_with_one_of_labels(std::initializer_list< const char * > labels, char type=' *') const
the order of labels matters
Definition mtz.hpp:343
size_t write_to_buffer(char *buf, size_t maxlen) const
Mtz & operator=(Mtz &&o) noexcept
Definition mtz.hpp:181
std::vector< Dataset > datasets
Definition mtz.hpp:171
Column * column_with_label(const std::string &label, const Dataset *ds=nullptr, char type=' *')
Definition mtz.hpp:285
void read_stream(AnyStream &stream, bool with_data)
const Column * iplus_column() const
Definition mtz.hpp:381
Column & add_column(const std::string &label, char type, int dataset_id, int pos, bool expand_data)
int count_type(char type) const
Definition mtz.hpp:277
std::vector< Batch > batches
Definition mtz.hpp:173
const Column & get_column_with_label(const std::string &label, const Dataset *ds=nullptr) const
Definition mtz.hpp:297
void reindex(const Op &op)
Reindex data, usually followed by ensure_asu(). Outputs messages through logger.
void write_to_cstream(std::FILE *stream) const
void expand_to_p1()
Change symmetry to P1 and expand reflections.
std::vector< int > positions_of_columns_with_type(char col_type) const
Definition mtz.hpp:311
const Dataset * dataset_with_name(const std::string &label) const
Definition mtz.hpp:265
bool sort(int use_first=3)
bool has_data() const
Definition mtz.hpp:392
Dataset & add_dataset(const std::string &name)
Definition mtz.hpp:482
const UnitCell & get_cell(int dataset=-1) const
Definition mtz.hpp:222
const Column * iminus_column() const
Definition mtz.hpp:388
void read_main_headers(AnyStream &stream, std::vector< std::string > *save_headers)
read headers until END
bool switch_to_asu_hkl()
(for unmerged MTZ only) change HKL to ASU equivalent and set ISYM
void write_to_file(const std::string &path) const
void ensure_asu(bool tnt_asu=false)
(for merged MTZ only) change HKL to ASU equivalent, adjust phases, etc
void set_spacegroup(const SpaceGroup *new_sg)
Definition mtz.hpp:235
double resolution_low() const
Definition mtz.hpp:213
Column * rfree_column()
Definition mtz.hpp:362
void read_file_gz(const std::string &path, bool with_data=true)
the same as read_input(MaybeGzipped(path), with_data)
Dataset & dataset(int id)
Definition mtz.hpp:247
size_t size_to_write() const
std::vector< const Column * > columns_with_type(char type) const
Definition mtz.hpp:303
Column & copy_column(int dest_idx, const Column &src_col, const std::vector< std::string > &trailing_cols={})
void read_all_headers(AnyStream &stream)
std::vector< int > sorted_row_indices(int use_first=3) const
void read_input(Input &&input, bool with_data)
Definition mtz.hpp:444
Dataset & last_dataset()
Definition mtz.hpp:241
std::array< double, 2 > calculate_min_max_1_d2() const
Calculates min/max for all combinations of reflections and unit cells, where unit cells are a global ...
std::vector< std::pair< int, int > > positions_of_plus_minus_columns() const
Definition mtz.hpp:322
const Column * rfree_column() const
Definition mtz.hpp:367
Column * imean_column()
Definition mtz.hpp:371
const Column * imean_column() const
Definition mtz.hpp:374
void read_first_bytes(AnyStream &stream)
Column * column_with_type_and_any_of_labels(char type, std::initializer_list< const char * > labels)
the order of labels doesn't matter
Definition mtz.hpp:352
void set_hkl(size_t offset, const Miller &hkl)
Definition mtz.hpp:458
void toggle_endianness()
Definition mtz.hpp:410
Mtz(Mtz &&o) noexcept
Definition mtz.hpp:180
double resolution_high() const
Definition mtz.hpp:212
Mtz(const Mtz &o)
Definition mtz.hpp:193
void read_raw_data(AnyStream &stream, bool do_read=true)
void set_cell_for_all(const UnitCell &new_cell)
Definition mtz.hpp:226
Dataset * dataset_with_name(const std::string &name)
Definition mtz.hpp:259
void read_file(const std::string &path)
Definition mtz.hpp:431
Mtz & operator=(Mtz const &)=delete
void read_history_and_batch_headers(AnyStream &stream)
read the part between END and MTZENDOFHEADERS
Column & replace_column(size_t dest_idx, const Column &src_col, const std::vector< std::string > &trailing_cols={})
const Column * column_with_label(const std::string &label, const Dataset *ds=nullptr, char type=' *') const
Definition mtz.hpp:292
Column * iminus_column()
Definition mtz.hpp:385
bool switch_to_original_hkl()
(for unmerged MTZ only) change HKL according to M/ISYM
Column * iplus_column()
Definition mtz.hpp:378
void set_data(const float *new_data, size_t n)
Definition mtz.hpp:531
const Dataset & dataset(int id) const
Definition mtz.hpp:255
std::vector< Column > columns
Definition mtz.hpp:172
void remove_rows_if(Func condition)
Definition mtz.hpp:506
Mtz(bool with_base=false)
Definition mtz.hpp:176
size_t find_offset_of_hkl(const Miller &hkl, size_t start=0) const
Returns offset of the first hkl or (size_t)-1. Can be slow.
void write_to_string(std::string &str) const
bool is_merged() const
Definition mtz.hpp:396
UnitCellParameters get_average_cell_from_batch_headers(double *rmsd) const
void expand_data_rows(size_t added, int pos_=-1)
Definition mtz.hpp:521
Miller get_hkl(size_t offset) const
Definition mtz.hpp:455
void update_reso()
Definition mtz.hpp:402
void add_base()
Definition mtz.hpp:204
UnitCell & get_cell(int dataset=-1)
Definition mtz.hpp:215
int count(const std::string &label) const
Definition mtz.hpp:269
void setup_spacegroup()
std::vector< float > data
Definition mtz.hpp:174
void remove_column(size_t idx)
GroupOps operations() const
Definition symmetry.hpp:837
Unit cell.
Definition unitcell.hpp:165
UnmergedHklMover(const SpaceGroup *spacegroup)
Definition mtz.hpp:30
int move_to_asu(std::array< int, 3 > &hkl)
Definition mtz.hpp:36
Crystallographic Symmetry. Space Groups. Coordinate Triplets.
Unit cell.
Utilities. Mostly for working with strings and vectors.