atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
dlp_mol.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: 'dlp_mol.c'
24*
25* Contains:
26*
27
28 - The functions to add / remove molecule(s) to / from the force field
29
30*
31* List of functions:
32
33 gchar * remove_text (int i, int j, gchar * str);
34
35 void clean_up_molecules_info (gboolean usel);
36 void set_sensitive_mol (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
37 void clear_field_atoms (field_molecule * fmol, field_atom* at, int mols, int * mol);
38 void molecule_set_color (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
39 void merge_all_atoms_to_mol (field_molecule * new_mol, int mstart);
40 void prepare_atoms_to_merge (field_atom* at, field_molecule * new_mol, field_molecule * old_mol);
41
42 G_MODULE_EXPORT void select_mol (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data);
43 G_MODULE_EXPORT void run_add_molecule_to_field (GtkDialog * dialog, gint response_id, gpointer data);
44 G_MODULE_EXPORT void add_molecule_to_field (GSimpleAction * action, GVariant * parameter, gpointer data);
45 G_MODULE_EXPORT void run_remove_molecule_from_field (GtkDialog * rmol, gint response_id, gpointer data);
46 G_MODULE_EXPORT void remove_molecule_from_field (GSimpleAction * action, GVariant * parameter, gpointer data);
47
48 field_atom* new_atom_to_merge (int id, field_molecule * fmol);
49
50*/
51
52#include "dlp_field.h"
53#include "calc.h"
54#include "interface.h"
55#include "glview.h"
56
59int * new_mol;
60extern ColRGBA init_color (int id, int numid);
62GtkWidget * remove_label;
63GtkCellRenderer * remove_renderer[5];
64GtkTreeViewColumn * remove_col[5];
65gboolean removing = FALSE;
66extern void field_unselect_all ();
67extern gchar * set_field_atom_name (field_atom* ato, field_molecule * mol);
69extern void viz_fragment (field_molecule * fmol, int id, int viz);
70extern void check_to_visualize_properties (int id);
71
81gchar * remove_text (int i, int j, gchar * str)
82{
83 switch (i)
84 {
85 case -2:
86 return g_strdup_printf (_("The description of atom <b>%s</b> will be deleted\n"
87 "and merged with the one of the selected field atom.\n"
88 "Field object(s) using atom <b>%s</b> will also be deleted\n"
89 "and the force field parameter(s) will be updated accordingly."),
90 str, str);
91 break;
92 case -1:
93 return g_strdup_printf (_("The description of molecule <b>%s</b> will be deleted\nand merged with the one of the selected molecule."), str);
94 break;
95 default:
96 switch (j)
97 {
98 case -1:
99 return g_strdup_printf (_("The description of molecule <b>%s</b> will be deleted\nand merged with the one of molecule <b>%s</b>"), str, get_active_field_molecule(i) -> name);
100 break;
101 default:
102 return g_strdup_printf (_("The description of atom <b>%s</b> will be deleted\n"
103 "and merged with the one of field atom <b>%s</b>\n"
104 "Field object(s) using atom <b>%s</b> will also be deleted\n"
105 "and the force field parameter(s) will be updated accordingly."),
106 str, get_active_atom(i,j) -> name, str);
107 break;
108 }
109 break;
110 }
111}
112
120void clean_up_molecules_info (gboolean usel)
121{
122 int i;
123
124 for (i=0; i<MOLIMIT-1; i++)
125 {
128 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, mol_box[i], combo_mol[i], FALSE, FALSE, 10);
130 changed_mol_box (GTK_COMBO_BOX(combo_mol[i]), GINT_TO_POINTER(i+1));
131 }
133 if (usel) field_unselect_all ();
134 gtk_tree_store_clear (field_model[0]);
135 fill_field_model (field_model[0], 0, -1);
136}
137
149void set_sensitive_mol (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
150{
151 int m;
152 gtk_tree_model_get (mod, iter, 0, & m, -1);
153 if (a_mol && m-1 != new_mol[0])
154 {
155 gtk_cell_renderer_set_visible (renderer, FALSE);
156 }
157 else
158 {
159 gtk_cell_renderer_set_visible (renderer, TRUE);
160 }
161}
162
164
174G_MODULE_EXPORT void select_mol (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
175{
176 GtkTreeStore ** model = (GtkTreeStore **)data;
177 GtkTreeIter iter;
178 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
179 gtk_tree_model_get_iter (GTK_TREE_MODEL(* model), & iter, path);
180 if (gtk_cell_renderer_toggle_get_active(cell_renderer))
181 {
182 new_mol[a_mol-1] = -1;
183 a_mol --;
184 gtk_tree_store_set (* model, & iter, active_col, 0, -1);
185 toviz.c = 0;
186 }
187 else
188 {
189 a_mol ++;
190 gtk_tree_store_set (* model, & iter, active_col, 1, -1);
191 gtk_tree_model_get (GTK_TREE_MODEL(* model), & iter, 0, & new_mol[a_mol-1], -1);
192 new_mol[a_mol-1] --;
193 toviz.c = 1;
194 }
195 if (active_col == 1)
196 {
197 toviz.a = 2;
198 gtk_tree_model_get (GTK_TREE_MODEL(* model), & iter, 0, & toviz.b, -1);
200 }
201 else if (active_col == 3)
202 {
203 if (toviz.c) old_viz_mol = new_mol[0];
206 gtk_label_set_text (GTK_LABEL(remove_label), remove_text(new_mol[0], -1, to_remove -> name));
207 gtk_label_set_use_markup (GTK_LABEL(remove_label), TRUE);
208 }
209}
210
212
223void clear_field_atoms (field_molecule * fmol, field_atom* at, int mols, int * mol)
224{
225 int i, j, k, l;
226 l = 0;
227 for (i=0; i < at -> num; i++)
228 {
229 k = at -> list[i];
230 for (j=0; j < mols; j++)
231 {
232 if (tmp_proj -> atoms[0][k].coord[2] == mol[j])
233 {
234 l ++;
235 }
236 }
237 }
238 int * r_list = allocint (l);
239 int * s_list = allocint (l);
240 int * t_list = allocint (l);
241 l = -1;
242 at -> frozen = 0;
243 for (i=0; i < at -> num; i++)
244 {
245 k = at -> list[i];
246 for (j=0; j < mols; j++)
247 {
248 if (tmp_proj -> atoms[0][k].coord[2] == mol[j])
249 {
250 l ++;
251 r_list[l] = k;
252 s_list[l] = at -> list_id[i];
253 t_list[l] = at -> frozen_id[i];
254 if (t_list[l]) at -> frozen ++;
255 }
256 }
257 }
258 at -> num = l+1;
259 at -> list = NULL;
260 at -> list = allocint (at -> num);
261 at -> list_id = NULL;
262 at -> list_id = allocint (at -> num);
263 at -> frozen_id = NULL;
264 at -> frozen_id = allocbool (at -> num);
265 for (i=0; i < at -> num; i++)
266 {
267 at -> list[i] = r_list[i];
268 at -> list_id[i] = s_list[i];
269 at -> frozen_id[i] = t_list[i];
270 j = at -> list[i];
271 k = at -> list_id[i];
272 for (l=0; l<mols; l++)
273 {
274 if (tmp_proj -> atoms[0][j].coord[2] == mol[l])
275 {
276 atomd_id_save[k][l].a = at -> id;
277 atomd_id_save[k][l].b = i;
278 }
279 }
280 }
281 g_free (r_list);
282 g_free (s_list);
283 g_free (t_list);
284}
285
297void molecule_set_color (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
298{
299 int i, j;
300 gtk_tree_model_get (mod, iter, active_col, & j, -1);
301 gtk_tree_model_get (mod, iter, 0, & i, -1);
302 set_renderer_color (j, renderer, init_color (i-1, num_field_objects));
303}
304
314G_MODULE_EXPORT void run_add_molecule_to_field (GtkDialog * dialog, gint response_id, gpointer data)
315{
316 int i, j, k;
317 int * old_mol = NULL;
318 gchar * str;
319 gboolean done = FALSE;
320 gboolean saveit = FALSE;
321 // Id - Name - Multiplicity - Select
322 // While selected < m apply inactif
323 switch (response_id)
324 {
325 case GTK_RESPONSE_APPLY:
327 {
328 if (a_mol > 1)
329 {
330 str = g_strdup_printf (_("Fragments N°%d"), new_mol[0]+1);
331 if (a_mol > 2)
332 {
333 for (i=1; i<a_mol-1; i++)
334 {
335 str = g_strdup_printf ("%s, %d", str, new_mol[i]+1);
336 }
337 }
338 str = g_strdup_printf (_("%s and %d have been selected !"), str, new_mol[a_mol-1]+1);
339 str = g_strdup_printf (_("%s\nConfirm this choice and create a new field molecule to describe these fragments ?"), str);
340 }
341 else
342 {
343 str = g_strdup_printf (_("Fragment N°%d has been selected !"), new_mol[0]+1);
344 str = g_strdup_printf (_("%s\nConfirm this choice and create a new field molecule to describe this fragment ?"), str);
345 }
346 selection_confirmed = FALSE;
347 field_question (str, G_CALLBACK(confirm_selection), NULL);
348 g_free (str);
350 {
351 done = TRUE;
353 field_molecule * next_fmol = duplicate_field_molecule (old_fmol);
354 get_active_field_molecule(tmp_field -> molecules-1) -> next = next_fmol;
355 next_fmol -> prev = get_active_field_molecule(tmp_field -> molecules-1);
356 next_fmol -> id = tmp_field -> molecules;
357 next_fmol -> multi = a_mol;
358 next_fmol -> fragments = NULL;
359 next_fmol -> fragments = allocint (a_mol);
360 for (i=0; i<a_mol; i++) next_fmol -> fragments[i] = new_mol[i];
361 // Atoms_id and field atoms
362 atomd_id_save = g_malloc0(next_fmol-> mol -> natoms*sizeof*atomd_id_save);
363 for (i=0; i<next_fmol-> mol -> natoms; i++)
364 {
365 atomd_id_save[i] = g_malloc0(next_fmol -> multi*sizeof*atomd_id_save[i]);
366 }
367 tmp_fat = next_fmol -> first_atom;
368 for (i=0; i < next_fmol -> atoms; i++)
369 {
370 clear_field_atoms (next_fmol, tmp_fat, a_mol, new_mol);
371 tmp_fat -> name = g_strdup_printf ("%s", set_field_atom_name (tmp_fat, next_fmol));
372 if (tmp_fat -> next != NULL) tmp_fat = tmp_fat -> next;
373 }
374 g_free (next_fmol -> atoms_id);
375 next_fmol -> atoms_id = NULL;
376 next_fmol -> atoms_id = g_malloc0(next_fmol-> mol -> natoms*sizeof*next_fmol -> atoms_id);
377 for (i=0; i<next_fmol-> mol -> natoms; i++)
378 {
379 next_fmol -> atoms_id[i] = g_malloc0(next_fmol -> multi*sizeof*next_fmol -> atoms_id[i]);
380 for (j=0; j<next_fmol -> multi; j++)
381 {
382 next_fmol -> atoms_id[i][j].a = atomd_id_save[i][j].a;
383 next_fmol -> atoms_id[i][j].b = atomd_id_save[i][j].b;
384 }
385 }
386 g_free (atomd_id_save);
387 old_mol = allocint (old_fmol -> multi - a_mol);
388 k = -1;
389 for (i=0; i<old_fmol -> multi; i++)
390 {
391 saveit = TRUE;
392 for (j=0; j<a_mol; j++)
393 {
394 if (new_mol[j] == old_fmol -> fragments[i])
395 {
396 saveit = FALSE;
397 break;
398 }
399 }
400 if (saveit)
401 {
402 k++;
403 old_mol[k] = old_fmol -> fragments[i];
404 }
405 }
406 new_mol = NULL;
407 // Now we deal with atoms_id and the field atoms
408 atomd_id_save = g_malloc0(old_fmol-> mol -> natoms*sizeof*atomd_id_save);
409 for (i=0; i<old_fmol -> mol -> natoms; i++)
410 {
411 atomd_id_save[i] = g_malloc0((old_fmol -> multi - a_mol)*sizeof*atomd_id_save[i]);
412 }
413 tmp_fat = old_fmol -> first_atom;
414 for (i=0; i < old_fmol -> atoms; i++)
415 {
416 clear_field_atoms (old_fmol, tmp_fat, old_fmol -> multi - a_mol, old_mol);
417 if (tmp_fat -> next != NULL) tmp_fat = tmp_fat -> next;
418 }
419 old_fmol -> multi -= a_mol;
420 g_free (old_fmol -> atoms_id);
421 old_fmol -> atoms_id = NULL;
422 old_fmol -> atoms_id = g_malloc0(old_fmol-> mol -> natoms*sizeof*old_fmol -> atoms_id);
423 for (i=0; i<old_fmol-> mol -> natoms; i++)
424 {
425 old_fmol -> atoms_id[i] = g_malloc0(old_fmol -> multi*sizeof*old_fmol -> atoms_id[i]);
426 for (j=0; j<old_fmol -> multi; j++)
427 {
428 old_fmol -> atoms_id[i][j].a = atomd_id_save[i][j].a;
429 old_fmol -> atoms_id[i][j].b = atomd_id_save[i][j].b;
430 }
431 }
432 g_free (atomd_id_save);
433 old_fmol -> fragments = NULL;
434 old_fmol -> fragments = allocint (old_fmol -> multi);
435 for (i=0; i<old_fmol -> multi; i++) old_fmol -> fragments[i] = old_mol[i];
436 old_mol = NULL;
438 tmp_field -> molecules ++;
439 edit_field_prop (NULL, NULL, GINT_TO_POINTER(0));
441 }
442 }
443 break;
444 default:
446 done = TRUE;
447 break;
448 }
449 if (done)
450 {
451 g_free (new_mol);
452 new_mol = NULL;
453 destroy_this_dialog (dialog);
454 }
455}
456
466G_MODULE_EXPORT void add_molecule_to_field (GSimpleAction * action, GVariant * parameter, gpointer data)
467{
468 int i;
469 field_object = 0;
470 gchar * str = g_strdup_printf (_("Please select the fragment(s) of the new molecule"));
471 GtkWidget * amol = dialogmodal (str, GTK_WINDOW(field_assistant));
472 g_free (str);
473 gtk_dialog_add_button (GTK_DIALOG(amol), _("Apply"), GTK_RESPONSE_APPLY);
474 GtkWidget * add_tree = NULL;
475 GtkTreeIter iter;
476 GtkTreeViewColumn * mol_col[2];
477 GtkCellRenderer * mol_cell[2];
478 gchar * mol_title[2] = {i18n("Fragment"), i18n("Viz.3D & Select")};
479 gchar * ctype[2]={"text", "active"};
480 GType col_type[2] = {G_TYPE_INT, G_TYPE_BOOLEAN};
481
482 active_col = 1;
483 a_mol = 0;
484 GtkTreeStore * add_model = gtk_tree_store_newv (2, col_type);
485 add_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(add_model));
487 for (i=0; i<2; i++)
488 {
489 if (i == 0)
490 {
491 mol_cell[i] = gtk_cell_renderer_text_new ();
492 }
493 else
494 {
495 mol_cell[i] = gtk_cell_renderer_toggle_new ();
496 g_signal_connect (G_OBJECT(mol_cell[i]), "toggled", G_CALLBACK(select_mol), & add_model);
497 }
498 mol_col[i] = gtk_tree_view_column_new_with_attributes (_(mol_title[i]), mol_cell[i], ctype[i], i, NULL);
499 gtk_tree_view_append_column (GTK_TREE_VIEW(add_tree), mol_col[i]);
500 gtk_tree_view_column_set_alignment (mol_col[i], 0.5);
501 if (i == 0)
502 {
503 gtk_tree_view_column_set_cell_data_func (mol_col[i], mol_cell[i], molecule_set_color, NULL, NULL);
504 }
505 }
506 // fill model
507 num_field_objects = tmp_coord-> totcoord[2];
508 new_mol = NULL;
510 for (i=0; i<tmp_fmol -> multi; i++)
511 {
512 gtk_tree_store_append (add_model, & iter, NULL);
513 gtk_tree_store_set (add_model, & iter, 0, tmp_fmol -> fragments[i] + 1, 1, 0, -1);
514 new_mol[i] = -1;
515 }
516 g_object_unref (add_model);
517 gtk_tree_view_expand_all (GTK_TREE_VIEW(add_tree));
518
519 i = ((tmp_fmol -> multi+1)*35 < 500) ? (tmp_fmol -> multi+1)*35 : 500;
520 GtkWidget * scrollsets = create_scroll (dialog_get_content_area (amol), 220, i, GTK_SHADOW_ETCHED_IN);
522 run_this_gtk_dialog (amol, G_CALLBACK(run_add_molecule_to_field), NULL);
523}
524
534{
535 field_atom* fat, * fbt;
536 fat = get_active_atom (new_mol -> id, new_mol -> atoms-1);
537 int i, j, k, l, m, n;
538 for (i=0; i<fat -> num; i++)
539 {
540 j = fat -> list[i];
541 k = fat -> list_id[i];
542 l = new_mol -> atoms_id[k][0].a;
543 fbt = get_active_atom (new_mol -> id, l);
544 fbt -> list[fbt -> num] = j;
545 fbt -> list_id[fbt -> num] = k;
546 m = tmp_proj -> atoms[0][j].coord[2];
547 for (n=mstart; n<new_mol -> multi; n++)
548 {
549 if (new_mol -> fragments[n] == m)
550 {
551 new_mol -> atoms_id[k][n].a = fbt -> id;
552 new_mol -> atoms_id[k][n].b = fbt -> num;
553 break;
554 }
555 }
556 fbt -> num ++;
557 }
558}
559
570{
571 int i, j;
572 int * saved_list = allocint (at -> num);
573 int * saved_list_id = allocint (at -> num);
574 int * saved_frozen_id = allocbool (at -> num);
575 for (j=0; j < at -> num; j++)
576 {
577 saved_list[j] = at -> list[j];
578 saved_list_id[j] = at -> list_id[j];
579 saved_frozen_id[j] = at -> frozen_id[j];
580 }
581 i = at -> num;
582 i /= (new_mol -> multi - old_mol -> multi);
583 i *= old_mol -> multi;
584 g_free (at -> list);
585 at -> list = allocint (at -> num + i);
586 g_free (at -> list_id);
587 at -> list_id = allocint (at -> num + i);
588 g_free (at -> frozen_id);
589 at -> frozen_id = allocbool (at -> num + i);
590 for (j=0; j< at -> num; j++)
591 {
592 at -> list[j] = saved_list[j];
593 at -> list_id[j] = saved_list_id[j];
594 at -> frozen_id[j] = saved_frozen_id[j];
595 }
596 g_free (saved_list);
597 g_free (saved_list_id);
598 g_free (saved_frozen_id);
599}
600
610{
611 field_atom* fat, * fbt;
612 fat = g_malloc0(sizeof*fat);
613 fat -> id = id;
614 fat -> sp = -1;
615 fat -> num = fmol -> mol -> natoms * fmol -> multi;
616 fat -> list = allocint (fmol -> mol -> natoms * fmol -> multi);
617 fat -> list_id = allocint (fmol -> mol -> natoms * fmol -> multi);
618 fbt = fmol -> first_atom;
619 int i, j;
620 i = 0;
621 while (fbt != NULL)
622 {
623 for (j=0; j<fbt -> num; j++)
624 {
625 fat -> list[i] = fbt -> list[j];
626 fat -> list_id[i] = fbt -> list_id[j];
627 i ++;
628 }
629 fbt = fbt -> next;
630 }
631 return fat;
632}
633
643G_MODULE_EXPORT void run_remove_molecule_from_field (GtkDialog * rmol, gint response_id, gpointer data)
644{
645 int i, j;
646 gboolean done = FALSE;
647 switch (response_id)
648 {
649 case GTK_RESPONSE_APPLY:
650 if (a_mol)
651 {
652 done = TRUE;
654 int * old_mol = allocint (to_merge -> multi);
655 for (i=0; i<to_merge -> multi; i++) old_mol[i] = to_merge -> fragments[i];
656 g_free (to_merge -> fragments);
657 to_merge -> fragments = allocint (to_merge -> multi + to_remove -> multi);
658 for (i=0; i<to_merge -> multi; i++) to_merge -> fragments[i] = old_mol[i];
659 old_mol = NULL;
660 for (i=to_merge -> multi; i < to_merge -> multi + to_remove -> multi; i++)
661 {
662 to_merge -> fragments[i] = to_remove -> fragments[i - to_merge -> multi];
663 }
664 atomd_id_save = g_malloc0(to_merge -> mol -> natoms*sizeof*atomd_id_save);
665 for (i=0; i<to_merge -> mol -> natoms; i++)
666 {
667 atomd_id_save[i] = g_malloc0((to_merge -> multi+to_remove -> multi)*sizeof*atomd_id_save[i]);
668 for (j=0; j<to_merge -> multi; j++)
669 {
670 atomd_id_save[i][j].a = to_merge -> atoms_id[i][j].a;
671 atomd_id_save[i][j].b = to_merge -> atoms_id[i][j].b;
672 }
673 for (j=to_merge -> multi; j<to_merge -> multi+to_remove -> multi; j++)
674 {
675 atomd_id_save[i][j].a = -1;
676 atomd_id_save[i][j].b = -1;
677 }
678 }
679 to_merge -> multi += to_remove -> multi;
680 g_free (to_merge -> atoms_id);
681 to_merge -> atoms_id = g_malloc0(to_merge -> mol -> natoms*sizeof*to_merge -> atoms_id);
682 for (i=0; i<to_merge -> mol -> natoms; i++)
683 {
684 to_merge -> atoms_id[i] = g_malloc0(to_merge -> multi*sizeof*to_merge -> atoms_id[i]);
685 for (j=0; j<to_merge -> multi; j++)
686 {
687 to_merge -> atoms_id[i][j].a = atomd_id_save[i][j].a;
688 to_merge -> atoms_id[i][j].b = atomd_id_save[i][j].b;
689 }
690 }
691 g_free (atomd_id_save);
692 tmp_fat = get_active_atom (to_merge -> id, to_merge -> atoms -1);
693 tmp_fat -> next = new_atom_to_merge (to_merge -> atoms, to_remove);
694 to_merge -> atoms ++;
695 tmp_fat = to_merge -> first_atom;
696 for (i=0; i < to_merge -> atoms-1; i++)
697 {
699 if (tmp_fat -> next != NULL) tmp_fat = tmp_fat -> next;
700 }
701 merge_all_atoms_to_mol (to_merge, to_merge -> multi - to_remove -> multi);
702 tmp_fat = get_active_atom (to_merge -> id, to_merge -> atoms-2);
703 g_free (tmp_fat -> next);
704 tmp_fat -> next = NULL;
705 to_merge -> atoms --;
706
707 if (to_remove == tmp_field -> first_molecule)
708 {
709 tmp_field -> first_molecule = to_remove -> next;
710 tmp_field -> first_molecule -> prev = NULL;
711 }
712 else
713 {
714 if (to_remove -> next != NULL)
715 {
716 tmp_fmol = to_remove -> prev;
717 tmp_fmol -> next = to_remove -> next;
718 to_remove -> next -> prev = tmp_fmol;
719 }
720 else
721 {
722 to_remove = to_remove -> prev;
723 to_remove -> next = NULL;
724 }
725 }
726
727 tmp_field -> molecules --;
729 }
730 break;
731 default:
733 done = TRUE;
734 break;
735 }
736 if (done) destroy_this_dialog (rmol);
737}
738
748G_MODULE_EXPORT void remove_molecule_from_field (GSimpleAction * action, GVariant * parameter, gpointer data)
749{
750 to_remove = (field_molecule *) data;
751 int i, j;
752 field_object = 0;
753 gchar * str = g_strdup_printf (_("Select the molecule to merge molecule \"%s\" with"), to_remove -> name);
754 GtkWidget * rmol = dialogmodal (str, GTK_WINDOW(field_assistant));
755 g_free (str);
756 gtk_dialog_add_button (GTK_DIALOG(rmol), _("Apply"), GTK_RESPONSE_APPLY);
757
758 GtkWidget * remove_tree = NULL;
759 GtkTreeIter iter;
760
761 gchar * mol_title[4] = {i18n("Id."), i18n("Name"), i18n("Multiplicity"), i18n("Viz.3D & Merge with")};
762 gchar * ctype[4]={"text", "text", "text", "active"};
763 GType col_type[4] = {G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN};
764
765 active_col = 3;
766 a_mol = 0;
767 new_mol = allocint (1);
768 GtkTreeStore * remove_model = gtk_tree_store_newv (4, col_type);
769 remove_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(remove_model));
770 for (i=0; i<4; i++)
771 {
772 if (i < 3)
773 {
774 remove_renderer[i] = gtk_cell_renderer_text_new ();
775 }
776 else
777 {
778 remove_renderer[i] = gtk_cell_renderer_toggle_new ();
779 gtk_cell_renderer_toggle_set_radio (GTK_CELL_RENDERER_TOGGLE(remove_renderer[i]), TRUE);
780 g_signal_connect (G_OBJECT(remove_renderer[i]), "toggled", G_CALLBACK(select_mol), & remove_model);
781 }
782 remove_col[i] = gtk_tree_view_column_new_with_attributes (_(mol_title[i]), remove_renderer[i], ctype[i], i, NULL);
783 gtk_tree_view_append_column (GTK_TREE_VIEW(remove_tree), remove_col[i]);
784 if (i < 3)
785 {
786 gtk_tree_view_column_set_cell_data_func (remove_col[i], remove_renderer[i], molecule_set_color, NULL, NULL);
787 }
788 else
789 {
790 gtk_tree_view_column_set_cell_data_func (remove_col[i], remove_renderer[i], set_sensitive_mol, NULL, NULL);
791 }
792 }
793 // fill model
794 tmp_fmol = tmp_field -> first_molecule;
795 j = 0;
796 for (i=0; i<tmp_field -> molecules; i++)
797 {
798 if (tmp_fmol != to_remove && tmp_fmol -> mol -> id == to_remove -> mol -> id)
799 {
800 j ++;
801 gtk_tree_store_append (remove_model, & iter, NULL);
802 gtk_tree_store_set (remove_model, & iter, 0, i+1,
803 1, tmp_fmol -> name,
804 2, tmp_fmol -> multi,
805 3, 0, -1);
806 }
807 if (tmp_fmol -> next != NULL) tmp_fmol = tmp_fmol -> next;
808 }
810 g_object_unref (remove_model);
811 gtk_tree_view_expand_all (GTK_TREE_VIEW(remove_tree));
812
813 i = ((j+1)*40 < 500) ? (j+1)*40 : 500;
814 GtkWidget * scrollsets = create_scroll (dialog_get_content_area (rmol), 375, i, GTK_SHADOW_ETCHED_IN);
815 add_container_child (CONTAINER_SCR, scrollsets, remove_tree);
816 remove_label = gtk_label_new (remove_text(-1, -1, to_remove -> name));
817 gtk_label_set_use_markup (GTK_LABEL(remove_label), TRUE);
818 add_box_child_start (GTK_ORIENTATION_VERTICAL, dialog_get_content_area (rmol), remove_label, FALSE, FALSE, 0);
819 run_this_gtk_dialog (rmol, G_CALLBACK(run_remove_molecule_from_field), NULL);
820}
insertion_menu mol[]
Definition w_library.c:193
void field_question(gchar *question, GCallback handler, gpointer data)
ask the use to confirm something
Definition calc.c:103
gboolean selection_confirmed
Definition calc.c:77
G_MODULE_EXPORT void confirm_selection(GtkDialog *dialog, gint response_id, gpointer data)
confirm that the selection is good
Definition calc.c:88
Variable declarations for the MD input preparation assistants.
ColRGBA init_color(int id, int numid)
initialize color based id number over total number of elements
Definition initcoord.c:81
GtkTreeStore * add_model
Definition cpmd_nose.c:157
ColRGBA col
Definition d_measures.c:77
int atoms[NUM_STYLES][2]
GtkTreePath * path
Definition datab.c:103
field_molecule * get_active_field_molecule(int a)
retrieve field molecule
Definition dlp_active.c:87
field_atom * get_active_atom(int a, int b)
retrieve field atom
Definition dlp_active.c:145
GtkWidget * remove_label
Definition dlp_mol.c:62
GtkTreeViewColumn * remove_col[5]
Definition dlp_mol.c:64
GtkCellRenderer * remove_renderer[5]
Definition dlp_mol.c:63
field_molecule * duplicate_field_molecule(field_molecule *old_fmol)
create copy of a field molecule
Definition dlp_copy.c:436
GtkWidget * add_tree
Definition dlp_edit.c:929
G_MODULE_EXPORT void edit_field_prop(GSimpleAction *action, GVariant *parameter, gpointer data)
edit field property callback
Definition dlp_edit.c:2994
int * atoms_id
int field_object
Definition dlp_field.c:1069
project * tmp_proj
Definition dlp_field.c:1043
GtkWidget * mol_box[MOLIMIT-1]
Definition dlp_field.c:1033
int num_field_objects
Definition dlp_field.c:1071
void set_mol_num_label()
classical force field prepare the molecule information widget
Definition dlp_field.c:1135
field_atom * tmp_fat
Definition dlp_field.c:1047
int row_id
Definition dlp_field.c:1072
GtkTreeStore * field_model[MAXDATA]
Definition dlp_field.c:1037
G_MODULE_EXPORT void changed_mol_box(GtkComboBox *box, gpointer data)
classical force field assistant change the target molecule for the page
Definition dlp_field.c:1891
void fill_field_model(GtkTreeStore *store, int f, int m)
classical force field fill the tree store
Definition dlp_field.c:1389
field_molecule * tmp_fmol
Definition dlp_field.c:1045
GType col_type[MAXDATA][12]
Definition dlp_field.c:946
GtkWidget * create_combo_mol(int f)
classical force field create molecule selection combo box
Definition dlp_field.c:2600
GtkWidget * field_assistant
Definition dlp_field.c:1030
coord_info * tmp_coord
Definition dlp_field.c:1044
classical_field * tmp_field
Definition dlp_field.c:1041
GtkWidget * combo_mol[MOLIMIT-1]
Definition dlp_field.c:1034
Variable declarations for the creation of the DL_POLY input file(s).
#define MOLIMIT
Definition dlp_field.h:117
tint toviz
Definition dlp_viz.c:75
void visualize_object(int id, int jd, int kd)
visualize object and update OpenGL rendering
Definition dlp_viz.c:550
gchar * set_field_atom_name(field_atom *ato, field_molecule *mol)
get name string for field atom
Definition dlp_init.c:247
int multi
Definition dlp_init.c:121
void find_atom_id_in_field_molecule()
find field atom id in field molecule (fragment multiplicity > 1)
Definition dlp_init.c:1960
int * new_mol
Definition dlp_mol.c:59
void field_unselect_all()
unselect all atoms
Definition dlp_viz.c:130
field_molecule * to_remove
Definition dlp_mol.c:61
G_MODULE_EXPORT void run_remove_molecule_from_field(GtkDialog *rmol, gint response_id, gpointer data)
remove molecule from force field - running the dialog
Definition dlp_mol.c:643
void set_sensitive_mol(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
set renderer sensitivity in the force field molecule selection tree store
Definition dlp_mol.c:149
G_MODULE_EXPORT void add_molecule_to_field(GSimpleAction *action, GVariant *parameter, gpointer data)
add molecule to force field - creating the dialog
Definition dlp_mol.c:466
void prepare_atoms_to_merge(field_atom *at, field_molecule *new_mol, field_molecule *old_mol)
update the data for the newly 'merged' field atom
Definition dlp_mol.c:569
G_MODULE_EXPORT void select_mol(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
on select field molecule toggle callback
Definition dlp_mol.c:174
void viz_fragment(field_molecule *fmol, int id, int viz)
show / hide fragment
Definition dlp_viz.c:115
void molecule_set_color(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
set renderer color in the force field molecule selection tree store
Definition dlp_mol.c:297
G_MODULE_EXPORT void run_add_molecule_to_field(GtkDialog *dialog, gint response_id, gpointer data)
add molecule to force field - running the dialog
Definition dlp_mol.c:314
gchar * set_field_atom_name(field_atom *ato, field_molecule *mol)
get name string for field atom
Definition dlp_init.c:247
dint ** atomd_id_save
Definition dlp_mol.c:211
ColRGBA init_color(int id, int numid)
initialize color based id number over total number of elements
Definition initcoord.c:81
void check_to_visualize_properties(int id)
check if it is requried to update rendering
Definition dlp_viz.c:766
int a_mol
Definition dlp_mol.c:58
G_MODULE_EXPORT void remove_molecule_from_field(GSimpleAction *action, GVariant *parameter, gpointer data)
remove molecule from force field - creating the dialog
Definition dlp_mol.c:748
field_atom * new_atom_to_merge(int id, field_molecule *fmol)
merge field atoms from a field molecule
Definition dlp_mol.c:609
gboolean removing
Definition dlp_mol.c:65
void merge_all_atoms_to_mol(field_molecule *new_mol, int mstart)
merge all field atoms to another field molecule
Definition dlp_mol.c:533
void clear_field_atoms(field_molecule *fmol, field_atom *at, int mols, int *mol)
clean the field atom from a list of atom(s)
Definition dlp_mol.c:223
gchar * remove_text(int i, int j, gchar *str)
get removal information text
Definition dlp_mol.c:81
int active_col
Definition dlp_mol.c:57
int old_viz_mol
Definition dlp_mol.c:163
int b_mol
Definition dlp_mol.c:58
void clean_up_molecules_info(gboolean usel)
prepare molecule related widgets in the assistant
Definition dlp_mol.c:120
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:241
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
#define i18n(String)
Definition global.c:80
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:533
void set_renderer_color(int tocol, GtkCellRenderer *renderer, ColRGBA col)
set the color of a GtkCellRenderer
Definition gtk-misc.c:1740
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2139
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:552
@ CONTAINER_SCR
Definition global.h:267
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:861
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 * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:198
Messaging function declarations.
integer(kind=c_int) function molecules(frag_and_mol, allbonds)
Definition global.h:111