atomes 1.1.14
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) gtk_widget_show (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
765 }
766}
767
776G_MODULE_EXPORT void on_isaacs_port (GtkWidget * widg, gpointer data)
777{
778 int i, j;
779 gboolean action;
780#ifdef GTK4
781 GtkFileChooserNative * info;
782#else
783 GtkWidget * info;
784#endif
785 GtkFileChooser * chooser;
786 GtkFileFilter * filter[2];
787 const gchar * file_ext[2]={"*.ipf", "*"};
788 const gchar * file_type[2]={"IPF file (*.ipf)", "All files (*)"};
789 const gchar * str[2]={"Import ISAACS Project File", "Export ISAACS Project File"};
790 const gchar * res[2]={"Open", "Save"};
791 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
792 int pactive = activep;
793 i = GPOINTER_TO_INT (data);
794
795 action = (i && ! nprojects) ? ask_yes_no ("Save an empty project ?", "Do you want to save an empty project ?", GTK_MESSAGE_QUESTION, MainWindow) : TRUE;
796 if (action)
797 {
798 info = create_file_chooser (str[i],
799 GTK_WINDOW(MainWindow),
800 act[i],
801 res[i]);
802 chooser = GTK_FILE_CHOOSER (info);
803#ifdef GTK3
804 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
805#endif
806 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
807 for (j=0; j<2; j++)
808 {
809 filter[j] = gtk_file_filter_new();
810 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), file_type[j]);
811 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), file_ext[j]);
812 gtk_file_chooser_add_filter (chooser, filter[j]);
813 }
815 osp.a = i;
816 osp.b = pactive;
817#ifdef GTK4
818 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_isaacs_port), NULL);
819#else
820 run_this_gtk_dialog (info, G_CALLBACK(run_on_isaacs_port), NULL);
821#endif
822 }
825}
826
833{
834 int i, j, k;
835 double * x, * y, * z;
836 double lat[3];
837
838 x = allocdouble(active_project -> steps*active_project -> natomes);
839 y = allocdouble(active_project -> steps*active_project -> natomes);
840 z = allocdouble(active_project -> steps*active_project -> natomes);
841 k = 0;
842 lat[0] = lat[1] = lat[2] = 0.0;
843 if (active_cell -> crystal)
844 {
845 for (i=0; i<3; i++)
846 {
847 for (j=0; j<3; j++) lat[i] -= active_box -> vect[j][i]/2.0;
848 }
849 }
850 for (i=0; i<active_project -> steps; i++)
851 {
852 for (j=0; j<active_project -> natomes; j++)
853 {
854 x[k] = active_project -> atoms[i][j].x + lat[0];
855 y[k] = active_project -> atoms[i][j].y + lat[1];
856 z[k] = active_project -> atoms[i][j].z + lat[2];
857 k ++;
858 }
859 }
860 read_pos_ (x, y, z);
861 g_free (x);
862 x = NULL;
863 g_free (y);
864 y = NULL;
865 g_free (z);
866 z = NULL;
867}
868
869GtkWidget * read_box;
870GtkWidget * all_sp_box;
871GtkWidget * sa_lab[2];
872GtkWidget * sa_entry[2];
873GtkWidget * read_this;
875
882{
883 int i, j, k;
884 i = j = 0;
885 for (k=0; k<this_reader -> nspec; k++)
886 {
887 i += this_reader -> nsps[k];
888 j += (this_reader -> label[k]) ? 1: 0;
889 }
890 if (i == this_reader -> natomes && j == this_reader -> nspec)
891 {
893 }
894 else
895 {
897 }
898}
899
907void update_sa_info (int sid)
908{
909 gchar * str = g_strdup_printf ("Label of atomic spec. N° %d:", sid+1);
910 gtk_label_set_text (GTK_LABEL(sa_lab[0]), str);
911 g_free (str);
912 if (this_reader -> label[sid])
913 {
914 update_entry_text (GTK_ENTRY(sa_entry[0]), this_reader -> label[sid]);
915 str = g_strdup_printf ("Number of %s atom(s):", this_reader -> label[sid]);
916 }
917 else
918 {
919 update_entry_text (GTK_ENTRY(sa_entry[0]), "");
920 str = g_strdup_printf ("Number of atom(s) for spec. N° %d:", sid+1);
921 }
922 gtk_label_set_text (GTK_LABEL(sa_lab[1]), str);
923 g_free (str);
924 if (this_reader -> nsps[sid])
925 {
926 update_entry_int (GTK_ENTRY(sa_entry[1]), this_reader -> nsps[sid]);
927 }
928 else
929 {
930 update_entry_text (GTK_ENTRY(sa_entry[1]), "");
931 }
932 read_spec = sid;
933}
934
943G_MODULE_EXPORT void update_sa (GtkEntry * res, gpointer data)
944{
945 int i, v;
946 i = GPOINTER_TO_INT(data);
947 const gchar * m = entry_get_text (res);
948 if (i == 0)
949 {
951 this_reader -> label[read_spec] = NULL;
952 this_reader -> label[read_spec] = g_strdup_printf ("%s", m);
954 }
955 else
956 {
957 v= (int)atof(m);
958 if (v > 0)
959 {
960 this_reader -> nsps[read_spec] = v;
961 }
963 }
964 check_read_sa ();
965}
966
975G_MODULE_EXPORT void changed_spec_combo (GtkComboBox * box, gpointer data)
976{
977 update_sa_info (gtk_combo_box_get_active (box));
978}
979
986{
987 int i;
988 if (all_sp_box)
989 {
990 for (i=0; i<2; i++)
991 {
994 }
996 }
999 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, read_box, all_sp_box, FALSE, FALSE, 20);
1000 GtkWidget * hbox;
1001 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, markup_label("Chemical species info:", 200, -1, 0.5, 0.5), FALSE, FALSE, 0);
1002 hbox = create_hbox(0);
1003 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1004 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label("Species: ", 100, -1, 0.0, 0.5), FALSE, FALSE, 5);
1005 GtkWidget * combo;
1006 combo = create_combo ();
1007 gchar * str;
1008
1009 for (i=0; i<this_reader -> nspec; i++)
1010 {
1011 str = g_strdup_printf ("N°%d", i+1);
1012 gtk_combo_box_text_append_text ((GtkComboBoxText *)combo, str);
1013 g_free (str);
1014 }
1015 gtk_combo_box_set_active (GTK_COMBO_BOX(combo), 0);
1016 g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK(changed_spec_combo), NULL);
1017 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, combo, FALSE, FALSE, 5);
1018 for (i=0; i<2; i++)
1019 {
1020 hbox = create_hbox(0);
1021 add_box_child_start (GTK_ORIENTATION_VERTICAL, all_sp_box, hbox, FALSE, FALSE, 5);
1022 sa_lab[i] = markup_label("", 250, -1, 0.0, 0.5);
1023 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_lab[i], FALSE, FALSE, 5);
1024 sa_entry[i] = create_entry (G_CALLBACK(update_sa), 100, 15, FALSE, GINT_TO_POINTER(i));
1025 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, sa_entry[i], FALSE, FALSE, 0);
1026 }
1028 update_sa_info (0);
1029}
1030
1039G_MODULE_EXPORT void update_at_sp (GtkEntry * res, gpointer data)
1040{
1041 int i, v;
1042 i = GPOINTER_TO_INT(data);
1043 const gchar * m = entry_get_text (res);
1044 gboolean up = FALSE;
1045 v = (int)atof(m);
1046 if (i == 0)
1047 {
1048 this_reader -> natomes = (v > 0) ? v : 0;
1049 update_entry_int (res, this_reader -> natomes);
1050 }
1051 else
1052 {
1053 if (v != this_reader -> nspec)
1054 {
1055 this_reader -> nspec = (v > 0) ? v : 0;
1056 if (this_reader -> nspec)
1057 {
1058 if (this_reader -> nsps) g_free (this_reader -> nsps);
1059 this_reader -> nsps = allocint (v);
1060 if (this_reader -> z) g_free (this_reader -> z);
1061 this_reader -> z = allocdouble (v);
1062 if (this_reader -> label) g_free (this_reader -> label);
1063 this_reader -> label = g_malloc0 (v*sizeof*this_reader -> label);
1064 }
1065 up = TRUE;
1066 }
1067 update_entry_int (res, this_reader -> nspec);
1068 }
1069 if (up) prepare_sp_box();
1070}
1071
1073
1080{
1081 int i;
1082 double z;
1083 for (i=0; i<this_reader -> nspec; i++)
1084 {
1086 if (! z) return 0;
1087 this_reader -> z[i] = z;
1088 }
1089 return 1;
1090}
1091
1101G_MODULE_EXPORT void run_to_read_trj_or_vas (GtkDialog * dialog, gint response_id, gpointer data)
1102{
1103 int id = GPOINTER_TO_INT(data);
1104 switch (response_id)
1105 {
1106 case GTK_RESPONSE_APPLY:
1107 if (prep_chem_data())
1108 {
1109 reading_vas_trj = open_coord_file (active_project -> coordfile, id);
1110 }
1111 else
1112 {
1113 reading_vas_trj = 3;
1114 }
1115 break;
1116 default:
1117 reading_vas_trj = 3;
1118 break;
1119 }
1120 destroy_this_dialog (dialog);
1121}
1122
1131{
1132 int i;
1133 gchar * rlabel[2]={"Total number of atom(s):", "Number of chemical species:"};
1134 GtkWidget * dialog = dialogmodal ("Data to read CPMD / VASP trajectory", GTK_WINDOW(MainWindow));
1135 read_this = gtk_dialog_add_button (GTK_DIALOG (dialog), "Apply", GTK_RESPONSE_APPLY);
1136 GtkWidget * vbox = dialog_get_content_area (dialog);
1138 GtkWidget * rentry;
1139 GtkWidget * hbox;
1140 for (i=0; i<2; i++)
1141 {
1142 hbox = create_hbox(0);
1143 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, hbox, FALSE, FALSE, 5);
1144 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, markup_label(rlabel[i], 200, -1, 0.0, 0.5), FALSE, FALSE, 5);
1145 rentry = create_entry (G_CALLBACK(update_at_sp), 100, 15, FALSE, GINT_TO_POINTER(i));
1146 update_entry_text (GTK_ENTRY(rentry), "");
1147 add_box_child_start (GTK_ORIENTATION_HORIZONTAL, hbox, rentry, FALSE, FALSE, 5);
1148 }
1149 read_box = create_hbox(0);
1150 add_box_child_start (GTK_ORIENTATION_VERTICAL, vbox, read_box, FALSE, FALSE, 5);
1151 run_this_gtk_dialog (dialog, G_CALLBACK(run_to_read_trj_or_vas), GINT_TO_POINTER(ff));
1152 return reading_vas_trj;
1153}
1154
1167void cell_data_from_pdb_ (float * a, float * b, float * c, float * alp, float * bet, float * gam)
1168{
1169 active_box -> param[0][0] = * a;
1170 active_box -> param[0][1] = * b;
1171 active_box -> param[0][2] = * c;
1172 active_box -> param[1][0] = * alp;
1173 active_box -> param[1][1] = * bet;
1174 active_box -> param[1][2] = * gam;
1175 // In a PDB file it is required to turn off PBC
1176 // The box usually barely encompass the molecule
1177 active_cell -> pbc = 0;
1178 active_cell -> ltype = 1;
1179}
1180
1182gchar * npt_file;
1183
1184#ifdef GTK4
1194G_MODULE_EXPORT void run_read_npt_data (GtkNativeDialog * info, gint response_id, gpointer data)
1195{
1196 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1197#else
1207G_MODULE_EXPORT void run_read_npt_data (GtkDialog * info, gint response_id, gpointer data)
1208{
1209 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1210#endif
1211 if (response_id == GTK_RESPONSE_ACCEPT)
1212 {
1214 npt_selection = iask ("Please select the file format of the NPT cell data", "Select format :", 3, MainWindow);
1215 }
1216 else
1217 {
1218 npt_selection = -1;
1219 }
1220#ifdef GTK4
1222#else
1223 destroy_this_dialog (info);
1224#endif
1225}
1226
1233{
1234 GtkFileFilter * filter[2];
1235#ifdef GTK4
1236 GtkFileChooserNative * info;
1237#else
1238 GtkWidget * info;
1239#endif
1240 info = create_file_chooser ("Read cell data for NPT molecular dynamics",
1241 GTK_WINDOW(MainWindow),
1242 GTK_FILE_CHOOSER_ACTION_OPEN,
1243 "Open");
1244 GtkFileChooser * chooser = GTK_FILE_CHOOSER(info);
1245 filter[0] = gtk_file_filter_new();
1246 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[0]), "DAT files (*.dat)");
1247 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[0]), "*.dat");
1248 gtk_file_chooser_add_filter (chooser, filter[0]);
1249 filter[1] = gtk_file_filter_new();
1250 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[1]), "All files (*)");
1251 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[1]), "*");
1252 gtk_file_chooser_add_filter (chooser, filter[1]);
1253 npt_file = NULL;
1254#ifdef GTK4
1255 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_read_npt_data), NULL);
1256#else
1257 run_this_gtk_dialog (info, G_CALLBACK(run_read_npt_data), NULL);
1258#endif
1259 return (npt_selection < 0) ? 0 : open_cell_file (npt_selection, npt_file);
1260}
1261
1270{
1271 struct timespec sta_time;
1272 struct timespec sto_time;
1273 int result;
1274 int length = strlen(active_project -> coordfile);
1275 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1276 this_reader = g_malloc0(sizeof*this_reader);
1277 // Set default message type to warning
1278 this_reader -> mid = 1;
1279 switch (id)
1280 {
1281 case 0:
1282 // XYZ file
1283 result = open_coord_file (active_project -> coordfile, id);
1284 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1285 break;
1286 case 1:
1287 // XYZ file NPT
1288 result = open_coord_file (active_project -> coordfile, id);
1289 // result = read_xyz_ (active_project -> coordfile, & length, & npt);
1290 if (! result) result = read_npt_data ();
1291 break;
1292 case 2:
1293 // Chem3D file
1294 result = open_coord_file (active_project -> coordfile, id);
1295 // result = read_c3d_ (active_project -> coordfile, & length);
1296 break;
1297 case 3:
1298 // CPMD TRJ file
1299 result = to_read_trj_or_vas (id);
1300 break;
1301 case 4:
1302 // CPMD TRJ file NPT
1303 result = to_read_trj_or_vas (id);
1304 if (! result) result = read_npt_data ();
1305 break;
1306 case 5:
1307 // VASP XDATCAR file
1308 result = to_read_trj_or_vas (id);
1309 break;
1310 case 6:
1311 // VASP XDATCAR file NPT
1312 result = to_read_trj_or_vas (id);
1313 if (! result) result = read_npt_data ();
1314 break;
1315 case 7:
1316 // PDB file
1317 // result = open_coord_file (active_project -> coordfile, id);
1318 result = read_pdb_ (active_project -> coordfile, & length);
1319 break;
1320 case 8:
1321 // PDB file
1322 // result = open_coord_file (active_project -> coordfile, id);
1323 result = read_pdb_ (active_project -> coordfile, & length);
1324 break;
1325 case 9:
1326 // CIF file building the crystal
1327 result = open_coord_file (active_project -> coordfile, 9);
1328 break;
1329 case 10:
1330 // CIF file using symmetry positions
1331 result = open_coord_file (active_project -> coordfile, 10);
1332 break;
1333 case 11:
1334 // DL-POLY file
1335 result = open_coord_file (active_project -> coordfile, 11);
1336 break;
1337 default:
1338 result = 2;
1339 break;
1340 }
1341 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1342 g_print ("Time to read atomic coordinates: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1343 if (this_reader)
1344 {
1346 {
1347 switch (this_reader -> mid)
1348 {
1349 case 0:
1350 show_error (this_reader -> info, 0, MainWindow);
1351 break;
1352 case 1:
1354 break;
1355 }
1356 }
1357 if (this_reader)
1358 {
1359 if (this_reader -> info) g_free (this_reader -> info);
1360 if (this_reader -> z) g_free (this_reader -> z);
1361 if (this_reader -> nsps) g_free (this_reader -> nsps);
1362 if (this_reader -> label) g_free (this_reader -> label);
1363 if (this_reader -> object_list) g_free (this_reader -> object_list);
1364 if (this_reader -> u_atom_list) g_free (this_reader -> u_atom_list);
1365 if (this_reader -> coord) g_free (this_reader -> coord);
1366 if (this_reader -> lot) g_free (this_reader -> lot);
1367 if (this_reader -> sym_pos) g_free (this_reader -> sym_pos);
1368 if (this_reader -> wyckoff) g_free (this_reader -> wyckoff);
1369 if (this_reader -> occupancy) g_free (this_reader -> occupancy);
1370 if (this_reader -> multi) g_free (this_reader -> multi);
1371 if (this_reader -> lattice.sp_group) g_free (this_reader -> lattice.sp_group);
1372 if (this_reader -> lattice.box) g_free (this_reader -> lattice.box);
1373 g_free (this_reader);
1374 this_reader = NULL;
1375 }
1376 }
1377 switch (result)
1378 {
1379 case 1:
1380 show_error ("Error loading atomic coordinates:\nfile does not exist", 0, MainWindow);
1381 break;
1382 case 2:
1383 show_error ("Error loading coordinates file: format not supported", 0, MainWindow);
1384 break;
1385 case 3:
1386 show_error ("Error at input: impossible to process input file data", 0, MainWindow);
1387 break;
1388 default:
1389 if (id > 6 && id < 9)
1390 {
1391 clock_gettime (CLOCK_MONOTONIC, & sta_time);
1392 if (! prep_data_ ())
1393 {
1394 show_error ("Error while parsing the chemical information\n"
1395 "please check carefully the coordinates file", 0, MainWindow);
1396 result = 4;
1397 }
1398 clock_gettime (CLOCK_MONOTONIC, & sto_time);
1399 g_print ("Time to prepare data: %s\n", calculation_time(FALSE, get_calc_time (sta_time, sto_time)));
1400 }
1401 break;
1402 }
1403 return result;
1404}
1405
1406GtkFileFilter * filter[NCFORMATS+1];
1408
1417void open_this_coordinate_file (int format, gchar * proj_name)
1418{
1419 active_project -> newproj = FALSE;
1420 clock_gettime (CLOCK_MONOTONIC, & start_time);
1421 if (open_coordinate_file (format) == 0)
1422 {
1423 clock_gettime (CLOCK_MONOTONIC, & stop_time);
1424 g_print ("Time to open coordinate file: %s\n", calculation_time(FALSE, get_calc_time (start_time, stop_time)));
1425 active_project -> tfile = format;
1426 if (proj_name)
1427 {
1428 active_project -> name = g_strdup_printf ("%s", proj_name);
1429 }
1430 else
1431 {
1432 gchar * str = g_path_get_basename (active_project -> coordfile);
1433 active_project -> name = g_strdup_printf ("%s", substitute_string (str, g_strdup_printf (".%s", coord_files_ext[format]), NULL));
1434 g_free (str);
1435 }
1436 on_edit_activate (NULL, GINT_TO_POINTER(0));
1437 if (format != 1 && format != 4 && format != 6 && format != 9 && format != 10 && format != 11) on_edit_activate (NULL, GINT_TO_POINTER(4));
1439 on_edit_activate (NULL, GINT_TO_POINTER(2));
1441 frag_update = (active_project -> natomes > ATOM_LIMIT) ? 0 : 1;
1442 mol_update = (frag_update) ? ((active_project -> steps > STEP_LIMIT) ? 0 : 1) : 0;
1443 chemistry_ ();
1444 apply_project (TRUE);
1446 if ((format == 9 || format == 10) && active_cell -> has_a_box)
1447 {
1448#ifdef GTK3
1449 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_rep[0], TRUE);
1450 set_rep (active_glwin -> ogl_rep[0], & active_glwin -> colorp[0][0]);
1451 gtk_check_menu_item_set_active ((GtkCheckMenuItem *)active_glwin -> ogl_clones[0], TRUE);
1452 widget_set_sensitive (active_glwin -> ogl_clones[0], active_glwin -> allbonds[1]);
1453 show_hide_clones (active_glwin -> ogl_clones[0], active_glwin);
1454#endif
1455 shift_it (vec3 (0.0, 0.0, 0.0), 1, activep);
1456 active_glwin -> wrapped = TRUE;
1457 }
1459 if (format == 9 && cif_use_symmetry_positions)
1460 {
1461 gchar * file_name = g_strdup_printf ("%s", active_project -> coordfile);
1462 gchar * proj_name = g_strdup_printf ("%s - symmetry position(s)", active_project -> name);
1463 init_project (TRUE);
1464 active_project -> coordfile = g_strdup_printf ("%s", file_name);
1465 g_free (file_name);
1466 open_this_coordinate_file (10, proj_name);
1467 g_free (proj_name);
1468 }
1469 }
1470 else
1471 {
1473 }
1474}
1475
1476#ifdef GTK4
1486G_MODULE_EXPORT void run_on_coord_port (GtkNativeDialog * info, gint response_id, gpointer data)
1487{
1488 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkFileChooserNative *)info);
1489#else
1499G_MODULE_EXPORT void run_on_coord_port (GtkDialog * info, gint response_id, gpointer data)
1500{
1501 GtkFileChooser * chooser = GTK_FILE_CHOOSER((GtkWidget *)info);
1502#endif
1503 int i, j, k, l, m;
1504 GtkFileFilter * tmp;
1505 int format;
1506 int car_to_au;
1507 i = GPOINTER_TO_INT(data);
1508 gchar * tmp_str;
1509 switch (response_id)
1510 {
1511 case GTK_RESPONSE_ACCEPT:
1512 tmp = gtk_file_chooser_get_filter (chooser);
1513 active_project -> coordfile = file_chooser_get_file_name (chooser);
1514#ifdef GTK4
1516#else
1517 destroy_this_dialog (info);
1518#endif
1519 j = 0;
1520 while (tmp != filter[j]) j++;
1521 if (i == 0)
1522 {
1523 if (j == NCFORMATS)
1524 {
1525 j = iask ("Please select the file format of the atomic coordinates", "Select format :", 2, MainWindow);
1526 }
1527 open_this_coordinate_file (j, NULL);
1528 }
1529 else
1530 {
1531 if (j < 2)
1532 {
1533 format = iask ("Please select the format of the atomic coordinates", "Select format :", 1, MainWindow);
1534 }
1535 else
1536 {
1537 format = 0;
1538 }
1539 active_cell -> frac = (format < 2) ? 0 : format - 1;
1540 car_to_au = (format == 1) ? 1 : 0;
1541 if (j < 2)
1542 {
1543 m = (active_cell -> npt) ? active_project -> steps : 1;
1544 for (l=0; l<m; l++)
1545 {
1546 lattice_ (& m, & l,
1547 active_cell -> box[l].vect,
1548 active_cell -> box[l].param[0],
1549 active_cell -> box[l].param[1],
1550 & active_cell -> ltype,
1551 & active_cell -> frac,
1552 & active_cell -> pbc);
1553 }
1554 to_read_pos ();
1555 }
1556 int length = strlen (active_project -> coordfile);
1557 for (l=1; l<active_project -> nspec+1; l++)
1558 {
1559 m = strlen(active_chem -> label[l-1]);
1560 send_label_ (& l, & m, active_chem -> label[l-1]);
1561 }
1562 switch (j)
1563 {
1564 case 0:
1565 k = write_xyz_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1566 break;
1567 case 1:
1568 k = write_c3d_ (active_project -> coordfile, & length, & active_cell -> frac, & car_to_au);
1569 break;
1570 }
1571 if (k)
1572 {
1573 tmp_str = g_strdup_printf ("Impossible to export the atomic coordinates\nError code: %d", k);
1574 show_error (tmp_str, 0, MainWindow);
1575 g_free (tmp_str);
1576 }
1578 }
1579 break;
1580 default:
1581 if (i == 0)
1582 {
1584 }
1585#ifdef GTK4
1587#else
1588 destroy_this_dialog (info);
1589#endif
1590 break;
1591 }
1592}
1593
1602G_MODULE_EXPORT void on_coord_port (GtkWidget * widg, gpointer data)
1603{
1604 int i, j;
1605#ifdef GTK4
1606 GtkFileChooserNative * info;
1607#else
1608 GtkWidget * info;
1609#endif
1610 GtkFileChooser * chooser;
1611 gchar * tmp_str;
1612 int num_files[2]={NCFORMATS, 2};
1613 const gchar * str[2]={"Import atomic coordinates", "Export atomic coordinates"};
1614 const gchar * res[2]={"Open", "Save"};
1615 char * out_files[2] = {"XYZ file",
1616 "Chem3D file"};
1617 char * out_ext[2]={"xyz", "c3d"};
1618 GtkFileChooserAction act[2]={GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_SAVE};
1619 pactive = activep;
1620 i = GPOINTER_TO_INT (data);
1621
1622 if ((nprojects > 0 && get_project_by_id(activew) -> natomes) || i == 0)
1623 {
1624 if (i == 0)
1625 {
1626 init_project (TRUE);
1627 }
1628 else
1629 {
1631 }
1632 tmp_str = g_strdup_printf ("%s - %s", prepare_for_title(active_project -> name), str[i]);
1633 info = create_file_chooser (tmp_str,
1634 GTK_WINDOW(MainWindow),
1635 act[i],
1636 res[i]);
1637 g_free (tmp_str);
1638 chooser = GTK_FILE_CHOOSER(info);
1639 if (i) gtk_file_chooser_set_create_folders (chooser, TRUE);
1640#ifdef GTK3
1641 gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
1642#endif
1643 for (j=0; j<num_files[i]; j++)
1644 {
1645 filter[j] = gtk_file_filter_new();
1646 if (i == 0)
1647 {
1648 tmp_str = g_strdup_printf ("%s (*.%s)", coord_files[j], coord_files_ext[j]);
1649 }
1650 else
1651 {
1652 tmp_str = g_strdup_printf ("%s (*.%s)", out_files[j], out_ext[j]);
1653 }
1654 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), tmp_str);
1655 g_free (tmp_str);
1656 if (i == 0)
1657 {
1658 tmp_str = g_strdup_printf ("*.%s", coord_files_ext[j]);
1659 }
1660 else
1661 {
1662 tmp_str = g_strdup_printf ("*.%s", out_ext[j]);
1663 }
1664 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), tmp_str);
1665 gtk_file_chooser_add_filter (chooser, filter[j]);
1666 g_free (tmp_str);
1667 }
1668 if (i==0)
1669 {
1670 filter[j] = gtk_file_filter_new();
1671 gtk_file_filter_set_name (GTK_FILE_FILTER(filter[j]), "All files (*)");
1672 gtk_file_filter_add_pattern (GTK_FILE_FILTER(filter[j]), "*");
1673 gtk_file_chooser_add_filter (chooser, filter[j]);
1674 }
1675 else
1676 {
1678 gtk_file_chooser_set_current_name (chooser, "coord.xyz");
1679 }
1680#ifdef GTK4
1681 run_this_gtk_native_dialog ((GtkNativeDialog *)info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1682#else
1683 run_this_gtk_dialog (info, G_CALLBACK(run_on_coord_port), GINT_TO_POINTER(i));
1684#endif
1685 }
1686 else
1687 {
1688 if (nprojects == 0)
1689 {
1690 show_warning ("No project loaded ... nothing to be saved\n", MainWindow);
1691 }
1692 else
1693 {
1694 tmp_str = g_strdup_printf ("Project <b>%s</b> is empty ... nothing to be saved\n",
1695 get_project_by_id(activew) -> name);
1696 show_warning (tmp_str, MainWindow);
1697 g_free (tmp_str);
1698 }
1699 }
1700 activew = activep;
1702}
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:1269
GtkWidget * read_box
Definition callbacks.c:869
int open_coord_file(gchar *filename, int fti)
open atomic coordinates file
Definition read_coord.c:248
int to_read_trj_or_vas(int ff)
reading CPMD/VASP trajectory - prepare the dialog
Definition callbacks.c:1130
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:1207
G_MODULE_EXPORT void changed_spec_combo(GtkComboBox *box, gpointer data)
reading CPMD/VASP trajectory, change the active species
Definition callbacks.c:975
int read_npt_data()
read NPT data associated with atomic coordinates: setup the dialog
Definition callbacks.c:1232
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:870
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:1499
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:1079
G_MODULE_EXPORT void on_isaacs_port(GtkWidget *widg, gpointer data)
open or write ISAACS XML file - prepare the dialog
Definition callbacks.c:776
void open_this_coordinate_file(int format, gchar *proj_name)
open coordinate file format, if successful add to workspace
Definition callbacks.c:1417
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:1407
GtkWidget * sa_entry[2]
Definition callbacks.c:872
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:1101
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:1167
GtkFileFilter * filter[NCFORMATS+1]
Definition callbacks.c:1406
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:943
G_MODULE_EXPORT void on_coord_port(GtkWidget *widg, gpointer data)
export or import atomic coordinates: prepare dialog
Definition callbacks.c:1602
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:873
int reading_vas_trj
Definition callbacks.c:1072
void update_sa_info(int sid)
reading CPMD/VASP trajectory, update chemical species info
Definition callbacks.c:907
int read_spec
Definition callbacks.c:874
void prepare_sp_box()
eading CPMD/VASP trajectory, prepare the species combo box
Definition callbacks.c:985
const gchar * dfi[2]
Definition main-b.c:75
char * coord_files[NCFORMATS+1]
Definition callbacks.c:86
int npt_selection
Definition callbacks.c:1181
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:1039
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:832
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:871
gchar * npt_file
Definition callbacks.c:1182
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:881
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:213
int nprojects
Definition global.c:158
int frag_update
Definition global.c:170
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:471
GtkWidget * MainWindow
Definition global.c:214
gchar * calculation_time(gboolean modelv, double ctime)
get calculation time, human readable
Definition global.c:649
gchar * projfile
Definition global.c:140
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
double get_calc_time(struct timespec start, struct timespec stop)
get calculation time in s
Definition global.c:636
struct timespec stop_time
Definition global.c:192
gboolean cif_use_symmetry_positions
Definition global.c:189
GtkWidget * curvetoolbox
Definition global.c:218
Global variable declarations Global convenience function declarations Global data structure defin...
void run_this_gtk_dialog(GtkWidget *dial, GCallback handler, gpointer data)
run a GTK (3 and 4) basic GtkDialog
Definition gtk-misc.c:472
void file_chooser_set_current_folder(GtkFileChooser *chooser)
set current folder in a GtkFilechooser
Definition gtk-misc.c:2164
GtkWidget * create_entry(GCallback handler, int dim, int cdim, gboolean key_release, gpointer data)
Create a GtkEntry.
Definition gtk-misc.c:1294
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:490
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:2112
const gchar * entry_get_text(GtkEntry *entry)
get the text in a GtkEntry
Definition gtk-misc.c:577
chemical_data * active_chem
Definition project.c:48
#define BSEP
Definition global.h:217
void update_entry_int(GtkEntry *entry, int intval)
update the content of a GtkEntry as int
Definition gtk-misc.c:594
gboolean file_chooser_set_file_name(GtkFileChooser *chooser, gchar *filename)
set file name in a GtkFilechooser
Definition gtk-misc.c:2145
#define STEP_LIMIT
Definition global.h:249
box_info * active_box
Definition project.c:51
#define NCFORMATS
Definition global.h:290
GtkWidget * create_combo()
create a GtkCombox widget, note deprecated in GTK4
Definition gtk-misc.c:903
GtkWidget * dialog_get_content_area(GtkWidget *widg)
prepare GtkWidget to insert content in a GtkDialog window
Definition gtk-misc.c:805
GtkWidget * markup_label(gchar *text, int dimx, int dimy, float ax, float ay)
Definition gtk-misc.c:1565
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:279
void widget_set_sensitive(GtkWidget *widg, gboolean sensitive)
Set sensitivity for a GtkWidget, ensuring it is a GtkWidget.
Definition gtk-misc.c:186
void destroy_this_dialog(GtkDialog *dialog)
destroy a GtkDialog
Definition gtk-misc.c:2041
GtkWidget * create_hbox(int spacing)
create a GtkBox with horizontal orientation
Definition gtk-misc.c:793
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2010
void update_entry_text(GtkEntry *entry, gchar *text)
update the content of a GtkEntry as string
Definition gtk-misc.c:651
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:781
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:2199
GSList * file_chooser_get_file_names(GtkFileChooser *chooser)
create a file list from files selected using a GtkFileChooser
Definition gtk-misc.c:2099
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:2060
void show_the_widgets(GtkWidget *widg)
show GtkWidget
Definition gtk-misc.c:169
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:1359
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:69
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:98
int b
Definition global.h:100
int c
Definition global.h:101
int a
Definition global.h:99
int b
Definition tab-1.c:95
int c
Definition tab-1.c:95
int a
Definition tab-1.c:95
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.