atomes 1.2.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_hist.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: 'read_hist.c'
24*
25* Contains:
26*
27
28 - The functions to read DL-POLY history file
29
30*
31* List of functions:
32
33 int hist_get_data (int linec);
34 int hist_get_content ();
35 int open_hist_file (int linec);
36
37*/
38
39#include "global.h"
40#include "bind.h"
41#include "interface.h"
42#include "project.h"
43#include <ctype.h>
44#include "cbuild_edit.h"
45#include "readers.h"
46#ifdef OPENMP
47# include <omp.h>
48#endif
49
50extern void check_for_species (double v, int ato);
51
59int hist_get_data (int linec)
60{
61 int i;
62 if (linec < 7) return 0;
63#ifdef OPENMP
64 this_line = g_strdup_printf ("%s", coord_line[1]);
65#else
66 line_node * tmp_line;
67 tail = head;
68 tmp_line = tail;
69 tail = tail -> next;
70 g_free (tmp_line);
71 this_line = g_strdup_printf ("%s", tail -> line);
72#endif // OPENMP
73 this_word = strtok (this_line, " ");
74 this_reader -> traj = (int)string_to_double ((gpointer)this_word);
75 this_word = strtok (NULL, " ");
76 if (! this_word)
77 {
78 add_reader_info ("Wrong file format - record <b>ii</b> line is corrupted !", 0);
79 return 0;
80 }
81 this_reader -> lattice.pbc = (int)string_to_double ((gpointer)this_word);
82 this_word = strtok (NULL, " ");
83 if (! this_word)
84 {
85 add_reader_info ("Wrong file format - record <b>ii</b> line is corrupted !", 0);
86 return 0;
87 }
88 this_reader -> natomes = (int)string_to_double ((gpointer)this_word);
89 i = linec - 2;
90 if (i%(4 + (2+this_reader -> traj)*this_reader -> natomes)) return 0;
91 this_reader -> steps = i/(4 + (2+this_reader -> traj)*this_reader -> natomes);
92 return 1;
93}
94
101{
102 gchar * lil[3] = {"ii", "iii", "iv"};
103 int i, j, k, l;
104 double v;
105 this_reader -> nspec = 0;
106 active_project -> steps = this_reader -> steps;
107 active_project -> natomes = this_reader -> natomes;
109 this_reader -> z = allocdouble (1);
110 this_reader -> nsps = allocint (1);
111 this_reader -> lattice.box = g_malloc0(this_reader -> steps*sizeof*this_reader -> lattice.box);
112 int res = 1;
113#ifdef OPENMP
114 int numth = omp_get_max_threads ();
115 gboolean doatoms = FALSE;
116 gchar * saved_line;
117 if (this_reader -> steps < numth)
118 {
119 if (numth >= 2*(this_reader -> steps-1))
120 {
121 doatoms = TRUE;
122 }
123 else
124 {
125 numth = this_reader -> steps;
126 }
127 }
128 if (doatoms)
129 {
130 // OpenMP on atoms
131 for (i=0; i<this_reader -> steps; i++)
132 {
133 k = 3 + i*(this_reader -> natomes*(2+this_reader -> traj) + 4);
134 for (j=0; j<3; j++)
135 {
136 this_line = g_strdup_printf ("%s", coord_line[k+j]);
137 this_word = strtok_r (this_line, " ", & saved_line);
138 for (l=0; l<3; l++)
139 {
140 if (! this_word)
141 {
142 format_error (i+1, -1, lil[l], k+j);
143 return 0;
144 }
145 this_reader -> lattice.box[i].vect[j][l] = string_to_double ((gpointer)this_word);
146 this_word = strtok_r (NULL, " ", & saved_line);
147 }
148 }
149 k += 3;
150 #pragma omp parallel for num_threads(numth) private(j,l,v,this_line,saved_line,this_word) shared(i,k,lil,coord_line,this_reader,active_project,res)
151 for (j=0; j<this_reader -> natomes; j++)
152 {
153 if (res == 2) goto enda;
154 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)]);
155 this_word = strtok_r (this_line, " ", & saved_line);
156 for (l=0; l<3; l++)
157 {
158 if (! this_word)
159 {
160 format_error (i+1, j+1, lil[l], k+j*(2+this_reader -> traj));
161 res = 0;
162 goto enda;
163 }
164 if (l < 2) this_word = strtok_r (NULL, " ", & saved_line);
165 }
166 v = string_to_double ((gpointer)this_word);
167 if (v > 0.0)
168 {
169 if (! i)
170 {
171 #pragma omp critical
172 check_for_species (v, j);
173 }
174 g_free (this_line);
175 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)+1]);
176 this_word = strtok_r (this_line, " ", & saved_line);
177 if (! this_word)
178 {
179 format_error (i+1, j+1, lil[0], k+j*(2+this_reader -> traj));
180 res = 0;
181 goto enda;
182 }
183 active_project -> atoms[i][j].x = string_to_double ((gpointer)this_word);
184 this_word = strtok_r (NULL, " ", & saved_line);
185 if (! this_word)
186 {
187 format_error (i+1, j+1, lil[1], k+j*(2+this_reader -> traj));
188 res = 0;
189 goto enda;
190 }
191 active_project -> atoms[i][j].y = string_to_double ((gpointer)this_word);
192 this_word = strtok_r (NULL, " ", & saved_line);
193 if (! this_word)
194 {
195 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj));
196 res = 0;
197 goto enda;
198 }
199 active_project -> atoms[i][j].z = string_to_double ((gpointer)this_word);
200 }
201 else
202 {
203 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj));
204 res = 0;
205 goto enda;
206 }
207 g_free (this_line);
208 enda:;
209 }
210 if (res == 0) break;
211 }
212 }
213 else
214 {
215 // OpenMP on MD steps
216 #pragma omp parallel for num_threads(numth) private(i,j,k,l,v,this_line,saved_line,this_word) shared(lil,coord_line,this_reader,active_project,res)
217 for (i=0; i<this_reader -> steps; i++)
218 {
219 if (! res) goto ends;
220 k = 3 + i*(this_reader -> natomes*(2+this_reader -> traj)+4);
221 for (j=0; j<3; j++)
222 {
223 this_line = g_strdup_printf ("%s", coord_line[k+j]);
224 this_word = strtok_r (this_line, " ", & saved_line);
225 for (l=0; l<3; l++)
226 {
227 if (! this_word)
228 {
229 format_error (i+1, -1, lil[l], k+j);
230 res = 0;
231 goto ends;
232 }
233 this_reader -> lattice.box[i].vect[j][l] = string_to_double ((gpointer)this_word);
234 this_word = strtok_r (NULL, " ", & saved_line);
235 }
236 }
237 k += 3;
238 for (j=0; j<this_reader -> natomes; j++)
239 {
240 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)]);
241 this_word = strtok_r (this_line, " ", & saved_line);
242 for (l=0; l<3; l++)
243 {
244 if (! this_word)
245 {
246 format_error (i+1, j+1, lil[l], k+j*(2+this_reader -> traj));
247 res = 0;
248 goto ends;
249 }
250 if (l < 2) this_word = strtok_r (NULL, " ", & saved_line);
251 }
252 v = string_to_double ((gpointer)this_word);
253 if (v > 0.0)
254 {
255 if (! i) check_for_species (v, j);
256 g_free (this_line);
257 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)+1]);
258 this_word = strtok_r (this_line, " ", & saved_line);
259 if (! this_word)
260 {
261 format_error (i+1, j+1, lil[0], k+j*(2+this_reader -> traj)+1);
262 res = 0;
263 goto ends;
264 }
265 active_project -> atoms[i][j].x = string_to_double ((gpointer)this_word);
266 this_word = strtok_r (NULL, " ", & saved_line);
267 if (! this_word)
268 {
269 format_error (i+1, j+1, lil[1], k+j*(2+this_reader -> traj)+1);
270 res = 0;
271 goto ends;
272 }
273 active_project -> atoms[i][j].y = string_to_double ((gpointer)this_word);
274 this_word = strtok_r (NULL, " ", & saved_line);
275 if (! this_word)
276 {
277 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj)+1);
278 res = 0;
279 goto ends;
280 }
281 active_project -> atoms[i][j].z = string_to_double ((gpointer)this_word);
282 }
283 else
284 {
285 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj));
286 res = 0;
287 goto ends;
288 }
289 g_free (this_line);
290 }
291 ends:;
292 }
293 }
294#else
295 line_node * tmp_line;
296 tmp_line = tail;
297 tail = tail -> next;
298 g_free (tmp_line);
299 for (i=0; i<this_reader -> steps; i++)
300 {
301 tmp_line = tail;
302 tail = tail -> next;
303 g_free (tmp_line);
304 k = 3 + i*(this_reader -> natomes*(2+this_reader -> traj) + 4);
305 for (j=0; j<3; j++)
306 {
307 this_line = g_strdup_printf ("%s", tail -> line);
308 this_word = strtok (this_line, " ");
309 for (l=0; l<3; l++)
310 {
311 if (! this_word)
312 {
313 format_error (i+1, -1, lil[l], k+j);
314 return 0;
315 }
316 this_reader -> lattice.box[i].vect[j][l] = string_to_double ((gpointer)this_word);
317 this_word = strtok (NULL, " ");
318 }
319 tmp_line = tail;
320 tail = tail -> next;
321 g_free (tmp_line);
322 }
323 k += 3;
324 for (j=0; j<this_reader -> natomes; j++)
325 {
326 this_line = g_strdup_printf ("%s", tail -> line);
327 this_word = strtok (this_line, " ");
328 for (l=0; l<3; l++)
329 {
330 if (! this_word)
331 {
332 format_error (i+1, j+1, lil[l], k+2*j);
333 return 0;
334 }
335 if (l < 2) this_word = strtok (NULL, " ");
336 }
337 v = string_to_double ((gpointer)this_word);
338 if (v > 0.0)
339 {
340 if (! i) check_for_species (v, j);
341 tmp_line = tail;
342 tail = tail -> next;
343 g_free (tmp_line);
344 this_line = g_strdup_printf ("%s", tail -> line);
345 this_word = strtok (this_line, " ");
346 if (! this_word)
347 {
348 format_error (i+1, j+1, lil[0], k+2*j+1);
349 return 0;
350 }
351 active_project -> atoms[i][j].x = string_to_double ((gpointer)this_word);
352 this_word = strtok (NULL, " ");
353 if (! this_word)
354 {
355 format_error (i+1, j+1, lil[1], k+2*j+1);
356 return 0;
357 }
358 active_project -> atoms[i][j].y = string_to_double ((gpointer)this_word);
359 this_word = strtok (NULL, " ");
360 if (! this_word)
361 {
362 format_error (i+1, j+1, lil[2], k+2*j+1);
363 return 0;
364 }
365 active_project -> atoms[i][j].z = string_to_double ((gpointer)this_word);
366 }
367 else
368 {
369 format_error (i+1, j+1, lil[l], k+2*j+1);
370 return 0;
371 }
372 tmp_line = tail;
373 tail = tail -> next;
374 g_free (tmp_line);
375 }
376 }
377#endif
378 if (! res) return res;
379 gboolean add_spec;
380 for (i=0; i<this_reader -> nspec; i++)
381 {
382 add_spec = FALSE;
383 for (j=1; j<120; j++)
384 {
385 if (fabs(periodic_table_info[j].M - this_reader -> z[i]) < 0.1)
386 {
387 this_reader -> z[i] = (float)j;
388 add_spec = TRUE;
389 break;
390 }
391 }
392 if (! add_spec)
393 {
394 gchar * str = g_strdup_printf ("Cannot find species with a mass of %f !", this_reader -> z[i]);
395 add_reader_info (str, 0);
396 g_free (str);
397 return 0;
398 }
399 }
400 for (i=1; i<active_project -> steps; i++)
401 {
402 for (j=0; j<active_project -> natomes; j++)
403 {
404 active_project -> atoms[i][j].sp = active_project -> atoms[0][j].sp;
405 }
406 }
407 this_reader -> lattice.npt = FALSE;
408 for (i=1; i<this_reader -> steps; i++)
409 {
410 for (j=0; j<3; j++)
411 {
412 for (k=0; k<3; k++)
413 {
414 if (this_reader -> lattice.box[i].vect[j][k] != this_reader -> lattice.box[0].vect[j][k])
415 {
416 this_reader -> lattice.npt = TRUE;
417 break;
418 }
419 }
420 if (this_reader -> lattice.npt) break;
421 }
422 if (this_reader -> lattice.npt) break;
423 }
424 return 1;
425}
426
434int open_hist_file (int linec)
435{
436 int res;
437 int i, j, k, l;
438 if (hist_get_data(linec))
439 {
440 reader_info ("hist", "Number of atoms", this_reader -> natomes);
441 reader_info ("hist", "Number of steps", this_reader -> steps);
442 if (hist_get_content())
443 {
444 active_cell -> ltype = 2;
445 active_cell -> pbc = this_reader -> lattice.pbc;
446 active_cell -> npt = this_reader -> lattice.npt;
447 i = (active_cell -> npt) ? this_reader -> steps : 1;
448 if (active_cell -> npt)
449 {
450 g_free (active_cell -> box);
451 active_cell -> box = g_malloc0(i*sizeof*active_cell -> box);
452 active_box = & active_cell -> box[0];
453 }
454 for (j=0; j<i; j++)
455 {
456 for (k=0; k<3; k++)
457 {
458 for (l=0; l<3; l++)
459 {
460 active_cell -> box[j].vect[k][l] = this_reader -> lattice.box[j].vect[k][l];
461 }
462 }
463 }
464 active_cell -> has_a_box = TRUE;
465 active_cell -> crystal = FALSE;
466 res = 0;
467 }
468 else
469 {
470 // Content error
471 res = 2;
472 }
473 }
474 else
475 {
476 // Data error
477 res = 2;
478 }
479 return res;
480}
Binding to the Fortran90 subroutines.
Function declarations for the crystal builder.
void allocatoms(project *this_proj)
allocate project data
Definition open_p.c:163
int atoms[NUM_STYLES][2]
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:459
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
double string_to_double(gpointer string)
convert string to double
Definition global.c:624
Global variable declarations Global convenience function declarations Global data structure defin...
cell_info * active_cell
Definition project.c:50
element_data periodic_table_info[]
Definition w_library.c:71
box_info * active_box
Definition project.c:51
project * active_project
Definition project.c:47
Messaging function declarations.
integer(kind=c_int) function lattice(totl, lid, vectors, vmod, angles, lat, cfrac, apbc)
Definition lattice.F90:162
double z
Definition ogl_draw.c:61
Function declarations for reading atomes project file Function declarations for saving atomes proje...
line_node * head
Definition read_coord.c:77
gchar ** coord_line
Definition read_coord.c:74
coord_file * this_reader
Definition read_coord.c:73
void reader_info(gchar *type, gchar *sinf, int val)
display reader information
Definition read_coord.c:125
line_node * tail
Definition read_coord.c:78
void add_reader_info(gchar *info, int mid)
append information message to the reader information
Definition read_coord.c:88
char * this_word
Definition read_coord.c:76
void format_error(int stp, int ato, gchar *mot, int line)
Message to display an error message.
Definition read_coord.c:140
gchar * this_line
Definition read_coord.c:75
int hist_get_content()
read the content of the DL-POLY history file
Definition read_hist.c:100
int open_hist_file(int linec)
open DL-POLY history file
Definition read_hist.c:434
void check_for_species(double v, int ato)
Fill the species for each atom and the associated data.
Definition read_coord.c:220
int hist_get_data(int linec)
read data from the DL-POLY history file
Definition read_hist.c:59
Functions declaration to read atomic coordinates.
Definition glwin.h:351
GtkWidget * res[2]
Definition w_encode.c:212