atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
save_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: 'save_qm.c'
24*
25* Contains:
26*
27
28 - The functions to save ab-initio (CPMD/CP2K) calculation parameters in the atomes project file format
29
30*
31* List of functions:
32
33 int save_thermo (FILE * fp, thermostat * thermo);
34 int save_fixed_atoms (FILE * fp, int fixatoms, int * fixlist, int ** fixcoord);
35 int save_cpmd_data (FILE * fp, int cid, project * this_proj);
36 int save_cp2k_data (FILE * fp, int cid, project * this_proj);
37
38*/
39
40#include "global.h"
41#include "project.h"
42
51int save_thermo (FILE * fp, thermostat * thermo)
52{
53 if (fwrite (& thermo -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
54 if (fwrite (& thermo -> type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
55 if (fwrite (& thermo -> sys, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
56 if (fwrite (& thermo -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
57 if (fwrite (thermo -> params, sizeof(double), 4, fp) != 4) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
58 if (fwrite (& thermo -> natoms, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
59 return OK;
60}
61
72int save_fixed_atoms (FILE * fp, int fixatoms, int * fixlist, int ** fixcoord)
73{
74 int i;
75 if (fwrite (& fixatoms, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
76 if (fixatoms)
77 {
78 if (fixlist)
79 {
80 if (fwrite (fixlist, sizeof(int), fixatoms, fp) != fixatoms) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
81 }
82 else
83 {
84 i = 0;
85 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
86 }
87 if (fixcoord)
88 {
89 for (i=0; i<fixatoms; i++) if (fwrite (fixcoord[i], sizeof(int), 3, fp) != 3) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
90 }
91 else
92 {
93 i = 0;
94 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
95 }
96 }
97 return OK;
98}
99
109int save_cpmd_data (FILE * fp, int cid, project * this_proj)
110{
111 int i;
112 if (this_proj -> cpmd_input[cid] == NULL)
113 {
114 i = 0;
115 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
116 return OK;
117 }
118 i = 1;
119 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
120 if (fwrite (& this_proj -> cpmd_input[cid] -> calc_type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
121 if (fwrite (this_proj -> cpmd_input[cid] -> default_opts, sizeof(double), 17, fp) != 17) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
122 if (fwrite (this_proj -> cpmd_input[cid] -> calc_opts, sizeof(double), 24, fp) != 24) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
123 if (fwrite (& this_proj -> cpmd_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
124 if (this_proj -> cpmd_input[cid] -> thermostats)
125 {
126 thermostat * thermo = this_proj -> cpmd_input[cid] -> ions_thermostat;
127 i = 0;
128 while (thermo)
129 {
130 if (save_thermo (fp, thermo) != OK)
131 {
132 update_error_trace (__FILE__, __func__, __LINE__-2);
133 return ERROR_QM;
134 }
135 i ++;
136 thermo = thermo -> next;
137 }
138 i = (this_proj -> cpmd_input[cid] -> elec_thermostat) ? 1 : 0;
139 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
140 if (this_proj -> cpmd_input[cid] -> elec_thermostat)
141 {
142 if (save_thermo (fp, this_proj -> cpmd_input[cid] -> elec_thermostat) != OK)
143 {
144 update_error_trace (__FILE__, __func__, __LINE__-2);
145 return ERROR_QM;
146 }
147 }
148 }
149 if (save_fixed_atoms (fp, this_proj -> cpmd_input[cid] -> fixat, this_proj -> cpmd_input[cid] -> fixlist, this_proj -> cpmd_input[cid] -> fixcoord) != OK)
150 {
151 update_error_trace (__FILE__, __func__, __LINE__-2);
152 return ERROR_QM;
153 }
154 if (fwrite (& this_proj -> cpmd_input[cid] -> dummies, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
155 if (this_proj -> cpmd_input[cid] -> dummies)
156 {
157 dummy_atom * dummy = this_proj -> cpmd_input[cid] -> dummy;
158 while (dummy)
159 {
160 if (fwrite (& dummy -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
161 if (fwrite (& dummy -> type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
162 if (fwrite (& dummy -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
163 if (fwrite (dummy -> xyz, sizeof(double), 3, fp) != 3) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
164 if (fwrite (dummy -> coord, sizeof(int), 4, fp) != 4) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
165 if (fwrite (& dummy -> natoms, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
166 if (dummy -> natoms)
167 {
168 if (fwrite (dummy -> list, sizeof(int), dummy -> natoms, fp) != dummy -> natoms) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
169 }
170 dummy = dummy -> next;
171 }
172 }
173 for (i=0; i<this_proj -> nspec; i++)
174 {
175 if (fwrite (this_proj -> cpmd_input[cid] -> pp[i], sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
176 }
177 return save_this_string (fp, this_proj -> cpmd_input[cid] -> info);
178}
179
189int save_cp2k_data (FILE * fp, int cid, project * this_proj)
190{
191 int i, j;
192 if (this_proj -> cp2k_input[cid] == NULL)
193 {
194 i = 0;
195 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
196 return OK;
197 }
198 i = 1;
199 if (fwrite (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
200 if (fwrite (& this_proj -> cp2k_input[cid] -> input_type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
201 if (fwrite (this_proj -> cp2k_input[cid] -> opts, sizeof(double), 42, fp) != 42) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
202 for (i=0; i<3; i++)
203 {
204 if (fwrite (this_proj -> cp2k_input[cid] -> extra_opts[i], sizeof(double), 4, fp) != 4) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
205 }
206 if (fwrite (& this_proj -> cp2k_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
207 if (this_proj -> cp2k_input[cid] -> thermostats)
208 {
209 thermostat * thermo = this_proj -> cp2k_input[cid] -> ions_thermostat;
210 while (thermo)
211 {
212 if (save_thermo (fp, thermo) != OK)
213 {
214 update_error_trace (__FILE__, __func__, __LINE__-2);
215 return ERROR_QM;
216 }
217 thermo = thermo -> next;
218 }
219 }
220 for (i=0; i<2; i++)
221 {
222 if (save_fixed_atoms (fp, this_proj -> cp2k_input[cid] -> fixat[i], this_proj -> cp2k_input[cid] -> fixlist[i], this_proj -> cp2k_input[cid] -> fixcoord[i]) != OK)
223 {
224 update_error_trace (__FILE__, __func__, __LINE__-2);
225 return ERROR_QM;
226 }
227 }
228 for (i=0; i<this_proj -> nspec; i++)
229 {
230 if (fwrite (this_proj -> cp2k_input[cid] -> spec_data[i], sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
231 for (j=0; j<2; j++)
232 {
233 if (save_this_string (fp, this_proj -> cp2k_input[cid] -> spec_files[i][j]) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
234 }
235 }
236 for (i=0; i<5; i++)
237 {
238 if (save_this_string (fp, this_proj -> cp2k_input[cid] -> files[i]) != OK) return signal_error (__FILE__, __func__, __LINE__, ERROR_QM);
239 }
240 return save_this_string (fp, this_proj -> cp2k_input[cid] -> info);
241}
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
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
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int save_this_string(FILE *fp, gchar *string)
save string to file
Definition save_p.c:50
int save_cp2k_data(FILE *fp, int cid, project *this_proj)
save CP2K data to file
Definition save_qm.c:189
int save_fixed_atoms(FILE *fp, int fixatoms, int *fixlist, int **fixcoord)
save fixed atom(s) to file
Definition save_qm.c:72
int save_cpmd_data(FILE *fp, int cid, project *this_proj)
save CPMD data to file
Definition save_qm.c:109
int save_thermo(FILE *fp, thermostat *thermo)
save thermostat to file
Definition save_qm.c:51