1 /*This file is a part of luscus project*/
2 /*Licensed under the Academic Free License version 3.0*/
3 #include<gtk/gtk.h>
4 #include<string.h>
5 #include"luscus.h"
6 #include"gv.h"
7 #include"gv_functions.h"
8 #include"gv_gtk.h"
9 /*#include"gv_gtk_fragments.h"*/
10 #include "center16.xpm"
11 #include "icon_revert20.xpm"
12 
13 /*#define NONE 0
14 #define SPHERE 1
15 #define VECTOR 2
16 #define TRIANGLE 3
17 #define SURFACE 4
18 #define CELL 5
19 
20 typedef struct gtk_3d_description
21 {
22   GtkWidget *button;
23   char i3dtype;
24   int inum;
25 } GTK_3D_DESC;*/
26 
27 int n_calc_defs;
28 DEF_CALC_T *calc_defs;
29 int n_fragments;
30 FRAG_DATA *frag;
31 GtkWidget **freq_buttons = NULL;
32 GtkWidget **freq_labels = NULL;
33 GtkWidget ***calc_keys = NULL;
34 int n_vibs = 0;
35 int n_3D_desc = 0;
36 GTK_3D_DESC *gtk_3d_desc = NULL;
37 
38 static gboolean luscus_gtk_find_selected_orbital(gint, gint);
39 
40 
41 char *bond_description[NUM_OF_BONDS] =
42 {
43   "No bond",
44   "Single bond",
45   "double bond",
46   "triple bond",
47   "partial bond",
48   "One and half bond",
49   "Line"
50 };
51 
52 char *orbital_description_short[] =
53 {
54   "u", "f", "i", "1", "2", "3", "s", "d"
55 };
56 
57 char *angle_description[NUM_OF_ANGLES] =
58 {
59   "60°",
60   "90°",
61   "109.47°",
62   "120°",
63   "180°"
64 };
65 
66 char *orbital_description[NUM_ORB_TYPES] =
67 {
68   "undefined",
69   "frozen",
70   "inactive",
71   "RAS 1",
72   "RAS 2",
73   "RAS 3",
74   "secondary",
75   "deleted"
76 };
77 
78 MOL *m;
79 INPUT_DATA Input_Data;
80 
81 GtkWidget *notebook = NULL;
82 
83 GtkWidget *vbox_watched;
84 int n_label_watched;
85 GtkWidget **labels_watched = NULL;
86 GtkWidget *vbox_vibration;
87 GtkWidget *vbox_edit;
88 GtkWidget *table_fragments;
89 GtkWidget *vbox_symmetry;
90 GtkWidget *vbox_draw;
91 GtkWidget *vbox_orbitals;
92 GtkWidget *vbox_calculation;
93 
94 GtkTreeIter *selected_orbital;
95 GtkListStore *store;
96 GtkTreeSelection *selection;
97 GtkWidget *treeview;
98 GtkWidget *geo_separator;
99 GtkWidget *geo_button;
100 GtkWidget *geo_play_button;
101 GtkWidget *geo_hbox;
102 GtkWidget *geo_slider;
103 GtkWidget *label_igeo;
104 GtkWidget *spin_bond;
105 GtkWidget *spin_angle;
106 GtkWidget *spin_tors;
107 /*GtkWidget *spin_play_speed;*/
108 GtkWidget *hbox_xyz, *spin_x, *spin_y, *spin_z;
109 GtkWidget *grid_expander;
110 GtkWidget *geo_expander;
111 GtkWidget *grid_frame_transp;
112 GtkWidget *grid_frame_isosurf;
113 GtkWidget *all_orbitals_button;
114 GtkWidget *epot_button;
115 /*GtkWidget *dens_diff_button;*/
116 GtkWidget *vib_spectrum_button;
117 GtkWidget *vbox_freqs;
118 GtkWidget *vbox_3Dobject;
119 
120 GtkWidget *combo_button;
121 
122 GtkWidget *button_add_atom;
123 GtkWidget *button_remove_atom;
124 GtkWidget *button_change_atom;
125 GtkWidget *button_undo;
126 
127 /*GtkWidget *label_bond_angle_torsion;
128 GtkWidget *label_unit;*/
129 GtkWidget *button_change_bond;
130 GtkWidget *button_change_angle;
131 GtkWidget *button_add_dummy;
132 GtkWidget *button_remove_selection;
133 GtkWidget *button_unmark;
134 GtkWidget *button_renumber;
135 GtkWidget *button_mark_H, *button_mark_reverse, *button_mark_element, *button_neighbor;
136 GtkWidget *button_watch;
137 GtkWidget *button_unwatch;
138 GtkWidget *button_symmetry;
139 GtkWidget *button_average_symm;
140 GtkWidget *button_trans_symm;
141 GtkWidget *button_inversion_symm;
142 GtkWidget *button_mirror_symm;
143 GtkWidget *spin_transl_vect;
144 GtkWidget *hbox_transl;
145 GtkWidget *button_c2;
146 GtkWidget *spin_axis;
147 GtkWidget *hbox_rot_axis;
148 
149 GtkWidget *button_arrow;
150 GtkWidget *button_sphere;
151 GtkWidget *button_plain;
152 GtkWidget *button_triangle;
153 GtkWidget *button_cell;
154 GtkWidget *button_clear_drawed;
155 
156 GtkWidget **button_custom_grid = NULL;
157 gint n_custom_grid = 0;
158 /*GtkWidget *element_dialog;*/
159 #ifdef GTK2
160   GtkObject *tranparency_level, *isosurface_level, *vibration_speed, *vibration_amplitude;
161   GtkObject *adj_bond;
162   GtkObject *adj_angle;
163   GtkObject *adj_tors;
164   GtkObject *translation_magnitude, *rotation_axis;
165   GtkObject *adj_geoms, *adj_play_speed;
166 #elif GTK3
167   GtkAdjustment *tranparency_level, *isosurface_level, *vibration_speed, *vibration_amplitude;
168   GtkAdjustment *adj_bond;
169   GtkAdjustment *adj_angle;
170   GtkAdjustment *adj_tors;
171   GtkAdjustment *translation_magnitude, *rotation_axis;
172   GtkAdjustment *adj_geoms, *adj_play_speed;
173 #endif
174 
175 
make_notebook(void)176 GtkWidget *make_notebook(void)
177 {
178   GtkWidget *vbox_outer, *hbox, *vbox_inner;
179   GtkWidget *label;
180   GtkWidget *scale;
181   GtkWidget *frame;
182   GtkWidget *table;
183   GtkWidget *button;
184   GtkWidget *icon;
185   GtkWidget *separator;
186   GtkWidget *scrolled_window;
187   GtkWidget *entry;
188   GtkWidget *expander;
189 
190 /*  GList *combo_list = NULL;*/
191 
192   GdkPixbuf *pixb;
193   gint i;
194   gint ix, iy;
195   gchar *textbuf;
196 
197 #ifdef GTK2
198   vbox_outer = gtk_vbox_new(FALSE, 0);
199 #endif
200 #ifdef GTK3
201   vbox_outer = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
202   gtk_box_set_homogeneous(GTK_BOX(vbox_outer), FALSE);
203 #endif
204 
205   notebook = gtk_notebook_new();
206   gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE);
207   gtk_box_pack_start(GTK_BOX(vbox_outer), notebook, TRUE, TRUE, 0);
208 
209   /*--------frequency--------*/
210 
211 #ifdef GTK2
212   vbox_vibration = gtk_vbox_new(FALSE, 0);
213 #endif
214 #ifdef GTK3
215   vbox_vibration = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
216   gtk_box_set_homogeneous(GTK_BOX(vbox_vibration), FALSE);
217 #endif
218   frame = gtk_frame_new("vibration speed");
219   gtk_box_pack_start(GTK_BOX(vbox_vibration), frame, FALSE, FALSE, 0);
220 
221   vibration_speed = gtk_adjustment_new(0.2, 0.F, 1.F, 0.01F, 0.1F, 0.F);
222   gtk_adjustment_set_value(GTK_ADJUSTMENT(vibration_speed), Input_Data.frequency_speed);
223   g_signal_connect(G_OBJECT(vibration_speed), "value-changed", G_CALLBACK(luscus_gtk_change_vibration_speed), NULL);
224 #ifdef GTK2
225   scale = gtk_hscale_new(GTK_ADJUSTMENT(vibration_speed));
226 #elif GTK3
227   scale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, vibration_speed);
228 #endif
229 
230   gtk_scale_set_digits(GTK_SCALE(scale), 2);
231   gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE);
232   gtk_container_add(GTK_CONTAINER(frame), scale);
233   gtk_widget_show(scale);
234 
235   gtk_widget_show(frame);
236 
237  /* amplitude */
238 
239   frame = gtk_frame_new("amplitude");
240   gtk_box_pack_start(GTK_BOX(vbox_vibration), frame, FALSE, FALSE, 0);
241 
242   vibration_amplitude = gtk_adjustment_new(0.F, 0.F, 2.F, 1.F, 1.F, 0.F);
243   gtk_adjustment_set_value(GTK_ADJUSTMENT(vibration_amplitude), Input_Data.frequency_amplitude);
244   g_signal_connect(G_OBJECT(vibration_amplitude), "value-changed", G_CALLBACK(luscus_gtk_change_vibration_amplitude), NULL);
245 #ifdef GTK2
246   scale = gtk_hscale_new(GTK_ADJUSTMENT(vibration_amplitude));
247 #elif GTK3
248   scale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, vibration_amplitude);
249 #endif
250   gtk_scale_set_digits(GTK_SCALE(scale), 0);
251   gtk_scale_set_draw_value(GTK_SCALE(scale), FALSE);
252   gtk_container_add(GTK_CONTAINER(frame), scale);
253   gtk_widget_show(scale);
254 
255   gtk_widget_show(frame);
256 
257   /*frequency buttons*/
258   scrolled_window = gtk_scrolled_window_new(NULL, NULL);
259   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
260   gtk_box_pack_start(GTK_BOX(vbox_vibration), scrolled_window, TRUE, TRUE, 0);
261 
262 #ifdef GTK2
263   vbox_freqs = gtk_vbox_new(FALSE, 0);
264 #endif
265 #ifdef GTK3
266   vbox_freqs = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
267   gtk_box_set_homogeneous(GTK_BOX(vbox_freqs), FALSE);
268 #endif
269   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox_freqs);
270 
271   gtk_widget_hide(vbox_freqs);
272   gtk_widget_show(scrolled_window);
273 
274   vib_spectrum_button = gtk_button_new_with_label("vibrational spectrum");
275   gtk_box_pack_start(GTK_BOX(vbox_vibration), vib_spectrum_button, FALSE, FALSE, 5);
276   g_signal_connect(G_OBJECT(vib_spectrum_button), "clicked", G_CALLBACK(luscus_gtk_show_vib_spectrum), NULL);
277   gtk_widget_hide(vib_spectrum_button);
278 
279   gtk_widget_hide(vbox_vibration);
280 
281   label = gtk_label_new("vibrations");
282   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_vibration, label);
283 
284   /*--------edit--------*/
285 
286 #ifdef GTK2
287   vbox_edit = gtk_vbox_new(FALSE, 0);
288 #endif
289 #ifdef GTK3
290   vbox_edit = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
291   gtk_box_set_homogeneous(GTK_BOX(vbox_edit), FALSE);
292 #endif
293 
294   label = gtk_label_new("edit molecule");
295   gtk_box_pack_start(GTK_BOX(vbox_edit), label, FALSE, FALSE, 0);
296   gtk_widget_show(label);
297 
298 #ifdef GTK2
299   hbox = gtk_hbox_new(TRUE, 0);
300 #endif
301 #ifdef GTK3
302   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
303   gtk_box_set_homogeneous(GTK_BOX(hbox), TRUE);
304 #endif
305   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
306 
307   button_add_atom = gtk_button_new_from_stock(GTK_STOCK_ADD);
308   gtk_widget_set_tooltip_text(GTK_WIDGET(button_add_atom), "Add an atom"); /*add bond*/
309   gtk_box_pack_start(GTK_BOX(hbox), button_add_atom, FALSE, FALSE, 0);
310   g_signal_connect(G_OBJECT(button_add_atom), "clicked", G_CALLBACK(luscus_gtk_add_fragment), NULL);
311   gtk_widget_show(button_add_atom);
312 
313   button_remove_atom = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
314   gtk_widget_set_tooltip_text(GTK_WIDGET(button_remove_atom), "delete atom"); /*delete bond*/
315   gtk_box_pack_start(GTK_BOX(hbox), button_remove_atom, FALSE, FALSE, 0);
316   gtk_widget_show(button_remove_atom);
317   g_signal_connect(G_OBJECT(button_remove_atom), "clicked", G_CALLBACK(luscus_gtk_remove_fragment), NULL);
318   gtk_widget_set_sensitive(GTK_WIDGET(button_remove_atom), FALSE);
319   gtk_widget_show(hbox);
320 
321   button_change_atom = gtk_button_new_with_label("Change");
322   gtk_box_pack_start(GTK_BOX(hbox), button_change_atom, FALSE, FALSE, 0);
323   g_signal_connect(G_OBJECT(button_change_atom), "clicked", G_CALLBACK(callback_change_atom), NULL);
324   gtk_widget_set_sensitive(GTK_WIDGET(button_change_atom), FALSE);
325   gtk_widget_show(button_change_atom);
326 
327   button_undo = gtk_button_new_from_stock(GTK_STOCK_UNDO);
328   gtk_widget_set_tooltip_text(GTK_WIDGET(button_undo), "Undo last action");
329   gtk_box_pack_start(GTK_BOX(hbox), button_undo, FALSE, FALSE, 0);
330   g_signal_connect(G_OBJECT(button_undo), "clicked", G_CALLBACK(callback_do_undo), NULL);
331   gtk_widget_show(button_undo);
332 
333   adj_bond = gtk_adjustment_new(0.000F, 0.F, 1000.F, 0.1F, 1.0F, 0.F);
334   adj_angle = gtk_adjustment_new(0.000F, 0.F, 180.F, 1.0F, 5.0F, 0.F);
335   adj_tors = gtk_adjustment_new(0.000F, -360.0F, 360.0F, 1.0F, 5.0F, 0.F);
336 
337 #ifdef GTK2
338   spin_bond = gtk_spin_button_new(GTK_ADJUSTMENT(adj_bond), 0.1, 2);
339   spin_angle = gtk_spin_button_new(GTK_ADJUSTMENT(adj_angle), 1.0, 2);
340   spin_tors = gtk_spin_button_new(GTK_ADJUSTMENT(adj_tors), 1.0, 2);
341 
342   hbox = gtk_hbox_new(FALSE, 0);
343 #elif GTK3
344   spin_bond = gtk_spin_button_new(adj_bond, 0.1, 2);
345   spin_angle = gtk_spin_button_new(adj_angle, 1.0, 2);
346   spin_tors = gtk_spin_button_new(adj_tors, 1.0, 2);
347 
348   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
349   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
350 #endif
351   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
352 
353   label = gtk_label_new("bond: ");
354   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
355   gtk_widget_show(label);
356 
357   g_signal_connect(G_OBJECT(spin_bond), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
358   g_signal_connect(G_OBJECT(spin_bond), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
359   g_signal_connect(G_OBJECT(spin_bond), "value-changed", G_CALLBACK(luscus_gtk_change_bond_value), NULL);
360 
361   gtk_box_pack_start(GTK_BOX(hbox), spin_bond, FALSE, FALSE, 0);
362   gtk_widget_set_sensitive(GTK_WIDGET(spin_bond), FALSE);
363   gtk_widget_show(spin_bond);
364 
365   label = gtk_label_new("\303\205");
366   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
367   gtk_widget_show(label);
368 
369   gtk_widget_show(hbox);
370 
371 #ifdef GTK2
372   hbox = gtk_hbox_new(FALSE, 0);
373 #endif
374 #ifdef GTK3
375   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
376   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
377 #endif
378   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
379 
380   label = gtk_label_new("angle: ");
381   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
382   gtk_widget_show(label);
383 
384   g_signal_connect(G_OBJECT(spin_angle), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
385   g_signal_connect(G_OBJECT(spin_angle), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
386   g_signal_connect(G_OBJECT(spin_angle), "value-changed", G_CALLBACK(luscus_gtk_change_angle_value), NULL);
387 
388 /*  g_signal_connect(G_OBJECT(spin_bond_ang_tor), "value-changed", G_CALLBACK(luscus_gtk_change_bond_angle_tors_value), NULL);*/
389 
390   gtk_box_pack_start(GTK_BOX(hbox), spin_angle, FALSE, FALSE, 0);
391   gtk_widget_set_sensitive(GTK_WIDGET(spin_angle), FALSE);
392   gtk_widget_show(spin_angle);
393 
394   label = gtk_label_new("\313\232");
395   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
396   gtk_widget_show(label);
397 
398   gtk_widget_show(hbox);
399 
400 #ifdef GTK2
401   hbox = gtk_hbox_new(FALSE, 0);
402 #endif
403 #ifdef GTK3
404   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
405   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
406 #endif
407   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
408 
409   label = gtk_label_new("dihedral: ");
410   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
411   gtk_widget_show(label);
412 
413   g_signal_connect(G_OBJECT(spin_tors), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
414   g_signal_connect(G_OBJECT(spin_tors), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
415   g_signal_connect(G_OBJECT(spin_tors), "value-changed", G_CALLBACK(luscus_gtk_change_tors_value), NULL);
416 
417 /*  g_signal_connect(G_OBJECT(spin_bond_ang_tor), "value-changed", G_CALLBACK(luscus_gtk_change_bond_angle_tors_value), NULL);*/
418 
419   gtk_box_pack_start(GTK_BOX(hbox), spin_tors, FALSE, FALSE, 0);
420   gtk_widget_set_sensitive(GTK_WIDGET(spin_tors), FALSE);
421   gtk_widget_show(spin_tors);
422 
423   label = gtk_label_new("\313\232");
424   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
425   gtk_widget_show(label);
426 
427   gtk_widget_show(hbox);
428 
429 #ifdef GTK2
430   hbox_xyz = gtk_hbox_new(FALSE, 0);
431 #endif
432 #ifdef GTK3
433   hbox_xyz = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
434   gtk_box_set_homogeneous(GTK_BOX(hbox_xyz), FALSE);
435 #endif
436   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox_xyz, FALSE, FALSE, 0);
437 
438   label = gtk_label_new("x:");
439   gtk_box_pack_start(GTK_BOX(hbox_xyz), label, FALSE, FALSE, 0);
440   gtk_widget_show(label);
441 
442   spin_x = gtk_spin_button_new_with_range(-999.0, 999.0, 0.01);
443   gtk_spin_button_set_increments(GTK_SPIN_BUTTON(spin_x), 0.01, 0.1);
444   gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin_x), 3);
445   gtk_box_pack_start(GTK_BOX(hbox_xyz), spin_x, FALSE, FALSE, 0);
446   g_signal_connect(G_OBJECT(spin_x), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
447   g_signal_connect(G_OBJECT(spin_x), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
448   g_signal_connect(G_OBJECT(spin_x), "value-changed", G_CALLBACK(luscus_gtk_change_xyz_coordinate), GINT_TO_POINTER(0));
449   gtk_widget_show(spin_x);
450 
451   label = gtk_label_new("y:");
452   gtk_box_pack_start(GTK_BOX(hbox_xyz), label, FALSE, FALSE, 0);
453   gtk_widget_show(label);
454 
455   spin_y = gtk_spin_button_new_with_range(-999.0, 999.0, 0.01);
456   gtk_spin_button_set_increments(GTK_SPIN_BUTTON(spin_x), 0.01, 0.1);
457   gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin_y), 3);
458   gtk_box_pack_start(GTK_BOX(hbox_xyz), spin_y, FALSE, FALSE, 0);
459   g_signal_connect(G_OBJECT(spin_y), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
460   g_signal_connect(G_OBJECT(spin_y), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
461   g_signal_connect(G_OBJECT(spin_y), "value-changed", G_CALLBACK(luscus_gtk_change_xyz_coordinate), GINT_TO_POINTER(1));
462   gtk_widget_show(spin_y);
463 
464   label = gtk_label_new("z:");
465   gtk_box_pack_start(GTK_BOX(hbox_xyz), label, FALSE, FALSE, 0);
466   gtk_widget_show(label);
467 
468   spin_z = gtk_spin_button_new_with_range(-999.0, 999.0, 0.01);
469   gtk_spin_button_set_increments(GTK_SPIN_BUTTON(spin_x), 0.01, 0.1);
470   gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin_z), 3);
471   gtk_box_pack_start(GTK_BOX(hbox_xyz), spin_z, FALSE, FALSE, 0);
472   g_signal_connect(G_OBJECT(spin_z), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
473   g_signal_connect(G_OBJECT(spin_z), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
474   g_signal_connect(G_OBJECT(spin_z), "value-changed", G_CALLBACK(luscus_gtk_change_xyz_coordinate), GINT_TO_POINTER(2));
475   gtk_widget_show(spin_z);
476 
477   gtk_widget_hide(hbox_xyz);
478 
479 #ifdef GTK_OLD
480   button_change_bond = gtk_combo_box_new_text();
481   for(i = 0; i < NUM_OF_BONDS; i++)
482     gtk_combo_box_append_text(GTK_COMBO_BOX(button_change_bond), bond_description[i]);
483 #else
484   button_change_bond = gtk_combo_box_text_new();
485   for(i = 0; i < NUM_OF_BONDS; i++)
486     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(button_change_bond), bond_description[i]);
487 #endif
488   g_signal_connect(G_OBJECT(button_change_bond), "changed", G_CALLBACK(luscus_gtk_change_bond_callback), NULL);
489   gtk_box_pack_start(GTK_BOX(vbox_edit), button_change_bond, FALSE, FALSE, 0);
490   gtk_widget_hide(button_change_bond);
491 
492 #ifdef GTK_OLD
493   button_change_angle = gtk_combo_box_new_text();
494   for(i = 0; i < NUM_OF_ANGLES; i++)
495     gtk_combo_box_append_text(GTK_COMBO_BOX(button_change_angle), angle_description[i]);
496   gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_angle), -1);
497 #else
498   button_change_angle = gtk_combo_box_text_new();
499   for(i = 0; i < NUM_OF_ANGLES; i++)
500     gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(button_change_angle), angle_description[i]);
501   gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_angle), -1);
502 #endif
503   g_signal_connect(G_OBJECT(button_change_angle), "changed", G_CALLBACK(luscus_gtk_change_angle_callback), NULL);
504   gtk_box_pack_start(GTK_BOX(vbox_edit), button_change_angle, FALSE, FALSE, 0);
505   gtk_widget_hide(button_change_angle);
506 
507 #ifdef GTK2
508   separator = gtk_hseparator_new();
509 #endif
510 #ifdef GTK3
511   separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
512 #endif
513 
514   gtk_box_pack_start(GTK_BOX(vbox_edit), separator, FALSE, FALSE, 5);
515   gtk_widget_show(separator);
516 
517   button_remove_selection = gtk_button_new_with_label("unselect");
518   gtk_widget_set_tooltip_text(GTK_WIDGET(button_remove_selection), "add dummy atoms (reference points) on the direction of axis");
519   gtk_box_pack_start(GTK_BOX(vbox_edit), button_remove_selection, FALSE, FALSE, 0);
520   gtk_widget_set_sensitive(GTK_WIDGET(button_remove_atom), FALSE);
521   g_signal_connect(G_OBJECT(button_remove_selection), "clicked", G_CALLBACK(luscus_gtk_remove_selection), NULL);
522   gtk_widget_show(button_remove_selection);
523 
524 #ifdef GTK2
525   separator = gtk_hseparator_new();
526 #endif
527 #ifdef GTK3
528   separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
529 #endif
530   gtk_box_pack_start(GTK_BOX(vbox_edit), separator, FALSE, FALSE, 5);
531   gtk_widget_show(separator);
532 
533   label = gtk_label_new("mark atoms");
534   gtk_box_pack_start(GTK_BOX(vbox_edit), label, FALSE, FALSE, 0);
535   gtk_widget_show(label);
536 
537 #ifdef GTK2
538   hbox = gtk_hbox_new(TRUE, 0);
539 #endif
540 #ifdef GTK3
541   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
542   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
543 #endif
544   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
545 
546   icon = gtk_image_new_from_stock(GTK_STOCK_CLEAR, GTK_ICON_SIZE_BUTTON);
547   button_unmark = gtk_button_new();
548   gtk_button_set_image(GTK_BUTTON(button_unmark), icon);
549   gtk_widget_set_tooltip_text(GTK_WIDGET(button_unmark), "unmark all marked atoms");
550   gtk_box_pack_start(GTK_BOX(hbox), button_unmark, TRUE, FALSE, 0);
551   g_signal_connect(G_OBJECT(button_unmark), "clicked", G_CALLBACK(luscus_gtk_unmark), NULL);
552   gtk_widget_set_sensitive(GTK_WIDGET(button_unmark), FALSE);
553   gtk_widget_show(button_unmark);
554 
555   icon = gtk_image_new_from_stock(GTK_STOCK_SORT_ASCENDING, GTK_ICON_SIZE_BUTTON);
556   button_renumber = gtk_button_new();
557   gtk_button_set_image(GTK_BUTTON(button_renumber), icon);
558   gtk_widget_set_tooltip_text(GTK_WIDGET(button_renumber), "renumber atoms and put marked atoms first");
559   gtk_box_pack_start(GTK_BOX(hbox), button_renumber, TRUE, FALSE, 0);
560   g_signal_connect(G_OBJECT(button_renumber), "clicked", G_CALLBACK(luscus_gtk_sort_mark), NULL);
561   gtk_widget_set_sensitive(GTK_WIDGET(button_renumber), FALSE);
562   gtk_widget_show(button_renumber);
563 
564   textbuf = g_markup_escape_text("<span size=xx-large>H</span>", -1); /* g_markup_printf_escaped("<>H<>");*/
565   label = gtk_label_new(NULL);
566   gtk_label_set_markup(GTK_LABEL(label), textbuf);
567   g_free(textbuf);
568 
569   button_mark_H = gtk_button_new_with_label("H");
570   gtk_widget_set_tooltip_text(GTK_WIDGET(button_mark_H), "Mark hydrogen atoms in the molecule ");
571   gtk_box_pack_start(GTK_BOX(hbox), button_mark_H, TRUE, FALSE, 0);
572   g_signal_connect(G_OBJECT(button_mark_H), "clicked", G_CALLBACK(luscus_gtk_mark_H_atoms), NULL);
573   gtk_widget_set_sensitive(GTK_WIDGET(button_mark_H), TRUE);
574   gtk_widget_show(button_mark_H);
575   gtk_widget_show(label);
576 
577   pixb = gdk_pixbuf_new_from_xpm_data(icon_revert_xpm);
578   icon = gtk_image_new_from_pixbuf(pixb);
579   button_mark_reverse = gtk_button_new();
580   gtk_container_add(GTK_CONTAINER(button_mark_reverse), icon);
581 /*  button_mark_reverse = gtk_button_new_with_label("reverse");*/
582   gtk_widget_set_tooltip_text(GTK_WIDGET(button_mark_reverse), "Reverse marked atoms");
583   gtk_box_pack_start(GTK_BOX(hbox), button_mark_reverse, TRUE, FALSE, 0);
584   g_signal_connect(G_OBJECT(button_mark_reverse), "clicked", G_CALLBACK(luscus_gtk_mark_reverse), NULL);
585   gtk_widget_set_sensitive(GTK_WIDGET(button_mark_reverse), TRUE);
586   gtk_widget_show(button_mark_reverse);
587   gtk_widget_show(icon);
588 
589   icon = gtk_image_new_from_stock(GTK_STOCK_SELECT_ALL, GTK_ICON_SIZE_BUTTON);
590   button_mark_element = gtk_button_new();
591   gtk_button_set_image(GTK_BUTTON(button_mark_element), icon);
592 /*  button_mark_element = gtk_button_new_with_label("mark element");*/
593   gtk_widget_set_tooltip_text(GTK_WIDGET(button_mark_element), "Mark all atoms which are the same element as selected atom");
594   gtk_box_pack_start(GTK_BOX(hbox), button_mark_element, TRUE, FALSE, 0);
595   g_signal_connect(G_OBJECT(button_mark_element), "clicked", G_CALLBACK(luscus_gtk_mark_element), NULL);
596   gtk_widget_set_sensitive(GTK_WIDGET(button_mark_element), FALSE);
597   gtk_widget_show(button_mark_element);
598 
599   button_neighbor = gtk_button_new_with_label("\342\212\266");
600   gtk_widget_set_tooltip_text(GTK_WIDGET(button_neighbor), "Mark atoms bonded to the selected atom");
601   gtk_box_pack_start(GTK_BOX(hbox), button_neighbor, TRUE, FALSE, 0);
602   g_signal_connect(G_OBJECT(button_neighbor), "clicked", G_CALLBACK(luscus_gtk_mark_neighbor), NULL);
603   gtk_widget_set_sensitive(GTK_WIDGET(button_neighbor), FALSE);
604   gtk_widget_show(button_neighbor);
605 
606   gtk_widget_show(hbox);
607 
608 #ifdef GTK2
609   separator = gtk_hseparator_new();
610 #endif
611 #ifdef GTK3
612   separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
613 #endif
614   gtk_box_pack_start(GTK_BOX(vbox_edit), separator, FALSE, FALSE, 5);
615   gtk_widget_show(separator);
616 
617   label = gtk_label_new("watch values");
618   gtk_box_pack_start(GTK_BOX(vbox_edit), label, FALSE, FALSE, 0);
619   gtk_widget_show(label);
620 
621 #ifdef GTK2
622   hbox = gtk_hbox_new(TRUE, 0);
623 #endif
624 #ifdef GTK3
625   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
626   gtk_box_set_homogeneous(GTK_BOX(hbox), TRUE);
627 #endif
628   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
629 
630   button_watch = gtk_button_new_from_stock(GTK_STOCK_ADD);
631   gtk_widget_set_tooltip_text(GTK_WIDGET(button_watch), "Watch the value of the bond/angle/torsion");
632   gtk_box_pack_start(GTK_BOX(hbox), button_watch, FALSE, FALSE, 0);
633   g_signal_connect(G_OBJECT(button_watch), "clicked", G_CALLBACK(luscus_gtk_watch_value), NULL);
634   gtk_widget_set_sensitive(GTK_WIDGET(button_watch), FALSE);
635   gtk_widget_show(button_watch);
636 
637   button_unwatch = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
638   gtk_widget_set_tooltip_text(GTK_WIDGET(button_unwatch), "Remove all watched values");
639   gtk_box_pack_start(GTK_BOX(hbox), button_unwatch, FALSE, FALSE, 0);
640   g_signal_connect(G_OBJECT(button_unwatch), "clicked", G_CALLBACK(luscus_gtk_unwatch_values), NULL);
641   gtk_widget_set_sensitive(GTK_WIDGET(button_unwatch), FALSE);
642   gtk_widget_show(button_unwatch);
643 
644   gtk_widget_show(hbox);
645 
646 #ifdef GTK2
647   separator = gtk_hseparator_new();
648 #endif
649 #ifdef GTK3
650   separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
651 #endif
652   gtk_box_pack_start(GTK_BOX(vbox_edit), separator, FALSE, FALSE, 5);
653   gtk_widget_show(separator);
654 
655   label = gtk_label_new("dummy atoms");
656   gtk_box_pack_start(GTK_BOX(vbox_edit), label, FALSE, FALSE, 0);
657   gtk_widget_show(label);
658 
659 #ifdef GTK2
660   hbox = gtk_hbox_new(FALSE, 0);
661 #endif
662 #ifdef GTK3
663   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
664   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
665 #endif
666   gtk_box_pack_start(GTK_BOX(vbox_edit), hbox, FALSE, FALSE, 0);
667 
668   button_add_dummy = gtk_button_new_from_stock(GTK_STOCK_ADD);
669   gtk_widget_set_tooltip_text(GTK_WIDGET(button_add_dummy), "add dummy atoms");
670   gtk_box_pack_start(GTK_BOX(hbox), button_add_dummy, TRUE, FALSE, 0);
671   g_signal_connect(G_OBJECT(button_add_dummy), "clicked", G_CALLBACK(luscus_gtk_add_dummy_atoms), NULL);
672   gtk_widget_show(button_add_dummy);
673 
674   button = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
675   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "remove dummy atoms");
676   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
677   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_remove_dummy_atoms), NULL);
678   gtk_widget_show(button);
679 
680   gtk_widget_show(hbox);
681 
682   gtk_widget_show(vbox_edit);
683   label = gtk_label_new("edit");
684   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_edit, label);
685 
686   /*-------Fragments-------*/
687 
688   table_fragments = gtk_table_new(5, 4, TRUE);
689 
690   for (i=0; i < n_fragments; i++)
691   {
692     ix = i%4;
693     iy = (i - ix)/4;
694 
695     button = gtk_button_new();
696 /*    pix = gdk_pixbuf_new_from_xpm_data(a_xpms[i]);*/
697 /*    icon = gtk_image_new_from_pixbuf(pix);*/
698 #ifdef WINDOWS
699     textbuf = g_strconcat(rcdir, "\\", frag[i].image_file_name, NULL);
700 #else
701     textbuf = g_strconcat(rcdir, "/", frag[i].image_file_name, NULL);
702 #endif
703     icon = gtk_image_new_from_file(textbuf);
704     g_free(textbuf);
705     gtk_container_add(GTK_CONTAINER(button), icon);
706     gtk_table_attach(GTK_TABLE(table_fragments), button, ix, ix+1, iy, iy+1, GTK_FILL, GTK_FILL, 1, 1);
707 
708     g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_select_fragment), GINT_TO_POINTER(i));
709     gtk_widget_show(button);
710     gtk_widget_show(icon);
711   }
712 
713   gtk_widget_show(table_fragments);
714   label = gtk_label_new("fragments");
715   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), table_fragments, label);
716   gtk_widget_show(table_fragments);
717 
718    /*symmetry*/
719 
720 #ifdef GTK2
721   vbox_symmetry = gtk_vbox_new(FALSE, 0);
722 #endif
723 #ifdef GTK3
724   vbox_symmetry = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
725   gtk_box_set_homogeneous(GTK_BOX(vbox_symmetry), FALSE);
726 #endif
727 
728 #ifdef HAS_MSYM
729   /*here goes MSYM stuff*/
730 #else
731   button_symmetry = gtk_button_new_with_label("Symmetry"); /*inversion*/
732   gtk_widget_set_tooltip_text(GTK_WIDGET(button_symmetry), "analyze the symmetry of the molecule and display symmetry elements");
733   gtk_box_pack_start(GTK_BOX(vbox_symmetry), button_symmetry, FALSE, FALSE, 0);
734   g_signal_connect(G_OBJECT(button_symmetry), "clicked", G_CALLBACK(luscus_gtk_alpply_symmetry), NULL);
735 /*  gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);*/
736   gtk_widget_show(button_symmetry);
737 
738   button_average_symm = gtk_button_new_with_label("Average symmetry");
739   gtk_box_pack_start(GTK_BOX(vbox_symmetry), button_average_symm, FALSE, FALSE, 0);
740   g_signal_connect(G_OBJECT(button_average_symm), "clicked", G_CALLBACK(luscus_gtk_force_symmetry), NULL);
741 /*  gtk_widget_set_sensitive(GTK_WIDGET(button_average_symm), FALSE);*/
742   gtk_widget_show(button_average_symm);
743 #endif
744 
745   button_inversion_symm = gtk_button_new_with_label("apply inversion symmetry");
746   gtk_box_pack_start(GTK_BOX(vbox_symmetry), button_inversion_symm, FALSE, FALSE, 0);
747   g_signal_connect(G_OBJECT(button_inversion_symm), "clicked", G_CALLBACK(luscus_gtk_alpply_symmetry), NULL);
748   gtk_widget_set_sensitive(GTK_WIDGET(button_inversion_symm), FALSE);
749   gtk_widget_show(button_inversion_symm);
750 
751 #ifdef GTK2
752   hbox_transl = gtk_hbox_new(FALSE, 0);
753 #endif
754 #ifdef GTK3
755   hbox_transl = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
756   gtk_box_set_homogeneous(GTK_BOX(hbox_transl), FALSE);
757 #endif
758   gtk_box_pack_start(GTK_BOX(vbox_symmetry), hbox_transl, FALSE, FALSE, 0);
759 
760   button_trans_symm = gtk_button_new_with_label("apply translation");
761   gtk_widget_set_tooltip_text(GTK_WIDGET(button_trans_symm), "Translate molecule in the direction of selected atoms");
762   gtk_box_pack_start(GTK_BOX(hbox_transl), button_trans_symm, FALSE, FALSE, 0);
763   g_signal_connect(G_OBJECT(button_trans_symm), "clicked", G_CALLBACK(luscus_gtk_apply_translation), NULL);
764   gtk_widget_set_sensitive(GTK_WIDGET(button_trans_symm), FALSE);
765   gtk_widget_show(button_trans_symm);
766 
767   label = gtk_label_new(" r=");
768   gtk_box_pack_start(GTK_BOX(hbox_transl), label, FALSE, FALSE, 0);
769   gtk_widget_show(label);
770 
771   translation_magnitude = gtk_adjustment_new(0.F, 0.F, 100.F, 1.F, 1.F, 0.F);
772 #ifdef GTK2
773   spin_transl_vect = gtk_spin_button_new(GTK_ADJUSTMENT(translation_magnitude), 0.01, 2);
774 #elif GTK3
775   spin_transl_vect = gtk_spin_button_new(translation_magnitude, 0.01, 2);
776 #endif
777   gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin_transl_vect), 2);
778   g_signal_connect(G_OBJECT(spin_transl_vect), "value-changed", G_CALLBACK(change_translation_magnitude), NULL);
779   g_signal_connect(G_OBJECT(spin_transl_vect), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
780   g_signal_connect(G_OBJECT(spin_transl_vect), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
781   gtk_box_pack_start(GTK_BOX(hbox_transl), spin_transl_vect, FALSE, FALSE, 0);
782   gtk_widget_set_sensitive(GTK_WIDGET(spin_transl_vect), FALSE);
783   gtk_widget_show(spin_transl_vect);
784 
785   gtk_widget_show(hbox_transl);
786 
787 #ifdef GTK2
788   hbox_rot_axis = gtk_hbox_new(FALSE, 0);
789 #endif
790 #ifdef GTK3
791   hbox_rot_axis = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
792   gtk_box_set_homogeneous(GTK_BOX(hbox_transl), FALSE);
793 #endif
794   gtk_box_pack_start(GTK_BOX(vbox_symmetry), hbox_rot_axis, FALSE, FALSE, 0);
795 
796   button_c2 = gtk_button_new_with_label("apply Cn symmetry");
797   gtk_widget_set_tooltip_text(GTK_WIDGET(button_c2), "apply Cn symmetry operation around axis defined by selected atoms");
798   gtk_box_pack_start(GTK_BOX(hbox_rot_axis), button_c2, FALSE, FALSE, 0);
799   g_signal_connect(G_OBJECT(button_c2), "clicked", G_CALLBACK(luscus_gtk_alpply_rot_symmetry), NULL);
800   gtk_widget_set_sensitive(GTK_WIDGET(button_c2), FALSE);
801   gtk_widget_show(button_c2);
802 
803   label = gtk_label_new(" n=");
804   gtk_box_pack_start(GTK_BOX(hbox_rot_axis), label, FALSE, FALSE, 0);
805   gtk_widget_show(label);
806 
807   rotation_axis = gtk_adjustment_new(2.F, 2.F, 100.F, 1.F, 1.F, 0.F);
808 #ifdef GTK2
809   spin_axis = gtk_spin_button_new(GTK_ADJUSTMENT(rotation_axis), 0.01, 2);
810 #elif GTK3
811   spin_axis = gtk_spin_button_new(rotation_axis, 0.01, 2);
812 #endif
813   gtk_spin_button_set_digits(GTK_SPIN_BUTTON(spin_axis), 0);
814   g_signal_connect(G_OBJECT(spin_axis), "value-changed", G_CALLBACK(change_rotation_axis_order), NULL);
815   g_signal_connect(G_OBJECT(spin_axis), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
816   g_signal_connect(G_OBJECT(spin_axis), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
817   gtk_box_pack_start(GTK_BOX(hbox_rot_axis), spin_axis, FALSE, FALSE, 0);
818   gtk_widget_set_sensitive(GTK_WIDGET(spin_axis), FALSE);
819   gtk_widget_show(spin_axis);
820 
821   gtk_widget_show(hbox_rot_axis);
822 
823   button_mirror_symm = gtk_button_new_with_label("apply mirror symmetry");
824   gtk_box_pack_start(GTK_BOX(vbox_symmetry), button_mirror_symm, FALSE, FALSE, 0);
825   g_signal_connect(G_OBJECT(button_mirror_symm), "clicked", G_CALLBACK(luscus_gtk_alpply_symmetry), NULL);
826   gtk_widget_set_sensitive(GTK_WIDGET(button_mirror_symm), FALSE);
827   gtk_widget_show(button_mirror_symm);
828 
829   label = gtk_label_new("Symmetry");
830   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_symmetry, label);
831   gtk_widget_show(vbox_symmetry);
832 
833   /*objects*/
834 
835 #ifdef GTK2
836   vbox_draw = gtk_vbox_new(FALSE, 0);
837 #endif
838 #ifdef GTK3
839   vbox_draw = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
840   gtk_box_set_homogeneous(GTK_BOX(vbox_draw), FALSE);
841 #endif
842 
843   button_arrow = gtk_button_new_with_label("draw arrow");
844   gtk_box_pack_start(GTK_BOX(vbox_draw), button_arrow, FALSE, FALSE, 0);
845   g_signal_connect(G_OBJECT(button_arrow), "clicked", G_CALLBACK(luscus_add_arrow), NULL);
846   gtk_widget_set_tooltip_text(GTK_WIDGET(button_arrow), "select two atoms that define vector");
847   gtk_widget_set_sensitive(GTK_WIDGET(button_arrow), FALSE);
848   gtk_widget_show(button_arrow);
849 
850   button_sphere = gtk_button_new_with_label("draw sphere");
851   gtk_box_pack_start(GTK_BOX(vbox_draw), button_sphere, FALSE, FALSE, 0);
852   g_signal_connect(G_OBJECT(button_sphere), "clicked", G_CALLBACK(luscus_add_sphere), NULL);
853   gtk_widget_set_tooltip_text(GTK_WIDGET(button_sphere), "select atom that defines center of sphere");
854   gtk_widget_set_sensitive(GTK_WIDGET(button_sphere), FALSE);
855   gtk_widget_show(button_sphere);
856 
857   button_plain = gtk_button_new_with_label("draw plain");
858   gtk_box_pack_start(GTK_BOX(vbox_draw), button_plain, FALSE, FALSE, 0);
859   g_signal_connect(G_OBJECT(button_plain), "clicked", G_CALLBACK(luscus_add_plain), NULL);
860   gtk_widget_set_tooltip_text(GTK_WIDGET(button_plain), "select three atoms that define plain");
861   gtk_widget_set_sensitive(GTK_WIDGET(button_plain), FALSE);
862   gtk_widget_show(button_plain);
863 
864   button_triangle = gtk_button_new_with_label("draw triangle");
865   gtk_box_pack_start(GTK_BOX(vbox_draw), button_triangle, FALSE, FALSE, 0);
866   g_signal_connect(G_OBJECT(button_triangle), "clicked", G_CALLBACK(luscus_add_triangle), NULL);
867   gtk_widget_set_tooltip_text(GTK_WIDGET(button_triangle), "select three atoms that define triangle");
868   gtk_widget_set_sensitive(GTK_WIDGET(button_triangle), FALSE);
869   gtk_widget_show(button_triangle);
870 
871   button_cell = gtk_button_new_with_label("draw cell");
872   gtk_box_pack_start(GTK_BOX(vbox_draw), button_cell, FALSE, FALSE, 0);
873   g_signal_connect(G_OBJECT(button_cell), "clicked", G_CALLBACK(luscus_add_cell), NULL);
874   gtk_widget_set_tooltip_text(GTK_WIDGET(button_cell), "select four atoms that define a cell");
875   gtk_widget_set_sensitive(GTK_WIDGET(button_cell), FALSE);
876   gtk_widget_show(button_cell);
877 
878   button = gtk_button_new_with_label("insert text");
879   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_insert_textbox), NULL);
880   gtk_box_pack_start(GTK_BOX(vbox_draw), button, FALSE, FALSE, 0);
881   gtk_widget_show(button);
882 
883 #ifdef GTK2
884   separator = gtk_hseparator_new();
885 #endif
886 #ifdef GTK3
887   separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
888 #endif
889   gtk_box_pack_start(GTK_BOX(vbox_draw), separator, FALSE, FALSE, 5);
890   gtk_widget_show(separator);
891 
892   button_clear_drawed = gtk_button_new_from_stock(GTK_STOCK_CLEAR);
893   gtk_box_pack_start(GTK_BOX(vbox_draw), button_clear_drawed, FALSE, FALSE, 0);
894   g_signal_connect(GTK_WIDGET(button_clear_drawed), "clicked", G_CALLBACK(luscus_clear_drawings), NULL);
895   gtk_widget_set_tooltip_text(GTK_WIDGET(button_clear_drawed), "Clear all vectors, spheres, triangles, plains and cells");
896   gtk_widget_set_sensitive(GTK_WIDGET(button_clear_drawed), FALSE);
897   gtk_widget_show(button_clear_drawed);
898 
899 #ifdef GTK2
900   separator = gtk_hseparator_new();
901 #endif
902 #ifdef GTK3
903   separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
904 #endif
905   gtk_box_pack_start(GTK_BOX(vbox_draw), separator, FALSE, FALSE, 5);
906   gtk_widget_show(separator);
907 
908   scrolled_window = gtk_scrolled_window_new(NULL, NULL);
909   gtk_box_pack_start(GTK_BOX(vbox_draw), scrolled_window, TRUE, TRUE, 0);
910 #ifdef GTK2
911   vbox_3Dobject = gtk_vbox_new(FALSE, 0);
912 #endif
913 #ifdef GTK3
914   vbox_3Dobject = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
915   gtk_box_set_homogeneous(GTK_BOX(vbox_3Dobject), FALSE);
916 #endif
917   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox_3Dobject);
918   gtk_widget_show(vbox_3Dobject);
919   gtk_widget_show(scrolled_window);
920 
921   /*color_button, transparency, radius, */
922 
923   label = gtk_label_new("draw");
924   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_draw, label);
925   gtk_widget_show(vbox_draw);
926 
927   /*--------grid--------*/
928 
929 #ifdef GTK2
930   vbox_orbitals = gtk_vbox_new(FALSE, 0);
931 #endif
932 #ifdef GTK3
933   vbox_orbitals = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
934   gtk_box_set_homogeneous(GTK_BOX(vbox_orbitals), FALSE);
935 #endif
936 
937   /*orbitals*/
938 
939   label = gtk_label_new("orbitals");
940   gtk_widget_show(vbox_orbitals);
941   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_orbitals, label);
942 
943   /* treeview */
944 
945   scrolled_window = gtk_scrolled_window_new(NULL, NULL);
946   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
947   gtk_box_pack_start(GTK_BOX(vbox_orbitals), scrolled_window, TRUE, TRUE, 0);
948 
949   treeview = luscus_gtk_make_treeview();
950   gtk_container_add(GTK_CONTAINER(scrolled_window), treeview);
951   gtk_widget_show(treeview);
952 
953   gtk_widget_show(scrolled_window);
954 
955 #ifdef GTK2
956   hbox = gtk_hbox_new(TRUE, 0);
957 #endif
958 #ifdef GTK3
959   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
960   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
961 #endif
962   gtk_box_pack_start(GTK_BOX(vbox_orbitals), hbox, FALSE, FALSE, 0);
963 
964   button = gtk_button_new_from_stock(GTK_STOCK_DELETE);
965   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
966   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(delete_orbital_from_list), NULL);
967   gtk_widget_show(button);
968 
969   button = gtk_button_new_from_stock(GTK_STOCK_UNDELETE);
970   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
971   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(undelete_all_orbitals_from_list), NULL);
972   gtk_widget_show(button);
973 
974 /*  button = gtk_button_new_with_label("show density");
975   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
976   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(show_density_callback), NULL);
977   gtk_widget_show(button);*/
978 
979   gtk_widget_show(hbox);
980 
981 #ifdef GTK2
982   hbox = gtk_hbox_new(FALSE, 0);
983 #endif
984 #ifdef GTK3
985   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
986   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
987 #endif
988   gtk_box_pack_start(GTK_BOX(vbox_orbitals), hbox, FALSE, FALSE, 0);
989 
990   label = gtk_label_new("filter");
991   gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
992   gtk_widget_show(label);
993 
994   entry = gtk_entry_new();
995   gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0);
996   g_signal_connect(G_OBJECT(entry), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
997   g_signal_connect(G_OBJECT(entry), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
998   g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(orbital_filter_callback), NULL);
999   gtk_widget_show(entry);
1000 
1001   gtk_widget_show(hbox);
1002 
1003   gtk_widget_hide(vbox_orbitals);
1004 
1005   /* -- calculations -- */
1006 
1007 
1008   if(n_calc_defs)
1009   {
1010     calc_keys = (GtkWidget***) g_malloc(n_calc_defs * sizeof(GtkWidget**));
1011 
1012 #ifdef GTK2
1013     vbox_calculation = gtk_vbox_new(FALSE, 0);
1014 #endif
1015 #ifdef GTK3
1016     vbox_calculation = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1017     gtk_box_set_homogeneous(GTK_BOX(vbox_calculation), FALSE);
1018 #endif
1019 
1020     for(i = 0; i < n_calc_defs; i++)
1021     {
1022       int j;
1023       GtkWidget **calc_wgs;
1024 
1025       if(calc_defs[i].file_description) calc_keys[i] = (GtkWidget**) g_malloc((calc_defs[i].nargs+1) * sizeof(GtkWidget*));
1026       else  calc_keys[i] = (GtkWidget**) g_malloc(calc_defs[i].nargs * sizeof(GtkWidget*));
1027       calc_wgs = calc_keys[i];
1028 
1029       expander = gtk_expander_new(calc_defs[i].description);
1030 
1031 #ifdef GTK3
1032       gtk_expander_set_resize_toplevel(GTK_EXPANDER(expander), TRUE);
1033 #endif
1034       gtk_expander_set_expanded(GTK_EXPANDER(expander), FALSE);
1035       gtk_box_pack_start(GTK_BOX(vbox_calculation), expander, TRUE, TRUE, 0);
1036 
1037       scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1038       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1039 
1040       gtk_container_add(GTK_CONTAINER(expander), scrolled_window);
1041 
1042 #ifdef GTK2
1043       vbox_inner = gtk_vbox_new(FALSE, 0);
1044 #endif
1045 #ifdef GTK3
1046       vbox_inner = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1047       gtk_box_set_homogeneous(GTK_BOX(vbox_inner), FALSE);
1048 #endif
1049       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox_inner);
1050 
1051       if(calc_defs[i].file_description)
1052       {
1053 #ifdef GTK2
1054         hbox = gtk_hbox_new(FALSE, 0);
1055 #endif
1056 #ifdef GTK3
1057         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1058         gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1059 #endif
1060         gtk_box_pack_start(GTK_BOX(vbox_inner), hbox, TRUE, FALSE, 0);
1061 
1062         label = gtk_label_new(calc_defs[i].file_description);
1063         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
1064         gtk_widget_show(label);
1065 
1066         calc_wgs[0] = gtk_file_chooser_button_new("compare density with this file", GTK_FILE_CHOOSER_ACTION_OPEN);
1067         gtk_box_pack_start(GTK_BOX(hbox), calc_wgs[0], TRUE, FALSE, 0);
1068         gtk_widget_show(calc_wgs[0]);
1069 
1070         gtk_widget_show(hbox);
1071       }
1072 
1073       for(j = 0; j < calc_defs[i].nargs; j++)
1074       {
1075 #ifdef GTK2
1076         hbox = gtk_hbox_new(FALSE, 0);
1077 #endif
1078 #ifdef GTK3
1079         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1080         gtk_box_set_homogeneous(GTK_BOX(hbox),vbox_inner TRUE);
1081 #endif
1082         gtk_box_pack_start(GTK_BOX(vbox_inner), hbox, TRUE, FALSE, 0);
1083 
1084         label = gtk_label_new(calc_defs[i].argdes[j]);
1085         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 2);
1086         gtk_widget_show(label);
1087 
1088         if(calc_defs[i].file_description)
1089         {
1090           calc_wgs[j+1] = gtk_entry_new();
1091           g_signal_connect(G_OBJECT(calc_wgs[j+1]), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
1092           g_signal_connect(G_OBJECT(calc_wgs[j+1]), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
1093           gtk_entry_set_text(GTK_ENTRY(calc_wgs[j+1]), calc_defs[i].argval[j]);
1094           gtk_editable_set_editable(GTK_EDITABLE(calc_wgs[j+1]), TRUE);
1095           gtk_box_pack_start(GTK_BOX(hbox), calc_wgs[j+1], TRUE, TRUE, 2);
1096           gtk_widget_show(calc_wgs[j+1]);
1097         }
1098         else
1099         {
1100           calc_wgs[j] = gtk_entry_new();
1101           g_signal_connect(G_OBJECT(calc_wgs[j]), "focus-in-event", G_CALLBACK(luscus_gtk_disable_keys), NULL);
1102           g_signal_connect(G_OBJECT(calc_wgs[j]), "focus-out-event", G_CALLBACK(luscus_gtk_enable_keys), NULL);
1103           gtk_entry_set_text(GTK_ENTRY(calc_wgs[j]), calc_defs[i].argval[j]);
1104           gtk_editable_set_editable(GTK_EDITABLE(calc_wgs[j]), TRUE);
1105           gtk_box_pack_start(GTK_BOX(hbox), calc_wgs[j], TRUE, TRUE, 2);
1106           gtk_widget_show(calc_wgs[j]);
1107         }
1108 
1109         gtk_widget_show(hbox);
1110       }
1111 
1112 #ifdef GTK2
1113       hbox = gtk_hbox_new(TRUE, 0);
1114 #endif
1115 #ifdef GTK3
1116       hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1117       gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1118 #endif
1119 
1120       button = gtk_button_new_from_stock(GTK_STOCK_EXECUTE);
1121       gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
1122 
1123     /* luscus_start_calculation(GtkWidget* menu, gint icalc)*/
1124 
1125       g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_start_calculation), GINT_TO_POINTER(i));
1126       gtk_widget_show(button);
1127 
1128       gtk_box_pack_end(GTK_BOX(vbox_inner), hbox, TRUE, FALSE, 0);
1129 
1130       gtk_widget_show(hbox);
1131 
1132       gtk_widget_show(vbox_inner);
1133       gtk_widget_show(scrolled_window);
1134       gtk_widget_show(expander);
1135     }
1136 
1137 
1138     label = gtk_label_new("calculation");
1139     gtk_widget_show(vbox_calculation);
1140     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox_calculation, label);
1141   }
1142   /* -- calculation end -- */
1143 
1144 
1145   /*general*/
1146 
1147 /*  vbox = gtk_vbox_new(FALSE, 0);*/
1148 
1149   expander = gtk_expander_new("zoom/translation");
1150   gtk_expander_set_expanded(GTK_EXPANDER(expander), FALSE);
1151   gtk_box_pack_start(GTK_BOX(vbox_outer), expander, FALSE, FALSE, 0);
1152   gtk_widget_show(expander);
1153 
1154 #ifdef GTK2
1155   vbox_inner = gtk_vbox_new(FALSE, 0);
1156 #endif
1157 #ifdef GTK3
1158   vbox_inner = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1159   gtk_box_set_homogeneous(GTK_BOX(vbox_inner), FALSE);
1160 #endif
1161   gtk_container_add(GTK_CONTAINER(expander), vbox_inner);
1162 
1163 #ifdef GTK_OLD
1164   combo_button = gtk_combo_box_new_text();
1165   gtk_combo_box_append_text(GTK_COMBO_BOX(combo_button), "Move molecule");
1166   gtk_combo_box_append_text(GTK_COMBO_BOX(combo_button), "Move camera");
1167 #else
1168   combo_button = gtk_combo_box_text_new();
1169   gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_button), "Move molecule");
1170   gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo_button), "Move camera");
1171 #endif
1172   gtk_box_pack_start(GTK_BOX(vbox_inner), combo_button, FALSE, FALSE, 0);
1173 
1174 /*  combo_list = g_list_append(combo_list, "Move molecule");
1175   combo_list = g_list_append(combo_list, "Move camera");
1176   gtk_combo_set_popdown_strings(GTK_COMBO(combo_button), combo_list);
1177   g_list_free(combo_list);*/
1178 
1179   if (move_camera)
1180     gtk_combo_box_set_active(GTK_COMBO_BOX(combo_button), 1);
1181   else
1182     gtk_combo_box_set_active(GTK_COMBO_BOX(combo_button), 0);
1183   g_signal_connect(G_OBJECT(combo_button), "changed", G_CALLBACK(luscus_toggle_movement_mode), NULL);
1184   gtk_widget_show(combo_button);
1185 
1186 #ifdef GTK2
1187   hbox = gtk_hbox_new(FALSE, 0);
1188 #endif
1189 #ifdef GTK3
1190   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1191   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1192 #endif
1193   gtk_box_pack_start(GTK_BOX(vbox_inner), hbox, FALSE, FALSE, 5);
1194   gtk_widget_show(hbox);
1195 
1196   table = gtk_table_new(3, 3, TRUE);
1197   gtk_box_pack_start(GTK_BOX(hbox), table, TRUE, FALSE, 5);
1198 
1199   icon = gtk_image_new_from_stock(GTK_STOCK_GO_UP, GTK_ICON_SIZE_BUTTON);
1200   button = gtk_button_new();
1201   gtk_button_set_image(GTK_BUTTON(button), icon);
1202   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "move up");
1203   gtk_table_attach(GTK_TABLE(table), button, 1,2, 0,1, GTK_SHRINK, GTK_SHRINK, 3, 3);
1204   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_move_up), NULL);
1205   gtk_widget_show(button);
1206 
1207   icon = gtk_image_new_from_stock(GTK_STOCK_GO_FORWARD, GTK_ICON_SIZE_BUTTON);
1208   button = gtk_button_new();
1209   gtk_button_set_image(GTK_BUTTON(button), icon);
1210   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "move right");
1211   gtk_table_attach(GTK_TABLE(table), button, 2,3, 1,2, GTK_SHRINK, GTK_SHRINK, 3, 3);
1212   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_move_forw), NULL);
1213   gtk_widget_show(button);
1214 
1215   icon = gtk_image_new_from_stock(GTK_STOCK_GO_BACK, GTK_ICON_SIZE_BUTTON);
1216   button = gtk_button_new();
1217   gtk_button_set_image(GTK_BUTTON(button), icon);
1218   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "move left");
1219   gtk_table_attach(GTK_TABLE(table), button, 0,1, 1,2, GTK_SHRINK, GTK_SHRINK, 3, 3);
1220   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_move_back), NULL);
1221   gtk_widget_show(button);
1222 
1223   icon = gtk_image_new_from_stock(GTK_STOCK_GO_DOWN, GTK_ICON_SIZE_BUTTON);
1224   button = gtk_button_new();
1225   gtk_button_set_image(GTK_BUTTON(button), icon);
1226   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "move down");
1227   gtk_table_attach(GTK_TABLE(table), button, 1,2, 2,3, GTK_SHRINK, GTK_SHRINK, 3, 3);
1228   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_move_down), NULL);
1229   gtk_widget_show(button);
1230 
1231   pixb = gdk_pixbuf_new_from_xpm_data(center_xpm);
1232   icon = gtk_image_new_from_pixbuf(pixb);
1233   button = gtk_button_new();
1234   gtk_container_add(GTK_CONTAINER(button), icon);
1235   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "center");
1236   gtk_table_attach(GTK_TABLE(table), button, 1,2, 1,2, GTK_SHRINK, GTK_SHRINK, 3, 3);
1237   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_center), NULL);
1238   gtk_widget_show(button);
1239   gtk_widget_show(icon);
1240 
1241   gtk_widget_show(table);
1242   gtk_widget_show(hbox);
1243 
1244 #ifdef GTK2
1245   hbox = gtk_hbox_new(FALSE, 0);
1246 #endif
1247 #ifdef GTK3
1248   hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1249   gtk_box_set_homogeneous(GTK_BOX(hbox), FALSE);
1250 #endif
1251   gtk_box_pack_start(GTK_BOX(vbox_inner), hbox, FALSE, FALSE, 5);
1252 
1253   icon = gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, GTK_ICON_SIZE_BUTTON);
1254   button = gtk_button_new();
1255   gtk_button_set_image(GTK_BUTTON(button), icon);
1256   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "zoom out");
1257   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_zoom), (gpointer) -1);
1258   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
1259   gtk_widget_show(button);
1260 
1261   icon = gtk_image_new_from_stock(GTK_STOCK_ZOOM_100, GTK_ICON_SIZE_BUTTON);
1262   button = gtk_button_new();
1263   gtk_button_set_image(GTK_BUTTON(button), icon);
1264   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "Normal size");
1265   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_zoom), (gpointer) 0);
1266   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
1267   gtk_widget_show(button);
1268 
1269   icon = gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, GTK_ICON_SIZE_BUTTON);
1270   button = gtk_button_new();
1271   gtk_button_set_image(GTK_BUTTON(button), icon);
1272   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "zoom in");
1273   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(luscus_gtk_zoom), (gpointer) 1);
1274   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
1275   gtk_widget_show(button);
1276 
1277   gtk_widget_show(hbox);
1278   gtk_widget_show(vbox_inner);
1279 
1280 /*multiple geometries options*/
1281 
1282   geo_expander = gtk_expander_new("geometries");
1283   gtk_expander_set_expanded(GTK_EXPANDER(geo_expander), FALSE);
1284   gtk_box_pack_start(GTK_BOX(vbox_outer), geo_expander, FALSE, FALSE, 0);
1285   gtk_widget_hide(geo_expander);
1286 
1287 #ifdef GTK2
1288   vbox_inner = gtk_vbox_new(FALSE, 0);
1289 #endif
1290 #ifdef GTK3
1291   vbox_inner = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1292   gtk_box_set_homogeneous(GTK_BOX(vbox_inner), FALSE);
1293 #endif
1294 
1295   gtk_container_add(GTK_CONTAINER(geo_expander), vbox_inner);
1296 
1297 #ifdef GTK2
1298   geo_separator = gtk_hseparator_new();
1299 #endif
1300 #ifdef GTK3
1301   geo_separator = gtk_separator_new(GTK_ORIENTATION_HORIZONTAL);
1302 #endif
1303   gtk_box_pack_start(GTK_BOX(vbox_inner), geo_separator, FALSE, FALSE, 5);
1304   gtk_widget_show(geo_separator);
1305 
1306   geo_button = gtk_button_new_with_label("graphical info");
1307   gtk_box_pack_start(GTK_BOX(vbox_inner), geo_button, FALSE, FALSE, 5);
1308   g_signal_connect(G_OBJECT(geo_button), "clicked", G_CALLBACK(luscus_gtk_show_graphical_energies), NULL);
1309   gtk_widget_show(geo_button);
1310 
1311 #ifdef GTK2
1312   geo_hbox = gtk_hbox_new(FALSE, 0);
1313 #endif
1314 #ifdef GTK3
1315   geo_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1316   gtk_box_set_homogeneous(GTK_BOX(geo_hbox), FALSE);
1317 #endif
1318   gtk_box_pack_start(GTK_BOX(vbox_inner), geo_hbox, FALSE, FALSE, 5);
1319 
1320   adj_play_speed = gtk_adjustment_new(0.00F, 0.F, 1.F, 0.01F, 0.1F, 0.F);
1321  /* g_signal_connect();*/
1322 
1323   /*
1324 #ifdef GTK2
1325   spin_play_speed = gtk_spin_button_new(GTK_ADJUSTMENT(adj_play_speed), 0.01, 2);
1326 #endif
1327 #ifdef GTK3
1328   spin_play_speed = gtk_spin_button_new(adj_play_speed, 0.01, 2);
1329 #endif
1330 
1331   gtk_box_pack_start(GTK_BOX(geo_hbox), spin_play_speed, TRUE, FALSE, 0);
1332   gtk_widget_show(spin_play_speed);
1333   */
1334 
1335 
1336   icon = gtk_image_new_from_stock(GTK_STOCK_GOTO_FIRST, GTK_ICON_SIZE_BUTTON);
1337   button = gtk_button_new();
1338   gtk_button_set_image(GTK_BUTTON(button), icon);
1339   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "first geometry");
1340   gtk_box_pack_start(GTK_BOX(geo_hbox), button, TRUE, FALSE, 0);
1341   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback_geo_first), NULL);
1342   gtk_widget_show(button);
1343 
1344   icon = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON);
1345   geo_play_button = gtk_button_new();
1346   gtk_button_set_image(GTK_BUTTON(geo_play_button), icon);
1347   gtk_widget_set_tooltip_text(GTK_WIDGET(geo_play_button), "Play trajectory");
1348   gtk_box_pack_start(GTK_BOX(geo_hbox), geo_play_button, TRUE, FALSE, 0);
1349   g_signal_connect(G_OBJECT(geo_play_button), "clicked", G_CALLBACK(callback_geo_play), NULL);
1350   gtk_widget_show(geo_play_button);
1351 
1352 /*  icon = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON);
1353   button = gtk_button_new();
1354   gtk_button_set_image(GTK_BUTTON(button), icon);
1355   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "pause");
1356   gtk_box_pack_start(GTK_BOX(geo_hbox), button, TRUE, FALSE, 0);
1357   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback_geo_forw), NULL);
1358   gtk_widget_show(button);*/
1359 
1360   icon = gtk_image_new_from_stock(GTK_STOCK_GOTO_LAST, GTK_ICON_SIZE_BUTTON);
1361   button = gtk_button_new();
1362   gtk_button_set_image(GTK_BUTTON(button), icon);
1363   gtk_widget_set_tooltip_text(GTK_WIDGET(button), "last geometry");
1364   gtk_box_pack_start(GTK_BOX(geo_hbox), button, TRUE, FALSE, 0);
1365   g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(callback_geo_last), NULL);
1366   gtk_widget_show(button);
1367 
1368   gtk_widget_show(geo_hbox);
1369 
1370   /*slider*/
1371   adj_geoms = gtk_adjustment_new(0.F, 0.F, (gdouble) n_geometries, 1.F, 1.F, 0.F);
1372   gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_geoms), 0);
1373   g_signal_connect(G_OBJECT(adj_geoms), "value-changed", G_CALLBACK(callback_adj_geometry), NULL);
1374 #ifdef GTK2
1375   geo_slider = gtk_hscale_new(GTK_ADJUSTMENT(adj_geoms));
1376 #endif
1377 #ifdef GTK3
1378   geo_slider = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, adj_geoms);
1379 #endif
1380   gtk_scale_set_digits(GTK_SCALE(geo_slider), 0);
1381   gtk_scale_set_draw_value(GTK_SCALE(geo_slider), TRUE);
1382   gtk_box_pack_start(GTK_BOX(vbox_inner), geo_slider, FALSE, FALSE, 0);
1383   gtk_widget_show(geo_slider);
1384 
1385   label_igeo = gtk_label_new(NULL);
1386   gtk_box_pack_start(GTK_BOX(vbox_inner), label_igeo, FALSE, FALSE, 0);
1387   gtk_widget_show(label_igeo);
1388 
1389   gtk_widget_show(vbox_inner);
1390 
1391   /*grid info*/
1392 
1393   grid_expander = gtk_expander_new("surface");
1394   gtk_expander_set_expanded(GTK_EXPANDER(grid_expander), FALSE);
1395   gtk_box_pack_start(GTK_BOX(vbox_outer), grid_expander, FALSE, FALSE, 0);
1396   gtk_widget_hide(grid_expander);
1397 
1398 #ifdef GTK2
1399   vbox_inner = gtk_vbox_new(FALSE, 0);
1400 #endif
1401 #ifdef GTK3
1402   vbox_inner = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1403   gtk_box_set_homogeneous(GTK_BOX(vbox_inner), FALSE);
1404 #endif
1405   gtk_container_add(GTK_CONTAINER(grid_expander), vbox_inner);
1406 
1407   grid_frame_transp = gtk_frame_new("transparency");
1408   gtk_box_pack_start(GTK_BOX(vbox_inner), grid_frame_transp, FALSE, FALSE, 0);
1409 
1410   tranparency_level = gtk_adjustment_new(0.0, 0.F, 1.F, 0.01F, 0.1F, 0.F);
1411   gtk_adjustment_set_value(GTK_ADJUSTMENT(tranparency_level), Input_Data.neg_pos_color[0][3]);
1412 #ifdef GTK2
1413   scale = gtk_hscale_new(GTK_ADJUSTMENT(tranparency_level));
1414 #elif GTK3
1415   scale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, tranparency_level);
1416 #endif
1417   gtk_scale_set_digits(GTK_SCALE(scale), 2);
1418   g_signal_connect(G_OBJECT(tranparency_level), "value-changed", G_CALLBACK(luscus_gtk_change_transparency_level), NULL);
1419   gtk_container_add(GTK_CONTAINER(grid_frame_transp), scale);
1420   gtk_widget_show(scale);
1421 
1422   gtk_widget_hide(grid_frame_transp);
1423 
1424   grid_frame_isosurf = gtk_frame_new("isosurface");
1425 
1426   gtk_box_pack_start(GTK_BOX(vbox_inner), grid_frame_isosurf, FALSE, FALSE, 0);
1427   isosurface_level = gtk_adjustment_new(0.0, 0.F, 0.2F, 0.001F, 0.01F, 0.F);
1428   gtk_adjustment_set_value(GTK_ADJUSTMENT(isosurface_level), Input_Data.lev);
1429 
1430 #ifdef GTK2
1431   scale = gtk_hscale_new(GTK_ADJUSTMENT(isosurface_level));
1432 #elif GTK3
1433   scale = gtk_scale_new(GTK_ORIENTATION_HORIZONTAL, isosurface_level);
1434 #endif
1435   gtk_scale_set_digits(GTK_SCALE(scale), 3);
1436   g_signal_connect(G_OBJECT(isosurface_level), "value-changed", G_CALLBACK(luscus_gtk_change_isosurface_level), NULL);
1437   gtk_container_add(GTK_CONTAINER(grid_frame_isosurf), scale);
1438   gtk_widget_show(scale);
1439 
1440   gtk_widget_hide(grid_frame_isosurf);
1441 
1442   all_orbitals_button = gtk_button_new_with_label("View all orbitals");
1443   gtk_box_pack_start(GTK_BOX(vbox_inner), all_orbitals_button, FALSE, FALSE, 0);
1444   g_signal_connect(G_OBJECT(all_orbitals_button), "clicked", G_CALLBACK(luscus_gtk_show_all_orbitals), NULL);
1445   gtk_widget_hide(all_orbitals_button);
1446 
1447   epot_button = gtk_button_new_with_label("Show electrostatic potential");
1448   gtk_box_pack_start(GTK_BOX(vbox_inner), epot_button, FALSE, FALSE, 0);
1449   g_signal_connect(G_OBJECT(epot_button), "clicked", G_CALLBACK(luscus_gtk_show_electrostatic_potential), NULL);
1450   gtk_widget_hide(epot_button);
1451 
1452   gtk_widget_show(vbox_inner);
1453 
1454   /*density difference*/
1455 /*  dens_diff_button = gtk_button_new_with_label("Calculate density difference");
1456   gtk_box_pack_start(GTK_BOX(vbox_outer), dens_diff_button, FALSE, FALSE, 0);
1457   g_signal_connect(G_OBJECT(dens_diff_button), "clicked", G_CALLBACK(luscus_calculate_dens_difference), NULL);
1458   gtk_widget_hide(dens_diff_button);*/
1459 
1460   expander = gtk_expander_new("whatched values");
1461   gtk_expander_set_expanded(GTK_EXPANDER(expander), FALSE);
1462   gtk_box_pack_start(GTK_BOX(vbox_outer), expander, TRUE, TRUE, 0);
1463   gtk_widget_show(expander);
1464 
1465   scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1466   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1467 
1468 #ifdef GTK2
1469   vbox_watched = gtk_vbox_new(FALSE, 0);
1470 #endif
1471 #ifdef GTK3
1472   vbox_watched = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
1473   gtk_box_set_homogeneous(GTK_BOX(vbox_watched), FALSE);
1474 #endif
1475   gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window), vbox_watched);
1476   gtk_widget_hide(vbox_watched);
1477 
1478   gtk_container_add(GTK_CONTAINER(expander), scrolled_window);
1479 /*  gtk_box_pack_start(GTK_BOX(vbox_outer), scrolled_window, TRUE, TRUE, 0);*/
1480   gtk_widget_show(scrolled_window);
1481 
1482  /*list of all geometrical elements*/
1483 
1484 /*  label = gtk_label_new("general");
1485   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, label);
1486   gtk_widget_show(vbox);*/
1487   gtk_widget_show(notebook);
1488 
1489   gtk_widget_show(vbox_outer);
1490   return vbox_outer;
1491 }
1492 
luscus_gtk_diseable_editing(void)1493 void luscus_gtk_diseable_editing(void)
1494 {
1495 /*GtkWidget *vbox_vibration;
1496 GtkWidget *vbox_edit;
1497 GtkWidget *vbox_fragments;
1498 GtkWidget *vbox_symmetry;
1499 GtkWidget *vbox_draw;
1500 GtkWidget *vbox_orbitals;*/
1501   gtk_widget_set_sensitive(GTK_WIDGET(vbox_edit), FALSE);
1502   gtk_widget_set_sensitive(GTK_WIDGET(table_fragments), FALSE);
1503   gtk_widget_set_sensitive(GTK_WIDGET(vbox_symmetry), FALSE);
1504   gtk_widget_set_sensitive(GTK_WIDGET(vbox_draw), FALSE);
1505 
1506   luscus_gtk_menubar_show_or_hide_widgets();
1507 }
1508 
luscus_gtk_enable_editing(void)1509 void luscus_gtk_enable_editing(void)
1510 {
1511   gtk_widget_set_sensitive(GTK_WIDGET(vbox_edit), TRUE);
1512   gtk_widget_set_sensitive(GTK_WIDGET(table_fragments), TRUE);
1513   gtk_widget_set_sensitive(GTK_WIDGET(vbox_symmetry), TRUE);
1514   gtk_widget_set_sensitive(GTK_WIDGET(vbox_draw), TRUE);
1515 /*  gtk_widget_set_sensitive(GTK_WIDGET(notebook), TRUE);*/
1516   luscus_gtk_menubar_show_or_hide_widgets();
1517 }
1518 
luscus_gtk_make_treeview(void)1519 GtkWidget *luscus_gtk_make_treeview(void)
1520 {
1521   GtkTreeIter iter_combo;
1522   GtkCellRenderer *renderer;
1523   GtkTreeViewColumn *column;
1524   GtkListStore *list_store_combo;
1525   GtkTreeSortable *sortable;
1526   gint i;
1527 /*  gint data_sym, data_orbnum;
1528   gdouble data_energy, data_occu;
1529   gint orb_num_type;*/
1530 
1531   /*-------creating a view component-------*/
1532 
1533   treeview = gtk_tree_view_new();
1534 
1535   list_store_combo = gtk_list_store_new(1, G_TYPE_STRING);
1536 
1537   for(i = 0; i < NUM_ORB_TYPES; i++)
1538   {
1539     gtk_list_store_append(list_store_combo, &iter_combo);
1540     gtk_list_store_set(list_store_combo, &iter_combo, 0, orbital_description[i], -1);
1541   }
1542 
1543   renderer = gtk_cell_renderer_combo_new();
1544   g_object_set(renderer, "text-column", 0, "model", list_store_combo, "editable", TRUE, "has-entry", FALSE, NULL);
1545   g_signal_connect(renderer, "edited", G_CALLBACK(orbital_combo_edited), (gpointer) list_store_combo);
1546   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, "orbital type", renderer, "text", ORBITAL_TYPE, NULL);
1547 
1548   renderer = gtk_cell_renderer_text_new();
1549   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, "symmetry", renderer, "text", ORBITAL_SYMM, NULL);
1550 
1551   renderer = gtk_cell_renderer_text_new();
1552   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, "index", renderer, "text", ORBITAL_NUM, NULL);
1553 
1554   renderer = gtk_cell_renderer_text_new();
1555   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, "energy", renderer, "text", ORBITAL_ENERG, NULL);
1556 
1557   renderer = gtk_cell_renderer_text_new();
1558   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, "occupancy", renderer, "text", ORBITAL_OCC, NULL);
1559 
1560   renderer = gtk_cell_renderer_text_new();
1561   gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(treeview), -1, " ", renderer, "text", ORBITAL_EDITED, NULL);
1562 
1563   /*-------creating store(model)-------*/
1564 
1565   store = gtk_list_store_new(NUM_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_STRING);
1566   sortable = GTK_TREE_SORTABLE(store);
1567 
1568   gtk_tree_sortable_set_sort_func(sortable, ORBITAL_SYMM, luscus_gtk_orbital_compare_func, GINT_TO_POINTER(ORBITAL_SYMM), NULL);
1569   gtk_tree_sortable_set_sort_func(sortable, ORBITAL_NUM,  luscus_gtk_orbital_compare_func, GINT_TO_POINTER(ORBITAL_NUM), NULL);
1570   gtk_tree_sortable_set_sort_func(sortable, ORBITAL_ENERG, luscus_gtk_orbital_compare_func, GINT_TO_POINTER(ORBITAL_ENERG), NULL);
1571   gtk_tree_sortable_set_sort_func(sortable, ORBITAL_OCC,  luscus_gtk_orbital_compare_func, GINT_TO_POINTER(ORBITAL_OCC), NULL);
1572   column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), ORBITAL_SYMM);
1573   gtk_tree_view_column_set_sort_column_id(column, ORBITAL_SYMM);
1574   column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), ORBITAL_NUM);
1575   gtk_tree_view_column_set_sort_column_id(column, ORBITAL_NUM);
1576   column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), ORBITAL_ENERG);
1577   gtk_tree_view_column_set_sort_column_id(column, ORBITAL_ENERG);
1578   column = gtk_tree_view_get_column(GTK_TREE_VIEW(treeview), ORBITAL_OCC);
1579   gtk_tree_view_column_set_sort_column_id(column, ORBITAL_OCC);
1580 
1581   selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
1582   gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE | GTK_SELECTION_NONE);
1583   if (selected_orbital) gtk_tree_selection_select_iter(selection, selected_orbital);
1584   gtk_tree_selection_set_select_function(selection, luscus_gtk_select_orbital_from_list, NULL, NULL);
1585 
1586   return treeview;
1587 }
1588 
luscus_gtk_orbital_compare_func(GtkTreeModel * model,GtkTreeIter * a,GtkTreeIter * b,gpointer data)1589 gint luscus_gtk_orbital_compare_func(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
1590 {
1591   gint sort_col = GPOINTER_TO_INT(data);
1592   gint int_data1, int_data2;
1593   gdouble double_data1, double_data2;
1594   gint res = 0;
1595 
1596   switch(sort_col)
1597   {
1598     case ORBITAL_SYMM:
1599       gtk_tree_model_get(model, a, ORBITAL_SYMM, &int_data1, -1);
1600       gtk_tree_model_get(model, b, ORBITAL_SYMM, &int_data2, -1);
1601       res = (int_data1 > int_data2) ? -1 : 1;
1602       return res;
1603     case ORBITAL_NUM:
1604       gtk_tree_model_get(model, a, ORBITAL_NUM, &int_data1, -1);
1605       gtk_tree_model_get(model, b, ORBITAL_NUM, &int_data2, -1);
1606       res = (int_data1 > int_data2) ? -1 : 1;
1607       return res;
1608     case ORBITAL_ENERG:
1609       gtk_tree_model_get(model, a, ORBITAL_ENERG, &double_data1, -1);
1610       gtk_tree_model_get(model, b, ORBITAL_ENERG, &double_data2, -1);
1611       res = (double_data1 > double_data2) ? 1 : -1;
1612       return res;
1613     case ORBITAL_OCC:
1614       gtk_tree_model_get(model, a, ORBITAL_OCC, &double_data1, -1);
1615       gtk_tree_model_get(model, b, ORBITAL_OCC, &double_data2, -1);
1616       res = (double_data1 > double_data2) ? -1 : 1;
1617       return res;
1618   }
1619   return res;
1620 }
1621 
luscus_gtk_select_orbital_from_list(GtkTreeSelection * selection,GtkTreeModel * model,GtkTreePath * path,gboolean path_selected,gpointer data)1622 gboolean luscus_gtk_select_orbital_from_list(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path,
1623                                          gboolean path_selected, gpointer data)
1624 {
1625 /*  gint test_sym, test_orbnum;*/
1626   GtkTreeIter iter;
1627   char lin[82];
1628   int orb_symm, orb_index;
1629   double orb_occ, orb_energ;
1630   gchar *orb_type, *orb_edit;
1631 
1632   if (gtk_tree_model_get_iter(model, &iter, path))
1633   {
1634     if (!gtk_tree_selection_iter_is_selected(selection, &iter))
1635     {
1636 /*      gtk_tree_model_get(GTK_TREE_MODEL(store) , &iter, ORBITAL_SYMM, &test_sym, ORBITAL_NUM, &test_orbnum, -1);
1637       luscus_gtk_find_selected_orbital(test_sym, test_orbnum);*/
1638 
1639       gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
1640                                                       ORBITAL_TYPE, &orb_type,
1641                                                       ORBITAL_SYMM, &orb_symm,
1642                                                       ORBITAL_NUM,  &orb_index,
1643                                                       ORBITAL_ENERG,&orb_energ,
1644                                                       ORBITAL_OCC,  &orb_occ,
1645                                                       ORBITAL_EDITED,&orb_edit,  -1);
1646       snprintf(lin, 82, "%1s orbital sym: %2d index: %2d energy: %12.4f occ: %5.2f type: %s", orb_edit, orb_symm, orb_index, orb_energ, orb_occ, orb_type);
1647       luscus_gtk_pop_message_from_statusbar1();
1648       luscus_gtk_push_message_to_statusbar1(lin);
1649 
1650       luscus_gtk_find_selected_orbital(orb_symm, orb_index);
1651     }
1652   }
1653 
1654   return TRUE;
1655 }
1656 
luscus_gtk_show_or_hide_widgets(void)1657 void luscus_gtk_show_or_hide_widgets(void)
1658 {
1659   int i;
1660 
1661   for(i = 0; i < n_custom_grid; i++)
1662     if (GTK_IS_WIDGET(button_custom_grid[i]))
1663       gtk_widget_destroy(button_custom_grid[i]);
1664   n_custom_grid = 0;
1665   if (button_custom_grid) g_free(button_custom_grid);
1666   button_custom_grid = NULL;
1667 
1668   if (!m)
1669   {
1670     gtk_widget_hide(vbox_vibration);
1671     gtk_widget_hide(vbox_orbitals);
1672     gtk_widget_hide(geo_expander);
1673 /*    gtk_widget_hide(geo_button);
1674     gtk_widget_hide(geo_hbox);
1675     gtk_widget_hide(label_igeo);*/
1676     gtk_widget_hide(grid_frame_transp);
1677     gtk_widget_hide(grid_frame_isosurf);
1678     gtk_widget_hide(all_orbitals_button);
1679     gtk_widget_hide(grid_expander);
1680     gtk_widget_hide(epot_button);
1681 /*    gtk_widget_hide(dens_diff_button);*/
1682     gtk_widget_hide(vib_spectrum_button);
1683     gtk_widget_hide(vbox_freqs);
1684 /*    gtk_widget_hide(vbox_3Dobject);*/
1685     gtk_widget_set_sensitive(button_remove_atom, FALSE);
1686     gtk_widget_set_sensitive(button_change_atom, FALSE);
1687     gtk_widget_hide(button_change_bond);
1688     gtk_widget_set_sensitive(button_add_dummy, FALSE);
1689     gtk_widget_set_sensitive(button_remove_selection, FALSE);
1690     gtk_widget_set_sensitive(button_mark_H, FALSE);
1691     gtk_widget_set_sensitive(button_mark_reverse, FALSE);
1692     gtk_widget_set_sensitive(button_mark_element, FALSE);
1693     gtk_widget_set_sensitive(button_neighbor, FALSE);
1694     return;
1695   }
1696   if (m->nvibr)
1697   {
1698     gtk_widget_show(vbox_vibration);
1699     gtk_widget_show(vib_spectrum_button);
1700     gtk_widget_show(vbox_freqs);
1701   }
1702   else
1703   {
1704     gtk_widget_hide(vbox_vibration);
1705     gtk_widget_hide(vib_spectrum_button);
1706     gtk_widget_hide(vbox_freqs);
1707   }
1708   if (n_geometries > 1)
1709   {
1710     gtk_widget_show(geo_expander);
1711     gtk_adjustment_set_upper(GTK_ADJUSTMENT(adj_geoms), (gdouble) n_geometries-1);
1712 /*    gtk_widget_show(geo_button);
1713     gtk_widget_show(geo_hbox);
1714     gtk_widget_show(label_igeo);*/
1715   }
1716   else
1717   {
1718     gtk_widget_hide(geo_expander);
1719 /*    gtk_widget_hide(geo_button);
1720     gtk_widget_hide(geo_hbox);
1721     gtk_widget_hide(label_igeo);*/
1722   }
1723   if (m->nvector + m->ntriangle + m->nsphere + m->nsurf + m->ncells)
1724   {
1725     gtk_widget_show(vbox_3Dobject);
1726   }
1727   if (m->ngrids)
1728   {
1729     gtk_widget_show(grid_frame_transp);
1730     gtk_widget_show(grid_frame_isosurf);
1731     gtk_widget_show(all_orbitals_button);
1732     gtk_widget_show(grid_expander);
1733 /*    gtk_widget_show(dens_diff_button);*/
1734     gtk_widget_show(vbox_orbitals);
1735 
1736     for(i = 0; i < m->ngrids; i++)
1737     {
1738       if (m->grid_type[i] == CUSTOM)
1739       {
1740         n_custom_grid++;
1741         button_custom_grid = (GtkWidget**) g_realloc(button_custom_grid, sizeof(GtkWidget*) * n_custom_grid);
1742         button_custom_grid[n_custom_grid - 1] = gtk_button_new_with_label(m->grid.titlesArr[i]);
1743         g_signal_connect(G_OBJECT(button_custom_grid[n_custom_grid - 1]), "clicked", G_CALLBACK(show_custom_grid), GINT_TO_POINTER(i));
1744         gtk_box_pack_start(GTK_BOX(vbox_orbitals), button_custom_grid[n_custom_grid - 1], FALSE, FALSE, 0);
1745         gtk_widget_show(button_custom_grid[n_custom_grid - 1]);
1746       }
1747     }
1748   }
1749   else
1750   {
1751     gtk_widget_hide(grid_expander);
1752     gtk_widget_hide(grid_frame_transp);
1753     gtk_widget_hide(grid_frame_isosurf);
1754     gtk_widget_hide(all_orbitals_button);
1755     gtk_widget_hide(vbox_orbitals);
1756   }
1757 /*  if (m->ngrids) gtk_widget_show(vbox_orbitals);
1758   else gtk_widget_hide(vbox_orbitals);*/
1759   if (m->ishow & HAS_E_POT) gtk_widget_show(epot_button);
1760   else gtk_widget_hide(epot_button);
1761   load_grid_data();
1762 }
1763 
luscus_gtk_update_upon_select_or_mark(void)1764 void luscus_gtk_update_upon_select_or_mark(void)
1765 {
1766   int i;
1767   gchar *tmp;
1768 
1769   if (m->n_selected == 0)
1770   {
1771     gtk_widget_set_sensitive(button_change_atom, FALSE);
1772     gtk_widget_hide(button_change_bond);
1773     gtk_widget_hide(button_change_angle);
1774     gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_angle), -1);
1775     gtk_widget_hide(hbox_xyz);
1776 
1777     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), TRUE);
1778     luscus_gtk_pop_message_from_statusbar2();
1779     gtk_widget_set_sensitive(GTK_WIDGET(button_average_symm), TRUE);
1780     gtk_widget_set_sensitive(GTK_WIDGET(button_trans_symm), FALSE);
1781     gtk_widget_set_tooltip_text(GTK_WIDGET(button_trans_symm), "select two atoms that define the translation vector");
1782     gtk_widget_set_sensitive(GTK_WIDGET(spin_transl_vect), FALSE);
1783     gtk_widget_set_sensitive(GTK_WIDGET(button_c2), FALSE);
1784     gtk_widget_set_tooltip_text(GTK_WIDGET(button_c2), "select two atoms that define the rotation vector");
1785     gtk_widget_set_sensitive(GTK_WIDGET(spin_axis), FALSE);
1786     gtk_widget_set_sensitive(GTK_WIDGET(button_inversion_symm), FALSE);
1787     gtk_widget_set_tooltip_text(GTK_WIDGET(button_inversion_symm), "select an atom that defines the center of inversion");
1788     gtk_widget_set_sensitive(GTK_WIDGET(button_mirror_symm), FALSE);
1789     gtk_widget_set_tooltip_text(GTK_WIDGET(button_mirror_symm), "select three atoms that define mirror plane");
1790 
1791     gtk_widget_set_sensitive(GTK_WIDGET(button_add_atom), TRUE);
1792     gtk_widget_set_sensitive(GTK_WIDGET(button_remove_selection), FALSE);
1793     gtk_widget_set_sensitive(GTK_WIDGET(button_add_dummy), TRUE);
1794     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_H), TRUE);
1795     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_reverse), TRUE);
1796     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_element), FALSE);
1797     gtk_widget_set_sensitive(GTK_WIDGET(button_neighbor), FALSE);
1798     gtk_widget_set_sensitive(GTK_WIDGET(button_watch), FALSE);
1799     gtk_button_set_label(GTK_BUTTON(button_symmetry), "apply symmetry");
1800 
1801     gtk_widget_set_sensitive(GTK_WIDGET(spin_bond), FALSE);
1802     gtk_widget_set_sensitive(GTK_WIDGET(spin_angle), FALSE);
1803     gtk_widget_set_sensitive(GTK_WIDGET(spin_tors), FALSE);
1804 
1805 /*    gtk_label_set_text(GTK_LABEL(label_bond_angle_torsion), NULL);
1806     gtk_label_set_text(GTK_LABEL(label_unit), NULL);
1807     gtk_widget_hide(spin_bond_ang_tor);*/
1808 
1809     gtk_widget_set_sensitive(GTK_WIDGET(button_arrow), FALSE);
1810     gtk_widget_set_tooltip_text(GTK_WIDGET(button_arrow), "select two atoms that define vector");
1811     gtk_widget_set_sensitive(GTK_WIDGET(button_sphere), FALSE);
1812     gtk_widget_set_tooltip_text(GTK_WIDGET(button_sphere), "select one or two that defines center (and radius) of sphere");
1813     gtk_widget_set_sensitive(GTK_WIDGET(button_plain), FALSE);
1814     gtk_widget_set_tooltip_text(GTK_WIDGET(button_plain), "select three atoms that define plain");
1815     gtk_widget_set_sensitive(GTK_WIDGET(button_triangle), FALSE);
1816     gtk_widget_set_tooltip_text(GTK_WIDGET(button_triangle), "select three atoms that define triangle");
1817     gtk_widget_set_sensitive(GTK_WIDGET(button_cell), FALSE);
1818     gtk_widget_set_tooltip_text(GTK_WIDGET(button_cell), "select four atoms that define a cell");
1819   }
1820   else if (m->n_selected == 1)
1821   {
1822     gtk_widget_set_sensitive(button_change_atom, TRUE);
1823     gtk_widget_hide(button_change_bond);
1824     gtk_widget_hide(button_change_angle);
1825     gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_angle), -1);
1826     gtk_widget_show(hbox_xyz);
1827 
1828     gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_x), m->xyz[m->selected[0]][0]);
1829     gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_y), m->xyz[m->selected[0]][1]);
1830     gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_z), m->xyz[m->selected[0]][2]);
1831 
1832     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);
1833     gtk_widget_set_sensitive(GTK_WIDGET(button_average_symm), FALSE);
1834     gtk_widget_set_sensitive(GTK_WIDGET(button_trans_symm), FALSE);
1835     gtk_widget_set_tooltip_text(GTK_WIDGET(button_trans_symm), "select two atoms that define the translation vector");
1836     gtk_widget_set_sensitive(GTK_WIDGET(spin_transl_vect), FALSE);
1837     gtk_widget_set_sensitive(GTK_WIDGET(button_c2), FALSE);
1838     gtk_widget_set_tooltip_text(GTK_WIDGET(button_c2), "select two atoms that define the rotation vector");
1839     gtk_widget_set_sensitive(GTK_WIDGET(spin_axis), FALSE);
1840     gtk_widget_set_sensitive(GTK_WIDGET(button_inversion_symm), TRUE);
1841     gtk_widget_set_tooltip_text(GTK_WIDGET(button_inversion_symm), "apply inversion symmetry");
1842     gtk_widget_set_sensitive(GTK_WIDGET(button_mirror_symm), FALSE);
1843     gtk_widget_set_tooltip_text(GTK_WIDGET(button_mirror_symm), "select three atoms that define mirror plane");
1844 
1845     gtk_widget_set_sensitive(GTK_WIDGET(button_add_atom), TRUE);
1846     gtk_widget_set_sensitive(GTK_WIDGET(button_remove_selection), TRUE);
1847     gtk_widget_set_sensitive(GTK_WIDGET(button_add_dummy), FALSE);
1848     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_H), FALSE);
1849     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_reverse), FALSE);
1850     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_element), TRUE);
1851     gtk_widget_set_sensitive(GTK_WIDGET(button_neighbor), TRUE);
1852     gtk_widget_set_sensitive(GTK_WIDGET(button_watch), FALSE);
1853 
1854     gtk_widget_set_sensitive(GTK_WIDGET(spin_bond), FALSE);
1855     gtk_widget_set_sensitive(GTK_WIDGET(spin_angle), FALSE);
1856     gtk_widget_set_sensitive(GTK_WIDGET(spin_tors), FALSE);
1857 
1858 /*    gtk_label_set_text(GTK_LABEL(label_bond_angle_torsion), "atom: ");
1859     gtk_label_set_text(GTK_LABEL(label_unit), m->elem[m->selected[0]].name);
1860     gtk_widget_hide(spin_bond_ang_tor);*/
1861 
1862     gtk_widget_set_sensitive(GTK_WIDGET(button_arrow), FALSE);
1863     gtk_widget_set_tooltip_text(GTK_WIDGET(button_arrow), "select two atoms that define vector");
1864     gtk_widget_set_sensitive(GTK_WIDGET(button_sphere), TRUE);
1865     gtk_widget_set_tooltip_text(GTK_WIDGET(button_sphere), "draw sphere around selected atom");
1866     gtk_widget_set_sensitive(GTK_WIDGET(button_plain), FALSE);
1867     gtk_widget_set_tooltip_text(GTK_WIDGET(button_plain), "select three atoms that define plain");
1868     gtk_widget_set_sensitive(GTK_WIDGET(button_triangle), FALSE);
1869     gtk_widget_set_tooltip_text(GTK_WIDGET(button_triangle), "select three atoms that define triangle");
1870     gtk_widget_set_sensitive(GTK_WIDGET(button_cell), FALSE);
1871     gtk_widget_set_tooltip_text(GTK_WIDGET(button_cell), "select four atoms that define a cell");
1872 
1873     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);
1874     tmp = g_strdup_printf("%s %d (%f %f %f)", m->elem[m->selected[0]].name, m->selected[0]+1, m->xyz[m->selected[0]][0],  m->xyz[m->selected[0]][1], m->xyz[m->selected[0]][2]);
1875     luscus_gtk_pop_message_from_statusbar2();
1876     luscus_gtk_push_message_to_statusbar2(tmp);
1877     g_free(tmp);
1878   }
1879   else if (m->n_selected == 2)
1880   {
1881     gtk_widget_set_sensitive(button_change_atom, FALSE);
1882     gtk_widget_show(button_change_bond);
1883     gtk_widget_hide(button_change_angle);
1884     gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_angle), -1);
1885     gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_bond), get_bond_type(m->selected[0], m->selected[1]));
1886     gtk_adjustment_set_value(GTK_ADJUSTMENT(translation_magnitude), get_selected_bond_length());  /*OPTION: use default value from Input_Data*/
1887     gtk_widget_hide(hbox_xyz);
1888 
1889     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);
1890     gtk_widget_set_sensitive(GTK_WIDGET(button_average_symm), FALSE);
1891     gtk_widget_set_sensitive(GTK_WIDGET(button_trans_symm), TRUE);
1892     gtk_widget_set_tooltip_text(GTK_WIDGET(button_trans_symm), "Translate molecule in the direction of selected atoms");
1893     gtk_widget_set_sensitive(GTK_WIDGET(spin_transl_vect), TRUE);
1894     gtk_widget_set_sensitive(GTK_WIDGET(button_c2), TRUE);
1895     gtk_widget_set_tooltip_text(GTK_WIDGET(button_c2), "apply Cn symmetry operation around axis defined by selected atoms");
1896     gtk_widget_set_sensitive(GTK_WIDGET(spin_axis), TRUE);
1897     gtk_widget_set_sensitive(GTK_WIDGET(button_inversion_symm), FALSE);
1898     gtk_widget_set_tooltip_text(GTK_WIDGET(button_inversion_symm), "select an atom that defines the center of inversion");
1899     gtk_widget_set_sensitive(GTK_WIDGET(button_mirror_symm), FALSE);
1900     gtk_widget_set_tooltip_text(GTK_WIDGET(button_mirror_symm), "select three atoms that define mirror plane");
1901 
1902     gtk_widget_set_sensitive(GTK_WIDGET(button_add_atom), TRUE);
1903     gtk_widget_set_sensitive(GTK_WIDGET(button_remove_selection), TRUE);
1904     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_H), FALSE);
1905     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_reverse), FALSE);
1906     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_element), FALSE);
1907     gtk_widget_set_sensitive(GTK_WIDGET(button_neighbor), TRUE);
1908     gtk_widget_set_sensitive(GTK_WIDGET(button_watch), TRUE);
1909 
1910     gtk_widget_set_sensitive(GTK_WIDGET(spin_bond), TRUE);
1911     gtk_widget_set_sensitive(GTK_WIDGET(spin_angle), FALSE);
1912     gtk_widget_set_sensitive(GTK_WIDGET(spin_tors), FALSE);
1913     gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_bond), get_selected_bond_length());
1914 
1915 /*    gtk_label_set_text(GTK_LABEL(label_bond_angle_torsion), "bond");
1916     gtk_label_set_text(GTK_LABEL(label_unit), "\303\205");
1917     gtk_adjustment_set_upper(GTK_ADJUSTMENT(adj_bond_angle_tors), 100.F);
1918     gtk_adjustment_set_lower(GTK_ADJUSTMENT(adj_bond_angle_tors), 0.01F);
1919     gtk_adjustment_set_step_increment(GTK_ADJUSTMENT(adj_bond_angle_tors),0.01F);
1920     gtk_adjustment_set_page_increment(GTK_ADJUSTMENT(adj_bond_angle_tors),0.1F);
1921     gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_bond_angle_tors), get_selected_bond_length());
1922     gtk_widget_show(spin_bond_ang_tor);*/
1923     gtk_widget_set_sensitive(GTK_WIDGET(button_add_dummy), TRUE);
1924 
1925     gtk_widget_set_sensitive(GTK_WIDGET(button_arrow), TRUE);
1926     gtk_widget_set_tooltip_text(GTK_WIDGET(button_arrow), "draw vector between selecter atoms");
1927     gtk_widget_set_sensitive(GTK_WIDGET(button_sphere), TRUE);
1928     gtk_widget_set_tooltip_text(GTK_WIDGET(button_sphere), "draw sphere around selected atom");
1929     gtk_widget_set_sensitive(GTK_WIDGET(button_plain), FALSE);
1930     gtk_widget_set_tooltip_text(GTK_WIDGET(button_plain), "select three atoms that define plain");
1931     gtk_widget_set_sensitive(GTK_WIDGET(button_triangle), FALSE);
1932     gtk_widget_set_tooltip_text(GTK_WIDGET(button_triangle), "select three atoms that define triangle");
1933     gtk_widget_set_sensitive(GTK_WIDGET(button_cell), FALSE);
1934     gtk_widget_set_tooltip_text(GTK_WIDGET(button_cell), "select four atoms that define a cell");
1935 
1936 /*    if (m->n_selected != m->natom)
1937     {
1938       gtk_button_set_label(GTK_BUTTON(button_symmetry), "apply translation symmetry");
1939     }
1940     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);*/
1941 
1942     tmp = g_strdup_printf("bond: %s %d-%s %d  %f", m->elem[m->selected[0]].name, m->selected[0]+1,
1943                                                    m->elem[m->selected[1]].name, m->selected[1]+1, get_selected_bond_length());
1944     luscus_gtk_pop_message_from_statusbar2();
1945     luscus_gtk_push_message_to_statusbar2(tmp);
1946     g_free(tmp);
1947   }
1948   else if (m->n_selected == 3)
1949   {
1950     gtk_widget_set_sensitive(button_change_atom, FALSE);
1951     gtk_widget_hide(button_change_bond);
1952     gtk_widget_show(button_change_angle);
1953     gtk_widget_hide(hbox_xyz);
1954 
1955     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);
1956     gtk_widget_set_sensitive(GTK_WIDGET(button_average_symm), FALSE);
1957     gtk_widget_set_sensitive(GTK_WIDGET(button_trans_symm), FALSE);
1958     gtk_widget_set_tooltip_text(GTK_WIDGET(button_trans_symm), "select two atoms that define the translation vector");
1959     gtk_widget_set_sensitive(GTK_WIDGET(spin_transl_vect), FALSE);
1960     gtk_widget_set_sensitive(GTK_WIDGET(button_c2), FALSE);
1961     gtk_widget_set_tooltip_text(GTK_WIDGET(button_c2), "select two atoms that define the rotation vector");
1962     gtk_widget_set_sensitive(GTK_WIDGET(spin_axis), FALSE);
1963     gtk_widget_set_sensitive(GTK_WIDGET(button_inversion_symm), FALSE);
1964     gtk_widget_set_tooltip_text(GTK_WIDGET(button_inversion_symm), "select an atom that defines the center of inversion");
1965     gtk_widget_set_sensitive(GTK_WIDGET(button_mirror_symm), TRUE);
1966     gtk_widget_set_tooltip_text(GTK_WIDGET(button_mirror_symm), "apply mirror symmetry");
1967 
1968     gtk_widget_set_sensitive(GTK_WIDGET(button_add_atom), FALSE);
1969     gtk_widget_set_sensitive(GTK_WIDGET(button_remove_selection), TRUE);
1970 
1971     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_H), FALSE);
1972     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_reverse), FALSE);
1973     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_element), FALSE);
1974     gtk_widget_set_sensitive(GTK_WIDGET(button_neighbor), FALSE);
1975     gtk_widget_set_sensitive(GTK_WIDGET(button_watch), TRUE);
1976 
1977 
1978     gtk_widget_set_sensitive(GTK_WIDGET(spin_bond), FALSE);
1979     gtk_widget_set_sensitive(GTK_WIDGET(spin_angle), TRUE);
1980     gtk_widget_set_sensitive(GTK_WIDGET(spin_tors), FALSE);
1981     gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_angle), get_selected_angle_value());
1982 
1983 /*    gtk_label_set_text(GTK_LABEL(label_bond_angle_torsion), "angle");
1984     gtk_label_set_text(GTK_LABEL(label_unit), "\313\232");
1985     gtk_adjustment_set_upper(GTK_ADJUSTMENT(adj_bond_angle_tors), 180.F);
1986     gtk_adjustment_set_lower(GTK_ADJUSTMENT(adj_bond_angle_tors), 0.01F);
1987     gtk_adjustment_set_step_increment(GTK_ADJUSTMENT(adj_bond_angle_tors),0.2F);
1988     gtk_adjustment_set_page_increment(GTK_ADJUSTMENT(adj_bond_angle_tors),1.0F);
1989     gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_bond_angle_tors), get_selected_angle_value());*/
1990 
1991     gtk_widget_set_sensitive(GTK_WIDGET(button_arrow), FALSE);
1992     gtk_widget_set_tooltip_text(GTK_WIDGET(button_arrow), "draw vector between selecter atoms");
1993     gtk_widget_set_sensitive(GTK_WIDGET(button_sphere), FALSE);
1994     gtk_widget_set_tooltip_text(GTK_WIDGET(button_sphere), "select atom that defines center of sphere");
1995     gtk_widget_set_sensitive(GTK_WIDGET(button_plain), TRUE);
1996     gtk_widget_set_tooltip_text(GTK_WIDGET(button_plain), "draw plain through selected atoms");
1997     gtk_widget_set_sensitive(GTK_WIDGET(button_triangle), TRUE);
1998     gtk_widget_set_tooltip_text(GTK_WIDGET(button_triangle), "draw triangle through selected atoms");
1999     gtk_widget_set_sensitive(GTK_WIDGET(button_cell), FALSE);
2000     gtk_widget_set_tooltip_text(GTK_WIDGET(button_cell), "select four atoms that define a cell");
2001 
2002 /*    if (m->n_selected != m->natom)
2003     {
2004       gtk_widget_show(spin_bond_ang_tor);
2005       gtk_button_set_label(GTK_BUTTON(button_symmetry), "apply mirror symmetry");
2006     }
2007     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), TRUE);*/
2008 
2009     tmp = g_strdup_printf("angle: %s %d-%s %d-%s %d  %f", m->elem[m->selected[0]].name, m->selected[0]+1,
2010                                                           m->elem[m->selected[1]].name, m->selected[1]+1,
2011                                                           m->elem[m->selected[2]].name, m->selected[2]+1,
2012                                                           get_selected_angle_value());
2013     luscus_gtk_pop_message_from_statusbar2();
2014     luscus_gtk_push_message_to_statusbar2(tmp);
2015     g_free(tmp);
2016   }
2017   else if (m->n_selected == 4)
2018   {
2019     gtk_widget_set_sensitive(button_change_atom, FALSE);
2020     gtk_widget_hide(button_change_bond);
2021     gtk_widget_hide(button_change_angle);
2022     gtk_combo_box_set_active(GTK_COMBO_BOX(button_change_angle), -1);
2023     gtk_widget_hide(hbox_xyz);
2024 
2025     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);
2026     gtk_widget_set_sensitive(GTK_WIDGET(button_average_symm), FALSE);
2027     gtk_widget_set_sensitive(GTK_WIDGET(button_trans_symm), FALSE);
2028     gtk_widget_set_tooltip_text(GTK_WIDGET(button_trans_symm), "select two atoms that define the translation vector");
2029     gtk_widget_set_sensitive(GTK_WIDGET(spin_transl_vect), FALSE);
2030     gtk_widget_set_sensitive(GTK_WIDGET(button_c2), FALSE);
2031     gtk_widget_set_tooltip_text(GTK_WIDGET(button_c2), "select two atoms that define the rotation vector");
2032     gtk_widget_set_sensitive(GTK_WIDGET(spin_axis), FALSE);
2033     gtk_widget_set_sensitive(GTK_WIDGET(button_inversion_symm), FALSE);
2034     gtk_widget_set_tooltip_text(GTK_WIDGET(button_inversion_symm), "select an atom that defines the center of inversion");
2035     gtk_widget_set_sensitive(GTK_WIDGET(button_mirror_symm), FALSE);
2036     gtk_widget_set_tooltip_text(GTK_WIDGET(button_mirror_symm), "select three atoms that define mirror plane");
2037 
2038     gtk_widget_set_sensitive(GTK_WIDGET(button_add_atom), FALSE);
2039     gtk_widget_set_sensitive(GTK_WIDGET(button_remove_selection), TRUE);
2040     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_H), FALSE);
2041     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_reverse), FALSE);
2042     gtk_widget_set_sensitive(GTK_WIDGET(button_mark_element), FALSE);
2043     gtk_widget_set_sensitive(GTK_WIDGET(button_neighbor), FALSE);
2044     gtk_widget_set_sensitive(GTK_WIDGET(button_watch), TRUE);
2045 
2046     gtk_widget_set_sensitive(GTK_WIDGET(spin_bond), FALSE);
2047     gtk_widget_set_sensitive(GTK_WIDGET(spin_angle), FALSE);
2048     gtk_widget_set_sensitive(GTK_WIDGET(spin_tors), TRUE);
2049     gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_tors), get_selected_dihedral_value());
2050 
2051 /*    gtk_label_set_text(GTK_LABEL(label_bond_angle_torsion), "dihedral");
2052     gtk_label_set_text(GTK_LABEL(label_unit), "\313\232");
2053     gtk_adjustment_set_upper(GTK_ADJUSTMENT(adj_bond_angle_tors), 360.F);
2054     gtk_adjustment_set_lower(GTK_ADJUSTMENT(adj_bond_angle_tors),-360.F);
2055     gtk_adjustment_set_step_increment(GTK_ADJUSTMENT(adj_bond_angle_tors),0.2F);
2056     gtk_adjustment_set_page_increment(GTK_ADJUSTMENT(adj_bond_angle_tors),1.0F);
2057     gtk_adjustment_set_value(GTK_ADJUSTMENT(adj_bond_angle_tors), get_selected_dihedral_value());
2058     gtk_widget_show(spin_bond_ang_tor);*/
2059     gtk_widget_set_sensitive(GTK_WIDGET(button_add_dummy), FALSE);
2060 
2061     gtk_widget_set_sensitive(GTK_WIDGET(button_arrow), FALSE);
2062     gtk_widget_set_tooltip_text(GTK_WIDGET(button_arrow), "draw vector between selecter atoms");
2063     gtk_widget_set_sensitive(GTK_WIDGET(button_sphere), FALSE);
2064     gtk_widget_set_tooltip_text(GTK_WIDGET(button_sphere), "select atom that defines center of sphere");
2065     gtk_widget_set_sensitive(GTK_WIDGET(button_plain), FALSE);
2066     gtk_widget_set_tooltip_text(GTK_WIDGET(button_plain), "draw plain through selected atoms");
2067     gtk_widget_set_sensitive(GTK_WIDGET(button_triangle), FALSE);
2068     gtk_widget_set_tooltip_text(GTK_WIDGET(button_triangle), "draw triangle through selected atoms");
2069     gtk_widget_set_sensitive(GTK_WIDGET(button_cell), TRUE);
2070     gtk_widget_set_tooltip_text(GTK_WIDGET(button_cell), "draw cell through selected atoms");
2071 
2072     gtk_widget_set_sensitive(GTK_WIDGET(button_symmetry), FALSE);
2073 
2074     tmp = g_strdup_printf("dihedral:%s %d-%s %d-%s %d-%s %d  %f",
2075                           m->elem[m->selected[0]].name, m->selected[0]+1,
2076                           m->elem[m->selected[1]].name, m->selected[1]+1,
2077                           m->elem[m->selected[2]].name, m->selected[2]+1,
2078                           m->elem[m->selected[3]].name, m->selected[3]+1, get_selected_dihedral_value());
2079     luscus_gtk_pop_message_from_statusbar2();
2080     luscus_gtk_push_message_to_statusbar2(tmp);
2081     g_free(tmp);
2082   }
2083   if (m->n_marked)
2084   {
2085     gtk_widget_set_sensitive(GTK_WIDGET(button_unmark), TRUE);
2086     gtk_widget_set_sensitive(GTK_WIDGET(button_renumber), TRUE);
2087   }
2088   else
2089   {
2090     gtk_widget_set_sensitive(GTK_WIDGET(button_unmark), FALSE);
2091     gtk_widget_set_sensitive(GTK_WIDGET(button_renumber), FALSE);
2092   }
2093 
2094   if (m->n_selected == 1 || m->n_selected == 2 || m->n_marked) gtk_widget_set_sensitive(GTK_WIDGET(button_remove_atom), TRUE);
2095   else gtk_widget_set_sensitive(GTK_WIDGET(button_remove_atom), FALSE);
2096 
2097   if (m->nvector || m->ntriangle || m->nsphere || m->nsurf || m->ncells)
2098     gtk_widget_set_sensitive(GTK_WIDGET(button_clear_drawed), TRUE);
2099   else
2100     gtk_widget_set_sensitive(GTK_WIDGET(button_clear_drawed), FALSE);
2101 
2102   /**/
2103   if (n_watched)
2104   {
2105     gtk_widget_set_sensitive(GTK_WIDGET(button_unwatch), TRUE);
2106     gtk_widget_show(vbox_watched);
2107 
2108     if (n_watched != n_label_watched)
2109     {
2110       for(i = 0; i < n_label_watched; i++)
2111        	gtk_widget_destroy(labels_watched[i]);
2112       g_free(labels_watched);
2113       labels_watched = (GtkWidget**) g_malloc(sizeof(GtkWidget*) * n_watched);
2114       for(i = 0; i < n_watched; i++)
2115       {
2116         switch(watch[i].coord_type)
2117         {
2118           case C_BOND:
2119             tmp = g_strdup_printf("bond: %d-%d: %f", watch[i].atom[0], watch[i].atom[1],
2120                   get_bond_length(watch[i].atom[0] - 1, watch[i].atom[1] - 1));
2121           break;
2122           case C_ANGLE:
2123             tmp = g_strdup_printf("angle: %d-%d-%d: %f", watch[i].atom[0],
2124                   watch[i].atom[1], watch[i].atom[2],
2125                   get_angle_value(watch[i].atom[0] - 1, watch[i].atom[1]-1, watch[i].atom[2]-1));
2126           break;
2127           case C_DIHEDRAL:
2128             tmp = g_strdup_printf("dihedral: %d-%d-%d-%d: %f", watch[i].atom[0],
2129             watch[i].atom[1], watch[i].atom[2], watch[i].atom[3],
2130             get_dihedral_value(watch[i].atom[0]-1, watch[i].atom[1]-1, watch[i].atom[2]-1, watch[i].atom[3]-1));
2131           break;
2132           default:
2133           tmp = NULL;
2134         }
2135         labels_watched[i] = gtk_label_new(tmp);
2136         gtk_box_pack_start(GTK_BOX(vbox_watched), labels_watched[i], FALSE, FALSE, 0);
2137         gtk_widget_show(labels_watched[i]);
2138         g_free(tmp);
2139       }
2140       n_label_watched = n_watched;
2141     }
2142   }
2143   else
2144   {
2145     gtk_widget_set_sensitive(GTK_WIDGET(button_unwatch), FALSE);
2146     if (n_label_watched)
2147     {
2148       for(i = 0; i < n_label_watched; i++)
2149        	gtk_widget_destroy(labels_watched[i]);
2150       g_free(labels_watched);
2151       labels_watched = NULL;
2152       n_label_watched = 0;
2153     }
2154   }
2155 
2156 /*GtkWidget *vbox_watched;
2157 int n_label_watched;
2158 GtkWidget **labels_watched;*/
2159 
2160 }
2161 
change_watched_data(void)2162 void change_watched_data(void)
2163 {
2164   int i;
2165   char *tmp;
2166   if (n_label_watched != n_watched) return;
2167   for(i = 0; i < n_label_watched; i++)
2168   {
2169     switch(watch[i].coord_type)
2170     {
2171       case C_BOND:
2172         tmp = g_strdup_printf("bond: %d-%d: %f", watch[i].atom[0], watch[i].atom[1],
2173               get_bond_length(watch[i].atom[0]-1, watch[i].atom[1]-1));
2174       break;
2175       case C_ANGLE:
2176         tmp = g_strdup_printf("angle: %d-%d-%d: %f", watch[i].atom[0],
2177               watch[i].atom[1], watch[i].atom[2],
2178               get_angle_value(watch[i].atom[0]-1, watch[i].atom[1]-1, watch[i].atom[2]-1));
2179       break;
2180       case C_DIHEDRAL:
2181         tmp = g_strdup_printf("dihedral: %d-%d-%d-%d: %f", watch[i].atom[0],
2182         watch[i].atom[1], watch[i].atom[2], watch[i].atom[3],
2183         get_dihedral_value(watch[i].atom[0]-1, watch[i].atom[1]-1, watch[i].atom[2]-1, watch[i].atom[3]-1));
2184       break;
2185       default:
2186       tmp = NULL;
2187     }
2188     gtk_label_set_text(GTK_LABEL(labels_watched[i]), tmp);
2189     g_free(tmp);
2190   }
2191 }
2192 
luscus_gtk_update_geo_info(void)2193 void luscus_gtk_update_geo_info(void)
2194 {
2195   gint i;
2196   gchar *textbuf;
2197   gchar *tmpbuf;
2198   gchar *txt_freq = NULL;
2199   gchar *txt_irint = NULL;
2200   gchar *txt_ramint = NULL;
2201 
2202   if (m->ishow & HAS_ENERGY && m->ishow & HAS_RMS_GRAD && m->ishow & HAS_MAX_GRAD)
2203     textbuf = g_strdup_printf("Geometry: %d\nEnergy: %f\nRMS grad: %f\nmax. grad: %f", igeo, m->geo_energy, m->rms_grad, m->max_grad);
2204   else if (m->ishow & HAS_ENERGY && m->ishow & HAS_RMS_GRAD)
2205     textbuf = g_strdup_printf("Geometry: %d\nEnergy: %f\nRMS grad: %f", igeo, m->geo_energy, m->rms_grad);
2206   else if (m->ishow & HAS_ENERGY && m->ishow & HAS_MAX_GRAD)
2207     textbuf = g_strdup_printf("Geometry: %d\nEnergy: %f\nmax. grad: %f", igeo, m->geo_energy, m->max_grad);
2208   else if (m->ishow & HAS_RMS_GRAD && m->ishow & HAS_MAX_GRAD)
2209     textbuf = g_strdup_printf("Geometry: %d\nRMS grad: %f\nmax. grad: %f", igeo, m->rms_grad, m->max_grad);
2210   else if (m->ishow & HAS_ENERGY) textbuf = g_strdup_printf("Geometry: %d\nEnergy: %f", igeo, m->geo_energy);
2211   else if (m->ishow & HAS_RMS_GRAD) textbuf = g_strdup_printf("Geometry: %d\nRMS grad: %f", igeo, m->rms_grad);
2212   else if (m->ishow & HAS_MAX_GRAD) textbuf = g_strdup_printf("Geometry: %d\nmax. grad: %f", igeo, m->max_grad);
2213   else textbuf = g_strdup_printf("Geometry: %d", igeo);
2214 #ifdef EBUG
2215   printf("SETTING LABEL WITH THE TEXT: |%s|\n", (char*) textbuf); fflush(stdout);
2216 #endif
2217   gtk_label_set_text(GTK_LABEL(label_igeo), textbuf);
2218 #ifdef EBUG
2219   printf("SETTING LABEL DONE\n"); fflush(stdout);
2220 #endif
2221   g_free(textbuf);
2222 
2223   /*delete buttons from the last geom*/
2224   deallocate_vib_buttons();
2225 
2226   n_vibs = m->nvibr;
2227   freq_buttons = (GtkWidget**) g_malloc(sizeof(GtkWidget*) * m->nvibr);
2228   freq_labels = (GtkWidget**) g_malloc(sizeof(GtkWidget*) * m->nvibr);
2229 
2230   for(i = 0; i < m->nvibr; i++)
2231   {
2232     /*this allocation/deallocation of strings is bizarre!*/
2233     txt_freq = g_markup_printf_escaped("%.2f cm<sup>-1</sup>", m->freq[i]);
2234     textbuf = g_strdup(txt_freq);
2235 
2236     if (m->ishow & HAS_IRINT)
2237     {
2238       txt_irint = g_markup_printf_escaped(" IR int.=%.2f", m->ir_intensity[i]);
2239       g_free(textbuf);
2240       textbuf = g_strconcat(txt_freq, txt_irint, NULL);
2241       g_free(txt_irint);
2242     }
2243     if (m->ishow & HAS_RAMAN)
2244     {
2245       txt_ramint = g_markup_printf_escaped(" Raman int.=%.2f", m->raman_intensity[i]);
2246       tmpbuf = g_strconcat(textbuf, txt_ramint, NULL);
2247       g_free(textbuf);
2248       textbuf = tmpbuf;
2249 /*      textbuf = g_strconcat(txt_freq, txt_irint, NULL);*/
2250     }
2251 
2252     freq_labels[i] = gtk_label_new(NULL);
2253     gtk_label_set_markup(GTK_LABEL(freq_labels[i]), textbuf);
2254     freq_buttons[i] = gtk_button_new();
2255     gtk_container_add(GTK_CONTAINER(freq_buttons[i]), freq_labels[i]);
2256     gtk_box_pack_start(GTK_BOX(vbox_freqs), freq_buttons[i], FALSE, FALSE, 0);
2257     g_signal_connect(G_OBJECT(freq_buttons[i]), "clicked", G_CALLBACK(luscus_gtk_goto_freq), GINT_TO_POINTER(i));
2258 
2259     gtk_widget_show(freq_buttons[i]);
2260     gtk_widget_show(freq_labels[i]);
2261     g_free(txt_freq);
2262     g_free(textbuf);
2263   }
2264   /*if vibrations exists, start frequency timer*/
2265   if (m->nvibr) luscus_gtk_freq_timer();
2266 
2267   if (m->editable) luscus_gtk_enable_editing();
2268   else luscus_gtk_diseable_editing();
2269 }
2270 
deallocate_vib_buttons(void)2271 void deallocate_vib_buttons(void)
2272 {
2273   int i;
2274   /*delete buttons from the last geom*/
2275 
2276   if (freq_labels)
2277     for(i = 0; i < n_vibs; i++)
2278       gtk_widget_destroy(freq_labels[i]);
2279 
2280   if (freq_buttons)
2281     for(i = 0; i < n_vibs; i++)
2282       gtk_widget_destroy(freq_buttons[i]);
2283 
2284   g_free(freq_buttons);
2285   g_free(freq_labels);
2286   freq_buttons = NULL;
2287   freq_labels = NULL;
2288 }
2289 
deallocate_calc_widgets(void)2290 void deallocate_calc_widgets(void)
2291 {
2292   int i, j;
2293   for(i = 0; i < n_calc_defs; i++)
2294     g_free(calc_keys[i]);
2295   g_free(calc_keys);
2296 }
2297 
2298 /*ALLOCATE ADDITIONAL MEMORY FOR NORMAL MODES*/
2299 
load_grid_data(void)2300 void load_grid_data(void)
2301 {
2302   int i;
2303   int nnc_grid = 0;
2304   GtkTreeIter iter;
2305 
2306   if (m->ngrids == 0) return;
2307   for(i = 0; i < m->ngrids; i++)
2308   {
2309     if (m->grid_type[i] == ORBITAL)
2310     {
2311       nnc_grid++;
2312       gtk_list_store_append(store, &iter);
2313 
2314       if (i == iorb) selected_orbital = &iter;
2315 
2316       gtk_list_store_set(store, &iter,
2317                          ORBITAL_TYPE, orbital_description[m->orbital_type[i]],
2318                          ORBITAL_SYMM, m->grid_symmetry[i],
2319                          ORBITAL_NUM, m->grid_index[i],
2320                          ORBITAL_ENERG, m->grid_energy[i],
2321                          ORBITAL_OCC, m->grid_occ[i],
2322                          ORBITAL_EDITED, " ",
2323                         -1);
2324     }
2325   }
2326 
2327   if (nnc_grid)
2328   {
2329     gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(store));
2330     luscus_gtk_search_orbital_in_list(m->grid_symmetry[iorb], m->grid_index[iorb]);
2331   }
2332 /*  gtk_tree_selection_select_iter(selection, selected_orbital);*/
2333 }
2334 
delete_all_orbitals_from_list(void)2335 void delete_all_orbitals_from_list(void)
2336 {
2337   GtkTreeIter iter;
2338   GtkTreeModel *model;
2339   gboolean next = TRUE;
2340 
2341   if (!m) return;
2342   if (m->ngrids <= 0) return;
2343 
2344   model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
2345   gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), NULL);
2346 
2347 /*  while(next)
2348   {
2349     printf("REMOVING ");
2350     next = gtk_tree_model_get_iter_first(model, &iter);
2351     if (next)
2352     {
2353       gboolean irem;
2354       irem = gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2355       printf("REMOVING ITER irem = %d!\n", irem);
2356     }
2357   }*/
2358   gtk_list_store_clear(GTK_LIST_STORE(model));
2359 }
2360 
delete_orbital_from_list(GtkWidget * button,gpointer data)2361 void delete_orbital_from_list(GtkWidget *button, gpointer data)
2362 {
2363   GtkTreeIter iter;
2364   GtkTreeModel *model;
2365 
2366   if (gtk_tree_selection_get_selected(selection, &model, &iter))
2367     gtk_list_store_remove(store, &iter);
2368 }
2369 
undelete_all_orbitals_from_list(GtkWidget * widget,gpointer data)2370 void undelete_all_orbitals_from_list(GtkWidget *widget, gpointer data)
2371 {
2372   GtkTreeIter iter;
2373   GtkTreeModel *model;
2374   gboolean next = TRUE;
2375   gint i;
2376 /*  gint data_sym, data_orbnum;
2377   gdouble data_energy, data_occu;
2378   gint orb_num_type;*/
2379 
2380     /*detach model from the treeview*/
2381 
2382   model = gtk_tree_view_get_model(GTK_TREE_VIEW(treeview));
2383   g_object_ref(model);
2384   gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), NULL);
2385 
2386     /*remove all iters (data)*/
2387 
2388   while(next)
2389   {
2390     next = gtk_tree_model_get_iter_first(model, &iter);
2391     if (next) gtk_list_store_remove(GTK_LIST_STORE(model), &iter);
2392   }
2393 
2394   /*add new data*/
2395 
2396   selected_orbital = NULL;
2397   for (i = 0; i < m->ngrids; i++)
2398   {
2399     if (m->grid_type[i] == ORBITAL)
2400     {
2401     /*acquireing tree iter*/
2402 
2403       gtk_list_store_append(store, &iter);
2404       if (i == iorb)
2405       {
2406        	selected_orbital = &iter;
2407       }
2408 
2409       if (m->edited[i])
2410       {
2411         gtk_list_store_set(store, &iter,
2412                            ORBITAL_TYPE, orbital_description[m->orbital_type[i]],
2413                            ORBITAL_SYMM, m->grid_symmetry[i],
2414                            ORBITAL_NUM, m->grid_index[i],
2415                            ORBITAL_ENERG, m->grid_energy[i],
2416                            ORBITAL_OCC, m->grid_occ[i],
2417                            ORBITAL_EDITED, "*",
2418                           -1);
2419       }
2420       else
2421       {
2422         gtk_list_store_set(store, &iter,
2423                            ORBITAL_TYPE, orbital_description[m->orbital_type[i]],
2424                            ORBITAL_SYMM, m->grid_symmetry[i],
2425                            ORBITAL_NUM, m->grid_index[i],
2426                            ORBITAL_ENERG, m->grid_energy[i],
2427                            ORBITAL_OCC, m->grid_occ[i],
2428                            ORBITAL_EDITED, " ",
2429                           -1);
2430       }
2431     }
2432   }
2433 
2434   /*reattach the model to the treeview*/
2435 
2436   gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), model);
2437   g_object_unref(model);
2438 }
2439 
luscus_gtk_change_orbital_type(gint sym,gint num)2440 gint luscus_gtk_change_orbital_type(gint sym, gint num)
2441 {
2442   gint i;
2443   gint data_sym = 0, data_num = 0, data_type;
2444   /*changes orbital type return new orbital type*/
2445   GtkTreeModel *model;
2446   GtkTreeIter iter;
2447 
2448   gchar *tmptext;
2449   gboolean next = TRUE;
2450 
2451   model = GTK_TREE_MODEL(store);
2452   gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
2453 
2454 /*  gint iiorb = 0;*/
2455 
2456   while(next)
2457   {
2458     gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, ORBITAL_SYMM, &data_sym, -1);
2459     gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, ORBITAL_NUM, &data_num, -1);
2460 
2461     if (next && sym == data_sym && num == data_num) next = FALSE;
2462     else
2463     {
2464       next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2465 /*      iiorb++;*/
2466     }
2467   }
2468 
2469   gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, ORBITAL_TYPE, &tmptext, -1);
2470 
2471   for(data_type = 0; g_strcmp0(tmptext, orbital_description[data_type]) != 0; data_type++);
2472 
2473   data_type++;
2474   if (data_type > 7) data_type = 1;
2475 
2476 
2477   gtk_list_store_set(store, &iter, ORBITAL_TYPE, orbital_description[data_type], -1);
2478   gtk_list_store_set(store, &iter, ORBITAL_TYPE, orbital_description[data_type], ORBITAL_EDITED, "*", -1);
2479 
2480   for(i = 0; i < m->ngrids; i++)
2481     if (m->grid_type[i] == ORBITAL)
2482       if (m->grid_symmetry[i] == sym && m->grid_index[i] == num)
2483       {
2484         m->orbital_type[i] = data_type;
2485         m->edited[i] = 1;
2486         luscus_gtk_multiview_redraw_list(i, data_type);
2487       }
2488 
2489   luscus_show_substaces();
2490   return data_type;
2491 }
2492 
orbital_combo_edited(GtkCellRendererText * cell,gchar * path_string,gchar * new_text,GtkListStore * list_store_combo)2493 void orbital_combo_edited(GtkCellRendererText *cell, gchar *path_string, gchar *new_text, GtkListStore *list_store_combo)
2494 {
2495   GtkTreeModel *model;
2496   GtkTreeIter iter;
2497   gboolean obtain_iter;
2498   gint i;
2499   gint osym, oind;
2500   gint oldtype, newtype;
2501 
2502   model = GTK_TREE_MODEL(store);
2503   obtain_iter = gtk_tree_model_get_iter_from_string(model, &iter, path_string);
2504 
2505   gtk_tree_model_get(model, &iter, ORBITAL_SYMM, &osym, ORBITAL_NUM, &oind, -1);
2506   for(i = 0; i < m->ngrids && m->grid_symmetry[i] != osym || m->grid_index[i] != oind; i++);
2507   oldtype = m->grid_type[i];
2508   m->edited[i] = 1;
2509 
2510   newtype = 0;
2511   while(g_strcmp0(new_text, orbital_description[newtype])) newtype++;
2512   m->orbital_type[i] = newtype;
2513 
2514   gtk_list_store_set(store, &iter, ORBITAL_TYPE, new_text, ORBITAL_EDITED, "*", -1);
2515 
2516   m->grid.iniIndex[oldtype]--;
2517   m->grid.iniIndex[newtype]++;
2518   luscus_show_substaces();
2519 }
2520 
change_orbital_type(int itype)2521 void change_orbital_type(int itype)
2522 {
2523   GtkTreeModel *model;
2524   GtkTreeIter iter;
2525   int isym, iindex;
2526   int iorb;
2527 
2528   if (gtk_tree_selection_get_selected(selection, &model, &iter))
2529   {
2530     gtk_list_store_set(store, &iter, ORBITAL_TYPE, orbital_description[itype], ORBITAL_EDITED, "*", -1);
2531     gtk_tree_model_get(model, &iter, ORBITAL_SYMM, &isym, ORBITAL_NUM, &iindex, -1);
2532     iorb = get_orbital(isym, iindex);
2533     if (iorb >= 0) m->orbital_type[iorb] = itype;
2534     m->edited[iorb] = 1;
2535     luscus_gtk_multiview_redraw_list(iorb, itype);
2536   }
2537   else printf("NO orbital selected!\n");
2538   luscus_show_substaces();
2539 }
2540 
luscus_show_substaces(void)2541 void luscus_show_substaces(void)
2542 {
2543   int i;
2544   int test[NUM_ORB_TYPES];
2545   gchar tmp[512];
2546   gchar *text;
2547   tmp[0] = 0;
2548   g_strlcat(tmp, "Subspaces:", 512);
2549   for(i = 0; i < NUM_ORB_TYPES; i++) test[i] = 0;
2550   for(i = 0; i < m->ngrids; i++)
2551     if (strstr(m->grid.titlesArr[i], "Orbital"))
2552       test[m->orbital_type[i]]++;
2553 
2554   for(i = 0; i < NUM_ORB_TYPES; i++)
2555     if (test[i])
2556     {
2557       text = g_strdup_printf(" %s:%d;", orbital_description_short[i], test[i]);
2558       g_strlcat(tmp, text, 512);
2559       g_free(text);
2560     }
2561 
2562   luscus_gtk_pop_message_from_statusbar2();
2563   luscus_gtk_push_message_to_statusbar2(tmp);
2564 }
2565 
orbital_filter_callback(GtkWidget * entry,gpointer data)2566 void orbital_filter_callback(GtkWidget *entry, gpointer data)
2567 {
2568   gchar *string;
2569   int isym, inum;
2570   string = g_strdup(gtk_entry_get_text(GTK_ENTRY(entry)));
2571 
2572 
2573   if (string[0] != '#') gtk_entry_set_text(GTK_ENTRY(entry), "ERROR: wrong filter format!");
2574   else
2575   {
2576     if (string[1] == ':')
2577     {
2578       luscus_gtk_get_filter_str(string);
2579 /*      get_filter_str(string);
2580       validate_filter();*/
2581     }
2582     else
2583     {
2584       sscanf(string+1, "%d %d", &isym, &inum);
2585 /*      printf("searching orbital %d %d\n", isym, inum);*/
2586       if (luscus_gtk_find_selected_orbital(isym, inum)) gtk_entry_set_text(GTK_ENTRY(entry), "ERROR: No such orbital!");
2587       luscus_gtk_search_orbital_in_list(isym, inum);
2588     }
2589   }
2590 
2591   g_free(string);
2592 }
2593 
luscus_gtk_get_filter_str(gchar * string)2594 void luscus_gtk_get_filter_str(gchar *string) /*this function is replacement for the "get_filter_str"*/
2595 {                                         /*this function operates on the GTK storage of orbitals*/
2596   gint i = 1, j, k;
2597   gint slen = strlen((char*) string);
2598   gchar *tmp = NULL;
2599   gboolean filter_sym = FALSE;
2600   gboolean filter_occu = FALSE;
2601   gboolean filter_index = FALSE;
2602   gboolean filter_energ = FALSE;
2603   gchar testchar;
2604   gchar *use_sym = NULL;
2605   gdouble min_energ, max_energ, min_occu, max_occu;
2606   gchar *use_index = NULL;
2607 /*  GtkTreeModel *model;*/
2608   GtkTreeIter iter, olditer;
2609   gboolean next;
2610   gboolean do_erase;
2611 
2612   gint int_data;
2613   gdouble double_data;
2614   gchar *char_data;
2615 
2616   use_sym = g_malloc(sizeof(gchar));
2617   use_sym[0] = 0;
2618   use_index = g_malloc(sizeof(gchar));
2619   use_index[0] = 0;
2620 
2621   while(i < slen)
2622   {
2623     while(string[i] != 's' && string[i] != 'o' && string[i] != 'e' && string[i] != 'i' && i < slen) i++;
2624     if (i == slen) return;
2625 
2626     testchar = string[i];
2627     for(j = 1; string[i+j] != ';' && i+j <= slen; j++)
2628     {
2629       tmp = g_realloc(tmp, (j+1) * sizeof(gchar));
2630       tmp[j-1] = string[i+j];
2631       tmp[j] = 0;
2632     }
2633     i += j;
2634 
2635     switch(testchar)
2636     {
2637       case 's':
2638         filter_sym = TRUE;
2639         k = 1;
2640         for(j = 0; tmp[j] != 0; j++)
2641           if (g_ascii_isdigit(tmp[j]))
2642           {
2643             use_sym = g_realloc(use_sym, ++k);
2644             use_sym[k-2] = tmp[j];
2645             use_sym[k-1] = 0;
2646           }
2647         break;
2648       case 'o':
2649         filter_occu = TRUE;
2650         min_occu = g_ascii_strtod(tmp, NULL);
2651 /*      max_occu = g_ascii_strtod(index(tmp,':')+1, NULL);*/
2652         max_occu = g_ascii_strtod(strstr(tmp,":")+1, NULL);
2653         break;
2654       case 'e':
2655         filter_energ = TRUE;
2656         min_energ = g_ascii_strtod(tmp, NULL);
2657 /*      max_energ = g_ascii_strtod(index(tmp,':')+1, NULL);*/
2658         max_energ = g_ascii_strtod(strstr(tmp,":")+1, NULL);
2659         break;
2660       case 'i':
2661         filter_index = TRUE;
2662         k = 1;
2663         for(j = 0; tmp[j] != 0; j++)
2664           if (tmp[j] == 'F' || tmp[j] == 'I' || tmp[j] == '1' || tmp[j] == '2' || tmp[j] == '3' || tmp[j] == 'S' || tmp[j] == 'D' || tmp[j] == 'U')
2665           {
2666             use_index = g_realloc(use_index, ++k);
2667             use_index[k-2] = tmp[j];
2668             use_index[k-1] = 0;
2669           }
2670         break;
2671       default: break;
2672     }
2673     g_free(tmp);
2674     tmp = NULL;
2675   }
2676 
2677   /*Now delete orbitals that doesn't match criteria*/
2678 
2679   if (filter_sym)
2680   {
2681     if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) return;
2682     next = TRUE;
2683 
2684     while(next)
2685     {
2686       olditer = iter;
2687       next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); /*first move to the next list element in order not to delete current element (current iter might be lost)*/
2688 
2689       gtk_tree_model_get(GTK_TREE_MODEL(store), &olditer, ORBITAL_SYMM, &int_data, -1);
2690       do_erase = TRUE;
2691 
2692       for(i = 0; use_sym[i] != 0; i++)
2693       {
2694         if (use_sym[i] - 48 == int_data) /* this are ASCII representations! */
2695           do_erase = FALSE;
2696       }
2697 
2698       if (do_erase) gtk_list_store_remove(store, &olditer);
2699     }
2700   }
2701   if (filter_occu)
2702   {
2703     if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) return;
2704     next = TRUE;
2705 
2706     while(next)
2707     {
2708       olditer = iter;
2709       next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2710 
2711       gtk_tree_model_get(GTK_TREE_MODEL(store), &olditer, ORBITAL_OCC, &double_data, -1);
2712 
2713       if (double_data < max_occu && double_data > min_occu) do_erase = FALSE;
2714       else do_erase = TRUE;
2715 
2716       if (do_erase) gtk_list_store_remove(store, &olditer);
2717     }
2718   }
2719   if (filter_index)
2720   {
2721     if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) return;
2722     next = TRUE;
2723 
2724     while(next)
2725     {
2726       olditer = iter;
2727       next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2728 
2729       gtk_tree_model_get(GTK_TREE_MODEL(store), &olditer, ORBITAL_TYPE, &char_data, -1);
2730       do_erase = TRUE;
2731 
2732       for(i = 0; use_index[i] != 0; i++)
2733       {
2734         switch(use_index[i])
2735 	{
2736 	  case 'F': if (g_strcmp0(char_data, "frozen") == 0) do_erase = FALSE; break;
2737 	  case 'I': if (g_strcmp0(char_data, "inactive") == 0) do_erase = FALSE; break;
2738 	  case '1': if (g_strcmp0(char_data, "RAS 1") == 0) do_erase = FALSE; break;
2739 	  case '2': if (g_strcmp0(char_data, "RAS 2") == 0) do_erase = FALSE; break;
2740 	  case '3': if (g_strcmp0(char_data, "RAS 3") == 0) do_erase = FALSE; break;
2741 	  case 'S': if (g_strcmp0(char_data, "secondary") == 0) do_erase = FALSE; break;
2742 	  case 'D': if (g_strcmp0(char_data, "deleted") == 0) do_erase = FALSE; break;
2743 	  case 'U': if (g_strcmp0(char_data, "unknown") == 0) do_erase = FALSE; break;
2744 	}
2745       }
2746 
2747       if (do_erase) gtk_list_store_remove(store, &olditer);
2748     }
2749   }
2750   if (filter_energ)
2751   {
2752     if (!gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter)) return;
2753     next = TRUE;
2754 
2755     while(next)
2756     {
2757       olditer = iter;
2758       next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2759 
2760       gtk_tree_model_get(GTK_TREE_MODEL(store), &olditer, ORBITAL_ENERG, &double_data, -1);
2761 
2762       if (double_data < max_energ && double_data > min_energ) do_erase = FALSE;
2763       else do_erase = TRUE;
2764 
2765       if (do_erase) gtk_list_store_remove(store, &olditer);
2766     }
2767   }
2768 
2769   g_free(use_sym);
2770   g_free(use_index);
2771   return;
2772 }
2773 
luscus_gtk_search_orbital_in_list(gint isym,gint inum)2774 void luscus_gtk_search_orbital_in_list(gint isym, gint inum)
2775 {
2776   gboolean next = TRUE;
2777   gint tsym, tnum;
2778   GtkTreeIter iter;
2779 
2780   gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
2781 
2782   while(next)
2783   {
2784     gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, ORBITAL_SYMM, &tsym, -1);
2785     gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, ORBITAL_NUM, &tnum, -1);
2786 
2787     if (next && isym == tsym && inum == tnum)
2788     {
2789       gtk_tree_selection_select_iter(selection, &iter);
2790       next = FALSE;
2791     }
2792 
2793     next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2794   }
2795 
2796 }
2797 
luscus_gtk_select_orbital_up(void)2798 void luscus_gtk_select_orbital_up(void)
2799 {
2800   GtkTreeModel *mod;
2801   GtkTreeIter iter;
2802   gboolean next;
2803   char lin[82];
2804   int orb_symm, orb_index;
2805   double orb_occ, orb_energ;
2806   gchar *orb_type, *orb_edit;
2807   if (!gtk_tree_selection_get_selected(selection, &mod, NULL))
2808   { /*none selected!*/
2809     gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
2810     gtk_tree_selection_select_iter(selection, &iter);
2811     return;
2812   }
2813 
2814   if (gtk_tree_selection_get_selected(selection, &mod, &iter))
2815     next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2816   if (next)
2817     gtk_tree_selection_select_iter(selection, &iter);
2818   else /*last orbital is selected; goto first*/
2819   {
2820     gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
2821     gtk_tree_selection_select_iter(selection, &iter);
2822   }
2823   gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
2824                                                   ORBITAL_TYPE, &orb_type,
2825                                                   ORBITAL_SYMM, &orb_symm,
2826                                                   ORBITAL_NUM,  &orb_index,
2827                                                   ORBITAL_ENERG,&orb_energ,
2828                                                   ORBITAL_OCC,  &orb_occ,
2829                                                   ORBITAL_EDITED,&orb_edit,  -1);
2830   snprintf(lin, 82, "%1s orbital sym: %2d index: %2d energy: %12.4f occ: %5.2f type: %s", orb_edit, orb_symm, orb_index, orb_energ, orb_occ, orb_type);
2831 
2832   /*print orbital data*/
2833   luscus_gtk_pop_message_from_statusbar1();
2834   luscus_gtk_push_message_to_statusbar1(lin);
2835 }
2836 
luscus_gtk_select_orbital_down(void)2837 void luscus_gtk_select_orbital_down(void)
2838 {
2839   GtkTreeIter iter, last_iter;
2840   GtkTreeModel *mod;
2841   GtkTreePath *path;
2842   gboolean next;
2843   char lin[82];
2844   int orb_symm, orb_index;
2845   double orb_occ, orb_energ;
2846   gchar *orb_type, *orb_edit;
2847  /* gint nrow;*/
2848 
2849   if (gtk_tree_selection_get_selected(selection, &mod, NULL))
2850   {/*there is selected row*/
2851     gtk_tree_selection_get_selected(selection, &mod, &iter);
2852     path = gtk_tree_model_get_path(GTK_TREE_MODEL(store), &iter);
2853     if (path) next = gtk_tree_path_prev(path);
2854 
2855     if (next)
2856     {
2857       gtk_tree_model_get_iter(GTK_TREE_MODEL(store), &iter, path);
2858       gtk_tree_path_free(path);
2859     }
2860     else /*first orbital is selected -> goto last*/
2861     {
2862       gtk_tree_path_free(path);
2863 
2864       next = TRUE;
2865       while(next) /*rewind to last it might be CPU intensive if the list is very large!*/
2866       {
2867         last_iter = iter;
2868         next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2869       }
2870       iter = last_iter;
2871     }
2872   }
2873   else
2874   { /*select last row*/
2875     gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter); /*goto first*/
2876 
2877     next = TRUE;
2878     while(next) /*rewind to last it might be CPU intensive if the list is very large!*/
2879     {
2880       last_iter = iter;
2881       next = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter);
2882     }
2883     iter = last_iter;
2884   }
2885   gtk_tree_selection_select_iter(selection, &iter);
2886 
2887   /*print orbital data*/
2888   gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
2889                                                   ORBITAL_TYPE, &orb_type,
2890                                                   ORBITAL_SYMM, &orb_symm,
2891                                                   ORBITAL_NUM,  &orb_index,
2892                                                   ORBITAL_ENERG,&orb_energ,
2893                                                   ORBITAL_OCC,  &orb_occ,
2894                                                   ORBITAL_EDITED,&orb_edit,  -1);
2895   snprintf(lin, 82, "%1s orbital sym: %2d index: %2d energy: %12.4f occ: %5.2f type: %s", orb_edit, orb_symm, orb_index, orb_energ, orb_occ, orb_type);
2896 
2897   /*print orbital data*/
2898   luscus_gtk_pop_message_from_statusbar1();
2899   luscus_gtk_push_message_to_statusbar1(lin);
2900 }
2901 
luscus_gtk_find_selected_orbital(gint test_sym,gint test_orbnum)2902 static gboolean luscus_gtk_find_selected_orbital(gint test_sym, gint test_orbnum)
2903 {
2904   gint iiorb = 0;
2905 /*  gint data_sym = 0, data_orbnum = 0, data_type;
2906   gdouble data_energy, data_occu;*/
2907   gboolean next = TRUE;
2908 
2909   while(next)
2910   {
2911     if (m->grid_symmetry[iiorb] == test_sym && m->grid_index[iiorb] == test_orbnum) next = FALSE;
2912     else iiorb++;
2913     if (iiorb >= m->ngrids) return TRUE;
2914   }
2915 
2916   iorb = iiorb;
2917   do_load_grid();
2918 
2919   rerender_3d();
2920 
2921   redraw();
2922   return FALSE;
2923 }
2924 
show_custom_grid(GtkWidget * button,gpointer data)2925 void show_custom_grid(GtkWidget *button, gpointer data)
2926 {
2927   iorb = GPOINTER_TO_INT(data);
2928   gtk_tree_selection_unselect_all(selection);
2929   do_load_grid();
2930   rerender_3d();
2931   redraw();
2932 }
2933 
get_orbital(int isym,int iindex)2934 int get_orbital(int isym, int iindex)
2935 {
2936   int i;
2937 
2938   for(i = 0; i < m->ngrids; i++)
2939     if (isym == m->grid_symmetry[i] && iindex == m->grid_index[i]) return i;
2940 
2941   /*orbital is not found!*/
2942   return -1;
2943 }
2944 
luscus_gtk_update_3Dobject_info(void)2945 void luscus_gtk_update_3Dobject_info(void)
2946 {
2947   int i, j;
2948   gchar buff1[20];
2949   GdkColor color;
2950 
2951   /*destroy all gtk widgets that describe 3D objects*/
2952   for (i = 0; i < n_3D_desc; i++)
2953     if (GTK_IS_WIDGET(gtk_3d_desc[i].button))
2954       gtk_widget_destroy(gtk_3d_desc[i].button);
2955   g_free(gtk_3d_desc);
2956 
2957   n_3D_desc = m->nsphere + m->nvector + m->ntriangle + m->nsurf + m->ncells + m->ntextboxes;
2958   gtk_3d_desc = g_malloc(n_3D_desc * sizeof(GTK_3D_DESC));
2959 
2960   /*sphere*/
2961   j = 0;
2962   for(i = 0; i < m->nsphere; i++, j++)
2963   {
2964     g_snprintf(buff1, 20, "sphere #%d", i+1);
2965     gtk_3d_desc[j].i3dtype=SPHERE;
2966     gtk_3d_desc[j].inum = i;
2967     gtk_3d_desc[j].button = gtk_button_new_with_label(buff1);
2968     gtk_box_pack_start(GTK_BOX(vbox_3Dobject), gtk_3d_desc[j].button, FALSE, FALSE, 0);
2969     color.red = (guint16) (m->sphere_color[i][0] * (gfloat) G_MAXUINT16);
2970     color.green = (guint16) (m->sphere_color[i][1] * (gfloat) G_MAXUINT16);
2971     color.blue = (guint16) (m->sphere_color[i][2] * (gfloat) G_MAXUINT16);
2972     gtk_widget_modify_bg(GTK_WIDGET(gtk_3d_desc[j].button), GTK_STATE_NORMAL, &color);
2973     g_signal_connect(G_OBJECT(gtk_3d_desc[j].button), "clicked", G_CALLBACK(luscus_gtk_modify_3Dobject), (gpointer) (&gtk_3d_desc[j]));
2974 
2975     gtk_widget_show(gtk_3d_desc[j].button);
2976   }
2977   /*vector*/
2978   for(i = 0; i < m->nvector; i++, j++)
2979   {
2980     g_snprintf(buff1, 20, "vector #%d", i+1);
2981     gtk_3d_desc[j].i3dtype=VECTOR;
2982     gtk_3d_desc[j].inum = i;
2983     gtk_3d_desc[j].button = gtk_button_new_with_label(buff1);
2984     gtk_box_pack_start(GTK_BOX(vbox_3Dobject), gtk_3d_desc[j].button, FALSE, FALSE, 0);
2985     color.red = (guint16) (m->vector_color[i][0] * (gfloat) G_MAXUINT16);
2986     color.green = (guint16) (m->vector_color[i][1] * (gfloat) G_MAXUINT16);
2987     color.blue = (guint16) (m->vector_color[i][2] * (gfloat) G_MAXUINT16);
2988     gtk_widget_modify_bg(GTK_WIDGET(gtk_3d_desc[j].button), GTK_STATE_NORMAL, &color);
2989     g_signal_connect(G_OBJECT(gtk_3d_desc[j].button), "clicked", G_CALLBACK(luscus_gtk_modify_3Dobject), (gpointer) (&gtk_3d_desc[j]));
2990     gtk_widget_show(gtk_3d_desc[j].button);
2991   }
2992   /*triangle*/
2993   for(i = 0; i < m->ntriangle; i++, j++)
2994   {
2995     g_snprintf(buff1, 20, "triangle #%d", i+1);
2996     gtk_3d_desc[j].i3dtype=TRIANGLE;
2997     gtk_3d_desc[j].inum = i;
2998     gtk_3d_desc[j].button = gtk_button_new_with_label(buff1);
2999     gtk_box_pack_start(GTK_BOX(vbox_3Dobject), gtk_3d_desc[j].button, FALSE, FALSE, 0);
3000     color.red = (guint16) (m->triangle_color[i][0] * (gfloat) G_MAXUINT16);
3001     color.green = (guint16) (m->triangle_color[i][1] * (gfloat) G_MAXUINT16);
3002     color.blue = (guint16) (m->triangle_color[i][2] * (gfloat) G_MAXUINT16);
3003     gtk_widget_modify_bg(GTK_WIDGET(gtk_3d_desc[j].button), GTK_STATE_NORMAL, &color);
3004     g_signal_connect(G_OBJECT(gtk_3d_desc[j].button), "clicked", G_CALLBACK(luscus_gtk_modify_3Dobject), (gpointer) (&gtk_3d_desc[j]));
3005     gtk_widget_show(gtk_3d_desc[j].button);
3006   }
3007   /*surface*/
3008   for(i = 0; i < m->nsurf; i++, j++)
3009   {
3010     g_snprintf(buff1, 20, "surface #%d", i+1);
3011     gtk_3d_desc[j].i3dtype=SURFACE;
3012     gtk_3d_desc[j].inum = i;
3013     gtk_3d_desc[j].button = gtk_button_new_with_label(buff1);
3014     gtk_box_pack_start(GTK_BOX(vbox_3Dobject), gtk_3d_desc[j].button, FALSE, FALSE, 0);
3015     color.red = (guint16) (m->surf_color[i][0] * (gfloat) G_MAXUINT16);
3016     color.green = (guint16) (m->surf_color[i][1] * (gfloat) G_MAXUINT16);
3017     color.blue = (guint16) (m->surf_color[i][2] * (gfloat) G_MAXUINT16);
3018     gtk_widget_modify_bg(GTK_WIDGET(gtk_3d_desc[j].button), GTK_STATE_NORMAL, &color);
3019     g_signal_connect(G_OBJECT(gtk_3d_desc[j].button), "clicked", G_CALLBACK(luscus_gtk_modify_3Dobject), (gpointer) (&gtk_3d_desc[j]));
3020     gtk_widget_show(gtk_3d_desc[j].button);
3021   }
3022   /*cell*/
3023   for(i = 0; i < m->ncells; i++, j++)
3024   {
3025     printf("PUTTING CELL BUTTON #%d\n", i); fflush(stdout);
3026     gtk_3d_desc[j].i3dtype=CELL;
3027     gtk_3d_desc[j].inum = i;
3028     g_snprintf(buff1, 20, "cell #%d", i+1);
3029     gtk_3d_desc[j].button = gtk_button_new_with_label(buff1);
3030     gtk_box_pack_start(GTK_BOX(vbox_3Dobject), gtk_3d_desc[j].button, FALSE, FALSE, 0);
3031     color.red = (guint16) (m->cell_color[i][0] * (gfloat) G_MAXUINT16);
3032     color.green = (guint16) (m->cell_color[i][1] * (gfloat) G_MAXUINT16);
3033     color.blue = (guint16) (m->cell_color[i][2] * (gfloat) G_MAXUINT16);
3034     gtk_widget_modify_bg(GTK_WIDGET(gtk_3d_desc[j].button), GTK_STATE_NORMAL, &color);
3035     g_signal_connect(G_OBJECT(gtk_3d_desc[j].button), "clicked", G_CALLBACK(luscus_gtk_modify_3Dobject), (gpointer) (&gtk_3d_desc[j]));
3036     gtk_widget_show(gtk_3d_desc[j].button);
3037   }
3038 
3039 #ifdef EBUG
3040   printf("checking textboxes\n");
3041 #endif
3042   /*textboxes*/
3043   for(i = 0; i < m->ntextboxes; i++, j++)
3044   {
3045 #ifdef EBUG
3046     printf("textbox #%d\n", i);
3047 #endif
3048     gtk_3d_desc[j].i3dtype=TEXTBOX;
3049     gtk_3d_desc[j].inum = i;
3050     g_snprintf(buff1, 20, "textbox #%d", i+1);
3051     gtk_3d_desc[j].button = gtk_button_new_with_label(buff1);
3052     gtk_box_pack_start(GTK_BOX(vbox_3Dobject), gtk_3d_desc[j].button, FALSE, FALSE, 0);
3053 
3054     color.red = (guint16) (m->textboxes[i].color[0] * (gfloat) G_MAXUINT16);
3055     color.green = (guint16) (m->textboxes[i].color[1] * (gfloat) G_MAXUINT16);
3056     color.blue = (guint16) (m->textboxes[i].color[2] * (gfloat) G_MAXUINT16);
3057 
3058     gtk_widget_modify_text(GTK_WIDGET(gtk_3d_desc[j].button), GTK_STATE_NORMAL, &color);
3059     g_signal_connect(G_OBJECT(gtk_3d_desc[j].button), "clicked", G_CALLBACK(luscus_gtk_modify_3Dobject), (gpointer) (&gtk_3d_desc[j]));
3060     gtk_widget_show(gtk_3d_desc[j].button);
3061     if (!m->textboxes[i].pixtext.pixels)
3062       draw_pixdata_textbox(i);
3063   }
3064 
3065 /*int n_3D_desc = 0;
3066 GTK_3D_DESC *gtk_3d_desc;*/
3067 }
3068 
luscus_start_calculation(GtkWidget * menu,gint icalc)3069 void luscus_start_calculation(GtkWidget* menu, gint icalc)
3070 {
3071   gchar *calc_filename = NULL;
3072   gchar **gargv;
3073   GtkWidget **calc_wgs = calc_keys[icalc];
3074   char num[4];
3075   int i, ic = 0, iarg = 0;
3076 
3077   if (calc_defs[icalc].file_description) gargv = (gchar**) g_malloc((3 + 2 * (calc_defs[icalc].nargs + 1)) * sizeof(gchar*));
3078   else gargv = (gchar**) g_malloc((3 + 2 * calc_defs[icalc].nargs) * sizeof(gchar*));
3079 
3080   /*1. determine file name*/
3081   do
3082   {
3083     if (calc_filename) g_free(calc_filename);
3084     ic++;
3085     sprintf(num, "%03d", ic);
3086 #ifdef WINDOWS
3087     calc_filename = g_strconcat("\"", g_get_current_dir(), "\\","newfile_", num,".lus", "\"", NULL);
3088 #else
3089     calc_filename = g_strconcat(g_get_current_dir(), "/newfile_", num,".lus", NULL);
3090 #endif
3091   }
3092   while(get_file_exist(calc_filename));
3093 
3094 
3095   /*1a. setup plugin name*/
3096   gargv[0] = (gchar*) calc_defs[icalc].plugin_name;
3097   iarg++;
3098 
3099   /*2. determine name of the addtional file if it exists*/
3100 
3101 printf("file_description = |%s| = %ld\n", calc_defs[icalc].file_description, (long) calc_defs[icalc].file_description);
3102 
3103   if (calc_defs[icalc].file_description)
3104   {
3105     gargv[iarg++] = (gchar*) "-f";
3106 
3107     gargv[iarg++] = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(calc_wgs[0]));
3108     if(gargv[iarg-1] == NULL)
3109     {
3110       make_warning("No file is selected, calculation can not proceed!");
3111       g_free(gargv);
3112       g_free(calc_filename);
3113       return;
3114     }
3115   }
3116 
3117 #ifdef EBUG
3118   printf("Setting all parameters\n");
3119 #endif
3120 
3121   /*3. set all parameters*/
3122   for(i = 0; i < calc_defs[icalc].nargs; i++)
3123   {
3124     gargv[iarg++] = (gchar*) calc_defs[icalc].argsym[i];
3125 
3126     if(calc_defs[icalc].file_description)
3127       gargv[iarg++] = (gchar*) gtk_entry_get_text(GTK_ENTRY(calc_wgs[i+1]));
3128     else
3129       gargv[iarg++] = (gchar*) gtk_entry_get_text(GTK_ENTRY(calc_wgs[i]));
3130   }
3131 
3132   /*4. save file*/
3133 
3134 #ifdef EBUG
3135   printf("saving file: |%s|\n", calc_filename); fflush(stdout);
3136 #endif
3137   save_gv_file(calc_filename);
3138 #ifdef EBUG
3139   printf("file |%s| saved\n", calc_filename); fflush(stdout);
3140 #endif
3141 
3142   gargv[iarg++] = (gchar*) calc_filename;
3143   gargv[iarg++] = (gchar*) NULL;
3144 
3145   /*5. execute script*/
3146   set_calculation(gargv, calc_filename, calc_defs[icalc].path);
3147 
3148   g_free(gargv);
3149 /*  g_free(calc_filename);*/
3150 }
3151 
3152 
3153 
geo_play_button_play(int mode)3154 void geo_play_button_play(int mode)
3155 {
3156   GtkWidget *image;
3157   if (mode == 0) image = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PAUSE, GTK_ICON_SIZE_BUTTON);
3158   else image = gtk_image_new_from_stock(GTK_STOCK_MEDIA_PLAY, GTK_ICON_SIZE_BUTTON);
3159   gtk_button_set_image(GTK_BUTTON(geo_play_button), image);
3160 }
3161 
3162 /*typedef struct gtk_3d_description
3163 {
3164   GtkWidget *button;
3165   char i3dtype;
3166   int inum;
3167 } GTK_3D_DESC;*/
3168 
3169 
set_spin_button_bond_value(double newval)3170 void set_spin_button_bond_value(double newval)
3171 {
3172   gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_bond), newval);
3173 }
3174 
set_spin_button_angle_value(double newval)3175 void set_spin_button_angle_value(double newval)
3176 {
3177   gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_angle), newval);
3178 }
3179 
set_spin_button_dihedral_value(double newval)3180 void set_spin_button_dihedral_value(double newval)
3181 {
3182   gtk_spin_button_set_value(GTK_SPIN_BUTTON(spin_tors), newval);
3183 }
3184 
3185