34   USE iso_fortran_env,                 
ONLY: iostat_end
 
   65#include "../base/base_uses.f90" 
   71   CHARACTER(LEN=*), 
PARAMETER                           :: CP2K_SHELL_VERSION = 
"7.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
 
   94      CHARACTER(LEN=default_path_length)                 :: arg1, arg2, cmd
 
   95      TYPE(cp2k_shell_type)                              :: shell
 
   99      shell%para_env => logger%para_env
 
  103         IF (.NOT. parse_next_line(shell, cmd, arg1, arg2)) 
EXIT 
  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 (
'SETPOSFILE', 
'SET_POS_FILE')
 
  128            CALL set_pos_file_command(shell, arg1, arg2)
 
  129         CASE (
'SETCELL', 
'SET_CELL')
 
  130            CALL set_cell_command(shell, arg1)
 
  131         CASE (
'GETCELL', 
'GET_CELL')
 
  132            CALL get_cell_command(shell, arg1)
 
  133         CASE (
'GETSTRESS', 
'GET_STRESS')
 
  134            CALL get_stress_command(shell, arg1)
 
  135         CASE (
'GETPOS', 
'GET_POS')
 
  136            CALL get_pos_command(shell, arg1)
 
  137         CASE (
'GETE', 
'GET_E')
 
  138            CALL get_energy_command(shell, arg1)
 
  139         CASE (
'EVALE', 
'EVAL_E')
 
  140            CALL eval_energy_command(shell, arg1)
 
  141         CASE (
'CALCE', 
'CALC_E')
 
  142            CALL calc_energy_command(shell, arg1)
 
  143         CASE (
'EVALEF', 
'EVAL_EF')
 
  144            CALL eval_energy_force_command(shell, arg1)
 
  145         CASE (
'GETF', 
'GET_F')
 
  146            CALL get_forces_command(shell, arg1)
 
  147         CASE (
'CALCEF', 
'CALC_EF')
 
  148            CALL calc_energy_forces_command(shell, arg1)
 
  150            CALL run_command(shell, input_declaration, arg1, arg2)
 
  151         CASE (
'UNITS_EVA', 
'UNITS_EV_A')
 
  152            CALL set_units_ev_a(shell)
 
  154            CALL set_units_au(shell)
 
  156            CALL get_units(shell)
 
  160            shell%harsh = .false.
 
  162            CALL set_pwd_command(shell, arg1)
 
  164            CALL get_pwd_command(shell)
 
  166            IF (shell%iw > 0) 
