atomes 1.1.15
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;
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 if (up_match[i])
616 {
618 while (other_match)
619 {
620 str = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
621 gtk_tree_store_append (store, & iter, NULL);
622 gtk_tree_store_set (store, & iter, 0, str, -1);
623 g_free (str);
624 other_match = other_match -> next;
625 }
626 }
627 }
628 return gtk_tree_model_filter_new(GTK_TREE_MODEL (store), NULL);
629}
630
639dint get_visible (gboolean result, gchar * the_name)
640{
641 dint vis;
642 gchar * str;
643 gboolean done = FALSE;
644 // With the "Select ..." path starts at 1 and not 0
645 vis.a = vis.b = 0;
646 int i;
647 for (i=0; i<9; i++)
648 {
649 if (up_match[i])
650 {
652 while (other_match)
653 {
654 if (i == up.a && ((i < 8 && other_match -> id == up.b) || (i == 8 && other_match -> obj == up.b)))
655 {
656 if (result)
657 {
658 str = g_strdup_printf ("%s", get_this_prop_string (i, other_match -> oid, other_match -> type, 1));
659 if (g_strcmp0 (str, the_name) == 0)
660 {
661 vis.a = -1;
662 return vis;
663 }
664 }
665 vis.b ++;
666 done = TRUE;
667 }
668 else if (! done)
669 {
670 vis.a ++;
671 }
672 other_match = other_match -> next;
673 }
674 if (done) break;
675 }
676 }
677 return vis;
678}
689G_MODULE_EXPORT void changed_update_renderer (GtkCellRendererCombo * combo, gchar * path_string, GtkTreeIter * iter, gpointer data)
690{
691 GValue val = {0, };
692 GObject * cmodel;
693 dint res;
694 g_object_get (combo, "model", & cmodel, NULL);
695 gtk_tree_model_get_value ((GtkTreeModel *)cmodel, iter, 0, & val);
696 if (gtk_tree_model_get_iter_from_string ((GtkTreeModel *)update_model, iter, path_string))
697 {
698 gchar * str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
699 gtk_tree_store_set (update_model, iter, 5, str, -1);
700 res = get_visible (TRUE, str);
701 if (res.a < 0)
702 {
704 }
705 }
706}
707
717void get_update_tree_data (GtkWidget * tree, gpointer data, GtkTreePath * path)
718{
719 GtkTreeModel * tmodel = gtk_tree_view_get_model (GTK_TREE_VIEW(tree));
720 GtkTreeIter update_iter;
721 up.a = up.b = -1;
722 if (gtk_tree_model_get_iter (tmodel, & update_iter, path))
723 {
724 gtk_tree_model_get (tmodel, & update_iter, 0, & up.a, 1, & up.b, -1);
725 gtk_tree_model_filter_refilter ((GtkTreeModelFilter *)prop_to_up);
726 }
727}
728
729#ifdef GTK4
742void ff_button_event (double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
743#else
757void ff_button_event (GdkEvent * event, double event_x, double event_y, guint event_button, guint event_type, guint32 event_time, gpointer data)
758#endif
759{
760 if (event_type == GDK_BUTTON_PRESS)
761 {
762 GtkTreePath * path;
763 GtkTreeViewColumn * column;
764 int i, j;
765#ifdef GTK4
766 int e_x, e_y;
767 gtk_tree_view_convert_widget_to_bin_window_coords (GTK_TREE_VIEW(update_tree), event_x, event_y, & e_x, & e_y);
768 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(update_tree), e_x, e_y, & path, & column, & i, & j);
769#else
770 gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW(update_tree), event_x, event_y, & path, & column, & i, & j);
771#endif
772 if (path != NULL)
773 {
775 }
776 }
777}
778
779#ifdef GTK4
791G_MODULE_EXPORT void on_ff_button_pressed (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
792{
793 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);
794}
795
807G_MODULE_EXPORT void on_ff_button_released (GtkGesture * gesture, int n_press, double x, double y, gpointer data)
808{
809 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);
810}
811#else
821G_MODULE_EXPORT gboolean on_ff_button_event (GtkWidget * widget, GdkEvent * event, gpointer data)
822{
823 GdkEventButton * bevent = (GdkEventButton *)event;
824 ff_button_event (event, bevent -> x, bevent -> y, bevent -> button, bevent -> type, bevent -> time, data);
825 return FALSE;
826}
827#endif
828
838G_MODULE_EXPORT void on_toggle_update (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
839{
840 GtkTreeIter iter;
841 int i;
842 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
843 gtk_tree_model_get_iter (GTK_TREE_MODEL(update_model), & iter, path);
844 gtk_tree_model_get (GTK_TREE_MODEL(update_model), & iter, 7, & i, -1);
845 gchar * str;
846 gtk_tree_model_get (GTK_TREE_MODEL(update_model), & iter, 5, & str, -1);
847 dint res = get_visible(TRUE, str);
848 g_free (str);
849 if (res.a < 0)
850 {
852 while (tmp_match)
853 {
854 if (tmp_match -> id == other_match -> id && tmp_match -> obj == other_match -> obj)
855 {
856 tmp_match -> use = ! i;
857 break;
858 }
859 tmp_match = tmp_match -> next;
860 }
861 gtk_tree_store_set (update_model, & iter, 7, ! i, -1);
862 }
863}
864
874static gboolean update_rend (GtkTreeModel * model, GtkTreeIter * iter, gpointer data)
875{
876 GtkTreeIter upiter;
877 dint vis;
878 gchar * str;
879 if (gtk_tree_model_get_iter_first(model, & upiter))
880 {
881 GtkTreePath * path = gtk_tree_model_get_path(model, iter);
882 str = gtk_tree_path_to_string(path);
883 gtk_tree_path_free(path);
884 if (g_strcmp0 (str, "0") == 0) return TRUE;
885 vis = get_visible (FALSE, NULL);
886 int p = (int)string_to_double ((gpointer)str);
887 g_free (str);
888 if (p > vis.a && p < vis.a+vis.b+1) return TRUE;
889 }
890 return FALSE;
891}
892
904void field_set_markup_and_visible (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
905{
906 int i, j, k;
907 i = GPOINTER_TO_INT(data);
908 gtk_tree_model_get (mod, iter, 0, & j, -1);
909 k = (j < 0) ? 0 : 1;
910 gtk_cell_renderer_set_visible (renderer, (i == 2) ? ! k : k);
911 if ((j < 0 && i == 2) || (j>-1 && i != 7))
912 {
913 gchar * str = NULL;
914 gtk_tree_model_get (mod, iter, i, & str, -1);
915 g_object_set (renderer, "markup", str, NULL, NULL);
916 g_free (str);
917 }
918}
919
925GtkWidget * create_update_tree ()
926{
927 int i;
928 gchar * str;
929 gchar * up_title[NUCOL]={" ", " ", "Property", "Atoms", "Species", "parameters (1)", "Actual parameters (1)", "Update ?"};
930 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};
931
932 update_model = gtk_tree_store_newv (NUCOL, up_type);
933 update_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(update_model));
934 for (i=0; i<NUCOL; i++)
935 {
936 if (i == 5)
937 {
938 str = g_strdup_printf ("%s %s", field_acro[tmp_field -> type], up_title[i]);
939 }
940 else
941 {
942 str = g_strdup_printf ("%s", up_title[i]);
943 }
944 if (i == 5)
945 {
946 update_renderer[i] = gtk_cell_renderer_combo_new();
948 g_object_set (update_renderer[i], "model", prop_to_up, "text-column", 0, "has-entry", FALSE, "editable", TRUE, NULL);
949 gtk_tree_model_filter_set_visible_func ((GtkTreeModelFilter *)prop_to_up, (GtkTreeModelFilterVisibleFunc)G_CALLBACK(update_rend), GTK_TREE_VIEW(update_tree), NULL);
950 g_object_unref (prop_to_up);
951 g_signal_connect (G_OBJECT(update_renderer[i]), "editing-started", G_CALLBACK(markup_action_renderer), NULL);
952 g_signal_connect (G_OBJECT(update_renderer[i]), "changed", G_CALLBACK(changed_update_renderer), NULL);
953 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "text", i, NULL);
954 }
955 else if (i == NUCOL-1)
956 {
957 update_renderer[i] = gtk_cell_renderer_toggle_new ();
958 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "active", i, NULL);
959 g_signal_connect (G_OBJECT(update_renderer[i]), "toggled", G_CALLBACK(on_toggle_update), NULL);
960 }
961 else
962 {
963 update_renderer[i] = gtk_cell_renderer_text_new();
964 update_col[i] = gtk_tree_view_column_new_with_attributes (str, update_renderer[i], "text", i, NULL);
965 }
966 g_free (str);
967 if (i > 1)
968 {
969 gtk_tree_view_column_set_alignment (update_col[i], 0.5);
970 gtk_tree_view_append_column(GTK_TREE_VIEW(update_tree), update_col[i]);
971 gtk_tree_view_column_set_cell_data_func (update_col[i], update_renderer[i], field_set_markup_and_visible, GINT_TO_POINTER(i), NULL);
972 }
973 }
974 for (i=0; i<9; i++) tmp_res[i] = NULL;
976 g_object_unref (update_model);
977 GtkTreeSelection * update_select = gtk_tree_view_get_selection (GTK_TREE_VIEW(update_tree));
978 gtk_tree_selection_set_mode (update_select, GTK_SELECTION_SINGLE);
979#ifdef GTK4
980 add_widget_gesture_and_key_action (update_tree, "ff-button-pressed", G_CALLBACK(on_ff_button_pressed), NULL,
981 "ff-button-released", G_CALLBACK(on_ff_button_released), NULL,
982 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
983
984#else
985 g_signal_connect (G_OBJECT(update_tree), "button_press_event", G_CALLBACK(on_ff_button_event), NULL);
986#endif
987 return update_tree;
988}
989
997void win_update_tree (GtkWidget * vbx)
998{
999 int i;
1000 update_tree = NULL;
1001 update_model = NULL;
1002 for (i=0; i<NUCOL; i++)
1003 {
1004 update_renderer[i] = NULL;
1005 update_col[i] = NULL;
1006 }
1007 GtkWidget * scrollsets = create_scroll (NULL, -1, -1, GTK_SHADOW_ETCHED_IN);
1008 gtk_widget_set_size_request (scrollsets, 800, 400);
1009
1011 GtkWidget * hbox = create_hbox (0);
1012 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, scrollsets, FALSE, FALSE, 20);
1013 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, hbox, FALSE, FALSE, 20);
1014 gchar * funits[5] ={"Ev", "kcal mol<sup>-1</sup>", "kJ mol<sup>-1</sup>", "K B<sup>-1</sup>", "DL_POLY internal units"};
1015 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"
1016 "\t<b>(1)</b> %s energy unit: %s, if required conversion to FIELD file energy unit will be performed upon selection.\n"
1017 "\t<b>(2)</b> Restraint parameters are duplicates of the non-restraint parameters.\n",
1018 field_acro[tmp_field -> type], funits[ff_unit]);
1019 i = 3;
1020 if (tmp_field -> type > AMBER99 && tmp_field -> type < CVFF)
1021 {
1022 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]);
1023 i ++;
1024 }
1025 if (tmp_field -> type <= CVFF_AUG || tmp_field -> type > COMPASS)
1026 {
1027 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]);
1028 }
1029 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 0);
1030 g_free (str);
1031 if (tmp_field -> type <= CVFF_AUG || tmp_field -> type > COMPASS)
1032 {
1033 hbox = create_hbox (0);
1034 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbx, hbox, FALSE, FALSE, 0);
1035 if (tmp_field -> type < CVFF || tmp_field -> type > COMPASS)
1036 {
1037 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());
1038 if (tmp_field -> type > AMBER99)
1039 {
1040 str = g_strdup_printf ("%s\nScaled 1-4 exclusion parameters, provided by the %s force field, are ignored.", str, field_acro[tmp_field -> type]);
1041 }
1042 }
1043 else
1044 {
1045 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());
1046 }
1047 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, -1, -1, 0.0, 0.5), FALSE, FALSE, 200);
1048 g_free (str);
1049 }
1050}
1051
1064void look_up_this_field_object (int fsid, int fpid, int ssid, int nat, int * fsp, int * fat)
1065{
1066 int i, j;
1067 tmp_obj_id = field_objects_id[(fsid < 6) ? fsid / 2 : fsid - 3];
1068 while (tmp_obj_id)
1069 {
1070 i = tmp_obj_id -> oid;
1071 j = tmp_obj_id -> type;
1072 ff_data = get_ff_data (fsid, j);
1073 if (is_this_object_a_match (fsid, nat, fsp, ff_data -> atoms_z[i]))
1074 {
1075 if (is_this_object_a_match (fsid, nat, fat, ff_data -> atoms_id[i]))
1076 {
1077 if (up_match[fsid] == NULL)
1078 {
1079 up_match[fsid] = g_malloc0 (sizeof*up_match[fsid]);
1080 tmp_match = up_match[fsid];
1081 }
1082 else
1083 {
1084 tmp_match -> next = g_malloc0 (sizeof*tmp_match);
1085 tmp_match = tmp_match -> next;
1086 }
1087 tmp_match -> id = ssid;
1088 tmp_match -> obj = fpid;
1089 tmp_match -> oid = i;
1090 tmp_match -> type = j;
1091 // g_debug ("Match :: fsid= %d, -> id = %d, -> obj = %d, -> oid = %d, -> type = %d", fsid, ssid, fpid, i, j);
1092 }
1093 }
1094 tmp_obj_id = tmp_obj_id -> next;
1095 }
1096}
1097
1109void check_this_fprop (int fsid, int fpid, int ssid, int * fat, int * fsp)
1110{
1111 int i, j, k;
1112 int * ffat, * ffsp;
1113 gboolean update = TRUE;
1114 field_atom* tmpat;
1115 i = struct_id(fsid+7);
1116 for (j=0; j<i; j++)
1117 {
1118 k = fsp[j];
1119 tmpat = get_active_atom (tmp_fmol -> id, fat[j]);
1120 if (tmpat -> id != tmp_fat -> id)
1121 {
1122 if (tmpat -> afid < 0)
1123 {
1124 if (atoms_id[k] == 0 && extraz_id[(fsid < 6)? fsid/2: fsid-3][k] == 0)
1125 {
1126 update = FALSE;
1127 }
1128 }
1129 }
1130 }
1131 if (update)
1132 {
1133 // Is there any field data available ?
1134 // Check the field data for available parameters
1135 ffat = allocint(i);
1136 ffsp = allocint(i);
1137 for (j=0; j<i; j++)
1138 {
1139 ffat[j] = get_active_atom (tmp_fmol -> id, fat[j]) -> afid;
1140 ffsp[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][get_active_atom (tmp_fmol -> id, fat[j]) -> sp];
1141 }
1142 look_up_this_field_object (fsid, fpid, ssid, i, ffsp, ffat);
1143 g_free (ffat);
1144 g_free (ffsp);
1145 }
1146}
1147
1156int this_body_has_atom (field_nth_body * body, char * name)
1157{
1158 int i, j, k, l , m;
1159 m = 0;
1160 for (i=0; i<2; i++)
1161 {
1162 for (j=0; j<body -> na[i]; j++)
1163 {
1164 k = body -> ma[i][j];
1165 l = body -> a[i][j];
1166 if (g_strcmp0 (get_active_atom(k, l) -> name, name) == 0) m += (i+1);
1167 }
1168 }
1169 return m;
1170}
1171
1181G_MODULE_EXPORT void run_check_atom_for_updates (GtkDialog * dialog, gint response_id, gpointer data)
1182{
1183 int i, j, k, l, m;
1184 float v;
1185 gboolean update_vdw = FALSE;
1186 if (response_id == GTK_RESPONSE_APPLY)
1187 {
1188 for (i=0; i<9; i++)
1189 {
1190 if (tmp_res[i])
1191 {
1193 while (other_match)
1194 {
1195 if (tmp_match -> use)
1196 {
1197 if (i < 8)
1198 {
1199 tmp_fstr = get_active_struct (i, tmp_fmol -> id, tmp_match -> id);
1200 tmp_fprop = (tmp_match -> obj > 0) ? get_active_prop (tmp_fstr -> other, tmp_match -> obj - 1) : tmp_fstr -> def;
1201 g_free (tmp_fprop -> val);
1202 ff_data = get_ff_data (i, tmp_match -> type);
1203 tmp_fprop -> val = duplicate_float(ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1204 // UNITS !
1205 tmp_fprop -> fpid = tmp_match -> oid;
1206 tmp_fprop -> key = abs(ff_data -> key)-1;
1207 if ((i < 2 && (tmp_fprop -> key == 1 || tmp_fprop -> key == 5)) || ((i == 2 || i == 3) && tmp_fprop -> key < 2))
1208 {
1209 for (l=0; l<ff_data -> npar; l++)
1210 {
1211 if (l != 1) tmp_fprop -> val[l] *= (l+2 - l/3);
1212 }
1213 }
1214 if (ff_unit != tmp_field -> energy_unit)
1215 {
1217 tmp_fprop -> val[0] = tmp_fprop -> val[0]*v;
1218 if ((i/2 == 1 && tmp_fprop -> key == 1) || (i/2 == 1 && tmp_fprop -> key == 3))
1219 {
1220 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1221 tmp_fprop -> val[3] = tmp_fprop -> val[3]*v;
1222 }
1223 else if (i/2 == 0 && tmp_fprop -> key == 1)
1224 {
1225 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1226 }
1227 }
1228 tmp_fprop -> use = TRUE;
1229 }
1230 else
1231 {
1232 // Pot must be defined for the 2 atoms
1233 tmp_fbody = get_active_body (0, 0);
1234 ff_data = get_ff_data (i, tmp_match -> type);
1235 while (tmp_fbody)
1236 {
1237 update_vdw = FALSE;
1238 j = this_body_has_atom (tmp_fbody, tmp_fat -> name);
1239 k = tmp_match -> oid;
1240 if (j == 3)
1241 {
1242 tmp_fbody -> fpid[0] = tmp_fbody -> fpid[1] = k;
1243 j = l = k;
1244 update_vdw = TRUE;
1245 }
1246 else if (j)
1247 {
1248 j --;
1249 tmp_fbody -> fpid[j] = k;
1250 // Need to do something here !
1251 l = (j) ? 0 : 1;
1252 update_vdw = FALSE;
1253 if (tmp_fbody -> fpid[l] > -1)
1254 {
1255 j = k;
1256 l = tmp_fbody -> fpid[l];
1257 update_vdw = TRUE;
1258 }
1259 }
1260 if (update_vdw)
1261 {
1262 if (tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS)
1263 {
1264 v = sqrt(ff_data -> param[j][0]*ff_data -> param[l][0]);
1265 tmp_fbody -> val[0] = v*pow((double)(ff_data -> param[j][1] + ff_data -> param[l][1]), 12.0);
1266 tmp_fbody -> val[1] = 2.0 * v * pow((double)(ff_data -> param[j][1] + ff_data -> param[l][1]), 6.0);
1267 }
1268 else if (tmp_field -> type <= CVFF_AUG)
1269 {
1270 for (m=0; m<2; m++) tmp_fbody -> val[m] = sqrt(ff_data -> param[j][m]*ff_data -> param[l][m]);
1271 }
1272 }
1273 tmp_fbody = tmp_fbody -> next;
1274 }
1275 }
1276 }
1277 other_match = tmp_match -> next;
1278 g_free (tmp_match);
1280 }
1281 }
1282 }
1283 for (i=0; i<9; i++)
1284 {
1285 if (up_match[i])
1286 {
1288 while (other_match)
1289 {
1290 other_match = tmp_match -> next;
1291 g_free (tmp_match);
1293 }
1294 up_match[i] = NULL;
1295 }
1296 }
1297 }
1298 destroy_this_dialog (dialog);
1299}
1300
1307{
1308 int i, j, k, l;
1309 int * fsp;
1310 gboolean update_this = FALSE;
1311 field_prop * oth;
1312
1313 // Lookup for this atoms in bonds, etc ... and if parameters, then look for update is all atoms are field auto
1314 // Field struct (bonds, bond rest., angles, angles rest., dih, tors. rest., imp., vdw.)
1315 // g_debug ("Checking for field parameters of atoms: %s - id = %d", tmp_fat -> name, tmp_fat -> id + 1);
1316 for (i=0; i<8; i++)
1317 {
1318 up_match[i] = NULL;
1319 if ((i != 4 && i != 5) || tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1320 {
1321 if (get_ff_data(i, 0) && tmp_field -> afp[i+15])
1322 {
1323 k = struct_id(i+7);
1324 fsp = allocint(k);
1325 tmp_fstr = tmp_fmol -> first_struct[i];
1326 while (tmp_fstr != NULL)
1327 {
1328 for (j=0; j<k; j++)
1329 {
1330 if (tmp_fstr -> aid[j] == tmp_fat -> id)
1331 {
1332 // Update this field struct parameters
1333 for (l=0; l<k; l++)
1334 {
1335 fsp[l]= get_active_atom (tmp_fmol -> id, tmp_fstr -> aid[l]) -> sp;
1336 }
1337 check_this_fprop (i, 0, tmp_fstr -> id, tmp_fstr -> aid, fsp);
1338 oth = tmp_fstr -> other;
1339 while (oth != NULL)
1340 {
1341 check_this_fprop (i, oth -> pid+1, tmp_fstr -> id, tmp_fstr -> aid, fsp);
1342 oth = oth -> next;
1343 }
1344 break;
1345 }
1346 }
1347 tmp_fstr = tmp_fstr -> next;
1348 }
1349 g_free (fsp);
1350 }
1351 }
1352 }
1353 up_match[8] = NULL;
1354 if (tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1355 {
1356 tmp_fbody = get_active_body (0, 0);
1357 while (tmp_fbody && tmp_field -> afp[23])
1358 {
1359 if (this_body_has_atom (tmp_fbody, tmp_fat -> name) == 3)
1360 {
1362 while (tmp_obj_id)
1363 {
1364 i = tmp_proj -> chemistry -> chem_prop[CHEM_Z][tmp_fat -> sp];
1365 j = tmp_obj_id -> oid;
1366 if (ff_vdw -> atoms_z[j][0] == i && (ff_vdw -> atoms_id[j][0] == tmp_fat -> afid || ff_vdw -> atoms_id[j][0] == -1))
1367 {
1368 if (up_match[8] == NULL)
1369 {
1370 up_match[8] = g_malloc0 (sizeof*up_match[8]);
1371 tmp_match = up_match[8];
1372 }
1373 else
1374 {
1375 tmp_match -> next = g_malloc0 (sizeof*tmp_match);
1376 tmp_match = tmp_match -> next;
1377 }
1378 tmp_match -> id = 8;
1379 tmp_match -> obj = tmp_fbody -> id;
1380 tmp_match -> oid = tmp_obj_id -> oid;
1381 tmp_match -> type = 0;
1382 tmp_match -> use = FALSE;
1383 }
1384 tmp_obj_id = tmp_obj_id -> next;
1385 }
1386 }
1387 tmp_fbody = tmp_fbody -> next;
1388 }
1389 }
1390 for (i=0; i<9; i++)
1391 {
1392 if (up_match[i] != NULL)
1393 {
1394 update_this = TRUE;
1395 break;
1396 }
1397 }
1398 if (update_this)
1399 {
1400 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]));
1401 GtkWidget * dial = dialog_cancel_apply (str, field_assistant, FALSE);
1402 g_free (str);
1403 GtkWidget * vbox = dialog_get_content_area (dial);
1405 run_this_gtk_dialog (dial, G_CALLBACK(run_check_atom_for_updates), NULL);
1406 }
1407}
1408
1417G_MODULE_EXPORT void changed_field_prop_combo (GtkComboBox * box, gpointer data)
1418{
1419 int i, j;
1420 dint * prop = (dint *)data;
1421 float * val, * vbl;
1422 i = gtk_combo_box_get_active (box);
1423 if (i)
1424 {
1425 tmp_match = up_match[prop -> b];
1426 for (j=0; j<i-1; j++) tmp_match = tmp_match -> next;
1427 ff_data = get_ff_data (prop -> a - 7, tmp_match -> type);
1428 if (prop -> a < 15)
1429 {
1430 tmp_fprop -> key = abs(ff_data -> key) - 1;
1431 g_free (tmp_fprop -> val);
1432 tmp_fprop -> fpid = tmp_match -> oid;
1433 tmp_fprop -> val = duplicate_float (ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1434 if ((prop -> a < 9 && (tmp_fprop -> key == 0 || tmp_fprop -> key == 5)) || ((prop -> a == 9 || prop -> a == 10) && tmp_fprop -> key < 2))
1435 {
1436 for (j=0; j<ff_data -> npar; j++)
1437 {
1438 if (j != 1) tmp_fprop -> val[j] *= (j+2 - j/3);
1439 }
1440 }
1441 if (ff_unit != tmp_field -> energy_unit)
1442 {
1443 float v = internal_to_other[tmp_field -> energy_unit] / internal_to_other[ff_unit];
1444 tmp_fprop -> val[0] = tmp_fprop -> val[0]*v;
1445 if (((prop -> a - 7)/2 == 1 && tmp_fprop -> key == 1) || ((prop -> a - 7)/2 == 1 && tmp_fprop -> key == 3))
1446 {
1447 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1448 tmp_fprop -> val[3] = tmp_fprop -> val[3]*v;
1449 }
1450 else if ((prop -> a - 7)/2 == 0 && tmp_fprop -> key == 1)
1451 {
1452 tmp_fprop -> val[2] = tmp_fprop -> val[2]*v;
1453 }
1454 }
1455 gtk_combo_box_set_active (GTK_COMBO_BOX(field_key_combo), tmp_fprop -> key);
1456 }
1457 else
1458 {
1459 // Check both atoms pot, and use same pot.
1460 tmp_fbody -> key = abs(ff_data -> key) - 1;
1461 tmp_fbody -> fpid[prop -> b] = tmp_match -> oid;
1462 val = duplicate_float (ff_data -> npar, ff_data -> param[tmp_match -> oid]);
1463 gtk_combo_box_set_active (GTK_COMBO_BOX(field_key_combo), tmp_fbody -> key);
1464 }
1465 }
1466 else
1467 {
1468 if (prop -> a < 15)
1469 {
1470 tmp_fprop -> fpid = -1;
1471 }
1472 else
1473 {
1474 tmp_fbody -> fpid[prop -> b] = -1;
1475 }
1476 }
1477 if (prop -> a == 15)
1478 {
1479 float * vcl;
1480 float eij;
1481 float rij;
1482 i = (prop -> b) ? 0 : 1;
1483 if (vdw_same_atom)
1484 {
1485 tmp_fbody -> fpid[i] = tmp_fbody -> fpid[!i];
1486 }
1487 if (tmp_fbody -> fpid[0] > -1 && tmp_fbody -> fpid[1] > -1)
1488 {
1489 j = tmp_fbody -> fpid[i];
1490 vbl = duplicate_float (ff_data -> npar, ff_data -> param[j]);
1491 if ((tmp_field -> type <= CHARMMSI || tmp_field -> type > COMPASS) && tmp_fbody -> key == 0)
1492 {
1493 // 12-6, recalculate A and B
1494 vcl = allocfloat (ff_data -> npar);
1495 eij = sqrt(val[0]*vbl[0]);
1496 rij = (val[1] + vbl[1]);
1497 vcl[0] = eij * pow((double) rij, 12.0);
1498 vcl[1] = 2.0 * eij * pow((double) rij, 6.0);
1499 g_free (tmp_fbody -> val);
1500 tmp_fbody -> val = duplicate_float(ff_data -> npar, vcl);
1501 g_free (vcl);
1502 }
1503 else if (tmp_field -> type == CVFF || tmp_field -> type == CVFF_AUG)
1504 {
1505 // 12-6, A-B
1506 vcl = allocfloat (ff_data -> npar);
1507 vcl[0] = sqrt(val[0]*vbl[0]);
1508 vcl[1] = sqrt(val[1]*vbl[1]);
1509 g_free (tmp_fbody -> val);
1510 tmp_fbody -> val = duplicate_float(ff_data -> npar, vcl);
1511 g_free (vcl);
1512 }
1513 g_free (vbl);
1514 }
1515 g_free (val);
1516 }
1518 p_box = param_prop_param_box (prop -> a);
1519 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, param_box, p_box, FALSE, FALSE, 0);
1521}
1522
1531GtkWidget * create_field_prop_combo (int f, int is_moy)
1532{
1533 int h, i, j, k, l, m, n;
1534 GtkWidget * vbox, * hbox;
1535 gboolean save_it;
1536 gchar * str_vdw[2];
1537 gchar * str;
1538 h = (f == 15) ? 2 : struct_id(f);
1539 i = (f == 15) ? 2 : 1;
1540 for (j=0; j<i; j++) up_match[j] = g_malloc0 (sizeof*up_match[j]);
1541 int * spec_z = allocint (h);
1542 vbox = create_vbox (BSEP);
1543 if (f == 15)
1544 {
1545 vdw_same_atom = FALSE;
1546 j = get_num_vdw_max ();
1547 for (j=0; j<2; j++)
1548 {
1549 str_vdw[j] = g_strdup_printf ("%s", get_body_element_name (tmp_fbody, j, 0));
1550 l = tmp_fbody -> ma[j][0];
1551 m = tmp_fbody -> a[j][0];
1552 n = get_active_atom (l, m) -> sp;
1553 spec_z[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][n];
1554 }
1555 if (g_strcmp0 (str_vdw[0], str_vdw[1]) == 0)
1556 {
1557 vdw_same_atom = TRUE;
1558 i = 1;
1559 }
1560 for (j=0; j<i; j++)
1561 {
1562 hbox = create_hbox(0);
1563 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1564 ff_p_combo[j] = create_combo ();
1565 combo_text_append (ff_p_combo[j], "Manual");
1566 l = tmp_fbody -> ma[j][0];
1567 m = tmp_fbody -> a[j][0];
1568 if (i == 1)
1569 {
1570 str = g_strdup_printf ("Atom (1 and 2) <b>%s</b>", str_vdw[j]);
1571 }
1572 else
1573 {
1574 str = g_strdup_printf ("Atom (%d) <b>%s</b>", j+1, str_vdw[j]);
1575 }
1576 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 150, -1, 0.0, 0.5), FALSE, FALSE, 10);
1577 g_free (str);
1578 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ff_p_combo[j], FALSE, FALSE, 10);
1579 }
1580 for (j=0; j<2; j++) g_free (str_vdw[j]);
1581 }
1582 else
1583 {
1584 hbox = create_hbox(0);
1585 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1586 ff_p_combo[0] = create_combo ();
1587 combo_text_append (ff_p_combo[0], "Manual");
1588 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ff_p_combo[0], FALSE, FALSE, 10);
1589 for (j=0; j<h; j++)
1590 {
1591 if (is_moy)
1592 {
1593 k = tmp_fstr -> aid[j];
1594 l = get_active_atom (tmp_fmol -> id, k) -> sp;
1595 }
1596 else
1597 {
1598 k = tmp_fprop -> aid[j];
1599 l = get_active_atom (tmp_fmol -> id, tmp_fmol -> atoms_id[k][0].a) -> sp;
1600 }
1601 spec_z[j] = tmp_proj -> chemistry -> chem_prop[CHEM_Z][l];
1602 }
1603 }
1604 if (f != 15 || tmp_field -> type < CFF91 || tmp_field -> type > COMPASS)
1605 {
1606 for (j=0; j<i; j++)
1607 {
1608 tmp_obj_id = field_objects_id[(f-7) < 6 ? (f-7) / 2 : f-10];
1609 m = n = 0;
1610 up_match[j] = NULL;
1611 while (tmp_obj_id)
1612 {
1613 k = tmp_obj_id -> oid;
1614 l = tmp_obj_id -> type;
1615 ff_data = get_ff_data (f-7, l);
1616 save_it = FALSE;
1617 if (f < 15 && is_this_object_a_match (f-7, h, spec_z, ff_data -> atoms_z[k]))
1618 {
1619 m ++;
1620 if (tmp_fprop -> fpid == k && tmp_fprop -> key == abs(ff_data -> key)-1) n = m;
1621 save_it = TRUE;
1622 }
1623 else if (f == 15 && ff_data -> atoms_z[k][0] == spec_z[j])
1624 {
1625 m ++;
1626 if (tmp_fbody -> fpid[j] == k) n = m;
1627 save_it = TRUE;
1628 }
1629 if (save_it)
1630 {
1631 str = g_strdup_printf ("%s", get_this_prop_string (f-7, k, l, 0));
1632 if (ff_data -> info)
1633 {
1634 if (g_strcmp0 (ff_data -> info[k], " ") != 0) str = g_strdup_printf ("%s : %s", str, ff_data -> info[k]);
1635 }
1636 combo_text_append (ff_p_combo[j], str);
1637 g_free (str);
1638 if (up_match[j] == NULL)
1639 {
1640 up_match[j] = g_malloc0 (sizeof*up_match[j]);
1641 tmp_match = up_match[j];
1642 }
1643 else
1644 {
1645 tmp_match -> next = g_malloc0 (sizeof*tmp_match -> next);
1646 tmp_match -> next -> id = tmp_match -> id + 1;
1647 tmp_match = tmp_match -> next;
1648 }
1649 tmp_match -> obj = f - 7;
1650 tmp_match -> oid = k;
1651 tmp_match -> type = l;
1652 }
1653 tmp_obj_id = tmp_obj_id -> next;
1654 }
1655 GList * cell_list = gtk_cell_layout_get_cells(GTK_CELL_LAYOUT(ff_p_combo[j]));
1656 if (cell_list && cell_list -> data)
1657 {
1658 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(ff_p_combo[j]), cell_list -> data, "markup", 0, NULL);
1659 }
1660 pup[j].a = f;
1661 pup[j].b = j;
1662 gtk_combo_box_set_active (GTK_COMBO_BOX(ff_p_combo[j]), n);
1663 if (m == 0) widget_set_sensitive (ff_p_combo[j], FALSE);
1664 g_signal_connect (G_OBJECT(ff_p_combo[j]), "changed", G_CALLBACK(changed_field_prop_combo), & pup[j]);
1665 }
1666 }
1667 return vbox;
1668}
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:592
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:314
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:398
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
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:561
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:492
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1960
#define BSEP
Definition global.h:245
@ CONTAINER_SCR
Definition global.h:251
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:801
#define CHEM_Z
Definition global.h:297
#define MAXDATA
Number of tabs for the description of the classical force field.
Definition global.h:698
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
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:97
int b
Definition global.h:99
int a
Definition global.h:98
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