atomes 1.3.1
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
prepdata.F90
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
4! of the GNU Affero General Public License as published by the Free Software Foundation,
5! either 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;
8! without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9! See the GNU General Public License for more details.
10!
11! You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12! If not, see <https://www.gnu.org/licenses/>
13!
14! Copyright (C) 2022-2026 by CNRS and University of Strasbourg
15!
16!>
17!! @file prepdata.F90
18!! @short First level analysis of atomic coordinates
19!! @author Sébastien Le Roux <sebastien.leroux@ipcms.unistra.fr>
20
21#if defined (HAVE_CONFIG_H)
22# include <config.h>
23#endif
24
25SUBROUTINE free_contj_voisj () bind (C,NAME='free_contj_voisj_')
26
27USE parameters
28
29IMPLICIT NONE
30
31if (allocated(voisj)) deallocate(voisj)
32if (allocated(contj)) deallocate(contj)
33
34END SUBROUTINE
35
36SUBROUTINE read_contj (ATO, STP, CON) bind (C,NAME='read_contj_')
37
38USE parameters
39
40IMPLICIT NONE
41
42INTEGER (KIND=c_int), INTENT(IN) :: ATO, STP, CON
43
44contj(ato+1,stp+1) = con
45
46END SUBROUTINE
47
48SUBROUTINE read_voisj (ATO, STP, CID, VID) bind (C,NAME='read_voisj_')
49
50USE parameters
51
52IMPLICIT NONE
53
54INTEGER (KIND=c_int), INTENT(IN) :: ATO, STP, CID, VID
55
56voisj(cid+1,ato+1,stp+1) = vid+1
57
58END SUBROUTINE
59
60INTEGER (KIND=c_int) FUNCTION alloc_contj_voisj (N1, N2) bind (C,NAME='alloc_contj_voisj_')
61
62USE parameters
63
64IMPLICIT NONE
65
66INTEGER (KIND=c_int), INTENT(IN) :: n1, n2
67
68! N1 = atomes, N2 = steps
69if (allocated(voisj)) deallocate(voisj)
70allocate(voisj(maxn,n1,n2), stat=err)
71if (err .ne. 0) then
72 call show_error ("Impossible to allocate memory"//char(0), &
73 "Function: alloc_cont_vois"//char(0), "Table: VOISJ"//char(0))
75 goto 001
76endif
77if (allocated(contj)) deallocate(contj)
78allocate(contj(n1,n2), stat=err)
79if (err .ne. 0) then
80 call show_error ("Impossible to allocate memory"//char(0), &
81 "Function: alloc_cont_vois"//char(0), "Table: CONTJ"//char(0))
83endif
84
86
87001 continue
88
89END FUNCTION
90
91INTEGER (KIND=c_int) FUNCTION alloc_data (N1, N2, N3) bind (C,NAME='alloc_data_')
92
93USE parameters
94
95IMPLICIT NONE
96
97INTEGER (KIND=c_int), INTENT(IN) :: n1, n2, n3
98
99INTERFACE
100 INTEGER FUNCTION allochem()
101 END FUNCTION
102END INTERFACE
103
104na=n1
105nsp=n2
106ns=n3
107
108if (allocated(fullpos)) deallocate(fullpos)
109allocate (fullpos(na,3,ns), stat=err)
110if (err .ne. 0) then
111 call show_error ("Impossible to allocate memory"//char(0), &
112 "Function: alloc_data"//char(0), "Table: FULLPOS"//char(0))
113 alloc_data = 0
114 goto 001
115endif
116
117if (allocated(lot)) deallocate(lot)
118allocate(lot(na), stat=err)
119if (err .ne. 0) then
120 call show_error ("Impossible to allocate memory"//char(0), &
121 "Function: alloc_data"//char(0), "Table: LOT"//char(0))
122 alloc_data = 0
123 goto 001
124endif
126
127001 continue
128
129END FUNCTION
130
131SUBROUTINE prep_spec (idatoms, nsps, open_apf) bind (C,NAME='prep_spec_')
132
133USE parameters
134USE mendeleiev
135
136IMPLICIT NONE
137
138INTEGER (KIND=c_int), DIMENSION(NSP), INTENT(IN) :: nsps
139real(kind=c_double), DIMENSION(NSP), INTENT(IN) :: idatoms
140INTEGER (KIND=c_int), INTENT(IN) :: open_apf
141
142CHARACTER (LEN=14) :: ELEM
143! Now we are calling the GTK+ routines
144
145do i=1, nsp
146 nbspbs(i) = nsps(i)
147 j = int(idatoms(i))
148 atomid(i) = j
149 if (open_apf .eq. 1) then
150 if (j .gt. 0) then
151 tl(i) = atsym(j)
152 elem = element(j)
153 else
154 tl(i) = "X "
155 elem = "Unknown"
156 endif
157 ! In C all string must be terminated by a CHAR(0)
158 ! To spec_data_
159 call spec_data (0, i-1, atomid(i), nbspbs(i), &
160 tl(i)//char(0), elem//char(0), &
161 0.0d0, 0.0d0, 0.0d0, 0.0d0)
162 endif
163enddo
164nbspbs(nsp+1) = na
165
166END SUBROUTINE
167
168SUBROUTINE read_chem (PMASS, PRAD, PNSCATT, PXSCATT) bind (C,NAME='read_chem_')
169
170USE parameters
171
172IMPLICIT NONE
173
174real(kind=c_double), DIMENSION(NSP) :: pmass, prad, pnscatt, pxscatt
175
176do i=1, nsp
177 mass(i) = pmass(i)
178 rvdw(i) = prad(i)
179 nscattl(i) = pnscatt(i)
180 xscattl(i) = pxscatt(i)
181enddo
182
183END SUBROUTINE
184
185SUBROUTINE read_data (PLOT, PBS) bind (C,NAME='read_data_')
186
187USE parameters
188
189IMPLICIT NONE
190
191INTEGER (KIND=c_int), DIMENSION(NA), INTENT(IN) :: PLOT
192INTEGER (KIND=c_int), DIMENSION(NSP), INTENT(IN) :: PBS
193
194do i=1, na
195 lot(i)=plot(i)+1
196enddo
197do i=1, nsp
198 nbspbs(i) = pbs(i)
199 xi(i) = dble(nbspbs(i)) / dble(na)
200enddo
201nbspbs(nsp+1) = na
202
203END SUBROUTINE
204
205SUBROUTINE read_pos (PCX, PCY, PCZ) bind (C,NAME='read_pos_')
206
207USE parameters
208
209real(kind=c_double), DIMENSION(NA*NS), INTENT(IN) :: pcx, pcy, pcz
210
211k=0
212do i=1, ns
213 do j=1, na
214 k=k+1
215 fullpos(j,1,i)=pcx(k)
216 fullpos(j,2,i)=pcy(k)
217 fullpos(j,3,i)=pcz(k)
218 enddo
219enddo
220
221END SUBROUTINE
222
223INTEGER FUNCTION send_pos (NPA, NPS, NLOT, POSTAB)
224
225INTEGER :: i, j, k, err
226INTEGER, INTENT(IN) :: npa, nps
227INTEGER, DIMENSION(:), INTENT(IN) :: nlot
228DOUBLE PRECISION, DIMENSION(:,:,:), INTENT(IN) :: postab
229DOUBLE PRECISION, DIMENSION(:), ALLOCATABLE :: xpos, ypos, zpos
230
231if (allocated(xpos)) deallocate(xpos)
232allocate(xpos(npa*nps), stat=err)
233if (err .ne. 0) then
234 call show_error ("Impossible to allocate memory"//char(0), &
235 "Function: SEND_POS"//char(0), "Table: XPOS"//char(0))
236 send_pos = 0
237 goto 001
238endif
239if (allocated(ypos)) deallocate(ypos)
240allocate(ypos(npa*nps), stat=err)
241if (err .ne. 0) then
242 call show_error ("Impossible to allocate memory"//char(0), &
243 "Function: SEND_POS"//char(0), "Table: YPOS"//char(0))
244 send_pos = 0
245 goto 001
246endif
247if (allocated(zpos)) deallocate(zpos)
248allocate(zpos(npa*nps), stat=err)
249if (err .ne. 0) then
250 call show_error ("Impossible to allocate memory"//char(0), &
251 "Function: SEND_POS"//char(0), "Table: ZPOS"//char(0))
252 send_pos = 0
253 goto 001
254endif
255
256k=0
257do i=1, nps
258do j=1, npa
259 k=k+1
260 xpos(k)=postab(j,1,i)
261 ypos(k)=postab(j,2,i)
262 zpos(k)=postab(j,3,i)
263enddo
264enddo
265
266! To 'save_pos_'
267call save_pos (npa, nlot, k, xpos, ypos, zpos)
268
269send_pos = 1
270
271001 continue
272
273if (allocated(xpos)) deallocate (xpos)
274if (allocated(ypos)) deallocate (ypos)
275if (allocated(zpos)) deallocate (zpos)
276
277END FUNCTION
278
279INTEGER (KIND=c_int) FUNCTION prep_data () bind (C,NAME='prep_data_')
280
281!
282! Data initialization
283!
284
285USE parameters
286USE mendeleiev
287
288IMPLICIT NONE
289
290CHARACTER (LEN=2), DIMENSION(MAXE) :: ttype
291
292INTERFACE
293 INTEGER FUNCTION send_pos(NPA, NPS, NLOT, POSTAB)
294 INTEGER, INTENT(IN) :: npa, nps
295 INTEGER, DIMENSION(:), INTENT(IN) :: nlot
296 DOUBLE PRECISION, DIMENSION(:,:,:), INTENT(IN) :: postab
297 END FUNCTION
298 INTEGER FUNCTION allochem()
299 END FUNCTION
300 INTEGER FUNCTION findid(NAMEAT)
301 CHARACTER (LEN=2), INTENT(IN) :: nameat
302 END FUNCTION
303 INTEGER FUNCTION chemistry ()
304 END FUNCTION
305END INTERFACE
306
307prep_data = 0
308
309if (allocated(lot)) deallocate(lot)
310allocate(lot(na), stat=err)
311if (err .ne. 0) then
312 call show_error ("Impossible to allocate memory"//char(0), &
313 "Function: prep_data"//char(0), "Table: LOT"//char(0))
314 goto 001
315endif
316lot(:)=0 ! Initialisation du tableau
317
318noc=1
319do noa=1, na
320 if (noa .eq. 1) then
321 lot(noa)=noc
322 ttype(noc)=tab_of_type(noa)
323 else if (lot(noa) .eq. 0) then
324 do nob=1, noc
325 if (tab_of_type(noa) .eq. ttype(nob)) then
326 lot(noa)= nob
327 endif
328 enddo
329 if (lot(noa) .eq. 0) then
330 noc=noc+1
331 lot(noa)=noc
332 ttype(noc)=tab_of_type(noa)
333 endif
334 endif
335enddo
336nsp=noc
337
338if (allochem() == 0) then
339 prep_data = 0
340 goto 001
341endif
342
343if (allocated(elemid)) deallocate(elemid)
344allocate(elemid(nsp), stat=err)
345if (err .ne. 0) then
346 call show_error ("Impossible to allocate memory"//char(0), &
347 "Function: prep_data"//char(0), "Table: ELEMID"//char(0))
348 goto 001
349endif
350
351nbspbs(:) = 0
352do noa=1, na
353 nob=lot(noa)
354 nbspbs(nob)=nbspbs(nob)+1
355enddo
356
357nbspbs(nsp+1)=na
358
359!
360! Link between index and label
361! Correspondance entre indice de type et label
362!
363
364do nob=1, nsp
365 tl(nob)=ttype(nob)
366enddo
367
368do noa=1, nsp
369 atomid(noa) = findid(tl(noa))
370 select case (atomid(noa))
371 case (-1)
372 prep_data = 0
373 goto 001
374 case (0)
375 elemid(noa) = "Dummy "//tl(noa)
376 mass(noa) = 1.0
377 rvdw(noa) = 0.5
378 nscattl(noa) = 0.0
379 xscattl(noa) = 0.0
380 case default
382 mass(noa) = amass(atomid(noa))
384 if(atomid(noa) < 105) then
386 ! Covalent radius are the defaut values
387 rvdw(noa) = arcov(atomid(noa))
388 ! To use ionic radius uncomment the following line
389 ! RVDW(NOA) = ARION(ATOMID(NOA))
390 ! To use Wander Waals radius uncomment the following line
391 ! RVDW(NOA) = ARVDW(ATOMID(NOA))
392 else
393 nscattl(noa) = 0.0d0
394 rvdw(noa) = 0.0d0
395 endif
396 end select
397 if (nscattl(noa) .eq. 0.00) then
398 call show_warning ("Element "//tl(noa)//" does not have neutron scattering length "//char(0), &
399 "If this is a bug please report it to"//char(0), package_bugreport//char(0))
400 endif
401enddo
402
403! Now we are calling the GTK+ routines
404! To init_data_
405call init_data (na, nsp, ns, 1)
406
407do i=1, nsp
408! In C all string must be terminated by a CHAR(0)
409! To spec_data_
410 call spec_data (1, i-1, atomid(i), nbspbs(i), &
411 tl(i)//char(0), elemid(i)//char(0), &
412 mass(i), rvdw(i), nscattl(i), xscattl(i))
413enddo
414
415if (chemistry() .eq. 1) then
417endif
418
419001 continue
420
421if (allocated(elemid)) deallocate(elemid)
422
423END FUNCTION
424
425INTEGER FUNCTION findid(NAMEAT)
426
427USE parameters
428USE mendeleiev
429
430INTEGER (KIND=c_int), EXTERNAL :: dummy_ask
431INTEGER :: elemt
432CHARACTER (LEN=2), INTENT(IN) :: nameat
433
434findid=0
435do elemt=1, maxe
436
437 if (atsym(elemt) .eq. nameat) then
438 findid=elemt
439 exit
440 endif
441
442enddo
443
444if (findid .eq. 0) then
445 call show_warning ("Problem with the atomic coordinates"//char(0), &
446 "Element "//nameat//" does not exist "//char(0), " "//char(0))
447 findid = dummy_ask("Do you want to use dummy atom(s) for unknown species "//nameat//" ?"//char(0));
448endif
449
450END FUNCTION
451
452REAL (KIND=c_double) FUNCTION set_mass (SW) bind (C,NAME='set_mass_')
453
454USE mendeleiev
455USE parameters
456
457INTEGER (KIND=c_int), INTENT(IN) :: sw
458
459set_mass = amass(sw)
460
461END FUNCTION
462
463REAL (KIND=c_double) FUNCTION set_radius (SW, RD) bind (C,NAME='set_radius_')
464
465USE mendeleiev
466USE parameters
467
468INTEGER (KIND=c_int), INTENT(IN) :: sw, rd
469DOUBLE PRECISION :: rad
470
471if (sw .lt. 108) then
472 if (rd .eq. 0) then
473 rad = arcov(sw)
474 else if (rd .eq. 1) then
475 rad = arion(sw)
476 else if (rd .eq. 2) then
477 rad = arvdw(sw)
478 else if (rd .eq. 3) then
479 rad = arcry(sw)
480 endif
481else
482 rad = 0.0
483endif
484set_radius = rad
485
486END FUNCTION
487
488REAL (KIND=c_double) FUNCTION set_neutron (SW) bind (C,NAME='set_neutron_')
489
490USE mendeleiev
491USE parameters
492
493INTEGER (KIND=c_int), INTENT(IN) :: sw
494
495if (sw .lt. 105) then
496 set_neutron = coheb(sw)
497else
498 set_neutron = 0.0
499endif
500
501END FUNCTION
502
503!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
504! Reconstruction des trajectoires réelles
505!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
506SUBROUTINE prep_pos (PINFO, FINFO) bind (C,NAME='prep_pos_')
507
508USE parameters
509
510IMPLICIT NONE
511
512INTEGER (KIND=c_int), INTENT(IN) :: PINFO, FINFO
513
514INTERFACE
515 INTEGER FUNCTION send_pos(NPA, NPS, NLOT, POSTAB)
516 INTEGER, INTENT(IN) :: NPA, NPS
517 INTEGER, DIMENSION(:), INTENT(IN) :: NLOT
518 DOUBLE PRECISION, DIMENSION(:,:,:), INTENT(IN) :: POSTAB
519 END FUNCTION
520END INTERFACE
521
522pbc=.false.
523if (pinfo .eq. 1) then
524 pbc=.true.
525endif
526
527frac=.false.
528if (finfo > 0) frac=.true.
529
530if (frac) then
531 do noc=1, ns
532 do noa=1, na
533 if (ncells .gt. 1) then
534 fullpos(noa,:,noc) = matmul(fullpos(noa,:,noc),the_box(noc)%fractocart)
535 else
536 fullpos(noa,:,noc) = matmul(fullpos(noa,:,noc),the_box(1)%fractocart)
537 endif
538 enddo
539 enddo
540endif
541
543
544END SUBROUTINE
integer function allochem()
Definition allochem.F90:22
integer(kind=c_int) function chemistry()
Definition chemistry.F90:22
void show_warning(char *warning, GtkWidget *win)
show warning
Definition interface.c:266
void show_error(char *error, int val, GtkWidget *win)
show error message
Definition interface.c:299
double precision, dimension(118), parameter arvdw
double precision, dimension(118), parameter amass
double precision, dimension(105), parameter coheb
double precision, dimension(118), parameter arcov
character(len=2), dimension(118), parameter atsym
double precision, dimension(118), parameter arion
integer maxe
character(len=14), dimension(118), parameter element
double precision, dimension(118), parameter arcry
double precision, dimension(:,:,:), allocatable fullpos
integer ncells
double precision, dimension(:), allocatable nscattl
double precision, dimension(:), allocatable mass
character(len=2), dimension(:), allocatable tab_of_type
character(len=15), dimension(:), allocatable elemid
double precision, dimension(:), allocatable xi
integer, dimension(:,:), allocatable contj
character(len=2), dimension(:), allocatable tl
integer nob
integer, dimension(:), allocatable nbspbs
integer noc
integer noa
integer err
type(lattice), dimension(:), allocatable, target the_box
integer maxn
integer, dimension(:,:,:), allocatable voisj
logical frac
double precision, dimension(:), allocatable xscattl
integer, dimension(:), allocatable atomid
integer, dimension(:), allocatable lot
double precision, dimension(:), allocatable rvdw
logical pbc
integer nsp
subroutine free_contj_voisj()
Definition prepdata.F90:26
subroutine read_contj(ato, stp, con)
Definition prepdata.F90:37
integer(kind=c_int) function alloc_data(n1, n2, n3)
Definition prepdata.F90:92
subroutine read_voisj(ato, stp, cid, vid)
Definition prepdata.F90:49
subroutine read_data(plot, pbs)
Definition prepdata.F90:186
subroutine prep_pos(pinfo, finfo)
Definition prepdata.F90:507
integer(kind=c_int) function prep_data()
Definition prepdata.F90:280
subroutine read_chem(pmass, prad, pnscatt, pxscatt)
Definition prepdata.F90:169
integer function send_pos(npa, nps, nlot, postab)
Definition prepdata.F90:224
subroutine read_pos(pcx, pcy, pcz)
Definition prepdata.F90:206
real(kind=c_double) function set_mass(sw)
Definition prepdata.F90:453
integer function findid(nameat)
Definition prepdata.F90:426
real(kind=c_double) function set_radius(sw, rd)
Definition prepdata.F90:464
integer(kind=c_int) function alloc_contj_voisj(n1, n2)
Definition prepdata.F90:61
real(kind=c_double) function set_neutron(sw)
Definition prepdata.F90:489
subroutine prep_spec(idatoms, nsps, open_apf)
Definition prepdata.F90:132