WRITE (shell%iw, 
'(a)') 
'* EXIT' 
  169            CALL print_error(
'unknown command: '//cmd, shell)
 
 
  183   FUNCTION parse_next_line(shell, cmd, arg1, arg2) 
RESULT(success)
 
  184      TYPE(cp2k_shell_type)                              :: shell
 
  185      CHARACTER(LEN=*), 
INTENT(out)                      :: cmd, arg1, arg2
 
  188      CHARACTER(LEN=default_path_length)                 :: line
 
  192      IF (shell%iw > 0) 
THEN 
  193         WRITE (shell%iw, 
'("* READY")')
 
  195         READ (*, 
'(a)', iostat=iostat) line
 
  196         IF (iostat /= 0) 
THEN 
  197            IF (iostat == iostat_end) 
THEN 
  198               WRITE (shell%iw, 
'(a)') 
'* EOF' 
  203      CALL shell%para_env%bcast(success)
 
  204      IF (.NOT. success) 
RETURN 
  205      CALL shell%para_env%bcast(line)
 
  209      DO i = 1, len_trim(line)
 
  210         IF (line(i:i) == 
' ') 
EXIT 
  214      line = adjustl(line(i:)) 
 
  217      DO i = 1, len_trim(line)
 
  218         IF (line(i:i) == 
' ') 
EXIT 
  221      line = adjustl(line(i:)) 
 
  224      DO i = 1, len_trim(line)
 
  225         IF (line(i:i) == 
' ') 
EXIT 
  230   END FUNCTION parse_next_line
 
  238   FUNCTION parse_env_id(str, shell) 
RESULT(success)
 
  239      CHARACTER(LEN=*), 
INTENT(in)                       :: str
 
  240      TYPE(cp2k_shell_type)                              :: shell
 
  246      IF (len_trim(str) > 0) 
THEN 
  247         READ (str, *, iostat=iostat) shell%env_id
 
  248         IF (iostat /= 0) 
THEN 
  251            CALL print_error(
"parse_env_id failed", shell)
 
  253      ELSE IF (shell%env_id < 1) 
THEN 
  254         CALL print_error(
"last env_id not set", shell)
 
  258   END FUNCTION parse_env_id
 
  267   FUNCTION my_assert(condition, message, shell) 
RESULT(success)
 
  268      LOGICAL, 
INTENT(in)                                :: condition
 
  269      CHARACTER(LEN=*), 
INTENT(in)                       :: message
 
  270      TYPE(cp2k_shell_type)                              :: shell
 
  274      IF (.NOT. success) 
THEN 
  275         CALL print_error(message, shell)
 
  277   END FUNCTION my_assert
 
  284   SUBROUTINE print_error(message, shell)
 
  285      CHARACTER(LEN=*), 
INTENT(in)                       :: message
 
  286      TYPE(cp2k_shell_type)                              :: shell
 
  288      IF (shell%harsh) cpabort(message)
 
  290      IF (shell%iw > 0) 
THEN 
  291         WRITE (shell%iw, 
'("* ERROR ",a)') message
 
  293   END SUBROUTINE print_error
 
  299   SUBROUTINE help_command(shell)
 
  300      TYPE(cp2k_shell_type)                              :: shell
 
  302      IF (shell%iw > 0) 
THEN 
  303         WRITE (shell%iw, *) 
'Commands' 
  304         WRITE (shell%iw, *) 
' ' 
  305         WRITE (shell%iw, *) 
' If there is [env_id] it means that an optional env_id can be given,' 
  306         WRITE (shell%iw, *) 
' if none is given it defaults to the last env_id loaded' 
  307         WRITE (shell%iw, *) 
' All commands are case insensitive.' 
  308         WRITE (shell%iw, *) 
' ' 
  309         WRITE (shell%iw, *) 
' INFO: returns some information about cp2k.' 
  310         WRITE (shell%iw, *) 
' VERSION: returns shell version. (queried by ASE to assert features & bugfixes)' 
  311         WRITE (shell%iw, *) 
' WRITE_FILE: Writes content to a file (allows for using ASE over ssh).' 
  312         WRITE (shell%iw, *) 
' LOAD <inp-filename> [out-filename]: loads the filename, returns the env_id, or -1 in case of error' 
  313         WRITE (shell%iw, *) 
'   out-filename is optional and defaults to <inp-filename>.out' 
  314         WRITE (shell%iw, *) 
'   use "__STD_OUT__" for printing to the screen' 
  315         WRITE (shell%iw, *) 
' BG_LOAD <filename>: loads the filename, without returning the env_id' 
  316         WRITE (shell%iw, *) 
' LAST_ENV_ID: returns the env_id of the last environment loaded' 
  317         WRITE (shell%iw, *) 
' DESTROY [env_id]: destroys the given environment (last and default env' 
  318         WRITE (shell%iw, *) 
'   might become invalid)' 
  319         WRITE (shell%iw, *) 
' NATOM [env_id]: returns the number of atoms in the environment env_id' 
  320         WRITE (shell%iw, *) 
' SET_POS [env_id]: sets the positions of the atoms, should be followed' 
  321         WRITE (shell%iw, *) 
'   by natom*3 (on a line) and then all the positions. Returns the max' 
  322         WRITE (shell%iw, *) 
'   change of the coordinates (useful to avoid extra calculations).' 
  323         WRITE (shell%iw, *) 
' SET_POS_FILE <filename> [env_id]: sets the positions of the atoms from a file.' 
  324         WRITE (shell%iw, *) 
'   Returns the max change of the coordinates.' 
  325         WRITE (shell%iw, *) 
' SET_CELL [env_id]: sets the cell, should be followed by 9 numbers' 
  326         WRITE (shell%iw, *) 
' GET_CELL [env_id]: gets the cell vectors' 
  327         WRITE (shell%iw, *) 
' GET_STRESS [env_id]: gets the stress tensor of the last calculation on env_id' 
  328         WRITE (shell%iw, *) 
' GET_POS [env_id]: gets the positions of the atoms, returns' 
  329         WRITE (shell%iw, *) 
'   natom*3 (on a line) and then all the positions then "* END" ' 
  330         WRITE (shell%iw, *) 
'   (alone on a line)' 
  331         WRITE (shell%iw, *) 
' GET_E [env_id]: gets the energy of the last calculation on env_id' 
  332         WRITE (shell%iw, *) 
' GET_F [env_id]: gets the forces on the atoms,of the last calculation on ' 
  333         WRITE (shell%iw, *) 
'   env_id, if only the energy was calculated the content is undefined. Returns' 
  334         WRITE (shell%iw, *) 
'   natom*3 (on a line) and then all the forces then "* END" (alone on' 
  335         WRITE (shell%iw, *) 
'   a line)' 
  336         WRITE (shell%iw, *) 
' CALC_E [env_id]: calculate the energy and returns it' 
  337         WRITE (shell%iw, *) 
' EVAL_E [env_id]: calculate the energy (without returning it)' 
  338         WRITE (shell%iw, *) 
' CALC_EF [env_id]: calculate energy and forces and returns them,' 
  339         WRITE (shell%iw, *) 
'   first the energy on a line, then the natom*3 (on a line)' 
  340         WRITE (shell%iw, *) 
'   and finally all the values and "* END" (alone on a line)' 
  341         WRITE (shell%iw, *) 
' EVAL_EF [env_id]: calculate the energy and forces (without returning them)' 
  342         WRITE (shell%iw, *) 
' RUN <inp-filename> <out-filename>: run the given input file' 
  343         WRITE (shell%iw, *) 
' HARSH: stops on any error' 
  344         WRITE (shell%iw, *) 
' PERMISSIVE: stops only on serious errors' 
  345         WRITE (shell%iw, *) 
' UNITS: returns the units used for energy and position' 
  346         WRITE (shell%iw, *) 
' UNITS_EV_A: sets the units to electron volt (energy)  and Angstrom (positions)' 
  347         WRITE (shell%iw, *) 
' UNITS_AU: sets the units atomic units' 
  348         WRITE (shell%iw, *) 
' CD <dir>: change working directory' 
  349         WRITE (shell%iw, *) 
' PWD: print working directory' 
  350         WRITE (shell%iw, *) 
' EXIT: Quit the shell' 
  351         WRITE (shell%iw, *) 
' HELP: writes the present help' 
  354   END SUBROUTINE help_command
 
  360   SUBROUTINE info_license_command(shell)
 
  361      TYPE(cp2k_shell_type)                              :: shell
 
  363      CHARACTER(LEN=default_path_length)                 :: cwd, host_name, user_name
 
  366      IF (shell%iw > 0) 
THEN 
  371         WRITE (unit=shell%iw, fmt=
"(A,A)") &
 
  372            " PROGRAM STARTED ON ", trim(host_name)
 
  373         WRITE (unit=shell%iw, fmt=
"(A,A)") &
 
  374            " PROGRAM STARTED BY ", trim(user_name)
 
  375         WRITE (unit=shell%iw, fmt=
"(A,i10)") &
 
  376            " PROGRAM PROCESS ID ", pid
 
  377         WRITE (unit=shell%iw, fmt=
"(A,A)") &
 
  378            " PROGRAM STARTED IN ", trim(cwd)
 
  379         WRITE (unit=shell%iw, fmt=
"(/,T2,A,T31,A50)") &
 
  380            "CP2K| version string: ", &
 
  382         WRITE (unit=shell%iw, fmt=
"(T2,A,T41,A40)") &
 
  383            "CP2K| source code revision number:", &
 
  385         WRITE (unit=shell%iw, fmt=
"(T2,A,T41,A40)") &
 
  386            "CP2K| is freely available from ", &
 
  388         WRITE (unit=shell%iw, fmt=
"(T2,A,T31,A50)") &
 
  389            "CP2K| Program compiled at", &
 
  391         WRITE (unit=shell%iw, fmt=
"(T2,A,T31,A50)") &
 
  392            "CP2K| Program compiled on", &
 
  394         WRITE (unit=shell%iw, fmt=
"(T2,A,T31,A50)") &
 
  395            "CP2K| Program compiled for", &
 
  402   END SUBROUTINE info_license_command
 
  408   SUBROUTINE version_command(shell)
 
  409      TYPE(cp2k_shell_type)                              :: shell
 
  411      IF (shell%iw > 0) 
THEN 
  412         WRITE (shell%iw, 
'(a,a)') 
"CP2K Shell Version: ", cp2k_shell_version
 
  415   END SUBROUTINE version_command
 
  421   SUBROUTINE write_file_command(shell)
 
  422      TYPE(cp2k_shell_type)                              :: shell
 
  424      CHARACTER(LEN=default_path_length)                 :: line, out_filename
 
  425      INTEGER                                            :: file_unit, i, iostat, n_lines
 
  427      IF (shell%iw > 0) 
THEN 
  428         READ (*, 
'(a)', iostat=iostat) out_filename
 
  429         IF (iostat /= 0) cpabort(
'WRITE_FILE bad filename')
 
  430         READ (*, *, iostat=iostat) n_lines
 
  431         IF (iostat /= 0) cpabort(
'WRITE_FILE bad number of lines')
 
  432         CALL open_file(file_name=trim(out_filename), unit_number=file_unit, &
 
  433                        file_status=
"UNKNOWN", file_form=
"FORMATTED", file_action=
"WRITE")
 
  435            READ (*, 
'(a)', iostat=iostat) line
 
  436            IF (iostat /= 0) cpabort(
'WRITE_FILE read error')
 
  437            WRITE (file_unit, 
'(a)', iostat=iostat) trim(line)
 
  438            IF (iostat /= 0) cpabort(
'WRITE_FILE write error')
 
  440         READ (*, 
'(a)', iostat=iostat) line
 
  441         IF (iostat /= 0) cpabort(
'WRITE_FILE read error')
 
  442         IF (trim(line) /= 
"*END") cpabort(
'WRITE_FILE bad end delimiter')
 
  445   END SUBROUTINE write_file_command
 
  451   SUBROUTINE get_last_env_id(shell)
 
  452      TYPE(cp2k_shell_type)                              :: shell
 
  454      IF (shell%iw > 0) 
THEN 
  455         WRITE (shell%iw, 
'(i10)') shell%env_id
 
  458   END SUBROUTINE get_last_env_id
 
  466   SUBROUTINE bg_load_command(shell, input_declaration, arg1)
 
  467      TYPE(cp2k_shell_type)                              :: shell
 
  469      CHARACTER(LEN=*)                                   :: arg1
 
  473      IF (.NOT. my_assert(len_trim(arg1) > 0, 
"file argument missing", shell)) 
RETURN 
  475                            input_declaration=input_declaration, &
 
  476                            input_path=trim(arg1), &
 
  477                            output_path=trim(arg1)//
'.out', &
 
  478                            owns_out_unit=.true., ierr=ierr)
 
  481         CALL print_error(
"create_force_env failed", shell)
 
  483   END SUBROUTINE bg_load_command
 
  492   SUBROUTINE load_command(shell, input_declaration, arg1, arg2)
 
  493      TYPE(cp2k_shell_type)                              :: shell
 
  495      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1, arg2
 
  497      CHARACTER(LEN=default_path_length)                 :: inp_filename, out_filename
 
  500      IF (.NOT. my_assert(len_trim(arg1) > 0, 
"file argument missing", shell)) 
RETURN 
  502      out_filename = trim(inp_filename)//
