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