atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_vas.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_vas.c'
24*
25* Contains:
26*
27
28 - The functions to read VASP atomic coordinates
29
30*
31* List of functions:
32
33 int vas_get_atom_coordinates (int sli);
34 int open_vas_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
55{
56 int i, j, k, l;
57 gchar * lia[4] = {"a", "b", "c", "d"};
59#ifdef OPENMP
60 int res;
61 int numth = omp_get_max_threads ();
62 gboolean doatoms = FALSE;
63 gchar * saved_line;
64 if (active_project -> steps < numth)
65 {
66 if (numth >= 2*(active_project -> steps-1))
67 {
68 doatoms = TRUE;
69 }
70 else
71 {
72 numth = active_project -> steps;
73 }
74 }
75 if (doatoms)
76 {
77 // OpenMP on atoms
78 res = 0;
79 for (i=0; i<active_project -> steps; i++)
80 {
81 k = 1 + i*(active_project -> natomes + 1) + sli;
82 #pragma omp parallel for num_threads(numth) private(j,this_line,saved_line,this_word) shared(i,k,lia,coord_line,active_project,res)
83 for (j=0; j<active_project -> natomes; j++)
84 {
85 if (res == 2) goto enda;
86 this_line = g_strdup_printf ("%s", coord_line[k+j]);
87 saved_line = g_strdup_printf ("%s", this_line);
88 this_word = strtok_r (this_line, " ", & saved_line);
89 if (! this_word)
90 {
91 format_error (i+1, j+1, lia[0], k+j);
92 res = 2;
93 goto enda;
94 }
95 active_project -> atoms[i][j].x = atof(this_word);
96 this_word = strtok_r (NULL, " ", & saved_line);
97 if (! this_word)
98 {
99 format_error (i+1, j+1, lia[1], k+j);
100 res = 2;
101 goto enda;
102 }
103 active_project -> atoms[i][j].y = atof(this_word);
104 this_word = strtok_r (NULL, " ", & saved_line);
105 if (! this_word)
106 {
107 format_error (i+1, j+1, lia[2], k+j);
108 res = 2;
109 goto enda;
110 }
111 active_project -> atoms[i][j].z = atof(this_word);
112 g_free (this_line);
113 enda:;
114 }
115 if (res == 2) break;
116 }
117 }
118 else
119 {
120 res = 0;
121 #pragma omp parallel for num_threads(numth) private(i,j,k,this_line,saved_line,this_word) shared(lia,coord_line,active_project,res)
122 for (i=0; i<active_project -> steps; i++)
123 {
124 if (res == 2) goto ends;
125 k = 1 + i*(active_project -> natomes + 1) + sli;
126 for (j=0; j<active_project -> natomes; j++)
127 {
128 this_line = g_strdup_printf ("%s", coord_line[k+j]);
129 saved_line = g_strdup_printf ("%s", this_line);
130 this_word = strtok_r (this_line, " ", & saved_line);
131 if (! this_word)
132 {
133 format_error (i+1, j+1, lia[0], k+j);
134 res = 2;
135 goto ends;
136 }
137 active_project -> atoms[i][j].x = atof(this_word);
138 this_word = strtok_r (NULL, " ", & saved_line);
139 if (! this_word)
140 {
141 format_error (i+1, j+1, lia[1], k+j);
142 res = 2;
143 goto ends;
144 }
145 active_project -> atoms[i][j].y = atof(this_word);
146 this_word = strtok_r (NULL, " ", & saved_line);
147 if (! this_word)
148 {
149 format_error (i+1, j+1, lia[2], k+j);
150 res = 2;
151 goto ends;
152 }
153 active_project -> atoms[i][j].z = atof(this_word);
154 g_free (this_line);
155 }
156 ends:;
157 }
158 }
159 g_free (coord_line);
160 if (res == 2) return 2;
161 for (i=1; i<active_project -> steps; i++)
162 {
163 for (j=0; j<active_project -> natomes; j++)
164 {
165 if (active_project -> atoms[i-1][j].sp != active_project -> atoms[i][j].sp)
166 {
167 add_reader_info (g_strdup_printf ("Error - chemical species changes between steps %d and %d, for atom %d !", i, i+1, j+1), 0);
168 return 2;
169 }
170 }
171 }
172#else
173 line_node * tmp_line;
174 tail = head;
175 k = 0;
176 for (i=0; i<sli; i++)
177 {
178 tmp_line = tail;
179 tail = tail -> next;
180 g_free (tmp_line);
181 k ++;
182 }
183 for (i=0; i<active_project -> steps; i++)
184 {
185 tmp_line = tail;
186 tail = tail -> next;
187 g_free (tmp_line);
188 k ++;
189 for (j=0; j<active_project -> natomes; j++)
190 {
191 this_line = g_strdup_printf ("%s", tail -> line);
192 this_word = strtok (this_line, " ");
193 if (! this_word)
194 {
195 format_error (i+1, j+1, lia[0], k);
196 return 2;
197 }
198 active_project -> atoms[i][j].x = atof(this_word);
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].y = atof(this_word);
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].z = atof(this_word);
213 tmp_line = tail;
214 tail = tail -> next;
215 g_free (tmp_line);
216 k ++;
217 }
218 }
219#endif
220 i = 0;
221 for (j=0; j<this_reader -> nspec; j++)
222 {
223 for (k=0; k<this_reader -> nsps[j]; k++)
224 {
225 for (l=0; l<active_project -> steps; l++)
226 {
227 active_project -> atoms[l][i].sp = j;
228 }
229 i ++;
230 }
231 }
232 return 0;
233}
234
242int open_vas_file (int linec)
243{
244 int i, j;
245 j = 0;
246 for (i=5; i<8; i++)
247 {
248 if ((linec - i)%(this_reader -> natomes + 1) == 0) j = i;
249 }
250 if (! j) return 2;
251 reader_info ("xdatcar", "Number of atoms", this_reader -> natomes);
252 active_project -> steps = (linec-j) / (this_reader -> natomes + 1);
253 reader_info ("xdatcar", "Number of steps", active_project -> steps);
254 active_project -> natomes = this_reader -> natomes;
255 return vas_get_atom_coordinates (j);
256}
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 vas_get_atom_coordinates(int sli)
get the atomic coordinates from the VASP file
Definition read_vas.c:54
int open_vas_file(int linec)
open VASP file
Definition read_vas.c:242
Functions declaration to read atomic coordinates.
GtkWidget * res[2]
Definition w_encode.c:212