'.out' 
  503      IF (len_trim(arg2) > 0) out_filename = arg2
 
  505                            input_declaration=input_declaration, &
 
  506                            input_path=inp_filename, &
 
  507                            output_path=out_filename, &
 
  508                            owns_out_unit=.true., ierr=ierr)
 
  511         CALL print_error(
"create_force_env failed", shell)
 
  512      ELSE IF (shell%iw > 0) 
THEN 
  513         WRITE (shell%iw, 
'(i10)') shell%env_id
 
  516   END SUBROUTINE load_command
 
  523   SUBROUTINE destroy_force_env_command(shell, arg1)
 
  524      TYPE(cp2k_shell_type)                              :: shell
 
  525      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  529      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  532      IF (ierr /= 0) 
CALL print_error(
'destroy_force_env failed', shell)
 
  533   END SUBROUTINE destroy_force_env_command
 
  540   SUBROUTINE get_natom_command(shell, arg1)
 
  541      TYPE(cp2k_shell_type)                              :: shell
 
  542      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  544      INTEGER                                            :: ierr, iostat, n_atom
 
  546      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  547      CALL get_natom(shell%env_id, n_atom, ierr)
 
  548      IF (.NOT. my_assert(ierr == 0, 
'get_natom failed', shell)) 
RETURN 
  549      IF (shell%iw > 0) 
