atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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 initgr (int r);
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
65void initgr (int r)
66{
67 int i, j, k;
68
69 active_project -> curves[r][0] -> name = g_strdup_printf ("g(r) neutrons");
70 active_project -> curves[r][1] -> name = g_strdup_printf ("g(r) neutrons - smoothed");
71 active_project -> curves[r][2] -> name = g_strdup_printf ("G(r) neutrons");
72 active_project -> curves[r][3] -> name = g_strdup_printf ("G(r) neutrons - smoothed");
73 active_project -> curves[r][4] -> name = g_strdup_printf ("D(r) neutrons");
74 active_project -> curves[r][5] -> name = g_strdup_printf ("D(r) neutrons - smoothed");
75 active_project -> curves[r][6] -> name = g_strdup_printf ("T(r) neutrons");
76 active_project -> curves[r][7] -> name = g_strdup_printf ("T(r) neutrons - smoothed");
77 active_project -> curves[r][8] -> name = g_strdup_printf ("g(r) X-rays");
78 active_project -> curves[r][9] -> name = g_strdup_printf ("g(r) X-rays - smoothed");
79 active_project -> curves[r][10] -> name = g_strdup_printf ("G(r) X-rays");
80 active_project -> curves[r][11] -> name = g_strdup_printf ("G(r) X-rays - smoothed");
81 active_project -> curves[r][12] -> name = g_strdup_printf ("D(r) X-rays");
82 active_project -> curves[r][13] -> name = g_strdup_printf ("D(r) X-rays - smoothed");
83 active_project -> curves[r][14] -> name = g_strdup_printf ("T(r) X-rays");
84 active_project -> curves[r][15] -> name = g_strdup_printf ("T(r) X-rays - smoothed");
85 k = 16;
86 for ( i = 0 ; i < active_project -> nspec ; i++ )
87 {
88 for ( j = 0 ; j < active_project -> nspec ; j++ )
89 {
90 active_project -> curves[r][k] -> name = g_strdup_printf ("g(r)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
91 k=k+1;
92 active_project -> curves[r][k] -> name = g_strdup_printf ("g(r)[%s,%s] - smoothed", active_chem -> label[i], active_chem -> label[j]);
93 k=k+1;
94 active_project -> curves[r][k] -> name = g_strdup_printf ("G(r)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
95 k=k+1;
96 active_project -> curves[r][k] -> name = g_strdup_printf ("G(r)[%s,%s] - smoothed", active_chem -> label[i], active_chem -> label[j]);
97 k=k+1;
98 active_project -> curves[r][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 ( active_project -> nspec == 2 )
103 {
104 active_project -> curves[r][k] -> name = g_strdup_printf("BT(r)[NN]");
105 k=k+1;
106 active_project -> curves[r][k] -> name = g_strdup_printf("BT(r)[NN] - smoothed");
107 k=k+1;
108 active_project -> curves[r][k] -> name = g_strdup_printf("BT(r)[NC]");
109 k=k+1;
110 active_project -> curves[r][k] -> name = g_strdup_printf("BT(r)[NC] - smoothed");
111 k=k+1;
112 active_project -> curves[r][k] -> name = g_strdup_printf("BT(r)[CC]");
113 k=k+1;
114 active_project -> curves[r][k] -> name = g_strdup_printf("BT(r)[CC] - smoothed");
115 }
116 addcurwidgets (activep, r, 0);
117 active_project -> initok[r] = TRUE;
118}
119
128void update_rdf_view (project * this_proj, int rdf)
129{
130 gchar * str;
131 if (this_proj -> text_buffer[rdf+OT] == NULL) this_proj -> text_buffer[rdf+OT] = add_buffer (NULL, NULL, NULL);
132 view_buffer (this_proj -> text_buffer[rdf+OT]);
133 print_info ("\n\nRadial distribution function(s)", "heading", this_proj -> text_buffer[rdf+OT]);
134 if (rdf == GR)
135 {
136 print_info (" - real space calculation\n\n", "heading", this_proj -> text_buffer[rdf+OT]);
137 }
138 else
139 {
140 print_info (" - FFT[S(q)]\n\n", "heading", this_proj -> text_buffer[rdf+OT]);
141 }
142 print_info ("Calculation details:\n\n", NULL, this_proj -> text_buffer[rdf+OT]);
143
144 if (rdf == GK)
145 {
146 print_info ("\tReciprocal space data:\n\n", NULL, this_proj -> text_buffer[rdf+OT]);
147 print_info ("\t - Minimum vector Q", "bold", this_proj -> text_buffer[rdf+OT]);
148 print_info ("min", "sub_bold", this_proj -> text_buffer[rdf+OT]);
149 print_info (": ", "bold", this_proj -> text_buffer[rdf+OT]);
150 str = g_strdup_printf ("%f", this_proj -> min[SK]);
151 print_info (str, "bold_red", this_proj -> text_buffer[rdf+OT]);
152 g_free (str);
153 print_info (" Å", "bold", this_proj -> text_buffer[rdf+OT]);
154 print_info ("-1", "sup_bold", this_proj -> text_buffer[rdf+OT]);
155 print_info ("\n\t - Maximum vector Q", "bold", this_proj -> text_buffer[rdf+OT]);
156 print_info ("max", "sub_bold", this_proj -> text_buffer[rdf+OT]);
157 print_info (" for the FFT: ", "bold", this_proj -> text_buffer[rdf+OT]);
158 str = g_strdup_printf ("%f", this_proj -> max[GK]);
159 print_info (str, "bold_red", this_proj -> text_buffer[rdf+OT]);
160 g_free (str);
161 print_info (" Å", "bold", this_proj -> text_buffer[rdf+OT]);
162 print_info ("-1", "sup_bold", this_proj -> text_buffer[rdf+OT]);
163 print_info ("\n\n", NULL, this_proj -> text_buffer[rdf+OT]);
164 }
165 print_info ("\tReal space discretization:\n\n", NULL, this_proj -> text_buffer[rdf+OT]);
166 print_info ("\t - Number of δr steps: ", "bold", this_proj -> text_buffer[rdf+OT]);
167 str = g_strdup_printf ("%d", this_proj -> num_delta[rdf]);
168 print_info (str, "bold_blue", this_proj -> text_buffer[rdf+OT]);
169 g_free (str);
170 print_info ("\n\n\t between 0.0 and ", NULL, this_proj -> text_buffer[rdf+OT]);
171 print_info ("D", "bold", this_proj -> text_buffer[rdf+OT]);
172 print_info ("max", "sub_bold", this_proj -> text_buffer[rdf+OT]);
173 print_info ("\n\t where ", NULL, this_proj -> text_buffer[rdf+OT]);
174 print_info ("D", "bold", this_proj -> text_buffer[rdf+OT]);
175 print_info ("max", "sub_bold", this_proj -> text_buffer[rdf+OT]);
176 print_info (" is the maximum distance in real space, ", NULL, this_proj -> text_buffer[rdf+OT]);
177 print_info ("D", "bold", this_proj -> text_buffer[rdf+OT]);
178 print_info ("max", "sub_bold", this_proj -> text_buffer[rdf+OT]);
179 print_info (" = ", NULL, this_proj -> text_buffer[rdf+OT]);
180 str = g_strdup_printf ("%f", this_proj -> max[GR]);
181 print_info (str, "bold_blue", this_proj -> text_buffer[rdf+OT]);
182 g_free (str);
183 print_info (" Å\n\n\t - δr = ", "bold", this_proj -> text_buffer[rdf+OT]);
184 str = g_strdup_printf ("%f", this_proj -> delta[rdf]);
185 print_info (str, "bold_blue", this_proj -> text_buffer[rdf+OT]);
186 g_free (str);
187 print_info (" Å\n", "bold", this_proj -> text_buffer[rdf+OT]);
188 print_info (calculation_time(TRUE, this_proj -> calc_time[rdf]), NULL, this_proj -> text_buffer[rdf+OT]);
189}
190
199G_MODULE_EXPORT void on_calc_gr_released (GtkWidget * widg, gpointer data)
200{
201 int i;
202 if (! active_project -> initok[GR]) initgr (GR);
203 clean_curves_data (GR, 0, active_project -> numc[GR]);
204 active_project -> delta[GR] = active_project -> max[GR] / active_project -> num_delta[GR];
205 prepostcalc (widg, FALSE, GR, 0, opac);
206 clock_gettime (CLOCK_MONOTONIC, & start_time);
207 i = g_of_r_ (& active_project -> num_delta[GR], & active_project -> delta[GR], & fitc);
208 clock_gettime (CLOCK_MONOTONIC, & stop_time);
210 prepostcalc (widg, TRUE, GR, i, 1.0);
211 if (! i)
212 {
214 show_error ("The RDF's calculation has failed", 0, widg);
215 }
216 else
217 {
221 }
223 for (i=0; i<4; i=i+3) update_after_calc (i);
224}
225
235void sendcutoffs_ (int * nc, double * totc, double partc[* nc][* nc])
236{
237 int i, j;
238
239 active_chem -> grtotcutoff = * totc;
240 for ( i=0; i< active_project -> nspec; i++)
241 {
242 for (j=0; j<active_project -> nspec; j++)
243 {
244 active_chem -> cutoffs[i][j]=partc[j][i];
245 }
246 }
247 active_project -> dmtx = FALSE;
248}
249
250#ifdef GTK4
259G_MODULE_EXPORT void on_cutcheck_toggled (GtkCheckButton * but, gpointer data)
260#else
269G_MODULE_EXPORT void on_cutcheck_toggled (GtkToggleButton * but, gpointer data)
270#endif
271{
272 gboolean status;
273#ifdef GTK4
274 status = gtk_check_button_get_active (but);
275#else
276 status = gtk_toggle_button_get_active (but);
277#endif
278 if (status)
279 {
280 fitc = 1;
281 }
282 else
283 {
284 fitc = 0;
285 }
286}
287
296int recup_data_ (int * cd, int * rd)
297{
298 if (* rd == 0)
299 {
300 return send_gr_ (cd,
301 & active_project -> curves[GR][* cd] -> ndata,
302 & active_project -> delta[GR],
303 active_project -> curves[GR][* cd] -> data[0],
304 active_project -> curves[GR][* cd] -> data[1]);
305 }
306 else
307 {
308 return send_sq_ (cd,
309 & active_project -> curves[SK][* cd] -> ndata,
310 & active_project -> delta[GK],
311 active_project -> curves[SK][* cd] -> data[0],
312 active_project -> curves[SK][* cd] -> data[1]);
313 }
314}
315
324G_MODULE_EXPORT void on_calc_gq_released (GtkWidget * widg, gpointer data)
325{
326 int i;
327
328 if (! active_project -> initok[GK]) initgr (GK);
329 clean_curves_data (GK, 0, active_project -> numc[GK]);
330 active_project -> delta[GK] = active_project -> max[GR] / active_project -> num_delta[GK];
331 prepostcalc (widg, FALSE, GK, 0, opac);
332 clock_gettime (CLOCK_MONOTONIC, & start_time);
333 i = g_of_r_fft_ (& active_project -> num_delta[GK],
334 & active_project -> delta[GK],
335 & active_project -> max[GK]);
336 clock_gettime (CLOCK_MONOTONIC, & stop_time);
338 prepostcalc (widg, TRUE, GK, i, 1.0);
339 if (! i)
340 {
341 show_error ("The RDF's from FFT[S(k)] calculation has failed", 0, widg);
342 }
343 else
344 {
347 }
349 for (i=0; i<4; i=i+3) update_after_calc (i);
350}
gchar * action_name[5]
Definition atom_edit.c:60
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:87
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
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
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
GSimpleAction * analyze_actions[9]
Definition global.c:198
GtkWidget * curvetoolbox
Definition global.c:205
Global variable declarations Global convenience function declarations Global data structure defin...
GtkTextBuffer * add_buffer(GCallback handler, gpointer data, gchar *text)
create a GtkTextBuffer
Definition gtk-misc.c:1171
chemical_data * active_chem
Definition project.c:48
atomes_action analyze_acts[]
Definition gui.c:112
#define GR
Definition global.h:322
#define OT
Definition global.h:321
#define SQ
Definition global.h:323
void add_action(GSimpleAction *action)
add action to the main window action map
Definition gui.c:400
#define min(a, b)
Definition global.h:81
#define SK
Definition global.h:324
#define GK
Definition global.h:325
project * active_project
Definition project.c:47
void remove_action(gchar *action_name)
add action from the main window action map
Definition gui.c:412
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
#define max(a, b)
Definition global.h:80
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
G_MODULE_EXPORT void on_cutcheck_toggled(GtkToggleButton *but, gpointer data)
Definition grcall.c:269
G_MODULE_EXPORT void on_calc_gq_released(GtkWidget *widg, gpointer data)
compute g(k)
Definition grcall.c:324
int recup_data_(int *cd, int *rd)
Sending data back to Fortran90.
Definition grcall.c:296
G_MODULE_EXPORT void on_calc_gr_released(GtkWidget *widg, gpointer data)
compute g(r)
Definition grcall.c:199
void initgr(int r)
initialize the curve widgets for the g(r)/g(k)
Definition grcall.c:65
int fitc
Definition grcall.c:56
void sendcutoffs_(int *nc, double *totc, double partc[*nc][*nc])
bond cutoff from Fortran90
Definition grcall.c:235
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
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
void update_after_calc(int calc)
To update all curve plots in the workspace after a calculation.
Definition interface.c:977
void print_info(gchar *str, gchar *stag, GtkTextBuffer *buffer)
print information in GtkTextBuffer
Definition interface.c:738
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int status
Definition w_advance.c:160