File: AngleInfo.cc

package info (click to toggle)
coot 1.1.18%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 220,004 kB
  • sloc: cpp: 495,934; python: 35,043; ansic: 26,143; lisp: 22,768; sh: 13,186; makefile: 2,746; awk: 441; xml: 245; csh: 14
file content (306 lines) | stat: -rw-r--r-- 8,839 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
 
#include <iostream>
#include <math.h>

#include "AngleInfo.h"


AngleInfo::AngleInfo() { 
   
   construct_theta_2_table(); 
   
   setup_angle_torsion_table(10,5);
   from_batched_angle_torsions(); 

} 


void
AngleInfo::assign_angle_torsion(double angle_bin_in, 
				double torsion_bin_in, 
				double n_count) {

   //
   // int theta_bin = int (round (( double (angle_bin_in) - angle_min)/step_ta_a));
   int theta_bin = int (floor ((angle_bin_in - 0)/step_ta_a + 0.5));

   int torsion_bin = int (floor ((torsion_bin_in - -180)/step_ta_t + 0.5 ));

//    cout << "debug: assigning " << theta_bin << " " << torsion_bin 
//  	<< " counts " << n_count << std::endl; 

   angle_torsion_table(theta_bin,torsion_bin) = float (n_count); 
//    std::cout << " and " 
// 	     << angle_torsion_table(theta_bin,torsion_bin) << endl; 

   // cout << "done" << endl; 
}

void
AngleInfo::from_batched_angle_torsions() { 

   from_batched_angle_torsions_bits_185();
   from_batched_angle_torsions_bits_190();
   from_batched_angle_torsions_bits_195();
   from_batched_angle_torsions_bits_200();
   from_batched_angle_torsions_bits_205();
   from_batched_angle_torsions_bits_210();
   from_batched_angle_torsions_bits_215();
   from_batched_angle_torsions_bits_220();
   from_batched_angle_torsions_bits_225();
   from_batched_angle_torsions_bits_230();
   from_batched_angle_torsions_bits_235();
   from_batched_angle_torsions_bits_240();
   from_batched_angle_torsions_bits_245();
   from_batched_angle_torsions_bits_250();
   from_batched_angle_torsions_bits_255();
   from_batched_angle_torsions_bits_260();
   from_batched_angle_torsions_bits_265();
   from_batched_angle_torsions_bits_270();
   from_batched_angle_torsions_bits_275();
   from_batched_angle_torsions_bits_280();
   from_batched_angle_torsions_bits_285();
   from_batched_angle_torsions_bits_290();
   from_batched_angle_torsions_bits_295();
   from_batched_angle_torsions_bits_300();
   from_batched_angle_torsions_bits_305();
   from_batched_angle_torsions_bits_310();
   from_batched_angle_torsions_bits_315();
   from_batched_angle_torsions_bits_320();
   from_batched_angle_torsions_bits_325();
   from_batched_angle_torsions_bits_330();
   from_batched_angle_torsions_bits_335();
   from_batched_angle_torsions_bits_340();
   from_batched_angle_torsions_bits_345();
   from_batched_angle_torsions_bits_350();
   from_batched_angle_torsions_bits_355();
   from_batched_angle_torsions_bits_360();
   from_batched_angle_torsions_bits_365();
   from_batched_angle_torsions_bits_370();
   from_batched_angle_torsions_bits_375();
   from_batched_angle_torsions_bits_380();
   from_batched_angle_torsions_bits_385();
   from_batched_angle_torsions_bits_390();
   from_batched_angle_torsions_bits_395();
   from_batched_angle_torsions_bits_400();
   from_batched_angle_torsions_bits_405();
   from_batched_angle_torsions_bits_410();
   from_batched_angle_torsions_bits_415();
   from_batched_angle_torsions_bits_420();
   from_batched_angle_torsions_bits_425();
   from_batched_angle_torsions_bits_430();
   from_batched_angle_torsions_bits_435();
   from_batched_angle_torsions_bits_440();
   from_batched_angle_torsions_bits_445();
   from_batched_angle_torsions_bits_450();
   from_batched_angle_torsions_bits_455();
   from_batched_angle_torsions_bits_460();
   from_batched_angle_torsions_bits_465();
   from_batched_angle_torsions_bits_470();
   from_batched_angle_torsions_bits_475();
   from_batched_angle_torsions_bits_480();
   from_batched_angle_torsions_bits_485();
   from_batched_angle_torsions_bits_490();
   from_batched_angle_torsions_bits_495();
   from_batched_angle_torsions_bits_500();
   from_batched_angle_torsions_bits_505();
   from_batched_angle_torsions_bits_510();
   from_batched_angle_torsions_bits_515();
   from_batched_angle_torsions_bits_520();
   from_batched_angle_torsions_bits_525();
   from_batched_angle_torsions_bits_530();
   from_batched_angle_torsions_bits_535();
   from_batched_angle_torsions_bits_540();


} 

