~ubuntu-branches/ubuntu/utopic/gdis/utopic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
/*
Copyright (C) 2003 by Sean David Fleming

sean@ivec.org

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

The GNU GPL can also be found at http://www.gnu.org
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

#include "gdis.h"
#include "coords.h"
#include "file.h"
#include "graph.h"
#include "analysis.h"
#include "dialog.h"
#include "interface.h"
#include "gui_shorts.h"

extern struct elem_pak elements[];
extern struct sysenv_pak sysenv;

/******************************/
/* export graphs as text data */
/******************************/
void analysis_export(gchar *name)
{
struct model_pak *model;

model = sysenv.active_model;
g_assert(model != NULL);

dialog_destroy_type(FILE_SELECT);

if (model->graph_active)
  {
  graph_write(name, model->graph_active);
  gui_text_show(STANDARD, "Successfully exported graph.\n");
  }
else
  gui_text_show(WARNING, "Current model is not a graph.\n");
}

/******************************/
/* export graph file selector */
/******************************/
void analysis_export_dialog(void)
{
/* FIXME - dialog + model are linked */
if (sysenv.active_model)
  file_dialog("Export graph as text", NULL, FILE_SAVE, 
              (gpointer) analysis_export, MD_ANALYSIS);
}

/**********************/
/* submit an rdf task */
/**********************/
void exec_analysis_task(GtkWidget *w, gpointer dialog)
{
const gchar *type;
gpointer gui_menu_calc;
struct analysis_pak *analysis;
struct model_pak *model;

/* duplicate the analysis structure at time of request */
g_assert(dialog != NULL);
model = dialog_model(dialog);
g_assert(model != NULL);
analysis = analysis_dup(model->analysis);

/* get the task type requested from the dialog */
gui_menu_calc = dialog_child_get(dialog, "gui_menu_calc");
type = gui_pulldown_text(gui_menu_calc);

if (g_ascii_strncasecmp(type, "RDF", 3) == 0)
  {
  analysis->rdf_normalize = TRUE;
  task_new("RDF", &analysis_plot_rdf, analysis, &analysis_show, model, model);
  return;
  }
if (g_ascii_strncasecmp(type, "Pair", 4) == 0)
  {
  analysis->rdf_normalize = FALSE;
  task_new("Pair", &analysis_plot_rdf, analysis, &analysis_show, model, model);
  return;
  }
if (g_ascii_strncasecmp(type, "VACF", 4) == 0)
  {
  task_new("VACF", &analysis_plot_vacf, analysis, &analysis_show, model, model);
  return;
  }
if (g_ascii_strncasecmp(type, "Temp", 4) == 0)
  {
  task_new("Temp", &analysis_plot_temp, analysis, &analysis_show, model, model);
  return;
  }
if (g_ascii_strncasecmp(type, "Pot", 3) == 0)
  {
  task_new("Energy", &analysis_plot_pe, analysis, &analysis_show, model, model);
  return;
  }
if (g_ascii_strncasecmp(type, "Kin", 3) == 0)
  {
  task_new("Energy", &analysis_plot_ke, analysis, &analysis_show, model, model);
  return;
  }
if (g_ascii_strncasecmp(type, "Meas", 4) == 0)
  {
  task_new("Measure", &analysis_plot_meas, analysis, &analysis_show, model, model);
  return;
  }
}

/**********************/
/* atom entry changed */
/**********************/
void md_atom_changed(GtkWidget *w, gchar **atom)
{
g_assert(w != NULL);

/* NB: we pass a pointer to the character pointer */
if (*atom)
  g_free(*atom);

*atom = g_strdup(gtk_entry_get_text(GTK_ENTRY(w)));
}

/*******************************/
/* multi-frame analysis dialog */
/*******************************/
void gui_analysis_dialog(void)
{
gpointer dialog;
GtkWidget *window, *combo, *label;
GtkWidget *frame, *main_hbox, *main_vbox, *hbox, *vbox;
GtkWidget *gui_menu_calc, *gui_vbox_rdf;
GSList *list, *item;
GList *match_list=NULL, *calc_list=NULL;
struct model_pak *model;
struct analysis_pak *analysis;

/* checks and setup */
model = sysenv.active_model;
if (!model)
  return;
if (!model->animation)
  return;
if (analysis_init(model))
  return;

analysis = model->analysis;

/* create new dialog */
dialog = dialog_request(MD_ANALYSIS, "MD analysis", NULL, NULL, model);
if (!dialog)
  return;
window = dialog_window(dialog);

/* --- main box */
main_hbox = gtk_hbox_new(TRUE, 0);
gtk_box_pack_start(GTK_BOX(GTK_DIALOG(window)->vbox), main_hbox, TRUE, TRUE, 0);

/* --- left pane */
main_vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(main_hbox), main_vbox, TRUE, TRUE, 0);

