IMP logo
IMP Reference Guide  2.6.1
The Integrative Modeling Platform
counting.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/counting.h
3  * \brief A simple unary function.
4  *
5  * Copyright 2007-2016 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEXAMPLE_COUNTING_H
10 #define IMPEXAMPLE_COUNTING_H
11 
12 #include <IMP/example/example_config.h>
14 #include <IMP/core/XYZ.h>
15 
16 IMPEXAMPLE_BEGIN_NAMESPACE
17 
18 /** Return the number of times particles from one set are close
19  to those from another set.
20  \note This method uses the distance between the centers of
21  the particles and does not use their radii.
22 */
23 inline unsigned int get_number_of_incidences(const ParticlesTemp &psa,
24  const ParticlesTemp &psb,
25  double point_distance) {
26  algebra::Vector3Ds vsa(psa.size());
27  for (unsigned int i = 0; i < vsa.size(); ++i) {
28  vsa[i] = core::XYZ(psa[i]).get_coordinates();
29  }
30  IMP_NEW(algebra::NearestNeighbor3D, nn, (vsa));
31  unsigned int ret = 0;
32  for (unsigned int i = 0; i < psb.size(); ++i) {
34  if (!nn->get_in_ball(v, point_distance).empty()) {
35  ++ret;
36  }
37  }
38  return ret;
39 }
40 
41 IMPEXAMPLE_END_NAMESPACE
42 
43 #endif /* IMPEXAMPLE_COUNTING_H */
unsigned int get_number_of_incidences(const ParticlesTemp &psa, const ParticlesTemp &psb, double point_distance)
Definition: counting.h:23
Simple XYZ decorator.
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Definition: object_macros.h:62
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:106
VectorD< 3 > Vector3D
Definition: VectorD.h:395
Functions to generate vectors.