atomes 1.1.14
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-2024 by CNRS and University of Strasbourg */
15
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 initsq (int r);
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
60void initsq (int r)
61{
62 int i, j, k;
63
64 active_project -> curves[r][0] -> name = g_strdup_printf ("S(q) Neutrons");
65 active_project -> curves[r][1] -> name = g_strdup_printf ("S(q) Neutrons - smoothed");
66 active_project -> curves[r][2] -> name = g_strdup_printf ("Q(q) Neutrons");
67 active_project -> curves[r][3] -> name = g_strdup_printf ("Q(q) Neutrons - smoothed");
68 active_project -> curves[r][4] -> name = g_strdup_printf ("S(q) X-rays");
69 active_project -> curves[r][5] -> name = g_strdup_printf ("S(q) X-rays - smoothed");
70 active_project -> curves[r][6] -> name = g_strdup_printf ("Q(q) X-rays");
71 active_project -> curves[r][7] -> name = g_strdup_printf ("Q(q) X-rays - smoothed");
72 k = 8;
73 for ( i = 0 ; i < active_project -> nspec ; i++ )
74 {
75 for ( j = 0 ; j < active_project -> nspec ; j++ )
76 {
77 active_project -> curves[r][k] -> name = g_strdup_printf ("AL(q)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
78 k=k+1;
79 active_project -> curves[r][k] -> name = g_strdup_printf ("AL(q)[%s,%s] - smoothed", active_chem -> label[i], active_chem -> label[j]);
80 k=k+1;
81 }
82 }
83 for ( i = 0 ; i < active_project -> nspec ; i++ )
84 {
85 for ( j = 0 ; j < active_project -> nspec ; j++ )
86 {
87 active_project -> curves[r][k] -> name = g_strdup_printf ("FZ(q)[%s,%s]", active_chem -> label[i], active_chem -> label[j]);
88 k=k+1;
89 active_project -> curves[r][k] -> name = g_strdup_printf ("FZ(q)[%s,%s] - smoothed", active_chem -> label[i], active_chem -> label[j]);
90 k=k+1;
91 }
92 }
93 if ( active_project -> nspec == 2 )
94 {
95 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[NN]");
96 k=k+1;
97 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[NN] - smoothed");
98 k=k+1;
99 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[NC]");
100 k=k+1;
101 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[NC] - smoothed");
102 k=k+1;
103 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[CC]");
104 k=k+1;
105 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[CC] - smoothed");
106 k=k+1;
107 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[ZZ]");
108 k=k+1;
109 active_project -> curves[r][k] -> name = g_strdup_printf ("BT(q)[ZZ] - smoothed");
110 }
111 addcurwidgets (activep, r, 0);
112 active_project -> initok[r] = TRUE;
113}
114
123void update_sq_view (project * this_proj, int sqk)
124{
125 gchar * str;
126 if (this_proj -> text_buffer[sqk+OT] == NULL) this_proj -> text_buffer[sqk+OT] = add_buffer (NULL, NULL, NULL);
127 view_buffer (this_proj -> text_buffer[sqk+OT]);
128 print_info ("\n\nStructure factor(s)", "heading", this_proj -> text_buffer[sqk+OT]);
129 if (sqk == SK)
130 {
131 print_info (" - reciprocal space calculation\n\n", "heading", this_proj -> text_buffer[sqk+OT]);
132 }
133 else
134 {
135 print_info (" - FFT[g(r)]\n\n", "heading", this_proj -> text_buffer[sqk+OT]);
136 }
137 print_info ("Calculation details:\n\n", NULL, this_proj -> text_buffer[sqk+OT]);
138 print_info ("\tReciprocal space discretization:\n\n", NULL, this_proj -> text_buffer[sqk+OT]);
139 print_info ("\t - Number of δq steps: ", "bold", this_proj -> text_buffer[sqk+OT]);
140 str = g_strdup_printf ("%d", this_proj -> num_delta[sqk]);
141 print_info (str, "bold_blue", this_proj -> text_buffer[sqk+OT]);
142 g_free (str);
143 print_info ("\n\n\t between ", NULL, this_proj -> text_buffer[sqk+OT]);
144 print_info ("Q", "bold", this_proj -> text_buffer[sqk+OT]);
145 print_info ("min", "sub_bold", this_proj -> text_buffer[sqk+OT]);
146 print_info (" and ", NULL, this_proj -> text_buffer[sqk+OT]);
147 print_info ("Q", "bold", this_proj -> text_buffer[sqk+OT]);
148 print_info ("max", "sub_bold", this_proj -> text_buffer[sqk+OT]);
149 print_info ("\n\t where ", NULL, this_proj -> text_buffer[sqk+OT]);
150 print_info ("Q", "bold", this_proj -> text_buffer[sqk+OT]);
151 print_info ("min", "sub_bold", this_proj -> text_buffer[sqk+OT]);
152 print_info (" is the minimum wave vector, and ", NULL, this_proj -> text_buffer[sqk+OT]);
153 print_info ("Q", "bold", this_proj -> text_buffer[sqk+OT]);
154 print_info ("max", "sub_bold", this_proj -> text_buffer[sqk+OT]);
155 print_info (" is the maximum wave vector:\n\n", NULL, this_proj -> text_buffer[sqk+OT]);
156 print_info ("\t\tQ", "bold", this_proj -> text_buffer[sqk+OT]);
157 print_info ("min", "sub_bold", this_proj -> text_buffer[sqk+OT]);
158 print_info (" = ", "bold", this_proj -> text_buffer[sqk+OT]);
159 str = g_strdup_printf ("%f", this_proj -> min[sqk]);
160 print_info (str, "bold_blue", this_proj -> text_buffer[sqk+OT]);
161 g_free (str);
162 print_info (" Å", "bold", this_proj -> text_buffer[sqk+OT]);
163 print_info ("-1", "sup_bold", this_proj -> text_buffer[sqk+OT]);
164 print_info ("\tand\t", NULL, this_proj -> text_buffer[sqk+OT]);
165 print_info ("Q", "bold", this_proj -> text_buffer[sqk+OT]);
166 print_info ("max", "sub_bold", this_proj -> text_buffer[sqk+OT]);
167 print_info (" = ", "bold", this_proj -> text_buffer[sqk+OT]);
168 str = g_strdup_printf ("%f", this_proj -> max[sqk]);
169 print_info (str, "bold_blue", this_proj -> text_buffer[sqk+OT]);
170 g_free (str);
171 print_info (" Å", "bold", this_proj -> text_buffer[sqk+OT]);
172 print_info ("-1", "sup_bold", this_proj -> text_buffer[sqk+OT]);
173
174 print_info ("\n\n\t - δq = ", "bold", this_proj -> text_buffer[sqk+OT]);
175 str = g_strdup_printf ("%f", this_proj -> delta[sqk]);
176 print_info (str, "bold_blue", this_proj -> text_buffer[sqk+OT]);
177 g_free (str);
178 print_info (" Å", "bold", this_proj -> text_buffer[sqk+OT]);
179 print_info ("-1", "sup_bold", this_proj -> text_buffer[sqk+OT]);
180 print_info ("\n", "bold", this_proj -> text_buffer[sqk+OT]);
181 print_info (calculation_time(TRUE, this_proj -> calc_time[sqk]), NULL, this_proj -> text_buffer[sqk+OT]);
182}
183
192G_MODULE_EXPORT void on_calc_sq_released (GtkWidget * widg, gpointer data)
193{
194 int i;
195
196 if (! active_project -> initok[SQ]) initsq (SQ);
197 clean_curves_data (SQ, 0, active_project -> numc[SQ]);
198 active_project -> delta[SQ] = (active_project -> max[SQ] - active_project -> min[SQ]) / active_project -> num_delta[SQ];
199 prepostcalc (widg, FALSE, SQ, 0, opac);
200 clock_gettime (CLOCK_MONOTONIC, & start_time);
201 i = s_of_q_ (& active_project -> max[SQ],
202 & active_project -> min[SQ],
203 & active_project -> num_delta[SQ]);
204 clock_gettime (CLOCK_MONOTONIC, & stop_time);
206 prepostcalc (widg, TRUE, SQ, i, 1.0);
207 if (! i)
208 {
209 show_error ("The S(q) calculation has failed", 0, widg);
210 }
211 else
212 {
214 gtk_widget_show (curvetoolbox);
215 }
217 for (i=1; i<3; i++) update_after_calc (i);
218}
219
228void save_xsk_ (int * interv, double datacurve[* interv])
229{
230 if (* interv != 0)
231 {
232 xsk = duplicate_double (* interv, datacurve);
233 }
234}
235
244G_MODULE_EXPORT void on_calc_sk_released (GtkWidget * widg, gpointer data)
245{
246 int i, j;
247
248 if (! active_project -> initok[SK]) initsq (SK);
249 clean_curves_data (SK, 0, active_project -> numc[SK]);
250 active_project -> delta[SK] = (active_project -> max[SK] - active_project -> min[SK]) / active_project -> num_delta[SK];
251 prepostcalc (widg, FALSE, SK, 0, opac);
252 i = cqvf_ (& active_project -> max[SK],
253 & active_project -> min[SK],
254 & active_project -> num_delta[SK],
255 & active_project -> sk_advanced[0],
256 & active_project -> sk_advanced[1]);
257 prepostcalc (widg, TRUE, SK, i, 1.0);
258 if (i == 1)
259 {
260 prepostcalc (widg, FALSE, SK, 0, opac);
261 for (i=0; i<active_project -> numc[SK]; i++)
262 {
263 active_project -> curves[SK][i] -> ndata = 0;
264 }
265 clock_gettime (CLOCK_MONOTONIC, & start_time);
266 j = s_of_k_ (& active_project -> num_delta[SK], & active_project -> xcor);
267 clock_gettime (CLOCK_MONOTONIC, & stop_time);
269 g_free (xsk);
270 xsk = NULL;
271 active_project -> runok[GK] = j;
272 prepostcalc (widg, TRUE, SK, j, 1.0);
273 if (! j)
274 {
276 show_error ("The S(q) calculation has failed", 0, widg);
277 }
278 else
279 {
282 gtk_widget_show (curvetoolbox);
283 }
284 }
285 else
286 {
287 show_error ("Problem during the selection of the k-points\nused to sample the recipocal lattice", 0, widg);
288 }
290 for (i=1; i<3; i++) update_after_calc (i);
291}
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: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
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:620
gchar * analyze_action_names[9]
Definition global.c:201
struct timespec start_time
Definition global.c:191
int activep
Definition global.c:159
double * xsk
Definition global.c:176
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:649
double opac
Definition global.c:194
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:636
struct timespec stop_time
Definition global.c:192
GSimpleAction * analyze_actions[9]
Definition global.c:211
GtkWidget * curvetoolbox
Definition global.c:218
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:1151
chemical_data * active_chem
Definition project.c:48
#define OT
Definition global.h:293
#define SQ
Definition global.h:295
void add_action(GSimpleAction *action)
add action to the main window action map
Definition gui.c:284
#define min(a, b)
Definition global.h:75
#define SK
Definition global.h:296
#define GK
Definition global.h:297
project * active_project
Definition project.c:47
void remove_action(gchar *action_name)
add action from the main window action map
Definition gui.c:296
#define max(a, b)
Definition global.h:74
void view_buffer(GtkTextBuffer *buffer)
set a text buffer in the main window or an image
Definition gui.c:182
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...
void update_sq_view(project *this_proj, int sqk)
update the text view for s(q) / s(k) calculation
Definition sqcall.c:123
void save_xsk_(int *interv, double datacurve[*interv])
get s(k) calculation results form Fortran90
Definition sqcall.c:228
void initsq(int r)
initialize the curve widgets for the s(q) / s(k) calculation
Definition sqcall.c:60
G_MODULE_EXPORT void on_calc_sk_released(GtkWidget *widg, gpointer data)
compute s(q) / s(k)
Definition sqcall.c:244
G_MODULE_EXPORT void on_calc_sq_released(GtkWidget *widg, gpointer data)
compute s(q) / s(k)
Definition sqcall.c:192