34 USE iso_fortran_env,
ONLY: iostat_end
65 #include "../base/base_uses.f90"
71 CHARACTER(LEN=*),
PARAMETER :: CP2K_SHELL_VERSION =
"6.0"
74 REAL(dp) :: pos_fact = 1.0_dp
75 REAL(dp) :: e_fact = 1.0_dp
76 LOGICAL :: harsh = .false.
77 TYPE(mp_para_env_type),
POINTER :: para_env => null()
78 CHARACTER(LEN=5) :: units =
"au"
79 INTEGER :: env_id = -1
81 END TYPE cp2k_shell_type
92 TYPE(section_type),
POINTER :: input_declaration
94 CHARACTER(LEN=default_path_length) :: arg1, arg2, cmd
95 TYPE(cp2k_shell_type) :: shell
96 TYPE(cp_logger_type),
POINTER :: logger
99 shell%para_env => logger%para_env
108 CALL help_command(shell)
109 CASE (
'INFO',
'INFORMATION',
'LICENSE')
110 CALL info_license_command(shell)
112 CALL version_command(shell)
114 CALL write_file_command(shell)
116 CALL get_last_env_id(shell)
117 CASE (
'BG_LOAD',
'BGLOAD')
118 CALL bg_load_command(shell, input_declaration, arg1)
120 CALL load_command(shell, input_declaration, arg1, arg2)
122 CALL destroy_force_env_command(shell, arg1)
123 CASE (
'NATOM',
'N_ATOM')
124 CALL get_natom_command(shell, arg1)
125 CASE (
'SETPOS',
'SET_POS')
126 CALL set_pos_command(shell, arg1)
127 CASE (
'SETCELL',
'SET_CELL')
128 CALL set_cell_command(shell, arg1)
129 CASE (
'GETCELL',
'GET_CELL')
130 CALL get_cell_command(shell, arg1)
131 CASE (
'GETSTRESS',
'GET_STRESS')
132 CALL get_stress_command(shell, arg1)
133 CASE (
'GETPOS',
'GET_POS')
134 CALL get_pos_command(shell, arg1)
135 CASE (
'GETE',
'GET_E')
136 CALL get_energy_command(shell, arg1)
137 CASE (
'EVALE',
'EVAL_E')
138 CALL eval_energy_command(shell, arg1)
139 CASE (
'CALCE',
'CALC_E')
140 CALL calc_energy_command(shell, arg1)
141 CASE (
'EVALEF',
'EVAL_EF')
142 CALL eval_energy_force_command(shell, arg1)
143 CASE (
'GETF',
'GET_F')
144 CALL get_forces_command(shell, arg1)
145 CASE (
'CALCEF',
'CALC_EF')
146 CALL calc_energy_forces_command(shell, arg1)
148 CALL run_command(shell, input_declaration, arg1, arg2)
149 CASE (
'UNITS_EVA',
'UNITS_EV_A')
150 CALL set_units_ev_a(shell)
152 CALL set_units_au(shell)
154 CALL get_units(shell)
158 shell%harsh = .false.
160 CALL set_pwd_command(shell, arg1)
162 CALL get_pwd_command(shell)
164 IF (shell%iw > 0)
WRITE (shell%iw,
'(a)')
'* EXIT'
167 CALL print_error(
'unknown command: '//cmd, shell)
182 TYPE(cp2k_shell_type) :: shell
183 CHARACTER(LEN=*),
INTENT(out) :: cmd, arg1, arg2
186 CHARACTER(LEN=default_path_length) :: line
190 IF (shell%iw > 0)
THEN
191 WRITE (shell%iw,
'("* READY")')
193 READ (*,
'(a)', iostat=iostat) line
194 IF (iostat /= 0)
THEN
195 IF (iostat == iostat_end)
THEN
196 WRITE (shell%iw,
'(a)')
'* EOF'
201 CALL shell%para_env%bcast(success)
202 IF (.NOT. success)
RETURN
203 CALL shell%para_env%bcast(line)
207 DO i = 1, len_trim(line)
208 IF (line(i:i) ==
' ')
EXIT
212 line = adjustl(line(i:))
215 DO i = 1, len_trim(line)
216 IF (line(i:i) ==
' ')
EXIT
219 line = adjustl(line(i:))
222 DO i = 1, len_trim(line)
223 IF (line(i:i) ==
' ')
EXIT
236 FUNCTION parse_env_id(str, shell)
RESULT(success)
237 CHARACTER(LEN=*),
INTENT(in) :: str
238 TYPE(cp2k_shell_type) :: shell
244 IF (len_trim(str) > 0)
THEN
245 READ (str, *, iostat=iostat) shell%env_id
246 IF (iostat /= 0)
THEN
249 CALL print_error(
"parse_env_id failed", shell)
251 ELSE IF (shell%env_id < 1)
THEN
252 CALL print_error(
"last env_id not set", shell)
256 END FUNCTION parse_env_id
265 FUNCTION my_assert(condition, message, shell)
RESULT(success)
266 LOGICAL,
INTENT(in) :: condition
267 CHARACTER(LEN=*),
INTENT(in) :: message
268 TYPE(cp2k_shell_type) :: shell
272 IF (.NOT. success)
THEN
273 CALL print_error(message, shell)
275 END FUNCTION my_assert
282 SUBROUTINE print_error(message, shell)
283 CHARACTER(LEN=*),
INTENT(in) :: message
284 TYPE(cp2k_shell_type) :: shell
286 IF (shell%harsh) cpabort(message)
288 IF (shell%iw > 0)
THEN
289 WRITE (shell%iw,
'("* ERROR ",a)') message
291 END SUBROUTINE print_error
297 SUBROUTINE help_command(shell)
298 TYPE(cp2k_shell_type) :: shell
300 IF (shell%iw > 0)
THEN
301 WRITE (shell%iw, *)
'Commands'
302 WRITE (shell%iw, *)
' '
303 WRITE (shell%iw, *)
' If there is [env_id] it means that an optional env_id can be given,'
304 WRITE (shell%iw, *)
' if none is given it defaults to the last env_id loaded'
305 WRITE (shell%iw, *)
' All commands are case insensitive.'
306 WRITE (shell%iw, *)
' '
307 WRITE (shell%iw, *)
' INFO: returns some information about cp2k.'
308 WRITE (shell%iw, *)
' VERSION: returns shell version. (queried by ASE to assert features & bugfixes)'
309 WRITE (shell%iw, *)
' WRITE_FILE: Writes content to a file (allows for using ASE over ssh).'
310 WRITE (shell%iw, *)
' LOAD <inp-filename> [out-filename]: loads the filename, returns the env_id, or -1 in case of error'
311 WRITE (shell%iw, *)
' out-filename is optional and defaults to <inp-filename>.out'
312 WRITE (shell%iw, *)
' use "__STD_OUT__" for printing to the screen'
313 WRITE (shell%iw, *)
' BG_LOAD <filename>: loads the filename, without returning the env_id'
314 WRITE (shell%iw, *)
' LAST_ENV_ID: returns the env_id of the last environment loaded'
315 WRITE (shell%iw, *)
' DESTROY [env_id]: destroys the given environment (last and default env'
316 WRITE (shell%iw, *)
' might become invalid)'
317 WRITE (shell%iw, *)
' NATOM [env_id]: returns the number of atoms in the environment env_id'
318 WRITE (shell%iw, *)
' SET_POS [env_id]: sets the positions of the atoms, should be followed'
319 WRITE (shell%iw, *)
' by natom*3 (on a line) and then all the positions. Returns the max'
320 WRITE (shell%iw, *)
' change of the coordinates (useful to avoid extra calculations).'
321 WRITE (shell%iw, *)
' SET_CELL [env_id]: sets the cell, should be followed by 9 numbers'
322 WRITE (shell%iw, *)
' GET_CELL [env_id]: gets the cell vectors'
323 WRITE (shell%iw, *)
' GET_STRESS [env_id]: gets the stress tensor of the last calculation on env_id'
324 WRITE (shell%iw, *)
' GET_POS [env_id]: gets the positions of the atoms, returns'
325 WRITE (shell%iw, *)
' natom*3 (on a line) and then all the positions then "* END" '
326 WRITE (shell%iw, *)
' (alone on a line)'
327 WRITE (shell%iw, *)
' GET_E [env_id]: gets the energy of the last calculation on env_id'
328 WRITE (shell%iw, *)
' GET_F [env_id]: gets the forces on the atoms,of the last calculation on '
329 WRITE (shell%iw, *)
' env_id, if only the energy was calculated the content is undefined. Returns'
330 WRITE (shell%iw, *)
' natom*3 (on a line) and then all the forces then "* END" (alone on'
331 WRITE (shell%iw, *)
' a line)'
332 WRITE (shell%iw, *)
' CALC_E [env_id]: calculate the energy and returns it'
333 WRITE (shell%iw, *)
' EVAL_E [env_id]: calculate the energy (without returning it)'
334 WRITE (shell%iw, *)
' CALC_EF [env_id]: calculate energy and forces and returns them,'
335 WRITE (shell%iw, *)
' first the energy on a line, then the natom*3 (on a line)'
336 WRITE (shell%iw, *)
' and finally all the values and "* END" (alone on a line)'
337 WRITE (shell%iw, *)
' EVAL_EF [env_id]: calculate the energy and forces (without returning them)'
338 WRITE (shell%iw, *)
' RUN <inp-filename> <out-filename>: run the given input file'
339 WRITE (shell%iw, *)
' HARSH: stops on any error'
340 WRITE (shell%iw, *)
' PERMISSIVE: stops only on serious errors'
341 WRITE (shell%iw, *)
' UNITS: returns the units used for energy and position'
342 WRITE (shell%iw, *)
' UNITS_EV_A: sets the units to electron volt (energy) and Angstrom (positions)'
343 WRITE (shell%iw, *)
' UNITS_AU: sets the units atomic units'
344 WRITE (shell%iw, *)
' CD <dir>: change working directory'
345 WRITE (shell%iw, *)
' PWD: print working directory'
346 WRITE (shell%iw, *)
' EXIT: Quit the shell'
347 WRITE (shell%iw, *)
' HELP: writes the present help'
350 END SUBROUTINE help_command
356 SUBROUTINE info_license_command(shell)
357 TYPE(cp2k_shell_type) :: shell
359 CHARACTER(LEN=default_path_length) :: cwd, host_name, user_name
362 IF (shell%iw > 0)
THEN
367 WRITE (unit=shell%iw, fmt=
"(A,A)") &
368 " PROGRAM STARTED ON ", trim(host_name)
369 WRITE (unit=shell%iw, fmt=
"(A,A)") &
370 " PROGRAM STARTED BY ", trim(user_name)
371 WRITE (unit=shell%iw, fmt=
"(A,i10)") &
372 " PROGRAM PROCESS ID ", pid
373 WRITE (unit=shell%iw, fmt=
"(A,A)") &
374 " PROGRAM STARTED IN ", trim(cwd)
375 WRITE (unit=shell%iw, fmt=
"(/,T2,A,T31,A50)") &
376 "CP2K| version string: ", &
378 WRITE (unit=shell%iw, fmt=
"(T2,A,T41,A40)") &
379 "CP2K| source code revision number:", &
381 WRITE (unit=shell%iw, fmt=
"(T2,A,T41,A40)") &
382 "CP2K| is freely available from ", &
384 WRITE (unit=shell%iw, fmt=
"(T2,A,T31,A50)") &
385 "CP2K| Program compiled at", &
387 WRITE (unit=shell%iw, fmt=
"(T2,A,T31,A50)") &
388 "CP2K| Program compiled on", &
390 WRITE (unit=shell%iw, fmt=
"(T2,A,T31,A50)") &
391 "CP2K| Program compiled for", &
398 END SUBROUTINE info_license_command
404 SUBROUTINE version_command(shell)
405 TYPE(cp2k_shell_type) :: shell
407 IF (shell%iw > 0)
THEN
408 WRITE (shell%iw,
'(a,a)')
"CP2K Shell Version: ", cp2k_shell_version
411 END SUBROUTINE version_command
417 SUBROUTINE write_file_command(shell)
418 TYPE(cp2k_shell_type) :: shell
420 CHARACTER(LEN=default_path_length) :: line, out_filename
421 INTEGER :: file_unit, i, iostat, n_lines
423 IF (shell%iw > 0)
THEN
424 READ (*,
'(a)', iostat=iostat) out_filename
425 IF (iostat /= 0) cpabort(
'WRITE_FILE bad filename')
426 READ (*, *, iostat=iostat) n_lines
427 IF (iostat /= 0) cpabort(
'WRITE_FILE bad number of lines')
428 CALL open_file(file_name=trim(out_filename), unit_number=file_unit, &
429 file_status=
"UNKNOWN", file_form=
"FORMATTED", file_action=
"WRITE")
431 READ (*,
'(a)', iostat=iostat) line
432 IF (iostat /= 0) cpabort(
'WRITE_FILE read error')
433 WRITE (file_unit,
'(a)', iostat=iostat) trim(line)
434 IF (iostat /= 0) cpabort(
'WRITE_FILE write error')
436 READ (*,
'(a)', iostat=iostat) line
437 IF (iostat /= 0) cpabort(
'WRITE_FILE read error')
438 IF (trim(line) /=
"*END") cpabort(
'WRITE_FILE bad end delimiter')
441 END SUBROUTINE write_file_command
447 SUBROUTINE get_last_env_id(shell)
448 TYPE(cp2k_shell_type) :: shell
450 IF (shell%iw > 0)
THEN
451 WRITE (shell%iw,
'(i10)') shell%env_id
454 END SUBROUTINE get_last_env_id
462 SUBROUTINE bg_load_command(shell, input_declaration, arg1)
463 TYPE(cp2k_shell_type) :: shell
464 TYPE(section_type),
POINTER :: input_declaration
465 CHARACTER(LEN=*) :: arg1
469 IF (.NOT. my_assert(len_trim(arg1) > 0,
"file argument missing", shell))
RETURN
471 input_declaration=input_declaration, &
472 input_path=trim(arg1), &
473 output_path=trim(arg1)//
'.out', &
474 owns_out_unit=.true., ierr=ierr)
477 CALL print_error(
"create_force_env failed", shell)
479 END SUBROUTINE bg_load_command
488 SUBROUTINE load_command(shell, input_declaration, arg1, arg2)
489 TYPE(cp2k_shell_type) :: shell
490 TYPE(section_type),
POINTER :: input_declaration
491 CHARACTER(LEN=*),
INTENT(IN) :: arg1, arg2
493 CHARACTER(LEN=default_path_length) :: inp_filename, out_filename
496 IF (.NOT. my_assert(len_trim(arg1) > 0,
"file argument missing", shell))
RETURN
498 out_filename = trim(inp_filename)//
'.out'
499 IF (len_trim(arg2) > 0) out_filename = arg2
501 input_declaration=input_declaration, &
502 input_path=inp_filename, &
503 output_path=out_filename, &
504 owns_out_unit=.true., ierr=ierr)
507 CALL print_error(
"create_force_env failed", shell)
508 ELSE IF (shell%iw > 0)
THEN
509 WRITE (shell%iw,
'(i10)') shell%env_id
512 END SUBROUTINE load_command
519 SUBROUTINE destroy_force_env_command(shell, arg1)
520 TYPE(cp2k_shell_type) :: shell
521 CHARACTER(LEN=*),
INTENT(IN) :: arg1
525 IF (.NOT. parse_env_id(arg1, shell))
RETURN
528 IF (ierr /= 0)
CALL print_error(
'destroy_force_env failed', shell)
529 END SUBROUTINE destroy_force_env_command
536 SUBROUTINE get_natom_command(shell, arg1)
537 TYPE(cp2k_shell_type) :: shell
538 CHARACTER(LEN=*),
INTENT(IN) :: arg1
540 INTEGER :: ierr, iostat, n_atom
542 IF (.NOT. parse_env_id(arg1, shell))
RETURN
543 CALL get_natom(shell%env_id, n_atom, ierr)
544 IF (.NOT. my_assert(ierr == 0,
'get_natom failed', shell))
RETURN
545 IF (shell%iw > 0)
THEN
546 WRITE (shell%iw,
'(i10)', iostat=iostat) n_atom
549 END SUBROUTINE get_natom_command
556 SUBROUTINE set_pos_command(shell, arg1)
557 TYPE(cp2k_shell_type) :: shell
558 CHARACTER(LEN=*),
INTENT(IN) :: arg1
560 CHARACTER(LEN=default_path_length) :: line
561 INTEGER :: i, ierr, iostat, n_atom
562 REAL(kind=
dp) :: max_change
563 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: old_pos, pos
565 IF (.NOT. parse_env_id(arg1, shell))
RETURN
566 CALL get_natom(shell%env_id, n_atom, ierr)
567 IF (.NOT. my_assert(ierr == 0,
'get_natom failed', shell))
RETURN
568 ALLOCATE (pos(3*n_atom), old_pos(3*n_atom))
569 IF (shell%iw > 0)
THEN
570 READ (*, *, iostat=iostat) n_atom
571 IF (.NOT. my_assert(iostat == 0,
'setpos read n_atom failed', shell))
RETURN
572 IF (.NOT. my_assert(n_atom ==
SIZE(pos),
'setpos invalid number of atoms', shell))
RETURN
573 READ (*, *, iostat=iostat) pos
574 IF (.NOT. my_assert(iostat == 0,
'setpos read coords failed', shell))
RETURN
575 pos(:) = pos(:)/shell%pos_fact
576 READ (*,
'(a)', iostat=iostat) line
577 IF (.NOT. my_assert(iostat == 0,
'setpos read END failed', shell))
RETURN
579 IF (.NOT. my_assert(trim(line) ==
'*END',
'missing *END', shell))
RETURN
581 CALL shell%para_env%bcast(pos)
582 CALL get_pos(shell%env_id, old_pos, n_el=3*n_atom, ierr=ierr)
583 IF (.NOT. my_assert(ierr == 0,
'get_pos error', shell))
RETURN
584 CALL set_pos(shell%env_id, new_pos=pos, n_el=3*n_atom, ierr=ierr)
585 IF (.NOT. my_assert(ierr == 0,
'set_pos error', shell))
RETURN
588 max_change = max(max_change, abs(pos(i) - old_pos(i)))
590 DEALLOCATE (pos, old_pos)
591 IF (shell%iw > 0)
THEN
592 WRITE (shell%iw,
'(ES22.13)') max_change*shell%pos_fact
595 END SUBROUTINE set_pos_command
602 SUBROUTINE set_cell_command(shell, arg1)
603 TYPE(cp2k_shell_type) :: shell
604 CHARACTER(LEN=*),
INTENT(IN) :: arg1
606 INTEGER :: ierr, iostat
607 REAL(kind=
dp),
DIMENSION(3, 3) :: cell
609 IF (.NOT. parse_env_id(arg1, shell))
RETURN
610 IF (shell%iw > 0)
THEN
611 READ (*, *, iostat=iostat) cell
612 IF (.NOT. my_assert(iostat == 0,
'setcell read failed', shell))
RETURN
613 cell(:, :) = cell(:, :)/shell%pos_fact
615 CALL shell%para_env%bcast(cell)
616 CALL set_cell(shell%env_id, new_cell=cell, ierr=ierr)
617 IF (.NOT. my_assert(ierr == 0,
'set_cell failed', shell))
RETURN
618 END SUBROUTINE set_cell_command
625 SUBROUTINE get_cell_command(shell, arg1)
626 TYPE(cp2k_shell_type) :: shell
627 CHARACTER(LEN=*),
INTENT(IN) :: arg1
630 REAL(kind=
dp),
DIMENSION(3, 3) :: cell
632 IF (.NOT. parse_env_id(arg1, shell))
RETURN
633 CALL get_cell(shell%env_id, cell=cell, ierr=ierr)
634 IF (.NOT. my_assert(ierr == 0,
'get_cell failed', shell))
RETURN
635 cell(:, :) = cell(:, :)*shell%pos_fact
636 IF (shell%iw > 0)
THEN
637 WRITE (shell%iw,
'(9ES22.13)') cell
640 END SUBROUTINE get_cell_command
647 SUBROUTINE get_stress_command(shell, arg1)
648 TYPE(cp2k_shell_type) :: shell
649 CHARACTER(LEN=*),
INTENT(IN) :: arg1
652 REAL(kind=
dp),
DIMENSION(3, 3) :: stress_tensor
654 IF (.NOT. parse_env_id(arg1, shell))
RETURN
656 IF (.NOT. my_assert(ierr == 0,
'get_stress_tensor failed', shell))
RETURN
657 stress_tensor(:, :) = stress_tensor(:, :)*(shell%e_fact/shell%pos_fact**3)
658 IF (shell%iw > 0)
THEN
659 WRITE (shell%iw,
'(9ES22.13)') stress_tensor
662 END SUBROUTINE get_stress_command
669 SUBROUTINE get_pos_command(shell, arg1)
670 TYPE(cp2k_shell_type) :: shell
671 CHARACTER(LEN=*),
INTENT(IN) :: arg1
673 INTEGER :: ierr, n_atom
674 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: pos
676 IF (.NOT. parse_env_id(arg1, shell))
RETURN
677 CALL get_natom(shell%env_id, n_atom, ierr)
678 IF (.NOT. my_assert(ierr == 0,
'get_natom failed', shell))
RETURN
679 ALLOCATE (pos(3*n_atom))
680 CALL get_pos(shell%env_id, pos=pos, n_el=3*n_atom, ierr=ierr)
681 IF (.NOT. my_assert(ierr == 0,
'get_pos failed', shell))
RETURN
682 IF (shell%iw > 0)
THEN
683 WRITE (shell%iw,
'(i10)') 3*n_atom
684 WRITE (shell%iw,
'(3ES22.13)') pos(:)*shell%pos_fact
685 WRITE (shell%iw,
'(a)')
"* END"
689 END SUBROUTINE get_pos_command
696 SUBROUTINE get_energy_command(shell, arg1)
697 TYPE(cp2k_shell_type) :: shell
698 CHARACTER(LEN=*),
INTENT(IN) :: arg1
701 REAL(kind=
dp) :: e_pot
703 IF (.NOT. parse_env_id(arg1, shell))
RETURN
705 IF (.NOT. my_assert(ierr == 0,
'get_energy failed', shell))
RETURN
706 IF (shell%iw > 0)
THEN
707 WRITE (shell%iw,
'(ES22.13)') e_pot*shell%e_fact
710 END SUBROUTINE get_energy_command
717 SUBROUTINE eval_energy_command(shell, arg1)
718 TYPE(cp2k_shell_type) :: shell
719 CHARACTER(LEN=*),
INTENT(IN) :: arg1
723 IF (.NOT. parse_env_id(arg1, shell))
RETURN
725 IF (ierr /= 0)
CALL print_error(
'calc_energy_force failed', shell)
726 END SUBROUTINE eval_energy_command
733 SUBROUTINE calc_energy_command(shell, arg1)
734 TYPE(cp2k_shell_type) :: shell
735 CHARACTER(LEN=*),
INTENT(IN) :: arg1
738 REAL(kind=
dp) :: e_pot
740 IF (.NOT. parse_env_id(arg1, shell))
RETURN
742 IF (.NOT. my_assert(ierr == 0,
'calc_energy_force failed', shell))
RETURN
744 IF (.NOT. my_assert(ierr == 0,
'get_energy failed', shell))
RETURN
745 IF (shell%iw > 0)
THEN
746 WRITE (shell%iw,
'(ES22.13)') e_pot*shell%e_fact
749 END SUBROUTINE calc_energy_command
756 SUBROUTINE eval_energy_force_command(shell, arg1)
757 TYPE(cp2k_shell_type) :: shell
758 CHARACTER(LEN=*),
INTENT(IN) :: arg1
762 IF (.NOT. parse_env_id(arg1, shell))
RETURN
764 IF (ierr /= 0)
CALL print_error(
'calc_energy_force failed', shell)
765 END SUBROUTINE eval_energy_force_command
772 SUBROUTINE get_forces_command(shell, arg1)
773 TYPE(cp2k_shell_type) :: shell
774 CHARACTER(LEN=*),
INTENT(IN) :: arg1
776 INTEGER :: ierr, n_atom
777 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: forces
779 IF (.NOT. parse_env_id(arg1, shell))
RETURN
780 CALL get_natom(shell%env_id, n_atom, ierr)
781 IF (.NOT. my_assert(ierr == 0,
'get_natom failed', shell))
RETURN
782 ALLOCATE (forces(3*n_atom))
783 CALL get_force(shell%env_id, frc=forces, n_el=3*n_atom, ierr=ierr)
784 IF (.NOT. my_assert(ierr == 0,
'get_force failed', shell))
RETURN
785 forces(:) = forces(:)*(shell%e_fact/shell%pos_fact)
786 IF (shell%iw > 0)
THEN
787 WRITE (shell%iw,
'(i10)') 3*n_atom
788 WRITE (shell%iw,
'(3ES22.13)') forces
789 WRITE (shell%iw,
'("* END")')
793 END SUBROUTINE get_forces_command
800 SUBROUTINE calc_energy_forces_command(shell, arg1)
801 TYPE(cp2k_shell_type) :: shell
802 CHARACTER(LEN=*),
INTENT(IN) :: arg1
804 INTEGER :: ierr, n_atom
805 REAL(kind=
dp) :: e_pot
806 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: forces
808 IF (.NOT. parse_env_id(arg1, shell))
RETURN
810 IF (.NOT. my_assert(ierr == 0,
'calc_energy_force failed', shell))
RETURN
812 IF (.NOT. my_assert(ierr == 0,
'get_energy failed', shell))
RETURN
813 CALL get_natom(shell%env_id, n_atom, ierr)
814 IF (.NOT. my_assert(ierr == 0,
'get_natom failed', shell))
RETURN
815 ALLOCATE (forces(3*n_atom))
816 CALL get_force(shell%env_id, frc=forces, n_el=3*n_atom, ierr=ierr)
817 IF (.NOT. my_assert(ierr == 0,
'get_energy failed', shell))
RETURN
818 IF (shell%iw > 0)
THEN
819 WRITE (shell%iw,
'(ES22.13)') e_pot*shell%e_fact
820 WRITE (shell%iw,
'(i10)') 3*n_atom
821 WRITE (shell%iw,
'(3ES22.13)') forces*(shell%e_fact/shell%pos_fact)
822 WRITE (shell%iw,
'("* END")')
826 END SUBROUTINE calc_energy_forces_command
835 SUBROUTINE run_command(shell, input_declaration, arg1, arg2)
836 TYPE(cp2k_shell_type) :: shell
837 TYPE(section_type),
POINTER :: input_declaration
838 CHARACTER(LEN=*),
INTENT(IN) :: arg1, arg2
840 IF (.NOT. my_assert(len_trim(arg1) > 0,
"input-file argument missing", shell))
RETURN
841 IF (.NOT. my_assert(len_trim(arg2) > 0,
"input-file argument missing", shell))
RETURN
842 CALL run_input(input_declaration, arg1, arg2, empty_initial_variables)
843 END SUBROUTINE run_command
849 SUBROUTINE set_units_ev_a(shell)
850 TYPE(cp2k_shell_type) :: shell
855 END SUBROUTINE set_units_ev_a
861 SUBROUTINE set_units_au(shell)
862 TYPE(cp2k_shell_type) :: shell
864 shell%e_fact = 1.0_dp
865 shell%pos_fact = 1.0_dp
867 END SUBROUTINE set_units_au
873 SUBROUTINE get_units(shell)
874 TYPE(cp2k_shell_type) :: shell
876 IF (shell%iw > 0)
THEN
877 WRITE (shell%iw,
'(a)') trim(shell%units)
880 END SUBROUTINE get_units
887 SUBROUTINE set_pwd_command(shell, arg1)
888 TYPE(cp2k_shell_type) :: shell
889 CHARACTER(LEN=*),
INTENT(IN) :: arg1
893 IF (.NOT. my_assert(len_trim(arg1) > 0,
'missing directory', shell))
RETURN
895 IF (ierr /= 0)
CALL print_error(
'changing directory failed', shell)
896 END SUBROUTINE set_pwd_command
902 SUBROUTINE get_pwd_command(shell)
903 TYPE(cp2k_shell_type) :: shell
905 CHARACTER(LEN=default_path_length) :: cwd
907 IF (shell%iw > 0)
THEN
909 WRITE (shell%iw,
'(a)') trim(cwd)
911 END SUBROUTINE get_pwd_command
static void parse_next_line(const char key[], FILE *fp, const char format[], const int nargs,...)
Parses next line from file, expecting it to match "${key} ${format}".
some minimal info about CP2K, including its version and license
character(len= *), parameter, public cp2k_home
character(len= *), parameter, public compile_host
character(len= *), parameter, public compile_arch
subroutine, public print_cp2k_license(iunit)
...
character(len= *), parameter, public compile_revision
character(len= *), parameter, public compile_date
character(len= *), parameter, public cp2k_version
subroutine, public run_input(input_declaration, input_file_path, output_file_path, initial_variables, mpi_comm)
runs the given input
Interactive shell of CP2K.
subroutine, public launch_cp2k_shell(input_declaration)
Launch the interactive CP2K shell.
Utility routines to open and close files. Tracking of preconnections.
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.
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.
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
interface to use cp2k as library
recursive subroutine, public destroy_force_env(env_id, ierr, q_finalize)
deallocates the force_env with the given id
subroutine, public get_natom(env_id, n_atom, ierr)
returns the number of atoms in the given force env
subroutine, public get_cell(env_id, cell, per, ierr)
gets a cell
recursive subroutine, public calc_energy_force(env_id, calc_force, ierr)
updates the energy and the forces of given force_env
subroutine, public get_energy(env_id, e_pot, ierr)
returns the energy of the last configuration calculated
subroutine, public get_pos(env_id, pos, n_el, ierr)
gets the positions of the particles
recursive subroutine, public create_force_env(new_env_id, input_declaration, input_path, output_path, mpi_comm, output_unit, owns_out_unit, input, ierr, work_dir, initial_variables)
creates a new force environment using the given input, and writing the output to the given output uni...
subroutine, public set_cell(env_id, new_cell, ierr)
sets a new cell
subroutine, public set_pos(env_id, new_pos, n_el, ierr)
sets the positions of the particles
subroutine, public get_stress_tensor(env_id, stress_tensor, ierr)
gets the stress tensor
subroutine, public get_force(env_id, frc, n_el, ierr)
gets the forces of the particles
recursive subroutine, public calc_force(env_id, pos, n_el_pos, e_pot, force, n_el_force, ierr)
returns the energy of the configuration given by the positions passed as argument
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_path_length
Machine interface based on Fortran 2003 and POSIX.
subroutine, public m_getpid(pid)
...
subroutine, public m_flush(lunit)
flushes units if the &GLOBAL flag is set accordingly
subroutine, public m_getcwd(curdir)
...
subroutine, public m_chdir(dir, ierror)
...
subroutine, public m_getlog(user)
...
subroutine, public m_hostnm(hname)
...
Interface to the message passing library MPI.
Definition of physical constants:
real(kind=dp), parameter, public evolt
real(kind=dp), parameter, public angstrom
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.