atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
dlp_ff_match.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_ff_match.c'
24*
25* Contains:
26*
27
28 - The functions the list the available database parameters for the atom database window
29
30*
31* List of functions:
32
33 int this_body_has_atom (field_nth_body * body, char * name);
34
35 gboolean is_this_object_a_match (int fsid, int nat, int * ffc, int * fpar);
36
37 static gboolean update_rend (GtkTreeModel * model, GtkTreeIter * iter, gpointer data);
38
39 G_MODULE_EXPORT gboolean on_ff_button_event (GtkWidget * widget, GdkEvent * event, gpointer data);
40
41 gchar * get_this_prop_param (int sid, int key, int calc, int newp, float * val);
42 gchar * get_this_prop_string (int sid, int oid, int type, int calc);
43
44 void update_result_list (int sid, field_object_match * new_match);
45 void fill_update_model (GtkTreeStore * store);
46 void get_update_tree_data (GtkWidget * tree, gpointer data, GtkTreePath * path);
47 void ff_button_event (double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data);
48 void ff_button_event (GdkEvent * event, double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data);
49 void win_update_tree (GtkWidget * vbx);
50 void look_up_this_field_object (int fsid, int fpid, int ssid, int nat, int * fsp, int * fat);
51 void check_this_fprop (int fsid, int fpid, int ssid, int * fat, int * fsp);
52 void check_atom_for_updates ();
53
54 G_MODULE_EXPORT void changed_update_renderer (GtkCellRendererCombo * combo, gchar * path_string, GtkTreeIter * iter, gpointer data);
55 G_MODULE_EXPORT void on_ff_button_pressed (GtkGesture * gesture, int n_press, double x, double y, gpointer data);
56 G_MODULE_EXPORT void on_ff_button_released (GtkGesture * gesture, int n_press, double x, double y, gpointer data);
57 G_MODULE_EXPORT void on_toggle_update (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data);
58 G_MODULE_EXPORT void run_check_atom_for_updates (GtkDialog * dialog, gint response_id, gpointer data);
59 G_MODULE_EXPORT void changed_field_prop_combo (GtkComboBox * box, gpointer data);
60
61 GtkWidget * create_update_tree ();
62 GtkWidget * create_field_prop_combo (int f, int is_moy);
63
64 GtkTreeModel * global_render_tree ();
65
66 field_data * get_ff_data (int i, int j);
67 field_object_match * duplicate_match (field_object_match * old_m);
68
69 dint get_visible (gboolean result, gchar * the_name);
70
71*/
72
73#include "global.h"
74#include "interface.h"
75#include "glwindow.h"
76#include "glview.h"
77#include "dlp_field.h"
78
79extern int * atoms_id;
80extern int ** atoms_id_list;
81extern int * field_objects;
82extern char *** ff_atoms;
83extern char * fvars_bond[2][FBONDS][FBONDS_P];
84extern char * fvars_angle[2][FANGLES][FANGLES_P];
85extern char * fvars_dihedral[2][FDIHEDRAL][FDIHEDRAL_P];
86extern char * fvars_inversion[2][FINVERS][FINVERS_P];
87extern char * fvars_vdw[2][FVDW][FVDW_P];
88extern gchar * felemts[MAXDATA+1];
89extern GtkWidget * afftype;
90extern GtkWidget * field_key_combo;
91extern GtkWidget * p_box;
92extern GtkWidget * param_box;
96
97extern GtkWidget * param_prop_param_box (int pid);
98extern gchar * get_this_vdw_string ();
99extern G_MODULE_EXPORT void markup_action_renderer (GtkCellRendererCombo * cell, GtkCellEditable * editable, gchar * path_string, gpointer data);
100extern int get_num_vdw_max ();
101extern gchar * get_body_element_name (field_nth_body * body, int aid, int nbd);
102
103#define NUCOL 8
104
105GtkTreeViewColumn * update_col[NUCOL];
106GtkCellRenderer * update_renderer[NUCOL];
107GtkWidget * update_tree;
108GtkWidget * ff_p_combo[2];
109GtkTreeStore * update_model;
111GtkTreeModel * prop_to_up;
115
126gboolean is_this_object_a_match (int fsid, int nat, int * ffc, int * fpar)
127{
128 int i, j;
129 int has_x = 0;
130 gboolean a_match, b_match;
131 for (i=0; i<nat; i++)
132 {
133 if (fpar[i] == -1 || ffc[i] == -1) has_x ++;
134 }
135 if (has_x == nat) return FALSE;
136 switch (nat)
137 {
138 case 2:
139 for (i=0; i<2; i++)
140 {
141 j = (i == 0) ? 1 : 0;
142 if (ffc[0] == fpar[i] && ffc[1] == fpar[j]) return TRUE;
143 if (ffc[0] == fpar[i] && has_x) return TRUE;
144 if (ffc[1] == fpar[i] && has_x) return TRUE;
145 }
146 return FALSE;
147 break;
148 case 3:
149 if (ffc[1] != fpar[1] && fpar[1] != -1 && ffc[1] != -1) return FALSE;
150 for (i=0; i<3; i=i+2)
151 {
152 j = (i==0) ? 2 : 0;
153 if (ffc[0] == fpar[i] && ffc[2] == fpar[j]) return TRUE;
154 if (ffc[i] == fpar[i] && (ffc[j] == -1 || fpar[j] == -1)) return TRUE;
155 if (ffc[j] == fpar[i] && (ffc[i] == -1 || fpar[j] == -1)) return TRUE;
156 }
157 return FALSE;
158 break;
159 case 4:
160 a_match = b_match = TRUE;
161 for (i=0; i<4; i++)
162 {
163 if (ffc[i] != fpar[i] && ffc[i] != -1 && fpar[i] != -1)
164 {
165 a_match = FALSE;
166 break;
167 }
168 }
169 if (fsid < 6)
170 {
171 for (i=0; i<4; i++)
172 {
173 j = 3-i;
174 if (ffc[i] != fpar[j] && ffc[i] != -1 && fpar[j] != -1)
175 {
176 b_match = FALSE;
177 break;
178 }
179 }
180 }
181 else if (fsid == 6)
182 {
183 if (ffc[0] != fpar[0] && ffc[0] != -1 && fpar[0] != -1)
184 {
185 b_match = FALSE;
186 }
187 else if (ffc[3] != fpar[3] && ffc[3] != -1 && fpar[3] != -1)
188 {
189 b_match = FALSE;
190 }
191 else
192 {
193 if ((ffc[1] == fpar[1] || ffc[1] == -1 || fpar[1] == -1) && (ffc[2] == fpar[2] || ffc[2] == -1 || fpar[2] == -1))
194 {
195 return TRUE;
196 }
197 else if ((ffc[1] == fpar[2] || ffc[1] == -1 || fpar[2] == -1) && (ffc[2] == fpar[1] || ffc[2] == -1 || fpar[1] == -1))
198 {
199 return TRUE;
200 }
201 }
202 }
203 if (! a_match && ! b_match) return FALSE;
204 return TRUE;
205 break;
206 }
207 return TRUE;
208}
209
218field_data * get_ff_data (int i, int j)
219{
220 switch (i/2)
221 {
222 case 0:
223 return ff_bonds[j];
224 break;
225 case 1:
226 return ff_angles[j];
227 break;
228 case 2:
229 return ff_dih[j];
230 break;
231 default:
232 if (i == 6)
233 {
234 return ff_imp;
235 }
236 else if (i == 7)
237 {
238 return ff_inv;
239 }
240 else
241 {
242 return ff_vdw;
243 }
244 break;
245 }
246}
247
259gchar * get_this_prop_param (int sid, int key, int calc, int newp, float * val)
260{
261 char ** vars;
262 char * vbdq[4] = {"k/2", "r<sub>0</sub>", "k'/3", "k''/4"};
263 char * vanq[4] = {"k/2", "θ<sub>0</sub>", "k'/3", "k''/4"};
264 char * vdwij[2] = {"Ɛ<sub>i</sub>", "r0<sub>i</sub>/2.0"};
265 switch (sid/2)
266 {
267 case 0:
268 if (newp && (key == 0 || key == 5))
269 {
270 vars = (char **)vbdq;
271 }
272 else
273 {
274 vars = (char **)fvars_bond[key];
275 }
276 break;
277 case 1:
278 if (newp && key < 2)
279 {
280 vars = (char **)vanq;
281 }
282 else
283 {
284 vars = (char **)fvars_angle[key];
285 }
286 break;
287 default:
288 if (sid > 7)
289 {
290 if (newp && (tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS) && ! calc)
291 {
292 vars = (char **)vdwij;
293 }
294 else
295 {
296 vars = (char **)fvars_vdw[key];
297 }
298 }
299 else if (sid < 7)
300 {
301 vars = (char **)fvars_dihedral[key];
302 }
303 else
304 {
305 vars = (char **)fvars_inversion[key];
306 }
307 break;
308 }
309
310 return g_strdup_printf ("%s pot. (%s)",
311 dlp_to_translate(activef,(sid > 7) ? 10 : sid+2, key) ? _(fnames[activef][(sid > 7) ? 10 : sid+2][key]) : fnames[activef][(sid > 7) ? 10 : sid+2][key],
312 parameters_info ((sid > 7) ? 9 : sid+1, key, vars, val));
313}
314
325gchar * get_this_prop_string (int sid, int oid, int type, int calc)
326{
327 gchar * str;
328 int i, j, k, l;
329 i = (sid > 7) ? 1 : struct_id (sid+7);
330 ff_data = get_ff_data (sid, type);
331 float * val;
332 for (j=0; j<i; j++)
333 {
334 k = ff_data -> atoms_id[oid][j];
335 if (j > 0)
336 {
337 str = g_strdup_printf ("%s-%s", str, (k < 0) ? "X" : ff_atoms[k][2]);
338 }
339 else
340 {
341 str = g_strdup_printf ("%s", (k < 0) ? "X" : ff_atoms[k][2]);
342 }
343 }
344 j = abs(ff_data -> key)-1;
345 k = fvalues[activef][(sid < 8) ? sid+1 : 9][j];
346 val = allocfloat (k);
347 for (l=0; l<k; l++) val[l] = ff_data -> param[oid][l];
348 // Here
349 if (sid == 8 && calc)
350 {
351 if (tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS)
352 {
353 float v = sqrt(ff_data -> param[oid][0]*ff_data -> param[oid][0]);
354 val[0] = v*pow((double)(ff_data -> param[oid][1] + ff_data -> param[oid][1]), 12.0);
355 val[1] = 2.0 * v * pow((double)(ff_data -> param[oid][1] + ff_data -> param[oid][1]), 6.0);
356 }
357 else if (tmp_field -> type <= CVFF_AUG)
358 {
359 for (l=0; l<2; l++) val[l] = sqrt(ff_data -> param[oid][l]*ff_data -> param[oid][l]);
360 }
361 }
362
363 str = g_strdup_printf ("%s: %s", str, get_this_prop_param(sid, j, calc, 1, val));
364 g_free (val);
365 return str;
366}
367
376{
377 field_object_match * new_m = g_malloc0(sizeof*new_m);
378 new_m -> id = old_m -> id;
379 new_m -> obj = old_m -> obj;
380 new_m -> oid = old_m -> oid;
381 new_m -> type = old_m -> type;
382 new_m -> use = old_m -> use;
383 return new_m;
384}
385
394void update_result_list (int sid, field_object_match * new_match)
395{
396 if (tmp_res[sid])
397 {
398 field_object_match * map, * mbp;
399 map = duplicate_match (new_match);
400 mbp = tmp_res[sid];
401 while (mbp)
402 {
403 if (mbp -> id == map -> id && mbp -> obj == map -> obj)
404 {
405 // Changing a value already saved
406 if (mbp -> next && mbp -> prev)
407 {
408 mbp -> prev -> next = map;
409 map -> prev = mbp -> prev;
410 map -> next = mbp -> next;
411 mbp -> next -> prev = map;
412 }
413 else if (mbp -> next)
414 {
415 mbp -> next -> prev = map;
416 map -> next = mbp -> next;
417 }
418 else if (mbp -> prev)
419 {
420 mbp -> prev -> next = map;
421 map -> prev = mbp -> prev;
422 }
423 }
424 else if (! mbp -> next)
425 {
426 mbp -> next = map;
427 map -> prev = mbp -> next;
428 mbp = mbp -> next;
429 }
430 mbp = mbp -> next;
431 }
432 }
433 else
434 {
435 tmp_res[sid] = duplicate_match (new_match);
436 }
437}
438
446void fill_update_model (GtkTreeStore * store)
447{
448 GtkTreeIter prop_level, struct_level;
449 field_atom* upat;
450 int g, h, i, j;
451 gchar * str;
452 gchar * stra, * strb, * strc, * strd, * stre;
453 for (i=0; i<9; i++)
454 {
455 g = (i==8) ? i+1 : i;
456 h = (i==8) ? 2 : struct_id (i+7);
457 if (up_match[i])
458 {
459 if (g%2 && i < 6)
460 {
461 if (i == 3 && tmp_field -> type > AMBER99 && tmp_field -> type < CVFF_AUG)
462 {
463 str = g_strdup_printf ("<b>%s</b> <sup>(2,3)</sup>", _(felemts[8+g]));
464 }
465 else
466 {
467 str = g_strdup_printf ("<b>%s</b> <sup>(2)</sup>", _(felemts[8+g]));
468 }
469 }
470 else if (i < 8)
471 {
472 if (i == 2 && tmp_field -> type > AMBER99 && tmp_field -> type < CVFF_AUG)
473 {
474 str = g_strdup_printf ("<b>%s</b> <sup>(3)</sup>", _(felemts[8+g]));
475 }
476 else
477 {
478 str = g_strdup_printf ("<b>%s</b>", _(felemts[8+g]));
479 }
480 }
481 else if (tmp_field -> type <= AMBER99 || tmp_field -> type > COMPASS)
482 {
483 str = g_strdup_printf ("<b>%s</b> <sup>(3)</sup>", _(felemts[8+i]));
484 }
485 else if (tmp_field -> type <= CHARMMSI)
486 {
487 str = g_strdup_printf ("<b>%s</b> <sup>(4)</sup>", _(felemts[8+i]));
488 }
489 else
490 {
491 str = g_strdup_printf ("<b>%s</b>", _(felemts[8+i]));
492 }
493 gtk_tree_store_append (store, & prop_level, NULL);
494 gtk_tree_store_set (store, & prop_level, 0, -(i+1),
495 1, 0,
496 2, str,
497 3, NULL,
498 4, NULL,
499 5, NULL,
500 6, NULL,
501 NUCOL-1, FALSE, -1);
502 g_free (str);
503 tmp_match = up_match[i];
504 while (tmp_match)
505 {
506 if (i<8)
507 {
508 tmp_fstr = get_active_struct (i, tmp_fmol -> id, tmp_match -> id);
509 if (tmp_match -> obj > 0)
510 {
511 tmp_fprop = get_active_prop (tmp_fstr -> other, tmp_match -> obj - 1);
512 tmp_match -> use = TRUE;
513 }
514 else
515 {
516 tmp_fprop = tmp_fstr -> def;
517 tmp_match -> use = TRUE;
518 }
519 }
520 else
521 {
522 tmp_fbody = get_active_body (tmp_match -> obj, 0);
523 tmp_match -> use = TRUE;
524 }
525 for (j=0; j<h; j++)
526 {
527 if (i < 8)
528 {
529 upat = get_active_atom (tmp_fmol -> id, tmp_fstr -> aid[j]);
530 }
531 else
532 {
533 upat = get_active_atom (tmp_fbody -> ma[j][0], tmp_fbody -> a[j][0]);
534 }
535 if (j > 0)
536 {
537 stra = g_strdup_printf ("%s - ""%s""", stra, upat -> name);
538 if (tmp_match -> obj > 0 && i < 8) strb = g_strdup_printf ("%s-%d", strb, tmp_fprop -> aid[j]+1);
539 strc = g_strdup_printf ("%s - %s", strc, tmp_proj -> chemistry -> label[upat -> sp]);
540 }
541 else
542 {
543 stra = g_strdup_printf ("""%s""", upat -> name);
544 if (tmp_match -> obj > 0 && i < 8) strb = g_strdup_printf ("%d", tmp_fprop -> aid[j]+1);
545 strc = g_strdup_printf ("%s", tmp_proj -> chemistry -> label[upat -> sp]);
546 }
547 }
549 if (tmp_match -> use)
550 {
552 strd = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
553 }
554 else
555 {
556 strd = g_strdup_printf (_("Select ..."));
557 }
558
559 if (i < 8)
560 {
561 stre = g_strdup_printf ("%s", get_this_prop_param(i, tmp_fprop -> key, 1, 0, tmp_fprop -> val));
562 }
563 else
564 {
565 stre = g_strdup_printf ("%s", get_this_prop_param(i, tmp_fbody -> key, 1, 0, tmp_fbody -> val));
566 }
567 if (tmp_match -> obj > 0 && i < 8)
568 {
569 str = g_strdup_printf ("%s", strb);
570 g_free (strb);
571 }
572 else
573 {
574 str = g_strdup_printf ("%s <sup>(*)</sup>", stra);
575 }
576 gtk_tree_store_append (store, & struct_level, & prop_level);
577 while (other_match && other_match -> id == tmp_match -> id && other_match -> obj == tmp_match -> obj)
578 {
579 other_match = other_match -> next;
580 }
581 gtk_tree_store_set (store, & struct_level, 0, i,
582 1, (i == 8) ? tmp_match -> obj : tmp_match -> id,
583 2, NULL,
584 3, str,
585 4, strc,
586 5, strd,
587 6, stre,
588 NUCOL-1, tmp_match -> use, -1);
589 g_free (str);
590 g_free (stra);
591 g_free (strc);
592 g_free (strd);
593 g_free (stre);
595 }
596 }
597 }
598}
599
605GtkTreeModel * global_render_tree ()
606{
607 int i;
608 GtkTreeIter iter;
609 GtkTreeStore * store;
610 gchar * str;
611 store = gtk_tree_store_new (1, G_TYPE_STRING);
612 gtk_tree_store_append (store, & iter, NULL);
613 gtk_tree_store_set (store, & iter, 0, _("Select ..."), -1);
614 for (i=0; i<9; i++)
615 {
616 if (up_match[i])
617 {
619 while (other_match)
620 {
621 str = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
622 gtk_tree_store_append (store, & iter, NULL);
623 gtk_tree_store_set (store, & iter, 0, str, -1);
624 g_free (str);
625 other_match = other_match -> next;
626 }
627 }
628 }
629 return gtk_tree_model_filter_new(GTK_TREE_MODEL (store), NULL);
630}
631
640dint get_visible (gboolean result, gchar * the_name)
641{
642 dint vis;
643 gchar * str;
644 gboolean done = FALSE;
645 // With the "Select ..." path starts at 1 and not 0
646 vis.a = vis.b = 0;
647 int i;
648 for (i=0; i<9; i++)
649 {
650 if (up_match[i])
651 {
653 while (other_match)
654 {
655 if (i == up.a && ((i < 8 && other_match -> id == up.b) || (i == 8 && other_match -> obj == up.b)))
656 {
657 if (result)
658 {
659 str = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
660 if (g_strcmp0 (str, the_name) == 0)
661 {
662 vis.a = -1;
663 return vis;
664 }
665 }
666 vis.b ++;
667 done = TRUE;
668 }
669 else if (! done)
670 {
671 vis.a ++;
672 }
673 other_match = other_match -> next;
674 }
675 if (done) break;
676 }
677 }
678 return vis;
679}
680
690G_MODULE_EXPORT void changed_update_renderer (GtkCellRendererCombo * combo, gchar * path_string, GtkTreeIter * iter, gpointer data)
691{
692 GValue val = {0, };
693 GObject * cmodel;
694 dint res;
695 g_object_get (combo, "model", & cmodel, NULL);
696 gtk_tree_model_get_value ((GtkTreeModel *)cmodel, iter, 0, & val);
697 if (gtk_tree_model_get_iter_from_string ((GtkTreeModel *)update_model, iter, path_string))
698 {
699 gchar * str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
700 gtk_tree_store_set (update_model, iter, 5, str, -1);
701 res = get_visible (TRUE, str);
702 if (res.a < 0)
703 {
705 }
706 }
707}
708
718void get_update_tree_data (GtkWidget * tree, gpointer data, GtkTreePath * path)
719{
720 GtkTreeModel * tmodel = gtk_tree_view_get_model (GTK_TREE_VIEW(tree));
721 GtkTreeIter update_iter;
722 up.a = up.b = -1;
723 if (gtk_tree_model_get_iter (tmodel, & update_iter, path))
724 {
725 gtk_tree_model_get (tmodel, & update_iter, 0, & up.a, 1, & up.b, -1);
726 gtk_tree_model_filter_refilter ((GtkTreeModelFilter *)prop_to_up);
727 }
728}
729
730#ifdef GTK4
743void ff_button_event (double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
744#else
758void ff_button_event (GdkEvent * event, double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
759#endif
760{
761 if (event_type == GDK_BUTTON_PRESS)
762 {
763 GtkTreePath * path;
764 GtkTreeViewColumn * column;
765 int i, j;
766#ifdef GTK4
767 int e_x, e_y;
768 gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW(update_tree), event_x, event_y, & e_x, & e_y);
769 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(update_tree), e_x, e_y, & path, & column, & i, & j);
770#else
771 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(update_tree), event_x, event_y, & path, & column, & i, & j);
772#endif
773 if (path != NULL)
774 {
776 }
777 }
778}
779
780#ifdef GTK4
792G_MODULE_EXPORT void on_ff_button_pressed (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
793{
794 ff_button_event (x, y, gtk_gesture_single_get_current_button ((GtkGestureSingle * )gesture), GDK_BUTTON_PRESS, gtk_event_controller_get_current_event_time((GtkEventController *)gesture), data);
795}
796
808G_MODULE_EXPORT void on_ff_button_released (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
809{
810 ff_button_event (x, y, gtk_gesture_single_get_current_button ((GtkGestureSingle * )gesture), GDK_BUTTON_RELEASE, gtk_event_controller_get_current_event_time((GtkEventController *)gesture), data);
811}
812#else
822G_MODULE_EXPORT gboolean on_ff_button_event (GtkWidget * widget, GdkEvent * event, gpointer data)
823{
824 GdkEventButton * bevent = (GdkEventButton *)event;
825 ff_button_event (event, bevent -> x, bevent -> y, bevent -> button, bevent -> type, bevent -> time, data);
826 return FALSE;
827}
828#endif
829
839G_MODULE_EXPORT void on_toggle_update (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
840{
841 GtkTreeIter iter;
842 int i;
843 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
844 gtk_tree_model_get_iter (GTK_TREE_MODEL(update_model), & iter, path);
845 gtk_tree_model_get (GTK_TREE_MODEL(update_model), & iter, 7, & i, -1);
846 gchar * str;
847 gtk_tree_model_get (GTK_TREE_MODEL(update_model), & iter, 5, & str, -1);
848 dint res = get_visible(TRUE, str);
849 g_free (str);
850 if (res.a < 0)
851 {
852 tmp_match = tmp_res[up.a];
853 while (tmp_match)
854 {
855 if (tmp_match -> id == other_match -> id && tmp_match -> obj == other_match -> obj)
856 {
857 tmp_match -> use = ! i;
858 break;
859 }
860 tmp_match = tmp_match -> next;
861 }
862 gtk_tree_store_set (update_model, & iter, 7, ! i, -1);
863 }
864}
865
875static gboolean update_rend (GtkTreeModel * model, GtkTreeIter * iter, gpointer data)
876{
877 GtkTreeIter upiter;
878 dint vis;
879 gchar * str;
880 if (gtk_tree_model_get_iter_first(model, & upiter))
881 {
882 GtkTreePath * path = gtk_tree_model_get_path(model, iter);
883 str = gtk_tree_path_to_string(path);
884 gtk_tree_path_free(path);
885 if (g_strcmp0 (str, "0") == 0) return TRUE;
886 vis = get_visible (FALSE, NULL);
887 int p = (int)string_to_double ((gpointer)str);
888 g_free (str);
889 if (p > vis.a && p < vis.a+vis.b+1) return TRUE;
890 }
891 return FALSE;
892}
893
905void field_set_markup_and_visible (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
906{
907 int i, j, k;
908 i = GPOINTER_TO_INT(data);
909 gtk_tree_model_get (mod, iter, 0, & j, -1);
910 k = (j < 0) ? 0 : 1;
911 gtk_cell_renderer_set_visible (renderer, (i == 2) ? ! k : k);
912 if ((j < 0 && i == 2) || (j>-1 && i != 7))
913 {
914 set_renderer_markup (mod, iter, renderer, i);
915 }
916}
917
923GtkWidget * create_update_tree ()
924{
925 int i;
926 gchar * str;
927 gchar * up_title[NUCOL]={" ", " ", i18n("Property"), i18n("Atoms"), i18n("Species"), i18n("parameters (1)"), i18n("Actual parameters (1)"), i18n("Update ?")};
928 GType up_type[NUCOL] = {G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN};
929
930 update_model = gtk_tree_store_newv (NUCOL, up_type);
931 update_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(update_model));
932 for (i=0; i<NUCOL; i++)
933 {
934 if (i == 5)
935 {
936 str = g_strdup_printf ("%s %s", field_acro[tmp_field -> type], _(up_title[i]));
937 }
938 else
939 {
940 str = g_strdup_printf ("%s", (i > 1) ? _(up_title[i]) : up_title[i]);
941 }
942 if (i == 5)
943 {
944 update_renderer[i] = gtk_cell_renderer_combo_new();
946 g_object_set (update_renderer[i], "model", prop_to_up, "text-column", 0, "has-entry", FALSE, "editable", TRUE, NULL);
947 gtk_tree_model_filter_set_visible_func ((GtkTreeModelFilter *)prop_to_up, (GtkTreeModelFilterVisibleFunc)G_CALLBACK(update_rend), GTK_TREE_VIEW(update_tree), NULL);
948 g_object_unref (prop_to_up);
949 g_signal_connect (G_OBJECT(update_renderer[i]), "editing-started", G_CALLBACK(markup_action_renderer), NULL);
950 g_signal_connect (G_OBJECT(update_renderer[i]), "changed", G_CALLBACK(changed_update_renderer), NULL);
951 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "text", i, NULL);
952 }
953 else if (i == NUCOL-1)
954 {
955 update_renderer[i] = gtk_cell_renderer_toggle_new ();
956 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "active", i, NULL);
957 g_signal_connect (G_OBJECT(update_renderer[i]), "toggled", G_CALLBACK(on_toggle_update), NULL);
958 }
959 else
960 {
961 update_renderer[i] = gtk_cell_renderer_text_new();
962 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "text", i, NULL);
963 }
964 g_free (str);
965 if (i > 1)
966 {
967 gtk_tree_view_column_set_alignment (update_col[i], 0.5);
968 gtk_tree_view_append_column(GTK_TREE_VIEW(update_tree), update_col[i]);
969 gtk_tree_view_column_set_cell_data_func (update_col[i], update_renderer[i], field_set_markup_and_visible, GINT_TO_POINTER(i), NULL);
970 }
971 }
972 for (i=0; i<9; i++) tmp_res[i] = NULL;
974 g_object_unref (update_model);
975 GtkTreeSelection * update_select = gtk_tree_view_get_selection (GTK_TREE_VIEW(update_tree));
976 gtk_tree_selection_set_mode (update_select, GTK_SELECTION_SINGLE);
977#ifdef GTK4
978 add_widget_gesture_and_key_action (update_tree, "ff-button-pressed", G_CALLBACK(on_ff_button_pressed), NULL,
979 "ff-button-released", G_CALLBACK(on_ff_button_released), NULL,
980 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
981
982#else
983 g_signal_connect (G_OBJECT(update_tree), "button_press_event", G_CALLBACK(on_ff_button_event), NULL);
984#endif
985 return update_tree;
986}
987
995void win_update_tree (GtkWidget * vbx)
996{
997 int i;
998 update_tree = NULL;
999 update_model = NULL;
1000 for (i=0; i<NUCOL; i++)
1001 {
1002 update_renderer[i] = NULL;
1003 update_col[i] = NULL;
1004 }
1005 GtkWidget * scrollsets = create_scroll (NULL, -1, -1, GTK_SHADOW_ETCHED_IN);
1006 gtk_widget_set_size_request (scrollsets, 800, 400);
1007
1009 GtkWidget * hbox = create_hbox (0);
1010 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, scrollsets, FALSE, FALSE, 20);
1011 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, hbox, FALSE, FALSE, 20);
1012 gchar * funits[5] ={"Ev", "kcal mol<sup>-1</sup>", "kJ mol<sup>-1</sup>", "K B<sup>-1</sup>", i18n("DL_POLY internal units")};
1013 gchar * str = g_strdup_printf (_("\t<b>(*)</b> Each force field element can be tuned separately, if not this <b>default</b> parameters will be used.\n"
1014 "\t<b>(1)</b> %s energy unit: %s, if required conversion to FIELD file energy unit will be performed upon selection.\n"
1015 "\t<b>(2)</b> Restraint parameters are duplicates of the non-restraint parameters.\n"),
1016 field_acro[tmp_field -> type], (ff_unit == 4) ? _(funits[ff_unit]) : funits[ff_unit]);
1017 i = 3;
1018 if (tmp_field -> type > AMBER99 && tmp_field -> type < CVFF)
1019 {
1020 str = g_strdup_printf (_("%s\t<b>(%d)</b> Urey-Bradley terms provided by the %s force field are ignored.\n"), str, i, field_acro[tmp_field -> type]);
1021 i ++;
1022 }
1023 if (tmp_field -> type <= CVFF_AUG || tmp_field -> type > COMPASS)
1024 {
1025 str = g_strdup_printf (_("%s\t<b>(%d)</b> In %s, 12-6 non-bonded interactions are evaluated using:"), str, i, field_acro[tmp_field -> type]);
1026 }
1027 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 0);
1028 g_free (str);
1029 if (tmp_field -> type <= CVFF_AUG || tmp_field -> type > COMPASS)
1030 {
1031 hbox = create_hbox (0);
1032 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, hbox, FALSE, FALSE, 0);
1033 if (tmp_field -> type < CVFF || tmp_field -> type > COMPASS)
1034 {
1035 str = g_strdup_printf (_("%s\n<i><b>A</b></i> and <i><b>B</b></i> are calculated using Ɛ<sub>i/j</sub> and r0<sub>i/j</sub> provided by the force field parameters."), get_this_vdw_string());
1036 if (tmp_field -> type > AMBER99)
1037 {
1038 str = g_strdup_printf (_("%s\nScaled 1-4 exclusion parameters, provided by the %s force field, are ignored."), str, field_acro[tmp_field -> type]);
1039 }
1040 }
1041 else
1042 {
1043 str = g_strdup_printf (_("%s\n<i><b>A</b></i> and <i><b>B</b></i> are calculated using A<sub>i/j</sub> and B<sub>i/j</sub> provided by the force field parameters."), get_this_vdw_string());
1044 }
1045 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 200);
1046 g_free (str);
1047 }
1048}
1049
1062void look_up_this_field_object (int fsid, int fpid, int ssid, int nat, int * fsp, int * fat)
1063{
1064 int i, j;
1065 tmp_obj_id = field_objects_id[(fsid < 6) ? fsid / 2 : fsid - 3];
1066 while (tmp_obj_id)
1067 {
1068 i = tmp_obj_id -> oid;
1069 j = tmp_obj_id -> type;
1070 ff_data = get_ff_data (fsid, j);
1071 if (is_this_object_a_match (fsid, nat, fsp, ff_data -> atoms_z[i]))
1072 {
1073 if (is_this_object_a_match (fsid, nat, fat, ff_data -> atoms_id[i]))
1074 {
1075 if (up_match[fsid] == NULL)
1076 {
1077 up_match[fsid] = g_malloc0(sizeof*up_match[fsid]);
1078 tmp_match = up_match[fsid];
1079 }
1080 else
1081 {
1082 tmp_match -> next = g_malloc0(sizeof*tmp_match);
1083 tmp_match = tmp_match -> next;
1084 }
1085 tmp_match -> id = ssid;
1086 tmp_match -> obj = fpid;
1087 tmp_match -> oid = i;
1088 tmp_match -> type = j;
1089 // g_debug ("Match :: fsid= %d, -> id = %d, -> obj = %d, -> oid = %d, -> type = %d", fsid, ssid, fpid, i, j);
1090 }
1091 }
1092 tmp_obj_id = tmp_obj_id -> next;
1093 }
1094}
1095
1107void check_this_fprop (int fsid, int fpid, int ssid, int * fat, int * fsp)
1108{
1109 int i, j, k;
1110 int * ffat, * ffsp;
1111 gboolean update = TRUE;
1112 field_atom* tmpat;
1113 i = struct_id(fsid+7);
1114 for (j=0; j<i; j++)
1115 {
1116 k = fsp[j];
1117 tmpat = get_active_atom (tmp_fmol -> id, fat[j]);
1118 if (tmpat -> id != tmp_fat -> id)
1119 {
1120 if (tmpat -> afid < 0)
1121 {
1122 if (atoms_id[k] == 0 && extraz_id[(fsid < 6)? fsid/2: fsid-3][k] == 0)
1123 {
1124 update = FALSE;
1125 }
1126 }
1127 }
1128 }
1129 if (update)
1130 {
1131 // Is there any field data available ?
1132 // Check the field data for available parameters
1133 ffat = allocint (i);
1134 ffsp = allocint (i);
1135 for (j=0; j<i; j++)
1136 {
1137 ffat[j] = get_active_atom (tmp_fmol -> id, fat[j]) -> afid;
1138 ffsp[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][get_active_atom (tmp_fmol -> id, fat[j]) -> sp];
1139 }
1140 look_up_this_field_object (fsid, fpid, ssid, i, ffsp, ffat);
1141 g_free (ffat);
1142 g_free (ffsp);
1143 }
1144}
1145
1154int this_body_has_atom (field_nth_body * body, char * name)
1155{
1156 int i, j, k, l , m;
1157 m = 0;
1158 for (i=0; i<2; i++)
1159 {
1160 for (j=0; j<body -> na[i]; j++)
1161 {
1162 k = body -> ma[i][j];
1163 l = body -> a[i][j];
1164 if (g_strcmp0 (get_active_atom(k, l) -> name, name) == 0) m += (i+1);
1165 }
1166 }
1167 return m;
1168}
1169
1179G_MODULE_EXPORT void run_check_atom_for_updates (GtkDialog * dialog, gint response_id, gpointer data)
1180{
1181 int i, j, k, l, m;
1182 float v;
1183 gboolean update_vdw = FALSE;
1184 if (response_id == GTK_RESPONSE_APPLY)
1185 {
1186 for (i=0; i<9; i++)
1187 {
1188 if (tmp_res[i])
1189 {
1191 while (other_match)
1192 {
1193 if (tmp_match -> use)
1194 {
1195 if (i < 8)
1196 {
1197 tmp_fstr = get_active_struct (i, tmp_fmol -> id, tmp_match -> id);
1198 tmp_fprop = (tmp_match -> obj > 0) ? get_active_prop (tmp_fstr -> other, tmp_match -> obj - 1) : tmp_fstr -> def;
1199 g_free (tmp_fprop -> val);
1200 ff_data = get_ff_data (i, tmp_match -> type);
1201 tmp_fprop -> val = duplicate_float(ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1202 // UNITS !
1203 tmp_fprop -> fpid = tmp_match -> oid;
1204 tmp_fprop -> key = abs(ff_data -> key)-1;
1205 if ((i < 2 && (tmp_fprop -> key == 1 || tmp_fprop -> key == 5)) || ((i == 2 || i == 3) && tmp_fprop -> key < 2))
1206 {
1207 for (l=0; l<ff_data -> npar; l++)
1208 {
1209 if (l != 1) tmp_fprop -> val[l] *= (l+2 - l/3);
1210 }
1211 }
1212 if (ff_unit != tmp_field -> energy_unit)
1213 {
1215 tmp_fprop -> val[0] = tmp_fprop -> val[0]*v;
1216 if ((i/2 == 1 && tmp_fprop -> key == 1) || (i/2 == 1 && tmp_fprop -> key == 3))
1217 {
1218 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1219 tmp_fprop -> val[3] = tmp_fprop -> val[3]*v;
1220 }
1221 else if (i/2 == 0 && tmp_fprop -> key == 1)
1222 {
1223 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1224 }
1225 }
1226 tmp_fprop -> use = TRUE;
1227 }
1228 else
1229 {
1230 // Pot must be defined for the 2 atoms
1231 tmp_fbody = get_active_body (0, 0);
1232 ff_data = get_ff_data (i, tmp_match -> type);
1233 while (tmp_fbody)
1234 {
1235 update_vdw = FALSE;
1236 j = this_body_has_atom (tmp_fbody, tmp_fat -> name);
1237 k = tmp_match -> oid;
1238 if (j == 3)
1239 {
1240 tmp_fbody -> fpid[0] = tmp_fbody -> fpid[1] = k;
1241 j = l = k;
1242 update_vdw = TRUE;
1243 }
1244 else if (j)
1245 {
1246 j --;
1247 tmp_fbody -> fpid[j] = k;
1248 // Need to do something here !
1249 l = (j) ? 0 : 1;
1250 update_vdw = FALSE;
1251 if (tmp_fbody -> fpid[l] > -1)
1252 {
1253 j = k;
1254 l = tmp_fbody -> fpid[l];
1255 update_vdw = TRUE;
1256 }
1257 }
1258 if (update_vdw)
1259 {
1260 if (tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS)
1261 {
1262 v = sqrt(ff_data -> param[j][0]*ff_data -> param[l][0]);
1263 tmp_fbody -> val[0] = v*pow((double)(ff_data -> param[j][1] + ff_data -> param[l][1]), 12.0);
1264 tmp_fbody -> val[1] = 2.0 * v * pow((double)(ff_data -> param[j][1] + ff_data -> param[l][1]), 6.0);
1265 }
1266 else if (tmp_field -> type <= CVFF_AUG)
1267 {
1268 for (m=0; m<2; m++) tmp_fbody -> val[m] = sqrt(ff_data -> param[j][m]*ff_data -> param[l][m]);
1269 }
1270 }
1271 tmp_fbody = tmp_fbody -> next;
1272 }
1273 }
1274 }
1275 other_match = tmp_match -> next;
1276 g_free (tmp_match);
1278 }
1279 }
1280 }
1281 for (i=0; i<9; i++)
1282 {
1283 if (up_match[i])
1284 {
1286 while (other_match)
1287 {
1288 other_match = tmp_match -> next;
1289 g_free (tmp_match);
1291 }
1292 up_match[i] = NULL;
1293 }
1294 }
1295 }
1296 destroy_this_dialog (dialog);
1297}
1298
1305{
1306 int i, j, k, l;
1307 int * fsp;
1308 gboolean update_this = FALSE;
1309 field_prop * oth;
1310
1311 // Lookup for this atoms in bonds, etc ... and if parameters, then look for update is all atoms are field auto
1312 // Field struct (bonds, bond rest., angles, angles rest., dih, tors. rest., imp., vdw.)
1313 // g_debug ("Checking for field parameters of atoms: %s - id = %d", tmp_fat -> name, tmp_fat -> id + 1);
1314 for (i=0; i<8; i++)
1315 {
1316 up_match[i] = NULL;
1317 if ((i != 4 && i != 5) || tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1318 {
1319 if (get_ff_data(i, 0) && tmp_field -> afp[i+15])
1320 {
1321 k = struct_id(i+7);
1322 fsp = allocint (k);
1323 tmp_fstr = tmp_fmol -> first_struct[i];
1324 while (tmp_fstr != NULL)
1325 {
1326 for (j=0; j<k; j++)
1327 {
1328 if (tmp_fstr -> aid[j] == tmp_fat -> id)
1329 {
1330 // Update this field struct parameters
1331 for (l=0; l<k; l++)
1332 {
1333 fsp[l]= get_active_atom (tmp_fmol -> id, tmp_fstr -> aid[l]) -> sp;
1334 }
1335 check_this_fprop (i, 0, tmp_fstr -> id, tmp_fstr -> aid, fsp);
1336 oth = tmp_fstr -> other;
1337 while (oth != NULL)
1338 {
1339 check_this_fprop (i, oth -> pid+1, tmp_fstr -> id, tmp_fstr -> aid, fsp);
1340 oth = oth -> next;
1341 }
1342 break;
1343 }
1344 }
1345 tmp_fstr = tmp_fstr -> next;
1346 }
1347 g_free (fsp);
1348 }
1349 }
1350 }
1351 up_match[8] = NULL;
1352 if (tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1353 {
1354 tmp_fbody = get_active_body (0, 0);
1355 while (tmp_fbody && tmp_field -> afp[23])
1356 {
1357 if (this_body_has_atom (tmp_fbody, tmp_fat -> name) == 3)
1358 {
1360 while (tmp_obj_id)
1361 {
1362 i = tmp_proj -> chemistry -> chem_prop[CHEM_Z][tmp_fat -> sp];
1363 j = tmp_obj_id -> oid;
1364 if (ff_vdw -> atoms_z[j][0] == i && (ff_vdw -> atoms_id[j][0] == tmp_fat -> afid || ff_vdw -> atoms_id[j][0] == -1))
1365 {
1366 if (up_match[8] == NULL)
1367 {
1368 up_match[8] = g_malloc0(sizeof*up_match[8]);
1369 tmp_match = up_match[8];
1370 }
1371 else
1372 {
1373 tmp_match -> next = g_malloc0(sizeof*tmp_match);
1374 tmp_match = tmp_match -> next;
1375 }
1376 tmp_match -> id = 8;
1377 tmp_match -> obj = tmp_fbody -> id;
1378 tmp_match -> oid = tmp_obj_id -> oid;
1379 tmp_match -> type = 0;
1380 tmp_match -> use = FALSE;
1381 }
1382 tmp_obj_id = tmp_obj_id -> next;
1383 }
1384 }
1385 tmp_fbody = tmp_fbody -> next;
1386 }
1387 }
1388 for (i=0; i<9; i++)
1389 {
1390 if (up_match[i] != NULL)
1391 {
1392 update_this = TRUE;
1393 break;
1394 }
1395 }
1396 if (update_this)
1397 {
1398 gchar * str = g_strdup_printf (_("Update FIELD file with %s parameters using \"%s\" atom(s)"), field_acro[tmp_field -> type], exact_name(ff_atoms[tmp_fat -> afid][2]));
1399 GtkWidget * dial = dialog_cancel_apply (str, field_assistant, FALSE);
1400 g_free (str);
1401 GtkWidget * vbox = dialog_get_content_area (dial);
1403 run_this_gtk_dialog (dial, G_CALLBACK(run_check_atom_for_updates), NULL);
1404 }
1405}
1406
1415G_MODULE_EXPORT void changed_field_prop_combo (GtkComboBox * box, gpointer data)
1416{
1417 int i, j;
1418 dint * prop = (dint *)data;
1419 float * val, * vbl;
1420 i = combo_get_active ((GtkWidget *)box);
1421 if (i)
1422 {
1423 tmp_match = up_match[prop -> b];
1424 for (j=0; j<i-1; j++) tmp_match = tmp_match -> next;
1425 ff_data = get_ff_data (prop -> a - 7, tmp_match -> type);
1426 if (prop -> a < 15)
1427 {
1428 tmp_fprop -> key = abs(ff_data -> key) - 1;
1429 g_free (tmp_fprop -> val);
1430 tmp_fprop -> fpid = tmp_match -> oid;
1431 tmp_fprop -> val = duplicate_float (ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1432 if ((prop -> a < 9 && (tmp_fprop -> key == 0 || tmp_fprop -> key == 5)) || ((prop -> a == 9 || prop -> a == 10) && tmp_fprop -> key < 2))
1433 {
1434 for (j=0; j<ff_data -> npar; j++)
1435 {
1436 if (j != 1) tmp_fprop -> val[j] *= (j+2 - j/3);
1437 }
1438 }
1439 if (ff_unit != tmp_field -> energy_unit)
1440 {
1441 float v = internal_to_other[tmp_field -> energy_unit] / internal_to_other[ff_unit];
1442 tmp_fprop -> val[0] = tmp_fprop -> val[0]*v;
1443 if (((prop -> a - 7)/2 == 1 && tmp_fprop -> key == 1) || ((prop -> a - 7)/2 == 1 && tmp_fprop -> key == 3))
1444 {
1445 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1446 tmp_fprop -> val[3] = tmp_fprop -> val[3]*v;
1447 }
1448 else if ((prop -> a - 7)/2 == 0 && tmp_fprop -> key == 1)
1449 {
1450 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1451 }
1452 }
1454 }
1455 else
1456 {
1457 // Check both atoms pot, and use same pot.
1458 tmp_fbody -> key = abs(ff_data -> key) - 1;
1459 tmp_fbody -> fpid[prop -> b] = tmp_match -> oid;
1460 val = duplicate_float (ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1462 }
1463 }
1464 else
1465 {
1466 if (prop -> a < 15)
1467 {
1468 tmp_fprop -> fpid = -1;
1469 }
1470 else
1471 {
1472 tmp_fbody -> fpid[prop -> b] = -1;
1473 }
1474 }
1475 if (prop -> a == 15 && i)
1476 {
1477 float * vcl;
1478 float eij;
1479 float rij;
1480 i = (prop -> b) ? 0 : 1;
1481 if (vdw_same_atom)
1482 {
1483 tmp_fbody -> fpid[i] = tmp_fbody -> fpid[!i];
1484 }
1485 if (tmp_fbody -> fpid[0] > -1 && tmp_fbody -> fpid[1] > -1)
1486 {
1487 j = tmp_fbody -> fpid[i];
1488 vbl = duplicate_float (ff_data -> npar, ff_data -> param[j]);
1489 if ((tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS) && tmp_fbody -> key == 0)
1490 {
1491 // 12-6, recalculate A and B
1492 vcl = allocfloat (ff_data -> npar);
1493 eij = sqrt(val[0]*vbl[0]);
1494 rij = (val[1] + vbl[1]);
1495 vcl[0] = eij * pow((double) rij, 12.0);
1496 vcl[1] = 2.0 * eij * pow((double) rij, 6.0);
1497 g_free (tmp_fbody -> val);
1498 tmp_fbody -> val = duplicate_float(ff_data -> npar, vcl);
1499 g_free (vcl);
1500 }
1501 else if (tmp_field -> type == CVFF || tmp_field -> type == CVFF_AUG)
1502 {
1503 // 12-6, A-B
1504 vcl = allocfloat (ff_data -> npar);
1505 vcl[0] = sqrt(val[0]*vbl[0]);
1506 vcl[1] = sqrt(val[1]*vbl[1]);
1507 g_free (tmp_fbody -> val);
1508 tmp_fbody -> val = duplicate_float(ff_data -> npar, vcl);
1509 g_free (vcl);
1510 }
1511 g_free (vbl);
1512 }
1513 g_free (val);
1514 }
1516 p_box = param_prop_param_box (prop -> a);
1517 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, param_box, p_box, FALSE, FALSE, 0);
1519}
1520
1529GtkWidget * create_field_prop_combo (int f, int is_moy)
1530{
1531 int h, i, j, k, l, m, n;
1532 GtkWidget * vbox, * hbox;
1533 gboolean save_it;
1534 gchar * str_vdw[2];
1535 gchar * str;
1536 h = (f == 15) ? 2 : struct_id(f);
1537 i = (f == 15) ? 2 : 1;
1538 for (j=0; j<i; j++) up_match[j] = g_malloc0(sizeof*up_match[j]);
1539 int * spec_z = allocint (h);
1540 vbox = create_vbox (BSEP);
1541 if (f == 15)
1542 {
1543 vdw_same_atom = FALSE;
1544 j = get_num_vdw_max ();
1545 for (j=0; j<2; j++)
1546 {
1547 str_vdw[j] = g_strdup_printf ("%s", get_body_element_name (tmp_fbody, j, 0));
1548 l = tmp_fbody -> ma[j][0];
1549 m = tmp_fbody -> a[j][0];
1550 n = get_active_atom (l, m) -> sp;
1551 spec_z[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][n];
1552 }
1553 if (g_strcmp0 (str_vdw[0], str_vdw[1]) == 0)
1554 {
1555 vdw_same_atom = TRUE;
1556 i = 1;
1557 }
1558 for (j=0; j<i; j++)
1559 {
1560 hbox = create_hbox(0);
1561 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1562 ff_p_combo[j] = create_combo ();
1563 combo_text_append (ff_p_combo[j], _("Manual"));
1564 l = tmp_fbody -> ma[j][0];
1565 m = tmp_fbody -> a[j][0];
1566 if (i == 1)
1567 {
1568 str = g_strdup_printf (_("Atom (1 and 2) <b>%s</b>"), str_vdw[j]);
1569 }
1570 else
1571 {
1572 str = g_strdup_printf (_("Atom (%d) <b>%s</b>"), j+1, str_vdw[j]);
1573 }
1574 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 150, -1, 0.0, 0.5), FALSE, FALSE, 10);
1575 g_free (str);
1576 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ff_p_combo[j], FALSE, FALSE, 10);
1577 }
1578 for (j=0; j<2; j++) g_free (str_vdw[j]);
1579 }
1580 else
1581 {
1582 hbox = create_hbox(0);
1583 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1584 ff_p_combo[0] = create_combo ();
1585 combo_text_append (ff_p_combo[0], _("Manual"));
1586 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ff_p_combo[0], FALSE, FALSE, 10);
1587 for (j=0; j<h; j++)
1588 {
1589 if (is_moy)
1590 {
1591 k = tmp_fstr -> aid[j];
1592 l = get_active_atom (tmp_fmol -> id, k) -> sp;
1593 }
1594 else
1595 {
1596 k = tmp_fprop -> aid[j];
1597 l = get_active_atom (tmp_fmol -> id, tmp_fmol -> atoms_id[k][0].a) -> sp;
1598 }
1599 spec_z[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][l];
1600 }
1601 }
1602 if (f != 15 || tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1603 {
1604 for (j=0; j<i; j++)
1605 {
1606 tmp_obj_id = field_objects_id[(f-7) < 6 ? (f-7) / 2 : f-10];
1607 m = n = 0;
1608 up_match[j] = NULL;
1609 while (tmp_obj_id)
1610 {
1611 k = tmp_obj_id -> oid;
1612 l = tmp_obj_id -> type;
1613 ff_data = get_ff_data (f-7, l);
1614 save_it = FALSE;
1615 if (f < 15 && is_this_object_a_match (f-7, h, spec_z, ff_data -> atoms_z[k]))
1616 {
1617 m ++;
1618 if (tmp_fprop -> fpid == k && tmp_fprop -> key == abs(ff_data -> key)-1) n = m;
1619 save_it = TRUE;
1620 }
1621 else if (f == 15 && ff_data -> atoms_z[k][0] == spec_z[j])
1622 {
1623 m ++;
1624 if (tmp_fbody -> fpid[j] == k) n = m;
1625 save_it = TRUE;
1626 }
1627 if (save_it)
1628 {
1629 str = g_strdup_printf ("%s", get_this_prop_string (f-7, k, l, 0));
1630 if (ff_data -> info)
1631 {
1632 if (g_strcmp0 (ff_data -> info[k], " ") != 0) str = g_strdup_printf ("%s : %s", str, ff_data -> info[k]);
1633 }
1634 combo_text_append (ff_p_combo[j], str);
1635 g_free (str);
1636 if (up_match[j] == NULL)
1637 {
1638 up_match[j] = g_malloc0(sizeof*up_match[j]);
1639 tmp_match = up_match[j];
1640 }
1641 else
1642 {
1643 tmp_match -> next = g_malloc0(sizeof*tmp_match -> next);
1644 tmp_match -> next -> id = tmp_match -> id + 1;
1645 tmp_match = tmp_match -> next;
1646 }
1647 tmp_match -> obj = f - 7;
1648 tmp_match -> oid = k;
1649 tmp_match -> type = l;
1650 }
1651 tmp_obj_id = tmp_obj_id -> next;
1652 }
1654 pup[j].a = f;
1655 pup[j].b = j;
1657 if (m == 0) widget_set_sensitive (ff_p_combo[j], FALSE);
1658 g_signal_connect (G_OBJECT(ff_p_combo[j]), "changed", G_CALLBACK(changed_field_prop_combo), & pup[j]);
1659 }
1660 }
1661 return vbox;
1662}
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
gchar * param[2]
ColRGBA col
Definition d_measures.c:77
GtkTreePath * path
Definition datab.c:103
field_struct * get_active_struct(int s, int a, int b)
retrieve field structural property
Definition dlp_active.c:318
field_atom * get_active_atom(int a, int b)
retrieve field atom
Definition dlp_active.c:145
field_nth_body * get_active_body(int a, int b)
retrieve field nth body interaction
Definition dlp_active.c:106
field_prop * get_active_prop(struct field_prop *pr, int a)
the field molecule structural property id to retrieve
Definition dlp_active.c:265
float val
Definition dlp_init.c:117
int is_moy
Definition dlp_edit.c:122
int ** atoms_id_list
GtkWidget * afftype
Definition dlp_edit.c:121
GtkWidget * field_key_combo
Definition dlp_edit.c:111
GtkWidget * param_box
Definition dlp_edit.c:114
int * atoms_id
GtkWidget * p_box
Definition dlp_edit.c:112
GtkWidget * ff_p_combo[2]
char *** ff_atoms
gchar * get_body_element_name(field_nth_body *body, int aid, int nbd)
get field body potential element name
Definition dlp_edit.c:1941
gchar * get_this_prop_string(int sid, int oid, int type, int calc)
get property name
field_object_match * tmp_res[9]
char * fvars_bond[2][FBONDS][FBONDS_P]
Definition dlp_field.c:396
G_MODULE_EXPORT void on_toggle_update(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
on select field parameter toggle callback
void check_this_fprop(int fsid, int fpid, int ssid, int *fat, int *fsp)
check if the database offers parameters for a field property
void field_set_markup_and_visible(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
field parameter set renderer markup and visibility in the parameter database selection tree model
G_MODULE_EXPORT void markup_action_renderer(GtkCellRendererCombo *cell, GtkCellEditable *editable, gchar *path_string, gpointer data)
add pango markup to a combo box inserted in the cell of a tree view
Definition w_search.c:3252
field_object_match * duplicate_match(field_object_match *old_m)
create a copy of a field match
GtkTreeViewColumn * update_col[NUCOL]
void update_result_list(int sid, field_object_match *new_match)
update avialable parameter list
gchar * felemts[MAXDATA+1]
Definition dlp_field.c:141
field_object_match * up_match[9]
dint get_visible(gboolean result, gchar *the_name)
get cell renderer visibility poitner
GtkTreeStore * update_model
char * fvars_inversion[2][FINVERS][FINVERS_P]
Definition dlp_field.c:612
G_MODULE_EXPORT void run_check_atom_for_updates(GtkDialog *dialog, gint response_id, gpointer data)
check for parameters in the database to be used in the force field - running the dialog
char * fvars_dihedral[2][FDIHEDRAL][FDIHEDRAL_P]
Definition dlp_field.c:540
gchar * get_this_vdw_string()
get VdW formalism description string
Definition dlp_edit.c:490
char * fvars_angle[2][FANGLES][FANGLES_P]
Definition dlp_field.c:462
dint pup[2]
int get_num_vdw_max()
Get the number of field shell interactions.
Definition dlp_edit.c:2009
void fill_update_model(GtkTreeStore *store)
fill the parameters database tree store
#define NUCOL
int this_body_has_atom(field_nth_body *body, char *name)
check if non bonded potential has this field atom
gboolean is_this_object_a_match(int fsid, int nat, int *ffc, int *fpar)
check if object matches parameters from the database
void win_update_tree(GtkWidget *vbx)
update the parameters database tree model
GtkCellRenderer * update_renderer[NUCOL]
GtkWidget * create_field_prop_combo(int f, int is_moy)
create field parameter selection combo box
dint up
gboolean vdw_same_atom
GtkWidget * param_prop_param_box(int pid)
prepare field parameter edition widgets
Definition dlp_edit.c:706
field_data * get_ff_data(int i, int j)
retrieve field property from database
int * field_objects
void get_update_tree_data(GtkWidget *tree, gpointer data, GtkTreePath *path)
update force field parameters database tree model data
char * fvars_vdw[2][FVDW][FVDW_P]
Definition dlp_field.c:692
void check_atom_for_updates()
check for parameters in the database to be used in the force field - creating the dialog
G_MODULE_EXPORT void changed_update_renderer(GtkCellRendererCombo *combo, gchar *path_string, GtkTreeIter *iter, gpointer data)
change combo box in tree model callback
gchar * get_this_prop_param(int sid, int key, int calc, int newp, float *val)
prepare field property parameters description string
field_object_match * tmp_match
GtkWidget * update_tree
GtkTreeModel * prop_to_up
G_MODULE_EXPORT gboolean on_ff_button_event(GtkWidget *widget, GdkEvent *event, gpointer data)
mouse button event on the DL-POLY force field parameters database window
field_object_match * other_match
GtkTreeModel * global_render_tree()
create the field property combo box model that contains the list of available parameters
void ff_button_event(GdkEvent *event, double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
handle mouse button event on the DL-POLY force field parameters database window GTK3
field_data * ff_data
G_MODULE_EXPORT void changed_field_prop_combo(GtkComboBox *box, gpointer data)
change the field parameter selection
gchar * get_body_element_name(field_nth_body *body, int aid, int nbd)
get field body potential element name
Definition dlp_edit.c:1941
void look_up_this_field_object(int fsid, int fpid, int ssid, int nat, int *fsp, int *fat)
look up in database for this field property
GtkWidget * create_update_tree()
create the parameters database tree model
int fvalues[2][15][21]
Definition dlp_field.c:345
field_nth_body * tmp_fbody
Definition dlp_field.c:1055
float internal_to_other[5]
Definition dlp_field.c:1028
project * tmp_proj
Definition dlp_field.c:1043
gchar * fnames[2][16][21]
Definition dlp_field.c:308
field_atom * tmp_fat
Definition dlp_field.c:1047
int struct_id(int f)
number of atoms in a structural element
Definition dlp_field.c:1089
field_struct * tmp_fstr
Definition dlp_field.c:1054
gchar * parameters_info(int obj, int key, gchar **words, float *data)
prepare classical force field parameter description string
Definition dlp_field.c:1187
field_molecule * tmp_fmol
Definition dlp_field.c:1045
field_prop * tmp_fprop
Definition dlp_field.c:1053
GtkWidget * field_assistant
Definition dlp_field.c:1030
gboolean dlp_to_translate(int fid, int obj, int key)
test if fnames text is to be translated or not
Definition dlp_field.c:1215
classical_field * tmp_field
Definition dlp_field.c:1041
Variable declarations for the creation of the DL_POLY input file(s).
#define FANGLES_P
Definition dlp_field.h:107
field_data * ff_angles[2]
#define FBONDS_P
Definition dlp_field.h:106
#define CHARMMSI
Definition dlp_field.h:133
#define COMPASS
Definition dlp_field.h:138
#define FVDW
Definition dlp_field.h:74
#define FINVERS
Definition dlp_field.h:73
field_data * ff_vdw
field_data * ff_dih[2]
#define FVDW_P
Definition dlp_field.h:110
field_data * ff_imp
#define FDIHEDRAL_P
Definition dlp_field.h:108
#define CVFF
Definition dlp_field.h:134
#define CVFF_AUG
Definition dlp_field.h:135
char * field_acro[N_FIELDS]
#define FBONDS
Definition dlp_field.h:70
#define FDIHEDRAL
Definition dlp_field.h:72
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:579
field_object_match * field_objects_id[6]
int ** extraz_id
#define AMBER99
Definition dlp_field.h:123
field_object_match * tmp_obj_id
#define FINVERS_P
Definition dlp_field.h:109
gboolean afp[MAXDATA]
field_data * ff_bonds[3]
field_data * ff_inv
#define FANGLES
Definition dlp_field.h:71
int ff_unit
int activef
Definition global.c:164
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
#define i18n(String)
Definition global.c:80
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:385
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...
GtkWidget * dialog_cancel_apply(gchar *title, GtkWidget *parent, gboolean resiz)
create a dialog modal offering a choice to apply something or not
Definition gtk-misc.c:616
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:533
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:935
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2139
void combo_set_markup(GtkWidget *combo)
use pango markup in combo widget
Definition gtk-misc.c:970
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:958
#define BSEP
Definition global.h:261
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_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:1010
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:861
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
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 widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:247
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 combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:987
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
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
#define CHEM_Z
Definition global.h:316
#define MAXDATA
Number of tabs for the description of the classical force field.
Definition global.h:776
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
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...
Function declarations for the creation of the OpenGL window.
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:434
Messaging function declarations.
double y
Definition ogl_draw.c:63
double x
Definition ogl_draw.c:63
Definition glwin.h:350
Definition global.h:111
int b
Definition global.h:113
int a
Definition global.h:112
GtkWidget * res[2]
Definition w_encode.c:342
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72