(git:374b731)
Loading...
Searching...
No Matches
kpoint_io.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Restart file for k point calculations
10!> \par History
11!> \author JGH (30.09.2015)
12! **************************************************************************************************
14
20 USE cp_files, ONLY: close_file,&
28 USE cp_output_handling, ONLY: cp_p_file,&
32 USE dbcsr_api, ONLY: dbcsr_get_info,&
33 dbcsr_p_type
35 USE kinds, ONLY: default_path_length
36 USE kpoint_types, ONLY: get_kpoint_info,&
39 USE orbital_pointers, ONLY: nso
43 USE qs_kind_types, ONLY: get_qs_kind,&
47#include "./base/base_uses.f90"
48
49 IMPLICIT NONE
50
51 PRIVATE
52
53 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'kpoint_io'
54
55 INTEGER, PARAMETER :: version = 1
56
57 PUBLIC :: read_kpoints_restart, &
59
60! **************************************************************************************************
61
62CONTAINS
63
64! **************************************************************************************************
65!> \brief ...
66!> \param denmat ...
67!> \param kpoints ...
68!> \param scf_env ...
69!> \param dft_section ...
70!> \param particle_set ...
71!> \param qs_kind_set ...
72! **************************************************************************************************
73 SUBROUTINE write_kpoints_restart(denmat, kpoints, scf_env, dft_section, &
74 particle_set, qs_kind_set)
75
76 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: denmat
77 TYPE(kpoint_type), POINTER :: kpoints
78 TYPE(qs_scf_env_type), POINTER :: scf_env
79 TYPE(section_vals_type), POINTER :: dft_section
80 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
81 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
82
83 CHARACTER(LEN=*), PARAMETER :: routinen = 'write_kpoints_restart'
84 CHARACTER(LEN=30), DIMENSION(2), PARAMETER :: &
85 keys = (/"SCF%PRINT%RESTART_HISTORY", "SCF%PRINT%RESTART "/)
86
87 INTEGER :: handle, ic, ikey, ires, ispin, nimages, &
88 nspin
89 INTEGER, DIMENSION(3) :: cell
90 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
91 TYPE(cp_fm_type), POINTER :: fmat
92 TYPE(cp_logger_type), POINTER :: logger
93
94 CALL timeset(routinen, handle)
95 logger => cp_get_default_logger()
96
97 IF (btest(cp_print_key_should_output(logger%iter_info, &
98 dft_section, keys(1)), cp_p_file) .OR. &
99 btest(cp_print_key_should_output(logger%iter_info, &
100 dft_section, keys(2)), cp_p_file)) THEN
101
102 DO ikey = 1, SIZE(keys)
103
104 IF (btest(cp_print_key_should_output(logger%iter_info, &
105 dft_section, keys(ikey)), cp_p_file)) THEN
106
107 ires = cp_print_key_unit_nr(logger, dft_section, keys(ikey), &
108 extension=".kp", file_status="REPLACE", file_action="WRITE", &
109 do_backup=.true., file_form="UNFORMATTED")
110
111 CALL write_kpoints_file_header(qs_kind_set, particle_set, ires)
112
113 nspin = SIZE(denmat, 1)
114 nimages = SIZE(denmat, 2)
115 NULLIFY (cell_to_index)
116 IF (nimages > 1) THEN
117 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
118 END IF
119 cpassert(ASSOCIATED(scf_env%scf_work1))
120 fmat => scf_env%scf_work1(1)
121
122 DO ispin = 1, nspin
123 IF (ires > 0) WRITE (ires) ispin, nspin, nimages
124 DO ic = 1, nimages
125 IF (nimages > 1) THEN
126 cell = get_cell(ic, cell_to_index)
127 ELSE
128 cell = 0
129 END IF
130 IF (ires > 0) WRITE (ires) ic, cell
131 CALL copy_dbcsr_to_fm(denmat(ispin, ic)%matrix, fmat)
132 CALL cp_fm_write_unformatted(fmat, ires)
133 END DO
134 END DO
135
136 CALL cp_print_key_finished_output(ires, logger, dft_section, trim(keys(ikey)))
137
138 END IF
139
140 END DO
141
142 END IF
143
144 CALL timestop(handle)
145
146 END SUBROUTINE write_kpoints_restart
147
148! **************************************************************************************************
149!> \brief ...
150!> \param ic ...
151!> \param cell_to_index ...
152!> \return ...
153! **************************************************************************************************
154 FUNCTION get_cell(ic, cell_to_index) RESULT(cell)
155 INTEGER, INTENT(IN) :: ic
156 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
157 INTEGER, DIMENSION(3) :: cell
158
159 INTEGER :: i1, i2, i3
160
161 cell = 0
162 allcell: DO i3 = lbound(cell_to_index, 3), ubound(cell_to_index, 3)
163 DO i2 = lbound(cell_to_index, 2), ubound(cell_to_index, 2)
164 DO i1 = lbound(cell_to_index, 1), ubound(cell_to_index, 1)
165 IF (cell_to_index(i1, i2, i3) == ic) THEN
166 cell(1) = i1
167 cell(2) = i2
168 cell(3) = i3
169 EXIT allcell
170 END IF
171 END DO
172 END DO
173 END DO allcell
174
175 END FUNCTION get_cell
176
177! **************************************************************************************************
178!> \brief ...
179!> \param qs_kind_set ...
180!> \param particle_set ...
181!> \param ires ...
182! **************************************************************************************************
183 SUBROUTINE write_kpoints_file_header(qs_kind_set, particle_set, ires)
184
185 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
186 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
187 INTEGER :: ires
188
189 CHARACTER(LEN=*), PARAMETER :: routinen = 'write_kpoints_file_header'
190
191 INTEGER :: handle, iatom, ikind, iset, ishell, &
192 lmax, lshell, nao, natom, nset, &
193 nset_max, nsgf, nshell_max
194 INTEGER, DIMENSION(:), POINTER :: nset_info, nshell
195 INTEGER, DIMENSION(:, :), POINTER :: l, nshell_info
196 INTEGER, DIMENSION(:, :, :), POINTER :: nso_info
197 TYPE(gto_basis_set_type), POINTER :: orb_basis_set
198 TYPE(qs_dftb_atom_type), POINTER :: dftb_parameter
199
200 CALL timeset(routinen, handle)
201
202 IF (ires > 0) THEN
203 ! create some info about the basis set first
204 natom = SIZE(particle_set, 1)
205 nset_max = 0
206 nshell_max = 0
207
208 DO iatom = 1, natom
209 NULLIFY (orb_basis_set, dftb_parameter)
210 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
211 CALL get_qs_kind(qs_kind_set(ikind), &
212 basis_set=orb_basis_set, dftb_parameter=dftb_parameter)
213 IF (ASSOCIATED(orb_basis_set)) THEN
214 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, &
215 nset=nset, &
216 nshell=nshell, &
217 l=l)
218 nset_max = max(nset_max, nset)
219 DO iset = 1, nset
220 nshell_max = max(nshell_max, nshell(iset))
221 END DO
222 ELSEIF (ASSOCIATED(dftb_parameter)) THEN
223 CALL get_dftb_atom_param(dftb_parameter, lmax=lmax)
224 nset_max = max(nset_max, 1)
225 nshell_max = max(nshell_max, lmax + 1)
226 ELSE
227 cpabort("Unknown basis type.")
228 END IF
229 END DO
230
231 ALLOCATE (nso_info(nshell_max, nset_max, natom))
232 nso_info(:, :, :) = 0
233
234 ALLOCATE (nshell_info(nset_max, natom))
235 nshell_info(:, :) = 0
236
237 ALLOCATE (nset_info(natom))
238 nset_info(:) = 0
239
240 nao = 0
241 DO iatom = 1, natom
242 NULLIFY (orb_basis_set, dftb_parameter)
243 CALL get_atomic_kind(particle_set(iatom)%atomic_kind, kind_number=ikind)
244 CALL get_qs_kind(qs_kind_set(ikind), &
245 basis_set=orb_basis_set, dftb_parameter=dftb_parameter)
246 IF (ASSOCIATED(orb_basis_set)) THEN
247 CALL get_gto_basis_set(gto_basis_set=orb_basis_set, nsgf=nsgf, nset=nset, nshell=nshell, l=l)
248 nao = nao + nsgf
249 nset_info(iatom) = nset
250 DO iset = 1, nset
251 nshell_info(iset, iatom) = nshell(iset)
252 DO ishell = 1, nshell(iset)
253 lshell = l(ishell, iset)
254 nso_info(ishell, iset, iatom) = nso(lshell)
255 END DO
256 END DO
257 ELSEIF (ASSOCIATED(dftb_parameter)) THEN
258 CALL get_dftb_atom_param(dftb_parameter, lmax=lmax)
259 nset_info(iatom) = 1
260 nshell_info(1, iatom) = lmax + 1
261 DO ishell = 1, lmax + 1
262 lshell = ishell - 1
263 nso_info(ishell, 1, iatom) = nso(lshell)
264 END DO
265 nao = nao + (lmax + 1)**2
266 ELSE
267 cpabort("Unknown basis set type.")
268 END IF
269 END DO
270
271 WRITE (ires) version
272 WRITE (ires) natom, nao, nset_max, nshell_max
273 WRITE (ires) nset_info
274 WRITE (ires) nshell_info
275 WRITE (ires) nso_info
276
277 DEALLOCATE (nset_info, nshell_info, nso_info)
278 END IF
279
280 CALL timestop(handle)
281
282 END SUBROUTINE write_kpoints_file_header
283
284! **************************************************************************************************
285!> \brief ...
286!> \param denmat ...
287!> \param kpoints ...
288!> \param fmwork ...
289!> \param natom ...
290!> \param para_env ...
291!> \param id_nr ...
292!> \param dft_section ...
293!> \param natom_mismatch ...
294! **************************************************************************************************
295 SUBROUTINE read_kpoints_restart(denmat, kpoints, fmwork, natom, &
296 para_env, id_nr, dft_section, natom_mismatch)
297
298 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: denmat
299 TYPE(kpoint_type), POINTER :: kpoints
300 TYPE(cp_fm_type), DIMENSION(:), INTENT(INOUT) :: fmwork
301 INTEGER, INTENT(IN) :: natom
302 TYPE(mp_para_env_type), POINTER :: para_env
303 INTEGER, INTENT(IN) :: id_nr
304 TYPE(section_vals_type), POINTER :: dft_section
305 LOGICAL, INTENT(OUT) :: natom_mismatch
306
307 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_kpoints_restart'
308
309 CHARACTER(LEN=default_path_length) :: file_name
310 INTEGER :: handle, restart_unit
311 LOGICAL :: exist
312 TYPE(cp_logger_type), POINTER :: logger
313
314 CALL timeset(routinen, handle)
315 logger => cp_get_default_logger()
316
317 restart_unit = -1
318
319 IF (para_env%is_source()) THEN
320
321 CALL wfn_restart_file_name(file_name, exist, dft_section, logger, kp=.true.)
322 IF (id_nr /= 0) THEN
323 ! Is it one of the backup files?
324 file_name = trim(file_name)//".bak-"//adjustl(cp_to_string(id_nr))
325 END IF
326
327 CALL open_file(file_name=file_name, &
328 file_action="READ", &
329 file_form="UNFORMATTED", &
330 file_status="OLD", &
331 unit_number=restart_unit)
332
333 END IF
334
335 CALL read_kpoints_restart_low(denmat, kpoints, fmwork(1), para_env, &
336 natom, restart_unit, natom_mismatch)
337
338 ! only the io_node returns natom_mismatch, must broadcast it
339 CALL para_env%bcast(natom_mismatch)
340
341 ! Close restart file
342 IF (para_env%is_source()) CALL close_file(unit_number=restart_unit)
343
344 CALL timestop(handle)
345
346 END SUBROUTINE read_kpoints_restart
347
348! **************************************************************************************************
349!> \brief Reading the mos from apreviously defined restart file
350!> \param denmat ...
351!> \param kpoints ...
352!> \param fmat ...
353!> \param para_env ...
354!> \param natom ...
355!> \param rst_unit ...
356!> \param natom_mismatch ...
357!> \par History
358!> 12.2007 created [MI]
359!> \author MI
360! **************************************************************************************************
361 SUBROUTINE read_kpoints_restart_low(denmat, kpoints, fmat, para_env, &
362 natom, rst_unit, natom_mismatch)
363
364 TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: denmat
365 TYPE(kpoint_type), POINTER :: kpoints
366 TYPE(cp_fm_type), INTENT(INOUT) :: fmat
367 TYPE(mp_para_env_type), POINTER :: para_env
368 INTEGER, INTENT(IN) :: natom, rst_unit
369 LOGICAL, INTENT(OUT) :: natom_mismatch
370
371 INTEGER :: ic, image, ispin, nao, nao_read, &
372 natom_read, ni, nimages, nset_max, &
373 nshell_max, nspin, nspin_read, &
374 version_read
375 INTEGER, DIMENSION(3) :: cell
376 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
377 LOGICAL :: natom_match
378
379 cpassert(ASSOCIATED(denmat))
380 CALL dbcsr_get_info(denmat(1, 1)%matrix, nfullrows_total=nao)
381
382 nspin = SIZE(denmat, 1)
383 nimages = SIZE(denmat, 2)
384 NULLIFY (cell_to_index)
385 IF (nimages > 1) THEN
386 CALL get_kpoint_info(kpoint=kpoints, cell_to_index=cell_to_index)
387 END IF
388
389 IF (para_env%is_source()) THEN
390 READ (rst_unit) version_read
391 IF (version_read /= version) THEN
392 CALL cp_abort(__location__, &
393 " READ RESTART : Version of restart file not supported")
394 END IF
395 READ (rst_unit) natom_read, nao_read, nset_max, nshell_max
396 natom_match = (natom_read == natom)
397 IF (natom_match) THEN
398 IF (nao_read /= nao) THEN
399 CALL cp_abort(__location__, &
400 " READ RESTART : Different number of basis functions")
401 END IF
402 READ (rst_unit)
403 READ (rst_unit)
404 READ (rst_unit)
405 END IF
406 END IF
407
408 ! make natom_match and natom_mismatch uniform across all nodes
409 CALL para_env%bcast(natom_match)
410 natom_mismatch = .NOT. natom_match
411 ! handle natom_match false
412 IF (natom_mismatch) THEN
413 CALL cp_warn(__location__, &
414 " READ RESTART : WARNING : DIFFERENT natom, returning ")
415 ELSE
416
417 DO
418 ispin = 0
419 IF (para_env%is_source()) THEN
420 READ (rst_unit) ispin, nspin_read, ni
421 END IF
422 CALL para_env%bcast(ispin)
423 CALL para_env%bcast(nspin_read)
424 CALL para_env%bcast(ni)
425 IF (nspin_read /= nspin) THEN
426 CALL cp_abort(__location__, &
427 " READ RESTART : Different spin polarisation not supported")
428 END IF
429 DO ic = 1, ni
430 IF (para_env%is_source()) THEN
431 READ (rst_unit) image, cell
432 END IF
433 CALL para_env%bcast(image)
434 CALL para_env%bcast(cell)
435 !
436 CALL cp_fm_read_unformatted(fmat, rst_unit)
437 !
438 IF (nimages > 1) THEN
439 image = get_index(cell, cell_to_index)
440 ELSE IF (sum(abs(cell(:))) == 0) THEN
441 image = 1
442 ELSE
443 image = 0
444 END IF
445 IF (image >= 1 .AND. image <= nimages) THEN
446 CALL copy_fm_to_dbcsr(fmat, denmat(ispin, image)%matrix)
447 END IF
448 END DO
449 IF (ispin == nspin_read) EXIT
450 END DO
451
452 END IF
453
454 END SUBROUTINE read_kpoints_restart_low
455
456! **************************************************************************************************
457!> \brief ...
458!> \param cell ...
459!> \param cell_to_index ...
460!> \return ...
461! **************************************************************************************************
462 FUNCTION get_index(cell, cell_to_index) RESULT(index)
463 INTEGER, DIMENSION(3), INTENT(IN) :: cell
464 INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
465 INTEGER :: index
466
467 IF (cell(1) >= lbound(cell_to_index, 1) .AND. cell(1) <= ubound(cell_to_index, 1) .AND. &
468 cell(2) >= lbound(cell_to_index, 2) .AND. cell(2) <= ubound(cell_to_index, 2) .AND. &
469 cell(3) >= lbound(cell_to_index, 3) .AND. cell(3) <= ubound(cell_to_index, 3)) THEN
470
471 index = cell_to_index(cell(1), cell(2), cell(3))
472
473 ELSE
474
475 index = 0
476
477 END IF
478
479 END FUNCTION get_index
480
481END MODULE kpoint_io
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_gto_basis_set(gto_basis_set, name, aliases, norm_type, kind_radius, ncgf, nset, nsgf, cgf_symbol, sgf_symbol, norm_cgf, set_radius, lmax, lmin, lx, ly, lz, m, ncgf_set, npgf, nsgf_set, nshell, cphi, pgf_radius, sphi, scon, zet, first_cgf, first_sgf, l, last_cgf, last_sgf, n, gcc, maxco, maxl, maxpgf, maxsgf_set, maxshell, maxso, nco_sum, npgf_sum, nshell_sum, maxder, short_kind_radius)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Utility routines to open and close files. Tracking of preconnections.
Definition cp_files.F:16
subroutine, public open_file(file_name, file_status, file_form, file_action, file_position, file_pad, unit_number, debug, skip_get_unit_number, file_access)
Opens the requested file using a free unit number.
Definition cp_files.F:308
subroutine, public close_file(unit_number, file_status, keep_preconnection)
Close an open file given by its logical unit number. Optionally, keep the file and unit preconnected.
Definition cp_files.F:119
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
subroutine, public cp_fm_write_unformatted(fm, unit)
...
subroutine, public cp_fm_read_unformatted(fm, unit)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
integer, parameter, public cp_p_file
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
objects that represent the structure of input sections and the data contained in an input section
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public default_path_length
Definition kinds.F:58
Restart file for k point calculations.
Definition kpoint_io.F:13
subroutine, public read_kpoints_restart(denmat, kpoints, fmwork, natom, para_env, id_nr, dft_section, natom_mismatch)
...
Definition kpoint_io.F:297
subroutine, public write_kpoints_restart(denmat, kpoints, scf_env, dft_section, particle_set, qs_kind_set)
...
Definition kpoint_io.F:75
Types and basic routines needed for a kpoint calculation.
subroutine, public get_kpoint_info(kpoint, kp_scheme, nkp_grid, kp_shift, symmetry, verbose, full_grid, use_real_wfn, eps_geo, parallel_group_size, kp_range, nkp, xkp, wkp, para_env, blacs_env_all, para_env_kp, para_env_inter_kp, blacs_env, kp_env, kp_aux_env, mpools, iogrp, nkp_groups, kp_dist, cell_to_index, index_to_cell, sab_nl, sab_nl_nosym)
Retrieve information from a kpoint environment.
Interface to the message passing library MPI.
Provides Cartesian and spherical orbital pointers and indices.
integer, dimension(:), allocatable, public nso
Define the data structure for the particle information.
Definition of the DFTB parameter types.
Working with the DFTB parameter types.
subroutine, public get_dftb_atom_param(dftb_parameter, name, typ, defined, z, zeff, natorb, lmax, skself, occupation, eta, energy, cutoff, xi, di, rcdisp, dudq)
...
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_r3d_rs_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, floating, name, element_symbol, pao_basis_size, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
Definition and initialisation of the mo data type.
Definition qs_mo_io.F:21
subroutine, public wfn_restart_file_name(filename, exist, section, logger, kp, xas, rtp)
...
Definition qs_mo_io.F:428
module that contains the definitions of the scf types
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
Contains information about kpoints.
stores all the informations relevant to an mpi environment
Provides all information about a quickstep kind.