atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
save_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: 'save_p.c'
24*
25* Contains:
26*
27
28 - The functions to start saving an atomes project file
29
30*
31* List of functions:
32
33 int save_this_string (FILE * fp, gchar * string);
34 int save_project (FILE * fp, project * this_proj, int npi);
35
36*/
37
38#include "global.h"
39#include "project.h"
40
49int save_this_string (FILE * fp, gchar * string)
50{
51 int i;
52 if (string)
53 {
54 i = strlen (string);
55 if (i > 0)
56 {
57 i ++;
58 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
59 if (fwrite (string, sizeof(char), i, fp) != i) return ERROR_RW;
60 }
61 else
62 {
63 i = 0;
64 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
65 }
66 }
67 else
68 {
69 i = 0;
70 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
71 }
72 return OK;
73}
74
84int save_project (FILE * fp, project * this_proj, int npi)
85{
86 int i, j, k;
87 gchar * ver;
88
89 // First 2 lines for compatibility issues
90 i = 2;
91 j = 7;
92 ver = g_strdup_printf ("%%\n%% project file v-%1d.%1d\n%%\n", i, j);
93 if (save_this_string (fp, ver) != OK)
94 {
95 g_free (ver);
96 return ERROR_PROJECT;
97 }
98 g_free (ver);
99 if (save_this_string (fp, this_proj -> name) != OK) return ERROR_PROJECT;
100 if (fwrite (& this_proj -> tfile, sizeof(this_proj -> tfile), 1, fp) != 1) return ERROR_PROJECT;
101 if (this_proj -> tfile > -1)
102 {
103 if (save_this_string (fp, this_proj -> coordfile) != OK) return ERROR_PROJECT;
104 }
105 if (this_proj -> bondfile != NULL)
106 {
107 if (save_this_string (fp, this_proj -> bondfile) != OK) return ERROR_PROJECT;
108 }
109 else
110 {
111 i = -1;
112 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
113 }
114 if (fwrite (this_proj -> runok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
115 if (fwrite (this_proj -> initok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
116 if (fwrite (this_proj -> visok, sizeof(gboolean), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
117 if (fwrite (& this_proj -> nspec, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
118 if (fwrite (& this_proj -> natomes, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
119 if (fwrite (& this_proj -> steps, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
120 if (fwrite (& this_proj -> cell.pbc, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
121 if (fwrite (& this_proj -> cell.frac, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
122 if (fwrite (& this_proj -> cell.ltype, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
123 i = (this_proj -> cell.npt) ? this_proj -> steps : 1;
124 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
125 for (j=0; j<i; j++)
126 {
127 for (k=0; k<3; k++)
128 {
129 if (fwrite (this_proj -> cell.box[j].vect[k], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
130 }
131 if (fwrite (this_proj -> cell.box[j].param[0], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
132 if (fwrite (this_proj -> cell.box[j].param[1], sizeof(double), 3, fp) != 3) return ERROR_PROJECT;
133 }
134 if (fwrite (& this_proj -> cell.crystal, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
135 if (this_proj -> cell.sp_group)
136 {
137 if (fwrite (& this_proj -> cell.sp_group -> id, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
138 if (save_this_string (fp, this_proj -> cell.sp_group -> bravais) != OK) return ERROR_PROJECT;
139 if (save_this_string (fp, this_proj -> cell.sp_group -> hms) != OK) return ERROR_PROJECT;
140 if (save_this_string (fp, this_proj -> cell.sp_group -> setting) != OK) return ERROR_PROJECT;
141 }
142 else
143 {
144 i = 0;
145 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
146 }
147
148 if (fwrite (& this_proj -> run, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
149 if (fwrite (& this_proj -> initgl, sizeof(gboolean), 1, fp) != 1) return ERROR_PROJECT;
150 if (fwrite (this_proj -> modelgl -> pixels, sizeof(int), 2, fp) != 2) return ERROR_PROJECT;
151 if (fwrite (this_proj -> num_delta, sizeof(int), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
152 if (fwrite (this_proj -> delta, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
153 if (fwrite (this_proj -> rsearch, sizeof(int), 2, fp) != 2) return ERROR_PROJECT;
154 for (i=0; i<5; i++)
155 {
156 if (fwrite (this_proj -> rsparam[i], sizeof(int), 6, fp) != 6) return ERROR_PROJECT;
157 if (fwrite (this_proj -> rsdata[i], sizeof(double), 5, fp) != 5) return ERROR_PROJECT;
158 }
159 if (fwrite (& this_proj -> csearch, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
160 if (fwrite (this_proj -> csparam, sizeof(int), 7, fp) != 7) return ERROR_PROJECT;
161 if (fwrite (this_proj -> csdata, sizeof(double), 2, fp) != 2) return ERROR_PROJECT;
162 if (fwrite (this_proj -> min, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
163 if (fwrite (this_proj -> max, sizeof(double), NGRAPHS, fp) != NGRAPHS) return ERROR_PROJECT;
164 if (fwrite (& this_proj -> tunit, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
165 if (this_proj -> natomes != 0 && this_proj -> nspec != 0)
166 {
167 for (i=0; i<this_proj -> nspec; i++)
168 {
169 if (save_this_string (fp, this_proj -> chemistry -> label[i]) != OK) return ERROR_PROJECT;
170 if (save_this_string (fp, this_proj -> chemistry -> element[i]) != OK) return ERROR_PROJECT;
171 }
172 if (fwrite (this_proj -> chemistry -> nsps, sizeof(int), this_proj -> nspec, fp) != this_proj -> nspec) return ERROR_PROJECT;
173 if (fwrite (this_proj -> chemistry -> formula, sizeof(int), this_proj -> nspec, fp) != this_proj -> nspec) return ERROR_PROJECT;
174 for (i=0; i<CHEM_PARAMS; i++)
175 {
176 if (fwrite (this_proj -> chemistry -> chem_prop[i], sizeof(double), this_proj -> nspec, fp) != this_proj -> nspec) return ERROR_PROJECT;
177 }
178 if (fwrite (& this_proj -> chemistry -> grtotcutoff, sizeof(double), 1, fp) != 1) return ERROR_PROJECT;
179 for (i=0; i<this_proj -> nspec; i++)
180 {
181 if (fwrite (this_proj -> chemistry -> cutoffs[i], sizeof(double), this_proj -> nspec, fp) != this_proj -> nspec) return ERROR_PROJECT;
182 }
183 for (i=0; i<this_proj -> steps; i++)
184 {
185 for (j=0; j<this_proj -> natomes; j++)
186 {
187 if (save_atom_a (fp, this_proj, i, j) != OK) return ERROR_ATOM_A;
188 }
189 }
190 if (this_proj -> run)
191 {
192 k = 0;
193 for (i=0; i<NGRAPHS; i++)
194 {
195 for (j=0; j<this_proj -> numc[i]; j++)
196 {
197 if (this_proj -> curves[i][j] -> ndata != 0)
198 {
199 k ++;
200 }
201 }
202 }
203 if (fwrite (& k, sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
204 if (k)
205 {
206 if (fwrite (& this_proj -> numc[SP], sizeof(int), 1, fp) != 1) return ERROR_PROJECT;
207 if (this_proj -> numc[SP])
208 {
209 for (i=0; i<this_proj -> numc[SP]; i++)
210 {
211 if (save_this_string (fp, this_proj -> curves[SP][i] -> name) != OK) return ERROR_PROJECT;
212 }
213 }
214 for (i=0; i< NGRAPHS; i++)
215 {
216 for (j=0; j<this_proj -> numc[i]; j++)
217 {
218 if (this_proj -> curves[i][j] -> ndata != 0)
219 {
220 if (save_project_curve (fp, npi, this_proj, i, j) != OK) return ERROR_CURVE;
221 }
222 }
223 }
224 }
225 if (this_proj -> initgl)
226 {
227 if (fwrite (& this_proj -> modelgl -> bonding, sizeof(gboolean), 1, fp) != 1) return ERROR_COORD;
228 if (fwrite (this_proj -> modelgl -> adv_bonding, sizeof(gboolean), 2, fp) != 2) return ERROR_COORD;
229 if (fwrite (this_proj -> coord -> totcoord, sizeof(int), 10, fp) != 10) return ERROR_COORD;
230 // Save molecule
231 if ((this_proj -> natomes > ATOM_LIMIT || this_proj -> steps > STEP_LIMIT) && this_proj -> modelgl -> adv_bonding[1])
232 {
233 if (save_mol (fp, this_proj) != OK) return ERROR_MOL;
234 }
235 // saving bonding info
236 if (save_bonding (fp, this_proj) != OK) return ERROR_COORD;
237 // saving glwin info
238 i = save_opengl_image (fp, this_proj, this_proj -> modelgl -> anim -> last -> img, this_proj -> nspec);
239 if (i != OK) return i;
240
241 i = save_dlp_field_data (fp, this_proj);
242 if (i != OK) return i;
243 i = save_lmp_field_data (fp, this_proj);
244 if (i != OK) return i;
245
246 for (i=0; i<2; i++)
247 {
248 j = save_cpmd_data (fp, i, this_proj);
249 if (j != OK) return j;
250 }
251 for (i=0; i<2; i++)
252 {
253 j = save_cp2k_data (fp, i, this_proj);
254 if (j != OK) return j;
255 }
256 }
257 }
258 }
259 else
260 {
261 // error
262 return ERROR_NO_WAY;
263 }
264#ifdef DEBUG
265// debugioproj (this_proj, "WRITE");
266#endif
267 return OK;
268}
integer(kind=c_int) function bonding(scf, sbf, adv, bdist, bmin, delt_ij, sfil)
Definition bonds.F90:22
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
FILE * fp
Global variable declarations Global convenience function declarations Global data structure defin...
#define ATOM_LIMIT
Atom number limit to compute fragment(s) and molecule(s) analysis automatically.
#define ERROR_RW
Definition global.h:252
#define ERROR_CURVE
Definition global.h:254
#define NGRAPHS
#define STEP_LIMIT
Definition global.h:249
#define ERROR_PROJECT
Definition global.h:253
#define CHEM_PARAMS
Definition global.h:268
#define ERROR_ATOM_A
Definition global.h:256
#define OK
Definition global.h:251
#define min(a, b)
Definition global.h:75
#define ERROR_COORD
Definition global.h:260
#define ERROR_MOL
#define SP
Definition global.h:302
#define ERROR_NO_WAY
Definition global.h:259
#define max(a, b)
Definition global.h:74
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int save_lmp_field_data(FILE *fp, project *this_proj)
save LAMMPS force field data to file
Definition save_field.c:492
int save_bonding(FILE *fp, project *this_proj)
save bonding information to file
Definition save_bond.c:50
int save_atom_a(FILE *fp, project *this_proj, int s, int a)
save atom data to file (a)
Definition save_opengl.c:54
int save_project_curve(FILE *fp, int wid, project *this_proj, int rid, int cid)
save project curve to file
Definition save_curve.c:76
int save_opengl_image(FILE *fp, project *this_proj, image *img, int sid)
save OpenGL image properties to file
int save_cp2k_data(FILE *fp, int cid, project *this_proj)
save CP2K data to file
Definition save_qm.c:180
int save_mol(FILE *fp, project *this_proj)
save molecule information to file
Definition save_mol.c:106
int save_dlp_field_data(FILE *fp, project *this_proj)
save force field data to file
Definition save_field.c:411
int save_cpmd_data(FILE *fp, int cid, project *this_proj)
save CPMD data to file
Definition save_qm.c:109
int save_this_string(FILE *fp, gchar *string)
save string to file
Definition save_p.c:49
int save_project(FILE *fp, project *this_proj, int npi)
save project to file
Definition save_p.c:84
int element
Definition w_periodic.c:61
atom_search * csearch
Definition w_search.c:2718
GtkWidget * img
Definition workspace.c:70