(git:ab76537)
Loading...
Searching...
No Matches
cell_types.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Handles all functions related to the CELL
10!> \par History
11!> 11.2008 Teodoro Laino [tlaino] - deeply cleaning cell_type from units
12!> 10.2014 Moved many routines from cell_types.F here.
13!> \author Matthias KracK (16.01.2002, based on a earlier version of CJM, JGH)
14! **************************************************************************************************
16 USE cp_units, ONLY: cp_unit_to_cp2k
17 USE kinds, ONLY: dp
18 USE mathconstants, ONLY: degree
19 USE mathlib, ONLY: angle
20#include "../base/base_uses.f90"
21
22 IMPLICIT NONE
23
24 PRIVATE
25
26 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_types'
27
28 ! Impose cell symmetry
29 INTEGER, PARAMETER, PUBLIC :: cell_sym_none = 0, &
41
42 INTEGER, PARAMETER, PUBLIC :: use_perd_none = 0, &
43 use_perd_x = 1, &
44 use_perd_y = 2, &
45 use_perd_z = 3, &
46 use_perd_xy = 4, &
47 use_perd_xz = 5, &
48 use_perd_yz = 6, &
49 use_perd_xyz = 7
50
51 CHARACTER(LEN=3), DIMENSION(7), &
52 PARAMETER, PUBLIC :: periodicity_string = [" X", " Y", " Z", &
53 " XY", " XZ", " YZ", &
54 "XYZ"]
55
56! **************************************************************************************************
57!> \brief Type defining parameters related to the simulation cell
58!> \version 1.0
59! **************************************************************************************************
61 CHARACTER(LEN=12) :: tag = "CELL"
62 INTEGER :: ref_count = -1, &
63 symmetry_id = use_perd_none
64 LOGICAL :: orthorhombic = .false. ! actually means a diagonal hmat
65 REAL(kind=dp) :: deth = 0.0_dp
66 INTEGER, DIMENSION(3) :: perd = -1
67 REAL(kind=dp), DIMENSION(3, 3) :: hmat = 0.0_dp, &
68 h_inv = 0.0_dp
69 END TYPE cell_type
70
72 TYPE(cell_type), POINTER :: cell => null()
73 END TYPE cell_p_type
74
75 ! Public data types
76 PUBLIC :: cell_type, &
78
79 ! Public subroutines
80 PUBLIC :: cell_clone, &
81 cell_copy, &
84 get_cell, &
86
87#if defined (__PLUMED2)
88 PUBLIC :: pbc_cp2k_plumed_getset_cell
89#endif
90
91 ! Public functions
92 PUBLIC :: plane_distance, &
93 pbc, &
96
97 INTERFACE pbc
98 MODULE PROCEDURE pbc1, pbc2, pbc3, pbc4
99 END INTERFACE
100
101CONTAINS
102
103! **************************************************************************************************
104!> \brief Clone cell variable
105!> \param cell_in Cell variable to be clone
106!> \param cell_out Cloned cell variable
107!> \param tag Optional new tag for cloned cell variable
108!> \par History
109!> - Optional tag added (17.05.2023, MK)
110! **************************************************************************************************
111 SUBROUTINE cell_clone(cell_in, cell_out, tag)
112
113 TYPE(cell_type), POINTER :: cell_in, cell_out
114 CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: tag
115
116 cell_out = cell_in
117 cell_out%ref_count = 1
118 IF (PRESENT(tag)) cell_out%tag = tag
119
120 END SUBROUTINE cell_clone
121
122! **************************************************************************************************
123!> \brief Copy cell variable
124!> \param cell_in Cell variable to be copied
125!> \param cell_out Copy of cell variable
126!> \param tag Optional new tag
127!> \par History
128!> - Optional tag added (17.05.2023, MK)
129! **************************************************************************************************
130 SUBROUTINE cell_copy(cell_in, cell_out, tag)
131
132 TYPE(cell_type), POINTER :: cell_in, cell_out
133 CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: tag
134
135 cell_out%deth = cell_in%deth
136 cell_out%perd = cell_in%perd
137 cell_out%hmat = cell_in%hmat
138 cell_out%h_inv = cell_in%h_inv
139 cell_out%orthorhombic = cell_in%orthorhombic
140 cell_out%symmetry_id = cell_in%symmetry_id
141 IF (PRESENT(tag)) THEN
142 cell_out%tag = tag
143 ELSE
144 cell_out%tag = cell_in%tag
145 END IF
146
147 END SUBROUTINE cell_copy
148
149! **************************************************************************************************
150!> \brief Read cell info from a line (parsed from a file)
151!> \param input_line ...
152!> \param cell_itimes ...
153!> \param cell_time ...
154!> \param h ...
155!> \param vol ...
156!> \date 19.02.2008
157!> \author Teodoro Laino [tlaino] - University of Zurich
158!> \version 1.0
159! **************************************************************************************************
160 SUBROUTINE parse_cell_line(input_line, cell_itimes, cell_time, h, vol)
161
162 CHARACTER(LEN=*), INTENT(IN) :: input_line
163 INTEGER, INTENT(OUT) :: cell_itimes
164 REAL(kind=dp), INTENT(OUT) :: cell_time
165 REAL(kind=dp), DIMENSION(3, 3), INTENT(OUT) :: h
166 REAL(kind=dp), INTENT(OUT) :: vol
167
168 INTEGER :: i, j
169
170 READ (input_line, *) cell_itimes, cell_time, &
171 h(1, 1), h(2, 1), h(3, 1), h(1, 2), h(2, 2), h(3, 2), h(1, 3), h(2, 3), h(3, 3), vol
172 DO i = 1, 3
173 DO j = 1, 3
174 h(j, i) = cp_unit_to_cp2k(h(j, i), "angstrom")
175 END DO
176 END DO
177
178 END SUBROUTINE parse_cell_line
179
180! **************************************************************************************************
181!> \brief Get informations about a simulation cell.
182!> \param cell ...
183!> \param alpha ...
184!> \param beta ...
185!> \param gamma ...
186!> \param deth ...
187!> \param orthorhombic ...
188!> \param abc ...
189!> \param periodic ...
190!> \param h ...
191!> \param h_inv ...
192!> \param symmetry_id ...
193!> \param tag ...
194!> \date 16.01.2002
195!> \author Matthias Krack
196!> \version 1.0
197! **************************************************************************************************
198 SUBROUTINE get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, &
199 h, h_inv, symmetry_id, tag)
200
201 TYPE(cell_type), POINTER :: cell
202 REAL(kind=dp), INTENT(OUT), OPTIONAL :: alpha, beta, gamma, deth
203 LOGICAL, INTENT(OUT), OPTIONAL :: orthorhombic
204 REAL(kind=dp), DIMENSION(3), INTENT(OUT), OPTIONAL :: abc
205 INTEGER, DIMENSION(3), INTENT(OUT), OPTIONAL :: periodic
206 REAL(kind=dp), DIMENSION(3, 3), INTENT(OUT), &
207 OPTIONAL :: h, h_inv
208 INTEGER, INTENT(OUT), OPTIONAL :: symmetry_id
209 CHARACTER(LEN=*), INTENT(OUT), OPTIONAL :: tag
210
211 cpassert(ASSOCIATED(cell))
212
213 IF (PRESENT(deth)) deth = cell%deth ! the volume
214 IF (PRESENT(orthorhombic)) orthorhombic = cell%orthorhombic
215 IF (PRESENT(periodic)) periodic(:) = cell%perd(:)
216 IF (PRESENT(h)) h(:, :) = cell%hmat(:, :)
217 IF (PRESENT(h_inv)) h_inv(:, :) = cell%h_inv(:, :)
218
219 ! Calculate the lengths of the cell vectors a, b, and c
220 IF (PRESENT(abc)) THEN
221 abc(1) = sqrt(cell%hmat(1, 1)*cell%hmat(1, 1) + &
222 cell%hmat(2, 1)*cell%hmat(2, 1) + &
223 cell%hmat(3, 1)*cell%hmat(3, 1))
224 abc(2) = sqrt(cell%hmat(1, 2)*cell%hmat(1, 2) + &
225 cell%hmat(2, 2)*cell%hmat(2, 2) + &
226 cell%hmat(3, 2)*cell%hmat(3, 2))
227 abc(3) = sqrt(cell%hmat(1, 3)*cell%hmat(1, 3) + &
228 cell%hmat(2, 3)*cell%hmat(2, 3) + &
229 cell%hmat(3, 3)*cell%hmat(3, 3))
230 END IF
231
232 ! Angles between the cell vectors a, b, and c
233 ! alpha = <(b,c)
234 IF (PRESENT(alpha)) alpha = angle(cell%hmat(:, 2), cell%hmat(:, 3))*degree
235 ! beta = <(a,c)
236 IF (PRESENT(beta)) beta = angle(cell%hmat(:, 1), cell%hmat(:, 3))*degree
237 ! gamma = <(a,b)
238 IF (PRESENT(gamma)) gamma = angle(cell%hmat(:, 1), cell%hmat(:, 2))*degree
239 IF (PRESENT(symmetry_id)) symmetry_id = cell%symmetry_id
240 IF (PRESENT(tag)) tag = cell%tag
241
242 END SUBROUTINE get_cell
243
244! **************************************************************************************************
245!> \brief Calculate the distance between two lattice planes as defined by
246!> a triple of Miller indices (hkl).
247!> \param h ...
248!> \param k ...
249!> \param l ...
250!> \param cell ...
251!> \return ...
252!> \date 18.11.2004
253!> \author Matthias Krack
254!> \version 1.0
255! **************************************************************************************************
256 FUNCTION plane_distance(h, k, l, cell) RESULT(distance)
257
258 INTEGER, INTENT(IN) :: h, k, l
259 TYPE(cell_type), POINTER :: cell
260 REAL(kind=dp) :: distance
261
262 REAL(kind=dp) :: a, alpha, b, beta, c, cosa, cosb, cosg, &
263 d, gamma, x, y, z
264 REAL(kind=dp), DIMENSION(3) :: abc
265
266 x = real(h, kind=dp)
267 y = real(k, kind=dp)
268 z = real(l, kind=dp)
269
270 CALL get_cell(cell=cell, abc=abc)
271
272 a = abc(1)
273 b = abc(2)
274 c = abc(3)
275
276 IF (cell%orthorhombic) THEN
277
278 d = (x/a)**2 + (y/b)**2 + (z/c)**2
279
280 ELSE
281
282 CALL get_cell(cell=cell, &
283 alpha=alpha, &
284 beta=beta, &
285 gamma=gamma)
286
287 alpha = alpha/degree
288 beta = beta/degree
290
291 cosa = cos(alpha)
292 cosb = cos(beta)
293 cosg = cos(gamma)
294
295 d = ((x*b*c*sin(alpha))**2 + &
296 (y*c*a*sin(beta))**2 + &
297 (z*a*b*sin(gamma))**2 + &
298 2.0_dp*a*b*c*(x*y*c*(cosa*cosb - cosg) + &
299 z*x*b*(cosg*cosa - cosb) + &
300 y*z*a*(cosb*cosg - cosa)))/ &
301 ((a*b*c)**2*(1.0_dp - cosa**2 - cosb**2 - cosg**2 + &
302 2.0_dp*cosa*cosb*cosg))
303
304 END IF
305
306 distance = 1.0_dp/sqrt(d)
307
308 END FUNCTION plane_distance
309
310! **************************************************************************************************
311!> \brief Apply the periodic boundary conditions defined by a simulation
312!> cell to a position vector r.
313!> \param r ...
314!> \param cell ...
315!> \return ...
316!> \date 16.01.2002
317!> \author Matthias Krack
318!> \version 1.0
319! **************************************************************************************************
320 FUNCTION pbc1(r, cell) RESULT(r_pbc)
321
322 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: r
323 TYPE(cell_type), POINTER :: cell
324 REAL(kind=dp), DIMENSION(3) :: r_pbc
325
326 REAL(kind=dp), DIMENSION(3) :: s
327
328 cpassert(ASSOCIATED(cell))
329
330 IF (cell%orthorhombic) THEN
331 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*anint(cell%h_inv(1, 1)*r(1))
332 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*anint(cell%h_inv(2, 2)*r(2))
333 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*anint(cell%h_inv(3, 3)*r(3))
334 ELSE
335 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
336 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
337 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
338 s(1) = s(1) - cell%perd(1)*anint(s(1))
339 s(2) = s(2) - cell%perd(2)*anint(s(2))
340 s(3) = s(3) - cell%perd(3)*anint(s(3))
341 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
342 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
343 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
344 END IF
345
346 END FUNCTION pbc1
347
348! **************************************************************************************************
349!> \brief Apply the periodic boundary conditions defined by a simulation
350!> cell to a position vector r subtracting nl from the periodic images
351!> \param r ...
352!> \param cell ...
353!> \param nl ...
354!> \return ...
355!> \date 16.01.2002
356!> \author Matthias Krack
357!> \version 1.0
358! **************************************************************************************************
359 FUNCTION pbc2(r, cell, nl) RESULT(r_pbc)
360
361 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: r
362 TYPE(cell_type), POINTER :: cell
363 INTEGER, DIMENSION(3), INTENT(IN) :: nl
364 REAL(kind=dp), DIMENSION(3) :: r_pbc
365
366 REAL(kind=dp), DIMENSION(3) :: s
367
368 cpassert(ASSOCIATED(cell))
369
370 IF (cell%orthorhombic) THEN
371 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
372 REAL(nint(cell%h_inv(1, 1)*r(1)) - nl(1), dp)
373 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
374 REAL(nint(cell%h_inv(2, 2)*r(2)) - nl(2), dp)
375 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
376 REAL(nint(cell%h_inv(3, 3)*r(3)) - nl(3), dp)
377 ELSE
378 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
379 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
380 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
381 s(1) = s(1) - cell%perd(1)*real(nint(s(1)) - nl(1), dp)
382 s(2) = s(2) - cell%perd(2)*real(nint(s(2)) - nl(2), dp)
383 s(3) = s(3) - cell%perd(3)*real(nint(s(3)) - nl(3), dp)
384 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
385 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
386 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
387 END IF
388
389 END FUNCTION pbc2
390
391! **************************************************************************************************
392!> \brief Apply the periodic boundary conditions defined by the simulation
393!> cell cell to the vector pointing from atom a to atom b.
394!> \param ra ...
395!> \param rb ...
396!> \param cell ...
397!> \return ...
398!> \date 11.03.2004
399!> \author Matthias Krack
400!> \version 1.0
401! **************************************************************************************************
402 FUNCTION pbc3(ra, rb, cell) RESULT(rab_pbc)
403
404 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: ra, rb
405 TYPE(cell_type), POINTER :: cell
406 REAL(kind=dp), DIMENSION(3) :: rab_pbc
407
408 INTEGER :: icell, jcell, kcell
409 INTEGER, DIMENSION(3) :: periodic
410 REAL(kind=dp) :: rab2, rab2_pbc
411 REAL(kind=dp), DIMENSION(3) :: r, ra_pbc, rab, rb_image, rb_pbc, s2r
412
413 CALL get_cell(cell=cell, periodic=periodic)
414
415 ra_pbc(:) = pbc(ra(:), cell)
416 rb_pbc(:) = pbc(rb(:), cell)
417
418 rab2_pbc = huge(1.0_dp)
419
420 DO icell = -periodic(1), periodic(1)
421 DO jcell = -periodic(2), periodic(2)
422 DO kcell = -periodic(3), periodic(3)
423 r = real([icell, jcell, kcell], dp)
424 CALL scaled_to_real(s2r, r, cell)
425 rb_image(:) = rb_pbc(:) + s2r
426 rab(:) = rb_image(:) - ra_pbc(:)
427 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
428 IF (rab2 < rab2_pbc) THEN
429 rab2_pbc = rab2
430 rab_pbc(:) = rab(:)
431 END IF
432 END DO
433 END DO
434 END DO
435
436 END FUNCTION pbc3
437
438 !if positive_range == true, r(i) (or s(i)) in range [0, hmat(i,i)],
439 !else, r(i) (s(i)) in range [-hmat(i,i)/2, hmat(i,i)/2]
440! **************************************************************************************************
441!> \brief ...
442!> \param r ...
443!> \param cell ...
444!> \param positive_range ...
445!> \return ...
446! **************************************************************************************************
447 FUNCTION pbc4(r, cell, positive_range) RESULT(r_pbc)
448
449 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: r
450 TYPE(cell_type), POINTER :: cell
451 LOGICAL :: positive_range
452 REAL(kind=dp), DIMENSION(3) :: r_pbc
453
454 REAL(kind=dp), DIMENSION(3) :: s
455
456 cpassert(ASSOCIATED(cell))
457
458 IF (positive_range) THEN
459 IF (cell%orthorhombic) THEN
460 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*floor(cell%h_inv(1, 1)*r(1))
461 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*floor(cell%h_inv(2, 2)*r(2))
462 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*floor(cell%h_inv(3, 3)*r(3))
463 ELSE
464 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
465 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
466 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
467 s(1) = s(1) - cell%perd(1)*floor(s(1))
468 s(2) = s(2) - cell%perd(2)*floor(s(2))
469 s(3) = s(3) - cell%perd(3)*floor(s(3))
470 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
471 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
472 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
473 END IF
474 ELSE
475 r_pbc = pbc1(r, cell)
476 END IF
477
478 END FUNCTION pbc4
479
480! **************************************************************************************************
481!> \brief Transform real to scaled cell coordinates.
482!> s=h_inv*r
483!> \param s ...
484!> \param r ...
485!> \param cell ...
486!> \date 16.01.2002
487!> \author Matthias Krack
488!> \version 1.0
489! **************************************************************************************************
490 SUBROUTINE real_to_scaled(s, r, cell)
491
492 REAL(kind=dp), DIMENSION(3), INTENT(OUT) :: s
493 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: r
494 TYPE(cell_type), POINTER :: cell
495
496 cpassert(ASSOCIATED(cell))
497
498 IF (cell%orthorhombic) THEN
499 s(1) = cell%h_inv(1, 1)*r(1)
500 s(2) = cell%h_inv(2, 2)*r(2)
501 s(3) = cell%h_inv(3, 3)*r(3)
502 ELSE
503 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
504 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
505 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
506 END IF
507
508 END SUBROUTINE real_to_scaled
509
510! **************************************************************************************************
511!> \brief Transform scaled cell coordinates real coordinates.
512!> r=h*s
513!> \param r ...
514!> \param s ...
515!> \param cell ...
516!> \date 16.01.2002
517!> \author Matthias Krack
518!> \version 1.0
519! **************************************************************************************************
520 SUBROUTINE scaled_to_real(r, s, cell)
521
522 REAL(kind=dp), DIMENSION(3), INTENT(OUT) :: r
523 REAL(kind=dp), DIMENSION(3), INTENT(IN) :: s
524 TYPE(cell_type), POINTER :: cell
525
526 cpassert(ASSOCIATED(cell))
527
528 IF (cell%orthorhombic) THEN
529 r(1) = cell%hmat(1, 1)*s(1)
530 r(2) = cell%hmat(2, 2)*s(2)
531 r(3) = cell%hmat(3, 3)*s(3)
532 ELSE
533 r(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
534 r(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
535 r(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
536 END IF
537
538 END SUBROUTINE scaled_to_real
539! **************************************************************************************************
540!> \brief retains the given cell (see doc/ReferenceCounting.html)
541!> \param cell the cell to retain
542!> \par History
543!> 09.2003 created [fawzi]
544!> \author Fawzi Mohamed
545! **************************************************************************************************
546 SUBROUTINE cell_retain(cell)
547
548 TYPE(cell_type), POINTER :: cell
549
550 cpassert(ASSOCIATED(cell))
551 cpassert(cell%ref_count > 0)
552 cell%ref_count = cell%ref_count + 1
553
554 END SUBROUTINE cell_retain
555
556! **************************************************************************************************
557!> \brief releases the given cell (see doc/ReferenceCounting.html)
558!> \param cell the cell to release
559!> \par History
560!> 09.2003 created [fawzi]
561!> \author Fawzi Mohamed
562! **************************************************************************************************
563 SUBROUTINE cell_release(cell)
564
565 TYPE(cell_type), POINTER :: cell
566
567 IF (ASSOCIATED(cell)) THEN
568 cpassert(cell%ref_count > 0)
569 cell%ref_count = cell%ref_count - 1
570 IF (cell%ref_count == 0) THEN
571 DEALLOCATE (cell)
572 END IF
573 NULLIFY (cell)
574 END IF
575
576 END SUBROUTINE cell_release
577
578#if defined (__PLUMED2)
579! **************************************************************************************************
580!> \brief For the interface with plumed, pass a cell pointer and retrieve it
581!> later. It's a hack, but avoids passing the cell back and forth
582!> across the Fortran/C++ interface
583!> \param cell ...
584!> \param set ...
585!> \date 28.02.2013
586!> \author RK
587!> \version 1.0
588! **************************************************************************************************
589 SUBROUTINE pbc_cp2k_plumed_getset_cell(cell, set)
590
591 TYPE(cell_type), POINTER :: cell
592 LOGICAL :: set
593
594 TYPE(cell_type), POINTER, SAVE :: stored_cell
595
596 IF (set) THEN
597 stored_cell => cell
598 ELSE
599 cell => stored_cell
600 END IF
601
602 END SUBROUTINE pbc_cp2k_plumed_getset_cell
603#endif
604
605END MODULE cell_types
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition cell_types.F:521
integer, parameter, public use_perd_xyz
Definition cell_types.F:42
subroutine, public parse_cell_line(input_line, cell_itimes, cell_time, h, vol)
Read cell info from a line (parsed from a file)
Definition cell_types.F:161
integer, parameter, public cell_sym_monoclinic
Definition cell_types.F:29
integer, parameter, public use_perd_y
Definition cell_types.F:42
integer, parameter, public cell_sym_triclinic
Definition cell_types.F:29
integer, parameter, public cell_sym_tetragonal_ab
Definition cell_types.F:29
integer, parameter, public use_perd_xz
Definition cell_types.F:42
integer, parameter, public cell_sym_rhombohedral
Definition cell_types.F:29
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition cell_types.F:491
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
Definition cell_types.F:564
integer, parameter, public use_perd_x
Definition cell_types.F:42
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
Definition cell_types.F:112
integer, parameter, public cell_sym_tetragonal_ac
Definition cell_types.F:29
integer, parameter, public use_perd_z
Definition cell_types.F:42
integer, parameter, public use_perd_yz
Definition cell_types.F:42
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
Definition cell_types.F:200
integer, parameter, public use_perd_none
Definition cell_types.F:42
subroutine, public cell_retain(cell)
retains the given cell (see doc/ReferenceCounting.html)
Definition cell_types.F:547
integer, parameter, public cell_sym_hexagonal_gamma_60
Definition cell_types.F:29
character(len=3), dimension(7), parameter, public periodicity_string
Definition cell_types.F:51
integer, parameter, public cell_sym_orthorhombic
Definition cell_types.F:29
integer, parameter, public cell_sym_none
Definition cell_types.F:29
integer, parameter, public cell_sym_hexagonal_gamma_120
Definition cell_types.F:29
subroutine, public cell_copy(cell_in, cell_out, tag)
Copy cell variable.
Definition cell_types.F:131
integer, parameter, public cell_sym_monoclinic_gamma_ab
Definition cell_types.F:29
integer, parameter, public cell_sym_cubic
Definition cell_types.F:29
integer, parameter, public use_perd_xy
Definition cell_types.F:42
integer, parameter, public cell_sym_tetragonal_bc
Definition cell_types.F:29
real(kind=dp) function, public plane_distance(h, k, l, cell)
Calculate the distance between two lattice planes as defined by a triple of Miller indices (hkl).
Definition cell_types.F:257
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_to_cp2k(value, unit_str, defaults, power)
converts to the internal cp2k units to the given unit
Definition cp_units.F:1149
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Definition gamma.F:15
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Definition of mathematical constants and functions.
real(kind=dp), parameter, public degree
Collection of simple mathematical functions and subroutines.
Definition mathlib.F:15
pure real(kind=dp) function, public angle(a, b)
Calculation of the angle between the vectors a and b. The angle is returned in radians.
Definition mathlib.F:183
Type defining parameters related to the simulation cell.
Definition cell_types.F:60