Definition of the public C-API of dftd4
/* This file is part of dftd4.
* SPDX-Identifier: LGPL-3.0-or-later
*
* dftd4 is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* dftd4 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with dftd4. If not, see <https://www.gnu.org/licenses/>.
**/
#pragma once
#ifdef __cplusplus
#define DFTD4_API_ENTRY extern "C"
#else
#define DFTD4_API_ENTRY extern
#ifndef DFTD4_CFFI
#include <stdbool.h>
#endif
#endif
#define DFTD4_API_CALL
#define DFTD4_API_SUFFIX__V_3_0
#define DFTD4_API_SUFFIX__V_3_1
#define DFTD4_API_SUFFIX__V_3_2
#define DFTD4_API_SUFFIX__V_3_3
#define DFTD4_API_SUFFIX__V_3_4
#define DFTD4_API_SUFFIX__V_3_5
#define DFTD4_API_SUFFIX__V_4_0
/// Error handle class
typedef struct _dftd4_error* dftd4_error;
/// Molecular structure data class
typedef struct _dftd4_structure* dftd4_structure;
/// Dispersion model class
typedef struct _dftd4_model* dftd4_model;
/// Damping parameter class
typedef struct _dftd4_param* dftd4_param;
/*
* Type generic macro for convenience
**/
#define dftd4_delete(ptr) _Generic((ptr), \
dftd4_error: dftd4_delete_error, \
dftd4_structure: dftd4_delete_structure, \
dftd4_model: dftd4_delete_model, \
dftd4_param: dftd4_delete_param \
)(&ptr)
/*
* Global API queries
**/
/// Obtain library version as major * 10000 + minor + 100 + patch
DFTD4_API_ENTRY int DFTD4_API_CALL
dftd4_get_version(void) DFTD4_API_SUFFIX__V_3_0;
/*
* Error handle class
**/
/// Create new error handle object
DFTD4_API_ENTRY dftd4_error DFTD4_API_CALL
dftd4_new_error(void) DFTD4_API_SUFFIX__V_3_0;
/// Check error handle status
DFTD4_API_ENTRY int DFTD4_API_CALL
dftd4_check_error(dftd4_error /* error */) DFTD4_API_SUFFIX__V_3_0;
/// Get error message from error handle
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_get_error(dftd4_error /* error */,
char* /* buffer */,
const int* /* buffersize */) DFTD4_API_SUFFIX__V_3_0;
/// Delete error handle object
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_delete_error(dftd4_error* /* error */) DFTD4_API_SUFFIX__V_3_0;
/*
* Molecular structure data class
**/
/// Create new molecular structure data (quantities in Bohr)
DFTD4_API_ENTRY dftd4_structure DFTD4_API_CALL
dftd4_new_structure(dftd4_error /* error */,
const int /* natoms */,
const int* /* numbers [natoms] */,
const double* /* positions [natoms][3] */,
const double* /* charge */,
const double* /* lattice [3][3] */,
const bool* /* periodic [3] */) DFTD4_API_SUFFIX__V_3_0;
/// Delete molecular structure data
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_delete_structure(dftd4_structure* /* mol */) DFTD4_API_SUFFIX__V_3_0;
/// Update coordinates and lattice parameters (quantities in Bohr)
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_update_structure(dftd4_error /* error */,
dftd4_structure /* mol */,
const double* /* positions [natoms][3] */,
const double* /* lattice [3][3] */) DFTD4_API_SUFFIX__V_3_0;
/*
* Dispersion model class
**/
/// Create new D4 dispersion model
DFTD4_API_ENTRY dftd4_model DFTD4_API_CALL
dftd4_new_d4_model(dftd4_error /* error */,
dftd4_structure /* mol */) DFTD4_API_SUFFIX__V_3_0;
/// Create new D4 dispersion model
DFTD4_API_ENTRY dftd4_model DFTD4_API_CALL
dftd4_new_d4s_model(dftd4_error /* error */,
dftd4_structure /* mol */) DFTD4_API_SUFFIX__V_4_0;
/// Create new D4 dispersion model
DFTD4_API_ENTRY dftd4_model DFTD4_API_CALL
dftd4_custom_d4_model(dftd4_error /* error */,
dftd4_structure /* mol */,
double /* ga */,
double /* gc */,
double /* wf */) DFTD4_API_SUFFIX__V_3_1;
/// Create new D4 dispersion model
DFTD4_API_ENTRY dftd4_model DFTD4_API_CALL
dftd4_custom_d4s_model(dftd4_error /* error */,
dftd4_structure /* mol */,
double /* ga */,
double /* gc */) DFTD4_API_SUFFIX__V_4_0;
/// Delete dispersion model
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_delete_model(dftd4_model* /* disp */) DFTD4_API_SUFFIX__V_3_0;
/*
* Damping parameter class
**/
/// Create new rational damping parameters
DFTD4_API_ENTRY dftd4_param DFTD4_API_CALL
dftd4_new_rational_damping(dftd4_error /* error */,
double /* s6 */,
double /* s8 */,
double /* s9 */,
double /* a1 */,
double /* a2 */,
double /* alp */) DFTD4_API_SUFFIX__V_3_0;
/// Load rational damping parameters from internal storage
DFTD4_API_ENTRY dftd4_param DFTD4_API_CALL
dftd4_load_rational_damping(dftd4_error /* error */,
char* /* method */,
bool /* mdb */) DFTD4_API_SUFFIX__V_3_0;
/// Delete damping parameters
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_delete_param(dftd4_param* /* param */) DFTD4_API_SUFFIX__V_3_0;
/*
* Perform dispersion calculations
**/
/// Evaluate properties related to the dispersion model
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_get_properties(dftd4_error /* error */,
dftd4_structure /* mol */,
dftd4_model /* disp */,
double* /* cn[n] */,
double* /* charges[n] */,
double* /* c6[n*n] */,
double* /* alpha[n] */) DFTD4_API_SUFFIX__V_3_1;
/// Evaluate the dispersion energy and its derivative
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_get_dispersion(dftd4_error /* error */,
dftd4_structure /* mol */,
dftd4_model /* disp */,
dftd4_param /* param */,
double* /* energy */,
double* /* gradient[n][3] */,
double* /* sigma[3][3] */) DFTD4_API_SUFFIX__V_3_0;
/// Evaluate the dispersion hessian numerically
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_get_numerical_hessian(dftd4_error /* error */,
dftd4_structure /* mol */,
dftd4_model /* disp */,
dftd4_param /* param */,
double* /* hess[n][3][n][3] */) DFTD4_API_SUFFIX__V_3_5;
/// Evaluate the pairwise representation of the dispersion energy
DFTD4_API_ENTRY void DFTD4_API_CALL
dftd4_get_pairwise_dispersion(dftd4_error /* error */,
dftd4_structure /* mol */,
dftd4_model /* disp */,
dftd4_param /* param */,
double* /* pair_energy2[n][n] */,
double* /* pair_energy3[n][n] */) DFTD4_API_SUFFIX__V_3_2;
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
logical, | private, | parameter | :: | debug | = | .false. | |
character(len=*), | private, | parameter | :: | namespace | = | "dftd4_" |
Namespace for C routines |
Void pointer to error handle
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(error_type), | public, | allocatable | :: | ptr |
Actual payload |
Void pointer to dispersion model
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
class(dispersion_model), | public, | allocatable | :: | ptr |
Actual payload |
Void pointer to damping parameters
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
class(damping_param), | public, | allocatable | :: | ptr |
Actual payload |
Void pointer to molecular structure data
Type | Visibility | Attributes | Name | Initial | |||
---|---|---|---|---|---|---|---|
type(structure_type), | public | :: | ptr |
Actual payload |
Check error handle status
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror |
Create new custom D4 dispersion model
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
real(kind=c_double), | intent(in), | value | :: | ga | ||
real(kind=c_double), | intent(in), | value | :: | gc | ||
real(kind=c_double), | intent(in), | value | :: | wf |
Create new custom D4S dispersion model
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
real(kind=c_double), | intent(in), | value | :: | ga | ||
real(kind=c_double), | intent(in), | value | :: | gc |
Obtain library version as major * 10000 + minor + 100 + patch
Load rational damping parameters from internal storage
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
character(kind=c_char, len=1), | intent(in) | :: | charptr(*) | |||
logical(kind=c_bool), | intent(in), | value | :: | atm |
Create new D4 dispersion model
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol |
Create new D4S dispersion model
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol |
Create new error handle object
Create new rational damping parameters
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
real(kind=c_double), | intent(in), | value | :: | s6 | ||
real(kind=c_double), | intent(in), | value | :: | s8 | ||
real(kind=c_double), | intent(in), | value | :: | s9 | ||
real(kind=c_double), | intent(in), | value | :: | a1 | ||
real(kind=c_double), | intent(in), | value | :: | a2 | ||
real(kind=c_double), | intent(in), | value | :: | alp |
Create new molecular structure data (quantities in Bohr)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
integer(kind=c_int), | intent(in), | value | :: | natoms | ||
integer(kind=c_int), | intent(in) | :: | numbers(natoms) | |||
real(kind=c_double), | intent(in) | :: | positions(3,natoms) | |||
real(kind=c_double), | intent(in), | optional | :: | c_charge | ||
real(kind=c_double), | intent(in), | optional | :: | c_lattice(3,3) | ||
logical(kind=c_bool), | intent(in), | optional | :: | c_periodic(3) |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=c_char, len=1), | intent(in) | :: | rhs(*) | |||
character(kind=c_char, len=:), | intent(out), | allocatable | :: | lhs |
Delete error handle object
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(inout) | :: | verror |
Delete dispersion model
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(inout) | :: | vdisp |
Delete damping parameters
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(inout) | :: | vparam |
Delete molecular structure data
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(inout) | :: | vmol |
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | rhs | |||
character(kind=c_char, len=1), | intent(out) | :: | lhs(*) | |||
integer, | intent(in) | :: | len |
Calculate dispersion
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
type(c_ptr), | value | :: | vdisp | |||
type(c_ptr), | value | :: | vparam | |||
real(kind=c_double), | intent(out) | :: | energy | |||
real(kind=c_double), | intent(out), | optional | :: | c_gradient(3,*) | ||
real(kind=c_double), | intent(out), | optional | :: | c_sigma(3,3) |
Get error message from error handle
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
character(kind=c_char, len=1), | intent(inout) | :: | charptr(*) | |||
integer(kind=c_int), | intent(in), | optional | :: | buffersize |
Calculate hessian numerically
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
type(c_ptr), | value | :: | vdisp | |||
type(c_ptr), | value | :: | vparam | |||
real(kind=c_double), | intent(out) | :: | c_hessian(*) |
Calculate pairwise representation of dispersion energy
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
type(c_ptr), | value | :: | vdisp | |||
type(c_ptr), | value | :: | vparam | |||
type(c_ptr), | intent(in), | value | :: | c_pair_energy2 | ||
type(c_ptr), | intent(in), | value | :: | c_pair_energy3 |
Calculate dispersion
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
type(c_ptr), | value | :: | vdisp | |||
real(kind=c_double), | intent(out), | optional | :: | c_cn(*) | ||
real(kind=c_double), | intent(out), | optional | :: | c_charges(*) | ||
real(kind=c_double), | intent(out), | optional | :: | c_c6(*) | ||
real(kind=c_double), | intent(out), | optional | :: | c_alpha(*) |
Update coordinates and lattice parameters (quantities in Bohr)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | value | :: | verror | |||
type(c_ptr), | value | :: | vmol | |||
real(kind=c_double), | intent(in) | :: | positions(3,*) | |||
real(kind=c_double), | intent(in), | optional | :: | lattice(3,3) |
Cold fusion check
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(error_type), | intent(out), | allocatable | :: | error | ||
type(structure_type), | intent(in) | :: | mol |