THEN 
  550         WRITE (shell%iw, 
'(i10)', iostat=iostat) n_atom
 
  553   END SUBROUTINE get_natom_command
 
  560   SUBROUTINE set_pos_command(shell, arg1)
 
  561      TYPE(cp2k_shell_type)                              :: shell
 
  562      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  564      CHARACTER(LEN=default_path_length)                 :: line
 
  565      INTEGER                                            :: ierr, iostat, n_atom
 
  566      REAL(kind=
dp), 
ALLOCATABLE, 
DIMENSION(:)           :: pos
 
  568      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  569      CALL get_natom(shell%env_id, n_atom, ierr)
 
  570      IF (.NOT. my_assert(ierr == 0, 
'get_natom failed', shell)) 
RETURN 
  571      ALLOCATE (pos(3*n_atom))
 
  572      IF (shell%iw > 0) 
THEN 
  573         READ (*, *, iostat=iostat) n_atom
 
  574         IF (.NOT. my_assert(iostat == 0, 
'setpos read n_atom failed', shell)) 
RETURN 
  575         IF (.NOT. my_assert(n_atom == 
SIZE(pos), 
'setpos invalid number of atoms', shell)) 
RETURN 
  576         READ (*, *, iostat=iostat) pos
 
  577         IF (.NOT. my_assert(iostat == 0, 
'setpos read coords failed', shell)) 
RETURN 
  578         pos(:) = pos(:)/shell%pos_fact
 
  579         READ (*, 
'(a)', iostat=iostat) line
 
  580         IF (.NOT. my_assert(iostat == 0, 
'setpos read END failed', shell)) 
RETURN 
  582         IF (.NOT. my_assert(trim(line) == 
'*END', 
'missing *END', shell)) 
RETURN 
  585      CALL send_pos_updates(shell, n_atom, pos)
 
  587   END SUBROUTINE set_pos_command
 
  595   SUBROUTINE set_pos_file_command(shell, arg1, arg2)
 
  596      TYPE(cp2k_shell_type)                              :: shell
 
  597      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1, arg2
 
  599      INTEGER                                            :: file_unit, ierr, iostat, n_atom
 
  600      REAL(kind=
dp), 
ALLOCATABLE, 
DIMENSION(:)           :: pos
 
  602      IF (.NOT. parse_env_id(arg2, shell)) 
