atomes 1.1.15
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-2024 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 "Crystallographic information (crystal build)",
96 "Crystallographic information (symmetry positions)",
97 "DL-POLY HISTORY file",
98 "ISAACS Project File"};
99
100char * coord_files_ext[NCFORMATS+1]={"xyz", "xyz", "c3d", "trj", "trj", "xdatcar", "xdatcar",
101 "pdb", "ent", "cif", "cif", "hist", "ipf"};
102
103char ** las;
104void initcwidgets ();
105extern G_MODULE_EXPORT void on_edit_activate (GtkWidget * widg, gpointer data);
106extern gchar * substitute_string (gchar * init, gchar * o_motif, gchar * n_motif);
107extern const gchar * dfi[2];
108extern int open_cif_file (gchar * filename);
109extern int open_coord_file (gchar * filename, int fti);
110extern int open_history_file (gchar * filename);
111extern int open_cell_file (int format, gchar * filename);
112extern double get_z_from_periodic_table (gchar * lab);
113
119void quit_gtk ()
120{
121 profree_ ();
122 g_application_quit (G_APPLICATION(AtomesApp));
123}
124
133G_MODULE_EXPORT void on_close_workspace (GtkWidget * widg, gpointer data)
134{
135 int i, j;
136 gboolean close = FALSE;
137 j = GPOINTER_TO_INT (data);
138 if (j == 1)
139 {
140 close = ask_yes_no ("Close workspace ?", "Are you sure ?", GTK_MESSAGE_QUESTION, MainWindow);
141 }
142 else
143 {
144 close = TRUE;
145 }
146
147 if (close)
148 {
149 j = nprojects-1;
150 for (i=j; i>-1; i--)
151 {
152#ifdef DEBUG
153 g_debug ("CLOSING:: %d", i);
154#endif
155 on_close_activate (NULL, GINT_TO_POINTER(i));
156 }
157 }
158}
159
160gboolean save = TRUE;
161
174int open_save (FILE * fp, int i, int pid, int aid, int npi, gchar * pfile)
175{
176 int j;
177 gchar * err;
178
179 if (i == 0)
180 {
181 reading_input = TRUE;
182 j = open_project (fp, npi);
183 reading_input = FALSE;
184 if (j != 0)
185 {
186 // error at read
187 if (pfile != NULL)
188 {
189 err = g_strdup_printf ("Impossible to open project file: \n%s\nError code: %d\n", pfile, j);
190 show_error (err, 0, MainWindow);
191 g_free (err);
192 }
194 }
195 else
196 {
197#ifdef DEBUG
198 g_debug ("pid= %d, pfile= %s", pid, pfile);
199#endif
200 get_project_by_id (pid) -> projfile = g_strdup_printf ("%s", pfile);
203 }
204 }
205 else
206 {
207 j = save_project (fp, get_project_by_id(pid), npi);
208 if (j != 0)
209 {
210 // error at write
211 if (pfile != NULL)
212 {
213 err = g_strdup_printf ("Impossible to save project file:\n%s\nError code: %d\n", pfile, j);
214 show_error (err, 0, MainWindow);
215 g_free (err);
216 }
217 }
218 else
219 {
220 if (pfile != NULL) get_project_by_id(pid) -> projfile = g_strdup_printf ("%s", pfile);
221 }
222 }
223 return j;
224}
225
234int open_save_workspace (FILE * fp, int act)
235{
236 int i, j, k, l, m;
237 gchar * ver;
238 /*PangoFontDescription * font_desc;
239 GtkTextBuffer * buffer;
240 GtkTextIter bStart;
241 GtkTextIter bEnd;*/
242
243 // First 2 lines for compatibility issues
244 if (act == 0)
245 {
246 if (fread (& i, sizeof(int), 1, fp) != 1) return 1;
247 ver = g_malloc0 (i*sizeof*ver);
248 if (fread (ver, sizeof(char), i, fp) != i) return 1;
249 // test on ver for version
250 g_free (ver);
251 if (fread (& i, sizeof(int), 1, fp) != 1) return 1;
252 }
253 else
254 {
255 i = 1;
256 ver = g_strdup_printf ("%%\n%% Workspace file v-%1d.0\n%%\n", i);
257 i = strlen (ver);
258 if (fwrite (& i, sizeof(int), 1, fp) != 1) return 1;
259 if (fwrite (ver, sizeof(char), i, fp) != i) return 1;
260 g_free (ver);
261 i = 0;
262 for (j=0; j<nprojects; j++) if (get_project_by_id(j) -> natomes) i++;
263 if (fwrite (& i, sizeof(int), 1, fp) != 1) return 1;
264 l = i;
265 i = nprojects;
266 }
267
268 if (i > 0)
269 {
270 for (j=0; j<i; j++)
271 {
272 k = activep;
273 if (act == 0)
274 {
275 init_project (FALSE);
276 m = open_save (fp, act, j, k, i, NULL);
277 if (m != 0) return m;
278 }
279 else if (get_project_by_id(j) -> natomes)
280 {
281 m = open_save (fp, act, j, k, l, NULL);
282 if (m != 0) return m;
283 }
284 }
285 return 0;
286 }
287 else
288 {
289 return -1;
290 }
291}
292
301void open_this_proj (gpointer data, gpointer user_data)
302{
303 FILE * fp = fopen (data, dfi[0]);
304 int pactive = activep;
305 init_project (FALSE);
306 open_save (fp, 0, activew, pactive, 0, data);
307 fclose (fp);
309}
310
312gboolean run_os;
313
314#ifdef GTK4
324G_MODULE_EXPORT void run_on_open_save_active (GtkNativeDialog * info, gint response_id, gpointer data)
325{
326 GListModel * projlist;
327 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
328#else
338G_MODULE_EXPORT void run_on_open_save_active (GtkDialog * info, gint response_id, gpointer data)
339{
340 GSList * projlist = NULL;
341 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
342#endif
343 FILE * fp = NULL;
344 gchar * err;
345 gboolean io = FALSE;
346 const gchar * mess[2]={"reading","saving "};
347 if (response_id == GTK_RESPONSE_ACCEPT)
348 {
349 if (osp.a == 0)
350 {
351 projlist = file_chooser_get_file_names (chooser);
352 }
353 else
354 {
356 }
357 if (osp.a > 1)
358 {
359 workspacefile = g_strdup_printf ("%s", projfile);
360 }
361 io = TRUE;
362 }
363 if (run_os)
364 {
365#ifdef GTK4
367#else
368 destroy_this_dialog (info);
369#endif
370 }
371 if (io)
372 {
373 if (osp.a > 0)
374 {
375 fp = fopen (projfile, dfi[osp.b]);
376 }
377 if (osp.a == 0)
378 {
379#ifdef GTK3
380 g_slist_foreach (projlist, open_this_proj, NULL);
381 g_slist_free (projlist);
382#else
383 int i;
384 for (i=0; i<g_list_model_get_n_items (projlist); i++)
385 {
386 GObject * obj = g_list_model_get_item (projlist, i);
387 open_this_proj (g_file_get_parse_name((GFile *)obj), NULL);
388 }
389 g_object_unref (projlist);
390#endif
391 }
392 else if (osp.a == 1)
393 {
395 }
396 else
397 {
398 int k = open_save_workspace (fp, osp.b);
399 if (k != 0)
400 {
401 err = g_strdup_printf ("Error %s workspace file\n%s\nError code: %d\n",
402 mess[osp.b], projfile, k);
403 show_error (err, 0, MainWindow);
404 g_free (err);
405 }
406 }
407 if (osp.a > 0)
408 {
409 fclose (fp);
410 g_free (projfile);
411 }
412 }
413}
414
423G_MODULE_EXPORT void on_open_save_activate (GtkWidget * widg, gpointer data)
424{
425 int i, j, k;
426 gint action;
427#ifdef GTK4
428 GtkFileChooserNative * info;
429#else
430 GtkWidget * info;
431#endif
432 GtkFileChooser * chooser;
433 GtkFileFilter * filter1, * filter2;
434 const gchar * str[4]={"Open Project File(s)", "Save Project File", "Open Workspace", "Save Workspace"};
435 const gchar * res[2]={"Open", "Save"};
436 const gchar * file_name[2]={"Project file (*.apf)", "Workspace file (*.awf)"};
437 const gchar * file_ext[2]={"*.apf", "*.awf"};
438 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
439 project * this_proj = get_project_by_id (activew);
440 int pactive = activep;
441 i = GPOINTER_TO_INT (data);
442 run_os = FALSE;
443 if (i == 1 || i == 3)
444 {
445 j = 1;
446 }
447 else
448 {
449 j = 0;
450 }
451 action = 0;
452 if (i == 2 && ! newspace)
453 {
454 show_info ("A workspace is already open !", 0, MainWindow);
455 }
456 else if (i == 3 && newspace)
457 {
458 show_warning ("Empty workspace ... nothing to be saved\n", MainWindow);
459 }
460 else if (i == 3)
461 {
462 for (k=0; k<nprojects; k++) if (get_project_by_id(k) -> natomes) action = 1;
463 if (! action)
464 {
465 show_warning ("Workspace contains only empty projects ... nothing to be saved\n", MainWindow);
466 }
467 }
468 else if (i == 1 && nprojects == 0)
469 {
470 show_warning ("No project open ... nothing to be saved\n", MainWindow);
471 }
472 else if (i == 1 && ! this_proj -> natomes)
473 {
474 show_warning ("Empty project ... nothing to be saved\n", MainWindow);
475 }
476 else
477 {
478 action = 1;
479 }
480
481 if (action)
482 {
483 if (nprojects == 0)
484 {
485 run_os = TRUE;
486 }
487 else
488 {
489 if (i == 1)
490 {
491 if (g_strcmp0(this_proj -> projfile, "(null)") == 0) this_proj -> projfile = NULL;
492 if (save && this_proj -> projfile != NULL)
493 {
494 run_os = FALSE;
495 projfile = g_strdup_printf ("%s", this_proj -> projfile);
496 }
497 else
498 {
499 run_os = TRUE;
500 projfile = NULL;
501 }
502 }
503 else if (i == 3)
504 {
505 if (g_strcmp0(workspacefile, "(null)") == 0) workspacefile = NULL;
506 if (save && workspacefile != NULL)
507 {
508 run_os = FALSE;
509 projfile = g_strdup_printf ("%s", workspacefile);
510 }
511 else
512 {
513 run_os = TRUE;
514 }
515 }
516 else
517 {
518 run_os = TRUE;
519 }
520 }
521
522 gchar * tmp_str;
523 if (i == 0)
524 {
525 tmp_str = g_strdup_printf ("%s - New project", str[i]);
526 }
527 else if (i == 1)
528 {
529 tmp_str = g_strdup_printf ("%s - %s", str[i], prepare_for_title(this_proj -> name));
530 }
531 else
532 {
533 tmp_str = g_strdup_printf ("%s", str[i]);
534 }
535 info = create_file_chooser (tmp_str,
536 GTK_WINDOW(MainWindow),
537 act[j],
538 res[j]);
539 chooser = GTK_FILE_CHOOSER (info);
540 g_free (tmp_str);
541#ifdef GTK3
542 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
543#endif
544 if (i == 1 || i == 3) gtk_file_chooser_set_create_folders (chooser, TRUE);
545 if (nprojects == 0 || i == 0)
546 {
548 if (i == 0)
549 {
550 gtk_file_chooser_set_select_multiple (chooser, TRUE);
551 }
552 }
553 else
554 {
555 if (i == 1)
556 {
557 if (projfile != NULL)
558 {
560 gtk_file_chooser_set_current_name (chooser, projfile);
561 }
562 else
563 {
564 if (! file_chooser_set_file_name (chooser, g_strdup_printf ("%s.apf", prepare_for_title(this_proj -> name)))) goto end;
565 }
566 }
567 else if (i == 3)
568 {
569 if (workspacefile != NULL)
570 {
572 gtk_file_chooser_set_current_name (chooser, g_strdup_printf ("%s", workspacefile));
573 }
574 else
575 {
576 if (! file_chooser_set_file_name (chooser, "New-Workspace.awf")) goto end;
577 }
578 }
579 }
580 filter1 = gtk_file_filter_new();
581 gtk_file_filter_set_name (GTK_FILE_FILTER(filter1), file_name[i/2]);
582 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter1), file_ext[i/2]);
583 gtk_file_chooser_add_filter (chooser, filter1);
584 filter2 = gtk_file_filter_new();
585 gtk_file_filter_set_name (GTK_FILE_FILTER(filter2), "All files (*)");
586 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter2), "*");
587 gtk_file_chooser_add_filter (chooser, filter2);
588 osp.a = i;
589 osp.b = j;
590 osp.c = pactive;
591 if (run_os)
592 {
593#ifdef GTK4
594 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_open_save_active), this_proj);
595#else
596 run_this_gtk_dialog (info, G_CALLBACK(run_on_open_save_active), this_proj);
597#endif
598 }
599 else
600 {
601#ifdef GTK4
602 run_on_open_save_active ((GtkNativeDialog *)info, GTK_RESPONSE_ACCEPT, this_proj);
603#else
604 run_on_open_save_active ((GtkDialog *)info, GTK_RESPONSE_ACCEPT, this_proj);
605#endif
606 }
607 }
610 end:;
611}
612
621G_MODULE_EXPORT void on_save_as_activate (GtkWidget * widg, gpointer data)
622{
623 save = FALSE;
624 on_open_save_activate (widg, data);
625 save = TRUE;
626}
627
634{
635 if (! active_project -> run)
636 {
637 int i, j;
638 j = (active_cell -> npt) ? active_project -> steps : 1;
639 for (i=0; i<j; i++)
640 {
641 lattice_ (& j, & i,
642 active_cell -> box[i].vect,
643 active_cell -> box[i].param[0],
644 active_cell -> box[i].param[1],
645 & active_cell -> ltype,
646 & active_cell -> frac,
647 & active_cell -> pbc);
648 }
649 to_read_pos ();
650 prep_pos_ (& active_cell -> pbc, & active_cell -> frac);
651 if (active_project -> numwid < 0) initcwidgets ();
652 active_project -> dmtx = FALSE;
653 active_project -> run = 1;
654 }
655 if (active_cell -> frac) active_cell -> frac = 0;
656}
657
665void apply_project (gboolean showtools)
666{
667 if (active_project -> natomes)
668 {
669 run_project ();
671 }
673 if (showtools) show_the_widgets (curvetoolbox);
674}
675
685void open_this_isaacs_xml_file (gchar * profile, int ptoc, gboolean visible)
686{
687 if (! open_xml (profile))
688 {
689 active_project -> name = substitute_string (g_path_get_basename (profile), ".ipf", NULL);
690 on_edit_activate (NULL, GINT_TO_POINTER(3));
691 on_edit_activate (NULL, GINT_TO_POINTER(5));
693 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
694 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
695 apply_project (TRUE);
698 if (visible) show_info ("ISAACS project file (XML) successfully opened", 0, MainWindow);
699 }
700 else
701 {
703 }
704}
705
706#ifdef GTK4
716G_MODULE_EXPORT void run_on_isaacs_port (GtkNativeDialog * info, gint response_id, gpointer data)
717{
718 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
719#else
729G_MODULE_EXPORT void run_on_isaacs_port (GtkDialog * info, gint response_id, gpointer data)
730{
731 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
732#endif
733 if (response_id == GTK_RESPONSE_ACCEPT)
734 {
735 if (osp.a == 0 || nprojects == 0) init_project (TRUE);
737#ifdef GTK4
739#else
740 destroy_this_dialog (info);
741#endif
742 if (osp.a == 0)
743 {
745 }
746 else if (osp.a == 1)
747 {
749 if (write_xml (projfile) == 0)
750 {
751 show_error ("Impossible to write the IPF file\n", 0, MainWindow);
752 }
754 }
755 g_free (projfile);
756 }
757 else
758 {
759#ifdef GTK4
761#else
762 destroy_this_dialog (info);
763#endif
764 }
765}
766
775G_MODULE_EXPORT void on_isaacs_port (GtkWidget * widg, gpointer data)
776{
777 int i, j;
778 gboolean action;
779#ifdef GTK4
780 GtkFileChooserNative * info;
781#else
782 GtkWidget * info;
783#endif
784 GtkFileChooser * chooser;
785 GtkFileFilter * filter[2];
786 const gchar * file_ext[2]={"*.ipf", "*"};
787 const gchar * file_type[2]={"IPF file (*.ipf)", "All files (*)"};
788 const gchar * str[2]={"Import ISAACS Project File", "Export ISAACS Project File"};
789 const gchar * res[2]={"Open", "Save"};
790 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
791 int pactive = activep;
792 i = GPOINTER_TO_INT (data);
793
794 action = (i && ! nprojects) ? ask_yes_no ("Save an empty project ?", "Do you want to save an empty project ?", GTK_MESSAGE_QUESTION, MainWindow) : TRUE;
795 if (action)
796 {
797 info = create_file_chooser (str[i],
798 GTK_WINDOW(MainWindow),
799 act[i],
800 res[i]);
801 chooser = GTK_FILE_CHOOSER (info);
802#ifdef GTK3
803 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
804#endif
805 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
806 for (j=0; j<2; j++)
807 {
808 filter[j] = gtk_file_filter_new();
809 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), file_type[j]);
810 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), file_ext[j]);
811 gtk_file_chooser_add_filter (chooser, filter[j]);
812 }
814 osp.a = i;
815 osp.b = pactive;
816#ifdef GTK4
817 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_isaacs_port), NULL);
818#else
819 run_this_gtk_dialog (info, G_CALLBACK(run_on_isaacs_port), NULL);
820#endif
821 }
824}
825
832{
833 int i, j, k;
834 double * x, * y, * z;
835 double lat[3];
836
837 x = allocdouble(active_project -> steps*active_project -> natomes);
838 y = allocdouble(active_project -> steps*active_project -> natomes);
839 z = allocdouble(active_project -> steps*active_project -> natomes);
840 k = 0;
841 lat[0] = lat[1] = lat[2] = 0.0;
842 if (active_cell -> crystal)
843 {
844 for (i=0; i<3; i++)
845 {
846 for (j=0; j<3; j++) lat[i] -= active_box -> vect[j][i]/2.0;
847 }
848 }
849 for (i=0; i<active_project -> steps; i++)
850 {
851 for (j=0; j<active_project -> natomes; j++)
852 {
853 x[k] = active_project -> atoms[i][j].x + lat[0];
854 y[k] = active_project -> atoms[i][j].y + lat[1];
855 z[k] = active_project -> atoms[i][j].z + lat[2];
856 k ++;
857 }
858 }
859 read_pos_ (x, y, z);
860 g_free (x);
861 x = NULL;
862 g_free (y);
863 y = NULL;
864 g_free (z);
865 z = NULL;
866}
867
868GtkWidget * read_box;
869GtkWidget * all_sp_box;
870GtkWidget * sa_lab[2];
871GtkWidget * sa_entry[2];
872GtkWidget * read_this;
874
881{
882 int i, j, k;
883 i = j = 0;
884 for (k=0; k<this_reader -> nspec; k++)
885 {
886 i += this_reader -> nsps[k];
887 j += (this_reader -> label[k]) ? 1: 0;
888 }
889 if (i == this_reader -> natomes && j == this_reader -> nspec)
890 {
892 }
893 else
894 {
896 }
897}
898
906void update_sa_info (int sid)
907{
908 gchar * str = g_strdup_printf ("Label of atomic spec. N° %d:", sid+1);
909 gtk_label_set_text (GTK_LABEL(sa_lab[0]), str);
910 g_free (str);
911 if (this_reader -> label[sid])
912 {
913 update_entry_text (GTK_ENTRY(sa_entry[0]), this_reader -> label[sid]);
914 str = g_strdup_printf ("Number of %s atom(s):", this_reader -> label[sid]);
915 }
916 else
917 {
918 update_entry_text (GTK_ENTRY(sa_entry[0]), "");
919 str = g_strdup_printf ("Number of atom(s) for spec. N° %d:", sid+1);
920 }
921 gtk_label_set_text (GTK_LABEL(sa_lab[1]), str);
922 g_free (str);
923 if (this_reader -> nsps[sid])
924 {
925 update_entry_int (GTK_ENTRY(sa_entry[1]), this_reader -> nsps[sid]);
926 }
927 else
928 {
929 update_entry_text (GTK_ENTRY(sa_entry[1]), "");
930 }
931 read_spec = sid;
932}
933
942G_MODULE_EXPORT void update_sa (GtkEntry * res, gpointer data)
943{
944 int i, v;
945 i = GPOINTER_TO_INT(data);
946 const gchar * m = entry_get_text (res);
947 if (i == 0)
948 {
950 this_reader -> label[read_spec] = NULL;
951 this_reader -> label[read_spec] = g_strdup_printf ("%s", m);
953 }
954 else
955 {
956 v= (int)string_to_double ((gpointer)m);
957 if (v > 0)
958 {
959 this_reader -> nsps[read_spec] = v;
960 }
962 }
963 check_read_sa ();
964}
965
974G_MODULE_EXPORT void changed_spec_combo (GtkComboBox * box, gpointer data)
975{
976 update_sa_info (gtk_combo_box_get_active (box));
977}
978
985{
986 int i;
987 if (all_sp_box)
988 {
989 for (i=0; i<2; i++)
990 {
993 }
995 }
998 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, read_box, all_sp_box, FALSE, FALSE, 20);
999 GtkWidget * hbox;
1000 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, markup_label("Chemical species info:", 200, -1, 0.5, 0.5), FALSE, FALSE, 0);
1001 hbox = create_hbox(0);
1002 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1003 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Species: ", 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
1004 GtkWidget * combo;
1005 combo = create_combo ();
1006 gchar * str;
1007
1008 for (i=0; i<this_reader -> nspec; i++)
1009 {
1010 str = g_strdup_printf ("N°%d", i+1);
1011 gtk_combo_box_text_append_text ((GtkComboBoxText *)combo, str);
1012 g_free (str);
1013 }
1014 gtk_combo_box_set_active (GTK_COMBO_BOX(combo), 0);
1015 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK(changed_spec_combo), NULL);
1016 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, combo, FALSE, FALSE, 5);
1017 for (i=0; i<2; i++)
1018 {
1019 hbox = create_hbox(0);
1020 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1021 sa_lab[i] = markup_label("", 250, -1, 0.0, 0.5);
1022 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_lab[i], FALSE, FALSE, 5);
1023 sa_entry[i] = create_entry (G_CALLBACK(update_sa), 100, 15, FALSE, GINT_TO_POINTER(i));
1024 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_entry[i], FALSE, FALSE, 0);
1025 }
1027 update_sa_info (0);
1028}
1029
1038G_MODULE_EXPORT void update_at_sp (GtkEntry * res, gpointer data)
1039{
1040 int i, v;
1041 i = GPOINTER_TO_INT(data);
1042 const gchar * m = entry_get_text (res);
1043 gboolean up = FALSE;
1044 v = (int)string_to_double ((gpointer)m);
1045 if (i == 0)
1046 {
1047 this_reader -> natomes = (v > 0) ? v : 0;
1048 update_entry_int (res, this_reader -> natomes);
1049 }
1050 else
1051 {
1052 if (v != this_reader -> nspec)
1053 {
1054 this_reader -> nspec = (v > 0) ? v : 0;
1055 if (this_reader -> nspec)
1056 {
1057 if (this_reader -> nsps) g_free (this_reader -> nsps);
1058 this_reader -> nsps = allocint (v);
1059 if (this_reader -> z) g_free (this_reader -> z);
1060 this_reader -> z = allocdouble (v);
1061 if (this_reader -> label) g_free (this_reader -> label);
1062 this_reader -> label = g_malloc0 (v*sizeof*this_reader -> label);
1063 }
1064 up = TRUE;
1065 }
1066 update_entry_int (res, this_reader -> nspec);
1067 }
1068 if (up) prepare_sp_box();
1069}
1070
1072
1079{
1080 int i;
1081 double z;
1082 for (i=0; i<this_reader -> nspec; i++)
1083 {
1085 if (! z) return 0;
1086 this_reader -> z[i] = z;
1087 }
1088 return 1;
1089}
1090
1100G_MODULE_EXPORT void run_to_read_trj_or_vas (GtkDialog * dialog, gint response_id, gpointer data)
1101{
1102 int id = GPOINTER_TO_INT(data);
1103 switch (response_id)
1104 {
1105 case GTK_RESPONSE_APPLY:
1106 if (prep_chem_data())
1107 {
1108 reading_vas_trj = open_coord_file (active_project -> coordfile, id);
1109 }
1110 else
1111 {
1112 reading_vas_trj = 3;
1113 }
1114 break;
1115 default:
1116 reading_vas_trj = 3;
1117 break;
1118 }
1119 destroy_this_dialog (dialog);
1120}
1121
1130{
1131 int i;
1132 gchar * rlabel[2]={"Total number of atom(s):", "Number of chemical species:"};
1133 GtkWidget * dialog = dialogmodal ("Data to read CPMD / VASP trajectory", GTK_WINDOW(MainWindow));
1134 read_this = gtk_dialog_add_button (GTK_DIALOG (dialog), "Apply", GTK_RESPONSE_APPLY);
1135 GtkWidget * vbox = dialog_get_content_area (dialog);
1137 GtkWidget * rentry;
1138 GtkWidget * hbox;
1139 for (i=0; i<2; i++)
1140 {
1141 hbox = create_hbox(0);
1142 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1143 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(rlabel[i], 200, -1, 0.0, 0.5), FALSE, FALSE, 5);
1144 rentry = create_entry (G_CALLBACK(update_at_sp), 100, 15, FALSE, GINT_TO_POINTER(i));
1145 update_entry_text (GTK_ENTRY(rentry), "");
1146 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rentry, FALSE, FALSE, 5);
1147 }
1148 read_box = create_hbox(0);
1149 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, read_box, FALSE, FALSE, 5);
1150 run_this_gtk_dialog (dialog, G_CALLBACK(run_to_read_trj_or_vas), GINT_TO_POINTER(ff));
1151 return reading_vas_trj;
1152}
1153
1166void cell_data_from_pdb_ (float * a, float * b, float * c, float * alp, float * bet, float * gam)
1167{
1168 active_box -> param[0][0] = * a;
1169 active_box -> param[0][1] = * b;
1170 active_box -> param[0][2] = * c;
1171 active_box -> param[1][0] = * alp;
1172 active_box -> param[1][1] = * bet;
1173 active_box -> param[1][2] = * gam;
1174 // In a PDB file it is required to turn off PBC
1175 // The box usually barely encompass the molecule
1176 active_cell -> pbc = 0;
1177 active_cell -> ltype = 1;
1178}
1179
1181gchar * npt_file;
1182
1183#ifdef GTK4
1193G_MODULE_EXPORT void run_read_npt_data (GtkNativeDialog * info, gint response_id, gpointer data)
1194{
1195 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1196#else
1206G_MODULE_EXPORT void run_read_npt_data (GtkDialog * info, gint response_id, gpointer data)
1207{
1208 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1209#endif
1210 if (response_id == GTK_RESPONSE_ACCEPT)
1211 {
1213 npt_selection = iask ("Please select the file format of the NPT cell data", "Select format :", 3, MainWindow);
1214 }
1215 else
1216 {
1217 npt_selection = -1;
1218 }
1219#ifdef GTK4
1221#else
1222 destroy_this_dialog (info);
1223#endif
1224}
1225
1232{
1233 GtkFileFilter * filter[2];
1234#ifdef GTK4
1235 GtkFileChooserNative * info;
1236#else
1237 GtkWidget * info;
1238#endif
1239 info = create_file_chooser ("Read cell data for NPT molecular dynamics",
1240 GTK_WINDOW(MainWindow),
1241 GTK_FILE_CHOOSER_ACTION_OPEN,
1242 "Open");
1243 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1244 filter[0] = gtk_file_filter_new();
1245 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[0]), "DAT files (*.dat)");
1246 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[0]), "*.dat");
1247 gtk_file_chooser_add_filter (chooser, filter[0]);
1248 filter[1] = gtk_file_filter_new();
1249 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[1]), "All files (*)");
1250 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[1]), "*");
1251 gtk_file_chooser_add_filter (chooser, filter[1]);
1252 npt_file = NULL;
1253#ifdef GTK4
1254 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_read_npt_data), NULL);
1255#else
1256 run_this_gtk_dialog (info, G_CALLBACK(run_read_npt_data), NULL);
1257#endif
1258 return (npt_selection < 0) ? 0 : open_cell_file (npt_selection, npt_file);
1259}
1260
1269{
1270 struct timespec sta_time;
1271 struct timespec sto_time;
1272 int result;
1273 int length = strlen(active_project -> coordfile);
1274 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1275 this_reader = g_malloc0(sizeof*this_reader);
1276 // Set default message type to warning
1277 this_reader -> mid = 1;
1278 switch (id)
1279 {
1280 case 0:
1281 // XYZ file
1282 result = open_coord_file (active_project -> coordfile, id);
1283 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1284 break;
1285 case 1:
1286 // XYZ file NPT
1287 result = open_coord_file (active_project -> coordfile, id);
1288 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1289 if (! result) result = read_npt_data ();
1290 break;
1291 case 2:
1292 // Chem3D file
1293 result = open_coord_file (active_project -> coordfile, id);
1294 // result = read_c3d_ (active_project -> coordfile, & length);
1295 break;
1296 case 3:
1297 // CPMD TRJ file
1298 result = to_read_trj_or_vas (id);
1299 break;
1300 case 4:
1301 // CPMD TRJ file NPT
1302 result = to_read_trj_or_vas (id);
1303 if (! result) result = read_npt_data ();
1304 break;
1305 case 5:
1306 // VASP XDATCAR file
1307 result = to_read_trj_or_vas (id);
1308 break;
1309 case 6:
1310 // VASP XDATCAR file NPT
1311 result = to_read_trj_or_vas (id);
1312 if (! result) result = read_npt_data ();
1313 break;
1314 case 7:
1315 // PDB file
1316 // result = open_coord_file (active_project -> coordfile, id);
1317 result = read_pdb_ (active_project -> coordfile, & length);
1318 break;
1319 case 8:
1320 // PDB file
1321 // result = open_coord_file (active_project -> coordfile, id);
1322 result = read_pdb_ (active_project -> coordfile, & length);
1323 break;
1324 case 9:
1325 // CIF file building the crystal
1326 result = open_coord_file (active_project -> coordfile, 9);
1327 break;
1328 case 10:
1329 // CIF file using symmetry positions
1330 result = open_coord_file (active_project -> coordfile, 10);
1331 break;
1332 case 11:
1333 // DL-POLY file
1334 result = open_coord_file (active_project -> coordfile, 11);
1335 break;
1336 default:
1337 result = 2;
1338 break;
1339 }
1340 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1341 g_print ("Time to read atomic coordinates: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1342 if (this_reader)
1343 {
1345 {
1346 switch (this_reader -> mid)
1347 {
1348 case 0:
1349 show_error (this_reader -> info, 0, MainWindow);
1350 break;
1351 case 1:
1353 break;
1354 }
1355 }
1356 if (this_reader)
1357 {
1358 if (this_reader -> info) g_free (this_reader -> info);
1359 if (this_reader -> z) g_free (this_reader -> z);
1360 if (this_reader -> nsps) g_free (this_reader -> nsps);
1361 if (this_reader -> label) g_free (this_reader -> label);
1362 if (this_reader -> object_list) g_free (this_reader -> object_list);
1363 if (this_reader -> u_atom_list) g_free (this_reader -> u_atom_list);
1364 if (this_reader -> coord) g_free (this_reader -> coord);
1365 if (this_reader -> lot) g_free (this_reader -> lot);
1366 if (this_reader -> sym_pos) g_free (this_reader -> sym_pos);
1367 if (this_reader -> wyckoff) g_free (this_reader -> wyckoff);
1368 if (this_reader -> occupancy) g_free (this_reader -> occupancy);
1369 if (this_reader -> multi) g_free (this_reader -> multi);
1370 if (this_reader -> lattice.sp_group) g_free (this_reader -> lattice.sp_group);
1371 if (this_reader -> lattice.box) g_free (this_reader -> lattice.box);
1372 g_free (this_reader);
1373 this_reader = NULL;
1374 }
1375 }
1376 switch (result)
1377 {
1378 case 1:
1379 show_error ("Error loading atomic coordinates:\nfile does not exist", 0, MainWindow);
1380 break;
1381 case 2:
1382 show_error ("Error loading coordinates file: format not supported", 0, MainWindow);
1383 break;
1384 case 3:
1385 show_error ("Error at input: impossible to process input file data", 0, MainWindow);
1386 break;
1387 default:
1388 if (id > 6 && id < 9)
1389 {
1390 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1391 if (! prep_data_ ())
1392 {
1393 show_error ("Error while parsing the chemical information\n"
1394 "please check carefully the coordinates file", 0, MainWindow);
1395 result = 4;
1396 }
1397 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1398 g_print ("Time to prepare data: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1399 }
1400 break;
1401 }
1402 return result;
1403}
1404
1405GtkFileFilter * filter[NCFORMATS+1];
1407
1416void open_this_coordinate_file (int format, gchar * proj_name)
1417{
1418 active_project -> newproj = FALSE;
1419 clock_gettime (CLOCK_MONOTONIC, & start_time);
1420 if (open_coordinate_file (format) == 0)
1421 {
1422 clock_gettime (CLOCK_MONOTONIC, & stop_time);
1423 g_print ("Time to open coordinate file: %s\n", calculation_time(FALSE, get_calc_time (start_time, stop_time)));
1424 active_project -> tfile = format;
1425 if (proj_name)
1426 {
1427 active_project -> name = g_strdup_printf ("%s", proj_name);
1428 }
1429 else
1430 {
1431 gchar * str = g_path_get_basename (active_project -> coordfile);
1432 active_project -> name = g_strdup_printf ("%s", substitute_string (str, g_strdup_printf (".%s", coord_files_ext[format]), NULL));
1433 g_free (str);
1434 }
1435 on_edit_activate (NULL, GINT_TO_POINTER(0));
1436 if (format != 1 && format != 4 && format != 6 && format != 9 && format != 10 && format != 11) on_edit_activate (NULL, GINT_TO_POINTER(4));
1438 on_edit_activate (NULL, GINT_TO_POINTER(2));
1440 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
1441 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
1442 chemistry_ ();
1443 apply_project (TRUE);
1445 if ((format == 9 || format == 10) && active_cell -> has_a_box)
1446 {
1447#ifdef GTK3
1448 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_rep[0], TRUE);
1449 set_rep (active_glwin -> ogl_rep[0], & active_glwin -> colorp[0][0]);
1450 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_clones[0], TRUE);
1451 widget_set_sensitive (active_glwin -> ogl_clones[0], active_glwin -> allbonds[1]);
1452 show_hide_clones (active_glwin -> ogl_clones[0], active_glwin);
1453#endif
1454 shift_it (vec3 (0.0, 0.0, 0.0), 1, activep);
1455 active_glwin -> wrapped = TRUE;
1456 }
1458 if (format == 9 && cif_use_symmetry_positions)
1459 {
1460 gchar * file_name = g_strdup_printf ("%s", active_project -> coordfile);
1461 gchar * proj_name = g_strdup_printf ("%s - symmetry position(s)", active_project -> name);
1462 init_project (TRUE);
1463 active_project -> coordfile = g_strdup_printf ("%s", file_name);
1464 g_free (file_name);
1465 open_this_coordinate_file (10, proj_name);
1466 g_free (proj_name);
1467 }
1468 }
1469 else
1470 {
1472 }
1473}
1474
1475#ifdef GTK4
1485G_MODULE_EXPORT void run_on_coord_port (GtkNativeDialog * info, gint response_id, gpointer data)
1486{
1487 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1488#else
1498G_MODULE_EXPORT void run_on_coord_port (GtkDialog * info, gint response_id, gpointer data)
1499{
1500 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1501#endif
1502 int i, j, k, l, m;
1503 GtkFileFilter * tmp;
1504 int format;
1505 int car_to_au;
1506 i = GPOINTER_TO_INT(data);
1507 gchar * tmp_str;
1508 switch (response_id)
1509 {
1510 case GTK_RESPONSE_ACCEPT:
1511 tmp = gtk_file_chooser_get_filter (chooser);
1512 active_project -> coordfile = file_chooser_get_file_name (chooser);
1513#ifdef GTK4
1515#else
1516 destroy_this_dialog (info);
1517#endif
1518 j = 0;
1519 while (tmp != filter[j]) j++;
1520 if (i == 0)
1521 {
1522#ifdef OSX
1523 j = NCFORMATS;
1524#endif
1525 if (j == NCFORMATS)
1526 {
1527 j = iask ("Please select the file format of the atomic coordinates", "Select format :", 2, MainWindow);
1528 }
1529 open_this_coordinate_file (j, NULL);
1530 }
1531 else
1532 {
1533 if (j < 2)
1534 {
1535 format = iask ("Please select the format of the atomic coordinates", "Select format :", 1, MainWindow);
1536 }
1537 else
1538 {
1539 format = 0;
1540 }
1541 active_cell -> frac = (format < 2) ? 0 : format - 1;
1542 car_to_au = (format == 1) ? 1 : 0;
1543 if (j < 2)
1544 {
1545 m = (active_cell -> npt) ? active_project -> steps : 1;
1546 for (l=0; l<m; l++)
1547 {
1548 lattice_ (& m, & l,
1549 active_cell -> box[l].vect,
1550 active_cell -> box[l].param[0],
1551 active_cell -> box[l].param[1],
1552 & active_cell -> ltype,
1553 & active_cell -> frac,
1554 & active_cell -> pbc);
1555 }
1556 to_read_pos ();
1557 }
1558 int length = strlen (active_project -> coordfile);
1559 for (l=1; l<active_project -> nspec+1; l++)
1560 {
1561 m = strlen(active_chem -> label[l-1]);
1562 send_label_ (& l, & m, active_chem -> label[l-1]);
1563 }
1564 switch (j)
1565 {
1566 case 0:
1567 k = write_xyz_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1568 break;
1569 case 1:
1570 k = write_c3d_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1571 break;
1572 }
1573 if (k)
1574 {
1575 tmp_str = g_strdup_printf ("Impossible to export the atomic coordinates\nError code: %d", k);
1576 show_error (tmp_str, 0, MainWindow);
1577 g_free (tmp_str);
1578 }
1580 }
1581 break;
1582 default:
1583 if (i == 0)
1584 {
1586 }
1587#ifdef GTK4
1589#else
1590 destroy_this_dialog (info);
1591#endif
1592 break;
1593 }
1594}
1595
1604G_MODULE_EXPORT void on_coord_port (GtkWidget * widg, gpointer data)
1605{
1606 int i, j;
1607#ifdef GTK4
1608 GtkFileChooserNative * info;
1609#else
1610 GtkWidget * info;
1611#endif
1612 GtkFileChooser * chooser;
1613 gchar * tmp_str;
1614 int num_files[2]={NCFORMATS, 2};
1615 const gchar * str[2]={"Import atomic coordinates", "Export atomic coordinates"};
1616 const gchar * res[2]={"Open", "Save"};
1617 char * out_files[2] = {"XYZ file",
1618 "Chem3D file"};
1619 char * out_ext[2]={"xyz", "c3d"};
1620 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
1621 pactive = activep;
1622 i = GPOINTER_TO_INT (data);
1623
1624 if ((nprojects > 0 && get_project_by_id(activew) -> natomes) || i == 0)
1625 {
1626 if (i == 0)
1627 {
1628 init_project (TRUE);
1629 }
1630 else
1631 {
1633 }
1634 tmp_str = g_strdup_printf ("%s - %s", prepare_for_title(active_project -> name), str[i]);
1635 info = create_file_chooser (tmp_str,
1636 GTK_WINDOW(MainWindow),
1637 act[i],
1638 res[i]);
1639 g_free (tmp_str);
1640 chooser = GTK_FILE_CHOOSER(info);
1641 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
1642#ifdef GTK3
1643 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1644#endif
1645 for (j=0; j<num_files[i]; j++)
1646 {
1647 filter[j] = gtk_file_filter_new();
1648 if (i == 0)
1649 {
1650 tmp_str = g_strdup_printf ("%s (*.%s)", coord_files[j], coord_files_ext[j]);
1651 }
1652 else
1653 {
1654 tmp_str = g_strdup_printf ("%s (*.%s)", out_files[j], out_ext[j]);
1655 }
1656 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), tmp_str);
1657 g_free (tmp_str);
1658 if (i == 0)
1659 {
1660 tmp_str = g_strdup_printf ("*.%s", coord_files_ext[j]);
1661 }
1662 else
1663 {
1664 tmp_str = g_strdup_printf ("*.%s", out_ext[j]);
1665 }
1666 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), tmp_str);
1667 gtk_file_chooser_add_filter (chooser, filter[j]);
1668 g_free (tmp_str);
1669 }
1670 if (i==0)
1671 {
1672 filter[j] = gtk_file_filter_new();
1673 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), "All files (*)");
1674 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), "*");
1675 gtk_file_chooser_add_filter (chooser, filter[j]);
1676 }
1677 else
1678 {
1680 gtk_file_chooser_set_current_name (chooser, "coord.xyz");
1681 }
1682#ifdef GTK4
1683 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1684#else
1685 run_this_gtk_dialog (info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1686#endif
1687 }
1688 else
1689 {
1690 if (nprojects == 0)
1691 {
1692 show_warning ("No project loaded ... nothing to be saved\n", MainWindow);
1693 }
1694 else
1695 {
1696 tmp_str = g_strdup_printf ("Project <b>%s</b> is empty ... nothing to be saved\n",
1697 get_project_by_id(activew) -> name);
1698 show_warning (tmp_str, MainWindow);
1699 g_free (tmp_str);
1700 }
1701 }
1702 activew = activep;
1704}
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:1268
GtkWidget * read_box
Definition callbacks.c:868
int open_coord_file(gchar *filename, int fti)
open atomic coordinates file
Definition read_coord.c:250
int to_read_trj_or_vas(int ff)
reading CPMD/VASP trajectory - prepare the dialog
Definition callbacks.c:1129
void initcwidgets()
initializing curve values
Definition initc.c:104
void quit_gtk()
Leave the application.
Definition callbacks.c:119
G_MODULE_EXPORT void on_edit_activate(GtkWidget *widg, gpointer data)
create an edition dialog - prepare the dialog
Definition edit_menu.c:835
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:1206
G_MODULE_EXPORT void changed_spec_combo(GtkComboBox *box, gpointer data)
reading CPMD/VASP trajectory, change the active species
Definition callbacks.c:974
int read_npt_data()
read NPT data associated with atomic coordinates: setup the dialog
Definition callbacks.c:1231
int open_save_workspace(FILE *fp, int act)
open or save the active workspace
Definition callbacks.c:234
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:338
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:133
tint osp
Definition callbacks.c:311
GtkWidget * all_sp_box
Definition callbacks.c:869
G_MODULE_EXPORT void on_open_save_activate(GtkWidget *widg, gpointer data)
open or save an atomes file - prepare the dialog
Definition callbacks.c:423
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:1498
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:729
char ** las
Definition callbacks.c:103
void apply_project(gboolean showtools)
get project ready for calculation and initialize the OpenGL window
Definition callbacks.c:665
int prep_chem_data()
prepare chemical data to read CPMD/VASP file
Definition callbacks.c:1078
G_MODULE_EXPORT void on_isaacs_port(GtkWidget *widg, gpointer data)
open or write ISAACS XML file - prepare the dialog
Definition callbacks.c:775
void open_this_coordinate_file(int format, gchar *proj_name)
open coordinate file format, if successful add to workspace
Definition callbacks.c:1416
int open_history_file(gchar *filename)
void run_project()
send project data to Fortran90
Definition callbacks.c:633
int open_save(FILE *fp, int i, int pid, int aid, int npi, gchar *pfile)
open or save project file
Definition callbacks.c:174
int pactive
Definition callbacks.c:1406
GtkWidget * sa_entry[2]
Definition callbacks.c:871
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:1100
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:1166
GtkFileFilter * filter[NCFORMATS+1]
Definition callbacks.c:1405
char * coord_files_ext[NCFORMATS+1]
Definition callbacks.c:100
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:942
G_MODULE_EXPORT void on_coord_port(GtkWidget *widg, gpointer data)
export or import atomic coordinates: prepare dialog
Definition callbacks.c:1604
G_MODULE_EXPORT void on_save_as_activate(GtkWidget *widg, gpointer data)
open or save, choosing a file name
Definition callbacks.c:621
GtkWidget * read_this
Definition callbacks.c:872
int reading_vas_trj
Definition callbacks.c:1071
void update_sa_info(int sid)
reading CPMD/VASP trajectory, update chemical species info
Definition callbacks.c:906
int read_spec
Definition callbacks.c:873
void prepare_sp_box()
eading CPMD/VASP trajectory, prepare the species combo box
Definition callbacks.c:984
const gchar * dfi[2]
Definition main.c:74
char * coord_files[NCFORMATS+1]
Definition callbacks.c:86
int npt_selection
Definition callbacks.c:1180
gboolean save
Definition callbacks.c:160
G_MODULE_EXPORT void update_at_sp(GtkEntry *res, gpointer data)
reading CPMD/VASP trajectory, changing number of atomes or species
Definition callbacks.c:1038
void open_this_isaacs_xml_file(gchar *profile, int ptoc, gboolean visible)
open an ISAACS XML file
Definition callbacks.c:685
void open_this_proj(gpointer data, gpointer user_data)
Open many projects, one at a time.
Definition callbacks.c:301
void to_read_pos()
send atomic coordinates to Fortran90
Definition callbacks.c:831
int open_cell_file(int format, gchar *filename)
open the file that contains the cell parameters
Definition read_npt.c:232
GtkWidget * sa_lab[2]
Definition callbacks.c:870
gchar * npt_file
Definition callbacks.c:1181
gboolean run_os
Definition callbacks.c:312
void check_read_sa()
reading CPMD/VASP trajectory, testing parameters to active the read capabilty
Definition callbacks.c:880
Callback declarations for main window.
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:309
G_MODULE_EXPORT void on_close_activate(GtkWidget *widg, gpointer cdata)
signal to close a project
Definition close_p.c:332
color colorp[64]
gchar * param[2]
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:140
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:492
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2188
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1314
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:510
cell_info * active_cell
Definition project.c:50
gchar * file_chooser_get_file_name(GtkFileChooser *chooser)
get a file name from a GtkFileChooser (single file selected)
Definition gtk-misc.c:2136
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:597
chemical_data * active_chem
Definition project.c:48
#define BSEP
Definition global.h:245
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:614
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2169
#define STEP_LIMIT
Definition global.h:277
box_info * active_box
Definition project.c:51
#define NCFORMATS
Definition global.h:318
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:923
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:825
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1585
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:299
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:206
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2065
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:813
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:671
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:801
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:2223
GSList * file_chooser_get_file_names(GtkFileChooser *chooser)
create a file list from files selected using a GtkFileChooser
Definition gtk-misc.c:2123
project * active_project
Definition project.c:47
void initcutoffs(chemical_data *chem, int species)
initialize bond cutoffs
Definition bdcall.c:207
void destroy_this_native_dialog(GtkNativeDialog *dialog)
destroy a GtkNativeDialog
Definition gtk-misc.c:2084
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:173
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:189
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:1518
Function declarations for the creation of the OpenGL window.
void init_project(gboolean alloc_box)
initialize a new project
Definition init_p.c:72
int iask(char *question, char *lab, int id, GtkWidget *win)
enter an integer value - prepare the dialog
Definition interface.c:529
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 - GTK3
Definition m_rep.c:367
double z
Definition ogl_draw.c:57
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
int open_project(FILE *fp, int npi)
open atomes project file
Definition open_p.c:220
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:71
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 global.h:104
int b
Definition global.h:106
int c
Definition global.h:107
int a
Definition global.h:105
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:594
GtkWidget * hbox
Definition workspace.c:71
GtkWidget * vbox
Definition workspace.c:72
GtkWidget * lab
Definition workspace.c:73
Function declarations for workspace managment.