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 REAL(kind=
dp) :: deth = 0.0_dp
66 INTEGER,
DIMENSION(3) :: perd = -1
67 REAL(kind=
dp),
DIMENSION(3, 3) :: hmat = 0.0_dp, &
87#if defined (__PLUMED2)
88 PUBLIC :: pbc_cp2k_plumed_getset_cell
98 MODULE PROCEDURE pbc1, pbc2, pbc3, pbc4
113 TYPE(
cell_type),
POINTER :: cell_in, cell_out
114 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
117 cell_out%ref_count = 1
118 IF (
PRESENT(tag)) cell_out%tag = tag
132 TYPE(
cell_type),
POINTER :: cell_in, cell_out
133 CHARACTER(LEN=*),
INTENT(IN),
OPTIONAL :: tag
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
144 cell_out%tag = cell_in%tag
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
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
198 SUBROUTINE get_cell(cell, alpha, beta, gamma, deth, orthorhombic, abc, periodic, &
199 h, h_inv, symmetry_id, tag)
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), &
208 INTEGER,
INTENT(OUT),
OPTIONAL :: symmetry_id
209 CHARACTER(LEN=*),
INTENT(OUT),
OPTIONAL :: tag
211 cpassert(
ASSOCIATED(cell))
213 IF (
PRESENT(deth)) deth = cell%deth
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(:, :)
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))
234 IF (
PRESENT(alpha)) alpha =
angle(cell%hmat(:, 2), cell%hmat(:, 3))*
degree
236 IF (
PRESENT(beta)) beta =
angle(cell%hmat(:, 1), cell%hmat(:, 3))*
degree
239 IF (
PRESENT(symmetry_id)) symmetry_id = cell%symmetry_id
240 IF (
PRESENT(tag)) tag = cell%tag
258 INTEGER,
INTENT(IN) :: h, k, l
260 REAL(kind=
dp) :: distance
262 REAL(kind=
dp) :: a, alpha, b, beta, c, cosa, cosb, cosg, &
264 REAL(kind=
dp),
DIMENSION(3) :: abc
276 IF (cell%orthorhombic)
THEN
278 d = (x/a)**2 + (y/b)**2 + (z/c)**2
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))
306 distance = 1.0_dp/sqrt(d)
320 FUNCTION pbc1(r, cell)
RESULT(r_pbc)
322 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
324 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
326 REAL(kind=
dp),
DIMENSION(3) :: s
328 cpassert(
ASSOCIATED(cell))
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))
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)
359 FUNCTION pbc2(r, cell, nl)
RESULT(r_pbc)
361 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
363 INTEGER,
DIMENSION(3),
INTENT(IN) :: nl
364 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
366 REAL(kind=
dp),
DIMENSION(3) :: s
368 cpassert(
ASSOCIATED(cell))
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)
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)
402 FUNCTION pbc3(ra, rb, cell)
RESULT(rab_pbc)
404 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: ra, rb
406 REAL(kind=
dp),
DIMENSION(3) :: rab_pbc
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
413 CALL get_cell(cell=cell, periodic=periodic)
415 ra_pbc(:) =
pbc(ra(:), cell)
416 rb_pbc(:) =
pbc(rb(:), cell)
418 rab2_pbc = huge(1.0_dp)
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)
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
447 FUNCTION pbc4(r, cell, positive_range)
RESULT(r_pbc)
449 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
451 LOGICAL :: positive_range
452 REAL(kind=
dp),
DIMENSION(3) :: r_pbc
454 REAL(kind=
dp),
DIMENSION(3) :: s
456 cpassert(
ASSOCIATED(cell))
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))
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)
475 r_pbc = pbc1(r, cell)
492 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: s
493 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: r
496 cpassert(
ASSOCIATED(cell))
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)
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)
522 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: r
523 REAL(kind=
dp),
DIMENSION(3),
INTENT(IN) :: s
526 cpassert(
ASSOCIATED(cell))
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)
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)
550 cpassert(
ASSOCIATED(cell))
551 cpassert(cell%ref_count > 0)
552 cell%ref_count = cell%ref_count + 1
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
578#if defined (__PLUMED2)
589 SUBROUTINE pbc_cp2k_plumed_getset_cell(cell, set)
594 TYPE(
cell_type),
POINTER,
SAVE :: stored_cell
602 END SUBROUTINE pbc_cp2k_plumed_getset_cell
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
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
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.