aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2008-03-01 15:26:01 +0000
committertaw27 <taw27@bf6ca9ba-c028-0410-8290-897cf20841d1>2008-03-01 15:26:01 +0000
commit61427e6c0d395c0bf6b454d4b317d6dc68cea2ca (patch)
treec075971afe7c6ade6bab38e90488385a990118e4
parent3d2d72bb3bae9cbeeb038577968e8fe8911c8b79 (diff)
More refinement stuff
git-svn-id: svn://cook.msm.cam.ac.uk:745/diff-tomo/dtr@268 bf6ca9ba-c028-0410-8290-897cf20841d1
-rw-r--r--Makefile.am2
-rw-r--r--src/refine.c53
2 files changed, 50 insertions, 5 deletions
diff --git a/Makefile.am b/Makefile.am
index 6a1a7a4..9ac3ebb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,5 +1,5 @@
EXTRA_DIST = configure src/displaywindow.h src/trackball.h src/reflections.h src/control.h src/readpng.h src/mrc.h src/imagedisplay.h src/main.h \
data/displaywindow.ui src/utils.h src/itrans.h src/qdrp.h src/cache.h src/itrans-threshold.h src/basis.h \
src/itrans-zaefferer.h src/itrans-stat.h src/mapping.h src/reproject.h src/prealign.h \
- src/dirax.h src/image.h src/refine.h src/gtk-valuegraph.h src/intensities.h src/glbits.h
+ src/dirax.h src/image.h src/refine.h src/gtk-valuegraph.h src/intensities.h src/glbits.h src/gtk-valuegraph.h
SUBDIRS = src data
diff --git a/src/refine.c b/src/refine.c
index 4d2a12e..b56cc05 100644
--- a/src/refine.c
+++ b/src/refine.c
@@ -26,6 +26,8 @@
#include "reproject.h"
#include "mapping.h"
#include "refine.h"
+#include "gtk-valuegraph.h"
+#include "utils.h"
/* A simplex is an array of ten of these */
typedef struct {
@@ -42,24 +44,62 @@ typedef struct {
void refine_do_sequence(ControlContext *ctx) {
double omega_offs;
-
- for ( omega_offs=-2.0; omega_offs<=2.0; omega_offs+=0.01 ) {
+ int idx;
+ double *fit_vals;
+ GtkWidget *window_fit;
+ GtkWidget *graph_fit;
+ double fit_best, omega_offs_best;
+ int j;
+
+ fit_vals = malloc(401*sizeof(double));
+ idx = 0;
+
+ fit_best = 1000.0e9;
+ omega_offs_best = 0.0;
+ for ( omega_offs=-deg2rad(2.0); omega_offs<=deg2rad(2.0); omega_offs+=deg2rad(0.01) ) {
double fit;
int i;
+ Basis cell_copy;
+
+ cell_copy = *ctx->cell;
for ( i=0; i<ctx->images->n_images; i++ ) {
ctx->images->images[i].omega += omega_offs;
}
+ reproject_lattice_changed(ctx);
fit = refine_do_cell(ctx);
- printf("RF: omega_offs=%f, fit=%f nm^-1\n", omega_offs, fit/1e9);
+ printf("RF: omega_offs=%f deg, fit=%f nm^-1\n", rad2deg(omega_offs), fit/1e9);
+ fit_vals[idx++] = fit;
+ if ( fit < fit_best ) {
+ fit_best = fit;
+ omega_offs_best = omega_offs;
+ }
for ( i=0; i<ctx->images->n_images; i++ ) {
ctx->images->images[i].omega -= omega_offs;
}
+ *ctx->cell = cell_copy;
}
+
+ window_fit = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size(GTK_WINDOW(window_fit), 640, 256);
+ gtk_window_set_title(GTK_WINDOW(window_fit), "Omega-Search Graph: Fit");
+ graph_fit = gtk_value_graph_new();
+ gtk_value_graph_set_data(GTK_VALUE_GRAPH(graph_fit), fit_vals, idx);
+ gtk_container_add(GTK_CONTAINER(window_fit), graph_fit);
+ gtk_widget_show_all(window_fit);
+
+ /* Perform final refinement */
+ refine_do_cell(ctx);
+ printf("Best omega offset = %f deg (%f nm^-1)\n", rad2deg(omega_offs_best), fit_best/1e9);
+ for ( j=0; j<ctx->images->n_images; j++ ) {
+ ctx->images->images[j].omega += omega_offs_best;
+ }
+ reproject_lattice_changed(ctx);
+ mapping_adjust_axis(ctx, omega_offs_best);
}
@@ -318,11 +358,16 @@ double refine_do_cell(ControlContext *ctx) {
// printf("Simplex method iteration %i\n", it);
conv = refine_iteration(s, d, nf);
if ( conv < tol ) {
- printf("Converged after %i iterations (%f)\n", it, conv);
+ printf("Converged after %i iterations (%f nm^-1)\n", it, conv/1e9);
break;
}
}
+ /* Apply the final values to the cell */
+ ctx->cell->a.x += s[0].dax; ctx->cell->b.x += s[0].dbx; ctx->cell->c.x += s[0].dcx;
+ ctx->cell->a.y += s[0].day; ctx->cell->b.y += s[0].dby; ctx->cell->c.y += s[0].dcy;
+ ctx->cell->a.z += s[0].daz; ctx->cell->b.z += s[0].dbz; ctx->cell->c.z += s[0].dcz;
+
ctx->images->images[ctx->dw->cur_image].rflist = NULL;
reproject_lattice_changed(ctx);
displaywindow_update(ctx->dw);