RETURN 
  603      CALL get_natom(shell%env_id, n_atom, ierr)
 
  604      IF (.NOT. my_assert(ierr == 0, 
'get_natom failed', shell)) 
RETURN 
  605      ALLOCATE (pos(3*n_atom))
 
  607      IF (shell%iw > 0) 
THEN 
  608         CALL open_file(file_name=trim(arg1), unit_number=file_unit, &
 
  609                        file_status=
"OLD", file_form=
"FORMATTED", file_action=
"READ")
 
  610         READ (file_unit, *, iostat=iostat) n_atom
 
  611         IF (.NOT. my_assert(iostat == 0, 
'setpos read n_atom failed', shell)) 
RETURN 
  612         IF (.NOT. my_assert(n_atom == 
SIZE(pos), 
'setpos invalid number of atoms', shell)) 
RETURN 
  613         READ (file_unit, *, iostat=iostat) pos
 
  614         IF (.NOT. my_assert(iostat == 0, 
'setpos read coords failed', shell)) 
RETURN 
  615         pos(:) = pos(:)/shell%pos_fact
 
  619      CALL send_pos_updates(shell, n_atom, pos)
 
  621   END SUBROUTINE set_pos_file_command
 
  629   SUBROUTINE send_pos_updates(shell, n_atom, pos)
 
  630      TYPE(cp2k_shell_type)                              :: shell
 
  632      REAL(kind=
dp), 
DIMENSION(:)                        :: pos
 
  635      REAL(kind=
dp)                                      :: max_change
 
  636      REAL(kind=
dp), 
ALLOCATABLE, 
DIMENSION(:)           :: old_pos
 
  639      ALLOCATE (old_pos(3*n_atom))
 
  640      CALL shell%para_env%bcast(pos)
 
  641      CALL get_pos(shell%env_id, old_pos, n_el=3*n_atom, ierr=ierr)
 
  642      IF (.NOT. my_assert(ierr == 0, 
'get_pos error', shell)) 
RETURN 
  645      CALL set_pos(shell%env_id, new_pos=pos, n_el=3*n_atom, ierr=ierr)
 
  646      IF (.NOT. my_assert(ierr == 0, 
'set_pos error', shell)) 
RETURN 
  649         max_change = max(max_change, abs(pos(i) - old_pos(i)))
 
  652      IF (shell%iw > 0) 
