atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cp2k_mol.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: 'cp2k_mol.c'
24*
25* Contains:
26*
27
28 - The functions to fix fragment(s) when creating the CP2K input file
29
30 Note: this is not used for the time being !
31
32*
33* List of functions:
34
35 void frag_set_visible (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
36 void frag_set_color (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data);
37 void cp2k_fix_molecule ();
38
39 G_MODULE_EXPORT void select_frag (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data);
40 G_MODULE_EXPORT void select_fixed_atom_confirm (GtkDialog * dialog, gint response_id, gpointer data);
41 G_MODULE_EXPORT void run_cp2k_fix_molecule (GtkDialog * dial, gint response_id, gpointer data);
42
43*/
44
45#include "global.h"
46#include "interface.h"
47#include "cp2k.h"
48#include "calc.h"
49
50extern void proj_unselect_all_atoms ();
51extern ColRGBA init_color (int id, int numid);
52extern G_MODULE_EXPORT void cp2k_select_coord_id (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data);
53extern int at_col;
54extern int ** old_fixed;
57extern GtkTreeStore * add_model;
58
69G_MODULE_EXPORT void select_frag (GtkCellRendererToggle * cell_renderer, gchar * string_path, gpointer data)
70{
71 GtkTreeIter iter;
72 GtkTreePath * path = gtk_tree_path_new_from_string (string_path);
73 gtk_tree_model_get_iter (GTK_TREE_MODEL(add_model), & iter, path);
74 int i;
75 gtk_tree_model_get (GTK_TREE_MODEL(add_model), & iter, 0, & i, -1);
76 if (gtk_cell_renderer_toggle_get_active(cell_renderer))
77 {
78 fix_frag[i-1] = 0;
79 a_frag --;
80 }
81 else
82 {
83 a_frag ++;
84 fix_frag[i-1] = 1;
85 }
86 gtk_tree_store_set (add_model, & iter, 1, fix_frag[i-1], -1);
87}
88
100void frag_set_visible (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
101{
102 int i;
103 gtk_tree_model_get (mod, iter, 1, & i, -1);
104 gtk_cell_renderer_set_visible (renderer, i);
105}
106
118void frag_set_color (GtkTreeViewColumn * col, GtkCellRenderer * renderer, GtkTreeModel * mod, GtkTreeIter * iter, gpointer data)
119{
120 int i, j;
121 gtk_tree_model_get (mod, iter, 0, & i, -1);
122 gtk_tree_model_get (mod, iter, 1, & j, -1);
123 set_renderer_color (j, renderer, init_color (i, qm_coord -> totcoord[2]));
124}
125
127
137G_MODULE_EXPORT void select_fixed_atom_confirm (GtkDialog * dialog, gint response_id, gpointer data)
138{
139 int i;
140 if (response_id == GTK_RESPONSE_YES)
141 {
142 sel_and_conf = TRUE;
143 for (i=0; i<qm_coord -> totcoord[2]; i++)
144 {
145 if (fix_frag[i] && ! old_fixed[i][0] && ! old_fixed[i][1] && ! old_fixed[i][2])
146 {
147 gchar * str = g_strdup_printf (_("Fragment %d has been selected but no coordinates appear to be frozen !\n"
148 "Unselect fragment %d or select coordinate(s) to freeze !"),
149 i+1, i+1);
151 g_free (str);
152 sel_and_conf = FALSE;
153 }
154 }
155 }
156 destroy_this_dialog (dialog);
157}
158
168G_MODULE_EXPORT void run_cp2k_fix_molecule (GtkDialog * dial, gint response_id, gpointer data)
169{
170 gchar * str;
171 int i, j;
172 gboolean done = FALSE;
173 switch (response_id)
174 {
175 case GTK_RESPONSE_APPLY:
176 if (a_frag > 0)
177 {
178 if (a_frag > 1)
179 {
180 str = g_strdup_printf (_("Fragments N°%d"), fix_frag[0]+1);
181 if (a_frag > 2)
182 {
183 for (i=1; i<a_frag-1; i++)
184 {
185 str = g_strdup_printf ("%s, %d", str, fix_frag[i]+1);
186 }
187 }
188 str = g_strdup_printf (_("%s and %d have been selected !"), str, fix_frag[a_frag-1]+1);
189 str = g_strdup_printf (_("%s\nConfirm this choice and fix these fragments ?"), str);
190 }
191 else
192 {
193 str = g_strdup_printf (_("Fragment N°%d has been selected !"), fix_frag[0]+1);
194 str = g_strdup_printf (_("%s\nConfirm this choice and fix this fragment ?"), str);
195 }
196 field_question (str, G_CALLBACK(select_fixed_atom_confirm), NULL);
197 g_free (str);
198 if (sel_and_conf)
199 {
200 done = TRUE;
201 if (tmp_cp2k -> fixlist[1] != NULL)
202 {
203 g_free (tmp_cp2k -> fixlist[1]);
204 tmp_cp2k -> fixlist[1] = NULL;
205 if (tmp_cp2k -> fixcoord[1] != NULL)
206 {
207 g_free (tmp_cp2k -> fixcoord[1]);
208 tmp_cp2k -> fixcoord[1] = NULL;
209 }
210 }
211 if (a_frag > 0)
212 {
213 tmp_cp2k -> fixlist[1] = allocint (a_frag);
214 tmp_cp2k -> fixcoord[1] = allocdint (a_frag, 3);
215 tmp_cp2k -> fixat[1] = a_frag;
216 j = -1;
217 for (i=0; i<qm_coord -> totcoord[2]; i++)
218 {
219 if (fix_frag[i])
220 {
221 j ++;
222 tmp_cp2k -> fixlist[1][j] = i;
223 tmp_cp2k -> fixcoord[1][j][0] = old_fixed[i][0];
224 tmp_cp2k -> fixcoord[1][j][1] = old_fixed[i][1];
225 tmp_cp2k -> fixcoord[1][j][2] = old_fixed[i][2];
226 }
227 }
228 }
229 }
230 }
231 break;
232 case GTK_RESPONSE_CLOSE:
233 done = TRUE;
234 break;
235 }
236 if (done) destroy_this_dialog (dial);
237}
238
245{
246 int i, j, k;
247 at_col = 0;
248 gchar * str = g_strdup_printf (_("Please select the fragment(s) to fix"));
249 GtkWidget * fmol = dialogmodal (str, GTK_WINDOW(qm_assistant));
250 g_free (str);
251 gtk_dialog_add_button (GTK_DIALOG(fmol), _("Apply"), GTK_RESPONSE_APPLY);
252 GtkWidget * frag_tree = NULL;
253 GtkTreeIter iter;
254 GtkTreeViewColumn * frag_col[5];
255 GtkCellRenderer * frag_cell[5];
256 gchar * frag_title[5] = {i18n("Fragment"), i18n("Viz.3D & Select"), "x", "y", "z"};
257 gchar * ctype[5]={"text", "active", "active", "active", "active"};
258 GType col_type[5] = {G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN};
259 add_model = gtk_tree_store_newv (5, col_type);
260 frag_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(add_model));
261 for (i=0; i<5; i++)
262 {
263 if (i == 0)
264 {
265 frag_cell[i] = gtk_cell_renderer_text_new ();
266 }
267 else
268 {
269 frag_cell[i] = gtk_cell_renderer_toggle_new ();
270 if (i == 1)
271 {
272 g_signal_connect (G_OBJECT(frag_cell[i]), "toggled", G_CALLBACK(select_frag), NULL);
273 }
274 else
275 {
276 j = i + 2;
277 g_signal_connect (G_OBJECT(frag_cell[i]), "toggled", G_CALLBACK(cp2k_select_coord_id), GINT_TO_POINTER(j));
278 }
279 }
280 frag_col[i] = gtk_tree_view_column_new_with_attributes ((i < 2) ? _(frag_title[i]) : frag_title[i], frag_cell[i], ctype[i], i, NULL);
281 gtk_tree_view_append_column (GTK_TREE_VIEW(frag_tree), frag_col[i]);
282 gtk_tree_view_column_set_alignment (frag_col[i], 0.5);
283 if (i == 0)
284 {
285 gtk_tree_view_column_set_cell_data_func (frag_col[i], frag_cell[i], frag_set_color, NULL, NULL);
286 }
287 else if (i > 1)
288 {
289 gtk_tree_view_column_set_cell_data_func (frag_col[i], frag_cell[i], frag_set_visible, NULL, NULL);
290 }
291 }
292 // fill model
293 fix_frag = NULL;
294 fix_frag = allocint (qm_coord -> totcoord[2]);
295 old_fixed = allocdint (qm_coord -> totcoord[2], 3);
296 a_frag = 0;
297 for (i=0; i<qm_coord -> totcoord[2]; i++)
298 {
299 gtk_tree_store_append (add_model, & iter, NULL);
300 for (j=0; j<tmp_cp2k -> fixat[1]; j++)
301 {
302 if (tmp_cp2k -> fixlist[1][j] == i)
303 {
304 fix_frag[i] = 1;
305 a_frag ++;
306 for (k=0; k<3; k++) old_fixed[i][k] = tmp_cp2k -> fixcoord[1][j][k];
307 break;
308 }
309 }
310 gtk_tree_store_set (add_model, & iter, 0, i + 1,
311 1, fix_frag[i],
312 2, old_fixed[i][0],
313 3, old_fixed[i][1],
314 4, old_fixed[i][2], -1);
315 }
316 g_object_unref (add_model);
317 gtk_tree_view_expand_all (GTK_TREE_VIEW(frag_tree));
318
319 i = ((qm_coord -> totcoord[2]+1)*35 < 500) ? (qm_coord -> totcoord[2]+1)*35 : 500;
320 GtkWidget * scrollsets = create_scroll (dialog_get_content_area (fmol), 220, i, GTK_SHADOW_ETCHED_IN);
321 add_container_child (CONTAINER_SCR, scrollsets, frag_tree);
322 run_this_gtk_dialog (fmol, G_CALLBACK(run_cp2k_fix_molecule), NULL);
324 g_free (fix_frag);
325}
void field_question(gchar *question, GCallback handler, gpointer data)
ask the use to confirm something
Definition calc.c:103
GtkWidget * qm_assistant
Definition calc.c:66
coord_info * qm_coord
Definition calc.c:69
Variable declarations for the MD input preparation assistants.
Variable declarations for the creation of the CP2K input file(s).
cp2k * tmp_cp2k
Definition cp2k_init.c:86
ColRGBA init_color(int id, int numid)
initialize color based id number over total number of elements
Definition initcoord.c:81
void cp2k_fix_molecule()
CP2K assistant fixing fragment(s) - creating the dialog.
Definition cp2k_mol.c:244
G_MODULE_EXPORT void cp2k_select_coord_id(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
on select CP2K fixed id toggle callback
Definition cpmd_nose.c:699
void frag_set_color(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
set renderer color in the CP2K molecule tree store
Definition cp2k_mol.c:118
G_MODULE_EXPORT void select_fixed_atom_confirm(GtkDialog *dialog, gint response_id, gpointer data)
confirm fix selection
Definition cp2k_mol.c:137
void frag_set_visible(GtkTreeViewColumn *col, GtkCellRenderer *renderer, GtkTreeModel *mod, GtkTreeIter *iter, gpointer data)
show / hide cell renderer in the CP2K molecule tree store
Definition cp2k_mol.c:100
gboolean sel_and_conf
Definition cp2k_mol.c:126
int a_frag
Definition cp2k_mol.c:55
ColRGBA init_color(int id, int numid)
initialize color based id number over total number of elements
Definition initcoord.c:81
void proj_unselect_all_atoms()
unselect all atom(s) in the target project of the assistant
Definition cpmd_init.c:1049
GtkTreeStore * add_model
Definition cpmd_nose.c:157
int * fix_frag
Definition cp2k_mol.c:56
int at_col
Definition cpmd_nose.c:151
G_MODULE_EXPORT void select_frag(GtkCellRendererToggle *cell_renderer, gchar *string_path, gpointer data)
on select molecule toggle callback
Definition cp2k_mol.c:69
int ** old_fixed
Definition cpmd_nose.c:153
G_MODULE_EXPORT void run_cp2k_fix_molecule(GtkDialog *dial, gint response_id, gpointer data)
CP2K assistant fixing fragment(s) - running the dialog.
Definition cp2k_mol.c:168
ColRGBA col
Definition d_measures.c:77
GtkTreePath * path
Definition datab.c:103
GType col_type[MAXDATA][12]
Definition dlp_field.c:946
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:317
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
#define i18n(String)
Definition global.c:80
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:533
void set_renderer_color(int tocol, GtkCellRenderer *renderer, ColRGBA col)
set the color of a GtkCellRenderer
Definition gtk-misc.c:1740
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2139
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:552
@ CONTAINER_SCR
Definition global.h:267
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:861
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2235
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:267
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:266
Messaging function declarations.