20#include "../base/base_uses.f90"
26 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'cell_types'
51 CHARACTER(LEN=3),
DIMENSION(7), &
53 " XY",
" XZ",
" YZ", &
61 CHARACTER(LEN=12) :: tag =
"CELL"
62 INTEGER :: ref_count = -1, &
64 LOGICAL :: orthorhombic = .false.
65 LOGICAL :: input_cell_canonicalized = .false.
66 REAL(kind=
dp) :: deth = 0.0_dp
67 INTEGER,
DIMENSION(3) :: perd = -1
68 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat = 0.0_dp, &
70 input_hmat = 0.0_dp, &
71 input_to_canonical = 0.0_dp, &
72 input_recip_to_canonical = 0.0_dp
93#if defined (__PLUMED2)
94 PUBLIC :: pbc_cp2k_plumed_getset_cell
104 MODULE PROCEDURE pbc1, pbc2, pbc3, pbc4
119 TYPE(
cell_type),
POINTER :: cell_in, cell_out
120 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
123 cell_out%ref_count = 1
124 IF (
PRESENT(tag)) cell_out%tag = tag
138 TYPE(
cell_type),
POINTER :: cell_in, cell_out
139 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
141 cell_out%deth = cell_in%deth
142 cell_out%perd = cell_in%perd
143 cell_out%hmat = cell_in%hmat
144 cell_out%h_inv = cell_in%h_inv
145 cell_out%input_cell_canonicalized = cell_in%input_cell_canonicalized
146 cell_out%input_hmat = cell_in%input_hmat
147 cell_out%input_to_canonical = cell_in%input_to_canonical
148 cell_out%input_recip_to_canonical = cell_in%input_recip_to_canonical
149 cell_out%orthorhombic = cell_in%orthorhombic
150 cell_out%symmetry_id = cell_in%symmetry_id
151 IF (
PRESENT(tag))
THEN
154 cell_out%tag = cell_in%tag
172 CHARACTER(LEN=*),
INTENT(IN) :: input_line
173 INTEGER,
INTENT(OUT) :: cell_itimes
174 REAL(kind=
dp),
INTENT(OUT) :: cell_time
175 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT) :: h
176 REAL(kind=
dp),
INTENT(OUT) :: vol
180 READ (input_line, *) cell_itimes, cell_time, &
181 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
208 SUBROUTINE get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, &
209 h, h_inv, symmetry_id, tag)
212 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: alpha, beta,
gamma, deth
213 LOGICAL,
INTENT(OUT),
OPTIONAL :: orthorhombic
214 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: abc
215 INTEGER,
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: periodic
216 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT), &
218 INTEGER,
INTENT(OUT),
OPTIONAL :: symmetry_id
219 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: tag
221 cpassert(
ASSOCIATED(cell))
223 IF (
PRESENT(deth)) deth = cell%deth
224 IF (
PRESENT(orthorhombic)) orthorhombic = cell%orthorhombic
225 IF (
PRESENT(periodic)) periodic(:) = cell%perd(:)
226 IF (
PRESENT(h)) h(:, :) = cell%hmat(:, :)
227 IF (
PRESENT(h_inv)) h_inv(:, :) = cell%h_inv(:, :)
230 IF (
PRESENT(abc))
THEN
231 abc(1) = sqrt(cell%hmat(1, 1)*cell%hmat(1, 1) + &
232 cell%hmat(2, 1)*cell%hmat(2, 1) + &
233 cell%hmat(3, 1)*cell%hmat(3, 1))
234 abc(2) = sqrt(cell%hmat(1, 2)*cell%hmat(1, 2) + &
235 cell%hmat(2, 2)*cell%hmat(2, 2) + &
236 cell%hmat(3, 2)*cell%hmat(3, 2))
237 abc(3) = sqrt(cell%hmat(1, 3)*cell%hmat(1, 3) + &
238 cell%hmat(2, 3)*cell%hmat(2, 3) + &
239 cell%hmat(3, 3)*cell%hmat(3, 3))
244 IF (
PRESENT(alpha)) alpha =
angle(cell%hmat(:, 2), cell%hmat(:, 3))*
degree
246 IF (
PRESENT(beta)) beta =
angle(cell%hmat(:, 1), cell%hmat(:, 3))*
degree
249 IF (
PRESENT(symmetry_id)) symmetry_id = cell%symmetry_id
250 IF (
PRESENT(tag)) tag = cell%tag
263 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT) :: vector
265 cpassert(
ASSOCIATED(cell))
267 IF (cell%input_cell_canonicalized) vector = matmul(cell%input_to_canonical, vector)
280 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT) :: vector
282 cpassert(
ASSOCIATED(cell))
284 IF (cell%input_cell_canonicalized) vector = matmul(cell%input_recip_to_canonical, vector)
302 INTEGER,
INTENT(IN) :: h, k, l
304 REAL(kind=
dp) :: distance
306 REAL(kind=
dp) :: a, alpha, b, beta, c, cosa, cosb, cosg, &
308 REAL(kind=
dp),
DIMENSION(3) :: abc
320 IF (cell%orthorhombic)
THEN
322 d = (x/a)**2 + (y/b)**2 + (z/c)**2
339 d = ((x*b*c*sin(alpha))**2 + &
340 (y*c*a*sin(beta))**2 + &
341 (z*a*b*sin(
gamma))**2 + &
342 2.0_dp*a*b*c*(x*y*c*(cosa*cosb - cosg) + &
343 z*x*b*(cosg*cosa - cosb) + &
344 y*z*a*(cosb*cosg - cosa)))/ &
345 ((a*b*c)**2*(1.0_dp - cosa**2 - cosb**2 - cosg**2 + &
346 2.0_dp*cosa*cosb*cosg))
350 distance = 1.0_dp/sqrt(d)
364 FUNCTION pbc1(r, cell)
RESULT(r_pbc)
366 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
368 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
370 REAL(kind=
dp),
DIMENSION(3) :: s
372 cpassert(
ASSOCIATED(cell))
374 IF (cell%orthorhombic)
THEN
375 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*anint(cell%h_inv(1, 1)*r(1))
376 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*anint(cell%h_inv(2, 2)*r(2))
377 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*anint(cell%h_inv(3, 3)*r(3))
379 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
380 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
381 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
382 s(1) = s(1) - cell%perd(1)*anint(s(1))
383 s(2) = s(2) - cell%perd(2)*anint(s(2))
384 s(3) = s(3) - cell%perd(3)*anint(s(3))
385 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
386 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
387 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
403 FUNCTION pbc2(r, cell, nl)
RESULT(r_pbc)
405 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
407 INTEGER,
DIMENSION(3),
INTENT(IN) :: nl
408 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
410 REAL(kind=
dp),
DIMENSION(3) :: s
412 cpassert(
ASSOCIATED(cell))
414 IF (cell%orthorhombic)
THEN
415 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
416 REAL(nint(cell%h_inv(1, 1)*r(1)) - nl(1),
dp)
417 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
418 REAL(nint(cell%h_inv(2, 2)*r(2)) - nl(2),
dp)
419 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
420 REAL(nint(cell%h_inv(3, 3)*r(3)) - nl(3),
dp)
422 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
423 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
424 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
425 s(1) = s(1) - cell%perd(1)*real(nint(s(1)) - nl(1),
dp)
426 s(2) = s(2) - cell%perd(2)*real(nint(s(2)) - nl(2),
dp)
427 s(3) = s(3) - cell%perd(3)*real(nint(s(3)) - nl(3),
dp)
428 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
429 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
430 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
446 FUNCTION pbc3(ra, rb, cell)
RESULT(rab_pbc)
448 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: ra, rb
450 REAL(kind=
dp),
DIMENSION(3) :: rab_pbc
452 INTEGER :: icell, jcell, kcell
453 INTEGER,
DIMENSION(3) :: periodic
454 REAL(kind=
dp) :: rab2, rab2_pbc
455 REAL(kind=
dp),
DIMENSION(3) :: r, ra_pbc, rab, rb_image, rb_pbc, s2r
457 CALL get_cell(cell=cell, periodic=periodic)
459 ra_pbc(:) =
pbc(ra(:), cell)
460 rb_pbc(:) =
pbc(rb(:), cell)
462 rab2_pbc = huge(1.0_dp)
464 DO icell = -periodic(1), periodic(1)
465 DO jcell = -periodic(2), periodic(2)
466 DO kcell = -periodic(3), periodic(3)
467 r = real([icell, jcell, kcell],
dp)
469 rb_image(:) = rb_pbc(:) + s2r
470 rab(:) = rb_image(:) - ra_pbc(:)
471 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
472 IF (rab2 < rab2_pbc)
THEN
491 FUNCTION pbc4(r, cell, positive_range)
RESULT(r_pbc)
493 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
495 LOGICAL :: positive_range
496 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
498 REAL(kind=
dp),
DIMENSION(3) :: s
500 cpassert(
ASSOCIATED(cell))
502 IF (positive_range)
THEN
503 IF (cell%orthorhombic)
THEN
504 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*floor(cell%h_inv(1, 1)*r(1))
505 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*floor(cell%h_inv(2, 2)*r(2))
506 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*floor(cell%h_inv(3, 3)*r(3))
508 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
509 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
510 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
511 s(1) = s(1) - cell%perd(1)*floor(s(1))
512 s(2) = s(2) - cell%perd(2)*floor(s(2))
513 s(3) = s(3) - cell%perd(3)*floor(s(3))
514 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
515 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
516 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
519 r_pbc = pbc1(r, cell)
536 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: s
537 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
540 cpassert(
ASSOCIATED(cell))
542 IF (cell%orthorhombic)
THEN
543 s(1) = cell%h_inv(1, 1)*r(1)
544 s(2) = cell%h_inv(2, 2)*r(2)
545 s(3) = cell%h_inv(3, 3)*r(3)
547 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
548 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
549 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
566 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: r
567 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: s
570 cpassert(
ASSOCIATED(cell))
572 IF (cell%orthorhombic)
THEN
573 r(1) = cell%hmat(1, 1)*s(1)
574 r(2) = cell%hmat(2, 2)*s(2)
575 r(3) = cell%hmat(3, 3)*s(3)
577 r(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
578 r(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
579 r(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
594 cpassert(
ASSOCIATED(cell))
595 cpassert(cell%ref_count > 0)
596 cell%ref_count = cell%ref_count + 1
611 IF (
ASSOCIATED(cell))
THEN
612 cpassert(cell%ref_count > 0)
613 cell%ref_count = cell%ref_count - 1
614 IF (cell%ref_count == 0)
THEN
622#if defined (__PLUMED2)
633 SUBROUTINE pbc_cp2k_plumed_getset_cell(cell, set)
638 TYPE(
cell_type),
POINTER,
SAVE :: stored_cell
646 END SUBROUTINE pbc_cp2k_plumed_getset_cell
Handles all functions related to the CELL.
subroutine, public cell_transform_input_reciprocal(cell, vector)
Transform a Cartesian reciprocal-space vector from the user input cell frame into CP2K's canonical in...
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
character(len=3), dimension(7), parameter, public periodicity_string
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
subroutine, public cell_transform_input_cartesian(cell, vector)
Transform a Cartesian real-space vector from the user input cell frame into CP2K's canonical internal...
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.
Type defining parameters related to the simulation cell.