atomes 1.1.16
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-2024 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
55extern void alloc_curves (int c);
56extern void init_box_calc ();
57extern void set_color_map_sensitive (glwin * view);
58extern void initgr (int r);
59extern void initsq (int r);
60extern void initbd ();
61extern void initang ();
62extern void initrng ();
63extern void initchn ();
64extern void initmsd ();
65extern void initsh (int s);
66
75char * read_string (int i, FILE * fp)
76{
77 char * tmp = NULL;
78 tmp = g_malloc0 (i*sizeof*tmp);
79 int j;
80 for (j=0; j<i; j++)
81 {
82 tmp[j] = fgetc(fp);
83 }
84 //return fgets (tmp, i+1, fp);
85 return tmp;
86}
87
95gchar * read_this_string (FILE * fp)
96{
97 int i;
98 if (fread (& i, sizeof(int), 1, fp) != 1) return NULL;
99 if (i > 0)
100 {
101 gchar * str = g_strdup_printf ("%s", read_string (i, fp));
102 return str;
103 }
104 return NULL;
105}
106
107
116void initcnames (int w, int s)
117{
118 switch (w)
119 {
120 case GR:
121 initgr (w);
122 break;
123 case SQ:
124 initsq (w);
125 break;
126 case SK:
127 initsq (w);
128 break;
129 case GK:
130 initgr (w);
131 break;
132 case BD:
133 initbd ();
134 break;
135 case AN:
136 initang ();
137 break;
138 case RI:
139 initrng ();
140 break;
141 case CH:
142 initchn ();
143 break;
144 case SP:
145 initsh (0);
146 break;
147 default:
148 initmsd ();
149 break;
150 }
151}
152
160void allocatoms (project * this_proj)
161{
162 int i, j;
163 if (this_proj -> atoms != NULL)
164 {
165 g_free (this_proj -> atoms);
166 this_proj -> atoms = NULL;
167 }
168 this_proj -> atoms = g_malloc0 (this_proj -> steps*sizeof*this_proj -> atoms);
169 for (i=0; i < this_proj -> steps; i++)
170 {
171 this_proj -> atoms[i] = g_malloc0 (this_proj -> natomes*sizeof*this_proj -> atoms[i]);
172 for (j=0; j<this_proj -> natomes; j++)
173 {
174 this_proj -> atoms[i][j].style = NONE;
175 }
176 }
177}
178
187{
188 chemical_data * chem = g_malloc0 (sizeof*chem);
189 chem -> label = g_malloc0 (spec*sizeof*chem -> label);
190 chem -> element = g_malloc0 (spec*sizeof*chem -> element);
191 chem -> nsps = allocint (spec);
192 chem -> formula = allocint (spec);
193 chem -> cutoffs = allocddouble (spec, spec);
194 chem -> chem_prop = allocddouble (CHEM_PARAMS, spec);
195 return chem;
196}
197
206void alloc_proj_data (project * this_proj, int cid)
207{
208 if (cid) this_proj -> chemistry = alloc_chem_data (this_proj -> nspec);
209 allocatoms (this_proj);
210}
211
220int open_project (FILE * fp, int npi)
221{
222 int i, j, k;
223 gchar * ver;
224 // First 2 lines for compatibility issues
225 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
226 ver = g_malloc0 (i*sizeof*ver);
227 if (fread (ver, sizeof(char), i, fp) != i) return ERROR_PROJECT;
228
229 gboolean labels_in_file = FALSE;
230 gboolean correct_x = TRUE;
231 // test on ver for version
232 if (g_strcmp0(ver, "%\n% project file v-2.6\n%\n") == 0)
233 {
234 labels_in_file = TRUE;
235 }
236 else if (g_strcmp0(ver, "%\n% project file v-2.7\n%\n") == 0)
237 {
238 labels_in_file = TRUE;
239 correct_x = FALSE;
240 }
241
242 #ifdef DEBUG
243 g_debug ("%s", ver);
244 #endif // DEBUG
245 g_free (ver);
246
247 // After that we read the data
249 if (active_project -> name == NULL) return ERROR_PROJECT;
250#ifdef DEBUG
251 g_debug ("OPEN_PROJECT: Project name= %s",active_project -> name);
252#endif
253 if (fread (& active_project -> tfile, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
254 if (active_project -> tfile > -1)
255 {
256 active_project -> coordfile = read_this_string (fp);
257 if (active_project -> coordfile == NULL) return ERROR_PROJECT;
258 }
259 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
260 if (i > -1)
261 {
262 active_project -> bondfile = read_this_string (fp);
263 if (active_project -> bondfile == NULL) return ERROR_PROJECT;
264 }
265 if (fread (active_project -> runok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
266 if (fread (active_project -> initok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
267 if (fread (active_project -> visok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
268 if (fread (& active_project -> nspec, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
269 if (fread (& active_project -> natomes, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
270 if (fread (& active_project -> steps, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
271 if (fread (& active_cell -> pbc, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
272 if (fread (& active_cell -> frac, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
273 if (fread (& active_cell -> ltype, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
274 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
275 if (i > 1 && i != active_project -> steps) return ERROR_PROJECT;
276 if (i > 1) active_cell -> npt = TRUE;
277 active_cell -> box = g_malloc0 (i*sizeof*active_cell -> box);
278 active_box = & active_cell -> box[0];
279 for (j=0; j<i; j++)
280 {
281 for (k=0; k<3; k++)
282 {
283 if (fread (active_cell -> box[j].vect[k], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
284 }
285 if (fread (active_cell -> box[j].param[0], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
286 if (fread (active_cell -> box[j].param[1], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
287 }
288 if (fread (& active_cell -> crystal, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
289 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
290 if (active_cell -> crystal && i)
291 {
292 active_cell -> sp_group = g_malloc0(sizeof*active_cell -> sp_group);
293 active_cell -> sp_group -> id = i;
294 active_cell -> sp_group -> bravais = read_this_string (fp);
295 if (! active_cell -> sp_group -> bravais) return ERROR_PROJECT;
296 active_cell -> sp_group -> hms = read_this_string (fp);
297 if (! active_cell -> sp_group -> hms) return ERROR_PROJECT;
298 active_cell -> sp_group -> setting = read_this_string (fp);
299 if (! active_cell -> sp_group -> setting) return ERROR_PROJECT;
300 }
301 if (fread (& active_project -> run, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
302 if (fread (& active_project -> initgl, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
303 if (fread (active_project -> tmp_pixels, sizeof(int), 2, fp) != 2) return ERROR_PROJECT;
304 if (fread (active_project -> num_delta, sizeof(int), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
305 if (fread (active_project -> delta, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
306 if (fread (active_project -> rsearch, sizeof(int), 2, fp) != 2) return ERROR_PROJECT;
307 for (i=0; i<5; i++)
308 {
309 if (fread (active_project -> rsparam[i], sizeof(int), 6, fp) != 6) return ERROR_PROJECT;
310 if (fread (active_project -> rsdata[i], sizeof(double), 5, fp) != 5) return ERROR_PROJECT;
311 }
312 if (fread (& active_project -> csearch, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
313 if (fread (active_project -> csparam, sizeof(int), 7, fp) != 7) return ERROR_PROJECT;
314 if (fread (active_project -> csdata, sizeof(double), 2, fp) != 2) return ERROR_PROJECT;
315 if (fread (active_project -> min, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
316 if (fread (active_project -> max, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
317 if (fread (& active_project -> tunit, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
318 if (active_project -> natomes != 0 && active_project -> nspec != 0)
319 {
322 if (labels_in_file)
323 {
324 for (i=0; i<active_project -> nspec; i++)
325 {
328 }
329 }
330 if (fread (active_chem -> nsps, sizeof(int), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
331 if (fread (active_chem -> formula, sizeof(int), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
332 j = 0;
333 for (i=0; i<active_project -> nspec; i++) j+= active_chem -> nsps[i];
334 if (j != active_project -> natomes) return ERROR_PROJECT;
335 for (i=0; i<CHEM_PARAMS; i++)
336 {
337 if (fread (active_chem -> chem_prop[i], sizeof(double), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
338 }
339 if (correct_x)
340 {
341 for (i=0; i<active_project -> nspec; i++)
342 {
343 active_chem -> chem_prop[CHEM_X][i] = active_chem -> chem_prop[CHEM_Z][i];
344 }
345 }
346 if (fread (& active_chem -> grtotcutoff, sizeof(double), 1, fp) != 1) return ERROR_PROJECT;
347 for ( i = 0 ; i < active_project -> nspec ; i ++ )
348 {
349 if (fread (active_chem -> cutoffs[i], sizeof(double), active_project -> nspec, fp) != active_project -> nspec) return ERROR_PROJECT;
350 }
351 for (i=0; i<active_project -> steps; i++)
352 {
353 for (j=0; j< active_project -> natomes; j++)
354 {
355 if (read_atom_a (fp, active_project, i, j) != OK) return ERROR_ATOM_A;
356 }
357 }
358 init_box_calc ();
359 if (active_project -> run)
360 {
361#ifdef DEBUG
362 g_debug ("OPEN_PROJECT:: So far so good ... still");
363 g_debug ("OPEN_PROJECT:: RUN PROJECT\n");
364#endif
365 i = alloc_data_ (& active_project -> natomes,
366 & active_project -> nspec,
367 & active_project -> steps);
368 if (i == 1)
369 {
370 if (! labels_in_file)
371 {
372 j = 1;
373 prep_spec_ (active_chem -> chem_prop[CHEM_Z], active_chem -> nsps, & j);
374 }
375 initcwidgets ();
376 // Read curves
377 for (i=0; i<NGRAPHS; i++) if (active_project -> initok[i]) initcnames (i, 0);
378 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
379#ifdef DEBUG
380 g_debug ("\n**********************************************\n curves to read= %d\n**********************************************\n", i);
381#endif
382 if (i != 0)
383 {
384 j = 0;
385 if (fread (& j, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
386 if (j)
387 {
388 active_project -> numc[SP] = j;
389 active_project -> numwid += j;
392 active_project -> initok[SP] = TRUE;
393 for (k=0; k<j; k++)
394 {
395 active_project -> curves[SP][k] -> name = read_this_string (fp);
396 if (active_project -> curves[SP][k] -> name == NULL) return ERROR_PROJECT;
397 }
398 }
399 for (j=0; j<i; j++)
400 {
401 if (read_project_curve (fp, npi, activep) != OK)
402 {
403 // error
404 return ERROR_CURVE;
405 }
406 }
407 }
409 }
410 else
411 {
412 return ERROR_PROJECT;
413 }
414 }
415 }
416 else
417 {
418 // error
419 return ERROR_NO_WAY;
420 }
421/* #ifdef DEBUG
422 debugioproj (active_project, "READ INIT");
423#endif */
424 if (update_project() == 1)
425 {
426 if (active_project -> initgl)
427 {
428 gboolean tmp_bonding;
429 if (fread (& tmp_bonding, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
430 if (fread (tmp_adv_bonding, sizeof(gboolean), 2, fp) != 2) return ERROR_PROJECT;
431 apply_project (TRUE);
433 int tmpcoord[10];
434 if (fread (tmpcoord, sizeof(int), 10, fp) != 10) return ERROR_PROJECT;
435 if (active_glwin -> bonding)
436 {
437 for (i=0; i<2; i++) if (tmpcoord[i] != active_project -> coord -> totcoord[i]) return ERROR_PROJECT;
438 for (i=2; i<4; i++)
439 {
440 if (active_glwin -> adv_bonding[i-2])
441 {
442 if (tmpcoord[i] != active_project -> coord -> totcoord[i]) return ERROR_PROJECT;
443 }
444 }
445 }
446 for (i=0; i<10; i++) active_project -> coord -> totcoord[i] = tmpcoord[i];
447 // Read molecule info
448 if ((active_project -> natomes > ATOM_LIMIT || active_project -> steps > STEP_LIMIT) && tmp_adv_bonding[1])
449 {
450 if (read_mol (fp) != OK) return ERROR_MOL;
451 }
452 for (i=0; i<2; i++) active_glwin -> adv_bonding[i] = tmp_adv_bonding[i];
453 active_glwin -> bonding = tmp_bonding;
454
455 if (read_bonding (fp) != OK) return ERROR_COORD;
456 i = read_opengl_image (fp, active_project, active_glwin -> anim -> last -> img, active_project -> nspec);
457 if (i != OK) return i;
458
460 if (i != OK) return i;
462 if (i != OK) return i;
463
464 for (i=0; i<2; i++)
465 {
467 if (j != OK) return j;
468 }
469 for (i=0; i<2; i++)
470 {
472 if (j != OK) return j;
473 }
474#ifdef GTK3
475 // GTK3 Menu Action To Check
477#endif
478 return OK;
479 }
480 return OK;
481 }
482 else
483 {
484 return ERROR_UPDATE;
485 }
486}
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:665
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:286
chemical_data * active_chem
Definition project.c:48
#define ERROR_CURVE
Definition global.h:282
#define GR
Definition global.h:322
#define NGRAPHS
#define SQ
Definition global.h:323
#define STEP_LIMIT
Definition global.h:277
#define ERROR_PROJECT
Definition global.h:281
#define CHEM_PARAMS
Definition global.h:296
#define RI
Definition global.h:328
box_info * active_box
Definition project.c:51
#define BD
Definition global.h:326
#define AN
Definition global.h:327
#define ERROR_ATOM_A
Definition global.h:284
#define OK
Definition global.h:279
#define min(a, b)
Definition global.h:81
#define ERROR_COORD
Definition global.h:288
#define ERROR_MOL
#define CHEM_X
Definition global.h:301
#define CHEM_Z
Definition global.h:297
#define SK
Definition global.h:324
#define GK
Definition global.h:325
#define SP
Definition global.h:330
project * active_project
Definition project.c:47
#define CH
Definition global.h:329
#define ERROR_NO_WAY
Definition global.h:287
#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:172
Messaging function declarations.
int open_project(FILE *fp, int npi)
open atomes project file
Definition open_p.c:220
void set_color_map_sensitive(glwin *view)
char * read_string(int i, FILE *fp)
read a string from a file
Definition open_p.c:75
gchar * read_this_string(FILE *fp)
is there a string to read in this file ? yes do it
Definition open_p.c:95
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:160
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:116
chemical_data * alloc_chem_data(int spec)
allocate chemistry data
Definition open_p.c:186
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:551
void allocatoms(project *this_proj)
allocate project data
Definition open_p.c:160
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:136
void alloc_proj_data(project *this_proj, int cid)
allocate data
Definition open_p.c:206
void alloc_curves(int c)
allocating curve data
Definition initc.c:74
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:55
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:875
int c
Definition tab-1.c:95
int element
Definition w_periodic.c:61
atom_search * csearch
Definition w_search.c:2718
GtkWidget * img
Definition workspace.c:70