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
105 MODULE PROCEDURE pbc1, pbc2, pbc3, pbc4
115 PURE ELEMENTAL FUNCTION pbc_image_shift(s)
RESULT(image_shift)
117 REAL(KIND=
dp),
INTENT(IN) :: s
118 REAL(KIND=
dp) :: image_shift
120 REAL(KIND=
dp) :: half_boundary, tolerance
122 image_shift = anint(s)
123 half_boundary = anint(s - 0.5_dp) + 0.5_dp
124 tolerance = min(1.0e-8_dp, 64.0_dp*epsilon(1.0_dp)*max(1.0_dp, abs(s)))
125 IF (abs(s - half_boundary) <= tolerance)
THEN
127 image_shift = half_boundary + 0.5_dp
130 END FUNCTION pbc_image_shift
142 TYPE(
cell_type),
POINTER :: cell_in, cell_out
143 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
146 cell_out%ref_count = 1
147 IF (
PRESENT(tag)) cell_out%tag = tag
161 TYPE(
cell_type),
POINTER :: cell_in, cell_out
162 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
164 cell_out%deth = cell_in%deth
165 cell_out%perd = cell_in%perd
166 cell_out%hmat = cell_in%hmat
167 cell_out%h_inv = cell_in%h_inv
168 cell_out%input_cell_canonicalized = cell_in%input_cell_canonicalized
169 cell_out%input_hmat = cell_in%input_hmat
170 cell_out%input_to_canonical = cell_in%input_to_canonical
171 cell_out%input_recip_to_canonical = cell_in%input_recip_to_canonical
172 cell_out%orthorhombic = cell_in%orthorhombic
173 cell_out%symmetry_id = cell_in%symmetry_id
174 IF (
PRESENT(tag))
THEN
177 cell_out%tag = cell_in%tag
195 CHARACTER(LEN=*),
INTENT(IN) :: input_line
196 INTEGER,
INTENT(OUT) :: cell_itimes
197 REAL(kind=
dp),
INTENT(OUT) :: cell_time
198 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT) :: h
199 REAL(kind=
dp),
INTENT(OUT) :: vol
203 READ (input_line, *) cell_itimes, cell_time, &
204 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
231 SUBROUTINE get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, &
232 h, h_inv, symmetry_id, tag)
235 REAL(kind=
dp),
INTENT(OUT),
OPTIONAL :: alpha, beta,
gamma, deth
236 LOGICAL,
INTENT(OUT),
OPTIONAL :: orthorhombic
237 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: abc
238 INTEGER,
DIMENSION(3),
INTENT(OUT),
OPTIONAL :: periodic
239 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(OUT), &
241 INTEGER,
INTENT(OUT),
OPTIONAL :: symmetry_id
242 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: tag
244 cpassert(
ASSOCIATED(cell))
246 IF (
PRESENT(deth)) deth = cell%deth
247 IF (
PRESENT(orthorhombic)) orthorhombic = cell%orthorhombic
248 IF (
PRESENT(periodic)) periodic(:) = cell%perd(:)
249 IF (
PRESENT(h)) h(:, :) = cell%hmat(:, :)
250 IF (
PRESENT(h_inv)) h_inv(:, :) = cell%h_inv(:, :)
253 IF (
PRESENT(abc))
THEN
254 abc(1) = sqrt(cell%hmat(1, 1)*cell%hmat(1, 1) + &
255 cell%hmat(2, 1)*cell%hmat(2, 1) + &
256 cell%hmat(3, 1)*cell%hmat(3, 1))
257 abc(2) = sqrt(cell%hmat(1, 2)*cell%hmat(1, 2) + &
258 cell%hmat(2, 2)*cell%hmat(2, 2) + &
259 cell%hmat(3, 2)*cell%hmat(3, 2))
260 abc(3) = sqrt(cell%hmat(1, 3)*cell%hmat(1, 3) + &
261 cell%hmat(2, 3)*cell%hmat(2, 3) + &
262 cell%hmat(3, 3)*cell%hmat(3, 3))
267 IF (
PRESENT(alpha)) alpha =
angle(cell%hmat(:, 2), cell%hmat(:, 3))*
degree
269 IF (
PRESENT(beta)) beta =
angle(cell%hmat(:, 1), cell%hmat(:, 3))*
degree
272 IF (
PRESENT(symmetry_id)) symmetry_id = cell%symmetry_id
273 IF (
PRESENT(tag)) tag = cell%tag
286 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT) :: vector
288 cpassert(
ASSOCIATED(cell))
290 IF (cell%input_cell_canonicalized) vector = matmul(cell%input_to_canonical, vector)
303 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT) :: vector
305 cpassert(
ASSOCIATED(cell))
307 IF (cell%input_cell_canonicalized) vector = matmul(cell%input_recip_to_canonical, vector)
325 INTEGER,
INTENT(IN) :: h, k, l
327 REAL(kind=
dp) :: distance
329 REAL(kind=
dp) :: a, alpha, b, beta, c, cosa, cosb, cosg, &
331 REAL(kind=
dp),
DIMENSION(3) :: abc
343 IF (cell%orthorhombic)
THEN
345 d = (x/a)**2 + (y/b)**2 + (z/c)**2
362 d = ((x*b*c*sin(alpha))**2 + &
363 (y*c*a*sin(beta))**2 + &
364 (z*a*b*sin(
gamma))**2 + &
365 2.0_dp*a*b*c*(x*y*c*(cosa*cosb - cosg) + &
366 z*x*b*(cosg*cosa - cosb) + &
367 y*z*a*(cosb*cosg - cosa)))/ &
368 ((a*b*c)**2*(1.0_dp - cosa**2 - cosb**2 - cosg**2 + &
369 2.0_dp*cosa*cosb*cosg))
373 distance = 1.0_dp/sqrt(d)
387 FUNCTION pbc1(r, cell)
RESULT(r_pbc)
389 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
391 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
393 REAL(kind=
dp),
DIMENSION(3) :: s
395 cpassert(
ASSOCIATED(cell))
397 IF (cell%orthorhombic)
THEN
398 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*anint(cell%h_inv(1, 1)*r(1))
399 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*anint(cell%h_inv(2, 2)*r(2))
400 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*anint(cell%h_inv(3, 3)*r(3))
402 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
403 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
404 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
405 s(1) = s(1) - cell%perd(1)*anint(s(1))
406 s(2) = s(2) - cell%perd(2)*anint(s(2))
407 s(3) = s(3) - cell%perd(3)*anint(s(3))
408 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
409 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
410 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
423 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
425 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
427 REAL(kind=
dp),
DIMENSION(3) :: s
429 cpassert(
ASSOCIATED(cell))
431 IF (cell%orthorhombic)
THEN
432 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
433 pbc_image_shift(cell%h_inv(1, 1)*r(1))
434 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
435 pbc_image_shift(cell%h_inv(2, 2)*r(2))
436 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
437 pbc_image_shift(cell%h_inv(3, 3)*r(3))
439 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
440 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
441 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
442 s(1) = s(1) - cell%perd(1)*pbc_image_shift(s(1))
443 s(2) = s(2) - cell%perd(2)*pbc_image_shift(s(2))
444 s(3) = s(3) - cell%perd(3)*pbc_image_shift(s(3))
445 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
446 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
447 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
463 FUNCTION pbc2(r, cell, nl)
RESULT(r_pbc)
465 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
467 INTEGER,
DIMENSION(3),
INTENT(IN) :: nl
468 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
470 REAL(kind=
dp),
DIMENSION(3) :: s
472 cpassert(
ASSOCIATED(cell))
474 IF (cell%orthorhombic)
THEN
475 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)* &
476 REAL(nint(cell%h_inv(1, 1)*r(1)) - nl(1),
dp)
477 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)* &
478 REAL(nint(cell%h_inv(2, 2)*r(2)) - nl(2),
dp)
479 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)* &
480 REAL(nint(cell%h_inv(3, 3)*r(3)) - nl(3),
dp)
482 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
483 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
484 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
485 s(1) = s(1) - cell%perd(1)*real(nint(s(1)) - nl(1),
dp)
486 s(2) = s(2) - cell%perd(2)*real(nint(s(2)) - nl(2),
dp)
487 s(3) = s(3) - cell%perd(3)*real(nint(s(3)) - nl(3),
dp)
488 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
489 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
490 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
506 FUNCTION pbc3(ra, rb, cell)
RESULT(rab_pbc)
508 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: ra, rb
510 REAL(kind=
dp),
DIMENSION(3) :: rab_pbc
512 INTEGER :: icell, jcell, kcell
513 INTEGER,
DIMENSION(3) :: periodic
514 REAL(kind=
dp) :: rab2, rab2_pbc
515 REAL(kind=
dp),
DIMENSION(3) :: r, ra_pbc, rab, rb_image, rb_pbc, s2r
517 CALL get_cell(cell=cell, periodic=periodic)
519 ra_pbc(:) =
pbc(ra(:), cell)
520 rb_pbc(:) =
pbc(rb(:), cell)
522 rab2_pbc = huge(1.0_dp)
524 DO icell = -periodic(1), periodic(1)
525 DO jcell = -periodic(2), periodic(2)
526 DO kcell = -periodic(3), periodic(3)
527 r = real([icell, jcell, kcell],
dp)
529 rb_image(:) = rb_pbc(:) + s2r
530 rab(:) = rb_image(:) - ra_pbc(:)
531 rab2 = rab(1)*rab(1) + rab(2)*rab(2) + rab(3)*rab(3)
532 IF (rab2 < rab2_pbc)
THEN
551 FUNCTION pbc4(r, cell, positive_range)
RESULT(r_pbc)
553 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
555 LOGICAL :: positive_range
556 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
558 REAL(kind=
dp),
DIMENSION(3) :: s
560 cpassert(
ASSOCIATED(cell))
562 IF (positive_range)
THEN
563 IF (cell%orthorhombic)
THEN
564 r_pbc(1) = r(1) - cell%hmat(1, 1)*cell%perd(1)*floor(cell%h_inv(1, 1)*r(1))
565 r_pbc(2) = r(2) - cell%hmat(2, 2)*cell%perd(2)*floor(cell%h_inv(2, 2)*r(2))
566 r_pbc(3) = r(3) - cell%hmat(3, 3)*cell%perd(3)*floor(cell%h_inv(3, 3)*r(3))
568 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
569 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
570 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
571 s(1) = s(1) - cell%perd(1)*floor(s(1))
572 s(2) = s(2) - cell%perd(2)*floor(s(2))
573 s(3) = s(3) - cell%perd(3)*floor(s(3))
574 r_pbc(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
575 r_pbc(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
576 r_pbc(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
579 r_pbc = pbc1(r, cell)
596 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: s
597 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
600 cpassert(
ASSOCIATED(cell))
602 IF (cell%orthorhombic)
THEN
603 s(1) = cell%h_inv(1, 1)*r(1)
604 s(2) = cell%h_inv(2, 2)*r(2)
605 s(3) = cell%h_inv(3, 3)*r(3)
607 s(1) = cell%h_inv(1, 1)*r(1) + cell%h_inv(1, 2)*r(2) + cell%h_inv(1, 3)*r(3)
608 s(2) = cell%h_inv(2, 1)*r(1) + cell%h_inv(2, 2)*r(2) + cell%h_inv(2, 3)*r(3)
609 s(3) = cell%h_inv(3, 1)*r(1) + cell%h_inv(3, 2)*r(2) + cell%h_inv(3, 3)*r(3)
626 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: r
627 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: s
630 cpassert(
ASSOCIATED(cell))
632 IF (cell%orthorhombic)
THEN
633 r(1) = cell%hmat(1, 1)*s(1)
634 r(2) = cell%hmat(2, 2)*s(2)
635 r(3) = cell%hmat(3, 3)*s(3)
637 r(1) = cell%hmat(1, 1)*s(1) + cell%hmat(1, 2)*s(2) + cell%hmat(1, 3)*s(3)
638 r(2) = cell%hmat(2, 1)*s(1) + cell%hmat(2, 2)*s(2) + cell%hmat(2, 3)*s(3)
639 r(3) = cell%hmat(3, 1)*s(1) + cell%hmat(3, 2)*s(2) + cell%hmat(3, 3)*s(3)
654 cpassert(
ASSOCIATED(cell))
655 cpassert(cell%ref_count > 0)
656 cell%ref_count = cell%ref_count + 1
671 IF (
ASSOCIATED(cell))
THEN
672 cpassert(cell%ref_count > 0)
673 cell%ref_count = cell%ref_count - 1
674 IF (cell%ref_count == 0)
THEN
682#if defined (__PLUMED2)
693 SUBROUTINE pbc_cp2k_plumed_getset_cell(cell, set)
698 TYPE(
cell_type),
POINTER,
SAVE :: stored_cell
706 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...
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.