atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
save_mol.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_mol.c'
24*
25* Contains:
26*
27
28 - The functions to save molecules information in the atomes project file format
29
30*
31* List of functions:
32
33 int save_atom_m (FILE * fp, project * this_proj, int s, int a);
34 int save_this_mol (FILE * fp, project * this_proj, molecule * tmp);
35 int save_mol (FILE * fp, project * this_proj);
36
37*/
38
39#include "global.h"
40#include "project.h"
41
42/*molecule {
43 int id; // Molecule id number
44 int md; // MD step
45 int multiplicity; // Multiplicity
46 int * fragments; // Fragments list
47 int natoms; // Number of atoms
48 int nspec; // Number of chemical species
49 int * species; // Number of atom by species
50 atom ** atoms; // The list of all atoms
51 int nbonds; // Number of chemical bonds
52 int ** pbonds; // Number of chemical bonds by geometries
53 int nangles; // Number of bond angles
54 int *** pangles; // Number of bond angles by geometries
55 int ** lgeo; // list of coordination spheres (by species)
56 molecule * next;
57 molecule * prev;
58};*/
59
70int save_atom_m (FILE * fp, project * this_proj, int s, int a)
71{
72 if (fwrite (& this_proj -> atoms[s][a].coord[2], sizeof(int), 1, fp) != 1) return ERROR_RW;
73 if (fwrite (& this_proj -> atoms[s][a].coord[3], sizeof(int), 1, fp) != 1) return ERROR_RW;
74 return OK;
75}
76
86int save_this_mol (FILE * fp, project * this_proj, molecule * tmp)
87{
88 if (fwrite (& tmp -> id, sizeof(int), 1, fp) != 1) return 0;
89 if (fwrite (& tmp -> md, sizeof(int), 1, fp) != 1) return 0;
90 if (fwrite (& tmp -> multiplicity, sizeof(int), 1, fp) != 1) return 0;
91 if (fwrite (tmp -> fragments, sizeof(int), tmp -> multiplicity, fp) != tmp -> multiplicity) return 0;
92 if (fwrite (& tmp -> natoms, sizeof(int), 1, fp) != 1) return 0;
93 if (fwrite (& tmp -> nspec, sizeof(int), 1, fp) != 1) return 0;
94 if (fwrite (tmp -> species, sizeof(int), this_proj -> nspec, fp) != this_proj -> nspec) return 0;
95 return 1;
96}
97
106int save_mol (FILE * fp, project * this_proj)
107{
108 int i, j;
109 i = 0;
110 if (! this_proj -> modelfc)
111 {
112 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_MOL;
113 return OK;
114 }
115 i = 1;
116 if (fwrite (& i, sizeof(int), 1, fp) != 1) return ERROR_MOL;
117 for (i=1; i<4; i++)
118 {
119 if (fwrite (& this_proj -> coord -> totcoord[i], sizeof(int), 1, fp) != 1) return ERROR_MOL;
120 }
121 if (fwrite (this_proj -> modelfc -> mol_by_step, sizeof(int), this_proj -> steps, fp) != this_proj -> steps) return ERROR_MOL;
122 for (i=0; i<this_proj -> steps; i++)
123 {
124 for (j=0; j<this_proj -> modelfc -> mol_by_step[i]; j++)
125 {
126 if (! save_this_mol (fp, this_proj, & this_proj -> modelfc -> mols[i][j])) return ERROR_MOL;
127 }
128 }
129 for (i=0; i<this_proj -> steps; i++)
130 {
131 for (j=0; j< this_proj -> natomes; j++)
132 {
133 if (save_atom_m (fp, this_proj, i, j) != OK) return ERROR_MOL;
134 }
135 }
136 return OK;
137}
int atoms[NUM_STYLES][2]
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
#define ERROR_MOL
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int save_atom_m(FILE *fp, project *this_proj, int s, int a)
save atom data to file
Definition save_mol.c:70
int save_mol(FILE *fp, project *this_proj)
save molecule information to file
Definition save_mol.c:106
int save_this_mol(FILE *fp, project *this_proj, molecule *tmp)
save this molecule data to file
Definition save_mol.c:86
int a
Definition tab-1.c:95