28 double rad_scale(
real_size().max()/sampling_ratio);
30 long maxrad(
size().max());
32 if ( resolution > 0.1 )
33 maxrad = (long) (rad_scale/resolution);
35 maxrad = (long) (maxrad/2.0);
48 long nn, xx, yy, zz, i, nb;
50 Vector3<long> bmin(0.4*x, 0.4*y, 0.4*z), bmax(0.6*x, 0.6*y, 0.6*z);
54 cout <<
"Calculating the Fourier transform background" << endl;
56 for ( nn=0; nn<n; ++nn ) {
59 for ( zz=bmin[2]; zz<bmax[2]; ++zz ) {
60 for ( yy=bmin[1]; yy<bmax[1]; ++yy ) {
61 for ( xx=bmin[0]; xx<bmax[0]; ++xx ) {
62 i =
index(xx, yy, zz, nn);
71 cout << nn <<
tab << scientific << bkg << endl;
89 if ( compoundtype !=
TComplex )
return value;
91 long xx, yy, zz, kx, ky, kz, mx, my, mz, jx, jy, jz;
93 long ix = (long) floor(m[0]);
94 long iy = (long) floor(m[1]);
95 long iz = (long) floor(m[2]);
96 long ikx(
kernel->half_width());
97 long iky(
kernel->half_width());
98 long ikz(
kernel->half_width());
102 ikx = ((long) ((m[0] - ix)*
kernel->divisions() + 0.5))*
kernel->width();
103 ix -=
kernel->half_width();
107 iky = ((long) ((m[1] - iy)*
kernel->divisions() + 0.5))*
kernel->width();
108 iy -=
kernel->half_width();
112 ikz = ((long) ((m[2] - iz)*
kernel->divisions() + 0.5))*
kernel->width();
113 iz -=
kernel->half_width();
116 for ( zz=0, kz=ikz, mz=iz; zz<nz; zz++, kz++, mz++ ) {
118 while ( jz < 0 ) jz += z;
119 while ( jz >= z ) jz -= z;
120 jz = (img_num*z + jz)*y;
121 for ( yy=0, ky=iky, my=iy; yy<ny; yy++, ky++, my++ ) {
123 while ( jy < 0 ) jy += y;
124 while ( jy >= y ) jy -= y;
126 wyz = (*kernel)[ky]*(*kernel)[kz];
127 for ( xx=0, kx=ikx, mx=ix; xx<nx; xx++, kx++, mx++ ) {
129 while ( jx < 0 ) jx += x;
130 while ( jx >= x ) jx -= x;
131 value +=
complex(jy + jx) * ((*kernel)[kx]*wyz);
137 cerr <<
"Warning: Interpolated complex value not finite! (" << value <<
")" << endl;
150 cout <<
"Translating in frequency space:" << endl;
151 cout <<
"Shift: " <<
shift << endl;
159 for (
long nn=0; nn<n; nn++ )
178 cout <<
"Translating in frequency space:" << endl;
179 cout <<
"Shift: " <<
shift << endl;
205 if ( x > 1 ) nusize[0] = (long) (x*scale);
206 if ( y > 1 ) nusize[1] = (long) (y*scale);
207 if ( z > 1 ) nusize[2] = (long) (z*scale);
211 if ( x > 1 ) olsize[0] = (long) (nusize[0]/scale);
212 if ( y > 1 ) olsize[1] = (long) (nusize[1]/scale);
213 if ( z > 1 ) olsize[2] = (long) (nusize[2]/scale);
216 if ( x > 1 ) error[0] = olsize[0]*scale - nusize[0];
217 if ( y > 1 ) error[1] = olsize[1]*scale - nusize[1];
218 if ( z > 1 ) error[2] = olsize[2]*scale - nusize[2];
222 cout <<
"Rescaling in frequency space:" << endl;
223 cout <<
"Scale: " << scale << endl;
224 cout <<
"New size: " << nusize <<
" voxels" << endl;
225 cout <<
"Error: " << error <<
" voxels" << endl << endl;
258 long nx(x * r + 0.5);
271 cout <<
"Intermediate size: " << nusize << endl;
272 cout <<
"Intermediate scale: " << scale << endl;
273 cout <<
"Intermediate translation: " << translate << endl << endl;
277 cout <<
"Comparing map " <<
file_name() << endl;
278 cout <<
"Map size: " <<
size() << endl;
280 cout <<
"Map sampling: " <<
sampling(0) << endl;
281 cout <<
"Map real size: " <<
real_size() << endl << endl;
282 cout <<
"Reference: " << pref->
file_name() << endl;
283 cout <<
"Reference size: " << pref->
size() << endl;
284 cout <<
"Reference origin: " << pref->
image->
origin() << endl;
285 cout <<
"Reference sampling: " << pref->
sampling(0) << endl;
286 cout <<
"Reference real size: " << pref->
real_size() << endl << endl;
294 cout <<
"Translate: " << translate << endl;
295 cout <<
"New map size: " << pt->
size() << endl;
296 cout <<
"New map origin: " << pt->
image->
origin() << endl;
297 cout <<
"New map sampling: " << pt->
sampling(0) << endl;
298 cout <<
"New map real size: " << pt->
real_size() << endl << endl;
326 cerr <<
"Error: No image data to process!" << endl << endl;
336 cout <<
"Setting all amplitudes to one" << endl << endl;
342 for ( i=0; i<ds; i++ ) {
344 if ( ( amp = cv.
amp() ) )
371 cerr <<
"Error: No image data to process!" << endl << endl;
375 if ( threshold <= 0 )
return 0;
383 cout <<
"Applying an amplitude filter with a threshold of " << threshold << endl;
387 double maxamp(0), zeroamp(1e-5*threshold);
388 double amp, ampkept(0), ampzeroed(0);
391 for ( i=0; i<ds; i++ ) {
393 if ( maxamp < amp ) maxamp = amp;
394 if ( amp < threshold ) {
396 if ( amp > zeroamp ) nz++;
405 cout <<
"Number of amplitudes kept: " << nk <<
" (" << nk*100.0/ds <<
" %)" << endl;
406 cout <<
"Number of amplitudes zeroed: " << nz <<
" (" << nz*100.0/ds <<
" %)" << endl;
407 cout <<
"Maximum amplitude: " << maxamp << endl;
408 cout <<
"Amplitude kept sum: " << ampkept << endl;
409 cout <<
"Amplitude zeroed sum: " << ampzeroed << endl << endl;
427 cerr <<
"Error: File " <<
file_name() <<
" must be a real space map!" << endl;
434 cout <<
"Changing the amplitudes to their square roots" << endl << endl;
440 for ( i=0; i<ds; i++ ) {
458 cerr <<
"Error: File " <<
file_name() <<
" must be a real space map!" << endl;
465 cout <<
"Changing the amplitudes to their squares" << endl << endl;
471 for ( i=0; i<ds; i++ ) {
528 cerr <<
"Error: No image data to process!" << endl << endl;
532 if ( width < 1e-6 ) width = 1e-6;
539 if ( res_lo > 0 && res_hi > res_lo ) swap(res_hi, res_lo);
540 if ( res_hi == res_lo ) res_lo = 0;
543 cout <<
"Applying a bandpass filter:" << endl;
544 cout <<
"High and low resolution limits: " << res_hi <<
" - ";
545 if ( res_lo > 0 ) cout << res_lo <<
" A" << endl;
546 else cout <<
"inf A" << endl;
547 cout <<
"Gaussian edge: " << width << endl << endl;
550 long i, nn, xx, yy, zz;
551 double edge_lo, edge_hi, f, test_width(10*width), a(
GOLDEN/fabs(width));
552 double s, sx2, sy2, sz2;
553 double shi = 1/res_hi;
554 double slo = (res_lo > 0)? 1/res_lo : 0;
558 for ( i=nn=0; nn<n; nn++ ) {
559 for ( zz=0; zz<z; zz++ ) {
561 if ( zz > h[2] ) sz2 -= z;
564 for ( yy=0; yy<y; yy++ ) {
566 if ( yy > h[1] ) sy2 -= y;
569 for ( xx=0; xx<x; xx++, i++ ) {
571 if ( xx > h[0] ) sx2 -= x;
574 s = sqrt(sx2 + sy2 + sz2);
575 if ( slo - s > test_width ) edge_lo = 1e300;
576 else edge_lo = exp(a*(slo - s));
577 if ( s - shi > test_width ) edge_hi = 1e300;
578 else edge_hi = exp(a*(s - shi));
579 f = (edge_hi > edge_lo)? 1/(1 + edge_hi): 1/(1 + edge_lo);
613 cerr <<
"Error: File " <<
file_name() <<
" must be a frequency space map!" << endl;
619 long i, j, nn, xx, yy, zz, iradius;
620 double radius, f, f1, rx, ry, rz, v;
621 double rad_scale(
real_size().max()/sampling_ratio);
628 prad->
sampling(1.0/rad_scale, 1, 1);
630 vector<float> radstd(n*maxrad);
631 vector<float> num(maxrad);
634 cout <<
"Calculating a radial power spectrum:" << endl;
635 cout <<
"Radial scale: " << rad_scale <<
" A" << endl;
636 cout <<
"Radial step size: " << 1.0/rad_scale <<
" 1/A" << endl;
637 cout <<
"Resolution limit: " << resolution <<
" A" << endl;
638 cout <<
"Number of values: " << maxrad << endl << endl;
641 for ( nn=0; nn<n; nn++ ) {
642 for ( i=0; i<maxrad; i++ ) num[i] = 0;
643 for ( zz=0; zz<z; zz++ ) {
645 if ( zz > h[2] ) rz -= z;
648 for ( yy=0; yy<y; yy++ ) {
650 if ( yy > h[1] ) ry -= y;
653 for ( xx=0; xx<x; xx++ ) {
655 if ( xx > h[0] ) rx -= x;
658 radius = rad_scale*sqrt(rx + ry + rz);
659 iradius = (long) radius;
660 if ( iradius < maxrad ) {
661 f = radius - iradius;
663 i =
index(xx, yy, zz, nn);
665 j = nn*maxrad + iradius;
670 if ( iradius < maxrad ) {
680 for ( i=0; i<maxrad; i++ ) {
683 prad->
set(j, (*prad)[j]/num[i]);
684 radstd[j] = radstd[j]/num[i] - (*prad)[j]*(*prad)[j];
686 radstd[j] = sqrt(radstd[j]);
695 cout <<
"DEBUG Bimage::fspace_radial_power: Calculating statistics" << endl;
700 cout << endl <<
"Radial power spectrum:" << endl;
702 for ( nn=0; nn<prad->
images(); nn++ ) cout <<
" " << nn+1 <<
" (std)";
704 for ( xx=0; xx<prad->
sizeX(); xx++ ) {
706 for ( nn=0, i=xx; nn<prad->
images(); nn++, i+=prad->
sizeX() )
707 cout <<
" " << (*prad)[i] <<
" " << radstd[i];
732 cerr <<
"Error: File " <<
file_name() <<
" must be a frequency space map!" << endl;
736 bool amp(flag & 1), norm(1 - (flag & 2));
737 long i, xx, yy, zz, iradius, iradius2;
738 double radius, fraction, fraction2, v;
744 double* num =
new double[maxrad];
745 double* rps =
new double[maxrad];
747 for ( i=0; i<maxrad; i++ ) num[i] = rps[i] = 0;
749 for ( zz=0; zz<z; zz++ ) {
751 if ( zz > h[2] ) rz -= z;
754 for ( yy=0; yy<y; yy++ ) {
756 if ( yy > h[1] ) ry -= y;
759 for ( xx=0; xx<x/2; xx++ ) {
761 if ( xx > h[0] ) rx -= x;
764 i =
index(xx, yy, zz, nn);
765 radius = rad_scale*sqrt(rx + ry + rz);
766 iradius = (long) radius;
767 iradius2 = iradius + 1;
768 if ( iradius2 < maxrad ) {
769 fraction = radius - iradius;
770 fraction2 = 1.0 - fraction;
775 num[iradius] += fraction2;
776 num[iradius2] += fraction;
777 rps[iradius] += fraction2*v;
778 rps[iradius2] += fraction*v;
786 for ( i=0; i<maxrad; i++ )
787 if ( num[i] ) rps[i] /= num[i];
805 for ( nn=0; nn<n; nn++ ) {
807 for ( i=0; i<maxrad; i++ )
808 if ( rps[i] ) rps[i] = curve[i]/rps[i];
820 long maxrad(curve.size());
829 for ( nn=0; nn<n; nn++ ) {
831 for ( i=0; i<maxrad; i++ )
832 if ( rps[i] ) rps[i] = curve[i]/rps[i];
851 for ( nn=0; nn<n; nn++ )
863 long i, j, xx, yy, zz, iradius, iradius2;
866 double radius, fraction, fraction2, w;
872 for ( j=zz=0; zz<z; zz++ ) {
874 if ( zz > h[2] ) rz -= z;
877 for ( yy=0; yy<y; yy++ ) {
879 if ( yy > h[1] ) ry -= y;
882 for ( xx=0; xx<x; xx++, j++ ) {
884 if ( xx > h[0] ) rx -= x;
887 i =
index(xx, yy, zz, nn);
888 radius = rad_scale*sqrt(rx + ry + rz);
889 iradius = (long) radius;
890 iradius2 = iradius + 1;
892 if ( pmask && (*pmask)[j] < 1 ) use_this = 0;
893 if ( iradius2 >= maxrad ) use_this = 0;
895 fraction = radius - iradius;
896 fraction2 = 1.0 - fraction;
897 w = scale[iradius]*fraction2 + scale[iradius2]*fraction;
918 for ( nn=0; nn<n; nn++ )
929 long maxrad(scale.size());
931 long i, j, xx, yy, zz, iradius, iradius2;
934 double radius, fraction, fraction2, w;
940 for ( j=zz=0; zz<z; zz++ ) {
942 if ( zz > h[2] ) rz -= z;
945 for ( yy=0; yy<y; yy++ ) {
947 if ( yy > h[1] ) ry -= y;
950 for ( xx=0; xx<x; xx++, j++ ) {
952 if ( xx > h[0] ) rx -= x;
955 i =
index(xx, yy, zz, nn);
956 radius = rad_scale*sqrt(rx + ry + rz);
957 iradius = (long) radius;
958 iradius2 = iradius + 1;
960 if ( pmask && (*pmask)[j] < 1 ) use_this = 0;
961 if ( iradius2 >= maxrad ) use_this = 0;
963 fraction = radius - iradius;
964 fraction2 = 1.0 - fraction;
965 w = scale[iradius]*fraction2 + scale[iradius2]*fraction;
997 cerr <<
"Error: Cannot estimate the B-factor - the data block is empty!" << endl << endl;
1004 cout <<
"B-factor estimation:" << endl;
1005 cout <<
"High resolution limit: " << res_hi << endl;
1014 double frac_res2(1.0/(realsize));
1015 frac_res2 *= frac_res2;
1017 long minrad((
long) (realsize/res_lo));
1018 long maxrad((
long) (realsize/res_hi));
1019 double scat, logScale, Bfactor(-1);
1022 cout <<
"DEBUG Bimage::fspace_fit_B_factor: minrad=" << minrad <<
" maxrad=" << maxrad << endl;
1024 double* s2 =
new double[maxrad];
1025 double* logF =
new double[maxrad];
1027 for ( i=0; i<maxrad; i++ ) {
1028 s2[i] = i*i*frac_res2;
1029 scat = 1.494*exp(-23.22*s2[i]) + 0.937*exp(-3.79*s2[i]);
1030 logF[i] = 4*(log(scat) - log((*prps)[i]));
1032 cout << i <<
tab << sqrt(s2[i]) <<
tab << 1/sqrt(s2[i]) <<
tab << (*prps)[i] <<
tab << scat << endl;
1038 cout <<
"B-factor: " << Bfactor << endl;
1039 cout <<
"Correlation index: " << CI << endl << endl;
1041 cout <<
"B-factor: " << Bfactor << endl << endl;
1068 long i, xx, yy, zz, nzero(0), nuse(0);
1072 double s2max(1.0/(resolution*resolution)), weight(0), s2;
1076 cout <<
"Filtering with a ramp to a resolution of " << resolution <<
" A" << endl;
1078 for ( i=zz=0; zz<z; zz++ ) {
1079 k[2] = (zz>h[2])? z - zz: zz;
1080 s[2] = k[2]/realsize[2];
1081 for ( yy=0; yy<y; yy++ ) {
1082 k[1] = (yy>h[1])? y - yy: yy;
1083 s[1] = k[1]/realsize[1];
1084 for ( xx=0; xx<x; xx++, i++ ) {
1085 k[0] = (xx>h[1])? x - xx: xx;
1086 s[0] = k[0]/realsize[0];
1101 cout <<
"Weighed fractions: zeroed=" << nzero*1.0/i <<
" used=" << nuse*1.0/i << endl << endl;
1130 long i, xx, yy, zz, nzero(0), nuse(0);
1134 double s2max(1.0/(resolution*resolution)), weight(0), s2;
1138 cout <<
"Filtering with a ramp to a resolution of " << resolution <<
" A" << endl;
1140 for ( i=zz=0; zz<z; zz++ ) {
1141 k[2] = (zz>h[2])? z - zz: zz;
1142 for ( yy=0; yy<y; yy++ ) {
1143 k[1] = (yy>h[1])? y - yy: yy;
1144 s[1] = k[1]/realsize[1];
1145 for ( xx=0; xx<x; xx++, i++ ) {
1146 k[0] = (xx>h[1])? x - xx: xx;
1147 s[0] = k[0]/realsize[0];
1153 weight = sqrt(s2)*sin(axis-atan2(s[1],s[0]));
1162 cout <<
"Weighed fractions: zeroed=" << nzero*1.0/i <<
" used=" << nuse*1.0/i << endl << endl;
1193 long maxrad = (long) (2 + rad_scale/resolution);
1196 cout <<
"Weighing amplitudes with a B factor:" << endl;
1197 cout <<
"B factor: " << B << endl;
1198 cout <<
"Resolution: " << resolution <<
" A (" << maxrad <<
" pixels)" << endl << endl;
1202 vector<double> gcurve(maxrad);
1203 double s2, fac(-B/4);
1205 for ( i=0; i<maxrad; i++ ) {
1208 gcurve[i] = exp(fac*s2);
1236 long maxrad = (long) (2 + rad_scale/resolution);
1239 cout <<
"Weighing amplitudes with a C cross-section:" << endl;
1240 cout <<
"Resolution: " << resolution <<
" A (" << maxrad <<
" pixels)" << endl << endl;
1243 vector<double> ccurve =
C_curve(maxrad, 1/rad_scale);
1271 long maxrad = (long) (2 + rad_scale/resolution);
1274 cout <<
"Weighing amplitudes with a Laplacian-of-Gaussian function:" << endl;
1275 cout <<
"Sigma: " << sigma << endl;
1276 cout <<
"Resolution: " << resolution <<
" A (" << maxrad <<
" pixels)" << endl << endl;
1281 double* curve =
new double[maxrad];
1283 for ( i=0; i<maxrad; i++ ) {
1286 curve[i] = c1*s2*exp(c2*s2);
1315 double scale = 1/((*plot)[1] * rad_scale);
1319 long maxrad = (long) (2 + rad_scale/resolution);
1322 cout <<
"Weighing amplitudes with an RPS curve:" << endl;
1323 cout <<
"Resolution: " << resolution <<
" A (" << maxrad <<
" pixels)" << endl << endl;
1327 cout <<
"rad_scale=" << rad_scale << endl;
1328 cout <<
"(*plot)[1]=" << (*plot)[1] << endl;
1329 cout <<
"scale=" << scale << endl;
1334 vector<double> rps(maxrad);
1336 for ( i=
plot->
rows(); i<2*plot->rows(); ++i ) (*
plot)[i] = sqrt((*
plot)[i]);
1338 for ( i=0; i<maxrad; ++i ) {
1343 rps[i] = (1-s)*(*
plot)[j] + s*(*plot)[j+1];
1375 long maxrad = (long) (2 + rad_scale/resolution);
1379 cout <<
"Weighing amplitudes with an FSC curve:" << endl;
1380 cout <<
"Resolution: " << resolution <<
" A (" << maxrad <<
" pixels)" << endl << endl;
1384 double*
fsc =
new double[maxrad];
1386 for ( i=0, j=
plot->
rows(); i<maxrad; i++, j++ )
1399 double s, ds(1/real_size);
1401 double a(0.1), b(-2), c(3);
1402 double deb(6), des(150), ec(30);
1406 cout <<
"Critical exposure: "
1407 << deb <<
" + " << des <<
"exp(-" << ec <<
"s)"
1408 <<
" e/A2" << endl << endl;
1410 cout <<
"Critical exposure: "
1411 << a <<
"s^" << b <<
" + " << c
1412 <<
" e/A2" << endl << endl;
1415 vector<double> critexp(size, 0);
1417 for ( i=0, s=0; i<size; ++i, s+=ds ) {
1419 critexp[i] = 2*(deb + des*exp(-ec*s));
1421 critexp[i] = 2*(a*pow(s, b) + c);
1422 if ( !
isfinite(critexp[i]) ) critexp[i] = 1e10;
1430 vector<double> rdcurve(size, 0);
1432 if ( dose.size() < 1 )
return rdcurve;
1434 if ( dose.size() < 2 ) {
1436 dose.push_back(150);
1438 }
else if ( dose.size() < 3 ) dose.push_back(0.1);
1440 double s, is2, v, de(3), D(real_size);
1443 for (
long i=0; i<rdcurve.size(); ++i ) {
1445 if ( dose.size() == 3 ) {
1449 de = 2*(dose[1] + dose[2]*is2);
1450 }
else if ( dose.size() == 4 ) {
1451 de = 2*(dose[1] + dose[2]*exp(-dose[3]*s));
1453 v = de*(1 - exp(-dose[0]/de));
1454 rdcurve[i] = v*v/dose[0];
1462 long maxrad(critdose.size());
1467 if ( dose_per_frame > 1e-3 )
1468 for ( i=0; i<=nn; ++i ) dose += dose_per_frame;
1472 if ( dose < 1e-3 ) {
1473 cerr <<
"Error: The dose is too low! (" << dose <<
")" << endl;
1477 vector<double> scale(maxrad);
1479 for ( i=0; i<maxrad; ++i )
1480 scale[i] = exp(-dose/critdose[i]);
1508 cout <<
"Weighing amplitudes with the accumulated dose:" << endl;
1509 cout <<
"Dose per frame: " << dose_per_frame <<
" e/Ã…2" << endl;
1534 dispatch_apply(n, dispatch_get_global_queue(0, 0), ^(
size_t nn){
1538 #pragma omp parallel for
1539 for (
long nn=0; nn<n; ++nn )
1563 if ( dose.size() < 1 )
return 0;
1597 long maxrad = (long) (2 + rad_scale/resolution);
1600 cout <<
"Weighing amplitudes:" << endl;
1601 cout <<
"Reference map: " << pref->
file_name() << endl;
1602 cout <<
"Resolution: " << resolution <<
" A (" << maxrad <<
" pixels)" << endl << endl;
1616 for ( nn=0; nn<n; nn++ ) {
1618 for ( i=0; i<maxrad; i++ )
1619 if ( rps[i] ) rps[i] = ref[i]/rps[i];
1637 cerr <<
"Error: File " <<
file_name() <<
" must be a Fourier transform!" << endl;
1643 long nn, i, j, ds(x*y*z);
1646 for ( nn=i=0; nn<n; ++nn ) {
1648 for ( j=0; j<ds; i++, j++ )
set(i,
complex(i)*scale);
1665 cerr <<
"Error: File " <<
file_name() <<
" must be a real space map!" << endl;
1679 long maxrad = (long) (2 + rad_scale/resolution);
1686 for ( nn=0; nn<n; nn++ ) {
1688 for ( i=0; i<maxrad; i++ )
1689 if ( rps[i] ) rps[i] = 1/sqrt(rps[i]);
1706 long i(0), ds(x*y*z);
1707 double fmax(0), scale;
1709 fmax = ds * (avg-min);
1716 if ( (*
this)[i] >
SMALLFLOAT ) fmax = (*this)[i];
1718 cout <<
"Converting to a positive definite image:" << endl;
1719 cout <<
"F0: " << fmax << endl << endl;
1727 for ( i=0; i<ds; i++ )
set(i,
complex(i) * scale);
1748 long i, j, nn, xx, yy, zz, xf, yf, zf;
1749 double d, w, s(0), R(0), Ri(0), Rr(0), Ra(0), Rp(0);
1752 for ( nn=0; nn<n; nn++ ) {
1753 for ( zz=0; zz<z; zz++ ) {
1754 zf = (zz)? z - zz: 0;
1755 for ( yy=0; yy<y; yy++ ) {
1756 yf = (yy)? y - yy: 0;
1757 for ( xx=0; xx<(x+1)/2; xx++ ) {
1758 xf = (xx)? x - xx: 0;
1759 i =
index(xx, yy, zz, nn);
1760 j =
index(xf, yf, zf, nn);
1782 R = sqrt(Rr*Rr + Ri*Ri);
1785 cout <<
"Friedel symmetry residuals:" << endl;
1786 cout <<
"Real: " << Rr << endl;
1787 cout <<
"Imaginary: " << Ri << endl;
1788 cout <<
"Amplitude: " << Ra << endl;
1789 cout <<
"Phase: " << Rp*180.0/
M_PI <<
" degrees" << endl;
1790 cout <<
"Overall: " << R << endl << endl;
1808 long i, j, nn, xx, yy, zz, xf, yf, zf, nR;
1809 double amp, amps, phi, phis, damp, dphi;
1810 double ampavg, phiavg, fomavg;
1818 cout <<
"Applying Friedel symmetry:" << endl;
1819 cout <<
"Image\tRefl\tR(amp)\tR(phi)" << endl;
1821 cout <<
"Applying Friedel symmetry" << endl << endl;
1823 for ( nn=0; nn<n; nn++ ) {
1826 for ( zz=0; zz<z; zz++ ) {
1827 zf = (zz)? z - zz: 0;
1828 for ( yy=0; yy<y; yy++ ) {
1829 yf = (yy)? y - yy: 0;
1830 for ( xx=0; xx<(x+1)/2; xx++ ) {
1831 xf = (xx)? x - xx: 0;
1832 i =
index(xx, yy, zz, nn);
1833 j =
index(xf, yf, zf, nn);
1844 if ( fabs(dphi) > tol )
1845 cout <<
"amp dphi: " << xx <<
" " << yy <<
" "
1846 << zz <<
" " << j <<
" " << damp <<
" " << dphi << endl;
1847 ampavg = (amp + amps)/2;
1848 phiavg = phi - dphi/2;
1853 fomavg = (fom[i] + fom[j])/2;
1864 Ramp = sqrt(Ramp/nR);
1865 Rphi = sqrt(Rphi/nR);
1868 cout << nn+1 <<
tab << nR <<
tab << Ramp <<
tab << Rphi*180/
M_PI << endl;
1890 if ( res_hi <= 0 ) res_hi = 0.1;
1891 if ( res_lo <= 0 ) res_lo = 1e10;
1892 if ( res_lo < res_hi + 1 ) res_lo = res_hi + 1;
1900 if ( !(type&1) ) cout <<
"Phase angle";
1901 else if ( type&1 ) cout <<
"Cosine phase angle";
1902 cout <<
" difference" << endl;
1903 if ( type & 2 ) cout <<
"With amplitude scaling" << endl;
1904 cout <<
"Resolution range: "
1905 << res_hi <<
" - " << res_lo << endl << endl;
1908 long i, j, xx, yy, zz, nn;
1911 double smax2 = 1.0/(res_hi*res_hi);
1912 double smin2 = 1.0/(res_lo*res_lo);
1913 double dy, dz, sx2, sy2, sz2, s2, w;
1917 float* dphi =
new float[datasize];
1920 cout <<
"Image\tShift" << endl;
1921 for ( nn=0; nn<ppd->
images(); nn++ ) {
1925 cout << nn+1 <<
tab <<
shift << endl;
1926 for ( zz=0; zz<ppd->z; zz++ ) {
1928 if ( iz < 0 ) iz += ppd->z;
1930 if ( zz > (ppd->z - 1)/2 ) dz -= ppd->z;
1933 for ( yy=0; yy<ppd->y; yy++ ) {
1935 if ( iy < 0 ) iy += ppd->y;
1937 if ( yy > (ppd->y - 1)/2 ) dy -= ppd->y;
1940 for ( xx=0; xx<ppd->x/2+1; xx++ ) {
1942 if ( ix < 0 ) ix += ppd->x;
1945 s2 = sx2 + sy2 + sz2;
1946 if ( s2 >= smin2 && s2 <= smax2 ) {
1947 i = ppd->
index(xx,yy,zz,nn);
1948 j = ppd->
index(ix,iy,iz,nn);
1953 if ( type & 1 ) dphi[i] = cos(dphi[i]);
1988 if ( res_hi <= 0 ) res_hi = 0.1;
1989 if ( res_lo < res_hi + 1 ) res_lo = res_hi + 1;
1995 long i, j, xx, yy, zz, nn;
1998 double smax2 = 1.0/(res_hi*res_hi);
1999 double smin2 = 1.0/(res_lo*res_lo);
2000 double dy, dz, sx2, sy2, sz2, s2;
2004 double amp, dphi, sum_amp(0), avg_pd(0);
2006 for ( nn=0; nn<ppd->
images(); nn++ ) {
2011 cout << nn+1 <<
tab <<
shift << endl;
2012 for ( zz=0; zz<ppd->z; zz++ ) {
2014 if ( iz < 0 ) iz += ppd->z;
2016 if ( zz > (ppd->z - 1)/2 ) dz -= ppd->z;
2019 for ( yy=0; yy<ppd->y; yy++ ) {
2021 if ( iy < 0 ) iy += ppd->y;
2023 if ( yy > (ppd->y - 1)/2 ) dy -= ppd->y;
2026 for ( xx=0; xx<ppd->x/2+1; xx++ ) {
2028 if ( ix < 0 ) ix += ppd->x;
2031 s2 = sx2 + sy2 + sz2;
2032 if ( s2 >= smin2 && s2 <= smax2 ) {
2033 i = ppd->
index(xx,yy,zz,nn);
2034 j = ppd->
index(ix,iy,iz,nn);
2039 switch ( weighting ) {
2047 amp = temp1.
amp()*temp2.
amp();
2054 avg_pd += amp*fabs(dphi);
2061 if ( sum_amp ) avg_pd /= sum_amp;
2078 long i, ds(x*y*z*n);
2080 for ( i=0; i<ds; i++ )