atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cp2k_files.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: 'cp2k_files.c'
24*
25* Contains:
26*
27
28 - The functions to handle CP2K basis sets and pseudopotentials
29
30*
31* List of functions:
32
33 int cp2k_is_basis_in_database (int sp);
34 int cp2k_is_pseudo_in_database (int sp);
35 int prepare_cp2k_basis_pseudo_list (int sp, int * sp_id, int n_basis_pseudo, char * bp_elem[n_basis_pseudo]);
36
37 gchar * get_nth_elem (int sp, int id, int obj);
38 gchar * get_nth_key (int sp, int id, int obj);
39
40 G_MODULE_EXPORT void changed_basis_pseudo_box (GtkComboBox * box, gpointer data);
41
42 GtkWidget * prepare_basis_combo (int sp, int obj);
43
44*/
45
46#include "global.h"
47#include "callbacks.h"
48#include "interface.h"
49#include "project.h"
50#include "glwindow.h"
51#include "glview.h"
52#include "calc.h"
53#include "cp2k.h"
54
55extern GtkWidget * cp2k_spec_combo;
56
66gchar * get_nth_elem (int sp, int id, int obj)
67{
68 int i, j;
69 j = -1;
70 if (obj)
71 {
72 for (i=0; i<N_POTS; i++)
73 {
74 if (g_strcmp0 (pot_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
75 {
76 j++;
77 if (j == id)
78 {
79 return g_strdup_printf ("%s", cp2k_pot[i]);
80 }
81 }
82 }
83 }
84 else
85 {
86 for (i=0; i<N_MOLOPT; i++)
87 {
88 if (g_strcmp0 (molopt_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
89 {
90 j++;
91 if (j == id)
92 {
93 return g_strdup_printf ("%s", cp2k_molopt[i]);
94 }
95 }
96 }
97 for (i=0; i<N_GTH; i++)
98 {
99 if (g_strcmp0 (gth_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
100 {
101 j++;
102 if (j == id)
103 {
104 return g_strdup_printf ("%s", cp2k_gth[i]);
105 }
106 }
107 }
108 for (i=0; i<N_BASIS; i++)
109 {
110 if (g_strcmp0 (basis_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
111 {
112 j++;
113 if (j == id)
114 {
115 return g_strdup_printf ("%s", cp2k_basis[i]);
116 }
117 }
118 }
119 }
120 return NULL;
121}
122
132gchar * get_nth_key (int sp, int id, int obj)
133{
134 int i, j;
135 j = -1;
136 if (obj)
137 {
138 for (i=0; i<N_POTS; i++)
139 {
140 if (g_strcmp0 (pot_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
141 {
142 j++;
143 if (j == id)
144 {
145 return g_strdup_printf ("%s", pot_keys[i]);
146 }
147 }
148 }
149 }
150 else
151 {
152 for (i=0; i<N_MOLOPT; i++)
153 {
154 if (g_strcmp0 (molopt_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
155 {
156 j++;
157 if (j == id)
158 {
159 return g_strdup_printf ("%s", molopt_keys[i]);
160 }
161 }
162 }
163 for (i=0; i<N_GTH; i++)
164 {
165 if (g_strcmp0 (gth_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
166 {
167 j++;
168 if (j == id)
169 {
170 return g_strdup_printf ("%s", gth_keys[i]);
171 }
172 }
173 }
174 for (i=0; i<N_BASIS; i++)
175 {
176 if (g_strcmp0 (basis_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
177 {
178 j++;
179 if (j == id)
180 {
181 return g_strdup_printf ("%s", basis_keys[i]);
182 }
183 }
184 }
185 }
186 return NULL;
187}
188
197{
198 int i;
199 for (i=0; i<N_MOLOPT; i++)
200 {
201 if (g_strcmp0 (molopt_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0) return 0;
202 }
203 for (i=0; i<N_GTH; i++)
204 {
205 if (g_strcmp0 (gth_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0) return 0;
206 }
207 for (i=0; i<N_BASIS; i++)
208 {
209 if (g_strcmp0 (basis_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0) return 0;
210 }
211 return -1;
212}
213
222{
223 int i;
224 for (i=0; i<N_POTS; i++)
225 {
226 if (g_strcmp0 (pot_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0) return 0;
227 }
228 return -1;
229}
230
241int prepare_cp2k_basis_pseudo_list (int sp, int * sp_id, int n_basis_pseudo, char * bp_elem[n_basis_pseudo])
242{
243 int i, j;
244 j = 0;
245 for (i=0; i<n_basis_pseudo; i++)
246 {
247 if (g_strcmp0 (bp_elem[i], exact_name(qm_proj -> chemistry -> label[sp])) == 0)
248 {
249 j ++;
250 sp_id[j-1] = i;
251 }
252 }
253 return j;
254}
255
264G_MODULE_EXPORT void changed_basis_pseudo_box (GtkComboBox * box, gpointer data)
265{
266 int i, j, k;
267 i = gtk_combo_box_get_active (GTK_COMBO_BOX(cp2k_spec_combo));
268 j = GPOINTER_TO_INT(data);
269 k = gtk_combo_box_get_active (box);
270 if (k > -1)
271 {
272 tmp_cp2k -> spec_data[i][j] = k;
273 if (tmp_cp2k -> spec_files[i][j] != NULL)
274 {
275 g_free (tmp_cp2k -> spec_files[i][j]);
276 tmp_cp2k -> spec_files[i][j] = NULL;
277 }
278 }
279}
280
289GtkWidget * prepare_basis_combo (int sp, int obj)
290{
291 int i, j;
292 GtkWidget * widg = create_combo ();
293 int * sp_id = g_malloc0 (100*sizeof*sp_id);
294 if (obj)
295 {
297 if (i > 0)
298 {
299 for (j=0; j<i; j++)
300 {
301 combo_text_append (widg, pot_keys[sp_id[j]]);
302 }
303 }
304 }
305 else
306 {
308 if (i > 0)
309 {
310 for (j=0; j<i; j++)
311 {
312 combo_text_append (widg, molopt_keys[sp_id[j]]);
313 }
314 }
316 if (i > 0)
317 {
318 for (j=0; j<i; j++)
319 {
320 combo_text_append (widg, gth_keys[sp_id[j]]);
321 }
322 }
324 if (i > 0)
325 {
326 for (j=0; j<i; j++)
327 {
328 combo_text_append (widg, basis_keys[sp_id[j]]);
329 }
330 }
331 }
332 if (tmp_cp2k -> spec_files[sp][obj] == NULL)
333 {
334 gtk_combo_box_set_active (GTK_COMBO_BOX(widg), tmp_cp2k -> spec_data[sp][obj]);
335 }
336 else
337 {
338 widget_set_sensitive (widg, FALSE);
339 }
340 g_signal_connect (G_OBJECT (widg), "changed", G_CALLBACK(changed_basis_pseudo_box), GINT_TO_POINTER(obj));
341 return widg;
342}
project * qm_proj
Definition calc.c:67
Variable declarations for the MD input preparation assistants.
Callback declarations for main window.
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
Variable declarations for the creation of the CP2K input file(s)
char * basis_keys[N_BASIS]
Definition cp2k_basis.c:291
char * pot_elem[N_POTS]
Definition cp2k_pot.c:40
char * basis_elem[N_BASIS]
Definition cp2k_basis.c:40
char * cp2k_basis[N_BASIS]
Definition cp2k_basis.c:542
char * molopt_elem[N_MOLOPT]
char * pot_keys[N_POTS]
Definition cp2k_pot.c:462
char * gth_keys[N_GTH]
#define N_GTH
Definition cp2k.h:113
#define N_POTS
Definition cp2k.h:121
char * cp2k_pot[N_POTS]
Definition cp2k_pot.c:884
char * cp2k_gth[N_GTH]
cp2k * tmp_cp2k
Definition cp2k_init.c:86
#define N_BASIS
Definition cp2k.h:117
char * cp2k_molopt[N_MOLOPT]
char * molopt_keys[N_MOLOPT]
#define N_MOLOPT
Definition cp2k.h:109
char * gth_elem[N_GTH]
gchar * get_nth_key(int sp, int id, int obj)
retrieve basis or pseudopotential key string for element from global list
Definition cp2k_files.c:132
gchar * get_nth_elem(int sp, int id, int obj)
retrieve basis or pseudopotential name string for element from global list
Definition cp2k_files.c:66
int cp2k_is_pseudo_in_database(int sp)
does this chemical species have pseudopotential(s) in store ?
Definition cp2k_files.c:221
GtkWidget * cp2k_spec_combo
Definition cp2k_init.c:235
int cp2k_is_basis_in_database(int sp)
does this chemical species have basis set(s) in store ?
Definition cp2k_files.c:196
GtkWidget * prepare_basis_combo(int sp, int obj)
prepare basis set / pseudopotential combo box
Definition cp2k_files.c:289
G_MODULE_EXPORT void changed_basis_pseudo_box(GtkComboBox *box, gpointer data)
change basis or pseudopotential
Definition cp2k_files.c:264
int prepare_cp2k_basis_pseudo_list(int sp, int *sp_id, int n_basis_pseudo, char *bp_elem[n_basis_pseudo])
find matching chemical element in basis / pseudo database
Definition cp2k_files.c:241
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
Global variable declarations Global convenience function declarations Global data structure defin...
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:900
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
Function declarations for the creation of the OpenGL window.
gchar * exact_name(gchar *name)
short cut to print string without spaces
Definition interface.c:370
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...