19 int zmin,
int zmax,
double radius,
int norm_flag)
27 if ( r > radius )
return 0;
31 double a, cosang, sinang, value(0);
33 long umin = (long)((zmin-(
float)zz)/pix_rise);
34 if ( zz < zmin ) umin += 1;
35 long umax = (long)((zmax-(
float)zz)/pix_rise);
36 if ( zz > zmax ) umax -= 1;
38 for ( u = umin; u <= umax; u++ ) {
43 xs = d[0]*cosang - d[1]*sinang +
image[nn].
origin()[0];
44 ys = d[0]*sinang + d[1]*cosang +
image[nn].
origin()[1];
51 if ( norm_flag && num ) value /= num;
61 double value = (*this)[i];
68 if ( norm_flag ) value /= 2;
74 double latconst,
int zmin,
int zmax,
double radius,
int norm_flag)
82 if ( r > radius )
return 0;
85 double da(atan2(d[1], d[0]));
88 double t(sqrt(h*h + h*k + k*k));
89 double a(atan2(k*sqrt(3.0)/2, h+k/2.0));
93 double value(0), bottom(zmin/pix_rise), top(zmax/pix_rise);
95 start[1] = zz/pix_rise;
96 while ( start[1] < bottom ) start += w;
97 while ( start[1] > bottom ) start -= w;
99 while ( lat[1] < top ) {
100 for ( lat = start; lat[0] < t + start[0]; lat += u ) {
101 if ( lat[1] >= bottom && lat[1] <= top ) {
102 a = da +
TWOPI * lat[0]/t;
105 loc[2] = lat[1] * pix_rise;
113 if ( norm_flag && num ) value /= num;
134 int dyad_axis,
int zmin,
int zmax,
double radius,
int norm_flag)
138 if ( helix_rise < 0 ) {
139 helix_rise = -helix_rise;
140 helix_angle = -helix_angle;
143 if ( radius <= 0 ) radius = x/2;
145 if ( zmin < 0 ) zmin = 0;
146 if ( zmax >= z ) zmax = z - 1;
149 long nun((
long) ((zmax - zmin)/pix_rise));
152 double v, vr, d, nsum(0), sum1(0), sum2(0), sum1sq(0), sum2sq(0), sum12(0), R(1e37), CC(0);
153 double w, ndsum(0), dsum1(0), dsum2(0), dsum1sq(0), dsum2sq(0), dsum12(0), Rd, CCd;
155 float* symdata =
new float[datasize];
156 for ( i=0; i<datasize; i++ ) symdata[i] = 0;
159 cout <<
"Helical symmetrization:" << endl;
160 cout <<
"Helical axis origin: " <<
image->
origin() << endl;
161 cout <<
"Asymmetric unit rise: " << helix_rise <<
" A" << endl;
162 cout <<
"Asymmetric unit rotation angle: " << helix_angle*180/
M_PI <<
" degrees" << endl;
163 if ( dyad_axis == 2 ) cout <<
"Dyad axis along the x axis" << endl;
164 cout <<
"Radius: " << radius <<
" pixels" << endl;
165 cout <<
"Limits along helical axis: " << zmin <<
" - " << zmax <<
" pixels" << endl;
166 cout <<
"Units along helical axis: " << nun << endl;
169 if ( norm_flag) w = 1;
175 dispatch_apply(datasize, dispatch_get_global_queue(0, 0), ^(
size_t k){
176 symdata[k] =
helix_interpolate(k, helix_rise, helix_angle, zmin, zmax, radius, norm_flag);
179 #pragma omp parallel for
180 for ( i=0; i<datasize; i++ )
181 symdata[i] =
helix_interpolate(i, helix_rise, helix_angle, zmin, zmax, radius, norm_flag);
184 for ( i=0; i<datasize; i++ ) {
198 if ( dyad_axis == 2 ) {
200 if ( !norm_flag ) w = 2;
203 dispatch_apply(datasize, dispatch_get_global_queue(0, 0), ^(
size_t k){
207 #pragma omp parallel for
208 for ( i=0; i<datasize; i++ )
212 for ( i=0; i<datasize; i++ ) {
228 d = (sum1sq - sum1*sum1/nsum)*(sum2sq - sum2*sum2/nsum);
231 R = sqrt((sum1sq - 2*sum12 + sum2sq)/d);
232 CC = (sum12 - sum1*sum2/nsum)/d;
237 d = (dsum1sq - dsum1*dsum1/ndsum)*(dsum2sq - dsum2*dsum2/ndsum);
240 Rd = sqrt((dsum1sq - 2*dsum12 + dsum2sq)/d);
241 CCd = (dsum12 - dsum1*dsum2/ndsum)/d;
246 cout <<
"Helical symmetry R factor: " << R << endl;
247 cout <<
"Helical symmetry correlation: " << CC << endl;
248 if ( dyad_axis == 2 ) {
249 cout <<
"Dyad R factor: " << Rd << endl;
250 cout <<
"Dyad correlation: " << CCd << endl;
281 double seam_shift,
int dyad_axis,
int zmin,
int zmax,
double radius,
int norm_flag)
285 if ( helix_rise < 0 ) {
286 helix_rise = -helix_rise;
287 helix_angle = -helix_angle;
290 if ( zmin < 0 ) zmin = 0;
291 if ( zmax >= z ) zmax = z - 1;
292 if ( zmax < zmin ) swap(zmin, zmax);
294 long nproto((
long) (
TWOPI/fabs(helix_angle) + 0.5));
295 double seam_rise(nproto*helix_rise/seam_shift);
299 double hr(helix_angle*pix_seam_rise - seam_angle*pix_helix_rise);
300 double daz(seam_angle/pix_seam_rise);
303 cout <<
"Helical symmetrization with a seam with a shift of " << seam_shift <<
":" << endl;
304 cout <<
"Asymmetric unit rise: " << helix_rise <<
" A" << endl;
305 cout <<
"Asymmetric unit rotation angle: " << helix_angle*180/
M_PI <<
" degrees" << endl;
306 cout <<
"Number of protofilaments: " << nproto << endl;
307 cout <<
"Seam rise: " << seam_rise <<
" A" << endl;
308 cout <<
"Seam rotation angle: " << seam_angle*180/
M_PI <<
" degrees" << endl;
310 cout <<
"Limits along helical axis: " << zmin <<
" - " << zmax <<
" pixels" << endl;
311 cout <<
"Units along helical axis: " << (long) ((zmax - zmin)*nproto/pix_seam_rise) << endl << endl;
314 long i, xx, yy, zz, nn;
316 double xs, ys, zs, dx, dy, dz, d, d2;
317 double rad(0), radsq, a, sa, da, as, cosang, sinang;
318 double v, vr, CC, R(0);
320 float* symdata =
new float[datasize];
321 float* num =
new float[datasize];
324 double* nsum =
new double[na];
325 double* s1 =
new double[na];
326 double* s2 =
new double[na];
327 double* s1sq =
new double[na];
328 double* s2sq =
new double[na];
329 double* s12 =
new double[na];
331 for ( i=0; i<datasize; i++ ) symdata[i] = num[i] = 0;
333 for ( u=0; u<na; u++ ) nsum[u] = s1[u] = s2[u] = s1sq[u] = s2sq[u] = s12[u] = 0;
335 for ( i=nn=0; nn<n; nn++ ) {
336 if ( radius > 0 ) rad = radius;
343 if ( rad < 1 ) rad = x/2;
345 for ( zz=0; zz<z; zz++ ) {
348 kmin = (long)((zmin-(
double)zz)/pix_seam_rise);
349 if ( zz < zmin )
kmin += 1;
350 kmax = (long)((zmax-(
double)zz)/pix_seam_rise);
351 if ( zz > zmax )
kmax -= 1;
352 for ( yy=0; yy<y; yy++ ) {
354 for ( xx=0; xx<x; xx++, i++ ) {
359 if ( a*pix_seam_rise < seam_angle*dz ) a +=
TWOPI;
361 if ( da < 0 ) da +=
TWOPI;
363 ia = (long) (na*da/
TWOPI);
364 if ( ia < 0 ) ia += na;
365 if ( ia >= na ) ia -= na;
366 u = (long) ((a*pix_seam_rise - seam_angle*dz)/hr);
367 while ( u < 0 ) u += nproto;
368 while ( u >= nproto ) u -= nproto;
371 for ( h=-u; h<nproto-u; h++ ) {
372 zs = zz + h*pix_helix_rise + k*pix_seam_rise;
373 as = h*helix_angle + k*seam_angle;
376 xs = dx*cosang - dy*sinang +
image[nn].
origin()[0];
377 ys = dx*sinang + dy*cosang +
image[nn].
origin()[1];
395 cout <<
"Completed: " << (nn*z+zz)*100.0/(n*z) <<
" %" <<
"\r" << flush;
400 for ( i=0; i<datasize; i++ )
401 if ( num[i] ) symdata[i] /= num[i];
409 for ( ia=0; ia<na; ia++ ) {
413 d = (s1sq[ia] - s1[ia]*s1[ia]/nsum[ia])*(s2sq[ia] - s2[ia]*s2[ia]/nsum[ia]);
415 R = sqrt(nsum[ia]*(s1sq[ia] - 2*s12[ia] + s2sq[ia])/d);
416 CC = (s12[ia] - s1[ia]*s2[ia]/nsum[ia])/sqrt(d);
423 cout <<
"Helical symmetry R factor: " << R << endl;
424 cout <<
"Helical symmetry correlation: " << CC << endl << endl;
428 long umin, umax, ulen(na/(2*nproto) + 1);
429 double cc_min, cc_max, cc_cut, angle_best(0);
431 Bstring title(
"Seamed helix symmetrization");
450 cout << endl <<
"Angle\tCC" << endl;
451 for ( ia=0, CC=0, cc_min=1, cc_max=0; ia<na; ia++ ) {
455 for ( u = umin, s1[ia] = 0; u < umax; u++ ) {
456 i = (u < 0)? u + na: u;
457 if ( i >= na ) i -= na;
461 if ( cc_min > s1[ia] ) cc_min = s1[ia];
462 if ( cc_max < s1[ia] ) cc_max = s1[ia];
464 (*plot)[ia] = ia*360.0/na;
465 (*plot)[ia+na] = s1[ia];
467 cout << ia*360.0/na <<
tab << s1[ia] << endl;
471 cc_cut = (cc_max + cc_min)/2;
473 for ( i=1; i<na/2; i++ ) {
476 if ( s1[i] > cc_cut && s1[i-1] < cc_cut ) angle_best = a;
477 if ( s1[i] < cc_cut && s1[i-1] > cc_cut ) angle_best = a;
478 a = ia*
TWOPI*1.0L/na;
479 if ( s1[ia] > cc_cut && s1[ia-1] < cc_cut ) angle_best = a;
480 if ( s1[ia] < cc_cut && s1[ia-1] > cc_cut ) angle_best = a;
485 cout <<
"Correlation coefficient: " << CC << endl;
486 cout <<
"Best seam location angle: " << angle_best*180.0/
M_PI <<
" degrees" << endl;
487 cout <<
"Min & max correlation: " << cc_min <<
" " << cc_max << endl << endl;
492 txt =
Bstring(helix_rise,
"Helix rise: %g A");
494 txt =
Bstring(helix_angle*180.0/
M_PI,
"Helix rotation angle: %g degrees");
496 txt =
Bstring(seam_rise,
"Seam rise: %g A");
498 txt =
Bstring(seam_angle*180.0/
M_PI,
"Seam rotation angle: %g degrees");
500 txt =
Bstring(angle_best*180.0/
M_PI,
"Seam location angle: %g degrees");
502 txt =
Bstring(CC,
"Correlation coefficient: %g");
526 long i, j, k, xx, yy, zz, nn, cc, ir;
527 long rmax = (long) sqrt(x*x + y*y);
528 long cylsize(n*z*rmax*c);
532 cout <<
"Symmetrizing cylindrically around " <<
image->
origin() << endl << endl;
537 case 1: pcyl =
new Bimage(
Float, compoundtype, z, rmax, 1, n);
break;
538 default: pcyl =
new Bimage(
Float, compoundtype, rmax, 1, z, n);
541 float* num =
new float[cylsize];
542 for ( i=0; i<cylsize; i++ ) num[i] = 0;
544 for ( i=nn=0; nn<n; nn++ ) {
545 for ( zz=0; zz<z; zz++ ) {
546 for ( yy=0; yy<y; yy++ ) {
548 for ( xx=0; xx<x; xx++ ) {
550 r = sqrt(dx*dx + dy*dy);
554 j = ((nn*z + zz)*rmax + ir)*c;
557 j = ((nn*rmax + ir)*z + zz)*c;
560 for ( cc=0; cc<c; cc++, i++, j++, k++ ) {
561 pcyl->
add(j, (1-f) * (*this)[i]);
562 pcyl->
add(k, f * (*
this)[i]);
571 for ( i=0; i<cylsize; i++ )
if ( num[i] ) pcyl->
set(i, (*pcyl)[i]/num[i]);
590 long i, j, k, xx, yy, zz, nn, cc, ir;
593 for ( i=nn=0; nn<n; nn++ ) {
594 for ( zz=0; zz<z; zz++ ) {
595 for ( yy=0; yy<y; yy++ ) {
597 for ( xx=0; xx<x; xx++ ) {
599 r = sqrt(dx*dx + dy*dy);
602 j = ((nn*z + zz)*rmax + ir)*c;
604 for ( cc=0; cc<c; cc++, i++, j++, k++ )
605 set(i, (1-f)*(*pcyl)[j] + f*(*pcyl)[k]);
634 int zmin,
int zmax,
double radius,
int norm_flag)
639 double v, vr, d, nsum(0), sum1(0), sum2(0), sum1sq(0), sum2sq(0), sum12(0), R(1e37), CC(0);
641 if ( zmin < 0 ) zmin = 0;
642 if ( zmax >= z ) zmax = z - 1;
644 if ( radius <= 0 ) radius = x/2;
646 float* symdata =
new float[datasize];
647 for ( i=0; i<datasize; i++ ) symdata[i] = 0;
650 cout <<
"Tubular symmetrization:" << endl;
651 cout <<
"Tubular axis origin: " <<
image->
origin() << endl;
652 cout <<
"Lattice parameters: " << h <<
" x " << k << endl;
653 cout <<
"Lattice constant: " << latconst <<
" A" << endl;
654 cout <<
"Radius: " << radius <<
" pixels" << endl;
655 cout <<
"Limits along helical axis: " << zmin <<
" - " << zmax <<
" pixels" << endl;
660 dispatch_apply(datasize, dispatch_get_global_queue(0, 0), ^(
size_t k){
661 symdata[k] =
tube_interpolate(k, h, k, latconst, zmin, zmax, radius, norm_flag);
662 cout << k*100.0/datasize <<
" % \r" << flush;
665 #pragma omp parallel for
666 for ( i=0; i<datasize; i++ )
667 symdata[i] =
tube_interpolate(i, h, k, latconst, zmin, zmax, radius, norm_flag);
670 for ( i=0; i<datasize; i++ ) {
685 d = (sum1sq - sum1*sum1/nsum)*(sum2sq - sum2*sum2/nsum);
688 R = sqrt((sum1sq - 2*sum12 + sum2sq)/d);
689 CC = (sum12 - sum1*sum2/nsum)/d;
694 cout <<
"Tubular symmetry R factor: " << R << endl;
695 cout <<
"Tubular symmetry correlation: " << CC << endl;
726 long i, xx, yy, zz, nn;
727 double angle, dx, dy;
729 double angle0(atan2(offset[1], offset[0]));
730 double angle2(atan2(
distance*sqrt(1-cos(helix_angle)), helix_rise*1.0));
735 float* nudata =
new float[datasize];
737 for ( i=0; i<datasize; i++ ) nudata[i] = 0;
739 for ( i=nn=0; nn<n; nn++ ) {
742 for ( zz=0; zz<z; zz++ ) {
744 angle = helix_angle*(zz -
image[nn].
origin()[2])/u[2] + angle0;
751 for ( yy=0; yy<y; yy++ ) {
752 old[1] = yy - dy - ori[1];
753 for ( xx=0; xx<x; xx++, i++ ) {
754 old[0] = xx - dx - ori[0];
755 rold = (mat * old) + ori;
784 cout <<
"Elliptical distortion: " << endl;
785 cout <<
"Major axis angle: " << angle*180.0/
M_PI <<
" degrees" << endl;
786 cout <<
"Shift at major axis: " <<
shift <<
" pixels" << endl << endl;
789 long xx, yy, zz, nn, i, j, inz, ix, iy;
790 double dx, dy, a, r, s, rx, ry, fx, fy;
791 float* nudata =
new float[datasize];
793 for ( i=0; i<datasize; i++ ) nudata[i] = 0;
795 for ( j=nn=0; nn<n; nn++ ) {
796 for ( zz=0; zz<z; zz++ ) {
797 inz = (nn*z + zz)*y*x;
798 for ( yy=0; yy<y; yy++ ) {
800 for ( xx=0; xx<x; xx++, j++ ) {
802 r = sqrt(dx*dx + dy*dy);
803 a = 2*(atan2(dy, dx) - angle);
811 if ( ix < x-1 && iy < y-1 ) {
815 nudata[j] = (1-fx)*(1-fy)*(*this)[i] + fx*(1-fy)*(*
this)[i+1] +
816 (1-fx)*fy*(*
this)[i+x] + fx*fy*(*this)[i+x+1];
849 double angle_step,
int bin,
double hires,
double lores,
double radius)
851 angle_step = fabs(angle_step);
852 if ( angle_step < 0.0001 ) angle_step = 0.0001;
853 if ( angle_start > angle_end ) swap(angle_start, angle_end);
855 if ( bin < 1 ) bin = 1;
856 if ( bin > 4 ) bin = 4;
858 if ( lores > 0 && hires > lores ) swap(hires, lores);
862 if ( radius < 1 ) radius = x/2;
868 long i, j, na, max_iter(10);
869 double rise, angle, offset, bestrise(0), bestangle(0);
870 double cc, dd, bestcc(0), mincc(1);
875 cout <<
"Searching for helical parameters by cross-correlation:" << endl;
876 cout <<
"Angular range " << angle_start*180.0/
M_PI <<
" - "
877 << angle_end*180.0/
M_PI <<
" degrees" << endl;
878 cout <<
"Angular increment: " << angle_step*180.0/
M_PI <<
" degrees" << endl;
879 cout <<
"Resolution limits: " << hires <<
" - " << lores <<
" A" << endl;
880 cout <<
"Radius: " << radius << endl;
881 cout <<
"Binning: " << bin << endl << endl;
885 angle_end += angle_step/2;
887 for ( na=0, angle = angle_start; angle <= angle_end; angle += angle_step ) na++;
894 cout <<
"DEBUG Bimage::find_helix_parameters: binned size = " << pb->
size() << endl;
903 Bstring title(
"Helical parameter search");
922 cout <<
"Rise\tAngle\tOffset\tCC" << endl;
923 for ( i=0, angle = angle_start; angle <= angle_end; angle += angle_step, i++ ) {
928 for ( j=0; j<max_iter && fabs(
shift[2]) > 0.001; j++ ) {
934 if ( fabs(
shift[2]) > 0.001 ) {
935 translate[2] += dd*
shift[2];
940 rise = pb->
sampling(0)[2]*translate[2];
941 offset = pb->
sampling(0)[2]*sqrt(translate[0]*translate[0] + translate[1]*translate[1]);
943 (*plot)[i+na] = angle*180.0/
M_PI;
944 (*plot)[i+2*na] = cc;
950 if ( mincc > cc ) mincc = cc;
952 cout << setprecision(6) << rise <<
tab << angle*180.0/
M_PI
953 <<
tab << offset <<
tab << cc << endl << flush;
958 if ( bestrise < 0 ) {
959 bestrise = -bestrise;
960 bestangle = -bestangle;
964 cout <<
"Best helical rise: " << bestrise <<
" A" << endl;
965 cout <<
"Best helical rotation angle: " << bestangle*180.0/
M_PI <<
" degrees" << endl;
966 cout <<
"Best correlation coefficient: " << bestcc << endl << endl;
971 txt =
Bstring(bestrise,
"Best helical rise: %g A");
973 txt =
Bstring(bestangle*180.0/
M_PI,
"Best helical rotation angle: %g degrees");
975 txt =
Bstring(bestcc,
"Best correlation coefficient: %g");
977 txt =
Bstring(mincc,
"Minimum correlation coefficient: %g");
999 double rise_step,
double angle_start,
double angle_end,
double angle_step,
1000 int bin,
double radius)
1002 rise_step = fabs(rise_step);
1003 if ( rise_step < 0.001 ) rise_step = 0.001;
1004 if ( rise_start > rise_end ) swap(rise_start, rise_end);
1006 angle_step = fabs(angle_step);
1007 if ( angle_step < 0.0001 ) angle_step = 0.0001;
1008 if ( angle_start > angle_end ) swap(angle_start, angle_end);
1010 if ( bin < 1 ) bin = 1;
1011 if ( bin > 4 ) bin = 4;
1013 if ( radius < 1 ) radius = x/2;
1020 double rise, angle, bestrise(0), bestangle(0);
1021 double cc, bestcc(0), mincc(1);
1026 cout <<
"Searching for helical parameters:" << endl;
1027 cout <<
"Rise range " << rise_start <<
" - "
1028 << rise_end <<
" A" << endl;
1029 cout <<
"Rise increment: " << rise_step <<
" A" << endl;
1030 cout <<
"Angular range " << angle_start*180.0/
M_PI <<
" - "
1031 << angle_end*180.0/
M_PI <<
" degrees" << endl;
1032 cout <<
"Angular increment: " << angle_step*180.0/
M_PI <<
" degrees" << endl;
1033 cout <<
"Binning: " << bin << endl;
1035 cout <<
"Radius: " << radius << endl << endl;
1039 rise_end += rise_step/2;
1040 angle_end += angle_step/2;
1042 for ( na=0, rise = rise_start; rise < rise_end; rise += rise_step )
1043 for ( angle = angle_start; angle <= angle_end; angle += angle_step ) na++;
1050 cout <<
"DEBUG Bimage::find_helix_parameters: binned size = " << pb->
size() << endl;
1058 Bstring title(
"Helical parameter search");
1077 cout <<
"Rise\tAngle\tCC" << endl;
1078 for ( i=0, rise = rise_start; rise < rise_end; rise += rise_step ) {
1079 for ( angle = angle_start; angle <= angle_end; angle += angle_step, i++ ) {
1081 translate[2] = rise/pb->
sampling(0)[2];
1091 (*plot)[i+na] = angle*180.0/
M_PI;
1092 (*plot)[i+2*na] = cc;
1093 if ( bestcc < cc ) {
1098 if ( mincc > cc ) mincc = cc;
1100 cout << setprecision(6) << rise <<
tab << angle*180.0/
M_PI
1101 <<
tab << cc << endl << flush;
1107 if ( bestrise < 0 ) {
1108 bestrise = -bestrise;
1109 bestangle = -bestangle;
1113 cout <<
"Best helical rise: " << bestrise <<
" A" << endl;
1114 cout <<
"Best helical rotation angle: " << bestangle*180.0/
M_PI <<
" degrees" << endl;
1115 cout <<
"Best correlation coefficient: " << bestcc << endl << endl;
1120 txt =
Bstring(bestrise,
"Best helical rise: %g A");
1122 txt =
Bstring(bestangle*180.0/
M_PI,
"Best helical rotation angle: %g degrees");
1124 txt =
Bstring(bestcc,
"Best correlation coefficient: %g");
1126 txt =
Bstring(mincc,
"Minimum correlation coefficient: %g");
1134 double angle_start,
double angle_end,
double angle_step,
1135 int bin,
double hires,
double lores,
double radius,
1139 long m = (long) ((angle_end - angle_start)/angle_step) + 1;
1145 for ( k = i*m, angle = angle_start; angle <= angle_end; angle += angle_step, k++ ) {
1176 double angle_start,
double angle_end,
double angle_step,
1177 int bin,
double hires,
double lores,
double radius)
1179 if ( hires > lores ) swap(hires, lores);
1181 if ( radius <= 0 || radius > x/2 ) radius = x/2;
1184 Vector3<long> mask_size((
long) (2*radius), (
long) (2*radius), z);
1204 long nt(ptiles->
images());
1205 long m = (long) ((angle_end - angle_start)/angle_step) + 1;
1212 cout <<
"Calculating cross-correlations between helical segments:" << endl;
1213 cout <<
"Thickness: " << tile_size[2] << endl;
1214 cout <<
"Angular range " << angle_start*180.0/
M_PI <<
" - "
1215 << angle_end*180.0/
M_PI <<
" degrees" << endl;
1216 cout <<
"Angular increment: " << angle_step*180.0/
M_PI <<
" degrees" << endl;
1217 cout <<
"Resolution limits: " << hires <<
" - " << lores <<
" A" << endl;
1218 cout <<
"Radius: " << radius << endl;
1219 cout <<
"Binning: " << bin << endl << endl;
1222 double* cc =
new double[m*nt];
1223 for ( i=0; i<m*nt; i++ ) cc[i] = 0;
1229 dispatch_apply(nt-1, dispatch_get_global_queue(0, 0), ^(
size_t i){
1231 angle_start, angle_end, angle_step,
1232 bin, hires, lores, radius,
1236 #pragma omp parallel for
1237 for (
long i=0; i<nt; ++i )
1239 angle_start, angle_end, angle_step,
1240 bin, hires, lores, radius,
1244 Bstring title(
"Helix segment correlation");
1254 for ( i=1; i<ncol; i++ ) {
1269 cout << endl <<
"Angle";
1270 for ( i=0; i<nt-1; i++ ) cout <<
"\tCC(" << i+1 <<
")";
1272 for ( k=0, angle = angle_start; angle <= angle_end; angle += angle_step, k++ ) {
1273 cout << setprecision(4) << angle*180.0/
M_PI;
1274 for ( i=0; i<nt-1; i++ ) cout <<
tab << cc[i*m + k];
1279 for ( k=0, angle = angle_start; angle <= angle_end; angle += angle_step, k++ ) {
1280 (*plot)[k] = angle*180.0/
M_PI;
1281 for ( i=0; i<nt-1; i++ ) (*
plot)[(i+1)*m+k] = cc[i*m + k];
1303 cerr <<
"Error: Line transforms can only be calculated from 2D images!" << endl;
1313 cout <<
"Transforming lines of size: " << x << endl;
1315 long i, xx, yy, nn, hx(x/2);
1316 double dx,
shift, phi, sx(x);
1319 for ( i=nn=0; nn<n; nn++ ) {
1322 cout <<
"Shift: " <<
shift << endl;
1323 for ( yy=0; yy<y; yy++ ) {
1326 for ( xx=0; xx<x; xx++, i++ ) {
1327 dx = (xx < hx)? xx: xx - sx;
1337 cout <<
"Finished transforming" << endl << endl;
1357 double scale,
double hires)
1360 cerr <<
"Error: Cross sections can only be calculated from 2D images!" << endl;
1366 cout <<
"Rotating image" << endl;
1376 long i, j, xx, yy, nn;
1377 long ix, iy, pad_factor(2);
1378 double a, cosang, sinang, dx;
1381 double apz = helix_angle/pix_rise;
1387 cout <<
"2D reconstruction:" << endl;
1388 cout <<
"Size: " << recsize << endl;
1389 cout <<
"Helical rise and angle: " << helix_rise <<
" " << helix_angle*180/
M_PI << endl;
1390 cout <<
"Rotation per pixel along axis: " << apz*180/
M_PI << endl;
1391 cout <<
"Resolution limit: " << hires <<
" Ã…" << endl;
1392 cout <<
"Fourier transform size: " << ft_size << endl;
1405 double rscale = pcs->x/(scale*sx);
1407 if ( mx > sx ) mx = sx;
1410 cout <<
"DEBUG Bimage::helical_cross_section: sampling=" <<
image->
sampling()[0] <<
" mx=" << mx << endl;
1412 for ( i=nn=0; nn<pp->n; nn++ ) {
1413 for ( yy=0; yy<pp->y; yy++ ) {
1419 for ( xx=0; xx<pp->x; xx++, i++ ) {
1420 dx = ( xx < hx )? xx: xx - sx;
1421 if ( fabs(dx) <= mx ) {
1423 ix = (long) floor(dx*cosang + 0.5);
1424 iy = (long) floor(dx*sinang + 0.5);
1425 if ( ix < 0 ) ix += pcs->x;
1426 if ( iy < 0 ) iy += pcs->y;
1427 if ( ix >= 0 && iy >= 0 && ix < pcs->x && iy < pcs->y ) {
1428 j = (nn*pcs->y + iy)*pcs->x + ix;
1441 cout <<
"Weighing reconstruction" << endl;
1442 for ( i=0; i<pcs->
size().
volume() * pcs->n; i++ )
1443 if ( w[i] > 0 ) pcs->
set(i, pcs->
complex(i) / w[i]);
1450 cout <<
"Backtransforming reconstruction" << endl << endl;
1469 if ( snradius < 1 || snradius > x/2 ) snradius = x/4;
1471 long nn, i, xx, yy, fn, bn;
1472 double x2, y2, r2(snradius*snradius), v, fa, fv, ba, bv, snr(0);
1475 cout <<
"Image\tSNR" << endl;
1476 for ( i=nn=0; nn<n; nn++ ) {
1478 fa = fv = ba = bv = 0;
1479 for ( yy=0; yy<y; yy++ ) {
1482 for ( xx=0; xx<x; xx++, i++ ) {
1486 if ( x2 + y2 <= r2 ) {
1501 if ( fv < 0 ) fv = 0;
1502 if ( bv < 0 ) bv = 0;
1507 cerr <<
"Error: The background variance is zero or less! (" << bv <<
")" << endl;
1510 cout << nn+1 <<
tab << snr << endl;
1532 double helix_angle,
int fill_type,
double fill)
1539 double a, ca, sa, dx, dy, cx, cy;
1542 cout <<
"Extruding the image:" << endl;
1543 cout <<
"Helical rise and rotation: " << helix_rise <<
" A " << helix_angle*180.0/
M_PI <<
"°" << endl;
1544 cout <<
"Length: " <<
length << endl;
1548 float* nudata =
new float[nusize];
1549 for ( i=0; i<nusize; i++ ) nudata[i] = 0;
1551 for ( i=zz=0; zz<
length; zz++ ) {
1556 for ( yy=0; yy<y; yy++ ) {
1558 for ( xx=0; xx<x; xx++, i++ ) {
1585 if ( lim_lo > lim_hi ) swap(lim_lo, lim_hi);
1586 if ( lim_lo < 1 ) lim_lo = 1;
1587 if ( lim_hi < 1 || lim_hi > x ) lim_hi = x;
1589 long i, xx, yy, zz, nn, left, right;
1590 long n1, n2, hw(width/2);
1591 double ox(
image->
origin()[0]), a, b, slope_max, slope_min;
1592 if ( ox < hw || ox > x - hw ) ox = x/2;
1596 double* vx =
new double[x];
1597 double* vy =
new double[x];
1599 long leftmin = (long) (ox - lim_hi/2);
1600 long leftmax = (long) (ox - lim_lo/2);
1601 long rightmin = (long) (ox + lim_lo/2);
1602 long rightmax = (long) (ox + lim_hi/2);
1603 if ( leftmin < 0 ) leftmin = 0;
1604 if ( leftmax <= leftmin ) leftmax = leftmin + 1;
1605 if ( rightmax >= x ) rightmax = x - 1;
1606 if ( rightmin >= rightmax ) rightmin = rightmax - 1;
1608 for ( xx=0; xx<x; xx++ ) vx[xx] = xx;
1611 cout <<
"Calculating filament width:" << endl;
1612 cout <<
"Origin: " << ox << endl;
1613 cout <<
"Moving line window width: " << width << endl;
1614 cout <<
"Allowed filament width range: " << lim_lo <<
" - " << lim_hi << endl;
1616 lim_lo*u[1] <<
" - " << lim_hi*u[1] <<
" A" << endl << endl;
1619 Bstring title(
"Filament width");
1636 cout <<
"y\ty(A)\tleft\tright\twidth\twidth(A)" << endl;
1637 for ( i=nn=0; nn<n; nn++ ) {
1638 for ( zz=0; zz<z; zz++ ) {
1639 for ( yy=0; yy<y; yy++ ) {
1641 for ( xx=0; xx<x; xx++, i++ ) vy[xx] = (*
this)[i];
1642 slope_max = slope_min = 0;
1643 for ( xx=0; xx<x; xx++ ) {
1645 if ( n1 < 0 ) n1 = 0;
1647 if ( n2 >= x ) n2 = x - 1;
1650 if ( xx >= leftmin && xx <= leftmax && slope_max < b ) {
1654 if ( xx >= rightmin && xx <= rightmax && slope_min > b ) {
1659 (*plot)[yy] = yy*u[1];
1660 (*plot)[yy+y] = (right - left)*u[0];
1663 cout << yy <<
tab << yy*u[1] <<
tab << left <<
tab
1664 << right <<
tab << right - left <<
tab
1665 << (right - left)*u[0] << endl;
1696 if ( width < 1 || width >= x ) width = x/2;
1699 cout <<
"Calculating filament density per pixel length:" << endl;
1700 cout <<
"Filament width: " << width <<
1702 cout <<
"Image width: " << x << endl << endl;
1705 long i, xx, yy, zz, nn;
1706 double t, tl, tr, hw((x-width)/2), hwm(x-hw);
1711 for ( nn=0; nn<n; nn++ ) {
1712 for ( zz=0; zz<z; zz++ ) {
1713 for ( yy=0; yy<y; yy++ ) {
1715 i =
index(0, 0, yy, zz, nn);
1716 for ( xx=0; xx<hw; xx++, i++ )
1718 for ( ; xx<hwm; xx++, i++ )
1720 for ( ; xx<x; xx++, i++ )
1725 if ( tl < tr ) t -= tl;