atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
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-2024 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, 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
105void restore_coord_and_poly_info (project * proj, gboolean ** cshow, gboolean ** pshow)
106{
107 int i, j;
108 for (i=0; i<2; i++)
109 {
110 for (j=0; j<active_coord -> totcoord[i]; j++)
111 {
112#ifdef GTK3
113 if (active_glwin -> ogl_geom[0][i][j] != NULL)
114 {
115 if (GTK_IS_WIDGET(active_glwin -> ogl_geom[0][i][j]))
116 {
117 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_geom[0][i][j], cshow[i][j]);
118 if (cshow[i][j]) show_hide_coord (active_glwin -> ogl_geom[0][i][j], & active_glwin -> gcid[i][j][i]);
119 }
120 }
121 if (active_glwin -> ogl_poly[0][i][j] != NULL)
122 {
123 if (GTK_IS_WIDGET(active_glwin -> ogl_poly[0][i][j]))
124 {
125 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_poly[0][i][j], pshow[i][j]);
126 if (pshow[i][j]) show_hide_poly (active_glwin -> ogl_poly[0][i][j], & active_glwin -> gcid[i][j][i]);
127 }
128 }
129#endif
130 }
131 }
132}
133
141void sens_superbut (project * this_proj)
142{
143 int i, j;
144 if (this_proj -> modelgl -> record)
145 {
146 i = 0;
147 }
148 else
149 {
150 i = 0;
151 for (j=0; j<3; j++) i += this_proj -> modelgl -> anim -> last -> img -> extra_cell[j];
152 }
153 if (this_proj -> modelgl -> cell_win)
154 {
155 widget_set_sensitive (this_proj -> modelgl -> cell_win -> superbut, i);
156 }
157#ifdef GTK3
158 // GTK3 Menu Action To Check
159 widget_set_sensitive (this_proj -> modelgl -> ogl_box[5], i);
160#endif
161}
162
170void super_celling (glwin * view)
171{
172 gchar * txta = "You are about to change the periodicity of the 3D model,";
173 gchar * txtb = "this will affect the entire molecular dynamics trajectory,";
174 gchar * txtc = "\tand the action is irreversible, proceed anyway ?";
175 gchar * str;
176 if (get_project_by_id(view -> proj) -> steps > 1)
177 {
178 str = g_strdup_printf ("%s\n%s\n%s", txta, txtb, txtc);
179 }
180 else
181 {
182 str = g_strdup_printf ("%s\n%s", txta, txtc);
183 }
184 if (ask_yes_no ("Create a super-cell ?", str, GTK_MESSAGE_WARNING, view -> win))
185 {
186 int i, j, k, l;
187 k = activep;
188 image * last = view -> anim -> last -> img;
189 if (k != view -> proj) active_project_changed (view -> proj);
191 if (add_cells_ (& active_project -> natomes, & active_project -> steps, last -> extra_cell))
192 {
193 if (active_cell -> crystal)
194 {
196 shift.x = active_box -> vect[0][0] + active_box -> vect[1][0] + active_box -> vect[2][0];
197 shift.y = active_box -> vect[0][1] + active_box -> vect[1][1] + active_box -> vect[2][1];
198 shift.z = active_box -> vect[0][2] + active_box -> vect[1][2] + active_box -> vect[2][2];
199 for (i=0; i<active_project -> steps; i++)
200 {
201 for (j=0; j<active_project -> natomes; j++)
202 {
203 active_project -> atoms[i][j].x += shift.x;
204 active_project -> atoms[i][j].y += shift.y;
205 active_project -> atoms[i][j].z += shift.z;
206 }
207 }
208 }
209 l = 1;
210 for (i=0; i<3; i++)
211 {
212 for (j=0; j<3; j++)
213 {
214 active_box -> vect[i][j] *= (last -> extra_cell[i] + 1);
215 }
216 l *= (last -> extra_cell[i] + 1);
217 active_box -> param[0][i] *= (last -> extra_cell[i] + 1);
218 last -> extra_cell[i] = 0;
219 if (active_glwin -> cell_win)
220 {
221 if (active_glwin -> cell_win -> ax_cell[i])
222 {
223 gtk_spin_button_set_value (GTK_SPIN_BUTTON(active_glwin -> cell_win -> ax_cell[i]), 1.0);
224 }
225 }
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/2.0;
238 active_project -> atoms[i][j].y -= shift.y/2.0;
239 active_project -> atoms[i][j].z -= shift.z/2.0;
240 }
241 }
242 }
243 for (i=0; i<active_project -> nspec; i++)
244 {
245 active_chem -> nsps[i] *= l;
246 }
248 if (! active_project -> cell.crystal) center_molecule (active_project);
249
251 active_project -> dmtx = FALSE;
252 bonds_update = 1;
253 active_project -> runc[0] = FALSE;
254 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
255 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
256 gboolean ** cshow = duplicate_geom_info (active_project);
257 gboolean ** pshow = duplicate_poly_info (active_project);
258 if (view -> rings)
259 {
260 view -> rings = FALSE;
261 for (i=0; i<5; i++)
262 {
263 clean_rings_data (i, view);
264#ifdef GTK3
265 update_rings_menus (view);
266#endif
267 }
268 }
269 if (view -> chains)
270 {
271 clean_chains_data (view);
272#ifdef GTK3
273 update_chains_menus (view);
274#endif
275 }
276 on_calc_bonds_released (NULL, NULL);
278 g_free (cshow);
279 g_free (pshow);
280 int shaders[1] = {POLYS};
282 view -> create_shaders[PICKS] = TRUE;
283 view -> create_shaders[MDBOX] = TRUE;
284 view -> create_shaders[LABEL] = TRUE;
285 view -> create_shaders[MEASU] = TRUE;
286 }
287 else
288 {
289 show_warning ("Something went wrong, the 3D model was not updated", view -> win);
290 }
294 if (k != view -> proj) active_project_changed (k);
295 }
296 update (view);
297#ifdef GTK
298 update_menu_bar (view);
299#endif
300}
301
302#ifdef GTK4
312G_MODULE_EXPORT void super_cell (GSimpleAction * action, GVariant * parameter, gpointer data)
313#else
322G_MODULE_EXPORT void super_cell (GtkWidget * widg, gpointer data)
323#endif
324{
325 glwin * view = (glwin *)data;
326 super_celling (view);
328}
329
338G_MODULE_EXPORT void super_cell_but (GtkButton * but, gpointer data)
339{
340 glwin * view = (glwin *)data;
341 super_celling (view);
343}
344
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:322
void super_celling(glwin *view)
create super cell
Definition cell_super.c:170
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:141
gboolean ** duplicate_geom_info(project *this_proj)
duplicate coordinations show status
Definition cell_super.c:59
void restore_coord_and_poly_info(project *proj, gboolean **cshow, gboolean **pshow)
restore show status after
Definition cell_super.c:105
G_MODULE_EXPORT void super_cell_but(GtkButton *but, gpointer data)
create super cell callback
Definition cell_super.c:338
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