atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
open_p.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2025 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'open_p.c'
24*
25* Contains:
26*
27
28 - The functions to start the reading of an atomes project file
29
30*
31* List of functions:
32
33 int open_project (FILE * fp, int npi);
34
35 char * read_string (int i, FILE * fp);
36
37 gchar * read_this_string (FILE * fp);
38
39 void initcnames (int w, int s);
40 void allocatoms (project * this_proj);
41 void alloc_proj_data (project * this_proj, int cid);
42
43 chemical_data * alloc_chem_data (int spec);
44
45*/
46
47#include "global.h"
48#include "bind.h"
49#include "interface.h"
50#include "callbacks.h"
51#include "project.h"
52#include "curve.h"
53#include "glview.h"
54#include "preferences.h"
55
56extern void alloc_curves (int c);
57extern void init_box_calc ();
58extern void set_color_map_sensitive (glwin * view);
59extern void initgr (int r);
60extern void initsq (int r);
61extern void initbd ();
62extern void initang ();
63extern void initrng ();
64extern void initchn ();
65extern void initmsd ();
66extern void initsh (int s);
67
69
78char * read_string (int i, FILE * fp)
79{
80 char * tmp = NULL;
81 tmp = g_malloc0 (i*sizeof*tmp);
82 int j;
83 for (j=0; j<i; j++)
84 {
85 tmp[j] = fgetc(fp);
86 }
87 //return fgets (tmp, i+1, fp);
88 return tmp;
89}
90
98gchar * read_this_string (FILE * fp)
99{
100 int i;
101 if (fread (& i, sizeof(int), 1, fp) != 1) return NULL;
102 if (i > 0)
103 {
104 gchar * str = g_strdup_printf ("%s", read_string (i, fp));
105 return str;
106 }
107 return NULL;
108}
109
110
119void initcnames (int w, int s)
120{
121 switch (w)
122 {
123 case GR:
124 initgr (w);
125 break;
126 case SQ:
127 initsq (w);
128 break;
129 case SK:
130 initsq (w);
131 break;
132 case GK:
133 initgr (w);
134 break;
135 case BD:
136 initbd ();
137 break;
138 case AN:
139 initang ();
140 break;
141 case RI:
142 initrng ();
143 break;
144 case CH:
145 initchn ();
146 break;
147 case SP:
148 initsh (0);
149 break;
150 default:
151 initmsd ();
152 break;
153 }
154}
155
163void allocatoms (project * this_proj)
164{
165 int i, j;
166 if (this_proj -> atoms != NULL)
167 {
168 g_free (this_proj -> atoms);
169 this_proj -> atoms = NULL;
170 }
171 this_proj -> atoms = g_malloc0 (this_proj -> steps*sizeof*this_proj -> atoms);
172 for (i=0; i < this_proj -> steps; i++)
173 {
174 this_proj -> atoms[i] = g_malloc0 (this_proj -> natomes*sizeof*this_proj -> atoms[i]);
175 for (j=0; j<this_proj -> natomes; j++)
176 {
177 this_proj -> atoms[i][j].style = NONE;
178 }
179 }
180}
181
190{
191 chemical_data * chem = g_malloc0 (sizeof*chem);
192 chem -> label = g_malloc0 (spec*sizeof*chem -> label);
193 chem -> element = g_malloc0 (spec*sizeof*chem -> element);
194 chem -> nsps = allocint (spec);
195 chem -> formula = allocint (spec);
196 chem -> grtotcutoff = default_totcut;
197 chem -> cutoffs = allocddouble (spec, spec);
198 chem -> chem_prop = allocddouble (CHEM_PARAMS, spec);
199 return chem;
200}
201
210void alloc_proj_data (project * this_proj, int cid)
211{
212 if (cid) this_proj -> chemistry = alloc_chem_data (this_proj -> nspec);
213 allocatoms (this_proj);
214}
215
224int open_project (FILE * fp, int npi)
225{
226 int i, j, k;
227 gchar * ver;
228 // First 2 lines for compatibility issues
229 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
230 ver = g_malloc0 (i*sizeof*ver);
231 if (fread (ver, sizeof(char), i, fp) != i) return ERROR_PROJECT;
232
233 gboolean labels_in_file = FALSE;
234 gboolean correct_x = TRUE;
235 old_la_bo_ax_gr = TRUE;
236 // test on ver for version
237 if (g_strcmp0(ver, "%\n% project file v-2.6\n%\n") == 0)
238 {
239 labels_in_file = TRUE;
240 }
241 else if (g_strcmp0(ver, "%\n% project file v-2.7\n%\n") == 0)
242 {
243 labels_in_file = TRUE;
244 correct_x = FALSE;
245 }
246 else if (g_strcmp0(ver, "%\n% project file v-2.8\n%\n") == 0)
247 {
248 old_la_bo_ax_gr = FALSE;
249 labels_in_file = TRUE;
250 correct_x = FALSE;
251 }
252
253 #ifdef DEBUG
254 g_debug ("%s", ver);
255 #endif // DEBUG
256 g_free (ver);
257
258 // After that we read the data
260 if (active_project -> name == NULL) return ERROR_PROJECT;
261#ifdef DEBUG
262 g_debug ("OPEN_PROJECT: Project name= %s",active_project -> name);
263#endif
264 if (fread (& active_project -> tfile, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
265 if (active_project -> tfile > -1)
266 {
267 active_project -> coordfile = read_this_string (fp);
268 if (active_project -> coordfile == NULL) return ERROR_PROJECT;
269 }
270 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
271 if (i > -1)
272 {
273 active_project -> bondfile = read_this_string (fp);
274 if (active_project -> bondfile == NULL) return ERROR_PROJECT;
275 }
276 if (fread (active_project -> runok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
277 if (fread (active_project -> initok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
278 if (fread (active_project -> visok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
279 if (fread (& active_project -> nspec, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
280 if (fread (& active_project -> natomes, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
281 if (fread (& active_project -> steps, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
282 if (fread (& active_cell -> pbc, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
283 if (fread (& active_cell -> frac, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
284 if (fread (& active_cell -> ltype, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
285 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
286 if (i > 1 && i != active_project -> steps) return ERROR_PROJECT;
287 if (i > 1) active_cell -> npt = TRUE;
288 active_cell -> box = g_malloc0 (i*sizeof*active_cell -> box);
289 active_box = & active_cell -> box[0];
290 for (j=0; j<i; j++)
291 {
292 for (k=0; k<3; k++)
293 {
294 if (fread (active_cell -> box[j].vect[k], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
295 }
296 if (fread (active_cell -> box[j].param[0], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
297 if (fread (active_cell -> box[j].param[1], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
298 }
299 if (fread (& active_cell -> crystal, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
300 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
301 if (active_cell -> crystal && i)
302 {
303 active_cell -> sp_group = g_malloc0(sizeof*active_cell -> sp_group);
304 active_cell -> sp_group -> id = i;
305 active_cell -> sp_group -> bravais = read_this_string (fp);
306 if (! active_cell -> sp_group -> bravais) return ERROR_PROJECT;
307 active_cell -> sp_group -> hms = read_this_string (fp);
308 if (! active_cell -> sp_group -> hms) return ERROR_PROJECT;
309 active_cell -> sp_group -> setting = read_this_string (fp);
310 if (! active_cell -> sp_group -> setting) return ERROR_PROJECT;
311 }
312 if (fread (& active_project -> run, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
313 if (fread (& active_project -> initgl, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
314 if (fread (active_project -> tmp_pixels, sizeof(int), 2, fp) != 2) return ERROR_PROJECT;
315 if (fread (active_project -> num_delta, sizeof(int), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
316 if (fread (active_project -> delta, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
317 if (fread (active_project -> rsearch, sizeof(int), 2, fp) != 2) return ERROR_PROJECT;
318 for (i=0; i<5; i++)
319 {
320 if (fread (active_project -> rsparam[i], sizeof(int), 6, fp) != 6) return ERROR_PROJECT;
321 if (fread (active_project -> rsdata[i], sizeof(double), 5, fp) != 5) return ERROR_PROJECT;
322 }
323 if (fread (& active_project -> csearch, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
324 if (fread (active_project -> csparam, sizeof(int), 7, fp) != 7) return ERROR_PROJECT;
325 if (fread (active_project -> csdata, sizeof(double), 2, fp) != 2) return ERROR_PROJECT;
326 if (fread (active_project -> min, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
327 if (fread (active_project -> max, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
328 if (fread (& active_project -> tunit, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
329 if (active_project -> natomes != 0 && active_project -> nspec != 0)
330 {
333 if (labels_in_file)
334 {
335 for (i=0; i<active_project -> nspec; i++)
336 {
339 }
340 }
341 if (fread (active_chem -> nsps, sizeof(int), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
342 if (fread (active_chem -> formula, sizeof(int), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
343 j = 0;
344 for (i=0; i<active_project -> nspec; i++) j+= active_chem -> nsps[i];
345 if (j != active_project -> natomes) return ERROR_PROJECT;
346 for (i=0; i<CHEM_PARAMS; i++)
347 {
348 if (fread (active_chem -> chem_prop[i], sizeof(double), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
349 }
350 if (correct_x)
351 {
352 for (i=0; i<active_project -> nspec; i++)
353 {
354 active_chem -> chem_prop[CHEM_X][i] = active_chem -> chem_prop[CHEM_Z][i];
355 }
356 }
357 if (fread (& active_chem -> grtotcutoff, sizeof(double), 1, fp) != 1) return ERROR_PROJECT;
358 for ( i = 0 ; i < active_project -> nspec ; i ++ )
359 {
360 if (fread (active_chem -> cutoffs[i], sizeof(double), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
361 }
362 for (i=0; i<active_project -> steps; i++)
363 {
364 for (j=0; j< active_project -> natomes; j++)
365 {
366 if (read_atom_a (fp, active_project, i, j) != OK) return ERROR_ATOM_A;
367 }
368 }
369 init_box_calc ();
370 if (active_project -> run)
371 {
372#ifdef DEBUG
373 g_debug ("OPEN_PROJECT:: So far so good ... still");
374 g_debug ("OPEN_PROJECT:: RUN PROJECT\n");
375#endif
376 i = alloc_data_ (& active_project -> natomes,
377 & active_project -> nspec,
378 & active_project -> steps);
379 if (i == 1)
380 {
381 if (! labels_in_file)
382 {
383 j = 1;
384 prep_spec_ (active_chem -> chem_prop[CHEM_Z], active_chem -> nsps, & j);
385 }
386 initcwidgets ();
387 // Read curves
388 for (i=0; i<NGRAPHS; i++) if (active_project -> initok[i]) initcnames (i, 0);
389 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
390#ifdef DEBUG
391 g_debug ("\n**********************************************\n curves to read= %d\n**********************************************\n", i);
392#endif
393 if (i != 0)
394 {
395 j = 0;
396 if (fread (& j, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
397 if (j)
398 {
399 active_project -> numc[SP] = j;
400 active_project -> numwid += j;
403 active_project -> initok[SP] = TRUE;
404 for (k=0; k<j; k++)
405 {
406 active_project -> curves[SP][k] -> name = read_this_string (fp);
407 if (active_project -> curves[SP][k] -> name == NULL) return ERROR_PROJECT;
408 }
409 }
410 for (j=0; j<i; j++)
411 {
412 if (read_project_curve (fp, npi, activep) != OK)
413 {
414 // error
415 return ERROR_CURVE;
416 }
417 }
418 }
420 }
421 else
422 {
423 return ERROR_PROJECT;
424 }
425 }
426 }
427 else
428 {
429 // error
430 return ERROR_NO_WAY;
431 }
432/* #ifdef DEBUG
433 debugioproj (active_project, "READ INIT");
434#endif */
435 if (update_project() == 1)
436 {
437 if (active_project -> initgl)
438 {
439 gboolean tmp_bonding;
440 if (fread (& tmp_bonding, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
441 if (fread (tmp_adv_bonding, sizeof(gboolean), 2, fp) != 2) return ERROR_PROJECT;
442 apply_project (TRUE);
444 int tmpcoord[10];
445 if (fread (tmpcoord, sizeof(int), 10, fp) != 10) return ERROR_PROJECT;
446 if (active_glwin -> bonding)
447 {
448 for (i=0; i<2; i++) if (tmpcoord[i] != active_project -> coord -> totcoord[i]) return ERROR_PROJECT;
449 for (i=2; i<4; i++)
450 {
451 if (active_glwin -> adv_bonding[i-2])
452 {
453 if (tmpcoord[i] != active_project -> coord -> totcoord[i]) return ERROR_PROJECT;
454 }
455 }
456 }
457 for (i=0; i<10; i++) active_project -> coord -> totcoord[i] = tmpcoord[i];
458 // Read molecule info
459 if ((active_project -> natomes > ATOM_LIMIT || active_project -> steps > STEP_LIMIT) && tmp_adv_bonding[1])
460 {
461 if (read_mol (fp) != OK) return ERROR_MOL;
462 }
463 for (i=0; i<2; i++) active_glwin -> adv_bonding[i] = tmp_adv_bonding[i];
464 active_glwin -> bonding = tmp_bonding;
465
466 if (read_bonding (fp) != OK) return ERROR_COORD;
467 i = read_opengl_image (fp, active_project, active_glwin -> anim -> last -> img, active_project -> nspec);
468 if (i != OK) return i;
469
471 if (i != OK) return i;
473 if (i != OK) return i;
474
475 for (i=0; i<2; i++)
476 {
478 if (j != OK) return j;
479 }
480 for (i=0; i<2; i++)
481 {
483 if (j != OK) return j;
484 }
485#ifdef GTK3
486 // GTK3 Menu Action To Check
488#endif
489 return OK;
490 }
491 return OK;
492 }
493 else
494 {
495 return ERROR_UPDATE;
496 }
497}
Binding to the Fortran90 subroutines.
void prep_spec_(double *, int *, int *)
int alloc_data_(int *, int *, int *)
integer(kind=c_int) function bonding(scf, sbf, adv, bdist, bmin, delt_ij, sfil)
Definition bonds.F90:22
void initcwidgets()
initializing curve values
Definition initc.c:104
void apply_project(gboolean showtools)
get project ready for calculation and initialize the OpenGL window
Definition callbacks.c:663
Callback declarations for main window.
void fill_tool_model()
fill the tool window tree model
Definition tools.c:87
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
gchar * param[2]
Variable declarations for the curve widget Functions for interactions with the curve widget.
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
void addcurwidgets(int pid, int rid, int st)
add curve widgets to the project
Definition cwidget.c:259
int atoms[NUM_STYLES][2]
FILE * fp
int activep
Definition global.c:159
gboolean tmp_adv_bonding[2]
Definition global.c:183
double ** allocddouble(int xal, int yal)
allocate a double ** pointer
Definition global.c:475
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
int tmp_pixels[2]
Definition global.c:173
Global variable declarations Global convenience function declarations Global data structure defin...
glwin * active_glwin
Definition project.c:53
#define ATOM_LIMIT
atom number limit to compute fragment(s) and molecule(s) analysis automatically
cell_info * active_cell
Definition project.c:50
#define ERROR_UPDATE
Definition global.h:288
chemical_data * active_chem
Definition project.c:48
#define ERROR_CURVE
Definition global.h:284
#define GR
Definition global.h:324
#define NGRAPHS
#define SQ
Definition global.h:325
#define STEP_LIMIT
Definition global.h:279
#define ERROR_PROJECT
Definition global.h:283
#define CHEM_PARAMS
Definition global.h:298
#define RI
Definition global.h:330
box_info * active_box
Definition project.c:51
#define BD
Definition global.h:328
#define AN
Definition global.h:329
#define ERROR_ATOM_A
Definition global.h:286
#define OK
Definition global.h:281
#define min(a, b)
Definition global.h:81
#define ERROR_COORD
Definition global.h:290
#define ERROR_MOL
#define CHEM_X
Definition global.h:303
#define CHEM_Z
Definition global.h:299
#define SK
Definition global.h:326
#define GK
Definition global.h:327
#define SP
Definition global.h:332
project * active_project
Definition project.c:47
#define CH
Definition global.h:331
#define ERROR_NO_WAY
Definition global.h:289
#define max(a, b)
Definition global.h:80
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
@ NONE
Definition glview.h:181
Messaging function declarations.
int open_project(FILE *fp, int npi)
open atomes project file
Definition open_p.c:224
void set_color_map_sensitive(glwin *view)
char * read_string(int i, FILE *fp)
read a string from a file
Definition open_p.c:78
gboolean old_la_bo_ax_gr
Definition open_p.c:68
gchar * read_this_string(FILE *fp)
is there a string to read in this file ? yes do it
Definition open_p.c:98
void initsh(int s)
initialize the curve widgets for the spherical harmonics
Definition spcall.c:57
void initang()
initialize the curve widgets for the angle distribution
Definition bdcall.c:163
void initmsd()
initialize the curve widgets for the MSD
Definition msdcall.c:56
void initsq(int r)
initialize the curve widgets for the s(q) / s(k) calculation
Definition sqcall.c:60
void initcnames(int w, int s)
initialize curve namees
Definition open_p.c:119
chemical_data * alloc_chem_data(int spec)
allocate chemistry data
Definition open_p.c:189
void initrng()
initialize the curve widgets for the ring statistics
Definition ringscall.c:81
void init_box_calc()
initialize calculation possibilities based the periodicity
Definition edit_menu.c:540
void allocatoms(project *this_proj)
allocate project data
Definition open_p.c:163
void initchn()
initialize the curve widgets for the chains statistics calculation
Definition chainscall.c:67
void initgr(int r)
initialize the curve widgets for the g(r)/g(k)
Definition grcall.c:65
void initbd()
initialize the curve widgets for the bond distribution
Definition bdcall.c:139
void alloc_proj_data(project *this_proj, int cid)
allocate data
Definition open_p.c:210
void alloc_curves(int c)
allocating curve data
Definition initc.c:74
double default_totcut
Preference variable declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int read_dlp_field_data(FILE *fp, project *this_proj)
read force field data from file
Definition read_field.c:460
int read_mol(FILE *fp)
read molecule(s) information from file
Definition read_mol.c:92
int read_lmp_field_data(FILE *fp, project *this_proj)
read LAMMPS field data from file
Definition read_field.c:579
int read_project_curve(FILE *fp, int wid, int pid)
read a project curve from file
Definition read_curve.c:74
int read_opengl_image(FILE *fp, project *this_proj, image *img, int sid)
read OpenGL image properties from file
int update_project()
update project: send data to Fortran90, and update calculation interactors
Definition update_p.c:94
int read_cpmd_data(FILE *fp, int cid, project *this_proj)
read CPMD data from file
Definition read_qm.c:133
int read_atom_a(FILE *fp, project *this_proj, int s, int a)
read atom properties from file (a)
Definition read_opengl.c:61
int read_bonding(FILE *fp)
read bonding information from file
Definition read_bond.c:52
int read_cp2k_data(FILE *fp, int cid, project *this_proj)
read CP2K data from file
Definition read_qm.c:216
Definition glwin.h:351
Definition glwin.h:965
int c
Definition tab-1.c:95
int element
Definition w_periodic.c:61
atom_search * csearch
Definition w_search.c:2729
GtkWidget * img
Definition workspace.c:70