IMP logo
IMP Reference Guide  2.6.1
The Integrative Modeling Platform
FormFactorTable.h
Go to the documentation of this file.
1 /**
2  * \file IMP/saxs/FormFactorTable.h \brief A class for computation of
3  * atomic and residue level form factors for SAXS calculations
4  *
5  * Copyright 2007-2016 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPSAXS_FORM_FACTOR_TABLE_H
10 #define IMPSAXS_FORM_FACTOR_TABLE_H
11 
12 #include <IMP/saxs/saxs_config.h>
13 
14 #include <IMP/Particle.h>
15 #include <IMP/base_types.h>
16 #include <IMP/atom/Residue.h>
17 #include <IMP/atom/Atom.h>
18 #include <IMP/atom/element.h>
19 #include <IMP/algebra/utility.h>
20 
21 #include <iostream>
22 
23 
24 IMPSAXS_BEGIN_NAMESPACE
25 
26 //! type of the form factors for profile calculations
27 /*
28  ALL_ATOMS - all atoms including hydrogens
29  HEAVY_ATOMS - no hydrogens, all other atoms included
30  CA_ATOMS - residue level, residue represented by CA
31 */
33  ALL_ATOMS,
34  HEAVY_ATOMS,
35  CA_ATOMS
36 };
37 
38 /**
39  class that deals with form factor computation
40  two form factors are supported:
41  (i) zero form factors for faster approximated calculations
42  (ii) full form factors for slower accurate calculations
43 
44  Each form factor can be divided into two parts: vacuum and dummy.
45  dummy is an approximated excluded volume (solvent) form factor.
46  The approximation is done using Fraser, MacRae and Suzuki (1978) model.
47 */
48 class IMPSAXSEXPORT FormFactorTable {
49  public:
50  //! default constructor
52 
53  //! constructor with form factor table file (required for full form factors)
54  FormFactorTable(const std::string& table_name, double min_q, double max_q,
55  double delta_q);
56 
57  // 1. Zero form factors
58 
59  //! get f(0), ie q=0 for real space profile calculation
60  double get_form_factor(Particle* p,
61  FormFactorType ff_type = HEAVY_ATOMS) const;
62 
63  //! f(0) in vacuum
64  double get_vacuum_form_factor(Particle* p,
65  FormFactorType ff_type = HEAVY_ATOMS) const;
66 
67  //! f(0) for solvent
68  double get_dummy_form_factor(Particle* p,
69  FormFactorType ff_type = HEAVY_ATOMS) const;
70 
71  //! f(0) for water
72  double get_water_form_factor() const { return zero_form_factors_[OH2]; }
73 
74  //! f(0) for water in vacuum
76  return vacuum_zero_form_factors_[OH2];
77  }
78 
79  //! f(0) for water (solvent)
80  double get_dummy_water_form_factor() const {
81  return dummy_zero_form_factors_[OH2];
82  }
83 
84  // 2. Full form factors
85 
86  //! full form factor for reciprocal space profile calculation
87  const Vector<double>& get_form_factors(Particle* p,
88  FormFactorType ff_type = HEAVY_ATOMS) const;
89 
90  //! for reciprocal space profile calculation
91  const Vector<double>& get_vacuum_form_factors(Particle* p,
92  FormFactorType ff_type = HEAVY_ATOMS) const;
93 
94  //! for reciprocal space profile calculation
95  const Vector<double>& get_dummy_form_factors(Particle* p,
96  FormFactorType ff_type = HEAVY_ATOMS) const;
97 
98  //! full water form factor
100  return form_factors_[OH2];
101  }
102 
103  //! full water vacuum form factor
105  return vacuum_form_factors_[OH2];
106  }
107 
108  //! full water dummy form factor
110  return dummy_form_factors_[OH2];
111  }
112 
113  //! radius
114  double get_radius(Particle* p, FormFactorType ff_type = HEAVY_ATOMS) const;
115 
116  //! volume
117  double get_volume(Particle* p, FormFactorType ff_type = HEAVY_ATOMS) const;
118 
119  //! print tables
120  void show(std::ostream& out = std::cout, std::string prefix = "") const;
121 
122  // electron density of solvent - default=0.334 e/A^3 (H2O)
123  static double rho_;
124 
125  private:
126  // atom types for heavy atoms according to the number of hydrogens
127  // connected to them
128  // ALL_ATOM_SIZE is number of types needed for all atom representation
129  // this indexing is used in form_factors arrays
130  enum FormFactorAtomType {
131  H,
132  He,
133  Li,
134  Be,
135  B,
136  C,
137  N,
138  O,
139  F,
140  Ne, // periodic table, lines 1-2 (10)
141  Na,
142  Mg,
143  Al,
144  Si,
145  P,
146  S,
147  Cl,
148  Ar, // line 3 (8)
149  K,
150  Ca,
151  Cr,
152  Mn,
153  Fe,
154  Co,
155  Ni,
156  Cu,
157  Zn,
158  Se,
159  Br, // line 4 (11)
160  I,
161  Ir,
162  Pt,
163  Au,
164  Hg,
165  ALL_ATOM_SIZE = 34,
166  CH = 34,
167  CH2 = 35,
168  CH3 = 36,
169  NH = 37,
170  NH2 = 38,
171  NH3 = 39,
172  OH = 40,
173  OH2 = 41,
174  SH = 42,
175  HEAVY_ATOM_SIZE = 43,
176  UNK = 44
177  };
178 
179  // map between atom element and FormFactorAtomType
180  static std::map<atom::Element, FormFactorAtomType> element_ff_type_map_;
181 
182  struct FormFactor {
183  FormFactor() {}
184  FormFactor(double ff, double vacuum_ff, double dummy_ff)
185  : ff_(ff), vacuum_ff_(vacuum_ff), dummy_ff_(dummy_ff) {}
186  double ff_, vacuum_ff_, dummy_ff_;
187  };
188 
189  // map between residue type and residue level form factors
190  static std::map<atom::ResidueType, FormFactor> residue_type_form_factor_map_;
191 
192  // form factors for q=0, the order as in the FormFactorAtomType enum
193  static double zero_form_factors_[];
194 
195  static double vacuum_zero_form_factors_[];
196  // those represent excluded volume
197  static double dummy_zero_form_factors_[];
198 
199  // a key for storing zero form factor in Particle as attribute
200  static IntKey form_factor_type_key_;
201 
202  // class for storing form factors solvation table
203  class AtomFactorCoefficients {
204  public:
205  std::string atom_type_;
206  double a_[5];
207  double b_[5];
208  double c_;
209  double excl_vol_;
210  };
211 
212  // read entry
213  friend std::istream& operator>>(
214  std::istream& s, AtomFactorCoefficients& atom_factor_coefficients);
215 
216  // write entry
217  friend std::ostream& operator<<(
218  std::ostream& s, const AtomFactorCoefficients& atom_factor_coefficients);
219 
220  private:
221  int read_form_factor_table(const std::string& table_name);
222 
223  void init_element_form_factor_map();
224 
225  void init_residue_type_form_factor_map();
226 
227  void compute_form_factors_all_atoms();
228 
229  void compute_form_factors_heavy_atoms();
230 
231  double get_form_factor(atom::ResidueType rt) const;
232 
233  double get_vacuum_form_factor(atom::ResidueType rt) const;
234 
235  double get_dummy_form_factor(atom::ResidueType rt) const;
236 
237  FormFactorAtomType get_form_factor_atom_type(atom::Element e) const;
238 
239  FormFactorAtomType get_form_factor_atom_type(Particle* p,
240  FormFactorType ff_type) const;
241 
242  FormFactorAtomType get_carbon_atom_type(const atom::AtomType& atom_type,
243  const atom::ResidueType& residue_type)
244  const;
245 
246  FormFactorAtomType get_nitrogen_atom_type(
247  const atom::AtomType& atom_type,
248  const atom::ResidueType& residue_type) const;
249 
250  FormFactorAtomType get_oxygen_atom_type(const atom::AtomType& atom_type,
251  const atom::ResidueType& residue_type)
252  const;
253 
254  FormFactorAtomType get_sulfur_atom_type(const atom::AtomType& atom_type,
255  const atom::ResidueType& residue_type)
256  const;
257 
258  private:
259  // read from lib file
260  Vector<AtomFactorCoefficients> form_factors_coefficients_;
261 
262  // table of full form factors for 14 atom types
263  Vector<Vector<double> > form_factors_;
264 
265  // vacuum full form factors for 14 atom types
266  Vector<Vector<double> > vacuum_form_factors_;
267 
268  // dummy full form factors for 14 atom types
269  Vector<Vector<double> > dummy_form_factors_;
270 
271  // min/max q and sampling resolution for form factor computation
272  double min_q_, max_q_, delta_q_;
273 
274  WarningContext warn_context_;
275 };
276 
277 /** Get the default table.*/
278 IMPSAXSEXPORT FormFactorTable* get_default_form_factor_table();
279 
280 IMPSAXS_END_NAMESPACE
281 
282 #endif /* IMPSAXS_FORM_FACTOR_TABLE_H */
Define the elements used in IMP.
Basic types used by IMP.
const Vector< double > & get_water_dummy_form_factors() const
full water dummy form factor
Simple atom decorator.
double get_water_form_factor() const
f(0) for water
FormFactorTable * get_default_form_factor_table()
Key< 1, true > IntKey
The type used to identify int attributes in the Particles.
Definition: base_types.h:36
double get_volume(const BoundingBoxD< D > &bb)
See BoundingBoxD.
Definition: BoundingBoxD.h:163
Functions to deal with very common math operations.
A decorator for Residues.
const ResidueType UNK
Unknown residue.
const Vector< double > & get_water_vacuum_form_factors() const
full water vacuum form factor
double get_dummy_water_form_factor() const
f(0) for water (solvent)
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
const Vector< double > & get_water_form_factors() const
full water form factor
Class to handle individual model particles.
Definition: Particle.h:37
FormFactorType
type of the form factors for profile calculations
Element
The various elements currently supported/known.
Definition: element.h:23
double get_vacuum_water_form_factor() const
f(0) for water in vacuum