atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
cbuild_edit.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: 'cbuild_edit.c'
24*
25* Contains:
26*
27
28 - The functions to create the crystal builder window
29
30*
31* List of functions:
32
33 int get_crystal_id (int spg);
34 int get_bravais_img_id (int spg);
35 int get_sg_num (GtkComboBox * box);
36 int read_space_group (builder_edition * cbuilder, int spg);
37 int get_group_id_from_name (gchar * sg_name);
38
39 G_MODULE_EXPORT gboolean delete_build (GtkWindow * widg, gpointer data);
40 G_MODULE_EXPORT gboolean delete_build (GtkWidget * widg, GdkEvent * event, gpointer data);
41
42 gchar * frac_string (gchar * init);
43 gchar * get_num_string (gchar * str);
44 gchar * get_so_string (space_group * spg, int id);
45
46 void adjust_lattice_parameters (builder_edition * cbuilder);
47 void adjust_so_combo (builder_edition * cbuilder);
48 void adjust_bv_img (builder_edition * cbuilder);
49 void adjust_lattice_constraints (builder_edition * cbuilder);
50 void adjust_sg_combo (builder_edition * cbuilder, int cs, int bl);
51 void prepare_crystal_builder (gpointer data);
52
53 G_MODULE_EXPORT void update_cb_vect (GtkEntry * entry, gpointer data);
54 G_MODULE_EXPORT void update_cb_box (GtkEntry * entry, gpointer data);
55 G_MODULE_EXPORT void set_lattice (GtkComboBox * box, gpointer data);
56 G_MODULE_EXPORT void set_so (GtkComboBox * box, gpointer data);
57 G_MODULE_EXPORT void set_sg (GtkComboBox * box, gpointer data);
58 G_MODULE_EXPORT void set_bl (GtkComboBox * box, gpointer data);
59 G_MODULE_EXPORT void set_cs (GtkComboBox * box, gpointer data);
60 G_MODULE_EXPORT void set_wr (GtkCheckButton * but, gpointer data);
61 G_MODULE_EXPORT void set_wr (GtkToggleButton * but, gpointer data);
62 G_MODULE_EXPORT void set_shc (GtkCheckButton * but, gpointer data);
63 G_MODULE_EXPORT void set_shc (GtkToggleButton * but, gpointer data);
64 G_MODULE_EXPORT void add_cryst_cell (GtkSpinButton * res, gpointer data);
65 G_MODULE_EXPORT void apply_build (GtkButton * but, gpointer data);
66 G_MODULE_EXPORT void close_build (GtkButton * but, gpointer data);
67 G_MODULE_EXPORT void toggle_occ (GtkCheckButton * but, gpointer data);
68 G_MODULE_EXPORT void toggle_occ (GtkToggleButton * but, gpointer data);
69 G_MODULE_EXPORT void toggle_overlap (GtkCheckButton * Button, gpointer data);
70 G_MODULE_EXPORT void toggle_overlap (GtkToggleButton * Button, gpointer data);
71 G_MODULE_EXPORT void on_rounding_changed (GtkComboBox * box, gpointer data);
72 G_MODULE_EXPORT void adjust_occupancy (GtkButton * but, gpointer data);
73 G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data);
74 G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data);
75
76 GtkWidget * prepare_lattice_grid (int type, builder_edition * cbuilder, glwin * glview);
77 GtkWidget * sg_info (int sg, gpointer data);
78 GtkWidget * create_bl_combo (int cs, gpointer data);
79 GtkWidget * builder_win (project * this_proj, gpointer data);
80
81 GtkTreeModel * so_combo_tree (space_group * spg);
82 GtkTreeModel * sg_combo_tree (int csid, int bvid);
83 GtkTreeModel * la_combo_tree ();
84
85*/
86
87#include "global.h"
88#include "interface.h"
89#include "glview.h"
90#include "cbuild_edit.h"
91#include "bind.h"
92#include "project.h"
93#include "workspace.h"
94#include "readers.h"
95
96extern G_MODULE_EXPORT void show_sg_info (GtkButton * but, gpointer data);
97
98extern void get_origin (space_group * spg);
99extern int test_lattice (builder_edition * cbuilder, cell_info * cif_cell);
100extern int build_crystal (gboolean visible, project * this_proj, int c_step, gboolean to_wrap, gboolean show_clones, cell_info * cell, GtkWidget * widg);
101
102gchar * crystal_sytems[7] = {"Triclinic", "Monoclinic", "Othorhombic", "Tetragonal", "Trigonal", "Hexagonal", "Cubic"};
103gchar * bravais_keys[7][4] = {{"Primitive", NULL, NULL, NULL},
104 {"Primitive", "Base-centered", NULL, NULL},
105 {"Primitive", "Base-centered", "Body-centered", "Face-centered"},
106 {"Primitive", "Body-centered", NULL, NULL},
107 {"Hexagonal axes", "Rhombohedral axes", NULL, NULL},
108 {"Hexagonal", NULL, NULL, NULL},
109 {"Primitive", "Body-centered", "Face-centered", NULL}};
110
111gchar * latt_info[7]={"<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; &#x2260; &#x3B2; &#x2260; &#x263;", // Triclinic
112 "<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = 90° &#x2260; &#x263;\n\tor\n&#x3B1; = &#x263; = 90° &#x2260; &#x3B2;", // Monoclinic
113 "<i>a</i> &#x2260; <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°", // Orthorhombic
114 "<i>a</i> = <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°", // Tetragonal
115 "<i>a</i> = <i>b</i> = <i>c</i>\n&#x3B1; = &#x3B2; = &#x3B3; &#x2260; 90°", // Trigonal R
116 "<i>a</i> = <i>b</i> &#x2260; <i>c</i>\n&#x3B1; = &#x3B2; = 90° and &#x263; = 120°", // Hexagonal
117 "<i>a</i> = <i>b</i> = <i>c</i>\n&#x3B1; = &#x3B2; = &#x263; = 90°"}; // Cubic
118int nsg_bv[7]={2, 13, 59, 68, 25, 27, 36};
119int min_bv[7]={0, 2, 15, 74, 142, 167, 194};
120
128int get_crystal_id (int spg)
129{
130 if (spg < 3)
131 {
132 return 0;
133 }
134 else if (spg < 16)
135 {
136 return 1;
137 }
138 else if (spg < 75)
139 {
140 return 2;
141 }
142 else if (spg < 143)
143 {
144 return 3;
145 }
146 else if (spg < 168)
147 {
148 if (groups[spg-1][0] == 'R')
149 {
150 return 4;
151 }
152 else
153 {
154 return 5;
155 }
156 }
157 else if (spg < 195)
158 {
159 return 5;
160 }
161 else
162 {
163 return 6;
164 }
165}
166
175{
176 if (spg < 3)
177 {
178 return 0;
179 }
180 else if (spg < 16)
181 {
182 if (groups[spg-1][0] == 'P')
183 {
184 return 1;
185 }
186 else
187 {
188 return 2;
189 }
190 }
191 else if (spg < 75)
192 {
193 if (groups[spg-1][0] == 'P')
194 {
195 return 3;
196 }
197 else if (groups[spg-1][0] == 'I')
198 {
199 return 4;
200 }
201 else if (groups[spg-1][0] == 'A' || groups[spg-1][0] == 'C')
202 {
203 return 5;
204 }
205 else
206 {
207 return 6;
208 }
209 }
210 else if (spg < 143)
211 {
212 if (groups[spg-1][0] == 'P')
213 {
214 return 7;
215 }
216 else
217 {
218 return 8;
219 }
220 }
221 else if (spg < 168)
222 {
223 if (groups[spg-1][0] == 'R')
224 {
225 return 9;
226 }
227 else
228 {
229 return 10;
230 }
231 }
232 else if (spg < 195)
233 {
234 return 10;
235 }
236 else
237 {
238 if (groups[spg-1][0] == 'P')
239 {
240 return 11;
241 }
242 else if (groups[spg-1][0] == 'I')
243 {
244 return 12;
245 }
246 else
247 {
248 return 13;
249 }
250 }
251}
252
260gchar * frac_string (gchar * init)
261{
262 gchar * end = substitute_string (init, "1/2", "&#189;");
263 end = substitute_string (end, "1/4", "&#188;");
264 end = substitute_string (end, "3/4", "&#190;");
265 end = substitute_string (end, "1/3", "&#8531;");
266 end = substitute_string (end, "2/3", "&#8532;");
267 end = substitute_string (end, "1/6", "&#8537;");
268 end = substitute_string (end, "5/6", "&#8538;");
269 end = substitute_string (end, "1/8", "&#8539;");
270 end = substitute_string (end, "3/8", "&#8540;");
271 end = substitute_string (end, "5/8", "&#8541;");
272 end = substitute_string (end, "7/8", "&#8542;");
273 return g_strdup_printf ("%s", end);
274}
275
283gchar * get_num_string (gchar * str)
284{
285 str = replace_markup (str, "65", "6<sub>5</sub>");
286 str = replace_markup (str, "64", "6<sub>4</sub>");
287 str = replace_markup (str, "63", "6<sub>3</sub>");
288 str = replace_markup (str, "62", "6<sub>2</sub>");
289 str = replace_markup (str, "61", "6<sub>1</sub>");
290 str = replace_markup (str, "43", "4<sub>3</sub>");
291 str = replace_markup (str, "42", "4<sub>2</sub>");
292 str = replace_markup (str, "41", "4<sub>1</sub>");
293 str = replace_markup (str, "32", "3<sub>2</sub>");
294 str = replace_markup (str, "31", "3<sub>1</sub>");
295 return substitute_string (str, "21", "2<sub>1</sub>");
296}
297
306gchar * get_so_string (space_group * spg, int id)
307{
308 gchar * str = replace_markup (spg -> settings[id].name, "s", "/");
309 str = get_num_string (str);
310 str = substitute_string (str, "_", NULL);
311 if (spg -> settings[id].origin)
312 {
313 str = g_strdup_printf ("%s (%d)", str, spg -> settings[id].origin);
314 }
315 return str;
316}
317
325GtkTreeModel * so_combo_tree (space_group * spg)
326{
327 GtkTreeIter iter;
328 GtkTreeStore * store;
329 int i;
330 store = gtk_tree_store_new (1, G_TYPE_STRING);
331 if (! spg) return GTK_TREE_MODEL (store);
332 if (spg -> nums > 1)
333 {
334 for (i=0; i<spg -> nums; i++)
335 {
336 gtk_tree_store_append (store, &iter, NULL);
337 gtk_tree_store_set (store, & iter, 0, get_so_string (spg, i), -1);
338 }
339 }
340 else
341 {
342 gtk_tree_store_append (store, &iter, NULL);
343 gtk_tree_store_set (store, & iter, 0, groups[spg -> id-1], -1);
344 }
345 return GTK_TREE_MODEL (store);
346}
347
356GtkTreeModel * sg_combo_tree (int csid, int bvid)
357{
358 GtkTreeIter iter;
359 GtkTreeStore * store;
360 int i;
361 gboolean doit;
362 gchar * str;
363 store = gtk_tree_store_new (1, G_TYPE_STRING);
364 for (i=min_bv[csid]; i<min_bv[csid]+nsg_bv[csid]; i++)
365 {
366 doit = FALSE;
367 if (! bvid || csid == 5)
368 {
369 doit = TRUE;
370 }
371 else
372 {
373 if (csid == 1 || csid == 3)
374 {
375 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] != 'P')) doit = TRUE;
376 }
377 else if (csid == 2)
378 {
379 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'A') || (bvid == 2 && groups[i][0] == 'C') ||
380 (bvid == 3 && groups[i][0] == 'I') || (bvid == 4 && groups[i][0] == 'F'))
381 {
382 doit = TRUE;
383 }
384 }
385 else if (csid == 4)
386 {
387 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'R')) doit = TRUE;
388 }
389 else if (csid == 6)
390 {
391 if ((bvid == 1 && groups[i][0] == 'P') || (bvid == 2 && groups[i][0] == 'I') || (bvid == 3 && groups[i][0] == 'F'))
392 {
393 doit = TRUE;
394 }
395 }
396 }
397 if (doit)
398 {
399 gtk_tree_store_append (store, &iter, NULL);
400 str = g_strdup_printf ("%3d: %s", i+1, groups[i]);
401 gtk_tree_store_set (store, & iter, 0, str, -1);
402 g_free (str);
403 }
404 }
405 return GTK_TREE_MODEL (store);
406}
407
413GtkTreeModel * la_combo_tree ()
414{
415 GtkTreeIter iter;
416 GtkTreeStore *store;
417 gchar * lat[2]={"<b><i>a</i></b>, <b><i>b</i></b>, <b><i>c</i></b>, &#x3B1; &#x3B2; &#x263;", "Vectors"};
418 int i;
419 store = gtk_tree_store_new (1, G_TYPE_STRING);
420 for (i=0; i<2; i++)
421 {
422 gtk_tree_store_append (store, &iter, NULL);
423 gtk_tree_store_set (store, & iter, 0, lat[i], -1);
424 }
425 return GTK_TREE_MODEL (store);
426}
427
435int get_sg_num (GtkComboBox * box)
436{
437 GValue val = {0, };
438 GtkTreeModel * cmodel = gtk_combo_box_get_model (box);
439 GtkTreeIter iter;
440 gchar * str = NULL;
441 gchar * num = NULL;
442 int i = 0;
443 if (gtk_combo_box_get_active_iter (box, & iter))
444 {
445 gtk_tree_model_get_value (cmodel, & iter, 0, & val);
446 str = g_strdup_printf ("%s", (char *)g_value_get_string (& val));
447 if (str)
448 {
449 num = g_strdup_printf ("%c%c%c", str[0], str[1], str[2]);
450 i = (int) string_to_double ((gpointer)num);
451 g_free (str);
452 g_free (num);
453 }
454 }
455 return i;
456}
457
466{
467 int i, j, k;
468 j = get_sg_num (GTK_COMBO_BOX(cbuilder -> sg_combo));
469 k = get_crystal_id (j);
470 box_info * box = & cbuilder -> cell.box[0];
471 switch (k)
472 {
473 case 1:
474 box -> param[1][0] = 90.0;
475 box -> vect[0][1] = box -> vect[0][2] = 0.0;
476 box -> vect[2][0] = box -> vect[2][1] = 0.0;
477 break;
478 case 2:
479 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
480 box -> vect[0][1] = box -> vect[0][2] = 0.0;
481 box -> vect[1][0] = box -> vect[1][2] = 0.0;
482 box -> vect[2][0] = box -> vect[2][1] = 0.0;
483 break;
484 case 3:
485 box -> param[0][1] = box -> param[0][0];
486 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
487 break;
488 case 4:
489 box -> param[0][1] = box -> param[0][0];
490 if (cbuilder -> cell.sp_group -> name[0] == 'R')
491 {
492 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 0.0;
493 }
494 else
495 {
496 box -> param[1][0] = box -> param[1][1] = 90.0;
497 box -> param[1][2] = 120.0;
498 }
499 box -> vect[1][1] = box -> vect[0][0];
500 box -> vect[0][1] = box -> vect[0][2] = 0.0;
501 box -> vect[1][0] = box -> vect[1][2] = 0.0;
502 break;
503 case 5:
504 box -> param[0][1] = box -> param[0][0];
505 box -> param[1][0] = box -> param[1][1] = 90.0;
506 box -> param[1][2] = 120.0;
507 box -> vect[0][1] = box -> vect[0][2] = 0.0;
508 box -> vect[1][0] = box -> vect[1][2] = 0.0;
509 break;
510 case 6:
511 box -> param[0][1] = box -> param[0][2] = box -> param[0][0];
512 box -> param[1][0] = box -> param[1][1] = box -> param[1][2] = 90.0;
513 box -> vect[1][1] = box -> vect[2][2] = box -> vect[0][0];
514 box -> vect[0][1] = box -> vect[0][2] = 0.0;
515 box -> vect[1][0] = box -> vect[1][2] = 0.0;
516 box -> vect[2][0] = box -> vect[2][1] = 0.0;
517 break;
518 default:
519 break;
520 }
521 if (cbuilder -> cell.ltype)
522 {
523 for (i=0; i<3; i++)
524 {
525 for (j=0; j<3; j++)
526 {
527 if (cbuilder -> ventry[i][j])
528 {
529 if (GTK_IS_WIDGET(cbuilder -> ventry[i][j]))
530 {
531 update_entry_double (GTK_ENTRY(cbuilder -> ventry[i][j]), box -> vect[i][j]);
532 }
533 }
534 }
535 }
536 }
537 else
538 {
539 for (i=0; i<2; i++)
540 {
541 for (j=0; j<3; j++)
542 {
543 if (cbuilder -> bentry[i][j])
544 {
545 if (GTK_IS_WIDGET(cbuilder -> bentry[i][j]))
546 {
547 update_entry_double (GTK_ENTRY(cbuilder -> bentry[i][j]), box -> param[i][j]);
548 }
549 }
550 }
551 }
552 if (cbuilder -> bentry[0][1])
553 {
554 if (GTK_IS_WIDGET(cbuilder -> bentry[0][1]))
555 {
556 widget_set_sensitive (cbuilder -> bentry[0][1], (k > 2) ? 0 : 1);
557 if (k > 2) update_entry_text (GTK_ENTRY(cbuilder -> bentry[0][1]), "");
558 }
559 }
560 if (cbuilder -> bentry[0][2])
561 {
562 if (GTK_IS_WIDGET(cbuilder -> bentry[0][2]))
563 {
564 widget_set_sensitive (cbuilder -> bentry[0][2], (k > 5 || (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')) ? 0 : 1);
565 if (k > 5 || (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')) update_entry_text (GTK_ENTRY(cbuilder -> bentry[0][2]), "");
566 }
567 }
568 for (i=0; i<3; i++)
569 {
570 if (cbuilder -> bentry[1][i])
571 {
572 if (GTK_IS_WIDGET(cbuilder -> bentry[1][i]))
573 {
574 widget_set_sensitive (cbuilder -> bentry[1][i], (k > 1) || (k == 1 && ! i) ? 0 : 1);
575 if (k == 4 && cbuilder -> cell.sp_group -> name[0] == 'R')
576 {
577 if (! i)
578 {
579 widget_set_sensitive (cbuilder -> bentry[1][i], 1);
580 }
581 else
582 {
583 update_entry_text (GTK_ENTRY(cbuilder -> bentry[1][i]), "");
584 }
585 }
586 }
587 }
588 }
589 }
590}
591
600G_MODULE_EXPORT void update_cb_vect (GtkEntry * entry, gpointer data)
601{
602 tint * id = (tint *)data;
603 const gchar * m = entry_get_text (entry);
604 double v = string_to_double ((gpointer)m);
605 get_project_by_id(id -> a) -> modelgl -> builder_win -> cell.box[0].vect[id -> b][id -> c] = v;
606 update_entry_double (entry, v);
607}
608
617G_MODULE_EXPORT void update_cb_box (GtkEntry * entry, gpointer data)
618{
619 tint * id = (tint *)data;
620 const gchar * m = entry_get_text (entry);
621 double v = string_to_double ((gpointer)m);
622 if (v >= 0.0)
623 {
624 get_project_by_id(id -> a) -> modelgl -> builder_win -> cell.box[0].param[id -> b][id -> c] = v;
625 }
626 update_entry_double (entry, v);
627}
628
638GtkWidget * prepare_lattice_grid (int type, builder_edition * cbuilder, glwin * glview)
639{
640 GtkWidget * table = gtk_grid_new ();
641 int i, j, k;
642 k = 0;
643 for (i=0; i<3; i++)
644 {
645 for (j=0; j<3; j++, k++)
646 {
647 if (i < 2) cbuilder -> cell.box[0].param[i][j] = 0.0;
648 cbuilder -> cell.box[0].vect[i][j] = 0.0;
649 t_box[k].a = i;
650 t_box[k].b = j;
651 }
652 }
653 cbuilder -> cell.ltype = type;
654 if (cbuilder -> cell.ltype)
655 {
656 k = 0;
657 for (i=0; i<4; i++)
658 {
659 if (i > 0)
660 {
661 gtk_grid_attach (GTK_GRID (table), markup_label(vect_name[i-1], 20, -1, 0.0, 0.5), 0, i, 1, 1);
662 }
663 for (j=0; j<4; j++)
664 {
665 if (j > 0)
666 {
667 if (i == 0)
668 {
669 gtk_grid_attach (GTK_GRID (table), markup_label(vect_comp[j-1], -1, 20, 0.5, 0.5), j, 0, 1, 1);
670 }
671 else
672 {
673 cbuilder -> ventry[i-1][j-1] = create_entry (G_CALLBACK(update_cb_vect), 100, 15, FALSE, & cbuilder -> pointers[i][j]);
674 update_entry_double (GTK_ENTRY(cbuilder -> ventry[i-1][j-1]), cbuilder -> cell.box[0].vect[i-1][j-1]);
675 gtk_grid_attach (GTK_GRID (table), cbuilder -> ventry[i-1][j-1], j, i, 1, 1);
676 k ++;
677 }
678 }
679 }
680 }
681 }
682 else
683 {
684 k = 0;
685 for (i=0; i<2; i++)
686 {
687 //gtk_grid_attach (GTK_GRID (table), markup_label(box_p[i], -1, 50, 0.5, 0.5), 1, i+2*i, 1, 1);
688 gtk_grid_attach (GTK_GRID (table), markup_label(" ", 20, -1, 0.5, 0.5), 0, i, 1, 1);
689 for (j=0; j<3; j++, k++)
690 {
691 gtk_grid_attach (GTK_GRID (table), markup_label(box_prop[i][j], -1, -1, 0.5, 0.5), j+1, i+2*i, 1, 1);
692 cbuilder -> bentry[i][j] = create_entry (G_CALLBACK(update_cb_box), 100, 15, FALSE, & cbuilder -> pointers[i][j]);
693 update_entry_double (GTK_ENTRY(cbuilder -> bentry[i][j]), cbuilder -> cell.box[0].param[i][j]);
694 gtk_grid_attach (GTK_GRID (table), cbuilder -> bentry[i][j], j+1, i+2*i+1, 1, 1);
695 }
696 }
697 adjust_lattice_parameters (cbuilder);
698 }
699 return table;
700}
701
710G_MODULE_EXPORT void set_lattice (GtkComboBox * box, gpointer data)
711{
712 tint * id = (tint *) data;
713 glwin * view = get_project_by_id(id -> a) -> modelgl;
714 builder_edition * cbuilder = view -> builder_win;
715 cbuilder -> lattice_grid = destroy_this_widget (cbuilder -> lattice_grid);
716 cbuilder -> lattice_grid = prepare_lattice_grid (combo_get_active ((GtkWidget *)box), cbuilder, view);
717 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> lattice_box, cbuilder -> lattice_grid, FALSE, FALSE, 5);
718 show_the_widgets (cbuilder -> lattice_grid);
719}
720
729G_MODULE_EXPORT void set_so (GtkComboBox * box, gpointer data)
730{
731 tint * id = (tint *) data;
732 builder_edition * cbuilder = get_project_by_id(id -> a) -> modelgl -> builder_win;
733 int i = combo_get_active ((GtkWidget *)box);
734 gchar * str = g_strdup_printf ("(%s,%s,%s)", cbuilder -> cell.sp_group -> settings[i].pos[0],
735 cbuilder -> cell.sp_group -> settings[i].pos[1],
736 cbuilder -> cell.sp_group -> settings[i].pos[2]);
737 cbuilder -> so_info = destroy_this_widget(cbuilder -> so_info);
738 cbuilder -> so_info = markup_label(frac_string(str), -1, -1, 0.5, 0.5);
739 g_free (str);
740 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, cbuilder -> so_info, FALSE, FALSE, 10);
741 show_the_widgets (cbuilder -> so_info);
742 cbuilder -> cell.sp_group -> sid = i;
743 get_origin (cbuilder -> cell.sp_group);
744}
745
754GtkWidget * sg_info (int sg, gpointer data)
755{
756 gchar * str = g_strdup_printf ("%s group info", groups[sg]);
757 GtkWidget * mlab = markup_label(str, -1, -1, 0.5, 0.5);
758 GtkWidget * mbut = create_button (NULL, IMG_NONE, NULL, 50, -1, GTK_RELIEF_NORMAL, G_CALLBACK(show_sg_info), data);
760 show_the_widgets (mbut);
761 return mbut;
762}
763
772int read_space_group (builder_edition * cbuilder, int spg)
773{
774 // Read file
775 gchar * sgfile = substitute_string(groups[spg], "<sub>", NULL);
776 sgfile = substitute_string(sgfile, "</sub>", NULL);
777 sgfile = substitute_string(sgfile, "/", "s");
778#ifdef G_OS_WIN32
779 sgfile = g_strdup_printf ("%s\\space_groups\\%d-%s.sgl", PACKAGE_LIB_DIR, spg+1, sgfile);
780#else
781 sgfile = g_strdup_printf ("%s/space_groups/%d-%s.sgl", PACKAGE_LIB_DIR, spg+1, sgfile);
782#endif
783 int res;
784 if (cbuilder)
785 {
786 cbuilder -> cell.sp_group = read_sg_xml_file (sgfile);
787 res = (cbuilder -> cell.sp_group) ? 1 : 0;
788 }
789 else if (this_reader)
790 {
791 this_reader -> lattice.sp_group = read_sg_xml_file (sgfile);
792 res = (this_reader -> lattice.sp_group) ? 1 : 0;
793 }
794 g_free (sgfile);
795 return res;
796}
797
805int get_group_id_from_name (gchar * sg_name)
806{
807 int i;
808 for (i=0; i<230; i++)
809 {
810 if (g_strcmp0(groups[i], sg_name) == 0) return i+1;
811 }
812 return 0;
813}
814
823{
824 GtkTreeModel * model = so_combo_tree (cbuilder -> cell.sp_group);
825 gtk_combo_box_set_model (GTK_COMBO_BOX(cbuilder -> so_combo), model);
826 g_object_unref (model);
827 combo_set_active (cbuilder -> so_combo, 0);
828 combo_set_markup (cbuilder -> so_combo);
829 widget_set_sensitive (cbuilder -> so_combo, cbuilder -> cell.sp_group -> nums-1);
830 if (cbuilder -> cell.sp_group) get_origin (cbuilder -> cell.sp_group);
831}
832
841{
842 if (cbuilder -> bv_img) cbuilder -> bv_img = destroy_this_widget(cbuilder -> bv_img);
843 cbuilder -> bv_img = gtk_image_new_from_file (bravais_img[get_bravais_img_id(cbuilder -> cell.sp_group -> id)]);
844#ifdef GTK4
845 gtk_widget_set_size_request (cbuilder -> bv_img, 200, 200);
846 gtk_widget_set_hexpand (cbuilder -> bv_img, TRUE);
847 gtk_widget_set_vexpand (cbuilder -> bv_img, TRUE);
848#endif
849 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[1], cbuilder -> bv_img, FALSE, FALSE, 5);
850}
851
860{
861 if (cbuilder -> ltc_cons) cbuilder -> ltc_cons = destroy_this_widget(cbuilder -> ltc_cons);
862 gchar * str = g_strdup_printf ("<b>%s</b>", latt_info[get_crystal_id (cbuilder -> cell.sp_group -> id)]);
863 cbuilder -> ltc_cons = markup_label(str, 150, -1, 0.0, 0.5);
864 g_free (str);
865 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, cbuilder -> ltc_cons, FALSE, FALSE, 5);
866}
867
876G_MODULE_EXPORT void set_sg (GtkComboBox * box, gpointer data)
877{
878 tint * id = (tint *) data;
879 builder_edition * cbuilder = get_project_by_id(id -> a) -> modelgl -> builder_win;
880 int i = get_sg_num(box);
881 if (i)
882 {
883 cbuilder -> sg_but = destroy_this_widget(cbuilder -> sg_but);
884 if (read_space_group (cbuilder, i-1))
885 {
886 cbuilder -> sg_but = sg_info (i-1, data);
887 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, cbuilder -> sg_but, FALSE, FALSE, 10);
888 if (cbuilder -> bv_box[0]) adjust_lattice_constraints (cbuilder);
889 if (cbuilder -> bv_box[1]) adjust_bv_img (cbuilder);
890 show_the_widgets (cbuilder -> bh_box);
891 if (cbuilder -> so_combo) adjust_so_combo (cbuilder);
892 if (cbuilder -> lattice_grid) adjust_lattice_parameters (cbuilder);
893 }
894 else
895 {
896 // Error reading file
897 show_error ("Cannot read space group *.sgl file ?!\nPlease check the program library !", 0, cbuilder -> win);
898 }
899 }
900}
901
911void adjust_sg_combo (builder_edition * cbuilder, int cs, int bl)
912{
913 GtkTreeModel * model = sg_combo_tree (cs, bl);
914 gtk_combo_box_set_model (GTK_COMBO_BOX(cbuilder -> sg_combo), model);
915 g_object_unref (model);
916 combo_set_active (cbuilder -> sg_combo, 0);
917 combo_set_markup (cbuilder -> sg_combo);
918 adjust_lattice_parameters (cbuilder);
919}
920
929G_MODULE_EXPORT void set_bl (GtkComboBox * box, gpointer data)
930{
931 builder_edition * cbuilder = (builder_edition *)data;
932 int i, j;
933 i = combo_get_active (cbuilder -> cs_combo);
934 j = combo_get_active ((GtkWidget *)box);
935 adjust_sg_combo (cbuilder, i, j);
936}
937
946GtkWidget * create_bl_combo (int cs, gpointer data)
947{
948 GtkWidget * cbox = create_combo();
949 int i;
950 combo_text_append (cbox, "All");
951 for (i=0; i<4; i++)
952 {
953 if (bravais_keys[cs][i]) combo_text_append (cbox, bravais_keys[cs][i]);
954 }
955 i = (cs == 0 || cs == 5) ? 0 : 1;
957 combo_set_active (cbox, ! i);
958 g_signal_connect (G_OBJECT(cbox), "changed", G_CALLBACK(set_bl), data);
959 gtk_widget_set_size_request (cbox, 150, 25);
960 return cbox;
961}
962
971G_MODULE_EXPORT void set_cs (GtkComboBox * box, gpointer data)
972{
973 builder_edition * cbuilder = (builder_edition *)data;
974 int i = combo_get_active ((GtkWidget *)box);
975 cbuilder -> bl_combo = destroy_this_widget(cbuilder -> bl_combo);
976 cbuilder -> bl_combo = create_bl_combo (i, data);
977 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, cbuilder -> bl_combo, FALSE, FALSE, 0);
978 adjust_sg_combo (cbuilder, i, 0);
979 show_the_widgets (cbuilder -> bl_combo);
980}
981
982#ifdef GTK4
991G_MODULE_EXPORT void set_wr (GtkCheckButton * but, gpointer data)
992#else
1001G_MODULE_EXPORT void set_wr (GtkToggleButton * but, gpointer data)
1002#endif
1003{
1004 builder_edition * cbuilder = (builder_edition * )data;
1005 cbuilder -> wrap = button_get_status ((GtkWidget *)but);
1006}
1007
1008#ifdef GTK4
1017G_MODULE_EXPORT void set_shc (GtkCheckButton * but, gpointer data)
1018#else
1027G_MODULE_EXPORT void set_shc (GtkToggleButton * but, gpointer data)
1028#endif
1029{
1030 builder_edition * cbuilder = (builder_edition * )data;
1031 cbuilder -> clones = button_get_status ((GtkWidget *)but);
1032}
1033
1042G_MODULE_EXPORT void add_cryst_cell (GtkSpinButton * res, gpointer data)
1043{
1044 tint * bid = (tint *)data;
1045 builder_edition * cbuilder = get_project_by_id(bid -> a) -> modelgl -> builder_win;
1046 cbuilder -> cell.cextra[bid -> b] = gtk_spin_button_get_value_as_int(res);
1047}
1048
1057G_MODULE_EXPORT void apply_build (GtkButton * but, gpointer data)
1058{
1059 int id = GPOINTER_TO_INT(data);
1060 project * this_proj = get_project_by_id(id);
1061 if (test_lattice(this_proj -> modelgl -> builder_win, NULL))
1062 {
1063 crystal_dist_chk = TRUE;
1064 crystal_crowded = FALSE;
1065 crystal_low_warning = TRUE;
1066 build_crystal (TRUE, this_proj, 0, this_proj -> modelgl -> builder_win -> wrap, this_proj -> modelgl -> builder_win -> clones,
1067 & this_proj -> modelgl -> builder_win -> cell, this_proj -> modelgl -> builder_win -> win);
1068 }
1069}
1070
1079G_MODULE_EXPORT void close_build (GtkButton * but, gpointer data)
1080{
1081 int id = GPOINTER_TO_INT(data);
1082 project * this_proj = get_project_by_id(id);
1083 this_proj -> modelgl -> search_widg[7] = free_this_search_data (this_proj -> modelgl -> search_widg[7]);
1084 this_proj -> modelgl -> builder_win -> win = destroy_this_widget(this_proj -> modelgl -> builder_win -> win);
1085 g_free (this_proj -> modelgl -> builder_win);
1086 this_proj -> modelgl -> builder_win = NULL;
1087}
1088
1089#ifdef GTK4
1098G_MODULE_EXPORT gboolean delete_build (GtkWindow * widg, gpointer data)
1099#else
1109G_MODULE_EXPORT gboolean delete_build (GtkWidget * widg, GdkEvent * event, gpointer data)
1110#endif
1111{
1112 close_build (NULL, data);
1113 return TRUE;
1114}
1115
1117
1118#ifdef GTK4
1127G_MODULE_EXPORT void toggle_occ (GtkCheckButton * but, gpointer data)
1128#else
1137G_MODULE_EXPORT void toggle_occ (GtkToggleButton * but, gpointer data)
1138#endif
1139{
1140 dint * cid = (dint *)data;
1141 get_project_by_id(cid -> a) -> modelgl -> builder_win -> occupancy = cid -> b;
1142}
1143
1144#ifdef GTK4
1153G_MODULE_EXPORT void toggle_overlap (GtkCheckButton * Button, gpointer data)
1154#else
1163G_MODULE_EXPORT void toggle_overlap (GtkToggleButton * Button, gpointer data)
1164#endif
1165{
1166 builder_edition * cbuilder = (builder_edition * )data;
1167 cbuilder -> overlapping = button_get_status ((GtkWidget *)Button);
1168}
1169
1178G_MODULE_EXPORT void on_rounding_changed (GtkComboBox * box, gpointer data)
1179{
1180 builder_edition * cbuilder = (builder_edition *)data;
1181 cbuilder -> rounding = combo_get_active ((GtkWidget *)box);
1182}
1183
1192G_MODULE_EXPORT void adjust_occupancy (GtkButton * but, gpointer data)
1193{
1194 project * this_proj = (project *)data;
1195 builder_edition * cbuilder = this_proj -> modelgl -> builder_win;
1196 GtkWidget * info = dialogmodal ("Occupancy set-up", GTK_WINDOW(cbuilder -> win));
1197 GtkWidget * vbox, * hbox;
1199 gchar * boccup[5] = {"<b>Random for the initial cell only</b>",
1200 "<b>Random cell by cell</b>",
1201 "<b>Completely random</b>",
1202 "<b>Successively</b>",
1203 "<b>Alternatively</b>"};
1204 gchar * occup[5] = {"<i>Sites are filled randomly in the initial cell only,\n"
1205 " then the initial cell is simply replicated.</i>",
1206 "<i>Sites are filled randomly for each cell, cell by cell separately.</i>",
1207 "<i>Sites are filled randomly for the entire network,\n"
1208 " the final crystal is considered as a whole.</i>",
1209 "<i>Sites are filled successively: all object(s) A, then all object(s) B ... </i>",
1210 "<i>Sites are filled alternatively: object A, object B, object A ...</i>"};
1211
1212 GtkWidget * occ_but[5];
1213 int i;
1214 for (i=0; i<5; i++)
1215 {
1216 hbox = create_hbox(0);
1217 occp[i].a = this_proj -> id;
1218 occp[i].b = i;
1219 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1220#ifdef GTK4
1221 occ_but[i] = check_button (boccup[i], -1, 25, FALSE, G_CALLBACK(toggle_occ), & occp[i]);
1222 if (i)
1223 {
1224 gtk_check_button_set_group ((GtkCheckButton *)occ_but[i], (GtkCheckButton *)occ_but[0]);
1225 }
1226#else
1227 if (! i)
1228 {
1229 occ_but[i] = radio_button (boccup[i], -1, 25, FALSE, G_CALLBACK(toggle_occ), & occp[i]);
1230 }
1231 else
1232 {
1233 occ_but[i] = gtk_radio_button_new_from_widget (GTK_RADIO_BUTTON(occ_but[0]));
1234 add_container_child (CONTAINER_BUT, occ_but[i], markup_label(boccup[i], -1, 25, 0.0, 0.5));
1235 }
1236#endif
1237 if (i) g_signal_connect (G_OBJECT(occ_but[i]), "toggled", G_CALLBACK(toggle_occ), & occp[i]);
1238#ifdef GTK4
1239 gtk_button_set_has_frame (GTK_BUTTON(occ_but[i]), FALSE);
1240#endif
1241 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, occ_but[i], FALSE, FALSE, 5);
1242 hbox = create_hbox(0);
1243 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1244 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (occup[i], 200, -1, 0.5, 0.5), FALSE, FALSE, 50);
1245 }
1246 i = cbuilder -> occupancy;
1247 button_set_status (occ_but[i], TRUE);
1248 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, check_button ("<b>Allow overlapping</b>", -1, 25, cbuilder -> overlapping, G_CALLBACK(toggle_overlap), (gpointer)cbuilder), FALSE, FALSE, 0);
1249 hbox = create_hbox(0);
1250 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1251 gchar * overlap = "<i>Instead of ensuring that sites are filled by a single object,\n"
1252 "this allows object(s) to share the same crystalline position. \n"
1253 "The option above describes how filled and empty positions alternate.</i>\n";
1254 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label (overlap, 200, -1, 0.5, 0.5), FALSE, FALSE, 50);
1255
1256 // Rounding occupancy here
1257 hbox = create_hbox(0);
1258 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 10);
1259 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label ("<b>Occupancy rounding:</b>", 200, -1, 0.5, 0.5), FALSE, FALSE, 0);
1260 GtkWidget * rounding = create_combo ();
1261 gtk_widget_set_size_request (rounding, -1, 30);
1262 for (i=0; i<3; i++) combo_text_append (rounding, cif_occupancies[i]);
1263 combo_set_active (rounding, cbuilder -> rounding);
1264 g_signal_connect(G_OBJECT(rounding), "changed", G_CALLBACK(on_rounding_changed), & cbuilder);
1265 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rounding, FALSE, FALSE, 10);
1266 gchar * str = g_strdup_printf ("\t<b>Lowest integer: </b>\n"
1267 "\t\t Occupancy %s\n\t\t\t ex:\t ⌊8.75⌋ = 8\n"
1268 "\t<b>Highest integer: </b>\n"
1269 "\t\t Occupancy %s\n\t\t\t ex:\t ⌈5.39⌉ = 6\n"
1270 "\t<b>Nearest integer: </b>\n"
1271 "\t\t Occupancy %s\n\t\t\t ex:\t ⌊6.82⌉ = 7\t\t and\t ⌊4.31⌉ = 4\n"
1272 "\n\t\t%s\n", cif_occ[0], cif_occ[1], cif_occ[2], cif_sites[0]);
1273 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, markup_label (str, 450, -1, 0.5, 0.5), FALSE, FALSE, 5);
1274 g_free (str);
1275
1276 show_the_widgets (info);
1277 run_this_gtk_dialog (info, G_CALLBACK(run_destroy_dialog), NULL);
1278}
1279
1288GtkWidget * builder_win (project * this_proj, gpointer data)
1289{
1290 int i, j;
1291 gchar * str = (! this_proj -> natomes) ? g_strdup_printf ("Crystal builder - %s", this_proj -> name) : g_strdup_printf ("Crystal builder");
1292 builder_edition * cbuilder = this_proj -> modelgl -> builder_win;
1293 GtkWidget * win = create_win (str, this_proj -> modelgl -> win, FALSE, FALSE);
1294 g_free (str);
1295 GtkWidget * vbox = create_vbox (BSEP);
1297
1298 cbuilder -> bh_box = create_hbox(0);
1299 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> bh_box, FALSE, FALSE, 0);
1300 for (i=0; i<2; i++)
1301 {
1302 cbuilder -> bv_box[i] = create_vbox (BSEP);
1303 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bh_box, cbuilder -> bv_box[i], FALSE, FALSE, 0);
1304 }
1305
1306 // Crystal system
1307 GtkWidget * hbox = create_hbox(0);
1308 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], hbox, FALSE, FALSE, 0);
1309 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Crystal system:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1310 cbuilder -> cs_combo = create_combo();
1311
1312 for (i=0; i<7;i++) combo_text_append (cbuilder -> cs_combo, crystal_sytems[i]);
1313 combo_set_active (cbuilder -> cs_combo, 0);
1314 gtk_widget_set_size_request (cbuilder -> cs_combo, 150, 25);
1315 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> cs_combo, FALSE, FALSE, 0);
1316 g_signal_connect (G_OBJECT(cbuilder -> cs_combo), "changed", G_CALLBACK(set_cs), (gpointer)cbuilder);
1317
1318 // Bravais lattice
1319 cbuilder -> bl_box = create_hbox(0);
1320 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], cbuilder -> bl_box, FALSE, FALSE, 0);
1321 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, markup_label("Bravais lattice:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1322 cbuilder -> bl_combo = create_bl_combo (0, (gpointer)cbuilder);
1323 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> bl_box, cbuilder -> bl_combo, FALSE, FALSE, 0);
1324
1325 cbuilder -> ltc_box = create_hbox (0);
1326 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, markup_label("Lattice constraints: ", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1327 str = g_strdup_printf ("<b>%s</b>", latt_info[get_crystal_id (1)]);
1328 cbuilder -> ltc_cons = markup_label(str, 150, -1, 0.0, 0.5);
1329 g_free (str);
1330 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> ltc_box, cbuilder -> ltc_cons, FALSE, FALSE, 5);
1331 add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[0], cbuilder -> ltc_box, FALSE, FALSE, 5);
1332
1333 // cbuilder -> bv_img = gtk_image_new_from_file (bravais_img[get_bravais_img_id(1)]);
1334 // add_box_child_start (GTK_ORIENTATION_VERTICAL, cbuilder -> bv_box[1], cbuilder -> bv_img, FALSE, FALSE, 5);
1335
1336 // Space group
1337 cbuilder -> sg_box = create_hbox(0);
1338 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> sg_box, FALSE, FALSE, 0);
1339 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, markup_label("Space group:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1340 GtkTreeModel * model = sg_combo_tree (0, 0);
1341 cbuilder -> sg_combo = gtk_combo_box_new_with_model (model);
1342 g_object_unref (model);
1343 GtkCellRenderer * renderer = gtk_cell_renderer_combo_new ();
1344 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> sg_combo), renderer, TRUE);
1345 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> sg_combo), renderer, "text", 0, NULL);
1346 g_signal_connect (G_OBJECT(cbuilder -> sg_combo), "changed", G_CALLBACK(set_sg), data);
1347 gtk_widget_set_size_request (cbuilder -> sg_combo, 150, 25);
1348 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> sg_box, cbuilder -> sg_combo, FALSE, FALSE, 0);
1349 combo_set_active (cbuilder -> sg_combo, 0);
1350 combo_set_markup (cbuilder -> sg_combo);
1351 // Space group option
1352 cbuilder -> so_box = create_hbox(0);
1353 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, cbuilder -> so_box, FALSE, FALSE, 0);
1354 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, markup_label("Settings:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1355 model = so_combo_tree (cbuilder -> cell.sp_group);
1356 cbuilder -> so_combo = gtk_combo_box_new_with_model (model);
1357 g_object_unref (model);
1358 renderer = gtk_cell_renderer_combo_new ();
1359 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> so_combo), renderer, TRUE);
1360 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> so_combo), renderer, "text", 0, NULL);
1361 gtk_widget_set_size_request (cbuilder -> so_combo, 150, 25);
1362 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, cbuilder -> so_box, cbuilder -> so_combo, FALSE, FALSE, 0);
1363 combo_set_active (cbuilder -> so_combo, 0);
1364 widget_set_sensitive (cbuilder -> so_combo, 0);
1365 g_signal_connect (G_OBJECT(cbuilder -> so_combo), "changed", G_CALLBACK(set_so), data);
1366 combo_set_markup (cbuilder -> so_combo);
1367
1368 for (i=0; i<3; i++)
1369 {
1370 cbuilder -> cell.cextra[i] = 1;
1371 for (j=0; j<3; j++)
1372 {
1373 cbuilder -> pointers[i][j].a = this_proj -> id;
1374 cbuilder -> pointers[i][j].b = i;
1375 cbuilder -> pointers[i][j].c = j;
1376 }
1377 }
1378 if (cbuilder -> cell.sp_group) get_origin (cbuilder -> cell.sp_group);
1379 // Lattice parameters
1380 hbox = create_hbox(0);
1381 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1382 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Lattice parameters:", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1383 cbuilder -> lattice_box = create_vbox (BSEP);
1384 GtkTreeModel * lmodel = la_combo_tree ();
1385 cbuilder -> la_combo = gtk_combo_box_new_with_model (lmodel);
1386 g_object_unref (lmodel);
1387 renderer = gtk_cell_renderer_combo_new ();
1388 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (cbuilder -> la_combo), renderer, TRUE);
1389 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (cbuilder -> la_combo), renderer, "text", 0, NULL);
1390 gtk_widget_set_size_request (cbuilder -> la_combo, 150, 25);
1391 g_signal_connect (G_OBJECT(cbuilder -> la_combo), "changed", G_CALLBACK(set_lattice), data);
1392 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> la_combo, FALSE, FALSE, 0);
1393 combo_set_active (cbuilder -> la_combo, 0);
1394 combo_set_markup (cbuilder -> la_combo);
1395 hbox = create_hbox(0);
1396 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1397 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> lattice_box, FALSE, FALSE, 50);
1398
1399 hbox = create_hbox(0);
1400 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1401 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Cell(s):", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1402 hbox = create_hbox(0);
1403 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 0);
1404 GtkWidget * ax_cell[3];
1405 for (i=0; i<3; i++)
1406 {
1407 ax_cell[i] = spin_button (G_CALLBACK(add_cryst_cell), cbuilder -> cell.cextra[i], 1, 1000, 1, 0, 100, & cbuilder -> pointers[i][0]);
1408 str = g_strdup_printf ("%s x ", box_prop[0][i]);
1409 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(str, 50, -1, 1.0, 0.5), FALSE, FALSE, 5);
1410 g_free (str);
1411 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, ax_cell[i], FALSE, FALSE, 0);
1412 }
1413
1414 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, check_button (" Wrap all atoms in the unit cell after building", -1, -1, FALSE, G_CALLBACK(set_wr), (gpointer)cbuilder), FALSE, FALSE, 10);
1415 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, check_button (" Show/hide clones after building", -1, -1, FALSE, G_CALLBACK(set_shc), (gpointer)cbuilder), FALSE, FALSE, 0);
1416
1417 hbox = create_hbox (0);
1418 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 10);
1419 this_proj -> modelgl -> search_widg[7] = allocate_atom_search (this_proj -> id, INSERT, 7, 0);
1420 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Add object(s):", 150, -1, 0.0, 0.5), FALSE, FALSE, 5);
1421 cbuilder -> add_combo = create_action_combo (5, this_proj);
1422 gtk_widget_set_size_request (cbuilder -> add_combo, 110, -1);
1423 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, cbuilder -> add_combo, FALSE, FALSE, 5);
1424 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, create_button ("Occupancy", IMG_STOCK, DPROPERTIES, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(adjust_occupancy), this_proj), FALSE, FALSE, 5);
1425
1426 GtkWidget * cbscroll = create_scroll (vbox, 400, 200, GTK_SHADOW_NONE);
1427 add_container_child (CONTAINER_SCR, cbscroll, create_atoms_tree (this_proj -> modelgl -> search_widg[7], this_proj, 0));
1428
1429 hbox = create_hbox (5);
1430 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, TRUE, FALSE, 5);
1431 cbuilder -> pbut = create_button ((this_proj -> natomes) ? "Build (new project)" : "Build", IMG_STOCK, APPLY, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(apply_build), GINT_TO_POINTER(this_proj -> id));
1432 add_box_child_end (hbox, cbuilder -> pbut, FALSE, FALSE, 5);
1433 GtkWidget * but = create_button ("Close", IMG_STOCK, FCLOSE, -1, -1, GTK_RELIEF_NORMAL, G_CALLBACK(close_build), GINT_TO_POINTER(this_proj -> id));
1434 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, but, FALSE, FALSE, 5);
1435 add_gtk_close_event (win, G_CALLBACK(delete_build), GINT_TO_POINTER(this_proj -> id));
1436
1437 return win;
1438}
1439
1447void prepare_crystal_builder (gpointer data)
1448{
1449 tint * id = (tint *) data;
1450 project * this_proj = get_project_by_id(id -> a);
1451 if (this_proj -> modelgl -> builder_win == NULL)
1452 {
1453 // close_edit (NULL, GINT_TO_POINTER(this_proj -> id));
1454 prepare_atom_edition (data, FALSE);
1455 this_proj -> modelgl -> builder_win = g_malloc0(sizeof*this_proj -> modelgl -> builder_win);
1456 this_proj -> modelgl -> builder_win -> cell.box = g_malloc0(sizeof*this_proj -> modelgl -> builder_win -> cell.box);
1457 this_proj -> modelgl -> builder_win -> win = builder_win (this_proj, data);
1458 this_proj -> modelgl -> builder_win -> rounding = 2;
1459 }
1460 show_the_widgets (this_proj -> modelgl -> builder_win -> win);
1461}
1462
1463#ifdef GTK4
1473G_MODULE_EXPORT void crystal_window (GSimpleAction * action, GVariant * parameter, gpointer data)
1474#else
1483G_MODULE_EXPORT void crystal_window (GtkWidget * widg, gpointer data)
1484#endif
1485{
1487}
void prepare_atom_edition(gpointer data, gboolean visible)
prepare atom edition
Definition atom_edit.c:453
atom_search * allocate_atom_search(int proj, int action, int searchid, int tsize)
allocate atom search data structure
Definition atom_edit.c:386
GtkWidget * create_action_combo(int id, project *this_proj)
create action combo box
Binding to the Fortran90 subroutines.
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:372
gboolean crystal_low_warning
gboolean crystal_crowded
int occupancy(double occ, int cif_occ)
handle occupancy integer rouding
gboolean crystal_dist_chk
void adjust_sg_combo(builder_edition *cbuilder, int cs, int bl)
adjust the space group combo box to use pango markup
void adjust_bv_img(builder_edition *cbuilder)
adjust the bravais lattice image
G_MODULE_EXPORT void toggle_overlap(GtkToggleButton *Button, gpointer data)
adjust overlapping toggle callback GTK3
G_MODULE_EXPORT void adjust_occupancy(GtkButton *but, gpointer data)
adjust occupancy create dialog callback
G_MODULE_EXPORT void toggle_occ(GtkToggleButton *but, gpointer data)
occupancy toggle callback GTK3
G_MODULE_EXPORT void set_wr(GtkToggleButton *but, gpointer data)
wrap or not atomic coordinates after crystal building toggle callback GTK3
G_MODULE_EXPORT void apply_build(GtkButton *but, gpointer data)
build crystall callback
G_MODULE_EXPORT void set_sg(GtkComboBox *box, gpointer data)
change space group
G_MODULE_EXPORT void show_sg_info(GtkButton *but, gpointer data)
G_MODULE_EXPORT void set_cs(GtkComboBox *box, gpointer data)
change the crystal system
G_MODULE_EXPORT void add_cryst_cell(GtkSpinButton *res, gpointer data)
add cell callback spin
GtkWidget * create_bl_combo(int cs, gpointer data)
create the bravais lattice combo box
G_MODULE_EXPORT void set_so(GtkComboBox *box, gpointer data)
set space group setting
GtkWidget * sg_info(int sg, gpointer data)
create the space group information button
void adjust_lattice_constraints(builder_edition *cbuilder)
adjust lattice constraints
GtkTreeModel * la_combo_tree()
create the lattice system combo box tree model
int min_bv[7]
gchar * get_num_string(gchar *str)
get description string for entry string
gchar * latt_info[7]
gchar * frac_string(gchar *init)
get pango string for fraction string
int get_crystal_id(int spg)
get the bravais lattice id from space group id
G_MODULE_EXPORT void set_bl(GtkComboBox *box, gpointer data)
change bravais lattice
int build_crystal(gboolean visible, project *this_proj, int c_step, gboolean to_wrap, gboolean show_clones, cell_info *cell, GtkWidget *widg)
build crystal
int read_space_group(builder_edition *cbuilder, int spg)
read space group N°spg data from file
G_MODULE_EXPORT void set_shc(GtkToggleButton *but, gpointer data)
show / hide clones after crystal building toggle callback GTK3
G_MODULE_EXPORT void close_build(GtkButton *but, gpointer data)
close crystal builder and free associated data pointers
int get_bravais_img_id(int spg)
get bravais image from space group id
int nsg_bv[7]
gchar * bravais_keys[7][4]
void get_origin(space_group *spg)
get space group origin matrices
void adjust_lattice_parameters(builder_edition *cbuilder)
adjust lattice parameters depending on space group
G_MODULE_EXPORT void update_cb_box(GtkEntry *entry, gpointer data)
update lattice box parameter callback
G_MODULE_EXPORT void set_lattice(GtkComboBox *box, gpointer data)
change the lattice system
G_MODULE_EXPORT void crystal_window(GtkWidget *widg, gpointer data)
create the crystal build window callback GTK3
G_MODULE_EXPORT gboolean delete_build(GtkWidget *widg, GdkEvent *event, gpointer data)
crystal builder delete event callback GTK3
int get_group_id_from_name(gchar *sg_name)
get space group id from name
dint occp[5]
G_MODULE_EXPORT void update_cb_vect(GtkEntry *entry, gpointer data)
update lattice vector callback
int get_sg_num(GtkComboBox *box)
get space group number from active iter in tree model of combo box
void prepare_crystal_builder(gpointer data)
create the crystal builder
int test_lattice(builder_edition *cbuilder, cell_info *cif_cell)
test lattice parameters
GtkTreeModel * sg_combo_tree(int csid, int bvid)
create the space group combo box tree model
GtkWidget * builder_win(project *this_proj, gpointer data)
create crystal builder window
GtkWidget * prepare_lattice_grid(int type, builder_edition *cbuilder, glwin *glview)
prepare the lattice parameters grid widget
GtkTreeModel * so_combo_tree(space_group *spg)
create the space group setting combo box tree model
gchar * get_so_string(space_group *spg, int id)
get space group setting descrption string
G_MODULE_EXPORT void on_rounding_changed(GtkComboBox *box, gpointer data)
changed rounding method for occupancy
void adjust_so_combo(builder_edition *cbuilder)
adjust the space group setting combo box to use pango markup
gchar * crystal_sytems[7]
Function declarations for the crystal builder.
gchar * groups[230]
Definition cbuild_sg.c:43
GtkWidget * create_atoms_tree(atom_search *asearch, project *this_proj, int na)
create atom search tree view
Definition w_search.c:3582
gchar * replace_markup(char *init, char *key, char *rep)
replace pattern in string
Definition w_library.c:339
space_group * read_sg_xml_file(const char *filetoread)
read space group data from XML file
Definition cbuild_sg.c:652
gchar * param[2]
float val
Definition dlp_init.c:117
char * box_prop[2][3]
Definition edit_menu.c:74
char * vect_name[3]
Definition edit_menu.c:82
dint t_box[9]
Definition edit_menu.c:95
gchar * PACKAGE_LIB_DIR
Definition global.c:78
gchar * bravais_img[14]
Definition global.c:139
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
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:501
@ IMG_NONE
Definition global.h:262
@ IMG_STOCK
Definition global.h:266
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:909
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1375
void update_entry_double(GtkEntry *entry, double doubleval)
update the content of a GtkEntry as double
Definition gtk-misc.c:643
GtkWidget * create_scroll(GtkWidget *box, int dimx, int dimy, int shadow)
create a scroll window
Definition gtk-misc.c:2095
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:520
GtkWidget * create_win(gchar *str, GtkWidget *parent, gboolean modal, gboolean resiz)
create a new GtkWindow
Definition gtk-misc.c:454
void combo_set_markup(GtkWidget *combo)
use pango markup in combo widget
Definition gtk-misc.c:944
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:932
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:607
#define BSEP
Definition global.h:247
void add_gtk_close_event(GtkWidget *widg, GCallback handler, gpointer data)
add a close event signal and callback to a GtkWidget
Definition gtk-misc.c:2522
void button_set_status(GtkWidget *button, int status)
set status of check / toggle button
Definition gtk-misc.c:1872
GtkWidget * radio_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a radio button
Definition gtk-misc.c:1926
GtkWidget * spin_button(GCallback handler, double value, double start, double end, double step, int digits, int dim, gpointer data)
create a spin button
Definition gtk-misc.c:1833
#define APPLY
Definition global.h:222
GtkWidget * check_button(gchar *text, int dimx, int dimy, gboolean state, GCallback handler, gpointer data)
create a check button
Definition gtk-misc.c:1893
@ CONTAINER_WIN
Definition global.h:252
@ CONTAINER_BUT
Definition global.h:255
@ CONTAINER_SCR
Definition global.h:253
#define DPROPERTIES
Definition global.h:208
GtkWidget * create_button(gchar *text, int image_format, gchar *image, int dimx, int dimy, int relief, GCallback handler, gpointer data)
create a simple button
Definition gtk-misc.c:1955
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:984
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:835
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1646
GtkWidget * cbox(GtkWidget *box, char *lab)
box creating routine, to help design faster elements for the GUI
Definition gtk-misc.c:2058
void add_box_child_start(int orientation, GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the initial position.
Definition gtk-misc.c:308
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:215
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:823
void combo_text_append(GtkWidget *combo, gchar *text)
append text in GtkComboBox widget
Definition gtk-misc.c:961
G_MODULE_EXPORT void run_destroy_dialog(GtkDialog *dialog, gint response_id, gpointer data)
to destroy a GtkDialog when the dialog emit the closing signal
Definition gtk-misc.c:2237
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2169
void add_box_child_end(GtkWidget *widg, GtkWidget *child, gboolean expand, gboolean fill, int padding)
Add a GtkWidget in a GtkBox at the end position.
Definition gtk-misc.c:286
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:681
void add_container_child(int type, GtkWidget *widg, GtkWidget *child)
Add a GtkWidget into another GtkWidget.
Definition gtk-misc.c:235
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:811
int button_get_status(GtkWidget *button)
get status of check / toggle button
Definition gtk-misc.c:1855
#define FCLOSE
Definition global.h:213
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:182
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
atom_search * free_this_search_data(atom_search *this_search)
free atom search data structure
Definition popup.c:284
action
Definition glview.h:198
@ INSERT
Definition glview.h:236
gchar * cif_occ[3]
Definition interface.c:478
gchar * cif_sites[2]
Definition interface.c:481
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
gchar * cif_occupancies[3]
Definition interface.c:460
Messaging function declarations.
char * vect_comp[3]
Definition edit_menu.c:83
integer(kind=c_int) function lattice(totl, lid, vectors, vmod, angles, lat, cfrac, apbc)
Definition lattice.F90:162
Function declarations for reading atomes project file Function declarations for saving atomes proje...
coord_file * this_reader
Definition read_coord.c:73
Functions declaration to read atomic coordinates.
Definition glwin.h:351
Definition global.h:99
int b
Definition global.h:101
int a
Definition global.h:100
Definition glwin.h:965
Definition global.h:106
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkWidget * res[2]
Definition w_encode.c:212
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
Function declarations for workspace managment.