THEN 
  653         WRITE (shell%iw, 
'(ES22.13)') max_change*shell%pos_fact
 
  656   END SUBROUTINE send_pos_updates
 
  663   SUBROUTINE set_cell_command(shell, arg1)
 
  664      TYPE(cp2k_shell_type)                              :: shell
 
  665      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  667      INTEGER                                            :: ierr, iostat
 
  668      REAL(kind=
dp), 
DIMENSION(3, 3)                     :: cell
 
  670      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  671      IF (shell%iw > 0) 
THEN 
  672         READ (*, *, iostat=iostat) cell
 
  673         IF (.NOT. my_assert(iostat == 0, 
'setcell read failed', shell)) 
RETURN 
  674         cell(:, :) = cell(:, :)/shell%pos_fact
 
  676      CALL shell%para_env%bcast(cell)
 
  677      CALL set_cell(shell%env_id, new_cell=cell, ierr=ierr)
 
  678      IF (.NOT. my_assert(ierr == 0, 
'set_cell failed', shell)) 
RETURN 
  679   END SUBROUTINE set_cell_command
 
  686   SUBROUTINE get_cell_command(shell, arg1)
 
  687      TYPE(cp2k_shell_type)                              :: shell
 
  688      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  691      REAL(kind=
dp), 
DIMENSION(3, 3)                     :: cell
 
  693      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  694      CALL get_cell(shell%env_id, cell=cell, ierr=ierr)
 
  695      IF (.NOT. my_assert(ierr == 0, 
'get_cell failed', shell)) 
RETURN 
  696      cell(:, :) = cell(:, :)*shell%pos_fact
 
  697      IF (shell%iw > 0) 
THEN 
  698         WRITE (shell%iw, 
'(9ES22.13)') cell
 
  701   END SUBROUTINE get_cell_command
 
  708   SUBROUTINE get_stress_command(shell, arg1)
 
  709      TYPE(cp2k_shell_type)                              :: shell
 
  710      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  713      REAL(kind=
dp), 
DIMENSION(3, 3)                     :: stress_tensor
 
  715      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  717      IF (.NOT. my_assert(ierr == 0, 
'get_stress_tensor failed', shell)) 
RETURN 
  718      stress_tensor(:, :) = stress_tensor(:, :)*(shell%e_fact/shell%pos_fact**3)
 
  719      IF (shell%iw > 0) 
