atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
sqcall.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: 'sqcall.c'
24*
25* Contains:
26*
27
28 - The callbacks for the s(q) / s(k) calculation dialog
29
30*
31* List of functions:
32
33 void init_sq (project * this_proj, int sqk);
34 void update_sq_view (project * this_proj, int sqk);
35 void save_xsk_ (int * interv, double datacurve[* interv]);
36
37 G_MODULE_EXPORT void on_calc_sq_released (GtkWidget * widg, gpointer data);
38 G_MODULE_EXPORT void on_calc_sk_released (GtkWidget * widg, gpointer data);
39
40*/
41
42#include <gtk/gtk.h>
43#include <string.h>
44#include <stdlib.h>
45
46#include "global.h"
47#include "bind.h"
48#include "interface.h"
49#include "callbacks.h"
50#include "project.h"
51#include "curve.h"
52
61void init_sq (project * this_proj, int sqk)
62{
63 int i, j, k;
64
65 this_proj -> analysis[sqk] -> curves[0] -> name = g_strdup_printf ("S(q) %s", _("Neutrons"));
66 this_proj -> analysis[sqk] -> curves[1] -> name = g_strdup_printf ("S(q) %s - %s", _("Neutrons"), _("smoothed"));
67 this_proj -> analysis[sqk] -> curves[2] -> name = g_strdup_printf ("Q(q) %s", _("Neutrons"));
68 this_proj -> analysis[sqk] -> curves[3] -> name = g_strdup_printf ("Q(q) %s - %s", _("Neutrons"), _("smoothed"));
69 this_proj -> analysis[sqk] -> curves[4] -> name = g_strdup_printf ("S(q) %s", _("X-rays"));
70 this_proj -> analysis[sqk] -> curves[5] -> name = g_strdup_printf ("S(q) %s - %s", _("X-rays"), _("smoothed"));
71 this_proj -> analysis[sqk] -> curves[6] -> name = g_strdup_printf ("Q(q) %s", _("X-rays"));
72 this_proj -> analysis[sqk] -> curves[7] -> name = g_strdup_printf ("Q(q) %s - %s", _("X-rays"), _("smoothed"));
73 k = 8;
74 for ( i = 0 ; i < this_proj -> nspec ; i++ )
75 {
76 for ( j = 0 ; j < this_proj -> nspec ; j++ )
77 {
78 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("AL(q)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
79 k=k+1;
80 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("AL(q)[%s,%s] - %s", active_chem -> label[i], active_chem -> label[j], _("smoothed"));
81 k=k+1;
82 }
83 }
84 for ( i = 0 ; i < this_proj -> nspec ; i++ )
85 {
86 for ( j = 0 ; j < this_proj -> nspec ; j++ )
87 {
88 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("FZ(q)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
89 k=k+1;
90 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("FZ(q)[%s,%s] - %s", active_chem -> label[i], active_chem -> label[j], _("smoothed"));
91 k=k+1;
92 }
93 }
94 if ( this_proj -> nspec == 2 )
95 {
96 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[NN]");
97 k=k+1;
98 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[NN] - %s", _("smoothed"));
99 k=k+1;
100 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[NC]");
101 k=k+1;
102 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[NC] - %s", _("smoothed"));
103 k=k+1;
104 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[CC]");
105 k=k+1;
106 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[CC] - %s", _("smoothed"));
107 k=k+1;
108 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[ZZ]");
109 k=k+1;
110 this_proj -> analysis[sqk] -> curves[k] -> name = g_strdup_printf ("BT(q)[ZZ] - %s", _("smoothed"));
111 }
112 add_curve_widgets (this_proj, sqk);
113 this_proj -> analysis[sqk] -> init_ok = TRUE;
114}
115
124void update_sq_view (project * this_proj, int sqk)
125{
126 gchar * str;
127 if (this_proj -> analysis[sqk] -> calc_buffer == NULL) this_proj -> analysis[sqk] -> calc_buffer = add_buffer (NULL, NULL, NULL);
128 view_buffer (this_proj -> analysis[sqk] -> calc_buffer);
129 if (sqk == SKD || sqk == SQD)
130 {
131 print_info (_("\n\nStructure factor(s)"), "heading", this_proj -> analysis[sqk] -> calc_buffer);
132 }
133 else
134 {
135 print_info (_("\n\nDynamic structure factor(s)"), "heading", this_proj -> analysis[sqk] -> calc_buffer);
136 }
137 if (sqk == SKD || sqk == SKT)
138 {
139 print_info (_(" - reciprocal space calculation\n\n"), "heading", this_proj -> analysis[sqk] -> calc_buffer);
140 }
141 else
142 {
143 print_info (" - FFT[g(r)]\n\n", "heading", this_proj -> analysis[sqk] -> calc_buffer);
144 }
145 print_info (_("Calculation details:\n\n"), NULL, this_proj -> analysis[sqk] -> calc_buffer);
146 print_info (_("\tReciprocal space discretization:\n\n"), NULL, this_proj -> analysis[sqk] -> calc_buffer);
147 print_info (_("\t - Number of δq steps: "), "bold", this_proj -> analysis[sqk] -> calc_buffer);
148 str = g_strdup_printf ("%d", this_proj -> analysis[sqk] -> num_delta);
149 print_info (str, "bold_blue", this_proj -> analysis[sqk] -> calc_buffer);
150 g_free (str);
151 print_info (_("\n\n\t between "), NULL, this_proj -> analysis[sqk] -> calc_buffer);
152 print_info ("Q", "bold", this_proj -> analysis[sqk] -> calc_buffer);
153 print_info ("min", "sub_bold", this_proj -> analysis[sqk] -> calc_buffer);
154 print_info (" ", NULL, this_proj -> analysis[sqk] -> calc_buffer);
155 print_info (_("and"), NULL, this_proj -> analysis[sqk] -> calc_buffer);
156 print_info (" ", NULL, this_proj -> analysis[sqk] -> calc_buffer);
157 print_info ("Q", "bold", this_proj -> analysis[sqk] -> calc_buffer);
158 print_info ("max", "sub_bold", this_proj -> analysis[sqk] -> calc_buffer);
159 print_info (_("\n\t where "), NULL, this_proj -> analysis[sqk] -> calc_buffer);
160 print_info ("Q", "bold", this_proj -> analysis[sqk] -> calc_buffer);
161 print_info ("min", "sub_bold", this_proj -> analysis[sqk] -> calc_buffer);
162 print_info (_(" is the minimum wave vector, and "), NULL, this_proj -> analysis[sqk] -> calc_buffer);
163 print_info ("Q", "bold", this_proj -> analysis[sqk] -> calc_buffer);
164 print_info ("max", "sub_bold", this_proj -> analysis[sqk] -> calc_buffer);
165 print_info (_(" is the maximum wave vector:\n\n"), NULL, this_proj -> analysis[sqk] -> calc_buffer);
166 print_info ("\t\tQ", "bold", this_proj -> analysis[sqk] -> calc_buffer);
167 print_info ("min", "sub_bold", this_proj -> analysis[sqk] -> calc_buffer);
168 print_info (" = ", "bold", this_proj -> analysis[sqk] -> calc_buffer);
169 str = g_strdup_printf ("%f", this_proj -> analysis[sqk] -> min);
170 print_info (str, "bold_blue", this_proj -> analysis[sqk] -> calc_buffer);
171 g_free (str);
172 print_info (" Å", "bold", this_proj -> analysis[sqk] -> calc_buffer);
173 print_info ("-1", "sup_bold", this_proj -> analysis[sqk] -> calc_buffer);
174 print_info ("\t", NULL, this_proj -> analysis[sqk] -> calc_buffer);
175 print_info (_("and"), NULL, this_proj -> analysis[sqk] -> calc_buffer);
176 print_info ("\t", NULL, this_proj -> analysis[sqk] -> calc_buffer);
177 print_info ("Q", "bold", this_proj -> analysis[sqk] -> calc_buffer);
178 print_info ("max", "sub_bold", this_proj -> analysis[sqk] -> calc_buffer);
179 print_info (" = ", "bold", this_proj -> analysis[sqk] -> calc_buffer);
180 str = g_strdup_printf ("%f", this_proj -> analysis[sqk] -> max);
181 print_info (str, "bold_blue", this_proj -> analysis[sqk] -> calc_buffer);
182 g_free (str);
183 print_info (" Å", "bold", this_proj -> analysis[sqk] -> calc_buffer);
184 print_info ("-1", "sup_bold", this_proj -> analysis[sqk] -> calc_buffer);
185
186 print_info ("\n\n\t - δq = ", "bold", this_proj -> analysis[sqk] -> calc_buffer);
187 str = g_strdup_printf ("%f", this_proj -> analysis[sqk] -> delta);
188 print_info (str, "bold_blue", this_proj -> analysis[sqk] -> calc_buffer);
189 g_free (str);
190 print_info (" Å", "bold", this_proj -> analysis[sqk] -> calc_buffer);
191 print_info ("-1", "sup_bold", this_proj -> analysis[sqk] -> calc_buffer);
192 print_info ("\n", "bold", this_proj -> analysis[sqk] -> calc_buffer);
193 if (sqk != SKT)
194 {
195 print_info (calculation_time(TRUE, this_proj -> analysis[sqk] -> calc_time), NULL, this_proj -> analysis[sqk] -> calc_buffer);
196 }
197}
198
207G_MODULE_EXPORT void on_calc_sq_released (GtkWidget * widg, gpointer data)
208{
209 int i;
210 if (! active_project -> analysis[SQD] -> init_ok) init_sq (active_project, SQD);
211 clean_curves_data (SQD, 0, active_project -> analysis[SQD] -> numc);
212 active_project -> analysis[SQD] -> delta = (active_project -> analysis[SQD] -> max - active_project -> analysis[SQD] -> min) / active_project -> analysis[SQD] -> num_delta;
213 prepostcalc (widg, FALSE, SQD, 0, opac);
214 i = s_of_q_ (& active_project -> analysis[SQD] -> max,
215 & active_project -> analysis[SQD] -> min,
216 & active_project -> analysis[SQD] -> num_delta);
217 prepostcalc (widg, TRUE, SQD, i, 1.0);
218 if (! i)
219 {
220 show_error (_("The S(q) calculation has failed"), 0, widg);
221 }
222 else
223 {
226 }
228 for (i=1; i<3; i++) update_after_calc (i);
229}
230
239void save_xsk_ (int * interv, double datacurve[* interv])
240{
241 if (* interv != 0)
242 {
243 xsk = duplicate_double (* interv, datacurve);
244 }
245}
246
255G_MODULE_EXPORT void on_calc_sk_released (GtkWidget * widg, gpointer data)
256{
257 int i, j;
258
259 if (! active_project -> analysis[SKD] -> init_ok) init_sq (active_project, SKD);
260 clean_curves_data (SKD, 0, active_project -> analysis[SKD] -> numc);
261 active_project -> analysis[SKD] -> delta = (active_project -> analysis[SKD] -> max - active_project -> analysis[SKD] -> min) / active_project -> analysis[SKD] -> num_delta;
262 prepostcalc (widg, FALSE, SKD, 0, opac);
263 i = cqvf_ (& active_project -> analysis[SKD] -> max,
264 & active_project -> analysis[SKD] -> min,
265 & active_project -> analysis[SKD] -> num_delta,
266 & active_project -> sk_advanced[0][0],
267 & active_project -> sk_advanced[0][1]);
268 if (i == 1)
269 {
270 for (i=0; i<active_project -> analysis[SKD] -> numc; i++)
271 {
272 active_project -> analysis[SKD] -> curves[i] -> ndata = 0;
273 }
274 j = s_of_k_ (& active_project -> analysis[SKD] -> num_delta, & active_project -> xcor);
275 g_free (xsk);
276 xsk = NULL;
277 prepostcalc (widg, TRUE, SKD, j, 1.0);
278 active_project -> analysis[GDK] -> avail_ok = j;
279
280 if (! j)
281 {
282 remove_action ("analyze.3");
283 show_error (_("The S(q) calculation has failed"), 0, widg);
284 }
285 else
286 {
290 }
291 }
292 else
293 {
294 prepostcalc (widg, TRUE, SKD, i, 1.0);
295 show_error (_("Problem during the selection of the k-points\nused to sample the reciprocal lattice"), 0, widg);
296 }
298 for (i=1; i<3; i++) update_after_calc (i);
299}
Binding to the Fortran90 subroutines.
int cqvf_(double *, double *, int *, double *, double *)
int s_of_q_(double *, double *, int *)
int s_of_k_(int *, int *)
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
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:595
double * xsk
Definition global.c:180
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...
#define SKT
Definition global.h:347
#define SQD
Definition global.h:338
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
#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
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
#define max(a, b)
Definition global.h:92
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...
void update_sq_view(project *this_proj, int sqk)
update the text view for s(q) / s(k) calculation
Definition sqcall.c:124
void save_xsk_(int *interv, double datacurve[*interv])
get s(k) calculation results form Fortran90
Definition sqcall.c:239
G_MODULE_EXPORT void on_calc_sk_released(GtkWidget *widg, gpointer data)
compute s(q) / s(k)
Definition sqcall.c:255
G_MODULE_EXPORT void on_calc_sq_released(GtkWidget *widg, gpointer data)
compute s(q) / s(k)
Definition sqcall.c:207
void init_sq(project *this_proj, int sqk)
initialize the curve widgets for the s(q) / s(k) calculation
Definition sqcall.c:61