(git:c641773)
Loading...
Searching...
No Matches
input_cp2k_binary_restarts.F
Go to the documentation of this file.
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 Routines to read the binary restart file of CP2K
10!> \author Matthias Krack (MK)
11!> \par History
12!> - Creation (17.02.2011,MK)
13!> \version 1.0
14! **************************************************************************************************
16
19 USE cp_files, ONLY: open_file
29 USE kinds, ONLY: default_path_length,&
31 dp
34 USE physcon, ONLY: angstrom
36 USE string_table, ONLY: id2str,&
37 s2s,&
38 str2id
41#include "./base/base_uses.f90"
42
43 IMPLICIT NONE
44
45 PRIVATE
46
47 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'input_cp2k_binary_restarts'
48
49 PUBLIC :: read_binary_coordinates, &
53
54CONTAINS
55
56! **************************************************************************************************
57!> \brief Read the input section &COORD from an external file written in
58!> binary format.
59!> \param topology ...
60!> \param root_section ...
61!> \param para_env ...
62!> \param subsys_section ...
63!> \param binary_file_read ...
64!> \par History
65!> - Creation (10.02.2011,MK)
66!> \author Matthias Krack (MK)
67!> \version 1.0
68! **************************************************************************************************
69 SUBROUTINE read_binary_coordinates(topology, root_section, para_env, &
70 subsys_section, binary_file_read)
71
73 TYPE(section_vals_type), POINTER :: root_section
74 TYPE(mp_para_env_type), POINTER :: para_env
75 TYPE(section_vals_type), POINTER :: subsys_section
76 LOGICAL, INTENT(OUT) :: binary_file_read
77
78 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_binary_coordinates'
79
80 CHARACTER(LEN=default_path_length) :: binary_restart_file_name
81 CHARACTER(LEN=default_string_length) :: string
82 INTEGER :: binary_restart_file_unit, handle, iatom, &
83 ikind, istat, iw, natom, natomkind, &
84 ncore, nmolecule, nmoleculekind, nshell
85 INTEGER, ALLOCATABLE, DIMENSION(:) :: ibuf, id_name
86 TYPE(atom_info_type), POINTER :: atom_info
87 TYPE(cp_logger_type), POINTER :: logger
88
89 CALL timeset(routinen, handle)
90
91 NULLIFY (logger)
92 cpassert(ASSOCIATED(root_section))
93 cpassert(ASSOCIATED(para_env))
94 cpassert(ASSOCIATED(subsys_section))
95 logger => cp_get_default_logger()
96
97 binary_file_read = .false.
98
99 CALL section_vals_val_get(root_section, "EXT_RESTART%BINARY_RESTART_FILE_NAME", &
100 c_val=binary_restart_file_name)
101
102 IF (trim(adjustl(binary_restart_file_name)) == "") THEN
103 CALL timestop(handle)
104 RETURN
105 END IF
106
107 iw = cp_print_key_unit_nr(logger, subsys_section, "PRINT%TOPOLOGY_INFO/XYZ_INFO", &
108 extension=".subsysLog")
109
110 natomkind = 0
111 natom = 0
112 ncore = 0
113 nshell = 0
114 nmoleculekind = 0
115 nmolecule = 0
116
117 ! Open binary restart file and read number atomic kinds, atoms, etc.
118 IF (para_env%is_source()) THEN
119 CALL open_file(file_name=binary_restart_file_name, &
120 file_status="OLD", &
121 file_form="UNFORMATTED", &
122 file_action="READWRITE", &
123 file_position="REWIND", &
124 unit_number=binary_restart_file_unit, &
125 debug=(iw > 0))
126 READ (unit=binary_restart_file_unit, iostat=istat) &
127 natomkind, natom, ncore, nshell, nmoleculekind, nmolecule
128 IF (istat /= 0) THEN
129 CALL stop_read("natomkind,natom,ncore,nshell,nmoleculekind,nmolecule "// &
130 "(IOSTAT = "//trim(adjustl(cp_to_string(istat)))//")", &
131 binary_restart_file_unit)
132 END IF
133 IF (iw > 0) THEN
134 WRITE (unit=iw, fmt="(T2,A,T71,I10)") &
135 "Number of atomic kinds:", natomkind, &
136 "Number of atoms:", natom, &
137 "Number of cores (only core-shell model):", ncore, &
138 "Number of shells (only core-shell model):", nshell, &
139 "Number of molecule kinds:", nmoleculekind, &
140 "Number of molecules", nmolecule
141 END IF
142 END IF
143
144 CALL para_env%bcast(natomkind)
145 CALL para_env%bcast(natom)
146 CALL para_env%bcast(ncore)
147 CALL para_env%bcast(nshell)
148 CALL para_env%bcast(nmoleculekind)
149 CALL para_env%bcast(nmolecule)
150
151 ALLOCATE (id_name(natomkind))
152 ! Read atomic kind names
153 DO ikind = 1, natomkind
154 IF (para_env%is_source()) THEN
155 READ (unit=binary_restart_file_unit, iostat=istat) string
156 IF (istat /= 0) CALL stop_read("string (IOSTAT = "// &
157 trim(adjustl(cp_to_string(istat)))//")", &
158 binary_restart_file_unit)
159 END IF
160 CALL para_env%bcast(string)
161 id_name(ikind) = str2id(string)
162 END DO
163
164 ! Allocate and initialise atom_info array
165 atom_info => topology%atom_info
166 ALLOCATE (atom_info%id_molname(natom))
167 atom_info%id_molname(:) = 0
168 ALLOCATE (atom_info%id_resname(natom))
169 atom_info%id_resname(:) = 0
170 ALLOCATE (atom_info%resid(natom))
171 atom_info%resid = 1
172 ALLOCATE (atom_info%id_atmname(natom))
173 atom_info%id_atmname = 0
174 ALLOCATE (atom_info%r(3, natom))
175 atom_info%r(:, :) = 0.0_dp
176 ALLOCATE (atom_info%atm_mass(natom))
177 atom_info%atm_mass(:) = huge(0.0_dp)
178 ALLOCATE (atom_info%atm_charge(natom))
179 atom_info%atm_charge(:) = -huge(0.0_dp)
180 ALLOCATE (atom_info%occup(natom))
181 atom_info%occup(:) = 0.0_dp
182 ALLOCATE (atom_info%beta(natom))
183 atom_info%beta(:) = 0.0_dp
184 ALLOCATE (atom_info%id_element(natom))
185 atom_info%id_element(:) = 0
186 ALLOCATE (ibuf(natom))
187
188 ! Read atomic kind number of each atom
189 IF (para_env%is_source()) THEN
190 READ (unit=binary_restart_file_unit, iostat=istat) ibuf(1:natom)
191 IF (istat /= 0) CALL stop_read("ibuf (IOSTAT = "// &
192 trim(adjustl(cp_to_string(istat)))//")", &
193 binary_restart_file_unit)
194 END IF
195 CALL para_env%bcast(ibuf)
196 DO iatom = 1, natom
197 ikind = ibuf(iatom)
198 atom_info%id_atmname(iatom) = id_name(ikind)
199 atom_info%id_element(iatom) = id_name(ikind)
200 END DO
201 DEALLOCATE (id_name)
202
203 ! Read atomic coordinates
204 IF (para_env%is_source()) THEN
205 READ (unit=binary_restart_file_unit, iostat=istat) atom_info%r(1:3, 1:natom)
206 IF (istat /= 0) CALL stop_read("atom_info%r(1:3,1:natom) (IOSTAT = "// &
207 trim(adjustl(cp_to_string(istat)))//")", &
208 binary_restart_file_unit)
209 END IF
210 CALL para_env%bcast(atom_info%r)
211 IF (ASSOCIATED(topology%cell_muc)) THEN
212 DO iatom = 1, natom
213 CALL cell_transform_input_cartesian(topology%cell_muc, atom_info%r(:, iatom))
214 END DO
215 END IF
216
217 ! Read molecule information if available
218 IF (nmolecule > 0) THEN
219 ALLOCATE (id_name(nmoleculekind))
220 ! Read molecule kind names
221 DO ikind = 1, nmoleculekind
222 IF (para_env%is_source()) THEN
223 READ (unit=binary_restart_file_unit, iostat=istat) string
224 IF (istat /= 0) CALL stop_read("string (IOSTAT = "// &
225 trim(adjustl(cp_to_string(istat)))//")", &
226 binary_restart_file_unit)
227 END IF
228 CALL para_env%bcast(string)
229 id_name(ikind) = str2id(string)
230 END DO
231 ! Read molecule kind numbers
232 IF (para_env%is_source()) THEN
233 READ (unit=binary_restart_file_unit, iostat=istat) ibuf(1:natom)
234 IF (istat /= 0) CALL stop_read("ibuf(1:natom) (IOSTAT = "// &
235 trim(adjustl(cp_to_string(istat)))//")", &
236 binary_restart_file_unit)
237 END IF
238 CALL para_env%bcast(ibuf)
239 DO iatom = 1, natom
240 ikind = ibuf(iatom)
241 atom_info%id_molname(iatom) = id_name(ikind)
242 END DO
243 DEALLOCATE (id_name)
244 ! Read molecule index which is used also as residue id
245 IF (para_env%is_source()) THEN
246 READ (unit=binary_restart_file_unit, iostat=istat) atom_info%resid(1:natom)
247 IF (istat /= 0) CALL stop_read("atom_info%resid(1:natom) (IOSTAT = "// &
248 trim(adjustl(cp_to_string(istat)))//")", &
249 binary_restart_file_unit)
250 END IF
251 CALL para_env%bcast(atom_info%resid)
252 DO iatom = 1, natom
253 atom_info%id_resname(iatom) = str2id(s2s(cp_to_string(atom_info%resid(iatom))))
254 END DO
255 END IF
256 DEALLOCATE (ibuf)
257
258 !MK to be checked ...
259 topology%aa_element = .true.
260 topology%molname_generated = .false.
261 topology%natoms = natom
262
263 IF (iw > 0) THEN
264 WRITE (unit=iw, fmt="(T2,A)") &
265 "BEGIN of COORD section data [Angstrom] read in binary format from file "// &
266 trim(binary_restart_file_name)
267 DO iatom = 1, natom
268 WRITE (unit=iw, fmt="(T2,A2,3(1X,ES25.16),2(1X,A))") &
269 trim(adjustl(id2str(atom_info%id_atmname(iatom)))), &
270 atom_info%r(1:3, iatom)*angstrom, &
271 trim(adjustl(id2str(atom_info%id_molname(iatom)))), &
272 trim(adjustl(id2str(atom_info%id_resname(iatom))))
273 END DO
274 WRITE (unit=iw, fmt="(T2,A)") &
275 "END of COORD section data [Angstrom] read from binary restart file "// &
276 trim(binary_restart_file_name)
277 END IF
278
279 ! Keep the file connected: the next reader continues at the current position
280
281 binary_file_read = .true.
282
283 CALL timestop(handle)
284
285 END SUBROUTINE read_binary_coordinates
286
287! **************************************************************************************************
288!> \brief Read the input section &CORE_COORD or &SHELL_COORD from an external
289!> file written in binary format.
290!> \param prefix ...
291!> \param particle_set ...
292!> \param root_section ...
293!> \param subsys_section ...
294!> \param binary_file_read ...
295!> \param cell ...
296!> \par History
297!> - Creation (17.02.2011,MK)
298!> \author Matthias Krack (MK)
299!> \version 1.0
300! **************************************************************************************************
301 SUBROUTINE read_binary_cs_coordinates(prefix, particle_set, root_section, &
302 subsys_section, binary_file_read, cell)
303
304 CHARACTER(LEN=*), INTENT(IN) :: prefix
305 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
306 TYPE(section_vals_type), POINTER :: root_section, subsys_section
307 LOGICAL, INTENT(OUT) :: binary_file_read
308 TYPE(cell_type), OPTIONAL, POINTER :: cell
309
310 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_binary_cs_coordinates'
311
312 CHARACTER(LEN=default_path_length) :: binary_restart_file_name, message
313 CHARACTER(LEN=default_string_length) :: section_label, section_name
314 INTEGER :: binary_restart_file_unit, handle, &
315 iparticle, istat, iw, nbuf, nparticle
316 INTEGER, ALLOCATABLE, DIMENSION(:) :: ibuf
317 LOGICAL :: exit_routine
318 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: rbuf
319 TYPE(cp_logger_type), POINTER :: logger
320 TYPE(mp_para_env_type), POINTER :: para_env
321
322 CALL timeset(routinen, handle)
323
324 NULLIFY (logger)
325 cpassert(ASSOCIATED(root_section))
326 cpassert(ASSOCIATED(subsys_section))
327 logger => cp_get_default_logger()
328 para_env => logger%para_env
329
330 binary_file_read = .false.
331
332 IF (ASSOCIATED(particle_set)) THEN
333 exit_routine = .false.
334 nparticle = SIZE(particle_set)
335 ELSE
336 exit_routine = .true.
337 nparticle = 0
338 END IF
339
340 CALL section_vals_val_get(root_section, "EXT_RESTART%BINARY_RESTART_FILE_NAME", &
341 c_val=binary_restart_file_name)
342
343 IF (trim(adjustl(binary_restart_file_name)) == "") THEN
344 CALL timestop(handle)
345 RETURN
346 END IF
347
348 iw = cp_print_key_unit_nr(logger, subsys_section, "PRINT%TOPOLOGY_INFO/XYZ_INFO", &
349 extension=".subsysLog")
350
351 section_name = prefix//" COORDINATES"
352
353 ! Open binary restart file at last position
354 IF (para_env%is_source()) THEN
355 CALL open_file(file_name=trim(binary_restart_file_name), &
356 file_status="OLD", &
357 file_form="UNFORMATTED", &
358 file_action="READWRITE", &
359 file_position="ASIS", &
360 unit_number=binary_restart_file_unit, &
361 debug=(iw > 0))
362 READ (unit=binary_restart_file_unit, iostat=istat) section_label, nbuf
363 IF (istat /= 0) CALL stop_read("section_label, nbuf -> "//trim(section_label)//", "// &
364 trim(adjustl(cp_to_string(nbuf)))// &
365 " (IOSTAT = "//trim(adjustl(cp_to_string(istat)))//"). "// &
366 "Section "//trim(adjustl(section_name))//" was expected.", &
367 binary_restart_file_unit)
368 IF (trim(section_label) == trim(section_name)) THEN
369 IF (nbuf /= nparticle) THEN
370 IF (iw > 0) THEN
371 message = "INFO: The requested number of "//trim(section_name)//" ("// &
372 trim(adjustl(cp_to_string(nparticle)))//") does not match the "// &
373 "number ("//trim(adjustl(cp_to_string(nbuf)))//") available from the "// &
374 "binary restart file <"//trim(binary_restart_file_name)// &
375 ">. The restart file information is ignored."
376 CALL print_message(message, iw, 1, 1, 1)
377 END IF
378 ! Ignore this section
379 IF (nbuf > 0) THEN
380 ! Perform dummy read
381 ALLOCATE (rbuf(3, nbuf))
382 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:3, 1:nbuf)
383 IF (istat /= 0) CALL stop_read("rbuf(1:3,1:nbuf) -> "//prefix// &
384 " coordinates (IOSTAT = "// &
385 trim(adjustl(cp_to_string(istat)))//")", &
386 binary_restart_file_unit)
387 DEALLOCATE (rbuf)
388 ALLOCATE (ibuf(nbuf))
389 READ (unit=binary_restart_file_unit, iostat=istat) ibuf(1:nbuf)
390 IF (istat /= 0) CALL stop_read("ibuf(1:nparticle) -> atomic indices of the "// &
391 trim(section_name)//" (IOSTAT = "// &
392 trim(adjustl(cp_to_string(istat)))//")", &
393 binary_restart_file_unit)
394 DEALLOCATE (ibuf)
395 END IF
396 exit_routine = .true.
397 ELSE
398 IF (iw > 0) THEN
399 WRITE (unit=iw, fmt="(T2,A,T71,I10)") &
400 "Number of "//prefix//" particles:", nparticle
401 END IF
402 IF (nparticle == 0) exit_routine = .true.
403 END IF
404 ELSE
405 CALL cp_abort(__location__, &
406 "Section label <"//trim(section_label)//"> read from the "// &
407 "binary restart file <"//trim(binary_restart_file_name)// &
408 "> does not match the requested section name <"// &
409 trim(section_name)//">.")
410 END IF
411 END IF
412
413 CALL para_env%bcast(exit_routine)
414 IF (exit_routine) THEN
415 ! Keep the file connected: the next reader continues at the current position
416 CALL timestop(handle)
417 RETURN
418 END IF
419
420 cpassert(nparticle > 0)
421
422 ALLOCATE (rbuf(3, nparticle))
423
424 IF (para_env%is_source()) THEN
425 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:3, 1:nparticle)
426 IF (istat /= 0) CALL stop_read("rbuf(1:3,1:nparticle) -> "//prefix// &
427 " coordinates (IOSTAT = "// &
428 trim(adjustl(cp_to_string(istat)))//")", &
429 binary_restart_file_unit)
430 END IF
431 CALL para_env%bcast(rbuf)
432
433 DO iparticle = 1, nparticle
434 particle_set(iparticle)%r(1:3) = rbuf(1:3, iparticle)
435 IF (PRESENT(cell)) THEN
436 IF (ASSOCIATED(cell)) CALL cell_transform_input_cartesian(cell, particle_set(iparticle)%r(1:3))
437 END IF
438 END DO
439
440 DEALLOCATE (rbuf)
441
442 ALLOCATE (ibuf(nparticle))
443
444 IF (para_env%is_source()) THEN
445 READ (unit=binary_restart_file_unit, iostat=istat) ibuf(1:nparticle)
446 IF (istat /= 0) CALL stop_read("ibuf(1:nparticle) -> atomic indices of the "// &
447 trim(section_name)//" (IOSTAT = "// &
448 trim(adjustl(cp_to_string(istat)))//")", &
449 binary_restart_file_unit)
450 END IF
451
452 CALL para_env%bcast(ibuf)
453
454 DO iparticle = 1, nparticle
455 particle_set(iparticle)%atom_index = ibuf(iparticle)
456 END DO
457
458 DEALLOCATE (ibuf)
459
460 IF (iw > 0) THEN
461 WRITE (unit=iw, fmt="(T2,A)") &
462 "BEGIN of "//trim(adjustl(section_name))// &
463 " section data [Angstrom] read in binary format from file "// &
464 trim(binary_restart_file_name)
465 DO iparticle = 1, nparticle
466 WRITE (unit=iw, fmt="(T2,A2,3(1X,ES25.16),1X,I0)") &
467 trim(adjustl(particle_set(iparticle)%atomic_kind%name)), &
468 particle_set(iparticle)%r(1:3)*angstrom, &
469 particle_set(iparticle)%atom_index
470 END DO
471 WRITE (unit=iw, fmt="(T2,A)") &
472 "END of "//trim(adjustl(section_name))// &
473 " section data [Angstrom] read from binary restart file "// &
474 trim(binary_restart_file_name)
475 END IF
476
477 ! Keep the file connected: the next reader continues at the current position
478
479 binary_file_read = .true.
480
481 CALL timestop(handle)
482
483 END SUBROUTINE read_binary_cs_coordinates
484
485! **************************************************************************************************
486!> \brief Read the input section &VELOCITY, &CORE_VELOCITY, or
487!> &SHELL_VELOCITY from an external file written in binary format.
488!> \param prefix ...
489!> \param particle_set ...
490!> \param root_section ...
491!> \param para_env ...
492!> \param subsys_section ...
493!> \param binary_file_read ...
494!> \param cell ...
495!> \par History
496!> - Creation (17.02.2011,MK)
497!> \author Matthias Krack (MK)
498!> \version 1.0
499! **************************************************************************************************
500 SUBROUTINE read_binary_velocities(prefix, particle_set, root_section, para_env, &
501 subsys_section, binary_file_read, cell)
502
503 CHARACTER(LEN=*), INTENT(IN) :: prefix
504 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
505 TYPE(section_vals_type), POINTER :: root_section
506 TYPE(mp_para_env_type), POINTER :: para_env
507 TYPE(section_vals_type), POINTER :: subsys_section
508 LOGICAL, INTENT(OUT) :: binary_file_read
509 TYPE(cell_type), OPTIONAL, POINTER :: cell
510
511 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_binary_velocities'
512
513 CHARACTER(LEN=default_path_length) :: binary_restart_file_name, message
514 CHARACTER(LEN=default_string_length) :: section_label, section_name
515 INTEGER :: binary_restart_file_unit, handle, i, &
516 iparticle, istat, iw, nbuf, nparticle
517 LOGICAL :: have_velocities
518 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: rbuf
519 TYPE(cp_logger_type), POINTER :: logger
520
521 CALL timeset(routinen, handle)
522
523 NULLIFY (logger)
524 cpassert(ASSOCIATED(root_section))
525 cpassert(ASSOCIATED(para_env))
526 cpassert(ASSOCIATED(subsys_section))
527 logger => cp_get_default_logger()
528
529 binary_file_read = .false.
530
531 CALL section_vals_val_get(root_section, "EXT_RESTART%BINARY_RESTART_FILE_NAME", &
532 c_val=binary_restart_file_name)
533
534 IF (trim(adjustl(binary_restart_file_name)) == "") THEN
535 CALL timestop(handle)
536 RETURN
537 END IF
538
539 iw = cp_print_key_unit_nr(logger, subsys_section, "PRINT%TOPOLOGY_INFO/XYZ_INFO", &
540 extension=".subsysLog")
541
542 IF (len_trim(prefix) == 0) THEN
543 section_name = "VELOCITIES"
544 ELSE
545 section_name = prefix//" VELOCITIES"
546 END IF
547
548 have_velocities = .false.
549
550 IF (ASSOCIATED(particle_set)) THEN
551 nparticle = SIZE(particle_set)
552 ELSE
553 nparticle = 0
554 END IF
555
556 ! Open binary restart file at last position and check if there are
557 ! velocities available
558 IF (para_env%is_source()) THEN
559 CALL open_file(file_name=binary_restart_file_name, &
560 file_status="OLD", &
561 file_form="UNFORMATTED", &
562 file_action="READWRITE", &
563 file_position="ASIS", &
564 unit_number=binary_restart_file_unit, &
565 debug=(iw > 0))
566 DO
567 READ (unit=binary_restart_file_unit, iostat=istat) section_label, nbuf
568 IF (istat /= 0) CALL stop_read("section_label, nbuf -> "//trim(section_label)//", "// &
569 trim(adjustl(cp_to_string(nbuf)))// &
570 " (IOSTAT = "//trim(adjustl(cp_to_string(istat)))//"). "// &
571 "Section "//trim(adjustl(section_name))//" was expected.", &
572 binary_restart_file_unit)
573 IF (index(section_label, "THERMOSTAT") > 0) THEN
574 IF (nbuf > 0) THEN
575 ! Ignore thermostat information
576 ALLOCATE (rbuf(nbuf, 1))
577 ! Perform dummy read
578 DO i = 1, 4
579 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:nbuf, 1)
580 IF (istat /= 0) CALL stop_read("rbuf(1:nbuf,1) -> "// &
581 trim(adjustl(section_label))// &
582 " (IOSTAT = "//trim(adjustl(cp_to_string(istat)))//")", &
583 binary_restart_file_unit)
584 END DO
585 DEALLOCATE (rbuf)
586 IF (iw > 0) THEN
587 message = "INFO: Ignoring section <"//trim(adjustl(section_label))// &
588 "> from binary restart file <"//trim(binary_restart_file_name)//">."
589 CALL print_message(message, iw, 1, 1, 1)
590 END IF
591 END IF
592 cycle
593 ELSE IF (index(section_label, "VELOCIT") == 0) THEN
594 CALL cp_abort(__location__, &
595 "Section label <"//trim(section_label)//"> read from the "// &
596 "binary restart file <"//trim(binary_restart_file_name)// &
597 "> does not match the requested section name <"// &
598 trim(section_name)//">.")
599 ELSE
600 IF (nbuf > 0) have_velocities = .true.
601 EXIT
602 END IF
603 END DO
604 END IF
605
606 CALL para_env%bcast(nbuf)
607 CALL para_env%bcast(have_velocities)
608
609 IF (have_velocities) THEN
610
611 ALLOCATE (rbuf(3, nbuf))
612
613 IF (para_env%is_source()) THEN
614 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:3, 1:nbuf)
615 IF (istat /= 0) CALL stop_read("rbuf(1:3,1:nbuf) -> "// &
616 trim(adjustl(section_name))// &
617 " (IOSTAT = "//trim(adjustl(cp_to_string(istat)))//")", &
618 binary_restart_file_unit)
619 END IF
620
621 IF (nbuf == nparticle) THEN
622 CALL para_env%bcast(rbuf)
623 DO iparticle = 1, nparticle
624 particle_set(iparticle)%v(1:3) = rbuf(1:3, iparticle)
625 IF (PRESENT(cell)) THEN
626 IF (ASSOCIATED(cell)) CALL cell_transform_input_cartesian(cell, particle_set(iparticle)%v(1:3))
627 END IF
628 END DO
629 ELSE
630 IF (iw > 0) THEN
631 message = "INFO: The requested number of "//trim(adjustl(section_name))// &
632 " ("//trim(adjustl(cp_to_string(nparticle)))//") does not match the "// &
633 "number ("//trim(adjustl(cp_to_string(nbuf)))//") available from the "// &
634 "binary restart file <"//trim(binary_restart_file_name)// &
635 ">. The restart file information is ignored."
636 CALL print_message(message, iw, 1, 1, 1)
637 END IF
638 END IF
639
640 DEALLOCATE (rbuf)
641
642 END IF
643
644 IF (nbuf == nparticle) THEN
645 IF (iw > 0) THEN
646 WRITE (unit=iw, fmt="(T2,A)") &
647 "BEGIN of "//trim(adjustl(section_name))// &
648 " section data [a.u.] read in binary format from file "// &
649 trim(binary_restart_file_name)
650 IF (have_velocities) THEN
651 DO iparticle = 1, nparticle
652 WRITE (unit=iw, fmt="(T2,A2,3(1X,ES25.16))") &
653 trim(adjustl(particle_set(iparticle)%atomic_kind%name)), &
654 particle_set(iparticle)%v(1:3)
655 END DO
656 ELSE
657 WRITE (unit=iw, fmt="(A)") &
658 "# No "//trim(adjustl(section_name))//" available"
659 END IF
660 WRITE (unit=iw, fmt="(T2,A)") &
661 "END of "//trim(adjustl(section_name))// &
662 " section data [a.u.] read from binary restart file "// &
663 trim(binary_restart_file_name)
664 END IF
665 binary_file_read = .true.
666 END IF
667
668 ! Keep the file connected: the next reader continues at the current position
669
670 CALL timestop(handle)
671
672 END SUBROUTINE read_binary_velocities
673
674! **************************************************************************************************
675!> \brief Read the input section &THERMOSTAT for Nose thermostats from an
676!> external file written in binary format.
677!> \param prefix ...
678!> \param nhc ...
679!> \param binary_restart_file_name ...
680!> \param restart ...
681!> \param para_env ...
682!> \par History
683!> - Creation (28.02.2011,MK)
684!> \author Matthias Krack (MK)
685!> \version 1.0
686! **************************************************************************************************
687 SUBROUTINE read_binary_thermostats_nose(prefix, nhc, binary_restart_file_name, &
688 restart, para_env)
689
690 CHARACTER(LEN=*), INTENT(IN) :: prefix
691 TYPE(lnhc_parameters_type), POINTER :: nhc
692 CHARACTER(LEN=*), INTENT(IN) :: binary_restart_file_name
693 LOGICAL, INTENT(OUT) :: restart
694 TYPE(mp_para_env_type), POINTER :: para_env
695
696 CHARACTER(LEN=*), PARAMETER :: routinen = 'read_binary_thermostats_nose'
697
698 CHARACTER(LEN=default_string_length) :: section_label, section_name
699 INTEGER :: binary_restart_file_unit, handle, i, &
700 idx, istat, j, nhc_size, output_unit
701 LOGICAL :: debug
702 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: rbuf
703 TYPE(cp_logger_type), POINTER :: logger
704
705 CALL timeset(routinen, handle)
706
707 cpassert(ASSOCIATED(nhc))
708 cpassert(ASSOCIATED(para_env))
709
710 ! Set to .TRUE. for debug mode, i.e. all data read are written to stdout
711 NULLIFY (logger)
712 logger => cp_get_default_logger()
713 output_unit = cp_logger_get_default_io_unit(logger)
714
715 IF (logger%iter_info%print_level >= debug_print_level) THEN
716 debug = .true.
717 ELSE
718 debug = .false.
719 END IF
720
721 restart = .false.
722
723 section_name = prefix//" THERMOSTATS"
724
725 ! Open binary restart file at last position
726 IF (para_env%is_source()) THEN
727 CALL open_file(file_name=binary_restart_file_name, &
728 file_status="OLD", &
729 file_form="UNFORMATTED", &
730 file_action="READWRITE", &
731 file_position="ASIS", &
732 unit_number=binary_restart_file_unit, &
733 debug=debug)
734 READ (unit=binary_restart_file_unit, iostat=istat) section_label, nhc_size
735 IF (istat /= 0) CALL stop_read("nhc_size (IOSTAT = "// &
736 trim(adjustl(cp_to_string(istat)))//")", &
737 binary_restart_file_unit)
738 IF (index(section_label, "THERMOSTAT") == 0) THEN
739 CALL cp_abort(__location__, &
740 "Section label <"//trim(section_label)//"> read from the "// &
741 "binary restart file <"//trim(binary_restart_file_name)// &
742 "> does not match the requested section name <"// &
743 trim(section_name)//">.")
744 END IF
745 IF (debug .AND. output_unit > 0) THEN
746 WRITE (unit=output_unit, fmt="(T2,A,/,T2,A,I0)") &
747 "BEGIN of "//trim(adjustl(section_label))// &
748 " section data read in binary format from file "// &
749 trim(binary_restart_file_name), &
750 "# nhc_size = ", nhc_size
751 END IF
752 END IF
753
754 CALL para_env%bcast(nhc_size)
755
756 IF (nhc_size > 0) THEN
757
758 ALLOCATE (rbuf(nhc_size))
759 rbuf(:) = 0.0_dp
760
761 ! Read NHC section &COORD
762 IF (para_env%is_source()) THEN
763 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:nhc_size)
764 IF (istat /= 0) CALL stop_read("eta -> rbuf (IOSTAT = "// &
765 trim(adjustl(cp_to_string(istat)))//")", &
766 binary_restart_file_unit)
767 IF (debug .AND. output_unit > 0) THEN
768 WRITE (unit=output_unit, fmt="(T2,A,/,(4(1X,ES25.16)))") &
769 "&COORD", rbuf(1:nhc_size)
770 END IF
771 END IF
772 CALL para_env%bcast(rbuf)
773 DO i = 1, SIZE(nhc%nvt, 2)
774 idx = (nhc%map_info%index(i) - 1)*nhc%nhc_len
775 DO j = 1, SIZE(nhc%nvt, 1)
776 idx = idx + 1
777 nhc%nvt(j, i)%eta = rbuf(idx)
778 END DO
779 END DO
780
781 ! Read NHC section &VELOCITY
782 IF (para_env%is_source()) THEN
783 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:nhc_size)
784 IF (istat /= 0) CALL stop_read("veta -> rbuf (IOSTAT = "// &
785 trim(adjustl(cp_to_string(istat)))//")", &
786 binary_restart_file_unit)
787 IF (debug .AND. output_unit > 0) THEN
788 WRITE (unit=output_unit, fmt="(T2,A,/,(4(1X,ES25.16)))") &
789 "&VELOCITY", rbuf(1:nhc_size)
790 END IF
791 END IF
792 CALL para_env%bcast(rbuf)
793 DO i = 1, SIZE(nhc%nvt, 2)
794 idx = (nhc%map_info%index(i) - 1)*nhc%nhc_len
795 DO j = 1, SIZE(nhc%nvt, 1)
796 idx = idx + 1
797 nhc%nvt(j, i)%v = rbuf(idx)
798 END DO
799 END DO
800
801 ! Read NHC section &MASS
802 IF (para_env%is_source()) THEN
803 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:nhc_size)
804 IF (istat /= 0) CALL stop_read("mnhc -> rbuf (IOSTAT = "// &
805 trim(adjustl(cp_to_string(istat)))//")", &
806 binary_restart_file_unit)
807 IF (debug .AND. output_unit > 0) THEN
808 WRITE (unit=output_unit, fmt="(T2,A,/,(4(1X,ES25.16)))") &
809 "&MASS:", rbuf(1:nhc_size)
810 END IF
811 END IF
812 CALL para_env%bcast(rbuf)
813 DO i = 1, SIZE(nhc%nvt, 2)
814 idx = (nhc%map_info%index(i) - 1)*nhc%nhc_len
815 DO j = 1, SIZE(nhc%nvt, 1)
816 idx = idx + 1
817 nhc%nvt(j, i)%mass = rbuf(idx)
818 END DO
819 END DO
820
821 ! Read NHC section &FORCE
822 IF (para_env%is_source()) THEN
823 READ (unit=binary_restart_file_unit, iostat=istat) rbuf(1:nhc_size)
824 IF (istat /= 0) CALL stop_read("fnhc -> rbuf (IOSTAT = "// &
825 trim(adjustl(cp_to_string(istat)))//")", &
826 binary_restart_file_unit)
827 IF (debug .AND. output_unit > 0) THEN
828 WRITE (unit=output_unit, fmt="(T2,A,/,(4(1X,ES25.16)))") &
829 "&FORCE", rbuf(1:nhc_size)
830 END IF
831 END IF
832 CALL para_env%bcast(rbuf)
833 DO i = 1, SIZE(nhc%nvt, 2)
834 idx = (nhc%map_info%index(i) - 1)*nhc%nhc_len
835 DO j = 1, SIZE(nhc%nvt, 1)
836 idx = idx + 1
837 nhc%nvt(j, i)%f = rbuf(idx)
838 END DO
839 END DO
840
841 DEALLOCATE (rbuf)
842
843 restart = .true.
844
845 END IF
846
847 IF (para_env%is_source()) THEN
848 IF (debug .AND. output_unit > 0) THEN
849 WRITE (unit=output_unit, fmt="(T2,A)") &
850 "END of"//trim(adjustl(section_label))// &
851 " section data read in binary format from file "// &
852 trim(binary_restart_file_name)
853 END IF
854 ! Keep the file connected: the next reader continues at the current position
855 END IF
856
857 CALL timestop(handle)
858
859 END SUBROUTINE read_binary_thermostats_nose
860
861! **************************************************************************************************
862!> \brief Print an error message and stop the program execution in case of a
863!> read error.
864!> \param object ...
865!> \param unit_number ...
866!> \par History
867!> - Creation (15.02.2011,MK)
868!> \author Matthias Krack (MK)
869!> \note
870!> object : Name of the data object for which I/O operation failed
871!> unit_number: Logical unit number of the file read from
872! **************************************************************************************************
873 SUBROUTINE stop_read(object, unit_number)
874 CHARACTER(LEN=*), INTENT(IN) :: object
875 INTEGER, INTENT(IN) :: unit_number
876
877 CHARACTER(LEN=2*default_path_length) :: message
878 CHARACTER(LEN=default_path_length) :: file_name
879 LOGICAL :: file_exists
880
881 IF (unit_number >= 0) THEN
882 INQUIRE (unit=unit_number, exist=file_exists)
883 ELSE
884 file_exists = .false.
885 END IF
886 IF (file_exists) THEN
887 INQUIRE (unit=unit_number, name=file_name)
888 WRITE (unit=message, fmt="(A)") &
889 "An error occurred reading data object <"//trim(adjustl(object))// &
890 "> from file <"//trim(adjustl(file_name))//">"
891 ELSE
892 WRITE (unit=message, fmt="(A,I0,A)") &
893 "Could not read data object <"//trim(adjustl(object))// &
894 "> from logical unit ", unit_number, ". The I/O unit does not exist."
895 END IF
896
897 cpabort(message)
898
899 END SUBROUTINE stop_read
900
static GRID_HOST_DEVICE int idx(const orbital a)
Return coset index of given orbital angular momentum.
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public cell_transform_input_cartesian(cell, vector)
Transform a Cartesian real-space vector from the user input cell frame into CP2K's canonical internal...
Definition cell_types.F:285
Utility routines to open and close files.
Definition cp_files.F:22
logical function, public file_exists(file_name)
Checks if a file exists, considering also the file discovery mechanism.
Definition cp_files.F:518
subroutine, public open_file(file_name, unit_number, file_status, file_form, file_action, file_position, file_pad, file_access, debug)
Opens a file and returns its logical unit number.
Definition cp_files.F:197
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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, parameter, public debug_print_level
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, file_access)
...
Lumps all possible extended system variables into one type for easy access and passing.
Routines to read the binary restart file of CP2K.
subroutine, public read_binary_thermostats_nose(prefix, nhc, binary_restart_file_name, restart, para_env)
Read the input section &THERMOSTAT for Nose thermostats from an external file written in binary forma...
subroutine, public read_binary_cs_coordinates(prefix, particle_set, root_section, subsys_section, binary_file_read, cell)
Read the input section &CORE_COORD or &SHELL_COORD from an external file written in binary format.
subroutine, public read_binary_coordinates(topology, root_section, para_env, subsys_section, binary_file_read)
Read the input section &COORD from an external file written in binary format.
subroutine, public read_binary_velocities(prefix, particle_set, root_section, para_env, subsys_section, binary_file_read, cell)
Read the input section &VELOCITY, &CORE_VELOCITY, or &SHELL_VELOCITY from an external file written in...
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Interface to the message passing library MPI.
Define the data structure for the particle information.
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public angstrom
Definition physcon.F:144
Perform an abnormal program termination.
subroutine, public print_message(message, output_unit, declev, before, after)
Perform a basic blocking of the text in message and print it optionally decorated with a frame of sta...
generates a unique id number for a string (str2id) that can be used two compare two strings....
character(len=default_string_length) function, public s2s(str)
converts a string in a string of default_string_length
integer function, public str2id(str)
returns a unique id for a given string, and stores the string for later retrieval using the id.
character(len=default_string_length) function, public id2str(id)
returns the string associated with a given id
Control for reading in different topologies and coordinates.
Definition topology.F:13
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
type of a logger, at the moment it contains just a print level starting at which level it should be l...
stores all the informations relevant to an mpi environment