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