atomes 1.1.16
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-2024 by CNRS and University of Strasbourg */
15
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 if (! active_glwin -> bonding || ! active_glwin -> adv_bonding[1] || active_project -> natomes > ATOM_LIMIT || active_project -> steps > STEP_LIMIT)
61 {
62 read_bond = TRUE;
63 }
64 if (read_bond)
65 {
66 active_glwin -> bonds = allocdint (active_project -> steps, 2);
67 active_glwin -> bondid = g_malloc0 (active_project -> steps*sizeof*active_glwin -> bondid);
68 for (i=0; i<active_project -> steps; i++)
69 {
70 for (j=0; j<active_project -> natomes; j++)
71 {
72 if (fread (active_project -> atoms[i][j].coord, sizeof(int), 5, fp) != 5) return ERROR_COORD;
73 if (fread (& active_project -> atoms[i][j].numv, sizeof(int), 1, fp) != 1) return ERROR_COORD;
74 if (active_project -> atoms[i][j].numv)
75 {
76 active_project -> atoms[i][j].vois = allocint(active_project -> atoms[i][j].numv);
77 if (fread (active_project -> atoms[i][j].vois, sizeof(int), active_project -> atoms[i][j].numv, fp) != active_project -> atoms[i][j].numv) return ERROR_COORD;
78 }
79 }
80 if (fread (active_glwin -> bonds[i], sizeof(int), 2, fp) != 2) return ERROR_COORD;
81 active_glwin -> bondid[i] = g_malloc0 (2*sizeof*active_glwin -> bondid[i]);
82 for (j=0; j<2; j++)
83 {
84 if (active_glwin -> bonds[i][j])
85 {
86 active_glwin -> allbonds[j] += active_glwin -> bonds[i][j];
87 active_glwin -> bondid[i][j] = allocdint (active_glwin -> bonds[i][j], 2);
88 if (j) active_glwin -> clones[i] = g_malloc0(active_glwin -> bonds[i][1]*sizeof*active_glwin -> clones[i]);
89 for (k=0; k<active_glwin -> bonds[i][j]; k++)
90 {
91 if (fread (active_glwin -> bondid[i][j][k], sizeof(int), 2, fp) != 2) return ERROR_COORD;
92 if (j)
93 {
94 l = active_glwin -> bondid[i][j][k][0];
95 m = active_glwin -> bondid[i][j][k][1];
96 clo = distance_3d (active_cell, (active_cell -> npt) ? i : 0, & active_project -> atoms[i][l], & active_project -> atoms[i][m]);
97 active_glwin -> clones[i][k].x = clo.x;
98 active_glwin -> clones[i][k].y = clo.y;
99 active_glwin -> clones[i][k].z = clo.z;
100 }
101 }
102 }
103 }
104 }
105
106 for (i=0; i<2; i++)
107 {
108 coord -> ntg[i] = allocint(coord -> species);
109 if (fread (coord -> ntg[i], sizeof(int), coord -> species, fp) != coord -> species) return ERROR_COORD;
110 coord -> geolist[i] = g_malloc0 (coord -> species*sizeof*coord -> geolist[i]);
111 if (i == 1) coord -> partial_geo = g_malloc0 (coord -> species*sizeof*coord -> partial_geo);
112 for (j=0; j<coord -> species; j++)
113 {
114 coord -> geolist[i][j] = g_malloc0 (coord -> ntg[i][j]*sizeof*coord -> geolist[i][j]);
115 if (fread (coord -> geolist[i][j], sizeof(int), coord -> ntg[i][j], fp) != coord -> ntg[i][j]) return ERROR_COORD;
116 if (i == 1)
117 {
118 coord -> partial_geo[j] = g_malloc0 (coord -> ntg[i][j]*sizeof*coord -> partial_geo[j]);
119 for (k=0; k<coord -> ntg[i][j]; k++)
120 {
121 coord -> partial_geo[j][k] = g_malloc0 (coord -> species*sizeof*coord -> partial_geo[j][k]);
122 if (fread (coord -> partial_geo[j][k], sizeof(int), coord -> species, fp) != coord -> species) return ERROR_COORD;
123 }
124 }
125 }
126 }
127 coord -> cmax = 0;
128 coord -> cmin = 20;
129 for (i=0; i<coord -> species; i++)
130 {
131 for (j=0; j<coord -> ntg[1][i]; j++)
132 {
133 coord -> cmax = max(coord -> cmax, coord -> geolist[1][i][j]);
134 coord -> cmin = min(coord -> cmin, coord -> geolist[1][i][j]);
135 }
136 }
137 }
138
139 for (i=0; i<10; i++)
140 {
141 if (fread (& j, sizeof(int), 1, fp) != 1) return ERROR_COORD;
142 if (i < 2 && active_glwin -> bonding && j != active_project -> coord -> totcoord[i]) return ERROR_COORD;
143 if (i > 1 && i < 4 && active_glwin -> adv_bonding[i-2] && j != active_project -> coord -> totcoord[i]) return ERROR_COORD;
144 if (i < 2)
145 {
146 if (fread (img -> show_atom[i], sizeof(gboolean), active_project -> nspec, fp) != active_project -> nspec) return ERROR_COORD;
147 if (fread (img -> show_label[i], sizeof(gboolean), active_project -> nspec, fp) != active_project -> nspec) return ERROR_COORD;
148 }
149
150 if (active_project -> coord -> totcoord[i])
151 {
152 if (! img -> show_poly[i] && (i < 2 || (i > 3 && i < 9))) img -> show_poly[i] = allocbool(active_project -> coord -> totcoord[i]);
153 if (! img -> show_coord[i]) img -> show_coord[i] = allocbool(active_project -> coord -> totcoord[i]);
154 if (fread (img -> show_coord[i], sizeof(gboolean), active_project -> coord -> totcoord[i], fp) != active_project -> coord -> totcoord[i]) return ERROR_RW;
155 if (i < 2 || (i > 3 && i < 9))
156 {
157 if (fread (img -> show_poly[i], sizeof(gboolean), active_project -> coord -> totcoord[i], fp) != active_project -> coord -> totcoord[i]) return ERROR_RW;
158 }
159 }
160 }
161
162 if (! active_glwin -> bonding || ! active_glwin -> adv_bonding[1] || active_project -> natomes > ATOM_LIMIT || active_project -> steps > 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
178 return OK;
179}
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:576
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:330
gboolean * allocbool(int val)
allocate a gboolean * pointer
Definition global.c:254
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
Global variable declarations Global convenience function declarations Global data structure defin...
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:280
#define STEP_LIMIT
Definition global.h:277
#define OK
Definition global.h:279
#define min(a, b)
Definition global.h:81
#define ERROR_COORD
Definition global.h:288
project * active_project
Definition project.c:47
#define max(a, b)
Definition global.h:80
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:126
double y
Definition glwin.h:125
double x
Definition glwin.h:124
Definition glwin.h:277
GtkWidget * img
Definition workspace.c:70