IMP  2.3.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 "FormFactorTable.h"
12 #include "Profile.h"
13 
14 #include <IMP/algebra/Vector3D.h>
15 #include <IMP/base/exception.h>
16 #include <IMP/core/XYZ.h>
17 
18 IMPSAXS_BEGIN_NAMESPACE
19 
20 inline void get_coordinates(const kernel::Particles& particles,
21  std::vector<algebra::Vector3D>& coordinates) {
22  // copy everything in advance for fast access
23  coordinates.resize(particles.size());
24  for (unsigned int i = 0; i < particles.size(); i++) {
25  coordinates[i] = core::XYZ(particles[i]).get_coordinates();
26  }
27 }
28 
29 inline void get_form_factors(const kernel::Particles& particles,
30  FormFactorTable* ff_table, Floats& form_factors,
31  FormFactorType ff_type) {
32  form_factors.resize(particles.size());
33  for (unsigned int i = 0; i < particles.size(); i++) {
34  form_factors[i] = ff_table->get_form_factor(particles[i], ff_type);
35  }
36 }
37 
38 //! compute max distance
39 inline Float compute_max_distance(const kernel::Particles& particles) {
40  Float max_dist2 = 0;
41  std::vector<algebra::Vector3D> coordinates(particles.size());
42  get_coordinates(particles, coordinates);
43  for (unsigned int i = 0; i < coordinates.size(); i++) {
44  for (unsigned int j = i + 1; j < coordinates.size(); j++) {
45  Float dist2 =
46  algebra::get_squared_distance(coordinates[i], coordinates[j]);
47  if (dist2 > max_dist2) 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 =
65  algebra::get_squared_distance(coordinates1[i], coordinates2[j]);
66  if (dist2 > max_dist2) max_dist2 = dist2;
67  }
68  }
69  return std::sqrt(max_dist2);
70 }
71 
72 //! compute radius_of_gyration
73 inline Float radius_of_gyration(const kernel::Particles& particles) {
74  algebra::Vector3D centroid(0.0, 0.0, 0.0);
75  std::vector<algebra::Vector3D> coordinates(particles.size());
76  get_coordinates(particles, coordinates);
77  for (unsigned int i = 0; i < particles.size(); i++) {
78  centroid += coordinates[i];
79  }
80  centroid /= particles.size();
81  Float rg = 0;
82  for (unsigned int i = 0; i < particles.size(); i++) {
83  rg += algebra::get_squared_distance(coordinates[i], centroid);
84  }
85  rg /= particles.size();
86  return std::sqrt(rg);
87 }
88 
89 //! profile calculation for particles and a given set of options
90 IMPSAXSEXPORT
91 Profile* compute_profile(IMP::kernel::Particles particles,
92  float min_q = 0.0, float max_q = 0.5,
93  float delta_q = 0.001,
94  FormFactorTable* ft = get_default_form_factor_table(),
95  FormFactorType ff_type = HEAVY_ATOMS,
96  float water_layer_c2 = 4.0,
97  bool fit = true,
98  bool reciprocal = false,
99  bool ab_initio = false,
100  bool vacuum = false,
101  std::string beam_profile_file = "");
102 
103 IMPSAXS_END_NAMESPACE
104 
105 #endif /* IMPSAXS_UTILITY_H */
Float compute_max_distance(const kernel::Particles &particles1, const kernel::Particles &particles2)
Definition: saxs/utility.h:55
double get_squared_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the squared distance between two vectors.
Definition: VectorD.h:201
FormFactorTable * get_default_form_factor_table()
Exception definitions and assertions.
Simple XYZ decorator.
A class for computation of atomic and residue level form factors for SAXS calculations.
Float radius_of_gyration(const kernel::Particles &particles)
compute radius_of_gyration
Definition: saxs/utility.h:73
IMP::base::Vector< Float > Floats
Standard way to pass a bunch of Float values.
Definition: types.h:47
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
FormFactorType
type of the form factors for profile calculations
Profile * compute_profile(IMP::kernel::Particles particles, float min_q=0.0, float max_q=0.5, float delta_q=0.001, FormFactorTable *ft=get_default_form_factor_table(), FormFactorType ff_type=HEAVY_ATOMS, float water_layer_c2=4.0, bool fit=true, bool reciprocal=false, bool ab_initio=false, bool vacuum=false, std::string beam_profile_file="")
profile calculation for particles and a given set of options
A class for profile storing and computation.