atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
callbacks.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
23/*
24* This file: 'callbacks.c'
25*
26* Contains:
27*
28
29 - General callbacks
30 - The functions to open and close files
31
32*
33* List of functions:
34
35 int open_save (FILE * fp, int i, int pid, int aid, int npi, gchar * pfile);
36 int open_save_workspace (FILE * fp, int act);
37 int prep_chem_data ();
38 int to_read_trj_or_vas (int ff);
39 int read_npt_data ();
40 int open_coordinate_file (int id);
41
42 void quit_gtk ();
43 void open_this_proj (gpointer data, gpointer user_data);
44 void run_project ();
45 void apply_project (gboolean showtools);
46 void open_this_isaacs_xml_file (gchar * profile, int ptoc, gboolean visible);
47 void to_read_pos ();
48 void check_read_sa ();
49 void update_sa_info (int sid);
50 void prepare_sp_box ();
51 void cell_data_from_pdb_ (float * a, float * b, float * c, float * alp, float * bet, float * gam);
52 void open_this_coordinate_file (int format, gchar * proj_name);
53
54 G_MODULE_EXPORT void on_close_workspace (GtkWidget * widg, gpointer data);
55 G_MODULE_EXPORT void run_on_open_save_active (GtkNativeDialog * info, gint response_id, gpointer data);
56 G_MODULE_EXPORT void run_on_open_save_active (GtkDialog * info, gint response_id, gpointer data);
57 G_MODULE_EXPORT void on_open_save_activate (GtkWidget * widg, gpointer data);
58 G_MODULE_EXPORT void on_save_as_activate (GtkWidget * widg, gpointer data);
59 G_MODULE_EXPORT void run_on_isaacs_port (GtkNativeDialog * info, gint response_id, gpointer data);
60 G_MODULE_EXPORT void run_on_isaacs_port (GtkDialog * info, gint response_id, gpointer data);
61 G_MODULE_EXPORT void on_isaacs_port (GtkWidget * widg, gpointer data);
62 G_MODULE_EXPORT void update_sa (GtkEntry * res, gpointer data);
63 G_MODULE_EXPORT void changed_spec_combo (GtkComboBox * box, gpointer data);
64 G_MODULE_EXPORT void update_at_sp (GtkEntry * res, gpointer data);
65 G_MODULE_EXPORT void run_to_read_trj_or_vas (GtkDialog * dialog, gint response_id, gpointer data);
66 G_MODULE_EXPORT void run_read_npt_data (GtkNativeDialog * info, gint response_id, gpointer data);
67 G_MODULE_EXPORT void run_read_npt_data (GtkDialog * info, gint response_id, gpointer data);
68 G_MODULE_EXPORT void run_on_coord_port (GtkNativeDialog * info, gint response_id, gpointer data);
69 G_MODULE_EXPORT void run_on_coord_port (GtkDialog * info, gint response_id, gpointer data);
70 G_MODULE_EXPORT void on_coord_port (GtkWidget * widg, gpointer data);
71
72*/
73
74#include "global.h"
75#include "interface.h"
76#include "callbacks.h"
77#include "bind.h"
78#include "project.h"
79#include "workspace.h"
80#include "glwindow.h"
81#include "glview.h"
82#include "atom_edit.h"
83#include "cell_edit.h"
84#include "readers.h"
85
86char * coord_files[NCFORMATS+1] = {"XYZ file",
87 "XYZ file - NPT",
88 "Chem3D file",
89 "CPMD trajectory",
90 "CPMD trajectory - NPT",
91 "VASP trajectory",
92 "VASP trajectory - NPT",
93 "Protein Data Bank file",
94 "Protein Data Bank file",
95 "Cryst. information (crystal build) - single configuration",
96 "Cryst. information (crystal build) - multiple configurations",
97 "Cryst. information (symmetry positions) - single configuration",
98 "DL-POLY HISTORY file",
99 "ISAACS Project File"};
100
101char * coord_files_ext[NCFORMATS+1]={"xyz", "xyz", "c3d", "trj", "trj", "xdatcar", "xdatcar",
102 "pdb", "ent", "cif", "cif", "cif", "hist", "ipf"};
103
104char ** las;
105void initcwidgets ();
106extern G_MODULE_EXPORT void on_edit_activate (GtkWidget * widg, gpointer data);
107extern gchar * substitute_string (gchar * init, gchar * o_motif, gchar * n_motif);
108extern const gchar * dfi[2];
109extern int open_cif_file (gchar * filename);
110extern int open_coord_file (gchar * filename, int fti);
111extern int open_history_file (gchar * filename);
112extern int open_cell_file (int format, gchar * filename);
113extern double get_z_from_periodic_table (gchar * lab);
114
120void quit_gtk ()
121{
122 profree_ ();
123 g_application_quit (G_APPLICATION(AtomesApp));
124}
125
134G_MODULE_EXPORT void on_close_workspace (GtkWidget * widg, gpointer data)
135{
136 int i, j;
137 gboolean close = FALSE;
138 j = GPOINTER_TO_INT (data);
139 if (j == 1)
140 {
141 close = ask_yes_no ("Close workspace ?", "Are you sure ?", GTK_MESSAGE_QUESTION, MainWindow);
142 }
143 else
144 {
145 close = TRUE;
146 }
147
148 if (close)
149 {
150 j = nprojects-1;
151 for (i=j; i>-1; i--)
152 {
153#ifdef DEBUG
154 g_debug ("CLOSING:: %d", i);
155#endif
156 on_close_activate (NULL, GINT_TO_POINTER(i));
157 }
158 }
159}
160
161gboolean save = TRUE;
162
175int open_save (FILE * fp, int i, int pid, int aid, int npi, gchar * pfile)
176{
177 int j;
178 gchar * err;
179
180 if (i == 0)
181 {
182 reading_input = TRUE;
183 j = open_project (fp, npi);
184 reading_input = FALSE;
185 if (j != 0)
186 {
187 // error at read
188 if (pfile != NULL)
189 {
190 err = g_strdup_printf ("Impossible to open project file: \n%s\nError code: %d\n", pfile, j);
191 show_error (err, 0, MainWindow);
192 g_free (err);
193 }
195 }
196 else
197 {
198 get_project_by_id (pid) -> projfile = g_strdup_printf ("%s", pfile);
201 }
202 }
203 else
204 {
205 j = save_project (fp, get_project_by_id(pid), npi);
206 if (j != 0)
207 {
208 // error at write
209 if (pfile != NULL)
210 {
211 err = g_strdup_printf ("Impossible to save project file:\n%s\nError code: %d\n", pfile, j);
212 show_error (err, 0, MainWindow);
213 g_free (err);
214 }
215 }
216 else
217 {
218 if (pfile != NULL) get_project_by_id(pid) -> projfile = g_strdup_printf ("%s", pfile);
219 }
220 }
221 return j;
222}
223
232int open_save_workspace (FILE * fp, int act)
233{
234 int i, j, k, l, m;
235 gchar * ver;
236 /*PangoFontDescription * font_desc;
237 GtkTextBuffer * buffer;
238 GtkTextIter bStart;
239 GtkTextIter bEnd;*/
240
241 // First 2 lines for compatibility issues
242 if (act == 0)
243 {
244 if (fread (& i, sizeof(int), 1, fp) != 1) return 1;
245 ver = g_malloc0 (i*sizeof*ver);
246 if (fread (ver, sizeof(char), i, fp) != i) return 1;
247 // test on ver for version
248 g_free (ver);
249 if (fread (& i, sizeof(int), 1, fp) != 1) return 1;
250 }
251 else
252 {
253 i = 1;
254 ver = g_strdup_printf ("%%\n%% Workspace file v-%1d.0\n%%\n", i);
255 i = strlen (ver);
256 if (fwrite (& i, sizeof(int), 1, fp) != 1) return 1;
257 if (fwrite (ver, sizeof(char), i, fp) != i) return 1;
258 g_free (ver);
259 i = 0;
260 for (j=0; j<nprojects; j++) if (get_project_by_id(j) -> natomes) i++;
261 if (fwrite (& i, sizeof(int), 1, fp) != 1) return 1;
262 l = i;
263 i = nprojects;
264 }
265
266 if (i > 0)
267 {
268 for (j=0; j<i; j++)
269 {
270 k = activep;
271 if (act == 0)
272 {
273 init_project (FALSE);
274 m = open_save (fp, act, j, k, i, NULL);
275 if (m != 0) return m;
276 }
277 else if (get_project_by_id(j) -> natomes)
278 {
279 m = open_save (fp, act, j, k, l, NULL);
280 if (m != 0) return m;
281 }
282 }
283 return 0;
284 }
285 else
286 {
287 return -1;
288 }
289}
290
299void open_this_proj (gpointer data, gpointer user_data)
300{
301 FILE * fp = fopen (data, dfi[0]);
302 int pactive = activep;
303 init_project (FALSE);
304 open_save (fp, 0, activew, pactive, 0, data);
305 fclose (fp);
307}
308
310gboolean run_os;
311
312#ifdef GTK4
322G_MODULE_EXPORT void run_on_open_save_active (GtkNativeDialog * info, gint response_id, gpointer data)
323{
324 GListModel * projlist;
325 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
326#else
336G_MODULE_EXPORT void run_on_open_save_active (GtkDialog * info, gint response_id, gpointer data)
337{
338 GSList * projlist = NULL;
339 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
340#endif
341 FILE * fp = NULL;
342 gchar * err;
343 gboolean io = FALSE;
344 const gchar * mess[2]={"reading","saving "};
345 if (response_id == GTK_RESPONSE_ACCEPT)
346 {
347 if (osp.a == 0)
348 {
349 projlist = file_chooser_get_file_names (chooser);
350 }
351 else
352 {
354 }
355 if (osp.a > 1)
356 {
357 workspacefile = g_strdup_printf ("%s", projfile);
358 }
359 io = TRUE;
360 }
361 if (run_os)
362 {
363#ifdef GTK4
365#else
366 destroy_this_dialog (info);
367#endif
368 }
369 if (io)
370 {
371 if (osp.a > 0)
372 {
373 fp = fopen (projfile, dfi[osp.b]);
374 }
375 if (osp.a == 0)
376 {
377#ifdef GTK3
378 g_slist_foreach (projlist, open_this_proj, NULL);
379 g_slist_free (projlist);
380#else
381 int i;
382 for (i=0; i<g_list_model_get_n_items (projlist); i++)
383 {
384 GObject * obj = g_list_model_get_item (projlist, i);
385 open_this_proj (g_file_get_parse_name((GFile *)obj), NULL);
386 }
387 g_object_unref (projlist);
388#endif
389 }
390 else if (osp.a == 1)
391 {
393 }
394 else
395 {
396 int k = open_save_workspace (fp, osp.b);
397 if (k != 0)
398 {
399 err = g_strdup_printf ("Error %s workspace file\n%s\nError code: %d\n",
400 mess[osp.b], projfile, k);
401 show_error (err, 0, MainWindow);
402 g_free (err);
403 }
404 }
405 if (osp.a > 0)
406 {
407 fclose (fp);
408 g_free (projfile);
409 }
410 }
411}
412
421G_MODULE_EXPORT void on_open_save_activate (GtkWidget * widg, gpointer data)
422{
423 int i, j, k;
424 gint action;
425#ifdef GTK4
426 GtkFileChooserNative * info;
427#else
428 GtkWidget * info;
429#endif
430 GtkFileChooser * chooser;
431 GtkFileFilter * filter1, * filter2;
432 const gchar * str[4]={"Open Project File(s)", "Save Project File", "Open Workspace", "Save Workspace"};
433 const gchar * res[2]={"Open", "Save"};
434 const gchar * file_name[2]={"Project file (*.apf)", "Workspace file (*.awf)"};
435 const gchar * file_ext[2]={"*.apf", "*.awf"};
436 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
437 project * this_proj = get_project_by_id (activew);
438 int pactive = activep;
439 i = GPOINTER_TO_INT (data);
440 run_os = FALSE;
441 if (i == 1 || i == 3)
442 {
443 j = 1;
444 }
445 else
446 {
447 j = 0;
448 }
449 action = 0;
450 if (i == 2 && ! newspace)
451 {
452 show_info ("A workspace is already open !", 0, MainWindow);
453 }
454 else if (i == 3 && newspace)
455 {
456 show_warning ("Empty workspace ... nothing to be saved\n", MainWindow);
457 }
458 else if (i == 3)
459 {
460 for (k=0; k<nprojects; k++) if (get_project_by_id(k) -> natomes) action = 1;
461 if (! action)
462 {
463 show_warning ("Workspace contains only empty projects ... nothing to be saved\n", MainWindow);
464 }
465 }
466 else if (i == 1 && nprojects == 0)
467 {
468 show_warning ("No project open ... nothing to be saved\n", MainWindow);
469 }
470 else if (i == 1 && ! this_proj -> natomes)
471 {
472 show_warning ("Empty project ... nothing to be saved\n", MainWindow);
473 }
474 else
475 {
476 action = 1;
477 }
478
479 if (action)
480 {
481 if (nprojects == 0)
482 {
483 run_os = TRUE;
484 }
485 else
486 {
487 if (i == 1)
488 {
489 if (g_strcmp0(this_proj -> projfile, "(null)") == 0) this_proj -> projfile = NULL;
490 if (save && this_proj -> projfile != NULL)
491 {
492 run_os = FALSE;
493 projfile = g_strdup_printf ("%s", this_proj -> projfile);
494 }
495 else
496 {
497 run_os = TRUE;
498 projfile = NULL;
499 }
500 }
501 else if (i == 3)
502 {
503 if (g_strcmp0(workspacefile, "(null)") == 0) workspacefile = NULL;
504 if (save && workspacefile != NULL)
505 {
506 run_os = FALSE;
507 projfile = g_strdup_printf ("%s", workspacefile);
508 }
509 else
510 {
511 run_os = TRUE;
512 }
513 }
514 else
515 {
516 run_os = TRUE;
517 }
518 }
519
520 gchar * tmp_str;
521 if (i == 0)
522 {
523 tmp_str = g_strdup_printf ("%s - New project", str[i]);
524 }
525 else if (i == 1)
526 {
527 tmp_str = g_strdup_printf ("%s - %s", str[i], prepare_for_title(this_proj -> name));
528 }
529 else
530 {
531 tmp_str = g_strdup_printf ("%s", str[i]);
532 }
533 info = create_file_chooser (tmp_str,
534 GTK_WINDOW(MainWindow),
535 act[j],
536 res[j]);
537 chooser = GTK_FILE_CHOOSER (info);
538 g_free (tmp_str);
539#ifdef GTK3
540 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
541#endif
542 if (i == 1 || i == 3) gtk_file_chooser_set_create_folders (chooser, TRUE);
543 if (nprojects == 0 || i == 0)
544 {
546 if (i == 0)
547 {
548 gtk_file_chooser_set_select_multiple (chooser, TRUE);
549 }
550 }
551 else
552 {
553 if (i == 1)
554 {
555 if (projfile != NULL)
556 {
558 gtk_file_chooser_set_current_name (chooser, projfile);
559 }
560 else
561 {
562 if (! file_chooser_set_file_name (chooser, g_strdup_printf ("%s.apf", prepare_for_title(this_proj -> name)))) goto end;
563 }
564 }
565 else if (i == 3)
566 {
567 if (workspacefile != NULL)
568 {
570 gtk_file_chooser_set_current_name (chooser, g_strdup_printf ("%s", workspacefile));
571 }
572 else
573 {
574 if (! file_chooser_set_file_name (chooser, "New-Workspace.awf")) goto end;
575 }
576 }
577 }
578 filter1 = gtk_file_filter_new();
579 gtk_file_filter_set_name (GTK_FILE_FILTER(filter1), file_name[i/2]);
580 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter1), file_ext[i/2]);
581 gtk_file_chooser_add_filter (chooser, filter1);
582 filter2 = gtk_file_filter_new();
583 gtk_file_filter_set_name (GTK_FILE_FILTER(filter2), "All files (*)");
584 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter2), "*");
585 gtk_file_chooser_add_filter (chooser, filter2);
586 osp.a = i;
587 osp.b = j;
588 osp.c = pactive;
589 if (run_os)
590 {
591#ifdef GTK4
592 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_open_save_active), this_proj);
593#else
594 run_this_gtk_dialog (info, G_CALLBACK(run_on_open_save_active), this_proj);
595#endif
596 }
597 else
598 {
599#ifdef GTK4
600 run_on_open_save_active ((GtkNativeDialog *)info, GTK_RESPONSE_ACCEPT, this_proj);
601#else
602 run_on_open_save_active ((GtkDialog *)info, GTK_RESPONSE_ACCEPT, this_proj);
603#endif
604 }
605 }
608 end:;
609}
610
619G_MODULE_EXPORT void on_save_as_activate (GtkWidget * widg, gpointer data)
620{
621 save = FALSE;
622 on_open_save_activate (widg, data);
623 save = TRUE;
624}
625
632{
633 if (! active_project -> run)
634 {
635 int i, j;
636 j = (active_cell -> npt) ? active_project -> steps : 1;
637 for (i=0; i<j; i++)
638 {
639 lattice_ (& j, & i,
640 active_cell -> box[i].vect,
641 active_cell -> box[i].param[0],
642 active_cell -> box[i].param[1],
643 & active_cell -> ltype,
644 & active_cell -> frac,
645 & active_cell -> pbc);
646 }
647 to_read_pos ();
648 prep_pos_ (& active_cell -> pbc, & active_cell -> frac);
649 if (active_project -> numwid < 0) initcwidgets ();
650 active_project -> dmtx = FALSE;
651 active_project -> run = 1;
652 }
653 if (active_cell -> frac) active_cell -> frac = 0;
654}
655
663void apply_project (gboolean showtools)
664{
665 if (active_project -> natomes)
666 {
667 run_project ();
669 }
671 if (showtools) show_the_widgets (curvetoolbox);
672}
673
683void open_this_isaacs_xml_file (gchar * profile, int ptoc, gboolean visible)
684{
685 if (! open_xml (profile))
686 {
687 active_project -> name = substitute_string (g_path_get_basename (profile), ".ipf", NULL);
688 on_edit_activate (NULL, GINT_TO_POINTER(3));
689 on_edit_activate (NULL, GINT_TO_POINTER(5));
691 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
692 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
693 apply_project (TRUE);
696 if (visible) show_info ("ISAACS project file (XML) successfully opened", 0, MainWindow);
697 }
698 else
699 {
701 }
702}
703
704#ifdef GTK4
714G_MODULE_EXPORT void run_on_isaacs_port (GtkNativeDialog * info, gint response_id, gpointer data)
715{
716 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
717#else
727G_MODULE_EXPORT void run_on_isaacs_port (GtkDialog * info, gint response_id, gpointer data)
728{
729 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
730#endif
731 if (response_id == GTK_RESPONSE_ACCEPT)
732 {
733 if (osp.a == 0 || nprojects == 0) init_project (TRUE);
735#ifdef GTK4
737#else
738 destroy_this_dialog (info);
739#endif
740 if (osp.a == 0)
741 {
743 }
744 else if (osp.a == 1)
745 {
747 if (write_xml (projfile) == 0)
748 {
749 show_error ("Impossible to write the IPF file\n", 0, MainWindow);
750 }
752 }
753 g_free (projfile);
754 }
755 else
756 {
757#ifdef GTK4
759#else
760 destroy_this_dialog (info);
761#endif
762 }
763}
764
773G_MODULE_EXPORT void on_isaacs_port (GtkWidget * widg, gpointer data)
774{
775 int i, j;
776 gboolean action;
777#ifdef GTK4
778 GtkFileChooserNative * info;
779#else
780 GtkWidget * info;
781#endif
782 GtkFileChooser * chooser;
783 GtkFileFilter * filter[2];
784 const gchar * file_ext[2]={"*.ipf", "*"};
785 const gchar * file_type[2]={"IPF file (*.ipf)", "All files (*)"};
786 const gchar * str[2]={"Import ISAACS Project File", "Export ISAACS Project File"};
787 const gchar * res[2]={"Open", "Save"};
788 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
789 int pactive = activep;
790 i = GPOINTER_TO_INT (data);
791
792 action = (i && ! nprojects) ? ask_yes_no ("Save an empty project ?", "Do you want to save an empty project ?", GTK_MESSAGE_QUESTION, MainWindow) : TRUE;
793 if (action)
794 {
795 info = create_file_chooser (str[i],
796 GTK_WINDOW(MainWindow),
797 act[i],
798 res[i]);
799 chooser = GTK_FILE_CHOOSER (info);
800#ifdef GTK3
801 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
802#endif
803 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
804 for (j=0; j<2; j++)
805 {
806 filter[j] = gtk_file_filter_new();
807 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), file_type[j]);
808 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), file_ext[j]);
809 gtk_file_chooser_add_filter (chooser, filter[j]);
810 }
812 osp.a = i;
813 osp.b = pactive;
814#ifdef GTK4
815 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_isaacs_port), NULL);
816#else
817 run_this_gtk_dialog (info, G_CALLBACK(run_on_isaacs_port), NULL);
818#endif
819 }
822}
823
830{
831 int i, j, k;
832 double * x, * y, * z;
833 double lat[3];
834
835 x = allocdouble(active_project -> steps*active_project -> natomes);
836 y = allocdouble(active_project -> steps*active_project -> natomes);
837 z = allocdouble(active_project -> steps*active_project -> natomes);
838 k = 0;
839 lat[0] = lat[1] = lat[2] = 0.0;
840 if (active_cell -> crystal)
841 {
842 for (i=0; i<3; i++)
843 {
844 for (j=0; j<3; j++) lat[i] -= active_box -> vect[j][i]/2.0;
845 }
846 }
847 for (i=0; i<active_project -> steps; i++)
848 {
849 for (j=0; j<active_project -> natomes; j++)
850 {
851 x[k] = active_project -> atoms[i][j].x + lat[0];
852 y[k] = active_project -> atoms[i][j].y + lat[1];
853 z[k] = active_project -> atoms[i][j].z + lat[2];
854 k ++;
855 }
856 }
857 read_pos_ (x, y, z);
858 g_free (x);
859 x = NULL;
860 g_free (y);
861 y = NULL;
862 g_free (z);
863 z = NULL;
864}
865
866GtkWidget * read_box;
867GtkWidget * all_sp_box;
868GtkWidget * sa_lab[2];
869GtkWidget * sa_entry[2];
870GtkWidget * read_this;
872
879{
880 int i, j, k;
881 i = j = 0;
882 for (k=0; k<this_reader -> nspec; k++)
883 {
884 i += this_reader -> nsps[k];
885 j += (this_reader -> label[k]) ? 1: 0;
886 }
887 if (i == this_reader -> natomes && j == this_reader -> nspec)
888 {
890 }
891 else
892 {
894 }
895}
896
904void update_sa_info (int sid)
905{
906 gchar * str = g_strdup_printf ("Label of atomic spec. N° %d:", sid+1);
907 gtk_label_set_text (GTK_LABEL(sa_lab[0]), str);
908 g_free (str);
909 if (this_reader -> label[sid])
910 {
911 update_entry_text (GTK_ENTRY(sa_entry[0]), this_reader -> label[sid]);
912 str = g_strdup_printf ("Number of %s atom(s):", this_reader -> label[sid]);
913 }
914 else
915 {
916 update_entry_text (GTK_ENTRY(sa_entry[0]), "");
917 str = g_strdup_printf ("Number of atom(s) for spec. N° %d:", sid+1);
918 }
919 gtk_label_set_text (GTK_LABEL(sa_lab[1]), str);
920 g_free (str);
921 if (this_reader -> nsps[sid])
922 {
923 update_entry_int (GTK_ENTRY(sa_entry[1]), this_reader -> nsps[sid]);
924 }
925 else
926 {
927 update_entry_text (GTK_ENTRY(sa_entry[1]), "");
928 }
929 read_spec = sid;
930}
931
940G_MODULE_EXPORT void update_sa (GtkEntry * res, gpointer data)
941{
942 int i, v;
943 i = GPOINTER_TO_INT(data);
944 const gchar * m = entry_get_text (res);
945 if (i == 0)
946 {
948 this_reader -> label[read_spec] = NULL;
949 this_reader -> label[read_spec] = g_strdup_printf ("%s", m);
951 }
952 else
953 {
954 v= (int)string_to_double ((gpointer)m);
955 if (v > 0)
956 {
957 this_reader -> nsps[read_spec] = v;
958 }
960 }
961 check_read_sa ();
962}
963
972G_MODULE_EXPORT void changed_spec_combo (GtkComboBox * box, gpointer data)
973{
974 update_sa_info (combo_get_active ((GtkWidget *)box));
975}
976
983{
984 int i;
985 if (all_sp_box)
986 {
987 for (i=0; i<2; i++)
988 {
991 }
993 }
996 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, read_box, all_sp_box, FALSE, FALSE, 20);
997 GtkWidget * hbox;
998 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, markup_label("Chemical species info:", 200, -1, 0.5, 0.5), FALSE, FALSE, 0);
999 hbox = create_hbox(0);
1000 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1001 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Species: ", 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
1002 GtkWidget * combo;
1003 combo = create_combo ();
1004 gchar * str;
1005
1006 for (i=0; i<this_reader -> nspec; i++)
1007 {
1008 str = g_strdup_printf ("N°%d", i+1);
1009 gtk_combo_box_text_append_text ((GtkComboBoxText *)combo, str);
1010 g_free (str);
1011 }
1012 combo_set_active (combo, 0);
1013 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK(changed_spec_combo), NULL);
1014 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, combo, FALSE, FALSE, 5);
1015 for (i=0; i<2; i++)
1016 {
1017 hbox = create_hbox(0);
1018 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1019 sa_lab[i] = markup_label("", 250, -1, 0.0, 0.5);
1020 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_lab[i], FALSE, FALSE, 5);
1021 sa_entry[i] = create_entry (G_CALLBACK(update_sa), 100, 15, FALSE, GINT_TO_POINTER(i));
1022 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_entry[i], FALSE, FALSE, 0);
1023 }
1025 update_sa_info (0);
1026}
1027
1036G_MODULE_EXPORT void update_at_sp (GtkEntry * res, gpointer data)
1037{
1038 int i, v;
1039 i = GPOINTER_TO_INT(data);
1040 const gchar * m = entry_get_text (res);
1041 gboolean up = FALSE;
1042 v = (int)string_to_double ((gpointer)m);
1043 if (i == 0)
1044 {
1045 this_reader -> natomes = (v > 0) ? v : 0;
1046 update_entry_int (res, this_reader -> natomes);
1047 }
1048 else
1049 {
1050 if (v != this_reader -> nspec)
1051 {
1052 this_reader -> nspec = (v > 0) ? v : 0;
1053 if (this_reader -> nspec)
1054 {
1055 if (this_reader -> nsps) g_free (this_reader -> nsps);
1056 this_reader -> nsps = allocint (v);
1057 if (this_reader -> z) g_free (this_reader -> z);
1058 this_reader -> z = allocdouble (v);
1059 if (this_reader -> label) g_free (this_reader -> label);
1060 this_reader -> label = g_malloc0 (v*sizeof*this_reader -> label);
1061 }
1062 up = TRUE;
1063 }
1064 update_entry_int (res, this_reader -> nspec);
1065 }
1066 if (up) prepare_sp_box();
1067}
1068
1070
1077{
1078 int i;
1079 double z;
1080 for (i=0; i<this_reader -> nspec; i++)
1081 {
1083 if (! z) return 0;
1084 this_reader -> z[i] = z;
1085 }
1086 return 1;
1087}
1088
1098G_MODULE_EXPORT void run_to_read_trj_or_vas (GtkDialog * dialog, gint response_id, gpointer data)
1099{
1100 int id = GPOINTER_TO_INT(data);
1101 switch (response_id)
1102 {
1103 case GTK_RESPONSE_APPLY:
1104 if (prep_chem_data())
1105 {
1106 reading_vas_trj = open_coord_file (active_project -> coordfile, id);
1107 }
1108 else
1109 {
1110 reading_vas_trj = 3;
1111 }
1112 break;
1113 default:
1114 reading_vas_trj = 3;
1115 break;
1116 }
1117 destroy_this_dialog (dialog);
1118}
1119
1128{
1129 int i;
1130 gchar * rlabel[2]={"Total number of atom(s):", "Number of chemical species:"};
1131 GtkWidget * dialog = dialogmodal ("Data to read CPMD / VASP trajectory", GTK_WINDOW(MainWindow));
1132 read_this = gtk_dialog_add_button (GTK_DIALOG (dialog), "Apply", GTK_RESPONSE_APPLY);
1133 GtkWidget * vbox = dialog_get_content_area (dialog);
1135 GtkWidget * rentry;
1136 GtkWidget * hbox;
1137 for (i=0; i<2; i++)
1138 {
1139 hbox = create_hbox(0);
1140 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1141 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(rlabel[i], 200, -1, 0.0, 0.5), FALSE, FALSE, 5);
1142 rentry = create_entry (G_CALLBACK(update_at_sp), 100, 15, FALSE, GINT_TO_POINTER(i));
1143 update_entry_text (GTK_ENTRY(rentry), "");
1144 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rentry, FALSE, FALSE, 5);
1145 }
1146 read_box = create_hbox(0);
1147 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, read_box, FALSE, FALSE, 5);
1148 run_this_gtk_dialog (dialog, G_CALLBACK(run_to_read_trj_or_vas), GINT_TO_POINTER(ff));
1149 return reading_vas_trj;
1150}
1151
1164void cell_data_from_pdb_ (float * a, float * b, float * c, float * alp, float * bet, float * gam)
1165{
1166 active_box -> param[0][0] = * a;
1167 active_box -> param[0][1] = * b;
1168 active_box -> param[0][2] = * c;
1169 active_box -> param[1][0] = * alp;
1170 active_box -> param[1][1] = * bet;
1171 active_box -> param[1][2] = * gam;
1172 // In a PDB file it is required to turn off PBC
1173 // The box usually barely encompass the molecule
1174 active_cell -> pbc = 0;
1175 active_cell -> ltype = 1;
1176}
1177
1179gchar * npt_file;
1180
1181#ifdef GTK4
1191G_MODULE_EXPORT void run_read_npt_data (GtkNativeDialog * info, gint response_id, gpointer data)
1192{
1193 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1194#else
1204G_MODULE_EXPORT void run_read_npt_data (GtkDialog * info, gint response_id, gpointer data)
1205{
1206 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1207#endif
1208 if (response_id == GTK_RESPONSE_ACCEPT)
1209 {
1211 npt_selection = iask ("Please select the file format of the NPT cell data", "Select format :", 6, MainWindow);
1212 }
1213 else
1214 {
1215 npt_selection = -1;
1216 }
1217#ifdef GTK4
1219#else
1220 destroy_this_dialog (info);
1221#endif
1222}
1223
1230{
1231 GtkFileFilter * filter[2];
1232#ifdef GTK4
1233 GtkFileChooserNative * info;
1234#else
1235 GtkWidget * info;
1236#endif
1237 info = create_file_chooser ("Read cell data for NPT molecular dynamics",
1238 GTK_WINDOW(MainWindow),
1239 GTK_FILE_CHOOSER_ACTION_OPEN,
1240 "Open");
1241 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1242 filter[0] = gtk_file_filter_new();
1243 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[0]), "DAT files (*.dat)");
1244 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[0]), "*.dat");
1245 gtk_file_chooser_add_filter (chooser, filter[0]);
1246 filter[1] = gtk_file_filter_new();
1247 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[1]), "All files (*)");
1248 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[1]), "*");
1249 gtk_file_chooser_add_filter (chooser, filter[1]);
1250 npt_file = NULL;
1251#ifdef GTK4
1252 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_read_npt_data), NULL);
1253#else
1254 run_this_gtk_dialog (info, G_CALLBACK(run_read_npt_data), NULL);
1255#endif
1256 return (npt_selection < 0) ? 0 : open_cell_file (npt_selection, npt_file);
1257}
1258
1267{
1268 struct timespec sta_time;
1269 struct timespec sto_time;
1270 int result;
1271 int length = strlen(active_project -> coordfile);
1272 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1273 this_reader = g_malloc0 (sizeof*this_reader);
1274 // Set default message type to warning
1275 this_reader -> mid = 1;
1276 switch (id)
1277 {
1278 case 0:
1279 // XYZ file
1280 result = open_coord_file (active_project -> coordfile, id);
1281 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1282 break;
1283 case 1:
1284 // XYZ file NPT
1285 result = open_coord_file (active_project -> coordfile, id);
1286 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1287 if (! result) result = read_npt_data ();
1288 break;
1289 case 2:
1290 // Chem3D file
1291 result = open_coord_file (active_project -> coordfile, id);
1292 // result = read_c3d_ (active_project -> coordfile, & length);
1293 break;
1294 case 3:
1295 // CPMD TRJ file
1296 result = to_read_trj_or_vas (id);
1297 break;
1298 case 4:
1299 // CPMD TRJ file NPT
1300 result = to_read_trj_or_vas (id);
1301 if (! result) result = read_npt_data ();
1302 break;
1303 case 5:
1304 // VASP XDATCAR file
1305 result = to_read_trj_or_vas (id);
1306 break;
1307 case 6:
1308 // VASP XDATCAR file NPT
1309 result = to_read_trj_or_vas (id);
1310 if (! result) result = read_npt_data ();
1311 break;
1312 case 7:
1313 // PDB file
1314 // result = open_coord_file (active_project -> coordfile, id);
1315 result = read_pdb_ (active_project -> coordfile, & length);
1316 break;
1317 case 8:
1318 // PDB file
1319 // result = open_coord_file (active_project -> coordfile, id);
1320 result = read_pdb_ (active_project -> coordfile, & length);
1321 break;
1322 case 9:
1323 // CIF file building the crystal
1324 result = open_coord_file (active_project -> coordfile, 9);
1325 break;
1326 case 10:
1327 // CIF file using symmetry positions
1328 result = open_coord_file (active_project -> coordfile, 10);
1329 break;
1330 case 11:
1331 // CIF file using symmetry positions
1332 result = open_coord_file (active_project -> coordfile, 11);
1333 break;
1334 case 12:
1335 // DL-POLY file
1336 result = open_coord_file (active_project -> coordfile, 12);
1337 break;
1338 default:
1339 result = 2;
1340 break;
1341 }
1342 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1343 g_print ("Time to read atomic coordinates: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1344 if (this_reader)
1345 {
1347 {
1348 gchar * info = g_strdup_printf ("%s", this_reader -> info[0]);
1349 int i;
1350 for (i=1; i<this_reader -> msg; i++)
1351 {
1352 info = g_strdup_printf ("%s\n%s", info, this_reader -> info[i]);
1353 }
1354 switch (this_reader -> mid)
1355 {
1356 case 0:
1357 show_error (info, 0, MainWindow);
1358 break;
1359 case 1:
1360 show_warning (info, MainWindow);
1361 break;
1362 }
1363 g_free (info);
1364 }
1365 if (this_reader)
1366 {
1367 if (this_reader -> info) g_free (this_reader -> info);
1368 if (this_reader -> z) g_free (this_reader -> z);
1369 if (this_reader -> nsps) g_free (this_reader -> nsps);
1370 if (this_reader -> dummy) g_free (this_reader -> dummy);
1371 if (this_reader -> label) g_free (this_reader -> label);
1372 if (this_reader -> object_list) g_free (this_reader -> object_list);
1373 if (this_reader -> u_atom_list) g_free (this_reader -> u_atom_list);
1374 if (this_reader -> coord) g_free (this_reader -> coord);
1375 if (this_reader -> lot) g_free (this_reader -> lot);
1376 if (this_reader -> sym_pos) g_free (this_reader -> sym_pos);
1377 if (this_reader -> wyckoff) g_free (this_reader -> wyckoff);
1378 if (this_reader -> occupancy) g_free (this_reader -> occupancy);
1379 if (this_reader -> disorder) g_free (this_reader -> disorder);
1380 if (this_reader -> multi) g_free (this_reader -> multi);
1381 if (this_reader -> lattice.sp_group) g_free (this_reader -> lattice.sp_group);
1382 if (this_reader -> lattice.box) g_free (this_reader -> lattice.box);
1383 g_free (this_reader);
1384 this_reader = NULL;
1385 }
1386 }
1387 switch (result)
1388 {
1389 case 1:
1390 show_error ("Error loading atomic coordinates:\nfile does not exist", 0, MainWindow);
1391 break;
1392 case 2:
1393 show_error ("Error loading coordinates file: format not supported", 0, MainWindow);
1394 break;
1395 case 3:
1396 show_error ("Error at input: impossible to process input file data", 0, MainWindow);
1397 break;
1398 default:
1399 if (id > 6 && id < 9)
1400 {
1401 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1402 if (! prep_data_ ())
1403 {
1404 show_error ("Error while parsing the chemical information\n"
1405 "please check carefully the coordinates file", 0, MainWindow);
1406 result = 4;
1407 }
1408 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1409 g_print ("Time to prepare data: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1410 }
1411 break;
1412 }
1413 return result;
1414}
1415
1416GtkFileFilter * filter[NCFORMATS+1];
1418
1427void open_this_coordinate_file (int format, gchar * proj_name)
1428{
1429 active_project -> newproj = FALSE;
1430 clock_gettime (CLOCK_MONOTONIC, & start_time);
1431 if (open_coordinate_file (format) == 0)
1432 {
1433 clock_gettime (CLOCK_MONOTONIC, & stop_time);
1434 g_print ("Time to open coordinate file: %s\n", calculation_time(FALSE, get_calc_time (start_time, stop_time)));
1435 active_project -> tfile = format;
1436 if (proj_name)
1437 {
1438 active_project -> name = g_strdup_printf ("%s", proj_name);
1439 }
1440 else
1441 {
1442 gchar * str = g_path_get_basename (active_project -> coordfile);
1443 active_project -> name = g_strdup_printf ("%s", substitute_string (str, g_strdup_printf (".%s", coord_files_ext[format]), NULL));
1444 g_free (str);
1445 }
1446 on_edit_activate (NULL, GINT_TO_POINTER(0));
1447 if (format != 1 && format != 4 && format != 6 && format != 9 && format != 10 && format != 11 && format != 12) on_edit_activate (NULL, GINT_TO_POINTER(4));
1449 on_edit_activate (NULL, GINT_TO_POINTER(2));
1451 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
1452 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
1453 chemistry_ ();
1454 apply_project (TRUE);
1456 if ((format == 9 || format == 10 || format == 11) && active_cell -> has_a_box)
1457 {
1458#ifdef GTK3
1459 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_rep[0], TRUE);
1460 set_rep (active_glwin -> ogl_rep[0], & active_glwin -> colorp[0][0]);
1461 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_clones[0], TRUE);
1462 widget_set_sensitive (active_glwin -> ogl_clones[0], active_glwin -> allbonds[1]);
1463 show_hide_clones (active_glwin -> ogl_clones[0], active_glwin);
1464#endif
1465 shift_it (vec3 (0.0, 0.0, 0.0), 1, activep);
1466 active_glwin -> wrapped = TRUE;
1467 }
1469 if ((format == 9 || format == 10) && cif_use_symmetry_positions)
1470 {
1471 gchar * file_name = g_strdup_printf ("%s", active_project -> coordfile);
1472 gchar * proj_name = g_strdup_printf ("%s - symmetry position(s)", active_project -> name);
1473 init_project (TRUE);
1474 active_project -> coordfile = g_strdup_printf ("%s", file_name);
1475 g_free (file_name);
1476 open_this_coordinate_file (11, proj_name);
1477 g_free (proj_name);
1478 }
1479 }
1480 else
1481 {
1483 }
1484}
1485
1486#ifdef GTK4
1496G_MODULE_EXPORT void run_on_coord_port (GtkNativeDialog * info, gint response_id, gpointer data)
1497{
1498 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1499#else
1509G_MODULE_EXPORT void run_on_coord_port (GtkDialog * info, gint response_id, gpointer data)
1510{
1511 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1512#endif
1513 int i, j, k, l, m;
1514 GtkFileFilter * tmp;
1515 int format;
1516 int car_to_au;
1517 i = GPOINTER_TO_INT(data);
1518 gchar * tmp_str;
1519 switch (response_id)
1520 {
1521 case GTK_RESPONSE_ACCEPT:
1522 tmp = gtk_file_chooser_get_filter (chooser);
1523 active_project -> coordfile = file_chooser_get_file_name (chooser);
1524#ifdef GTK4
1526#else
1527 destroy_this_dialog (info);
1528#endif
1529 j = 0;
1530 while (tmp != filter[j]) j++;
1531 if (i == 0)
1532 {
1533#ifdef OSX
1534 j = NCFORMATS;
1535#endif
1536 if (j == NCFORMATS)
1537 {
1538 j = iask ("Please select the file format of the atomic coordinates", "Select format :", 2, MainWindow);
1539 }
1540 open_this_coordinate_file (j, NULL);
1541 }
1542 else
1543 {
1544 if (j < 2)
1545 {
1546 format = iask ("Please select the format of the atomic coordinates", "Select format :", 1, MainWindow);
1547 }
1548 else
1549 {
1550 format = 0;
1551 }
1552 active_cell -> frac = (format < 2) ? 0 : format - 1;
1553 car_to_au = (format == 1) ? 1 : 0;
1554 if (j < 2)
1555 {
1556 m = (active_cell -> npt) ? active_project -> steps : 1;
1557 for (l=0; l<m; l++)
1558 {
1559 lattice_ (& m, & l,
1560 active_cell -> box[l].vect,
1561 active_cell -> box[l].param[0],
1562 active_cell -> box[l].param[1],
1563 & active_cell -> ltype,
1564 & active_cell -> frac,
1565 & active_cell -> pbc);
1566 }
1567 to_read_pos ();
1568 }
1569 int length = strlen (active_project -> coordfile);
1570 for (l=1; l<active_project -> nspec+1; l++)
1571 {
1572 m = strlen(active_chem -> label[l-1]);
1573 send_label_ (& l, & m, active_chem -> label[l-1]);
1574 }
1575 switch (j)
1576 {
1577 case 0:
1578 k = write_xyz_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1579 break;
1580 case 1:
1581 k = write_c3d_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1582 break;
1583 }
1584 if (k)
1585 {
1586 tmp_str = g_strdup_printf ("Impossible to export the atomic coordinates\nError code: %d", k);
1587 show_error (tmp_str, 0, MainWindow);
1588 g_free (tmp_str);
1589 }
1591 }
1592 break;
1593 default:
1594 if (i == 0)
1595 {
1597 }
1598#ifdef GTK4
1600#else
1601 destroy_this_dialog (info);
1602#endif
1603 break;
1604 }
1605}
1606
1615G_MODULE_EXPORT void on_coord_port (GtkWidget * widg, gpointer data)
1616{
1617 int i, j;
1618#ifdef GTK4
1619 GtkFileChooserNative * info;
1620#else
1621 GtkWidget * info;
1622#endif
1623 GtkFileChooser * chooser;
1624 gchar * tmp_str;
1625 int num_files[2]={NCFORMATS, 2};
1626 const gchar * str[2]={"Import atomic coordinates", "Export atomic coordinates"};
1627 const gchar * res[2]={"Open", "Save"};
1628 char * out_files[2] = {"XYZ file",
1629 "Chem3D file"};
1630 char * out_ext[2]={"xyz", "c3d"};
1631 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
1632 pactive = activep;
1633 i = GPOINTER_TO_INT (data);
1634
1635 if ((nprojects > 0 && get_project_by_id(activew) -> natomes) || i == 0)
1636 {
1637 if (i == 0)
1638 {
1639 init_project (TRUE);
1640 }
1641 else
1642 {
1644 }
1645 tmp_str = g_strdup_printf ("%s - %s", prepare_for_title(active_project -> name), str[i]);
1646 info = create_file_chooser (tmp_str,
1647 GTK_WINDOW(MainWindow),
1648 act[i],
1649 res[i]);
1650 g_free (tmp_str);
1651 chooser = GTK_FILE_CHOOSER(info);
1652 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
1653#ifdef GTK3
1654 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1655#endif
1656 for (j=0; j<num_files[i]; j++)
1657 {
1658 filter[j] = gtk_file_filter_new();
1659 if (i == 0)
1660 {
1661 tmp_str = g_strdup_printf ("%s (*.%s)", coord_files[j], coord_files_ext[j]);
1662 }
1663 else
1664 {
1665 tmp_str = g_strdup_printf ("%s (*.%s)", out_files[j], out_ext[j]);
1666 }
1667 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), tmp_str);
1668 g_free (tmp_str);
1669 if (i == 0)
1670 {
1671 tmp_str = g_strdup_printf ("*.%s", coord_files_ext[j]);
1672 }
1673 else
1674 {
1675 tmp_str = g_strdup_printf ("*.%s", out_ext[j]);
1676 }
1677 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), tmp_str);
1678 gtk_file_chooser_add_filter (chooser, filter[j]);
1679 g_free (tmp_str);
1680 }
1681 if (i==0)
1682 {
1683 filter[j] = gtk_file_filter_new();
1684 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), "All files (*)");
1685 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), "*");
1686 gtk_file_chooser_add_filter (chooser, filter[j]);
1687 }
1688 else
1689 {
1691 gtk_file_chooser_set_current_name (chooser, "coord.xyz");
1692 }
1693#ifdef GTK4
1694 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1695#else
1696 run_this_gtk_dialog (info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1697#endif
1698 }
1699 else
1700 {
1701 if (nprojects == 0)
1702 {
1703 show_warning ("No project loaded ... nothing to be saved\n", MainWindow);
1704 }
1705 else
1706 {
1707 tmp_str = g_strdup_printf ("Project <b>%s</b> is empty ... nothing to be saved\n",
1708 get_project_by_id(activew) -> name);
1709 show_warning (tmp_str, MainWindow);
1710 g_free (tmp_str);
1711 }
1712 }
1713 activew = activep;
1715}
Function declarations for the mode edition window.
Binding to the Fortran90 subroutines.
void send_label_(int *, int *, char *)
void read_pos_(double *, double *, double *)
void prep_pos_(int *, int *)
void profree_()
int prep_data_()
int write_xyz_(char *, int *, int *, int *)
void lattice_(int *, int *, double[3][3], double[3], double[3], int *, int *, int *)
int chemistry_()
int write_c3d_(char *, int *, int *, int *)
int read_pdb_(char *, int *)
int open_coordinate_file(int id)
try to open coordinate file, type is based of id
Definition callbacks.c:1266
GtkWidget * read_box
Definition callbacks.c:866
int open_coord_file(gchar *filename, int fti)
open atomic coordinates file
Definition read_coord.c:274
int to_read_trj_or_vas(int ff)
reading CPMD/VASP trajectory - prepare the dialog
Definition callbacks.c:1127
void initcwidgets()
initializing curve values
Definition initc.c:104
void quit_gtk()
Leave the application.
Definition callbacks.c:120
G_MODULE_EXPORT void on_edit_activate(GtkWidget *widg, gpointer data)
create an edition dialog - prepare the dialog
Definition edit_menu.c:845
G_MODULE_EXPORT void run_read_npt_data(GtkDialog *info, gint response_id, gpointer data)
read NPT data associated with atomic coordinates: run the dialog GTK3 callback
Definition callbacks.c:1204
G_MODULE_EXPORT void changed_spec_combo(GtkComboBox *box, gpointer data)
reading CPMD/VASP trajectory, change the active species
Definition callbacks.c:972
int read_npt_data()
read NPT data associated with atomic coordinates: setup the dialog
Definition callbacks.c:1229
int open_save_workspace(FILE *fp, int act)
open or save the active workspace
Definition callbacks.c:232
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:372
G_MODULE_EXPORT void run_on_open_save_active(GtkDialog *info, gint response_id, gpointer data)
open or save an atomes file - running the dialog
Definition callbacks.c:336
double get_z_from_periodic_table(gchar *lab)
get Z from atom label
Definition w_library.c:304
G_MODULE_EXPORT void on_close_workspace(GtkWidget *widg, gpointer data)
close the active workspace
Definition callbacks.c:134
tint osp
Definition callbacks.c:309
GtkWidget * all_sp_box
Definition callbacks.c:867
G_MODULE_EXPORT void on_open_save_activate(GtkWidget *widg, gpointer data)
open or save an atomes file - prepare the dialog
Definition callbacks.c:421
G_MODULE_EXPORT void run_on_coord_port(GtkDialog *info, gint response_id, gpointer data)
export or import atomic coordinates: run dialog
Definition callbacks.c:1509
G_MODULE_EXPORT void run_on_isaacs_port(GtkDialog *info, gint response_id, gpointer data)
open or write ISAACS XML file - running the dialog
Definition callbacks.c:727
char ** las
Definition callbacks.c:104
void apply_project(gboolean showtools)
get project ready for calculation and initialize the OpenGL window
Definition callbacks.c:663
int prep_chem_data()
prepare chemical data to read CPMD/VASP file
Definition callbacks.c:1076
G_MODULE_EXPORT void on_isaacs_port(GtkWidget *widg, gpointer data)
open or write ISAACS XML file - prepare the dialog
Definition callbacks.c:773
void open_this_coordinate_file(int format, gchar *proj_name)
open coordinate file format, if successful add to workspace
Definition callbacks.c:1427
int open_history_file(gchar *filename)
void run_project()
send project data to Fortran90
Definition callbacks.c:631
int open_save(FILE *fp, int i, int pid, int aid, int npi, gchar *pfile)
open or save project file
Definition callbacks.c:175
int pactive
Definition callbacks.c:1417
GtkWidget * sa_entry[2]
Definition callbacks.c:869
G_MODULE_EXPORT void run_to_read_trj_or_vas(GtkDialog *dialog, gint response_id, gpointer data)
reading CPMD/VASP trajectory: run the dialog
Definition callbacks.c:1098
void cell_data_from_pdb_(float *a, float *b, float *c, float *alp, float *bet, float *gam)
update cell parameters from the data in the PDB file
Definition callbacks.c:1164
GtkFileFilter * filter[NCFORMATS+1]
Definition callbacks.c:1416
char * coord_files_ext[NCFORMATS+1]
Definition callbacks.c:101
int open_cif_file(gchar *filename)
G_MODULE_EXPORT void update_sa(GtkEntry *res, gpointer data)
reading CPMD/VASP trajectory, set the number of chemical species
Definition callbacks.c:940
G_MODULE_EXPORT void on_coord_port(GtkWidget *widg, gpointer data)
export or import atomic coordinates: prepare dialog
Definition callbacks.c:1615
G_MODULE_EXPORT void on_save_as_activate(GtkWidget *widg, gpointer data)
open or save, choosing a file name
Definition callbacks.c:619
GtkWidget * read_this
Definition callbacks.c:870
int reading_vas_trj
Definition callbacks.c:1069
void update_sa_info(int sid)
reading CPMD/VASP trajectory, update chemical species info
Definition callbacks.c:904
int read_spec
Definition callbacks.c:871
void prepare_sp_box()
eading CPMD/VASP trajectory, prepare the species combo box
Definition callbacks.c:982
const gchar * dfi[2]
Definition main.c:76
char * coord_files[NCFORMATS+1]
Definition callbacks.c:86
int npt_selection
Definition callbacks.c:1178
gboolean save
Definition callbacks.c:161
G_MODULE_EXPORT void update_at_sp(GtkEntry *res, gpointer data)
reading CPMD/VASP trajectory, changing number of atomes or species
Definition callbacks.c:1036
void open_this_isaacs_xml_file(gchar *profile, int ptoc, gboolean visible)
open an ISAACS XML file
Definition callbacks.c:683
void open_this_proj(gpointer data, gpointer user_data)
Open many projects, one at a time.
Definition callbacks.c:299
void to_read_pos()
send atomic coordinates to Fortran90
Definition callbacks.c:829
int open_cell_file(int format, gchar *filename)
open the file that contains the cell parameters
Definition read_npt.c:231
GtkWidget * sa_lab[2]
Definition callbacks.c:868
gchar * npt_file
Definition callbacks.c:1179
gboolean run_os
Definition callbacks.c:310
void check_read_sa()
reading CPMD/VASP trajectory, testing parameters to active the read capabilty
Definition callbacks.c:878
Callback declarations for main window.
int occupancy(double occ, int cif_occ)
handle occupancy integer rouding
void shift_it(vec3_t shift, int refresh, int proj)
shift atomic coordinates
Definition cell_shift.c:206
Function declarations for the cell edition window.
void update_insert_combos()
update some GtkComboBox in the workspace if a project is removed
Definition close_p.c:60
void to_close_this_project(int to_activate, project *this_proj)
to close this project
Definition close_p.c:332
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:355
color colorp[64]
gchar * param[2]
dummy_atom * dummy
Definition cpmd_atoms.c:73
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
int atoms[NUM_STYLES][2]
dint up
int multi
Definition dlp_init.c:121
FILE * fp
gboolean reading_input
Definition global.c:182
int mol_update
Definition global.c:171
gchar * workspacefile
Definition global.c:156
gboolean newspace
Definition global.c:181
struct timespec start_time
Definition global.c:191
int activep
Definition global.c:159
gboolean silent_input
Definition global.c:188
int activew
Definition global.c:163
GtkApplication * AtomesApp
Definition global.c:200
int nprojects
Definition global.c:158
int frag_update
Definition global.c:170
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:459
GtkWidget * MainWindow
Definition global.c:201
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:656
gchar * projfile
Definition global.c:141
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:643
struct timespec stop_time
Definition global.c:192
gboolean cif_use_symmetry_positions
Definition global.c:189
GtkWidget * curvetoolbox
Definition global.c:205
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
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2323
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
glwin * active_glwin
Definition project.c:53
#define ATOM_LIMIT
atom number limit to compute fragment(s) and molecule(s) analysis automatically
GtkWidget * dialogmodal(gchar *str, GtkWindow *parent)
Create a new dialog modal window.
Definition gtk-misc.c:520
cell_info * active_cell
Definition project.c:50
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:932
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2271
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:607
chemical_data * active_chem
Definition project.c:48
#define BSEP
Definition global.h:247
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:624
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2304
#define STEP_LIMIT
Definition global.h:279
box_info * active_box
Definition project.c:51
#define NCFORMATS
Definition global.h:320
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
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
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2200
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:823
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2169
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:681
GSList * file_chooser_get_file_names(GtkFileChooser *chooser)
create a file list from files selected using a GtkFileChooser
Definition gtk-misc.c:2258
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:811
GtkWidget * create_file_chooser(const gchar *title, GtkWindow *parent, GtkFileChooserAction act, const gchar *act_name)
create a GtkFileChooser, utility to select file(s)
Definition gtk-misc.c:2358
project * active_project
Definition project.c:47
void initcutoffs(chemical_data *chem, int species)
initialize bond cutoffs
Definition bdcall.c:238
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2219
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...
action
Definition glview.h:198
G_MODULE_EXPORT void show_hide_clones(GSimpleAction *action, GVariant *state, gpointer data)
show/hide clones menu item callback
Definition m_clones.c:139
void prep_model(int p)
prepare, or display, the OpenGL model window
Definition glwindow.c:1533
Function declarations for the creation of the OpenGL window.
void init_project(gboolean alloc_box)
initialize a new project
Definition init_p.c:163
int iask(char *question, char *lab, int id, GtkWidget *win)
enter an integer value - prepare the dialog
Definition interface.c:556
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:260
void show_info(char *information, int val, GtkWidget *win)
add / show information message to widget
Definition interface.c:234
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:293
gboolean ask_yes_no(gchar *title, gchar *text, int type, GtkWidget *widg)
ask yes or no for something: prepare dialog
Definition interface.c:356
Messaging function declarations.
void prep_calc_actions()
prepare analysis widgets
Definition update_p.c:58
integer(kind=c_int) function lattice(totl, lid, vectors, vmod, angles, lat, cfrac, apbc)
Definition lattice.F90:162
G_MODULE_EXPORT void set_rep(GtkWidget *widg, gpointer data)
change representation callback
Definition m_rep.c:599
double z
Definition ogl_draw.c:61
double y
Definition ogl_draw.c:61
double x
Definition ogl_draw.c:61
int open_project(FILE *fp, int npi)
open atomes project file
Definition open_p.c:224
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int save_project(FILE *fp, project *this_proj, int wid)
save project to file
Definition save_p.c:84
void active_project_changed(int id)
change the active project
Definition update_p.c:175
coord_file * this_reader
Definition read_coord.c:73
int write_xml(const char *filetosave)
write XML file
gchar * open_xml(const char *filetoread)
Open ISAACS XML file.
Functions declaration to read atomic coordinates.
Definition glwin.h:351
Definition global.h:106
int b
Definition global.h:108
int c
Definition global.h:109
int a
Definition global.h:107
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
GtkFileFilter * filter1
Definition w_data.c:52
GtkFileFilter * filter2
Definition w_data.c:52
GtkWidget * res[2]
Definition w_encode.c:212
void add_project_to_workspace()
add project(s) to the workspace tree
Definition workspace.c:610
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73
Function declarations for workspace managment.