/* --- analysis dialogs are specific to the active model when initiated */
frame = gtk_frame_new("Model");
gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(frame), PANEL_SPACING);
hbox = gtk_hbox_new(TRUE, PANEL_SPACING);
gtk_container_add(GTK_CONTAINER(frame), hbox);
label = gtk_label_new(model->basename);
gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);

/* --- calculation menu */
frame = gtk_frame_new("Calculate");
gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(frame), PANEL_SPACING);
vbox = gtk_vbox_new(TRUE, PANEL_SPACING);
gtk_container_add(GTK_CONTAINER(frame), vbox);

/* --- menu items */
if (g_file_test(model->gulp.trj_file, G_FILE_TEST_EXISTS))
  {
  calc_list = g_list_prepend(calc_list, "Potential E");
  calc_list = g_list_prepend(calc_list, "Kinetic E");
  calc_list = g_list_prepend(calc_list, "Temperature");
  calc_list = g_list_prepend(calc_list, "VACF");
  }
else
  {
  calc_list = g_list_prepend(calc_list, "Measurements");
  }
calc_list = g_list_prepend(calc_list, "RDF");
calc_list = g_list_prepend(calc_list, "Pair count");
gui_menu_calc = gui_pulldown_new("Perform ", calc_list, FALSE, vbox);
dialog_child_set(dialog, "gui_menu_calc", gui_menu_calc);

/* --- right pane */
gui_vbox_rdf = gtk_vbox_new(FALSE, 0);
dialog_child_set(dialog, "gui_vbox_rdf", gui_vbox_rdf);
gtk_box_pack_start(GTK_BOX(main_hbox), gui_vbox_rdf, TRUE, TRUE, 0);

/* --- interval setup */
frame = gtk_frame_new("Analysis Interval");
gtk_box_pack_start(GTK_BOX(gui_vbox_rdf), frame, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(frame), PANEL_SPACING);
vbox = gtk_vbox_new(TRUE, PANEL_SPACING);
gtk_container_add(GTK_CONTAINER(frame), vbox);

/* TODO - some warning about the RDF being valid only for < L/2? */
/* see Allan & Tildesley pg 199 */
gui_direct_spin("Start", &analysis->start, 0.0, 10.0*model->rmax, 0.1, NULL, NULL, vbox);
gui_direct_spin("Stop", &analysis->stop, 0.1, 10.0*model->rmax, 0.1, NULL, NULL, vbox);
gui_direct_spin("Step", &analysis->step, 0.1, model->rmax, 0.1, NULL, NULL, vbox);

/* --- RDF atom setup */
frame = gtk_frame_new("Analysis Atoms");
gtk_box_pack_start(GTK_BOX(gui_vbox_rdf), frame, FALSE, FALSE, 0);
gtk_container_set_border_width(GTK_CONTAINER(frame), PANEL_SPACING);
vbox = gtk_vbox_new(TRUE, PANEL_SPACING);
gtk_container_add(GTK_CONTAINER(frame), vbox);

/* setup unique element label list */
list = find_unique(LABEL, model);
match_list = g_list_append(match_list, "Any");
for (item=list ; item  ; item=g_slist_next(item))
  {
  match_list = g_list_append(match_list, item->data);
  }
g_slist_free(list);

/* match 1 */
combo = gtk_combo_new();
gtk_combo_set_popdown_strings(GTK_COMBO(combo), match_list);
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(combo)->entry), TRUE);
gtk_box_pack_start(GTK_BOX(vbox), combo, TRUE, TRUE, 0);
g_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
                 GTK_SIGNAL_FUNC(md_atom_changed), (gpointer) &analysis->atom1);

/* match 2 */
combo = gtk_combo_new();
gtk_combo_set_popdown_strings(GTK_COMBO(combo), match_list);
gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(combo)->entry), TRUE);
gtk_box_pack_start(GTK_BOX(vbox), combo, TRUE, TRUE, 0);
g_signal_connect(GTK_OBJECT(GTK_COMBO(combo)->entry), "changed",
                 GTK_SIGNAL_FUNC(md_atom_changed), (gpointer) &analysis->atom2);

/* terminating buttons */
gui_stock_button(GTK_STOCK_EXECUTE, exec_analysis_task, dialog,
                   GTK_DIALOG(window)->action_area);

gui_stock_button(GTK_STOCK_CLOSE, dialog_destroy, dialog,
                   GTK_DIALOG(window)->action_area);

gtk_widget_show_all(window);
}