Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2023 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Contains type used for a Simulation Cell Optimization
10 : !> \par History
11 : !> none
12 : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
13 : ! **************************************************************************************************
14 : MODULE cell_opt_types
15 : USE cell_opt_utils, ONLY: get_ut_cell_matrix,&
16 : read_external_press_tensor
17 : USE cell_types, ONLY: cell_clone,&
18 : cell_create,&
19 : cell_release,&
20 : cell_type
21 : USE cp_log_handling, ONLY: cp_get_default_logger,&
22 : cp_logger_type
23 : USE cp_output_handling, ONLY: cp_print_key_finished_output,&
24 : cp_print_key_unit_nr
25 : USE cp_subsys_types, ONLY: cp_subsys_get,&
26 : cp_subsys_type
27 : USE cp_units, ONLY: cp_unit_from_cp2k
28 : USE force_env_types, ONLY: force_env_get,&
29 : force_env_type
30 : USE input_constants, ONLY: fix_none,&
31 : fix_x,&
32 : fix_xy,&
33 : fix_xz,&
34 : fix_y,&
35 : fix_yz,&
36 : fix_z
37 : USE input_section_types, ONLY: section_vals_type,&
38 : section_vals_val_get
39 : USE kinds, ONLY: dp
40 : USE particle_list_types, ONLY: particle_list_type
41 : #include "../base/base_uses.f90"
42 :
43 : IMPLICIT NONE
44 : PRIVATE
45 :
46 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .FALSE.
47 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_opt_types'
48 :
49 : PUBLIC :: cell_opt_env_type, &
50 : cell_opt_env_create, &
51 : cell_opt_env_release
52 :
53 : ! **************************************************************************************************
54 : !> \brief Type containing all informations abour the simulation cell optimization
55 : !> \par History
56 : !> none
57 : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
58 : ! **************************************************************************************************
59 : TYPE cell_opt_env_type
60 : ! Simulation cell optimization parameters
61 : INTEGER :: constraint_id
62 : LOGICAL :: keep_angles, &
63 : keep_symmetry
64 : REAL(KIND=dp) :: pres_ext, pres_int, pres_tol, pres_constr
65 : REAL(KIND=dp), DIMENSION(3, 3) :: mtrx
66 : REAL(KIND=dp), DIMENSION(3, 3) :: rot_matrix
67 : TYPE(cell_type), POINTER :: ref_cell
68 : END TYPE cell_opt_env_type
69 :
70 : CONTAINS
71 :
72 : ! **************************************************************************************************
73 : !> \brief ...
74 : !> \param cell_env ...
75 : !> \param force_env ...
76 : !> \param geo_section ...
77 : !> \par History
78 : !> none
79 : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
80 : ! **************************************************************************************************
81 192 : SUBROUTINE cell_opt_env_create(cell_env, force_env, geo_section)
82 : TYPE(cell_opt_env_type), INTENT(OUT) :: cell_env
83 : TYPE(force_env_type), POINTER :: force_env
84 : TYPE(section_vals_type), POINTER :: geo_section
85 :
86 : CHARACTER(LEN=4) :: label
87 : INTEGER :: ip, output_unit
88 : REAL(KIND=dp), DIMENSION(3) :: r
89 : TYPE(cell_type), POINTER :: cell
90 : TYPE(cp_logger_type), POINTER :: logger
91 : TYPE(cp_subsys_type), POINTER :: subsys
92 : TYPE(particle_list_type), POINTER :: particles
93 :
94 192 : NULLIFY (cell_env%ref_cell, cell, subsys, particles)
95 192 : CALL force_env_get(force_env, cell=cell, subsys=subsys)
96 192 : CALL cell_create(cell_env%ref_cell)
97 192 : CALL cell_clone(cell, cell_env%ref_cell)
98 192 : CALL section_vals_val_get(geo_section, "KEEP_ANGLES", l_val=cell_env%keep_angles)
99 192 : CALL section_vals_val_get(geo_section, "KEEP_SYMMETRY", l_val=cell_env%keep_symmetry)
100 192 : CALL section_vals_val_get(geo_section, "PRESSURE_TOLERANCE", r_val=cell_env%pres_tol)
101 192 : CALL section_vals_val_get(geo_section, "CONSTRAINT", i_val=cell_env%constraint_id)
102 :
103 : ! First let's rotate the cell vectors in order to have an upper triangular matrix.
104 192 : CALL get_ut_cell_matrix(cell)
105 :
106 : ! Compute the rotation matrix that give the cell vectors in the "canonical" orientation
107 10176 : cell_env%rot_matrix = MATMUL(cell_env%ref_cell%hmat, cell%h_inv)
108 :
109 : ! Get the external pressure
110 : CALL read_external_press_tensor(geo_section, cell, cell_env%pres_ext, cell_env%mtrx, &
111 192 : cell_env%rot_matrix)
112 :
113 : ! Rotate particles accordingly
114 192 : CALL cp_subsys_get(subsys, particles=particles)
115 13448 : DO ip = 1, particles%n_els
116 13256 : r = MATMUL(TRANSPOSE(cell_env%rot_matrix), particles%els(ip)%r)
117 53216 : particles%els(ip)%r = r
118 : END DO
119 :
120 : ! Print cell optimisation setup
121 192 : NULLIFY (logger)
122 192 : logger => cp_get_default_logger()
123 192 : output_unit = cp_print_key_unit_nr(logger, geo_section, "PRINT%CELL", extension=".Log")
124 192 : IF (output_unit > 0) THEN
125 : WRITE (UNIT=output_unit, FMT="(/,T2,A,T61,F20.1)") &
126 96 : "CELL_OPT| Pressure tolerance [bar]: ", cp_unit_from_cp2k(cell_env%pres_tol, "bar")
127 96 : IF (cell_env%keep_angles) THEN
128 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
129 12 : "CELL_OPT| Keep angles between the cell vectors: ", "YES"
130 : ELSE
131 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
132 84 : "CELL_OPT| Keep angles between the cell vectors: ", " NO"
133 : END IF
134 96 : IF (cell_env%keep_symmetry) THEN
135 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
136 16 : "CELL_OPT| Keep cell symmetry: ", "YES"
137 : ELSE
138 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
139 80 : "CELL_OPT| Keep cell symmetry: ", " NO"
140 : END IF
141 96 : SELECT CASE (cell_env%constraint_id)
142 : CASE (fix_x)
143 0 : label = " X"
144 : CASE (fix_y)
145 0 : label = " Y"
146 : CASE (fix_z)
147 1 : label = " Z"
148 : CASE (fix_xy)
149 1 : label = " XY"
150 : CASE (fix_xz)
151 0 : label = " XZ"
152 : CASE (fix_yz)
153 0 : label = " YZ"
154 : CASE (fix_none)
155 96 : label = "NONE"
156 : END SELECT
157 : WRITE (UNIT=output_unit, FMT="(T2,A,T77,A4)") &
158 96 : "CELL_OPT| Constraint: ", label
159 : END IF
160 192 : CALL cp_print_key_finished_output(output_unit, logger, geo_section, "PRINT%CELL")
161 :
162 192 : END SUBROUTINE cell_opt_env_create
163 :
164 : ! **************************************************************************************************
165 : !> \brief ...
166 : !> \param cell_env ...
167 : !> \par History
168 : !> none
169 : !> \author Teodoro Laino - created [tlaino] - 03.2008 - Zurich University
170 : ! **************************************************************************************************
171 192 : SUBROUTINE cell_opt_env_release(cell_env)
172 : TYPE(cell_opt_env_type), INTENT(INOUT) :: cell_env
173 :
174 192 : CALL cell_release(cell_env%ref_cell)
175 :
176 192 : END SUBROUTINE cell_opt_env_release
177 :
178 0 : END MODULE cell_opt_types
|