diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/refine.c | 53 |
1 files changed, 49 insertions, 4 deletions
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); |