atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_bond.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_bond.c'
24*
25* Contains:
26*
27
28 - The function to read bonding information in the atomes project file format
29
30*
31* List of functions:
32
33 int read_bonding (FILE * fp);
34
35*/
36
37#include "global.h"
38#include "project.h"
39#include "glview.h"
40
41extern void new_coord_menus (project * this_proj, coord_info * coord, int new_spec, int nmols,
42 gboolean * showcoord[2], gboolean * showpoly[2], gboolean * showfrag,
43 gboolean update_it, gboolean update_mol);
44
52int read_bonding (FILE * fp)
53{
54 int i, j, k, l, m;
55 distance clo;
56 coord_info * coord = g_malloc0(sizeof*coord);
57 coord -> species = active_project -> nspec;
58 image * img = active_glwin -> anim -> last -> img;
59 gboolean read_bond = FALSE;
60
61 if (! active_glwin -> bonding || ! active_glwin -> adv_bonding[1] || active_project -> natomes > ATOM_LIMIT || active_project -> steps > reading_step_limit)
62 {
63 read_bond = TRUE;
64 }
65 if (read_bond)
66 {
67 active_glwin -> bonds = allocdint (active_project -> steps, 2);
68 active_glwin -> bondid = g_malloc0(active_project -> steps*sizeof*active_glwin -> bondid);
69 for (i=0; i<active_project -> steps; i++)
70 {
71 for (j=0; j<active_project -> natomes; j++)
72 {
73 if (fread (active_project -> atoms[i][j].coord, sizeof(int), 5, fp) != 5) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
74 if (fread (& active_project -> atoms[i][j].numv, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
75 if (active_project -> atoms[i][j].numv)
76 {
77 active_project -> atoms[i][j].vois = allocint (active_project -> atoms[i][j].numv);
78 if (fread (active_project -> atoms[i][j].vois, sizeof(int), active_project -> atoms[i][j].numv, fp) != active_project -> atoms[i][j].numv) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
79 }
80 }
81 if (fread (active_glwin -> bonds[i], sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
82 active_glwin -> bondid[i] = g_malloc0(2*sizeof*active_glwin -> bondid[i]);
83 for (j=0; j<2; j++)
84 {
85 if (active_glwin -> bonds[i][j])
86 {
87 active_glwin -> allbonds[j] += active_glwin -> bonds[i][j];
88 active_glwin -> bondid[i][j] = allocdint (active_glwin -> bonds[i][j], 2);
89 if (j) active_glwin -> clones[i] = g_malloc0(active_glwin -> bonds[i][1]*sizeof*active_glwin -> clones[i]);
90 for (k=0; k<active_glwin -> bonds[i][j]; k++)
91 {
92 if (fread (active_glwin -> bondid[i][j][k], sizeof(int), 2, fp) != 2) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
93 if (j)
94 {
95 l = active_glwin -> bondid[i][j][k][0];
96 m = active_glwin -> bondid[i][j][k][1];
97 clo = distance_3d (active_cell, (active_cell -> npt) ? i : 0, & active_project -> atoms[i][l], & active_project -> atoms[i][m]);
98 active_glwin -> clones[i][k].x = clo.x;
99 active_glwin -> clones[i][k].y = clo.y;
100 active_glwin -> clones[i][k].z = clo.z;
101 }
102 }
103 }
104 }
105 }
106
107 for (i=0; i<2; i++)
108 {
109 coord -> ntg[i] = allocint (coord -> species);
110 if (fread (coord -> ntg[i], sizeof(int), coord -> species, fp) != coord -> species) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
111 coord -> geolist[i] = g_malloc0(coord -> species*sizeof*coord -> geolist[i]);
112 if (i == 1) coord -> partial_geo = g_malloc0(coord -> species*sizeof*coord -> partial_geo);
113 for (j=0; j<coord -> species; j++)
114 {
115 coord -> geolist[i][j] = g_malloc0(coord -> ntg[i][j]*sizeof*coord -> geolist[i][j]);
116 if (fread (coord -> geolist[i][j], sizeof(int), coord -> ntg[i][j], fp) != coord -> ntg[i][j]) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
117 if (i == 1)
118 {
119 coord -> partial_geo[j] = g_malloc0(coord -> ntg[i][j]*sizeof*coord -> partial_geo[j]);
120 for (k=0; k<coord -> ntg[i][j]; k++)
121 {
122 coord -> partial_geo[j][k] = g_malloc0(coord -> species*sizeof*coord -> partial_geo[j][k]);
123 if (fread (coord -> partial_geo[j][k], sizeof(int), coord -> species, fp) != coord -> species) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
124 }
125 }
126 }
127 }
128 coord -> cmax = 0;
129 coord -> cmin = 20;
130 for (i=0; i<coord -> species; i++)
131 {
132 for (j=0; j<coord -> ntg[1][i]; j++)
133 {
134 coord -> cmax = max(coord -> cmax, coord -> geolist[1][i][j]);
135 coord -> cmin = min(coord -> cmin, coord -> geolist[1][i][j]);
136 }
137 }
138 }
139
140 for (i=0; i<10; i++)
141 {
142 if (fread (& j, sizeof(int), 1, fp) != 1) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
143 if (i < 2 && active_glwin -> bonding && j != active_project -> coord -> totcoord[i]) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
144 if (i > 1 && i < 4 && active_glwin -> adv_bonding[i-2] && j != active_project -> coord -> totcoord[i]) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
145 if (i < 2)
146 {
147 if (fread (img -> show_atom[i], sizeof(gboolean), active_project -> nspec, fp) != active_project -> nspec) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
148 if (fread (img -> show_label[i], sizeof(gboolean), active_project -> nspec, fp) != active_project -> nspec) return signal_error (__FILE__, __func__, __LINE__, ERROR_COORD);
149 }
150
151 if (active_project -> coord -> totcoord[i])
152 {
153 if (! img -> show_poly[i] && (i < 2 || (i > 3 && i < 9))) img -> show_poly[i] = allocbool(active_project -> coord -> totcoord[i]);
154 if (! img -> show_coord[i]) img -> show_coord[i] = allocbool(active_project -> coord -> totcoord[i]);
155 if (fread (img -> show_coord[i], sizeof(gboolean), active_project -> coord -> totcoord[i], fp) != active_project -> coord -> totcoord[i]) return ERROR_RW;
156 if (i < 2 || (i > 3 && i < 9))
157 {
158 if (fread (img -> show_poly[i], sizeof(gboolean), active_project -> coord -> totcoord[i], fp) != active_project -> coord -> totcoord[i]) return ERROR_RW;
159 }
160 }
161 }
162 if (! active_glwin -> bonding || ! active_glwin -> adv_bonding[1] || active_project -> natomes > ATOM_LIMIT || active_project -> steps > reading_step_limit)
163 {
164 gboolean * showfrag = duplicate_bool (active_project -> coord -> totcoord[2], img -> show_coord[2]);
165 gboolean * showcoord[2];
166 gboolean * showpoly[2];
167 for (i=0; i<2; i++)
168 {
169 showcoord[i] = duplicate_bool (active_project -> coord -> totcoord[i], img -> show_coord[i]);
170 showpoly[i] = duplicate_bool (active_project -> coord -> totcoord[i], img -> show_poly[i]);
171 }
172 for (i=0; i<10; i++) coord -> totcoord[i] = active_project -> coord -> totcoord[i];
173 active_project -> coord -> cmax = coord -> cmax;
174 active_project -> coord -> cmin = coord -> cmin;
175 new_coord_menus (active_project, coord, active_project -> nspec, 0, showcoord, showpoly, showfrag, TRUE, TRUE);
176 }
177 g_free (coord);
178
179 return OK;
180}
integer(kind=c_int) function bonding(scf, sbf, adv, bdist, bmin, delt_ij, sfil)
Definition bonds.F90:22
int atoms[NUM_STYLES][2]
int bonds[NUM_STYLES][2]
gboolean * duplicate_bool(int num, gboolean *old_val)
copy a list of gboolean
Definition global.c:563
distance distance_3d(cell_info *cell, int mdstep, atom *at, atom *bt)
distance between atom a and b in 3D
Definition ogl_utils.c:81
FILE * fp
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:317
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:241
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
int reading_step_limit
Definition global.c:172
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
glwin * active_glwin
Definition project.c:53
#define ATOM_LIMIT
atom number limit to compute fragment(s) and molecule(s) analysis automatically
cell_info * active_cell
Definition project.c:50
#define ERROR_RW
Definition global.h:296
#define OK
Definition global.h:295
#define min(a, b)
Definition global.h:93
#define ERROR_COORD
Definition global.h:304
project * active_project
Definition project.c:47
#define max(a, b)
Definition global.h:92
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
Function declarations for reading atomes project file Function declarations for saving atomes proje...
void new_coord_menus(project *this_proj, coord_info *coord, int new_spec, int nmols, gboolean *showcoord[2], gboolean *showpoly[2], gboolean *showfrag, gboolean update_it, gboolean update_mol)
Definition atom_coord.c:419
int read_bonding(FILE *fp)
read bonding information from file
Definition read_bond.c:52
double z
Definition glwin.h:127
double y
Definition glwin.h:126
double x
Definition glwin.h:125
Definition glwin.h:364
GtkWidget * img
Definition workspace.c:70