6#ifndef GEMMI_NEIGHBOR_HPP_
7#define GEMMI_NEIGHBOR_HPP_
66 set_bounding_cell(cell);
89 template<
typename Func>
92 template<
typename Func>
117 std::vector<Mark*>
out;
134 std::pair<Mark*, double>
157 for (
int k = 1;
k <
max_k;
k *= 2) {
162 if (
result.first !=
nullptr) {
187 if ((
size_t)image_idx <=
grid.unit_cell.images.size())
188 return grid.unit_cell.images[image_idx-1];
189 fail(
"No such image index: " + std::to_string(image_idx));
193 void set_grid_size() {
203 void set_bounding_cell(
const UnitCell& cell) {
206 grid.unit_cell = cell;
210 for (CRA cra :
model->all())
211 box.extend(cra.atom->pos);
215 std::vector<FTransform> ncs = cell.get_ncs_transforms();
217 for (CRA cra :
model->all())
220 for (const Transform& tr : ncs)
221 box.extend(Position(tr.apply(cra.atom->pos)));
223 box.add_margin(0.01);
224 Position size = box.get_size();
225 grid.unit_cell.set(size.x, size.y, size.z, 90, 90, 90);
226 grid.unit_cell.frac.vec -=
grid.unit_cell.fractionalize(box.minimum);
227 grid.unit_cell.orth.vec += box.minimum;
228 for (
const Transform& tr : ncs) {
229 UnitCell& c =
grid.unit_cell;
231 c.images.push_back(c.frac.combine(tr.combine(c.orth)));
249 fail(
"NeighborSearch not initialized");
256 fail(
"NeighborSearch.add_chain(): model not initialized yet");
264 fail(
"NeighborSearch.add_chain(): chain not in this model");
304 std::vector<Fractional>
others;
315 return gcell.distance_sq(frac, f) < sq(SPECIAL_POS_TOL);
320 short(
n_im + 1), -1, -1, n);
325template<
typename Func>
329 fr =
fr.wrap_to_unit();
337 auto shift = [](
int j,
int n) {
339 return (
j + 1) / n - 1;
344 for (
int w =
w0; w <
wend; ++w) {
346 for (
int v =
v0; v <
vend; ++v) {
349 for (
int u =
u0; u <
uend; ++u) {
357 u0 = std::max(0,
u0);
358 v0 = std::max(0,
v0);
359 w0 = std::max(0,
w0);
363 for (
int w =
w0; w <
wend; ++w)
364 for (
int v =
v0; v <
vend; ++v)
365 for (
int u =
u0; u <
uend; ++u) {
366 size_t idx =
grid.index_q(u, v, w);
bool is_same_conformer(char altloc1, char altloc2)
constexpr float sq(float x)
void fail(const std::string &msg)
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