atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_qm.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-2026 by CNRS and University of Strasbourg */
15
21
22/*
23* This file: 'read_qm.c'
24*
25* Contains:
26*
27
28 - Functions to read ab-intio (CPMD/CP2K) calculation parameters in the atomes project file format
29
30*
31* List of functions:
32
33 int read_thermo (FILE * fp, thermostat * thermo);
34 int read_fixed_atoms_cpmd (FILE * fp, cpmd * cpmd_input);
35 int read_fixed_atoms_cp2k (FILE * fp, cp2k * cp2k_input, int idf);
36 int read_cpmd_data (FILE * fp, int cid, project * this_proj);
37 int read_cp2k_data (FILE * fp, int cid, project * this_proj);
38
39*/
40
41#include "global.h"
42#include "project.h"
43
52int read_thermo (FILE * fp, thermostat * thermo)
53{
54 if (fread (& thermo -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
55 if (fread (& thermo -> type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
56 if (fread (& thermo -> sys, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
57 if (fread (& thermo -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
58 if (fread (thermo -> params, sizeof(double), 4, fp) != 4) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
59 if (fread (& thermo -> natoms, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
60 return OK;
61}
62
71int read_fixed_atoms_cpmd (FILE * fp, cpmd * cpmd_input)
72{
73 int i;
74 if (fread (& cpmd_input -> fixat, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
75 if (cpmd_input -> fixat)
76 {
77 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
78 if (i)
79 {
80 cpmd_input -> fixlist = allocint (cpmd_input -> fixat);
81 if (fread (cpmd_input -> fixlist, sizeof(int), cpmd_input -> fixat, fp) != cpmd_input -> fixat) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
82 }
83 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
84 if (i)
85 {
86 cpmd_input -> fixcoord = allocdint (cpmd_input -> fixat, 3);
87 for (i=0; i<cpmd_input -> fixat; i++) if (fread (cpmd_input -> fixcoord[i], sizeof(int), 3, fp) != 3) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
88 }
89 }
90 return OK;
91}
92
102int read_fixed_atoms_cp2k (FILE * fp, cp2k * cp2k_input, int idf)
103{
104 int i;
105 if (fread (& cp2k_input -> fixat[idf], sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
106 if (cp2k_input -> fixat[idf])
107 {
108 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
109 if (i)
110 {
111 cp2k_input -> fixlist[idf] = allocint (cp2k_input -> fixat[idf]);
112 if (fread (cp2k_input -> fixlist[idf], sizeof(int), cp2k_input -> fixat[idf], fp) != cp2k_input -> fixat[idf]) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
113 }
114 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
115 if (i)
116 {
117 cp2k_input -> fixcoord[idf] = allocdint (cp2k_input -> fixat[idf], 3);
118 for (i=0; i<cp2k_input -> fixat[idf]; i++) if (fread (cp2k_input -> fixcoord[idf][i], sizeof(int), 3, fp) != 3) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
119 }
120 }
121 return OK;
122}
123
133int read_cpmd_data (FILE * fp, int cid, project * this_proj)
134{
135 int i;
136 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
137 if (! i) return OK;
138 this_proj -> cpmd_input[cid] = g_malloc0(sizeof*this_proj -> cpmd_input[cid]);
139 if (fread (& this_proj -> cpmd_input[cid] -> calc_type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
140 if (fread (this_proj -> cpmd_input[cid] -> default_opts, sizeof(double), 17, fp) != 17) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
141 if (fread (this_proj -> cpmd_input[cid] -> calc_opts, sizeof(double), 24, fp) != 24) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
142 if (fread (& this_proj -> cpmd_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
143 if (this_proj -> cpmd_input[cid] -> thermostats)
144 {
145 this_proj -> cpmd_input[cid] -> ions_thermostat = g_malloc0(sizeof*this_proj -> cpmd_input[cid] -> ions_thermostat);
146 thermostat * thermo = this_proj -> cpmd_input[cid] -> ions_thermostat;
147 for (i=0; i<this_proj -> cpmd_input[cid] -> thermostats; i++)
148 {
149 if (read_thermo (fp, thermo) != OK)
150 {
151 update_error_trace (__FILE__, __func__, __LINE__-2);
152 return ERROR_QM;
153 }
154 if (i < this_proj -> cpmd_input[cid] -> thermostats - 1)
155 {
156 thermo -> next = g_malloc0(sizeof*thermo -> next);
157 thermo -> next -> prev = thermo;
158 thermo = thermo -> next;
159 }
160 }
161 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
162 if (i)
163 {
164 this_proj -> cpmd_input[cid] -> elec_thermostat = g_malloc0(sizeof*this_proj -> cpmd_input[cid] -> elec_thermostat);
165 if (read_thermo (fp, this_proj -> cpmd_input[cid] -> elec_thermostat) != OK)
166 {
167 update_error_trace (__FILE__, __func__, __LINE__-2);
168 return ERROR_QM;
169 }
170 }
171 }
172 if (read_fixed_atoms_cpmd (fp, this_proj -> cpmd_input[cid]) != OK)
173 {
174 update_error_trace (__FILE__, __func__, __LINE__-2);
175 return ERROR_QM;
176 }
177 if (fread (& this_proj -> cpmd_input[cid] -> dummies, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
178 if (this_proj -> cpmd_input[cid] -> dummies)
179 {
180 this_proj -> cpmd_input[cid] -> dummy = g_malloc0(sizeof*this_proj -> cpmd_input[cid] -> dummy);
181 dummy_atom * dummy = this_proj -> cpmd_input[cid] -> dummy;
182 for (i=0; i < this_proj -> cpmd_input[cid] -> dummies; i ++)
183 {
184 if (fread (& dummy -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
185 if (fread (& dummy -> type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
186 if (fread (& dummy -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
187 if (fread (dummy -> xyz, sizeof(double), 3, fp) != 3) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
188 if (fread (dummy -> coord, sizeof(int), 4, fp) != 4) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
189 if (fread (& dummy -> natoms, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
190 if (dummy -> natoms)
191 {
192 dummy -> list = allocint (dummy -> natoms);
193 if (fread (dummy -> list, sizeof(int), dummy -> natoms, fp) != dummy -> natoms) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
194 }
195 if (i < this_proj -> cpmd_input[cid] -> dummies - 1)
196 {
197 dummy -> next = g_malloc0(sizeof*dummy -> next);
198 dummy -> next -> prev = dummy;
199 dummy = dummy -> next;
200 }
201 }
202 }
203 this_proj -> cpmd_input[cid] -> pp = allocdint (this_proj -> nspec, 2);
204 for (i=0; i<this_proj -> nspec; i++)
205 {
206 if (fread (this_proj -> cpmd_input[cid] -> pp[i], sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
207 }
208 this_proj -> cpmd_input[cid] -> info = read_this_string (fp);
209 /*g_debug (" ********************* CPMD INFO *********************");
210 g_debug ("\n%s\n", this_proj -> cpmd_input[cid] -> info);
211 g_debug (" *****************************************************");*/
212 if (this_proj -> cpmd_input[cid] -> info == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
213 return OK;
214}
215
225int read_cp2k_data (FILE * fp, int cid, project * this_proj)
226{
227 int i, j;
228 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
229 if (! i) return OK;
230 this_proj -> cp2k_input[cid] = g_malloc0(sizeof*this_proj -> cp2k_input[cid]);
231 if (fread (& this_proj -> cp2k_input[cid] -> input_type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
232 if (fread (this_proj -> cp2k_input[cid] -> opts, sizeof(double), 42, fp) != 42) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
233 for (i=0; i<3; i++)
234 {
235 if (fread (this_proj -> cp2k_input[cid] -> extra_opts[i], sizeof(double), 4, fp) != 4) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
236 }
237 if (fread (& this_proj -> cp2k_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
238 if (this_proj -> cp2k_input[cid] -> thermostats)
239 {
240 this_proj -> cp2k_input[cid] -> ions_thermostat = g_malloc0(sizeof*this_proj -> cp2k_input[cid] -> ions_thermostat);
241 thermostat * thermo = this_proj -> cp2k_input[cid] -> ions_thermostat;
242 for (i=0; i<this_proj -> cp2k_input[cid] -> thermostats; i++)
243 {
244 if (read_thermo (fp, thermo) != OK)
245 {
246 update_error_trace (__FILE__, __func__, __LINE__-2);
247 return ERROR_QM;
248 }
249 if (i < this_proj -> cp2k_input[cid] -> thermostats - 1)
250 {
251 thermo -> next = g_malloc0(sizeof*thermo -> next);
252 thermo -> next -> prev = thermo;
253 thermo = thermo -> next;
254 }
255 }
256 }
257 for (i=0; i<2; i++)
258 {
259 if (read_fixed_atoms_cp2k (fp, this_proj -> cp2k_input[cid], i) != OK)
260 {
261 update_error_trace (__FILE__, __func__, __LINE__-2);
262 return ERROR_QM;
263 }
264 }
265 this_proj -> cp2k_input[cid] -> spec_data = allocdint (this_proj -> nspec, 2);
266 this_proj -> cp2k_input[cid] -> spec_files = g_malloc0(this_proj -> nspec*sizeof*this_proj -> cp2k_input[cid] -> spec_files);
267 for (i=0; i<this_proj -> nspec; i++)
268 {
269 if (fread (this_proj -> cp2k_input[cid] -> spec_data[i], sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
270 this_proj -> cp2k_input[cid] -> spec_files[i] = g_malloc0(2*sizeof*this_proj -> cp2k_input[cid] -> spec_files[i]);
271 for (j=0; j<2; j++)
272 {
273 this_proj -> cp2k_input[cid] -> spec_files[i][j] = read_this_string (fp);
274 }
275 }
276 for (i=0; i<5; i++)
277 {
278 this_proj -> cp2k_input[cid] -> files[i] = read_this_string (fp);
279 }
280 this_proj -> cp2k_input[cid] -> info = read_this_string (fp);
281 if (this_proj -> cp2k_input[cid] -> info == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
282 return OK;
283}
gchar * calc_opts[NCPMDCALC][NOPTPC]
gchar * default_opts[MAXDATAQM-1][NSECOP]
Definition cpmd_init.c:123
dummy_atom * dummy
Definition cpmd_atoms.c:73
FILE * fp
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:317
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
Global variable declarations Global convenience function declarations Global data structure defin...
int signal_error(const char *file, const char *func, int error_line, int error_id)
Definition callbacks.c:182
#define OK
Definition global.h:295
void update_error_trace(const char *file, const char *func, int trace_line)
Definition callbacks.c:200
#define ERROR_QM
Definition global.h:309
gchar * read_this_string(FILE *fp)
is there a string to read in this file ? yes do it
Definition open_p.c:109
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int read_thermo(FILE *fp, thermostat *thermo)
read thermostat information from file
Definition read_qm.c:52
int read_fixed_atoms_cpmd(FILE *fp, cpmd *cpmd_input)
read fixed CPMD atom(s) from file
Definition read_qm.c:71
int read_fixed_atoms_cp2k(FILE *fp, cp2k *cp2k_input, int idf)
read fixed CP2K from file
Definition read_qm.c:102
int read_cpmd_data(FILE *fp, int cid, project *this_proj)
read CPMD data from file
Definition read_qm.c:133
int read_cp2k_data(FILE *fp, int cid, project *this_proj)
read CP2K data from file
Definition read_qm.c:225
Definition global.h:868
Definition global.h:849