atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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 initchn ();
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 void clean_coord_window (project * this_proj);
61
67void initchn ()
68{
69 int i;
70 active_project -> curves[CH][0] -> name = g_strdup_printf ("Chains - Cc(n)[All]");
71 for (i=0 ; i<active_project -> nspec ; i++)
72 {
73 active_project -> curves[CH][i+1] -> name = g_strdup_printf ("Chains - Cc(n)[%s]", active_chem -> label[i]);
74 }
76 active_project -> initok[CH] = TRUE;
77}
78
79#ifdef GTK3
87void update_chains_menus (glwin * view)
88{
89 GtkWidget * menu;
90 view -> ogl_chains[0] = destroy_this_widget (view -> ogl_chains[0]);
91 view -> ogl_chains[0] = menu_item_new_with_submenu ("Chain(s)", view -> chains, add_menu_coord (view, 0, 9));
92 menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (view -> ogl_coord[0]));
93 if (GTK_IS_WIDGET(menu))
94 {
95 gtk_menu_shell_insert (GTK_MENU_SHELL(menu), view -> ogl_chains[0], 3);
96 show_the_widgets (view -> ogl_chains[0]);
97 }
98}
99#endif
100
108void update_chains_view (project * this_proj)
109{
110 int i, j, k, l;
111 gchar * nelt;
112 gchar * col;
113 gchar * tab;
114 gchar * cid;
115 gchar * str;
116
117 if (this_proj -> text_buffer[CH+OT] == NULL) this_proj -> text_buffer[CH+OT] = add_buffer (NULL, NULL, NULL);
118 view_buffer (this_proj -> text_buffer[CH+OT]);
119 j = this_proj -> csparam[0];
120 if (! j)
121 {
122 nelt = g_strdup_printf ("All");
123 col = NULL;
124 }
125 else
126 {
127 nelt = g_strdup_printf ("%s", this_proj -> chemistry -> label[j-1]);
128 col = textcolor(j-1);
129 }
130 print_info ("\n\nChain statistics\n\n", "heading", this_proj -> text_buffer[CH+OT]);
131
132
133 if (this_proj -> csparam[1])
134 {
135 print_info (" * only AAAA chains have been considered\n", "italic", this_proj -> text_buffer[CH+OT]);
136 }
137 if (this_proj -> csparam[2])
138 {
139 print_info (" * only ABAB chains have been considered\n", "italic", this_proj -> text_buffer[CH+OT]);
140 }
141 if (this_proj -> csparam[3])
142 {
143 print_info (" * homopolar bonds can not shorten the chains\n", "italic", this_proj -> text_buffer[CH+OT]);
144 }
145 if (this_proj -> csparam[4])
146 {
147 print_info (" * only 1-(2)", "italic", this_proj -> text_buffer[CH+OT]);
148 print_info ("n", "sub_italic", this_proj -> text_buffer[CH+OT]);
149 print_info ("-1 chains have been considered, ie. isolated chains\n", "italic", this_proj -> text_buffer[CH+OT]);
150 }
151 print_info ("\n Atom(s) used to start the search: ", NULL, this_proj -> text_buffer[CH+OT]);
152 print_info (nelt, col, this_proj -> text_buffer[CH+OT]);
153 if (j != 0) print_info (" atom(s) only", NULL, this_proj -> text_buffer[CH+OT]);
154
155 if (this_proj -> steps > 1)
156 {
157 print_info ("\n Average number of chains per configuration: ", NULL, this_proj -> text_buffer[CH+OT]);
158 str = g_strdup_printf ("%f", this_proj -> csdata[0]);
159 print_info (str, "bold", this_proj -> text_buffer[CH+OT]);
160 g_free (str);
161 str = g_strdup_printf (" +/- %f\n", this_proj -> csdata[1]);
162 print_info (str, "bold", this_proj -> text_buffer[CH+OT]);
163 g_free (str);
164 }
165 else
166 {
167 print_info ("\n Total number of chains: ", NULL, this_proj -> text_buffer[CH+OT]);
168 str = g_strdup_printf ("%f\n", this_proj -> csdata[0]);
169 print_info (str, "bold", this_proj -> text_buffer[CH+OT]);
170 g_free (str);
171 }
172
173 if (this_proj -> steps > 1)
174 {
175 print_info ("\n\t n Av. by step \tCc(n)[", "bold", this_proj -> text_buffer[CH+OT]);
176 print_info (nelt, col, this_proj -> text_buffer[CH+OT]);
177 if (j == this_proj -> nspec)
178 {
179 print_info ("]\t +/-\n", "bold", this_proj -> text_buffer[CH+OT]);
180 }
181 else
182 {
183 print_info ("]\t +/-\n", "bold", this_proj -> text_buffer[CH+OT]);
184 }
185 }
186 else
187 {
188 print_info ("\n\t n\tNumber\t\tCc(n)[", "bold", this_proj -> text_buffer[CH+OT]);
189 print_info (nelt, col, this_proj -> text_buffer[CH+OT]);
190 print_info ("]\n", NULL, this_proj -> text_buffer[CH+OT]);
191 }
192 tab = NULL;
193 cid = NULL;
194 k = this_proj -> csparam[0];
195 l = (! k) ? this_proj -> natomes : this_proj -> chemistry -> nsps[k-1];
196 j = 1;
197 for ( i=1 ; i < this_proj -> csparam[5] ; i++ )
198 {
199 if (this_proj -> curves[CH][k] -> data[1][i] != 0.0)
200 {
201 j ++;
202 if (j - 2*(j/2) == 0)
203 {
204 tab = g_strdup_printf ("grey_back");
205 cid = g_strdup_printf ("bold_grey_back");
206 }
207 else
208 {
209 tab = NULL;
210 cid = g_strdup_printf ("bold");
211 }
212 print_info ("\t", NULL, this_proj -> text_buffer[CH+OT]);
213 if (i < 9)
214 {
215 print_info (" ",cid, this_proj -> text_buffer[CH+OT]);
216 }
217 str = g_strdup_printf("%d", i+1);
218 print_info (str, cid, this_proj -> text_buffer[CH+OT]);
219 g_free (str);
220 str = g_strdup_printf("\t%f\t", l*this_proj -> curves[CH][k] -> data[1][i]);
221 print_info (str, tab, this_proj -> text_buffer[CH+OT]);
222 g_free (str);
223 str = g_strdup_printf("%f\t", this_proj -> curves[CH][k] -> data[1][i]);
224 print_info (str, tab, this_proj -> text_buffer[CH+OT]);
225 g_free (str);
226 if (this_proj -> steps > 1)
227 {
228 str = g_strdup_printf("%f\t", this_proj -> curves[CH][k] -> err[i]);
229 print_info (str, tab, this_proj -> text_buffer[CH+OT]);
230 g_free (str);
231 }
232 print_info ("\n", NULL, this_proj -> text_buffer[CH+OT]);
233 if (tab != NULL)
234 {
235 g_free (tab);
236 }
237 if (cid != NULL)
238 {
239 g_free (cid);
240 }
241 }
242 }
243 print_info (calculation_time(TRUE, this_proj -> calc_time[CH]), NULL, this_proj -> text_buffer[CH+OT]);
244 g_free (nelt);
245 if (col != NULL)
246 {
247 g_free (col);
248 }
249}
250
259{
260 project * this_proj = get_project_by_id(view -> proj);
261 if (this_proj -> coord -> totcoord[9])
262 {
263 if (this_proj -> coord -> ntg[9]) g_free (this_proj -> coord -> ntg[9]);
264 this_proj -> coord -> ntg[9] = NULL;
265 if (this_proj -> coord -> geolist[9][0]) g_free (this_proj -> coord -> geolist[9][0]);
266 this_proj -> coord -> geolist[9][0] = NULL;
267 this_proj -> coord -> totcoord[9] = 0;
268 }
269 if (view -> all_chains) g_free (view -> all_chains);
270 view -> all_chains = NULL;
271 if (view -> num_chains) g_free (view -> num_chains);
272 view -> num_chains = NULL;
273 if (view -> gcid[9]) g_free (view -> gcid[9]);
274 view -> gcid[9] = NULL;
275 view -> chains = FALSE;
276 view -> chain_max = 0;
277 int i, j;
278 for (i=0; i<this_proj -> steps; i++)
279 {
280 for (j=0; j<this_proj -> natomes; j++)
281 {
282 if (this_proj -> atoms[i][j].chain)
283 {
284 g_free (this_proj -> atoms[i][j].chain);
285 this_proj -> atoms[i][j].chain = NULL;
286 }
287 }
288 }
289}
290
299G_MODULE_EXPORT void on_calc_chains_released (GtkWidget * widg, gpointer data)
300{
301 int j, k;
302
303 cutoffsend ();
304 //if (active_project -> steps > 1) statusb = 1;
305 if (! active_project -> initok[CH]) initchn ();
306 active_project -> csparam[6] = 0;
307 if (! active_project -> dmtx) active_project -> dmtx = run_distance_matrix (widg, 6, 0);
308
309 if (active_project -> dmtx)
310 {
311 clean_curves_data (CH, 0, active_project -> numc[CH]);
313 active_glwin -> all_chains = g_malloc0 (active_project -> steps*sizeof*active_glwin -> all_chains);
314 active_glwin -> num_chains = g_malloc0 (active_project -> steps*sizeof*active_glwin -> num_chains);
315 for (j=0; j<active_project -> steps; j++)
316 {
317 active_glwin -> all_chains[j] = g_malloc0 (active_project -> csparam[5]*sizeof*active_glwin -> all_chains[j]);
318 active_glwin -> num_chains[j] = allocint (active_project -> csparam[5]);
319 for (k=0; k < active_project -> natomes; k++)
320 {
321 if (active_project -> atoms[j][k].chain) g_free (active_project -> atoms[j][k].chain);
322 active_project -> atoms[j][k].chain = NULL;
323 active_project -> atoms[j][k].chain = g_malloc0 (active_project -> csparam[5]*sizeof*active_project -> atoms[j][k].chain);
324 }
325 }
326 k = 1;
327 prepostcalc (widg, FALSE, CH, 0, opac);
328 clock_gettime (CLOCK_MONOTONIC, & start_time);
329 j = initchains_ (& active_project -> csparam[0],
330 & active_project -> csparam[1],
331 & active_project -> csparam[2],
332 & active_project -> csparam[3],
333 & active_project -> csparam[4],
334 & active_project -> csparam[5],
336 clock_gettime (CLOCK_MONOTONIC, & stop_time);
338 if (j == 0)
339 {
340 show_error ("The chain statistics calculation has failed", 0, widg);
341 }
342 else if (j == 2)
343 {
344 gchar * str = g_strdup_printf ("\t<b>The chain statistics have failed !</b>\n\n"
345 "The number of chain per MD step appears\n"
346 "to be bigger than the initial value of <b>%d</b>\n"
347 "used to allocate memory to store the results.\n\n"
348 "Increase the value and start again !",
350 show_error (str, 0, widg);
351 g_free (str);
352 j = 0;
353 }
354 prepostcalc (widg, TRUE, CH, j, 1.0);
355 }
356 else
357 {
358 show_error ("The nearest neighbors table calculation has failed", 0, widg);
359 }
360 if (active_coord -> totcoord[9])
361 {
362 active_project -> csparam[6] = 1;
363 active_glwin -> chains = TRUE;
364 active_glwin -> chain_max = active_project -> csparam[5];
366 }
370#ifdef GTK3
372#endif
373}
374
385void save_chains_data_ (int * taille, double ectrc[* taille], double * rpstep, double * ectrpst)
386{
387 int i;
388 active_project -> csdata[0] = * rpstep;
389 active_project -> csdata[1] = * ectrpst;
390 i = active_project -> csparam[0];
391 active_project -> curves[CH][i] -> err = duplicate_double (* taille, ectrc);
392}
Binding to the Fortran90 subroutines.
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:87
integer function chains()
Definition chains.F90:54
void update_chains_view(project *this_proj)
update the chains statistics text view after the calculation
Definition chainscall.c:108
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:299
void clean_chains_data(glwin *view)
cleaning the OpenGL data related to chain statistics
Definition chainscall.c:258
void save_chains_data_(int *taille, double ectrc[*taille], double *rpstep, double *ectrpst)
get chains statistics results form Fortran90
Definition chainscall.c:385
void initchn()
initialize the curve widgets for the chains statistics calculation
Definition chainscall.c:67
gboolean run_distance_matrix(GtkWidget *widg, int calc, int up_ngb)
compute distance matrix
Definition bdcall.c:310
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
Variable declarations for the curve widget Functions for interactions with the curve widget.
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
void addcurwidgets(int pid, int rid, int st)
add curve widgets to the project
Definition cwidget.c:259
void clean_curves_data(int calc, int start, int end)
clean curve data on a range of curve id
Definition initc.c:55
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:608
struct timespec start_time
Definition global.c:191
int activep
Definition global.c:159
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:656
double opac
Definition global.c:194
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:643
struct timespec stop_time
Definition global.c:192
GtkWidget * curvetoolbox
Definition global.c:205
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:1171
coord_info * active_coord
Definition project.c:49
project * proj
chemical_data * active_chem
Definition project.c:48
#define OT
Definition global.h:321
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
void cutoffsend()
send cutoffs to Fortran90
Definition bdcall.c:243
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
project * active_project
Definition project.c:47
#define CH
Definition global.h:329
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
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:309
void prepostcalc(GtkWidget *widg, gboolean status, int run, int adv, double opc)
to just before and just after running a calculation
Definition initc.c:154
Function declarations to handle the atomic coordination data.
gchar * textcolor(int i)
setup text color keyword
Definition interface.c:763
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
void print_info(gchar *str, gchar *stag, GtkTextBuffer *buffer)
print information in GtkTextBuffer
Definition interface.c:738
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:875
Function declarations for the creation of the OpenGL window menus.
atom_search * csearch
Definition w_search.c:2718