From 89b372a8d17f3e9d5f8a4fef36cbc5aba033e639 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 5 Apr 2012 15:06:17 +0200 Subject: Fix iteration bounds for peak integration --- libcrystfel/src/peaks.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 829a35ab..2ab45e53 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -185,8 +185,8 @@ static int integrate_peak(struct image *image, int cfs, int css, out_lim_sq = pow(ir_out, 2.0); /* Estimate the background */ - for ( fs=-ir_out; fs<+ir_out; fs++ ) { - for ( ss=-ir_out; ss<+ir_out; ss++ ) { + for ( fs=-ir_out; fs<=+ir_out; fs++ ) { + for ( ss=-ir_out; ss<=+ir_out; ss++ ) { double val; uint16_t flags; @@ -234,8 +234,8 @@ static int integrate_peak(struct image *image, int cfs, int css, pk_total = 0.0; pk_counts = 0; fsct = 0.0; ssct = 0.0; - for ( fs=-ir_inn; fs<+ir_inn; fs++ ) { - for ( ss=-ir_inn; ss<+ir_inn; ss++ ) { + for ( fs=-ir_inn; fs<=+ir_inn; fs++ ) { + for ( ss=-ir_inn; ss<=+ir_inn; ss++ ) { double val; uint16_t flags; -- cgit v1.2.3 From f556bc88774d44206990557303881e3b3c320248 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 2 Apr 2012 19:29:48 +0200 Subject: Improved spot prediction --- libcrystfel/src/geometry.c | 83 +++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 53 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 218c0fee..0f6e4809 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -99,29 +99,6 @@ static signed int locate_peak(double x, double y, double z, double k, } -static double excitation_error(double xl, double yl, double zl, - double ds, double k, double divergence, - double tt) -{ - double al; - double r; - double delta; - - al = M_PI_2 - asin(-zl/ds); - - r = ( ds * sin(al) / sin(tt) ) - k; - - delta = sqrt(2.0 * pow(ds, 2.0) * (1.0-cos(divergence))); - if ( divergence > 0.0 ) { - r += delta; - } else { - r -= delta; - } - - return r; -} - - static double partiality(double r1, double r2, double r) { double q1, q2; @@ -146,46 +123,44 @@ static Reflection *check_reflection(struct image *image, double csx, double csy, double csz) { const int output = 0; - double xl, yl, zl; - double ds, ds_sq; + double xl, yl, zl, tl; double rlow, rhigh; /* "Excitation error" */ signed int p; /* Panel number */ double xda, yda; /* Position on detector */ int close, inside; double part; /* Partiality */ - int clamp_low = 0; - int clamp_high = 0; - double bandwidth = image->bw; - double divergence = image->div; - double lambda = image->lambda; - double klow, kcen, khigh; /* Wavenumber */ + int clamp_low, clamp_high; + double klow, khigh; /* Wavenumber */ Reflection *refl; - double tt, psi; + double cet, cez; /* "low" gives the largest Ewald sphere, * "high" gives the smallest Ewald sphere. */ - klow = 1.0/(lambda - lambda*bandwidth/2.0); - kcen = 1.0/lambda; - khigh = 1.0/(lambda + lambda*bandwidth/2.0); + klow = 1.0/(image->lambda - image->lambda*image->bw/2.0); + khigh = 1.0/(image->lambda + image->lambda*image->bw/2.0); /* Get the coordinates of the reciprocal lattice point */ xl = h*asx + k*bsx + l*csx; yl = h*asy + k*bsy + l*csy; zl = h*asz + k*bsz + l*csz; - ds_sq = modulus_squared(xl, yl, zl); /* d*^2 */ - ds = sqrt(ds_sq); + /* If the point is looking "backscattery", reject it straight away */ + if ( zl < -khigh/2.0 ) return NULL; - /* Simple (fast) check to reject reflection if it's "in front" */ - psi = atan2(zl, sqrt(xl*xl + yl*yl)); - if ( psi - atan2(image->profile_radius, ds) > divergence ) return NULL; + tl = sqrt(xl*xl + yl*yl); - tt = angle_between(0.0, 0.0, 1.0, xl, yl, zl+kcen); - if ( tt > deg2rad(90.0) ) return NULL; + cet = -sin(image->div/2.0) * khigh; + cez = -cos(image->div/2.0) * khigh; + rhigh = khigh - distance(cet, cez, tl, zl); /* Loss of precision */ - /* Calculate excitation errors */ - rlow = excitation_error(xl, yl, zl, ds, klow, -divergence/2.0, tt); - rhigh = excitation_error(xl, yl, zl, ds, khigh, +divergence/2.0, tt); + cet = sin(image->div/2.0) * klow; + cez = -cos(image->div/2.0) * klow; + rlow = klow - distance(cet, cez, tl, zl); /* Loss of precision */ + + if ( rlow < rhigh ) { + STATUS("%i %i %i\n", h, k, l); + return NULL; + } /* Is the reciprocal lattice point close to either extreme of * the sphere, maybe just outside the "Ewald volume"? */ @@ -204,7 +179,13 @@ static Reflection *check_reflection(struct image *image, /* If the "lower" Ewald sphere is a long way away, use the * position at which the Ewald sphere would just touch the - * reflection. */ + * reflection. + * + * The six possible combinations of clamp_{low,high} (including + * zero) correspond to the six situations in Table 3 of Rossmann + * et al. (1979). + */ + clamp_low = 0; clamp_high = 0; if ( rlow < -image->profile_radius ) { rlow = -image->profile_radius; clamp_low = -1; @@ -213,7 +194,6 @@ static Reflection *check_reflection(struct image *image, rlow = +image->profile_radius; clamp_low = +1; } - /* Likewise the "higher" Ewald sphere */ if ( rhigh < -image->profile_radius ) { rhigh = -image->profile_radius; clamp_high = -1; @@ -222,16 +202,13 @@ static Reflection *check_reflection(struct image *image, rhigh = +image->profile_radius; clamp_high = +1; } - assert(clamp_low <= clamp_high); - /* The six possible combinations of clamp_{low,high} (including - * zero) correspond to the six situations in Table 3 of Rossmann - * et al. (1979). */ + assert(clamp_low >= clamp_high); /* Calculate partiality */ part = partiality(rlow, rhigh, image->profile_radius); /* Locate peak on detector. */ - p = locate_peak(xl, yl, zl, kcen, image->det, &xda, &yda); + p = locate_peak(xl, yl, zl, 1.0/image->lambda, image->det, &xda, &yda); if ( p == -1 ) return NULL; /* Add peak to list */ @@ -276,7 +253,7 @@ RefList *find_intersections(struct image *image, UnitCell *cell) /* We add a horrific 20% fudge factor because bandwidth, divergence * and so on mean reflections appear beyond the largest q */ - mres = 1.2 * largest_q(image); + mres = largest_q(image); hmax = mres / modulus(asx, asy, asz); kmax = mres / modulus(bsx, bsy, bsz); -- cgit v1.2.3 From 6a694000083fd5d6e0ecb48212cf25396854c60e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 3 Apr 2012 15:16:04 +0200 Subject: Fix partiality calculation --- libcrystfel/src/geometry.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 0f6e4809..a62820b4 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -99,20 +99,20 @@ static signed int locate_peak(double x, double y, double z, double k, } -static double partiality(double r1, double r2, double r) +static double partiality(double rlow, double rhigh, double r) { - double q1, q2; - double p1, p2; + double qlow, qhigh; + double plow, phigh; /* Calculate degrees of penetration */ - q1 = (r1 + r)/(2.0*r); - q2 = (r2 + r)/(2.0*r); + qlow = (rlow + r)/(2.0*r); + qhigh = (rhigh + r)/(2.0*r); /* Convert to partiality */ - p1 = 3.0*pow(q1,2.0) - 2.0*pow(q1,3.0); - p2 = 3.0*pow(q2,2.0) - 2.0*pow(q2,3.0); + plow = 3.0*pow(qlow,2.0) - 2.0*pow(qlow,3.0); + phigh = 3.0*pow(qhigh,2.0) - 2.0*pow(qhigh,3.0); - return p2 - p1; + return plow - phigh; } -- cgit v1.2.3 From 0b63042eb2ba93cb7706d1501f4237fe30b0ef2c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 3 Apr 2012 15:21:24 +0200 Subject: Remove old comment --- libcrystfel/src/geometry.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index a62820b4..92a0ab9a 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -251,8 +251,6 @@ RefList *find_intersections(struct image *image, UnitCell *cell) &bsx, &bsy, &bsz, &csx, &csy, &csz); - /* We add a horrific 20% fudge factor because bandwidth, divergence - * and so on mean reflections appear beyond the largest q */ mres = largest_q(image); hmax = mres / modulus(asx, asy, asz); -- cgit v1.2.3 From cac83d4925f3543b4dfc4ce881824fea225cef7e Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 10 Apr 2012 12:04:19 +0100 Subject: Fix maximum index calculation --- libcrystfel/src/geometry.c | 45 +++++++++++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 18 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 92a0ab9a..6b01c51c 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -118,12 +118,10 @@ static double partiality(double rlow, double rhigh, double r) static Reflection *check_reflection(struct image *image, signed int h, signed int k, signed int l, - double asx, double asy, double asz, - double bsx, double bsy, double bsz, - double csx, double csy, double csz) + double xl, double yl, double zl) { const int output = 0; - double xl, yl, zl, tl; + double tl; double rlow, rhigh; /* "Excitation error" */ signed int p; /* Panel number */ double xda, yda; /* Position on detector */ @@ -139,10 +137,6 @@ static Reflection *check_reflection(struct image *image, klow = 1.0/(image->lambda - image->lambda*image->bw/2.0); khigh = 1.0/(image->lambda + image->lambda*image->bw/2.0); - /* Get the coordinates of the reciprocal lattice point */ - xl = h*asx + k*bsx + l*csx; - yl = h*asy + k*bsy + l*csy; - zl = h*asz + k*bsz + l*csz; /* If the point is looking "backscattery", reject it straight away */ if ( zl < -khigh/2.0 ) return NULL; @@ -229,6 +223,9 @@ static Reflection *check_reflection(struct image *image, RefList *find_intersections(struct image *image, UnitCell *cell) { + double ax, ay, az; + double bx, by, bz; + double cx, cy, cz; double asx, asy, asz; double bsx, bsy, bsz; double csx, csy, csz; @@ -247,15 +244,13 @@ RefList *find_intersections(struct image *image, UnitCell *cell) return NULL; } - cell_get_reciprocal(cell, &asx, &asy, &asz, - &bsx, &bsy, &bsz, - &csx, &csy, &csz); + cell_get_cartesian(cell, &ax, &ay, &az, &bx, &by, &bz, &cx, &cy, &cz); mres = largest_q(image); - hmax = mres / modulus(asx, asy, asz); - kmax = mres / modulus(bsx, bsy, bsz); - lmax = mres / modulus(csx, csy, csz); + hmax = mres * modulus(ax, ay, az); + kmax = mres * modulus(bx, by, bz); + lmax = mres * modulus(cx, cy, cz); if ( (hmax >= 256) || (kmax >= 256) || (lmax >= 256) ) { ERROR("Unit cell is stupidly large.\n"); @@ -265,14 +260,23 @@ RefList *find_intersections(struct image *image, UnitCell *cell) if ( lmax >= 256 ) lmax = 255; } + cell_get_reciprocal(cell, &asx, &asy, &asz, + &bsx, &bsy, &bsz, + &csx, &csy, &csz); + for ( h=-hmax; h<=hmax; h++ ) { for ( k=-kmax; k<=kmax; k++ ) { for ( l=-lmax; l<=lmax; l++ ) { Reflection *refl; + double xl, yl, zl; - refl = check_reflection(image, h, k, l, - asx,asy,asz,bsx,bsy,bsz,csx,csy,csz); + /* Get the coordinates of the reciprocal lattice point */ + xl = h*asx + k*bsx + l*csx; + yl = h*asy + k*bsy + l*csy; + zl = h*asz + k*bsz + l*csz; + + refl = check_reflection(image, h, k, l, xl, yl, zl); if ( refl != NULL ) { add_refl_to_list(refl, reflections); @@ -308,13 +312,18 @@ void update_partialities(struct image *image) { Reflection *vals; double r1, r2, p, x, y; + double xl, yl, zl; signed int h, k, l; int clamp1, clamp2; get_symmetric_indices(refl, &h, &k, &l); - vals = check_reflection(image, h, k, l, - asx,asy,asz,bsx,bsy,bsz,csx,csy,csz); + /* Get the coordinates of the reciprocal lattice point */ + xl = h*asx + k*bsx + l*csx; + yl = h*asy + k*bsy + l*csy; + zl = h*asz + k*bsz + l*csz; + + vals = check_reflection(image, h, k, l, xl, yl, zl); if ( vals == NULL ) { set_redundancy(refl, 0); -- cgit v1.2.3 From 605ed411cc56da3bbf6d33a441c3d16adcfeb3a1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 19 Apr 2012 12:10:13 +0200 Subject: Simplify prediction criterion --- libcrystfel/src/geometry.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index 6b01c51c..e416a883 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -125,15 +125,15 @@ static Reflection *check_reflection(struct image *image, double rlow, rhigh; /* "Excitation error" */ signed int p; /* Panel number */ double xda, yda; /* Position on detector */ - int close, inside; double part; /* Partiality */ int clamp_low, clamp_high; double klow, khigh; /* Wavenumber */ Reflection *refl; double cet, cez; - /* "low" gives the largest Ewald sphere, - * "high" gives the smallest Ewald sphere. */ + /* "low" gives the largest Ewald sphere (wavelength short => k large) + * "high" gives the smallest Ewald sphere (wavelength long => k small) + */ klow = 1.0/(image->lambda - image->lambda*image->bw/2.0); khigh = 1.0/(image->lambda + image->lambda*image->bw/2.0); @@ -156,20 +156,9 @@ static Reflection *check_reflection(struct image *image, return NULL; } - /* Is the reciprocal lattice point close to either extreme of - * the sphere, maybe just outside the "Ewald volume"? */ - close = (fabs(rlow) < image->profile_radius) - || (fabs(rhigh) < image->profile_radius); - - /* Is the reciprocal lattice point somewhere between the - * extremes of the sphere, i.e. inside the "Ewald volume"? */ - inside = signbit(rlow) ^ signbit(rhigh); - - /* Can't be both inside and close */ - if ( inside ) close = 0; - - /* Neither? Skip it. */ - if ( !(close || inside) ) return NULL; + if ( (signbit(rlow) == signbit(rhigh)) + && (fabs(rlow) > image->profile_radius) + && (fabs(rhigh) > image->profile_radius) ) return NULL; /* If the "lower" Ewald sphere is a long way away, use the * position at which the Ewald sphere would just touch the -- cgit v1.2.3 From 83e8ae45888b8edbe6112d9bcceea3352c422255 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 19 Apr 2012 12:15:05 +0200 Subject: Remove check for rlow > rhigh I'm happy that there are no gremlins here, now. This happens only for 000, where rlow and rhigh both go to zero. It doesn't make sense to have a special check for the condition. --- libcrystfel/src/geometry.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index e416a883..f46cea25 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -151,11 +151,6 @@ static Reflection *check_reflection(struct image *image, cez = -cos(image->div/2.0) * klow; rlow = klow - distance(cet, cez, tl, zl); /* Loss of precision */ - if ( rlow < rhigh ) { - STATUS("%i %i %i\n", h, k, l); - return NULL; - } - if ( (signbit(rlow) == signbit(rhigh)) && (fabs(rlow) > image->profile_radius) && (fabs(rhigh) > image->profile_radius) ) return NULL; -- cgit v1.2.3 From 7f221c3bfbc5ad41016a451c778f7b8710be03ef Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 19 Apr 2012 16:49:20 +0200 Subject: Formatting --- libcrystfel/src/geometry.c | 1 - 1 file changed, 1 deletion(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/geometry.c b/libcrystfel/src/geometry.c index f46cea25..24669aef 100644 --- a/libcrystfel/src/geometry.c +++ b/libcrystfel/src/geometry.c @@ -137,7 +137,6 @@ static Reflection *check_reflection(struct image *image, klow = 1.0/(image->lambda - image->lambda*image->bw/2.0); khigh = 1.0/(image->lambda + image->lambda*image->bw/2.0); - /* If the point is looking "backscattery", reject it straight away */ if ( zl < -khigh/2.0 ) return NULL; -- cgit v1.2.3 From d7ff5c5ab2ffdaa2808d5e336603804450ca15b0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Apr 2012 13:58:38 +0200 Subject: Remove PEAK_CLOSE (not used for anything) --- libcrystfel/src/peaks.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 2ab45e53..88477190 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -52,10 +52,6 @@ #include "beam-parameters.h" -/* How close a peak must be to an indexed position to be considered "close" - * for the purposes of double hit detection and sanity checking. */ -#define PEAK_CLOSE (30.0) - /* How close a peak must be to an indexed position to be considered "close" * for the purposes of integration. */ #define PEAK_REALLY_CLOSE (10.0) -- cgit v1.2.3 From cfbbdae0ff6b0823fd9de0971f51b9fd939db5b6 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Apr 2012 14:08:12 +0200 Subject: indexamajig: Make --no-closer-peak the default --- libcrystfel/src/peaks.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 88477190..cddb6069 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -52,10 +52,6 @@ #include "beam-parameters.h" -/* How close a peak must be to an indexed position to be considered "close" - * for the purposes of integration. */ -#define PEAK_REALLY_CLOSE (10.0) - /* Degree of polarisation of X-ray beam */ #define POL (1.0) @@ -640,7 +636,9 @@ void integrate_reflections(struct image *image, int use_closer, int bgsub, } else { f = NULL; } - if ( (f != NULL) && (d < PEAK_REALLY_CLOSE) ) { + + /* FIXME: Horrible hardcoded value */ + if ( (f != NULL) && (d < 10.0) ) { pfs = f->fs; pss = f->ss; -- cgit v1.2.3 From d6c040ed981827f072e3e22501620a65a4418acd Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Apr 2012 14:10:20 +0200 Subject: Single point of truth for indices when sorting reflections --- libcrystfel/src/peaks.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index cddb6069..4b146eb6 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -534,9 +534,6 @@ int peak_sanity_check(struct image *image) struct integr_ind { - signed int h; - signed int k; - signed int l; double res; Reflection *refl; }; @@ -578,9 +575,6 @@ static struct integr_ind *sort_reflections(RefList *list, UnitCell *cell, get_indices(refl, &h, &k, &l); res = resolution(cell, h, k, l); - il[i].h = h; - il[i].k = k; - il[i].l = l; il[i].res = res; il[i].refl = refl; @@ -620,10 +614,12 @@ void integrate_reflections(struct image *image, int use_closer, int bgsub, double pfs, pss; int r; Reflection *refl; + signed int h, k, l; refl = il[i].refl; get_detector_pos(refl, &pfs, &pss); + get_indices(refl, &h, &k, &l); /* Is there a really close feature which was detected? */ if ( use_closer ) { -- cgit v1.2.3 From 23295e405b524d86475e22eb21a56fd1ada3e530 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 26 Apr 2012 14:51:58 +0200 Subject: Update the peak coordinates when doing --closer-peak This should make it much more obvious (via check-near-bragg) when the peak positions are wrong. --- libcrystfel/src/peaks.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libcrystfel') diff --git a/libcrystfel/src/peaks.c b/libcrystfel/src/peaks.c index 4b146eb6..78a68185 100644 --- a/libcrystfel/src/peaks.c +++ b/libcrystfel/src/peaks.c @@ -636,9 +636,15 @@ void integrate_reflections(struct image *image, int use_closer, int bgsub, /* FIXME: Horrible hardcoded value */ if ( (f != NULL) && (d < 10.0) ) { + double exe; + + exe = get_excitation_error(refl); + pfs = f->fs; pss = f->ss; + set_detector_pos(refl, exe, pfs, pss); + } } -- cgit v1.2.3