@@ -7,39 +7,304 @@ The API user is required delete all objects created in the library by using the
77
88Overall four classes of objects are provided by the library
99
10- - error handlers (`` dftd3_error ` `),
10+ - error handlers (:c:type: ` dftd3_error `),
1111 used to communicate exceptional conditions and errors from the library to the user
12- - structure containers (`` dftd3_structure ` `),
12+ - structure containers (:c:type: ` dftd3_structure `),
1313 used to represent the system specific information and geometry data,
1414 only the latter are mutable for the user
15- - dispersion model objects (`` dftd3_model ` `),
15+ - dispersion model objects (:c:type: ` dftd3_model `),
1616 general model for calculating dispersion releated properties
17- - damping function objects (`` dftd3_param ` `)
17+ - damping function objects (:c:type: ` dftd3_param `)
1818 polymorphic objects to represent the actual method parametrisation
1919
2020.. note ::
2121
2222 Generally, all quantities provided to the library are assumed to be in `atomic units <https://en.wikipedia.org/wiki/Hartree_atomic_units >`_.
2323
24- .. contents ::
25-
2624
2725Error handling
2826--------------
2927
30- The library provides a light error handle type (``dftd3_error ``) for storing error information
28+ .. c :type :: struct _dftd3_error* dftd3_error;
29+
30+ Error handle class
31+
32+ The library provides a light error handle type (:c:type: `dftd3_error `) for storing error information
3133The error handle requires only small overhead to construct and can only contain a single error.
3234
3335The handler is represented by an opaque pointer and can only be manipulated by call from the library.
3436The user of those objects is required to delete the handlers again using the library provided deconstructors to avoid memory leaks.
3537
38+ .. c :function :: dftd3_error dftd3_new_error ();
39+
40+ :returns: New allocation for error handle
41+
42+ Create new error handle object
43+
44+ .. c :function :: int dftd3_check_error (dftd3_error error);
45+
46+ :param error: Error handle
47+ :returns: Current status of error handle, non-zero in case of error
48+
49+ Check error handle status
50+
51+ .. c :function :: void dftd3_get_error (dftd3_error error, char* buffer, const int* buffersize);
52+
53+ :param error: Error handle
54+ :param buffer: Allocation to store error message in
55+ :param buffersize: Maximum length of the buffer (optional)
56+
57+ Get error message from error handle
58+
59+ .. c :function :: void dftd3_delete_error (dftd3_error* error);
60+
61+ :param error: Error handle
62+
63+ Delete error handle object. The handle is set to NULL after deletion.
64+
3665
3766Structure data
3867--------------
3968
69+ .. c :type :: struct _dftd3_structure* dftd3_structure;
70+
71+ Molecular structure data class
72+
4073The structure data is used to represent the system of interest in the library.
4174It contains immutable system specific information like the number of atoms, the unique atom groups and the boundary conditions as well as mutable geometry data like cartesian coordinates and lattice parameters.
4275
76+ .. c :function :: dftd3_structure dftd3_new_structure (dftd3_error error, const int natoms, const int* numbers, const double* positions, const double* lattice, const bool* periodic);
77+
78+ :param natoms: Number of atoms in the system
79+ :param numbers: Atomic numbers of all atoms [natoms]
80+ :param positions: Cartesian coordinates in Bohr [natoms, 3]
81+ :param lattice: Lattice parameters in Bohr [3, 3] (optional)
82+ :param periodic: Periodic dimension of the system [3] (optional)
83+ :returns: New molecular structure data handle
84+
85+ Create new molecular structure data (quantities in Bohr)
86+
87+ .. c :function :: void dftd3_update_structure (dftd3_error error, dftd3_structure mol, const double* positions, const double* lattice);
88+
89+ :param error: Error handle
90+ :param mol: Molecular structure data handle
91+ :param positions: Cartesian coordinates in Bohr [natoms, 3]
92+ :param lattice: Lattice parameters in Bohr [3, 3] (optional)
93+
94+ Update coordinates and lattice parameters (quantities in Bohr)
95+
96+ .. c :function :: void dftd3_delete_structure (dftd3_structure* mol);
97+
98+ :param mol: Molecular structure data handle
99+
100+ Delete molecular structure data. The handle is set to NULL after deletion.
101+
102+
103+ Dispersion model
104+ ----------------
105+
106+ .. c :type :: struct _dftd3_model* dftd3_model;
107+
108+ Dispersion model class
109+
110+ Instantiated for a given molecular structure type, it carries no information on the geometry but relies on the atomic species of the structure object.
111+ Recreating a structure object requires to recreate the dispersion model as well.
112+
113+ .. c :function :: dftd3_model dftd3_new_d3_model (dftd3_error error, dftd3_structure mol);
114+
115+ :param error: Error handle
116+ :param mol: Molecular structure data handle
117+ :returns: New dispersion model handle
118+
119+ Create new D3 dispersion model
120+
121+ .. c :function :: void dftd3_set_model_realspace_cutoff (dftd3_error error, dftd3_model model, double disp2, double disp3, double cn);
122+
123+ :param error: Error handle
124+ :param model: Dispersion model handle
125+ :param disp2: Cutoff for two-body dispersion
126+ :param disp3: Cutoff for three-body dispersion
127+ :param cn: Cutoff for coordination number calculation
128+
129+ Set realspace cutoffs for usage in the dispersion calculation
130+
131+ .. c :function :: void dftd3_delete_model (dftd3_model* disp);
132+
133+ :param disp: Dispersion model handle
134+
135+ Delete dispersion model. The handle is set to NULL after deletion.
136+
137+
138+ Damping parameters
139+ ------------------
140+
141+ .. c :type :: struct _dftd3_param* dftd3_param;
142+
143+ Damping parameter class
144+
145+ The damping parameter object determining the short-range behaviour of the dispersion correction.
146+ Standard damping parameters like the rational damping are independent of the molecular structure and can easily be reused for several structures or easily exchanged.
147+
148+ .. c :function :: dftd3_param dftd3_new_zero_damping (dftd3_error error, double s6, double s8, double s9, double rs6, double rs8, double alp);
149+
150+ :param error: Error handle
151+ :param s6: Scaling of induced dipole-dipole dispersion energy
152+ :param s8: Scaling of induced dipole-quadrupole dispersion energy
153+ :param s9: Scaling of induced triple-dipole dispersion energy
154+ :param rs6: Range-separation parameter for induced dipole-dipole dispersion energy
155+ :param rs8: Range-separation parameter for induced dipole-quadrupole dispersion energy
156+ :param alp: Exponent for the zero damping function
157+ :returns: New damping parameter handle
158+
159+ Create new zero damping parameters
160+
161+ .. c :function :: dftd3_param dftd3_load_zero_damping (dftd3_error error, char* method, bool atm);
162+
163+ :param error: Error handle
164+ :param method: Name of the method to load parameters for
165+ :param atm: Use three-body dispersion
166+ :returns: New damping parameter handle
167+
168+ Load zero damping parameters from internal storage
169+
170+ .. c :function :: dftd3_param dftd3_new_rational_damping (dftd3_error error, double s6, double s8, double s9, double a1, double a2, double alp);
171+
172+ :param error: Error handle
173+ :param s6: Scaling of induced dipole-dipole dispersion energy
174+ :param s8: Scaling of induced dipole-quadrupole dispersion energy
175+ :param s9: Scaling of induced triple-dipole dispersion energy
176+ :param a1: Scaling of atom specific critical radii
177+ :param a2: Constant offset of critical radii
178+ :param alp: Exponent for the zero damping function (used for induced triple-dipole dispersion energy)
179+ :returns: New damping parameter handle
180+
181+ Create new rational damping parameters
182+
183+ .. c :function :: dftd3_param dftd3_load_rational_damping (dftd3_error error, char* method, bool atm);
184+
185+ :param error: Error handle
186+ :param method: Name of the method to load parameters for
187+ :param atm: Use three-body dispersion
188+ :returns: New damping parameter handle
189+
190+ Load rational damping parameters from internal storage
191+
192+ .. c :function :: dftd3_param dftd3_new_mzero_damping (dftd3_error error, double s6, double s8, double s9, double rs6, double rs8, double alp, double bet);
193+
194+ :param error: Error handle
195+ :param s6: Scaling of induced dipole-dipole dispersion energy
196+ :param s8: Scaling of induced dipole-quadrupole dispersion energy
197+ :param s9: Scaling of induced triple-dipole dispersion energy
198+ :param rs6: Range-separation parameter for induced dipole-dipole dispersion energy
199+ :param rs8: Range-separation parameter for induced dipole-quadrupole dispersion energy
200+ :param alp: Exponent for the zero damping function
201+ :returns: New damping parameter handle
202+
203+ Create new modified zero damping parameters
204+
205+ .. c :function :: dftd3_param dftd3_load_mzero_damping (dftd3_error error, char* method, bool atm);
206+
207+ :param error: Error handle
208+ :param method: Name of the method to load parameters for
209+ :param atm: Use three-body dispersion
210+ :returns: New damping parameter handle
211+
212+ Load modified zero damping parameters from internal storage
213+
214+ .. c :function :: dftd3_param dftd3_new_mrational_damping (dftd3_error error, double s6, double s8, double s9, double a1, double a2, double alp);
215+
216+ :param error: Error handle
217+ :param s6: Scaling of induced dipole-dipole dispersion energy
218+ :param s8: Scaling of induced dipole-quadrupole dispersion energy
219+ :param s9: Scaling of induced triple-dipole dispersion energy
220+ :param a1: Scaling of atom specific critical radii
221+ :param a2: Constant offset of critical radii
222+ :param alp: Exponent for the zero damping function (used for induced triple-dipole dispersion energy)
223+ :returns: New damping parameter handle
224+
225+ Create new modified rational damping parameters
226+
227+ .. c :function :: dftd3_param dftd3_load_mrational_damping (dftd3_error error, char* method, bool atm);
228+
229+ :param error: Error handle
230+ :param method: Name of the method to load parameters for
231+ :param atm: Use three-body dispersion
232+ :returns: New damping parameter handle
233+
234+ Load modified rational damping parameters from internal storage
235+
236+ .. c :function :: dftd3_param dftd3_new_optimizedpower_damping (dftd3_error error, double s6, double s8, double s9, double a1, double a2, double alp, double bet);
237+
238+ :param error: Error handle
239+ :param s6: Scaling of induced dipole-dipole dispersion energy
240+ :param s8: Scaling of induced dipole-quadrupole dispersion energy
241+ :param s9: Scaling of induced triple-dipole dispersion energy
242+ :param a1: Scaling of atom specific critical radii
243+ :param a2: Constant offset of critical radii
244+ :param alp: Exponent for the zero damping function
245+ :param bet: Exponent for the rational damping function (used for induced triple-dipole dispersion energy)
246+ :returns: New damping parameter handle
247+
248+ Create new optimized power damping parameters
249+
250+ .. c :function :: dftd3_param dftd3_load_optimizedpower_damping (dftd3_error error, char* method, bool atm);
251+
252+ :param error: Error handle
253+ :param method: Name of the method to load parameters for
254+ :param atm: Use three-body dispersion
255+ :returns: New damping parameter handle
256+
257+ Load optimized power damping parameters from internal storage
258+
259+ .. c :function :: void dftd3_delete_param (dftd3_param* param);
260+
261+ :param param: Dispersion parameter handle
262+
263+ Delete damping parameters. The handle is set to NULL after deletion.
264+
265+
266+ Calculation entrypoints
267+ -----------------------
268+
269+ To evaluate dispersion energies or related properties the :c:func: `dftd3_get_dispersion ` procedure and similar can be used.
270+
271+ .. c :function :: void dftd3_get_dispersion (dftd3_error error, dftd3_structure mol, dftd3_model disp, dftd3_param param, double* energy, double* gradient, double* sigma);
272+
273+ :param error: Error handle
274+ :param mol: Molecular structure data handle
275+ :param disp: Dispersion model handle
276+ :param param: Damping function parameter handle
277+ :param energy: Dispersion energy
278+ :param gradient: Dispersion gradient [natoms, 3] (optional)
279+ :param sigma: Dispersion strain derivatives [3, 3] (optional)
280+
281+ Evaluate the dispersion energy and its derivatives.
282+
283+ .. c :function :: void dftd3_get_pairwise_dispersion (dftd3_error error, dftd3_structure mol, dftd3_model disp, dftd3_param param, double* pair_energy2, double* pair_energy3);
284+
285+ :param error: Error handle
286+ :param mol: Molecular structure data handle
287+ :param disp: Dispersion model handle
288+ :param param: Damping function parameter handle
289+ :param energy2: Pairwise additive dispersion energies
290+ :param energy3: Pairwise non-addititive dispersion energies
291+
292+ Evaluate the pairwise representation of the dispersion energy
293+
294+
295+ Memory management
296+ -----------------
297+
298+ For each object type, a deconstructor function is provided to free the memory allocated by the library.
299+ A type-generic macro is provided to select the correct deconstructor based on the object type.
300+ Note that NULL pointers are allowed and will be ignored by the deconstructor.
301+
302+ .. c :macro :: dftd3_delete(ptr) _Generic ((ptr), dftd3_error: dftd3_delete_error, dftd3_structure: dftd3_delete_structure, dftd3_model: dftd3_delete_model, dftd3_param: dftd3_delete_param)(&ptr)
303+
304+ :param ptr: Object handle
305+
306+ Macro to delete objects created by the library. The macro is type-generic and selects the correct deconstructor based on the object type. The handle is set to NULL after deletion.
307+
43308
44309Performing calculations
45310-----------------------
@@ -96,7 +361,7 @@ An example wrapper to perform a DFT-D3(BJ)-ATM calculation is shown below.
96361
97362 if (!stat) {
98363 char buffer[buffersize];
99- dftd3_get_error(error, buffer, buffersize);
364+ dftd3_get_error(error, buffer, & buffersize);
100365 printf("[Error] %s\n", buffer);
101366 }
102367
0 commit comments