atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
grcall.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: 'grcall.c'
24*
25* Contains:
26*
27
28 - The callbacks for the g(r)/g(k) calculation dialog
29
30*
31* List of functions:
32
33 int recup_data_ (int * cd, int * rd);
34
35 void init_gr (project * this_proj, int rdf);
36 void update_rdf_view (project * this_proj, int rdf);
37 void sendcutoffs_ (int * nc, double * totc, double partc[* nc][* nc]);
38
39 G_MODULE_EXPORT void on_calc_gr_released (GtkWidget * widg, gpointer data);
40 G_MODULE_EXPORT void on_cutcheck_toggled (GtkToggleButton * Button);
41 G_MODULE_EXPORT void on_calc_gq_released (GtkWidget * widg, gpointer data);
42
43*/
44
45#include <gtk/gtk.h>
46#include <string.h>
47#include <stdlib.h>
48
49#include "global.h"
50#include "curve.h"
51#include "bind.h"
52#include "interface.h"
53#include "callbacks.h"
54#include "project.h"
55
56int fitc = 0;
57
66void init_gr (project * this_proj, int rdf)
67{
68 int i, j, k;
69 this_proj -> analysis[rdf] -> curves[0] -> name = g_strdup_printf ("g(r) %s", _("Neutrons"));
70 this_proj -> analysis[rdf] -> curves[1] -> name = g_strdup_printf ("g(r) %s - %s", _("Neutrons"), _("smoothed"));
71 this_proj -> analysis[rdf] -> curves[2] -> name = g_strdup_printf ("G(r) %s", _("Neutrons"));
72 this_proj -> analysis[rdf] -> curves[3] -> name = g_strdup_printf ("G(r) %s - %s", _("Neutrons"), _("smoothed"));
73 this_proj -> analysis[rdf] -> curves[4] -> name = g_strdup_printf ("D(r) %s", _("Neutrons"));
74 this_proj -> analysis[rdf] -> curves[5] -> name = g_strdup_printf ("D(r) %s - %s", _("Neutrons"), _("smoothed"));
75 this_proj -> analysis[rdf] -> curves[6] -> name = g_strdup_printf ("T(r) %s", _("Neutrons"));
76 this_proj -> analysis[rdf] -> curves[7] -> name = g_strdup_printf ("T(r) %s - %s", _("Neutrons"), _("smoothed"));
77 this_proj -> analysis[rdf] -> curves[8] -> name = g_strdup_printf ("g(r) %s", _("X-rays"));
78 this_proj -> analysis[rdf] -> curves[9] -> name = g_strdup_printf ("g(r) %s - %s", _("X-rays"), _("smoothed"));
79 this_proj -> analysis[rdf] -> curves[10] -> name = g_strdup_printf ("G(r) %s", _("X-rays"));
80 this_proj -> analysis[rdf] -> curves[11] -> name = g_strdup_printf ("G(r) %s - %s", _("X-rays"), _("smoothed"));
81 this_proj -> analysis[rdf] -> curves[12] -> name = g_strdup_printf ("D(r) %s", _("X-rays"));
82 this_proj -> analysis[rdf] -> curves[13] -> name = g_strdup_printf ("D(r) %s - %s", _("X-rays"), _("smoothed"));
83 this_proj -> analysis[rdf] -> curves[14] -> name = g_strdup_printf ("T(r) %s", _("X-rays"));
84 this_proj -> analysis[rdf] -> curves[15] -> name = g_strdup_printf ("T(r) %s - %s", _("X-rays"), _("smoothed"));
85 k = 16;
86 for ( i = 0 ; i < this_proj -> nspec ; i++ )
87 {
88 for ( j = 0 ; j < this_proj -> nspec ; j++ )
89 {
90 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf ("g(r)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
91 k=k+1;
92 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf ("g(r)[%s,%s] - %s", active_chem -> label[i], active_chem -> label[j], _("smoothed"));
93 k=k+1;
94 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf ("G(r)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
95 k=k+1;
96 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf ("G(r)[%s,%s] - %s", active_chem -> label[i], active_chem -> label[j], _("smoothed"));
97 k=k+1;
98 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf ("dn(r)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
99 k=k+1;
100 }
101 }
102 if ( this_proj -> nspec == 2 )
103 {
104 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf("BT(r)[NN]");
105 k=k+1;
106 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf("BT(r)[NN] - %s", _("smoothed"));
107 k=k+1;
108 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf("BT(r)[NC]");
109 k=k+1;
110 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf("BT(r)[NC] - %s", _("smoothed"));
111 k=k+1;
112 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf("BT(r)[CC]");
113 k=k+1;
114 this_proj -> analysis[rdf] -> curves[k] -> name = g_strdup_printf("BT(r)[CC] - %s", _("smoothed"));
115 }
116 add_curve_widgets (this_proj, rdf);
117 this_proj -> analysis[rdf] -> init_ok = TRUE;
118}
119
128void update_rdf_view (project * this_proj, int rdf)
129{
130 gchar * str;
131 if (this_proj -> analysis[rdf] -> calc_buffer == NULL) this_proj -> analysis[rdf] -> calc_buffer = add_buffer (NULL, NULL, NULL);
132 view_buffer (this_proj -> analysis[rdf] -> calc_buffer);
133 print_info (_("\n\nRadial distribution function(s)"), "heading", this_proj -> analysis[rdf] -> calc_buffer);
134 if (rdf == GDR)
135 {
136 print_info (_(" - real space calculation\n\n"), "heading", this_proj -> analysis[rdf] -> calc_buffer);
137 }
138 else
139 {
140 print_info (_(" - FFT[S(q)]\n\n"), "heading", this_proj -> analysis[rdf] -> calc_buffer);
141 }
142 print_info (_("Calculation details:\n\n"), NULL, this_proj -> analysis[rdf] -> calc_buffer);
143
144 if (rdf == GDK)
145 {
146 print_info (_("\tReciprocal space data:\n\n"), NULL, this_proj -> analysis[rdf] -> calc_buffer);
147 print_info (_("\t - Minimum vector Q"), "bold", this_proj -> analysis[rdf] -> calc_buffer);
148 print_info ("min", "sub_bold", this_proj -> analysis[rdf] -> calc_buffer);
149 print_info (": ", "bold", this_proj -> analysis[rdf] -> calc_buffer);
150 str = g_strdup_printf ("%f", this_proj -> analysis[SKD] -> min);
151 print_info (str, "bold_red", this_proj -> analysis[rdf] -> calc_buffer);
152 g_free (str);
153 print_info (" Å", "bold", this_proj -> analysis[rdf] -> calc_buffer);
154 print_info ("-1", "sup_bold", this_proj -> analysis[rdf] -> calc_buffer);
155 print_info (_("\n\t - Maximum vector Q"), "bold", this_proj -> analysis[rdf] -> calc_buffer);
156 print_info ("max", "sub_bold", this_proj -> analysis[rdf] -> calc_buffer);
157 print_info (_(" for the FFT: "), "bold", this_proj -> analysis[rdf] -> calc_buffer);
158 str = g_strdup_printf ("%f", this_proj -> analysis[rdf] -> max);
159 print_info (str, "bold_red", this_proj -> analysis[rdf] -> calc_buffer);
160 g_free (str);
161 print_info (" Å", "bold", this_proj -> analysis[rdf] -> calc_buffer);
162 print_info ("-1", "sup_bold", this_proj -> analysis[rdf] -> calc_buffer);
163 print_info ("\n\n", NULL, this_proj -> analysis[rdf] -> calc_buffer);
164 }
165 print_info (_("\tReal space discretization:\n\n"), NULL, this_proj -> analysis[rdf] -> calc_buffer);
166 print_info (_("\t - Number of δr steps: "), "bold", this_proj -> analysis[rdf] -> calc_buffer);
167 str = g_strdup_printf ("%d", this_proj -> analysis[rdf] -> num_delta);
168 print_info (str, "bold_blue", this_proj -> analysis[rdf] -> calc_buffer);
169 g_free (str);
170 print_info (_("\n\n\t between 0.0 and "), NULL, this_proj -> analysis[rdf] -> calc_buffer);
171 print_info ("D", "bold", this_proj -> analysis[rdf] -> calc_buffer);
172 print_info ("max", "sub_bold", this_proj -> analysis[rdf] -> calc_buffer);
173 print_info (_("\n\t where "), NULL, this_proj -> analysis[rdf] -> calc_buffer);
174 print_info ("D", "bold", this_proj -> analysis[rdf] -> calc_buffer);
175 print_info ("max", "sub_bold", this_proj -> analysis[rdf] -> calc_buffer);
176 print_info (_(" is the maximum distance in real space, "), NULL, this_proj -> analysis[rdf] -> calc_buffer);
177 print_info ("D", "bold", this_proj -> analysis[rdf] -> calc_buffer);
178 print_info ("max", "sub_bold", this_proj -> analysis[rdf] -> calc_buffer);
179 print_info (" = ", NULL, this_proj -> analysis[rdf] -> calc_buffer);
180 str = g_strdup_printf ("%f", this_proj -> analysis[rdf] -> max);
181 print_info (str, "bold_blue", this_proj -> analysis[rdf] -> calc_buffer);
182 g_free (str);
183 print_info (" Å\n\n\t - δr = ", "bold", this_proj -> analysis[rdf] -> calc_buffer);
184 str = g_strdup_printf ("%f", this_proj -> analysis[rdf] -> delta);
185 print_info (str, "bold_blue", this_proj -> analysis[rdf] -> calc_buffer);
186 g_free (str);
187 print_info (" Å\n", "bold", this_proj -> analysis[rdf] -> calc_buffer);
188 print_info (calculation_time(TRUE, this_proj -> analysis[rdf] -> calc_time), NULL, this_proj -> analysis[rdf] -> calc_buffer);
189}
190
199G_MODULE_EXPORT void on_calc_gr_released (GtkWidget * widg, gpointer data)
200{
201 int i;
202 if (! active_project -> analysis[GDR] -> init_ok) init_gr (active_project, GDR);
203 clean_curves_data (GDR, 0, active_project -> analysis[GDR] -> numc);
204 active_project -> analysis[GDR] -> delta = active_project -> analysis[GDR] -> max / active_project -> analysis[GDR] -> num_delta;
205 prepostcalc (widg, FALSE, GDR, 0, opac);
206 i = g_of_r_ (& active_project -> analysis[GDR] -> num_delta, & active_project -> analysis[GDR] -> delta, & fitc);
207 prepostcalc (widg, TRUE, GDR, i, 1.0);
208 if (! i)
209 {
210 remove_action ("analyze.1");
211 show_error (_("The g(r) calculation has failed"), 0, widg);
212 }
213 else
214 {
218 }
220 for (i=0; i<4; i=i+3) update_after_calc (i);
221}
222
232void sendcutoffs_ (int * nc, double * totc, double partc[* nc][* nc])
233{
234 int i, j;
235
236 active_chem -> grtotcutoff = * totc;
237 for ( i=0; i< active_project -> nspec; i++)
238 {
239 for (j=0; j<active_project -> nspec; j++)
240 {
241 active_chem -> cutoffs[i][j]=partc[j][i];
242 }
243 }
244 active_project -> dmtx = FALSE;
245}
246
247#ifdef GTK4
256G_MODULE_EXPORT void on_cutcheck_toggled (GtkCheckButton * but, gpointer data)
257#else
266G_MODULE_EXPORT void on_cutcheck_toggled (GtkToggleButton * but, gpointer data)
267#endif
268{
269 gboolean status = button_get_status ((GtkWidget *)but);
270 if (status)
271 {
272 fitc = 1;
273 }
274 else
275 {
276 fitc = 0;
277 }
278}
279
288int recup_data_ (int * cd, int * rd)
289{
290 if (* rd == 0)
291 {
292 return send_gr_ (cd,
293 & active_project -> analysis[GDR] -> curves[* cd] -> ndata,
294 & active_project -> analysis[GDR] -> delta,
295 active_project -> analysis[GDR] -> curves[* cd] -> data[0],
296 active_project -> analysis[GDR] -> curves[* cd] -> data[1]);
297 }
298 else
299 {
300 return send_sq_ (cd,
301 & active_project -> analysis[SKD] -> curves[* cd] -> ndata,
302 & active_project -> analysis[GDK] -> delta,
303 active_project -> analysis[SKD] -> curves[* cd] -> data[0],
304 active_project -> analysis[SKD] -> curves[* cd] -> data[1]);
305 }
306}
307
316G_MODULE_EXPORT void on_calc_gq_released (GtkWidget * widg, gpointer data)
317{
318 int i;
319
320 if (! active_project -> analysis[GDK] -> init_ok) init_gr (active_project, GDK);
321 clean_curves_data (GDK, 0, active_project -> analysis[GDK] -> numc);
322 active_project -> analysis[GDK] -> delta = active_project -> analysis[GDK] -> max / active_project -> analysis[GDK] -> num_delta;
323 prepostcalc (widg, FALSE, GDK, 0, opac);
324 i = g_of_r_fft_ (& active_project -> analysis[GDK] -> num_delta,
325 & active_project -> analysis[GDK] -> delta,
326 & active_project -> analysis[GDK] -> max);
327 prepostcalc (widg, TRUE, GDK, i, 1.0);
328 if (! i)
329 {
330 show_error (_("The g(r) from FFT[S(k)] calculation has failed"), 0, widg);
331 }
332 else
333 {
336 }
338 for (i=0; i<4; i=i+3) update_after_calc (i);
339}
Binding to the Fortran90 subroutines.
int send_sq_(int *, int *, double *, double *, double *)
int g_of_r_(int *, double *, int *)
int g_of_r_fft_(int *, double *, double *)
int send_gr_(int *, int *, double *, double *, double *)
Callback declarations for main window.
void fill_tool_model()
fill the tool window tree model
Definition tools.c:91
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
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:643
double opac
Definition global.c:201
GtkWidget * curvetoolbox
Definition global.c:211
Global variable declarations Global convenience function declarations Global data structure defin...
void add_analysis_action(int act)
add action to the main window action map
Definition gui.c:538
GtkTextBuffer * add_buffer(GCallback handler, gpointer data, gchar *text)
create a GtkTextBuffer
Definition gtk-misc.c:1258
chemical_data * active_chem
Definition project.c:48
#define SKD
Definition global.h:339
#define min(a, b)
Definition global.h:93
int button_get_status(GtkWidget *button)
get status of check / toggle button
Definition gtk-misc.c:1899
#define GDK
Definition global.h:340
project * active_project
Definition project.c:47
void remove_action(gchar *action_name)
add action from the main window action map
Definition gui.c:554
#define GDR
Definition global.h:337
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
#define max(a, b)
Definition global.h:92
void update_rdf_view(project *this_proj, int rdf)
update the project text view for the g(r)/g(k) calculation
Definition grcall.c:128
void init_gr(project *this_proj, int rdf)
initialize the curve widgets for the g(r)/g(k)
Definition grcall.c:66
G_MODULE_EXPORT void on_cutcheck_toggled(GtkToggleButton *but, gpointer data)
Definition grcall.c:266
G_MODULE_EXPORT void on_calc_gq_released(GtkWidget *widg, gpointer data)
compute g(k)
Definition grcall.c:316
int recup_data_(int *cd, int *rd)
Sending data back to Fortran90.
Definition grcall.c:288
G_MODULE_EXPORT void on_calc_gr_released(GtkWidget *widg, gpointer data)
compute g(r)
Definition grcall.c:199
int fitc
Definition grcall.c:56
void sendcutoffs_(int *nc, double *totc, double partc[*nc][*nc])
bond cutoff from Fortran90
Definition grcall.c:232
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
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
void update_after_calc(int calc)
update all curve plots in the workspace after a calculation
Definition interface.c:1110
void print_info(gchar *str, gchar *stag, GtkTextBuffer *buffer)
print information in GtkTextBuffer
Definition interface.c:869
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int status
Definition w_advance.c:173