atomes 1.1.17
atomes: an atomic scale modeling tool box
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cell_super.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-2025 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'cell_super.c'
24*
25* Contains:
26*
27
28 - The functions to create a super-cell using the extra cell(s)
29
30*
31* List of functions:
32
33 gboolean ** duplicate_geom_info (project * this_proj);
34 gboolean ** duplicate_poly_info (project * this_proj);
35
36 void restore_coord_and_poly_info (project * proj, coord_info * ocoord, gboolean ** cshow, gboolean ** pshow);
37 void sens_superbut (project * this_proj);
38 void super_celling (glwin * view);
39
40 G_MODULE_EXPORT void super_cell (GSimpleAction * action, GVariant * parameter, gpointer data);
41 G_MODULE_EXPORT void super_cell (GtkWidget * widg, gpointer data);
42 G_MODULE_EXPORT void super_cell_but (GtkButton * but, gpointer data);
43
44*/
45
46#include "cell_edit.h"
47#include "atom_edit.h"
48
49extern void clean_coord_window (project * this_proj);
50extern GtkWidget * cell_tab (int i, project * this_proj);
51
59gboolean ** duplicate_geom_info (project * this_proj)
60{
61 int i, j;
62 gboolean ** show = g_malloc (2*sizeof*show);
63 for (i=0; i<2; i++)
64 {
65 show[i] = allocbool(this_proj -> coord -> totcoord[i]);
66 for (j=0; j<this_proj -> coord -> totcoord[i]; j++)
67 {
68 show[i][j] = this_proj -> modelgl -> anim -> last -> img -> show_coord[i][j];
69 }
70 }
71 return show;
72}
73
81gboolean ** duplicate_poly_info (project * this_proj)
82{
83 int i, j;
84 gboolean ** show = g_malloc (2*sizeof*show);
85 for (i=0; i<2; i++)
86 {
87 show[i] = allocbool(this_proj -> coord -> totcoord[i]);
88 for (j=0; j<this_proj -> coord -> totcoord[i]; j++)
89 {
90 show[i][j] = this_proj -> modelgl -> anim -> last -> img -> show_poly[i][j];
91 }
92 }
93 return show;
94}
95
106void restore_coord_and_poly_info (project * proj, coord_info * ocoord, gboolean ** cshow, gboolean ** pshow)
107{
108 int i, j;
109 gboolean restore = TRUE;
110 for (i=0; i<2; i++)
111 {
112 if (ocoord -> totcoord[i] != active_coord -> totcoord[i])
113 {
114 restore = FALSE;
115 break;
116 }
117 for (j=0; j< ocoord -> species; j++)
118 {
119 if (ocoord -> ntg[i][j] != active_coord -> ntg[i][j])
120 {
121 restore = FALSE;
122 break;
123 }
124 }
125 if (! restore) break;
126 }
127
128 if (restore)
129 {
130 for (i=0; i<2; i++)
131 {
132 for (j=0; j<active_coord -> totcoord[i]; j++)
133 {
134#ifdef GTK3
135 if (active_glwin -> ogl_geom[0][i][j] != NULL)
136 {
137 if (GTK_IS_WIDGET(active_glwin -> ogl_geom[0][i][j]))
138 {
139 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_geom[0][i][j], cshow[i][j]);
140 show_hide_coord (active_glwin -> ogl_geom[0][i][j], & active_glwin -> gcid[i][j][i]);
141 }
142 }
143 if (active_glwin -> ogl_poly[0][i][j] != NULL)
144 {
145 if (GTK_IS_WIDGET(active_glwin -> ogl_poly[0][i][j]))
146 {
147 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_poly[0][i][j], pshow[i][j]);
148 show_hide_poly (active_glwin -> ogl_poly[0][i][j], & active_glwin -> gcid[i][j][i]);
149 }
150 }
151#else
152 active_glwin -> anim -> last -> img -> show_coord[i][j] = cshow[i][j];
153 if (! cshow[i][j])
154 {
155 show_hide_coord (NULL, NULL, & active_glwin -> gcid[i][j][i]);
156 }
157 active_glwin -> anim -> last -> img -> show_poly[i][j] = pshow[i][j];
158 if (pshow[i][j])
159 {
160 show_hide_poly (NULL, NULL, & active_glwin -> gcid[i][j][i]);
161 }
162#endif
163 }
164 }
165 }
166}
167
175void sens_superbut (project * this_proj)
176{
177 int i, j;
178 if (this_proj -> modelgl -> record)
179 {
180 i = 0;
181 }
182 else
183 {
184 i = 0;
185 for (j=0; j<3; j++) i += this_proj -> modelgl -> anim -> last -> img -> extra_cell[j];
186 }
187 if (this_proj -> modelgl -> cell_win)
188 {
189 widget_set_sensitive (this_proj -> modelgl -> cell_win -> superbut, i);
190 }
191#ifdef GTK3
192 // GTK3 Menu Action To Check
193 widget_set_sensitive (this_proj -> modelgl -> ogl_box[5], i);
194#endif
195}
196
204void super_celling (glwin * view)
205{
206 gchar * txta = "You are about to change the periodicity of the 3D model,";
207 gchar * txtb = "this will affect the entire molecular dynamics trajectory,";
208 gchar * txtc = "\tand the action is irreversible, proceed anyway ?";
209 gchar * str;
210 if (get_project_by_id(view -> proj) -> steps > 1)
211 {
212 str = g_strdup_printf ("%s\n%s\n%s", txta, txtb, txtc);
213 }
214 else
215 {
216 str = g_strdup_printf ("%s\n%s", txta, txtc);
217 }
218 if (ask_yes_no ("Create a super-cell ?", str, GTK_MESSAGE_WARNING, view -> win))
219 {
220 int i, j, k, l;
221 k = activep;
222 image * last = view -> anim -> last -> img;
223 if (k != view -> proj) active_project_changed (view -> proj);
225 if (add_cells_ (& active_project -> natomes, & active_project -> steps, last -> extra_cell))
226 {
227 if (active_cell -> crystal)
228 {
230 shift.x = active_box -> vect[0][0] + active_box -> vect[1][0] + active_box -> vect[2][0];
231 shift.y = active_box -> vect[0][1] + active_box -> vect[1][1] + active_box -> vect[2][1];
232 shift.z = active_box -> vect[0][2] + active_box -> vect[1][2] + active_box -> vect[2][2];
233 for (i=0; i<active_project -> steps; i++)
234 {
235 for (j=0; j<active_project -> natomes; j++)
236 {
237 active_project -> atoms[i][j].x += shift.x;
238 active_project -> atoms[i][j].y += shift.y;
239 active_project -> atoms[i][j].z += shift.z;
240 }
241 }
242 }
243 l = 1;
244 for (i=0; i<3; i++)
245 {
246 for (j=0; j<3; j++)
247 {
248 active_box -> vect[i][j] *= (last -> extra_cell[i] + 1);
249 }
250 l *= (last -> extra_cell[i] + 1);
251 active_box -> param[0][i] *= (last -> extra_cell[i] + 1);
252 last -> extra_cell[i] = 0;
253 if (active_glwin -> cell_win)
254 {
255 if (active_glwin -> cell_win -> ax_cell[i])
256 {
257 gtk_spin_button_set_value (GTK_SPIN_BUTTON(active_glwin -> cell_win -> ax_cell[i]), 1.0);
258 }
259 }
260 }
261 if (active_cell -> crystal)
262 {
264 shift.x = active_box -> vect[0][0] + active_box -> vect[1][0] + active_box -> vect[2][0];
265 shift.y = active_box -> vect[0][1] + active_box -> vect[1][1] + active_box -> vect[2][1];
266 shift.z = active_box -> vect[0][2] + active_box -> vect[1][2] + active_box -> vect[2][2];
267 for (i=0; i<active_project -> steps; i++)
268 {
269 for (j=0; j<active_project -> natomes; j++)
270 {
271 active_project -> atoms[i][j].x -= shift.x/2.0;
272 active_project -> atoms[i][j].y -= shift.y/2.0;
273 active_project -> atoms[i][j].z -= shift.z/2.0;
274 }
275 }
276 }
277 for (i=0; i<active_project -> nspec; i++)
278 {
279 active_chem -> nsps[i] *= l;
280 }
282 if (! active_project -> cell.crystal) center_molecule (active_project);
283
285 active_project -> dmtx = FALSE;
286 bonds_update = 1;
287 active_project -> runc[0] = FALSE;
288 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
289 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
290 gboolean ** cshow = duplicate_geom_info (active_project);
291 gboolean ** pshow = duplicate_poly_info (active_project);
293 if (view -> rings)
294 {
295 view -> rings = FALSE;
296 for (i=0; i<5; i++)
297 {
298 clean_rings_data (i, view);
299#ifdef GTK3
300 update_rings_menus (view);
301#endif
302 }
303 }
304 if (view -> chains)
305 {
306 clean_chains_data (view);
307#ifdef GTK3
308 update_chains_menus (view);
309#endif
310 }
311 on_calc_bonds_released (NULL, NULL);
312 restore_coord_and_poly_info (active_project, ocoord, cshow, pshow);
313 g_free (cshow);
314 g_free (pshow);
315 g_free (ocoord);
316 int shaders[1] = {POLYS};
318 view -> create_shaders[PICKS] = TRUE;
319 view -> create_shaders[MDBOX] = TRUE;
320 view -> create_shaders[LABEL] = TRUE;
321 view -> create_shaders[MEASU] = TRUE;
322 }
323 else
324 {
325 show_warning ("Something went wrong, the 3D model was not updated", view -> win);
326 }
330 if (k != view -> proj) active_project_changed (k);
331 }
332 update (view);
333#ifdef GTK4
334 update_menu_bar (view);
335#endif
336}
337
338#ifdef GTK4
348G_MODULE_EXPORT void super_cell (GSimpleAction * action, GVariant * parameter, gpointer data)
349#else
358G_MODULE_EXPORT void super_cell (GtkWidget * widg, gpointer data)
359#endif
360{
361 glwin * view = (glwin *)data;
362 super_celling (view);
364}
365
374G_MODULE_EXPORT void super_cell_but (GtkButton * but, gpointer data)
375{
376 glwin * view = (glwin *)data;
377 super_celling (view);
379}
380
coord_info * duplicate_coord_info(coord_info *old_coord)
duplicate coordination information data structure
Definition atom_coord.c:190
void clean_other_window_after_edit(project *this_proj)
update other windows after model edition if required
Definition atom_edit.c:110
Function declarations for the mode edition window.
void center_molecule(project *this_proj)
center atomic coordinates around (0,0,0)
Definition glview.c:1441
int add_cells_(int *, int *, int *)
void restore_ogl_selection(glwin *view)
restore a saved atom selection
Definition calc.c:218
void preserve_ogl_selection(glwin *view)
copy the atom selection, so that it can be re-used once the input assistant is closed.
Definition calc.c:264
void fill_tool_model()
fill the tool window tree model
Definition tools.c:87
Function declarations for the cell edition window.
void clean_coord_window(project *this_proj)
update the environment configuration window after edtion
Definition atom_edit.c:87
GtkWidget * cell_tab(int i, project *this_proj)
create the 'i'th cell tab
Definition cell_edit.c:105
G_MODULE_EXPORT void super_cell(GtkWidget *widg, gpointer data)
create super cell menu callback GTK3
Definition cell_super.c:358
void restore_coord_and_poly_info(project *proj, coord_info *ocoord, gboolean **cshow, gboolean **pshow)
restore show status after
Definition cell_super.c:106
void super_celling(glwin *view)
create super cell
Definition cell_super.c:204
gboolean ** duplicate_poly_info(project *this_proj)
duplicate polyhedra show status
Definition cell_super.c:81
void sens_superbut(project *this_proj)
adjust 'Create super-cell' button sensitivity
Definition cell_super.c:175
gboolean ** duplicate_geom_info(project *this_proj)
duplicate coordinations show status
Definition cell_super.c:59
G_MODULE_EXPORT void super_cell_but(GtkButton *but, gpointer data)
create super cell callback
Definition cell_super.c:374
integer function chains()
Definition chains.F90:54
gchar * param[2]
int * shift
Definition d_measures.c:72
int atoms[NUM_STYLES][2]
int mol_update
Definition global.c:171
int activep
Definition global.c:159
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:254
int frag_update
Definition global.c:170
int bonds_update
Definition global.c:169
glwin * active_glwin
Definition project.c:53
G_MODULE_EXPORT void show_hide_poly(GtkWidget *widg, gpointer data)
show / hide polyhedra callback - GTK3
Definition m_poly.c:79
void update_chains_menus(glwin *view)
#define ATOM_LIMIT
atom number limit to compute fragment(s) and molecule(s) analysis automatically
coord_info * active_coord
Definition project.c:49
cell_info * active_cell
Definition project.c:50
project * proj
G_MODULE_EXPORT void show_hide_coord(GtkWidget *widg, gpointer data)
show/hide coordination callback GTK3
Definition m_coord.c:106
chemical_data * active_chem
Definition project.c:48
void clean_rings_data(int rid, glwin *view)
clean a ring type data for a glview
Definition ringscall.c:374
#define STEP_LIMIT
Definition global.h:277
G_MODULE_EXPORT void on_calc_bonds_released(GtkWidget *widg, gpointer data)
compute bonding properties
Definition bdcall.c:471
box_info * active_box
Definition project.c:51
void clean_chains_data(glwin *view)
cleaning the OpenGL data related to chain statistics
Definition chainscall.c:258
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
project * active_project
Definition project.c:47
void update_rings_menus(glwin *view)
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
void update(glwin *view)
update the rendering of the OpenGL window
Definition glview.c:439
void re_create_md_shaders(int nshaders, int shaders[nshaders], project *this_proj)
re-initialize some MD dependent OpenGL shaders
action
Definition glview.h:189
shaders
The different types of shaders in the atomes program.
Definition glwin.h:88
@ PICKS
Definition glwin.h:97
@ LABEL
Definition glwin.h:98
@ POLYS
Definition glwin.h:92
@ MDBOX
Definition glwin.h:93
@ MEASU
Definition glwin.h:99
void init_curves_and_calc(project *this_proj)
for a project reset analysis, curves, data to not performed
Definition init_p.c:54
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:260
gboolean ask_yes_no(gchar *title, gchar *text, int type, GtkWidget *widg)
ask yes or no for something: prepare dialog
Definition interface.c:356
void active_project_changed(int id)
change the active project
Definition update_p.c:175
Definition glwin.h:875
Definition glwin.h:277
float x
Definition math_3d.h:130
GtkWidget * img
Definition workspace.c:70