21 USE iso_c_binding,
ONLY: c_char,&
46#include "../base/base_uses.f90"
53 INTEGER(C_INT),
POINTER :: coords(:) => null()
54 REAL(C_DOUBLE),
POINTER :: values(:) => null()
57 PROCEDURE :: func => eri2array_func
68 CHARACTER(LEN=1, KIND=C_CHAR),
INTENT(OUT) :: version_str(*)
69 INTEGER(C_INT),
VALUE :: str_length
74 cpassert(str_length >= n + 1)
81 version_str(n + 1) = c_null_char
87 SUBROUTINE cp2k_init()
BIND(C)
92 END SUBROUTINE cp2k_init
97 SUBROUTINE cp2k_init_without_mpi()
BIND(C)
102 END SUBROUTINE cp2k_init_without_mpi
107 SUBROUTINE cp2k_finalize()
BIND(C)
112 END SUBROUTINE cp2k_finalize
117 SUBROUTINE cp2k_finalize_without_mpi()
BIND(C)
122 END SUBROUTINE cp2k_finalize_without_mpi
130 SUBROUTINE cp2k_create_force_env(new_env_id, input_file_path, output_file_path)
BIND(C)
131 INTEGER(C_INT),
INTENT(OUT) :: new_env_id
132 CHARACTER(LEN=1, KIND=C_CHAR),
INTENT(IN) :: input_file_path(*), output_file_path(*)
134 CHARACTER(LEN=default_path_length) :: ifp, ofp
135 INTEGER :: ierr, ncopied
142 NULLIFY (input_declaration)
147 END SUBROUTINE cp2k_create_force_env
156 SUBROUTINE cp2k_create_force_env_comm(new_env_id, input_file_path, output_file_path, mpi_comm)
BIND(C)
157 INTEGER(C_INT),
INTENT(OUT) :: new_env_id
158 CHARACTER(LEN=1, KIND=C_CHAR),
INTENT(IN) :: input_file_path(*), output_file_path(*)
159 INTEGER(C_INT),
VALUE :: mpi_comm
161 CHARACTER(LEN=default_path_length) :: ifp, ofp
162 INTEGER :: ierr, ncopied
170 NULLIFY (input_declaration)
172 CALL my_mpi_comm%set_handle(int(mpi_comm))
173 CALL create_force_env(new_env_id, input_declaration, ifp, ofp, my_mpi_comm, ierr=ierr)
176 END SUBROUTINE cp2k_create_force_env_comm
182 SUBROUTINE cp2k_destroy_force_env(env_id)
BIND(C)
183 INTEGER(C_INT),
VALUE :: env_id
189 END SUBROUTINE cp2k_destroy_force_env
197 SUBROUTINE cp2k_set_positions(env_id, new_pos, n_el)
BIND(C)
198 INTEGER(C_INT),
VALUE :: env_id, n_el
199 REAL(C_DOUBLE),
DIMENSION(1:n_el),
INTENT(IN) :: new_pos
203 CALL set_pos(env_id, new_pos, n_el, ierr)
205 END SUBROUTINE cp2k_set_positions
213 SUBROUTINE cp2k_set_velocities(env_id, new_vel, n_el)
BIND(C)
214 INTEGER(C_INT),
VALUE :: env_id, n_el
215 REAL(C_DOUBLE),
DIMENSION(1:n_el),
INTENT(IN) :: new_vel
219 CALL set_vel(env_id, new_vel, n_el, ierr)
221 END SUBROUTINE cp2k_set_velocities
228 SUBROUTINE cp2k_set_cell(env_id, new_cell)
BIND(C)
229 INTEGER(C_INT),
VALUE :: env_id
230 REAL(C_DOUBLE),
DIMENSION(3, 3),
INTENT(IN) :: new_cell
234 CALL set_cell(env_id, new_cell, ierr)
236 END SUBROUTINE cp2k_set_cell
245 SUBROUTINE cp2k_get_result(env_id, description, RESULT, n_el)
BIND(C)
246 INTEGER(C_INT),
VALUE :: env_id
247 CHARACTER(LEN=1, KIND=C_CHAR),
INTENT(IN) :: description(*)
248 INTEGER(C_INT),
VALUE :: n_el
249 REAL(C_DOUBLE),
DIMENSION(1:n_el),
INTENT(OUT) :: RESULT
251 CHARACTER(LEN=default_string_length) :: desc_low
252 INTEGER :: ierr, ncopied
257 CALL get_result_r1(env_id, desc_low, n_el, result, ierr=ierr)
259 END SUBROUTINE cp2k_get_result
266 SUBROUTINE cp2k_get_natom(env_id, natom)
BIND(C)
267 INTEGER(C_INT),
VALUE :: env_id
268 INTEGER(C_INT),
INTENT(OUT) :: natom
274 END SUBROUTINE cp2k_get_natom
281 SUBROUTINE cp2k_get_nparticle(env_id, nparticle)
BIND(C)
282 INTEGER(C_INT),
VALUE :: env_id
283 INTEGER(C_INT),
INTENT(OUT) :: nparticle
289 END SUBROUTINE cp2k_get_nparticle
297 SUBROUTINE cp2k_get_positions(env_id, pos, n_el)
BIND(C)
298 INTEGER(C_INT),
VALUE :: env_id, n_el
299 REAL(C_DOUBLE),
DIMENSION(1:n_el),
INTENT(OUT) :: pos
303 CALL get_pos(env_id, pos, n_el, ierr)
305 END SUBROUTINE cp2k_get_positions
313 SUBROUTINE cp2k_get_forces(env_id, force, n_el)
BIND(C)
314 INTEGER(C_INT),
VALUE :: env_id, n_el
315 REAL(C_DOUBLE),
DIMENSION(1:n_el),
INTENT(OUT) :: force
319 CALL get_force(env_id, force, n_el, ierr)
321 END SUBROUTINE cp2k_get_forces
328 SUBROUTINE cp2k_get_potential_energy(env_id, e_pot)
BIND(C)
329 INTEGER(C_INT),
VALUE :: env_id
330 REAL(C_DOUBLE),
INTENT(OUT) :: e_pot
336 END SUBROUTINE cp2k_get_potential_energy
343 SUBROUTINE cp2k_get_cell(env_id, cell)
BIND(C)
344 INTEGER(C_INT),
VALUE :: env_id
345 REAL(C_DOUBLE),
DIMENSION(3, 3),
INTENT(OUT) :: cell
349 CALL get_cell(env_id, cell=cell, ierr=ierr)
351 END SUBROUTINE cp2k_get_cell
358 SUBROUTINE cp2k_get_qmmm_cell(env_id, cell)
BIND(C)
359 INTEGER(C_INT),
VALUE :: env_id
360 REAL(C_DOUBLE),
DIMENSION(3, 3),
INTENT(OUT) :: cell
366 END SUBROUTINE cp2k_get_qmmm_cell
372 SUBROUTINE cp2k_calc_energy_force(env_id)
BIND(C)
373 INTEGER(C_INT),
VALUE :: env_id
379 END SUBROUTINE cp2k_calc_energy_force
385 SUBROUTINE cp2k_calc_energy(env_id)
BIND(C)
386 INTEGER(C_INT),
VALUE :: env_id
392 END SUBROUTINE cp2k_calc_energy
399 SUBROUTINE cp2k_run_input(input_file_path, output_file_path)
BIND(C)
400 CHARACTER(LEN=1, KIND=C_CHAR),
INTENT(IN) :: input_file_path(*), output_file_path(*)
402 CHARACTER(LEN=default_path_length) :: ifp, ofp
410 NULLIFY (input_declaration)
412 CALL run_input(input_declaration, ifp, ofp, empty_initial_variables)
414 END SUBROUTINE cp2k_run_input
422 SUBROUTINE cp2k_run_input_comm(input_file_path, output_file_path, mpi_comm)
BIND(C)
423 CHARACTER(LEN=1, KIND=C_CHAR),
INTENT(IN) :: input_file_path(*), output_file_path(*)
424 INTEGER(C_INT),
VALUE :: mpi_comm
426 CHARACTER(LEN=default_path_length) :: ifp, ofp
435 NULLIFY (input_declaration)
437 CALL my_mpi_comm%set_handle(int(mpi_comm))
438 CALL run_input(input_declaration, ifp, ofp, empty_initial_variables, my_mpi_comm)
440 END SUBROUTINE cp2k_run_input_comm
451 SUBROUTINE cp2k_transport_set_callback(f_env_id, func_ptr)
BIND(C)
452 INTEGER(C_INT),
VALUE :: f_env_id
453 TYPE(c_funptr),
VALUE :: func_ptr
455 INTEGER :: ierr, in_use
462 f_env%force_env%qs_env%transport_env%ext_c_method_ptr = func_ptr
466 END SUBROUTINE cp2k_transport_set_callback
474 INTEGER(C_INT) FUNCTION cp2k_active_space_get_mo_count(f_env_id)
RESULT(nmo)
BIND(C)
478 INTEGER(C_INT),
VALUE :: f_env_id
490 CALL get_qs_env(f_env%force_env%qs_env, active_space=active_space_env)
492 IF (.NOT.
ASSOCIATED(active_space_env)) &
495 CALL get_mo_set(active_space_env%mos_active(1), nmo=nmo)
500 END FUNCTION cp2k_active_space_get_mo_count
510 INTEGER(C_LONG) FUNCTION cp2k_active_space_get_fock_sub(f_env_id, buf, buf_len)
RESULT(nelem)
BIND(C)
514 INTEGER(C_INT),
VALUE :: f_env_id
515 INTEGER(C_LONG),
VALUE :: buf_len
516 REAL(C_DOUBLE),
DIMENSION(0:buf_len-1), &
519 INTEGER :: i, ierr, j, norb
520 REAL(C_DOUBLE) :: mval
522 TYPE(f_env_type),
POINTER :: f_env
527 CALL f_env_add_defaults(f_env_id, f_env)
530 CALL get_qs_env(f_env%force_env%qs_env, active_space=active_space_env)
532 IF (.NOT.
ASSOCIATED(active_space_env)) &
535 CALL get_mo_set(active_space_env%mos_active(1), nmo=norb)
537 IF (buf_len < norb*norb) &
542 CALL cp_fm_get_element(active_space_env%fock_sub(1), i + 1, j + 1, mval)
543 buf(norb*i + j) = mval
544 buf(norb*j + i) = mval
552 CALL f_env_rm_defaults(f_env, ierr)
554 END FUNCTION cp2k_active_space_get_fock_sub
562 INTEGER(C_LONG) FUNCTION cp2k_active_space_get_eri_nze_count(f_env_id)
RESULT(nze_count)
BIND(C)
565 INTEGER(C_INT),
VALUE :: f_env_id
569 TYPE(f_env_type),
POINTER :: f_env
574 CALL f_env_add_defaults(f_env_id, f_env)
577 CALL get_qs_env(f_env%force_env%qs_env, active_space=active_space_env)
579 IF (.NOT.
ASSOCIATED(active_space_env)) &
582 nze_count = int(active_space_env%eri%eri(1)%csr_mat%nze_total, kind(nze_count))
585 CALL f_env_rm_defaults(f_env, ierr)
587 END FUNCTION cp2k_active_space_get_eri_nze_count
599 INTEGER(C_LONG) FUNCTION cp2k_active_space_get_eri(f_env_id, &
600 buf_coords, buf_coords_len, &
601 buf_values, buf_values_len)
RESULT(nelem)
BIND(C)
605 INTEGER(C_INT),
INTENT(IN),
VALUE :: f_env_id
606 INTEGER(C_LONG),
INTENT(IN),
VALUE :: buf_coords_len
607 INTEGER(C_INT),
INTENT(OUT),
TARGET :: buf_coords(1:buf_coords_len)
608 INTEGER(C_LONG),
INTENT(IN),
VALUE :: buf_values_len
609 REAL(C_DOUBLE),
INTENT(OUT),
TARGET :: buf_values(1:buf_values_len)
613 TYPE(f_env_type),
POINTER :: f_env
618 CALL f_env_add_defaults(f_env_id, f_env)
621 CALL get_qs_env(f_env%force_env%qs_env, active_space=active_space_env)
623 IF (.NOT.
ASSOCIATED(active_space_env)) &
626 associate(nze => active_space_env%eri%eri(1)%csr_mat%nze_total)
627 IF (buf_coords_len < 4*nze .OR. buf_values_len < nze) &
630 CALL active_space_env%eri%eri_foreach(1, active_space_env%active_orbitals, eri2array(buf_coords, buf_values))
632 nelem = int(nze, kind(nelem))
636 CALL f_env_rm_defaults(f_env, ierr)
638 END FUNCTION cp2k_active_space_get_eri
651 LOGICAL FUNCTION eri2array_func(this, i, j, k, l, val)
RESULT(cont)
652 CLASS(eri2array),
INTENT(inout) :: this
653 INTEGER,
INTENT(in) :: i, j, k, l
654 REAL(KIND=dp),
INTENT(in) :: val
656 this%coords(4*(this%idx - 1) + 1) = i
657 this%coords(4*(this%idx - 1) + 2) = j
658 this%coords(4*(this%idx - 1) + 3) = k
659 this%coords(4*(this%idx - 1) + 4) = l
660 this%values(this%idx) = val
662 this%idx = this%idx + 1
665 END FUNCTION eri2array_func
some minimal info about CP2K, including its version and license
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
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_element(matrix, irow_global, icol_global, alpha, local)
returns an element of a fm this value is valid on every cpu using this call is expensive
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 set_vel(env_id, new_vel, n_el, ierr)
sets the velocities of the particles
subroutine, public get_nparticle(env_id, n_particle, ierr)
returns the number of particles in the given force env
subroutine, public get_natom(env_id, n_atom, ierr)
returns the number of atoms in the given force env
subroutine, public f_env_add_defaults(f_env_id, f_env, handle)
adds the default environments of the f_env to the stack of the defaults, and returns a new error and ...
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 init_cp2k(init_mpi, ierr)
initializes cp2k, needs to be called once before using any of the other functions when using cp2k as ...
subroutine, public get_qmmm_cell(env_id, cell, ierr)
gets the qmmm cell
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 get_result_r1(env_id, description, n, result, res_exist, ierr)
gets a result from CP2K that is a real 1D array
subroutine, public set_cell(env_id, new_cell, ierr)
sets a new cell
subroutine, public finalize_cp2k(finalize_mpi, ierr)
cleanup after you have finished using this interface
subroutine, public set_pos(env_id, new_pos, n_el, ierr)
sets the positions of the particles
subroutine, public f_env_rm_defaults(f_env, ierr, handle)
removes the default environments of the f_env to the stack of the defaults, and sets ierr accordingly...
subroutine, public get_force(env_id, frc, n_el, ierr)
gets the forces of the particles
Interface for the force calculations.
recursive subroutine, public 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, ipi_env)
returns various attributes about the force environment
integer, parameter, public use_qs_force
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
integer, parameter, public default_path_length
subroutine cp2k_get_version(version_str, str_length)
...
Interface to the message passing library MPI.
The types needed for the calculation of active space Hamiltonians.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Definition and initialisation of the mo data type.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Utilities for string manipulations.
integer function, public strlcpy_c2f(fstring, cstring)
Copy the content of a \0-terminated C-string to a finite-length Fortran string.
Abstract function object for the eri_type_eri_foreach method.