atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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 !", i+1, i+1);
150 g_free (str);
151 sel_and_conf = FALSE;
152 }
153 }
154 }
155 destroy_this_dialog (dialog);
156}
157
167G_MODULE_EXPORT void run_cp2k_fix_molecule (GtkDialog * dial, gint response_id, gpointer data)
168{
169 gchar * str;
170 int i, j;
171 gboolean done = FALSE;
172 switch (response_id)
173 {
174 case GTK_RESPONSE_APPLY:
175 if (a_frag > 0)
176 {
177 if (a_frag > 1)
178 {
179 str = g_strdup_printf ("Fragments N°%d", fix_frag[0]+1);
180 if (a_frag > 2)
181 {
182 for (i=1; i<a_frag-1; i++)
183 {
184 str = g_strdup_printf ("%s, %d", str, fix_frag[i]+1);
185 }
186 }
187 str = g_strdup_printf ("%s and %d have been selected !", str, fix_frag[a_frag-1]+1);
188 str = g_strdup_printf ("%s\nConfirm this choice and fix these fragments ?", str);
189 }
190 else
191 {
192 str = g_strdup_printf ("Fragment N°%d has been selected !", fix_frag[0]+1);
193 str = g_strdup_printf ("%s\nConfirm this choice and fix this fragment ?", str);
194 }
195 field_question (str, G_CALLBACK(select_fixed_atom_confirm), NULL);
196 g_free (str);
197 if (sel_and_conf)
198 {
199 done = TRUE;
200 if (tmp_cp2k -> fixlist[1] != NULL)
201 {
202 g_free (tmp_cp2k -> fixlist[1]);
203 tmp_cp2k -> fixlist[1] = NULL;
204 if (tmp_cp2k -> fixcoord[1] != NULL)
205 {
206 g_free (tmp_cp2k -> fixcoord[1]);
207 tmp_cp2k -> fixcoord[1] = NULL;
208 }
209 }
210 if (a_frag > 0)
211 {
212 tmp_cp2k -> fixlist[1] = allocint (a_frag);
213 tmp_cp2k -> fixcoord[1] = allocdint (a_frag, 3);
214 tmp_cp2k -> fixat[1] = a_frag;
215 j = -1;
216 for (i=0; i<qm_coord -> totcoord[2]; i++)
217 {
218 if (fix_frag[i])
219 {
220 j ++;
221 tmp_cp2k -> fixlist[1][j] = i;
222 tmp_cp2k -> fixcoord[1][j][0] = old_fixed[i][0];
223 tmp_cp2k -> fixcoord[1][j][1] = old_fixed[i][1];
224 tmp_cp2k -> fixcoord[1][j][2] = old_fixed[i][2];
225 }
226 }
227 }
228 }
229 }
230 break;
231 case GTK_RESPONSE_CLOSE:
232 done = TRUE;
233 break;
234 }
235 if (done) destroy_this_dialog (dial);
236}
237
244{
245 int i, j, k;
246 at_col = 0;
247 gchar * str = g_strdup_printf ("Please select the fragment(s) to fix");
248 GtkWidget * fmol = dialogmodal (str, GTK_WINDOW(qm_assistant));
249 g_free (str);
250 gtk_dialog_add_button (GTK_DIALOG(fmol), "Apply", GTK_RESPONSE_APPLY);
251 GtkWidget * frag_tree = NULL;
252 GtkTreeIter iter;
253 GtkTreeViewColumn * frag_col[5];
254 GtkCellRenderer * frag_cell[5];
255 gchar * frag_title[5] = {"Fragment", "Viz.3D & Select", "x", "y", "z"};
256 gchar * ctype[5]={"text", "active", "active", "active", "active"};
257 GType col_type[5] = {G_TYPE_INT, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN};
258 add_model = gtk_tree_store_newv (5, col_type);
259 frag_tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(add_model));
260 for (i=0; i<5; i++)
261 {
262 if (i == 0)
263 {
264 frag_cell[i] = gtk_cell_renderer_text_new ();
265 }
266 else
267 {
268 frag_cell[i] = gtk_cell_renderer_toggle_new ();
269 if (i == 1)
270 {
271 g_signal_connect (G_OBJECT(frag_cell[i]), "toggled", G_CALLBACK(select_frag), NULL);
272 }
273 else
274 {
275 j = i + 2;
276 g_signal_connect (G_OBJECT(frag_cell[i]), "toggled", G_CALLBACK(cp2k_select_coord_id), GINT_TO_POINTER(j));
277 }
278 }
279 frag_col[i] = gtk_tree_view_column_new_with_attributes (frag_title[i], frag_cell[i], ctype[i], i, NULL);
280 gtk_tree_view_append_column (GTK_TREE_VIEW(frag_tree), frag_col[i]);
281 gtk_tree_view_column_set_alignment (frag_col[i], 0.5);
282 if (i == 0)
283 {
284 gtk_tree_view_column_set_cell_data_func (frag_col[i], frag_cell[i], frag_set_color, NULL, NULL);
285 }
286 else if (i > 1)
287 {
288 gtk_tree_view_column_set_cell_data_func (frag_col[i], frag_cell[i], frag_set_visible, NULL, NULL);
289 }
290 }
291 // fill model
292 fix_frag = NULL;
293 fix_frag = allocint (qm_coord -> totcoord[2]);
294 old_fixed = allocdint (qm_coord -> totcoord[2], 3);
295 a_frag = 0;
296 for (i=0; i<qm_coord -> totcoord[2]; i++)
297 {
298 gtk_tree_store_append (add_model, & iter, NULL);
299 for (j=0; j<tmp_cp2k -> fixat[1]; j++)
300 {
301 if (tmp_cp2k -> fixlist[1][j] == i)
302 {
303 fix_frag[i] = 1;
304 a_frag ++;
305 for (k=0; k<3; k++) old_fixed[i][k] = tmp_cp2k -> fixcoord[1][j][k];
306 break;
307 }
308 }
309 gtk_tree_store_set (add_model, & iter, 0, i + 1,
310 1, fix_frag[i],
311 2, old_fixed[i][0],
312 3, old_fixed[i][1],
313 4, old_fixed[i][2], -1);
314 }
315 g_object_unref (add_model);
316 gtk_tree_view_expand_all (GTK_TREE_VIEW(frag_tree));
317
318 i = ((qm_coord -> totcoord[2]+1)*35 < 500) ? (qm_coord -> totcoord[2]+1)*35 : 500;
319 GtkWidget * scrollsets = create_scroll (dialog_get_content_area (fmol), 220, i, GTK_SHADOW_ETCHED_IN);
320 add_container_child (CONTAINER_SCR, scrollsets, frag_tree);
321 run_this_gtk_dialog (fmol, G_CALLBACK(run_cp2k_fix_molecule), NULL);
323 g_free (fix_frag);
324}
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
void cp2k_fix_molecule()
CP2K assistant fixing fragment(s) - creating the dialog.
Definition cp2k_mol.c:243
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:689
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:1033
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:167
ColRGBA col
Definition d_measures.c:77
GtkTreePath * path
Definition datab.c:103
GType col_type[MAXDATA][12]
Definition dlp_field.c:856
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:330
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
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:492
void set_renderer_color(int tocol, GtkCellRenderer *renderer, ColRGBA col)
set the color of a GtkCellRenderer
Definition gtk-misc.c:1653
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:1960
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:510
@ CONTAINER_SCR
Definition global.h:251
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:226
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:260
Messaging function declarations.