atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_chains.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'w_chains.c'
24*
25* Contains:
26*
27
28 - The functions to create the chain(s) tab for the advanced environments window
29
30*
31* List of functions:
32
33 gchar * chain_atoms (project * this_proj, int step, int size, int cid, gboolean to_file);
34
35 int get_cmin (project * this_proj, int step);
36 int get_cmax (project * this_proj, int step);
37
38 void fill_chains_model (GtkTreeStore * store, project * this_proj);
39 void chains_set_markup (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
40 void add_this_chain_to_search_tree (project * this_proj);
41
42 G_MODULE_EXPORT void on_select_chains (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data);
43 G_MODULE_EXPORT void update_chains_search (GtkEntry * res, gpointer data);
44 G_MODULE_EXPORT void run_save_chains_to_file (GtkNativeDialog * info, gint response_id, gpointer data);
45 G_MODULE_EXPORT void run_save_chains_to_file (GtkDialog * info, gint response_id, gpointer data);
46 G_MODULE_EXPORT void save_chains_to_file (GtkButton * but, gpointer data);
47
48 GtkWidget * create_chains_tree (project * this_proj, gboolean fill_this);
49 GtkWidget * create_chains_search (project * this_proj);
50 GtkWidget * chains_tab (glwin * view);
51
52*/
53
54#include "global.h"
55#include "interface.h"
56#include "glview.h"
57#include "glwindow.h"
58
59extern const gchar * dfi[2];
60extern void rings_set_visible (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
61
71G_MODULE_EXPORT void on_select_chains (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
72{
73 tint * dat = (tint * )data;
74 gboolean saved_label[2];
75 int i, j, c, s, v, u, a, b;
76 opengl_project_changed(dat -> a);
77 coord_edition * coord = opengl_project -> modelgl -> coord_win;
78 b = (opengl_project -> steps > 1) ? 1: 0;
79 c = dat -> b;
80 if (gtk_cell_renderer_toggle_get_active(cell_renderer))
81 {
82 v = 0;
83 }
84 else
85 {
86 v = 1;
87 }
88 GtkTreeIter iter;
89 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
90 gtk_tree_model_get_iter (GTK_TREE_MODEL(coord -> chains_model), & iter, path);
91 gtk_tree_store_set (coord -> chains_model, & iter, c, v, -1);
92 if (b)
93 {
94 gtk_tree_model_get (GTK_TREE_MODEL(coord -> chains_model), & iter, 0, & s, -1);
95 s = - s - 1;
96 }
97 else
98 {
99 s = 0;
100 }
101 gtk_tree_model_get (GTK_TREE_MODEL(coord -> chains_model), & iter, b, & i, -1);
102 i = -i;
103 gtk_tree_model_get (GTK_TREE_MODEL(coord -> chains_model), & iter, b+1, & j, -1);
104 switch (c-b)
105 {
106 case 2:
107 // Viz
108 for (u=0; u<i; u++)
109 {
110 a = opengl_project -> modelgl -> all_chains[s][i-1][j-1][u];
111#ifdef GTK4
112 if (opengl_project -> atoms[s][a].show[0] != v) show_hide_this_atom (NULL, NULL, GINT_TO_POINTER(a));
113#else
114 if (opengl_project -> atoms[s][a].show[0] != v) show_hide_this_atom (NULL, GINT_TO_POINTER(a));
115#endif // GTK4
116 }
117 break;
118 case 3:
119 // Label
120 for (u=0; u<i; u++)
121 {
122 a = opengl_project -> modelgl -> all_chains[s][i-1][j-1][u];
123 opengl_project -> atoms[s][a].label[0] = opengl_project -> atoms[s][a].label[1] = v;
124 }
125 opengl_project -> modelgl -> create_shaders[LABEL] = TRUE;
126 break;
127 case 4:
128 // Pick
129 for (u=0; u<i; u++)
130 {
131 a = opengl_project -> modelgl -> all_chains[s][i-1][j-1][u];
132 saved_label[0] = opengl_project -> atoms[s][a].label[0];
133 saved_label[1] = opengl_project -> atoms[s][a].label[1];
134#ifdef GTK4
135 if (opengl_project -> atoms[s][a].pick[0] != v) select_unselect_this_atom (NULL, NULL, GINT_TO_POINTER(a));
136#else
137 if (opengl_project -> atoms[s][a].pick[0] != v) select_unselect_this_atom (NULL, GINT_TO_POINTER(a));
138#endif // GTK4
139 opengl_project -> atoms[s][a].label[0] = saved_label[0];
140 opengl_project -> atoms[s][a].label[1] = saved_label[1];
141 }
142 break;
143 }
144 update (opengl_project -> modelgl);
145}
146
158gchar * chain_atoms (project * this_proj, int step, int size, int cid, gboolean to_file)
159{
160 gchar * str;
161 int aid, sid;
162 aid = this_proj -> modelgl -> all_chains[step][size][cid][0];
163 sid = this_proj -> atoms[step][aid].sp;
164 int i;
165 if (to_file)
166 {
167 str = g_strdup_printf ("%s%d", exact_name(this_proj -> chemistry -> label[sid]), aid+1);
168 for (i=1; i<size+1; i++)
169 {
170 aid = this_proj -> modelgl -> all_chains[step][size][cid][i];
171 sid = this_proj -> atoms[step][aid].sp;
172 str = g_strdup_printf ("%s - %s%d", str, exact_name(this_proj -> chemistry -> label[sid]), aid+1);
173 }
174 }
175 else
176 {
177 str = g_strdup_printf ("%s<sub>%d</sub>", exact_name(this_proj -> chemistry -> label[sid]), aid+1);
178 for (i=1; i<size+1; i++)
179 {
180 aid = this_proj -> modelgl -> all_chains[step][size][cid][i];
181 sid = this_proj -> atoms[step][aid].sp;
182 str = g_strdup_printf ("%s-%s<sub>%d</sub>", str, exact_name(this_proj -> chemistry -> label[sid]), aid+1);
183 }
184 }
185 return str;
186}
187
196void fill_chains_model (GtkTreeStore * store, project * this_proj)
197{
198 GtkTreeIter step_level, size_level, chain_level;
199 int h, i, j, k, l;
200 gchar * str;
201 if (this_proj -> coord -> totcoord[9])
202 {
203 for (h=0; h < this_proj -> steps; h++)
204 {
205 if (this_proj -> steps > 1)
206 {
207 gtk_tree_store_append (store, & step_level, NULL);
208 gtk_tree_store_set (store, & step_level, 0, h+1,
209 1, 0,
210 2, 0,
211 3, 0,
212 4, 0,
213 5, 0, -1);
214 }
215 for (i=0; i < this_proj -> coord -> totcoord[9]; i++)
216 {
217 j = this_proj -> coord -> geolist[9][0][i];
218 k = this_proj -> modelgl -> num_chains[h][j-1];
219 if (this_proj -> steps > 1 && k > 0)
220 {
221 gtk_tree_store_append (store, & size_level, & step_level);
222 gtk_tree_store_set (store, & size_level, 0, 0,
223 1, j,
224 2, 0,
225 3, 0,
226 4, 0,
227 5, 0, -1);
228 }
229 else if (this_proj -> steps == 1)
230 {
231 gtk_tree_store_append (store, & size_level, NULL);
232 gtk_tree_store_set (store, & size_level, 0, j,
233 1, 0,
234 2, 0,
235 3, 0,
236 4, 0, -1);
237 }
238 for (l=0; l<k; l++)
239 {
240 gtk_tree_store_append (store, & chain_level, & size_level);
241 str = chain_atoms (this_proj, h, j-1, l, FALSE);
242 if (this_proj -> steps > 1)
243 {
244 gtk_tree_store_set (store, & chain_level, 0, -(h+1),
245 1, -j,
246 2, l+1,
247 3, FALSE,
248 4, FALSE,
249 5, FALSE,
250 6, str, -1);
251 }
252 else
253 {
254 gtk_tree_store_set (store, & chain_level, 0, -j,
255 1, l+1,
256 2, FALSE,
257 3, FALSE,
258 4, FALSE,
259 5, str, -1);
260 }
261 g_free (str);
262 }
263 }
264 }
265 }
266}
267
279void chains_set_markup (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
280{
281 int steps = GPOINTER_TO_INT(data);
282 set_renderer_markup (mod, iter, renderer, (steps) ? 6 : 5);
283}
284
293GtkWidget * create_chains_tree (project * this_proj, gboolean fill_this)
294{
295 int i, j, k;
296 GtkTreeViewColumn * chains_col[7];
297 GtkCellRenderer * chains_cell[7];
298 gchar * ctitle[7]={i18n("MD step"), i18n("Chain(s) size"), i18n("Id."), i18n("Show"), i18n("Label"), i18n("Pick"), i18n("Atoms")};
299 gchar * ctype[7]={"text", "text", "text", "active", "active", "active", "text"};
300 GType col_type_ms[7]={G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING};
301 GType col_type_ss[6]={G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING};
302
303 coord_edition * coord = this_proj -> modelgl -> coord_win;
304 j = (this_proj -> steps > 1) ? 1: 0;
305 k = (this_proj -> steps > 1) ? 0: 1;
306 coord -> chains_model = gtk_tree_store_newv (6+j, (j) ? col_type_ms : col_type_ss);
307 if (fill_this) fill_chains_model (coord -> chains_model, this_proj);
308 GtkWidget * chains_tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL(coord -> chains_model));
309 for (i=0; i<6+j; i++)
310 {
311 if (i < 2+j || i > 4+j)
312 {
313 chains_cell[i] = gtk_cell_renderer_text_new ();
314 }
315 else
316 {
317 chains_cell[i] = gtk_cell_renderer_toggle_new ();
318 g_signal_connect (G_OBJECT(chains_cell[i]), "toggled", G_CALLBACK(on_select_chains), & this_proj -> modelgl -> colorp[i][0]);
319 }
320 gtk_cell_renderer_set_fixed_size (chains_cell[i], -1, 25);
321 chains_col[i] = gtk_tree_view_column_new_with_attributes (_(ctitle[i+k]), chains_cell[i], ctype[i+k], i, NULL);
322 gtk_tree_view_append_column(GTK_TREE_VIEW(chains_tree), chains_col[i]);
323 gtk_tree_view_column_set_alignment (chains_col[i], 0.5);
324 gtk_tree_view_column_set_cell_data_func (chains_col[i], chains_cell[i], rings_set_visible, & this_proj -> modelgl -> colorp[i][0], NULL);
325 if (i > 4+j) gtk_tree_view_column_set_cell_data_func (chains_col[i], chains_cell[i], chains_set_markup, GINT_TO_POINTER(j), NULL);
326 }
327 return chains_tree;
328}
329
338{
339 GtkTreeIter step_level, size_level, chain_level;
340 GtkTreeIter new_level;
341 coord_edition * coord = this_proj -> modelgl -> coord_win;
342 GtkTreeStore * store = (GtkTreeStore *) coord -> chains_model;
343 GtkTreeModel * mod = GTK_TREE_MODEL(coord -> chains_model);
344 gboolean valid;
345 gboolean insert = TRUE;
346 int g, h, i, j, k, l, m;
347 gchar * str;
348 int prepend = 0;
349 if (this_proj -> steps > 1)
350 {
351 valid = gtk_tree_model_get_iter_first(mod, & step_level);
352 while (valid)
353 {
354 gtk_tree_model_get (mod, & step_level, 0, & g, -1);
355 if (g > coord -> cst)
356 {
357 prepend = 1;
358 valid = FALSE;
359 }
360 else if (g == coord -> cst)
361 {
362 if (gtk_tree_model_iter_has_child (mod, &step_level))
363 {
364 h = gtk_tree_model_iter_n_children (mod, &step_level);
365 for (i=0; i<h; i++)
366 {
367 if (gtk_tree_model_iter_nth_child (mod, &size_level, &step_level, i))
368 {
369 gtk_tree_model_get (mod, &size_level, 1, & j, -1);
370 if (j > coord -> csz)
371 {
372 prepend = 3;
373 valid = FALSE;
374 break;
375 }
376 else if (j == coord -> csz)
377 {
378 if (gtk_tree_model_iter_has_child (mod, &size_level))
379 {
380 k = gtk_tree_model_iter_n_children (mod, &size_level);
381 for (l=0; l<k; l++)
382 {
383 if (gtk_tree_model_iter_nth_child (mod, &chain_level, &size_level, l))
384 {
385 gtk_tree_model_get (mod, &chain_level, 2, & m, -1);
386 if (m > coord -> ch)
387 {
388 prepend = 5;
389 valid = FALSE;
390 break;
391 }
392 else if (m == coord -> ch)
393 {
394 insert = valid = FALSE;
395 break;
396 }
397 }
398 }
399 if (valid)
400 {
401 prepend = 4;
402 valid = FALSE;
403 break;
404 }
405 }
406 }
407 }
408 }
409 if (valid)
410 {
411 prepend = 2;
412 valid = FALSE;
413 }
414 }
415 }
416 else
417 {
418 valid = gtk_tree_model_iter_next(mod, & step_level);
419 }
420 }
421 if (insert)
422 {
423 str = chain_atoms (this_proj, coord -> cst-1, coord -> csz-1, coord -> ch-1, FALSE);
424 switch (prepend)
425 {
426 case 0:
427 gtk_tree_store_append (store, & step_level, NULL);
428 gtk_tree_store_set (store, & step_level, 0, coord -> cst,
429 1, 0,
430 2, 0,
431 3, 0,
432 4, 0,
433 5, 0, -1);
434 gtk_tree_store_append (store, & size_level, & step_level);
435 gtk_tree_store_set (store, & size_level, 0, 0,
436 1, coord -> csz,
437 2, 0,
438 3, 0,
439 4, 0,
440 5, 0, -1);
441 gtk_tree_store_append (store, & chain_level, & size_level);
442 gtk_tree_store_set (store, & chain_level, 0, -coord -> cst,
443 1, -coord -> csz,
444 2, coord -> ch,
445 3, FALSE,
446 4, FALSE,
447 5, FALSE,
448 6, str, -1);
449 break;
450 case 1:
451 gtk_tree_store_insert_before (store, & new_level, NULL, & step_level);
452 gtk_tree_store_set (store, & new_level, 0, coord -> cst,
453 1, 0,
454 2, 0,
455 3, 0,
456 4, 0,
457 5, 0, -1);
458 gtk_tree_store_append (store, & size_level, & new_level);
459 gtk_tree_store_set (store, & size_level, 0, 0,
460 1, coord -> csz,
461 2, 0,
462 3, 0,
463 4, 0,
464 5, 0, -1);
465 gtk_tree_store_append (store, & chain_level, & size_level);
466 gtk_tree_store_set (store, & chain_level, 0, -coord -> cst,
467 1, -coord -> csz,
468 2, coord -> ch,
469 3, FALSE,
470 4, FALSE,
471 5, FALSE,
472 6, str, -1);
473 break;
474 case 2:
475 gtk_tree_store_insert_after (store, & new_level, & step_level, & size_level);
476 gtk_tree_store_set (store, & new_level, 0, 0,
477 1, coord -> csz,
478 2, 0,
479 3, 0,
480 4, 0,
481 5, 0, -1);
482 gtk_tree_store_append (store, & chain_level, & new_level);
483 gtk_tree_store_set (store, & chain_level, 0, -coord -> cst,
484 1, -coord -> csz,
485 2, coord -> ch,
486 3, FALSE,
487 4, FALSE,
488 5, FALSE,
489 6, str, -1);
490 break;
491 case 3:
492 gtk_tree_store_insert_before (store, & new_level, & step_level, & size_level);
493 gtk_tree_store_set (store, & new_level, 0, 0,
494 1, coord -> csz,
495 2, 0,
496 3, 0,
497 4, 0,
498 5, 0, -1);
499 gtk_tree_store_append (store, & chain_level, & new_level);
500 gtk_tree_store_set (store, & chain_level, 0, -coord -> cst,
501 1, -coord -> csz,
502 2, coord -> ch,
503 3, FALSE,
504 4, FALSE,
505 5, FALSE,
506 6, str, -1);
507 break;
508 case 4:
509 gtk_tree_store_insert_after (store, & new_level, & size_level, & chain_level);
510 gtk_tree_store_set (store, & new_level, 0, -coord -> cst,
511 1, -coord -> csz,
512 2, coord -> ch,
513 3, FALSE,
514 4, FALSE,
515 5, FALSE,
516 6, str, -1);
517 break;
518 case 5:
519 gtk_tree_store_insert_before (store, & new_level, & size_level, & chain_level);
520 gtk_tree_store_set (store, & new_level, 0, -coord -> cst,
521 1, -coord -> csz,
522 2, coord -> ch,
523 3, FALSE,
524 4, FALSE,
525 5, FALSE,
526 6, str, -1);
527 break;
528 }
529 g_free (str);
530 }
531 }
532 else
533 {
534 valid = gtk_tree_model_get_iter_first(mod, & size_level);
535 while (valid)
536 {
537 gtk_tree_model_get (mod, & size_level, 0, & i, -1);
538 if (i > coord -> csz)
539 {
540 prepend = 1;
541 valid = FALSE;
542 }
543 else if (i == coord -> csz)
544 {
545 if (gtk_tree_model_iter_has_child (mod, &size_level))
546 {
547 j = gtk_tree_model_iter_n_children (mod, &size_level);
548 for (k=0; k<j; k++)
549 {
550 if (gtk_tree_model_iter_nth_child (mod, &chain_level, &size_level, k))
551 {
552 gtk_tree_model_get (mod, &chain_level, 1, & l, -1);
553 if (l > coord -> ch)
554 {
555 prepend = 2;
556 valid = FALSE;
557 break;
558 }
559 else if (l == coord -> ch)
560 {
561 insert = valid = FALSE;
562 break;
563 }
564 }
565 }
566 if (valid)
567 {
568 prepend = 3;
569 valid = FALSE;
570 }
571 }
572 }
573 else
574 {
575 valid = gtk_tree_model_iter_next(mod, & step_level);
576 }
577 }
578 if (insert)
579 {
580 str = chain_atoms (this_proj, coord -> cst-1, coord -> csz-1, coord -> ch-1, FALSE);
581 switch (prepend)
582 {
583 case 0:
584 gtk_tree_store_append (store, & size_level, NULL);
585 gtk_tree_store_set (store, & size_level, 0, coord -> csz,
586 1, 0,
587 2, 0,
588 3, 0,
589 4, 0, -1);
590 gtk_tree_store_append (store, & chain_level, & size_level);
591 gtk_tree_store_set (store, & chain_level, 0, -coord -> csz,
592 1, coord -> ch,
593 2, FALSE,
594 3, FALSE,
595 4, FALSE,
596 5, str, -1);
597 break;
598 case 1:
599 gtk_tree_store_insert_before (store, & new_level, NULL, & size_level);
600 gtk_tree_store_set (store, & new_level, 0, coord -> csz,
601 1, 0,
602 2, 0,
603 3, 0,
604 4, 0, -1);
605 gtk_tree_store_append (store, & chain_level, & new_level);
606 gtk_tree_store_set (store, & chain_level, 0, -coord -> csz,
607 1, coord -> ch,
608 2, FALSE,
609 3, FALSE,
610 4, FALSE,
611 5, str, -1);
612 break;
613 case 2:
614 gtk_tree_store_insert_before (store, & new_level, & size_level, & chain_level);
615 gtk_tree_store_set (store, & new_level, 0, -coord -> csz,
616 1, coord -> ch,
617 2, FALSE,
618 3, FALSE,
619 4, FALSE,
620 5, str, -1);
621 break;
622 case 3:
623 gtk_tree_store_insert_after (store, & new_level, & size_level, & chain_level);
624 gtk_tree_store_set (store, & new_level, 0, -coord -> csz,
625 1, coord -> ch,
626 2, FALSE,
627 3, FALSE,
628 4, FALSE,
629 5, str, -1);
630 break;
631 }
632 g_free (str);
633 }
634 }
635}
636
645int get_cmin (project * this_proj, int step)
646{
647 int i, j;
648 for (i=0; i<this_proj -> coord -> totcoord[9]; i++)
649 {
650 j = this_proj -> coord -> geolist[9][0][i];
651 if (this_proj -> modelgl -> num_chains[step-1][j-1]) break;
652 }
653 return j;
654}
655
664int get_cmax (project * this_proj, int step)
665{
666 int i, j;
667 for (i=this_proj -> coord -> totcoord[9]-1; i>-1; i--)
668 {
669 j = this_proj -> coord -> geolist[9][0][i];
670 if (this_proj -> modelgl -> num_chains[step-1][j-1]) break;
671 }
672 return j;
673}
674
695
704G_MODULE_EXPORT void update_chains_search (GtkEntry * res, gpointer data)
705{
706 tint * dat = (tint * )data;
707 gchar * str;
708 const gchar * m = entry_get_text (res);
709 int i, j;
710 int v = (int)string_to_double ((gpointer)m);
711 project * this_proj = get_project_by_id(dat -> a);
712 coord_edition * coord = this_proj -> modelgl -> coord_win;
713 switch (dat -> b)
714 {
715 case 0:
716 if (v > 0 && v < this_proj -> steps+1)
717 {
718 if (v != coord -> cst)
719 {
720 coord -> cst = v;
721 coord -> csz = coord -> ch = -1;
722 for (j=1; j<3; j++) gtk_label_set_text (GTK_LABEL(coord -> chlab[j]), "");
723 }
724 }
725 else
726 {
727 coord -> cst = coord -> csz = coord -> ch = -1;
728 }
729 if (coord -> cst > 0)
730 {
731 update_entry_int(res, coord -> cst);
732 str = g_strdup_printf ("&#x2208; [%d - %d]", get_cmin(this_proj, coord -> cst), get_cmax(this_proj, coord -> cst));
733 gtk_label_set_text (GTK_LABEL(coord -> chlab[1]), str);
734 g_free (str);
735 }
736 else
737 {
739 for (j=1; j<3; j++) gtk_label_set_text (GTK_LABEL(coord -> chlab[j]), "");
740 }
741 break;
742 case 1:
743 if (coord -> cst > -1)
744 {
745 i = get_cmin(this_proj, coord -> cst);
746 j = get_cmax(this_proj, coord -> cst);
747 if (v >= i && v <= j)
748 {
749 if (v != coord -> csz)
750 {
751 if (this_proj -> modelgl -> num_chains[coord -> cst-1][coord -> csz-1])
752 {
753 coord -> csz = v;
754 coord -> ch = -1;
755 gtk_label_set_text (GTK_LABEL(coord -> chlab[2]), "");
756 }
757 else
758 {
759 coord -> csz = coord -> ch = -1;
760 }
761 }
762 }
763 }
764 else
765 {
766 coord -> csz = coord -> ch = -1;
767 }
768 if (coord -> csz > 0)
769 {
770 update_entry_int(res, coord -> csz);
771 str = g_strdup_printf ("&#x2208; [1 - %d]", this_proj -> modelgl -> num_chains[coord -> cst-1][coord -> csz-1]);
772 gtk_label_set_text (GTK_LABEL(coord -> chlab[2]), str);
773 g_free (str);
774 }
775 else
776 {
778 gtk_label_set_text (GTK_LABEL(coord -> chlab[2]), "");
779 }
780 break;
781 case 2:
782 if (coord -> cst > -1 && coord -> csz > -1)
783 {
784 if (v > 0 && v < this_proj -> modelgl -> num_chains[coord -> cst-1][coord -> csz-1]+1)
785 {
786 coord -> ch = v;
787 }
788 else
789 {
790 coord -> ch = -1;
791 }
792 }
793 else
794 {
795 coord -> ch = -1;
796 }
797 if (coord -> ch > 0)
798 {
799 update_entry_int(res, coord -> ch);
800 }
801 else
802 {
804 }
805 break;
806 }
807 if (coord -> cst > 0 && coord -> csz > 0 && coord -> ch > 0)
808 {
810 }
811}
812
820GtkWidget * create_chains_search (project * this_proj)
821{
822 GtkWidget * chains_search = create_vbox (BSEP);
823 gchar * str = g_strdup_printf (_("Too many chains in your model !\n"
824 " It is impossible to display the entire list ...\n"
825 "... instead you can look for chain(s) individually:\n"));
826 add_box_child_start (GTK_ORIENTATION_VERTICAL, chains_search, markup_label(str, 200, -1, 0.5, 0.5), FALSE, FALSE, 10);
827 g_free (str);
828 gchar * search_item[3]={i18n("MD step:"), i18n("Chain size:"), i18n("Chain Id.:")};
829 int i, j;
830 GtkWidget * hbox;
831 GtkWidget * entry;
832 j = (this_proj -> steps) > 1 ? 0 : 1;
833 coord_edition * coord = this_proj -> modelgl -> coord_win;
834 coord -> cst = 1;
835 for (i=j; i<3; i++)
836 {
837 hbox = create_hbox (0);
838 add_box_child_start (GTK_ORIENTATION_VERTICAL, chains_search, hbox, FALSE, FALSE, 0);
839 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_(search_item[i]), 100, -1, 0.0, 0.5), FALSE, FALSE, 20);
840 entry = create_entry (G_CALLBACK(update_chains_search), 100, 15, FALSE, & this_proj -> modelgl -> colorp[i][0]);
841 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox,entry, FALSE, FALSE, 0);
842 if (i==0)
843 {
844 str = g_strdup_printf ("&#x2208; [1 - %d]", this_proj -> steps);
845 coord -> chlab[i] = markup_label(str, 50, -1, 0.0, 0.5);
846 g_free (str);
847 }
848 else if (i == 1)
849 {
850 str = g_strdup_printf ("&#x2208; [%d - %d]", get_cmin(this_proj, coord -> cst), get_cmax(this_proj, coord -> cst));
851 coord -> chlab[i] = markup_label(str, 50, -1, 0.0, 0.5);
852 g_free (str);
853 }
854 else
855 {
856 coord -> chlab[i] = markup_label("", 50, -1, 0.0, 0.5);
857 }
858 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, coord -> chlab[i], FALSE, FALSE, 5);
859 }
860 add_box_child_start (GTK_ORIENTATION_VERTICAL, chains_search, markup_label(_("<b>Search result(s)</b>"), 200, -1, 0.5, 0.5), FALSE, FALSE, 10);
861 add_box_child_start (GTK_ORIENTATION_VERTICAL, chains_search, create_chains_tree (this_proj, FALSE), FALSE, FALSE, 0);
862 return chains_search;
863}
864
865#ifdef GTK4
875G_MODULE_EXPORT void run_save_chains_to_file (GtkNativeDialog * info, gint response_id, gpointer data)
876{
877 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
878#else
888G_MODULE_EXPORT void run_save_chains_to_file (GtkDialog * info, gint response_id, gpointer data)
889{
890 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
891#endif
892 if (response_id == GTK_RESPONSE_ACCEPT)
893 {
894 gchar * chains_file = file_chooser_get_file_name (chooser);
895 // Save data to file here !
896 if (chains_file)
897 {
898 tint * dat = (tint *)data;
899 project * this_proj = get_project_by_id (dat -> a);
900 if (this_proj -> coord -> totcoord[9])
901 {
902 FILE * fp = fopen (chains_file, dfi[1]);
903 gchar * str;
904 if (fp)
905 {
906 fprintf (fp, _("# This file contains the list of all chains in the %s model\n\n"), prepare_for_title(this_proj -> name));
907 int h, i, j, k, l;
908 for (h=0; h < this_proj -> steps; h++)
909 {
910 i = h+1;
911 if (this_proj -> steps > 1) fprintf (fp, _("Step N°%d\n"), i);
912 for (i=0; i < this_proj -> coord -> totcoord[9]; i++)
913 {
914 j = this_proj -> coord -> geolist[9][0][i];
915 fprintf (fp, (this_proj -> steps > 1) ? _("\n\tChain(s) of size %d atoms\n") : _("\nChain(s) of size %d atoms\n"), j);
916 k = this_proj -> modelgl -> num_chains[h][j-1];
917 // ring size
918 for (l=0; l<k; l++)
919 {
920 str = chain_atoms (this_proj, h, j-1, l, TRUE);
921 fprintf (fp, (this_proj -> steps > 1) ? "\t\tN°%d\t:\t%s\n" : "\tN°%d\t:\t%s\n", l+1, str);
922 g_free (str);
923 }
924 }
925 }
926 fclose (fp);
927 }
928 else
929 {
930 str = g_strdup_printf (_("Impossible to open file: %s"), chains_file);
931 show_error (str, 0, this_proj -> modelgl -> coord_win -> win);
932 g_free (str);
933 }
934 }
935 }
936 }
937#ifdef GTK4
939#else
940 destroy_this_dialog (info);
941#endif
942}
943
952G_MODULE_EXPORT void save_chains_to_file (GtkButton * but, gpointer data)
953{
954#ifdef GTK4
955 GtkFileChooserNative * info;
956#else
957 GtkWidget * info;
958#endif
959 info = create_file_chooser (_("Save atoms in chains to file"),
960 GTK_WINDOW(MainWindow),
961 GTK_FILE_CHOOSER_ACTION_SAVE,
962 _("Save"));
963 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
964#ifdef GTK3
965 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
966#endif
968 gtk_file_chooser_set_current_name (chooser, "chains.dat");
969#ifdef GTK4
970 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_save_chains_to_file), data);
971#else
972 run_this_gtk_dialog (info, G_CALLBACK(run_save_chains_to_file), data);
973#endif
974}
975
983GtkWidget * chains_tab (glwin * view)
984{
985 GtkWidget * chains = create_vbox (0);
986 GtkWidget * scroll = create_scroll (chains, -1, -1, GTK_SHADOW_NONE);
987 gtk_widget_set_hexpand (chains, TRUE);
988 gtk_widget_set_vexpand (chains, TRUE);
989 int h, i, j, k;
990 project * this_proj = get_project_by_id(view -> proj);
991 k = 0;
992 for (h=0; h < this_proj -> steps; h++)
993 {
994 for (i=0; i < this_proj -> coord -> totcoord[9]; i++)
995 {
996 j = this_proj -> coord -> geolist[9][0][i];
997 k += this_proj -> modelgl -> num_chains[h][j-1];
998 }
999 }
1000 if (k < GTK_LIMIT)
1001 {
1002 add_container_child (CONTAINER_SCR, scroll, create_chains_tree (this_proj, TRUE));
1003 }
1004 else
1005 {
1007 }
1008
1009 GtkWidget * hbox = create_hbox (0);
1010 add_box_child_start (GTK_ORIENTATION_VERTICAL, chains, hbox, FALSE, FALSE, 2);
1011 GtkWidget * hhbox = create_hbox (0);
1012 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, hhbox, TRUE, TRUE, 100);
1013 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hhbox, create_button(_("Save to file"), IMG_NONE, NULL, 50, -1,
1014 GTK_RELIEF_NORMAL, G_CALLBACK(save_chains_to_file), & view -> colorp[0][0]), TRUE, TRUE, 40);
1015 return chains;
1016}
const gchar * dfi[2]
Definition main.c:93
integer function chains()
Definition chains.F90:54
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
color colorp[64]
ColRGBA col
Definition d_measures.c:77
int atoms[NUM_STYLES][2]
GtkTreePath * path
Definition datab.c:103
gchar * ctitle[MAXDATA][12]
Definition dlp_field.c:924
FILE * fp
GtkWidget * MainWindow
Definition global.c:207
#define i18n(String)
Definition global.c:80
double string_to_double(gpointer string)
convert string to double
Definition global.c:611
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:533
@ IMG_NONE
Definition global.h:276
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2358
#define GTK_LIMIT
maximum number of elements in GTK widgets like GtkTreeView, GtkTreeStore or similar rendering widgets...
Definition global.h:77
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1401
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2139
project * proj
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2306
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:652
#define BSEP
Definition global.h:261
void opengl_project_changed(int id)
change the OpenGL project
Definition update_p.c:296
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:669
G_MODULE_EXPORT void select_unselect_this_atom(GtkWidget *widg, gpointer data)
select / unselect this atom callback GTK3
Definition popup.c:1196
void set_renderer_markup(GtkTreeModel *mod, GtkTreeIter *iter, GtkCellRenderer *renderer, int col)
set Pango text markup for a GtkCellRenderer
Definition gtk-misc.c:1764
@ CONTAINER_SCR
Definition global.h:267
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1999
G_MODULE_EXPORT void show_hide_this_atom(GtkWidget *widg, gpointer data)
show / hide this atom callback GTK3
Definition popup.c:1038
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
project * opengl_project
Definition project.c:54
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:340
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2235
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:849
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:726
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
Definition gtk-misc.c:2393
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2254
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:461
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
gboolean pick
int step
Definition ogl_draw.c:76
@ LABEL
Definition glwin.h:98
Function declarations for the creation of the OpenGL window.
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:434
Messaging function declarations.
Definition glwin.h:967
Definition global.h:118
GtkWidget * create_chains_search(project *this_proj)
create the chain(s) search widget
Definition w_chains.c:820
G_MODULE_EXPORT void update_chains_search(GtkEntry *res, gpointer data)
update the chain(s) search widget
Definition w_chains.c:704
GtkWidget * create_chains_tree(project *this_proj, gboolean fill_this)
create the chain(s) search tree store
Definition w_chains.c:293
void add_this_chain_to_search_tree(project *this_proj)
add chain in the search tree based on chain length and id
Definition w_chains.c:337
G_MODULE_EXPORT void run_save_chains_to_file(GtkDialog *info, gint response_id, gpointer data)
save chains data to file: run the dialog
Definition w_chains.c:888
void chains_set_markup(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
Chains tree view set color and Pango markup in tree view.
Definition w_chains.c:279
G_MODULE_EXPORT void on_select_chains(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
on select chain toggle callback
Definition w_chains.c:71
gchar * chain_atoms(project *this_proj, int step, int size, int cid, gboolean to_file)
create a string containing the list of atoms in a chain
Definition w_chains.c:158
void fill_chains_model(GtkTreeStore *store, project *this_proj)
fill the entire chain(s) tree store
Definition w_chains.c:196
GtkWidget * chains_tab(glwin *view)
create the chain(s) tab for the advanced environments window
Definition w_chains.c:983
G_MODULE_EXPORT void save_chains_to_file(GtkButton *but, gpointer data)
save chains data to file
Definition w_chains.c:952
void rings_set_visible(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
show / hide cell renderer in the ring search tree store
Definition w_rings.c:174
int get_cmax(project *this_proj, int step)
get chain(s) max size for the MD step
Definition w_chains.c:664
int get_cmin(project *this_proj, int step)
get chain(s) min size for the MD step
Definition w_chains.c:645
GtkWidget * res[2]
Definition w_encode.c:342
GtkWidget * hbox
Definition workspace.c:71