atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
atom_species.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: 'atom_species.c'
24*
25* Contains:
26*
27
28 - The functions to look for new chemical species and modify the chemical information accordingly
29
30*
31* List of functions:
32
33 int find_spec_id (int s, int z, double * list_z);
34 int search_for_new_spec (atom_edition * edit, atomic_object * object);
35
36 chemical_data * duplicate_chemical_data (int spec, chemical_data * chem);
37
38*/
39
40#include "atom_edit.h"
41
51{
52 chemical_data * newchem = g_malloc0 (sizeof*chem);
53 newchem -> label = g_malloc (spec*sizeof*newchem -> label);
54 newchem -> element = g_malloc (spec*sizeof*newchem -> element);
55 int i, j;
56 for (i=0; i<spec; i++)
57 {
58 newchem -> label[i] = g_strdup_printf ("%s", chem -> label[i]);
59 newchem -> element[i] = g_strdup_printf ("%s", chem -> element[i]);
60 }
61 newchem -> nsps = duplicate_int (spec, chem -> nsps);
62 newchem -> formula = duplicate_int (spec, chem -> formula);
63 newchem -> cutoffs = allocddouble (spec, spec);
64 newchem -> grtotcutoff = chem -> grtotcutoff;
65 newchem -> chem_prop = allocddouble (CHEM_PARAMS, spec);
66 for (i=0; i<spec; i++)
67 {
68 for (j=0; j<spec; j++) newchem -> cutoffs[i][j] = chem -> cutoffs[i][j];
69 for (j=0; j<CHEM_PARAMS; j++) newchem -> chem_prop[j][i] = chem -> chem_prop[j][i];
70 }
71 return newchem;
72}
73
83int find_spec_id (int s, int z, double * list_z)
84{
85 int i;
86 if (list_z)
87 {
88 for (i=0; i<s; i++)
89 {
90 if (list_z[i] == (double)z)
91 {
92 return i;
93 }
94 }
95 }
96 return -1;
97}
98
108{
109 coord_info * coord = edit -> coord;
110 int i, j, k, l, m;
111 i = 0;
112 for (j=0; j<object -> species; j++)
113 {
114 if (object -> old_z[j] > 0)
115 {
116 k = find_spec_id (coord -> species, object -> old_z[j], edit -> new_z);
117 if (k < 0)
118 {
119 i ++;
120 edit -> new_z = g_realloc (edit -> new_z, (coord -> species+i)*sizeof*edit -> new_z);
121 edit -> new_z[coord -> species+i-1] = (double)object -> old_z[j];
122 }
123 }
124 }
125
126 if (i)
127 {
128 coord_info * tmp = duplicate_coord_info (edit -> coord);
129 for (j=0; j<2; j++)
130 {
131 if (coord -> species)
132 {
133 g_free (coord -> ntg[j]);
134 g_free (coord -> geolist[j]);
135 }
136 coord -> ntg[j] = allocint (coord -> species + i);
137 coord -> geolist[j] = g_malloc0 ((coord -> species + i)*sizeof* coord -> geolist[j]);
138 if (j)
139 {
140 if (coord -> species) g_free (coord -> partial_geo);
141 coord -> partial_geo = g_malloc0 ((coord -> species + i)*sizeof*coord -> partial_geo);
142 }
143 for (k=0; k<coord -> species; k++)
144 {
145 coord -> ntg[j][k] = tmp -> ntg[j][k];
146 coord -> geolist[j][k] = duplicate_int (tmp -> ntg[j][k], tmp -> geolist[j][k]);
147 if (j)
148 {
149 coord -> partial_geo[k] = allocdint (coord -> ntg[j][k], coord -> species + i);
150 for (l=0; l<tmp -> ntg[j][k]; l++)
151 {
152 for (m=0; m<coord -> species; m++)
153 {
154 coord -> partial_geo[k][l][m] = tmp -> partial_geo[k][l][m];
155 }
156 }
157 }
158 }
159 }
160 coord -> species += i;
161 g_free (tmp);
162 }
163 return i;
164}
coord_info * duplicate_coord_info(coord_info *old_coord)
duplicate coordination information data structure
Definition atom_coord.c:190
Function declarations for the mode edition window.
chemical_data * duplicate_chemical_data(int spec, chemical_data *chem)
duplicate chemical data information
int find_spec_id(int s, int z, double *list_z)
find species id based on Z
int search_for_new_spec(atom_edition *edit, atomic_object *object)
search for new chemical species
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:560
int ** allocdint(int xal, int yal)
allocate an int ** pointer
Definition global.c:330
double ** allocddouble(int xal, int yal)
allocate a double ** pointer
Definition global.c:475
int * allocint(int val)
allocate an int * pointer
Definition global.c:314
#define CHEM_PARAMS
Definition global.h:296
double z
Definition ogl_draw.c:57
int element
Definition w_periodic.c:61