IMP  2.2.1
The Integrative Modeling Platform
saxs/utility.h
Go to the documentation of this file.
1 /**
2  * \file IMP/saxs/utility.h
3  * \brief Functions to deal with very common saxs operations
4  * Copyright 2007-2014 IMP Inventors. All rights reserved.
5 */
6 
7 #ifndef IMPSAXS_UTILITY_H
8 #define IMPSAXS_UTILITY_H
9 
10 #include <IMP/saxs/saxs_config.h>
11 #include <IMP/algebra/Vector3D.h>
12 #include "FormFactorTable.h"
13 #include <IMP/base/exception.h>
14 #include <IMP/core/XYZ.h>
15 
16 IMPSAXS_BEGIN_NAMESPACE
17 
18 inline void get_coordinates(const kernel::Particles& particles,
19  std::vector<algebra::Vector3D>& coordinates) {
20  // copy everything in advance for fast access
21  coordinates.resize(particles.size());
22  for (unsigned int i = 0; i < particles.size(); i++) {
23  coordinates[i] = core::XYZ(particles[i]).get_coordinates();
24  }
25 }
26 
27 inline void get_form_factors(const kernel::Particles& particles,
28  FormFactorTable* ff_table, Floats& form_factors,
29  FormFactorType ff_type) {
30  form_factors.resize(particles.size());
31  for (unsigned int i = 0; i < particles.size(); i++) {
32  form_factors[i] = ff_table->get_form_factor(particles[i], ff_type);
33  }
34 }
35 
36 //! compute max distance
37 inline Float compute_max_distance(const kernel::Particles& particles) {
38  Float max_dist2 = 0;
39  std::vector<algebra::Vector3D> coordinates(particles.size());
40  get_coordinates(particles, coordinates);
41  for (unsigned int i = 0; i < coordinates.size(); i++) {
42  for (unsigned int j = i + 1; j < coordinates.size(); j++) {
43  Float dist2 =
44  algebra::get_squared_distance(coordinates[i], coordinates[j]);
45  if (dist2 > max_dist2) max_dist2 = dist2;
46  }
47  }
48  return std::sqrt(max_dist2);
49 }
50 
51 //! compute max distance between pairs of particles one from particles1
52 //! and the other from particles2
53 inline Float compute_max_distance(const kernel::Particles& particles1,
54  const kernel::Particles& particles2) {
55  Float max_dist2 = 0;
56  std::vector<algebra::Vector3D> coordinates1, coordinates2;
57  get_coordinates(particles1, coordinates1);
58  get_coordinates(particles2, coordinates2);
59 
60  for (unsigned int i = 0; i < coordinates1.size(); i++) {
61  for (unsigned int j = i + 1; j < coordinates2.size(); j++) {
62  Float dist2 =
63  algebra::get_squared_distance(coordinates1[i], coordinates2[j]);
64  if (dist2 > max_dist2) max_dist2 = dist2;
65  }
66  }
67  return std::sqrt(max_dist2);
68 }
69 
70 //! compute radius_of_gyration
71 inline Float radius_of_gyration(const kernel::Particles& particles) {
72  algebra::Vector3D centroid(0.0, 0.0, 0.0);
73  std::vector<algebra::Vector3D> coordinates(particles.size());
74  get_coordinates(particles, coordinates);
75  for (unsigned int i = 0; i < particles.size(); i++) {
76  centroid += coordinates[i];
77  }
78  centroid /= particles.size();
79  Float rg = 0;
80  for (unsigned int i = 0; i < particles.size(); i++) {
81  rg += algebra::get_squared_distance(coordinates[i], centroid);
82  }
83  rg /= particles.size();
84  return std::sqrt(rg);
85 }
86 
87 IMPSAXS_END_NAMESPACE
88 
89 #endif /* IMPSAXS_UTILITY_H */
Float compute_max_distance(const kernel::Particles &particles1, const kernel::Particles &particles2)
Definition: saxs/utility.h:53
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
compute the squared distance between two vectors
Definition: VectorD.h:201
Simple xyz decorator.
A class for computation of atomic and residue level form factors for SAXS calculations.
Exception definitions and assertions.
Float radius_of_gyration(const kernel::Particles &particles)
compute radius_of_gyration
Definition: saxs/utility.h:71
IMP::base::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: base/types.h:47
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
Simple 3D vector class.
FormFactorType
type of the form factors for profile calculations