THEN 
  720         WRITE (shell%iw, 
'(9ES22.13)') stress_tensor
 
  723   END SUBROUTINE get_stress_command
 
  730   SUBROUTINE get_pos_command(shell, arg1)
 
  731      TYPE(cp2k_shell_type)                              :: shell
 
  732      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  734      INTEGER                                            :: ierr, n_atom
 
  735      REAL(kind=
dp), 
ALLOCATABLE, 
DIMENSION(:)           :: pos
 
  737      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  738      CALL get_natom(shell%env_id, n_atom, ierr)
 
  739      IF (.NOT. my_assert(ierr == 0, 
'get_natom failed', shell)) 
RETURN 
  740      ALLOCATE (pos(3*n_atom))
 
  741      CALL get_pos(shell%env_id, pos=pos, n_el=3*n_atom, ierr=ierr)
 
  742      IF (.NOT. my_assert(ierr == 0, 
'get_pos failed', shell)) 
RETURN 
  743      IF (shell%iw > 0) 
THEN 
  744         WRITE (shell%iw, 
'(i10)') 3*n_atom
 
  745         WRITE (shell%iw, 
'(3ES22.13)') pos(:)*shell%pos_fact
 
  746         WRITE (shell%iw, 
'(a)') 
"* END" 
  750   END SUBROUTINE get_pos_command
 
  757   SUBROUTINE get_energy_command(shell, arg1)
 
  758      TYPE(cp2k_shell_type)                              :: shell
 
  759      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  762      REAL(kind=
dp)                                      :: e_pot
 
  764      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  766      IF (.NOT. my_assert(ierr == 0, 
'get_energy failed', shell)) 
RETURN 
  767      IF (shell%iw > 0) 
THEN 
  768         WRITE (shell%iw, 
'(ES22.13)') e_pot*shell%e_fact
 
  771   END SUBROUTINE get_energy_command
 
  778   SUBROUTINE eval_energy_command(shell, arg1)
 
  779      TYPE(cp2k_shell_type)                              :: shell
 
  780      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  784      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  786      IF (ierr /= 0) 
CALL print_error(
'calc_energy_force failed', shell)
 
  787   END SUBROUTINE eval_energy_command
 
  794   SUBROUTINE calc_energy_command(shell, arg1)
 
  795      TYPE(cp2k_shell_type)                              :: shell
 
  796      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  799      REAL(kind=
dp)                                      :: e_pot
 
  801      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  803      IF (.NOT. my_assert(ierr == 0, 
'calc_energy_force failed', shell)) 
RETURN 
  805      IF (.NOT. my_assert(ierr == 0, 
'get_energy failed', shell)) 
RETURN 
  806      IF (shell%iw > 0) 
THEN 
  807         WRITE (shell%iw, 
'(ES22.13)') e_pot*shell%e_fact
 
  810   END SUBROUTINE calc_energy_command
 
  817   SUBROUTINE eval_energy_force_command(shell, arg1)
 
  818      TYPE(cp2k_shell_type)                              :: shell
 
  819      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  823      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  825      IF (ierr /= 0) 
CALL print_error(
'calc_energy_force failed', shell)
 
  826   END SUBROUTINE eval_energy_force_command
 
  833   SUBROUTINE get_forces_command(shell, arg1)
 
  834      TYPE(cp2k_shell_type)                              :: shell
 
  835      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  837      INTEGER                                            :: ierr, n_atom
 
  838      REAL(kind=
dp), 
ALLOCATABLE, 
DIMENSION(:)           :: forces
 
  840      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  841      CALL get_natom(shell%env_id, n_atom, ierr)
 
  842      IF (.NOT. my_assert(ierr == 0, 
'get_natom failed', shell)) 
RETURN 
  843      ALLOCATE (forces(3*n_atom))
 
  844      CALL get_force(shell%env_id, frc=forces, n_el=3*n_atom, ierr=ierr)
 
  845      IF (.NOT. my_assert(ierr == 0, 
'get_force failed', shell)) 
RETURN 
  846      forces(:) = forces(:)*(shell%e_fact/shell%pos_fact)
 
  847      IF (shell%iw > 0) 
