atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
initmol.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
24/*
25* This file: 'initmol.c'
26*
27* Contains:
28*
29
30 - The functions to retrieve fragments data from Fortran90
31 - The functions to retrieve molecules data from Fortran90
32 - The functions to analyze molecule topology
33
34*
35* List of functions:
36
37 int * merge_mol_data (int val_a, int val_b, int table_a[val_a], int table_b[val_b]);
38
39 gboolean are_identical_molecules (search_molecule * mol_a, search_molecule * mol_b);
40
41 void duplicate_molecule (molecule * new_mol, search_molecule * old_mol);
42 void allocate_mol_for_step_ (int * sid, int * mol_in_step);
43 void allocate_mol_data_ ();
44 void send_mol_neighbors_ (int * stp, int * mol, int * aid, int * nvs, int neigh[* nvs]);
45 void update_mol_details (search_molecule * mol, int sp, int cp);
46 void send_mol_details_ (int * stp, int * mol, int * ats, int * sps, int spec_in_mol[* sps], int atom_in_mol[* ats]);
47 void free_search_molecule_data (search_molecule * smol);
48 void setup_molecules_ (int * stepid);
49 void setup_menu_molecules_ ();
50 void setup_fragments_ (int * sid, int coord[active_project -> natomes]);
51
52 search_molecule * duplicate_search_molecule (search_molecule * old_mol);
53
54*/
55
56#include "global.h"
57#include "interface.h"
58#include "bind.h"
59#include "color_box.h"
60#include "glwindow.h"
61#include "initcoord.h"
62
65{
66 int id; // Molecule id number
67 int md; // MD step
68 int multiplicity; // Multiplicity
69 int * fragments; // Fragments list
70 int natoms; // Number of atoms
71 int * atoms; // Temporary atom list
72 int nspec; // Number of chemical species
73 int * species; // Number of atom by species
74 int nbonds; // Number of chemical bonds
75 int ** pbonds; // Number of chemical bonds by geometries
76 int nangles; // Number of bond angles
77 int *** pangles; // Number of bond angles by geometries
78 int ** lgeo; // list of coordination spheres (by species)
81};
82
83int * pgeo;
86extern molecule * tmp_mol;
87
97{
98 new_mol -> id = old_mol -> id;
99 new_mol -> md = old_mol -> md;
100 new_mol -> multiplicity = old_mol -> multiplicity;
101 new_mol -> fragments = duplicate_int (old_mol -> multiplicity, old_mol -> fragments);
102 new_mol -> natoms = old_mol -> natoms;
103 new_mol -> nspec = old_mol -> nspec;
104 new_mol -> species = duplicate_int (active_project -> nspec, old_mol -> species);
105}
106
115{
116 search_molecule * new_mol = g_malloc0(sizeof*new_mol);
117 new_mol -> id = old_mol -> id;
118 new_mol -> md = old_mol -> md;
119 new_mol -> multiplicity = old_mol -> multiplicity;
120 new_mol -> fragments = duplicate_int (old_mol -> multiplicity, old_mol -> fragments);
121 new_mol -> natoms = old_mol -> natoms;
122 new_mol -> nspec = old_mol -> nspec;
123 new_mol -> species = duplicate_int (active_project -> nspec, old_mol -> species);
124 int j, k;
125 new_mol -> pbonds = g_malloc0 (active_project -> coord -> totcoord[1]*sizeof*new_mol -> pbonds);
126 new_mol -> pangles = g_malloc0 (active_project -> coord -> totcoord[1]*sizeof*new_mol -> pangles);
127 if (old_mol -> atoms)
128 {
129 new_mol -> atoms = duplicate_int (old_mol -> natoms*old_mol -> multiplicity, old_mol -> atoms);
130 }
131 new_mol -> nbonds = old_mol -> nbonds;
132 if (new_mol -> nbonds)
133 {
134 for (j=0; j<active_project -> coord -> totcoord[1]; j++)
135 {
136 new_mol -> pbonds[j] = duplicate_int (active_project -> coord -> totcoord[1], old_mol -> pbonds[j]);
137 }
138 new_mol -> nangles = old_mol -> nangles;
139 if (new_mol -> nangles)
140 {
141 for (j=0; j<active_project -> coord -> totcoord[1]; j++)
142 {
143 new_mol -> pangles[j] = g_malloc0 (active_project -> coord -> totcoord[1]*sizeof*new_mol -> pangles[j]);
144 for (k=0; k<active_project -> coord -> totcoord[1]; k++)
145 {
146 new_mol -> pangles[j][k] = duplicate_int (active_project -> coord -> totcoord[1], old_mol -> pangles[j][k]);
147 }
148 }
149 }
150 }
151 new_mol -> lgeo = g_malloc0 (active_project -> nspec*sizeof*new_mol -> lgeo);
152 for (j=0; j<active_project -> nspec; j++)
153 {
154 new_mol -> lgeo[j] = duplicate_int (active_project -> coord -> totcoord[1], old_mol -> lgeo[j]);
155 }
156 return new_mol;
157}
158
167void allocate_mol_for_step_ (int * sid, int * mol_in_step)
168{
169 in_calc_mol[* sid -1] = g_malloc0(* mol_in_step*sizeof*in_calc_mol[* sid -1]);
170 active_project -> modelfc -> mol_by_step[* sid - 1] = * mol_in_step;
171}
172
179{
180 int i;
181 if (active_project -> modelfc != NULL)
182 {
183 if (active_project -> modelfc -> mols != NULL)
184 {
185 g_free (active_project -> modelfc -> mols);
186 active_project -> modelfc -> mols = NULL;
187 }
188 active_project -> modelfc = NULL;
189 }
190 in_calc_mol = g_malloc0(active_project -> steps*sizeof*in_calc_mol);
191 active_project -> modelfc = g_malloc0 (sizeof*active_project -> modelfc);
192 active_project -> modelfc -> mols = g_malloc0(active_project -> steps*sizeof*active_project -> modelfc -> mols);
193 active_project -> modelfc -> mol_by_step = allocint (active_project -> steps);
194 for (i=0; i<2; i++)
195 {
196 if (active_project -> force_field[i]) g_free (active_project -> force_field[i]);
197 active_project -> force_field[i] = NULL;
198 }
199 pgeo = g_malloc0 ((active_project -> nspec+1)*sizeof*pgeo);
200 for (i=1; i<active_project -> nspec+1; i++)
201 {
202 pgeo[i] = pgeo[i-1] + active_coord -> ntg[1][i-1];
203 }
204}
205
217void send_mol_neighbors_ (int * stp, int * mol, int * aid, int * nvs, int neigh[* nvs])
218{
219 int i, j, k, l, m, n, o, p, q, r, s, t, u;
220 search_molecule * tmp_mol = & in_calc_mol[* stp - 1][* mol - 1];
221 i = active_project -> atoms[* stp - 1][* aid - 1].sp;
222 j = active_project -> atoms[* stp - 1][* aid - 1].coord[1];
223 k = pgeo[i] + j;
224 for (l=0; l < * nvs; l++)
225 {
226 m = neigh[l]-1;
227 n = active_project -> atoms[tmp_mol -> md][m].sp;
228 o = active_project -> atoms[tmp_mol -> md][m].coord[1];
229 p = pgeo[n] + o;
230 tmp_mol -> pbonds[k][p] ++;
231 }
232 if (* nvs > 1)
233 {
234 for (l=0; l<*nvs-1; l++)
235 {
236 m = neigh[l]-1;
237 n = active_project -> atoms[tmp_mol -> md][m].sp;
238 o = active_project -> atoms[tmp_mol -> md][m].coord[1];
239 p = pgeo[n] + o;
240 for (q= l+1; q<*nvs; q++)
241 {
242 r = neigh[q]-1;
243 s = active_project -> atoms[tmp_mol -> md][r].sp;
244 t = active_project -> atoms[tmp_mol -> md][r].coord[1];
245 u = pgeo[s] + t;
246 tmp_mol -> pangles[p][k][u] ++;
247 tmp_mol -> pangles[u][k][p] ++;
248 }
249 }
250 }
251}
252
262void update_mol_details (search_molecule * mol, int sp, int cp)
263{
264 int i, j, k, l, m;
265 for (i=0; i<active_project -> nspec; i++)
266 {
267 j = active_coord -> partial_geo[sp][cp][i];
268 mol -> nbonds += j;
269 if (j)
270 {
271 for (k=0; k<active_project -> nspec; k++)
272 {
273 l = active_coord -> partial_geo[sp][cp][k];
274 if (k != i || l > 1)
275 {
276 m = (j+l)*((j+l)-1)/2;
277 mol -> nangles += m;
278 }
279 }
280 }
281 }
282}
283
296void send_mol_details_ (int * stp, int * mol, int * ats, int * sps, int spec_in_mol[* sps], int atom_in_mol[* ats])
297{
298 int i, j, k, l;
299 search_molecule * tmp_mol = & in_calc_mol[* stp - 1][* mol - 1];
300 tmp_mol -> id = * mol - 1;
301 tmp_mol -> md = * stp - 1;
302 tmp_mol -> multiplicity = 1;
303 tmp_mol -> fragments = allocint(1);
304 tmp_mol -> fragments[0] = * mol - 1;
305 tmp_mol -> natoms = * ats;
306 tmp_mol -> lgeo = allocdint (active_project -> nspec, active_coord -> totcoord[1]);
307 tmp_mol -> pbonds = allocdint (active_coord -> totcoord[1], active_coord -> totcoord[1]);
308 tmp_mol -> pangles = alloctint (active_coord -> totcoord[1], active_coord -> totcoord[1], active_coord -> totcoord[1]);
309 tmp_mol -> atoms = duplicate_int (* ats, atom_in_mol);
310 for (i=0; i< * ats; i++)
311 {
312 j = atom_in_mol[i]-1;
313 k = active_project -> atoms[0][j].sp;
314 l = active_project -> atoms[* stp - 1][j].coord[1];
315 tmp_mol -> lgeo[k][pgeo[k]+l] ++;
317 }
318 j = 0;
319 for (i=0; i<active_project -> nspec; i++)
320 {
321 if (spec_in_mol[i] > 0) j++;
322 }
323 tmp_mol -> nspec = j;
324 tmp_mol -> species = duplicate_int (active_project -> nspec, spec_in_mol);
325 tmp_mol -> nbonds /= 2;
326 tmp_mol -> nangles /= 2;
327}
328
338{
339 int i, j, k;
340/*#ifdef DEBUG
341 g_debug ("AID:: mol_a -> id= %d, mol_b-> id= %d", mol_a -> id, mol_b -> id);
342 g_debug ("AID:: mol_a -> natoms= %d, mol_b-> natoms= %d", mol_a -> natoms, mol_b -> natoms);
343 g_debug ("AID:: mol_a -> nspec= %d, mol_b-> nspec= %d", mol_a -> nspec, mol_b -> nspec);
344 g_debug ("AID:: mol_a -> nbonds= %d, mol_b-> nbonds= %d", mol_a -> nbonds, mol_b -> nbonds);
345 g_debug ("AID:: mol_a -> nangles= %d, mol_b-> nangles= %d", mol_a -> nangles, mol_b -> nangles);
346#endif*/
347 if (mol_a -> md != mol_b -> md) return FALSE;
348 if (mol_a -> natoms != mol_b -> natoms) return FALSE;
349 if (mol_a -> nspec != mol_b -> nspec) return FALSE;
350 for (i=0; i < active_project -> nspec; i++)
351 {
352 if (mol_a -> species[i] != mol_b -> species[i]) return FALSE;
353 }
354
355 if (mol_a -> nbonds != mol_b -> nbonds) return FALSE;
356 if (mol_a -> nangles != mol_b -> nangles) return FALSE;
357
358 for (i=0; i < active_project -> nspec; i++)
359 {
360 for (j=0; j< active_coord -> totcoord[1]; j++)
361 {
362 if (mol_a -> lgeo[i][j] != mol_b -> lgeo[i][j]) return FALSE;
363 }
364 }
365
366 if (mol_a -> nbonds > 1)
367 {
368 for (i=0; i < active_coord -> totcoord[1]; i++)
369 {
370 for (j=0; j < active_coord -> totcoord[1]; j++)
371 {
372 if (mol_a -> pbonds[i][j] != mol_b -> pbonds[i][j]) return FALSE;
373 }
374 }
375 if (mol_a -> nangles > 1)
376 {
377 for (i=0; i < active_coord -> totcoord[1]; i++)
378 {
379 for (j=0; j < active_coord -> totcoord[1]; j++)
380 {
381 for (k=0; k < active_coord -> totcoord[1]; k++)
382 {
383 if (mol_a -> pangles[i][j][k] != mol_b -> pangles[i][j][k]) return FALSE;
384 }
385 }
386 }
387 }
388 }
389 return TRUE;
390}
391
402int * merge_mol_data (int val_a, int val_b, int table_a[val_a], int table_b[val_b])
403{
404 int * p_data;
405 int i;
406 p_data = allocint (val_a + val_b);
407 for (i=0; i<val_a; i++)
408 {
409 p_data[i] = table_a[i];
410 }
411 for (i=0; i<val_b; i++)
412 {
413 p_data[val_a+i] = table_b[i];
414 }
415 g_free (table_a);
416 return p_data;
417}
418
427{
428 int i, j;
429 g_free (smol -> atoms);
430 if (smol -> nbonds)
431 {
432 for (i=0; i<active_coord -> totcoord[1]; i++) g_free (smol -> pbonds[i]);
433 g_free (smol -> pbonds);
434 }
435 if (smol -> nangles)
436 {
437 for (i=0; i<active_coord -> totcoord[1]; i++)
438 {
439 for (j=0; j<active_coord -> totcoord[1]; j++) g_free (smol -> pangles[i][j]);
440 g_free (smol -> pangles[i]);
441 }
442 g_free (smol -> pangles);
443 }
444 for (i=0; i<active_project -> nspec; i++) g_free (smol -> lgeo[i]);
445 g_free (smol -> lgeo);
446 g_free (smol -> species);
447 g_free (smol -> fragments);
448}
449
457void setup_molecules_ (int * stepid)
458{
459 int i, j, k, l, m, n;
460 search_molecule * mtmp_at, * mtmp_bt;
461 search_molecule * first_mol = NULL;
463 gboolean add_it;
464 i = * stepid -1;
465 j = 0;
466 for (k=0; k<active_project -> modelfc -> mol_by_step[i]; k++)
467 {
468 mtmp_bt = & in_calc_mol[i][k];
469 add_it = TRUE;
470 mtmp_at = first_mol;
471 while (mtmp_at)
472 {
473 if (are_identical_molecules (mtmp_at, mtmp_bt))
474 {
475 mtmp_at -> fragments = merge_mol_data (mtmp_at -> multiplicity, mtmp_bt -> multiplicity,
476 mtmp_at -> fragments, mtmp_bt -> fragments);
477 mtmp_at -> atoms = merge_mol_data (mtmp_at -> natoms*mtmp_at -> multiplicity, mtmp_bt -> natoms*mtmp_bt -> multiplicity,
478 mtmp_at -> atoms, mtmp_bt -> atoms);
479 mtmp_at -> multiplicity ++;
480 add_it = FALSE;
481 break;
482 }
483 mtmp_at = mtmp_at -> next;
484 }
485 if (add_it)
486 {
487 if (first_mol)
488 {
489 mtmp_at = first_mol;
490 while (mtmp_at -> next) mtmp_at = mtmp_at -> next;
491 mtmp_at -> next = duplicate_search_molecule (mtmp_bt);
492 mtmp_at -> next -> prev = mtmp_at;
493 }
494 else
495 {
496 first_mol = duplicate_search_molecule (mtmp_bt);
497 }
498 j ++;
499 }
501 }
502 g_free (in_calc_mol[i]);
503 in_calc_mol[i] = NULL;
504 active_project -> modelfc -> mol_by_step[i] = j;
505 active_project -> modelfc -> mols[i] = g_malloc0(j*sizeof*active_project -> modelfc -> mols[i]);
506 tmp_mol = first_mol;
507 for (k=0; k<j; k++)
508 {
509 l = tmp_mol -> natoms*tmp_mol -> multiplicity;
510 for (m=0; m<l; m++)
511 {
512 n = tmp_mol -> atoms[m] - 1;
513 active_project -> atoms[i][n].coord[3] = k;
514 }
515 duplicate_molecule (& active_project -> modelfc -> mols[i][k], tmp_mol);
516 active_project -> modelfc -> mols[i][k].id = k;
518 if (k < j-1) tmp_mol = tmp_mol -> next;
519 }
520 while (tmp_mol -> prev)
521 {
522 tmp_mol = tmp_mol -> prev;
523 g_free (tmp_mol -> next);
524 }
525 g_free (first_mol);
526}
527
534{
535 int i, j;
536 g_free (in_calc_mol);
537 in_calc_mol = NULL;
538 g_free (pgeo);
539 pgeo = NULL;
540 i = 0;
541 for (j=0; j<active_project -> steps; j++)
542 {
543 i = max (i, active_project -> modelfc -> mol_by_step[j]);
544 }
545 active_coord -> totcoord[3] = i;
546 i = 3;
547 init_menu_fragmol_ (& i);
548}
549
558void setup_fragments_ (int * sid, int coord[active_project -> natomes])
559{
560 int i;
561 for (i=0; i < active_project -> natomes; i++)
562 {
563 active_project -> atoms[* sid-1][i].coord[2] = coord[i] - 1;
564 }
565}
insertion_menu mol[]
Definition w_library.c:193
Binding to the Fortran90 subroutines.
Structure definitions for color management Function declarations for color management.
int atoms[NUM_STYLES][2]
int *** nbonds[NUM_STYLES][2]
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:560
int * new_mol
Definition dlp_mol.c:59
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:330
int *** alloctint(int xal, int yal, int zal)
allocate an int *** pointer
Definition global.c:353
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
Global variable declarations Global convenience function declarations Global data structure defin...
coord_info * active_coord
Definition project.c:49
project * active_project
Definition project.c:47
#define max(a, b)
Definition global.h:80
Function declarations for the creation of the OpenGL window.
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.
void setup_molecules_(int *stepid)
setup molecule data
Definition initmol.c:457
int * pgeo
Definition initmol.c:83
void allocate_mol_data_()
allocate data to store molecule information
Definition initmol.c:178
void free_search_molecule_data(search_molecule *smol)
free search molecule data structure
Definition initmol.c:426
void setup_menu_molecules_()
prepare the menu elements related to molecule(s)
Definition initmol.c:533
int * merge_mol_data(int val_a, int val_b, int table_a[val_a], int table_b[val_b])
merge molecule a and molecule b data
Definition initmol.c:402
gboolean are_identical_molecules(search_molecule *mol_a, search_molecule *mol_b)
test if 2 molecules are identicals
Definition initmol.c:337
search_molecule ** in_calc_mol
Definition initmol.c:85
void update_mol_details(search_molecule *mol, int sp, int cp)
update molecule information
Definition initmol.c:262
void send_mol_details_(int *stp, int *mol, int *ats, int *sps, int spec_in_mol[*sps], int atom_in_mol[*ats])
overall molecule information from Fortran90
Definition initmol.c:296
void send_mol_neighbors_(int *stp, int *mol, int *aid, int *nvs, int neigh[*nvs])
update molecule typology information from Fortran90
Definition initmol.c:217
search_molecule * duplicate_search_molecule(search_molecule *old_mol)
create a copy of a search molecule data structure
Definition initmol.c:114
void setup_fragments_(int *sid, int coord[active_project -> natomes])
Definition initmol.c:558
search_molecule * tmp_search
Definition initmol.c:84
void duplicate_molecule(molecule *new_mol, search_molecule *old_mol)
create a copy of a molecule data structure
Definition initmol.c:96
molecule * tmp_mol
Definition dlp_field.c:956
void allocate_mol_for_step_(int *sid, int *mol_in_step)
allocate the data to store molecule information for a MD step
Definition initmol.c:167
Messaging function declarations.
coord_info * coord
Definition global.h:956
int id
Definition global.h:941
int ** pbonds
Definition initmol.c:75
int * fragments
Definition initmol.c:69
int *** pangles
Definition initmol.c:77
search_molecule * prev
Definition initmol.c:80
search_molecule * next
Definition initmol.c:79
int ** lgeo
Definition initmol.c:78
int * species
Definition initmol.c:73