atomes 1.1.14
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-2024 by CNRS and University of Strasbourg */
15
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 ERROR_RW;
55 if (fread (& thermo -> type, sizeof(int), 1, fp) != 1) return ERROR_RW;
56 if (fread (& thermo -> sys, sizeof(int), 1, fp) != 1) return ERROR_RW;
57 if (fread (& thermo -> show, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
58 if (fread (thermo -> params, sizeof(double), 4, fp) != 4) return ERROR_RW;
59 if (fread (& thermo -> natoms, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
75 if (cpmd_input -> fixat)
76 {
77 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
82 }
83 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
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 ERROR_RW;
106 if (cp2k_input -> fixat[idf])
107 {
108 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
113 }
114 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
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 ERROR_RW;
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 ERROR_RW;
140 if (fread (this_proj -> cpmd_input[cid] -> default_opts, sizeof(double), 17, fp) != 17) return ERROR_RW;
141 if (fread (this_proj -> cpmd_input[cid] -> calc_opts, sizeof(double), 24, fp) != 24) return ERROR_RW;
142 if (fread (& this_proj -> cpmd_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return ERROR_RW;
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) return ERROR_RW;
150 if (i < this_proj -> cpmd_input[cid] -> thermostats - 1)
151 {
152 thermo -> next = g_malloc0 (sizeof*thermo -> next);
153 thermo -> next -> prev = thermo;
154 thermo = thermo -> next;
155 }
156 }
157 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
158 if (i)
159 {
160 this_proj -> cpmd_input[cid] -> elec_thermostat = g_malloc0 (sizeof*this_proj -> cpmd_input[cid] -> elec_thermostat);
161 if (read_thermo (fp, this_proj -> cpmd_input[cid] -> elec_thermostat) != OK) return ERROR_RW;
162 }
163 }
164 if (read_fixed_atoms_cpmd (fp, this_proj -> cpmd_input[cid]) != OK)
165 {
166 return ERROR_RW;
167 }
168 if (fread (& this_proj -> cpmd_input[cid] -> dummies, sizeof(int), 1, fp) != 1) return ERROR_RW;
169 if (this_proj -> cpmd_input[cid] -> dummies)
170 {
171 this_proj -> cpmd_input[cid] -> dummy = g_malloc0 (sizeof*this_proj -> cpmd_input[cid] -> dummy);
172 dummy_atom * dummy = this_proj -> cpmd_input[cid] -> dummy;
173 for (i=0; i < this_proj -> cpmd_input[cid] -> dummies; i ++)
174 {
175 if (fread (& dummy -> id, sizeof(int), 1, fp) != 1) return ERROR_RW;
176 if (fread (& dummy -> type, sizeof(int), 1, fp) != 1) return ERROR_RW;
177 if (fread (& dummy -> show, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
178 if (fread (dummy -> xyz, sizeof(double), 3, fp) != 3) return ERROR_RW;
179 if (fread (dummy -> coord, sizeof(int), 4, fp) != 4) return ERROR_RW;
180 if (fread (& dummy -> natoms, sizeof(int), 1, fp) != 1) return ERROR_RW;
181 if (dummy -> natoms)
182 {
183 dummy -> list = allocint (dummy -> natoms);
184 if (fread (dummy -> list, sizeof(int), dummy -> natoms, fp) != dummy -> natoms) return ERROR_RW;
185 }
186 if (i < this_proj -> cpmd_input[cid] -> dummies - 1)
187 {
188 dummy -> next = g_malloc0 (sizeof*dummy -> next);
189 dummy -> next -> prev = dummy;
190 dummy = dummy -> next;
191 }
192 }
193 }
194 this_proj -> cpmd_input[cid] -> pp = allocdint (this_proj -> nspec, 2);
195 for (i=0; i<this_proj -> nspec; i++)
196 {
197 if (fread (this_proj -> cpmd_input[cid] -> pp[i], sizeof(int), 2, fp) != 2) return ERROR_RW;
198 }
199 this_proj -> cpmd_input[cid] -> info = read_this_string (fp);
200 /*g_debug (" ********************* CPMD INFO *********************");
201 g_debug ("\n%s\n", this_proj -> cpmd_input[cid] -> info);
202 g_debug (" *****************************************************");*/
203 if (this_proj -> cpmd_input[cid] -> info == NULL) return ERROR_RW;
204 return OK;
205}
206
216int read_cp2k_data (FILE * fp, int cid, project * this_proj)
217{
218 int i, j;
219 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
220 if (! i) return OK;
221 this_proj -> cp2k_input[cid] = g_malloc0 (sizeof*this_proj -> cp2k_input[cid]);
222 if (fread (& this_proj -> cp2k_input[cid] -> input_type, sizeof(int), 1, fp) != 1) return ERROR_RW;
223 if (fread (this_proj -> cp2k_input[cid] -> opts, sizeof(double), 42, fp) != 42) return ERROR_RW;
224 for (i=0; i<3; i++)
225 {
226 if (fread (this_proj -> cp2k_input[cid] -> extra_opts[i], sizeof(double), 4, fp) != 4) return ERROR_RW;
227 }
228 if (fread (& this_proj -> cp2k_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return ERROR_RW;
229 if (this_proj -> cp2k_input[cid] -> thermostats)
230 {
231 this_proj -> cp2k_input[cid] -> ions_thermostat = g_malloc0 (sizeof*this_proj -> cp2k_input[cid] -> ions_thermostat);
232 thermostat * thermo = this_proj -> cp2k_input[cid] -> ions_thermostat;
233 for (i=0; i<this_proj -> cp2k_input[cid] -> thermostats; i++)
234 {
235 if (read_thermo (fp, thermo) != OK) return ERROR_RW;
236 if (i < this_proj -> cp2k_input[cid] -> thermostats - 1)
237 {
238 thermo -> next = g_malloc0 (sizeof*thermo -> next);
239 thermo -> next -> prev = thermo;
240 thermo = thermo -> next;
241 }
242 }
243 }
244 for (i=0; i<2; i++)
245 {
246 if (read_fixed_atoms_cp2k (fp, this_proj -> cp2k_input[cid], i) != OK)
247 {
248 return ERROR_RW;
249 }
250 }
251 this_proj -> cp2k_input[cid] -> spec_data = allocdint (this_proj -> nspec, 2);
252 this_proj -> cp2k_input[cid] -> spec_files = g_malloc0 (this_proj -> nspec*sizeof*this_proj -> cp2k_input[cid] -> spec_files);
253 for (i=0; i<this_proj -> nspec; i++)
254 {
255 if (fread (this_proj -> cp2k_input[cid] -> spec_data[i], sizeof(int), 2, fp) != 2) return ERROR_RW;
256 this_proj -> cp2k_input[cid] -> spec_files[i] = g_malloc0 (2*sizeof*this_proj -> cp2k_input[cid] -> spec_files[i]);
257 for (j=0; j<2; j++)
258 {
259 this_proj -> cp2k_input[cid] -> spec_files[i][j] = read_this_string (fp);
260 }
261 }
262 for (i=0; i<5; i++)
263 {
264 this_proj -> cp2k_input[cid] -> files[i] = read_this_string (fp);
265 }
266 this_proj -> cp2k_input[cid] -> info = read_this_string (fp);
267 if (this_proj -> cp2k_input[cid] -> info == NULL) return ERROR_RW;
268 return OK;
269}
gchar * calc_opts[NCPMDCALC][NOPTPC]
Definition cpmd_init.c:169
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:342
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
Global variable declarations Global convenience function declarations Global data structure defin...
#define ERROR_RW
Definition global.h:252
#define OK
Definition global.h:251
gchar * read_this_string(FILE *fp)
is there a string to read in this file ? yes do it
Definition open_p.c:95
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:216
Definition global.h:754
Definition global.h:735