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