atomes 1.1.15
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-2024 by CNRS and University of Strasbourg */
15
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 ERROR_RW;
54 if (fwrite (& thermo -> type, sizeof(int), 1, fp) != 1) return ERROR_RW;
55 if (fwrite (& thermo -> sys, sizeof(int), 1, fp) != 1) return ERROR_RW;
56 if (fwrite (& thermo -> show, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
57 if (fwrite (thermo -> params, sizeof(double), 4, fp) != 4) return ERROR_RW;
58 if (fwrite (& thermo -> natoms, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
76 if (fixatoms)
77 {
78 if (fixlist)
79 {
80 if (fwrite (fixlist, sizeof(int), fixatoms, fp) != fixatoms) return ERROR_RW;
81 }
82 else
83 {
84 i = 0;
85 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
86 }
87 if (fixcoord)
88 {
89 for (i=0; i<fixatoms; i++) if (fwrite (fixcoord[i], sizeof(int), 3, fp) != 3) return ERROR_RW;
90 }
91 else
92 {
93 i = 0;
94 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
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 ERROR_RW;
116 return OK;
117 }
118 i = 1;
119 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
120 if (fwrite (& this_proj -> cpmd_input[cid] -> calc_type, sizeof(int), 1, fp) != 1) return ERROR_RW;
121 if (fwrite (this_proj -> cpmd_input[cid] -> default_opts, sizeof(double), 17, fp) != 17) return ERROR_RW;
122 if (fwrite (this_proj -> cpmd_input[cid] -> calc_opts, sizeof(double), 24, fp) != 24) return ERROR_RW;
123 if (fwrite (& this_proj -> cpmd_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return ERROR_RW;
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) return ERROR_RW;
131 i ++;
132 thermo = thermo -> next;
133 }
134 i = (this_proj -> cpmd_input[cid] -> elec_thermostat) ? 1 : 0;
135 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
136 if (this_proj -> cpmd_input[cid] -> elec_thermostat)
137 {
138 if (save_thermo (fp, this_proj -> cpmd_input[cid] -> elec_thermostat) != OK) return ERROR_RW;
139 }
140 }
141 if (save_fixed_atoms (fp, this_proj -> cpmd_input[cid] -> fixat, this_proj -> cpmd_input[cid] -> fixlist, this_proj -> cpmd_input[cid] -> fixcoord) != OK)
142 {
143 return ERROR_RW;
144 }
145 if (fwrite (& this_proj -> cpmd_input[cid] -> dummies, sizeof(int), 1, fp) != 1) return ERROR_RW;
146 if (this_proj -> cpmd_input[cid] -> dummies)
147 {
148 dummy_atom * dummy = this_proj -> cpmd_input[cid] -> dummy;
149 while (dummy)
150 {
151 if (fwrite (& dummy -> id, sizeof(int), 1, fp) != 1) return ERROR_RW;
152 if (fwrite (& dummy -> type, sizeof(int), 1, fp) != 1) return ERROR_RW;
153 if (fwrite (& dummy -> show, sizeof(gboolean), 1, fp) != 1) return ERROR_RW;
154 if (fwrite (dummy -> xyz, sizeof(double), 3, fp) != 3) return ERROR_RW;
155 if (fwrite (dummy -> coord, sizeof(int), 4, fp) != 4) return ERROR_RW;
156 if (fwrite (& dummy -> natoms, sizeof(int), 1, fp) != 1) return ERROR_RW;
157 if (dummy -> natoms)
158 {
159 if (fwrite (dummy -> list, sizeof(int), dummy -> natoms, fp) != dummy -> natoms) return ERROR_RW;
160 }
161 dummy = dummy -> next;
162 }
163 }
164 for (i=0; i<this_proj -> nspec; i++)
165 {
166 if (fwrite (this_proj -> cpmd_input[cid] -> pp[i], sizeof(int), 2, fp) != 2) return ERROR_RW;
167 }
168 return save_this_string (fp, this_proj -> cpmd_input[cid] -> info);
169}
170
180int save_cp2k_data (FILE * fp, int cid, project * this_proj)
181{
182 int i, j;
183 if (this_proj -> cp2k_input[cid] == NULL)
184 {
185 i = 0;
186 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
187 return OK;
188 }
189 i = 1;
190 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_RW;
191 if (fwrite (& this_proj -> cp2k_input[cid] -> input_type, sizeof(int), 1, fp) != 1) return ERROR_RW;
192 if (fwrite (this_proj -> cp2k_input[cid] -> opts, sizeof(double), 42, fp) != 42) return ERROR_RW;
193 for (i=0; i<3; i++)
194 {
195 if (fwrite (this_proj -> cp2k_input[cid] -> extra_opts[i], sizeof(double), 4, fp) != 4) return ERROR_RW;
196 }
197 if (fwrite (& this_proj -> cp2k_input[cid] -> thermostats, sizeof(int), 1, fp) != 1) return ERROR_RW;
198 if (this_proj -> cp2k_input[cid] -> thermostats)
199 {
200 thermostat * thermo = this_proj -> cp2k_input[cid] -> ions_thermostat;
201 while (thermo)
202 {
203 if (save_thermo (fp, thermo) != OK) return ERROR_RW;
204 thermo = thermo -> next;
205 }
206 }
207 for (i=0; i<2; i++)
208 {
209 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)
210 {
211 return ERROR_RW;
212 }
213 }
214 for (i=0; i<this_proj -> nspec; i++)
215 {
216 if (fwrite (this_proj -> cp2k_input[cid] -> spec_data[i], sizeof(int), 2, fp) != 2) return ERROR_RW;
217 for (j=0; j<2; j++)
218 {
219 if (save_this_string (fp, this_proj -> cp2k_input[cid] -> spec_files[i][j]) != OK) return ERROR_RW;
220 }
221 }
222 for (i=0; i<5; i++)
223 {
224 if (save_this_string (fp, this_proj -> cp2k_input[cid] -> files[i]) != OK) return ERROR_RW;
225 }
226 return save_this_string (fp, this_proj -> cp2k_input[cid] -> info);
227}
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
Global variable declarations Global convenience function declarations Global data structure defin...
#define ERROR_RW
Definition global.h:280
#define OK
Definition global.h:279
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:49
int save_cp2k_data(FILE *fp, int cid, project *this_proj)
save CP2K data to file
Definition save_qm.c:180
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