THEN 
  848         WRITE (shell%iw, 
'(i10)') 3*n_atom
 
  849         WRITE (shell%iw, 
'(3ES22.13)') forces
 
  850         WRITE (shell%iw, 
'("* END")')
 
  854   END SUBROUTINE get_forces_command
 
  861   SUBROUTINE calc_energy_forces_command(shell, arg1)
 
  862      TYPE(cp2k_shell_type)                              :: shell
 
  863      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  865      INTEGER                                            :: ierr, n_atom
 
  866      REAL(kind=
dp)                                      :: e_pot
 
  867      REAL(kind=
dp), 
ALLOCATABLE, 
DIMENSION(:)           :: forces
 
  869      IF (.NOT. parse_env_id(arg1, shell)) 
RETURN 
  871      IF (.NOT. my_assert(ierr == 0, 
'calc_energy_force failed', shell)) 
RETURN 
  873      IF (.NOT. my_assert(ierr == 0, 
'get_energy failed', shell)) 
RETURN 
  874      CALL get_natom(shell%env_id, n_atom, ierr)
 
  875      IF (.NOT. my_assert(ierr == 0, 
'get_natom failed', shell)) 
RETURN 
  876      ALLOCATE (forces(3*n_atom))
 
  877      CALL get_force(shell%env_id, frc=forces, n_el=3*n_atom, ierr=ierr)
 
  878      IF (.NOT. my_assert(ierr == 0, 
'get_energy failed', shell)) 
RETURN 
  879      IF (shell%iw > 0) 
THEN 
  880         WRITE (shell%iw, 
'(ES22.13)') e_pot*shell%e_fact
 
  881         WRITE (shell%iw, 
'(i10)') 3*n_atom
 
  882         WRITE (shell%iw, 
'(3ES22.13)') forces*(shell%e_fact/shell%pos_fact)
 
  883         WRITE (shell%iw, 
'("* END")')
 
  887   END SUBROUTINE calc_energy_forces_command
 
  896   SUBROUTINE run_command(shell, input_declaration, arg1, arg2)
 
  897      TYPE(cp2k_shell_type)                              :: shell
 
  899      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1, arg2
 
  901      IF (.NOT. my_assert(len_trim(arg1) > 0, 
"input-file argument missing", shell)) 
RETURN 
  902      IF (.NOT. my_assert(len_trim(arg2) > 0, 
"input-file argument missing", shell)) 
RETURN 
  903      CALL run_input(input_declaration, arg1, arg2, empty_initial_variables)
 
  904   END SUBROUTINE run_command
 
  910   SUBROUTINE set_units_ev_a(shell)
 
  911      TYPE(cp2k_shell_type)                              :: shell
 
  916   END SUBROUTINE set_units_ev_a
 
  922   SUBROUTINE set_units_au(shell)
 
  923      TYPE(cp2k_shell_type)                              :: shell
 
  925      shell%e_fact = 1.0_dp
 
  926      shell%pos_fact = 1.0_dp
 
  928   END SUBROUTINE set_units_au
 
  934   SUBROUTINE get_units(shell)
 
  935      TYPE(cp2k_shell_type)                              :: shell
 
  937      IF (shell%iw > 0) 
THEN 
  938         WRITE (shell%iw, 
'(a)') trim(shell%units)
 
  941   END SUBROUTINE get_units
 
  948   SUBROUTINE set_pwd_command(shell, arg1)
 
  949      TYPE(cp2k_shell_type)                              :: shell
 
  950      CHARACTER(LEN=*), 
INTENT(IN)                       :: arg1
 
  954      IF (.NOT. my_assert(len_trim(arg1) > 0, 
'missing directory', shell)) 
RETURN 
  956      IF (ierr /= 0) 
CALL print_error(
'changing directory failed', shell)
 
  957   END SUBROUTINE set_pwd_command
 
  963   SUBROUTINE get_pwd_command(shell)
 
  964      TYPE(cp2k_shell_type)                              :: shell
 
  966      CHARACTER(LEN=default_path_length)                 :: cwd
 
  968      IF (shell%iw > 0) 
THEN 
  970         WRITE (shell%iw, 
'(a)') trim(cwd)
 
  972   END SUBROUTINE get_pwd_command
 
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.
 
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