atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_trj.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_trj.c'
24*
25* Contains:
26*
27
28 - The functions to read CPMD atomic coordinates
29
30*
31* List of functions:
32
33 int trj_get_atom_coordinates ();
34 int open_trj_file (int linec);
35
36*/
37
38#include "global.h"
39#include "glview.h"
40#include "callbacks.h"
41#include "interface.h"
42#include "project.h"
43#include "bind.h"
44#include <omp.h>
45#include "readers.h"
46
53{
54 int i, j, k, l;
55 gchar * lia[4] = {"a", "b", "c", "d"};
57#ifdef OPENMP
58 int res;
59 int numth = omp_get_max_threads ();
60 gboolean doatoms = FALSE;
61 gchar * saved_line;
62 if (active_project -> steps < numth)
63 {
64 if (numth >= 2*(active_project -> steps-1))
65 {
66 doatoms = TRUE;
67 }
68 else
69 {
70 numth = active_project -> steps;
71 }
72 }
73 if (doatoms)
74 {
75 // OpenMP on atoms
76 res = 0;
77 for (i=0; i<active_project -> steps; i++)
78 {
79 k = i*active_project -> natomes;
80 #pragma omp parallel for num_threads(numth) private(j,this_line,saved_line,this_word) shared(i,k,lia,coord_line,active_project,res)
81 for (j=0; j<active_project -> natomes; j++)
82 {
83 if (res == 2) goto enda;
84 this_line = g_strdup_printf ("%s", coord_line[k+j]);
85 saved_line = g_strdup_printf ("%s", this_line);
86 this_word = strtok_r (this_line, " ", & saved_line);
87 if (! this_word)
88 {
89 format_error (i+1, j+1, lia[0], k+j);
90 res = 2;
91 goto enda;
92 }
93 this_word = strtok_r (NULL, " ", & saved_line);
94 if (! this_word)
95 {
96 format_error (i+1, j+1, lia[1], k+j);
97 res = 2;
98 goto enda;
99 }
100 active_project -> atoms[i][j].x = atof(this_word);
101 this_word = strtok_r (NULL, " ", & saved_line);
102 if (! this_word)
103 {
104 format_error (i+1, j+1, lia[2], k+j);
105 res = 2;
106 goto enda;
107 }
108 active_project -> atoms[i][j].y = atof(this_word);
109 this_word = strtok_r (NULL, " ", & saved_line);
110 if (! this_word)
111 {
112 format_error (i+1, j+1, lia[3], k+j);
113 res = 2;
114 goto enda;
115 }
116 active_project -> atoms[i][j].z = atof(this_word);
117 g_free (this_line);
118 enda:;
119 }
120 if (res == 2) break;
121 }
122 }
123 else
124 {
125 res = 0;
126 #pragma omp parallel for num_threads(numth) private(i,j,k,this_line,saved_line,this_word) shared(lia,coord_line,active_project,res)
127 for (i=0; i<active_project -> steps; i++)
128 {
129 if (res == 2) goto ends;
130 k = i*active_project -> natomes;
131 for (j=0; j<active_project -> natomes; j++)
132 {
133 this_line = g_strdup_printf ("%s", coord_line[k+j]);
134 saved_line = g_strdup_printf ("%s", this_line);
135 this_word = strtok_r (this_line, " ", & saved_line);
136 if (! this_word)
137 {
138 format_error (i+1, j+1, lia[0], k+j);
139 res = 2;
140 goto ends;
141 }
142 this_word = strtok_r (NULL, " ", & saved_line);
143 if (! this_word)
144 {
145 format_error (i+1, j+1, lia[1], k+j);
146 res = 2;
147 goto ends;
148 }
149 active_project -> atoms[i][j].x = atof(this_word) * 0.52917721;
150 this_word = strtok_r (NULL, " ", & saved_line);
151 if (! this_word)
152 {
153 format_error (i+1, j+1, lia[2], k+j);
154 res = 2;
155 goto ends;
156 }
157 active_project -> atoms[i][j].y = atof(this_word) * 0.52917721;
158 this_word = strtok_r (NULL, " ", & saved_line);
159 if (! this_word)
160 {
161 format_error (i+1, j+1, lia[3], k+j);
162 res = 2;
163 goto ends;
164 }
165 active_project -> atoms[i][j].z = atof(this_word) * 0.52917721;
166 g_free (this_line);
167 }
168 ends:;
169 }
170 }
171 g_free (coord_line);
172 if (res == 2) return 2;
173 for (i=1; i<active_project -> steps; i++)
174 {
175 for (j=0; j<active_project -> natomes; j++)
176 {
177 if (active_project -> atoms[i-1][j].sp != active_project -> atoms[i][j].sp)
178 {
179 add_reader_info (g_strdup_printf ("Error - chemical species changes between steps %d and %d, for atom %d !", i, i+1, j+1), 0);
180 return 2;
181 }
182 }
183 }
184#else
185 line_node * tmp_line;
186 tail = head;
187 k = 0;
188 for (i=0; i<active_project -> steps; i++)
189 {
190 for (j=0; j<active_project -> natomes; j++)
191 {
192 this_line = g_strdup_printf ("%s", tail -> line);
193 this_word = strtok (this_line, " ");
194 if (! this_word)
195 {
196 format_error (i+1, j+1, lia[0], k);
197 return 2;
198 }
199 this_word = strtok (NULL, " ");
200 if (! this_word)
201 {
202 format_error (i+1, j+1, lia[1], k);
203 return 2;
204 }
205 active_project -> atoms[i][j].x = atof(this_word) * 0.52917721;
206 this_word = strtok (NULL, " ");
207 if (! this_word)
208 {
209 format_error (i+1, j+1, lia[2], k);
210 return 2;
211 }
212 active_project -> atoms[i][j].y = atof(this_word) * 0.52917721;
213 this_word = strtok (NULL, " ");
214 if (! this_word)
215 {
216 format_error (i+1, j+1, lia[3], k);
217 return 2;
218 }
219 active_project -> atoms[i][j].z = atof(this_word) * 0.52917721;
220 tmp_line = tail;
221 tail = tail -> next;
222 g_free (tmp_line);
223 k ++;
224 }
225 }
226#endif
227 i = 0;
228 for (j=0; j<this_reader -> nspec; j++)
229 {
230 for (k=0; k<this_reader -> nsps[j]; k++)
231 {
232 for (l=0; l<active_project -> steps; l++)
233 {
234 active_project -> atoms[l][i].sp = j;
235 }
236 i ++;
237 }
238 }
239 return 0;
240}
241
249int open_trj_file (int linec)
250{
251 if (linec%(this_reader -> natomes) != 0) return 2;
252 reader_info ("trj", "Number of atoms", this_reader -> natomes);
253 active_project -> steps = linec / this_reader -> natomes;
254 reader_info ("trj", "Number of steps", active_project -> steps);
255 active_project -> natomes = this_reader -> natomes;
256 return trj_get_atom_coordinates ();
257}
Binding to the Fortran90 subroutines.
Callback declarations for main window.
void allocatoms(project *this_proj)
allocate project data
Definition open_p.c:160
int atoms[NUM_STYLES][2]
Global variable declarations Global convenience function declarations Global data structure defin...
project * active_project
Definition project.c:47
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
Messaging function declarations.
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 open_trj_file(int linec)
open CPMD file
Definition read_trj.c:249
int trj_get_atom_coordinates()
get the atomic coordinates from the CPMD file
Definition read_trj.c:52
Functions declaration to read atomic coordinates.
GtkWidget * res[2]
Definition w_encode.c:212