IMP.bff
Loading...
Searching...
No Matches
AV.h
Go to the documentation of this file.
1
9#ifndef IMPBFF_AV_H
10#define IMPBFF_AV_H
11
12#include <IMP/bff/bff_config.h>
13
14#include <IMP/decorator_macros.h>
15#include <IMP/Decorator.h>
16#include <IMP/algebra/Vector3D.h>
17#include <IMP/algebra/Transformation3D.h>
18#include <IMP/core/XYZ.h>
19#include <IMP/log.h>
20
21
22#include <IMP/bff/PathMap.h>
23
24#include <string>
25#include <cmath>
26#include <vector>
27#include <limits>
28#include <iostream> // std::cout, std::cout, std::flush
29
30#include <IMP/bff/internal/json.h>
31#include <IMP/bff/internal/InverseSampler.h>
32// requires C++14
33// #include <boost/histogram.hpp> // make_histogram, regular, weight, indexed
34#include <IMP/bff/internal/Histogram.h>
35
36IMPBFF_BEGIN_NAMESPACE
37
38
48
49
50
52class IMPBFFEXPORT AVPairDistanceMeasurement{
53
54public:
55
56 double distance = -1;
57 double error_neg = -1;
58 double error_pos = -1;
59 double forster_radius = 52.0;
60 int distance_type = IMP::bff::DYE_PAIR_DISTANCE_MEAN;
61 std::string position_1;
62 std::string position_2;
63
65 std::string get_json();
66
72 double score_model(double model);
73
74};
75
76
77
79
90class IMPBFFEXPORT AV : public IMP::core::Gaussian {
91
92private:
93
94 IMP::bff::PathMap* av_map_ = nullptr;
95
96protected:
97
98 IMP::algebra::VectorD<9> get_parameter() const {
99 IMP::algebra::VectorD<9> v;
100 v[0] = get_linker_length();
101 v[1] = get_radius1();
102 v[2] = get_radius2();
103 v[3] = get_radius3();
104 v[4] = get_linker_width();
105 v[5] = get_allowed_sphere_radius();
106 v[6] = get_contact_volume_thickness();
107 v[7] = get_contact_volume_trapped_fraction();
108 v[8] = get_simulation_grid_resolution();
109 return v;
110 }
111
112public:
113
118 IMP::bff::PathMapHeader create_path_map_header();
119
129
142 static FloatKey get_av_key(unsigned int i){
143 IMP_USAGE_CHECK(i < 9, "Out of range av feature");
144 static const FloatKey k[] = {
145 FloatKey("linker_length"),
146 FloatKey("radius1"),
147 FloatKey("radius2"),
148 FloatKey("radius3"),
149 FloatKey("linker_width"),
150 FloatKey("allowed_sphere_radius"),
151 FloatKey("contact_volume_thickness"),
152 FloatKey("contact_volume_trapped_fraction"),
153 FloatKey("simulation_grid_resolution")
154 };
155 return k[i];
156 }
157
177 static void do_setup_particle(Model *m, ParticleIndex pi,
178 ParticleIndex pi_source,
179 double linker_length = 20.0,
180 const algebra::Vector3D radii = algebra::Vector3D(3.5, 0, 0),
181 double linker_width = 0.5,
182 double allowed_sphere_radius = 1.5,
183 double contact_volume_thickness = 0.0,
184 double contact_volume_trapped_fraction = -1,
185 double simulation_grid_resolution = 1.5) {
186 if (!IMP::core::Gaussian::get_is_setup(m, pi)) {
187 IMP::core::Gaussian::setup_particle(m, pi);
188 }
189 m->add_attribute(get_av_key(0), pi, linker_length);
190 m->add_attribute(get_av_key(1), pi, radii[0]);
191 m->add_attribute(get_av_key(2), pi, radii[1]);
192 m->add_attribute(get_av_key(3), pi, radii[2]);
193 m->add_attribute(get_av_key(4), pi, linker_width);
194 m->add_attribute(get_av_key(5), pi, allowed_sphere_radius);
195 m->add_attribute(get_av_key(6), pi, contact_volume_thickness);
196 m->add_attribute(get_av_key(7), pi, contact_volume_trapped_fraction);
197 m->add_attribute(get_av_key(8), pi, simulation_grid_resolution);
198 m->add_attribute(get_particle_key(0), pi, pi_source);
199 }
200
206 static ParticleIndexKey get_particle_key(unsigned int i) {
207 static const ParticleIndexKey k[1] = {
208 ParticleIndexKey("Source particle")
209 };
210 return k[i];
211 }
212
217 ParticleIndex get_particle_index() const {
218 return Decorator::get_particle_index();
219 }
220
226 ParticleIndex get_particle_index(unsigned int i) const {
227 return get_model()->get_attribute(get_particle_key(i), get_particle_index());
228 }
229
234 Particle* get_particle() const {
235 return Decorator::get_particle();
236 }
237
243 Particle* get_particle(unsigned int i) const {
244 return get_model()->get_particle(get_particle_index(i));
245 }
246 IMP_DECORATOR_METHODS(AV, IMP::core::Gaussian);
247
249 IMP_DECORATOR_SETUP_1(AV, IMP::ParticleIndex, pi_source);
250 IMP_DECORATOR_GET_SET(linker_length, get_av_key(0), Float, Float);
251 IMP_DECORATOR_GET_SET(radius1, get_av_key(1), Float, Float);
252 IMP_DECORATOR_GET_SET(radius2, get_av_key(2), Float, Float);
253 IMP_DECORATOR_GET_SET(radius3, get_av_key(3), Float, Float);
254 IMP_DECORATOR_GET_SET(linker_width, get_av_key(4), Float, Float);
255 IMP_DECORATOR_GET_SET(allowed_sphere_radius, get_av_key(5), Float, Float);
256 IMP_DECORATOR_GET_SET(contact_volume_thickness, get_av_key(6), Float, Float);
257 IMP_DECORATOR_GET_SET(contact_volume_trapped_fraction, get_av_key(7), Float, Float);
258 IMP_DECORATOR_GET_SET(simulation_grid_resolution, get_av_key(8), Float, Float);
259
260
268 IMP::algebra::Vector3D get_radii(){
269 return IMP::algebra::Vector3D({get_radius1(), get_radius3(), get_radius3()});
270 }
271
273
276 return
277 get_particle()->get_is_optimized(get_av_key(0)) &&
278 get_particle()->get_is_optimized(get_av_key(1)) &&
279 get_particle()->get_is_optimized(get_av_key(2)) &&
280 get_particle()->get_is_optimized(get_av_key(3)) &&
281 get_particle()->get_is_optimized(get_av_key(6)) &&
282 get_particle()->get_is_optimized(get_av_key(7));
283 }
284
287 get_particle()->set_is_optimized(get_av_key(0), tf);
288 get_particle()->set_is_optimized(get_av_key(1), tf);
289 get_particle()->set_is_optimized(get_av_key(2), tf);
290 get_particle()->set_is_optimized(get_av_key(3), tf);
291 get_particle()->set_is_optimized(get_av_key(6), tf);
292 get_particle()->set_is_optimized(get_av_key(7), tf);
293 }
294
302 void set_av_parameter(const nlohmann::json &j);
303
304
306
308 algebra::Vector3D get_derivatives() const {
309 return get_model()->get_coordinate_derivatives(get_particle_index());
310 }
311
312 static bool get_is_setup(Model *m, ParticleIndex pi) {
313 return m->get_has_attribute(get_av_key(2), pi);
314 }
315
320 IMP::bff::PathMap* get_map() const;
321
326 void resample(bool shift_xyz=true);
327
332 IMP::algebra::Vector3D get_mean_position(bool include_source=true) const;
333
338 IMP::algebra::Vector3D get_source_coordinates() const;
339
344 Particle* get_source() const;
345
346};
347
348IMP_DECORATORS(AV, AVs, ParticlesTemp);
349
357template<typename T>
358T inline fret_efficiency(T distance, double forster_radius){
359 double rda_r0_6 = std::pow(distance / forster_radius, 6.0);
360 return 1. / (1. + rda_r0_6);
361}
362
370template<typename T>
371T inline distance_fret(double fret_efficiency, double forster_radius){
372 return forster_radius * std::pow(1. / fret_efficiency - 1.0, 1. / 6.);
373}
374
384IMPBFFEXPORT double av_distance(
385 const AV& a,
386 const AV& b,
387 double forster_radius = 52.0,
388 int distance_type = DYE_PAIR_DISTANCE_MEAN,
389 int n_samples = 10000
390);
391
392// Draw random points in AV. Returns (x,y,z,d) vector
393IMPBFFEXPORT std::vector<double> av_random_points(
394 const AV& av1,
395 int n_samples=10000
396);
397
399IMPBFFEXPORT std::vector<double> av_random_distances(
400 const AV& av1,
401 const AV& av2,
402 int n_samples=10000
403);
404
405
407IMPBFFEXPORT std::vector<double> av_distance_distribution(
408 const AV& av1,
409 const AV& av2,
410 std::vector<double> axis,
411 //double start, double stop, int n_bins, // for boost histogram
412 int n_samples=10000
413);
414
415
429IMPBFFEXPORT IMP::ParticleIndex search_labeling_site(
430 const IMP::core::Hierarchy& hier,
431 std::string json_str = "",
432 const nlohmann::json &json_data = nlohmann::json()
433);
434
435
436IMPBFF_END_NAMESPACE
437
438#endif /* IMPBFF_AV_H */
IMPBFFEXPORT IMP::ParticleIndex search_labeling_site(const IMP::core::Hierarchy &hier, std::string json_str="", const nlohmann::json &json_data=nlohmann::json())
Find the particle index of a labeling site.
IMPBFFEXPORT double av_distance(const AV &a, const AV &b, double forster_radius=52.0, int distance_type=DYE_PAIR_DISTANCE_MEAN, int n_samples=10000)
Computes the distance to another accessible volume.
DyePairMeasures
Different types of distances between two accessible volumes.
Definition AV.h:40
@ DYE_PAIR_DISTANCE_E
Definition AV.h:41
@ DYE_PAIR_DISTANCE_DISTRIBUTION
Mean FRET efficiency.
Definition AV.h:45
@ DYE_PAIR_EFFICIENCY
Distance between AV mean positions.
Definition AV.h:44
@ DYE_PAIR_DISTANCE_MP
Mean distance <R_DA>
Definition AV.h:43
@ DYE_PAIR_DISTANCE_MEAN
Mean FRET averaged distance R_E.
Definition AV.h:42
@ DYE_PAIR_XYZ_DISTANCE
Distance distribution.
Definition AV.h:46
T distance_fret(double fret_efficiency, double forster_radius)
Computes the distance between two volumes given the FRET efficiency and Forster radius.
Definition AV.h:371
IMP_DECORATORS(AV, AVs, ParticlesTemp)
T fret_efficiency(T distance, double forster_radius)
Computes the FRET efficiency given the distance and Forster radius.
Definition AV.h:358
IMPBFFEXPORT std::vector< double > av_random_distances(const AV &av1, const AV &av2, int n_samples=10000)
Random sampling over AV/AV distances.
IMPBFFEXPORT std::vector< double > av_random_points(const AV &av1, int n_samples=10000)
IMPBFFEXPORT std::vector< double > av_distance_distribution(const AV &av1, const AV &av2, std::vector< double > axis, int n_samples=10000)
Compute the distance to another accessible volume.
A decorator for a particle with accessible volume (AV).
Definition AV.h:90
IMP_DECORATOR_GET_SET(radius2, get_av_key(2), Float, Float)
Particle * get_particle() const
Get the particle pointer of the AV object.
Definition AV.h:234
IMP::bff::PathMapHeader create_path_map_header()
Creates a path map header.
IMP::algebra::Vector3D get_radii()
Returns the radii of an object.
Definition AV.h:268
static ParticleIndexKey get_particle_key(unsigned int i)
Get the particle key for the specified index.
Definition AV.h:206
IMP::algebra::VectorD< 9 > get_parameter() const
Definition AV.h:98
bool get_parameters_are_optimized() const
Get whether the coordinates are optimized.
Definition AV.h:275
void set_av_parameters_are_optimized(bool tf) const
Set whether the coordinates are optimized.
Definition AV.h:286
IMP::algebra::Vector3D get_mean_position(bool include_source=true) const
Get the mean position of the AV object.
IMP_DECORATOR_GET_SET(contact_volume_trapped_fraction, get_av_key(7), Float, Float)
IMP::bff::PathMap * get_map() const
Get the PathMap associated with the AV object.
Particle * get_source() const
Get the source particle of the AV object.
void set_av_parameter(const nlohmann::json &j)
Sets the AV parameter using a JSON object.
static void do_setup_particle(Model *m, ParticleIndex pi, ParticleIndex pi_source, double linker_length=20.0, const algebra::Vector3D radii=algebra::Vector3D(3.5, 0, 0), double linker_width=0.5, double allowed_sphere_radius=1.5, double contact_volume_thickness=0.0, double contact_volume_trapped_fraction=-1, double simulation_grid_resolution=1.5)
Sets up the attributes for a particle in a model for AV (Anisotropic Volume) calculations.
Definition AV.h:177
ParticleIndex get_particle_index() const
Get the particle index of the AV object.
Definition AV.h:217
void init_path_map()
Initializes the path map.
ParticleIndex get_particle_index(unsigned int i) const
Get the particle index of the AV object at the specified index.
Definition AV.h:226
algebra::Vector3D get_derivatives() const
Get the vector of derivatives accumulated by add_to_derivatives().
Definition AV.h:308
Particle * get_particle(unsigned int i) const
Get the particle pointer of the AV object at the specified index.
Definition AV.h:243
void resample(bool shift_xyz=true)
Resample the AV object.
IMP_DECORATOR_GET_SET(radius1, get_av_key(1), Float, Float)
IMP_DECORATOR_GET_SET(simulation_grid_resolution, get_av_key(8), Float, Float)
static FloatKey get_av_key(unsigned int i)
Get the FloatKey object for a specific AV feature.
Definition AV.h:142
IMP_DECORATOR_SETUP_1(AV, IMP::ParticleIndex, pi_source)
IMP_DECORATOR_GET_SET(linker_length, get_av_key(0), Float, Float)
IMP_DECORATOR_GET_SET(allowed_sphere_radius, get_av_key(5), Float, Float)
static bool get_is_setup(Model *m, ParticleIndex pi)
Definition AV.h:312
IMP_DECORATOR_GET_SET(contact_volume_thickness, get_av_key(6), Float, Float)
IMP_DECORATOR_METHODS(AV, IMP::core::Gaussian)
IMP_DECORATOR_GET_SET(linker_width, get_av_key(4), Float, Float)
IMP::algebra::Vector3D get_source_coordinates() const
Get the source coordinates of the AV object.
IMP_DECORATOR_GET_SET(radius3, get_av_key(3), Float, Float)
Container for experimental distance measurement.
Definition AV.h:52
std::string get_json()
Get a JSON string.
double score_model(double model)
Score a model distance against the experimental distance.
std::string position_1
Definition AV.h:61
std::string position_2
Definition AV.h:62