atomes 1.1.14
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-2024 by CNRS and University of Strasbourg */
15
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)", fnames[activef][(sid > 7) ? 10 : sid+2][key],
311 parameters_info ((sid > 7) ? 9 : sid+1, key, vars, val));
312}
313
324gchar * get_this_prop_string (int sid, int oid, int type, int calc)
325{
326 gchar * str;
327 int i, j, k, l;
328 i = (sid > 7) ? 1 : struct_id (sid+7);
329 ff_data = get_ff_data (sid, type);
330 float * val;
331 for (j=0; j<i; j++)
332 {
333 k = ff_data -> atoms_id[oid][j];
334 if (j > 0)
335 {
336 str = g_strdup_printf ("%s-%s", str, (k < 0) ? "X" : ff_atoms[k][2]);
337 }
338 else
339 {
340 str = g_strdup_printf ("%s", (k < 0) ? "X" : ff_atoms[k][2]);
341 }
342 }
343 j = abs(ff_data -> key)-1;
344 k = fvalues[activef][(sid < 8) ? sid+1 : 9][j];
345 val = allocfloat (k);
346 for (l=0; l<k; l++) val[l] = ff_data -> param[oid][l];
347 // Here
348 if (sid == 8 && calc)
349 {
350 if (tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS)
351 {
352 float v = sqrt(ff_data -> param[oid][0]*ff_data -> param[oid][0]);
353 val[0] = v*pow((double)(ff_data -> param[oid][1] + ff_data -> param[oid][1]), 12.0);
354 val[1] = 2.0 * v * pow((double)(ff_data -> param[oid][1] + ff_data -> param[oid][1]), 6.0);
355 }
356 else if (tmp_field -> type <= CVFF_AUG)
357 {
358 for (l=0; l<2; l++) val[l] = sqrt(ff_data -> param[oid][l]*ff_data -> param[oid][l]);
359 }
360 }
361
362 str = g_strdup_printf ("%s: %s", str, get_this_prop_param(sid, j, calc, 1, val));
363 g_free (val);
364 return str;
365}
366
375{
376 field_object_match * new_m = g_malloc0 (sizeof*new_m);
377 new_m -> id = old_m -> id;
378 new_m -> obj = old_m -> obj;
379 new_m -> oid = old_m -> oid;
380 new_m -> type = old_m -> type;
381 new_m -> use = old_m -> use;
382 return new_m;
383}
384
393void update_result_list (int sid, field_object_match * new_match)
394{
395 if (tmp_res[sid])
396 {
397 field_object_match * map, * mbp;
398 map = duplicate_match (new_match);
399 mbp = tmp_res[sid];
400 while (mbp)
401 {
402 if (mbp -> id == map -> id && mbp -> obj == map -> obj)
403 {
404 // Changing a value already saved
405 if (mbp -> next && mbp -> prev)
406 {
407 mbp -> prev -> next = map;
408 map -> prev = mbp -> prev;
409 map -> next = mbp -> next;
410 mbp -> next -> prev = map;
411 }
412 else if (mbp -> next)
413 {
414 mbp -> next -> prev = map;
415 map -> next = mbp -> next;
416 }
417 else if (mbp -> prev)
418 {
419 mbp -> prev -> next = map;
420 map -> prev = mbp -> prev;
421 }
422 }
423 else if (! mbp -> next)
424 {
425 mbp -> next = map;
426 map -> prev = mbp -> next;
427 mbp = mbp -> next;
428 }
429 mbp = mbp -> next;
430 }
431 }
432 else
433 {
434 tmp_res[sid] = duplicate_match (new_match);
435 }
436}
437
445void fill_update_model (GtkTreeStore * store)
446{
447 GtkTreeIter prop_level, struct_level;
448 field_atom* upat;
449 int g, h, i, j;
450 gchar * str;
451 gchar * stra, * strb, * strc, * strd, * stre;
452 for (i=0; i<9; i++)
453 {
454 g = (i==8) ? i+1 : i;
455 h = (i==8) ? 2 : struct_id (i+7);
456 if (up_match[i])
457 {
458 if (g%2 && i < 6)
459 {
460 if (i == 3 && tmp_field -> type > AMBER99 && tmp_field -> type < CVFF_AUG)
461 {
462 str = g_strdup_printf ("<b>%s(s)</b> <sup>(2,3)</sup>", felemts[8+g]);
463 }
464 else
465 {
466 str = g_strdup_printf ("<b>%s(s)</b> <sup>(2)</sup>", felemts[8+g]);
467 }
468 }
469 else if (i < 8)
470 {
471 if (i == 2 && tmp_field -> type > AMBER99 && tmp_field -> type < CVFF_AUG)
472 {
473 str = g_strdup_printf ("<b>%s(s)</b> <sup>(3)</sup>", felemts[8+g]);
474 }
475 else
476 {
477 str = g_strdup_printf ("<b>%s(s)</b>", felemts[8+g]);
478 }
479 }
480 else if (tmp_field -> type <= AMBER99 || tmp_field -> type > COMPASS)
481 {
482 str = g_strdup_printf ("<b>%s(s)</b> <sup>(3)</sup>", felemts[8+i]);
483 }
484 else if (tmp_field -> type <= CHARMMSI)
485 {
486 str = g_strdup_printf ("<b>%s(s)</b> <sup>(4)</sup>", felemts[8+i]);
487 }
488 else
489 {
490 str = g_strdup_printf ("<b>%s(s)</b>", felemts[8+i]);
491 }
492 gtk_tree_store_append (store, & prop_level, NULL);
493 gtk_tree_store_set (store, & prop_level, 0, -(i+1),
494 1, 0,
495 2, str,
496 3, NULL,
497 4, NULL,
498 5, NULL,
499 6, NULL,
500 NUCOL-1, FALSE, -1);
501 g_free (str);
502 tmp_match = up_match[i];
503 while (tmp_match)
504 {
505 if (i<8)
506 {
507 tmp_fstr = get_active_struct (i, tmp_fmol -> id, tmp_match -> id);
508 if (tmp_match -> obj > 0)
509 {
510 tmp_fprop = get_active_prop (tmp_fstr -> other, tmp_match -> obj - 1);
511 tmp_match -> use = TRUE;
512 }
513 else
514 {
515 tmp_fprop = tmp_fstr -> def;
516 tmp_match -> use = TRUE;
517 }
518 }
519 else
520 {
521 tmp_fbody = get_active_body (tmp_match -> obj, 0);
522 tmp_match -> use = TRUE;
523 }
524 for (j=0; j<h; j++)
525 {
526 if (i < 8)
527 {
528 upat = get_active_atom (tmp_fmol -> id, tmp_fstr -> aid[j]);
529 }
530 else
531 {
532 upat = get_active_atom (tmp_fbody -> ma[j][0], tmp_fbody -> a[j][0]);
533 }
534 if (j > 0)
535 {
536 stra = g_strdup_printf ("%s - ""%s""", stra, upat -> name);
537 if (tmp_match -> obj > 0 && i < 8) strb = g_strdup_printf ("%s-%d", strb, tmp_fprop -> aid[j]+1);
538 strc = g_strdup_printf ("%s - %s", strc, tmp_proj -> chemistry -> label[upat -> sp]);
539 }
540 else
541 {
542 stra = g_strdup_printf ("""%s""", upat -> name);
543 if (tmp_match -> obj > 0 && i < 8) strb = g_strdup_printf ("%d", tmp_fprop -> aid[j]+1);
544 strc = g_strdup_printf ("%s", tmp_proj -> chemistry -> label[upat -> sp]);
545 }
546 }
548 if (tmp_match -> use)
549 {
551 strd = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
552 }
553 else
554 {
555 strd = g_strdup_printf ("Select ...");
556 }
557
558 if (i < 8)
559 {
560 stre = g_strdup_printf ("%s", get_this_prop_param(i, tmp_fprop -> key, 1, 0, tmp_fprop -> val));
561 }
562 else
563 {
564 stre = g_strdup_printf ("%s", get_this_prop_param(i, tmp_fbody -> key, 1, 0, tmp_fbody -> val));
565 }
566 if (tmp_match -> obj > 0 && i < 8)
567 {
568 str = g_strdup_printf ("%s", strb);
569 g_free (strb);
570 }
571 else
572 {
573 str = g_strdup_printf ("%s <sup>(*)</sup>", stra);
574 }
575 gtk_tree_store_append (store, & struct_level, & prop_level);
576 while (other_match && other_match -> id == tmp_match -> id && other_match -> obj == tmp_match -> obj)
577 {
578 other_match = other_match -> next;
579 }
580 gtk_tree_store_set (store, & struct_level, 0, i,
581 1, (i == 8) ? tmp_match -> obj : tmp_match -> id,
582 2, NULL,
583 3, str,
584 4, strc,
585 5, strd,
586 6, stre,
587 NUCOL-1, tmp_match -> use, -1);
588 g_free (str);
589 g_free (stra);
590 g_free (strc);
591 g_free (strd);
592 g_free (stre);
594 }
595 }
596 }
597}
598
604GtkTreeModel * global_render_tree ()
605{
606 int i, j;
607 GtkTreeIter iter;
608 GtkTreeStore * store;
609 gchar * str;
610 store = gtk_tree_store_new (1, G_TYPE_STRING);
611 gtk_tree_store_append (store, & iter, NULL);
612 gtk_tree_store_set (store, & iter, 0, "Select ...", -1);
613 for (i=0; i<9; i++)
614 {
615 j = 0;
616 if (up_match[i])
617 {
619 while (other_match)
620 {
621 j ++;
622 str = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
623 gtk_tree_store_append (store, & iter, NULL);
624 gtk_tree_store_set (store, & iter, 0, str, -1);
625 g_free (str);
626 other_match = other_match -> next;
627 }
628 }
629 }
630 return gtk_tree_model_filter_new(GTK_TREE_MODEL (store), NULL);
631}
632
641dint get_visible (gboolean result, gchar * the_name)
642{
643 dint vis;
644 gchar * str;
645 gboolean done = FALSE;
646 // With the "Select ..." path starts at 1 and not 0
647 vis.a = vis.b = 0;
648 int i;
649 for (i=0; i<9; i++)
650 {
651 if (up_match[i])
652 {
654 while (other_match)
655 {
656 if (i == up.a && ((i < 8 && other_match -> id == up.b) || (i == 8 && other_match -> obj == up.b)))
657 {
658 if (result)
659 {
660 str = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
661 if (g_strcmp0 (str, the_name) == 0)
662 {
663 vis.a = -1;
664 return vis;
665 }
666 }
667 vis.b ++;
668 done = TRUE;
669 }
670 else if (! done)
671 {
672 vis.a ++;
673 }
674 other_match = other_match -> next;
675 }
676 if (done) break;
677 }
678 }
679 return vis;
680}
691G_MODULE_EXPORT void changed_update_renderer (GtkCellRendererCombo * combo, gchar * path_string, GtkTreeIter * iter, gpointer data)
692{
693 GValue val = {0, };
694 GObject * cmodel;
695 dint res;
696 g_object_get (combo, "model", & cmodel, NULL);
697 gtk_tree_model_get_value ((GtkTreeModel *)cmodel, iter, 0, & val);
698 if (gtk_tree_model_get_iter_from_string ((GtkTreeModel *)update_model, iter, path_string))
699 {
700 gchar * str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
701 gtk_tree_store_set (update_model, iter, 5, str, -1);
702 res = get_visible (TRUE, str);
703 if (res.a < 0)
704 {
706 }
707 }
708}
709
719void get_update_tree_data (GtkWidget * tree, gpointer data, GtkTreePath * path)
720{
721 GtkTreeModel * tmodel = gtk_tree_view_get_model (GTK_TREE_VIEW(tree));
722 GtkTreeIter update_iter;
723 up.a = up.b = -1;
724 if (gtk_tree_model_get_iter (tmodel, & update_iter, path))
725 {
726 gtk_tree_model_get (tmodel, & update_iter, 0, & up.a, 1, & up.b, -1);
727 gtk_tree_model_filter_refilter ((GtkTreeModelFilter *)prop_to_up);
728 }
729}
730
731#ifdef GTK4
744void ff_button_event (double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
745#else
759void ff_button_event (GdkEvent * event, double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
760#endif
761{
762 if (event_type == GDK_BUTTON_PRESS)
763 {
764 GtkTreePath * path;
765 GtkTreeViewColumn * column;
766 int i, j;
767#ifdef GTK4
768 int e_x, e_y;
769 gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW(update_tree), event_x, event_y, & e_x, & e_y);
770 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(update_tree), e_x, e_y, & path, & column, & i, & j);
771#else
772 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(update_tree), event_x, event_y, & path, & column, & i, & j);
773#endif
774 if (path != NULL)
775 {
777 }
778 }
779}
780
781#ifdef GTK4
793G_MODULE_EXPORT void on_ff_button_pressed (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
794{
795 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);
796}
797
809G_MODULE_EXPORT void on_ff_button_released (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
810{
811 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);
812}
813#else
823G_MODULE_EXPORT gboolean on_ff_button_event (GtkWidget * widget, GdkEvent * event, gpointer data)
824{
825 GdkEventButton * bevent = (GdkEventButton *)event;
826 ff_button_event (event, bevent -> x, bevent -> y, bevent -> button, bevent -> type, bevent -> time, data);
827 return FALSE;
828}
829#endif
830
840G_MODULE_EXPORT void on_toggle_update (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
841{
842 GtkTreeIter iter;
843 int i;
844 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
845 gtk_tree_model_get_iter (GTK_TREE_MODEL(update_model), & iter, path);
846 gtk_tree_model_get (GTK_TREE_MODEL(update_model), & iter, 7, & i, -1);
847 gchar * str;
848 gtk_tree_model_get (GTK_TREE_MODEL(update_model), & iter, 5, & str, -1);
849 dint res = get_visible(TRUE, str);
850 g_free (str);
851 if (res.a < 0)
852 {
854 while (tmp_match)
855 {
856 if (tmp_match -> id == other_match -> id && tmp_match -> obj == other_match -> obj)
857 {
858 tmp_match -> use = ! i;
859 break;
860 }
861 tmp_match = tmp_match -> next;
862 }
863 gtk_tree_store_set (update_model, & iter, 7, ! i, -1);
864 }
865}
866
876static gboolean update_rend (GtkTreeModel * model, GtkTreeIter * iter, gpointer data)
877{
878 GtkTreeIter upiter;
879 dint vis;
880 gchar * str;
881 if (gtk_tree_model_get_iter_first(model, & upiter))
882 {
883 GtkTreePath * path = gtk_tree_model_get_path(model, iter);
884 str = gtk_tree_path_to_string(path);
885 gtk_tree_path_free(path);
886 if (g_strcmp0 (str, "0") == 0) return TRUE;
887 vis = get_visible (FALSE, NULL);
888 int p = (int)atof(str);
889 g_free (str);
890 if (p > vis.a && p < vis.a+vis.b+1) return TRUE;
891 }
892 return FALSE;
893}
894
906void field_set_markup_and_visible (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
907{
908 int i, j, k;
909 i = GPOINTER_TO_INT(data);
910 gtk_tree_model_get (mod, iter, 0, & j, -1);
911 k = (j < 0) ? 0 : 1;
912 gtk_cell_renderer_set_visible (renderer, (i == 2) ? ! k : k);
913 if ((j < 0 && i == 2) || (j>-1 && i != 7))
914 {
915 gchar * str = NULL;
916 gtk_tree_model_get (mod, iter, i, & str, -1);
917 g_object_set (renderer, "markup", str, NULL, NULL);
918 g_free (str);
919 }
920}
921
927GtkWidget * create_update_tree ()
928{
929 int i;
930 gchar * str;
931 gchar * up_title[NUCOL]={" ", " ", "Property", "Atoms", "Species", "parameters (1)", "Actual parameters (1)", "Update ?"};
932 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};
933
934 update_model = gtk_tree_store_newv (NUCOL, up_type);
935 update_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(update_model));
936 for (i=0; i<NUCOL; i++)
937 {
938 if (i == 5)
939 {
940 str = g_strdup_printf ("%s %s", field_acro[tmp_field -> type], up_title[i]);
941 }
942 else
943 {
944 str = g_strdup_printf ("%s", up_title[i]);
945 }
946 if (i == 5)
947 {
948 update_renderer[i] = gtk_cell_renderer_combo_new();
950 g_object_set (update_renderer[i], "model", prop_to_up, "text-column", 0, "has-entry", FALSE, "editable", TRUE, NULL);
951 gtk_tree_model_filter_set_visible_func ((GtkTreeModelFilter *)prop_to_up, (GtkTreeModelFilterVisibleFunc)G_CALLBACK(update_rend), GTK_TREE_VIEW(update_tree), NULL);
952 g_object_unref (prop_to_up);
953 g_signal_connect (G_OBJECT(update_renderer[i]), "editing-started", G_CALLBACK(markup_action_renderer), NULL);
954 g_signal_connect (G_OBJECT(update_renderer[i]), "changed", G_CALLBACK(changed_update_renderer), NULL);
955 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "text", i, NULL);
956 }
957 else if (i == NUCOL-1)
958 {
959 update_renderer[i] = gtk_cell_renderer_toggle_new ();
960 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "active", i, NULL);
961 g_signal_connect (G_OBJECT(update_renderer[i]), "toggled", G_CALLBACK(on_toggle_update), NULL);
962 }
963 else
964 {
965 update_renderer[i] = gtk_cell_renderer_text_new();
966 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "text", i, NULL);
967 }
968 g_free (str);
969 if (i > 1)
970 {
971 gtk_tree_view_column_set_alignment (update_col[i], 0.5);
972 gtk_tree_view_append_column(GTK_TREE_VIEW(update_tree), update_col[i]);
973 gtk_tree_view_column_set_cell_data_func (update_col[i], update_renderer[i], field_set_markup_and_visible, GINT_TO_POINTER(i), NULL);
974 }
975 }
976 for (i=0; i<9; i++) tmp_res[i] = NULL;
978 g_object_unref (update_model);
979 GtkTreeSelection * update_select = gtk_tree_view_get_selection (GTK_TREE_VIEW(update_tree));
980 gtk_tree_selection_set_mode (update_select, GTK_SELECTION_SINGLE);
981#ifdef GTK4
982 add_widget_gesture_and_key_action (update_tree, "ff-button-pressed", G_CALLBACK(on_ff_button_pressed), NULL,
983 "ff-button-released", G_CALLBACK(on_ff_button_released), NULL,
984 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
985
986#else
987 g_signal_connect (G_OBJECT(update_tree), "button_press_event", G_CALLBACK(on_ff_button_event), NULL);
988#endif
989 return update_tree;
990}
991
999void win_update_tree (GtkWidget * vbx)
1000{
1001 int i;
1002 update_tree = NULL;
1003 update_model = NULL;
1004 for (i=0; i<NUCOL; i++)
1005 {
1006 update_renderer[i] = NULL;
1007 update_col[i] = NULL;
1008 }
1009 GtkWidget * scrollsets = create_scroll (NULL, -1, -1, GTK_SHADOW_ETCHED_IN);
1010 gtk_widget_set_size_request (scrollsets, 800, 400);
1011
1013 GtkWidget * hbox = create_hbox (0);
1014 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, scrollsets, FALSE, FALSE, 20);
1015 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, hbox, FALSE, FALSE, 20);
1016 gchar * funits[5] ={"Ev", "kcal mol<sup>-1</sup>", "kJ mol<sup>-1</sup>", "K B<sup>-1</sup>", "DL_POLY internal units"};
1017 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"
1018 "\t<b>(1)</b> %s energy unit: %s, if required conversion to FIELD file energy unit will be performed upon selection.\n"
1019 "\t<b>(2)</b> Restraint parameters are duplicates of the non-restraint parameters.\n",
1020 field_acro[tmp_field -> type], funits[ff_unit]);
1021 i = 3;
1022 if (tmp_field -> type > AMBER99 && tmp_field -> type < CVFF)
1023 {
1024 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]);
1025 i ++;
1026 }
1027 if (tmp_field -> type <= CVFF_AUG || tmp_field -> type > COMPASS)
1028 {
1029 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]);
1030 }
1031 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 0);
1032 g_free (str);
1033 if (tmp_field -> type <= CVFF_AUG || tmp_field -> type > COMPASS)
1034 {
1035 hbox = create_hbox (0);
1036 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, hbox, FALSE, FALSE, 0);
1037 if (tmp_field -> type < CVFF || tmp_field -> type > COMPASS)
1038 {
1039 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());
1040 if (tmp_field -> type > AMBER99)
1041 {
1042 str = g_strdup_printf ("%s\nScaled 1-4 exclusion parameters, provided by the %s force field, are ignored.", str, field_acro[tmp_field -> type]);
1043 }
1044 }
1045 else
1046 {
1047 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());
1048 }
1049 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 200);
1050 g_free (str);
1051 }
1052}
1053
1066void look_up_this_field_object (int fsid, int fpid, int ssid, int nat, int * fsp, int * fat)
1067{
1068 int i, j;
1069 tmp_obj_id = field_objects_id[(fsid < 6) ? fsid / 2 : fsid - 3];
1070 while (tmp_obj_id)
1071 {
1072 i = tmp_obj_id -> oid;
1073 j = tmp_obj_id -> type;
1074 ff_data = get_ff_data (fsid, j);
1075 if (is_this_object_a_match (fsid, nat, fsp, ff_data -> atoms_z[i]))
1076 {
1077 if (is_this_object_a_match (fsid, nat, fat, ff_data -> atoms_id[i]))
1078 {
1079 if (up_match[fsid] == NULL)
1080 {
1081 up_match[fsid] = g_malloc0 (sizeof*up_match[fsid]);
1082 tmp_match = up_match[fsid];
1083 }
1084 else
1085 {
1086 tmp_match -> next = g_malloc0 (sizeof*tmp_match);
1087 tmp_match = tmp_match -> next;
1088 }
1089 tmp_match -> id = ssid;
1090 tmp_match -> obj = fpid;
1091 tmp_match -> oid = i;
1092 tmp_match -> type = j;
1093 // g_debug ("Match :: fsid= %d, -> id = %d, -> obj = %d, -> oid = %d, -> type = %d", fsid, ssid, fpid, i, j);
1094 }
1095 }
1096 tmp_obj_id = tmp_obj_id -> next;
1097 }
1098}
1099
1111void check_this_fprop (int fsid, int fpid, int ssid, int * fat, int * fsp)
1112{
1113 int i, j, k;
1114 int * ffat, * ffsp;
1115 gboolean update = TRUE;
1116 field_atom* tmpat;
1117 i = struct_id(fsid+7);
1118 for (j=0; j<i; j++)
1119 {
1120 k = fsp[j];
1121 tmpat = get_active_atom (tmp_fmol -> id, fat[j]);
1122 if (tmpat -> id != tmp_fat -> id)
1123 {
1124 if (tmpat -> afid < 0)
1125 {
1126 if (atoms_id[k] == 0 && extraz_id[(fsid < 6)? fsid/2: fsid-3][k] == 0)
1127 {
1128 update = FALSE;
1129 }
1130 }
1131 }
1132 }
1133 if (update)
1134 {
1135 // Is there any field data available ?
1136 // Check the field data for available parameters
1137 ffat = allocint(i);
1138 ffsp = allocint(i);
1139 for (j=0; j<i; j++)
1140 {
1141 ffat[j] = get_active_atom (tmp_fmol -> id, fat[j]) -> afid;
1142 ffsp[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][get_active_atom (tmp_fmol -> id, fat[j]) -> sp];
1143 }
1144 look_up_this_field_object (fsid, fpid, ssid, i, ffsp, ffat);
1145 g_free (ffat);
1146 g_free (ffsp);
1147 }
1148}
1149
1158int this_body_has_atom (field_nth_body * body, char * name)
1159{
1160 int i, j, k, l , m;
1161 m = 0;
1162 for (i=0; i<2; i++)
1163 {
1164 for (j=0; j<body -> na[i]; j++)
1165 {
1166 k = body -> ma[i][j];
1167 l = body -> a[i][j];
1168 if (g_strcmp0 (get_active_atom(k, l) -> name, name) == 0) m += (i+1);
1169 }
1170 }
1171 return m;
1172}
1173
1183G_MODULE_EXPORT void run_check_atom_for_updates (GtkDialog * dialog, gint response_id, gpointer data)
1184{
1185 int i, j, k, l, m;
1186 float v;
1187 gboolean update_vdw = FALSE;
1188 if (response_id == GTK_RESPONSE_APPLY)
1189 {
1190 for (i=0; i<9; i++)
1191 {
1192 if (tmp_res[i])
1193 {
1195 while (other_match)
1196 {
1197 if (tmp_match -> use)
1198 {
1199 if (i < 8)
1200 {
1201 tmp_fstr = get_active_struct (i, tmp_fmol -> id, tmp_match -> id);
1202 tmp_fprop = (tmp_match -> obj > 0) ? get_active_prop (tmp_fstr -> other, tmp_match -> obj - 1) : tmp_fstr -> def;
1203 g_free (tmp_fprop -> val);
1204 ff_data = get_ff_data (i, tmp_match -> type);
1205 tmp_fprop -> val = duplicate_float(ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1206 // UNITS !
1207 tmp_fprop -> fpid = tmp_match -> oid;
1208 tmp_fprop -> key = abs(ff_data -> key)-1;
1209 if ((i < 2 && (tmp_fprop -> key == 1 || tmp_fprop -> key == 5)) || ((i == 2 || i == 3) && tmp_fprop -> key < 2))
1210 {
1211 for (l=0; l<ff_data -> npar; l++)
1212 {
1213 if (l != 1) tmp_fprop -> val[l] *= (l+2 - l/3);
1214 }
1215 }
1216 if (ff_unit != tmp_field -> energy_unit)
1217 {
1219 tmp_fprop -> val[0] = tmp_fprop -> val[0]*v;
1220 if ((i/2 == 1 && tmp_fprop -> key == 1) || (i/2 == 1 && tmp_fprop -> key == 3))
1221 {
1222 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1223 tmp_fprop -> val[3] = tmp_fprop -> val[3]*v;
1224 }
1225 else if (i/2 == 0 && tmp_fprop -> key == 1)
1226 {
1227 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1228 }
1229 }
1230 tmp_fprop -> use = TRUE;
1231 }
1232 else
1233 {
1234 // Pot must be defined for the 2 atoms
1235 tmp_fbody = get_active_body (0, 0);
1236 ff_data = get_ff_data (i, tmp_match -> type);
1237 while (tmp_fbody)
1238 {
1239 update_vdw = FALSE;
1240 j = this_body_has_atom (tmp_fbody, tmp_fat -> name);
1241 k = tmp_match -> oid;
1242 if (j == 3)
1243 {
1244 tmp_fbody -> fpid[0] = tmp_fbody -> fpid[1] = k;
1245 j = l = k;
1246 update_vdw = TRUE;
1247 }
1248 else if (j)
1249 {
1250 j --;
1251 tmp_fbody -> fpid[j] = k;
1252 // Need to do something here !
1253 l = (j) ? 0 : 1;
1254 update_vdw = FALSE;
1255 if (tmp_fbody -> fpid[l] > -1)
1256 {
1257 j = k;
1258 l = tmp_fbody -> fpid[l];
1259 update_vdw = TRUE;
1260 }
1261 }
1262 if (update_vdw)
1263 {
1264 if (tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS)
1265 {
1266 v = sqrt(ff_data -> param[j][0]*ff_data -> param[l][0]);
1267 tmp_fbody -> val[0] = v*pow((double)(ff_data -> param[j][1] + ff_data -> param[l][1]), 12.0);
1268 tmp_fbody -> val[1] = 2.0 * v * pow((double)(ff_data -> param[j][1] + ff_data -> param[l][1]), 6.0);
1269 }
1270 else if (tmp_field -> type <= CVFF_AUG)
1271 {
1272 for (m=0; m<2; m++) tmp_fbody -> val[m] = sqrt(ff_data -> param[j][m]*ff_data -> param[l][m]);
1273 }
1274 }
1275 tmp_fbody = tmp_fbody -> next;
1276 }
1277 }
1278 }
1279 other_match = tmp_match -> next;
1280 g_free (tmp_match);
1282 }
1283 }
1284 }
1285 for (i=0; i<9; i++)
1286 {
1287 if (up_match[i])
1288 {
1290 while (other_match)
1291 {
1292 other_match = tmp_match -> next;
1293 g_free (tmp_match);
1295 }
1296 up_match[i] = NULL;
1297 }
1298 }
1299 }
1300 destroy_this_dialog (dialog);
1301}
1302
1309{
1310 int i, j, k, l;
1311 int * fsp;
1312 gboolean update_this = FALSE;
1313 field_prop * oth;
1314
1315 // Lookup for this atoms in bonds, etc ... and if parameters, then look for update is all atoms are field auto
1316 // Field struct (bonds, bond rest., angles, angles rest., dih, tors. rest., imp., vdw.)
1317 // g_debug ("Checking for field parameters of atoms: %s - id = %d", tmp_fat -> name, tmp_fat -> id + 1);
1318 for (i=0; i<8; i++)
1319 {
1320 up_match[i] = NULL;
1321 if ((i != 4 && i != 5) || tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1322 {
1323 if (get_ff_data(i, 0) && tmp_field -> afp[i+15])
1324 {
1325 k = struct_id(i+7);
1326 fsp = allocint(k);
1327 tmp_fstr = tmp_fmol -> first_struct[i];
1328 while (tmp_fstr != NULL)
1329 {
1330 for (j=0; j<k; j++)
1331 {
1332 if (tmp_fstr -> aid[j] == tmp_fat -> id)
1333 {
1334 // Update this field struct parameters
1335 for (l=0; l<k; l++)
1336 {
1337 fsp[l]= get_active_atom (tmp_fmol -> id, tmp_fstr -> aid[l]) -> sp;
1338 }
1339 check_this_fprop (i, 0, tmp_fstr -> id, tmp_fstr -> aid, fsp);
1340 oth = tmp_fstr -> other;
1341 while (oth != NULL)
1342 {
1343 check_this_fprop (i, oth -> pid+1, tmp_fstr -> id, tmp_fstr -> aid, fsp);
1344 oth = oth -> next;
1345 }
1346 break;
1347 }
1348 }
1349 tmp_fstr = tmp_fstr -> next;
1350 }
1351 g_free (fsp);
1352 }
1353 }
1354 }
1355 up_match[8] = NULL;
1356 if (tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1357 {
1358 tmp_fbody = get_active_body (0, 0);
1359 while (tmp_fbody && tmp_field -> afp[23])
1360 {
1361 if (this_body_has_atom (tmp_fbody, tmp_fat -> name) == 3)
1362 {
1364 while (tmp_obj_id)
1365 {
1366 i = tmp_proj -> chemistry -> chem_prop[CHEM_Z][tmp_fat -> sp];
1367 j = tmp_obj_id -> oid;
1368 if (ff_vdw -> atoms_z[j][0] == i && (ff_vdw -> atoms_id[j][0] == tmp_fat -> afid || ff_vdw -> atoms_id[j][0] == -1))
1369 {
1370 if (up_match[8] == NULL)
1371 {
1372 up_match[8] = g_malloc0 (sizeof*up_match[8]);
1373 tmp_match = up_match[8];
1374 }
1375 else
1376 {
1377 tmp_match -> next = g_malloc0 (sizeof*tmp_match);
1378 tmp_match = tmp_match -> next;
1379 }
1380 tmp_match -> id = 8;
1381 tmp_match -> obj = tmp_fbody -> id;
1382 tmp_match -> oid = tmp_obj_id -> oid;
1383 tmp_match -> type = 0;
1384 tmp_match -> use = FALSE;
1385 }
1386 tmp_obj_id = tmp_obj_id -> next;
1387 }
1388 }
1389 tmp_fbody = tmp_fbody -> next;
1390 }
1391 }
1392 for (i=0; i<9; i++)
1393 {
1394 if (up_match[i] != NULL)
1395 {
1396 update_this = TRUE;
1397 break;
1398 }
1399 }
1400 if (update_this)
1401 {
1402 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]));
1403 GtkWidget * dial = dialog_cancel_apply (str, field_assistant, FALSE);
1404 g_free (str);
1405 GtkWidget * vbox = dialog_get_content_area (dial);
1407 run_this_gtk_dialog (dial, G_CALLBACK(run_check_atom_for_updates), NULL);
1408 }
1409}
1410
1419G_MODULE_EXPORT void changed_field_prop_combo (GtkComboBox * box, gpointer data)
1420{
1421 int i, j;
1422 dint * prop = (dint *)data;
1423 float * val, * vbl;
1424 i = gtk_combo_box_get_active (box);
1425 if (i)
1426 {
1427 tmp_match = up_match[prop -> b];
1428 for (j=0; j<i-1; j++) tmp_match = tmp_match -> next;
1429 ff_data = get_ff_data (prop -> a - 7, tmp_match -> type);
1430 if (prop -> a < 15)
1431 {
1432 tmp_fprop -> key = abs(ff_data -> key) - 1;
1433 g_free (tmp_fprop -> val);
1434 tmp_fprop -> fpid = tmp_match -> oid;
1435 tmp_fprop -> val = duplicate_float (ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1436 if ((prop -> a < 9 && (tmp_fprop -> key == 0 || tmp_fprop -> key == 5)) || ((prop -> a == 9 || prop -> a == 10) && tmp_fprop -> key < 2))
1437 {
1438 for (j=0; j<ff_data -> npar; j++)
1439 {
1440 if (j != 1) tmp_fprop -> val[j] *= (j+2 - j/3);
1441 }
1442 }
1443 if (ff_unit != tmp_field -> energy_unit)
1444 {
1445 float v = internal_to_other[tmp_field -> energy_unit] / internal_to_other[ff_unit];
1446 tmp_fprop -> val[0] = tmp_fprop -> val[0]*v;
1447 if (((prop -> a - 7)/2 == 1 && tmp_fprop -> key == 1) || ((prop -> a - 7)/2 == 1 && tmp_fprop -> key == 3))
1448 {
1449 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1450 tmp_fprop -> val[3] = tmp_fprop -> val[3]*v;
1451 }
1452 else if ((prop -> a - 7)/2 == 0 && tmp_fprop -> key == 1)
1453 {
1454 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1455 }
1456 }
1457 gtk_combo_box_set_active (GTK_COMBO_BOX(field_key_combo), tmp_fprop -> key);
1458 }
1459 else
1460 {
1461 // Check both atoms pot, and use same pot.
1462 tmp_fbody -> key = abs(ff_data -> key) - 1;
1463 tmp_fbody -> fpid[prop -> b] = tmp_match -> oid;
1464 val = duplicate_float (ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1465 gtk_combo_box_set_active (GTK_COMBO_BOX(field_key_combo), tmp_fbody -> key);
1466 }
1467 }
1468 else
1469 {
1470 if (prop -> a < 15)
1471 {
1472 tmp_fprop -> fpid = -1;
1473 }
1474 else
1475 {
1476 tmp_fbody -> fpid[prop -> b] = -1;
1477 }
1478 }
1479 if (prop -> a == 15)
1480 {
1481 float * vcl;
1482 float eij;
1483 float rij;
1484 i = (prop -> b) ? 0 : 1;
1485 if (vdw_same_atom)
1486 {
1487 tmp_fbody -> fpid[i] = tmp_fbody -> fpid[!i];
1488 }
1489 if (tmp_fbody -> fpid[0] > -1 && tmp_fbody -> fpid[1] > -1)
1490 {
1491 j = tmp_fbody -> fpid[i];
1492 vbl = duplicate_float (ff_data -> npar, ff_data -> param[j]);
1493 if ((tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS) && tmp_fbody -> key == 0)
1494 {
1495 // 12-6, recalculate A and B
1496 vcl = allocfloat (ff_data -> npar);
1497 eij = sqrt(val[0]*vbl[0]);
1498 rij = (val[1] + vbl[1]);
1499 vcl[0] = eij * pow((double) rij, 12.0);
1500 vcl[1] = 2.0 * eij * pow((double) rij, 6.0);
1501 g_free (tmp_fbody -> val);
1502 tmp_fbody -> val = duplicate_float(ff_data -> npar, vcl);
1503 g_free (vcl);
1504 }
1505 else if (tmp_field -> type == CVFF || tmp_field -> type == CVFF_AUG)
1506 {
1507 // 12-6, A-B
1508 vcl = allocfloat (ff_data -> npar);
1509 vcl[0] = sqrt(val[0]*vbl[0]);
1510 vcl[1] = sqrt(val[1]*vbl[1]);
1511 g_free (tmp_fbody -> val);
1512 tmp_fbody -> val = duplicate_float(ff_data -> npar, vcl);
1513 g_free (vcl);
1514 }
1515 g_free (vbl);
1516 }
1517 g_free (val);
1518 }
1520 p_box = param_prop_param_box (prop -> a);
1521 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, param_box, p_box, FALSE, FALSE, 0);
1523}
1524
1533GtkWidget * create_field_prop_combo (int f, int is_moy)
1534{
1535 int h, i, j, k, l, m, n;
1536 GtkWidget * vbox, * hbox;
1537 gboolean save_it;
1538 gchar * str_vdw[2];
1539 gchar * str;
1540 h = (f == 15) ? 2 : struct_id(f);
1541 i = (f == 15) ? 2 : 1;
1542 for (j=0; j<i; j++) up_match[j] = g_malloc0 (sizeof*up_match[j]);
1543 int * spec_z = allocint (h);
1544 vbox = create_vbox (BSEP);
1545 if (f == 15)
1546 {
1547 vdw_same_atom = FALSE;
1548 j = get_num_vdw_max ();
1549 for (j=0; j<2; j++)
1550 {
1551 str_vdw[j] = g_strdup_printf ("%s", get_body_element_name (tmp_fbody, j, 0));
1552 l = tmp_fbody -> ma[j][0];
1553 m = tmp_fbody -> a[j][0];
1554 n = get_active_atom (l, m) -> sp;
1555 spec_z[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][n];
1556 }
1557 if (g_strcmp0 (str_vdw[0], str_vdw[1]) == 0)
1558 {
1559 vdw_same_atom = TRUE;
1560 i = 1;
1561 }
1562 for (j=0; j<i; j++)
1563 {
1564 hbox = create_hbox(0);
1565 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1566 ff_p_combo[j] = create_combo ();
1567 combo_text_append (ff_p_combo[j], "Manual");
1568 l = tmp_fbody -> ma[j][0];
1569 m = tmp_fbody -> a[j][0];
1570 if (i == 1)
1571 {
1572 str = g_strdup_printf ("Atom (1 and 2) <b>%s</b>", str_vdw[j]);
1573 }
1574 else
1575 {
1576 str = g_strdup_printf ("Atom (%d) <b>%s</b>", j+1, str_vdw[j]);
1577 }
1578 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 150, -1, 0.0, 0.5), FALSE, FALSE, 10);
1579 g_free (str);
1580 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ff_p_combo[j], FALSE, FALSE, 10);
1581 }
1582 for (j=0; j<2; j++) g_free (str_vdw[j]);
1583 }
1584 else
1585 {
1586 hbox = create_hbox(0);
1587 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1588 ff_p_combo[0] = create_combo ();
1589 combo_text_append (ff_p_combo[0], "Manual");
1590 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ff_p_combo[0], FALSE, FALSE, 10);
1591 for (j=0; j<h; j++)
1592 {
1593 if (is_moy)
1594 {
1595 k = tmp_fstr -> aid[j];
1596 l = get_active_atom (tmp_fmol -> id, k) -> sp;
1597 }
1598 else
1599 {
1600 k = tmp_fprop -> aid[j];
1601 l = get_active_atom (tmp_fmol -> id, tmp_fmol -> atoms_id[k][0].a) -> sp;
1602 }
1603 spec_z[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][l];
1604 }
1605 }
1606 if (f != 15 || tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1607 {
1608 for (j=0; j<i; j++)
1609 {
1610 tmp_obj_id = field_objects_id[(f-7) < 6 ? (f-7) / 2 : f-10];
1611 m = n = 0;
1612 up_match[j] = NULL;
1613 while (tmp_obj_id)
1614 {
1615 k = tmp_obj_id -> oid;
1616 l = tmp_obj_id -> type;
1617 ff_data = get_ff_data (f-7, l);
1618 save_it = FALSE;
1619 if (f < 15 && is_this_object_a_match (f-7, h, spec_z, ff_data -> atoms_z[k]))
1620 {
1621 m ++;
1622 if (tmp_fprop -> fpid == k && tmp_fprop -> key == abs(ff_data -> key)-1) n = m;
1623 save_it = TRUE;
1624 }
1625 else if (f == 15 && ff_data -> atoms_z[k][0] == spec_z[j])
1626 {
1627 m ++;
1628 if (tmp_fbody -> fpid[j] == k) n = m;
1629 save_it = TRUE;
1630 }
1631 if (save_it)
1632 {
1633 str = g_strdup_printf ("%s", get_this_prop_string (f-7, k, l, 0));
1634 if (ff_data -> info)
1635 {
1636 if (g_strcmp0 (ff_data -> info[k], " ") != 0) str = g_strdup_printf ("%s : %s", str, ff_data -> info[k]);
1637 }
1638 combo_text_append (ff_p_combo[j], str);
1639 g_free (str);
1640 if (up_match[j] == NULL)
1641 {
1642 up_match[j] = g_malloc0 (sizeof*up_match[j]);
1643 tmp_match = up_match[j];
1644 }
1645 else
1646 {
1647 tmp_match -> next = g_malloc0 (sizeof*tmp_match -> next);
1648 tmp_match -> next -> id = tmp_match -> id + 1;
1649 tmp_match = tmp_match -> next;
1650 }
1651 tmp_match -> obj = f - 7;
1652 tmp_match -> oid = k;
1653 tmp_match -> type = l;
1654 }
1655 tmp_obj_id = tmp_obj_id -> next;
1656 }
1657 GList * cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(ff_p_combo[j]));
1658 if (cell_list && cell_list -> data)
1659 {
1660 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(ff_p_combo[j]), cell_list -> data, "markup", 0, NULL);
1661 }
1662 pup[j].a = f;
1663 pup[j].b = j;
1664 gtk_combo_box_set_active (GTK_COMBO_BOX(ff_p_combo[j]), n);
1665 if (m == 0) widget_set_sensitive (ff_p_combo[j], FALSE);
1666 g_signal_connect (G_OBJECT(ff_p_combo[j]), "changed", G_CALLBACK(changed_field_prop_combo), & pup[j]);
1667 }
1668 }
1669 return vbox;
1670}
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
gchar * param[2]
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
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
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:306
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:3251
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:140
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:522
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
int ** atoms_id_list
char * fvars_dihedral[2][FDIHEDRAL][FDIHEDRAL_P]
Definition dlp_field.c:450
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:372
dint pup[2]
int get_num_vdw_max()
Get the number of field shell interactions.
Definition dlp_edit.c:2002
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
GtkWidget * afftype
Definition dlp_edit.c:121
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:687
GtkWidget * field_key_combo
Definition dlp_edit.c:111
GtkWidget * param_box
Definition dlp_edit.c:114
int * atoms_id
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
GtkWidget * p_box
Definition dlp_edit.c:112
char * fvars_vdw[2][FVDW][FVDW_P]
Definition dlp_field.c:602
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
GtkWidget * ff_p_combo[2]
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
char *** ff_atoms
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:1934
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:255
field_nth_body * tmp_fbody
Definition dlp_field.c:965
float internal_to_other[5]
Definition dlp_field.c:938
project * tmp_proj
Definition dlp_field.c:953
gchar * fnames[2][16][21]
Definition dlp_field.c:218
field_atom * tmp_fat
Definition dlp_field.c:957
int struct_id(int f)
number of atoms in a structural element
Definition dlp_field.c:999
field_struct * tmp_fstr
Definition dlp_field.c:964
gchar * parameters_info(int obj, int key, gchar **words, float *data)
prepare classical force field parameter description string
Definition dlp_field.c:1097
field_molecule * tmp_fmol
Definition dlp_field.c:955
field_prop * tmp_fprop
Definition dlp_field.c:963
GtkWidget * field_assistant
Definition dlp_field.c:940
classical_field * tmp_field
Definition dlp_field.c:951
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:604
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:161
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:410
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:541
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:472
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1940
#define BSEP
Definition global.h:217
@ CONTAINER_SCR
Definition global.h:223
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:903
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:805
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1565
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:279
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:186
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2041
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:793
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:880
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2010
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:206
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:781
#define CHEM_Z
Definition global.h:269
#define MAXDATA
Number of tabs for the description of the classical force field.
Definition global.h:662
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:169
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
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:370
Messaging function declarations.
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
Definition global.h:91
int b
Definition global.h:93
int a
Definition global.h:92
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72