6#ifndef GEMMI_NEIGHBOR_HPP_
7#define GEMMI_NEIGHBOR_HPP_
66 set_bounding_cell(cell);
87 if (idx >=
grid.data.size())
88 fail(
"NeighborSearch error, probably due to NaN in coordinates");
89 return grid.data[idx];
92 template<
typename Func>
95 template<
typename Func>
120 std::vector<Mark*>
out;
137 std::pair<Mark*, double>
160 for (
int k = 1;
k <
max_k;
k *= 2) {
165 if (
result.first !=
nullptr) {
190 if ((
size_t)image_idx <=
grid.unit_cell.images.size())
191 return grid.unit_cell.images[image_idx-1];
192 fail(
"No such image index: " + std::to_string(image_idx));
196 void set_grid_size() {
206 void set_bounding_cell(
const UnitCell& cell) {
209 grid.unit_cell = cell;
213 for (CRA cra :
model->all())
214 box.extend(cra.atom->pos);
218 std::vector<FTransform> ncs = cell.get_ncs_transforms();
220 for (CRA cra :
model->all())
223 for (const Transform& tr : ncs)
224 box.extend(Position(tr.apply(cra.atom->pos)));
226 box.add_margin(0.01);
227 Position size = box.get_size();
228 grid.unit_cell.set(size.x, size.y, size.z, 90, 90, 90);
229 grid.unit_cell.frac.vec -=
grid.unit_cell.fractionalize(box.minimum);
230 grid.unit_cell.orth.vec += box.minimum;
231 for (
const Transform& tr : ncs) {
232 UnitCell& c =
grid.unit_cell;
234 c.images.push_back(c.frac.combine(tr.combine(c.orth)));
252 fail(
"NeighborSearch not initialized");
259 fail(
"NeighborSearch.add_chain(): model not initialized yet");
267 fail(
"NeighborSearch.add_chain(): chain not in this model");
307 std::vector<Fractional>
others;
318 return gcell.distance_sq(frac, f) < sq(SPECIAL_POS_TOL);
323 short(
n_im + 1), -1, -1, n);
328template<
typename Func>
332 fr =
fr.wrap_to_unit();
340 auto shift = [](
int j,
int n) {
342 return (
j + 1) / n - 1;
347 for (
int w =
w0; w <
wend; ++w) {
349 for (
int v =
v0; v <
vend; ++v) {
352 for (
int u =
u0; u <
uend; ++u) {
360 u0 = std::max(0,
u0);
361 v0 = std::max(0,
v0);
362 w0 = std::max(0,
w0);
366 for (
int w =
w0; w <
wend; ++w)
367 for (
int v =
v0; v <
vend; ++v)
368 for (
int u =
u0; u <
uend; ++u) {
369 size_t idx =
grid.index_q(u, v, w);
fail(), unreachable() and __declspec/__attribute__ macros
3d grids used by CCP4 maps, cell-method search and hkl data.
Data structures to store macromolecular structure models.
bool is_same_conformer(char altloc1, char altloc2)
constexpr float sq(float x)
void fail(const std::string &msg)
Representation of a small molecule or inorganic crystal. Flat list of atom sites. Minimal functionali...
Represents atom site in macromolecular structure (~100 bytes).
std::vector< Residue > residues
std::vector< Chain > chains
const_CRA to_cra(const Model &mdl) const
CRA to_cra(Model &mdl) const
SmallStructure::Site & to_site(SmallStructure &small_st) const
const SmallStructure::Site & to_site(const SmallStructure &small_st) const
Mark(const Position &p, char alt, El el, short im, int ch, int res, int atom)
int sufficient_k(double r) const
void add_atom(const Atom &atom, int n_ch, int n_res, int n_atom)
void add_site(const SmallStructure::Site &site, int n)
void add_chain(const Chain &chain, bool include_h_=true)
NeighborSearch & populate(bool include_h_=true)
void for_each(const Position &pos, char alt, double radius, const Func &func, int k=1)
NeighborSearch(Model &model_, const UnitCell &cell, double radius)
Grid< std::vector< Mark > > grid
NeighborSearch(SmallStructure &small_st, double radius)
SmallStructure * small_structure
std::pair< Mark *, double > find_nearest_atom_within_k(const Position &pos, int k, double radius)
void for_each_cell(const Position &pos, const Func &func, int k=1)
double dist_sq(const Position &pos1, const Position &pos2) const
void add_chain_n(const Chain &chain, int n_ch)
std::vector< Mark * > find_site_neighbors(const SmallStructure::Site &site, double min_dist, double max_dist)
std::vector< Mark * > find_neighbors(const Atom &atom, double min_dist, double max_dist)
std::vector< Mark * > find_atoms(const Position &pos, char alt, double min_dist, double radius)
FTransform get_image_transformation(int image_idx) const
Mark * find_nearest_atom(const Position &pos, double radius=INFINITY)
std::vector< Mark > & get_subcell(const Fractional &fr)
double dist(const Position &pos1, const Position &pos2) const
Coordinates in Angstroms - orthogonal (Cartesian) coordinates.
std::vector< Atom > atoms
std::vector< Site > sites