atomes 1.1.15
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#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 saved_line = g_strdup_printf ("%s", this_line);
138 this_word = strtok_r (this_line, " ", & saved_line);
139 for (l=0; l<3; l++)
140 {
141 if (! this_word)
142 {
143 format_error (i+1, -1, lil[l], k+j);
144 return 0;
145 }
146 this_reader -> lattice.box[i].vect[j][l] = string_to_double ((gpointer)this_word);
147 this_word = strtok_r (NULL, " ", & saved_line);
148 }
149 }
150 k += 3;
151 #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)
152 for (j=0; j<this_reader -> natomes; j++)
153 {
154 if (res == 2) goto enda;
155 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)]);
156 saved_line = g_strdup_printf ("%s", this_line);
157 this_word = strtok_r (this_line, " ", & saved_line);
158 for (l=0; l<3; l++)
159 {
160 if (! this_word)
161 {
162 format_error (i+1, j+1, lil[l], k+j*(2+this_reader -> traj));
163 res = 0;
164 goto enda;
165 }
166 if (l < 2) this_word = strtok_r (NULL, " ", & saved_line);
167 }
168 v = string_to_double ((gpointer)this_word);
169 if (v > 0.0)
170 {
171 if (! i)
172 {
173 #pragma omp critical
174 check_for_species (v, j);
175 }
176 g_free (this_line);
177 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)+1]);
178 saved_line = g_strdup_printf ("%s", this_line);
179 this_word = strtok_r (this_line, " ", & saved_line);
180 if (! this_word)
181 {
182 format_error (i+1, j+1, lil[0], k+j*(2+this_reader -> traj));
183 res = 0;
184 goto enda;
185 }
186 active_project -> atoms[i][j].x = string_to_double ((gpointer)this_word);
187 this_word = strtok_r (NULL, " ", & saved_line);
188 if (! this_word)
189 {
190 format_error (i+1, j+1, lil[1], k+j*(2+this_reader -> traj));
191 res = 0;
192 goto enda;
193 }
194 active_project -> atoms[i][j].y = string_to_double ((gpointer)this_word);
195 this_word = strtok_r (NULL, " ", & saved_line);
196 if (! this_word)
197 {
198 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj));
199 res = 0;
200 goto enda;
201 }
202 active_project -> atoms[i][j].z = string_to_double ((gpointer)this_word);
203 }
204 else
205 {
206 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj));
207 res = 0;
208 goto enda;
209 }
210 g_free (this_line);
211 enda:;
212 }
213 if (res == 0) break;
214 }
215 }
216 else
217 {
218 // OpenMP on MD steps
219 #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)
220 for (i=0; i<this_reader -> steps; i++)
221 {
222 if (! res) goto ends;
223 k = 3 + i*(this_reader -> natomes*(2+this_reader -> traj)+4);
224 for (j=0; j<3; j++)
225 {
226 this_line = g_strdup_printf ("%s", coord_line[k+j]);
227 saved_line = g_strdup_printf ("%s", this_line);
228 this_word = strtok_r (this_line, " ", & saved_line);
229 for (l=0; l<3; l++)
230 {
231 if (! this_word)
232 {
233 format_error (i+1, -1, lil[l], k+j);
234 res = 0;
235 goto ends;
236 }
237 this_reader -> lattice.box[i].vect[j][l] = string_to_double ((gpointer)this_word);
238 this_word = strtok_r (NULL, " ", & saved_line);
239 }
240 }
241 k += 3;
242 for (j=0; j<this_reader -> natomes; j++)
243 {
244 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)]);
245 saved_line = g_strdup_printf ("%s", this_line);
246 this_word = strtok_r (this_line, " ", & saved_line);
247 for (l=0; l<3; l++)
248 {
249 if (! this_word)
250 {
251 format_error (i+1, j+1, lil[l], k+j*(2+this_reader -> traj));
252 res = 0;
253 goto ends;
254 }
255 if (l < 2) this_word = strtok_r (NULL, " ", & saved_line);
256 }
257 v = string_to_double ((gpointer)this_word);
258 if (v > 0.0)
259 {
260 if (! i) check_for_species (v, j);
261 g_free (this_line);
262 this_line = g_strdup_printf ("%s", coord_line[k+j*(2+this_reader -> traj)+1]);
263 saved_line = g_strdup_printf ("%s", this_line);
264 this_word = strtok_r (this_line, " ", & saved_line);
265 if (! this_word)
266 {
267 format_error (i+1, j+1, lil[0], k+j*(2+this_reader -> traj)+1);
268 res = 0;
269 goto ends;
270 }
271 active_project -> atoms[i][j].x = string_to_double ((gpointer)this_word);
272 this_word = strtok_r (NULL, " ", & saved_line);
273 if (! this_word)
274 {
275 format_error (i+1, j+1, lil[1], k+j*(2+this_reader -> traj)+1);
276 res = 0;
277 goto ends;
278 }
279 active_project -> atoms[i][j].y = string_to_double ((gpointer)this_word);
280 this_word = strtok_r (NULL, " ", & saved_line);
281 if (! this_word)
282 {
283 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj)+1);
284 res = 0;
285 goto ends;
286 }
287 active_project -> atoms[i][j].z = string_to_double ((gpointer)this_word);
288 }
289 else
290 {
291 format_error (i+1, j+1, lil[2], k+j*(2+this_reader -> traj));
292 res = 0;
293 goto ends;
294 }
295 g_free (this_line);
296 }
297 ends:;
298 }
299 }
300#else
301 line_node * tmp_line;
302 tmp_line = tail;
303 tail = tail -> next;
304 g_free (tmp_line);
305 for (i=0; i<this_reader -> steps; i++)
306 {
307 tmp_line = tail;
308 tail = tail -> next;
309 g_free (tmp_line);
310 k = 3 + i*(this_reader -> natomes*(2+this_reader -> traj) + 4);
311 for (j=0; j<3; j++)
312 {
313 this_line = g_strdup_printf ("%s", tail -> line);
314 this_word = strtok (this_line, " ");
315 for (l=0; l<3; l++)
316 {
317 if (! this_word)
318 {
319 format_error (i+1, -1, lil[l], k+j);
320 return 0;
321 }
322 this_reader -> lattice.box[i].vect[j][l] = string_to_double ((gpointer)this_word);
323 this_word = strtok (NULL, " ");
324 }
325 tmp_line = tail;
326 tail = tail -> next;
327 g_free (tmp_line);
328 }
329 k += 3;
330 for (j=0; j<this_reader -> natomes; j++)
331 {
332 this_line = g_strdup_printf ("%s", tail -> line);
333 this_word = strtok (this_line, " ");
334 for (l=0; l<3; l++)
335 {
336 if (! this_word)
337 {
338 format_error (i+1, j+1, lil[l], k+2*j);
339 return 0;
340 }
341 if (l < 2) this_word = strtok (NULL, " ");
342 }
343 v = string_to_double ((gpointer)this_word);
344 if (v > 0.0)
345 {
346 if (! i) check_for_species (v, j);
347 tmp_line = tail;
348 tail = tail -> next;
349 g_free (tmp_line);
350 this_line = g_strdup_printf ("%s", tail -> line);
351 this_word = strtok (this_line, " ");
352 if (! this_word)
353 {
354 format_error (i+1, j+1, lil[0], k+2*j+1);
355 return 0;
356 }
357 active_project -> atoms[i][j].x = string_to_double ((gpointer)this_word);
358 this_word = strtok (NULL, " ");
359 if (! this_word)
360 {
361 format_error (i+1, j+1, lil[1], k+2*j+1);
362 return 0;
363 }
364 active_project -> atoms[i][j].y = string_to_double ((gpointer)this_word);
365 this_word = strtok (NULL, " ");
366 if (! this_word)
367 {
368 format_error (i+1, j+1, lil[2], k+2*j+1);
369 return 0;
370 }
371 active_project -> atoms[i][j].z = string_to_double ((gpointer)this_word);
372 }
373 else
374 {
375 format_error (i+1, j+1, lil[l], k+2*j+1);
376 return 0;
377 }
378 tmp_line = tail;
379 tail = tail -> next;
380 g_free (tmp_line);
381 }
382 }
383#endif
384 if (! res) return res;
385 gboolean add_spec;
386 for (i=0; i<this_reader -> nspec; i++)
387 {
388 add_spec = FALSE;
389 for (j=1; j<120; j++)
390 {
391 if (fabs(periodic_table_info[j].M - this_reader -> z[i]) < 0.1)
392 {
393 this_reader -> z[i] = (float)j;
394 add_spec = TRUE;
395 break;
396 }
397 }
398 if (! add_spec)
399 {
400 gchar * str = g_strdup_printf ("Cannot find species with a mass of %f !", this_reader -> z[i]);
401 add_reader_info (str, 0);
402 g_free (str);
403 return 0;
404 }
405 }
406 for (i=1; i<active_project -> steps; i++)
407 {
408 for (j=0; j<active_project -> natomes; j++)
409 {
410 active_project -> atoms[i][j].sp = active_project -> atoms[0][j].sp;
411 }
412 }
413 this_reader -> lattice.npt = FALSE;
414 for (i=1; i<this_reader -> steps; i++)
415 {
416 for (j=0; j<3; j++)
417 {
418 for (k=0; k<3; k++)
419 {
420 if (this_reader -> lattice.box[i].vect[j][k] != this_reader -> lattice.box[0].vect[j][k])
421 {
422 this_reader -> lattice.npt = TRUE;
423 break;
424 }
425 }
426 if (this_reader -> lattice.npt) break;
427 }
428 if (this_reader -> lattice.npt) break;
429 }
430 return 1;
431}
432
440int open_hist_file (int linec)
441{
442 int res;
443 int i, j, k, l;
444 if (hist_get_data(linec))
445 {
446 reader_info ("hist", "Number of atoms", this_reader -> natomes);
447 reader_info ("hist", "Number of steps", this_reader -> steps);
448 if (hist_get_content())
449 {
450 active_cell -> ltype = 2;
451 active_cell -> pbc = this_reader -> lattice.pbc;
452 active_cell -> npt = this_reader -> lattice.npt;
453 i = (active_cell -> npt) ? this_reader -> steps : 1;
454 if (active_cell -> npt)
455 {
456 g_free (active_cell -> box);
457 active_cell -> box = g_malloc0(i*sizeof*active_cell -> box);
458 active_box = & active_cell -> box[0];
459 }
460 for (j=0; j<i; j++)
461 {
462 for (k=0; k<3; k++)
463 {
464 for (l=0; l<3; l++)
465 {
466 active_cell -> box[j].vect[k][l] = this_reader -> lattice.box[j].vect[k][l];
467 }
468 }
469 }
470 active_cell -> has_a_box = TRUE;
471 active_cell -> crystal = FALSE;
472 res = 0;
473 }
474 else
475 {
476 // Content error
477 res = 2;
478 }
479 }
480 else
481 {
482 // Data error
483 res = 2;
484 }
485 return res;
486}
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: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:57
Function declarations for reading atomes project file Function declarations for saving atomes proje...
line_node * head
Definition read_coord.c:75
gchar ** coord_line
Definition read_coord.c:72
coord_file * this_reader
Definition read_coord.c:71
void reader_info(gchar *type, gchar *sinf, int val)
display reader information
Definition read_coord.c:101
line_node * tail
Definition read_coord.c:76
void add_reader_info(gchar *info, int mid)
append information message to the reader information
Definition read_coord.c:86
char * this_word
Definition read_coord.c:74
void format_error(int stp, int ato, gchar *mot, int line)
Message to display an error message.
Definition read_coord.c:116
gchar * this_line
Definition read_coord.c:73
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:440
void check_for_species(double v, int ato)
Fill the species for each atom and the associated data.
Definition read_coord.c:196
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.
GtkWidget * res[2]
Definition w_encode.c:212