atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
read_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: 'read_mol.c'
24*
25* Contains:
26*
27
28 - The functions to read molecule(s) data in the atomes project file format
29
30*
31* List of functions:
32
33 int read_atom_m (FILE * fp, int s, int a);
34 int read_this_mol (FILE * fp, molecule * tmp);
35 int read_mol (FILE * fp);
36
37*/
38
39#include "global.h"
40#include "project.h"
41#include "initcoord.h"
42#include "submenus.h"
43
44extern void duplicate_molecule (molecule * new_mol, molecule * old_mol);
45
55int read_atom_m (FILE * fp, int s, int a)
56{
57 if (fread (& active_project -> atoms[s][a].coord[2], sizeof(int), 1, fp) != 1) return ERROR_RW;
58 if (fread (& active_project -> atoms[s][a].coord[3], sizeof(int), 1, fp) != 1) return ERROR_RW;
59 return OK;
60}
61
70int read_this_mol (FILE * fp, molecule * tmp)
71{
72 if (fread (& tmp -> id, sizeof(int), 1, fp) != 1) return 0;
73 if (fread (& tmp -> md, sizeof(int), 1, fp) != 1) return 0;
74 if (fread (& tmp -> multiplicity, sizeof(int), 1, fp) != 1) return 0;
75 if (! tmp -> multiplicity) return 0;
76 tmp -> fragments = allocint(tmp -> multiplicity);
77 if (fread (tmp -> fragments, sizeof(int), tmp -> multiplicity, fp) != tmp -> multiplicity) return 0;
78 if (fread (& tmp -> natoms, sizeof(int), 1, fp) != 1) return 0;
79 if (fread (& tmp -> nspec, sizeof(int), 1, fp) != 1) return 0;
80 tmp -> species = allocint(active_project -> nspec);
81 if (fread (tmp -> species, sizeof(int), active_project -> nspec, fp) != active_project -> nspec) return 0;
82 return 1;
83}
84
92int read_mol (FILE * fp)
93{
94 int i, j;
95 if (fread (& i, sizeof(int), 1, fp) != 1) return ERROR_MOL;
96 if (! i) return OK;
97 active_project -> modelfc = g_malloc0 (sizeof*active_project -> modelfc);
98 for (i=1; i<4; i++)
99 {
100 if (fread (& j, sizeof(int), 1, fp) != 1) return ERROR_MOL;
101 if (i == 1 && j != active_coord -> totcoord[1]) return ERROR_MOL;
102 if (i > 1) active_coord -> totcoord[i] = j;
103 }
104 active_project -> modelfc -> mol_by_step = allocint(active_project -> steps);
105 if (fread (active_project -> modelfc -> mol_by_step, sizeof(int), active_project -> steps, fp) != active_project -> steps) return ERROR_MOL;
106 active_project -> modelfc -> mols = g_malloc0 (active_project -> steps*sizeof*active_project -> modelfc -> mols);
107 for (i=0; i<active_project -> steps; i++)
108 {
109 active_project -> modelfc -> mols[i] = g_malloc0 (active_project -> modelfc -> mol_by_step[i]*sizeof*active_project -> modelfc -> mols[i]);
110 }
111
112 molecule * tmp = g_malloc0(sizeof*tmp);
113 for (i=0; i<active_project -> steps; i++)
114 {
115 for (j=0; j<active_project -> modelfc -> mol_by_step[i]; j++)
116 {
117 if (! read_this_mol(fp, & active_project -> modelfc -> mols[i][j])) return ERROR_MOL;
118 }
119 }
120 for (i=0; i<active_project -> steps; i++)
121 {
122 for (j=0; j< active_project -> natomes; j++)
123 {
124 if (read_atom_m (fp, i, j) != OK) return ERROR_MOL;
125 }
126 }
127
128#ifdef GTK3
129 // Now recreate menus
130 for (i=2; i<4; i++)
131 {
132 init_opengl_coords (i, active_coord -> totcoord[i], 1);
133 init_menu_fragmol_ (& i);
134 active_glwin -> adv_bonding[i-2] = TRUE;
135 for (j=2; j<4; j++)
136 {
137 detach_frag_mol_menu (active_glwin, i, j);
138 }
139
140 active_glwin -> ogl_coord[i+1] = destroy_this_widget (active_glwin -> ogl_coord[i+1]);
141 if (i == 2) active_glwin -> ogl_coord[3] = menu_item_new_with_submenu ("Fragment(s)", active_project -> coord -> totcoord[2], add_menu_coord (active_glwin, 0, 2));
142 if (i == 3) active_glwin -> ogl_coord[4] = menu_item_new_with_submenu ("Molecule(s)", active_project -> coord -> totcoord[2], add_menu_coord (active_glwin, 0, 3));
143 GtkWidget * cmenu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (active_glwin -> ogl_coord[0]));
144 gtk_menu_shell_insert (GTK_MENU_SHELL(cmenu), active_glwin -> ogl_coord[i+1], i+2);
145 }
146#endif
147 return OK;
148}
int atoms[NUM_STYLES][2]
int * new_mol
Definition dlp_mol.c:59
FILE * fp
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
coord_info * active_coord
Definition project.c:49
#define ERROR_RW
Definition global.h:280
#define OK
Definition global.h:279
GtkWidget * destroy_this_widget(GtkWidget *widg)
destroy a GtkWidget
Definition gtk-misc.c:2034
#define ERROR_MOL
GtkWidget * menu_item_new_with_submenu(gchar *name, gboolean active, GtkWidget *sub_menu)
project * active_project
Definition project.c:47
void init_opengl_coords(int id, int nt, int init)
initialize data to store the coordination data
Definition initcoord.c:659
void init_menu_fragmol_(int *id)
getting fragment(s)/molecule(s) data from Fortran90, and related GTK3 menu elements creation
Definition initcoord.c:478
Function declarations to handle the atomic coordination data.
GMenu * add_menu_coord(glwin *view, int popm, int id)
create a coordination type submenu
Definition m_coord.c:652
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int read_mol(FILE *fp)
read molecule(s) information from file
Definition read_mol.c:92
int read_this_mol(FILE *fp, molecule *tmp)
read molecule data
Definition read_mol.c:70
int read_atom_m(FILE *fp, int s, int a)
read atom fragment and molecule data
Definition read_mol.c:55
void duplicate_molecule(molecule *new_mol, molecule *old_mol)
Function declarations for the creation of the OpenGL window menus.
int a
Definition tab-1.c:95