atomes 1.3.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-2026 by CNRS and University of Strasbourg */
15
22
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 signal_error (gchar * file, gchar * func, int error_line, int error_id);
36 int open_save (FILE * fp, int act, int wid, int pid, int aid, gchar * pfile);
37 int open_save_workspace (FILE * fp, int act);
38 int prep_chem_data ();
39 int to_read_trj_or_vas (int ff);
40 int read_npt_data ();
41 int open_coordinate_file (int id);
42
43 void quit_gtk ();
44 void update_error_trace (gchar * file, gchar * func, int trace_line);
45 void open_this_proj (gpointer data, gpointer user_data);
46 void run_project ();
47 void apply_project (gboolean showtools);
48 void open_this_isaacs_xml_file (gchar * profile, int ptoc, gboolean visible);
49 void to_read_pos ();
50 void check_read_sa ();
51 void update_sa_info (int sid);
52 void prepare_sp_box ();
53 void cell_data_from_pdb_ (float * a, float * b, float * c, float * alp, float * bet, float * gam);
54 void open_this_coordinate_file (int format, gchar * proj_name);
55
56 G_MODULE_EXPORT void on_close_workspace (GtkWidget * widg, gpointer data);
57 G_MODULE_EXPORT void run_on_open_save_active (GtkNativeDialog * info, gint response_id, gpointer data);
58 G_MODULE_EXPORT void run_on_open_save_active (GtkDialog * info, gint response_id, gpointer data);
59 G_MODULE_EXPORT void on_open_save_activate (GtkWidget * widg, gpointer data);
60 G_MODULE_EXPORT void on_save_as_activate (GtkWidget * widg, gpointer data);
61 G_MODULE_EXPORT void run_on_isaacs_port (GtkNativeDialog * info, gint response_id, gpointer data);
62 G_MODULE_EXPORT void run_on_isaacs_port (GtkDialog * info, gint response_id, gpointer data);
63 G_MODULE_EXPORT void on_isaacs_port (GtkWidget * widg, gpointer data);
64 G_MODULE_EXPORT void update_sa (GtkEntry * res, gpointer data);
65 G_MODULE_EXPORT void changed_spec_combo (GtkComboBox * box, gpointer data);
66 G_MODULE_EXPORT void update_at_sp (GtkEntry * res, gpointer data);
67 G_MODULE_EXPORT void run_to_read_trj_or_vas (GtkDialog * dialog, gint response_id, gpointer data);
68 G_MODULE_EXPORT void run_read_npt_data (GtkNativeDialog * info, gint response_id, gpointer data);
69 G_MODULE_EXPORT void run_read_npt_data (GtkDialog * info, gint response_id, gpointer data);
70 G_MODULE_EXPORT void run_on_coord_port (GtkNativeDialog * info, gint response_id, gpointer data);
71 G_MODULE_EXPORT void run_on_coord_port (GtkDialog * info, gint response_id, gpointer data);
72 G_MODULE_EXPORT void on_coord_port (GtkWidget * widg, gpointer data);
73
74*/
75
76#include "global.h"
77#include "interface.h"
78#include "callbacks.h"
79#include "bind.h"
80#include "project.h"
81#include "workspace.h"
82#include "glwindow.h"
83#include "glview.h"
84#include "atom_edit.h"
85#include "cell_edit.h"
86#include "readers.h"
87
88char * coord_files[NCFORMATS+1] = {i18n("XYZ file"),
89 i18n("XYZ file - NPT"),
90 i18n("Chem3D file"),
91 i18n("CPMD trajectory"),
92 i18n("CPMD trajectory - NPT"),
93 i18n("VASP trajectory"),
94 i18n("VASP trajectory - NPT"),
95 i18n("PDB file"),
96 i18n("PDB file"),
97 i18n("Cryst. information (crystal build) - single configuration"),
98 i18n("Cryst. information (crystal build) - multiple configurations"),
99 i18n("Cryst. information (symmetry positions) - single configuration"),
100 i18n("DL-POLY HISTORY file"),
101 i18n("ISAACS Project File")};
102
103char * coord_files_ext[NCFORMATS+1]={"xyz", "xyz", "c3d", "trj", "trj", "xdatcar", "xdatcar",
104 "pdb", "ent", "cif", "cif", "cif", "hist", "ipf"};
105
106char ** las;
107
108extern void simple_image_render();
109extern G_MODULE_EXPORT void on_edit_activate (GtkWidget * widg, gpointer data);
110extern gchar * substitute_string (gchar * init, gchar * o_motif, gchar * n_motif);
111extern const gchar * dfi[2];
112extern int open_cif_file (gchar * filename);
113extern int open_coord_file (gchar * filename, int fti);
114extern int open_history_file (gchar * filename);
115extern int open_cell_file (int format, gchar * filename);
116extern double get_z_from_periodic_table (gchar * lab);
117
126G_MODULE_EXPORT void on_close_workspace (GtkWidget * widg, gpointer data)
127{
128 int i, j;
129 gboolean close = FALSE;
130 j = GPOINTER_TO_INT (data);
131 if (j == 1)
132 {
133 close = ask_yes_no (_("Close workspace ?"), _("Are you sure ?"), GTK_MESSAGE_QUESTION, MainWindow);
134 }
135 else
136 {
137 close = TRUE;
138 }
139
140 if (close)
141 {
142 j = nprojects-1;
143 for (i=j; i>-1; i--)
144 {
145#ifdef DEBUG
146 g_debug ("CLOSING:: %d", i);
147#endif
148 on_close_activate (NULL, GINT_TO_POINTER(i));
149 }
150 }
151}
152
153gboolean save = TRUE;
154
157 { ERROR_PROJECT, i18n("project information")},
158 { ERROR_CURVE, i18n("curve(s) information")},
159 { ERROR_IMAGE, i18n("OpenGL information")},
160 { ERROR_ATOM_A, i18n("atom's data - A")},
161 { ERROR_ATOM_B, i18n("atom's data - B")},
162 { ERROR_UPDATE, i18n("updating project")},
163 { ERROR_NO_WAY, i18n("this should not happen")},
164 { ERROR_COORD, i18n("coordination data")},
165 { ERROR_RINGS, i18n("ring(s) data")},
166 { ERROR_CHAINS, i18n("chain(s) data")},
167 { ERROR_MOL, i18n("molecule(s) data")},
168 { ERROR_ANA, i18n("analysis data")},
169 { ERROR_QM, i18n("ab-initio data")},
170 { ERROR_FIELD, i18n("classical data")}};
171
182int signal_error (const char * file, const char * func, int error_line, int error_id)
183{
184 project_error -> error_file = g_strdup_printf("%s", file);
185 project_error -> error_func = g_strdup_printf("%s", func);
186 project_error -> error_line = error_line;
187 project_error -> error_signal = errors_messages[error_id-1];
188 return error_line;
189}
190
200void update_error_trace (const char * file, const char * func, int trace_line)
201{
202 gchar * intro = "<span font_desc=\"monospace 10\">\n";
203 gchar * file_part;
204 gchar * func_part;
205 gchar * line_part;
206 gchar * tab_part = NULL;
207 gchar * tmp_trace;
208 int i;
209 if (project_error -> trace_id)
210 {
211 tmp_trace = g_strdup_printf ("%s\n%s", project_error -> error_trace, intro);
212 g_free (project_error -> error_trace);
213 }
214 else
215 {
216 tmp_trace = g_strdup_printf ("%s", intro);
217 }
218 for (i=0; i<project_error -> trace_id+1; i++)
219 {
220 tab_part = (tab_part) ? g_strdup_printf ("%s\t\t", tab_part) : g_strdup_printf ("\t\t");
221 }
222 file_part = g_strdup_printf (_("File : %s\n"), file);
223 func_part = g_strdup_printf (_("Function: %s()\n"), func);
224 line_part = g_strdup_printf (_("Line : %d</span>"), trace_line);
225 project_error -> error_trace = g_strdup_printf ("%s%s%s%s%s%s%s", tmp_trace, tab_part, file_part, tab_part, func_part, tab_part, line_part);
226 g_free (tmp_trace);
227 g_free (tab_part);
228 g_free (file_part);
229 g_free (func_part);
230 g_free (line_part);
231 project_error -> trace_id ++;
232}
233
246int open_save (FILE * fp, int act, int wid, int pid, int aid, gchar * pfile)
247{
248 int j;
249 project_error = g_malloc0(sizeof*project_error);
250 gchar * tmp_err;
251 if (act == 0)
252 {
253 reading_input = TRUE;
254 j = open_project (fp, wid);
255 reading_input = FALSE;
256 if (j != OK)
257 {
258 tmp_err = g_strdup_printf ("%s", get_project_by_id (pid) -> name);
260 }
261 else
262 {
263 get_project_by_id (pid) -> projfile = g_strdup_printf ("%s", pfile);
265 {
268 }
269 else
270 {
272 }
273 }
274 }
275 else
276 {
277 j = save_project (fp, get_project_by_id(pid), wid);
278 if (j == OK)
279 {
280 if (pfile != NULL) get_project_by_id(pid) -> projfile = g_strdup_printf ("%s", pfile);
281 }
282 else
283 {
284 tmp_err = g_strdup_printf ("%s", get_project_by_id(pid) -> name);
285 }
286 }
287 if (j != OK)
288 {
289 gchar * err;
290 if (pfile != NULL && ! wid)
291 {
292 err = g_strdup_printf (_("Impossible to %s project file: \n\n"
293 "\t\t%s\n\n"
294 "\tError %s %s\n"
295 "\tProject file version: <b>%1.1f</b>\n"),
296 (! act) ? _("open") : _("save"),
297 pfile,
298 (! act) ? _("reading") : _("saving"),
299 _(project_error -> error_signal.message),
301
302 }
303 else if (wid)
304 {
305 err = g_strdup_printf (_("Impossible to %s workspace file.\n"
306 "Error with project: \n\n"
307 "\t\t%s\n\n"
308 "\tError %s %s\n"
309 "\tProject file version: <b>%1.1f</b>\n"),
310 (! act) ? _("open") : _("save"),
311 tmp_err,
312 (! act) ? _("reading") : _("saving"),
313 _(project_error -> error_signal.message),
315 }
317 g_free (tmp_err);
318 g_free (err);
319 }
320 g_free (project_error);
321 project_error = NULL;
322 return j;
323}
324
330void quit_gtk ()
331{
333 {
334 // Update image for LibreOffice document
335 atomes_render_image = TRUE;
337 atomes_render_image = FALSE;
338 // Mandatory saving of the project file
339 FILE * fp = fopen (projfile, dfi[1]);
340 open_save (fp, 1, 1, 0, 0, NULL);
341 fclose (fp);
343 }
344 else
345 {
346 int i;
347 for (i=nprojects-1; i>=0; i--) to_close_this_project (i, get_project_by_id(i));
348 }
349 profree_ ();
350 g_application_quit (G_APPLICATION(AtomesApp));
351}
352
361int open_save_workspace (FILE * fp, int act)
362{
363 int i, j, k, l;
364 gchar * ver;
365 /*PangoFontDescription * font_desc;
366 GtkTextBuffer * buffer;
367 GtkTextIter bStart;
368 GtkTextIter bEnd;*/
369
370 // First 2 lines for compatibility issues
371 if (act == 0)
372 {
373 if (fread (& i, sizeof(int), 1, fp) != 1) return 1;
374 ver = g_malloc0(i*sizeof*ver);
375 if (fread (ver, sizeof(char), i, fp) != i) return 1;
376 // test on ver for version ?
377 g_free (ver);
378 if (fread (& i, sizeof(int), 1, fp) != 1) return 1;
379 }
380 else
381 {
382 i = 1;
383 ver = g_strdup_printf ("%%\n%% Workspace file v-%1d.0\n%%\n", i);
384 i = strlen (ver);
385 if (fwrite (& i, sizeof(int), 1, fp) != 1) return 1;
386 if (fwrite (ver, sizeof(char), i, fp) != i) return 1;
387 g_free (ver);
388 i = 0;
389 for (j=0; j<nprojects; j++) if (get_project_by_id(j) -> natomes) i++;
390 if (fwrite (& i, sizeof(int), 1, fp) != 1) return 1;
391 }
392
393 if (i > 0)
394 {
395 for (j=0; j<i; j++)
396 {
397 k = activep;
398 if (act == 0)
399 {
400 init_project (FALSE);
401 l = open_save (fp, act, 1, j, k, NULL);
402 if (l != 0) return l;
403 }
404 else if (get_project_by_id(j) -> natomes)
405 {
406 l = open_save (fp, act, 1, j, k, NULL);
407 if (l != 0) return l;
408 }
409 }
410 return 0;
411 }
412 else
413 {
414 return -1;
415 }
416}
417
426void open_this_proj (gpointer data, gpointer user_data)
427{
428 FILE * fp = fopen (data, dfi[0]);
429 int pactive = activep;
430 init_project (FALSE);
431 reading_project = TRUE;
432 open_save (fp, 0, 0, activew, pactive, data);
433 reading_project = FALSE;
434 fclose (fp);
436}
437
439gboolean run_os;
440
441#ifdef GTK4
451G_MODULE_EXPORT void run_on_open_save_active (GtkNativeDialog * info, gint response_id, gpointer data)
452{
453 GListModel * projlist;
454 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
455#else
465G_MODULE_EXPORT void run_on_open_save_active (GtkDialog * info, gint response_id, gpointer data)
466{
467 GSList * projlist = NULL;
468 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
469#endif
470 FILE * fp = NULL;
471 gchar * err;
472 gboolean io = FALSE;
473 const gchar * mess[2]={i18n("reading"),i18n("saving")};
474 if (response_id == GTK_RESPONSE_ACCEPT)
475 {
476 if (osp.a == 0)
477 {
478 projlist = file_chooser_get_file_names (chooser);
479 }
480 else
481 {
483 }
484 if (osp.a > 1)
485 {
486 workspacefile = g_strdup_printf ("%s", projfile);
487 }
488 io = TRUE;
489 }
490 if (run_os)
491 {
492#ifdef GTK4
494#else
495 destroy_this_dialog (info);
496#endif
497 }
498 if (io)
499 {
500 if (osp.a > 0)
501 {
502 fp = fopen (projfile, dfi[osp.b]);
503 }
504 if (osp.a == 0)
505 {
506#ifdef GTK3
507 g_slist_foreach (projlist, open_this_proj, NULL);
508 g_slist_free (projlist);
509#else
510 int i;
511 for (i=0; i<g_list_model_get_n_items (projlist); i++)
512 {
513 GObject * obj = g_list_model_get_item (projlist, i);
514 open_this_proj (g_file_get_parse_name((GFile *)obj), NULL);
515 }
516 g_object_unref (projlist);
517#endif
518 }
519 else if (osp.a == 1)
520 {
521 open_save (fp, osp.a, 0, activew, osp.c, projfile);
522 }
523 else
524 {
525 int k = open_save_workspace (fp, osp.b);
526 if (k != 0)
527 {
528 err = g_strdup_printf (_("Error %s workspace file\n%s\n"), _(mess[osp.b]), projfile);
529 show_error (err, 0, MainWindow);
530 g_free (err);
531 }
532 }
533 if (osp.a > 0)
534 {
535 fclose (fp);
536 g_free (projfile);
537 }
538 }
539}
540
549G_MODULE_EXPORT void on_open_save_activate (GtkWidget * widg, gpointer data)
550{
551 int i, j, k;
552 gint action;
553#ifdef GTK4
554 GtkFileChooserNative * info;
555#else
556 GtkWidget * info;
557#endif
558 GtkFileChooser * chooser;
559 GtkFileFilter * filter1, * filter2;
560 const gchar * str[4]={i18n("Open Project File(s)"), i18n("Save Project File"), i18n("Open Workspace"), i18n("Save Workspace")};
561 const gchar * res[2]={i18n("Open"), i18n("Save")};
562 const gchar * file_name[2]={i18n("Project file (*.apf)"), i18n("Workspace file (*.awf)")};
563 const gchar * file_ext[2]={"*.apf", "*.awf"};
564 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
565 project * this_proj = get_project_by_id (activew);
566 int pactive = activep;
567 i = GPOINTER_TO_INT (data);
568 run_os = FALSE;
569 if (i == 1 || i == 3)
570 {
571 j = 1;
572 }
573 else
574 {
575 j = 0;
576 }
577 action = 0;
578 if (i == 2 && ! newspace)
579 {
580 show_info (_("A workspace is already open !"), 0, MainWindow);
581 }
582 else if (i == 3 && newspace)
583 {
584 show_warning (_("Empty workspace ... nothing to be saved\n"), MainWindow);
585 }
586 else if (i == 3)
587 {
588 for (k=0; k<nprojects; k++) if (get_project_by_id(k) -> natomes) action = 1;
589 if (! action)
590 {
591 show_warning (_("Workspace contains only empty projects ... nothing to be saved\n"), MainWindow);
592 }
593 }
594 else if (i == 1 && nprojects == 0)
595 {
596 show_warning (_("No project open ... nothing to be saved\n"), MainWindow);
597 }
598 else if (i == 1 && ! this_proj -> natomes)
599 {
600 show_warning (_("Empty project ... nothing to be saved\n"), MainWindow);
601 }
602 else
603 {
604 action = 1;
605 }
606
607 if (action)
608 {
609 if (nprojects == 0)
610 {
611 run_os = TRUE;
612 }
613 else
614 {
615 if (i == 1)
616 {
617 if (g_strcmp0(this_proj -> projfile, "(null)") == 0) this_proj -> projfile = NULL;
618 if (save && this_proj -> projfile != NULL)
619 {
620 run_os = FALSE;
621 projfile = g_strdup_printf ("%s", this_proj -> projfile);
622 }
623 else
624 {
625 run_os = TRUE;
626 projfile = NULL;
627 }
628 }
629 else if (i == 3)
630 {
631 if (g_strcmp0(workspacefile, "(null)") == 0) workspacefile = NULL;
632 if (save && workspacefile != NULL)
633 {
634 run_os = FALSE;
635 projfile = g_strdup_printf ("%s", workspacefile);
636 }
637 else
638 {
639 run_os = TRUE;
640 }
641 }
642 else
643 {
644 run_os = TRUE;
645 }
646 }
647
648 gchar * tmp_str;
649 if (i == 0)
650 {
651 tmp_str = g_strdup_printf (_("%s - New project"), _(str[i]));
652 }
653 else if (i == 1)
654 {
655 tmp_str = g_strdup_printf ("%s - %s", _(str[i]), prepare_for_title(this_proj -> name));
656 }
657 else
658 {
659 tmp_str = g_strdup_printf ("%s", _(str[i]));
660 }
661 info = create_file_chooser (tmp_str,
662 GTK_WINDOW(MainWindow),
663 act[j],
664 _(res[j]));
665 chooser = GTK_FILE_CHOOSER (info);
666 g_free (tmp_str);
667#ifdef GTK3
668 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
669#endif
670 if (i == 1 || i == 3) gtk_file_chooser_set_create_folders (chooser, TRUE);
671 if (nprojects == 0 || i == 0)
672 {
674 if (i == 0)
675 {
676 gtk_file_chooser_set_select_multiple (chooser, TRUE);
677 }
678 }
679 else
680 {
681 if (i == 1)
682 {
683 if (projfile != NULL)
684 {
686 gtk_file_chooser_set_current_name (chooser, projfile);
687 }
688 else
689 {
690 if (! file_chooser_set_file_name (chooser, g_strdup_printf ("%s.apf", prepare_for_title(this_proj -> name)))) goto end;
691 }
692 }
693 else if (i == 3)
694 {
695 if (workspacefile != NULL)
696 {
698 gtk_file_chooser_set_current_name (chooser, g_strdup_printf ("%s", workspacefile));
699 }
700 else
701 {
702 if (! file_chooser_set_file_name (chooser, "New-Workspace.awf")) goto end;
703 }
704 }
705 }
706 filter1 = gtk_file_filter_new();
707 gtk_file_filter_set_name (GTK_FILE_FILTER(filter1), _(file_name[i/2]));
708 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter1), file_ext[i/2]);
709 gtk_file_chooser_add_filter (chooser, filter1);
710 filter2 = gtk_file_filter_new();
711 gtk_file_filter_set_name (GTK_FILE_FILTER(filter2), _("All files (*)"));
712 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter2), "*");
713 gtk_file_chooser_add_filter (chooser, filter2);
714 osp.a = i;
715 osp.b = j;
716 osp.c = pactive;
717 if (run_os)
718 {
719#ifdef GTK4
720 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_open_save_active), this_proj);
721#else
722 run_this_gtk_dialog (info, G_CALLBACK(run_on_open_save_active), this_proj);
723#endif
724 }
725 else
726 {
727#ifdef GTK4
728 run_on_open_save_active ((GtkNativeDialog *)info, GTK_RESPONSE_ACCEPT, this_proj);
729#else
730 run_on_open_save_active ((GtkDialog *)info, GTK_RESPONSE_ACCEPT, this_proj);
731#endif
732 }
733 }
736 end:;
737}
738
747G_MODULE_EXPORT void on_save_as_activate (GtkWidget * widg, gpointer data)
748{
749 save = FALSE;
750 on_open_save_activate (widg, data);
751 save = TRUE;
752}
753
760{
761 if (! active_project -> run)
762 {
763 if (! active_project -> analysis)
764 {
766 }
767 int i, j;
768 j = (active_cell -> npt) ? active_project -> steps : 1;
769 for (i=0; i<j; i++)
770 {
771 lattice_ (& j, & i,
772 active_cell -> box[i].vect,
773 active_cell -> box[i].param[0],
774 active_cell -> box[i].param[1],
775 & active_cell -> ltype,
776 & active_cell -> frac,
777 & active_cell -> pbc);
778 }
779 to_read_pos ();
780 prep_pos_ (& active_cell -> pbc, & active_cell -> frac);
781 active_project -> dmtx = FALSE;
782 active_project -> run = 1;
783 }
784 if (active_cell -> frac) active_cell -> frac = 0;
785}
786
794void apply_project (gboolean showtools)
795{
796 if (active_project -> natomes)
797 {
798 run_project ();
800 }
803}
804
814void open_this_isaacs_xml_file (gchar * profile, int ptoc, gboolean visible)
815{
816 if (! open_xml (profile))
817 {
818 active_project -> name = substitute_string (g_path_get_basename (profile), ".ipf", NULL);
819 on_edit_activate (NULL, GINT_TO_POINTER(3));
820 on_edit_activate (NULL, GINT_TO_POINTER(5));
822 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
823 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
824 apply_project (TRUE);
827 if (visible) show_info (_("ISAACS project file (XML) successfully opened"), 0, MainWindow);
828 }
829 else
830 {
832 }
833}
834
835#ifdef GTK4
845G_MODULE_EXPORT void run_on_isaacs_port (GtkNativeDialog * info, gint response_id, gpointer data)
846{
847 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
848#else
858G_MODULE_EXPORT void run_on_isaacs_port (GtkDialog * info, gint response_id, gpointer data)
859{
860 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
861#endif
862 if (response_id == GTK_RESPONSE_ACCEPT)
863 {
864 if (osp.a == 0 || nprojects == 0) init_project (TRUE);
866#ifdef GTK4
868#else
869 destroy_this_dialog (info);
870#endif
871 if (osp.a == 0)
872 {
874 }
875 else if (osp.a == 1)
876 {
878 if (write_xml (projfile) == 0)
879 {
880 show_error (_("Impossible to write the IPF file\n"), 0, MainWindow);
881 }
883 }
884 g_free (projfile);
885 }
886 else
887 {
888#ifdef GTK4
890#else
891 destroy_this_dialog (info);
892#endif
893 }
894}
895
904G_MODULE_EXPORT void on_isaacs_port (GtkWidget * widg, gpointer data)
905{
906 int i, j;
907 gboolean action;
908#ifdef GTK4
909 GtkFileChooserNative * info;
910#else
911 GtkWidget * info;
912#endif
913 GtkFileChooser * chooser;
914 GtkFileFilter * filter[2];
915 const gchar * file_ext[2]={"*.ipf", "*"};
916 const gchar * file_type[2]={i18n("IPF file (*.ipf)"), i18n("All files (*)")};
917 const gchar * str[2]={i18n("Import ISAACS Project File"), i18n("Export ISAACS Project File")};
918 const gchar * res[2]={i18n("Open"), i18n("Save")};
919 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
920 int pactive = activep;
921 i = GPOINTER_TO_INT (data);
922
923 action = (i && ! nprojects) ? ask_yes_no (_("Save an empty project ?"), _("Do you want to save an empty project ?"), GTK_MESSAGE_QUESTION, MainWindow) : TRUE;
924 if (action)
925 {
926 info = create_file_chooser (_(str[i]),
927 GTK_WINDOW(MainWindow),
928 act[i],
929 _(res[i]));
930 chooser = GTK_FILE_CHOOSER (info);
931#ifdef GTK3
932 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
933#endif
934 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
935 for (j=0; j<2; j++)
936 {
937 filter[j] = gtk_file_filter_new();
938 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), _(file_type[j]));
939 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), file_ext[j]);
940 gtk_file_chooser_add_filter (chooser, filter[j]);
941 }
943 osp.a = i;
944 osp.b = pactive;
945#ifdef GTK4
946 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_isaacs_port), NULL);
947#else
948 run_this_gtk_dialog (info, G_CALLBACK(run_on_isaacs_port), NULL);
949#endif
950 }
953}
954
961{
962 int i, j, k;
963 double * x, * y, * z;
964 double lat[3];
965
966 x = allocdouble (active_project -> steps*active_project -> natomes);
967 y = allocdouble (active_project -> steps*active_project -> natomes);
968 z = allocdouble (active_project -> steps*active_project -> natomes);
969 k = 0;
970 lat[0] = lat[1] = lat[2] = 0.0;
971 if (active_cell -> crystal)
972 {
973 for (i=0; i<3; i++)
974 {
975 for (j=0; j<3; j++) lat[i] -= active_box -> vect[j][i]/2.0;
976 }
977 }
978 for (i=0; i<active_project -> steps; i++)
979 {
980 for (j=0; j<active_project -> natomes; j++)
981 {
982 x[k] = active_project -> atoms[i][j].x + lat[0];
983 y[k] = active_project -> atoms[i][j].y + lat[1];
984 z[k] = active_project -> atoms[i][j].z + lat[2];
985 k ++;
986 }
987 }
988 read_pos_ (x, y, z);
989 g_free (x);
990 x = NULL;
991 g_free (y);
992 y = NULL;
993 g_free (z);
994 z = NULL;
995}
996
997GtkWidget * read_box;
998GtkWidget * all_sp_box = NULL;
999GtkWidget * sa_lab[2];
1000GtkWidget * sa_entry[2];
1001GtkWidget * read_this;
1003
1010{
1011 int i, j, k;
1012 i = j = 0;
1013 for (k=0; k<this_reader -> nspec; k++)
1014 {
1015 i += this_reader -> nsps[k];
1016 j += (this_reader -> label[k]) ? 1: 0;
1017 }
1018 if (i == this_reader -> natomes && j == this_reader -> nspec)
1019 {
1021 }
1022 else
1023 {
1025 }
1026}
1027
1035void update_sa_info (int sid)
1036{
1037 gchar * str = g_strdup_printf (_("Label of atomic spec. N° %d:"), sid+1);
1038 gtk_label_set_text (GTK_LABEL(sa_lab[0]), str);
1039 g_free (str);
1040 if (this_reader -> label[sid])
1041 {
1042 update_entry_text (GTK_ENTRY(sa_entry[0]), this_reader -> label[sid]);
1043 str = g_strdup_printf (_("Number of %s atom(s):"), this_reader -> label[sid]);
1044 }
1045 else
1046 {
1047 update_entry_text (GTK_ENTRY(sa_entry[0]), "");
1048 str = g_strdup_printf (_("Number of atom(s) for spec. N° %d:"), sid+1);
1049 }
1050 gtk_label_set_text (GTK_LABEL(sa_lab[1]), str);
1051 g_free (str);
1052 if (this_reader -> nsps[sid])
1053 {
1054 update_entry_int (GTK_ENTRY(sa_entry[1]), this_reader -> nsps[sid]);
1055 }
1056 else
1057 {
1058 update_entry_text (GTK_ENTRY(sa_entry[1]), "");
1059 }
1060 read_spec = sid;
1061}
1062
1071G_MODULE_EXPORT void update_sa (GtkEntry * res, gpointer data)
1072{
1073 int i, v;
1074 i = GPOINTER_TO_INT(data);
1075 const gchar * m = entry_get_text (res);
1076 if (i == 0)
1077 {
1078 if (this_reader -> label[read_spec]) g_free (this_reader -> label[read_spec]);
1079 this_reader -> label[read_spec] = NULL;
1080 this_reader -> label[read_spec] = g_strdup_printf ("%s", m);
1082 }
1083 else
1084 {
1085 v= (int)string_to_double ((gpointer)m);
1086 if (v > 0)
1087 {
1088 this_reader -> nsps[read_spec] = v;
1089 }
1091 }
1092 check_read_sa ();
1093}
1094
1103G_MODULE_EXPORT void changed_spec_combo (GtkComboBox * box, gpointer data)
1104{
1105 update_sa_info (combo_get_active ((GtkWidget *)box));
1106}
1107
1114{
1115 int i;
1116 if (all_sp_box)
1117 {
1118 for (i=0; i<2; i++)
1119 {
1122 }
1124 }
1127 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, read_box, all_sp_box, FALSE, FALSE, 20);
1128 GtkWidget * hbox;
1129 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, markup_label(_("Chemical species info:"), 200, -1, 0.5, 0.5), FALSE, FALSE, 0);
1130 hbox = create_hbox(0);
1131 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1132 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_("Species: "), 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
1133 GtkWidget * combo;
1134 combo = create_combo ();
1135 gchar * str;
1136
1137 for (i=0; i<this_reader -> nspec; i++)
1138 {
1139 str = g_strdup_printf ("N°%d", i+1);
1140 gtk_combo_box_text_append_text ((GtkComboBoxText *)combo, str);
1141 g_free (str);
1142 }
1143 combo_set_active (combo, 0);
1144 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK(changed_spec_combo), NULL);
1145 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, combo, FALSE, FALSE, 5);
1146 for (i=0; i<2; i++)
1147 {
1148 hbox = create_hbox(0);
1149 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1150 sa_lab[i] = markup_label("", 250, -1, 0.0, 0.5);
1151 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_lab[i], FALSE, FALSE, 5);
1152 sa_entry[i] = create_entry (G_CALLBACK(update_sa), 100, 15, FALSE, GINT_TO_POINTER(i));
1153 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_entry[i], FALSE, FALSE, 0);
1154 }
1156 update_sa_info (0);
1157}
1158
1167G_MODULE_EXPORT void update_at_sp (GtkEntry * res, gpointer data)
1168{
1169 int i, v;
1170 i = GPOINTER_TO_INT(data);
1171 const gchar * m = entry_get_text (res);
1172 gboolean up = FALSE;
1173 v = (int)string_to_double ((gpointer)m);
1174 if (i == 0)
1175 {
1176 this_reader -> natomes = (v > 0) ? v : 0;
1177 update_entry_int (res, this_reader -> natomes);
1178 }
1179 else
1180 {
1181 if (v != this_reader -> nspec)
1182 {
1183 this_reader -> nspec = (v > 0) ? v : 0;
1184 if (this_reader -> nspec)
1185 {
1186 if (this_reader -> nsps) g_free (this_reader -> nsps);
1187 this_reader -> nsps = allocint (v);
1188 if (this_reader -> z) g_free (this_reader -> z);
1189 this_reader -> z = allocdouble (v);
1190 if (this_reader -> label) g_free (this_reader -> label);
1191 this_reader -> label = g_malloc0(v*sizeof*this_reader -> label);
1192 }
1193 up = TRUE;
1194 }
1195 update_entry_int (res, this_reader -> nspec);
1196 }
1197 if (up) prepare_sp_box();
1198}
1199
1201
1208{
1209 int i;
1210 double z;
1211 for (i=0; i<this_reader -> nspec; i++)
1212 {
1213 z = get_z_from_periodic_table (this_reader -> label[i]);
1214 if (! z) return 0;
1215 this_reader -> z[i] = z;
1216 }
1217 return 1;
1218}
1219
1229G_MODULE_EXPORT void run_to_read_trj_or_vas (GtkDialog * dialog, gint response_id, gpointer data)
1230{
1231 int id = GPOINTER_TO_INT(data);
1232 switch (response_id)
1233 {
1234 case GTK_RESPONSE_APPLY:
1235 if (prep_chem_data())
1236 {
1237 reading_vas_trj = open_coord_file (active_project -> coordfile, id);
1238 }
1239 else
1240 {
1241 reading_vas_trj = 3;
1242 }
1243 break;
1244 default:
1245 reading_vas_trj = 3;
1246 break;
1247 }
1248 if (all_sp_box)
1249 {
1250 int i;
1251 for (i=0; i<2; i++)
1252 {
1255 }
1257 }
1258 destroy_this_dialog (dialog);
1259}
1260
1269{
1270 int i;
1271 gchar * rlabel[2]={i18n("Total number of atom(s):"), i18n("Number of chemical species:")};
1272 GtkWidget * dialog = dialogmodal (_("Reading CPMD / VASP trajectory"), GTK_WINDOW(MainWindow));
1273 read_this = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Apply"), GTK_RESPONSE_APPLY);
1274 GtkWidget * vbox = dialog_get_content_area (dialog);
1276 GtkWidget * rentry;
1277 GtkWidget * hbox;
1278 for (i=0; i<2; i++)
1279 {
1280 hbox = create_hbox(0);
1281 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1282 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(_(rlabel[i]), 200, -1, 0.0, 0.5), FALSE, FALSE, 5);
1283 rentry = create_entry (G_CALLBACK(update_at_sp), 100, 15, FALSE, GINT_TO_POINTER(i));
1284 update_entry_text (GTK_ENTRY(rentry), "");
1285 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rentry, FALSE, FALSE, 5);
1286 }
1287 read_box = create_hbox(0);
1288 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, read_box, FALSE, FALSE, 5);
1289 run_this_gtk_dialog (dialog, G_CALLBACK(run_to_read_trj_or_vas), GINT_TO_POINTER(ff));
1290 return reading_vas_trj;
1291}
1292
1305void cell_data_from_pdb_ (float * a, float * b, float * c, float * alp, float * bet, float * gam)
1306{
1307 active_box -> param[0][0] = * a;
1308 active_box -> param[0][1] = * b;
1309 active_box -> param[0][2] = * c;
1310 active_box -> param[1][0] = * alp;
1311 active_box -> param[1][1] = * bet;
1312 active_box -> param[1][2] = * gam;
1313 // In a PDB file it is required to turn off PBC
1314 // The box usually barely encompass the molecule
1315 active_cell -> pbc = 0;
1316 active_cell -> ltype = 1;
1317}
1318
1320gchar * npt_file;
1321
1322#ifdef GTK4
1332G_MODULE_EXPORT void run_read_npt_data (GtkNativeDialog * info, gint response_id, gpointer data)
1333{
1334 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1335#else
1345G_MODULE_EXPORT void run_read_npt_data (GtkDialog * info, gint response_id, gpointer data)
1346{
1347 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1348#endif
1349 if (response_id == GTK_RESPONSE_ACCEPT)
1350 {
1352 npt_selection = iask (_("Please select the file format of the NPT cell data"), _("Select format:"), 6, MainWindow);
1353 }
1354 else
1355 {
1356 npt_selection = -1;
1357 }
1358#ifdef GTK4
1360#else
1361 destroy_this_dialog (info);
1362#endif
1363}
1364
1371{
1372 GtkFileFilter * filter[2];
1373#ifdef GTK4
1374 GtkFileChooserNative * info;
1375#else
1376 GtkWidget * info;
1377#endif
1378 info = create_file_chooser (_("Read cell data for NPT molecular dynamics"),
1379 GTK_WINDOW(MainWindow),
1380 GTK_FILE_CHOOSER_ACTION_OPEN,
1381 _("Open"));
1382 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1383 filter[0] = gtk_file_filter_new();
1384 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[0]), _("DAT files (*.dat)"));
1385 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[0]), "*.dat");
1386 gtk_file_chooser_add_filter (chooser, filter[0]);
1387 filter[1] = gtk_file_filter_new();
1388 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[1]), _("All files (*)"));
1389 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[1]), "*");
1390 gtk_file_chooser_add_filter (chooser, filter[1]);
1391 npt_file = NULL;
1392#ifdef GTK4
1393 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_read_npt_data), NULL);
1394#else
1395 run_this_gtk_dialog (info, G_CALLBACK(run_read_npt_data), NULL);
1396#endif
1397 return (npt_selection < 0) ? 0 : open_cell_file (npt_selection, npt_file);
1398}
1399
1408{
1409 struct timespec sta_time;
1410 struct timespec sto_time;
1411 int result;
1412 int length = strlen(active_project -> coordfile);
1413 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1414 this_reader = g_malloc0(sizeof*this_reader);
1415 // Set default message type to warning
1416 this_reader -> mid = 1;
1417 switch (id)
1418 {
1419 case 0:
1420 // XYZ file
1421 result = open_coord_file (active_project -> coordfile, id);
1422 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1423 break;
1424 case 1:
1425 // XYZ file NPT
1426 result = open_coord_file (active_project -> coordfile, id);
1427 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1428 if (! result) result = read_npt_data ();
1429 break;
1430 case 2:
1431 // Chem3D file
1432 result = open_coord_file (active_project -> coordfile, id);
1433 // result = read_c3d_ (active_project -> coordfile, & length);
1434 break;
1435 case 3:
1436 // CPMD TRJ file
1437 result = to_read_trj_or_vas (id);
1438 break;
1439 case 4:
1440 // CPMD TRJ file NPT
1441 result = to_read_trj_or_vas (id);
1442 if (! result) result = read_npt_data ();
1443 break;
1444 case 5:
1445 // VASP XDATCAR file
1446 result = to_read_trj_or_vas (id);
1447 break;
1448 case 6:
1449 // VASP XDATCAR file NPT
1450 result = to_read_trj_or_vas (id);
1451 if (! result) result = read_npt_data ();
1452 break;
1453 case 7:
1454 // PDB file
1455 // result = open_coord_file (active_project -> coordfile, id);
1456 result = read_pdb_ (active_project -> coordfile, & length);
1457 break;
1458 case 8:
1459 // PDB file
1460 // result = open_coord_file (active_project -> coordfile, id);
1461 result = read_pdb_ (active_project -> coordfile, & length);
1462 break;
1463 case 9:
1464 // CIF file building the crystal
1465 result = open_coord_file (active_project -> coordfile, 9);
1466 break;
1467 case 10:
1468 // CIF file using symmetry positions
1469 result = open_coord_file (active_project -> coordfile, 10);
1470 break;
1471 case 11:
1472 // CIF file using symmetry positions
1473 result = open_coord_file (active_project -> coordfile, 11);
1474 break;
1475 case 12:
1476 // DL-POLY file
1477 result = open_coord_file (active_project -> coordfile, 12);
1478 break;
1479 default:
1480 result = 2;
1481 break;
1482 }
1483 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1484 g_print ("Time to read atomic coordinates: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1485 if (this_reader)
1486 {
1488 {
1489 gchar * info = g_strdup_printf ("%s", this_reader -> info[0]);
1490 int i;
1491 for (i=1; i<this_reader -> msg; i++)
1492 {
1493 info = g_strdup_printf ("%s\n%s", info, this_reader -> info[i]);
1494 }
1495 switch (this_reader -> mid)
1496 {
1497 case 0:
1498 show_error (info, 0, MainWindow);
1499 break;
1500 case 1:
1501 show_warning (info, MainWindow);
1502 break;
1503 }
1504 g_free (info);
1505 }
1506 if (this_reader)
1507 {
1508 if (this_reader -> info) g_free (this_reader -> info);
1509 if (this_reader -> z) g_free (this_reader -> z);
1510 if (this_reader -> nsps) g_free (this_reader -> nsps);
1511 if (this_reader -> dummy) g_free (this_reader -> dummy);
1512 if (this_reader -> label) g_free (this_reader -> label);
1513 if (this_reader -> object_list) g_free (this_reader -> object_list);
1514 if (this_reader -> u_atom_list) g_free (this_reader -> u_atom_list);
1515 if (this_reader -> coord) g_free (this_reader -> coord);
1516 if (this_reader -> lot) g_free (this_reader -> lot);
1517 if (this_reader -> sym_pos) g_free (this_reader -> sym_pos);
1518 if (this_reader -> wyckoff) g_free (this_reader -> wyckoff);
1519 if (this_reader -> occupancy) g_free (this_reader -> occupancy);
1520 if (this_reader -> disorder) g_free (this_reader -> disorder);
1521 if (this_reader -> multi) g_free (this_reader -> multi);
1522 if (this_reader -> lattice.sp_group) g_free (this_reader -> lattice.sp_group);
1523 if (this_reader -> lattice.box) g_free (this_reader -> lattice.box);
1524 g_free (this_reader);
1525 this_reader = NULL;
1526 }
1527 }
1528 switch (result)
1529 {
1530 case 1:
1531 show_error (_("Error loading atomic coordinates:\nfile does not exist"), 0, MainWindow);
1532 break;
1533 case 2:
1534 show_error (_("Error loading coordinates file: format not supported"), 0, MainWindow);
1535 break;
1536 case 3:
1537 show_error (_("Error at input: impossible to process input file data"), 0, MainWindow);
1538 break;
1539 default:
1540 if (id > 6 && id < 9)
1541 {
1542 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1543 if (! prep_data_ ())
1544 {
1545 show_error (_("Error while parsing the chemical information\n"
1546 "please check carefully the coordinates file"), 0, MainWindow);
1547 result = 4;
1548 }
1549 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1550 g_print ("Time to prepare data: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1551 }
1552 break;
1553 }
1554 return result;
1555}
1556
1557GtkFileFilter * filter[NCFORMATS+1];
1559
1568void open_this_coordinate_file (int format, gchar * proj_name)
1569{
1570 active_project -> newproj = FALSE;
1571 clock_gettime (CLOCK_MONOTONIC, & start_time);
1572 if (open_coordinate_file (format) == 0)
1573 {
1574 clock_gettime (CLOCK_MONOTONIC, & stop_time);
1575 g_print ("Time to open coordinate file: %s\n", calculation_time(FALSE, get_calc_time (start_time, stop_time)));
1576 active_project -> tfile = format;
1577 if (proj_name)
1578 {
1579 active_project -> name = g_strdup_printf ("%s", proj_name);
1580 }
1581 else
1582 {
1583 gchar * str = g_path_get_basename (active_project -> coordfile);
1584 active_project -> name = g_strdup_printf ("%s", substitute_string (str, g_strdup_printf (".%s", coord_files_ext[format]), NULL));
1585 g_free (str);
1586 }
1587 on_edit_activate (NULL, GINT_TO_POINTER(0));
1588 if (format != 1 && format != 4 && format != 6 && format != 9 && format != 10 && format != 11 && format != 12) on_edit_activate (NULL, GINT_TO_POINTER(4));
1590 on_edit_activate (NULL, GINT_TO_POINTER(2));
1592 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
1593 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
1594 chemistry_ ();
1595 apply_project (TRUE);
1598 {
1600 }
1601 else
1602 {
1603 if ((format == 9 || format == 10 || format == 11) && active_cell -> has_a_box)
1604 {
1605#ifdef GTK3
1606 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_rep[0], TRUE);
1607 set_rep (active_glwin -> ogl_rep[0], & active_glwin -> colorp[0][0]);
1608 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_clones[0], TRUE);
1609 widget_set_sensitive (active_glwin -> ogl_clones[0], active_glwin -> allbonds[1]);
1610 show_hide_clones (active_glwin -> ogl_clones[0], active_glwin);
1611#endif
1612 shift_it (vec3 (0.0, 0.0, 0.0), 1, activep);
1613 active_glwin -> wrapped = TRUE;
1614 }
1616 if ((format == 9 || format == 10) && cif_use_symmetry_positions)
1617 {
1618 gchar * file_name = g_strdup_printf ("%s", active_project -> coordfile);
1619 gchar * proj_name = g_strdup_printf (_("%s - symmetry position(s)"), active_project -> name);
1620 init_project (TRUE);
1621 active_project -> coordfile = g_strdup_printf ("%s", file_name);
1622 g_free (file_name);
1623 open_this_coordinate_file (11, proj_name);
1624 g_free (proj_name);
1625 }
1626 }
1627 }
1628 else
1629 {
1631 }
1632}
1633
1634#ifdef GTK4
1644G_MODULE_EXPORT void run_on_coord_port (GtkNativeDialog * info, gint response_id, gpointer data)
1645{
1646 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1647#else
1657G_MODULE_EXPORT void run_on_coord_port (GtkDialog * info, gint response_id, gpointer data)
1658{
1659 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1660#endif
1661 int i, j, k, l, m;
1662 GtkFileFilter * tmp;
1663 int format;
1664 int car_to_au;
1665 i = GPOINTER_TO_INT(data);
1666 gchar * tmp_str;
1667 switch (response_id)
1668 {
1669 case GTK_RESPONSE_ACCEPT:
1670 tmp = gtk_file_chooser_get_filter (chooser);
1671 active_project -> coordfile = file_chooser_get_file_name (chooser);
1672#ifdef GTK4
1674#else
1675 destroy_this_dialog (info);
1676#endif
1677 j = 0;
1678 while (tmp != filter[j]) j++;
1679 if (i == 0)
1680 {
1681#ifdef OSX
1682 j = NCFORMATS;
1683#endif
1684 if (j == NCFORMATS)
1685 {
1686 j = iask (_("Please select the file format of the atomic coordinates"), _("Select format:"), 2, MainWindow);
1687 }
1688 open_this_coordinate_file (j, NULL);
1689 }
1690 else
1691 {
1692 if (j < 2)
1693 {
1694 format = iask (_("Please select the format of the atomic coordinates"), _("Select format:"), 1, MainWindow);
1695 }
1696 else
1697 {
1698 format = 0;
1699 }
1700 active_cell -> frac = (format < 2) ? 0 : format - 1;
1701 car_to_au = (format == 1) ? 1 : 0;
1702 if (j < 2)
1703 {
1704 m = (active_cell -> npt) ? active_project -> steps : 1;
1705 for (l=0; l<m; l++)
1706 {
1707 lattice_ (& m, & l,
1708 active_cell -> box[l].vect,
1709 active_cell -> box[l].param[0],
1710 active_cell -> box[l].param[1],
1711 & active_cell -> ltype,
1712 & active_cell -> frac,
1713 & active_cell -> pbc);
1714 }
1715 to_read_pos ();
1716 }
1717 int length = strlen (active_project -> coordfile);
1718 for (l=1; l<active_project -> nspec+1; l++)
1719 {
1720 m = strlen(active_chem -> label[l-1]);
1721 send_label_ (& l, & m, active_chem -> label[l-1]);
1722 }
1723 switch (j)
1724 {
1725 case 0:
1726 k = write_xyz_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1727 break;
1728 case 1:
1729 k = write_c3d_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1730 break;
1731 }
1732 if (k)
1733 {
1734 tmp_str = g_strdup_printf (_("Impossible to export the atomic coordinates\nError code: %d"), k);
1735 show_error (tmp_str, 0, MainWindow);
1736 g_free (tmp_str);
1737 }
1739 }
1740 break;
1741 default:
1742 if (i == 0)
1743 {
1745 }
1746#ifdef GTK4
1748#else
1749 destroy_this_dialog (info);
1750#endif
1751 break;
1752 }
1753}
1754
1763G_MODULE_EXPORT void on_coord_port (GtkWidget * widg, gpointer data)
1764{
1765 int i, j;
1766#ifdef GTK4
1767 GtkFileChooserNative * info;
1768#else
1769 GtkWidget * info;
1770#endif
1771 GtkFileChooser * chooser;
1772 gchar * tmp_str;
1773 int num_files[2]={NCFORMATS, 2};
1774 const gchar * str[2]= {i18n("Import atomic coordinates"), i18n("Export atomic coordinates")};
1775 const gchar * res[2]= {i18n("Open"), i18n("Save")};
1776 char * out_files[2] = {i18n("XYZ file"), i18n("Chem3D file")};
1777 char * out_ext[2]={"xyz", "c3d"};
1778 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
1779 pactive = activep;
1780 i = GPOINTER_TO_INT (data);
1781
1782 if ((nprojects > 0 && get_project_by_id(activew) -> natomes) || i == 0)
1783 {
1784 if (i == 0)
1785 {
1786 init_project (TRUE);
1787 }
1788 else
1789 {
1791 }
1792 tmp_str = g_strdup_printf ("%s - %s", prepare_for_title(active_project -> name), _(str[i]));
1793 info = create_file_chooser (tmp_str,
1794 GTK_WINDOW(MainWindow),
1795 act[i],
1796 _(res[i]));
1797 g_free (tmp_str);
1798 chooser = GTK_FILE_CHOOSER(info);
1799 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
1800#ifdef GTK3
1801 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1802#endif
1803 for (j=0; j<num_files[i]; j++)
1804 {
1805 filter[j] = gtk_file_filter_new();
1806 if (i == 0)
1807 {
1808 tmp_str = g_strdup_printf ("%s (*.%s)", _(coord_files[j]), coord_files_ext[j]);
1809 }
1810 else
1811 {
1812 tmp_str = g_strdup_printf ("%s (*.%s)", _(out_files[j]), out_ext[j]);
1813 }
1814 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), tmp_str);
1815 g_free (tmp_str);
1816 if (i == 0)
1817 {
1818 tmp_str = g_strdup_printf ("*.%s", coord_files_ext[j]);
1819 }
1820 else
1821 {
1822 tmp_str = g_strdup_printf ("*.%s", out_ext[j]);
1823 }
1824 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), tmp_str);
1825 gtk_file_chooser_add_filter (chooser, filter[j]);
1826 g_free (tmp_str);
1827 }
1828 if (i==0)
1829 {
1830 filter[j] = gtk_file_filter_new();
1831 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), _("All files (*)"));
1832 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), "*");
1833 gtk_file_chooser_add_filter (chooser, filter[j]);
1834 }
1835 else
1836 {
1838 gtk_file_chooser_set_current_name (chooser, "coord.xyz");
1839 }
1840#ifdef GTK4
1841 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1842#else
1843 run_this_gtk_dialog (info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1844#endif
1845 }
1846 else
1847 {
1848 if (nprojects == 0)
1849 {
1850 show_warning (_("No project loaded ... nothing to be saved\n"), MainWindow);
1851 }
1852 else
1853 {
1854 tmp_str = g_strdup_printf (_("Project <b>%s</b> is empty ... nothing to be saved\n"),
1855 get_project_by_id(activew) -> name);
1856 show_warning (tmp_str, MainWindow);
1857 g_free (tmp_str);
1858 }
1859 }
1860 activew = activep;
1862}
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:1407
GtkWidget * read_box
Definition callbacks.c:997
int open_coord_file(gchar *filename, int fti)
open atomic coordinates file
Definition read_coord.c:274
int signal_error(const char *file, const char *func, int error_line, int error_id)
Definition callbacks.c:182
int to_read_trj_or_vas(int ff)
reading CPMD/VASP trajectory - prepare the dialog
Definition callbacks.c:1268
void quit_gtk()
Leave the application.
Definition callbacks.c:330
G_MODULE_EXPORT void on_edit_activate(GtkWidget *widg, gpointer data)
create an edition dialog - prepare the dialog
Definition edit_menu.c:865
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:1345
G_MODULE_EXPORT void changed_spec_combo(GtkComboBox *box, gpointer data)
reading CPMD/VASP trajectory, change the active species
Definition callbacks.c:1103
int read_npt_data()
read NPT data associated with atomic coordinates: setup the dialog
Definition callbacks.c:1370
int open_save_workspace(FILE *fp, int act)
open or save the active workspace
Definition callbacks.c:361
gchar * substitute_string(gchar *init, gchar *o_motif, gchar *n_motif)
substitute all patterns in string
Definition w_library.c:375
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:465
double get_z_from_periodic_table(gchar *lab)
get Z from atom label
Definition w_library.c:305
G_MODULE_EXPORT void on_close_workspace(GtkWidget *widg, gpointer data)
close the active workspace
Definition callbacks.c:126
tint osp
Definition callbacks.c:438
GtkWidget * all_sp_box
Definition callbacks.c:998
atomes_error_signal errors_messages[]
Definition callbacks.c:156
G_MODULE_EXPORT void on_open_save_activate(GtkWidget *widg, gpointer data)
open or save an atomes file - prepare the dialog
Definition callbacks.c:549
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:1657
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:858
void simple_image_render()
simple direct rendering from command line
Definition image.c:241
char ** las
Definition callbacks.c:106
void apply_project(gboolean showtools)
get project ready for calculation and initialize the OpenGL window
Definition callbacks.c:794
int prep_chem_data()
prepare chemical data to read CPMD/VASP file
Definition callbacks.c:1207
G_MODULE_EXPORT void on_isaacs_port(GtkWidget *widg, gpointer data)
open or write ISAACS XML file - prepare the dialog
Definition callbacks.c:904
void open_this_coordinate_file(int format, gchar *proj_name)
open coordinate file format, if successful add to workspace
Definition callbacks.c:1568
int open_history_file(gchar *filename)
void run_project()
send project data to Fortran90
Definition callbacks.c:759
int pactive
Definition callbacks.c:1558
GtkWidget * sa_entry[2]
Definition callbacks.c:1000
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:1229
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:1305
int open_save(FILE *fp, int act, int wid, int pid, int aid, gchar *pfile)
open or save project file
Definition callbacks.c:246
GtkFileFilter * filter[NCFORMATS+1]
Definition callbacks.c:1557
atomes_error * project_error
Definition callbacks.c:155
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:1071
G_MODULE_EXPORT void on_coord_port(GtkWidget *widg, gpointer data)
export or import atomic coordinates: prepare dialog
Definition callbacks.c:1763
G_MODULE_EXPORT void on_save_as_activate(GtkWidget *widg, gpointer data)
open or save, choosing a file name
Definition callbacks.c:747
GtkWidget * read_this
Definition callbacks.c:1001
int reading_vas_trj
Definition callbacks.c:1200
void update_sa_info(int sid)
reading CPMD/VASP trajectory, update chemical species info
Definition callbacks.c:1035
int read_spec
Definition callbacks.c:1002
void prepare_sp_box()
eading CPMD/VASP trajectory, prepare the species combo box
Definition callbacks.c:1113
const gchar * dfi[2]
Definition main.c:93
int npt_selection
Definition callbacks.c:1319
gboolean save
Definition callbacks.c:153
G_MODULE_EXPORT void update_at_sp(GtkEntry *res, gpointer data)
reading CPMD/VASP trajectory, changing number of atomes or species
Definition callbacks.c:1167
void open_this_isaacs_xml_file(gchar *profile, int ptoc, gboolean visible)
open an ISAACS XML file
Definition callbacks.c:814
void update_error_trace(const char *file, const char *func, int trace_line)
Definition callbacks.c:200
void open_this_proj(gpointer data, gpointer user_data)
Open many projects, one at a time.
Definition callbacks.c:426
void to_read_pos()
send atomic coordinates to Fortran90
Definition callbacks.c:960
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:999
gchar * npt_file
Definition callbacks.c:1320
gboolean run_os
Definition callbacks.c:439
void check_read_sa()
reading CPMD/VASP trajectory, testing parameters to active the read capabilty
Definition callbacks.c:1009
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:65
void to_close_this_project(int to_activate, project *this_proj)
to close this project
Definition close_p.c:479
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:503
color colorp[64]
gchar * param[2]
dummy_atom * dummy
Definition cpmd_atoms.c:73
int atoms[NUM_STYLES][2]
dint up
int multi
Definition dlp_init.c:121
FILE * fp
gboolean reading_input
Definition global.c:186
int mol_update
Definition global.c:175
gchar * workspacefile
Definition global.c:159
gboolean newspace
Definition global.c:185
struct timespec start_time
Definition global.c:198
int activep
Definition global.c:162
gboolean silent_input
Definition global.c:192
int activew
Definition global.c:166
GtkApplication * AtomesApp
Definition global.c:206
int nprojects
Definition global.c:161
int frag_update
Definition global.c:174
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:446
GtkWidget * MainWindow
Definition global.c:207
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:643
gchar * projfile
Definition global.c:144
gboolean atomes_render_image
Definition global.c:196
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:630
#define i18n(String)
Definition global.c:80
struct timespec stop_time
Definition global.c:199
gboolean cif_use_symmetry_positions
Definition global.c:193
GtkWidget * curvetoolbox
Definition global.c:211
double string_to_double(gpointer string)
convert string to double
Definition global.c:611
gboolean atomes_from_libreoffice
Definition global.c:195
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:533
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2358
int combo_get_active(GtkWidget *combo)
retrieve the active item's position
Definition gtk-misc.c:935
#define ERROR_CHAINS
Definition global.h:306
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1401
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:552
#define ERROR_ATOM_B
Definition global.h:301
cell_info * active_cell
Definition project.c:50
#define ERROR_RW
Definition global.h:296
#define ERROR_UPDATE
Definition global.h:302
void combo_set_active(GtkWidget *combo, int pos)
set the active item's position
Definition gtk-misc.c:958
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2306
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:652
chemical_data * active_chem
Definition project.c:48
#define BSEP
Definition global.h:261
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:669
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2339
#define ERROR_CURVE
Definition global.h:298
#define STEP_LIMIT
Definition global.h:293
#define ERROR_PROJECT
Definition global.h:297
#define ERROR_FIELD
box_info * active_box
Definition project.c:51
#define ERROR_IMAGE
Definition global.h:299
#define NCFORMATS
Definition global.h:332
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:1010
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:861
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
create a GtkLabel with pango markup
Definition gtk-misc.c:1672
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:340
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:247
#define ERROR_RINGS
Definition global.h:305
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2235
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:849
char * coord_files_ext[NCFORMATS+1]
Definition callbacks.c:103
#define ERROR_ATOM_A
Definition global.h:300
#define OK
Definition global.h:295
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2213
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:726
GSList * file_chooser_get_file_names(GtkFileChooser *chooser)
create a file list from files selected using a GtkFileChooser
Definition gtk-misc.c:2293
gchar * prepare_for_title(gchar *init)
prepare a string for a window title, getting rid of all markup
Definition tools.c:71
#define ERROR_COORD
Definition global.h:304
#define ERROR_MOL
Definition global.h:307
char * coord_files[NCFORMATS+1]
Definition callbacks.c:88
GtkWidget * create_vbox(int spacing)
create a GtkBox with vertical orientation
Definition gtk-misc.c:837
#define ERROR_ANA
Definition global.h:308
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:2393
project * active_project
Definition project.c:47
void initcutoffs(chemical_data *chem, int species)
initialize bond cutoffs
Definition bdcall.c:245
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2254
#define ERROR_QM
Definition global.h:309
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:202
#define ERROR_NO_WAY
Definition global.h:303
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:1498
Function declarations for the creation of the OpenGL window.
void init_project(gboolean alloc_box)
initialize a new project
Definition init_p.c:273
void init_atomes_analysis(project *this_proj, gboolean apply_defaults)
initialize analysis data structures for atomes
Definition initc.c:223
int iask(char *question, char *lab, int id, GtkWidget *win)
enter an integer value - prepare the dialog
Definition interface.c:620
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:266
void show_info(char *information, int val, GtkWidget *win)
add / show information message to widget
Definition interface.c:240
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
void show_error_with_trace(gchar *error, atomes_error *this_error, int act, int val, GtkWidget *win)
show error message
Definition interface.c:328
gboolean ask_yes_no(gchar *title, gchar *text, int type, GtkWidget *widg)
ask yes or no for something: prepare dialog
Definition interface.c:420
Messaging function declarations.
void prep_calc_actions()
prepare analysis widgets
Definition update_p.c:59
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:600
double z
Definition ogl_draw.c:63
double y
Definition ogl_draw.c:63
double x
Definition ogl_draw.c:63
float project_file_version
Definition open_p.c:74
int open_project(FILE *fp, int wid)
open atomes project file
Definition open_p.c:308
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:153
void active_project_changed(int id)
change the active project
Definition update_p.c:220
gboolean reading_project
Definition read_curve.c:43
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:350
Definition global.h:118
GtkFileFilter * filter1
Definition w_data.c:53
GtkFileFilter * filter2
Definition w_data.c:53
GtkWidget * res[2]
Definition w_encode.c:342
void add_project_to_workspace()
add project(s) to the workspace tree
Definition workspace.c:597
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73
Function declarations for workspace managment.