atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
chainscall.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'chainscall.c'
24*
25* Contains:
26*
27
28 - The callbacks for the chains statistics calculation dialog
29
30*
31* List of functions:
32
33 void init_chain (project * this_proj);
34 void update_chains_menus (glwin * view);
35 void update_chains_view (project * this_proj);
36 void clean_chains_data (glwin * view);
37
38 G_MODULE_EXPORT void on_calc_chains_released (GtkWidget * widg, gpointer data);
39
40*/
41
42#ifdef HAVE_CONFIG_H
43# include <config.h>
44#endif
45
46#include <gtk/gtk.h>
47#include <string.h>
48#include <stdlib.h>
49
50#include "global.h"
51#include "bind.h"
52#include "interface.h"
53#include "callbacks.h"
54#include "project.h"
55#include "curve.h"
56#include "initcoord.h"
57#include "submenus.h"
58
59extern gboolean run_distance_matrix (GtkWidget * widg, int calc, int up_ngb);
60extern int update_voisj_and_contj ();
61extern void clean_coord_window (project * this_proj);
62
70void init_chain (project * this_proj)
71{
72 int i;
73 this_proj -> analysis[CHA] -> curves[0] -> name = g_strdup_printf (_("Chains - C<sub>c</sub>(n)[All]"));
74 for (i=0 ; i<this_proj -> nspec ; i++)
75 {
76 this_proj -> analysis[CHA] -> curves[i+1] -> name = g_strdup_printf (_("Chains - C<sub>c</sub>(n)[%s]"), active_chem -> label[i]);
77 }
78 add_curve_widgets (this_proj, CHA);
79 this_proj -> analysis[CHA] -> init_ok = TRUE;
80}
81
82#ifdef GTK3
90void update_chains_menus (glwin * view)
91{
92 GtkWidget * menu;
93 view -> ogl_chains[0] = destroy_this_widget (view -> ogl_chains[0]);
94 view -> ogl_chains[0] = menu_item_new_with_submenu (_("Chain(s)"), view -> chains, add_menu_coord (view, 0, 9));
95 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (view -> ogl_coord[0]));
96 if (GTK_IS_WIDGET(menu))
97 {
98 gtk_menu_shell_insert (GTK_MENU_SHELL(menu), view -> ogl_chains[0], 3);
99 show_the_widgets (view -> ogl_chains[0]);
100 }
101}
102#endif
103
111void update_chains_view (project * this_proj)
112{
113 int i, j, k, l;
114 gchar * nelt;
115 gchar * col;
116 gchar * tab;
117 gchar * cid;
118 gchar * str;
119 if (this_proj -> analysis[CHA] -> calc_buffer == NULL) this_proj -> analysis[CHA] -> calc_buffer = add_buffer (NULL, NULL, NULL);
120 view_buffer (this_proj -> analysis[CHA] -> calc_buffer);
121 j = this_proj -> csparam[0];
122 if (! j)
123 {
124 nelt = g_strdup_printf (_("All"));
125 col = NULL;
126 }
127 else
128 {
129 nelt = g_strdup_printf ("%s", this_proj -> chemistry -> label[j-1]);
130 col = g_strdup_printf("%s", textcolor(j-1));
131 }
132 print_info (_("\n\nChain statistics\n\n"), "heading", this_proj -> analysis[CHA] -> calc_buffer);
133
134 if (this_proj -> csparam[1])
135 {
136 print_info (_(" * only AAAA chains have been considered\n"), "italic", this_proj -> analysis[CHA] -> calc_buffer);
137 }
138 if (this_proj -> csparam[2])
139 {
140 print_info (_(" * only ABAB chains have been considered\n"), "italic", this_proj -> analysis[CHA] -> calc_buffer);
141 }
142 if (this_proj -> csparam[3])
143 {
144 print_info (_(" * homopolar bonds can not shorten the chains\n"), "italic", this_proj -> analysis[CHA] -> calc_buffer);
145 }
146 if (this_proj -> csparam[4])
147 {
148 print_info (_(" * only 1-(2)"), "italic", this_proj -> analysis[CHA] -> calc_buffer);
149 print_info ("n", "sub_italic", this_proj -> analysis[CHA] -> calc_buffer);
150 print_info (_("-1 chains have been considered, ie. isolated chains\n"), "italic", this_proj -> analysis[CHA] -> calc_buffer);
151 }
152 print_info (_("\n Atom(s) used to start the search: "), NULL, this_proj -> analysis[CHA] -> calc_buffer);
153 print_info (nelt, col, this_proj -> analysis[CHA] -> calc_buffer);
154 if (j != 0) print_info (_(" atom(s) only"), NULL, this_proj -> analysis[CHA] -> calc_buffer);
155
156 if (this_proj -> steps > 1)
157 {
158 print_info (_("\n Average number of chains per configuration: "), NULL, this_proj -> analysis[CHA] -> calc_buffer);
159 str = g_strdup_printf ("%f", this_proj -> csdata[0]);
160 print_info (str, "bold", this_proj -> analysis[CHA] -> calc_buffer);
161 g_free (str);
162 str = g_strdup_printf (" +/- %f\n", this_proj -> csdata[1]);
163 print_info (str, "bold", this_proj -> analysis[CHA] -> calc_buffer);
164 g_free (str);
165 }
166 else
167 {
168 print_info (_("\n Total number of chains: "), NULL, this_proj -> analysis[CHA] -> calc_buffer);
169 str = g_strdup_printf ("%f\n", this_proj -> csdata[0]);
170 print_info (str, "bold", this_proj -> analysis[CHA] -> calc_buffer);
171 g_free (str);
172 }
173
174 if (this_proj -> steps > 1)
175 {
176 print_info (_("\n\t n Av. by step \tC"), "bold", this_proj -> analysis[CHA] -> calc_buffer);
177 print_info ("c", "sub_bold", this_proj -> analysis[CHA] -> calc_buffer);
178 print_info ("(n)[", "bold", this_proj -> analysis[CHA] -> calc_buffer);
179 print_info (nelt, col, this_proj -> analysis[CHA] -> calc_buffer);
180 if (j == this_proj -> nspec)
181 {
182 print_info ("]\t +/-\n", "bold", this_proj -> analysis[CHA] -> calc_buffer);
183 }
184 else
185 {
186 print_info ("]\t +/-\n", "bold", this_proj -> analysis[CHA] -> calc_buffer);
187 }
188 }
189 else
190 {
191 print_info (_("\n\t n\tNumber\t\tC"), "bold", this_proj -> analysis[CHA] -> calc_buffer);
192 print_info ("c", "sub_bold", this_proj -> analysis[CHA] -> calc_buffer);
193 print_info ("(n)[", "bold", this_proj -> analysis[CHA] -> calc_buffer);
194 print_info (nelt, col, this_proj -> analysis[CHA] -> calc_buffer);
195 print_info ("]\n", NULL, this_proj -> analysis[CHA] -> calc_buffer);
196 }
197 tab = NULL;
198 cid = NULL;
199 k = this_proj -> csparam[0];
200 l = (! k) ? this_proj -> natomes : this_proj -> chemistry -> nsps[k-1];
201 j = 1;
202 for ( i=1 ; i < this_proj -> csparam[5] ; i++ )
203 {
204 if (this_proj -> analysis[CHA] -> curves[k] -> data[1][i] != 0.0)
205 {
206 j ++;
207 if (j - 2*(j/2) == 0)
208 {
209 tab = g_strdup_printf ("grey_back");
210 cid = g_strdup_printf ("bold_grey_back");
211 }
212 else
213 {
214 tab = NULL;
215 cid = g_strdup_printf ("bold");
216 }
217 print_info ("\t", NULL, this_proj -> analysis[CHA] -> calc_buffer);
218 if (i < 9)
219 {
220 print_info (" ",cid, this_proj -> analysis[CHA] -> calc_buffer);
221 }
222 str = g_strdup_printf("%d", i+1);
223 print_info (str, cid, this_proj -> analysis[CHA] -> calc_buffer);
224 g_free (str);
225 str = g_strdup_printf("\t%f\t", l*this_proj -> analysis[CHA] -> curves[k] -> data[1][i]);
226 print_info (str, tab, this_proj -> analysis[CHA] -> calc_buffer);
227 g_free (str);
228 str = g_strdup_printf("%f\t", this_proj -> analysis[CHA] -> curves[k] -> data[1][i]);
229 print_info (str, tab, this_proj -> analysis[CHA] -> calc_buffer);
230 g_free (str);
231 if (this_proj -> steps > 1)
232 {
233 str = g_strdup_printf("%f\t", this_proj -> analysis[CHA] -> curves[k] -> err[i]);
234 print_info (str, tab, this_proj -> analysis[CHA] -> calc_buffer);
235 g_free (str);
236 }
237 print_info ("\n", NULL, this_proj -> analysis[CHA] -> calc_buffer);
238 if (tab != NULL)
239 {
240 g_free (tab);
241 }
242 if (cid != NULL)
243 {
244 g_free (cid);
245 }
246 }
247 }
248 print_info (calculation_time(TRUE, this_proj -> analysis[CHA] -> calc_time), NULL, this_proj -> analysis[CHA] -> calc_buffer);
249 g_free (nelt);
250 if (col != NULL)
251 {
252 g_free (col);
253 }
254}
255
264{
265 project * this_proj = get_project_by_id(view -> proj);
266 if (this_proj -> coord -> totcoord[9])
267 {
268 if (this_proj -> coord -> ntg[9]) g_free (this_proj -> coord -> ntg[9]);
269 this_proj -> coord -> ntg[9] = NULL;
270 if (this_proj -> coord -> geolist[9][0]) g_free (this_proj -> coord -> geolist[9][0]);
271 this_proj -> coord -> geolist[9][0] = NULL;
272 this_proj -> coord -> totcoord[9] = 0;
273 }
274 if (view -> all_chains) g_free (view -> all_chains);
275 view -> all_chains = NULL;
276 if (view -> num_chains) g_free (view -> num_chains);
277 view -> num_chains = NULL;
278 if (view -> gcid[9]) g_free (view -> gcid[9]);
279 view -> gcid[9] = NULL;
280 view -> chains = FALSE;
281 view -> chain_max = 0;
282 int i, j;
283 for (i=0; i<this_proj -> steps; i++)
284 {
285 for (j=0; j<this_proj -> natomes; j++)
286 {
287 if (this_proj -> atoms[i][j].chain)
288 {
289 g_free (this_proj -> atoms[i][j].chain);
290 this_proj -> atoms[i][j].chain = NULL;
291 }
292 }
293 }
294}
295
304G_MODULE_EXPORT void on_calc_chains_released (GtkWidget * widg, gpointer data)
305{
306 int j, k;
307
308 cutoffsend ();
309 //if (active_project -> steps > 1) statusb = 1;
310
311 if (! active_project -> analysis[CHA] -> init_ok) init_chain (active_project);
312 active_project -> csparam[6] = 0;
313 if (! run_distance_matrix (widg, 6, 0))
314 {
315 show_error (_("The nearest neighbors table calculation has failed"), 0, widg);
316 }
317 else
318 {
319 clean_curves_data (CHA, active_project -> csparam[0], active_project -> csparam[0]+1);
321 active_glwin -> all_chains = g_malloc0(active_project -> steps*sizeof*active_glwin -> all_chains);
322 active_glwin -> num_chains = g_malloc0(active_project -> steps*sizeof*active_glwin -> num_chains);
323 for (j=0; j<active_project -> steps; j++)
324 {
325 active_glwin -> all_chains[j] = g_malloc0(active_project -> csparam[5]*sizeof*active_glwin -> all_chains[j]);
326 active_glwin -> num_chains[j] = allocint (active_project -> csparam[5]);
327 for (k=0; k < active_project -> natomes; k++)
328 {
329 if (active_project -> atoms[j][k].chain) g_free (active_project -> atoms[j][k].chain);
330 active_project -> atoms[j][k].chain = NULL;
331 active_project -> atoms[j][k].chain = g_malloc0(active_project -> csparam[5]*sizeof*active_project -> atoms[j][k].chain);
332 }
333 }
334 k = 1;
335 prepostcalc (widg, FALSE, CHA, 0, opac);
336 j = initchains_ (& active_project -> csparam[0],
337 & active_project -> csparam[1],
338 & active_project -> csparam[2],
339 & active_project -> csparam[3],
340 & active_project -> csparam[4],
341 & active_project -> csparam[5],
343 prepostcalc (widg, TRUE, CHA, (j == 1) ? 1 : 0, 1.0);
344 if (j == 0)
345 {
346 show_error (_("The chain statistics calculation has failed"), 0, widg);
347 }
348 else if (j == 2)
349 {
350 gchar * str = g_strdup_printf (_("\t<b>The chain statistics have failed !</b>\n\n"
351 "The number of chain per MD step appears\n"
352 "to be bigger than the initial value of <b>%d</b>\n"
353 "used to allocate memory to store the results.\n\n"
354 "Increase the value and start again !"),
356 show_error (str, 0, widg);
357 g_free (str);
358 j = 0;
359 }
360 }
361
362 if (j == 1)
363 {
364 active_project -> csparam[6] = 1;
365 active_glwin -> chains = TRUE;
366 active_glwin -> chain_max = active_project -> csparam[5];
368 }
373#ifdef GTK3
375#endif
376}
377
388void save_chains_data_ (int * taille, double ectrc[* taille], double * rpstep, double * ectrpst)
389{
390 int i;
391 active_project -> csdata[0] = * rpstep;
392 active_project -> csdata[1] = * ectrpst;
393 i = active_project -> csparam[0];
394 active_project -> analysis[CHA] -> curves[i] -> err = duplicate_double (* taille, ectrc);
395}
gboolean run_distance_matrix(GtkWidget *widg, int calc, int up_ngb)
compute distance matrix
Definition bdcall.c:372
Binding to the Fortran90 subroutines.
void free_contj_voisj_()
int initchains_(int *, int *, int *, int *, int *, int *, int *)
Callback declarations for main window.
void fill_tool_model()
fill the tool window tree model
Definition tools.c:91
integer function chains()
Definition chains.F90:54
void init_chain(project *this_proj)
initialize the curve widgets for the chains statistics calculation
Definition chainscall.c:70
void update_chains_view(project *this_proj)
update the chains statistics text view after the calculation
Definition chainscall.c:111
void clean_coord_window(project *this_proj)
update the environment configuration window after edtion
Definition atom_edit.c:87
G_MODULE_EXPORT void on_calc_chains_released(GtkWidget *widg, gpointer data)
compute chains statistics
Definition chainscall.c:304
void clean_chains_data(glwin *view)
cleaning the OpenGL data related to chain statistics
Definition chainscall.c:263
void save_chains_data_(int *taille, double ectrc[*taille], double *rpstep, double *ectrpst)
get chains statistics results form Fortran90
Definition chainscall.c:388
int update_voisj_and_contj()
update FORTRAN CONTJ and VOISJ for the active project
Definition bdcall.c:531
gboolean run_distance_matrix(GtkWidget *widg, int calc, int up_ngb)
compute distance matrix
Definition bdcall.c:372
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
Variable declarations for the curve widget Functions for interactions with the curve widget.
void add_curve_widgets(project *this_proj, int rid)
add curve widgets to the project
Definition cwidget.c:283
void clean_curves_data(int calc, int start, int end)
clean curve data on a range of curve id
Definition initc.c:61
ColRGBA col
Definition d_measures.c:77
int atoms[NUM_STYLES][2]
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:595
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:643
double opac
Definition global.c:201
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
GtkWidget * curvetoolbox
Definition global.c:211
Global variable declarations Global convenience function declarations Global data structure defin...
glwin * active_glwin
Definition project.c:53
void update_chains_menus(glwin *view)
GtkTextBuffer * add_buffer(GCallback handler, gpointer data, gchar *text)
create a GtkTextBuffer
Definition gtk-misc.c:1258
project * proj
chemical_data * active_chem
Definition project.c:48
#define CHA
Definition global.h:344
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
void cutoffsend()
send cutoffs to Fortran90
Definition bdcall.c:293
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
project * active_project
Definition project.c:47
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void view_buffer(GtkTextBuffer *buffer)
set a text buffer in the main window or an image
Definition gui.c:311
void prepostcalc(GtkWidget *widg, gboolean status, int run, int adv, double opc)
to just before and just after running a calculation
Definition initc.c:87
Function declarations to handle the atomic coordination data.
gchar * textcolor(int i)
setup text color keyword
Definition interface.c:893
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
void print_info(gchar *str, gchar *stag, GtkTextBuffer *buffer)
print information in GtkTextBuffer
Definition interface.c:869
Messaging function declarations.
GMenu * add_menu_coord(glwin *view, int popm, int id)
create a coordination type submenu
Definition m_coord.c:652
Function declarations for reading atomes project file Function declarations for saving atomes proje...
Definition glwin.h:967
Function declarations for the creation of the OpenGL window menus.
atom_search * csearch
Definition w_search.c:2719