32 cerr <<
"Error: Cannot check the symmetry - the data block is empty!" << endl;
36 if ( resolution <= 0 ) resolution = 0.1;
38 double* avgdx =
new double[3*p->
images()];
49 unsigned long i, j, n, x, y, z;
51 int h[3], hs[3], xs[3], nx[3], avgnx[3];
54 double dist, tol(0.01);
55 double amp[200], phi[200], phis[200], damp, dphi;
56 double ampavg, phiavg, fomavg;
58 float* fom = p->
FOM();
61 cout <<
"Checking symmetry for space group " << p->
space_group() << endl;
62 cout <<
"Symmetry operators: " << nsym << endl;
63 cout <<
"Tolerance for selection: " << tol << endl;
64 cout <<
"Reflection index limit: " << order << endl;
66 cout <<
"Checking symmetry for space group " << p->
space_group() << endl << endl;
69 for ( i=0; i<nsym; i++ ) {
70 cout <<
"Symmetry operator " << i+1 <<
":" << endl;
72 cout <<
"|" << symat[i*12+4*j] <<
" " << symat[i*12+4*j+1] <<
" "
73 << symat[i*12+4*j+2] <<
"| |" << symat[i*12+4*j+3] <<
"|" << endl;
78 cout <<
"Image\tRefl\tR(amp)\tR(phi)\tdx\tdy\tdz" << endl;
80 for ( n=0; n<p->
images(); n++ ) {
83 avgnx[0] = avgnx[1] = avgnx[2] = 0;
84 for ( z=0; z<p->
sizeZ(); z++ ) {
86 if ( h[2] >= (p->
sizeZ()+1)/2 ) h[2] -= p->
sizeZ();
87 for ( y=0; y<p->
sizeY(); y++ ) {
89 if ( h[1] >= (p->
sizeY()+1)/2 ) h[1] -= p->
sizeY();
90 for ( x=0; x<p->
sizeX(); x++ ) {
92 if ( h[0] >= (p->
sizeX()+1)/2 ) h[0] -= p->
sizeX();
93 dist = sqrt(1.0*h[0]*h[0] + h[1]*h[1] + h[2]*h[2]);
95 i = p->
index(0,x,y,z,n);
97 if ( dist <= order && amp[0] > tol ) {
99 nx[0] = nx[1] = nx[2] = 0;
100 dx[0] = dx[1] = dx[2] = 0;
101 ampavg = phiavg = fomavg = 0;
102 for ( j=0; j<nsym; j++ ) {
103 for ( m=0; m<3; m++ ) {
104 hs[m] = (int) (h[0]*symat[j*12+4*m] +
105 h[1]*symat[j*12+4*m+1] +
106 h[2]*symat[j*12+4*m+2]);
109 if ( xs[0] < 0 ) xs[0] += p->
sizeX();
110 if ( xs[1] < 0 ) xs[1] += p->
sizeY();
111 if ( xs[2] < 0 ) xs[2] += p->
sizeZ();
113 amp[j] = (p->
complex(i)).amp();
114 if ( amp[j] > tol ) {
115 phi[j] = (p->
complex(i)).phi();
116 phis[j] = phi[j] +
TWOPI*(h[0]*symat[j*12+3] +
118 h[2]*symat[j*12+11]);
119 damp = amp[0] - amp[j];
120 dphi = phi[0] - phis[j];
122 phis[j] = phi[0] - dphi;
123 for ( m=0; m<3; m++ )
if ( hs[m] != h[m] ) {
124 dx[m] -= dphi/(
TWOPI*(hs[m]-h[m]));
128 if ( fabs(dphi) > tol )
129 cout <<
"amp dphi: " << x <<
" " << y <<
" "
130 << z <<
" " << j <<
" " << amp[j] <<
" " << dphi << endl;
134 if ( fom ) fomavg += fom[i];
145 for ( m=0; m<3; m++ ) {
146 if ( nx[m] ) dx[m] /= nx[m];
147 avgdx[3*n+m] += dx[m];
152 if ( fabs(phiavg-phi[0]) > tol )
153 cout <<
"d_phiavg: " << x <<
" " << y <<
" "
154 << z <<
" " << phi[0] <<
" " << phiavg <<
" " << ni << endl;
159 for ( m=0; m<3; m++ )
if ( avgnx[m] ) avgdx[3*n+m] /= avgnx[m];
161 Ramp = sqrt(Ramp/nR);
162 Rphi = sqrt(Rphi/nR);
167 p->
image[n].
origin(avgdx[3*n+0], avgdx[3*n+1], avgdx[3*n+2]);
182 cerr <<
"Error: Cannot apply the symmetry - the data block is empty!" << endl;
186 if ( resolution <= 0 ) resolution = 0.1;
188 double* dx =
new double[3*p->
images()];
199 unsigned long i, j, n, x, y, z;
201 int h[3], hs[3], xs[3], ind[200];
203 double dist, tol(0.01);
204 double amp[200], phi[200], phis[200], damp, dphi;
205 double ampavg, phiavg, fomavg;
207 float* fom = p->
FOM();
210 cout <<
"Applying symmetry for space group " << p->
space_group() << endl;
211 cout <<
"Symmetry operators: " << nsym << endl;
212 cout <<
"Tolerance for selection: " << tol << endl;
213 cout <<
"Reflection index limit: " << order << endl;
215 cout <<
"Applying symmetry for space group " << p->
space_group() << endl << endl;
218 for ( i=0; i<nsym; i++ ) {
219 cout <<
"Symmetry operator " << i+1 <<
":" << endl;
220 for ( j=0; j<3; j++ )
221 cout <<
"|" << symat[i*12+4*j] <<
" " << symat[i*12+4*j+1] <<
" "
222 << symat[i*12+4*j+2] <<
"| |" << symat[i*12+4*j+3] <<
"|" << endl;
227 cout <<
"Image\tRefl\tR(amp)\tR(phi)\tdx\tdy\tdz" << endl;
229 for ( n=0; n<p->
images(); n++ ) {
235 for ( z=0; z<p->
sizeZ(); z++ ) {
237 if ( h[2] >= (p->
sizeZ()+1)/2 ) h[2] -= p->
sizeZ();
238 for ( y=0; y<p->
sizeY(); y++ ) {
240 if ( h[1] >= (p->
sizeY()+1)/2 ) h[1] -= p->
sizeY();
241 for ( x=0; x<p->
sizeX(); x++ ) {
243 if ( h[0] >= (p->
sizeX()+1)/2 ) h[0] -= p->
sizeX();
244 dist = sqrt(1.0*h[0]*h[0] + h[1]*h[1] + h[2]*h[2]);
246 i = p->
index(0,x,y,z,n);
247 amp[0] = (p->
complex(i)).amp();
248 if ( dist <= order && amp[0] > tol ) {
250 ampavg = phiavg = fomavg = 0;
251 for ( j=0; j<nsym; j++ ) {
252 for ( m=0; m<3; m++ ) {
253 hs[m] = (int) (h[0]*symat[j*12+4*m] +
254 h[1]*symat[j*12+4*m+1] +
255 h[2]*symat[j*12+4*m+2]);
258 if ( xs[0] < 0 ) xs[0] += p->
sizeX();
259 if ( xs[1] < 0 ) xs[1] += p->
sizeY();
260 if ( xs[2] < 0 ) xs[2] += p->
sizeZ();
263 amp[j] = (p->
complex(i)).amp();
264 if ( amp[j] > tol ) {
265 phi[j] = (p->
complex(i)).phi();
266 phis[j] = phi[j] +
TWOPI*(h[0]*symat[j*12+3] +
268 h[2]*symat[j*12+11]);
269 damp = amp[0] - amp[j];
270 dphi = phi[0] - phis[j];
272 phis[j] = phi[0] - dphi;
274 if ( fabs(dphi) > tol )
275 cout <<
"amp dphi: " << x <<
" " << y <<
" "
276 << z <<
" " << j <<
" " << amp[j] <<
" " << dphi << endl;
279 if ( fom ) fomavg += fom[i];
292 if ( fabs(phiavg-phi[0]) > tol )
293 cout <<
"d_phiavg: " << x <<
" " << y <<
" "
294 << z <<
" " << phi[0] <<
" " << phiavg <<
" " << ni << endl;
295 for ( j=0; j<nsym; j++ ) {
297 for ( m=0; m<3; m++ )
298 hs[m] = (
int) (h[0]*symat[j*12+4*m] +
299 h[1]*symat[j*12+4*m+1] +
300 h[2]*symat[j*12+4*m+2]);
301 phi[j] = phi[0] -
TWOPI*(h[0]*symat[j*12+3] +
304 -
TWOPI*((hs[0]-h[0])*dx[3*n+0] +
305 (hs[1]-h[1])*dx[3*n+1] +
306 (hs[2]-h[2])*dx[3*n+2]);
308 if ( fom ) fom[i] = fomavg;
315 Ramp = sqrt(Ramp/nR);
316 Rphi = sqrt(Rphi/nR);
320 dx[3*n+0] <<
tab << dx[3*n+1] <<
tab << dx[3*n+2] << endl;
339 unsigned long i, j, n, x, y, z;
341 double amp, amps, phi, phis, damp, dphi;
342 double ampavg, phiavg, fomavg;
346 float* fom = p->
FOM();
349 cout <<
"Applying Friedel symmetry:" << endl;
350 cout <<
"Image\tRefl\tR(amp)\tR(phi)" << endl;
352 cout <<
"Applying Friedel symmetry" << endl << endl;
354 for ( n=0; n<p->
images(); n++ ) {
357 for ( z=0; z<p->
sizeZ(); z++ ) {
359 if ( zf < 0 ) zf += p->
sizeZ();
360 for ( y=0; y<p->
sizeY(); y++ ) {
362 if ( yf < 0 ) yf += p->
sizeY();
363 for ( x=0; x<(p->
sizeX()+1)/2; x++ ) {
365 if ( xf < 0 ) xf += p->
sizeX();
367 i = p->
index(0,x,y,z,n);
369 j = p->
index(0,xf,yf,zf,n);
378 if ( fabs(dphi) > tol )
379 cout <<
"amp dphi: " << x <<
" " << y <<
" "
380 << z <<
" " << j <<
" " << damp <<
" " << dphi << endl;
381 ampavg = (amp + amps)/2;
382 phiavg = phi - dphi/2;
387 fomavg = (fom[i] + fom[j])/2;
398 Ramp = sqrt(Ramp/nR);
399 Rphi = sqrt(Rphi/nR);
402 cout << n+1 <<
tab << nR <<
tab << Ramp <<
tab << Rphi*180/
M_PI << endl;
424 unsigned long i, j, n, x, y, z, ix, iy, iz;
425 double d, w, s(0), R(0), Ri(0), Rr(0), Ra(0), Rp(0);
429 for ( n=0; n<p->
images(); n++ ) {
430 for ( z=0; z<p->
sizeZ(); z++ ) {
431 iz = (z > 0)? p->
sizeZ() - z: z;
432 for ( y=0; y<p->
sizeY(); y++ ) {
433 iy = (y > 0)? p->
sizeY() - y: y;
434 for ( x=0; x<p->
sizeX(); x++ ) {
435 ix = (x > 0)? p->
sizeX() - x: x;
437 j = p->
index(0,x,y,z,n);
439 i = p->
index(0,ix,iy,iz,n);
442 if ( !isfinite(w) ) cout << x <<
" " << y <<
" " << z <<
" " << w << endl;
461 R = sqrt(Rr*Rr + Ri*Ri);
464 cout <<
"Friedel symmetry residuals:" << endl;
465 cout <<
"Real: " << Rr << endl;
466 cout <<
"Imaginary: " << Ri << endl;
467 cout <<
"Amplitude: " << Ra << endl;
468 cout <<
"Phase: " << Rp*180.0/
M_PI <<
" degrees" << endl;
469 cout <<
"Overall: " << R << endl << endl;
float * read_symat(Bstring &filename, int spacegroup, int *nsym)
Reading crystallographic symmetry operators.
Header file for image class.
double bcos(double x)
Avoid non-zero values for cos(PI/2) and cos(-PI/2).
Header file for general utilities.
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
CompoundType compound_type()
Class for complex numbers.
Header file for reading and writing symmetry operators.
size_t index(size_t nx, size_t ny)
3x3 Matrix manipulation functions
double bsin(double x)
Avoid non-zero values for sin(PI) and sin(-PI).
General image parameter class.
Vector3< double > real_size()
Header file for generalized linked list functions.
double img_check_friedel(Bimage *p)
Checks Friedel symmetry.
Complex< double > complex(size_t j)
Returns a complex value at the given index.
General FFT for n-dimensional data.
Header file for combining two images in various ways.
void simple_to_complex()
A simple image is converted to a complex image.
unsigned int space_group()
double * img_check_space_group(Bimage *p, double resolution)
Checks the crystal space group symmetry and the shift to a symmetry axis.
Header file for trigonometry functions.
void origin(double x, double y, double z)
void set(size_t j, double v)
Sets a single value at the given index.
unsigned char * data_pointer()
Header file for symmetry functions.
int img_apply_friedel(Bimage *p)
Applies Friedel symmetry.
double * img_apply_space_group(Bimage *p, double resolution)
Applies the necessary shift to superimpose the origin on a symmetry axis.
ostream & tab(ostream &out)