atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
w_cutoffs.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: 'w_cutoffs.c'
24*
25* Contains:
26*
27
28 - The functions to create the bond cutoffs update dialog
29
30*
31* List of functions:
32
33 void update_cutoffs (project * this_proj);
34 void cut_box (project * this_proj, GtkWidget * vbox);
35
36 G_MODULE_EXPORT void set_cut (GtkEntry * res, gpointer data);
37 G_MODULE_EXPORT void run_window_cuts (GtkDialog * win, gint response_id, gpointer data);
38 G_MODULE_EXPORT void window_cuts (GSimpleAction * action, GVariant * parameter, gpointer data);
39 G_MODULE_EXPORT void window_cuts (GtkWidget * widg, gpointer data);
40
41*/
42
43#include "global.h"
44#include "interface.h"
45#include "project.h"
46#include "glview.h"
47#include "glwindow.h"
48
49extern gchar * label_cutrab (project * this_proj, glwin * view, int id);
50double * tmpcut;
51
59void update_cutoffs (project * this_proj)
60{
61 int i, j, k;
62 k = 0;
63 for (i=0; i<this_proj -> nspec; i++, k++)
64 {
65 if (this_proj -> chemistry -> cutoffs[i][i] != tmpcut[k] && tmpcut[k] >= 0.0)
66 {
67 this_proj -> chemistry -> cutoffs[i][i] = tmpcut[k];
68 this_proj -> dmtx = FALSE;
69 }
70 }
71 for (i=0; i<this_proj -> nspec-1; i++)
72 {
73 for (j=i+1; j<this_proj -> nspec; j++, k++)
74 {
75 if (this_proj -> chemistry -> cutoffs[i][j] != tmpcut[k] && tmpcut[k] >= 0.0)
76 {
77 this_proj -> chemistry -> cutoffs[i][j] = this_proj -> chemistry -> cutoffs[j][i] = tmpcut[k];
78 this_proj -> dmtx = FALSE;
79 }
80 }
81 }
82 if (this_proj -> chemistry -> grtotcutoff != tmpcut[k] && tmpcut[k] >= 0.0)
83 {
84 this_proj -> chemistry -> grtotcutoff = tmpcut[k];
85 this_proj -> dmtx = FALSE;
86 }
87 if (! this_proj -> dmtx && this_proj -> initgl)
88 {
89 if (this_proj -> modelgl -> rings)
90 {
91 this_proj -> modelgl -> rings = FALSE;
92 for (j=0; j<5; j++)
93 {
94 clean_rings_data (j, this_proj -> modelgl);
95#ifdef GTK3
96 update_rings_menus (this_proj -> modelgl);
97#endif
98 }
99 }
100 if (this_proj -> modelgl -> chains)
101 {
102 clean_chains_data (this_proj -> modelgl);
103#ifdef GTK3
104 update_chains_menus (this_proj -> modelgl);
105#endif
106 }
107 bonds_update = 1;
108 frag_update = (this_proj -> natomes > ATOM_LIMIT) ? 0 : 1;
109 mol_update = (frag_update) ? ((this_proj -> steps > STEP_LIMIT) ? 0 : 1) : 0;
110 this_proj -> runc[0] = FALSE;
111 if (this_proj -> id != activep)
112 {
113 k = activep;
114 active_project_changed (this_proj -> id);
115 on_calc_bonds_released (NULL, NULL);
117 }
118 else
119 {
120 update_project (this_proj -> id);
121 on_calc_bonds_released (NULL, NULL);
122 }
123 }
124}
125
134G_MODULE_EXPORT void set_cut (GtkEntry * res, gpointer data)
135{
136 const gchar * m;
137 int id = GPOINTER_TO_INT(data);
138 m = entry_get_text (res);
139 double v = atof(m);
140 if (v >= 0.0)
141 {
142 tmpcut[id] = (v < 0.5) ? 0.5 : v;
143 }
145}
146
155void cut_box (project * this_proj, GtkWidget * vbox)
156{
157 int i, j, k;
158 GtkWidget * vbo, * hbo, * cut;
159 gchar * str;
160
161 i = 1 + this_proj -> nspec * (this_proj -> nspec + 1) / 2;
162 j = (this_proj -> nspec > 4) ? 500 : i * 37;
163 GtkWidget * cutscroll = create_scroll (vbox, 350, j, GTK_SHADOW_NONE);
164 vbo = create_vbox (BSEP);
165 tmpcut = allocdouble (i);
166 k = 0;
167 for (i=0; i<this_proj -> nspec; i++, k++)
168 {
169 hbo = create_hbox (0);
170 gtk_widget_set_size_request (hbo, 250, -1);
171 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbo, hbo, FALSE, FALSE, 1);
172 str = g_strdup_printf ("%s - %s", exact_name(this_proj -> chemistry -> label[i]), exact_name(this_proj -> chemistry -> label[i]));
173 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
174 g_free (str);
175 cut = create_entry (G_CALLBACK(set_cut), 120, 15, FALSE, GINT_TO_POINTER(k));
176 update_entry_double (GTK_ENTRY(cut), this_proj -> chemistry -> cutoffs[i][i]);
177 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, cut, FALSE, FALSE, 0);
178 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label("&#xC5;", 30, -1, 0.0, 0.5), FALSE, FALSE, 5);
179 tmpcut[k] = this_proj -> chemistry -> cutoffs[i][i];
180 }
181 for (i=0; i<this_proj -> nspec-1; i++)
182 {
183 for (j=i+1; j<this_proj -> nspec; j++, k++)
184 {
185 hbo = create_hbox (0);
186 gtk_widget_set_size_request (hbo, 250, -1);
187 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbo, hbo, FALSE, FALSE, 1);
188 str = g_strdup_printf ("%s - %s", exact_name(this_proj -> chemistry -> label[i]), exact_name(this_proj -> chemistry -> label[j]));
189 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
190 g_free (str);
191 cut = create_entry (G_CALLBACK(set_cut), 120, 15, FALSE, (gpointer)GINT_TO_POINTER(k));
192 update_entry_double (GTK_ENTRY(cut), this_proj -> chemistry -> cutoffs[i][j]);
193 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, cut, FALSE, FALSE, 0);
194 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label("&#xC5;", 30, -1, 0.0, 0.5), FALSE, FALSE, 5);
195 tmpcut[k] = this_proj -> chemistry -> cutoffs[i][j];
196 }
197 }
198 hbo = create_hbox (0);
199 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbo, hbo, FALSE, FALSE, 1);
200 gtk_widget_set_size_request (hbo, 250, -1);
201 str = g_strdup_printf ("Total");
202 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label(str, 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
203 g_free (str);
204 cut = create_entry (G_CALLBACK(set_cut), 120, 15, FALSE, (gpointer)GINT_TO_POINTER(k));
205 update_entry_double (GTK_ENTRY(cut), this_proj -> chemistry -> grtotcutoff);
206 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, cut, FALSE, FALSE, 0);
207 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbo, markup_label("&#xC5;", 30, -1, 0.0, 0.5), FALSE, FALSE, 5);
208 tmpcut[k] = this_proj -> chemistry -> grtotcutoff;
209 add_container_child (CONTAINER_SCR, cutscroll, vbo);
210 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, markup_label("<b>Cutoff(s) must be &#8805; 0.5 &#xC5;</b>", -1, -1, 0.5, 0.5), FALSE, FALSE, 10);
211}
212
222G_MODULE_EXPORT void run_window_cuts (GtkDialog * win, gint response_id, gpointer data)
223{
224 if (response_id == GTK_RESPONSE_APPLY)
225 {
226 gboolean upc = FALSE;
227 if (opengl_project -> modelgl -> rings || opengl_project -> modelgl -> chains)
228 {
229 upc = ask_yes_no ("Data can be lost !", "You will lose\n rings statistics and/or chains statistics data\nProceed anyway ?", GTK_MESSAGE_WARNING, GTK_WIDGET(win));
230 }
231 else
232 {
233 upc = TRUE;
234 }
235 if (upc)
236 {
237 bonds_update = 1;
239#ifdef GTK3
240 gtk_menu_item_set_label (GTK_MENU_ITEM(opengl_project -> modelgl -> ogl_bonds[7]), label_cutrab (opengl_project, opengl_project -> modelgl, 0));
241#endif
242 }
243 }
245 if (tmpcut)
246 {
247 g_free (tmpcut);
248 tmpcut = NULL;
249 }
250}
251
252#ifdef GTK4
262G_MODULE_EXPORT void window_cuts (GSimpleAction * action, GVariant * parameter, gpointer data)
263#else
272G_MODULE_EXPORT void window_cuts (GtkWidget * widg, gpointer data)
273#endif
274{
275 tint * the_data = (tint *)data;
276 int p = the_data -> a;
278 gchar * str = g_strdup_printf ("Adjust cutoff radius(ii) - %s", prepare_for_title(opengl_project -> name));
279 GtkWidget * win = dialog_cancel_apply (str, opengl_project -> modelgl -> win, FALSE);
280 g_free (str);
282 run_this_gtk_dialog (win, G_CALLBACK(run_window_cuts), NULL);
283}
integer function chains()
Definition chains.F90:54
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
int mol_update
Definition global.c:171
int activep
Definition global.c:159
int frag_update
Definition global.c:170
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:471
int bonds_update
Definition global.c:169
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_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1294
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:613
void update_chains_menus(glwin *view)
#define ATOM_LIMIT
Atom number limit to compute fragment(s) and molecule(s) analysis automatically.
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1940
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:577
void clean_rings_data(int rid, glwin *view)
clean a ring type data for a glview
Definition ringscall.c:374
#define BSEP
Definition global.h:217
void opengl_project_changed(int id)
change the OpenGL project
Definition update_p.c:245
#define STEP_LIMIT
Definition global.h:249
G_MODULE_EXPORT void on_calc_bonds_released(GtkWidget *widg, gpointer data)
compute bonding properties
Definition bdcall.c:471
@ CONTAINER_SCR
Definition global.h:223
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 clean_chains_data(glwin *view)
cleaning the OpenGL data related to chain statistics
Definition chainscall.c:258
project * opengl_project
Definition project.c:54
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 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
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
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
void update_rings_menus(glwin *view)
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
action
Definition glview.h:189
Function declarations for the creation of the OpenGL window.
gboolean ask_yes_no(gchar *title, gchar *text, int type, GtkWidget *widg)
ask yes or no for something: prepare dialog
Definition interface.c:356
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:370
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
void active_project_changed(int id)
change the active project
Definition update_p.c:175
int update_project()
update project: send data to Fortran90, and update calculation interactors
Definition update_p.c:94
Definition glwin.h:875
Definition global.h:98
int a
Definition tab-1.c:95
G_MODULE_EXPORT void window_cuts(GtkWidget *widg, gpointer data)
adjust bond cutoffs window callback GTK3
Definition w_cutoffs.c:272
void update_cutoffs(project *this_proj)
update bond cutoffs
Definition w_cutoffs.c:59
void cut_box(project *this_proj, GtkWidget *vbox)
box cutoff entries
Definition w_cutoffs.c:155
double * tmpcut
Definition w_cutoffs.c:50
gchar * label_cutrab(project *this_proj, glwin *view, int id)
prepare the text of a menu item in the 'Model -> Bond(s)' submenu
Definition m_bonds.c:67
G_MODULE_EXPORT void set_cut(GtkEntry *res, gpointer data)
change cutoff entry callback
Definition w_cutoffs.c:134
G_MODULE_EXPORT void run_window_cuts(GtkDialog *win, gint response_id, gpointer data)
bond cutoffs window - running the dialog
Definition w_cutoffs.c:222
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * vbox
Definition workspace.c:72