void 
AngleInfo::setup_angle_torsion_table(float step_torsion_in,
				     float step_angle_in) { 

   step_ta_a = step_angle_in; 
   step_ta_t = step_torsion_in; 

//    angle_min = angle_min_in;
//    angle_max = angle_max_in;

//    torsion_min = torsion_min_in;
//    torsion_max = torsion_max_in;

   int angle_resize_size = nint((180 - 0)/step_ta_a);
   int torsion_resize_size = nint((180 - -180)/step_ta_t);

//    std::cout << "angle   resize size: " << resize_size << endl;
//    std::cout << "torsion resize size: " << torsion_resize_size << endl;


   // std::cout << "angle_resize_size:  " << angle_resize_size << std::endl; 
   // std::cout << "torsion_resize_size " << torsion_resize_size << std::endl; 

   if ( ! (angle_resize_size == torsion_resize_size) ) { 

      std::cout << "ERROR angle_resize_size and torsion_resize_size " 
	   << "must be equal" << std::endl; 
      
   } else { 

      angle_torsion_table.resize(torsion_resize_size); 
      angle_torsion_table_size_ = torsion_resize_size; 
      
   }
   

}

void
AngleInfo::print_angle_torsion_table() const {

   // FIXME

   for (float angle = 0; angle <= 180; angle += 2) { 
      for (float torsion = -180; torsion <= 180; torsion += 4) { 

	 std::cout << angle << " " << torsion << " " 
	      << prob_angle_torsion(angle, torsion) << std::endl; 

      }
   }
}


float
AngleInfo::check_sum() const {

   float sum = 0.0; 

   for (float angle = 0; angle <= 180; angle += step_ta_t) { 
      for (float torsion = -180; torsion < 180; torsion += step_ta_t) { 

	 sum += prob_angle_torsion(angle, torsion); 
      } 
   }

   std::cout << "# angle_torsion_table sum is: " << sum << std::endl;
   return sum; 
}

void
AngleInfo::normalize_angle_torsion() {

   float sum = 0.0; 

   for (float angle = 0; angle <= 180; angle += step_ta_t) { 
      for (float torsion = -180; torsion < 180; torsion += step_ta_t) { 

	 sum += prob_angle_torsion(angle, torsion); 
      } 
   }

   for (float angle = 0; angle <= 180; angle += step_ta_t) { 
      for (float torsion = -180; torsion < 180; torsion += step_ta_t) { 

	 assign_angle_torsion(angle,torsion, 
			      prob_angle_torsion(angle,torsion)/sum); 
      } 
   }
   
}

// Return the probability of the nearest bin
// so that 89.5 will have the same return values as 90.0
// 
float
AngleInfo::prob_angle_torsion_by_bin(float angle, float torsion) const {
   //
   // int theta_bin = nint ((angle - angle_min)/step_ta_a);
   int theta_bin = nint ((angle)/step_ta_a);

   int torsion_bin = nint ((torsion - -180)/step_ta_t);

   std::cout << "debug: theta_bin: " << theta_bin << " torsion_bin: "
	     << torsion_bin << std::endl; 

   return angle_torsion_table.interp(theta_bin,torsion_bin); 
}

// As above, except we interpolate from the angles, not just the
// flat bin, 5 degrees wide.
// float
// AngleInfo::interp_prob_angle_torsion(float angle, float torsion) const {

// }
   

float 
AngleInfo::prob_angle_torsion(float angle, float torsion) const { 

   float angle_index = angle/step_ta_a; 
   float torsion_index = (torsion +180)/step_ta_t; 

//     cout << "evaluating: angle bin: " << angle_index 
//  	<< ", torsion bin: " << torsion_index << endl; 

   int a = int (floor(angle_index));
   int t = int (floor(torsion_index)); 
   
//    cout << "DEBUG: int angle bin " << a 
// 	<< " and int torsion bin " << t << " has value " 
// 	<< angle_torsion_table(a,t) << endl; 

//    cout << "DEBUG: 46, 62 " << angle_torsion_table(46,62) << endl; 

   return angle_torsion_table.interp(angle_index, torsion_index); 

} 

void 
AngleInfo::theta_2_table_assign_step(float step) { 

   theta_2_step = step;

   int nbins = int (floor(180/theta_2_step)) + 1; 
   
   // cout << "DEBUG: theta_2_table nbins: " << nbins << endl; 
   theta_2_array = new float[nbins]; 
   theta_2_array[nbins -1] = 0; // put the end point at zero.
                                // (it may not be otherwise assigned). 
}

void 
AngleInfo::assign_theta_2(float angle, float n_count) { 
   
   int i_bin = nint(angle/theta_2_step); 
//    cout << "DEBUG:  assigning bin "<< i_bin << " with " 
// 	<< n_count << " counts" << endl; 

   theta_2_array[i_bin] = n_count; 

}

// look up theta_2 and return n_count for the apropriate bin.
// Except that we are doing interpolation too.
// 
float 
AngleInfo::theta_2_score(float theta_2_in) const {

   float f = (floor (theta_2_in/theta_2_step));

   int bin = int (f); 

   float w1 = theta_2_in/theta_2_step - f;
   float w2 = 1.0 - w1; 

//    cout << theta_2_in << " corresponds to bin: " << bin << endl; 
//    cout << " combining: " << theta_2_array[bin] << " and "
// 	<< theta_2_array[bin+1] << " with " << w1 << " and " << w2 << endl; 

   return w2*theta_2_array[bin] + w1*theta_2_array[bin+1]; 

} 


void
a_init() { 
   AngleInfo ai;  
}