Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 2 : PROGRAM orbital_transformation_matrices_unittest
8 2 : USE kinds, ONLY: dp
9 : USE orbital_pointers, ONLY: deallocate_orbital_pointers,&
10 : init_orbital_pointers
11 : USE orbital_transformation_matrices, ONLY: calculate_rotmat,&
12 : orbrotmat_type,&
13 : release_rotmat
14 :
15 : IMPLICIT NONE
16 :
17 : INTEGER, PARAMETER :: lmax = 5
18 : REAL(KIND=dp), PARAMETER :: tolerance = 1.0E-12_dp
19 : INTEGER :: i, l, n
20 : REAL(KIND=dp) :: rotmat(3, 3), residual(2*lmax + 1, 2*lmax + 1)
21 : TYPE(orbrotmat_type), DIMENSION(:), POINTER :: orbrot => NULL()
22 :
23 2 : CALL init_orbital_pointers(lmax)
24 : ! Rotation about (1,2,2), with cos(theta)=3/5 and sin(theta)=4/5.
25 : rotmat = RESHAPE([29.0_dp, 28.0_dp, -20.0_dp, -20.0_dp, 35.0_dp, 20.0_dp, &
26 2 : 28.0_dp, -4.0_dp, 35.0_dp], [3, 3])/45.0_dp
27 2 : CALL calculate_rotmat(orbrot, rotmat, lmax)
28 2 : IF (.NOT. (ABS(orbrot(0)%mat(1, 1) - 1.0_dp) <= tolerance)) ERROR STOP "Incorrect s rotation"
29 : ! The real p harmonics are ordered (y,z,x).
30 : rotmat = RESHAPE([35.0_dp, 20.0_dp, -20.0_dp, -4.0_dp, 35.0_dp, 28.0_dp, &
31 2 : 28.0_dp, -20.0_dp, 29.0_dp], [3, 3])/45.0_dp
32 26 : IF (.NOT. ALL(ABS(orbrot(1)%mat - rotmat) <= tolerance)) ERROR STOP "Incorrect p rotation"
33 14 : DO l = 0, lmax
34 12 : n = SIZE(orbrot(l)%mat, 1)
35 11548 : residual(1:n, 1:n) = MATMUL(orbrot(l)%mat, TRANSPOSE(orbrot(l)%mat))
36 84 : DO i = 1, n
37 84 : residual(i, i) = residual(i, i) - 1.0_dp
38 : END DO
39 658 : IF (.NOT. ALL(ABS(residual(1:n, 1:n)) <= tolerance)) THEN
40 0 : PRINT *, "Nonorthogonal orbital rotation for l =", l
41 0 : ERROR STOP 1
42 : END IF
43 : END DO
44 2 : CALL release_rotmat(orbrot)
45 2 : CALL deallocate_orbital_pointers()
46 :
47 2 : END PROGRAM orbital_transformation_matrices_unittest
|