37 for ( i=0; i<n; i++ ) ampavg += (p->
complex(i)).amp();
39 if ( ampavg < 1e-30 ) {
40 cout <<
"Error: Structure factor amplitude average too low: " << ampavg << endl;
45 cout <<
"Normalizing with amplitude average: " << ampavg << endl << endl;
47 for ( i=0; i<n; i++ ) {
71 cout <<
"Mirroring reflections" << endl << endl;
73 for ( i=0; i<n; i++ ) p->
set(i, (p->
complex(i)).conj());
95 double cone,
int weigh,
double fomcut)
97 if ( cone <= 0 ) cone =
M_PI_2;
99 if ( hires <= 0 ) hires = 0.1;
100 if ( lores > 0 && lores < hires ) swap(hires, lores);
102 unsigned long i, j, x, y, z, n, c, nr(0), deselect;
104 double s2, h2, k2, l2;
105 double smin2 = (lores > 0)? 1/lores: 0;
106 double smax2 = 1/hires;
112 double inv_tan_cone = 1/tan(cone);
114 float* fom = p->
FOM();
116 if ( cone <= 0 ) cone = 0.01;
117 for ( i=n=0; n<p->
images(); n++ ) {
118 for ( z=0; z<p->
sizeZ(); z++ ) {
120 if ( l > half.
z() ) l -= p->
sizeZ();
123 for ( y=0; y<p->
sizeY(); y++ ) {
125 if ( k > half.
y() ) k -= p->
sizeY();
128 for ( x=0; x<p->
sizeX(); x++, i++ ) {
130 if ( h > half.
x() ) h -= p->
sizeX();
135 if ( s2 > smax2 ) deselect = 1;
136 if ( s2 < smin2 ) deselect = 1;
140 }
else if ( sqrt((
double)h*h + (
double)k*k) -
141 fabs((
double)l)*inv_tan_cone < 0 ) {
145 if ( fom )
if ( fom[i] < fomcut ) {
153 if ( weigh && fom ) {
154 if ( isfinite(fom[i]) ) {
155 p->
set(j, (*p)[j] * fom[i]);
157 cout <<
"NaN at " << h <<
" " << k <<
" " << l << endl;
171 cout <<
"Reflections selected: " << nr << endl << endl;
189 unsigned long i, j, x, y, z, nmax = 0;
191 double hkl, idist, amp;
205 for ( i=z=0; z<p->
sizeZ(); z++ ) {
207 if ( l >= half.
z() ) l -= p->
sizeZ();
208 for ( y=0; y<p->
sizeY(); y++ ) {
210 if ( k >= half.
y() ) k -= p->
sizeY();
211 for ( x=0; x<p->
sizeX(); x++, i++ ) {
213 if ( h >= half.
x() ) h -= p->
sizeX();
216 hkl = sqrt(1.0*h*h + k*k + l*l);
218 j = (int) (idist*idist*idist);
219 if ( j >= NSHELLS ) j = NSHELLS - 1;
220 if ( nmax < j ) nmax = j;
221 if ( prof->
dist[j] < hkl ) prof->
dist[j] = hkl;
223 ampssum[j] += amp*amp;
230 for ( j=0; j<nmax; j++ )
231 if ( prof->
num[j] ) prof->
amp[j] = ampssum[j]/ampsum[j];
235 cout <<
"Resolution shell statistics for " << p->
file_name() <<
":" << endl;
236 cout <<
"Number of shells: " << nmax << endl;
237 cout <<
"Radius of inner shell: " << radius <<
" voxels" << endl;
238 cout <<
"Shell\tOrder\tReflections\tAmplitude" << endl;
239 for ( j=0; j<nmax; j++ )
241 prof->
num[j] <<
tab << prof->
amp[j] << endl;
260 unsigned long i, j, x, y, z;
261 int iq, iqz, iqy, iqx, oct[8];
264 for ( iq=0; iq<8; iq++ ) oct[iq] = 0;
266 for ( i=z=0; z<p->
sizeZ(); z++ ) {
267 iqz = (int) (4*floor(z*2.0/p->
sizeZ()));
268 for ( y=0; y<p->
sizeY(); y++ ) {
269 iqy = (int) (2*floor(y*2.0/p->
sizeY()));
270 for ( x=0; x<p->
sizeX(); x++, i++ ){
271 iqx = (int) (floor(x*2.0/p->
sizeX()));
272 iq = iqx + iqy + iqz;
274 if ( fabs(cv.
real()) > 1e-10 || fabs(cv.
imag()) > 1e-10 ) oct[iq]++;
280 for ( iq=0; iq<8; iq++ ) j += oct[iq];
283 cout <<
"Reflections: " << j << endl;
284 cout <<
"Octant coverage: ";
285 for ( iq=0; iq<8; iq++ ) cout <<
" " << oct[iq];
286 cout << endl << endl;
290 for ( i=0; i<8; i++ )
if ( oct[i] ) iq++;
303 if ( !p->
FOM() )
return -1;
305 unsigned long i, x, y, z, ihkl, ihisto, nmax(0);
308 double r1 = p->
sizeX()/3;
309 double r3 = r1*r1*r1;
313 float* sh =
new float[nsh];
314 int* npos =
new int[nsh];
315 int* nres =
new int[nsh];
316 float* res =
new float[nsh];
317 float* amp =
new float[nsh];
318 float* fomavg =
new float[nsh];
319 int* histo =
new int[nsh];
321 float* fom = p->
FOM();
326 cout <<
"Analyzing reflections" << endl;
329 for ( i=0; i<nsh; i++ ) {
330 sh[i] = pow(i*r3,1.0/3.0);
331 npos[i] = nres[i] = histo[i] = 0;
332 res[i] = amp[i] = fomavg[i] = 0;
339 for ( h=0; h<nsh; h++ )
340 for ( k=0; k<=nsh; k++ )
341 for ( l=0; l<=nsh; l++ ) {
342 s = sqrt(1.0*h*h + k*k + l*l);
344 while ( ( s >= sh[ihkl] ) && ( ihkl < nsh ) ) ihkl++;
349 for ( i=z=0; z<p->
sizeZ(); z++ ) {
351 if ( l >= half.
z() ) l -= p->
sizeZ();
352 for ( y=0; y<p->
sizeY(); y++ ) {
354 if ( k >= half.
y() ) k -= p->
sizeY();
355 for ( x=0; x<p->
sizeX(); x++, i++ ) {
357 if ( h >= half.
x() ) h -= p->
sizeX();
358 s = sqrt(1.0*h*h + k*k + l*l);
360 while ( ( s >= sh[ihkl] ) && ( ihkl < nsh ) ) ihkl++;
362 cout <<
"Too large: " << h <<
" " << k <<
" " << l << endl;
363 if ( fom[i] ) nres[ihkl]++;
364 if ( ihkl > nmax ) nmax = ihkl;
366 amp[ihkl] += (p->
complex(i)).amp();
367 fomavg[ihkl] += fom[i];
368 ihisto = (int) floor(19.9*fom[i]/p->
FOM_maximum());
376 cout <<
"Resolution shell statistics for " << iq <<
" octants:" << endl;
377 cout <<
"Shell\tMaxOrder\tMaxResol\tMaxRefl\tReflections\t%Complete\tAmplitudes\tFOM" << endl;
378 for ( i=1; i<nmax; i++ ) {
382 res[i] = realsize/res[i];
384 fomavg[i] /= nres[i];
386 cout << i <<
tab << sh[i] <<
tab << realsize/sh[i] <<
tab << npos[i] <<
tab << nres[i] <<
tab <<
387 nres[i]*100.0/npos[i] <<
tab << amp[i] <<
tab << fomavg[i] << endl;
393 cout <<
"Histogram:" << endl;
394 cout <<
"Bin\tFOM\tCount\tFOM cutoff" << endl;
395 for ( i=0; i<20; i++ ) {
427 double radius = 0.15*p->
sizeX();
434 cout <<
"Scale profile:" << endl;
436 unsigned long i, j, x, y, z;
438 double idist, thresh = 1e-10, scale[
NSHELLS];
442 if ( prof->
amp[i] > thresh && prof2->
amp[i] > thresh ) {
443 scale[i] = prof2->
amp[i]/prof->
amp[i];
445 cout << i <<
tab << scale[i] << endl;
448 if (
verbose & VERB_PROCESS ) cout << endl;
450 for ( i=z=0; z<p->
sizeZ(); z++ ) {
452 if ( l >= half.
z() ) l -= p->
sizeZ();
453 for ( y=0; y<p->
sizeY(); y++ ) {
455 if ( k >= half.
y() ) k -= p->
sizeY();
456 for ( x=0; x<p->
sizeX(); x++, i++ ) {
458 if ( h >= half.
x() ) h -= p->
sizeX();
459 idist = sqrt(1.0*h*h + k*k + l*l)/radius;
460 j = (int) floor(idist*idist*idist);
486 double radius = 0.15*p->
sizeX();
490 float* fom = p->
FOM();
491 float* fom2 = p2->
FOM();
494 cout <<
"Scale profile for 2nd data set:" << endl;
496 unsigned long i, j, x, y, z;
498 double idist, thresh = 0.1, scale[
NSHELLS], fomsum;
503 if ( prof->
amp[i] > thresh && prof2->
amp[i] > thresh ) {
504 scale[i] = prof->
amp[i]/prof2->
amp[i];
506 cout << i <<
tab << scale[i] << endl;
510 for ( i=z=0; z<p->
sizeZ(); z++ ) {
513 for ( y=0; y<p->
sizeY(); y++ ) {
516 for ( x=0; x<p->
sizeX(); x++, i++ ) {
519 idist = sqrt(1.0*h*h + k*k + l*l)/radius;
520 j = (int) floor(idist*idist*idist);
522 if ( fom && fom2 ) fomsum = fom[i] + fom2[i];
525 if ( fomsum > thresh ) {
527 p->
set(i, (cv * fom[i] + cv2 * fom2[i] * scale[j])/fomsum);
528 fom[i] = (fom[i]*fom[i] + fom2[i]*fom2[i])/fomsum;
529 }
else if ( fom2 && fom2[i] > thresh ) {
531 p->
set(i, cv2 * scale[j]);
Header file for general utilities.
CompoundType compound_type()
Class for complex numbers.
General image parameter class.
int img_normalize_reflections(Bimage *p)
Normalizes a set of reflections encoded as a complex image.
Vector3< double > real_size()
int img_mirror_reflections(Bimage *p)
Mirrors a set of reflections by negating the phases.
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Complex< double > complex(size_t j)
Returns a complex value at the given index.
General FFT for n-dimensional data.
int img_fft(Bimage *p)
Fast Fourier transforms an image.
void file_name(Bstring s)
unsigned long img_select_reflections(Bimage *p, double hires, double lores, double cone, int weigh, double fomcut)
Selects reflections for output.
void origin(double x, double y, double z)
int img_octants(Bimage *p)
Counts the number of reflections in each octant.
void set(size_t j, double v)
Sets a single value at the given index.
int img_sfscale(Bimage *p, Bstring &hklname)
Scales the input reflections with a second set.
Bprofile * img_reflection_profile(Bimage *p, double radius)
Calculates a radial profile average.
Header file for symmetry functions.
int img_sfanalyze(Bimage *p)
Analyzes the FOM's of a set of reflections encoded as a complex image.
Header file for 2D and 3D image I/O.
Routines to manipulate reflection files.
int img_sfmerge(Bimage *p, Bstring &hklname)
Merges the input reflections with a second set.
ostream & tab(ostream &out)