IMP logo
IMP Reference Guide  2.13.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-2020 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/exception.h>
16 #include <IMP/core/XYZ.h>
17 
18 IMPSAXS_BEGIN_NAMESPACE
19 
20 inline void get_coordinates(const 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 Particles& particles,
30  FormFactorTable* ff_table,
31  Vector<double>& form_factors,
32  FormFactorType ff_type) {
33  form_factors.resize(particles.size());
34  for (unsigned int i = 0; i < particles.size(); i++) {
35  form_factors[i] = ff_table->get_form_factor(particles[i], ff_type);
36  }
37 }
38 
39 //! compute max distance
40 inline double compute_max_distance(const Particles& particles) {
41  double max_dist2 = 0;
42  std::vector<algebra::Vector3D> coordinates(particles.size());
43  get_coordinates(particles, coordinates);
44  for (unsigned int i = 0; i < coordinates.size(); i++) {
45  for (unsigned int j = i + 1; j < coordinates.size(); j++) {
46  double dist2 =
47  algebra::get_squared_distance(coordinates[i], coordinates[j]);
48  if (dist2 > max_dist2) max_dist2 = dist2;
49  }
50  }
51  return std::sqrt(max_dist2);
52 }
53 
54 //! compute max distance between pairs of particles one from particles1
55 //! and the other from particles2
56 inline double compute_max_distance(const Particles& particles1,
57  const Particles& particles2) {
58  double max_dist2 = 0;
59  std::vector<algebra::Vector3D> coordinates1, coordinates2;
60  get_coordinates(particles1, coordinates1);
61  get_coordinates(particles2, coordinates2);
62 
63  for (unsigned int i = 0; i < coordinates1.size(); i++) {
64  for (unsigned int j = i + 1; j < coordinates2.size(); j++) {
65  double dist2 =
66  algebra::get_squared_distance(coordinates1[i], coordinates2[j]);
67  if (dist2 > max_dist2) max_dist2 = dist2;
68  }
69  }
70  return std::sqrt(max_dist2);
71 }
72 
73 //! compute radius_of_gyration
74 inline double radius_of_gyration(const 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  double 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 //! profile calculation for particles and a given set of options
91 IMPSAXSEXPORT
92 Profile* compute_profile(Particles particles,
93  double min_q = 0.0, double max_q = 0.5,
94  double delta_q = 0.001,
95  FormFactorTable* ft = get_default_form_factor_table(),
96  FormFactorType ff_type = HEAVY_ATOMS,
97  bool hydration_layer = true,
98  bool fit = true,
99  bool reciprocal = false,
100  bool ab_initio = false,
101  bool vacuum = false,
102  std::string beam_profile_file = "");
103 
104 //! Read PDB files
105 IMPSAXSEXPORT
106 void read_pdb(Model *m, const std::string file,
107  std::vector<std::string>& pdb_file_names,
108  std::vector<IMP::Particles>& particles_vec,
109  bool residue_level = false,
110  bool heavy_atoms_only = true,
111  int multi_model_pdb = 2,
112  bool explicit_water = false);
113 
114 //! Parse PDB and profile files
115 IMPSAXSEXPORT
116 void read_files(Model *m, const std::vector<std::string>& files,
117  std::vector<std::string>& pdb_file_names,
118  std::vector<std::string>& dat_files,
119  std::vector<IMP::Particles>& particles_vec,
120  Profiles& exp_profiles,
121  bool residue_level = false,
122  bool heavy_atoms_only = true,
123  int multi_model_pdb = 2,
124  bool explicit_water = false,
125  float max_q = 0.0,
126  int units = 1);
127 
128 IMPSAXSEXPORT
129 std::string trim_extension(const std::string file_name);
130 
131 
132 IMPSAXS_END_NAMESPACE
133 
134 #endif /* IMPSAXS_UTILITY_H */
void read_pdb(Model *m, const std::string file, std::vector< std::string > &pdb_file_names, std::vector< IMP::Particles > &particles_vec, bool residue_level=false, bool heavy_atoms_only=true, int multi_model_pdb=2, bool explicit_water=false)
Read PDB files.
IMP::Vector< IMP::Pointer< Profile > > Profiles
Definition: Profile.h:304
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.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A class for computation of atomic and residue level form factors for SAXS calculations.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
Profile * compute_profile(Particles particles, double min_q=0.0, double max_q=0.5, double delta_q=0.001, FormFactorTable *ft=get_default_form_factor_table(), FormFactorType ff_type=HEAVY_ATOMS, bool hydration_layer=true, 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
Simple 3D vector class.
void read_files(Model *m, const std::vector< std::string > &files, std::vector< std::string > &pdb_file_names, std::vector< std::string > &dat_files, std::vector< IMP::Particles > &particles_vec, Profiles &exp_profiles, bool residue_level=false, bool heavy_atoms_only=true, int multi_model_pdb=2, bool explicit_water=false, float max_q=0.0, int units=1)
Parse PDB and profile files.
FormFactorType
type of the form factors for profile calculations
double compute_max_distance(const Particles &particles1, const Particles &particles2)
Definition: saxs/utility.h:56
double radius_of_gyration(const Particles &particles)
compute radius_of_gyration
Definition: saxs/utility.h:74
A class for profile storing and computation.