(git:374b731)
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-2024 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();
36
37/*******************************************************************************
38 * \brief Initialize CP2K without initializing MPI
39 * \warning You are supposed to call cp2k_finalize() before exiting the program.
40 ******************************************************************************/
42
43/*******************************************************************************
44 * \brief Finalize CP2K and MPI
45 ******************************************************************************/
47
48/*******************************************************************************
49 * \brief Finalize CP2K and without finalizing MPI
50 ******************************************************************************/
52
53/*******************************************************************************
54 * \brief Create a new force environment
55 * \param new_force_env the created force environment
56 * \param input_file_path Path to a CP2K input file
57 * \param output_file_path Path to a file where CP2K is going to append its
58 * output (created if non-existent)
59 * \warning You are supposed to call cp2k_destroy_force_env() to cleanup,
60 * before cp2k_finalize().
61 ******************************************************************************/
63 const char *input_file_path,
64 const char *output_file_path);
65
66/*******************************************************************************
67 * \brief Create a new force environment (custom managed MPI)
68 * \param new_force_env the created force environment
69 * \param input_file_path Path to a CP2K input file
70 * \param output_file_path Path to a file where CP2K is will write its output.
71 * Will be created if not existent, otherwise appended.
72 * \param mpi_comm Fortran MPI communicator if MPI is not managed by CP2K
73 * \warning You are supposed to call cp2k_destroy_force_env() to cleanup,
74 * before cp2k_finalize().
75 ******************************************************************************/
77 const char *input_file_path,
78 const char *output_file_path, int mpi_comm);
79
80/*******************************************************************************
81 * \brief Destroy/cleanup a force environment
82 * \param force_env the force environment
83 ******************************************************************************/
85
86/*******************************************************************************
87 * \brief Set positions of the particles
88 * \param force_env the force environment
89 * \param new_pos Array containing the new positions of the particles
90 * \param n_el Size of the new_pos array
91 ******************************************************************************/
92void cp2k_set_positions(force_env_t force_env, const double *new_pos, int n_el);
93
94/*******************************************************************************
95 * \brief Set velocity of the particles
96 * \param force_env the force environment
97 * \param new_vel Array containing the new velocities of the particles
98 * \param n_el Size of the new_vel array
99 ******************************************************************************/
100void cp2k_set_velocities(force_env_t force_env, const double *new_vel,
101 int n_el);
102
103/*******************************************************************************
104 * \brief Set the size of the cell
105 * \param force_env the force environment
106 * \param new_cell Array containing the new cell
107 ******************************************************************************/
108void cp2k_set_cell(force_env_t force_env, const double *new_cell);
109
110/*******************************************************************************
111 * \brief Get an arbitrary result as 1D array from CP2K
112 * \param force_env the force environment
113 * \param description The string tag of the result
114 * \param results Pre-allocated array
115 * \param n_el size of the results array
116 ******************************************************************************/
117void cp2k_get_result(force_env_t force_env, const char *description,
118 double *result, int n_el);
119
120/*******************************************************************************
121 * \brief Get the number of atoms
122 * \param force_env the force environment
123 * \param natom The number of atoms
124 ******************************************************************************/
125void cp2k_get_natom(force_env_t force_env, int *natom);
126
127/*******************************************************************************
128 * \brief Get the number of particles
129 * \param force_env the force environment
130 * \param nparticle The number of particles
131 ******************************************************************************/
132void cp2k_get_nparticle(force_env_t force_env, int *nparticle);
133
134/*******************************************************************************
135 * \brief Get the positions of the particles
136 * \param force_env the force environment
137 * \param pos Pre-allocated array of at least 3*nparticle elements.
138 * Use cp2k_get_nparticle() to get the number of particles.
139 * \param n_el Size of the force array
140 ******************************************************************************/
141void cp2k_get_positions(force_env_t force_env, double *pos, int n_el);
142
143/*******************************************************************************
144 * \brief Get the forces for the particles
145 * \param force_env the force environment
146 * \param force Pre-allocated array of at least 3*nparticle elements.
147 * Use cp2k_get_nparticle() to get the number of particles.
148 * \param n_el Size of the force array
149 ******************************************************************************/
150void cp2k_get_forces(force_env_t force_env, double *force, int n_el);
151
152/*******************************************************************************
153 * \brief Get the potential energy of the system
154 * \param force_env the force environment
155 * \param e_pot The potential energy
156 ******************************************************************************/
157void cp2k_get_potential_energy(force_env_t force_env, double *e_pot);
158
159/*******************************************************************************
160 * \brief Get the size of the cell
161 * \param force_env the force environment
162 * \param cell Array containing the cell
163 ******************************************************************************/
164void cp2k_get_cell(force_env_t force_env, const double *cell);
165
166/*******************************************************************************
167 * \brief Get the size of the qmmm cell
168 * \param force_env the force environment
169 * \param cell Array containing the qmmm cell
170 ******************************************************************************/
171void cp2k_get_qmmm_cell(force_env_t force_env, const double *cell);
172
173/*******************************************************************************
174 * \brief Calculate energy and forces of the system
175 * \param force_env the force environment
176 ******************************************************************************/
178
179/*******************************************************************************
180 * \brief Calculate only the energy of the system
181 * \param force_env the force environment
182 ******************************************************************************/
184
185/*******************************************************************************
186 * \brief Make a CP2K run with the given input file
187 * \param input_file_path Path to a CP2K input file
188 * \param output_file_path Path to a file where CP2K is going to append its
189 * output (created if non-existent)
190 ******************************************************************************/
191void cp2k_run_input(const char *input_file_path, const char *output_file_path);
192
193/*******************************************************************************
194 * \brief Make a CP2K run with the given input file (custom managed MPI)
195 * \param input_file_path Path to a CP2K input file
196 * \param output_file_path Path to a file where CP2K is going to append its
197 * output (created if non-existent)
198 * \param mpi_comm Fortran MPI communicator if MPI is not managed by CP2K
199 ******************************************************************************/
200void cp2k_run_input_comm(const char *input_file_path,
201 const char *output_file_path, int mpi_comm);
202
203/*******************************************************************************
204 * \brief Transport parameters read from a CP2K input file.
205 * This definition matches the respective type definition in the
206 * transport_env_types module
207 ******************************************************************************/
262
263/*******************************************************************************
264 * \brief CP2K's C-interoperable CSR matrix
265 * This definition matches the respective type definition in the
266 * transport_env_types module
267 ******************************************************************************/
281
282/*******************************************************************************
283 * \brief Function pointer type for the externally evaluated density matrix
284 * Function pointer type pointing to a C routine that takes the S and H
285 * matrices as input and outputs a P matrix.
286 *
287 * Function definition example:
288 * \code{.c}
289 * void c_scf_method(
290 * cp2k_transport_parameters cp2k_transport_params,
291 * cp2k_csr_interop_type S,
292 * cp2k_csr_interop_type KS,
293 * cp2k_csr_interop_type* P,
294 * cp2k_csr_interop_type* PImag
295 * );
296 * \endcode
297 * \sa cp2k_transport_parameters, cp2k_csr_interop_type
298 ******************************************************************************/
300 cp2k_transport_parameters, // Transport parameters
301 cp2k_csr_interop_type, // S-Matrix
302 cp2k_csr_interop_type, // H-Matrix
303 cp2k_csr_interop_type *, // P-Matrix
304 cp2k_csr_interop_type * // PImag-Matrix
305);
306
307/*******************************************************************************
308 * \brief Set the function callback for the externally evaluated density matrix
309 ******************************************************************************/
312
313/*******************************************************************************
314 * \brief Get the number of molecular orbitals in the active space
315 * \param force_env the force environment
316 * \returns The number of elements or -1 if unavailable
317 ******************************************************************************/
319
320/*******************************************************************************
321 * \brief Get the Fock submatrix for the active space
322 * \param force_env the force environment
323 * \param buf Pre-allocated array of at least mo_count^2 elements.
324 * Use `cp2k_active_space_get_mo_count()` to get the number of
325 * molecular orbitals.
326 * \param buf_len Size of the buf array
327 * \returns The number of elements written to buf or -1 if unavailable
328 ******************************************************************************/
329long int cp2k_active_space_get_fock_sub(force_env_t force_env, double *buf,
330 long int buf_len);
331
332/*******************************************************************************
333 * \brief Get the number of non-zero elements in the ERI matrix
334 * \param force_env the force environment
335 * \returns The number of elements or -1 if unavailable
336 ******************************************************************************/
338
339/*******************************************************************************
340 * \brief Get the non-zero elements of the ERI matrix
341 * The buf_coords will contain the coordinates in the format
342 * `[i1, j1, k1, l1, i2, j2, k2, l2, ... ]`.
343 *
344 * \param force_env the force environment
345 * \param buf_coords Pre-allocated array of at least 4*nze_count elements.
346 * Use `cp2k_active_space_get_eri_nze_count()` to get the
347 * number of non-zero elements.
348 * \param buf_coords_len Size of the buf_coords array
349 * \param buf_values Pre-allocated array of at least nze_count elements.
350 * Use `cp2k_active_space_get_eri_nze_count()` to get the
351 * number of non-zero elements.
352 * \param buf_values_len Size of the buf_values array
353 * \returns The number of elements written to buf_values or -1 if unavailable
354 ******************************************************************************/
355int cp2k_active_space_get_eri(force_env_t force_env, int *buf_coords,
356 long int buf_coords_len, double *buf_values,
357 long int buf_values_len);
358
359#ifdef __cplusplus
360}
361#endif
362
363#endif
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:299
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.
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_init()
Initialize 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()
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_init_without_mpi()
Initialize CP2K without initializing MPI.
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_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)
void cp2k_finalize()
Finalize CP2K and MPI.
CP2K's C-interoperable CSR matrix This definition matches the respective type definition in the trans...
Definition libcp2k.h:268
double * nzvals_local
Definition libcp2k.h:279
Transport parameters read from a CP2K input file. This definition matches the respective type definit...
Definition libcp2k.h:208
double eps_singularity_curvatures
Definition libcp2k.h:245