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 :
8 : ! **************************************************************************************************
9 : !> \brief Handles all functions related to the CELL
10 : !> \par History
11 : !> 11.2008 Teodoro Laino [tlaino] - deeply cleaning cell_type from units
12 : !> 10.2014 Moved many routines to cell_types.F.
13 : !> \author Matthias KracK (16.01.2002, based on a earlier version of CJM, JGH)
14 : ! **************************************************************************************************
15 : MODULE cell_methods
16 : USE cell_types, ONLY: &
17 : cell_clone, cell_release, cell_sym_cubic, cell_sym_hexagonal_gamma_120, &
18 : cell_sym_hexagonal_gamma_60, cell_sym_monoclinic, cell_sym_monoclinic_gamma_ab, &
19 : cell_sym_none, cell_sym_orthorhombic, cell_sym_rhombohedral, cell_sym_tetragonal_ab, &
20 : cell_sym_tetragonal_ac, cell_sym_tetragonal_bc, cell_sym_triclinic, cell_type, get_cell, &
21 : plane_distance, use_perd_none, use_perd_x, use_perd_xy, use_perd_xyz, use_perd_xz, &
22 : use_perd_y, use_perd_yz, use_perd_z
23 : USE cp_log_handling, ONLY: cp_get_default_logger,&
24 : cp_logger_type
25 : USE cp_output_handling, ONLY: cp_print_key_finished_output,&
26 : cp_print_key_unit_nr
27 : USE cp_parser_methods, ONLY: parser_get_next_line,&
28 : parser_get_object,&
29 : parser_search_string
30 : USE cp_parser_types, ONLY: cp_parser_type,&
31 : parser_create,&
32 : parser_release
33 : USE cp_units, ONLY: cp_unit_from_cp2k,&
34 : cp_unit_to_cp2k
35 : USE input_constants, ONLY: &
36 : canonicalize_cell_auto, canonicalize_cell_true, do_cell_cif, do_cell_cp2k, do_cell_extxyz, &
37 : do_cell_pdb, do_cell_xsc, do_coord_cif, do_coord_cp2k, do_coord_pdb, do_coord_xyz
38 : USE input_cp2k_subsys, ONLY: create_cell_section
39 : USE input_enumeration_types, ONLY: enum_i2c,&
40 : enumeration_type
41 : USE input_keyword_types, ONLY: keyword_get,&
42 : keyword_type
43 : USE input_section_types, ONLY: &
44 : section_get_keyword, section_release, section_type, section_vals_get, &
45 : section_vals_get_subs_vals, section_vals_type, section_vals_val_get, section_vals_val_set, &
46 : section_vals_val_unset
47 : USE kinds, ONLY: default_path_length,&
48 : default_string_length,&
49 : dp,&
50 : max_line_length
51 : USE machine, ONLY: default_output_unit
52 : USE mathconstants, ONLY: degree,&
53 : sqrt3
54 : USE mathlib, ONLY: angle,&
55 : det_3x3,&
56 : inv_3x3
57 : USE message_passing, ONLY: mp_para_env_type
58 : USE string_utilities, ONLY: uppercase
59 : #include "./base/base_uses.f90"
60 :
61 : IMPLICIT NONE
62 :
63 : PRIVATE
64 :
65 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cell_methods'
66 :
67 : PUBLIC :: cell_create, &
68 : cell_finalize_canonical_input, &
69 : init_cell, &
70 : read_cell, &
71 : read_cell_cif, &
72 : read_cell_cp2k, &
73 : read_cell_xyz, &
74 : read_cell_pdb, &
75 : read_cell_xsc, &
76 : read_xyz_comment, &
77 : set_cell_param, &
78 : write_cell, &
79 : write_cell_low
80 :
81 : CONTAINS
82 :
83 : ! **************************************************************************************************
84 : !> \brief allocates and initializes a cell
85 : !> \param cell the cell to initialize
86 : !> \param hmat the h matrix that defines the cell
87 : !> \param periodic periodicity of the cell
88 : !> \param tag ...
89 : !> \par History
90 : !> 09.2003 created [fawzi]
91 : !> \author Fawzi Mohamed
92 : ! **************************************************************************************************
93 80524 : SUBROUTINE cell_create(cell, hmat, periodic, tag)
94 :
95 : TYPE(cell_type), POINTER :: cell
96 : REAL(KIND=dp), DIMENSION(3, 3), INTENT(IN), &
97 : OPTIONAL :: hmat
98 : INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: periodic
99 : CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: tag
100 :
101 0 : CPASSERT(.NOT. ASSOCIATED(cell))
102 5556156 : ALLOCATE (cell)
103 80524 : cell%ref_count = 1
104 80524 : IF (PRESENT(periodic)) THEN
105 1380 : cell%perd = periodic
106 : ELSE
107 320716 : cell%perd = 1
108 : END IF
109 80524 : cell%orthorhombic = .FALSE.
110 80524 : cell%input_cell_canonicalized = .FALSE.
111 1046812 : cell%input_hmat(:, :) = 0.0_dp
112 1046812 : cell%input_to_canonical(:, :) = 0.0_dp
113 1046812 : cell%input_recip_to_canonical(:, :) = 0.0_dp
114 80524 : cell%symmetry_id = cell_sym_none
115 80524 : IF (PRESENT(hmat)) CALL init_cell(cell, hmat)
116 80524 : IF (PRESENT(tag)) cell%tag = tag
117 :
118 80524 : END SUBROUTINE cell_create
119 :
120 : ! **************************************************************************************************
121 : !> \brief Store the transform between the user input cell and the canonical cell.
122 : !> \param cell ...
123 : !> \param hmat_input ...
124 : !> \param hmat_canonical ...
125 : ! **************************************************************************************************
126 114 : SUBROUTINE cell_finalize_canonical_input(cell, hmat_input, hmat_canonical)
127 :
128 : TYPE(cell_type), POINTER :: cell
129 : REAL(KIND=dp), DIMENSION(3, 3), INTENT(IN) :: hmat_input, hmat_canonical
130 :
131 : REAL(KIND=dp), PARAMETER :: eps_hmat = 1.0E-12_dp
132 :
133 : REAL(KIND=dp), DIMENSION(3, 3) :: tmat
134 :
135 114 : CPASSERT(ASSOCIATED(cell))
136 :
137 1482 : IF (MAXVAL(ABS(hmat_canonical - hmat_input)) <= eps_hmat) THEN
138 22 : cell%input_cell_canonicalized = .FALSE.
139 286 : cell%input_hmat(:, :) = 0.0_dp
140 286 : cell%input_to_canonical(:, :) = 0.0_dp
141 286 : cell%input_recip_to_canonical(:, :) = 0.0_dp
142 : ELSE
143 6164 : tmat = MATMUL(hmat_canonical, inv_3x3(hmat_input))
144 92 : cell%input_cell_canonicalized = .TRUE.
145 1196 : cell%input_hmat(:, :) = hmat_input(:, :)
146 1196 : cell%input_to_canonical(:, :) = tmat(:, :)
147 1196 : cell%input_recip_to_canonical(:, :) = TRANSPOSE(inv_3x3(tmat))
148 : END IF
149 :
150 114 : END SUBROUTINE cell_finalize_canonical_input
151 :
152 : ! **************************************************************************************************
153 : !> \brief Canonicalize a general cell matrix without changing lengths and angles.
154 : !> \param cell ...
155 : ! **************************************************************************************************
156 114 : SUBROUTINE canonicalize_cell_matrix(cell)
157 :
158 : TYPE(cell_type), POINTER :: cell
159 :
160 : REAL(KIND=dp), DIMENSION(3) :: abc, cell_angle
161 :
162 114 : CPASSERT(ASSOCIATED(cell))
163 :
164 114 : CALL get_cell(cell=cell, abc=abc)
165 114 : cell_angle(1) = angle(cell%hmat(:, 2), cell%hmat(:, 3))
166 114 : cell_angle(2) = angle(cell%hmat(:, 1), cell%hmat(:, 3))
167 114 : cell_angle(3) = angle(cell%hmat(:, 1), cell%hmat(:, 2))
168 :
169 : CALL set_cell_param(cell, cell_length=abc, cell_angle=cell_angle, &
170 114 : periodic=cell%perd, do_init_cell=.TRUE.)
171 :
172 114 : END SUBROUTINE canonicalize_cell_matrix
173 :
174 : ! **************************************************************************************************
175 : !> \brief Initialise/readjust a simulation cell after hmat has been changed
176 : !> \param cell ...
177 : !> \param hmat ...
178 : !> \param periodic ...
179 : !> \date 16.01.2002
180 : !> \author Matthias Krack
181 : !> \version 1.0
182 : ! **************************************************************************************************
183 341501 : SUBROUTINE init_cell(cell, hmat, periodic)
184 :
185 : TYPE(cell_type), POINTER :: cell
186 : REAL(KIND=dp), DIMENSION(3, 3), INTENT(IN), &
187 : OPTIONAL :: hmat
188 : INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: periodic
189 :
190 : REAL(KIND=dp), PARAMETER :: eps_hmat = 1.0E-14_dp
191 :
192 : INTEGER :: dim
193 : REAL(KIND=dp) :: a, acosa, acosah, acosg, alpha, asina, &
194 : asinah, asing, beta, gamma, norm, &
195 : norm_c
196 : REAL(KIND=dp), DIMENSION(3) :: abc
197 :
198 341501 : CPASSERT(ASSOCIATED(cell))
199 :
200 502553 : IF (PRESENT(hmat)) cell%hmat(:, :) = hmat(:, :)
201 341927 : IF (PRESENT(periodic)) cell%perd(:) = periodic(:)
202 :
203 341501 : cell%deth = ABS(det_3x3(cell%hmat))
204 :
205 341501 : IF (cell%deth < 1.0E-10_dp) THEN
206 0 : CALL write_cell_low(cell, "angstrom", default_output_unit)
207 : CALL cp_abort(__LOCATION__, &
208 : "An invalid set of cell vectors was specified. "// &
209 0 : "The cell volume is too small")
210 : END IF
211 :
212 345588 : SELECT CASE (cell%symmetry_id)
213 : CASE (cell_sym_cubic, &
214 : cell_sym_tetragonal_ab, &
215 : cell_sym_tetragonal_ac, &
216 : cell_sym_tetragonal_bc, &
217 : cell_sym_orthorhombic)
218 4087 : CALL get_cell(cell=cell, abc=abc)
219 4087 : abc(2) = plane_distance(0, 1, 0, cell=cell)
220 4087 : abc(3) = plane_distance(0, 0, 1, cell=cell)
221 4087 : SELECT CASE (cell%symmetry_id)
222 : CASE (cell_sym_cubic)
223 5593 : abc(1:3) = SUM(abc(1:3))/3.0_dp
224 : CASE (cell_sym_tetragonal_ab, &
225 : cell_sym_tetragonal_ac, &
226 : cell_sym_tetragonal_bc)
227 4087 : SELECT CASE (cell%symmetry_id)
228 : CASE (cell_sym_tetragonal_ab)
229 1318 : a = 0.5_dp*(abc(1) + abc(2))
230 1318 : abc(1) = a
231 1318 : abc(2) = a
232 : CASE (cell_sym_tetragonal_ac)
233 631 : a = 0.5_dp*(abc(1) + abc(3))
234 631 : abc(1) = a
235 631 : abc(3) = a
236 : CASE (cell_sym_tetragonal_bc)
237 610 : a = 0.5_dp*(abc(2) + abc(3))
238 610 : abc(2) = a
239 2559 : abc(3) = a
240 : END SELECT
241 : END SELECT
242 4087 : cell%hmat(1, 1) = abc(1); cell%hmat(1, 2) = 0.0_dp; cell%hmat(1, 3) = 0.0_dp
243 4087 : cell%hmat(2, 1) = 0.0_dp; cell%hmat(2, 2) = abc(2); cell%hmat(2, 3) = 0.0_dp
244 4087 : cell%hmat(3, 1) = 0.0_dp; cell%hmat(3, 2) = 0.0_dp; cell%hmat(3, 3) = abc(3)
245 : CASE (cell_sym_hexagonal_gamma_60, cell_sym_hexagonal_gamma_120)
246 2630 : CALL get_cell(cell=cell, abc=abc)
247 2630 : a = 0.5_dp*(abc(1) + abc(2))
248 2630 : acosg = 0.5_dp*a
249 2630 : asing = sqrt3*acosg
250 2630 : IF (cell%symmetry_id == cell_sym_hexagonal_gamma_120) acosg = -acosg
251 2630 : cell%hmat(1, 1) = a; cell%hmat(1, 2) = acosg; cell%hmat(1, 3) = 0.0_dp
252 2630 : cell%hmat(2, 1) = 0.0_dp; cell%hmat(2, 2) = asing; cell%hmat(2, 3) = 0.0_dp
253 2630 : cell%hmat(3, 1) = 0.0_dp; cell%hmat(3, 2) = 0.0_dp; cell%hmat(3, 3) = abc(3)
254 : CASE (cell_sym_rhombohedral)
255 649 : CALL get_cell(cell=cell, abc=abc)
256 2596 : a = SUM(abc(1:3))/3.0_dp
257 : alpha = (angle(cell%hmat(:, 3), cell%hmat(:, 2)) + &
258 : angle(cell%hmat(:, 1), cell%hmat(:, 3)) + &
259 649 : angle(cell%hmat(:, 1), cell%hmat(:, 2)))/3.0_dp
260 649 : acosa = a*COS(alpha)
261 649 : asina = a*SIN(alpha)
262 649 : acosah = a*COS(0.5_dp*alpha)
263 649 : asinah = a*SIN(0.5_dp*alpha)
264 649 : norm = acosa/acosah
265 649 : norm_c = SQRT(1.0_dp - norm*norm)
266 649 : cell%hmat(1, 1) = a; cell%hmat(1, 2) = acosa; cell%hmat(1, 3) = acosah*norm
267 649 : cell%hmat(2, 1) = 0.0_dp; cell%hmat(2, 2) = asina; cell%hmat(2, 3) = asinah*norm
268 649 : cell%hmat(3, 1) = 0.0_dp; cell%hmat(3, 2) = 0.0_dp; cell%hmat(3, 3) = a*norm_c
269 : CASE (cell_sym_monoclinic)
270 6486 : CALL get_cell(cell=cell, abc=abc)
271 6486 : beta = angle(cell%hmat(:, 1), cell%hmat(:, 3))
272 6486 : cell%hmat(1, 1) = abc(1); cell%hmat(1, 2) = 0.0_dp; cell%hmat(1, 3) = abc(3)*COS(beta)
273 6486 : cell%hmat(2, 1) = 0.0_dp; cell%hmat(2, 2) = abc(2); cell%hmat(2, 3) = 0.0_dp
274 6486 : cell%hmat(3, 1) = 0.0_dp; cell%hmat(3, 2) = 0.0_dp; cell%hmat(3, 3) = abc(3)*SIN(beta)
275 : CASE (cell_sym_monoclinic_gamma_ab)
276 : ! Cell symmetry with a = b, alpha = beta = 90 degree and gammma not equal 90 degree
277 738 : CALL get_cell(cell=cell, abc=abc)
278 738 : a = 0.5_dp*(abc(1) + abc(2))
279 738 : gamma = angle(cell%hmat(:, 1), cell%hmat(:, 2))
280 738 : acosg = a*COS(gamma)
281 738 : asing = a*SIN(gamma)
282 738 : cell%hmat(1, 1) = a; cell%hmat(1, 2) = acosg; cell%hmat(1, 3) = 0.0_dp
283 738 : cell%hmat(2, 1) = 0.0_dp; cell%hmat(2, 2) = asing; cell%hmat(2, 3) = 0.0_dp
284 342239 : cell%hmat(3, 1) = 0.0_dp; cell%hmat(3, 2) = 0.0_dp; cell%hmat(3, 3) = abc(3)
285 : CASE (cell_sym_triclinic)
286 : ! Nothing to do
287 : END SELECT
288 :
289 : ! Do we have an (almost) orthorhombic cell?
290 : IF ((ABS(cell%hmat(1, 2)) < eps_hmat) .AND. (ABS(cell%hmat(1, 3)) < eps_hmat) .AND. &
291 : (ABS(cell%hmat(2, 1)) < eps_hmat) .AND. (ABS(cell%hmat(2, 3)) < eps_hmat) .AND. &
292 341501 : (ABS(cell%hmat(3, 1)) < eps_hmat) .AND. (ABS(cell%hmat(3, 2)) < eps_hmat)) THEN
293 312511 : cell%orthorhombic = .TRUE.
294 : ELSE
295 28990 : cell%orthorhombic = .FALSE.
296 : END IF
297 :
298 : ! Retain an exact orthorhombic cell
299 : ! (off-diagonal elements must remain zero identically to keep QS fast)
300 341501 : IF (cell%orthorhombic) THEN
301 312511 : cell%hmat(1, 2) = 0.0_dp
302 312511 : cell%hmat(1, 3) = 0.0_dp
303 312511 : cell%hmat(2, 1) = 0.0_dp
304 312511 : cell%hmat(2, 3) = 0.0_dp
305 312511 : cell%hmat(3, 1) = 0.0_dp
306 312511 : cell%hmat(3, 2) = 0.0_dp
307 : END IF
308 :
309 1366004 : dim = COUNT(cell%perd == 1)
310 341501 : IF ((dim == 1) .AND. (.NOT. cell%orthorhombic)) THEN
311 0 : CPABORT("Non-orthorhombic and not periodic")
312 : END IF
313 :
314 : ! Update deth and hmat_inv with enforced symmetry
315 341501 : cell%deth = ABS(det_3x3(cell%hmat))
316 341501 : IF (cell%deth < 1.0E-10_dp) THEN
317 : CALL cp_abort(__LOCATION__, &
318 : "An invalid set of cell vectors was obtained after applying "// &
319 0 : "the requested cell symmetry. The cell volume is too small")
320 : END IF
321 4439513 : cell%h_inv = inv_3x3(cell%hmat)
322 :
323 341501 : END SUBROUTINE init_cell
324 :
325 : ! **************************************************************************************************
326 : !> \brief ...
327 : !> \param cell ...
328 : !> \param cell_ref ...
329 : !> \param use_ref_cell ...
330 : !> \param cell_section ...
331 : !> \param topology_section ...
332 : !> \param check_for_ref ...
333 : !> \param para_env ...
334 : !> \par History
335 : !> 03.2005 created [teo]
336 : !> 03.2026 revamped logic with pdb and extxyz parsers
337 : !> \author Teodoro Laino
338 : ! **************************************************************************************************
339 113860 : RECURSIVE SUBROUTINE read_cell(cell, cell_ref, use_ref_cell, cell_section, &
340 : topology_section, check_for_ref, para_env)
341 :
342 : TYPE(cell_type), POINTER :: cell, cell_ref
343 : LOGICAL, INTENT(INOUT), OPTIONAL :: use_ref_cell
344 : TYPE(section_vals_type), OPTIONAL, POINTER :: cell_section, topology_section
345 : LOGICAL, INTENT(IN), OPTIONAL :: check_for_ref
346 : TYPE(mp_para_env_type), POINTER :: para_env
347 :
348 : REAL(KIND=dp), PARAMETER :: eps = 1.0E-14_dp
349 :
350 : CHARACTER(LEN=default_path_length) :: cell_file_name, coord_file_name, &
351 : error_msg
352 : INTEGER :: canonicalize_mode, cell_file_format, &
353 : coord_file_format, my_per
354 11386 : INTEGER, DIMENSION(:), POINTER :: multiple_unit_cell
355 : LOGICAL :: canonicalize_cell, cell_read_a, cell_read_abc, cell_read_alpha_beta_gamma, &
356 : cell_read_b, cell_read_c, cell_read_file, my_check_ref, tmp_comb_abc, tmp_comb_cell, &
357 : tmp_comb_top, topo_read_coord
358 : REAL(KIND=dp), DIMENSION(3) :: read_ang, read_len
359 : REAL(KIND=dp), DIMENSION(3, 3) :: hmat_input, read_mat
360 11386 : REAL(KIND=dp), DIMENSION(:), POINTER :: cell_par
361 : TYPE(cell_type), POINTER :: cell_tmp
362 : TYPE(section_vals_type), POINTER :: cell_ref_section
363 :
364 11386 : my_check_ref = .TRUE.
365 11386 : NULLIFY (cell_ref_section, cell_par, cell_tmp, multiple_unit_cell)
366 : ! cell_tmp has two purposes:
367 : ! 1. for transferring matrix of cell vectors from individual
368 : ! file parser subroutines to read_mat here, assuming that
369 : ! unit conversion has been done in those subroutines;
370 : ! 2. for testing whether enforcing symmetry makes a new set
371 : ! of cell vectors significantly different from parsed input
372 11386 : CALL cell_create(cell_tmp)
373 11386 : IF (.NOT. ASSOCIATED(cell)) CALL cell_create(cell, tag="CELL")
374 11386 : IF (.NOT. ASSOCIATED(cell_ref)) CALL cell_create(cell_ref, tag="CELL_REF")
375 11386 : IF (PRESENT(check_for_ref)) my_check_ref = check_for_ref
376 :
377 11386 : cell%deth = 0.0_dp
378 11386 : cell%orthorhombic = .FALSE.
379 45544 : cell%perd(:) = 1
380 11386 : cell%symmetry_id = cell_sym_none
381 148018 : cell%hmat(:, :) = 0.0_dp
382 148018 : cell%h_inv(:, :) = 0.0_dp
383 11386 : cell%input_cell_canonicalized = .FALSE.
384 148018 : cell%input_hmat(:, :) = 0.0_dp
385 148018 : cell%input_to_canonical(:, :) = 0.0_dp
386 148018 : cell%input_recip_to_canonical(:, :) = 0.0_dp
387 : cell_read_file = .FALSE.
388 : cell_read_a = .FALSE.
389 : cell_read_b = .FALSE.
390 : cell_read_c = .FALSE.
391 : cell_read_abc = .FALSE.
392 : cell_read_alpha_beta_gamma = .FALSE.
393 11386 : hmat_input(:, :) = 0.0_dp
394 11386 : read_mat(:, :) = 0.0_dp
395 11386 : read_ang(:) = 0.0_dp
396 11386 : read_len(:) = 0.0_dp
397 :
398 : ! Precedence of retrieving cell information from input:
399 : ! 1. CELL/CELL_FILE_NAME
400 : ! 2. CELL/ABC and optionally CELL/ALPHA_BETA_GAMMA
401 : ! 3. CELL/A, CELL/B, CELL/C
402 : ! 4. TOPOLOGY/COORD_FILE_NAME, if topology_section is present
403 : ! The actual order of processing is 4 -> 1 -> 2 -> 3, with
404 : ! case 4 merged to case 1 (if file format permits) first.
405 : ! Store data into either read_mat or read_ang and read_len
406 : ! in CP2K units, which will be converted to cell%hmat and A, B, C.
407 11386 : CALL section_vals_val_get(cell_section, "A", explicit=cell_read_a)
408 11386 : CALL section_vals_val_get(cell_section, "B", explicit=cell_read_b)
409 11386 : CALL section_vals_val_get(cell_section, "C", explicit=cell_read_c)
410 11386 : CALL section_vals_val_get(cell_section, "ABC", explicit=cell_read_abc)
411 11386 : CALL section_vals_val_get(cell_section, "ALPHA_BETA_GAMMA", explicit=cell_read_alpha_beta_gamma)
412 11386 : CALL section_vals_val_get(cell_section, "CELL_FILE_NAME", explicit=cell_read_file)
413 11386 : CALL section_vals_val_get(cell_section, "CANONICALIZE", i_val=canonicalize_mode)
414 11386 : canonicalize_cell = (canonicalize_mode == canonicalize_cell_true)
415 :
416 : ! Case 4
417 11386 : tmp_comb_top = (.NOT. (cell_read_file .OR. cell_read_abc))
418 1590 : tmp_comb_top = (tmp_comb_top .AND. (.NOT. cell_read_a))
419 0 : tmp_comb_top = (tmp_comb_top .AND. (.NOT. cell_read_b))
420 0 : tmp_comb_top = (tmp_comb_top .AND. (.NOT. cell_read_c))
421 : IF (tmp_comb_top) THEN
422 : CALL cp_warn(__LOCATION__, &
423 : "None of the keywords CELL_FILE_NAME, ABC, or A, B, C "// &
424 : "are specified in CELL section. CP2K will now attempt to read "// &
425 : "TOPOLOGY/COORD_FILE_NAME if its format can be parsed for "// &
426 0 : "cell information.")
427 0 : IF (ASSOCIATED(topology_section)) THEN
428 0 : CALL section_vals_val_get(topology_section, "COORD_FILE_NAME", explicit=topo_read_coord)
429 0 : IF (topo_read_coord) THEN
430 0 : CALL section_vals_val_get(topology_section, "COORD_FILE_NAME", c_val=coord_file_name)
431 0 : CALL section_vals_val_get(topology_section, "COORD_FILE_FORMAT", i_val=coord_file_format)
432 0 : SELECT CASE (coord_file_format) ! Add formats with both cell and coord parser manually
433 : CASE (do_coord_cif)
434 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_NAME", c_val=coord_file_name)
435 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_FORMAT", i_val=do_cell_cif)
436 : CASE (do_coord_cp2k)
437 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_NAME", c_val=coord_file_name)
438 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_FORMAT", i_val=do_cell_cp2k)
439 : CASE (do_coord_pdb)
440 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_NAME", c_val=coord_file_name)
441 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_FORMAT", i_val=do_cell_pdb)
442 : CASE (do_coord_xyz)
443 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_NAME", c_val=coord_file_name)
444 0 : CALL section_vals_val_set(cell_section, "CELL_FILE_FORMAT", i_val=do_cell_extxyz)
445 : CASE DEFAULT
446 : CALL cp_abort(__LOCATION__, &
447 : "COORD_FILE_FORMAT is not set to one of the implemented "// &
448 0 : "CELL_FILE_FORMAT options and cannot be parsed for cell information!")
449 : END SELECT
450 : ELSE
451 : CALL cp_abort(__LOCATION__, &
452 0 : "COORD_FILE_NAME is not set, so no cell information is available!")
453 : END IF
454 : ELSE
455 : CALL cp_warn(__LOCATION__, &
456 : "TOPOLOGY section is not available, so COORD_FILE_NAME cannot "// &
457 0 : "be parsed for cell information in lieu of missing CELL settings.")
458 : END IF
459 : END IF
460 : ! Former logic in SUBROUTINE read_cell_from_external_file is moved here
461 11386 : CALL section_vals_val_get(cell_section, "CELL_FILE_NAME", explicit=cell_read_file)
462 11386 : IF (cell_read_file) THEN ! Case 1
463 18 : tmp_comb_cell = (cell_read_abc .OR. (cell_read_a .OR. (cell_read_b .OR. cell_read_c)))
464 : IF (tmp_comb_cell) THEN
465 : CALL cp_warn(__LOCATION__, &
466 : "Cell Information provided through A, B, C, or ABC in conjunction "// &
467 : "with CELL_FILE_NAME. The definition in external file will override "// &
468 0 : "other ones.")
469 : END IF
470 18 : CALL section_vals_val_get(cell_section, "CELL_FILE_NAME", c_val=cell_file_name)
471 18 : CALL section_vals_val_get(cell_section, "CELL_FILE_FORMAT", i_val=cell_file_format)
472 2 : SELECT CASE (cell_file_format)
473 : CASE (do_cell_cp2k)
474 2 : CALL read_cell_cp2k(cell_file_name, cell_tmp, para_env)
475 : CASE (do_cell_xsc)
476 0 : CALL read_cell_xsc(cell_file_name, cell_tmp, para_env)
477 : CASE (do_cell_extxyz)
478 4 : CALL read_cell_xyz(cell_file_name, cell_tmp, para_env)
479 : CASE (do_cell_pdb)
480 2 : CALL read_cell_pdb(cell_file_name, cell_tmp, para_env)
481 : CASE (do_cell_cif)
482 10 : CALL read_cell_cif(cell_file_name, cell_tmp, para_env)
483 : CASE DEFAULT
484 : CALL cp_abort(__LOCATION__, &
485 : "CELL_FILE_FORMAT is not set to one of the implemented "// &
486 18 : "options and cannot be parsed for cell information!")
487 : END SELECT
488 234 : read_mat = cell_tmp%hmat
489 : ELSE
490 11368 : IF (cell_read_abc) THEN ! Case 2
491 9778 : CALL section_vals_val_get(cell_section, "ABC", r_vals=cell_par)
492 39112 : read_len = cell_par
493 9778 : CALL section_vals_val_get(cell_section, "ALPHA_BETA_GAMMA", r_vals=cell_par)
494 39112 : read_ang = cell_par
495 9778 : IF (cell_read_a .OR. cell_read_b .OR. cell_read_c) THEN
496 : CALL cp_warn(__LOCATION__, &
497 : "Cell information provided through vectors A, B or C in conjunction with ABC. "// &
498 0 : "The definition of the ABC keyword will override the one provided by A, B and C.")
499 : END IF
500 : ELSE ! Case 3
501 1590 : tmp_comb_abc = ((cell_read_a .EQV. cell_read_b) .AND. (cell_read_b .EQV. cell_read_c))
502 : IF (tmp_comb_abc) THEN
503 1590 : CALL section_vals_val_get(cell_section, "A", r_vals=cell_par)
504 6360 : read_mat(:, 1) = cell_par(:)
505 1590 : CALL section_vals_val_get(cell_section, "B", r_vals=cell_par)
506 6360 : read_mat(:, 2) = cell_par(:)
507 1590 : CALL section_vals_val_get(cell_section, "C", r_vals=cell_par)
508 6360 : read_mat(:, 3) = cell_par(:)
509 1590 : IF (cell_read_alpha_beta_gamma) THEN
510 : CALL cp_warn(__LOCATION__, &
511 : "The keyword ALPHA_BETA_GAMMA is ignored because it was used without the "// &
512 0 : "keyword ABC.")
513 : END IF
514 : ELSE
515 : CALL cp_abort(__LOCATION__, &
516 : "Neither of the keywords CELL_FILE_NAME or ABC are specified, "// &
517 0 : "and cell vector settings in A, B, C are incomplete!")
518 : END IF
519 : END IF
520 : END IF
521 :
522 : ! Convert read_mat or read_len and read_ang to actual cell%hmat
523 128854 : IF (ANY(read_mat(:, :) > eps)) THEN
524 : ! Make a warning before storing cell vectors that
525 : ! do not form a triangular matrix.
526 1608 : IF (.NOT. canonicalize_cell .AND. &
527 : ((ABS(read_mat(2, 1)) > eps) .OR. &
528 : (ABS(read_mat(3, 1)) > eps) .OR. &
529 : (ABS(read_mat(3, 2)) > eps))) THEN
530 348 : IF (canonicalize_mode == canonicalize_cell_auto) THEN
531 : CALL cp_warn(__LOCATION__, &
532 : "CELL%CANONICALIZE AUTO keeps the general input cell orientation. "// &
533 : "The cell matrix is not a lower triangle and does not conform to the "// &
534 : "program convention that A lies along the X-axis and B is in the XY plane. "// &
535 : "Set CELL%CANONICALIZE TRUE to explicitly transform the cell and supported "// &
536 346 : "cell-dependent input to the canonical internal frame.")
537 : ELSE
538 : CALL cp_warn(__LOCATION__, &
539 : "Cell vectors are read but cell matrix is not "// &
540 : "a lower triangle, not conforming to the program "// &
541 : "convention that A lies along the X-axis and "// &
542 2 : "B is in the XY plane.")
543 : END IF
544 : END IF
545 20904 : cell%hmat = read_mat
546 : ELSE
547 19556 : IF (ANY(read_ang(:) > eps) .AND. ANY(read_len(:) > eps)) THEN
548 : CALL set_cell_param(cell, cell_length=read_len, cell_angle=read_ang, &
549 9778 : do_init_cell=.FALSE.)
550 : ELSE
551 : CALL cp_abort(__LOCATION__, &
552 0 : "No meaningful cell information is read from parser!")
553 : END IF
554 : END IF
555 : ! Reset cell section so that only A, B, C are kept
556 11386 : CALL reset_cell_section_by_cell_mat(cell, cell_section)
557 :
558 : ! Multiple unit cell
559 11386 : CALL section_vals_val_get(cell_section, "MULTIPLE_UNIT_CELL", i_vals=multiple_unit_cell)
560 45110 : IF (ANY(multiple_unit_cell /= 1)) CALL set_multiple_unit_cell(cell, multiple_unit_cell)
561 :
562 11386 : CALL section_vals_val_get(cell_section, "PERIODIC", i_val=my_per)
563 16 : SELECT CASE (my_per)
564 : CASE (use_perd_x)
565 64 : cell%perd = [1, 0, 0]
566 : CASE (use_perd_y)
567 16 : cell%perd = [0, 1, 0]
568 : CASE (use_perd_z)
569 24 : cell%perd = [0, 0, 1]
570 : CASE (use_perd_xy)
571 144 : cell%perd = [1, 1, 0]
572 : CASE (use_perd_xz)
573 32 : cell%perd = [1, 0, 1]
574 : CASE (use_perd_yz)
575 200 : cell%perd = [0, 1, 1]
576 : CASE (use_perd_xyz)
577 28752 : cell%perd = [1, 1, 1]
578 : CASE (use_perd_none)
579 16312 : cell%perd = [0, 0, 0]
580 : CASE DEFAULT
581 11386 : CPABORT("Invalid or not yet implemented cell periodicity")
582 : END SELECT
583 :
584 : ! Load requested cell symmetry
585 11386 : CALL section_vals_val_get(cell_section, "SYMMETRY", i_val=cell%symmetry_id)
586 : ! Try enforcing symmetry by initializing a temporary copy of cell
587 : ! and see if the resulting cell matrix differ significantly
588 148018 : hmat_input(:, :) = cell%hmat(:, :)
589 11386 : CALL cell_clone(cell, cell_tmp)
590 11386 : CALL init_cell(cell_tmp)
591 147732 : IF (.NOT. canonicalize_cell .AND. ANY(ABS(cell_tmp%hmat - cell%hmat) > eps)) THEN
592 : WRITE (UNIT=error_msg, FMT="(A)") &
593 : "When initializing cell vectors with requested symmetry, one "// &
594 : "or more elements of the cell matrix has varied significantly. "// &
595 : "The input parameters are either deviating from the symmetry, "// &
596 : "or not conforming to the program convention that cell matrix "// &
597 : "is a lower triangle. The symmetrized cell vectors will be used "// &
598 26 : "anyway with the input atomic coordinates."
599 26 : CALL cp_warn(__LOCATION__, error_msg)
600 : END IF
601 11386 : IF (canonicalize_cell) THEN
602 114 : CALL canonicalize_cell_matrix(cell_tmp)
603 114 : CALL cell_finalize_canonical_input(cell_tmp, hmat_input, cell_tmp%hmat)
604 : END IF
605 11386 : CALL cell_clone(cell_tmp, cell)
606 11386 : CALL cell_release(cell_tmp)
607 11386 : CALL reset_cell_section_by_cell_mat(cell, cell_section)
608 :
609 11386 : IF (my_check_ref) THEN
610 : ! Recursive check for reference cell requested
611 10966 : cell_ref_section => section_vals_get_subs_vals(cell_section, "CELL_REF")
612 10966 : IF (parsed_cp2k_input(cell_ref_section, check_this_section=.TRUE.)) THEN
613 26 : IF (PRESENT(use_ref_cell)) use_ref_cell = .TRUE.
614 : CALL read_cell(cell_ref, cell_ref, use_ref_cell=use_ref_cell, &
615 : cell_section=cell_ref_section, check_for_ref=.FALSE., &
616 26 : para_env=para_env)
617 : ELSE
618 10940 : CALL cell_clone(cell, cell_ref, tag="CELL_REF")
619 10940 : IF (PRESENT(use_ref_cell)) use_ref_cell = .FALSE.
620 : END IF
621 : END IF
622 :
623 11386 : END SUBROUTINE read_cell
624 :
625 : ! **************************************************************************************************
626 : !> \brief utility function to ease the transition to the new input.
627 : !> returns true if the new input was parsed
628 : !> \param input_file the parsed input file
629 : !> \param check_this_section ...
630 : !> \return ...
631 : !> \author fawzi
632 : ! **************************************************************************************************
633 10966 : FUNCTION parsed_cp2k_input(input_file, check_this_section) RESULT(res)
634 :
635 : TYPE(section_vals_type), POINTER :: input_file
636 : LOGICAL, INTENT(IN), OPTIONAL :: check_this_section
637 : LOGICAL :: res
638 :
639 : LOGICAL :: my_check
640 : TYPE(section_vals_type), POINTER :: glob_section
641 :
642 10966 : my_check = .FALSE.
643 10966 : IF (PRESENT(check_this_section)) my_check = check_this_section
644 10966 : res = ASSOCIATED(input_file)
645 10966 : IF (res) THEN
646 10966 : CPASSERT(input_file%ref_count > 0)
647 10966 : IF (.NOT. my_check) THEN
648 0 : glob_section => section_vals_get_subs_vals(input_file, "GLOBAL")
649 0 : CALL section_vals_get(glob_section, explicit=res)
650 : ELSE
651 10966 : CALL section_vals_get(input_file, explicit=res)
652 : END IF
653 : END IF
654 :
655 10966 : END FUNCTION parsed_cp2k_input
656 :
657 : ! **************************************************************************************************
658 : !> \brief Sets the cell using the internal parameters (a,b,c) (alpha,beta,gamma)
659 : !> using the convention: a parallel to the x axis, b in the x-y plane and
660 : !> and c univoquely determined; gamma is the angle between a and b; beta
661 : !> is the angle between c and a and alpha is the angle between c and b
662 : !> \param cell ...
663 : !> \param cell_length ...
664 : !> \param cell_angle ...
665 : !> \param periodic ...
666 : !> \param do_init_cell ...
667 : !> \date 03.2008
668 : !> \author Teodoro Laino
669 : ! **************************************************************************************************
670 9920 : SUBROUTINE set_cell_param(cell, cell_length, cell_angle, periodic, do_init_cell)
671 :
672 : TYPE(cell_type), POINTER :: cell
673 : REAL(KIND=dp), DIMENSION(3), INTENT(IN) :: cell_length, cell_angle
674 : INTEGER, DIMENSION(3), INTENT(IN), OPTIONAL :: periodic
675 : LOGICAL, INTENT(IN) :: do_init_cell
676 :
677 : REAL(KIND=dp), PARAMETER :: eps = EPSILON(0.0_dp)
678 :
679 : REAL(KIND=dp) :: cos_alpha, cos_beta, cos_gamma, sin_gamma
680 :
681 9920 : CPASSERT(ASSOCIATED(cell))
682 39680 : CPASSERT(ALL(cell_angle /= 0.0_dp))
683 :
684 9920 : cos_gamma = COS(cell_angle(3)); IF (ABS(cos_gamma) < eps) cos_gamma = 0.0_dp
685 9920 : IF (ABS(ABS(cos_gamma) - 1.0_dp) < eps) cos_gamma = SIGN(1.0_dp, cos_gamma)
686 9920 : sin_gamma = SIN(cell_angle(3)); IF (ABS(sin_gamma) < eps) sin_gamma = 0.0_dp
687 9920 : IF (ABS(ABS(sin_gamma) - 1.0_dp) < eps) sin_gamma = SIGN(1.0_dp, sin_gamma)
688 9920 : cos_beta = COS(cell_angle(2)); IF (ABS(cos_beta) < eps) cos_beta = 0.0_dp
689 9920 : IF (ABS(ABS(cos_beta) - 1.0_dp) < eps) cos_beta = SIGN(1.0_dp, cos_beta)
690 9920 : cos_alpha = COS(cell_angle(1)); IF (ABS(cos_alpha) < eps) cos_alpha = 0.0_dp
691 9920 : IF (ABS(ABS(cos_alpha) - 1.0_dp) < eps) cos_alpha = SIGN(1.0_dp, cos_alpha)
692 :
693 39680 : cell%hmat(:, 1) = [1.0_dp, 0.0_dp, 0.0_dp]
694 39680 : cell%hmat(:, 2) = [cos_gamma, sin_gamma, 0.0_dp]
695 39680 : cell%hmat(:, 3) = [cos_beta, (cos_alpha - cos_gamma*cos_beta)/sin_gamma, 0.0_dp]
696 9920 : cell%hmat(3, 3) = SQRT(1.0_dp - cell%hmat(1, 3)**2 - cell%hmat(2, 3)**2)
697 :
698 39680 : cell%hmat(:, 1) = cell%hmat(:, 1)*cell_length(1)
699 39680 : cell%hmat(:, 2) = cell%hmat(:, 2)*cell_length(2)
700 39680 : cell%hmat(:, 3) = cell%hmat(:, 3)*cell_length(3)
701 :
702 9920 : IF (do_init_cell) THEN
703 142 : IF (PRESENT(periodic)) THEN
704 142 : CALL init_cell(cell=cell, periodic=periodic)
705 : ELSE
706 0 : CALL init_cell(cell=cell)
707 : END IF
708 : END IF
709 :
710 9920 : END SUBROUTINE set_cell_param
711 :
712 : ! **************************************************************************************************
713 : !> \brief Setup of the multiple unit_cell
714 : !> \param cell ...
715 : !> \param multiple_unit_cell ...
716 : !> \date 05.2009
717 : !> \author Teodoro Laino [tlaino]
718 : !> \version 1.0
719 : ! **************************************************************************************************
720 148 : SUBROUTINE set_multiple_unit_cell(cell, multiple_unit_cell)
721 :
722 : TYPE(cell_type), POINTER :: cell
723 : INTEGER, DIMENSION(:), POINTER :: multiple_unit_cell
724 :
725 148 : CPASSERT(ASSOCIATED(cell))
726 :
727 : ! Abort, if one of the value is set to zero
728 592 : IF (ANY(multiple_unit_cell <= 0)) THEN
729 : CALL cp_abort(__LOCATION__, &
730 : "CELL%MULTIPLE_UNIT_CELL accepts only integer values larger than 0! "// &
731 0 : "A value of 0 or negative is meaningless!")
732 : END IF
733 :
734 : ! Scale abc according to user request
735 592 : cell%hmat(:, 1) = cell%hmat(:, 1)*multiple_unit_cell(1)
736 592 : cell%hmat(:, 2) = cell%hmat(:, 2)*multiple_unit_cell(2)
737 592 : cell%hmat(:, 3) = cell%hmat(:, 3)*multiple_unit_cell(3)
738 :
739 148 : END SUBROUTINE set_multiple_unit_cell
740 :
741 : ! **************************************************************************************************
742 : !> \brief Reads cell information from CIF file
743 : !> \param cif_file_name ...
744 : !> \param cell ...
745 : !> \param para_env ...
746 : !> \date 12.2008
747 : !> \par Format Information implemented:
748 : !> _cell_length_a (_cell.length_a)
749 : !> _cell_length_b (_cell.length_b)
750 : !> _cell_length_c (_cell.length_c)
751 : !> _cell_angle_alpha (_cell.length_alpha)
752 : !> _cell_angle_beta (_cell.length_beta)
753 : !> _cell_angle_gamma (_cell.length_gamma)
754 : !>
755 : !> \author Teodoro Laino [tlaino]
756 : !> moved from topology_cif (1/2019 JHU)
757 : ! **************************************************************************************************
758 48 : SUBROUTINE read_cell_cif(cif_file_name, cell, para_env)
759 :
760 : CHARACTER(len=*) :: cif_file_name
761 : TYPE(cell_type), POINTER :: cell
762 : TYPE(mp_para_env_type), POINTER :: para_env
763 :
764 : CHARACTER(len=*), PARAMETER :: routineN = 'read_cell_cif'
765 :
766 : INTEGER :: handle
767 : INTEGER, DIMENSION(3) :: periodic
768 : LOGICAL :: found
769 : REAL(KIND=dp), DIMENSION(3) :: cell_angles, cell_lengths
770 : TYPE(cp_parser_type) :: parser
771 :
772 24 : CALL timeset(routineN, handle)
773 :
774 : CALL parser_create(parser, cif_file_name, &
775 24 : para_env=para_env, apply_preprocessing=.FALSE.)
776 :
777 : ! Parsing cell infos
778 96 : periodic = 1
779 : ! Check for _cell_length_a or _cell.length_a
780 : CALL parser_search_string(parser, "_cell_length_a", ignore_case=.FALSE., found=found, &
781 24 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
782 24 : IF (.NOT. found) THEN
783 : CALL parser_search_string(parser, "_cell.length_a", ignore_case=.FALSE., found=found, &
784 0 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
785 0 : IF (.NOT. found) THEN
786 0 : CPABORT("The field _cell_length_a or _cell.length_a was not found in CIF file! ")
787 : END IF
788 : END IF
789 24 : CALL cif_get_real(parser, cell_lengths(1))
790 24 : cell_lengths(1) = cp_unit_to_cp2k(cell_lengths(1), "angstrom")
791 :
792 : ! Check for _cell_length_b or _cell.length_b
793 : CALL parser_search_string(parser, "_cell_length_b", ignore_case=.FALSE., found=found, &
794 24 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
795 24 : IF (.NOT. found) THEN
796 : CALL parser_search_string(parser, "_cell.length_b", ignore_case=.FALSE., found=found, &
797 0 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
798 0 : IF (.NOT. found) THEN
799 0 : CPABORT("The field _cell_length_b or _cell.length_b was not found in CIF file! ")
800 : END IF
801 : END IF
802 24 : CALL cif_get_real(parser, cell_lengths(2))
803 24 : cell_lengths(2) = cp_unit_to_cp2k(cell_lengths(2), "angstrom")
804 :
805 : ! Check for _cell_length_c or _cell.length_c
806 : CALL parser_search_string(parser, "_cell_length_c", ignore_case=.FALSE., found=found, &
807 24 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
808 24 : IF (.NOT. found) THEN
809 : CALL parser_search_string(parser, "_cell.length_c", ignore_case=.FALSE., found=found, &
810 0 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
811 0 : IF (.NOT. found) THEN
812 0 : CPABORT("The field _cell_length_c or _cell.length_c was not found in CIF file! ")
813 : END IF
814 : END IF
815 24 : CALL cif_get_real(parser, cell_lengths(3))
816 24 : cell_lengths(3) = cp_unit_to_cp2k(cell_lengths(3), "angstrom")
817 :
818 : ! Check for _cell_angle_alpha or _cell.angle_alpha
819 : CALL parser_search_string(parser, "_cell_angle_alpha", ignore_case=.FALSE., found=found, &
820 24 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
821 24 : IF (.NOT. found) THEN
822 : CALL parser_search_string(parser, "_cell.angle_alpha", ignore_case=.FALSE., found=found, &
823 0 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
824 0 : IF (.NOT. found) THEN
825 0 : CPABORT("The field _cell_angle_alpha or _cell.angle_alpha was not found in CIF file! ")
826 : END IF
827 : END IF
828 24 : CALL cif_get_real(parser, cell_angles(1))
829 24 : cell_angles(1) = cp_unit_to_cp2k(cell_angles(1), "deg")
830 :
831 : ! Check for _cell_angle_beta or _cell.angle_beta
832 : CALL parser_search_string(parser, "_cell_angle_beta", ignore_case=.FALSE., found=found, &
833 24 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
834 24 : IF (.NOT. found) THEN
835 : CALL parser_search_string(parser, "_cell.angle_beta", ignore_case=.FALSE., found=found, &
836 0 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
837 0 : IF (.NOT. found) THEN
838 0 : CPABORT("The field _cell_angle_beta or _cell.angle_beta was not found in CIF file! ")
839 : END IF
840 : END IF
841 24 : CALL cif_get_real(parser, cell_angles(2))
842 24 : cell_angles(2) = cp_unit_to_cp2k(cell_angles(2), "deg")
843 :
844 : ! Check for _cell_angle_gamma or _cell.angle_gamma
845 : CALL parser_search_string(parser, "_cell_angle_gamma", ignore_case=.FALSE., found=found, &
846 24 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
847 24 : IF (.NOT. found) THEN
848 : CALL parser_search_string(parser, "_cell.angle_gamma", ignore_case=.FALSE., found=found, &
849 0 : begin_line=.FALSE., search_from_begin_of_file=.TRUE.)
850 0 : IF (.NOT. found) THEN
851 0 : CPABORT("The field _cell_angle_gamma or _cell.angle_gamma was not found in CIF file! ")
852 : END IF
853 : END IF
854 24 : CALL cif_get_real(parser, cell_angles(3))
855 24 : cell_angles(3) = cp_unit_to_cp2k(cell_angles(3), "deg")
856 :
857 : ! Create cell
858 : CALL set_cell_param(cell, cell_lengths, cell_angles, periodic=periodic, &
859 24 : do_init_cell=.TRUE.)
860 :
861 24 : CALL parser_release(parser)
862 :
863 24 : CALL timestop(handle)
864 :
865 72 : END SUBROUTINE read_cell_cif
866 :
867 : ! **************************************************************************************************
868 : !> \brief Reads REAL from the CIF file.. This wrapper is needed in order to
869 : !> treat properly the accuracy specified in the CIF file, i.e. 3.45(6)
870 : !> \param parser ...
871 : !> \param r ...
872 : !> \date 12.2008
873 : !> \author Teodoro Laino [tlaino]
874 : ! **************************************************************************************************
875 144 : SUBROUTINE cif_get_real(parser, r)
876 :
877 : TYPE(cp_parser_type), INTENT(INOUT) :: parser
878 : REAL(KIND=dp), INTENT(OUT) :: r
879 :
880 : CHARACTER(LEN=default_string_length) :: s_tag
881 : INTEGER :: iln
882 :
883 144 : CALL parser_get_object(parser, s_tag)
884 144 : iln = LEN_TRIM(s_tag)
885 144 : IF (INDEX(s_tag, "(") /= 0) iln = INDEX(s_tag, "(") - 1
886 144 : READ (s_tag(1:iln), *) r
887 :
888 144 : END SUBROUTINE cif_get_real
889 :
890 : ! **************************************************************************************************
891 : !> \brief Reads xyz file and pass comments on the second line to get cell information
892 : !> \param xyz_file_name ...
893 : !> \param cell ...
894 : !> \param para_env ...
895 : !> \par History
896 : !> 03.2026 - Created as read_cell_extxyz with extended XYZ parser
897 : !> 06.2026 - Refactored the parser to allow for reftraj use
898 : !> \author HE Zilong
899 : ! **************************************************************************************************
900 12 : SUBROUTINE read_cell_xyz(xyz_file_name, cell, para_env)
901 :
902 : CHARACTER(len=*) :: xyz_file_name
903 : TYPE(cell_type), POINTER :: cell
904 : TYPE(mp_para_env_type), POINTER :: para_env
905 :
906 : CHARACTER(len=*), PARAMETER :: routineN = 'read_cell_xyz'
907 :
908 : INTEGER :: handle
909 : LOGICAL :: has_cell
910 : TYPE(cp_parser_type) :: parser
911 :
912 4 : CALL timeset(routineN, handle)
913 :
914 : CALL parser_create(parser, xyz_file_name, &
915 4 : para_env=para_env, apply_preprocessing=.FALSE.)
916 4 : CALL parser_get_next_line(parser, 2) ! Skip number of atoms
917 4 : CALL read_xyz_comment(parser%input_line, cell, has_cell)
918 4 : IF (.NOT. has_cell) THEN
919 : CALL cp_abort(__LOCATION__, &
920 : "The keyword CELL_FILE_FORMAT requested cell information "// &
921 : "from XYZ file, but it is not available from the file <"// &
922 0 : TRIM(ADJUSTL(xyz_file_name))//"> as CELL_FILE_NAME specified!")
923 : END IF
924 4 : CALL parser_release(parser)
925 4 : CALL timestop(handle)
926 :
927 12 : END SUBROUTINE read_cell_xyz
928 :
929 : ! **************************************************************************************************
930 : !> \brief Reads comment line of XYZ files to get cell, step, time and energy info
931 : !> \param line the single comment line of an XYZ file
932 : !> \param cell the pointer to which cell is written
933 : !> \param has_cell a flag for presence of cell information
934 : !> \param step an integer value for step number, if requested; HUGE(0) if not available
935 : !> \param time a real value for time, if requested; HUGE(0.0_dp) if not available
936 : !> \param ener a real value for energy, if requested; HUGE(0.0_dp) if not available
937 : !> \par Intended for both the FORCE_EVAL/SUBSYS/CELL and MOTION/MD/REFTRAJ.
938 : !> At minimum, should work with outputs from write_trajectory() in
939 : !> src/motion_utils.F, around line 879 of src/motion/dumpdcd.F and
940 : !> write_final_structure() in src/particle_methods.F (for cell only).
941 : !> Recognized formats (case insensitive, no hard restriction on data width):
942 : !> (1) Extended xyz format, whose comment on the second line contains fields:
943 : !> Lattice="Ax Ay Az Bx By Bz Cx Cy Cz"
944 : !> where Ax, Ay, Az are three Cartesian components of cell vector A,
945 : !> Bx, By, Bz are components of B, Cx, Cy, Cz are components of C,
946 : !> all in the unit of angstrom, and must occur;
947 : !> Step=S
948 : !> where S is the integer step number;
949 : !> Time=T
950 : !> where T is the time in femtoseconds;
951 : !> Energy=E
952 : !> where E is the energy.
953 : !> No whitespace around the = sign is present; the whitespace is used as
954 : !> the delimiter between fields; apart from lattice= at the front, other
955 : !> fields are optional and do not have a fixed order.
956 : !> (2) dumpdcd format, whose comment on the second line contains fields:
957 : !> a = A, b = B, c = C, alpha = ALPHA, beta = BETA, gamma = GAMMA
958 : !> where A, B, C are three lengths of cell vectors in angstrom, ALPHA,
959 : !> BETA, GAMMA are three angles between cell vectors in degrees;
960 : !> i = I,
961 : !> where I is the integer step number;
962 : !> time = T,
963 : !> where T is the time in femtoseconds;
964 : !> E = ENER,
965 : !> where ENER is the energy.
966 : !> There is one whitespace before and after each equal sign; the comma
967 : !> is used as the delimiter between fields; the cell information is
968 : !> optional.
969 : !>
970 : !> History
971 : !> 06.2026 - Created by combining the extxyz parser from former read_cell_extxyz
972 : !> and the parser for reftraj in src/motion/integrator.F
973 : !> \author HE Zilong
974 : ! **************************************************************************************************
975 286 : SUBROUTINE read_xyz_comment(line, cell, has_cell, step, time, ener)
976 :
977 : CHARACTER(LEN=*), INTENT(IN) :: line
978 : TYPE(cell_type), INTENT(INOUT), POINTER :: cell
979 : LOGICAL, INTENT(OUT) :: has_cell
980 : INTEGER, INTENT(OUT), OPTIONAL :: step
981 : REAL(KIND=dp), INTENT(OUT), OPTIONAL :: time, ener
982 :
983 : CHARACTER(LEN=3) :: abc
984 : CHARACTER(LEN=max_line_length) :: my_line, raw_str
985 : INTEGER :: i, id1, id2, ios, j, my_step
986 : REAL(KIND=dp) :: my_ener, my_time
987 : REAL(KIND=dp), DIMENSION(3) :: my_abc, my_albega
988 : REAL(KIND=dp), DIMENSION(3, 3) :: my_hmat
989 :
990 286 : has_cell = .FALSE.
991 286 : my_step = HUGE(0)
992 286 : my_time = HUGE(0.0_dp)
993 286 : my_ener = HUGE(0.0_dp)
994 286 : my_hmat = 0.0_dp
995 286 : my_abc = 0.0_dp
996 286 : my_albega = 0.0_dp
997 :
998 286 : my_line = line
999 286 : CALL uppercase(my_line)
1000 286 : id1 = INDEX(my_line, "LATTICE=")
1001 286 : IF (id1 > 0) THEN ! Extended XYZ
1002 22 : id2 = INDEX(my_line(id1 + 9:), '"') ! Strip 'LATTICE="' and find the next quote
1003 22 : READ (my_line(id1 + 9:id1 + id2 + 7), '(A)') raw_str
1004 22 : READ (raw_str, *, IOSTAT=ios) my_hmat(:, 1), my_hmat(:, 2), my_hmat(:, 3)
1005 22 : IF (ios /= 0) THEN
1006 : CALL cp_abort(__LOCATION__, "Error while parsing input line for cell vectors as "// &
1007 : "extended XYZ format: expected 9 real values in the <lattice=> "// &
1008 0 : "quoted field, found <"//TRIM(raw_str)//"> which is invalid!")
1009 : ELSE
1010 22 : has_cell = .TRUE.
1011 88 : DO i = 1, 3
1012 286 : DO j = 1, 3
1013 264 : cell%hmat(j, i) = cp_unit_to_cp2k(my_hmat(j, i), "angstrom")
1014 : END DO
1015 : END DO
1016 : END IF
1017 22 : IF (PRESENT(step)) THEN
1018 18 : id1 = INDEX(my_line, "STEP=")
1019 18 : IF (id1 > 0) THEN
1020 18 : READ (my_line(id1 + 5:), '(A)') raw_str
1021 18 : READ (raw_str, *, IOSTAT=ios) my_step
1022 18 : IF (ios /= 0) THEN
1023 : CALL cp_abort(__LOCATION__, &
1024 : "Error while parsing input line for step as extended "// &
1025 : "XYZ format: expected 1 integer value in the <step=> "// &
1026 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1027 : END IF
1028 : END IF
1029 18 : step = my_step
1030 : END IF
1031 22 : IF (PRESENT(time)) THEN
1032 18 : id1 = INDEX(my_line, "TIME=")
1033 18 : IF (id1 > 0) THEN
1034 18 : READ (my_line(id1 + 5:), '(A)') raw_str
1035 18 : READ (raw_str, *, IOSTAT=ios) my_time
1036 18 : IF (ios /= 0) THEN
1037 : CALL cp_abort(__LOCATION__, &
1038 : "Error while parsing input line for time as extended "// &
1039 : "XYZ format: expected 1 real value in the <time=> "// &
1040 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1041 : END IF
1042 : END IF
1043 18 : time = my_time
1044 : END IF
1045 22 : IF (PRESENT(ener)) THEN
1046 18 : id1 = INDEX(my_line, "ENERGY=")
1047 18 : IF (id1 > 0) THEN
1048 18 : READ (my_line(id1 + 7:), '(A)') raw_str
1049 18 : READ (raw_str, *, IOSTAT=ios) my_ener
1050 18 : IF (ios /= 0) THEN
1051 : CALL cp_abort(__LOCATION__, &
1052 : "Error while parsing input line for energy as extended "// &
1053 : "XYZ format: expected 1 real value in the <energy=> "// &
1054 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1055 : END IF
1056 : END IF
1057 18 : ener = my_ener
1058 : END IF
1059 : ELSE ! May or may not be dumpdcd format, and may or may not has cell
1060 264 : abc = "ABC"
1061 1056 : DO i = 1, 3
1062 792 : id1 = INDEX(my_line, " "//abc(i:i)//" = ")
1063 1056 : IF (id1 > 0) THEN
1064 0 : READ (my_line(id1 + 5:), '(A)') raw_str
1065 0 : READ (raw_str, *, IOSTAT=ios) my_abc(i)
1066 0 : IF (ios /= 0) THEN
1067 : CALL cp_abort(__LOCATION__, &
1068 : "Error while parsing input line for cell vector as dumpdcd "// &
1069 : "XYZ format: expected 1 real value in the <"//abc(i:i)//" = > "// &
1070 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1071 : ELSE
1072 0 : my_abc(i) = cp_unit_to_cp2k(my_abc(i), "angstrom")
1073 : END IF
1074 : END IF
1075 : END DO
1076 264 : id1 = INDEX(my_line, " ALPHA = ")
1077 264 : IF (id1 > 0) THEN
1078 0 : READ (my_line(id1 + 9:), '(A)') raw_str
1079 0 : READ (raw_str, *, IOSTAT=ios) my_albega(1)
1080 0 : IF (ios /= 0) THEN
1081 : CALL cp_abort(__LOCATION__, &
1082 : "Error while parsing input line for cell angle alpha as dumpdcd "// &
1083 : "XYZ format: expected 1 real value in the <alpha = > "// &
1084 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1085 : ELSE
1086 0 : my_albega(1) = cp_unit_to_cp2k(my_albega(1), "deg")
1087 : END IF
1088 : END IF
1089 264 : id1 = INDEX(my_line, " BETA = ")
1090 264 : IF (id1 > 0) THEN
1091 0 : READ (my_line(id1 + 8:), '(A)') raw_str
1092 0 : READ (raw_str, *, IOSTAT=ios) my_albega(2)
1093 0 : IF (ios /= 0) THEN
1094 : CALL cp_abort(__LOCATION__, &
1095 : "Error while parsing input line for cell angle beta as dumpdcd "// &
1096 : "XYZ format: expected 1 real value in the <beta = > "// &
1097 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1098 : ELSE
1099 0 : my_albega(2) = cp_unit_to_cp2k(my_albega(2), "deg")
1100 : END IF
1101 : END IF
1102 264 : id1 = INDEX(my_line, " GAMMA = ")
1103 264 : IF (id1 > 0) THEN
1104 0 : READ (my_line(id1 + 9:), '(A)') raw_str
1105 0 : READ (raw_str, *, IOSTAT=ios) my_albega(3)
1106 0 : IF (ios /= 0) THEN
1107 : CALL cp_abort(__LOCATION__, &
1108 : "Error while parsing input line for cell angle gamma as dumpdcd "// &
1109 : "XYZ format: expected 1 real value in the <gamma = > "// &
1110 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1111 : ELSE
1112 0 : my_albega(3) = cp_unit_to_cp2k(my_albega(3), "deg")
1113 : END IF
1114 : END IF
1115 528 : IF (ALL(my_abc(1:3) > 0.0_dp) .AND. ALL(my_albega(1:3) > 0.0_dp)) THEN
1116 0 : has_cell = .TRUE.
1117 0 : CALL set_cell_param(cell, my_abc, my_albega, do_init_cell=.FALSE.)
1118 : END IF
1119 264 : IF (PRESENT(step)) THEN
1120 264 : id1 = INDEX(my_line, " I = ")
1121 264 : IF (id1 > 0) THEN
1122 214 : READ (my_line(id1 + 5:), '(A)') raw_str
1123 214 : READ (raw_str, *, IOSTAT=ios) my_step
1124 214 : IF (ios /= 0) THEN
1125 : CALL cp_abort(__LOCATION__, &
1126 : "Error while parsing input line for step as dumpdcd "// &
1127 : "XYZ format: expected 1 integer value in the <i = > "// &
1128 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1129 : END IF
1130 : END IF
1131 264 : step = my_step
1132 : END IF
1133 264 : IF (PRESENT(time)) THEN
1134 264 : id1 = INDEX(my_line, " TIME = ")
1135 264 : IF (id1 > 0) THEN
1136 214 : READ (my_line(id1 + 8:), '(A)') raw_str
1137 214 : READ (raw_str, *, IOSTAT=ios) my_time
1138 214 : IF (ios /= 0) THEN
1139 : CALL cp_abort(__LOCATION__, &
1140 : "Error while parsing input line for time as dumpdcd "// &
1141 : "XYZ format: expected 1 real value in the <time = > "// &
1142 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1143 : END IF
1144 : END IF
1145 264 : time = my_time
1146 : END IF
1147 264 : IF (PRESENT(ener)) THEN
1148 264 : id1 = INDEX(my_line, " E = ")
1149 264 : IF (id1 > 0) THEN
1150 214 : READ (my_line(id1 + 5:), '(A)') raw_str
1151 214 : READ (raw_str, *, IOSTAT=ios) my_ener
1152 214 : IF (ios /= 0) THEN
1153 : CALL cp_abort(__LOCATION__, &
1154 : "Error while parsing input line for energy as dumpdcd "// &
1155 : "XYZ format: expected 1 real value in the <E = > "// &
1156 0 : "field, found <"//TRIM(raw_str)//"> which is invalid!")
1157 : END IF
1158 : END IF
1159 264 : ener = my_ener
1160 : END IF
1161 : END IF
1162 :
1163 286 : END SUBROUTINE read_xyz_comment
1164 :
1165 : ! **************************************************************************************************
1166 : !> \brief Reads cell information from CRYST1 record of PDB file
1167 : !> \param pdb_file_name ...
1168 : !> \param cell ...
1169 : !> \param para_env ...
1170 : !> \date 03.2026
1171 : !> \par CRYST1 record may contain space group and Z value at the end,
1172 : !> but here only the first entries are read:
1173 : !> COLUMNS DATA TYPE FIELD DEFINITION
1174 : !> -------------------------------------------------------------
1175 : !> 1 - 6 Record name "CRYST1"
1176 : !> 7 - 15 Real(9.3) a a (Angstroms).
1177 : !> 16 - 24 Real(9.3) b b (Angstroms).
1178 : !> 25 - 33 Real(9.3) c c (Angstroms).
1179 : !> 34 - 40 Real(7.2) alpha alpha (degrees).
1180 : !> 41 - 47 Real(7.2) beta beta (degrees).
1181 : !> 48 - 54 Real(7.2) gamma gamma (degrees).
1182 : ! **************************************************************************************************
1183 4 : SUBROUTINE read_cell_pdb(pdb_file_name, cell, para_env)
1184 :
1185 : CHARACTER(len=*) :: pdb_file_name
1186 : TYPE(cell_type), POINTER :: cell
1187 : TYPE(mp_para_env_type), POINTER :: para_env
1188 :
1189 : CHARACTER(len=*), PARAMETER :: routineN = 'read_cell_pdb'
1190 :
1191 : CHARACTER(LEN=default_string_length) :: cryst
1192 : INTEGER :: handle, i, ios
1193 : INTEGER, DIMENSION(3) :: periodic
1194 : LOGICAL :: found
1195 : REAL(KIND=dp), DIMENSION(3) :: cell_angles, cell_lengths
1196 : TYPE(cp_parser_type) :: parser
1197 :
1198 2 : CALL timeset(routineN, handle)
1199 :
1200 : CALL parser_create(parser, pdb_file_name, &
1201 2 : para_env=para_env, apply_preprocessing=.FALSE.)
1202 :
1203 : CALL parser_search_string(parser, "CRYST1", ignore_case=.FALSE., found=found, &
1204 2 : begin_line=.TRUE., search_from_begin_of_file=.TRUE.)
1205 2 : IF (.NOT. found) THEN
1206 0 : CPABORT("The line <CRYST1> was not found in PDB file! ")
1207 : END IF
1208 :
1209 8 : periodic = 1
1210 2 : READ (parser%input_line, *, IOSTAT=ios) cryst, cell_lengths(:), cell_angles(:)
1211 2 : IF (ios /= 0) THEN
1212 : CALL cp_abort(__LOCATION__, "Error while parsing PDB file "// &
1213 : "<"//TRIM(pdb_file_name)//"> for cell lengths and angles: "// &
1214 0 : "found CRYST1 line as <"//TRIM(parser%input_line)//">")
1215 : END IF
1216 8 : DO i = 1, 3
1217 6 : cell_lengths(i) = cp_unit_to_cp2k(cell_lengths(i), "angstrom")
1218 8 : cell_angles(i) = cp_unit_to_cp2k(cell_angles(i), "deg")
1219 : END DO
1220 : CALL set_cell_param(cell, cell_lengths, cell_angles, periodic=periodic, &
1221 2 : do_init_cell=.TRUE.)
1222 :
1223 2 : CALL parser_release(parser)
1224 :
1225 2 : CALL timestop(handle)
1226 :
1227 6 : END SUBROUTINE read_cell_pdb
1228 :
1229 : ! **************************************************************************************************
1230 : !> \brief Reads cell information from cp2k file
1231 : !> \param cp2k_file_name ...
1232 : !> \param cell ...
1233 : !> \param para_env ...
1234 : !> \date 03.2026
1235 : !> \par Isolated from former read_cell_from_external_file
1236 : ! **************************************************************************************************
1237 4 : SUBROUTINE read_cell_cp2k(cp2k_file_name, cell, para_env)
1238 :
1239 : CHARACTER(len=*) :: cp2k_file_name
1240 : TYPE(cell_type), POINTER :: cell
1241 : TYPE(mp_para_env_type), POINTER :: para_env
1242 :
1243 : CHARACTER(len=*), PARAMETER :: routineN = 'read_cell_cp2k'
1244 :
1245 : INTEGER :: handle, i, idum, j
1246 : LOGICAL :: my_end
1247 : REAL(KIND=dp) :: xdum
1248 : REAL(KIND=dp), DIMENSION(3, 3) :: hmat
1249 : TYPE(cp_parser_type) :: parser
1250 :
1251 2 : CALL timeset(routineN, handle)
1252 :
1253 : CALL parser_create(parser, cp2k_file_name, &
1254 2 : para_env=para_env, apply_preprocessing=.FALSE.)
1255 :
1256 2 : CALL parser_get_next_line(parser, 1)
1257 2 : my_end = .FALSE.
1258 24 : DO WHILE (.NOT. my_end)
1259 22 : READ (parser%input_line, *) idum, xdum, hmat(:, 1), hmat(:, 2), hmat(:, 3)
1260 24 : CALL parser_get_next_line(parser, 1, at_end=my_end)
1261 : END DO
1262 8 : DO i = 1, 3
1263 26 : DO j = 1, 3
1264 24 : cell%hmat(j, i) = cp_unit_to_cp2k(hmat(j, i), "angstrom")
1265 : END DO
1266 : END DO
1267 :
1268 2 : CALL parser_release(parser)
1269 :
1270 2 : CALL timestop(handle)
1271 :
1272 6 : END SUBROUTINE read_cell_cp2k
1273 :
1274 : ! **************************************************************************************************
1275 : !> \brief Reads cell information from xsc file
1276 : !> \param xsc_file_name ...
1277 : !> \param cell ...
1278 : !> \param para_env ...
1279 : !> \date 03.2026
1280 : !> \par Isolated from former read_cell_from_external_file
1281 : ! **************************************************************************************************
1282 0 : SUBROUTINE read_cell_xsc(xsc_file_name, cell, para_env)
1283 :
1284 : CHARACTER(len=*) :: xsc_file_name
1285 : TYPE(cell_type), POINTER :: cell
1286 : TYPE(mp_para_env_type), POINTER :: para_env
1287 :
1288 : CHARACTER(len=*), PARAMETER :: routineN = 'read_cell_xsc'
1289 :
1290 : INTEGER :: handle, i, idum, j
1291 : REAL(KIND=dp), DIMENSION(3, 3) :: hmat
1292 : TYPE(cp_parser_type) :: parser
1293 :
1294 0 : CALL timeset(routineN, handle)
1295 :
1296 : CALL parser_create(parser, xsc_file_name, &
1297 0 : para_env=para_env, apply_preprocessing=.FALSE.)
1298 :
1299 0 : CALL parser_get_next_line(parser, 1)
1300 0 : READ (parser%input_line, *) idum, hmat(:, 1), hmat(:, 2), hmat(:, 3)
1301 0 : DO i = 1, 3
1302 0 : DO j = 1, 3
1303 0 : cell%hmat(j, i) = cp_unit_to_cp2k(hmat(j, i), "angstrom")
1304 : END DO
1305 : END DO
1306 :
1307 0 : CALL parser_release(parser)
1308 :
1309 0 : CALL timestop(handle)
1310 :
1311 0 : END SUBROUTINE read_cell_xsc
1312 :
1313 : ! **************************************************************************************************
1314 : !> \brief Reset cell section by matrix in cell-type pointer
1315 : !> \param cell ...
1316 : !> \param cell_section ...
1317 : !> \date 03.2026
1318 : !> \par Alternative keywords for cell settings will be unset
1319 : !> except MULTIPLE_UNIT_CELL, PERIODIC and SYMMETRY.
1320 : ! **************************************************************************************************
1321 22772 : SUBROUTINE reset_cell_section_by_cell_mat(cell, cell_section)
1322 :
1323 : TYPE(cell_type), POINTER :: cell
1324 : TYPE(section_vals_type), POINTER :: cell_section
1325 :
1326 22772 : REAL(KIND=dp), DIMENSION(:), POINTER :: cell_par
1327 :
1328 22772 : CALL section_vals_val_unset(cell_section, "CELL_FILE_NAME")
1329 22772 : CALL section_vals_val_unset(cell_section, "CELL_FILE_FORMAT")
1330 22772 : CALL section_vals_val_unset(cell_section, "ABC")
1331 22772 : CALL section_vals_val_unset(cell_section, "ALPHA_BETA_GAMMA")
1332 22772 : CALL section_vals_val_unset(cell_section, "A")
1333 22772 : CALL section_vals_val_unset(cell_section, "B")
1334 22772 : CALL section_vals_val_unset(cell_section, "C")
1335 22772 : ALLOCATE (cell_par(3))
1336 182176 : cell_par = cell%hmat(:, 1)
1337 22772 : CALL section_vals_val_set(cell_section, "A", r_vals_ptr=cell_par)
1338 22772 : ALLOCATE (cell_par(3))
1339 182176 : cell_par = cell%hmat(:, 2)
1340 22772 : CALL section_vals_val_set(cell_section, "B", r_vals_ptr=cell_par)
1341 22772 : ALLOCATE (cell_par(3))
1342 182176 : cell_par = cell%hmat(:, 3)
1343 22772 : CALL section_vals_val_set(cell_section, "C", r_vals_ptr=cell_par)
1344 :
1345 22772 : END SUBROUTINE reset_cell_section_by_cell_mat
1346 :
1347 : ! **************************************************************************************************
1348 : !> \brief Write the cell parameters to the output unit.
1349 : !> \param cell ...
1350 : !> \param subsys_section ...
1351 : !> \param tag ...
1352 : !> \date 02.06.2000
1353 : !> \par History
1354 : !> - 11.2008 Teodoro Laino [tlaino] - rewrite and enabling user driven units
1355 : !> \author Matthias Krack
1356 : !> \version 1.0
1357 : ! **************************************************************************************************
1358 31273 : SUBROUTINE write_cell(cell, subsys_section, tag)
1359 :
1360 : TYPE(cell_type), POINTER :: cell
1361 : TYPE(section_vals_type), POINTER :: subsys_section
1362 : CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: tag
1363 :
1364 : CHARACTER(LEN=default_string_length) :: label, unit_str
1365 : INTEGER :: output_unit
1366 : TYPE(cp_logger_type), POINTER :: logger
1367 :
1368 31273 : NULLIFY (logger)
1369 31273 : logger => cp_get_default_logger()
1370 31273 : IF (PRESENT(tag)) THEN
1371 23000 : label = TRIM(tag)//"|"
1372 : ELSE
1373 8273 : label = TRIM(cell%tag)//"|"
1374 : END IF
1375 :
1376 31273 : output_unit = cp_print_key_unit_nr(logger, subsys_section, "PRINT%CELL", extension=".Log")
1377 31273 : CALL section_vals_val_get(subsys_section, "PRINT%CELL%UNIT", c_val=unit_str)
1378 31273 : CALL write_cell_low(cell, unit_str, output_unit, label)
1379 31273 : CALL cp_print_key_finished_output(output_unit, logger, subsys_section, "PRINT%CELL")
1380 :
1381 31273 : END SUBROUTINE write_cell
1382 :
1383 : ! **************************************************************************************************
1384 : !> \brief Write the cell parameters to the output unit
1385 : !> \param cell ...
1386 : !> \param unit_str ...
1387 : !> \param output_unit ...
1388 : !> \param label ...
1389 : !> \date 17.05.2023
1390 : !> \par History
1391 : !> - Extracted from write_cell (17.05.2023, MK)
1392 : !> \version 1.0
1393 : ! **************************************************************************************************
1394 31273 : SUBROUTINE write_cell_low(cell, unit_str, output_unit, label)
1395 :
1396 : TYPE(cell_type), POINTER :: cell
1397 : CHARACTER(LEN=*), INTENT(IN) :: unit_str
1398 : INTEGER, INTENT(IN) :: output_unit
1399 : CHARACTER(LEN=*), INTENT(IN), OPTIONAL :: label
1400 :
1401 : CHARACTER(LEN=12) :: tag
1402 : CHARACTER(LEN=3) :: string
1403 : CHARACTER(LEN=default_string_length) :: my_label
1404 : REAL(KIND=dp) :: alpha, beta, gamma, val
1405 : REAL(KIND=dp), DIMENSION(3) :: abc
1406 : TYPE(enumeration_type), POINTER :: enum
1407 : TYPE(keyword_type), POINTER :: keyword
1408 : TYPE(section_type), POINTER :: section
1409 :
1410 31273 : NULLIFY (enum)
1411 31273 : NULLIFY (keyword)
1412 31273 : NULLIFY (section)
1413 :
1414 41425 : IF (output_unit > 0) THEN
1415 10152 : CALL get_cell(cell=cell, abc=abc, alpha=alpha, beta=beta, gamma=gamma, tag=tag)
1416 10152 : IF (PRESENT(label)) THEN
1417 10152 : my_label = label
1418 : ELSE
1419 0 : my_label = TRIM(tag)//"|"
1420 : END IF
1421 10152 : val = cp_unit_from_cp2k(cell%deth, TRIM(unit_str)//"^3")
1422 : WRITE (UNIT=output_unit, FMT="(/,T2,A,T61,F20.6)") &
1423 10152 : TRIM(my_label)//" Volume ["//TRIM(unit_str)//"^3]:", val
1424 10152 : val = cp_unit_from_cp2k(1.0_dp, TRIM(unit_str))
1425 : WRITE (UNIT=output_unit, FMT="(T2,A,T30,3F10.3,3X,A6,F12.6)") &
1426 40608 : TRIM(my_label)//" Vector a ["//TRIM(unit_str)//"]:", cell%hmat(:, 1)*val, &
1427 10152 : "|a| = ", abc(1)*val, &
1428 40608 : TRIM(my_label)//" Vector b ["//TRIM(unit_str)//"]:", cell%hmat(:, 2)*val, &
1429 10152 : "|b| = ", abc(2)*val, &
1430 40608 : TRIM(my_label)//" Vector c ["//TRIM(unit_str)//"]:", cell%hmat(:, 3)*val, &
1431 20304 : "|c| = ", abc(3)*val
1432 : WRITE (UNIT=output_unit, FMT="(T2,A,T69,F12.6)") &
1433 10152 : TRIM(my_label)//" Angle (b,c), alpha [degree]: ", alpha, &
1434 10152 : TRIM(my_label)//" Angle (a,c), beta [degree]: ", beta, &
1435 20304 : TRIM(my_label)//" Angle (a,b), gamma [degree]: ", gamma
1436 10152 : IF (cell%symmetry_id /= cell_sym_none) THEN
1437 2208 : CALL create_cell_section(section)
1438 2208 : keyword => section_get_keyword(section, "SYMMETRY")
1439 2208 : CALL keyword_get(keyword, enum=enum)
1440 : WRITE (UNIT=output_unit, FMT="(T2,A,T61,A20)") &
1441 2208 : TRIM(my_label)//" Requested initial symmetry: ", &
1442 4416 : ADJUSTR(TRIM(enum_i2c(enum, cell%symmetry_id)))
1443 2208 : CALL section_release(section)
1444 : END IF
1445 10152 : IF (cell%orthorhombic) THEN
1446 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
1447 6304 : TRIM(my_label)//" Numerically orthorhombic: ", "YES"
1448 : ELSE
1449 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
1450 3848 : TRIM(my_label)//" Numerically orthorhombic: ", " NO"
1451 : END IF
1452 40608 : IF (SUM(cell%perd(1:3)) == 0) THEN
1453 : WRITE (UNIT=output_unit, FMT="(T2,A,T77,A4)") &
1454 1914 : TRIM(my_label)//" Periodicity", "NONE"
1455 : ELSE
1456 8238 : string = ""
1457 8238 : IF (cell%perd(1) == 1) string = TRIM(string)//"X"
1458 8238 : IF (cell%perd(2) == 1) string = TRIM(string)//"Y"
1459 8238 : IF (cell%perd(3) == 1) string = TRIM(string)//"Z"
1460 : WRITE (UNIT=output_unit, FMT="(T2,A,T78,A3)") &
1461 8238 : TRIM(my_label)//" Periodicity", ADJUSTR(string)
1462 : END IF
1463 : END IF
1464 :
1465 31273 : END SUBROUTINE write_cell_low
1466 :
1467 : END MODULE cell_methods
|