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>
25IMPSAXS_BEGIN_NAMESPACE
27class 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);
80 void calculate_profile_reciprocal_partial(
const Particles& particles,
90 calculate_profile_real(particles1, particles2, ff_type);
99 double form_factor = 1.0);
105 void calculate_profile_symmetric(
const Particles& particles,
111 double max_distance)
const;
121 unsigned int point_number)
const;
141 void read_SAXS_file(
const std::string& file_name,
bool fit_file =
false,
double max_q = 0.0,
int units = 1);
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(); }
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);
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 "
329 "factors is not supported", IMP::ValueException);
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) {
computes distribution functions
A shared base class to help in debugging and things.
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Object(std::string name)
Construct an object with the given name.
A more IMP-like version of the std::vector.
void add_partial_profiles(const Vector< Profile * > &profiles, const Vector< double > &weights=Vector< double >())
add other partial profiles
void calculate_profile_partial(const Particles &particles1, const Particles &particles2, const Vector< double > &surface1=Vector< double >(), const Vector< double > &surface2=Vector< double >(), FormFactorType ff_type=HEAVY_ATOMS)
compute profile for fitting with hydration layer and excluded volume
Profile(const std::string &file_name, bool fit_file=false, double max_q=0.0, int units=1)
init from file
void add(const Vector< Profile * > &profiles, const Vector< double > &weights=Vector< double >())
add other profiles - useful for weighted ensembles
void scale(double c)
scale
void distribution_2_profile(const RadialDistributionFunction &r_dist)
convert to reciprocal space I(q) = Sum(P(r)*sin(qr)/qr)
void read_partial_profiles(const std::string &file_name)
read a partial profile from file (7 columns)
void calculate_profile_constant_form_factor(const Particles &particles, double form_factor=1.0)
calculate profile for any type of Particles that have coordinates
void calculate_profile(const Particles &particles, FormFactorType ff_type=HEAVY_ATOMS, bool reciprocal=false)
computes theoretical profile
void add_noise(double percentage=0.03)
add simulated noise
void profile_2_distribution(RadialDistributionFunction &rd, double max_distance) const
convert to real space P(r) function P(r) = 1/2PI^2 Sum(I(q)*qr*sin(qr))
bool is_uniform_sampling() const
checks the sampling of experimental profile
void add_errors()
add simulated error
void downsample(Profile *downsampled_profile, unsigned int point_number) const
downsample the profile to a given number of points
void calculate_profile_partial(const Particles &particles, const Vector< double > &surface=Vector< double >(), FormFactorType ff_type=HEAVY_ATOMS)
compute profile for fitting with hydration layer and excluded volume
unsigned int size() const
return number of entries in SAXS profile
double get_max_q() const
return maximal sampling point
Profile(double qmin=0.0, double qmax=0.5, double delta=0.005)
init for theoretical profile
void background_adjust(double start_q)
background adjustment option
void set_ff_table(FormFactorTable *ff_table)
required for reciprocal space calculation
double get_delta_q() const
return sampling resolution
void resample(const Profile *exp_profile, Profile *resampled_profile) const
return a profile that is sampled on the q values of the exp_profile
void calculate_profile(const Particles &particles1, const Particles &particles2, FormFactorType ff_type=HEAVY_ATOMS)
void offset(double c)
offset profile by c, I(q) = I(q) - c
double radius_of_gyration(double end_q_rg=1.3) const
compute radius of gyration with Guinier approximation
double calculate_I0(const Particles &particles, FormFactorType ff_type=HEAVY_ATOMS)
calculate Intensity at zero (= squared number of electrons)
void write_SAXS_file(const std::string &file_name, double max_q=0.0) const
print to file
void add_partial_profiles(const Profile *other_profile, double weight=1.0)
add partial profiles
void write_partial_profiles(const std::string &file_name) const
write a partial profile to file
double get_min_q() const
return minimal sampling point
void read_SAXS_file(const std::string &file_name, bool fit_file=false, double max_q=0.0, int units=1)
reads SAXS profile from file
double mean_intensity() const
calculate mean intensity
void sum_partial_profiles(double c1, double c2, bool check_cashed=true)
computes full profile for given fitting parameters
void add(const Profile *other_profile, double weight=1.0)
add another profile - useful for rigid bodies
FormFactorTable * get_default_form_factor_table()
IMP::Vector< IMP::Pointer< Profile > > Profiles
FormFactorType
type of the form factors for profile calculations
Vector< Pointer< Particle > > Particles
A list of reference-counted Particle objects.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
A smart pointer to a reference counted object.
Macros to control compiler warnings.
#define IMP_UNUSED(variable)