20 #include "../base/base_uses.f90"
26 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cell_types'
56 CHARACTER(LEN=12) :: tag =
"CELL"
57 INTEGER :: ref_count = -1, &
59 LOGICAL :: orthorhombic = .false.
60 REAL(kind=
dp) :: deth = 0.0_dp
61 INTEGER,
DIMENSION(3) :: perd = -1
62 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat = 0.0_dp, &
67 TYPE(cell_type),
POINTER :: cell => null()
71 PUBLIC :: cell_type, &
82 #if defined (__PLUMED2)
83 PUBLIC :: pbc_cp2k_plumed_getset_cell
93 MODULE PROCEDURE pbc1, pbc2, pbc3, pbc4
108 TYPE(cell_type),
POINTER :: cell_in, cell_out
109 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
112 cell_out%ref_count = 1
113 IF (
PRESENT(tag)) cell_out%tag = tag
127 TYPE(cell_type),
POINTER :: cell_in, cell_out
128 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
130 cell_out%deth = cell_in%deth
131 cell_out%perd = cell_in%perd
132 cell_out%hmat = cell_in%hmat
133 cell_out%h_inv = cell_in%h_inv
134 cell_out%orthorhombic = cell_in%orthorhombic
135 cell_out%symmetry_id = cell_in%symmetry_id
136 IF (
PRESENT(tag))
THEN
139 cell_out%tag = cell_in%tag
157 CHARACTER(LEN=*),
INTENT(IN) :: input_line
158 INTEGER,
INTENT(OUT) :: cell_itimes
159 REAL(kind=
dp),
INTENT(OUT) :: cell_time
160 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT) :: h
161 REAL(kind=
dp),
INTENT(OUT) :: vol
165 READ (input_line, *) cell_itimes, cell_time, &
166 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
193 SUBROUTINE get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, &
194 h, h_inv, symmetry_id, tag)
196 TYPE(cell_type),
POINTER :: cell
197 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: alpha, beta,
gamma, deth
198 LOGICAL,
INTENT(OUT),
OPTIONAL :: orthorhombic
199 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: abc
200 INTEGER,
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: periodic
201 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT), &
203 INTEGER,
INTENT(OUT),
OPTIONAL :: symmetry_id
204 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: tag
206 cpassert(
ASSOCIATED(cell))
208 IF (
PRESENT(deth)) deth = cell%deth
209 IF (
PRESENT(orthorhombic)) orthorhombic = cell%orthorhombic
210 IF (
PRESENT(periodic)) periodic(:) = cell%perd(:)
211 IF (
PRESENT(h)) h(:, :) = cell%hmat(:, :)
212 IF (
PRESENT(h_inv)) h_inv(:, :) = cell%h_inv(:, :)
215 IF (
PRESENT(abc))
THEN
216 abc(1) = sqrt(cell%hmat(1, 1)*cell%hmat(1, 1) + &
217 cell%hmat(2, 1)*cell%hmat(2, 1) + &
218 cell%hmat(3, 1)*cell%hmat(3, 1))
219 abc(2) = sqrt(cell%hmat(1, 2)*cell%hmat(1, 2) + &
220 cell%hmat(2, 2)*cell%hmat(2, 2) + &
221 cell%hmat(3, 2)*cell%hmat(3, 2))
222 abc(3) = sqrt(cell%hmat(1, 3)*cell%hmat(1, 3) + &
223 cell%hmat(2, 3)*cell%hmat(2, 3) + &
224 cell%hmat(3, 3)*cell%hmat(3, 3))
229 IF (
PRESENT(alpha)) alpha =
angle(cell%hmat(:, 2), cell%hmat(:, 3))*
degree
231 IF (
PRESENT(beta)) beta =
angle(cell%hmat(:, 1), cell%hmat(:, 3))*
degree
234 IF (
PRESENT(symmetry_id)) symmetry_id = cell%symmetry_id
235 IF (
PRESENT(tag)) tag = cell%tag
253 INTEGER,
INTENT(IN) :: h, k, l
254 TYPE(cell_type),
POINTER :: cell
255 REAL(kind=
dp) :: distance
257 REAL(kind=
dp) :: a, alpha, b, beta, c, cosa, cosb, cosg, &
259 REAL(kind=
dp),
DIMENSION(3) :: abc
271 IF (cell%orthorhombic)
THEN
273 d = (x/a)**2 + (y/b)**2 + (z/c)**2
290 d = ((x*b*c*sin(alpha))**2 + &
291 (y*c*a*sin(beta))**2 + &
292 (z*a*b*sin(
gamma))**2 + &
293 2.0_dp*a*b*c*(x*y*c*(cosa*cosb - cosg) + &
294 z*x*b*(cosg*cosa - cosb) + &
295 y*z*a*(cosb*cosg - cosa)))/ &
296 ((a*b*c)**2*(1.0_dp - cosa**2 - cosb**2 - cosg**2 + &
297 2.0_dp*cosa*cosb*cosg))
301 distance = 1.0_dp/sqrt(d)
315 FUNCTION pbc1(r, cell)
RESULT(r_pbc)
317 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
318 TYPE(cell_type),
POINTER :: cell
319 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
321 REAL(kind=
dp),
DIMENSION(3) :: s
323 cpassert(
ASSOCIATED(cell))
325 IF (cell%orthorhombic)
THEN
326 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*anint(cell%h_inv(1, 1)*r(1))
327 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*anint(cell%h_inv(2, 2)*r(2))
328 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*anint(cell%h_inv(3, 3)*r(3))
330 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
331 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
332 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
333 s(1) = s(1) - cell%perd(1)*anint(s(1))
334 s(2) = s(2) - cell%perd(2)*anint(s(2))
335 s(3) = s(3) - cell%perd(3)*anint(s(3))
336 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
337 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
338 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
354 FUNCTION pbc2(r, cell, nl)
RESULT(r_pbc)
356 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
357 TYPE(cell_type),
POINTER :: cell
358 INTEGER,
DIMENSION(3),
INTENT(IN) :: nl
359 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
361 REAL(kind=
dp),
DIMENSION(3) :: s
363 cpassert(
ASSOCIATED(cell))
365 IF (cell%orthorhombic)
THEN
366 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
367 REAL(nint(cell%h_inv(1, 1)*r(1)) - nl(1),
dp)
368 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
369 REAL(nint(cell%h_inv(2, 2)*r(2)) - nl(2),
dp)
370 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
371 REAL(nint(cell%h_inv(3, 3)*r(3)) - nl(3),
dp)
373 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
374 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
375 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
376 s(1) = s(1) - cell%perd(1)*real(nint(s(1)) - nl(1),
dp)
377 s(2) = s(2) - cell%perd(2)*real(nint(s(2)) - nl(2),
dp)
378 s(3) = s(3) - cell%perd(3)*real(nint(s(3)) - nl(3),
dp)
379 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
380 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
381 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
397 FUNCTION pbc3(ra, rb, cell)
RESULT(rab_pbc)
399 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: ra, rb
400 TYPE(cell_type),
POINTER :: cell
401 REAL(kind=
dp),
DIMENSION(3) :: rab_pbc
403 INTEGER :: icell, jcell, kcell
404 INTEGER,
DIMENSION(3) :: periodic
405 REAL(kind=
dp) :: rab2, rab2_pbc
406 REAL(kind=
dp),
DIMENSION(3) :: r, ra_pbc, rab, rb_image, rb_pbc, s2r
408 CALL get_cell(cell=cell, periodic=periodic)
410 ra_pbc(:) =
pbc(ra(:), cell)
411 rb_pbc(:) =
pbc(rb(:), cell)
413 rab2_pbc = huge(1.0_dp)
415 DO icell = -periodic(1), periodic(1)
416 DO jcell = -periodic(2), periodic(2)
417 DO kcell = -periodic(3), periodic(3)
418 r = real((/icell, jcell, kcell/),
dp)
420 rb_image(:) = rb_pbc(:) + s2r
421 rab(:) = rb_image(:) - ra_pbc(:)
422 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
423 IF (rab2 < rab2_pbc)
THEN
442 FUNCTION pbc4(r, cell, positive_range)
RESULT(r_pbc)
444 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
445 TYPE(cell_type),
POINTER :: cell
446 LOGICAL :: positive_range
447 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
449 REAL(kind=
dp),
DIMENSION(3) :: s
451 cpassert(
ASSOCIATED(cell))
453 IF (positive_range)
THEN
454 IF (cell%orthorhombic)
THEN
455 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*floor(cell%h_inv(1, 1)*r(1))
456 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*floor(cell%h_inv(2, 2)*r(2))
457 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*floor(cell%h_inv(3, 3)*r(3))
459 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
460 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
461 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
462 s(1) = s(1) - cell%perd(1)*floor(s(1))
463 s(2) = s(2) - cell%perd(2)*floor(s(2))
464 s(3) = s(3) - cell%perd(3)*floor(s(3))
465 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
466 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
467 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
470 r_pbc = pbc1(r, cell)
487 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: s
488 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
489 TYPE(cell_type),
POINTER :: cell
491 cpassert(
ASSOCIATED(cell))
493 IF (cell%orthorhombic)
THEN
494 s(1) = cell%h_inv(1, 1)*r(1)
495 s(2) = cell%h_inv(2, 2)*r(2)
496 s(3) = cell%h_inv(3, 3)*r(3)
498 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
499 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
500 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
517 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: r
518 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: s
519 TYPE(cell_type),
POINTER :: cell
521 cpassert(
ASSOCIATED(cell))
523 IF (cell%orthorhombic)
THEN
524 r(1) = cell%hmat(1, 1)*s(1)
525 r(2) = cell%hmat(2, 2)*s(2)
526 r(3) = cell%hmat(3, 3)*s(3)
528 r(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
529 r(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
530 r(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
543 TYPE(cell_type),
POINTER :: cell
545 cpassert(
ASSOCIATED(cell))
546 cpassert(cell%ref_count > 0)
547 cell%ref_count = cell%ref_count + 1
560 TYPE(cell_type),
POINTER :: cell
562 IF (
ASSOCIATED(cell))
THEN
563 cpassert(cell%ref_count > 0)
564 cell%ref_count = cell%ref_count - 1
565 IF (cell%ref_count == 0)
THEN
573 #if defined (__PLUMED2)
584 SUBROUTINE pbc_cp2k_plumed_getset_cell(cell, set)
586 TYPE(cell_type),
POINTER :: cell
589 TYPE(cell_type),
POINTER,
SAVE :: stored_cell
597 END SUBROUTINE pbc_cp2k_plumed_getset_cell
subroutine pbc(r, r_pbc, s, s_pbc, a, b, c, alpha, beta, gamma, debug, info, pbc0, h, hinv)
...
Handles all functions related to the CELL.
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
integer, parameter, public use_perd_xyz
subroutine, public parse_cell_line(input_line, cell_itimes, cell_time, h, vol)
Read cell info from a line (parsed from a file)
integer, parameter, public cell_sym_monoclinic
integer, parameter, public use_perd_y
integer, parameter, public cell_sym_triclinic
integer, parameter, public cell_sym_tetragonal_ab
integer, parameter, public use_perd_xz
integer, parameter, public cell_sym_rhombohedral
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
integer, parameter, public use_perd_x
subroutine, public cell_clone(cell_in, cell_out, tag)
Clone cell variable.
integer, parameter, public cell_sym_tetragonal_ac
integer, parameter, public use_perd_z
integer, parameter, public use_perd_yz
subroutine, public get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, h, h_inv, symmetry_id, tag)
Get informations about a simulation cell.
integer, parameter, public use_perd_none
subroutine, public cell_retain(cell)
retains the given cell (see doc/ReferenceCounting.html)
integer, parameter, public cell_sym_hexagonal_gamma_60
integer, parameter, public cell_sym_orthorhombic
integer, parameter, public cell_sym_none
integer, parameter, public cell_sym_hexagonal_gamma_120
subroutine, public cell_copy(cell_in, cell_out, tag)
Copy cell variable.
integer, parameter, public cell_sym_monoclinic_gamma_ab
integer, parameter, public cell_sym_cubic
integer, parameter, public use_perd_xy
integer, parameter, public cell_sym_tetragonal_bc
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).
real(kind=dp) function, public cp_unit_to_cp2k(value, unit_str, defaults, power)
converts to the internal cp2k units to the given unit
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Defines the basic variable types.
integer, parameter, public dp
Definition of mathematical constants and functions.
real(kind=dp), parameter, public degree
Collection of simple mathematical functions and subroutines.
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.