atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
calc.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
24/*
25* This file: 'calc.c'
26*
27* Contains:
28*
29
30 - Callbacks used in by the molecular dynamics calculation assistant
31 - Atom selection structure manipulation tools
32 - The initialization of the assistants
33
34*
35* List of functions:
36
37 void field_question (gchar * question, GCallback handler, gpointer data);
38 void unselect_all_atoms (glwin * view);
39 void restore_ogl_selection (glwin * view);
40 void preserve_ogl_selection (glwin * view);
41
42 G_MODULE_EXPORT void confirm_selection (GtkDialog * dialog, gint response_id, gpointer data);
43 G_MODULE_EXPORT void create_field (GtkWidget * widg, gpointer data);
44
45 atom_selection * duplicate_ogl_selection (atom_selection * old_sel);
46
47*/
48
49#include "global.h"
50#include "interface.h"
51#include "project.h"
52#include "glwindow.h"
53#include "glview.h"
54
55#define MAXDATAQM 7
56
57extern void create_classical_force_field (int p, int f);
58extern void create_qm_input_file (int c, int p, int s);
59extern void create_new_project_using_data (atom_selection * selection);
60extern int selected_aspec;
61extern int num_bonds (int i);
62extern int num_angles (int i);
63extern int num_dihedrals (int i);
64extern atom_in_selection * new_atom_in_selection (int id, int sp);
65
66GtkWidget * qm_assistant;
70GtkTextBuffer * qmbuffer[MAXDATAQM+2];
71gboolean force_mol = FALSE;
76
78
88G_MODULE_EXPORT void confirm_selection (GtkDialog * dialog, gint response_id, gpointer data)
89{
90 selection_confirmed = (response_id == GTK_RESPONSE_YES) ? TRUE : FALSE;
91 destroy_this_dialog (dialog);
92}
93
103void field_question (gchar * question, GCallback handler, gpointer data)
104{
105 GtkWidget * dialog;
106 dialog = gtk_message_dialog_new (NULL, GTK_DIALOG_MODAL, GTK_MESSAGE_QUESTION, GTK_BUTTONS_YES_NO, "Are you sure ?");
107 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s", question);
108 gtk_window_set_title(GTK_WINDOW(dialog), "Please confirm");
109 run_this_gtk_dialog (dialog, handler, data);
110}
111
120{
121 int i, j;
122 atom_in_selection * at, * bt;
123 atom_selection * new_sel = g_malloc0 (sizeof*new_sel);
124 if (! old_sel -> selected) return new_sel;
125 new_sel -> selected = old_sel -> selected;
126 at = old_sel -> first;
127 for (i=0; i< old_sel -> selected; i++)
128 {
129 if (! i)
130 {
131 new_sel -> first = new_atom_in_selection (at -> id, at -> sp);
132 bt = new_sel -> first;
133 new_sel -> last = NULL;
134 }
135 else
136 {
137 bt -> next = new_atom_in_selection (at -> id, at -> sp);
138 bt -> next -> prev = bt;
139 bt = bt -> next;
140 }
141 if (at -> next != NULL) at = at -> next;
142 }
143 bt -> next = NULL;
144 new_sel -> last = bt;
145 if (old_sel -> selected > 1 && old_sel -> selected < MAX_IN_SELECTION)
146 {
147 i = num_bonds (old_sel -> selected);
148 new_sel -> selected_bonds = allocint (i);
149 for (j=0; j<i; j++)
150 {
151 new_sel -> selected_bonds[j] = old_sel -> selected_bonds[j];
152 }
153 if (new_sel -> selected > 2)
154 {
155 i = num_angles (old_sel -> selected);
156 new_sel -> selected_angles = allocint (i);
157 for (j=0; j<i; j++)
158 {
159 new_sel -> selected_angles[j] = old_sel -> selected_angles[j];
160 }
161 if (new_sel -> selected > 3 && new_sel -> selected < MAX_IN_SELECTION-10)
162 {
163 i = num_dihedrals (old_sel -> selected);
164 new_sel -> selected_dihedrals = allocint (i);
165 for (j=0; j<i; j++)
166 {
167 new_sel -> selected_dihedrals[j] = old_sel -> selected_dihedrals[j];
168 }
169 }
170 }
171 }
172 return new_sel;
173}
174
183{
184 int i, j, k;
185 project * this_proj = get_project_by_id (view -> proj);
186 for (i=0; i<2; i++)
187 {
188 save_all_selections (view, i);
189 for (j=0; j<this_proj -> steps; j++)
190 {
191 for (k=0; k<this_proj -> natomes; k++)
192 {
193 if (j == view -> anim -> last -> img -> step)
194 {
195 if (this_proj -> atoms[j][k].pick[i])
196 {
197 process_selected_atom (this_proj, view, k, 0, 0, i);
198 }
199 }
200 else
201 {
202 this_proj -> atoms[j][k].pick[i] = FALSE;
203 }
204 }
205 }
206 update_all_selections (view, i);
207 }
209}
210
219{
220 int i, j, k, l;
221 project * this_proj = get_project_by_id (view -> proj);
222 unselect_all_atoms (view);
223 for (i=0; i<2; i++)
224 {
225 view -> anim -> last -> img -> selected[i] = duplicate_ogl_selection (view -> tmp_sel[i]);
226 if (view -> anim -> last -> img -> selected[i] -> selected)
227 {
228 atom_in_selection * at = view -> anim -> last -> img -> selected[i] -> first;
229 while (at)
230 {
231 for (j=0; j<this_proj -> steps; j++)
232 {
233 this_proj -> atoms[j][at -> id].pick[i] = TRUE;
234 }
235 at = at -> next;
236 }
237 }
238 if (view -> stored_labels[i])
239 {
240 for (j=1; j<view -> stored_labels[i][0]; j++)
241 {
242 k = view -> stored_labels[i][j];
243 for (l=0; l<this_proj -> steps; l++) this_proj -> atoms[l][k].label[i] = TRUE;
244 }
245 g_free (view -> stored_labels[i]);
246 view -> stored_labels[i] = NULL;
247 }
248 }
250 if (check_label)
251 {
252 view -> labelled = check_label_numbers (this_proj, 2);
253 update (view);
254 }
255}
256
265{
266 int h, i, j, k, l;
267 project * this_proj = get_project_by_id (view -> proj);
268 h = view -> anim -> last -> img -> step;
269 k = 0;
270 for (i=0; i<2; i++)
271 {
272 view -> tmp_sel[i] = duplicate_ogl_selection (view -> anim -> last -> img -> selected[i]);
273 for (j=0; j<2; j++)
274 {
275 if (j && k)
276 {
277 view -> stored_labels[i] = allocint(k+1);
278 view -> stored_labels[i][0] = k+1;
279 }
280 k = j;
281 for (l=0; l<this_proj -> natomes; l++)
282 {
283 if (this_proj -> atoms[h][l].label[i])
284 {
285 if (j)
286 {
287 view -> stored_labels[i][k] = l;
288 this_proj -> atoms[h][l].label[i] = FALSE;
289 }
290 k ++;
291 }
292 }
293 }
294 }
295 unselect_all_atoms (view);
296}
297
298extern char * input_types[NINPUTS];
299
308G_MODULE_EXPORT void create_field (GtkWidget * widg, gpointer data)
309{
310 tint * the_data = (tint *)data;
311 int p = the_data -> a;
312 int t = the_data -> b;
313 // if a selection was made preserve it
316 update (opengl_project -> modelgl);
317
318 if (opengl_project -> steps > 1)
319 {
320 gchar * info = g_strdup_printf (" %s contains %d different sets of atomic coordinates. \n"
321 " Please select the one to use to create the input file(s) \n"
322 " Note that a new project will be generated for that purpose. \n",
323 opengl_project -> name,
324 opengl_project -> steps);
325 // preserve parameters
326 int tmp_s = opengl_project -> modelgl -> anim -> last -> img -> step;
327 int tmp_a = activep;
328 int tmp_v = activev;
329 tint t_data;
330 t_data.a = p;
331 t_data.b = iask (info, "Enter the selected MD step: ", 2+opengl_project -> steps, opengl_project -> modelgl -> win);
332 t_data.c = 1;
333 g_free (info);
334
335 // then change the MD step and select all atoms
336 opengl_project -> modelgl -> anim -> last -> img -> step = t_data.b;
337 selected_aspec = -1;
338#ifdef GTK4
339 select_unselect_atoms (NULL, NULL, & t_data);
340#else
341 select_unselect_atoms (NULL, & t_data);
342#endif
343 // create new project with selection
344 force_mol = TRUE;
345 create_new_project_using_data (opengl_project -> modelgl -> anim -> last -> img -> selected[0]);
346 force_mol = FALSE;
347 opengl_project -> modelgl -> anim -> last -> img -> step = tmp_s;
349 // Set the new project to be use for input creation
350 p = activep;
352 // restore old active project
355 }
356
357 switch (t)
358 {
359 case 0:
360 // DLPOLY
362 break;
363 case 1:
364 // LAMMPS
366 break;
367 case 2:
368 create_qm_input_file (0, p, 0);
369 break;
370 case 3:
371 create_qm_input_file (1, p, 0);
372 break;
373 case 4:
374 create_qm_input_file (0, p, 1);
375 break;
376 case 5:
377 create_qm_input_file (1, p, 1);
378 break;
379 }
380}
381
atom_selection * duplicate_ogl_selection(atom_selection *old_sel)
copy an atom selection
Definition calc.c:119
void field_question(gchar *question, GCallback handler, gpointer data)
ask the use to confirm something
Definition calc.c:103
int num_bonds(int i)
number of distinct pair(s) of atoms in selection
Definition selection.c:183
GtkTextBuffer * qmbuffer[MAXDATAQM+2]
Definition calc.c:70
void create_new_project_using_data(atom_selection *selection)
create new project using an atom selection
Definition popup.c:2060
#define MAXDATAQM
Definition calc.c:55
gboolean selection_confirmed
Definition calc.c:77
void unselect_all_atoms(glwin *view)
remove all atom(s) from selection
Definition calc.c:182
G_MODULE_EXPORT void confirm_selection(GtkDialog *dialog, gint response_id, gpointer data)
confirm that the selection is good
Definition calc.c:88
int ident
Definition calc.c:74
G_MODULE_EXPORT void create_field(GtkWidget *widg, gpointer data)
start an input creation assistant
Definition calc.c:308
GtkWidget * qm_assistant
Definition calc.c:66
gboolean force_mol
Definition calc.c:71
int num_dihedrals(int i)
number of distinct quadruplet(s) of atoms in selection
Definition selection.c:207
int idopt
Definition calc.c:72
glwin * qm_view
Definition calc.c:68
char * input_types[NINPUTS]
Definition m_tools.c:71
void restore_ogl_selection(glwin *view)
restore a saved atom selection
Definition calc.c:218
int num_angles(int i)
number of distinct triplet(s) of atoms in selection
Definition selection.c:195
atom_in_selection * new_atom_in_selection(int id, int sp)
create a selected atom
Definition selection.c:428
void create_qm_input_file(int c, int p, int s)
initialize an ab-initio MD input file creation assistant
Definition cpmd_init.c:1567
void create_classical_force_field(int p, int f)
create classical force field prepare the assistant
Definition dlp_field.c:4674
project * qm_proj
Definition calc.c:67
int icomb
Definition calc.c:75
int icalc
Definition calc.c:73
int selected_aspec
Definition popup.c:179
coord_info * qm_coord
Definition calc.c:69
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 label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
void process_selected_atom(project *this_proj, glwin *view, int id, int ac, int se, int pi)
process selected atom
Definition selection.c:514
atom_in_selection * tmp_a
Definition d_measures.c:69
int atoms[NUM_STYLES][2]
void init_default_shaders(glwin *view)
re-initialize the default OpenGL shaders
int activep
Definition global.c:159
int activev
Definition global.c:160
gboolean check_label
Definition global.c:185
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
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:472
glwin * active_glwin
Definition project.c:53
project * proj
void opengl_project_changed(int id)
change the OpenGL project
Definition update_p.c:245
project * opengl_project
Definition project.c:54
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2041
G_MODULE_EXPORT void select_unselect_atoms(GtkWidget *widg, gpointer data)
select / unselect a type of atom(s) callback GTK3
Definition popup.c:1550
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
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
#define MAX_IN_SELECTION
Maximum number of atoms in selection to display measure information.
Definition glview.h:135
gboolean pick
int check_label_numbers(project *this_proj, int types)
check how many atom label(s) are visible
Definition popup.c:1039
int step
Definition ogl_draw.c:70
void update_all_selections(glwin *view, int pi)
update the selection data: bonds, angles and dihedrals
Definition selection.c:387
void save_all_selections(glwin *view, int pi)
save all selection data
Definition selection.c:372
#define NINPUTS
Definition glwin.h:66
Function declarations for the creation of the OpenGL window.
int iask(char *question, char *lab, int id, GtkWidget *win)
enter an integer value - prepare the dialog
Definition interface.c:529
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
void active_project_changed(int id)
change the active project
Definition update_p.c:175
Definition glwin.h:875
Definition global.h:98
int b
Definition global.h:100
int c
Definition global.h:101
int a
Definition global.h:99
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * img
Definition workspace.c:70