From a2d88b99434ce0a6a3d663b780c424b27ce95a46 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Feb 2021 12:19:51 +0100 Subject: GUI: Plumbing, ready to run ambigator job --- src/gui_ambi.c | 146 +++++++++++++++++++++++++++++++++++++++++++++++- src/gui_backend_local.c | 91 ++++++++++++++++++++++++++++++ src/gui_backend_slurm.c | 122 ++++++++++++++++++++++++++++++++++++++++ src/gui_project.c | 11 ++++ src/gui_project.h | 30 ++++++++++ 5 files changed, 398 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui_ambi.c b/src/gui_ambi.c index 20cc8055..d5a295cf 100644 --- a/src/gui_ambi.c +++ b/src/gui_ambi.c @@ -59,9 +59,45 @@ struct ambi_window GtkWidget *operator; GtkWidget *use_source_sym; GtkWidget *use_operator; + GtkWidget *backend_combo; + GtkWidget *backend_opts_widget; + GtkWidget *backend_opts_box; }; +static int run_ambi(struct crystfelproject *proj, + const char *results_name, + int backend_idx, + const char *job_title, + const char *job_notes) +{ + struct crystfel_backend *be; + void *job_priv; + struct gui_indexing_result *input; + + /* Which result to merge? */ + input = find_indexing_result_by_name(proj, results_name); + if ( input == NULL ) { + ERROR("Please select a result first\n"); + return 1; + } + + be = &proj->backends[backend_idx]; + job_priv = be->run_ambi(job_title, job_notes, proj, input, + be->ambi_opts_priv); + + if ( job_priv != NULL ) { + char name[256]; + snprintf(name, 255, "Resolving indexing ambiguity (%s)", job_title); + add_running_task(proj, name, be, job_priv); + return 0; + } else { + return 1; + } +} + + + static char *get_sym(GtkWidget *w) { return crystfel_symmetry_selector_get_group_symbol(CRYSTFEL_SYMMETRY_SELECTOR(w)); @@ -83,6 +119,12 @@ static void ambi_response_sig(GtkWidget *dialog, gint resp, int r = 0; if ( resp == GTK_RESPONSE_ACCEPT ) { + + int backend_idx; + const char *job_title; + char *job_notes; + const char *results_name; + win->proj->ambi_use_res = get_bool(win->limit_res); win->proj->ambi_res_min = get_float(win->min_res); win->proj->ambi_res_max = get_float(win->max_res); @@ -92,9 +134,41 @@ static void ambi_response_sig(GtkWidget *dialog, gint resp, win->proj->ambi_sym = get_sym(win->sym); win->proj->ambi_source_sym = get_sym(win->source_sym); win->proj->ambi_operator = get_str(win->operator); + + backend_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(win->backend_combo)); + if ( backend_idx < 0 ) return; + + job_title = gtk_entry_get_text(GTK_ENTRY(win->jobname)); + job_notes = get_all_text(GTK_TEXT_VIEW(win->notes_page->textview)); + + if ( job_title[0] == '\0' ) { + ERROR("You must provide a job name.\n"); + return; + } + + free(win->proj->ambi_new_job_title); + win->proj->ambi_new_job_title = strdup(job_title); + + results_name = gtk_combo_box_get_active_id(GTK_COMBO_BOX(win->dataset)); + if ( results_name == NULL ) { + ERROR("Please select the input\n"); + return; + } + if ( run_ambi(win->proj, results_name, + backend_idx, job_title, job_notes) == 0 ) + { + gtk_widget_destroy(dialog); + win->proj->ambi_opts = NULL; + } + + free(job_notes); + } - if ( !r ) gtk_widget_destroy(dialog); + if ( !r ) { + gtk_widget_destroy(dialog); + win->proj->ambi_opts = NULL; + } } @@ -223,9 +297,74 @@ static GtkWidget *make_ambigator_options(struct ambi_window *win) } +static void ambi_backend_changed_sig(GtkWidget *combo, + struct ambi_window *win) +{ + int backend_idx; + struct crystfel_backend *be; + + backend_idx = gtk_combo_box_get_active(GTK_COMBO_BOX(combo)); + if ( backend_idx < 0 ) return; + win->proj->ambi_backend_selected = backend_idx; + + be = &win->proj->backends[backend_idx]; + + if ( win->backend_opts_widget != NULL ) { + gtk_widget_destroy(win->backend_opts_widget); + } + + win->backend_opts_widget = be->make_ambi_parameters_widget(be->ambi_opts_priv); + + gtk_box_pack_start(GTK_BOX(win->backend_opts_box), + GTK_WIDGET(win->backend_opts_widget), + FALSE, FALSE, 0); + gtk_widget_show_all(win->backend_opts_widget); +} + + static GtkWidget *make_ambi_backend_opts(struct ambi_window *win) { - return gtk_vbox_new(FALSE, 0.0); + GtkWidget *box; + GtkWidget *hbox; + GtkWidget *label; + int i; + + box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); + gtk_container_set_border_width(GTK_CONTAINER(box), 8); + + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); + gtk_box_pack_start(GTK_BOX(box), GTK_WIDGET(hbox), + FALSE, FALSE, 0); + label = gtk_label_new("Batch system:"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), + FALSE, FALSE, 0); + + win->backend_combo = gtk_combo_box_text_new(); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(win->backend_combo), + FALSE, FALSE, 0); + + for ( i=0; iproj->n_backends; i++ ) { + gtk_combo_box_text_append(GTK_COMBO_BOX_TEXT(win->backend_combo), + win->proj->backends[i].name, + win->proj->backends[i].friendly_name); + } + + win->backend_opts_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, + 0); + gtk_box_pack_start(GTK_BOX(box), + GTK_WIDGET(win->backend_opts_box), + FALSE, FALSE, 0); + win->backend_opts_widget = NULL; + + /* win->backend_opts{_box} must exist before the following */ + g_signal_connect(G_OBJECT(win->backend_combo), "changed", + G_CALLBACK(ambi_backend_changed_sig), win); + gtk_combo_box_set_active(GTK_COMBO_BOX(win->backend_combo), + win->proj->ambi_backend_selected); + + gtk_widget_show_all(box); + + return box; } @@ -241,6 +380,8 @@ gint ambi_sig(GtkWidget *widget, struct crystfelproject *proj) struct ambi_window *win; int i; + if ( proj->ambi_opts != NULL ) return FALSE; + win = malloc(sizeof(struct ambi_window)); if ( win == NULL ) return 0; @@ -252,6 +393,7 @@ gint ambi_sig(GtkWidget *widget, struct crystfelproject *proj) "Close", GTK_RESPONSE_CLOSE, "Run", GTK_RESPONSE_ACCEPT, NULL); + proj->ambi_opts = dialog; g_signal_connect(G_OBJECT(dialog), "response", G_CALLBACK(ambi_response_sig), diff --git a/src/gui_backend_local.c b/src/gui_backend_local.c index 224d3415..3af63ea0 100644 --- a/src/gui_backend_local.c +++ b/src/gui_backend_local.c @@ -52,6 +52,12 @@ struct local_merging_opts }; +struct local_ambi_opts +{ + int n_threads; +}; + + struct local_job { double frac_complete; @@ -436,6 +442,16 @@ static gboolean merge_readable(GIOChannel *source, GIOCondition cond, } +static void *run_ambi(const char *job_title, + const char *job_notes, + struct crystfelproject *proj, + struct gui_indexing_result *input, + void *opts_priv) +{ + return NULL; +} + + static void *run_merging(const char *job_title, const char *job_notes, struct crystfelproject *proj, @@ -563,6 +579,74 @@ static void read_merging_opt(void *opts_priv, } +static GtkWidget *make_ambi_parameters_widget(void *opts_priv) +{ + struct local_ambi_opts *opts = opts_priv; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *entry; + GtkWidget *label; + char tmp[64]; + + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); + + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), + FALSE, FALSE, 0); + label = gtk_label_new("Number of threads:"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), + FALSE, FALSE, 0); + entry = gtk_entry_new(); + snprintf(tmp, 63, "%i", opts->n_threads); + gtk_entry_set_text(GTK_ENTRY(entry), tmp); + gtk_entry_set_width_chars(GTK_ENTRY(entry), 5); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), + FALSE, FALSE, 0); + + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(n_threads_activate_sig), + opts); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(n_threads_focus_sig), + opts); + return vbox; +} + + +static struct local_ambi_opts *make_default_local_ambi_opts() +{ + struct local_ambi_opts *opts = malloc(sizeof(struct local_ambi_opts)); + if ( opts == NULL ) return NULL; + + opts->n_threads = 4; + + return opts; +} + + +static void write_ambi_opts(void *opts_priv, FILE *fh) +{ + struct local_ambi_opts *opts = opts_priv; + + fprintf(fh, "ambi.local.n_threads %i\n", + opts->n_threads); +} + + +static void read_ambi_opt(void *opts_priv, + const char *key, + const char *val) +{ + struct local_ambi_opts *opts = opts_priv; + + if ( strcmp(key, "ambi.local.n_threads") == 0 ) { + if ( convert_int(val, &opts->n_threads) ) { + ERROR("Invalid number of threads: %s\n", val); + } + } +} + + int make_local_backend(struct crystfel_backend *be) { be->name = "local"; @@ -585,5 +669,12 @@ int make_local_backend(struct crystfel_backend *be) be->write_merging_opts = write_merging_opts; be->read_merging_opt = read_merging_opt; + be->make_ambi_parameters_widget = make_ambi_parameters_widget; + be->run_ambi = run_ambi; + be->ambi_opts_priv = make_default_local_ambi_opts(); + if ( be->ambi_opts_priv == NULL ) return 1; + be->write_ambi_opts = write_ambi_opts; + be->read_ambi_opt = read_ambi_opt; + return 0; }; diff --git a/src/gui_backend_slurm.c b/src/gui_backend_slurm.c index 74396699..e6526574 100644 --- a/src/gui_backend_slurm.c +++ b/src/gui_backend_slurm.c @@ -57,6 +57,12 @@ struct slurm_merging_opts char *email_address; }; +struct slurm_ambi_opts +{ + char *partition; + char *email_address; +}; + enum slurm_job_type { SLURM_JOB_INDEXING, @@ -731,6 +737,16 @@ static void read_indexing_opt(void *opts_priv, } +static void *run_ambi(const char *job_title, + const char *job_notes, + struct crystfelproject *proj, + struct gui_indexing_result *input, + void *opts_priv) +{ + return NULL; +} + + static void *run_merging(const char *job_title, const char *job_notes, struct crystfelproject *proj, @@ -909,6 +925,105 @@ static GtkWidget *make_merging_parameters_widget(void *opts_priv) } +static struct slurm_ambi_opts *make_default_slurm_ambi_opts() +{ + struct slurm_ambi_opts *opts = malloc(sizeof(struct slurm_ambi_opts)); + if ( opts == NULL ) return NULL; + + opts->email_address = NULL; + opts->partition = NULL; + + return opts; +} + + +static void write_ambi_opts(void *opts_priv, FILE *fh) +{ + struct slurm_ambi_opts *opts = opts_priv; + + if ( opts->partition != NULL) { + fprintf(fh, "ambi.slurm.partition %s\n", + opts->partition); + } + + if ( opts->email_address != NULL ) { + fprintf(fh, "ambi.slurm.email_address %s\n", + opts->email_address); + } +} + + +static void read_ambi_opt(void *opts_priv, + const char *key, + const char *val) +{ + struct slurm_ambi_opts *opts = opts_priv; + + if ( strcmp(key, "ambi.slurm.email_address") == 0 ) { + opts->email_address = strdup(val); + } + + if ( strcmp(key, "ambi.slurm.partition") == 0 ) { + opts->partition = strdup(val); + } +} + + +static GtkWidget *make_ambi_parameters_widget(void *opts_priv) +{ + struct slurm_ambi_opts *opts = opts_priv; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *entry; + GtkWidget *label; + + vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8); + + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), + FALSE, FALSE, 0); + label = gtk_label_new("Submit job to partition:"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), + FALSE, FALSE, 0); + entry = gtk_entry_new(); + if ( opts->partition != NULL ) { + gtk_entry_set_text(GTK_ENTRY(entry), opts->partition); + } + gtk_entry_set_placeholder_text(GTK_ENTRY(entry), "maxwell"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), + FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(partition_activate_sig), + opts); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(partition_focus_sig), + opts); + + hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); + gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET(hbox), + FALSE, FALSE, 0); + label = gtk_label_new("Send notifications to:"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(label), + FALSE, FALSE, 0); + entry = gtk_entry_new(); + if ( opts->email_address != NULL ) { + gtk_entry_set_text(GTK_ENTRY(entry), opts->email_address); + } + gtk_entry_set_placeholder_text(GTK_ENTRY(entry), + "myself@example.org"); + gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(entry), + FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(entry), "activate", + G_CALLBACK(email_activate_sig), + opts); + g_signal_connect(G_OBJECT(entry), "focus-out-event", + G_CALLBACK(email_focus_sig), + opts); + + return vbox; +} + + int make_slurm_backend(struct crystfel_backend *be) { be->name = "slurm"; @@ -931,5 +1046,12 @@ int make_slurm_backend(struct crystfel_backend *be) be->write_merging_opts = write_merging_opts; be->read_merging_opt = read_merging_opt; + be->make_ambi_parameters_widget = make_ambi_parameters_widget; + be->run_ambi = run_ambi; + be->ambi_opts_priv = make_default_slurm_ambi_opts(); + if ( be->ambi_opts_priv == NULL ) return 1; + be->write_ambi_opts = write_ambi_opts; + be->read_ambi_opt = read_ambi_opt; + return 0; }; diff --git a/src/gui_project.c b/src/gui_project.c index 29d91b94..aea76d1e 100644 --- a/src/gui_project.c +++ b/src/gui_project.c @@ -461,6 +461,11 @@ static void handle_var(const char *key, const char *val, proj->merging_new_job_title = strdup(val); } + if ( strcmp(key, "ambi.new_job_title") == 0 ) { + free(proj->ambi_new_job_title); + proj->ambi_new_job_title = strdup(val); + } + if ( strcmp(key, "indexing.backend") == 0 ) { proj->indexing_backend_selected = find_backend(val, proj); } @@ -923,6 +928,10 @@ int save_project(struct crystfelproject *proj) if ( proj->ambi_operator != NULL ) { fprintf(fh, "ambi.operator %s\n", proj->ambi_operator); } + if ( proj->ambi_new_job_title != NULL ) { + fprintf(fh, "ambi.new_job_title %s\n", + proj->ambi_new_job_title); + } fprintf(fh, "merging.model %s\n", proj->merging_params.model); @@ -1030,9 +1039,11 @@ void default_project(struct crystfelproject *proj) proj->cur_image = NULL; proj->indexing_opts = NULL; proj->merging_opts = NULL; + proj->ambi_opts = NULL; proj->n_running_tasks = 0; proj->indexing_new_job_title = NULL; proj->merging_new_job_title = NULL; + proj->ambi_new_job_title = NULL; proj->indexing_backend_selected = 0; proj->merging_backend_selected = 0; diff --git a/src/gui_project.h b/src/gui_project.h index 4a2fd4dd..123a926a 100644 --- a/src/gui_project.h +++ b/src/gui_project.h @@ -146,6 +146,8 @@ struct crystfel_backend { int *running, float *fraction_complete); + /* ....................... Indexing ........................ */ + /* Backend should provide a GTK widget to set options */ GtkWidget *(*make_indexing_parameters_widget)(void *opts_priv); @@ -167,6 +169,8 @@ struct crystfel_backend { /* Backend should store options for indexing here */ void *indexing_opts_priv; + /* ....................... Merging ........................ */ + /* Backend should provide a GTK widget to set options */ GtkWidget *(*make_merging_parameters_widget)(void *opts_priv); @@ -189,6 +193,29 @@ struct crystfel_backend { /* Backend should store options for merging here */ void *merging_opts_priv; + /* .................. Indexing ambiguity .................. */ + + /* Backend should provide a GTK widget to set options */ + GtkWidget *(*make_ambi_parameters_widget)(void *opts_priv); + + /* Called to ask the backend to start resolving indexing ambiguity. + * It should return a void pointer representing this job */ + void *(*run_ambi)(const char *job_title, + const char *job_notes, + struct crystfelproject *proj, + struct gui_indexing_result *input, + void *opts_priv); + + /* Called to ask the backend to write its ambigator options */ + void (*write_ambi_opts)(void *opts_priv, FILE *fh); + + /* Called when reading a project from file */ + void (*read_ambi_opt)(void *opts_priv, + const char *key, + const char *val); + + /* Backend should store options for ambigator here */ + void *ambi_opts_priv; }; struct gui_task @@ -278,6 +305,9 @@ struct crystfelproject { double export_res_min; /* Angstroms */ double export_res_max; /* Angstroms */ + char *ambi_new_job_title; + int ambi_backend_selected; + GtkWidget *ambi_opts; int ambi_use_res; double ambi_res_min; /* Angstroms */ double ambi_res_max; /* Angstroms */ -- cgit v1.2.3