Skip to content

Commit

Permalink
Add i–PI server functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
FurstPlattner authored Jun 17, 2024
1 parent 9ba71be commit cd6f6b9
Show file tree
Hide file tree
Showing 13 changed files with 1,042 additions and 21 deletions.
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ list(
iao_analysis.F
iao_types.F
ipi_driver.F
ipi_environment.F
ipi_environment_types.F
ipi_server.F
iterate_matrix.F
kg_correction.F
kg_environment.F
Expand Down
12 changes: 11 additions & 1 deletion src/f77_interface.F
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ MODULE f77_interface
USE grid_api, ONLY: grid_library_finalize,&
grid_library_init
USE input_constants, ONLY: &
do_eip, do_embed, do_fist, do_mixed, do_nnp, do_qmmm, do_qmmmx, do_qs, do_sirius
do_eip, do_embed, do_fist, do_ipi, do_mixed, do_nnp, do_qmmm, do_qmmmx, do_qs, do_sirius
USE input_cp2k_check, ONLY: check_cp2k_input
USE input_cp2k_force_eval, ONLY: create_force_eval_section
USE input_cp2k_read, ONLY: empty_initial_variables,&
Expand All @@ -87,6 +87,8 @@ MODULE f77_interface
section_vals_get, section_vals_get_subs_vals, section_vals_release, &
section_vals_remove_values, section_vals_retain, section_vals_type, section_vals_val_get, &
section_vals_write
USE ipi_environment, ONLY: ipi_init
USE ipi_environment_types, ONLY: ipi_environment_type
USE kinds, ONLY: default_path_length,&
default_string_length,&
dp
Expand Down Expand Up @@ -594,6 +596,7 @@ RECURSIVE SUBROUTINE create_force_env(new_env_id, input_declaration, input_path,
TYPE(force_env_type), POINTER :: force_env, my_force_env
TYPE(fp_type), POINTER :: fp_env
TYPE(global_environment_type), POINTER :: globenv
TYPE(ipi_environment_type), POINTER :: ipi_env
TYPE(keyword_type), POINTER :: keyword
TYPE(meta_env_type), POINTER :: meta_env
TYPE(mixed_environment_type), POINTER :: mixed_env
Expand Down Expand Up @@ -868,6 +871,13 @@ RECURSIVE SUBROUTINE create_force_env(new_env_id, input_declaration, input_path,
CALL force_env_create(my_force_env, root_section, nnp_env=nnp_env, para_env=my_para_env, &
globenv=globenv, force_env_section=force_env_section)

CASE (do_ipi)
ALLOCATE (ipi_env)
CALL ipi_init(ipi_env, root_section, my_para_env, force_env_section=force_env_section, &
subsys_section=subsys_section)
CALL force_env_create(my_force_env, root_section, ipi_env=ipi_env, para_env=my_para_env, &
globenv=globenv, force_env_section=force_env_section)

CASE default
CALL create_force_eval_section(section)
keyword => section_get_keyword(section, "METHOD")
Expand Down
18 changes: 15 additions & 3 deletions src/force_env_methods.F
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ MODULE force_env_methods
USE fist_force, ONLY: fist_calc_energy_force
USE force_env_types, ONLY: &
force_env_get, force_env_get_natom, force_env_p_type, force_env_set, force_env_type, &
use_eip_force, use_embed, use_fist_force, use_mixed_force, use_nnp_force, use_prog_name, &
use_pwdft_force, use_qmmm, use_qmmmx, use_qs_force
use_eip_force, use_embed, use_fist_force, use_ipi, use_mixed_force, use_nnp_force, &
use_prog_name, use_pwdft_force, use_qmmm, use_qmmmx, use_qs_force
USE force_env_utils, ONLY: rescale_forces,&
write_atener,&
write_forces
Expand All @@ -89,6 +89,8 @@ MODULE force_env_methods
section_vals_retain,&
section_vals_type,&
section_vals_val_get
USE ipi_environment_types, ONLY: ipi_environment_type
USE ipi_server, ONLY: request_forces
USE kahan_sum, ONLY: accurate_sum
USE kinds, ONLY: default_path_length,&
default_string_length,&
Expand Down Expand Up @@ -283,6 +285,8 @@ RECURSIVE SUBROUTINE force_env_calc_energy_force(force_env, calc_force, &
calculate_forces)
CASE (use_embed)
CALL embed_energy(force_env)
CASE (use_ipi)
CALL request_forces(force_env%ipi_env)
CASE default
CPABORT("")
END SELECT
Expand Down Expand Up @@ -749,13 +753,14 @@ END SUBROUTINE force_env_calc_num_pressure
!> \param mixed_env ...
!> \param embed_env ...
!> \param nnp_env ...
!> \param ipi_env ...
!> \par History
!> 04.2003 created [fawzi]
!> \author fawzi
! **************************************************************************************************
SUBROUTINE force_env_create(force_env, root_section, para_env, globenv, fist_env, &
qs_env, meta_env, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, force_env_section, &
mixed_env, embed_env, nnp_env)
mixed_env, embed_env, nnp_env, ipi_env)
TYPE(force_env_type), POINTER :: force_env
TYPE(section_vals_type), POINTER :: root_section
Expand All @@ -774,6 +779,7 @@ SUBROUTINE force_env_create(force_env, root_section, para_env, globenv, fist_env
TYPE(mixed_environment_type), OPTIONAL, POINTER :: mixed_env
TYPE(embed_env_type), OPTIONAL, POINTER :: embed_env
TYPE(nnp_type), OPTIONAL, POINTER :: nnp_env
TYPE(ipi_environment_type), OPTIONAL, POINTER :: ipi_env
ALLOCATE (force_env)
NULLIFY (force_env%fist_env, force_env%qs_env, &
Expand Down Expand Up @@ -854,6 +860,12 @@ SUBROUTINE force_env_create(force_env, root_section, para_env, globenv, fist_env
force_env%in_use = use_nnp_force
force_env%nnp_env => nnp_env
END IF
IF (PRESENT(ipi_env)) THEN
CPASSERT(ASSOCIATED(ipi_env))
CPASSERT(force_env%in_use == 0)
force_env%in_use = use_ipi
force_env%ipi_env => ipi_env
END IF
CPASSERT(force_env%in_use /= 0)
IF (PRESENT(sub_force_env)) THEN
Expand Down
34 changes: 30 additions & 4 deletions src/force_env_types.F
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ MODULE force_env_types
section_vals_retain,&
section_vals_type,&
section_vals_val_get
USE ipi_environment_types, ONLY: ipi_env_get,&
ipi_env_release,&
ipi_environment_type
USE ipi_server, ONLY: shutdown_server
USE kinds, ONLY: dp
USE message_passing, ONLY: mp_para_env_release,&
mp_para_env_type
Expand Down Expand Up @@ -84,9 +88,10 @@ MODULE force_env_types
use_mixed_force = 506, &
use_embed = 507, &
use_pwdft_force = 508, &
use_nnp_force = 509
use_nnp_force = 509, &
use_ipi = 510

CHARACTER(LEN=10), DIMENSION(501:509), PARAMETER, PUBLIC :: &
CHARACTER(LEN=10), DIMENSION(501:510), PARAMETER, PUBLIC :: &
use_prog_name = (/ &
"FIST ", &
"QS ", &
Expand All @@ -96,7 +101,8 @@ MODULE force_env_types
"MIXED ", &
"EMBED ", &
"SIRIUS", &
"NNP "/)
"NNP ", &
"IPI "/)

PUBLIC :: force_env_type, &
force_env_p_type
Expand Down Expand Up @@ -153,6 +159,7 @@ MODULE force_env_types
TYPE(mixed_environment_type), POINTER :: mixed_env => NULL()
TYPE(nnp_type), POINTER :: nnp_env => NULL()
TYPE(embed_env_type), POINTER :: embed_env => NULL()
TYPE(ipi_environment_type), POINTER :: ipi_env => NULL()
TYPE(section_vals_type), POINTER :: force_env_section => NULL()
TYPE(section_vals_type), POINTER :: root_section => NULL()
END TYPE force_env_type
Expand Down Expand Up @@ -253,6 +260,10 @@ RECURSIVE SUBROUTINE force_env_release(force_env)
CASE (use_embed)
CALL embed_env_release(force_env%embed_env)
DEALLOCATE (force_env%embed_env)
CASE (use_ipi)
CALL shutdown_server(force_env%ipi_env)
CALL ipi_env_release(force_env%ipi_env)
DEALLOCATE (force_env%ipi_env)
END SELECT
CALL globenv_release(force_env%globenv)
CALL mp_para_env_release(force_env%para_env)
Expand All @@ -264,6 +275,7 @@ RECURSIVE SUBROUTINE force_env_release(force_env)
CPASSERT(.NOT. ASSOCIATED(force_env%mixed_env))
CPASSERT(.NOT. ASSOCIATED(force_env%nnp_env))
CPASSERT(.NOT. ASSOCIATED(force_env%embed_env))
CPASSERT(.NOT. ASSOCIATED(force_env%ipi_env))
IF (ASSOCIATED(force_env%meta_env)) THEN
CALL meta_env_release(force_env%meta_env)
DEALLOCATE (force_env%meta_env)
Expand Down Expand Up @@ -317,6 +329,7 @@ END SUBROUTINE force_env_release
!> \param mixed_env ...
!> \param nnp_env ...
!> \param embed_env ...
!> \param ipi_env ...
!> \par History
!> 04.2003 created [fawzi]
!> \author fawzi
Expand All @@ -325,7 +338,7 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, &
kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, &
qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, &
method_name_id, root_section, mixed_env, nnp_env, embed_env)
method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
TYPE(force_env_type), INTENT(IN) :: force_env
INTEGER, INTENT(out), OPTIONAL :: in_use
TYPE(fist_environment_type), OPTIONAL, POINTER :: fist_env
Expand All @@ -351,6 +364,7 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
TYPE(mixed_environment_type), OPTIONAL, POINTER :: mixed_env
TYPE(nnp_type), OPTIONAL, POINTER :: nnp_env
TYPE(embed_env_type), OPTIONAL, POINTER :: embed_env
TYPE(ipi_environment_type), OPTIONAL, POINTER :: ipi_env

REAL(KIND=dp) :: eip_kinetic_energy, eip_potential_energy
TYPE(cp_subsys_type), POINTER :: subsys_tmp
Expand All @@ -369,6 +383,7 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
CPASSERT(.NOT. PRESENT(fist_env))
CPASSERT(.NOT. PRESENT(eip_env))
CPASSERT(.NOT. PRESENT(pwdft_env))
CPASSERT(.NOT. PRESENT(ipi_env))
CALL get_qs_env(force_env%qs_env, &
energy=qs_energy, &
input=input, &
Expand All @@ -389,6 +404,7 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
CPASSERT(ASSOCIATED(force_env%eip_env))
CPASSERT(.NOT. PRESENT(qs_env))
CPASSERT(.NOT. PRESENT(fist_env))
CPASSERT(.NOT. PRESENT(ipi_env))
CALL eip_env_get(force_env%eip_env, &
eip_potential_energy=eip_potential_energy, &
eip_kinetic_energy=eip_kinetic_energy, &
Expand All @@ -402,6 +418,7 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
CPASSERT(ASSOCIATED(force_env%pwdft_env))
CPASSERT(.NOT. PRESENT(qs_env))
CPASSERT(.NOT. PRESENT(fist_env))
CPASSERT(.NOT. PRESENT(ipi_env))
CALL pwdft_env_get(force_env%pwdft_env, energy=pwdft_energy)
CALL pwdft_env_get(force_env%pwdft_env, cp_subsys=subsys)
IF (PRESENT(potential_energy)) potential_energy = pwdft_energy%etotal
Expand Down Expand Up @@ -433,10 +450,15 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
subsys=subsys)
CASE (use_nnp_force)
CPASSERT(ASSOCIATED(force_env%nnp_env))
CPASSERT(.NOT. PRESENT(ipi_env))
CALL nnp_env_get(force_env%nnp_env, &
nnp_potential_energy=potential_energy, &
subsys=subsys)
CPASSERT(.NOT. PRESENT(kinetic_energy))
CASE (use_ipi)
CALL ipi_env_get(force_env%ipi_env, &
ipi_energy=potential_energy, &
subsys=subsys)
CASE DEFAULT
CPABORT("unknown in_use flag value ")
END SELECT
Expand All @@ -459,6 +481,9 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
IF (PRESENT(nnp_env)) THEN
nnp_env => force_env%nnp_env
END IF
IF (PRESENT(ipi_env)) THEN
ipi_env => force_env%ipi_env
END IF
IF (PRESENT(para_env)) para_env => force_env%para_env
! adjust the total energy for the metadynamics
IF (ASSOCIATED(force_env%meta_env)) THEN
Expand Down Expand Up @@ -495,6 +520,7 @@ RECURSIVE SUBROUTINE force_env_get(force_env, in_use, fist_env, qs_env, &
IF (PRESENT(qmmmx_env)) qmmmx_env => force_env%qmmmx_env
IF (PRESENT(mixed_env)) mixed_env => force_env%mixed_env
IF (PRESENT(embed_env)) embed_env => force_env%embed_env
IF (PRESENT(ipi_env)) ipi_env => force_env%ipi_env
IF (PRESENT(globenv)) globenv => force_env%globenv
IF (PRESENT(root_section)) root_section => force_env%root_section

Expand Down
3 changes: 2 additions & 1 deletion src/input_constants.F
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ MODULE input_constants
do_mixed = 6, &
do_embed = 7, &
do_sirius = 8, &
do_nnp = 9
do_nnp = 9, &
do_ipi = 10

! QMMM
REAL(KIND=dp), PARAMETER, PUBLIC :: RADIUS_QMMM_DEFAULT = 0.80_dp, & ! Angstrom
Expand Down
10 changes: 6 additions & 4 deletions src/input_cp2k_force_eval.F
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ MODULE input_cp2k_force_eval
medium_print_level
USE cp_units, ONLY: cp_unit_to_cp2k
USE input_constants, ONLY: &
do_eip, do_embed, do_fist, do_mixed, do_nnp, do_qmmm, do_qs, do_sirius, &
do_eip, do_embed, do_fist, do_ipi, do_mixed, do_nnp, do_qmmm, do_qs, do_sirius, &
do_stress_analytical, do_stress_diagonal_anal, do_stress_diagonal_numer, do_stress_none, &
do_stress_numerical, numerical
USE input_cp2k_dft, ONLY: create_bsse_section,&
Expand Down Expand Up @@ -90,7 +90,8 @@ SUBROUTINE create_force_eval_section(section)
"QUICKSTEP", &
"NNP", &
"MIXED", &
"EMBED"), &
"EMBED", &
"IPI"), &
enum_desc=s2a("Alias for QUICKSTEP", &
"PW DFT using the SIRIUS library", &
"Molecular Mechanics", &
Expand All @@ -99,8 +100,9 @@ SUBROUTINE create_force_eval_section(section)
"Electronic structure methods (DFT, ...)", &
"Neural Network Potentials", &
"Use a combination of two of the above", &
"Perform an embedded calculation"), &
enum_i_vals=(/do_qs, do_sirius, do_fist, do_qmmm, do_eip, do_qs, do_nnp, do_mixed, do_embed/), &
"Perform an embedded calculation", &
"Recieve forces from i–PI client"), &
enum_i_vals=(/do_qs, do_sirius, do_fist, do_qmmm, do_eip, do_qs, do_nnp, do_mixed, do_embed, do_ipi/), &
default_i_val=do_qs)
CALL section_add_keyword(section, keyword)
CALL keyword_release(keyword)
Expand Down
Loading

0 comments on commit cd6f6b9

Please sign in to comment.