(git:e68414f)
Loading...
Searching...
No Matches
libcp2k.h
Go to the documentation of this file.
1/*----------------------------------------------------------------------------*/
2/* CP2K: A general program to perform molecular dynamics simulations */
3/* Copyright 2000-2025 CP2K developers group <https://cp2k.org> */
4/* */
5/* SPDX-License-Identifier: GPL-2.0-or-later */
6/*----------------------------------------------------------------------------*/
7
8#include <stdbool.h>
9
10/*******************************************************************************
11 * \brief Definitions for the functions exported in libcp2k.F
12 * \author Mohammad Hossein Bani-Hashemian
13 ******************************************************************************/
14
15#ifndef LIBCP2K_H
16#define LIBCP2K_H
17
18#ifdef __cplusplus
19extern "C" {
20#endif
21
22typedef int force_env_t;
23
24/*******************************************************************************
25 * \brief Get the CP2K version string
26 * \param version_str The buffer to write the version string into
27 * \param str_length The size of the buffer (must be large enough)
28 ******************************************************************************/
29void cp2k_get_version(char *version_str, int str_length);
30
31/*******************************************************************************
32 * \brief Initialize CP2K and MPI
33 * \warning You are supposed to call cp2k_finalize() before exiting the program.
34 ******************************************************************************/
35void cp2k_init(void);
36
37/*******************************************************************************
38 * \brief Initialize CP2K without initializing MPI (on MPI_COMM_WORLD)
39 * \warning You are supposed to call cp2k_finalize() before exiting the program.
40 ******************************************************************************/
42
43/*******************************************************************************
44 * \brief Initialize CP2K without initializing MPI on the given comm
45 * \warning You are supposed to call cp2k_finalize() before exiting the program.
46 * \param mpi_comm Fortran MPI communicator if MPI is not managed by CP2K
47 ******************************************************************************/
48void cp2k_init_without_mpi_comm(int mpi_comm);
49
50/*******************************************************************************
51 * \brief Finalize CP2K and MPI
52 ******************************************************************************/
53void cp2k_finalize(void);
54
55/*******************************************************************************
56 * \brief Finalize CP2K and without finalizing MPI
57 ******************************************************************************/
59
60/*******************************************************************************
61 * \brief Create a new force environment
62 * \param new_force_env the created force environment
63 * \param input_file_path Path to a CP2K input file
64 * \param output_file_path Path to a file where CP2K is going to append its
65 * output (created if non-existent)
66 * \warning You are supposed to call cp2k_destroy_force_env() to cleanup,
67 * before cp2k_finalize().
68 ******************************************************************************/
70 const char *input_file_path,
71 const char *output_file_path);
72
73/*******************************************************************************
74 * \brief Create a new force environment (custom managed MPI)
75 * \param new_force_env the created force environment
76 * \param input_file_path Path to a CP2K input file
77 * \param output_file_path Path to a file where CP2K is will write its output.
78 * Will be created if not existent, otherwise appended.
79 * \param mpi_comm Fortran MPI communicator if MPI is not managed by CP2K
80 * \warning You are supposed to call cp2k_destroy_force_env() to cleanup,
81 * before cp2k_finalize().
82 ******************************************************************************/
84 const char *input_file_path,
85 const char *output_file_path, int mpi_comm);
86
87/*******************************************************************************
88 * \brief Destroy/cleanup a force environment
89 * \param force_env the force environment
90 ******************************************************************************/
92
93/*******************************************************************************
94 * \brief Set positions of the particles
95 * \param force_env the force environment
96 * \param new_pos Array containing the new positions of the particles
97 * \param n_el Size of the new_pos array
98 ******************************************************************************/
99void cp2k_set_positions(force_env_t force_env, const double *new_pos, int n_el);
100
101/*******************************************************************************
102 * \brief Set velocity of the particles
103 * \param force_env the force environment
104 * \param new_vel Array containing the new velocities of the particles
105 * \param n_el Size of the new_vel array
106 ******************************************************************************/
107void cp2k_set_velocities(force_env_t force_env, const double *new_vel,
108 int n_el);
109
110/*******************************************************************************
111 * \brief Set the size of the cell
112 * \param force_env the force environment
113 * \param new_cell Array containing the new cell
114 ******************************************************************************/
115void cp2k_set_cell(force_env_t force_env, const double *new_cell);
116
117/*******************************************************************************
118 * \brief Get an arbitrary result as 1D array from CP2K
119 * \param force_env the force environment
120 * \param description The string tag of the result
121 * \param results Pre-allocated array
122 * \param n_el size of the results array
123 ******************************************************************************/
124void cp2k_get_result(force_env_t force_env, const char *description,
125 double *result, int n_el);
126
127/*******************************************************************************
128 * \brief Get the number of atoms
129 * \param force_env the force environment
130 * \param natom The number of atoms
131 ******************************************************************************/
132void cp2k_get_natom(force_env_t force_env, int *natom);
133
134/*******************************************************************************
135 * \brief Get the number of particles
136 * \param force_env the force environment
137 * \param nparticle The number of particles
138 ******************************************************************************/
139void cp2k_get_nparticle(force_env_t force_env, int *nparticle);
140
141/*******************************************************************************
142 * \brief Get the positions of the particles
143 * \param force_env the force environment
144 * \param pos Pre-allocated array of at least 3*nparticle elements.
145 * Use cp2k_get_nparticle() to get the number of particles.
146 * \param n_el Size of the force array
147 ******************************************************************************/
148void cp2k_get_positions(force_env_t force_env, double *pos, int n_el);
149
150/*******************************************************************************
151 * \brief Get the forces for the particles
152 * \param force_env the force environment
153 * \param force Pre-allocated array of at least 3*nparticle elements.
154 * Use cp2k_get_nparticle() to get the number of particles.
155 * \param n_el Size of the force array
156 ******************************************************************************/
157void cp2k_get_forces(force_env_t force_env, double *force, int n_el);
158
159/*******************************************************************************
160 * \brief Get the potential energy of the system
161 * \param force_env the force environment
162 * \param e_pot The potential energy
163 ******************************************************************************/
164void cp2k_get_potential_energy(force_env_t force_env, double *e_pot);
165
166/*******************************************************************************
167 * \brief Get the size of the cell
168 * \param force_env the force environment
169 * \param cell Array containing the cell
170 ******************************************************************************/
171void cp2k_get_cell(force_env_t force_env, const double *cell);
172
173/*******************************************************************************
174 * \brief Get the size of the qmmm cell
175 * \param force_env the force environment
176 * \param cell Array containing the qmmm cell
177 ******************************************************************************/
178void cp2k_get_qmmm_cell(force_env_t force_env, const double *cell);
179
180/*******************************************************************************
181 * \brief Calculate energy and forces of the system
182 * \param force_env the force environment
183 ******************************************************************************/
185
186/*******************************************************************************
187 * \brief Calculate only the energy of the system
188 * \param force_env the force environment
189 ******************************************************************************/
191
192/*******************************************************************************
193 * \brief Make a CP2K run with the given input file
194 * \param input_file_path Path to a CP2K input file
195 * \param output_file_path Path to a file where CP2K is going to append its
196 * output (created if non-existent)
197 ******************************************************************************/
198void cp2k_run_input(const char *input_file_path, const char *output_file_path);
199
200/*******************************************************************************
201 * \brief Make a CP2K run with the given input file (custom managed MPI)
202 * \param input_file_path Path to a CP2K input file
203 * \param output_file_path Path to a file where CP2K is going to append its
204 * output (created if non-existent)
205 * \param mpi_comm Fortran MPI communicator if MPI is not managed by CP2K
206 ******************************************************************************/
207void cp2k_run_input_comm(const char *input_file_path,
208 const char *output_file_path, int mpi_comm);
209
210/*******************************************************************************
211 * \brief Transport parameters read from a CP2K input file.
212 * This definition matches the respective type definition in the
213 * transport_env_types module
214 ******************************************************************************/
269
270/*******************************************************************************
271 * \brief CP2K's C-interoperable CSR matrix
272 * This definition matches the respective type definition in the
273 * transport_env_types module
274 ******************************************************************************/
288
289/*******************************************************************************
290 * \brief Function pointer type for the externally evaluated density matrix
291 * Function pointer type pointing to a C routine that takes the S and H
292 * matrices as input and outputs a P matrix.
293 *
294 * Function definition example:
295 * \code{.c}
296 * void c_scf_method(
297 * cp2k_transport_parameters cp2k_transport_params,
298 * cp2k_csr_interop_type S,
299 * cp2k_csr_interop_type KS,
300 * cp2k_csr_interop_type* P,
301 * cp2k_csr_interop_type* PImag
302 * );
303 * \endcode
304 * \sa cp2k_transport_parameters, cp2k_csr_interop_type
305 ******************************************************************************/
307 cp2k_transport_parameters, // Transport parameters
308 cp2k_csr_interop_type, // S-Matrix
309 cp2k_csr_interop_type, // H-Matrix
310 cp2k_csr_interop_type *, // P-Matrix
311 cp2k_csr_interop_type * // PImag-Matrix
312);
313
314/*******************************************************************************
315 * \brief Set the function callback for the externally evaluated density matrix
316 ******************************************************************************/
319
320/*******************************************************************************
321 * \brief Get the number of molecular orbitals in the active space
322 * \param force_env the force environment
323 * \returns The number of elements or -1 if unavailable
324 ******************************************************************************/
326
327/*******************************************************************************
328 * \brief Get the Fock submatrix for the active space
329 * \param force_env the force environment
330 * \param buf Pre-allocated array of at least mo_count^2 elements.
331 * Use `cp2k_active_space_get_mo_count()` to get the number of
332 * molecular orbitals.
333 * \param buf_len Size of the buf array
334 * \returns The number of elements written to buf or -1 if unavailable
335 ******************************************************************************/
336long int cp2k_active_space_get_fock_sub(force_env_t force_env, double *buf,
337 long int buf_len);
338
339/*******************************************************************************
340 * \brief Get the number of non-zero elements in the ERI matrix
341 * \param force_env the force environment
342 * \returns The number of elements or -1 if unavailable
343 ******************************************************************************/
345
346/*******************************************************************************
347 * \brief Get the non-zero elements of the ERI matrix
348 * The buf_coords will contain the coordinates in the format
349 * `[i1, j1, k1, l1, i2, j2, k2, l2, ... ]`.
350 *
351 * \param force_env the force environment
352 * \param buf_coords Pre-allocated array of at least 4*nze_count elements.
353 * Use `cp2k_active_space_get_eri_nze_count()` to get the
354 * number of non-zero elements.
355 * \param buf_coords_len Size of the buf_coords array
356 * \param buf_values Pre-allocated array of at least nze_count elements.
357 * Use `cp2k_active_space_get_eri_nze_count()` to get the
358 * number of non-zero elements.
359 * \param buf_values_len Size of the buf_values array
360 * \returns The number of elements written to buf_values or -1 if unavailable
361 ******************************************************************************/
362int cp2k_active_space_get_eri(force_env_t force_env, int *buf_coords,
363 long int buf_coords_len, double *buf_values,
364 long int buf_values_len);
365
366#ifdef __cplusplus
367}
368#endif
369
370#endif
void cp2k_init_without_mpi(void)
Initialize CP2K without initializing MPI (on MPI_COMM_WORLD)
void cp2k_create_force_env(force_env_t *new_force_env, const char *input_file_path, const char *output_file_path)
Create a new force environment.
int cp2k_active_space_get_mo_count(force_env_t force_env)
Get the number of molecular orbitals in the active space.
void cp2k_get_qmmm_cell(force_env_t force_env, const double *cell)
Get the size of the qmmm cell.
void(* ext_method_callback_f_ptr)(cp2k_transport_parameters, cp2k_csr_interop_type, cp2k_csr_interop_type, cp2k_csr_interop_type *, cp2k_csr_interop_type *)
Function pointer type for the externally evaluated density matrix Function pointer type pointing to a...
Definition libcp2k.h:306
void cp2k_run_input_comm(const char *input_file_path, const char *output_file_path, int mpi_comm)
Make a CP2K run with the given input file (custom managed MPI)
void cp2k_run_input(const char *input_file_path, const char *output_file_path)
Make a CP2K run with the given input file.
void cp2k_transport_set_callback(force_env_t force_env, ext_method_callback_f_ptr func)
Set the function callback for the externally evaluated density matrix.
void cp2k_get_forces(force_env_t force_env, double *force, int n_el)
Get the forces for the particles.
void cp2k_get_version(char *version_str, int str_length)
Get the CP2K version string.
void cp2k_set_positions(force_env_t force_env, const double *new_pos, int n_el)
Set positions of the particles.
int force_env_t
Definitions for the functions exported in libcp2k.F.
Definition libcp2k.h:22
long int cp2k_active_space_get_fock_sub(force_env_t force_env, double *buf, long int buf_len)
Get the Fock submatrix for the active space.
void cp2k_set_velocities(force_env_t force_env, const double *new_vel, int n_el)
Set velocity of the particles.
void cp2k_get_natom(force_env_t force_env, int *natom)
Get the number of atoms.
void cp2k_init(void)
Initialize CP2K and MPI.
int cp2k_active_space_get_eri(force_env_t force_env, int *buf_coords, long int buf_coords_len, double *buf_values, long int buf_values_len)
Get the non-zero elements of the ERI matrix The buf_coords will contain the coordinates in the format...
long int cp2k_active_space_get_eri_nze_count(force_env_t force_env)
Get the number of non-zero elements in the ERI matrix.
void cp2k_finalize(void)
Finalize CP2K and MPI.
void cp2k_get_positions(force_env_t force_env, double *pos, int n_el)
Get the positions of the particles.
void cp2k_finalize_without_mpi(void)
Finalize CP2K and without finalizing MPI.
void cp2k_get_nparticle(force_env_t force_env, int *nparticle)
Get the number of particles.
void cp2k_destroy_force_env(force_env_t force_env)
Destroy/cleanup a force environment.
void cp2k_get_cell(force_env_t force_env, const double *cell)
Get the size of the cell.
void cp2k_set_cell(force_env_t force_env, const double *new_cell)
Set the size of the cell.
void cp2k_get_result(force_env_t force_env, const char *description, double *result, int n_el)
Get an arbitrary result as 1D array from CP2K.
void cp2k_calc_energy_force(force_env_t force_env)
Calculate energy and forces of the system.
void cp2k_get_potential_energy(force_env_t force_env, double *e_pot)
Get the potential energy of the system.
void cp2k_calc_energy(force_env_t force_env)
Calculate only the energy of the system.
void cp2k_init_without_mpi_comm(int mpi_comm)
Initialize CP2K without initializing MPI on the given comm.
void cp2k_create_force_env_comm(force_env_t *new_force_env, const char *input_file_path, const char *output_file_path, int mpi_comm)
Create a new force environment (custom managed MPI)
CP2K's C-interoperable CSR matrix This definition matches the respective type definition in the trans...
Definition libcp2k.h:275
double * nzvals_local
Definition libcp2k.h:286
Transport parameters read from a CP2K input file. This definition matches the respective type definit...
Definition libcp2k.h:215
double eps_singularity_curvatures
Definition libcp2k.h:252