atomes 1.1.14
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
dlp_copy.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: 'dlp_copy.c'
24*
25* Contains:
26*
27
28 - The functions to copy force field and related data structures
29
30*
31* List of functions:
32
33 gboolean check_this_other_prop (int oid, int nat, field_prop * other);
34
35 void duplicate_other_prop (int oid, field_struct * old_fstr, field_struct * new_fstr);
36 void duplicate_nbody_params (field_nth_body * new_fbody, field_nth_body * old_fbody);
37
38 field_atom* duplicate_field_atom (field_atom* old_fat);
39 field_shell * duplicate_field_shell (field_shell * old_shell);
40 field_constraint * duplicate_field_constraint (field_constraint * old_cons);
41 field_pmf * duplicate_field_pmf (field_pmf * old_pmf);
42 field_rigid * duplicate_field_rigid (field_rigid * old_rig);
43 field_tethered * duplicate_field_tethered (field_tethered * old_tet);
44 field_prop * duplicate_field_prop (field_prop * old_prop, int ti);
45 field_struct * duplicate_field_struct (field_struct * old_fstr);
46 field_struct * duplicate_field_struct_list (field_struct * list_str, gboolean init);
47 field_nth_body * duplicate_field_nth_body (field_nth_body * old_fbody);
48 field_external * duplicate_field_external (field_external * old_fext);
49 field_molecule * duplicate_field_molecule (field_molecule * old_fmol);
50
51 classical_field * duplicate_classical_field (classical_field * init_field);
52
53*/
54
55#include "dlp_field.h"
56#include "global.h"
57
58extern void print_all_field_struct (field_molecule * mol, int str);
59
68{
69 field_atom* new_fat;
70 new_fat = g_malloc0 (sizeof*new_fat);
71 new_fat -> id = old_fat -> id;
72 new_fat -> fid = old_fat -> fid;
73 new_fat -> afid = old_fat -> afid;
74 new_fat -> name = g_strdup_printf ("%s", old_fat -> name);
75 new_fat -> num = old_fat -> num;
76 new_fat -> sp = old_fat -> sp;
77 new_fat -> type = old_fat -> type;
78 new_fat -> mass = old_fat -> mass;
79 new_fat -> charge = old_fat -> charge;
80 new_fat -> frozen = old_fat -> frozen;
81 new_fat -> show = FALSE;
82 new_fat -> list = duplicate_int (old_fat -> num, old_fat -> list);
83 /* g_debug ("Debug copy atom: %d", new_fat -> id);
84 int i;
85 for (i=0; i<new_fat -> num; i++) g_debug ("old_fat -> list[%d]= %d", i, old_fat -> list[i]);
86 for (i=0; i<new_fat -> num; i++) g_debug ("new_fat -> list[%d]= %d", i, new_fat -> list[i]); */
87 new_fat -> list_id = duplicate_int (old_fat -> num, old_fat -> list_id);
88 new_fat -> frozen_id = duplicate_bool (old_fat -> num, old_fat -> frozen_id);
89 new_fat -> prev = NULL;
90 new_fat -> next = NULL;
91 return new_fat;
92}
93
102{
103 field_shell * new_shell;
104 new_shell = g_malloc0 (sizeof*new_shell);
105 new_shell -> id = old_shell -> id;
106 new_shell -> ia[0] = old_shell -> ia[0];
107 new_shell -> ia[1] = old_shell -> ia[1];
108 new_shell -> m = old_shell -> m;
109 new_shell -> z = old_shell -> z;
110 new_shell -> k2 = old_shell -> k2;
111 new_shell -> k4 = old_shell -> k4;
112 new_shell -> vdw = old_shell -> vdw;
113 new_shell -> use = old_shell -> use;
114 new_shell -> show = old_shell -> show;
115 new_shell -> prev = NULL;
116 new_shell -> next = NULL;
117 return new_shell;
118}
119
128{
129 field_constraint * new_cons;
130 new_cons = g_malloc0 (sizeof*new_cons);
131 new_cons -> id = old_cons -> id;
132 new_cons -> ia[0] = old_cons -> ia[0];
133 new_cons -> ia[1] = old_cons -> ia[1];
134 new_cons -> length = old_cons -> length;
135 new_cons -> use = old_cons -> use;
136 new_cons -> show = old_cons -> show;
137 new_cons -> prev = NULL;
138 new_cons -> next = NULL;
139 return new_cons;
140}
141
150{
151 field_pmf * new_pmf;
152 new_pmf = g_malloc0 (sizeof*new_pmf);
153 new_pmf -> id = old_pmf -> id;
154 new_pmf -> length = old_pmf -> length;
155 int i;
156 for (i=0; i<2; i++)
157 {
158 new_pmf -> num[i] = old_pmf -> num[i];
159 new_pmf -> list[i] = duplicate_int (old_pmf -> num[i], old_pmf -> list[i]);
160 new_pmf -> weight[i] = duplicate_float (old_pmf -> num[i], old_pmf -> weight[i]);
161 }
162 new_pmf -> show = old_pmf -> show;
163 new_pmf -> use = old_pmf -> use;
164 new_pmf -> next = NULL;
165 new_pmf -> prev = NULL;
166 return new_pmf;
167}
168
177{
178 field_rigid * new_rig;
179 new_rig = g_malloc0 (sizeof*new_rig);
180 new_rig -> id = old_rig -> id;
181 new_rig -> num = old_rig -> num;
182 new_rig -> list = duplicate_int (old_rig -> num, old_rig -> list);
183 new_rig -> show = old_rig -> show;
184 new_rig -> use = old_rig -> use;
185 new_rig -> next = NULL;
186 new_rig -> prev = NULL;
187 return new_rig;
188}
189
198{
199 field_tethered * new_tet;
200 new_tet = g_malloc0 (sizeof*new_tet);
201 new_tet -> id = old_tet -> id;
202 new_tet -> num = old_tet -> num;
203 new_tet -> show = old_tet -> show;
204 new_tet -> use = old_tet -> use;
205 new_tet -> next = NULL;
206 new_tet -> prev = NULL;
207 return new_tet;
208}
209
219{
220 field_prop * new_prop;
221 new_prop = g_malloc0 (sizeof*new_prop);
222 new_prop -> aid = duplicate_int (struct_id(ti+7), old_prop -> aid);
223 new_prop -> key = old_prop -> key;
224 new_prop -> pid = old_prop -> pid;
225 new_prop -> fpid = old_prop -> fpid;
226 new_prop -> val = NULL;
227 if (fvalues[activef][ti+1][new_prop -> key] > 0)
228 {
229 new_prop -> val = duplicate_float (fvalues[activef][ti+1][new_prop -> key], old_prop -> val);
230 }
231 new_prop -> show = old_prop -> show;
232 new_prop -> use = old_prop -> use;
233 new_prop -> next = NULL;
234 new_prop -> prev = NULL;
235 return new_prop;
236}
237
247gboolean check_this_other_prop (int oid, int nat, field_prop * other)
248{
249 if (oid > -1)
250 {
251 int i;
252 for (i=0; i<nat; i++)
253 {
254 if (tmp_fmol -> atoms_id[other -> aid[i]][0].a == oid) return FALSE;
255 }
256 }
257 return TRUE;
258}
259
269void duplicate_other_prop (int oid, field_struct * old_fstr, field_struct * new_fstr)
270{
271 int i = struct_id(new_fstr -> st+7);
272 field_prop * tmp_new;
273 field_prop * tmp_old = old_fstr -> other;
274 while (tmp_old)
275 {
276 if (check_this_other_prop(oid, i, tmp_old))
277 {
278 if (new_fstr -> other)
279 {
280 tmp_new -> next = duplicate_field_prop (tmp_old, old_fstr -> st);
281 tmp_new = tmp_new -> next;
282 }
283 else
284 {
285 new_fstr -> other = duplicate_field_prop (tmp_old, old_fstr -> st);
286 tmp_new = new_fstr -> other;
287 }
288 }
289 tmp_old = tmp_old -> next;
290 }
291}
292
301{
302 field_struct * new_fstr;
303 new_fstr = g_malloc0 (sizeof*new_fstr);
304 new_fstr -> st = old_fstr -> st;
305 new_fstr -> id = old_fstr -> id;
306 new_fstr -> num = old_fstr -> num;
307 new_fstr -> aid = duplicate_int (struct_id(old_fstr -> st+7), old_fstr -> aid);
308 new_fstr -> av = old_fstr -> av;
309 new_fstr -> def = duplicate_field_prop (old_fstr -> def, old_fstr -> st);
310 new_fstr -> other = NULL;
311 if (old_fstr -> other != NULL) duplicate_other_prop (-1, old_fstr, new_fstr);
312 new_fstr -> prev = NULL;
313 new_fstr -> next = NULL;
314 return new_fstr;
315}
316
326{
327 field_struct * str_list = duplicate_field_struct (list_str);
328 if (init) str_list -> def -> use = FALSE;
329 field_struct * tmp_str = str_list;
330 field_struct * tmp_fst = list_str;
331 while (tmp_fst -> next)
332 {
333 tmp_str -> next = duplicate_field_struct (tmp_fst -> next);
334 tmp_str -> next -> prev = tmp_str;
335 if (init) tmp_str -> next -> def -> use = FALSE;
336 tmp_str = tmp_str -> next;
337 tmp_fst = tmp_fst -> next;
338 }
339 return str_list;
340}
341
351{
352 new_fbody -> key = old_fbody -> key;
353 new_fbody -> val = duplicate_float (fvalues[activef][9+new_fbody -> bd][new_fbody -> key], old_fbody -> val);
354 new_fbody -> show = old_fbody -> show;
355 new_fbody -> use = old_fbody -> use;
356}
357
366{
367 field_nth_body * new_fbody;
368 int i, j;
369 new_fbody = g_malloc0 (sizeof*new_fbody);
370 new_fbody -> id = old_fbody -> id;
371 new_fbody -> bd = old_fbody -> bd;
372 if (old_fbody -> fpid) new_fbody -> fpid = duplicate_int (2, old_fbody -> fpid);
373 j = body_at (old_fbody -> bd);
374 new_fbody -> na = duplicate_int (j, old_fbody -> na);
375 new_fbody -> ma = NULL;
376 new_fbody -> ma = g_malloc (j*sizeof*new_fbody -> ma);
377 new_fbody -> a = NULL;
378 new_fbody -> a = g_malloc (j*sizeof*new_fbody -> a);
379
380 for (i=0; i<j; i++)
381 {
382 if (old_fbody -> ma[i] != NULL)
383 {
384 new_fbody -> ma[i] = duplicate_int (old_fbody -> na[i], old_fbody -> ma[i]);
385 }
386 else
387 {
388 new_fbody -> ma[i] = NULL;
389 }
390 if (old_fbody -> a[i] != NULL)
391 {
392 new_fbody -> a[i] = duplicate_int (old_fbody -> na[i], old_fbody -> a[i]);
393 }
394 else
395 {
396 new_fbody -> a[i] = NULL;
397 }
398 }
399 duplicate_nbody_params (new_fbody, old_fbody);
400 new_fbody -> prev = NULL;
401 new_fbody -> next = NULL;
402 return new_fbody;
403}
404
413{
414 field_external * new_fext;
415 new_fext = g_malloc0 (sizeof*new_fext);
416 new_fext -> id = old_fext -> id;
417 new_fext -> key = old_fext -> key;
418 new_fext -> val = NULL;
419 if (old_fext -> val != NULL)
420 {
421 new_fext -> val = duplicate_float (fvalues[activef][SEXTERN-6][new_fext -> key], old_fext -> val);
422 }
423 new_fext -> use = old_fext -> use;
424 new_fext -> next = NULL;
425 new_fext -> prev = NULL;
426 return new_fext;
427}
428
437{
438 int i, j;
439 field_molecule * new_fmol;
440 new_fmol = g_malloc0 (sizeof*new_fmol);
441 new_fmol -> id = old_fmol -> id;
442 new_fmol -> multi = old_fmol -> multi;
443 new_fmol -> name = g_strdup_printf ("%s", old_fmol -> name);
444 new_fmol -> show = old_fmol -> show;
445 new_fmol -> show_id = old_fmol -> show_id;
446 new_fmol -> atoms = old_fmol -> atoms;
447 new_fmol -> first_atom = NULL;
448 new_fmol -> tethered = old_fmol -> tethered;
449 new_fmol -> first_tethered = NULL;
450 new_fmol -> rigids = old_fmol -> rigids;
451 new_fmol -> first_rigid = NULL;
452 new_fmol -> pmfs = old_fmol -> pmfs;
453 new_fmol -> first_pmf = NULL;
454 new_fmol -> first_constraint = NULL;
455 new_fmol -> constraints = old_fmol -> constraints;
456 new_fmol -> first_shell = NULL;
457 new_fmol -> shells = old_fmol -> shells;
458 new_fmol -> mol = g_malloc0 (sizeof*new_fmol -> mol);
459 new_fmol -> mol = & tmp_proj -> modelfc -> mols[0][old_fmol -> mol -> id];
460 // Duplicating atoms
461 new_fmol -> fragments = NULL;
462 new_fmol -> fragments = allocint(new_fmol -> multi);
463 for (i=0; i<new_fmol -> multi; i++) new_fmol -> fragments[i] = old_fmol -> fragments[i];
464
465 new_fmol -> first_atom = duplicate_field_atom (old_fmol -> first_atom);
466 field_atom* tmp_fat = new_fmol -> first_atom;
467 field_atom* tmp_fa = old_fmol -> first_atom;
468
469 for (i=1; i<new_fmol -> atoms; i++)
470 {
471 tmp_fat -> next = duplicate_field_atom (tmp_fa -> next);
472 tmp_fat -> next -> prev = tmp_fat;
473 tmp_fat = tmp_fat -> next;
474 tmp_fa = tmp_fa -> next;
475 }
476
477 new_fmol -> atoms_id = g_malloc (new_fmol -> mol -> natoms*sizeof*new_fmol -> atoms_id);
478 for (i=0; i<new_fmol -> mol -> natoms; i++)
479 {
480 new_fmol -> atoms_id[i] = g_malloc0 (new_fmol -> multi*sizeof*new_fmol -> atoms_id[i]);
481 for (j=0; j<new_fmol -> multi; j++)
482 {
483 new_fmol -> atoms_id[i][j].a = old_fmol -> atoms_id[i][j].a;
484 new_fmol -> atoms_id[i][j].b = old_fmol -> atoms_id[i][j].b;
485 }
486 }
487
488 for (i=0; i<8; i++)
489 {
490 // Duplicating bonds / br / angles / ar / diherdrals / impropers / tr / inversions
491 new_fmol -> nstruct[i] = old_fmol -> nstruct[i];
492 new_fmol -> first_struct[i] = NULL;
493 if (old_fmol -> nstruct[i] > 0)
494 {
495 new_fmol -> first_struct[i] = duplicate_field_struct (old_fmol -> first_struct[i]);
496 field_struct * tmp_str = new_fmol -> first_struct[i];
497 field_struct * tmp_fst = old_fmol -> first_struct[i];
498 for (j=1; j<new_fmol -> nstruct[i]; j++)
499 {
500 tmp_str -> next = duplicate_field_struct (tmp_fst -> next);
501 tmp_str -> next -> prev = tmp_str;
502 tmp_str = tmp_str -> next;
503 tmp_fst = tmp_fst -> next;
504 }
505 }
506 }
507 new_fmol -> next = NULL;
508 new_fmol -> prev = NULL;
509 return new_fmol;
510}
511
520{
521 classical_field * new_field = NULL;
522 new_field = g_malloc (sizeof*new_field);
523
524 int i, j, k;
525
526 // All
527 for (i=0; i<MAXDATC+MAXDATA; i++) new_field -> afp[i] = init_field -> afp[i];
528 for (i=0; i<2; i++) new_field -> prepare_file[i] = init_field -> prepare_file[i];
529
530 // Control
531 new_field -> ensemble = init_field -> ensemble;
532 new_field -> thermostat = init_field -> thermostat;
533 for (i=0; i<17; i++) new_field -> sys_opts[i] = init_field -> sys_opts[i];
534 for (i=0; i<23; i++) new_field -> io_opts[i] = init_field -> io_opts[i];
535 for (i=0; i<17; i++) new_field -> ana_opts[i] = init_field -> ana_opts[i];
536 for (i=0; i<11; i++) new_field -> elec_opts[i] = init_field -> elec_opts[i];
537 for (i=0; i<6; i++) new_field -> vdw_opts[i] = init_field -> vdw_opts[i];
538 for (i=0; i<2; i++) new_field -> met_opts[i] = init_field -> met_opts[i];
539 for (i=0; i<17; i++) new_field -> equi_opts[i] = init_field -> equi_opts[i];
540 for (i=0; i<10; i++) new_field -> thermo_opts[i] = init_field -> thermo_opts[i];
541 for (i=0; i<20; i++) new_field -> md_opts[i] = init_field -> md_opts[i];
542 for (i=0; i<31; i++) new_field -> out_opts[i] = init_field -> out_opts[i];
543
544 // Field
545 new_field -> energy_unit = init_field -> energy_unit;
546 new_field -> atom_init = init_field -> atom_init;
547
548 new_field -> molecules = init_field -> molecules;
549 if (new_field -> molecules)
550 {
551 field_molecule * fmol;
552 new_field -> first_molecule = duplicate_field_molecule (init_field -> first_molecule);
553 fmol = new_field -> first_molecule;
554 tmp_fmol = init_field -> first_molecule;
555 for (i=1; i<init_field -> molecules; i++)
556 {
557 fmol -> next = duplicate_field_molecule (tmp_fmol -> next);
558 fmol -> next -> prev = fmol;
559 fmol = fmol -> next;
560 tmp_fmol = tmp_fmol -> next;
561 }
562
563 // Duplicating nth_body
564 for (i=0; i<5; i++)
565 {
566 new_field -> first_body[i] = NULL;
567 new_field -> nbody[i] = init_field -> nbody[i];
568 if (init_field -> nbody[i] > 0)
569 {
570 new_field -> first_body[i] = duplicate_field_nth_body (init_field -> first_body[i]);
571 field_nth_body * tmp_fbod = new_field -> first_body[i];
572 field_nth_body * tmp_fbo = init_field -> first_body[i];
573 for (j=1; j<new_field -> nbody[i]; j++)
574 {
575 tmp_fbod -> next = duplicate_field_nth_body (tmp_fbo -> next);
576 tmp_fbod -> next -> prev = tmp_fbod;
577 tmp_fbod = tmp_fbod -> next;
578 tmp_fbo = tmp_fbo -> next;
579 }
580 }
581 }
582 // Tersoff cross terms
583 new_field -> cross = NULL;
584 if (init_field -> cross != NULL)
585 {
586 new_field -> cross = g_malloc (tmp_field -> nbody[2]*sizeof*new_field -> cross);
587 for (i=0; i<tmp_field -> nbody[2]; i++)
588 {
589 new_field -> cross[i] = g_malloc (tmp_field -> nbody[2]*sizeof*new_field -> cross[i]);
590 for (j=0; j<tmp_field -> nbody[2]; k++) new_field -> cross[i][j] = duplicate_double (3, init_field -> cross[i][j]);
591 }
592 }
593
594 // Duplicating external fields
595 new_field -> first_external = NULL;
596 new_field -> extern_fields = init_field -> extern_fields;
597 if (init_field -> extern_fields > 0)
598 {
599 new_field -> first_external = duplicate_field_external (init_field -> first_external);
600 field_external * tmp_fext = new_field -> first_external;
601 field_external * tmp_ftxt = init_field -> first_external;
602 for (i=1; i<new_field -> extern_fields; i++)
603 {
604 tmp_fext -> next = duplicate_field_external (tmp_ftxt -> next);
605 tmp_fext -> next -> prev = tmp_fext;
606 tmp_fext = tmp_fext -> next;
607 tmp_ftxt = tmp_ftxt -> next;
608 }
609 }
610 }
611 return new_field;
612}
insertion_menu mol[]
Definition w_library.c:193
int atoms[NUM_STYLES][2]
float val
Definition dlp_init.c:117
gchar * sys_opts[10]
field_molecule * duplicate_field_molecule(field_molecule *old_fmol)
create copy of a field molecule
Definition dlp_copy.c:436
field_nth_body * duplicate_field_nth_body(field_nth_body *old_fbody)
create copy of a field body property
Definition dlp_copy.c:365
void print_all_field_struct(field_molecule *mol, int str)
print all field structural element(s)
Definition dlp_print.c:195
field_pmf * duplicate_field_pmf(field_pmf *old_pmf)
create copy of a field PMF data structure
Definition dlp_copy.c:149
field_prop * duplicate_field_prop(field_prop *old_prop, int ti)
create a copy of a field property
Definition dlp_copy.c:218
void duplicate_nbody_params(field_nth_body *new_fbody, field_nth_body *old_fbody)
copy field body parameter list
Definition dlp_copy.c:350
gboolean check_this_other_prop(int oid, int nat, field_prop *other)
check if field atom already in field property
Definition dlp_copy.c:247
field_tethered * duplicate_field_tethered(field_tethered *old_tet)
create copy of a field tethered data structure
Definition dlp_copy.c:197
void duplicate_other_prop(int oid, field_struct *old_fstr, field_struct *new_fstr)
create copy of a field property 'other' list
Definition dlp_copy.c:269
field_external * duplicate_field_external(field_external *old_fext)
create copy of a field external property
Definition dlp_copy.c:412
classical_field * duplicate_classical_field(classical_field *init_field)
create copy of a force field
Definition dlp_copy.c:519
field_constraint * duplicate_field_constraint(field_constraint *old_cons)
create copy of a field constraint data structure
Definition dlp_copy.c:127
field_atom * duplicate_field_atom(field_atom *old_fat)
create copy of a field atom data structure
Definition dlp_copy.c:67
field_shell * duplicate_field_shell(field_shell *old_shell)
create copy of a field shell data structure
Definition dlp_copy.c:101
field_struct * duplicate_field_struct(field_struct *old_fstr)
create copy of a field structural element
Definition dlp_copy.c:300
field_rigid * duplicate_field_rigid(field_rigid *old_rig)
create copy of a field rigid data structure
Definition dlp_copy.c:176
field_struct * duplicate_field_struct_list(field_struct *list_str, gboolean init)
create copy of list of field structural element(s)
Definition dlp_copy.c:325
int * atoms_id
double *** cross
Definition dlp_edit.c:418
int fvalues[2][15][21]
Definition dlp_field.c:255
project * tmp_proj
Definition dlp_field.c:953
int body_at(int b)
find the number of atom(s) in a non bonded interaction
Definition dlp_field.c:1022
field_external * tmp_fext
Definition dlp_field.c:967
field_atom * tmp_fat
Definition dlp_field.c:957
int struct_id(int f)
number of atoms in a structural element
Definition dlp_field.c:999
field_molecule * tmp_fmol
Definition dlp_field.c:955
int atom_init
Definition dlp_field.c:950
classical_field * tmp_field
Definition dlp_field.c:951
Variable declarations for the creation of the DL_POLY input file(s)
int * duplicate_int(int num, int *old_val)
copy a list of int
Definition global.c:572
float * duplicate_float(int num, float *old_val)
copy a list of float
Definition global.c:604
#define SEXTERN
Definition dlp_field.h:118
gboolean * duplicate_bool(int num, gboolean *old_val)
copy a list of gboolean
Definition global.c:588
gboolean afp[MAXDATA]
int multi
Definition dlp_init.c:121
double * duplicate_double(int num, double *old_val)
copy a list of double
Definition global.c:620
int activef
Definition global.c:161
int * allocint(int val)
allocate an int * pointer
Definition global.c:326
Global variable declarations Global convenience function declarations Global data structure defin...
struct thermostat thermostat
Definition global.h:697
#define MAXDATC
Number of tabs for the description of the classical calculation.
Definition global.h:657
#define MAXDATA
Number of tabs for the description of the classical force field.
Definition global.h:662
integer(kind=c_int) function molecules(frag_and_mol, allbonds)
double z
Definition ogl_draw.c:57
int a
Definition tab-1.c:95