atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_field.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_field.c'
24*
25* Contains:
26*
27
28 - The functions to read DLPOLY force field data in the atomes project file format
29
30*
31* List of functions:
32
33 int read_field_atom (FILE * fp);
34 int read_field_shell (FILE * fp);
35 int read_field_constraint (FILE * fp);
36 int read_field_pmf (FILE * fp);
37 int read_field_rigid (FILE * fp);
38 int read_field_tethered (FILE * fp, int fid);
39 int read_field_prop (FILE * fp, int fid, int pid);
40 int read_field_struct (FILE * fp, int fid);
41 int read_field_molecule (FILE * fp, int fid);
42 int read_field_body (FILE * fp, int fid);
43 int read_field_external (FILE * fp, int fid);
44 int read_dlp_field_data (FILE * fp, project * this_proj);
45 int read_lmp_field_data (FILE * fp, project * this_proj);
46
47*/
48
49#include "global.h"
50#include "project.h"
51#include "dlp_field.h"
52
60int read_field_atom (FILE * fp)
61{
62 if (fread (& tmp_fat -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
63 if (fread (& tmp_fat -> fid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
64 if (fread (& tmp_fat -> afid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
65 if (fread (& tmp_fat -> type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
66 tmp_fat -> name = read_this_string (fp);
67 if (tmp_fat -> name == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
68 if (fread (& tmp_fat -> num, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
69 if (fread (& tmp_fat -> sp, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
70 if (fread (& tmp_fat -> mass, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
71 if (fread (& tmp_fat -> charge, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
72 if (fread (& tmp_fat -> frozen, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
73 tmp_fat -> frozen_id = allocbool(tmp_fat -> num);
74 if (fread (tmp_fat -> frozen_id, sizeof(gboolean), tmp_fat -> num, fp) != tmp_fat -> num) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
75 if (fread (& tmp_fat -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
76 tmp_fat -> list = allocint (tmp_fat -> num);
77 if (fread (tmp_fat -> list, sizeof(int), tmp_fat -> num, fp) != tmp_fat -> num) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
78 tmp_fat -> list_id = allocint (tmp_fat -> num);
79 if (fread (tmp_fat -> list_id, sizeof(int), tmp_fat -> num, fp) != tmp_fat -> num) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
80 return OK;
81}
82
90int read_field_shell (FILE * fp)
91{
92 if (fread (& tmp_fshell -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
93 if (fread (tmp_fshell -> ia, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
94 if (fread (& tmp_fshell -> m, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
95 if (fread (& tmp_fshell -> z, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
96 if (fread (& tmp_fshell -> k2, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
97 if (fread (& tmp_fshell -> k4, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
98 if (fread (& tmp_fshell -> vdw, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
99 if (fread (& tmp_fshell -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
100 if (fread (& tmp_fshell -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
101 return OK;
102}
103
112{
113 if (fread (& tmp_fcons -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
114 if (fread (tmp_fcons -> ia, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
115 if (fread (& tmp_fcons -> av, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
116 if (fread (& tmp_fcons -> length, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
117 if (fread (& tmp_fcons -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
118 if (fread (& tmp_fcons -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
119 return OK;
120}
121
129int read_field_pmf (FILE * fp)
130{
131 if (fread (& tmp_fpmf -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
132 if (fread (& tmp_fpmf -> av, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
133 if (fread (& tmp_fpmf -> length, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
134 if (fread (tmp_fpmf -> num, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
135 int i;
136 for (i=0; i<2; i++)
137 {
138 tmp_fpmf -> list[i] = allocint (tmp_fpmf -> num[i]);
139 if (fread (tmp_fpmf -> list[i], sizeof(int), tmp_fpmf -> num[i], fp) != tmp_fpmf -> num[i]) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
140 tmp_fpmf -> weight[i] = allocfloat (tmp_fpmf -> num[i]);
141 if (fread (tmp_fpmf -> weight[i], sizeof(float), tmp_fpmf -> num[i], fp) != tmp_fpmf -> num[i]) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
142 }
143 if (fread (& tmp_fpmf -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
144 if (fread (& tmp_fpmf -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
145 return OK;
146}
147
156{
157 if (fread (& tmp_frig -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
158 if (fread (& tmp_frig -> num, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
159 tmp_frig -> list = allocint (tmp_frig -> num);
160 if (fread (tmp_frig -> list, sizeof(int), tmp_frig -> num, fp) != tmp_frig -> num) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
161 if (fread (& tmp_frig -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
162 if (fread (& tmp_frig -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
163 return OK;
164}
165
174int read_field_tethered (FILE * fp, int fid)
175{
176 if (fread (& tmp_ftet -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
177 if (fread (& tmp_ftet -> num, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
178 if (fread (& tmp_ftet -> key, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
179 int i = fvalues[fid][0][tmp_ftet -> key];
180 tmp_ftet -> val = allocfloat (i);
181 if (fread (tmp_ftet -> val, sizeof(float), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
182 if (fread (& tmp_ftet -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
183 if (fread (& tmp_ftet -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
184 return OK;
185}
186
196int read_field_prop (FILE * fp, int fid, int pid)
197{
198 if (fread (& tmp_fprop -> pid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
199 if (fread (& tmp_fprop -> fpid, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
200 if (fread (& tmp_fprop -> key, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
201 int i = struct_id(pid+7);
202 tmp_fprop -> aid = allocint (i);
203 if (fread (tmp_fprop -> aid, sizeof(int), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
204 i = fvalues[fid][pid+1][tmp_fprop -> key];
205 tmp_fprop -> val = allocfloat (i);
206 if (fread (tmp_fprop -> val, sizeof(float), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
207 if (fread (& tmp_fprop -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
208 if (fread (& tmp_fprop -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
209 return OK;
210}
211
220int read_field_struct (FILE * fp, int fid)
221{
222 if (fread (& tmp_fstr -> st, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
223 if (fread (& tmp_fstr -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
224 if (fread (& tmp_fstr -> num, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
225 int i, j;
226 i = struct_id(tmp_fstr -> st + 7);
227 tmp_fstr -> aid = allocint (i);
228 if (fread (tmp_fstr -> aid, sizeof(int), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
229 if (fread (& tmp_fstr-> av, sizeof(float), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
230 tmp_fstr -> def = g_malloc0(sizeof*tmp_fstr -> def);
231 tmp_fprop = tmp_fstr -> def;
232 if (read_field_prop(fp, fid, tmp_fstr -> st) != OK)
233 {
234 update_error_trace (__FILE__, __func__, __LINE__-2);
235 return ERROR_FIELD;
236 }
237 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
238 if (i)
239 {
240 tmp_fstr -> other = g_malloc0(sizeof*tmp_fstr -> other);
241 tmp_fprop = tmp_fstr -> other;
242 for (j=0; j<i; j++)
243 {
244 if (read_field_prop(fp, fid, tmp_fstr -> st) != OK)
245 {
246 update_error_trace (__FILE__, __func__, __LINE__-2);
247 return ERROR_FIELD;
248 }
249 if (j < i-1)
250 {
251 tmp_fprop -> next = g_malloc0(sizeof*tmp_fprop -> next);
252 tmp_fprop = tmp_fprop -> next;
253 }
254 }
255 }
256 return OK;
257}
258
267int read_field_molecule (FILE * fp, int fid)
268{
269 if (fread (& tmp_fmol -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
270 //tmp_fmol -> mol = g_malloc0(sizeof*tmp_fmol -> mol);
271 int i, j;
272 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
273 // if (i == 20) i = 1;
274 tmp_fmol -> mol = & active_project -> modelfc -> mols[0][i];
275 tmp_fmol -> name = read_this_string (fp);
276 if (tmp_fmol -> name == NULL) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
277 if (fread (& tmp_fmol -> multi, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
278 tmp_fmol -> fragments = allocint (tmp_fmol -> multi);
279 if (fread (tmp_fmol -> fragments, sizeof(int), tmp_fmol -> multi, fp) != tmp_fmol -> multi) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
280 tmp_fmol -> atoms_id = g_malloc0(tmp_fmol -> mol -> natoms*sizeof*tmp_fmol -> atoms_id);
281
282 for (i=0; i<tmp_fmol -> mol -> natoms; i++)
283 {
284 tmp_fmol -> atoms_id[i] = g_malloc0(tmp_fmol -> multi*sizeof*tmp_fmol -> atoms_id[i]);
285 if (fread (tmp_fmol -> atoms_id[i], sizeof(dint), tmp_fmol -> multi, fp) != tmp_fmol -> multi) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
286 }
287
288 if (fread (& tmp_fmol -> atoms, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
289 tmp_fmol -> first_atom = g_malloc0(sizeof*tmp_fmol -> first_atom);
290 tmp_fat = tmp_fmol -> first_atom;
291 for (i=0; i<tmp_fmol -> atoms; i++)
292 {
293 if (read_field_atom(fp) != OK)
294 {
295 update_error_trace (__FILE__, __func__, __LINE__-2);
296 return ERROR_FIELD;
297 }
298 if (i < tmp_fmol -> atoms-1)
299 {
300 tmp_fat -> next = g_malloc0(sizeof*tmp_fat -> next);
301 tmp_fat = tmp_fat -> next;
302 }
303 }
304
305 if (fread (& tmp_fmol -> shells, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
306 if (tmp_fmol -> shells)
307 {
308 tmp_fmol -> first_shell = g_malloc0(sizeof*tmp_fmol -> first_shell);
309 tmp_fshell = tmp_fmol -> first_shell;
310 for (i=0; i<tmp_fmol -> shells; i++)
311 {
312 if (read_field_shell(fp) != OK)
313 {
314 update_error_trace (__FILE__, __func__, __LINE__-2);
315 return ERROR_FIELD;
316 }
317 if (i < tmp_fmol -> shells - 1)
318 {
319 tmp_fshell -> next = g_malloc0(sizeof*tmp_fshell -> next);
320 tmp_fshell = tmp_fshell -> next;
321 }
322 }
323 }
324
325 if (fread (& tmp_fmol -> constraints, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
326 if (tmp_fmol -> constraints)
327 {
328 tmp_fmol -> first_constraint = g_malloc0(sizeof*tmp_fmol -> first_constraint);
329 tmp_fcons = tmp_fmol -> first_constraint;
330 for (i=0; i<tmp_fmol -> constraints; i++)
331 {
333 {
334 update_error_trace (__FILE__, __func__, __LINE__-2);
335 return ERROR_FIELD;
336 }
337 if (i < tmp_fmol -> constraints - 1)
338 {
339 tmp_fcons -> next = g_malloc0(sizeof*tmp_fcons -> next);
340 tmp_fcons = tmp_fcons -> next;
341 }
342 }
343 }
344
345 if (fread (& tmp_fmol -> pmfs, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
346 if (tmp_fmol -> pmfs)
347 {
348 tmp_fmol -> first_pmf = g_malloc0(sizeof*tmp_fmol -> first_pmf);
349 tmp_fpmf = tmp_fmol -> first_pmf;
350 for (i=0; i<tmp_fmol -> pmfs; i++)
351 {
352 if (read_field_pmf(fp) != OK)
353 {
354 update_error_trace (__FILE__, __func__, __LINE__-2);
355 return ERROR_FIELD;
356 }
357 if (i < tmp_fmol -> pmfs - 1)
358 {
359 tmp_fpmf -> next = g_malloc0(sizeof*tmp_fpmf -> next);
360 tmp_fpmf = tmp_fpmf -> next;
361 }
362 }
363 }
364
365 if (fread (& tmp_fmol -> rigids, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
366 if (tmp_fmol -> rigids)
367 {
368 tmp_fmol -> first_rigid = g_malloc0(sizeof*tmp_fmol -> first_rigid);
369 tmp_frig = tmp_fmol -> first_rigid;
370 for (i=0; i<tmp_fmol -> rigids; i++)
371 {
372 if (read_field_rigid(fp) != OK)
373 {
374 update_error_trace (__FILE__, __func__, __LINE__-2);
375 return ERROR_FIELD;
376 }
377 if (i < tmp_fmol -> rigids - 1)
378 {
379 tmp_frig -> next = g_malloc0(sizeof*tmp_frig -> next);
380 tmp_frig = tmp_frig -> next;
381 }
382 }
383 }
384
385 if (fread (& tmp_fmol -> tethered, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
386 if (tmp_fmol -> tethered)
387 {
388 tmp_fmol -> first_tethered = g_malloc0(sizeof*tmp_fmol -> first_tethered);
389 tmp_ftet = tmp_fmol -> first_tethered;
390 for (i=0; i<tmp_fmol -> tethered; i++)
391 {
392 if (read_field_tethered(fp, fid) != OK)
393 {
394 update_error_trace (__FILE__, __func__, __LINE__-2);
395 return ERROR_FIELD;
396 }
397 if (i < tmp_fmol -> tethered - 1)
398 {
399 tmp_ftet -> next = g_malloc0(sizeof*tmp_ftet -> next);
400 tmp_ftet = tmp_ftet -> next;
401 }
402 }
403 }
404
405 if (fread (tmp_fmol -> nstruct, sizeof(int), 8, fp) != 8) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
406 for (i=0; i<8; i++)
407 {
408 if (tmp_fmol -> nstruct[i])
409 {
410 tmp_fmol -> first_struct[i] = g_malloc0(sizeof*tmp_fmol -> first_struct[i]);
411 tmp_fstr = tmp_fmol -> first_struct[i];
412 for (j=0; j<tmp_fmol -> nstruct[i]; j++)
413 {
414 if (read_field_struct (fp, fid)!= OK)
415 {
416 update_error_trace (__FILE__, __func__, __LINE__-2);
417 return ERROR_FIELD;
418 }
419 if (j < tmp_fmol -> nstruct[i]-1)
420 {
421 tmp_fstr -> next = g_malloc0(sizeof*tmp_fstr -> next);
422 tmp_fstr = tmp_fstr -> next;
423 }
424 }
425 }
426 }
427 return OK;
428}
429
438int read_field_body (FILE * fp, int fid)
439{
440 if (fread (& tmp_fbody -> bd, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
441 if (fread (& tmp_fbody -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
442 if (fread (& tmp_fbody -> key, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
443 if (tmp_fbody -> bd == 0)
444 {
445 tmp_fbody -> fpid = allocint (2);
446 if (fread (tmp_fbody -> fpid, sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
447 }
448 int i, j;
449 i = body_at(tmp_fbody -> bd);
450 tmp_fbody -> na = allocint (i);
451 if (fread (tmp_fbody -> na, sizeof(int), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
452 tmp_fbody -> ma = g_malloc0(i*sizeof*tmp_fbody -> ma);
453 tmp_fbody -> a = g_malloc0(i*sizeof*tmp_fbody -> a);
454 for (j=0; j<i; j++)
455 {
456 tmp_fbody -> ma[j] = allocint (tmp_fbody -> na[j]);
457 if (fread (tmp_fbody -> ma[j], sizeof(int), tmp_fbody -> na[j], fp) != tmp_fbody -> na[j]) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
458 tmp_fbody -> a[j] = allocint (tmp_fbody -> na[j]);
459 if (fread (tmp_fbody -> a[j], sizeof(int), tmp_fbody -> na[j], fp) != tmp_fbody -> na[j]) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
460 }
461 i = fvalues[fid][9+tmp_fbody -> bd][tmp_fbody -> key];
462 tmp_fbody -> val = allocfloat (i);
463 if (fread (tmp_fbody -> val, sizeof(float), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
464 if (fread (& tmp_fbody -> show, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
465 if (fread (& tmp_fbody -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
466 return OK;
467}
468
477int read_field_external (FILE * fp, int fid)
478{
479 if (fread (& tmp_fext -> id, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
480 if (fread (& tmp_fext -> key, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
481 int i = fvalues[fid][14][tmp_fext -> key];
482 tmp_fext -> val = allocfloat (i);
483 if (fread (tmp_fext -> val, sizeof(float), i, fp) != i) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
484 if (fread (& tmp_fext -> use, sizeof(gboolean), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
485 return OK;
486}
487
496int read_dlp_field_data (FILE * fp, project * this_proj)
497{
498 int i, j, k, l, m, n;
499 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
500 if (! i) return OK;
501 this_proj -> force_field[0] = g_malloc0(sizeof*this_proj -> force_field[0]);
502 // Allocate force field data
503 this_proj -> force_field[0] -> sys_opts = allocdouble (17);
504 this_proj -> force_field[0] -> io_opts = allocdouble (23);
505 this_proj -> force_field[0] -> ana_opts = allocdouble (17);
506 this_proj -> force_field[0] -> elec_opts = allocdouble (11);
507 this_proj -> force_field[0] -> vdw_opts = allocdouble (6);
508 this_proj -> force_field[0] -> met_opts = allocdouble (2);
509 this_proj -> force_field[0] -> equi_opts = allocdouble (17);
510 this_proj -> force_field[0] -> thermo_opts= allocdouble (10);
511 this_proj -> force_field[0] -> md_opts = allocdouble (20);
512 this_proj -> force_field[0] -> out_opts = allocdouble (31);
513 // CONTROL file
514 if (fread (this_proj -> force_field[0] -> sys_opts, sizeof(double), 17, fp) != 17) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
515 if (fread (this_proj -> force_field[0] -> io_opts, sizeof(double), 23, fp) != 23) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
516 if (fread (this_proj -> force_field[0] -> ana_opts, sizeof(double), 17, fp) != 17) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
517 if (fread (this_proj -> force_field[0] -> elec_opts, sizeof(double), 11, fp) != 11) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
518 if (fread (this_proj -> force_field[0] -> vdw_opts, sizeof(double), 6, fp) != 6) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
519 if (fread (this_proj -> force_field[0] -> met_opts, sizeof(double), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
520 if (fread (this_proj -> force_field[0] -> equi_opts, sizeof(double), 17, fp) != 17) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
521 if (fread (& this_proj -> force_field[0] -> ensemble, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
522 if (fread (& this_proj -> force_field[0] -> thermostat, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
523 if (fread (this_proj -> force_field[0] -> thermo_opts, sizeof(double), 10, fp) != 10) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
524 if (fread (this_proj -> force_field[0] -> md_opts, sizeof(double), 20, fp) != 20) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
525 if (fread (this_proj -> force_field[0] -> out_opts, sizeof(double), 31, fp) != 31) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
526 // FIELD file
527 if (fread (this_proj -> force_field[0] -> prepare_file, sizeof(gboolean), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
528 if (fread (this_proj -> force_field[0] -> afp, sizeof(gboolean), MAXDATC+MAXDATA, fp) != MAXDATC+MAXDATA) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
529 if (fread (& this_proj -> force_field[0] -> type, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
530 if (fread (& this_proj -> force_field[0] -> energy_unit, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
531 if (fread (& this_proj -> force_field[0] -> atom_init, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
532 if (fread (& this_proj -> force_field[0] -> molecules, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
533 if (! this_proj -> force_field[0] -> molecules) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
534 this_proj -> force_field[0] -> first_molecule = g_malloc0(sizeof*this_proj -> force_field[0] -> first_molecule);
535 tmp_fmol = this_proj -> force_field[0] -> first_molecule;
536 for (i=0; i<this_proj -> force_field[0] -> molecules; i++)
537 {
538 if (read_field_molecule (fp, 0) != OK)
539 {
540 update_error_trace (__FILE__, __func__, __LINE__-2);
541 return ERROR_FIELD;
542 }
543 // setup_field_molecule_neighbors (i, this_proj);
544 for (j=0; j<tmp_fmol -> mol -> natoms; j++)
545 {
546 for (k=0; k<tmp_fmol -> multi; k++)
547 {
548 l = tmp_fmol -> atoms_id[j][k].a;
549 m = tmp_fmol -> atoms_id[j][k].b;
550 tmp_fat = tmp_fmol -> first_atom;
551 while (tmp_fat -> id < l) tmp_fat = tmp_fat -> next;
552 n = tmp_fat -> list[m];
553 this_proj -> atoms[0][n].fid = j;
554 this_proj -> atoms[0][n].faid = l;
555 }
556 }
557 if (i < this_proj -> force_field[0] -> molecules-1)
558 {
559 tmp_fmol -> next = g_malloc0(sizeof*tmp_fmol -> next);
560 tmp_fmol = tmp_fmol -> next;
561 }
562 }
563 if (fread (this_proj -> force_field[0] -> nbody, sizeof(int), 5, fp) != 5) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
564 for (i=0; i<5; i++)
565 {
566 if (this_proj -> force_field[0] -> nbody[i])
567 {
568 this_proj -> force_field[0] -> first_body[i] = g_malloc0(sizeof*this_proj -> force_field[0] -> first_body[i]);
569 tmp_fbody = this_proj -> force_field[0] -> first_body[i];
570 for (j=0; j<this_proj -> force_field[0] -> nbody[i]; j++)
571 {
572 if (read_field_body (fp, 0) != OK)
573 {
574 update_error_trace (__FILE__, __func__, __LINE__-2);
575 return ERROR_FIELD;
576 }
577 if (j < this_proj -> force_field[0] -> nbody[i]-1)
578 {
579 tmp_fbody -> next = g_malloc0(sizeof*tmp_fbody -> next);
580 tmp_fbody = tmp_fbody -> next;
581 }
582 }
583 }
584 }
585 // Tersoff potential cross terms
586 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
587 if (i)
588 {
589 j = this_proj -> force_field[0] -> nbody[2] * (this_proj -> force_field[0] -> nbody[2] - 1) / 2;
590 this_proj -> force_field[0] -> cross = g_malloc0(j*sizeof*this_proj -> force_field[0] -> cross);
591 for (k=0; k<j; k++)
592 {
593 this_proj -> force_field[0] -> cross[k] = g_malloc0(3*sizeof*this_proj -> force_field[0] -> cross[k]);
594 if (fread (& this_proj -> force_field[0] -> cross[k], sizeof(double), 3, fp) != 3) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
595 }
596 }
597 if (fread (& this_proj -> force_field[0] -> extern_fields, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
598 if (this_proj -> force_field[0] -> extern_fields)
599 {
600 this_proj -> force_field[0] -> first_external = g_malloc0(sizeof*this_proj -> force_field[0] -> first_external);
601 tmp_fext = this_proj -> force_field[0] -> first_external;
602 for (i=0; i<this_proj -> force_field[0] -> extern_fields; i++)
603 {
604 if (read_field_external(fp, 0) != OK)
605 {
606 update_error_trace (__FILE__, __func__, __LINE__-2);
607 return ERROR_FIELD;
608 }
609 if (i < this_proj -> force_field[0] -> extern_fields-1)
610 {
611 tmp_fext -> next = g_malloc0(sizeof*tmp_fext -> next);
612 tmp_fext = tmp_fext -> next;
613 }
614 }
615 }
616 return OK;
617}
618
627int read_lmp_field_data (FILE * fp, project * this_proj)
628{
629 int i;
630 if (fread (& i, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_FIELD);
631 if (! i) return OK;
632 return OK;
633}
insertion_menu mol[]
Definition w_library.c:193
int atoms[NUM_STYLES][2]
float val
Definition dlp_init.c:117
gchar * sys_opts[10]
int * atoms_id
double *** cross
Definition dlp_edit.c:418
field_constraint * tmp_fcons
Definition dlp_field.c:1049
int fvalues[2][15][21]
Definition dlp_field.c:345
field_nth_body * tmp_fbody
Definition dlp_field.c:1055
field_shell * tmp_fshell
Definition dlp_field.c:1048
field_rigid * tmp_frig
Definition dlp_field.c:1051
int body_at(int b)
find the number of atom(s) in a non bonded interaction
Definition dlp_field.c:1112
field_pmf * tmp_fpmf
Definition dlp_field.c:1050
field_external * tmp_fext
Definition dlp_field.c:1057
field_atom * tmp_fat
Definition dlp_field.c:1047
int struct_id(int f)
number of atoms in a structural element
Definition dlp_field.c:1089
field_struct * tmp_fstr
Definition dlp_field.c:1054
field_molecule * tmp_fmol
Definition dlp_field.c:1045
int atom_init
Definition dlp_field.c:1040
field_prop * tmp_fprop
Definition dlp_field.c:1053
field_tethered * tmp_ftet
Definition dlp_field.c:1052
Variable declarations for the creation of the DL_POLY input file(s).
gboolean afp[MAXDATA]
int multi
Definition dlp_init.c:121
FILE * fp
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:241
double * allocdouble(int val)
allocate a double * pointer
Definition global.c:446
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
float * allocfloat(int val)
allocate a float * pointer
Definition global.c:385
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 ERROR_FIELD
#define OK
Definition global.h:295
#define MAXDATC
Number of tabs for the description of the classical calculation.
Definition global.h:771
void update_error_trace(const char *file, const char *func, int trace_line)
Definition callbacks.c:200
#define MAXDATA
Number of tabs for the description of the classical force field.
Definition global.h:776
project * active_project
Definition project.c:47
integer(kind=c_int) function molecules(frag_and_mol, allbonds)
double z
Definition ogl_draw.c:63
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_dlp_field_data(FILE *fp, project *this_proj)
read force field data from file
Definition read_field.c:496
int read_field_molecule(FILE *fp, int fid)
read field molecule from file
Definition read_field.c:267
int read_field_external(FILE *fp, int fid)
read field external data from file
Definition read_field.c:477
int read_field_struct(FILE *fp, int fid)
read field structural properties from file
Definition read_field.c:220
int read_field_atom(FILE *fp)
read field atom properties from file
Definition read_field.c:60
int read_field_shell(FILE *fp)
read field core shell data from file
Definition read_field.c:90
int read_field_rigid(FILE *fp)
read field rigid constraints data from file
Definition read_field.c:155
int read_field_pmf(FILE *fp)
read field mean force potential data from file
Definition read_field.c:129
int read_field_body(FILE *fp, int fid)
read field nth body data from file
Definition read_field.c:438
int read_lmp_field_data(FILE *fp, project *this_proj)
read LAMMPS field data from file
Definition read_field.c:627
int read_field_constraint(FILE *fp)
read field constraint data from file
Definition read_field.c:111
int read_field_tethered(FILE *fp, int fid)
read field tethered data from file
Definition read_field.c:174
int read_field_prop(FILE *fp, int fid, int pid)
read field property from file
Definition read_field.c:196
Definition global.h:111