atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
spcall.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: 'spcall.c'
24*
25* Contains:
26*
27
28 - The callbacks for the spherical harmonics calculation dialog
29
30*
31* List of functions:
32
33 void init_sph (project * this_proj, int opening);
34 void update_spherical_view (project * this_proj);
35
36 G_MODULE_EXPORT void on_calc_sph_released (GtkWidget * widg, gpointer data);
37
38*/
39
40#include "global.h"
41#include "bind.h"
42#include "interface.h"
43#include "callbacks.h"
44#include "project.h"
45#include "curve.h"
46
47extern void alloc_analysis_curves (int pid, atomes_analysis * this_analysis);
48extern gboolean run_distance_matrix (GtkWidget * widg, int calc, int up_ngb);
49extern int update_voisj_and_contj ();
50
59void init_sph (project * this_proj, int opening)
60{
61 int i, j, k;
62 gchar * env;
63 if (! opening)
64 {
65 this_proj -> analysis[SPH] -> numc = this_proj -> nspec;
66 for (i=0; i<this_proj -> nspec; i++)
67 {
68 this_proj -> analysis[SPH] -> numc += this_proj -> coord -> ntg[1][i];
69 }
70 }
71 alloc_analysis_curves (this_proj -> id, this_proj -> analysis[SPH]);
72 if (! opening)
73 {
74 j = 0;
75 for (i = 0 ; i < this_proj -> nspec ; i++)
76 {
77 this_proj -> analysis[SPH] -> curves[i+j] -> name = g_strdup_printf("Q(l) [%s] (l=0 -> %d)",
78 this_proj -> chemistry -> label[i],
79 this_proj -> analysis[SPH] -> num_delta);
80 j += this_proj -> coord -> ntg[1][i];
81 }
82 k = 1;
83 for (i=0 ; i < this_proj -> nspec; i++)
84 {
85 for (j=0 ; j < this_proj -> coord -> ntg[1][i]; j++)
86 {
87 env = env_name (this_proj, j, i, 1, NULL);
88 this_proj -> analysis[SPH] -> curves[j+k] -> name = g_strdup_printf("Q(l) %s (l=0 -> %d)",
89 exact_name(env),
90 this_proj -> analysis[SPH] -> num_delta);
91 g_free (env);
92 }
93 k += this_proj -> coord -> ntg[1][i]+1;
94 }
95 }
96 add_curve_widgets (this_proj, SPH);
97 this_proj -> analysis[SPH] -> init_ok = (opening) ? FALSE : TRUE;
98}
99
108{
109 int i, j, k, l, m;
110 gchar * str;
111 gchar * tab;
112 gchar * cid;
113 if (this_proj -> analysis[SPH] -> calc_buffer == NULL) this_proj -> analysis[SPH] -> calc_buffer = add_buffer (NULL, NULL, NULL);
114 view_buffer (this_proj -> analysis[SPH] -> calc_buffer);
115
116 print_info (_("\n\nSpherical harmonics\n\n"), "heading", this_proj -> analysis[SPH] -> calc_buffer);
117 m = 0;
118 for (i=0; i<this_proj -> nspec; i++)
119 {
120 print_info (_("\nResults for the "), NULL, this_proj -> analysis[SPH] -> calc_buffer);
121 print_info (exact_name(active_chem -> label[i]), textcolor(i), this_proj -> analysis[SPH] -> calc_buffer);
122 print_info (_(" atoms: \n\n"), NULL, this_proj -> analysis[SPH] -> calc_buffer);
123 // Here print average spec info
124
125 print_info ("\tl\t", "bold_italic", this_proj -> analysis[SPH] -> calc_buffer);
126 print_info ("Q(","bold", this_proj -> analysis[SPH] -> calc_buffer);
127 print_info ("l", "bold_italic", this_proj -> analysis[SPH] -> calc_buffer);
128 print_info (")","bold", this_proj -> analysis[SPH] -> calc_buffer);
129 print_info (active_chem -> label[i], textcolor(i), this_proj -> analysis[SPH] -> calc_buffer);
130 print_info (_("[All]"), "bold", this_proj -> analysis[SPH] -> calc_buffer);
131 for (j=0 ; j < active_coord -> ntg[1][i]; j++)
132 {
133 print_info ("\tQ(","bold", this_proj -> analysis[SPH] -> calc_buffer);
134 print_info ("l", "bold_italic", this_proj -> analysis[SPH] -> calc_buffer);
135 print_info (")","bold", this_proj -> analysis[SPH] -> calc_buffer);
136 env_name (this_proj, j, i, 1, this_proj -> analysis[SPH] -> calc_buffer);
137 }
138 print_info ("\n", NULL, this_proj -> analysis[SPH] -> calc_buffer);
139 k = 1;
140 tab = NULL;
141 cid = NULL;
142 for (j=0; j<this_proj -> analysis[SPH] -> num_delta/2+1 ; j++)
143 {
144 k ++;
145 if (k - 2*(k/2) == 0)
146 {
147 tab = g_strdup_printf ("grey_back");
148 cid = g_strdup_printf ("bold_grey_back");
149 }
150 else
151 {
152 tab = NULL;
153 cid = g_strdup_printf ("bold");
154 }
155 print_info ("\t", NULL, this_proj -> analysis[SPH] -> calc_buffer);
156 if (j < 5)
157 {
158 print_info (" ",cid, this_proj -> analysis[SPH] -> calc_buffer);
159 }
160 str = g_strdup_printf("%d", 2*j);
161 print_info (str, cid, this_proj -> analysis[SPH] -> calc_buffer);
162 g_free (str);
163 for (l=0; l<active_coord -> ntg[1][i]+1; l++)
164 {
165 str = g_strdup_printf("\t%f", this_proj -> analysis[SPH] -> curves[l+m] -> data[1][j]);
166 print_info (str, tab, this_proj -> analysis[SPH] -> calc_buffer);
167 g_free (str);
168 }
169 print_info ("\n", NULL, this_proj -> analysis[SPH] -> calc_buffer);
170 if (tab != NULL)
171 {
172 g_free (tab);
173 }
174 if (cid != NULL)
175 {
176 g_free (cid);
177 }
178 }
179 m += active_coord -> ntg[1][i]+1;
180 }
181 print_info (calculation_time(TRUE, this_proj -> analysis[SPH] -> calc_time), NULL, this_proj -> analysis[SPH] -> calc_buffer);
182}
183
192G_MODULE_EXPORT void on_calc_sph_released (GtkWidget * widg, gpointer data)
193{
194 int i, j, k, l, m;
195 int err_update = 1;
196 if (! active_project -> analysis[SPH] -> init_ok) init_sph (active_project, 0);
197 if (! active_project -> dmtx)
198 {
199 active_project -> dmtx = run_distance_matrix (widg, 0, 0);
200 }
201 else
202 {
203 err_update = update_voisj_and_contj ();
204 }
205 if (! err_update)
206 {
207 show_error (_("Impossible to update FORTRAN data"), 0, (widg) ? widg : MainWindow);
208 }
209 else if (! active_project -> dmtx)
210 {
211 show_error (_("The nearest neighbors table calculation has failed"), 0, widg);
212 }
213 else
214 {
215 clean_curves_data (SPH, 0, active_project -> analysis[SPH] -> numc);
216 prepostcalc (widg, FALSE, SPH, 0, opac);
217 k = 0;
218 l = active_project -> nspec;
219 m = active_project -> analysis[SPH] -> num_delta;
220 for (i=0; i<active_project -> nspec; i++)
221 {
222 for (j=0; j< active_coord -> ntg[1][i]; j++)
223 {
224 if (j==0) k ++;
225 l += sphericals_ (& m, & i, & j, & k, active_coord -> partial_geo[i][j]);
226 k ++;
227 }
228 }
229 if (l != active_project -> analysis[SPH] -> numc)
230 {
231 i = 0;
232 }
233 else
234 {
235 i = 1;
236 }
237 prepostcalc (widg, TRUE, SPH, i, 1.0);
238 if (! i)
239 {
240 show_error (_("Unexpected error when analyzing the spherical harmonics"), 0, widg);
241 }
242 else
243 {
246 }
247 }
250}
Binding to the Fortran90 subroutines.
void free_contj_voisj_()
int sphericals_(int *, int *, int *, int *, int *)
Callback declarations for main window.
void fill_tool_model()
fill the tool window tree model
Definition tools.c:91
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
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
GtkWidget * MainWindow
Definition global.c:207
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...
GtkTextBuffer * add_buffer(GCallback handler, gpointer data, gchar *text)
create a GtkTextBuffer
Definition gtk-misc.c:1258
coord_info * active_coord
Definition project.c:49
chemical_data * active_chem
Definition project.c:48
#define SPH
Definition global.h:345
project * active_project
Definition project.c:47
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
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
gchar * textcolor(int i)
setup text color keyword
Definition interface.c:893
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
gchar * env_name(project *this_proj, int g, int s, int f, GtkTextBuffer *buffer)
output the name of a coordination sphere
Definition interface.c:1022
void print_info(gchar *str, gchar *stag, GtkTextBuffer *buffer)
print information in GtkTextBuffer
Definition interface.c:869
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:434
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
void init_sph(project *this_proj, int opening)
initialize the curve widgets for the spherical harmonics
Definition spcall.c:59
G_MODULE_EXPORT void on_calc_sph_released(GtkWidget *widg, gpointer data)
compute spherical harmonics
Definition spcall.c:192
void alloc_analysis_curves(int pid, atomes_analysis *this_analysis)
allocating analysis curve data
Definition initc.c:134
int update_voisj_and_contj()
update FORTRAN CONTJ and VOISJ for the active project
Definition bdcall.c:531
gboolean run_distance_matrix(GtkWidget *widg, int calc, int up_ngb)
compute distance matrix
Definition bdcall.c:372
void update_spherical_view(project *this_proj)
update the text view for spherical harmonics
Definition spcall.c:107