IMP  2.1.0
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-2013 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,
29  Floats& form_factors,
30  FormFactorType ff_type) {
31  form_factors.resize(particles.size());
32  for (unsigned int i=0; i<particles.size(); i++) {
33  form_factors[i] = ff_table->get_form_factor(particles[i], ff_type);
34  }
35 }
36 
37 //! compute max distance
38 inline Float compute_max_distance(const kernel::Particles& particles) {
39  Float max_dist2 = 0;
40  std::vector<algebra::Vector3D> coordinates(particles.size());
41  get_coordinates(particles, coordinates);
42  for (unsigned int i = 0; i < coordinates.size(); i++) {
43  for (unsigned int j = i + 1; j < coordinates.size(); j++) {
44  Float dist2 = algebra::get_squared_distance(coordinates[i],
45  coordinates[j]);
46  if(dist2 > max_dist2)
47  max_dist2 = dist2;
48  }
49  }
50  return std::sqrt(max_dist2);
51 }
52 
53 //! compute max distance between pairs of particles one from particles1
54 //! and the other from particles2
55 inline Float compute_max_distance(const kernel::Particles& particles1,
56  const kernel::Particles& particles2) {
57  Float max_dist2 = 0;
58  std::vector<algebra::Vector3D> coordinates1, coordinates2;
59  get_coordinates(particles1, coordinates1);
60  get_coordinates(particles2, coordinates2);
61 
62  for (unsigned int i = 0; i < coordinates1.size(); i++) {
63  for (unsigned int j = i + 1; j < coordinates2.size(); j++) {
64  Float dist2 = algebra::get_squared_distance(coordinates1[i],
65  coordinates2[j]);
66  if(dist2 > max_dist2)
67  max_dist2 = dist2;
68  }
69  }
70  return std::sqrt(max_dist2);
71 }
72 
73 //! compute radius_of_gyration
74 inline Float radius_of_gyration(const kernel::Particles& particles) {
75  algebra::Vector3D centroid(0.0, 0.0, 0.0);
76  std::vector<algebra::Vector3D> coordinates(particles.size());
77  get_coordinates(particles, coordinates);
78  for (unsigned int i = 0; i < particles.size(); i++) {
79  centroid += coordinates[i];
80  }
81  centroid /= particles.size();
82  Float rg = 0;
83  for (unsigned int i = 0; i < particles.size(); i++) {
84  rg += algebra::get_squared_distance(coordinates[i], centroid);
85  }
86  rg /= particles.size();
87  return std::sqrt(rg);
88 }
89 
90 IMPSAXS_END_NAMESPACE
91 
92 #endif /* IMPSAXS_UTILITY_H */
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
compute the squared distance between two vectors
Definition: VectorD.h:393
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:74
IMP::base::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: base/types.h:47
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
Simple 3D vector class.
Float compute_max_distance(const kernel::Particles &particles)
compute max distance
Definition: saxs/utility.h:38
FormFactorType
type of the form factors for profile calculations