Gemmi C++ API
Loading...
Searching...
No Matches
reciproc.hpp
Go to the documentation of this file.
1// Copyright 2020 Global Phasing Ltd.
2//
3// Reciprocal space helper functions.
4
5#ifndef GEMMI_RECIPROC_HPP_
6#define GEMMI_RECIPROC_HPP_
7
8#include "symmetry.hpp" // for SpaceGroup
9#include "unitcell.hpp" // for UnitCell
10
11namespace gemmi {
12
13// dmin should include a tiny margin for numerical errors
14template<typename Func>
16 const UnitCell& cell, const SpaceGroup* spacegroup,
17 double dmin, double dmax=0., bool unique=true) {
18 Miller lim = cell.get_hkl_limits(dmin);
19 double inv_dmin2 = 1. / sq(dmin);
20 double inv_dmax2 = 0.;
21 if (dmax > 0)
22 inv_dmax2 = dmax == INFINITY ? -1 : 1. / sq(dmax);
23 ReciprocalAsu asu(spacegroup);
24 GroupOps gops = spacegroup->operations();
25 Miller hkl;
26 for (hkl[0] = -lim[0]; hkl[0] <= lim[0]; ++hkl[0])
27 for (hkl[1] = -lim[1]; hkl[1] <= lim[1]; ++hkl[1])
28 for (hkl[2] = -lim[2]; hkl[2] <= lim[2]; ++hkl[2])
29 if (!unique || asu.is_in(hkl)) {
30 double inv_d2 = cell.calculate_1_d2(hkl);
32 !gops.is_systematically_absent(hkl))
33 func(hkl);
34 }
35}
36
37// dmin should include a tiny margin for numerical errors
38inline int count_reflections(const UnitCell& cell, const SpaceGroup* spacegroup,
39 double dmin, double dmax=0., bool unique=true) {
40 int counter = 0;
41 for_all_reflections([&counter](const Miller&) { ++counter; },
42 cell, spacegroup, dmin, dmax, unique);
43 return counter;
44}
45
46inline std::vector<Miller>
47make_miller_vector(const UnitCell& cell, const SpaceGroup* spacegroup,
48 double dmin, double dmax=0., bool unique=true) {
49 std::vector<Miller> hkls;
50 for_all_reflections([&hkls](const Miller& hkl) { hkls.push_back(hkl); },
51 cell, spacegroup, dmin, dmax, unique);
52 return hkls;
53}
54
55
56} // namespace gemmi
57#endif
std::array< int, 3 > Miller
A synonym for convenient passing of hkl.
Definition unitcell.hpp:128
void for_all_reflections(Func func, const UnitCell &cell, const SpaceGroup *spacegroup, double dmin, double dmax=0., bool unique=true)
Definition reciproc.hpp:15
int count_reflections(const UnitCell &cell, const SpaceGroup *spacegroup, double dmin, double dmax=0., bool unique=true)
Definition reciproc.hpp:38
std::vector< Miller > make_miller_vector(const UnitCell &cell, const SpaceGroup *spacegroup, double dmin, double dmax=0., bool unique=true)
Definition reciproc.hpp:47
constexpr float sq(float x)
Definition math.hpp:34
bool is_systematically_absent(const Op::Miller &hkl) const
Definition symmetry.hpp:515
bool is_in(const Op::Miller &hkl) const
GroupOps operations() const
Unit cell.
Definition unitcell.hpp:139
Miller get_hkl_limits(double dmin) const
Definition unitcell.hpp:561
double calculate_1_d2(const Miller &hkl) const
Definition unitcell.hpp:529