00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef IMPSAXS_DISTRIBUTION_H
00013 #define IMPSAXS_DISTRIBUTION_H
00014
00015 #include "saxs_config.h"
00016 #include "Profile.h"
00017 #include <IMP/Particle.h>
00018
00019 #include <iostream>
00020 #include <vector>
00021
00022 IMPSAXS_BEGIN_NAMESPACE
00023
00024 namespace {
00025 static const Float pr_resolution = 0.5;
00026 }
00027
00028
00029
00030
00031 template<class ValueT>
00032 class Distribution : public std::vector< ValueT > {
00033 public:
00034
00035 Distribution(Float bin_size = pr_resolution) { init(bin_size); }
00036
00037
00038 Float get_max_distance() { return max_distance_; }
00039
00040
00041 Float get_bin_size() { return bin_size_; }
00042
00043 protected:
00044 void init(Float bin_size) {
00045
00046 bin_size_ = bin_size;
00047 one_over_bin_size_ = 1.0/bin_size_;
00048 max_distance_ = 50.0;
00049 reserve(dist2index(max_distance_) + 1);
00050 }
00051 unsigned int dist2index(Float dist) const {
00052 return algebra::get_rounded( dist * one_over_bin_size_ );
00053 }
00054 Float index2dist(unsigned int index) const { return index * bin_size_; }
00055 protected:
00056 Float bin_size_, one_over_bin_size_;
00057 Float max_distance_;
00058 };
00059
00060 #ifdef SWIG
00061 %template(FloatDistribution) Distribution<Float>;
00062 %template(VectorDistribution) Distribution<algebra::Vector3D>;
00063 #endif
00064
00065
00066
00067
00068
00069 class IMPSAXSEXPORT RadialDistributionFunction : public Distribution<Float> {
00070
00071 public:
00072
00073 RadialDistributionFunction(Float bin_size = pr_resolution);
00074
00075
00076 RadialDistributionFunction(const std::string& file_name);
00077
00078 friend class Profile;
00079
00080
00081 void scale(Float c);
00082
00083
00084 void add(const RadialDistributionFunction& model_pr);
00085
00086
00087 void show(std::ostream &out=std::cout, std::string prefix="") const;
00088
00089
00090 Float R_factor_score(const RadialDistributionFunction& model_pr,
00091 const std::string& file_name = "") const;
00092
00093
00094
00095
00096
00097 Float fit(const RadialDistributionFunction& model_pr,
00098 const std::string& file_name = "") const;
00099
00100
00101 void normalize();
00102
00103 private:
00104
00105 void add_to_distribution(Float dist, Float value) {
00106 unsigned int index = dist2index(dist);
00107 if(index >= size()) {
00108 if(capacity() <= index)
00109 reserve(2 * index);
00110 resize(index + 1, 0);
00111 max_distance_ = index2dist(index + 1);
00112 }
00113 (*this)[index] += value;
00114 }
00115
00116
00117 void read_pr_file(const std::string& file_name);
00118
00119
00120 void write_fit_file(const RadialDistributionFunction& model_pr,
00121 Float c = 1.0, const std::string& file_name = "") const;
00122
00123 };
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133 class IMPSAXSEXPORT
00134 DeltaDistributionFunction : public Distribution<algebra::Vector3D> {
00135 public:
00136
00137 DeltaDistributionFunction(const Particles& particles,
00138 Float max_distance = 0.0,
00139 Float bin_size = pr_resolution);
00140
00141 friend class Score;
00142
00143
00144 void calculate_derivative_distribution(Particle* particle);
00145
00146
00147 void show(std::ostream &out=std::cout, std::string prefix="") const;
00148
00149 private:
00150 void add_to_distribution(Float dist, const algebra::Vector3D& value) {
00151 unsigned int index = dist2index(dist);
00152 if(index >= size()) {
00153 if(capacity() <= index)
00154 reserve(2 * index);
00155 resize(index + 1, algebra::Vector3D(0.0, 0.0, 0.0));
00156 max_distance_ = index2dist(index + 1);
00157 }
00158 (*this)[index] += value;
00159 }
00160
00161 void init() {
00162 clear();
00163 insert(begin(), dist2index(max_distance_) + 1,
00164 algebra::Vector3D(0.0, 0.0, 0.0));
00165 }
00166
00167 protected:
00168 std::vector<algebra::Vector3D> coordinates_;
00169 Floats form_factors_;
00170 };
00171
00172 IMPSAXS_END_NAMESPACE
00173
00174 #endif