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
94#if defined (__PLUMED2)
95 PUBLIC :: pbc_cp2k_plumed_getset_cell
106 MODULE PROCEDURE pbc1, pbc2, pbc3, pbc4
116 PURE ELEMENTAL FUNCTION pbc_image_shift(s)
RESULT(image_shift)
118 REAL(KIND=
dp),
INTENT(IN) :: s
119 REAL(KIND=
dp) :: image_shift
121 REAL(KIND=
dp) :: half_boundary, tolerance
123 image_shift = anint(s)
124 half_boundary = anint(s - 0.5_dp) + 0.5_dp
125 tolerance = min(1.0e-8_dp, 64.0_dp*epsilon(1.0_dp)*max(1.0_dp, abs(s)))
126 IF (abs(s - half_boundary) <= tolerance)
THEN
128 image_shift = half_boundary + 0.5_dp
131 END FUNCTION pbc_image_shift
143 TYPE(
cell_type),
POINTER :: cell_in, cell_out
144 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
147 cell_out%ref_count = 1
148 IF (
PRESENT(tag)) cell_out%tag = tag
162 TYPE(
cell_type),
POINTER :: cell_in, cell_out
163 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
165 cell_out%deth = cell_in%deth
166 cell_out%perd = cell_in%perd
167 cell_out%hmat = cell_in%hmat
168 cell_out%h_inv = cell_in%h_inv
169 cell_out%input_cell_canonicalized = cell_in%input_cell_canonicalized
170 cell_out%input_hmat = cell_in%input_hmat
171 cell_out%input_to_canonical = cell_in%input_to_canonical
172 cell_out%input_recip_to_canonical = cell_in%input_recip_to_canonical
173 cell_out%orthorhombic = cell_in%orthorhombic
174 cell_out%symmetry_id = cell_in%symmetry_id
175 IF (
PRESENT(tag))
THEN
178 cell_out%tag = cell_in%tag
196 CHARACTER(LEN=*),
INTENT(IN) :: input_line
197 INTEGER,
INTENT(OUT) :: cell_itimes
198 REAL(kind=
dp),
INTENT(OUT) :: cell_time
199 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT) :: h
200 REAL(kind=
dp),
INTENT(OUT) :: vol
204 READ (input_line, *) cell_itimes, cell_time, &
205 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
232 SUBROUTINE get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, &
233 h, h_inv, symmetry_id, tag)
236 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: alpha, beta,
gamma, deth
237 LOGICAL,
INTENT(OUT),
OPTIONAL :: orthorhombic
238 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: abc
239 INTEGER,
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: periodic
240 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT), &
242 INTEGER,
INTENT(OUT),
OPTIONAL :: symmetry_id
243 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: tag
245 cpassert(
ASSOCIATED(cell))
247 IF (
PRESENT(deth)) deth = cell%deth
248 IF (
PRESENT(orthorhombic)) orthorhombic = cell%orthorhombic
249 IF (
PRESENT(periodic)) periodic(:) = cell%perd(:)
250 IF (
PRESENT(h)) h(:, :) = cell%hmat(:, :)
251 IF (
PRESENT(h_inv)) h_inv(:, :) = cell%h_inv(:, :)
254 IF (
PRESENT(abc))
THEN
255 abc(1) = sqrt(cell%hmat(1, 1)*cell%hmat(1, 1) + &
256 cell%hmat(2, 1)*cell%hmat(2, 1) + &
257 cell%hmat(3, 1)*cell%hmat(3, 1))
258 abc(2) = sqrt(cell%hmat(1, 2)*cell%hmat(1, 2) + &
259 cell%hmat(2, 2)*cell%hmat(2, 2) + &
260 cell%hmat(3, 2)*cell%hmat(3, 2))
261 abc(3) = sqrt(cell%hmat(1, 3)*cell%hmat(1, 3) + &
262 cell%hmat(2, 3)*cell%hmat(2, 3) + &
263 cell%hmat(3, 3)*cell%hmat(3, 3))
268 IF (
PRESENT(alpha)) alpha =
angle(cell%hmat(:, 2), cell%hmat(:, 3))*
degree
270 IF (
PRESENT(beta)) beta =
angle(cell%hmat(:, 1), cell%hmat(:, 3))*
degree
273 IF (
PRESENT(symmetry_id)) symmetry_id = cell%symmetry_id
274 IF (
PRESENT(tag)) tag = cell%tag
287 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT) :: vector
289 cpassert(
ASSOCIATED(cell))
291 IF (cell%input_cell_canonicalized) vector = matmul(cell%input_to_canonical, vector)
304 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT) :: vector
306 cpassert(
ASSOCIATED(cell))
308 IF (cell%input_cell_canonicalized) vector = matmul(cell%input_recip_to_canonical, vector)
326 INTEGER,
INTENT(IN) :: h, k, l
328 REAL(kind=
dp) :: distance
330 REAL(kind=
dp) :: a, alpha, b, beta, c, cosa, cosb, cosg, &
332 REAL(kind=
dp),
DIMENSION(3) :: abc
344 IF (cell%orthorhombic)
THEN
346 d = (x/a)**2 + (y/b)**2 + (z/c)**2
363 d = ((x*b*c*sin(alpha))**2 + &
364 (y*c*a*sin(beta))**2 + &
365 (z*a*b*sin(
gamma))**2 + &
366 2.0_dp*a*b*c*(x*y*c*(cosa*cosb - cosg) + &
367 z*x*b*(cosg*cosa - cosb) + &
368 y*z*a*(cosb*cosg - cosa)))/ &
369 ((a*b*c)**2*(1.0_dp - cosa**2 - cosb**2 - cosg**2 + &
370 2.0_dp*cosa*cosb*cosg))
374 distance = 1.0_dp/sqrt(d)
388 FUNCTION pbc1(r, cell)
RESULT(r_pbc)
390 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
392 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
394 REAL(kind=
dp),
DIMENSION(3) :: s
396 cpassert(
ASSOCIATED(cell))
398 IF (cell%orthorhombic)
THEN
399 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*anint(cell%h_inv(1, 1)*r(1))
400 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*anint(cell%h_inv(2, 2)*r(2))
401 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*anint(cell%h_inv(3, 3)*r(3))
403 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
404 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
405 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
406 s(1) = s(1) - cell%perd(1)*anint(s(1))
407 s(2) = s(2) - cell%perd(2)*anint(s(2))
408 s(3) = s(3) - cell%perd(3)*anint(s(3))
409 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
410 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
411 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
426 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: ra, rb
427 TYPE(
cell_type),
INTENT(IN),
POINTER :: cell
428 INTEGER,
DIMENSION(:, :),
INTENT(IN) :: index_to_cell
429 REAL(kind=
dp),
DIMENSION(:),
INTENT(OUT) :: weights
432 REAL(kind=
dp),
DIMENSION(3) :: ra_pbc, rab, rb_pbc
433 REAL(kind=
dp),
DIMENSION(SIZE(index_to_cell, 2)) :: distances
435 cpassert(
SIZE(index_to_cell, 1) == 3)
436 cpassert(
SIZE(index_to_cell, 2) > 0)
437 cpassert(
SIZE(weights) ==
SIZE(index_to_cell, 2))
439 ra_pbc =
pbc(ra, cell)
440 rb_pbc =
pbc(rb, cell)
441 DO i_image = 1,
SIZE(index_to_cell, 2)
442 rab = ra_pbc - (rb_pbc + matmul(cell%hmat, real(index_to_cell(:, i_image), kind=
dp)))
443 distances(i_image) = norm2(rab)
446 weights = merge(1.0_dp, 0.0_dp, distances <= minval(distances) + 1.0e-6_dp)
447 weights = weights/sum(weights)
459 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
461 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
463 REAL(kind=
dp),
DIMENSION(3) :: s
465 cpassert(
ASSOCIATED(cell))
467 IF (cell%orthorhombic)
THEN
468 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
469 pbc_image_shift(cell%h_inv(1, 1)*r(1))
470 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
471 pbc_image_shift(cell%h_inv(2, 2)*r(2))
472 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
473 pbc_image_shift(cell%h_inv(3, 3)*r(3))
475 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
476 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
477 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
478 s(1) = s(1) - cell%perd(1)*pbc_image_shift(s(1))
479 s(2) = s(2) - cell%perd(2)*pbc_image_shift(s(2))
480 s(3) = s(3) - cell%perd(3)*pbc_image_shift(s(3))
481 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
482 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
483 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
499 FUNCTION pbc2(r, cell, nl)
RESULT(r_pbc)
501 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
503 INTEGER,
DIMENSION(3),
INTENT(IN) :: nl
504 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
506 REAL(kind=
dp),
DIMENSION(3) :: s
508 cpassert(
ASSOCIATED(cell))
510 IF (cell%orthorhombic)
THEN
511 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
512 REAL(nint(cell%h_inv(1, 1)*r(1)) - nl(1),
dp)
513 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
514 REAL(nint(cell%h_inv(2, 2)*r(2)) - nl(2),
dp)
515 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
516 REAL(nint(cell%h_inv(3, 3)*r(3)) - nl(3),
dp)
518 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
519 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
520 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
521 s(1) = s(1) - cell%perd(1)*real(nint(s(1)) - nl(1),
dp)
522 s(2) = s(2) - cell%perd(2)*real(nint(s(2)) - nl(2),
dp)
523 s(3) = s(3) - cell%perd(3)*real(nint(s(3)) - nl(3),
dp)
524 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
525 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
526 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
542 FUNCTION pbc3(ra, rb, cell)
RESULT(rab_pbc)
544 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: ra, rb
546 REAL(kind=
dp),
DIMENSION(3) :: rab_pbc
548 INTEGER :: icell, jcell, kcell
549 INTEGER,
DIMENSION(3) :: periodic
550 REAL(kind=
dp) :: rab2, rab2_pbc
551 REAL(kind=
dp),
DIMENSION(3) :: r, ra_pbc, rab, rb_image, rb_pbc, s2r
553 CALL get_cell(cell=cell, periodic=periodic)
555 ra_pbc(:) =
pbc(ra(:), cell)
556 rb_pbc(:) =
pbc(rb(:), cell)
558 rab2_pbc = huge(1.0_dp)
560 DO icell = -periodic(1), periodic(1)
561 DO jcell = -periodic(2), periodic(2)
562 DO kcell = -periodic(3), periodic(3)
563 r = real([icell, jcell, kcell],
dp)
565 rb_image(:) = rb_pbc(:) + s2r
566 rab(:) = rb_image(:) - ra_pbc(:)
567 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
568 IF (rab2 < rab2_pbc)
THEN
587 FUNCTION pbc4(r, cell, positive_range)
RESULT(r_pbc)
589 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
591 LOGICAL :: positive_range
592 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
594 REAL(kind=
dp),
DIMENSION(3) :: s
596 cpassert(
ASSOCIATED(cell))
598 IF (positive_range)
THEN
599 IF (cell%orthorhombic)
THEN
600 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*floor(cell%h_inv(1, 1)*r(1))
601 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*floor(cell%h_inv(2, 2)*r(2))
602 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*floor(cell%h_inv(3, 3)*r(3))
604 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
605 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
606 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
607 s(1) = s(1) - cell%perd(1)*floor(s(1))
608 s(2) = s(2) - cell%perd(2)*floor(s(2))
609 s(3) = s(3) - cell%perd(3)*floor(s(3))
610 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
611 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
612 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
615 r_pbc = pbc1(r, cell)
632 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: s
633 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
636 cpassert(
ASSOCIATED(cell))
638 IF (cell%orthorhombic)
THEN
639 s(1) = cell%h_inv(1, 1)*r(1)
640 s(2) = cell%h_inv(2, 2)*r(2)
641 s(3) = cell%h_inv(3, 3)*r(3)
643 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
644 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
645 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
662 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: r
663 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: s
666 cpassert(
ASSOCIATED(cell))
668 IF (cell%orthorhombic)
THEN
669 r(1) = cell%hmat(1, 1)*s(1)
670 r(2) = cell%hmat(2, 2)*s(2)
671 r(3) = cell%hmat(3, 3)*s(3)
673 r(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
674 r(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
675 r(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
690 cpassert(
ASSOCIATED(cell))
691 cpassert(cell%ref_count > 0)
692 cell%ref_count = cell%ref_count + 1
707 IF (
ASSOCIATED(cell))
THEN
708 cpassert(cell%ref_count > 0)
709 cell%ref_count = cell%ref_count - 1
710 IF (cell%ref_count == 0)
THEN
718#if defined (__PLUMED2)
729 SUBROUTINE pbc_cp2k_plumed_getset_cell(cell, set)
734 TYPE(
cell_type),
POINTER,
SAVE :: stored_cell
742 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
subroutine, public minimum_image_weights(ra, rb, cell, index_to_cell, weights)
Distribute an atom-pair contribution equally among its nearest candidate images. Images within 1....
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...
real(kind=dp) function, dimension(3), public pbc_stable(r, cell)
Apply a stable periodic-image convention for k-point Bloch gauges.
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.