atomes 1.3.1
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-2026 by CNRS and University of Strasbourg */
15
23
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 if (old_mol -> natoms > 1)
126 {
127 new_mol -> pbonds = g_malloc0(active_project -> coord -> totcoord[1]*sizeof*new_mol -> pbonds);
128 if (old_mol -> natoms > 2)
129 {
130 new_mol -> pangles = g_malloc0(active_project -> coord -> totcoord[1]*sizeof*new_mol -> pangles);
131 }
132 }
133 if (old_mol -> atoms)
134 {
135 new_mol -> atoms = duplicate_int (old_mol -> natoms*old_mol -> multiplicity, old_mol -> atoms);
136 }
137 new_mol -> nbonds = old_mol -> nbonds;
138 if (new_mol -> nbonds)
139 {
140 for (j=0; j<active_project -> coord -> totcoord[1]; j++)
141 {
142 new_mol -> pbonds[j] = duplicate_int (active_project -> coord -> totcoord[1], old_mol -> pbonds[j]);
143 }
144 new_mol -> nangles = old_mol -> nangles;
145 if (new_mol -> nangles)
146 {
147 for (j=0; j<active_project -> coord -> totcoord[1]; j++)
148 {
149 new_mol -> pangles[j] = g_malloc0(active_project -> coord -> totcoord[1]*sizeof*new_mol -> pangles[j]);
150 for (k=0; k<active_project -> coord -> totcoord[1]; k++)
151 {
152 new_mol -> pangles[j][k] = duplicate_int (active_project -> coord -> totcoord[1], old_mol -> pangles[j][k]);
153 }
154 }
155 }
156 }
157 new_mol -> lgeo = g_malloc0(active_project -> nspec*sizeof*new_mol -> lgeo);
158 for (j=0; j<active_project -> nspec; j++)
159 {
160 new_mol -> lgeo[j] = duplicate_int (active_project -> coord -> totcoord[1], old_mol -> lgeo[j]);
161 }
162 return new_mol;
163}
164
173void allocate_mol_for_step_ (int * sid, int * mol_in_step)
174{
175 in_calc_mol[* sid -1] = g_malloc0(* mol_in_step*sizeof*in_calc_mol[* sid -1]);
176 active_project -> modelfc -> mol_by_step[* sid - 1] = * mol_in_step;
177}
178
185{
186 int i;
187 if (active_project -> modelfc != NULL)
188 {
189 if (active_project -> modelfc -> mols != NULL)
190 {
191 g_free (active_project -> modelfc -> mols);
192 active_project -> modelfc -> mols = NULL;
193 }
194 active_project -> modelfc = NULL;
195 }
196 in_calc_mol = g_malloc0(active_project -> steps*sizeof*in_calc_mol);
197 active_project -> modelfc = g_malloc0(sizeof*active_project -> modelfc);
198 active_project -> modelfc -> mols = g_malloc0(active_project -> steps*sizeof*active_project -> modelfc -> mols);
199 active_project -> modelfc -> mol_by_step = allocint (active_project -> steps);
200 for (i=0; i<2; i++)
201 {
202 if (active_project -> force_field[i]) g_free (active_project -> force_field[i]);
203 active_project -> force_field[i] = NULL;
204 }
205 pgeo = g_malloc0((active_project -> nspec+1)*sizeof*pgeo);
206 for (i=1; i<active_project -> nspec+1; i++)
207 {
208 pgeo[i] = pgeo[i-1] + active_coord -> ntg[1][i-1];
209 }
210}
211
223void send_mol_neighbors_ (int * stp, int * mol, int * aid, int * nvs, int neigh[* nvs])
224{
225 int i, j, k, l, m, n, o, p, q, r, s, t, u;
226 search_molecule * tmp_mol = & in_calc_mol[* stp - 1][* mol - 1];
227 i = active_project -> atoms[* stp - 1][* aid - 1].sp;
228 j = active_project -> atoms[* stp - 1][* aid - 1].coord[1];
229 k = pgeo[i] + j;
230 for (l=0; l < * nvs; l++)
231 {
232 m = neigh[l]-1;
233 n = active_project -> atoms[tmp_mol -> md][m].sp;
234 o = active_project -> atoms[tmp_mol -> md][m].coord[1];
235 p = pgeo[n] + o;
236 tmp_mol -> pbonds[k][p] ++;
237 }
238 if (* nvs > 1)
239 {
240 for (l=0; l<*nvs-1; l++)
241 {
242 m = neigh[l]-1;
243 n = active_project -> atoms[tmp_mol -> md][m].sp;
244 o = active_project -> atoms[tmp_mol -> md][m].coord[1];
245 p = pgeo[n] + o;
246 for (q= l+1; q<*nvs; q++)
247 {
248 r = neigh[q]-1;
249 s = active_project -> atoms[tmp_mol -> md][r].sp;
250 t = active_project -> atoms[tmp_mol -> md][r].coord[1];
251 u = pgeo[s] + t;
252 tmp_mol -> pangles[p][k][u] ++;
253 tmp_mol -> pangles[u][k][p] ++;
254 }
255 }
256 }
257}
258
268void update_mol_details (search_molecule * mol, int sp, int cp)
269{
270 int i, j, k, l, m;
271 for (i=0; i<active_project -> nspec; i++)
272 {
273 j = active_coord -> partial_geo[sp][cp][i];
274 mol -> nbonds += j;
275 if (j && mol -> natoms > 2)
276 {
277 for (k=0; k<active_project -> nspec; k++)
278 {
279 l = active_coord -> partial_geo[sp][cp][k];
280 if (k != i || l > 1)
281 {
282 m = (j+l)*((j+l)-1)/2;
283 mol -> nangles += m;
284 }
285 }
286 }
287 }
288}
289
302void send_mol_details_ (int * stp, int * mol, int * ats, int * sps, int spec_in_mol[* sps], int atom_in_mol[* ats])
303{
304 int i, j, k, l;
305 search_molecule * tmp_mol = & in_calc_mol[* stp - 1][* mol - 1];
306 tmp_mol -> id = * mol - 1;
307 tmp_mol -> md = * stp - 1;
308 tmp_mol -> multiplicity = 1;
309 tmp_mol -> fragments = allocint (1);
310 tmp_mol -> fragments[0] = * mol - 1;
311 tmp_mol -> natoms = * ats;
312 tmp_mol -> lgeo = allocdint (active_project -> nspec, active_coord -> totcoord[1]);
313 if (tmp_mol -> natoms > 1)
314 {
315 tmp_mol -> pbonds = allocdint (active_coord -> totcoord[1], active_coord -> totcoord[1]);
316 if (tmp_mol -> natoms > 2)
317 {
318 tmp_mol -> pangles = alloctint (active_coord -> totcoord[1], active_coord -> totcoord[1], active_coord -> totcoord[1]);
319 }
320 }
321 tmp_mol -> atoms = duplicate_int (* ats, atom_in_mol);
322 for (i=0; i< * ats; i++)
323 {
324 j = atom_in_mol[i]-1;
325 k = active_project -> atoms[0][j].sp;
326 l = active_project -> atoms[* stp - 1][j].coord[1];
327 tmp_mol -> lgeo[k][pgeo[k]+l] ++;
329 }
330 j = 0;
331 for (i=0; i<active_project -> nspec; i++)
332 {
333 if (spec_in_mol[i] > 0) j++;
334 }
335 tmp_mol -> nspec = j;
336 tmp_mol -> species = duplicate_int (active_project -> nspec, spec_in_mol);
337 tmp_mol -> nbonds /= 2;
338 tmp_mol -> nangles /= 2;
339}
340
350{
351 int i, j, k;
352/*#ifdef DEBUG
353 g_debug ("AID:: mol_a -> id= %d, mol_b-> id= %d", mol_a -> id, mol_b -> id);
354 g_debug ("AID:: mol_a -> natoms= %d, mol_b-> natoms= %d", mol_a -> natoms, mol_b -> natoms);
355 g_debug ("AID:: mol_a -> nspec= %d, mol_b-> nspec= %d", mol_a -> nspec, mol_b -> nspec);
356 g_debug ("AID:: mol_a -> nbonds= %d, mol_b-> nbonds= %d", mol_a -> nbonds, mol_b -> nbonds);
357 g_debug ("AID:: mol_a -> nangles= %d, mol_b-> nangles= %d", mol_a -> nangles, mol_b -> nangles);
358#endif*/
359 if (mol_a -> md != mol_b -> md) return FALSE;
360 if (mol_a -> natoms != mol_b -> natoms) return FALSE;
361 if (mol_a -> nspec != mol_b -> nspec) return FALSE;
362 for (i=0; i < active_project -> nspec; i++)
363 {
364 if (mol_a -> species[i] != mol_b -> species[i]) return FALSE;
365 }
366
367 if (mol_a -> nbonds != mol_b -> nbonds) return FALSE;
368 if (mol_a -> nangles != mol_b -> nangles) return FALSE;
369
370 for (i=0; i < active_project -> nspec; i++)
371 {
372 for (j=0; j< active_coord -> totcoord[1]; j++)
373 {
374 if (mol_a -> lgeo[i][j] != mol_b -> lgeo[i][j]) return FALSE;
375 }
376 }
377
378 if (mol_a -> nbonds > 1)
379 {
380 for (i=0; i < active_coord -> totcoord[1]; i++)
381 {
382 for (j=0; j < active_coord -> totcoord[1]; j++)
383 {
384 if (mol_a -> pbonds[i][j] != mol_b -> pbonds[i][j]) return FALSE;
385 }
386 }
387 if (mol_a -> nangles > 1)
388 {
389 for (i=0; i < active_coord -> totcoord[1]; i++)
390 {
391 for (j=0; j < active_coord -> totcoord[1]; j++)
392 {
393 for (k=0; k < active_coord -> totcoord[1]; k++)
394 {
395 if (mol_a -> pangles[i][j][k] != mol_b -> pangles[i][j][k]) return FALSE;
396 }
397 }
398 }
399 }
400 }
401 return TRUE;
402}
403
414int * merge_mol_data (int val_a, int val_b, int table_a[val_a], int table_b[val_b])
415{
416 int * p_data;
417 int i;
418 p_data = allocint (val_a + val_b);
419 for (i=0; i<val_a; i++)
420 {
421 p_data[i] = table_a[i];
422 }
423 for (i=0; i<val_b; i++)
424 {
425 p_data[val_a+i] = table_b[i];
426 }
427 return p_data;
428}
429
438{
439 int i, j;
440 if (smol -> atoms)
441 {
442 g_free (smol -> atoms);
443 smol -> atoms = NULL;
444 }
445 if (smol -> pbonds)
446 {
447 for (i=0; i<active_coord -> totcoord[1]; i++)
448 {
449 if (smol -> pbonds[i])
450 {
451 g_free (smol -> pbonds[i]);
452 smol -> pbonds[i] = NULL;
453 }
454 }
455 g_free (smol -> pbonds);
456 smol -> pbonds = NULL;
457 }
458 if (smol -> pangles)
459 {
460 for (i=0; i<active_coord -> totcoord[1]; i++)
461 {
462 if (smol -> pangles[i])
463 {
464 for (j=0; j<active_coord -> totcoord[1]; j++)
465 {
466 if (smol -> pangles[i][j])
467 {
468 g_free (smol -> pangles[i][j]);
469 smol -> pangles[i][j] = NULL;
470 }
471 }
472 g_free (smol -> pangles[i]);
473 smol -> pangles[i] = NULL;
474 }
475 }
476 g_free (smol -> pangles);
477 smol -> pangles = NULL;
478 }
479 if (smol -> lgeo)
480 {
481 for (i=0; i<active_project -> nspec; i++)
482 {
483 if (smol -> lgeo[i])
484 {
485 g_free (smol -> lgeo[i]);
486 smol -> lgeo[i] = NULL;
487 }
488 }
489 g_free (smol -> lgeo);
490 smol -> lgeo = NULL;
491 }
492 g_free (smol -> species);
493 smol -> species = NULL;
494 g_free (smol -> fragments);
495 smol -> fragments = NULL;
496}
497
505void setup_molecules_ (int * stepid)
506{
507 int i, j, k, l, m, n;
508 search_molecule * mtmp_at, * mtmp_bt;
509 search_molecule * first_mol = NULL;
511 gboolean add_it;
512 int * tmp_data;
513 i = * stepid -1;
514 j = 0;
515 for (k=0; k<active_project -> modelfc -> mol_by_step[i]; k++)
516 {
517 mtmp_bt = & in_calc_mol[i][k];
518 add_it = TRUE;
519 mtmp_at = (first_mol) ? first_mol : NULL;
520 while (mtmp_at)
521 {
522 if (are_identical_molecules (mtmp_at, mtmp_bt))
523 {
524 tmp_data = merge_mol_data (mtmp_at -> multiplicity, mtmp_bt -> multiplicity, mtmp_at -> fragments, mtmp_bt -> fragments);
525 g_free (mtmp_at -> fragments);
526 mtmp_at -> fragments = NULL;
527 mtmp_at -> fragments = duplicate_int (mtmp_at -> multiplicity+mtmp_bt -> multiplicity, tmp_data);
528 g_free (tmp_data);
529 tmp_data = merge_mol_data (mtmp_at -> natoms*mtmp_at -> multiplicity, mtmp_bt -> natoms*mtmp_bt -> multiplicity, mtmp_at -> atoms, mtmp_bt -> atoms);
530 g_free (mtmp_at -> atoms);
531 mtmp_at -> atoms = NULL;
532 mtmp_at -> atoms = duplicate_int (mtmp_at -> natoms*mtmp_at -> multiplicity+mtmp_bt -> natoms*mtmp_bt -> multiplicity, tmp_data);
533 g_free (tmp_data);
534 mtmp_at -> multiplicity ++;
535 add_it = FALSE;
536 break;
537 }
538 mtmp_at = mtmp_at -> next;
539 }
540 if (add_it)
541 {
542 if (first_mol)
543 {
544 mtmp_at = first_mol;
545 while (mtmp_at -> next) mtmp_at = mtmp_at -> next;
546 mtmp_at -> next = duplicate_search_molecule (mtmp_bt);
547 mtmp_at -> next -> prev = mtmp_at;
548 }
549 else
550 {
551 first_mol = duplicate_search_molecule (mtmp_bt);
552 mtmp_at = first_mol;
553 }
554 j ++;
555 }
556 }
557 for (k=0; k<active_project -> modelfc -> mol_by_step[i]; k++)
558 {
560 }
561 g_free (in_calc_mol[i]);
562 in_calc_mol[i] = NULL;
563 active_project -> modelfc -> mol_by_step[i] = j;
564 active_project -> modelfc -> mols[i] = g_malloc0(j*sizeof*active_project -> modelfc -> mols[i]);
565 tmp_mol = first_mol;
566 for (k=0; k<j; k++)
567 {
568 l = tmp_mol -> natoms*tmp_mol -> multiplicity;
569 for (m=0; m<l; m++)
570 {
571 n = tmp_mol -> atoms[m] - 1;
572 active_project -> atoms[i][n].coord[3] = k;
573 }
574 duplicate_molecule (& active_project -> modelfc -> mols[i][k], tmp_mol);
575 active_project -> modelfc -> mols[i][k].id = k;
576 if (k < j-1) tmp_mol = tmp_mol -> next;
577 }
578 tmp_mol = first_mol;
579 while (tmp_mol)
580 {
582 if (tmp_mol -> next)
583 {
584 tmp_mol = tmp_mol -> next;
585 g_free (tmp_mol -> prev);
586 }
587 else
588 {
589 g_free (tmp_mol);
590 tmp_mol = NULL;
591 }
592 }
593}
594
601{
602 int i, j;
603 g_free (in_calc_mol);
604 in_calc_mol = NULL;
605 g_free (pgeo);
606 pgeo = NULL;
607 i = 0;
608 for (j=0; j<active_project -> steps; j++)
609 {
610 i = max (i, active_project -> modelfc -> mol_by_step[j]);
611 }
612 active_coord -> totcoord[3] = i;
613 i = 3;
614 init_menu_fragmol_ (& i);
615}
616
625void setup_fragments_ (int * sid, int coord[active_project -> natomes])
626{
627 int i;
628 for (i=0; i < active_project -> natomes; i++)
629 {
630 active_project -> atoms[* sid-1][i].coord[2] = coord[i] - 1;
631 }
632}
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]
molecule * tmp_mol
Definition dlp_field.c:1046
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:547
int * new_mol
Definition dlp_mol.c:59
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:317
int *** alloctint(int xal, int yal, int zal)
allocate an int *** pointer
Definition global.c:340
int * allocint(int val)
allocate an int * pointer
Definition global.c:301
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:92
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:480
Function declarations to handle the atomic coordination data.
void setup_molecules_(int *stepid)
setup molecule data
Definition initmol.c:505
int * pgeo
Definition initmol.c:83
void allocate_mol_data_()
allocate data to store molecule information
Definition initmol.c:184
void free_search_molecule_data(search_molecule *smol)
free search molecule data structure
Definition initmol.c:437
void setup_menu_molecules_()
prepare the menu elements related to molecule(s)
Definition initmol.c:600
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:414
gboolean are_identical_molecules(search_molecule *mol_a, search_molecule *mol_b)
test if 2 molecules are identicals
Definition initmol.c:349
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:268
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:302
void send_mol_neighbors_(int *stp, int *mol, int *aid, int *nvs, int neigh[*nvs])
update molecule typology information from Fortran90
Definition initmol.c:223
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:625
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
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:173
Messaging function declarations.
float * tmp_data
Definition m_map.c:90
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