9 #ifndef IMPSAXS_PROFILE_H 
   10 #define IMPSAXS_PROFILE_H 
   12 #include <IMP/saxs/saxs_config.h> 
   21 #include <cereal/access.hpp> 
   22 #include <cereal/types/base_class.hpp> 
   23 #include <cereal/types/vector.hpp> 
   25 IMPSAXS_BEGIN_NAMESPACE
 
   27 class RadialDistributionFunction;
 
   45   Profile(
const std::string& file_name, 
bool fit_file = 
false, 
double max_q = 0.0, 
int units = 1);
 
   48   Profile(
double qmin = 0.0, 
double qmax = 0.5, 
double delta = 0.005);
 
   55                          bool reciprocal = 
false) {
 
   57       calculate_profile_real(particles, ff_type);
 
   59       calculate_profile_reciprocal(particles, ff_type);
 
   69   void calculate_profile_partial(
const Particles& particles,
 
   74   void calculate_profile_partial(
const Particles& particles1,
 
   80   void calculate_profile_reciprocal_partial(
const Particles& particles,
 
   90     calculate_profile_real(particles1, particles2, ff_type);
 
   94   double calculate_I0(
const Particles& particles,
 
   98   void calculate_profile_constant_form_factor(
const Particles& particles,
 
   99                                               double form_factor = 1.0);
 
  105   void calculate_profile_symmetric(
const Particles& particles,
 
  111                               double max_distance) 
const;
 
  117   void resample(
const Profile* exp_profile, 
Profile* resampled_profile) 
const;
 
  120   void downsample(
Profile* downsampled_profile,
 
  121                   unsigned int point_number) 
const;
 
  131   double mean_intensity() 
const;
 
  141   void read_SAXS_file(
const std::string& file_name, 
bool fit_file = 
false, 
double max_q = 0.0, 
int units = 1);
 
  147   void write_SAXS_file(
const std::string& file_name, 
double max_q = 0.0) 
const;
 
  150   void read_partial_profiles(
const std::string& file_name);
 
  153   void write_partial_profiles(
const std::string& file_name) 
const;
 
  166   double get_intensity(
unsigned int i)
 const { 
return intensity_(i); }
 
  167   double get_q(
unsigned int i)
 const { 
return q_(i); }
 
  168   double get_error(
unsigned int i)
 const { 
return error_(i); }
 
  169   double get_weight(
unsigned int i)
 const {
 
  174   const Eigen::VectorXd& get_qs()
 const { 
return q_; }
 
  175   const Eigen::VectorXd& get_intensities()
 const { 
return intensity_; }
 
  176   const Eigen::VectorXd& get_errors()
 const { 
return error_; }
 
  178   double get_average_radius()
 const { 
return average_radius_; }
 
  181   unsigned int size()
 const { 
return q_.size(); }
 
  184   bool is_uniform_sampling() 
const;
 
  186   bool is_partial_profile()
 const { 
return (partial_profiles_.size()>0); }
 
  188   std::string get_name()
 const { 
return name_; }
 
  190   unsigned int get_id()
 const { 
return id_; }
 
  193   void set_qs(
const Eigen::VectorXd& q) { q_ = q; }
 
  194   void set_intensities(
const Eigen::VectorXd& i) { intensity_ = i; }
 
  195   void set_errors(
const Eigen::VectorXd& e) { error_ = e; }
 
  197   void set_intensity(
unsigned int i, 
double iq) { intensity_(i) = iq; }
 
  202   void set_average_radius(
double r) { average_radius_ = r; }
 
  204   void set_average_volume(
double v) { average_volume_ = v; }
 
  206   void set_name(std::string name) { name_ = name; }
 
  208   void set_id(
unsigned int id) { id_ = id; }
 
  210   void set_beam_profile(std::string beam_profile_file) {
 
  211     beam_profile_ = 
new Profile(beam_profile_file);
 
  218   void add_noise(
double percentage = 0.03);
 
  221   void sum_partial_profiles(
double c1, 
double c2, 
bool check_cashed = 
true);
 
  224   void add(
const Profile* other_profile, 
double weight = 1.0);
 
  227   void add_partial_profiles(
const Profile* other_profile, 
double weight = 1.0);
 
  230   void add(
const Vector<Profile*>& profiles,
 
  231            const Vector<double>& weights = Vector<double>());
 
  234   void add_partial_profiles(
const Vector<Profile*>& profiles,
 
  235                             const Vector<double>& weights = Vector<double>());
 
  238   void background_adjust(
double start_q);
 
  241   void scale(
double c);
 
  244   void offset(
double c);
 
  247   void copy_errors(
const Profile* exp_profile);
 
  250   static const double modulation_function_parameter_;
 
  255   void init(
unsigned int size = 0, 
unsigned int partial_profiles_size = 0);
 
  258   void calculate_profile_reciprocal(
const Particles& particles,
 
  261   void calculate_profile_reciprocal(
const Particles& particles1,
 
  265   void calculate_profile_real(
const Particles& particles,
 
  268   void calculate_profile_real(
const Particles& particles1,
 
  274   void squared_distributions_2_partial_profiles(
 
  277   double radius_of_gyration_fixed_q(
double end_q) 
const;
 
  279   double find_max_q(
const std::string& file_name) 
const;
 
  283   Eigen::VectorXd intensity_;
 
  284   Eigen::VectorXd error_;  
 
  286   double min_q_, max_q_;        
 
  291   std::vector<Eigen::VectorXd> partial_profiles_;
 
  295   double average_radius_;  
 
  296   double average_volume_;  
 
  299   mutable std::map<double, unsigned int> q_mapping_;
 
  306   friend class cereal::access;
 
  307   template<
class Archive> 
void serialize(Archive &ar) {
 
  308     ar(cereal::base_class<Object>(
this), q_, intensity_, error_,
 
  309        min_q_, max_q_, delta_q_, partial_profiles_, c1_, c2_,
 
  310        experimental_, average_radius_, average_volume_,
 
  311        name_, id_, beam_profile_);
 
  312     if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
 
  315       bool default_ff_table;
 
  316       ar(default_ff_table);
 
  317       if (default_ff_table) {
 
  323       if (ff_table_ == 
nullptr) {
 
  328         IMP_THROW(
"Serialization of profiles using non-default form " 
  338 IMPSAXS_END_NAMESPACE
 
  341   template<
class Archive, 
typename _Scalar, 
int _Rows, 
int _Cols,
 
  342            int _Options, 
int _MaxRows, 
int _MaxCols>
 
  343   inline void serialize(
 
  344       Archive &ar, Eigen::Matrix<_Scalar, _Rows, _Cols, _Options, _MaxRows,
 
  347     if (std::is_base_of<cereal::detail::OutputArchiveBase, Archive>::value) {
 
  348       rows = matrix.rows();
 
  349       cols = matrix.cols();
 
  353     if (std::is_base_of<cereal::detail::InputArchiveBase, Archive>::value) {
 
  354       if (rows != matrix.rows() || cols != matrix.cols()) {
 
  355         matrix.resize(rows, cols);
 
  358     auto mat_data = cereal::binary_data(matrix.data(),
 
  359                                         rows * cols * 
sizeof(_Scalar));
 
  360     if (matrix.size() != 0) {
 
unsigned int size() const 
return number of entries in SAXS profile 
 
void calculate_profile(const Particles &particles, FormFactorType ff_type=HEAVY_ATOMS, bool reciprocal=false)
computes theoretical profile 
 
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object. 
 
FormFactorTable * get_default_form_factor_table()
 
A smart pointer to a reference counted object. 
 
Common base class for heavy weight IMP objects. 
 
Macros to control compiler warnings. 
 
#define IMP_UNUSED(variable)
 
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers. 
 
double get_delta_q() const 
return sampling resolution 
 
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers. 
 
#define IMP_THROW(message, exception_name)
Throw an exception with a message. 
 
double get_min_q() const 
return minimal sampling point 
 
A shared base class to help in debugging and things. 
 
FormFactorType
type of the form factors for profile calculations 
 
void set_ff_table(FormFactorTable *ff_table)
required for reciprocal space calculation 
 
void calculate_profile(const Particles &particles1, const Particles &particles2, FormFactorType ff_type=HEAVY_ATOMS)
 
computes distribution functions 
 
double get_max_q() const 
return maximal sampling point 
 
An exception for an invalid value being passed to IMP. 
 
double radius_of_gyration(const Particles &particles)
compute radius_of_gyration