atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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\n"
94 "and merged with the one of the selected molecule.",
95 str);
96 break;
97 default:
98 switch (j)
99 {
100 case -1:
101 return g_strdup_printf ("The description of molecule <b>%s</b> will be deleted\n"
102 "and merged with the one of molecule <b>%s</b>",
103 str, get_active_field_molecule(i) -> name);
104 break;
105 default:
106 return g_strdup_printf ("The description of atom <b>%s</b> will be deleted\n"
107 "and merged with the one of field atom <b>%s</b>\n"
108 "Field object(s) using atom <b>%s</b> will also be deleted\n"
109 "and the force field parameter(s) will be updated accordingly.",
110 str, get_active_atom(i,j) -> name, str);
111 break;
112 }
113 break;
114 }
115}
116
124void clean_up_molecules_info (gboolean usel)
125{
126 int i;
127
128 for (i=0; i<MOLIMIT-1; i++)
129 {
132 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, mol_box[i], combo_mol[i], FALSE, FALSE, 10);
134 changed_mol_box (GTK_COMBO_BOX(combo_mol[i]), GINT_TO_POINTER(i+1));
135 }
137 if (usel) field_unselect_all ();
138 gtk_tree_store_clear (field_model[0]);
139 fill_field_model (field_model[0], 0, -1);
140}
141
153void set_sensitive_mol (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
154{
155 int m;
156 gtk_tree_model_get (mod, iter, 0, & m, -1);
157 if (a_mol && m-1 != new_mol[0])
158 {
159 gtk_cell_renderer_set_visible (renderer, FALSE);
160 }
161 else
162 {
163 gtk_cell_renderer_set_visible (renderer, TRUE);
164 }
165}
166
168
178G_MODULE_EXPORT void select_mol (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
179{
180 GtkTreeStore ** model = (GtkTreeStore **)data;
181 GtkTreeIter iter;
182 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
183 gtk_tree_model_get_iter (GTK_TREE_MODEL(* model), & iter, path);
184 if (gtk_cell_renderer_toggle_get_active(cell_renderer))
185 {
186 new_mol[a_mol-1] = -1;
187 a_mol --;
188 gtk_tree_store_set (* model, & iter, active_col, 0, -1);
189 toviz.c = 0;
190 }
191 else
192 {
193 a_mol ++;
194 gtk_tree_store_set (* model, & iter, active_col, 1, -1);
195 gtk_tree_model_get (GTK_TREE_MODEL(* model), & iter, 0, & new_mol[a_mol-1], -1);
196 new_mol[a_mol-1] --;
197 toviz.c = 1;
198 }
199 if (active_col == 1)
200 {
201 toviz.a = 2;
202 gtk_tree_model_get (GTK_TREE_MODEL(* model), & iter, 0, & toviz.b, -1);
204 }
205 else if (active_col == 3)
206 {
207 if (toviz.c) old_viz_mol = new_mol[0];
210 gtk_label_set_text (GTK_LABEL(remove_label), remove_text(new_mol[0], -1, to_remove -> name));
211 gtk_label_set_use_markup (GTK_LABEL(remove_label), TRUE);
212 }
213}
214
216
227void clear_field_atoms (field_molecule * fmol, field_atom* at, int mols, int * mol)
228{
229 int i, j, k, l;
230 l = 0;
231 for (i=0; i < at -> num; i++)
232 {
233 k = at -> list[i];
234 for (j=0; j < mols; j++)
235 {
236 if (tmp_proj -> atoms[0][k].coord[2] == mol[j])
237 {
238 l ++;
239 }
240 }
241 }
242 int * r_list = allocint (l);
243 int * s_list = allocint (l);
244 int * t_list = allocint (l);
245 l = -1;
246 at -> frozen = 0;
247 for (i=0; i < at -> num; i++)
248 {
249 k = at -> list[i];
250 for (j=0; j < mols; j++)
251 {
252 if (tmp_proj -> atoms[0][k].coord[2] == mol[j])
253 {
254 l ++;
255 r_list[l] = k;
256 s_list[l] = at -> list_id[i];
257 t_list[l] = at -> frozen_id[i];
258 if (t_list[l]) at -> frozen ++;
259 }
260 }
261 }
262 at -> num = l+1;
263 at -> list = NULL;
264 at -> list = allocint (at -> num);
265 at -> list_id = NULL;
266 at -> list_id = allocint (at -> num);
267 at -> frozen_id = NULL;
268 at -> frozen_id = allocbool (at -> num);
269 for (i=0; i < at -> num; i++)
270 {
271 at -> list[i] = r_list[i];
272 at -> list_id[i] = s_list[i];
273 at -> frozen_id[i] = t_list[i];
274 j = at -> list[i];
275 k = at -> list_id[i];
276 for (l=0; l<mols; l++)
277 {
278 if (tmp_proj -> atoms[0][j].coord[2] == mol[l])
279 {
280 atomd_id_save[k][l].a = at -> id;
281 atomd_id_save[k][l].b = i;
282 }
283 }
284 }
285 g_free (r_list);
286 g_free (s_list);
287 g_free (t_list);
288}
289
301void molecule_set_color (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
302{
303 int i, j;
304 gtk_tree_model_get (mod, iter, active_col, & j, -1);
305 gtk_tree_model_get (mod, iter, 0, & i, -1);
306 set_renderer_color (j, renderer, init_color (i-1, num_field_objects));
307}
308
318G_MODULE_EXPORT void run_add_molecule_to_field (GtkDialog * dialog, gint response_id, gpointer data)
319{
320 int i, j, k;
321 int * old_mol = NULL;
322 gchar * str;
323 gboolean done = FALSE;
324 gboolean saveit = FALSE;
325 // Id - Name - Multiplicity - Select
326 // While selected < m apply inactif
327 switch (response_id)
328 {
329 case GTK_RESPONSE_APPLY:
330 if (a_mol > 0 && a_mol < tmp_fmol -> multi)
331 {
332 if (a_mol > 1)
333 {
334 str = g_strdup_printf ("Fragments N°%d", new_mol[0]+1);
335 if (a_mol > 2)
336 {
337 for (i=1; i<a_mol-1; i++)
338 {
339 str = g_strdup_printf ("%s, %d", str, new_mol[i]+1);
340 }
341 }
342 str = g_strdup_printf ("%s and %d have been selected !", str, new_mol[a_mol-1]+1);
343 str = g_strdup_printf ("%s\nConfirm this choice and create a new field molecule to describe these fragments ?", str);
344 }
345 else
346 {
347 str = g_strdup_printf ("Fragment N°%d has been selected !", new_mol[0]+1);
348 str = g_strdup_printf ("%s\nConfirm this choice and create a new field molecule to describe this fragment ?", str);
349 }
350 selection_confirmed = FALSE;
351 field_question (str, G_CALLBACK(confirm_selection), NULL);
352 g_free (str);
354 {
355 done = TRUE;
357 field_molecule * next_fmol = duplicate_field_molecule (old_fmol);
358 get_active_field_molecule(tmp_field -> molecules-1) -> next = next_fmol;
359 next_fmol -> prev = get_active_field_molecule(tmp_field -> molecules-1);
360 next_fmol -> id = tmp_field -> molecules;
361 next_fmol -> multi = a_mol;
362 next_fmol -> fragments = NULL;
363 next_fmol -> fragments = allocint(a_mol);
364 for (i=0; i<a_mol; i++) next_fmol -> fragments[i] = new_mol[i];
365 // Atoms_id and field atoms
366 atomd_id_save = g_malloc (next_fmol-> mol -> natoms*sizeof*atomd_id_save);
367 for (i=0; i<next_fmol-> mol -> natoms; i++)
368 {
369 atomd_id_save[i] = g_malloc (next_fmol -> multi*sizeof*atomd_id_save[i]);
370 }
371 tmp_fat = next_fmol -> first_atom;
372 for (i=0; i < next_fmol -> atoms; i++)
373 {
374 clear_field_atoms (next_fmol, tmp_fat, a_mol, new_mol);
375 tmp_fat -> name = g_strdup_printf ("%s", set_field_atom_name (tmp_fat, next_fmol));
376 if (tmp_fat -> next != NULL) tmp_fat = tmp_fat -> next;
377 }
378 g_free (next_fmol -> atoms_id);
379 next_fmol -> atoms_id = NULL;
380 next_fmol -> atoms_id = g_malloc (next_fmol-> mol -> natoms*sizeof*next_fmol -> atoms_id);
381 for (i=0; i<next_fmol-> mol -> natoms; i++)
382 {
383 next_fmol -> atoms_id[i] = g_malloc (next_fmol -> multi*sizeof*next_fmol -> atoms_id[i]);
384 for (j=0; j<next_fmol -> multi; j++)
385 {
386 next_fmol -> atoms_id[i][j].a = atomd_id_save[i][j].a;
387 next_fmol -> atoms_id[i][j].b = atomd_id_save[i][j].b;
388 }
389 }
390 g_free (atomd_id_save);
391 old_mol = allocint(old_fmol -> multi - a_mol);
392 k = -1;
393 for (i=0; i<old_fmol -> multi; i++)
394 {
395 saveit = TRUE;
396 for (j=0; j<a_mol; j++)
397 {
398 if (new_mol[j] == old_fmol -> fragments[i])
399 {
400 saveit = FALSE;
401 break;
402 }
403 }
404 if (saveit)
405 {
406 k++;
407 old_mol[k] = old_fmol -> fragments[i];
408 }
409 }
410 new_mol = NULL;
411 // Now we deal with atoms_id and the field atoms
412 atomd_id_save = g_malloc (old_fmol-> mol -> natoms*sizeof*atomd_id_save);
413 for (i=0; i<old_fmol -> mol -> natoms; i++)
414 {
415 atomd_id_save[i] = g_malloc ((old_fmol -> multi - a_mol)*sizeof*atomd_id_save[i]);
416 }
417 tmp_fat = old_fmol -> first_atom;
418 for (i=0; i < old_fmol -> atoms; i++)
419 {
420 clear_field_atoms (old_fmol, tmp_fat, old_fmol -> multi - a_mol, old_mol);
421 if (tmp_fat -> next != NULL) tmp_fat = tmp_fat -> next;
422 }
423 old_fmol -> multi -= a_mol;
424 g_free (old_fmol -> atoms_id);
425 old_fmol -> atoms_id = NULL;
426 old_fmol -> atoms_id = g_malloc (old_fmol-> mol -> natoms*sizeof*old_fmol -> atoms_id);
427 for (i=0; i<old_fmol-> mol -> natoms; i++)
428 {
429 old_fmol -> atoms_id[i] = g_malloc (old_fmol -> multi*sizeof*old_fmol -> atoms_id[i]);
430 for (j=0; j<old_fmol -> multi; j++)
431 {
432 old_fmol -> atoms_id[i][j].a = atomd_id_save[i][j].a;
433 old_fmol -> atoms_id[i][j].b = atomd_id_save[i][j].b;
434 }
435 }
436 g_free (atomd_id_save);
437 old_fmol -> fragments = NULL;
438 old_fmol -> fragments = allocint(old_fmol -> multi);
439 for (i=0; i<old_fmol -> multi; i++) old_fmol -> fragments[i] = old_mol[i];
440 old_mol = NULL;
442 tmp_field -> molecules ++;
443 edit_field_prop (NULL, NULL, GINT_TO_POINTER(0));
445 }
446 }
447 break;
448 default:
450 done = TRUE;
451 break;
452 }
453 if (done)
454 {
455 g_free (new_mol);
456 new_mol = NULL;
457 destroy_this_dialog (dialog);
458 }
459}
460
470G_MODULE_EXPORT void add_molecule_to_field (GSimpleAction * action, GVariant * parameter, gpointer data)
471{
472 int i;
473 field_object = 0;
474 gchar * str = g_strdup_printf ("Please select the fragment(s) of the new molecule");
475 GtkWidget * amol = dialogmodal (str, GTK_WINDOW(field_assistant));
476 g_free (str);
477 gtk_dialog_add_button (GTK_DIALOG(amol), "Apply", GTK_RESPONSE_APPLY);
478 GtkWidget * add_tree = NULL;
479 GtkTreeIter iter;
480 GtkTreeViewColumn * mol_col[2];
481 GtkCellRenderer * mol_cell[2];
482 gchar * mol_title[2] = {"Fragment", "Viz.3D & Select"};
483 gchar * ctype[2]={"text", "active"};
484 GType col_type[2] = {G_TYPE_INT, G_TYPE_BOOLEAN};
485
486 active_col = 1;
487 a_mol = 0;
488 GtkTreeStore * add_model = gtk_tree_store_newv (2, col_type);
489 add_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(add_model));
491 for (i=0; i<2; i++)
492 {
493 if (i == 0)
494 {
495 mol_cell[i] = gtk_cell_renderer_text_new ();
496 }
497 else
498 {
499 mol_cell[i] = gtk_cell_renderer_toggle_new ();
500 g_signal_connect (G_OBJECT(mol_cell[i]), "toggled", G_CALLBACK(select_mol), & add_model);
501 }
502 mol_col[i] = gtk_tree_view_column_new_with_attributes (mol_title[i], mol_cell[i], ctype[i], i, NULL);
503 gtk_tree_view_append_column (GTK_TREE_VIEW(add_tree), mol_col[i]);
504 gtk_tree_view_column_set_alignment (mol_col[i], 0.5);
505 if (i == 0)
506 {
507 gtk_tree_view_column_set_cell_data_func (mol_col[i], mol_cell[i], molecule_set_color, NULL, NULL);
508 }
509 }
510 // fill model
511 num_field_objects = tmp_coord-> totcoord[2];
512 new_mol = NULL;
514 for (i=0; i<tmp_fmol -> multi; i++)
515 {
516 gtk_tree_store_append (add_model, & iter, NULL);
517 gtk_tree_store_set (add_model, & iter, 0, tmp_fmol -> fragments[i] + 1, 1, 0, -1);
518 new_mol[i] = -1;
519 }
520 g_object_unref (add_model);
521 gtk_tree_view_expand_all (GTK_TREE_VIEW(add_tree));
522
523 i = ((tmp_fmol -> multi+1)*35 < 500) ? (tmp_fmol -> multi+1)*35 : 500;
524 GtkWidget * scrollsets = create_scroll (dialog_get_content_area (amol), 220, i, GTK_SHADOW_ETCHED_IN);
526 run_this_gtk_dialog (amol, G_CALLBACK(run_add_molecule_to_field), NULL);
527}
528
538{
539 field_atom* fat, * fbt;
540 fat = get_active_atom (new_mol -> id, new_mol -> atoms-1);
541 int i, j, k, l, m, n;
542 for (i=0; i<fat -> num; i++)
543 {
544 j = fat -> list[i];
545 k = fat -> list_id[i];
546 l = new_mol -> atoms_id[k][0].a;
547 fbt = get_active_atom (new_mol -> id, l);
548 fbt -> list[fbt -> num] = j;
549 fbt -> list_id[fbt -> num] = k;
550 m = tmp_proj -> atoms[0][j].coord[2];
551 for (n=mstart; n<new_mol -> multi; n++)
552 {
553 if (new_mol -> fragments[n] == m)
554 {
555 new_mol -> atoms_id[k][n].a = fbt -> id;
556 new_mol -> atoms_id[k][n].b = fbt -> num;
557 break;
558 }
559 }
560 fbt -> num ++;
561 }
562}
563
574{
575 int i, j;
576 int * saved_list = allocint (at -> num);
577 int * saved_list_id = allocint (at -> num);
578 int * saved_frozen_id = allocbool (at -> num);
579 for (j=0; j < at -> num; j++)
580 {
581 saved_list[j] = at -> list[j];
582 saved_list_id[j] = at -> list_id[j];
583 saved_frozen_id[j] = at -> frozen_id[j];
584 }
585 i = at -> num;
586 i /= (new_mol -> multi - old_mol -> multi);
587 i *= old_mol -> multi;
588 g_free (at -> list);
589 at -> list = allocint (at -> num + i);
590 g_free (at -> list_id);
591 at -> list_id = allocint (at -> num + i);
592 g_free (at -> frozen_id);
593 at -> frozen_id = allocbool (at -> num + i);
594 for (j=0; j< at -> num; j++)
595 {
596 at -> list[j] = saved_list[j];
597 at -> list_id[j] = saved_list_id[j];
598 at -> frozen_id[j] = saved_frozen_id[j];
599 }
600 g_free (saved_list);
601 g_free (saved_list_id);
602 g_free (saved_frozen_id);
603}
604
614{
615 field_atom* fat, * fbt;
616 fat = g_malloc (sizeof*fat);
617 fat -> id = id;
618 fat -> sp = -1;
619 fat -> num = fmol -> mol -> natoms * fmol -> multi;
620 fat -> list = allocint (fmol -> mol -> natoms * fmol -> multi);
621 fat -> list_id = allocint (fmol -> mol -> natoms * fmol -> multi);
622 fbt = fmol -> first_atom;
623 int i, j;
624 i = 0;
625 while (fbt != NULL)
626 {
627 for (j=0; j<fbt -> num; j++)
628 {
629 fat -> list[i] = fbt -> list[j];
630 fat -> list_id[i] = fbt -> list_id[j];
631 i ++;
632 }
633 fbt = fbt -> next;
634 }
635 return fat;
636}
637
647G_MODULE_EXPORT void run_remove_molecule_from_field (GtkDialog * rmol, gint response_id, gpointer data)
648{
649 int i, j;
650 gboolean done = FALSE;
651 switch (response_id)
652 {
653 case GTK_RESPONSE_APPLY:
654 if (a_mol)
655 {
656 done = TRUE;
658 int * old_mol = allocint (to_merge -> multi);
659 for (i=0; i<to_merge -> multi; i++) old_mol[i] = to_merge -> fragments[i];
660 g_free (to_merge -> fragments);
661 to_merge -> fragments = allocint (to_merge -> multi + to_remove -> multi);
662 for (i=0; i<to_merge -> multi; i++) to_merge -> fragments[i] = old_mol[i];
663 old_mol = NULL;
664 for (i=to_merge -> multi; i < to_merge -> multi + to_remove -> multi; i++)
665 {
666 to_merge -> fragments[i] = to_remove -> fragments[i - to_merge -> multi];
667 }
668 atomd_id_save = g_malloc (to_merge -> mol -> natoms*sizeof*atomd_id_save);
669 for (i=0; i<to_merge -> mol -> natoms; i++)
670 {
671 atomd_id_save[i] = g_malloc ((to_merge -> multi+to_remove -> multi)*sizeof*atomd_id_save[i]);
672 for (j=0; j<to_merge -> multi; j++)
673 {
674 atomd_id_save[i][j].a = to_merge -> atoms_id[i][j].a;
675 atomd_id_save[i][j].b = to_merge -> atoms_id[i][j].b;
676 }
677 for (j=to_merge -> multi; j<to_merge -> multi+to_remove -> multi; j++)
678 {
679 atomd_id_save[i][j].a = -1;
680 atomd_id_save[i][j].b = -1;
681 }
682 }
683 to_merge -> multi += to_remove -> multi;
684 g_free (to_merge -> atoms_id);
685 to_merge -> atoms_id = g_malloc (to_merge -> mol -> natoms*sizeof*to_merge -> atoms_id);
686 for (i=0; i<to_merge -> mol -> natoms; i++)
687 {
688 to_merge -> atoms_id[i] = g_malloc (to_merge -> multi*sizeof*to_merge -> atoms_id[i]);
689 for (j=0; j<to_merge -> multi; j++)
690 {
691 to_merge -> atoms_id[i][j].a = atomd_id_save[i][j].a;
692 to_merge -> atoms_id[i][j].b = atomd_id_save[i][j].b;
693 }
694 }
695 g_free (atomd_id_save);
696 tmp_fat = get_active_atom (to_merge -> id, to_merge -> atoms -1);
697 tmp_fat -> next = new_atom_to_merge (to_merge -> atoms, to_remove);
698 to_merge -> atoms ++;
699 tmp_fat = to_merge -> first_atom;
700 for (i=0; i < to_merge -> atoms-1; i++)
701 {
703 if (tmp_fat -> next != NULL) tmp_fat = tmp_fat -> next;
704 }
705 merge_all_atoms_to_mol (to_merge, to_merge -> multi - to_remove -> multi);
706 tmp_fat = get_active_atom (to_merge -> id, to_merge -> atoms-2);
707 g_free (tmp_fat -> next);
708 tmp_fat -> next = NULL;
709 to_merge -> atoms --;
710
711 if (to_remove == tmp_field -> first_molecule)
712 {
713 tmp_field -> first_molecule = to_remove -> next;
714 tmp_field -> first_molecule -> prev = NULL;
715 }
716 else
717 {
718 if (to_remove -> next != NULL)
719 {
720 tmp_fmol = to_remove -> prev;
721 tmp_fmol -> next = to_remove -> next;
722 to_remove -> next -> prev = tmp_fmol;
723 }
724 else
725 {
726 to_remove = to_remove -> prev;
727 to_remove -> next = NULL;
728 }
729 }
730
731 tmp_field -> molecules --;
733 }
734 break;
735 default:
737 done = TRUE;
738 break;
739 }
740 if (done) destroy_this_dialog (rmol);
741}
742
752G_MODULE_EXPORT void remove_molecule_from_field (GSimpleAction * action, GVariant * parameter, gpointer data)
753{
754 to_remove = (field_molecule *) data;
755 int i, j;
756 field_object = 0;
757 gchar * str = g_strdup_printf ("Select the molecule to merge molecule \"%s\" with", to_remove -> name);
758 GtkWidget * rmol = dialogmodal (str, GTK_WINDOW(field_assistant));
759 g_free (str);
760 gtk_dialog_add_button (GTK_DIALOG(rmol), "Apply", GTK_RESPONSE_APPLY);
761
762 GtkWidget * remove_tree = NULL;
763 GtkTreeIter iter;
764
765 gchar * mol_title[4] = {"Id", "Name", "Multiplicity", "Viz.3D & Merge with"};
766 gchar * ctype[4]={"text", "text", "text", "active"};
767 GType col_type[4] = {G_TYPE_INT, G_TYPE_STRING, G_TYPE_INT, G_TYPE_BOOLEAN};
768
769 active_col = 3;
770 a_mol = 0;
771 new_mol = allocint(1);
772 GtkTreeStore * remove_model = gtk_tree_store_newv (4, col_type);
773 remove_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(remove_model));
774 for (i=0; i<4; i++)
775 {
776 if (i < 3)
777 {
778 remove_renderer[i] = gtk_cell_renderer_text_new ();
779 }
780 else
781 {
782 remove_renderer[i] = gtk_cell_renderer_toggle_new ();
783 gtk_cell_renderer_toggle_set_radio (GTK_CELL_RENDERER_TOGGLE(remove_renderer[i]), TRUE);
784 g_signal_connect (G_OBJECT(remove_renderer[i]), "toggled", G_CALLBACK(select_mol), & remove_model);
785 }
786 remove_col[i] = gtk_tree_view_column_new_with_attributes (mol_title[i], remove_renderer[i], ctype[i], i, NULL);
787 gtk_tree_view_append_column (GTK_TREE_VIEW(remove_tree), remove_col[i]);
788 if (i < 3)
789 {
790 gtk_tree_view_column_set_cell_data_func (remove_col[i], remove_renderer[i], molecule_set_color, NULL, NULL);
791 }
792 else
793 {
794 gtk_tree_view_column_set_cell_data_func (remove_col[i], remove_renderer[i], set_sensitive_mol, NULL, NULL);
795 }
796 }
797 // fill model
798 tmp_fmol = tmp_field -> first_molecule;
799 j = 0;
800 for (i=0; i<tmp_field -> molecules; i++)
801 {
802 if (tmp_fmol != to_remove && tmp_fmol -> mol -> id == to_remove -> mol -> id)
803 {
804 j ++;
805 gtk_tree_store_append (remove_model, & iter, NULL);
806 gtk_tree_store_set (remove_model, & iter, 0, i+1,
807 1, tmp_fmol -> name,
808 2, tmp_fmol -> multi,
809 3, 0, -1);
810 }
811 if (tmp_fmol -> next != NULL) tmp_fmol = tmp_fmol -> next;
812 }
814 g_object_unref (remove_model);
815 gtk_tree_view_expand_all (GTK_TREE_VIEW(remove_tree));
816
817 i = ((j+1)*40 < 500) ? (j+1)*40 : 500;
818 GtkWidget * scrollsets = create_scroll (dialog_get_content_area (rmol), 375, i, GTK_SHADOW_ETCHED_IN);
819 add_container_child (CONTAINER_SCR, scrollsets, remove_tree);
820 remove_label = gtk_label_new (remove_text(-1, -1, to_remove -> name));
821 gtk_label_set_use_markup (GTK_LABEL(remove_label), TRUE);
822 add_box_child_start (GTK_ORIENTATION_VERTICAL, dialog_get_content_area (rmol), remove_label, FALSE, FALSE, 0);
823 run_this_gtk_dialog (rmol, G_CALLBACK(run_remove_molecule_from_field), NULL);
824}
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.
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
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:918
G_MODULE_EXPORT void edit_field_prop(GSimpleAction *action, GVariant *parameter, gpointer data)
edit field property callback
Definition dlp_edit.c:2993
int * atoms_id
int field_object
Definition dlp_field.c:979
project * tmp_proj
Definition dlp_field.c:953
GtkWidget * mol_box[MOLIMIT-1]
Definition dlp_field.c:943
int num_field_objects
Definition dlp_field.c:981
void set_mol_num_label()
classical force field prepare the molecule information widget
Definition dlp_field.c:1045
field_atom * tmp_fat
Definition dlp_field.c:957
int row_id
Definition dlp_field.c:982
GtkTreeStore * field_model[MAXDATA]
Definition dlp_field.c:947
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:1770
void fill_field_model(GtkTreeStore *store, int f, int m)
classical force field fill the tree store
Definition dlp_field.c:1264
field_molecule * tmp_fmol
Definition dlp_field.c:955
GType col_type[MAXDATA][12]
Definition dlp_field.c:856
GtkWidget * create_combo_mol(int f)
classical force field create molecule selection combo box
Definition dlp_field.c:2479
GtkWidget * field_assistant
Definition dlp_field.c:940
coord_info * tmp_coord
Definition dlp_field.c:954
classical_field * tmp_field
Definition dlp_field.c:951
GtkWidget * combo_mol[MOLIMIT-1]
Definition dlp_field.c:944
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:552
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:1972
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:647
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:153
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:470
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:573
G_MODULE_EXPORT void select_mol(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
on select field molecule toggle callback
Definition dlp_mol.c:178
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:301
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:318
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:215
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:768
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:752
field_atom * new_atom_to_merge(int id, field_molecule *fmol)
merge field atoms from a field molecule
Definition dlp_mol.c:613
gboolean removing
Definition dlp_mol.c:65
GtkWidget * remove_label
Definition dlp_mol.c:62
void merge_all_atoms_to_mol(field_molecule *new_mol, int mstart)
merge all field atoms to another field molecule
Definition dlp_mol.c:537
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:227
GtkTreeViewColumn * remove_col[5]
Definition dlp_mol.c:64
gchar * remove_text(int i, int j, gchar *str)
get removal information text
Definition dlp_mol.c:81
GtkCellRenderer * remove_renderer[5]
Definition dlp_mol.c:63
int active_col
Definition dlp_mol.c:57
int old_viz_mol
Definition dlp_mol.c:167
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:124
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:254
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
void set_renderer_color(int tocol, GtkCellRenderer *renderer, ColRGBA col)
set the color of a GtkCellRenderer
Definition gtk-misc.c:1653
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1960
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
@ CONTAINER_SCR
Definition global.h:251
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
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:299
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:189
Messaging function declarations.
integer(kind=c_int) function molecules(frag_and_mol, allbonds)
Definition global.h:97
int b
Definition global.h:99
int a
Definition global.h:98
coord_info * coord
Definition global.h:956
int b
Definition global.h:106
int c
Definition global.h:107
int a
Definition global.h:105