Loading...
Searching...
No Matches
gpridge.f90
Go to the documentation of this file.
1! SPDX-License-Identifier: MIT
2! Copyright (c) gpridge developers
3!
4! Ergonomic Fortran module for gpridge.
5! Wraps the C API with derived types, type-bound procedures, and finalizers.
6
7module gpridge
8 use, intrinsic :: iso_c_binding
9 implicit none
10 private
11
12 ! =====================================================================
13 ! Error codes
14 ! =====================================================================
15 integer(c_int), parameter, public :: gpr_success = 0
16 integer(c_int), parameter, public :: gpr_err_null_handle = -1
17 integer(c_int), parameter, public :: gpr_err_invalid_arg = -2
18 integer(c_int), parameter, public :: gpr_err_not_trained = -3
19 integer(c_int), parameter, public :: gpr_err_alloc = -4
20 integer(c_int), parameter, public :: gpr_err_cholesky = -5
21 integer(c_int), parameter, public :: gpr_err_optimizer = -6
22 integer(c_int), parameter, public :: gpr_err_not_converged = -7
23 integer(c_int), parameter, public :: gpr_err_size_limit = -8
24 integer(c_int), parameter, public :: gpr_err_oracle = -9
25 integer(c_int), parameter, public :: gpr_err_unsupported = -10
26 integer(c_int), parameter, public :: gpr_err_abi = -11
27 integer(c_int), parameter, public :: gpr_err_out_of_support = -12
28 integer(c_int), parameter, public :: gpr_err_unit_mismatch = -13
29 integer(c_int), parameter, public :: gpr_err_internal = -99
30
31 !> C ABI version this module was written against (gpridge_c.h).
32 integer(c_int), parameter, public :: gpr_c_abi_major = 1
33 integer(c_int), parameter, public :: gpr_c_abi_minor = 26
34
35 ! Why a dimer search stopped (gpr_dimer_stop_t)
36 integer(c_int), parameter, public :: gpr_dimer_stop_unspecified = 0
37 integer(c_int), parameter, public :: gpr_dimer_stop_force_converged = 1
38 integer(c_int), parameter, public :: gpr_dimer_stop_measured_non_descent = 2
39 integer(c_int), parameter, public :: gpr_dimer_stop_degenerate_probe = 3
40 integer(c_int), parameter, public :: gpr_dimer_stop_uninformative_rotation = 4
41 integer(c_int), parameter, public :: gpr_dimer_stop_alignment_loss = 5
42 integer(c_int), parameter, public :: gpr_dimer_stop_iteration_budget = 6
43 integer(c_int), parameter, public :: gpr_dimer_stop_interatomic_collapse = 7
44 integer(c_int), parameter, public :: gpr_dimer_stop_invalid_atoms = 8
45 integer(c_int), parameter, public :: gpr_dimer_stop_oracle_budget = 9
46 integer(c_int), parameter, public :: gpr_dimer_stop_invalid_parameters = 10
47 integer(c_int), parameter, public :: gpr_dimer_stop_measured_index_zero = 11
48 integer(c_int), parameter, public :: gpr_dimer_stop_uncertified_force_stop = 12
49
50 ! How a NEB converged (gpr_neb_status_t)
51 integer(c_int), parameter, public :: gpr_neb_not_converged = 0
52 integer(c_int), parameter, public :: gpr_neb_force_tolerance = 1
53 integer(c_int), parameter, public :: gpr_neb_model_noise_floor = 2
54
55 ! Unit tags of the derivative primitives (gpr_energy_unit_t,
56 ! gpr_length_unit_t, ABI 1.20). Labels only; nothing is converted.
57 integer(c_int), parameter, public :: gpr_energy_unit_native = 0
58 integer(c_int), parameter, public :: gpr_energy_unit_ev = 1
59 integer(c_int), parameter, public :: gpr_energy_unit_hartree = 2
60 integer(c_int), parameter, public :: gpr_energy_unit_kcal_per_mol = 3
61 integer(c_int), parameter, public :: gpr_energy_unit_kj_per_mol = 4
62 integer(c_int), parameter, public :: gpr_length_unit_native = 0
63 integer(c_int), parameter, public :: gpr_length_unit_angstrom = 1
64 integer(c_int), parameter, public :: gpr_length_unit_bohr = 2
65 integer(c_int), parameter, public :: gpr_length_unit_nanometer = 3
66
67 ! Harmonic prefactors (gpr_htst_*_t, ABI 1.20)
68 integer(c_int), parameter, public :: gpr_htst_refined = 0
69 integer(c_int), parameter, public :: gpr_htst_measured = 1
70 integer(c_int), parameter, public :: gpr_htst_surrogate = 2
71 integer(c_int), parameter, public :: gpr_htst_minimum = 0
72 integer(c_int), parameter, public :: gpr_htst_saddle = 1
73 integer(c_int), parameter, public :: gpr_htst_ok = 0
74 integer(c_int), parameter, public :: gpr_htst_not_converged = 1
75 integer(c_int), parameter, public :: gpr_htst_wrong_index = 2
76 integer(c_int), parameter, public :: gpr_htst_unavailable = 3
77 integer(c_int), parameter, public :: gpr_htst_source_refined = 0
78 integer(c_int), parameter, public :: gpr_htst_source_measured = 1
79 integer(c_int), parameter, public :: gpr_htst_source_stencil = 2
80 integer(c_int), parameter, public :: gpr_htst_source_surrogate = 3
81 integer(c_int), parameter, public :: gpr_htst_source_conditioned = 4
82 integer(c_int), parameter, public :: gpr_htst_reactant = 0
83 integer(c_int), parameter, public :: gpr_htst_transition = 1
84 integer(c_int), parameter, public :: gpr_htst_product = 2
85 !> sqrt(eV / (Angstrom^2 amu)) in rad/s.
86 real(c_double), parameter, public :: gpr_htst_omega_ev_angstrom_amu = &
87 9.82269385d13
88
89 ! =====================================================================
90 ! Enum values
91 ! =====================================================================
92
93 ! Model type enumerators
94 integer(c_int), parameter, public :: gpr_model_gp = 0
95 integer(c_int), parameter, public :: gpr_model_tp = 1
96
97 ! Optimization algorithms
98 integer(c_int), parameter, public :: gpr_opt_scg = 0
99 integer(c_int), parameter, public :: gpr_opt_factorized = 2
100
101 ! Posterior solver on ModelConfig%use_hssvd_backend. Zero keeps HS-SVD.
102 integer(c_int), parameter, public :: gpr_hssvd_backend_default = 0
103 integer(c_int), parameter, public :: gpr_hssvd_backend_hssvd = 1
104 integer(c_int), parameter, public :: gpr_hssvd_backend_cholesky = 2
105
106 ! NEB modes (gpr_neb_mode_t)
107 integer(c_int), parameter, public :: gpr_neb_standard = 0
108 integer(c_int), parameter, public :: gpr_neb_aie = 1
109 integer(c_int), parameter, public :: gpr_neb_oie = 2
110 integer(c_int), parameter, public :: gpr_neb_gp_aie = 3
111 integer(c_int), parameter, public :: gpr_neb_gp_oie = 4
112 integer(c_int), parameter, public :: gpr_neb_gp_local = 5
113
114 ! Acquisition strategies (gpr_acquisition_t)
115 integer(c_int), parameter, public :: gpr_acq_max_variance = 0
116 integer(c_int), parameter, public :: gpr_acq_max_force = 1
117 integer(c_int), parameter, public :: gpr_acq_ucb = 2
118 integer(c_int), parameter, public :: gpr_acq_thompson = 3
119 integer(c_int), parameter, public :: gpr_acq_imspe = 4
120 integer(c_int), parameter, public :: gpr_acq_ei = 5
121 integer(c_int), parameter, public :: gpr_acq_priority_cascade = 6
122 integer(c_int), parameter, public :: gpr_acq_tpe = 7
123 integer(c_int), parameter, public :: gpr_acq_psbax = 8
124
125 ! Convergence norms
126 integer(c_int), parameter, public :: gpr_norm_l2 = 0
127 integer(c_int), parameter, public :: gpr_norm_linf = 1
128 integer(c_int), parameter, public :: gpr_norm_max_atom = 2
129
130 ! Uncertainty modes (gpr_uncertainty_mode_t)
131 integer(c_int), parameter, public :: gpr_uq_map = 0
132 integer(c_int), parameter, public :: gpr_uq_bma = 1
133 integer(c_int), parameter, public :: gpr_uq_laplace = 2
134 integer(c_int), parameter, public :: gpr_uq_eb = 3
135 integer(c_int), parameter, public :: gpr_uq_svgd = 4
136 integer(c_int), parameter, public :: gpr_uq_laplace_slice = 5
137
138 ! Hyperparameter optimiser / objective
139 integer(c_int), parameter, public :: gpr_hopt_scg = 0
140 integer(c_int), parameter, public :: gpr_hopt_inla = 1
141 integer(c_int), parameter, public :: gpr_hobj_nlml = 0
142 integer(c_int), parameter, public :: gpr_hobj_loo = 1
143
144 ! Trust distance metric (gpr_distance_metric_t)
145 integer(c_int), parameter, public :: gpr_dist_max_1d_log = 0
146 integer(c_int), parameter, public :: gpr_dist_rmsd = 1
147 integer(c_int), parameter, public :: gpr_dist_emd = 2
148
149 ! Scalar GP / Bayesian quadrature (ABI 1.17)
150 integer(c_int), parameter, public :: gpr_bq_kernel_se = 0
151 integer(c_int), parameter, public :: gpr_bq_kernel_matern32_product = 1
152 integer(c_int), parameter, public :: gpr_bq_kernel_matern52_product = 2
153 integer(c_int), parameter, public :: gpr_bq_kernel_matern32_isotropic = 3
154 integer(c_int), parameter, public :: gpr_bq_kernel_matern52_isotropic = 4
155 integer(c_int), parameter, public :: gpr_bq_hyper_fixed = 0
156 integer(c_int), parameter, public :: gpr_bq_hyper_ml = 1
157 integer(c_int), parameter, public :: gpr_bq_hyper_map = 2
158 integer(c_int), parameter, public :: gpr_bq_hyper_tp_marginal = 3
159 integer(c_int), parameter, public :: gpr_bq_hyper_marginalized = 4
160 integer(c_int), parameter, public :: gpr_bq_measure_lebesgue_box = 0
161 integer(c_int), parameter, public :: gpr_bq_measure_uniform_box = 1
162 integer(c_int), parameter, public :: gpr_bq_measure_gaussian = 2
163 integer(c_int), parameter, public :: gpr_bq_basis_follow_config = -1
164 integer(c_int), parameter, public :: gpr_bq_basis_none = 0
165 integer(c_int), parameter, public :: gpr_bq_basis_constant = 1
166 integer(c_int), parameter, public :: gpr_bq_basis_affine = 2
167 integer(c_int), parameter, public :: gpr_psearch_axis_linear = 0
168 integer(c_int), parameter, public :: gpr_psearch_axis_log = 1
169 integer(c_int), parameter, public :: gpr_psearch_axis_integer = 2
170
171 type, public, bind(C) :: bqconfig
172 integer(c_int) :: dimension
173 integer(c_int) :: kernel
174 integer(c_int) :: ard
175 integer(c_int) :: hyper_mode
176 real(c_double) :: magn_sigma2
177 real(c_double) :: lengthscale
178 real(c_double) :: extra_sigma2
179 integer(c_int) :: optimize_extra_sigma2
180 real(c_double) :: jitter_sigma2
181 real(c_double) :: kappa_max
182 integer(c_int) :: use_prior_mean
183 real(c_double) :: ls_prior_mu
184 real(c_double) :: ls_prior_s2
185 real(c_double) :: ls_prior_nu
186 real(c_double) :: tp_hyperprior_a
187 real(c_double) :: tp_hyperprior_b
188 integer(c_int) :: quad_nodes
189 integer(c_int) :: gl_max_panels
190 integer(c_int) :: max_iter
191 real(c_double) :: tol_func
192 real(c_double) :: tol_sol
193 integer(c_int) :: report_level
194 integer(c_int) :: interpolate_candidate_noise
195 end type
196
197 type, public, bind(C) :: bqintegralreport
198 real(c_double) :: mean
199 real(c_double) :: variance
200 real(c_double) :: std_dev
201 real(c_double) :: prior_integral_variance
202 real(c_double) :: explained_variance
203 real(c_double) :: mean_shift_variance
204 real(c_double) :: aleatoric_variance
205 real(c_double) :: epistemic_variance
206 real(c_double) :: hyperparameter_variance
207 real(c_double) :: loo_calibration_scale
208 real(c_double) :: tp_variance_scale
209 real(c_double) :: condition_number
210 real(c_double) :: effective_nugget
211 integer(c_int) :: quadrature_models
212 end type
213
214 type, public, bind(C) :: bquncertainty
215 real(c_double) :: mean
216 real(c_double) :: variance
217 real(c_double) :: gp_variance
218 real(c_double) :: observation_noise_variance
219 real(c_double) :: hyperparameter_variance
220 real(c_double) :: numerical_abs_tolerance
221 real(c_double) :: loo_predictive_scale
222 real(c_double) :: variance_model
223 real(c_double) :: measure_mass
224 integer(c_int) :: quadrature_models
225 end type
226
227 !> gpr_fes_config_t (ABI 1.23). fes_config_defaults() fills it.
228 type, public, bind(C) :: fesconfig
229 integer(c_size_t) :: struct_size = 0
230 integer(c_int) :: kernel = 0
231 integer(c_int) :: ard = 0
232 end type
233
234 !> gpr_fes_rate_config_t (ABI 1.23). fes_rate_config_defaults() fills it;
235 !> beta must then be set.
236 type, public, bind(C) :: fesrateconfig
237 integer(c_size_t) :: struct_size = 0
238 integer(c_int) :: posterior_samples = 0
239 integer(c_int64_t) :: seed = 0
240 real(c_double) :: beta = 0.0_c_double
241 real(c_double) :: credible_mass = 0.0_c_double
242 real(c_double) :: saddle_tolerance = 0.0_c_double
243 end type
244
245 !> gpr_fes_rate_report_t (ABI 1.23).
246 type, public, bind(C) :: fesratereport
247 integer(c_size_t) :: struct_size = 0
248 real(c_double) :: barrier_mean = 0.0_c_double
249 real(c_double) :: barrier_std = 0.0_c_double
250 real(c_double) :: barrier_lower = 0.0_c_double
251 real(c_double) :: barrier_upper = 0.0_c_double
252 real(c_double) :: prefactor_mean = 0.0_c_double
253 real(c_double) :: prefactor_std = 0.0_c_double
254 real(c_double) :: rate_mean = 0.0_c_double
255 real(c_double) :: rate_std = 0.0_c_double
256 real(c_double) :: rate_lower = 0.0_c_double
257 real(c_double) :: rate_upper = 0.0_c_double
258 integer(c_int) :: samples_requested = 0
259 integer(c_int) :: samples_accepted = 0
260 real(c_double) :: saddle_gradient_norm = 0.0_c_double
261 end type
262
263 ! =====================================================================
264 ! C API bindings (private)
265 ! =====================================================================
300 interface
301 ! Version
302 type(c_ptr) function c_gpr_version() bind(c, name='gpr_version')
303 import :: c_ptr
304 end function
305
306 function c_gpr_last_error() bind(C, name='gpr_last_error_message') result(p)
307 import :: c_ptr
308 type(c_ptr) :: p
309 end function
310
311 ! Atoms
312 type(c_ptr) function c_gpr_atoms_create_simple(n_atoms) &
313 bind(c, name='gpr_atoms_create_simple')
314 import :: c_ptr, c_int
315 integer(c_int), value :: n_atoms
316 end function
317
318 subroutine c_gpr_atoms_destroy(atoms) bind(C, name='gpr_atoms_destroy')
319 import :: c_ptr
320 type(c_ptr), value :: atoms
321 end subroutine
322
323 integer(c_int) function c_gpr_atoms_n_moving(atoms) &
324 bind(c, name='gpr_atoms_n_moving')
325 import :: c_ptr, c_int
326 type(c_ptr), value :: atoms
327 end function
328
329 integer(c_int) function c_gpr_atoms_n_pairtypes(atoms) &
330 bind(c, name='gpr_atoms_n_pairtypes')
331 import :: c_ptr, c_int
332 type(c_ptr), value :: atoms
333 end function
334
335 ! Model
336 type(c_ptr) function c_gpr_model_create(model_type) &
337 bind(c, name='gpr_model_create')
338 import :: c_ptr, c_int
339 integer(c_int), value :: model_type
340 end function
341
342 subroutine c_gpr_model_destroy(model) bind(C, name='gpr_model_destroy')
343 import :: c_ptr
344 type(c_ptr), value :: model
345 end subroutine
346
347 integer(c_int) function c_gpr_model_init(model, config, atoms) &
348 bind(c, name='gpr_model_init')
349 import :: c_ptr, c_int
350 type(c_ptr), value :: model
351 type(*), intent(in) :: config ! gpr_model_config_t
352 type(c_ptr), value :: atoms
353 end function
354
355 ! Extent-checked entry points (ABI 1.11): every buffer comes with its
356 ! length in doubles, and the C layer refuses a call that would pass it.
357 integer(c_int) function c_gpr_model_train_checked(model, R, R_len, E, &
358 E_len, G, G_len, n_obs, n_coords) &
359 bind(c, name='gpr_model_train_checked')
360 import :: c_ptr, c_int, c_double, c_size_t
361 type(c_ptr), value :: model
362 real(c_double), intent(in) :: r(*)
363 integer(c_size_t), value :: r_len
364 real(c_double), intent(in) :: e(*)
365 integer(c_size_t), value :: e_len
366 real(c_double), intent(in) :: g(*)
367 integer(c_size_t), value :: g_len
368 integer(c_int), value :: n_obs, n_coords
369 end function
370
371 integer(c_int) function c_gpr_model_train_marginal_likelihood_checked( &
372 model, R, R_len, E, E_len, G, G_len, n_obs, n_coords, report, &
373 lengthscales, lengthscales_len) &
374 bind(c, name='gpr_model_train_marginal_likelihood_checked')
375 import :: c_ptr, c_int, c_double, c_size_t
376 type(c_ptr), value :: model
377 real(c_double), intent(in) :: r(*), e(*), g(*)
378 integer(c_size_t), value :: r_len, e_len, g_len
379 integer(c_int), value :: n_obs, n_coords
380 type(*) :: report
381 real(c_double) :: lengthscales(*)
382 integer(c_size_t), value :: lengthscales_len
383 end function
384
385 integer(c_int) function c_gpr_model_update_checked(model, R, R_len, E, &
386 E_len, G, G_len, n_new, n_coords) &
387 bind(c, name='gpr_model_update_checked')
388 import :: c_ptr, c_int, c_double, c_size_t
389 type(c_ptr), value :: model
390 real(c_double), intent(in) :: r(*)
391 integer(c_size_t), value :: r_len
392 real(c_double), intent(in) :: e(*)
393 integer(c_size_t), value :: e_len
394 real(c_double), intent(in) :: g(*)
395 integer(c_size_t), value :: g_len
396 integer(c_int), value :: n_new, n_coords
397 end function
398
399 integer(c_int) function c_gpr_model_append_fixed_checked(model, R, R_len, &
400 E, E_len, G, G_len, n_new, n_coords) &
401 bind(c, name='gpr_model_append_fixed_checked')
402 import :: c_ptr, c_int, c_double, c_size_t
403 type(c_ptr), value :: model
404 real(c_double), intent(in) :: r(*), e(*), g(*)
405 integer(c_size_t), value :: r_len, e_len, g_len
406 integer(c_int), value :: n_new, n_coords
407 end function
408
409 integer(c_int) function c_gpr_model_calibrate_forces_checked(model, R, &
410 R_len, G, G_len, n_holdout, n_coords, nominal_probability, report) &
411 bind(c, name='gpr_model_calibrate_forces_checked')
412 import :: c_ptr, c_int, c_double, c_size_t
413 type(c_ptr), value :: model
414 real(c_double), intent(in) :: r(*), g(*)
415 integer(c_size_t), value :: r_len, g_len
416 integer(c_int), value :: n_holdout, n_coords
417 real(c_double), value :: nominal_probability
418 type(*) :: report
419 end function
420
421 integer(c_int) function c_gpr_model_calibrate_loo_checked(model, &
422 nominal_probability, report) &
423 bind(c, name='gpr_model_calibrate_loo_checked')
424 import :: c_ptr, c_int, c_double
425 type(c_ptr), value :: model
426 real(c_double), value :: nominal_probability
427 type(*) :: report
428 end function
429
430 integer(c_int) function c_gpr_model_predict_checked(model, R_q, R_len, &
431 E, G, G_len, n_coords) bind(C, name='gpr_model_predict_checked')
432 import :: c_ptr, c_int, c_double, c_size_t
433 type(c_ptr), value :: model
434 real(c_double), intent(in) :: r_q(*)
435 integer(c_size_t), value :: r_len
436 real(c_double), intent(out) :: e
437 real(c_double), intent(out) :: g(*)
438 integer(c_size_t), value :: g_len
439 integer(c_int), value :: n_coords
440 end function
441
442 integer(c_int) function c_gpr_model_predict_variance_checked(model, R_q, &
443 R_len, vE, vG, vG_len, n_coords) &
444 bind(c, name='gpr_model_predict_variance_checked')
445 import :: c_ptr, c_int, c_double, c_size_t
446 type(c_ptr), value :: model
447 real(c_double), intent(in) :: r_q(*)
448 integer(c_size_t), value :: r_len
449 real(c_double), intent(out) :: ve
450 real(c_double), intent(out) :: vg(*)
451 integer(c_size_t), value :: vg_len
452 integer(c_int), value :: n_coords
453 end function
454
455 integer(c_int) function c_gpr_model_n_lengthscales(model) &
456 bind(c, name='gpr_model_n_lengthscales')
457 import :: c_ptr, c_int
458 type(c_ptr), value :: model
459 end function
460
461 integer(c_int) function c_gpr_model_get_lengthscales(model, out) &
462 bind(c, name='gpr_model_get_lengthscales')
463 import :: c_ptr, c_int, c_double
464 type(c_ptr), value :: model
465 real(c_double), intent(out) :: out(*)
466 end function
467
468 integer(c_int) function c_gpr_model_set_lengthscales(model, values, n) &
469 bind(c, name='gpr_model_set_lengthscales')
470 import :: c_ptr, c_int, c_double
471 type(c_ptr), value :: model
472 real(c_double), intent(in) :: values(*)
473 integer(c_int), value :: n
474 end function
475
476 integer(c_int) function c_gpr_model_get_magn_sigma2(model, out) &
477 bind(c, name='gpr_model_get_magn_sigma2')
478 import :: c_ptr, c_int, c_double
479 type(c_ptr), value :: model
480 real(c_double), intent(out) :: out
481 end function
482
483 integer(c_int) function c_gpr_model_set_magn_sigma2(model, val) &
484 bind(c, name='gpr_model_set_magn_sigma2')
485 import :: c_ptr, c_int, c_double
486 type(c_ptr), value :: model
487 real(c_double), value :: val
488 end function
489
490 integer(c_int) function c_gpr_model_get_sigma2(model, out) &
491 bind(c, name='gpr_model_get_sigma2')
492 import :: c_ptr, c_int, c_double
493 type(c_ptr), value :: model
494 real(c_double), intent(out) :: out
495 end function
496
497 integer(c_int) function c_gpr_model_get_jitter(model, out) &
498 bind(c, name='gpr_model_get_jitter')
499 import :: c_ptr, c_int, c_double
500 type(c_ptr), value :: model
501 real(c_double) :: out
502 end function
503
504 integer(c_int) function c_gpr_model_set_hssvd_backend(model, enabled) &
505 bind(c, name='gpr_model_set_hssvd_backend')
506 import :: c_ptr, c_int
507 type(c_ptr), value :: model
508 integer(c_int), value :: enabled
509 end function
510
511 integer(c_int) function c_gpr_model_get_hssvd_backend(model, out) &
512 bind(c, name='gpr_model_get_hssvd_backend')
513 import :: c_ptr, c_int
514 type(c_ptr), value :: model
515 integer(c_int) :: out
516 end function
517
518 ! No INTENT: an error leaves the caller buffer unchanged, and a long
519 ! buffer keeps its unused tail. INTENT(OUT) would undefine both.
520 integer(c_int) function c_gpr_model_get_alpha(model, out, n) &
521 bind(c, name='gpr_model_get_alpha')
522 import :: c_ptr, c_int, c_double
523 type(c_ptr), value :: model
524 real(c_double) :: out(*)
525 integer(c_int), value :: n
526 end function
527
528 integer(c_int) function c_gpr_model_set_sigma2(model, val) &
529 bind(c, name='gpr_model_set_sigma2')
530 import :: c_ptr, c_int, c_double
531 type(c_ptr), value :: model
532 real(c_double), value :: val
533 end function
534
535 integer(c_int) function c_gpr_model_n_observations(model) &
536 bind(c, name='gpr_model_n_observations')
537 import :: c_ptr, c_int
538 type(c_ptr), value :: model
539 end function
540
541 integer(c_int) function c_gpr_model_tp_prefactor(model, out) &
542 bind(c, name='gpr_model_tp_prefactor')
543 import :: c_ptr, c_int, c_double
544 type(c_ptr), value :: model
545 real(c_double), intent(out) :: out
546 end function
547
548 ! NEB result queries
549 integer(c_int) function c_gpr_neb_result_converged(r) &
550 bind(c, name='gpr_neb_result_converged')
551 import :: c_ptr, c_int
552 type(c_ptr), value :: r
553 end function
554
555 integer(c_int) function c_gpr_neb_result_oracle_calls(r) &
556 bind(c, name='gpr_neb_result_oracle_calls')
557 import :: c_ptr, c_int
558 type(c_ptr), value :: r
559 end function
560
561 real(c_double) function c_gpr_neb_result_barrier(r) &
562 bind(c, name='gpr_neb_result_barrier')
563 import :: c_ptr, c_double
564 type(c_ptr), value :: r
565 end function
566
567 integer(c_int) function c_gpr_neb_result_n_images(r) &
568 bind(c, name='gpr_neb_result_n_images')
569 import :: c_ptr, c_int
570 type(c_ptr), value :: r
571 end function
572
573 integer(c_int) function c_gpr_neb_result_image_energy(r, idx, out) &
574 bind(c, name='gpr_neb_result_image_energy')
575 import :: c_ptr, c_int, c_double
576 type(c_ptr), value :: r
577 integer(c_int), value :: idx
578 real(c_double), intent(out) :: out
579 end function
580
581 integer(c_int) function c_gpr_neb_result_image_positions(r, idx, out, nc) &
582 bind(c, name='gpr_neb_result_image_positions')
583 import :: c_ptr, c_int, c_double
584 type(c_ptr), value :: r
585 integer(c_int), value :: idx, nc
586 real(c_double), intent(out) :: out(*)
587 end function
588
589 subroutine c_gpr_neb_result_destroy(r) &
590 bind(c, name='gpr_neb_result_destroy')
591 import :: c_ptr
592 type(c_ptr), value :: r
593 end subroutine
594
595 ! The dimer, NEB and minimizer entry points are bound below the config
596 ! types, so their interfaces carry the interoperable types.
597
598 ! Potentials
599 integer(c_int) function c_gpr_potential_lj(x, n, eps, sigma, E, G) &
600 bind(c, name='gpr_potential_lj')
601 import :: c_int, c_double
602 real(c_double), intent(in) :: x(*)
603 integer(c_int), value :: n
604 real(c_double), value :: eps, sigma
605 real(c_double), intent(out) :: e
606 real(c_double), intent(out) :: g(*)
607 end function
608
609 integer(c_int) function c_gpr_potential_muller_brown(xy, E, G) &
610 bind(c, name='gpr_potential_muller_brown')
611 import :: c_int, c_double
612 real(c_double), intent(in) :: xy(2)
613 real(c_double), intent(out) :: e, g(2)
614 end function
615
616 integer(c_int) function c_gpr_potential_leps(r, E, G) &
617 bind(c, name='gpr_potential_leps')
618 import :: c_int, c_double
619 real(c_double), intent(in) :: r(2)
620 real(c_double), intent(out) :: e, g(2)
621 end function
622
623 ! Oracle adapters
624 subroutine c_gpr_oracle_muller_brown(nc, pos, E, G, ud) &
625 bind(c, name='gpr_oracle_muller_brown')
626 import :: c_int, c_double, c_ptr
627 integer(c_int), value :: nc
628 real(c_double), intent(in) :: pos(*)
629 real(c_double), intent(out) :: e
630 real(c_double), intent(out) :: g(*)
631 type(c_ptr), value :: ud
632 end subroutine
633
634 subroutine c_gpr_oracle_leps(nc, pos, E, G, ud) &
635 bind(c, name='gpr_oracle_leps')
636 import :: c_int, c_double, c_ptr
637 integer(c_int), value :: nc
638 real(c_double), intent(in) :: pos(*)
639 real(c_double), intent(out) :: e
640 real(c_double), intent(out) :: g(*)
641 type(c_ptr), value :: ud
642 end subroutine
643
644 function c_gpr_bq_config_defaults() bind(C, name='gpr_bq_config_defaults') result(config)
645 import :: bqconfig
646 type(bqconfig) :: config
647 end function
648
649 type(c_ptr) function c_gpr_bq_create(config) bind(c, name='gpr_bq_create')
650 import :: c_ptr, bqconfig
651 type(bqconfig), intent(in) :: config
652 end function
653
654 subroutine c_gpr_bq_destroy(bq) bind(C, name='gpr_bq_destroy')
655 import :: c_ptr
656 type(c_ptr), value :: bq
657 end subroutine
658
659 integer(c_int) function c_gpr_bq_reset(bq, config) bind(C, name='gpr_bq_reset')
660 import :: c_ptr, c_int, bqconfig
661 type(c_ptr), value :: bq
662 type(bqconfig), intent(in) :: config
663 end function
664
665 integer(c_int) function c_gpr_bq_dimension(bq) bind(C, name='gpr_bq_dimension')
666 import :: c_ptr, c_int
667 type(c_ptr), value :: bq
668 end function
669
670 integer(c_int) function c_gpr_bq_n_observations(bq) bind(C, name='gpr_bq_n_observations')
671 import :: c_ptr, c_int
672 type(c_ptr), value :: bq
673 end function
674
675 integer(c_int) function c_gpr_bq_n_lengthscales(bq) bind(C, name='gpr_bq_n_lengthscales')
676 import :: c_ptr, c_int
677 type(c_ptr), value :: bq
678 end function
679
680 integer(c_int) function c_gpr_bq_train_checked(bq, X, X_len, y, y_len, noise, noise_len, n, d) &
681 bind(c, name='gpr_bq_train_checked')
682 import :: c_ptr, c_int, c_double, c_size_t
683 type(c_ptr), value :: bq
684 real(c_double), intent(in) :: x(*), y(*), noise(*)
685 integer(c_size_t), value :: x_len, y_len, noise_len
686 integer(c_int), value :: n, d
687 end function
688
689 integer(c_int) function c_gpr_bq_train_bounded_checked(bq, X, X_len, y, &
690 y_len, noise, noise_len, lower, lower_len, upper, upper_len, n, d) &
691 bind(c, name='gpr_bq_train_bounded_checked')
692 import :: c_ptr, c_int, c_double, c_size_t
693 type(c_ptr), value :: bq
694 real(c_double), intent(in) :: x(*), y(*), noise(*), lower(*), upper(*)
695 integer(c_size_t), value :: x_len, y_len, noise_len, lower_len, upper_len
696 integer(c_int), value :: n, d
697 end function
698
699 integer(c_int) function c_gpr_bq_append_checked(bq, X, X_len, y, y_len, noise, noise_len, n, d, refit) &
700 bind(c, name='gpr_bq_append_checked')
701 import :: c_ptr, c_int, c_double, c_size_t
702 type(c_ptr), value :: bq
703 real(c_double), intent(in) :: x(*), y(*), noise(*)
704 integer(c_size_t), value :: x_len, y_len, noise_len
705 integer(c_int), value :: n, d, refit
706 end function
707
708 integer(c_int) function c_gpr_bq_fit_hyperparameters_checked(bq, mode, report, ls, nls) &
709 bind(c, name='gpr_bq_fit_hyperparameters_checked')
710 import :: c_ptr, c_int, c_double, c_size_t
711 type(c_ptr), value :: bq
712 integer(c_int), value :: mode
713 type(*) :: report
714 real(c_double) :: ls(*)
715 integer(c_size_t), value :: nls
716 end function
717
718 integer(c_int) function c_gpr_bq_get_lengthscales_checked(bq, out, n) &
719 bind(c, name='gpr_bq_get_lengthscales_checked')
720 import :: c_ptr, c_int, c_double, c_size_t
721 type(c_ptr), value :: bq
722 real(c_double) :: out(*)
723 integer(c_size_t), value :: n
724 end function
725
726 integer(c_int) function c_gpr_bq_set_lengthscales_checked(bq, values, n) &
727 bind(c, name='gpr_bq_set_lengthscales_checked')
728 import :: c_ptr, c_int, c_double, c_size_t
729 type(c_ptr), value :: bq
730 real(c_double), intent(in) :: values(*)
731 integer(c_size_t), value :: n
732 end function
733
734 integer(c_int) function c_gpr_bq_get_magn_sigma2(bq, out) bind(C, name='gpr_bq_get_magn_sigma2')
735 import :: c_ptr, c_int, c_double
736 type(c_ptr), value :: bq
737 real(c_double) :: out
738 end function
739
740 integer(c_int) function c_gpr_bq_set_magn_sigma2(bq, value) bind(C, name='gpr_bq_set_magn_sigma2')
741 import :: c_ptr, c_int, c_double
742 type(c_ptr), value :: bq
743 real(c_double), value :: value
744 end function
745
746 integer(c_int) function c_gpr_bq_get_extra_sigma2(bq, out) bind(C, name='gpr_bq_get_extra_sigma2')
747 import :: c_ptr, c_int, c_double
748 type(c_ptr), value :: bq
749 real(c_double) :: out
750 end function
751
752 integer(c_int) function c_gpr_bq_set_extra_sigma2(bq, value) bind(C, name='gpr_bq_set_extra_sigma2')
753 import :: c_ptr, c_int, c_double
754 type(c_ptr), value :: bq
755 real(c_double), value :: value
756 end function
757
758 integer(c_int) function c_gpr_bq_predict_batch_checked(bq, X, X_len, mean, mean_len, var, var_len, n, d) &
759 bind(c, name='gpr_bq_predict_batch_checked')
760 import :: c_ptr, c_int, c_double, c_size_t
761 type(c_ptr), value :: bq
762 real(c_double), intent(in) :: x(*)
763 real(c_double) :: mean(*), var(*)
764 integer(c_size_t), value :: x_len, mean_len, var_len
765 integer(c_int), value :: n, d
766 end function
767
768 integer(c_int) function c_gpr_bq_kernel_mean_checked(bq, lower, nl, upper, nu, X, nx, n, d, z, nz) &
769 bind(c, name='gpr_bq_kernel_mean_checked')
770 import :: c_ptr, c_int, c_double, c_size_t
771 type(c_ptr), value :: bq
772 real(c_double), intent(in) :: lower(*), upper(*), x(*)
773 real(c_double) :: z(*)
774 integer(c_size_t), value :: nl, nu, nx, nz
775 integer(c_int), value :: n, d
776 end function
777
778 integer(c_int) function c_gpr_bq_kernel_double_integral_checked(bq, lower, nl, upper, nu, d, omega) &
779 bind(c, name='gpr_bq_kernel_double_integral_checked')
780 import :: c_ptr, c_int, c_double, c_size_t
781 type(c_ptr), value :: bq
782 real(c_double), intent(in) :: lower(*), upper(*)
783 integer(c_size_t), value :: nl, nu
784 integer(c_int), value :: d
785 real(c_double) :: omega
786 end function
787
788 integer(c_int) function c_gpr_bq_integrate_checked(bq, lower, nl, upper, nu, d, mean, var) &
789 bind(c, name='gpr_bq_integrate_checked')
790 import :: c_ptr, c_int, c_double, c_size_t
791 type(c_ptr), value :: bq
792 real(c_double), intent(in) :: lower(*), upper(*)
793 integer(c_size_t), value :: nl, nu
794 integer(c_int), value :: d
795 real(c_double) :: mean, var
796 end function
797
798 integer(c_int) function c_gpr_bq_integrate_report_checked(bq, lower, nl, upper, nu, d, report) &
799 bind(c, name='gpr_bq_integrate_report_checked')
800 import :: c_ptr, c_int, c_double, c_size_t
801 type(c_ptr), value :: bq
802 real(c_double), intent(in) :: lower(*), upper(*)
803 integer(c_size_t), value :: nl, nu
804 integer(c_int), value :: d
805 type(*) :: report
806 end function
807
808 integer(c_int) function c_gpr_bq_integrate_measure_checked(bq, kind, &
809 lower, nl, upper, nu, mean, nm, cov, nc, d, mout, vout, mass) &
810 bind(c, name='gpr_bq_integrate_measure_checked')
811 import :: c_ptr, c_int, c_double, c_size_t
812 type(c_ptr), value :: bq
813 integer(c_int), value :: kind, d
814 real(c_double), intent(in) :: lower(*), upper(*), mean(*), cov(*)
815 integer(c_size_t), value :: nl, nu, nm, nc
816 real(c_double) :: mout, vout, mass
817 end function
818
819 integer(c_int) function c_gpr_bq_integrate_uncertainty_checked(bq, kind, &
820 lower, nl, upper, nu, mean, nm, cov, nc, d, report) &
821 bind(c, name='gpr_bq_integrate_uncertainty_checked')
822 import :: c_ptr, c_int, c_double, c_size_t
823 type(c_ptr), value :: bq
824 integer(c_int), value :: kind, d
825 real(c_double), intent(in) :: lower(*), upper(*), mean(*), cov(*)
826 integer(c_size_t), value :: nl, nu, nm, nc
827 type(*) :: report
828 end function
829
830 integer(c_int) function c_gpr_bq_set_basis(bq, basis) bind(C, name='gpr_bq_set_basis')
831 import :: c_ptr, c_int
832 type(c_ptr), value :: bq
833 integer(c_int), value :: basis
834 end function
835
836 integer(c_int) function c_gpr_bq_get_basis(bq, basis) bind(C, name='gpr_bq_get_basis')
837 import :: c_ptr, c_int
838 type(c_ptr), value :: bq
839 integer(c_int) :: basis
840 end function
841
842 integer(c_int) function c_gpr_bq_integrate_cumulative_checked(bq, lower, nl, upper, nu, nlim, d, mean, nm, cov, nc) &
843 bind(c, name='gpr_bq_integrate_cumulative_checked')
844 import :: c_ptr, c_int, c_double, c_size_t
845 type(c_ptr), value :: bq
846 real(c_double), intent(in) :: lower(*), upper(*)
847 real(c_double) :: mean(*), cov(*)
848 integer(c_size_t), value :: nl, nu, nm, nc
849 integer(c_int), value :: nlim, d
850 end function
851
852 integer(c_int) function c_gpr_bq_sample_cumulative_checked(bq, lower, nl, upper, nu, nlim, d, ndraw, seed, draws, n) &
853 bind(c, name='gpr_bq_sample_cumulative_checked')
854 import :: c_ptr, c_int, c_double, c_size_t, c_int64_t
855 type(c_ptr), value :: bq
856 real(c_double), intent(in) :: lower(*), upper(*)
857 integer(c_size_t), value :: nl, nu, n
858 integer(c_int), value :: nlim, d, ndraw
859 integer(c_int64_t), value :: seed
860 real(c_double) :: draws(*)
861 end function
862
864 bq, lower, nl, upper, nu, X, nx, noise, nn, ncan, d, delta, nd) &
865 bind(c, name='gpr_bq_candidate_variance_reduction_checked')
866 import :: c_ptr, c_int, c_double, c_size_t
867 type(c_ptr), value :: bq
868 real(c_double), intent(in) :: lower(*), upper(*), x(*), noise(*)
869 real(c_double) :: delta(*)
870 integer(c_size_t), value :: nl, nu, nx, nn, nd
871 integer(c_int), value :: ncan, d
872 end function
873
875 bq, lower, nl, upper, nu, X, nx, noise, nn, ncan, d, batch, &
876 selected, ns, reduction, nr) &
877 bind(c, name='gpr_bq_select_batch_candidates_checked')
878 import :: c_ptr, c_int, c_double, c_size_t
879 type(c_ptr), value :: bq
880 real(c_double), intent(in) :: lower(*), upper(*), x(*), noise(*)
881 integer(c_int) :: selected(*)
882 real(c_double) :: reduction(*)
883 integer(c_size_t), value :: nl, nu, nx, nn, ns, nr
884 integer(c_int), value :: ncan, d, batch
885 end function
886
887 integer(c_int) function c_gpr_bq_calibrate_loo_checked(bq, probability, report) &
888 bind(c, name='gpr_bq_calibrate_loo_checked')
889 import :: c_ptr, c_int, c_double
890 type(c_ptr), value :: bq
891 real(c_double), value :: probability
892 type(*) :: report
893 end function
894
895 integer(c_int) function c_gpr_bq_calibrate_loo_scores_checked(bq, probability, report, scores, n) &
896 bind(c, name='gpr_bq_calibrate_loo_scores_checked')
897 import :: c_ptr, c_int, c_double, c_size_t
898 type(c_ptr), value :: bq
899 real(c_double), value :: probability
900 type(*) :: report
901 real(c_double) :: scores(*)
902 integer(c_size_t), value :: n
903 end function
904
905 integer(c_int) function c_gpr_fes_config_init(out, out_size) &
906 bind(c, name='gpr_fes_config_init')
907 import :: c_int, c_size_t, fesconfig
908 type(fesconfig), intent(inout) :: out
909 integer(c_size_t), value :: out_size
910 end function
911
912 integer(c_int) function c_gpr_fes_rate_config_init(out, out_size) &
913 bind(c, name='gpr_fes_rate_config_init')
914 import :: c_int, c_size_t, fesrateconfig
915 type(fesrateconfig), intent(inout) :: out
916 integer(c_size_t), value :: out_size
917 end function
918
919 subroutine c_gpr_fes_destroy(fes) bind(C, name='gpr_fes_destroy')
920 import :: c_ptr
921 type(c_ptr), value :: fes
922 end subroutine
923
924 integer(c_int) function c_gpr_fes_dimension(fes) bind(C, name='gpr_fes_dimension')
925 import :: c_ptr, c_int
926 type(c_ptr), value :: fes
927 end function
928
929 integer(c_int) function c_gpr_fes_n_observations(fes) &
930 bind(c, name='gpr_fes_n_observations')
931 import :: c_ptr, c_int
932 type(c_ptr), value :: fes
933 end function
934
935 integer(c_int) function c_gpr_fes_noise_from_weights_checked(weights, &
936 weights_len, reference_variance, min_relative_weight, noise, &
937 noise_len, n_obs) bind(C, name='gpr_fes_noise_from_weights_checked')
938 import :: c_int, c_double, c_size_t
939 real(c_double), intent(in) :: weights(*)
940 integer(c_size_t), value :: weights_len
941 real(c_double), value :: reference_variance, min_relative_weight
942 real(c_double) :: noise(*)
943 integer(c_size_t), value :: noise_len
944 integer(c_int), value :: n_obs
945 end function
946
947 integer(c_int) function c_gpr_fes_train_checked(fes, s, s_len, F, F_len, &
948 F_noise, F_noise_len, grad, grad_len, grad_noise, grad_noise_len, &
949 present, present_len, n_obs, dimension) &
950 bind(c, name='gpr_fes_train_checked')
951 import :: c_ptr, c_int, c_double, c_size_t
952 type(c_ptr), value :: fes
953 real(c_double), intent(in) :: s(*), f(*)
954 integer(c_size_t), value :: s_len, f_len
955 type(c_ptr), value :: f_noise, grad, grad_noise, present
956 integer(c_size_t), value :: f_noise_len, grad_len, grad_noise_len
957 integer(c_size_t), value :: present_len
958 integer(c_int), value :: n_obs, dimension
959 end function
960
961 integer(c_int) function c_gpr_fes_predict_batch_checked(fes, s, s_len, &
962 F, F_len, grad, grad_len, var, var_len, n_queries, dimension) &
963 bind(c, name='gpr_fes_predict_batch_checked')
964 import :: c_ptr, c_int, c_double, c_size_t
965 type(c_ptr), value :: fes
966 real(c_double), intent(in) :: s(*)
967 real(c_double) :: f(*)
968 type(c_ptr), value :: grad, var
969 integer(c_size_t), value :: s_len, f_len, grad_len, var_len
970 integer(c_int), value :: n_queries, dimension
971 end function
972
973 integer(c_int) function c_gpr_fes_rate_path_checked(fes, path, path_len, &
974 n_path, dimension, reactant_index, product_index, diffusion, &
975 diffusion_len, config, report) &
976 bind(c, name='gpr_fes_rate_path_checked')
977 import :: c_ptr, c_int, c_double, c_size_t, fesrateconfig, fesratereport
978 type(c_ptr), value :: fes
979 real(c_double), intent(in) :: path(*), diffusion(*)
980 integer(c_size_t), value :: path_len, diffusion_len
981 integer(c_int), value :: n_path, dimension, reactant_index, product_index
982 type(fesrateconfig), intent(in) :: config
983 type(fesratereport), intent(inout) :: report
984 end function
985
986 ! Scalar surrogate and parameter search (ABI 1.26). An argument declared
987 ! type(c_ptr) is optional in C: pass c_null_ptr with a zero length, or
988 ! c_loc of a target array.
989 type(c_ptr) function c_gpr_sgp_create(dimension, kernel) &
990 bind(c, name='gpr_sgp_create')
991 import :: c_ptr, c_int
992 integer(c_int), value :: dimension, kernel
993 end function
994
995 subroutine c_gpr_sgp_destroy(sgp) bind(C, name='gpr_sgp_destroy')
996 import :: c_ptr
997 type(c_ptr), value :: sgp
998 end subroutine
999
1000 integer(c_int) function c_gpr_sgp_n_observations(sgp) &
1001 bind(c, name='gpr_sgp_n_observations')
1002 import :: c_ptr, c_int
1003 type(c_ptr), value :: sgp
1004 end function
1005
1006 integer(c_int) function c_gpr_sgp_set_kernel(sgp, kernel) &
1007 bind(c, name='gpr_sgp_set_kernel')
1008 import :: c_ptr, c_int
1009 type(c_ptr), value :: sgp
1010 integer(c_int), value :: kernel
1011 end function
1012
1013 integer(c_int) function c_gpr_sgp_set_mean_basis(sgp, basis) &
1014 bind(c, name='gpr_sgp_set_mean_basis')
1015 import :: c_ptr, c_int
1016 type(c_ptr), value :: sgp
1017 integer(c_int), value :: basis
1018 end function
1019
1020 integer(c_int) function c_gpr_sgp_set_hyperparameters_checked(sgp, &
1021 length_scales, length_scales_len, signal_variance, noise_variance) &
1022 bind(c, name='gpr_sgp_set_hyperparameters_checked')
1023 import :: c_ptr, c_int, c_double, c_size_t
1024 type(c_ptr), value :: sgp
1025 real(c_double), intent(in) :: length_scales(*)
1026 integer(c_size_t), value :: length_scales_len
1027 real(c_double), value :: signal_variance, noise_variance
1028 end function
1029
1030 integer(c_int) function c_gpr_sgp_get_hyperparameters_checked(sgp, &
1031 length_scales, length_scales_len, signal_variance, noise_variance) &
1032 bind(c, name='gpr_sgp_get_hyperparameters_checked')
1033 import :: c_ptr, c_int, c_double, c_size_t
1034 type(c_ptr), value :: sgp
1035 real(c_double) :: length_scales(*)
1036 integer(c_size_t), value :: length_scales_len
1037 real(c_double) :: signal_variance, noise_variance
1038 end function
1039
1040 integer(c_int) function c_gpr_sgp_observe_checked(sgp, X, X_len, y, &
1041 y_len, noise_var, noise_var_len, n_obs, n_dims) &
1042 bind(c, name='gpr_sgp_observe_checked')
1043 import :: c_ptr, c_int, c_double, c_size_t
1044 type(c_ptr), value :: sgp
1045 real(c_double), intent(in) :: x(*), y(*)
1046 type(c_ptr), value :: noise_var
1047 integer(c_size_t), value :: x_len, y_len, noise_var_len
1048 integer(c_int), value :: n_obs, n_dims
1049 end function
1050
1051 integer(c_int) function c_gpr_sgp_fit_checked(sgp, optimize, n_starts, &
1052 log_marginal_likelihood) bind(C, name='gpr_sgp_fit_checked')
1053 import :: c_ptr, c_int, c_double
1054 type(c_ptr), value :: sgp
1055 integer(c_int), value :: optimize, n_starts
1056 real(c_double) :: log_marginal_likelihood
1057 end function
1058
1059 integer(c_int) function c_gpr_sgp_predict_checked(sgp, X, X_len, &
1060 n_queries, n_dims, query_noise_var, mean, mean_len, std, std_len) &
1061 bind(c, name='gpr_sgp_predict_checked')
1062 import :: c_ptr, c_int, c_double, c_size_t
1063 type(c_ptr), value :: sgp
1064 real(c_double), intent(in) :: x(*)
1065 integer(c_size_t), value :: x_len, mean_len, std_len
1066 integer(c_int), value :: n_queries, n_dims
1067 real(c_double), value :: query_noise_var
1068 real(c_double) :: mean(*)
1069 type(c_ptr), value :: std
1070 end function
1071
1072 type(c_ptr) function c_gpr_psearch_create(lower, lower_len, upper, &
1073 upper_len, axis_kind, axis_kind_len, dimension, kernel, noisy) &
1074 bind(c, name='gpr_psearch_create')
1075 import :: c_ptr, c_int, c_double, c_size_t
1076 real(c_double), intent(in) :: lower(*), upper(*)
1077 type(c_ptr), value :: axis_kind
1078 integer(c_size_t), value :: lower_len, upper_len, axis_kind_len
1079 integer(c_int), value :: dimension, kernel, noisy
1080 end function
1081
1082 subroutine c_gpr_psearch_destroy(search) bind(C, name='gpr_psearch_destroy')
1083 import :: c_ptr
1084 type(c_ptr), value :: search
1085 end subroutine
1086
1087 integer(c_int) function c_gpr_psearch_set_allowed_values_checked(search, &
1088 axis, values, values_len, categorical) &
1089 bind(c, name='gpr_psearch_set_allowed_values_checked')
1090 import :: c_ptr, c_int, c_double, c_size_t
1091 type(c_ptr), value :: search
1092 integer(c_int), value :: axis, categorical
1093 real(c_double), intent(in) :: values(*)
1094 integer(c_size_t), value :: values_len
1095 end function
1096
1097 integer(c_int) function c_gpr_psearch_observe_checked(search, X, X_len, &
1098 y, y_len, noise_var, noise_var_len, constraint, constraint_len, &
1099 n_obs, n_dims) bind(C, name='gpr_psearch_observe_checked')
1100 import :: c_ptr, c_int, c_double, c_size_t
1101 type(c_ptr), value :: search
1102 real(c_double), intent(in) :: x(*), y(*)
1103 type(c_ptr), value :: noise_var, constraint
1104 integer(c_size_t), value :: x_len, y_len, noise_var_len, constraint_len
1105 integer(c_int), value :: n_obs, n_dims
1106 end function
1107
1108 integer(c_int) function c_gpr_psearch_propose_checked(search, q, X, &
1109 X_len, n_dims, n_proposed) bind(C, name='gpr_psearch_propose_checked')
1110 import :: c_ptr, c_int, c_double, c_size_t
1111 type(c_ptr), value :: search
1112 integer(c_int), value :: q, n_dims
1113 real(c_double) :: x(*)
1114 integer(c_size_t), value :: x_len
1115 integer(c_int) :: n_proposed
1116 end function
1117
1118 integer(c_int) function c_gpr_psearch_best_checked(search, x, x_len, &
1119 loss) bind(C, name='gpr_psearch_best_checked')
1120 import :: c_ptr, c_int, c_double, c_size_t
1121 type(c_ptr), value :: search
1122 real(c_double) :: x(*)
1123 integer(c_size_t), value :: x_len
1124 real(c_double) :: loss
1125 end function
1126 end interface
1127
1128 ! =====================================================================
1129 ! Config types (Fortran derived types with defaults)
1130 ! =====================================================================
1131
1132 !> GP/TP model configuration (gpr_model_config_t). The initializers
1133 !> are gpr_model_config_defaults(), which ModelConfig() returns.
1134 type, public, bind(C) :: modelconfig
1135 real(c_double) :: sigma2 = 1.0d-4
1136 real(c_double) :: jitter_sigma2 = 1.0d-4
1137 real(c_double) :: magn_sigma2 = 0.0d0
1138 real(c_double) :: const_sigma2 = 0.0d0
1139 real(c_double) :: prior_mu = 0.0d0
1140 real(c_double) :: prior_nu = 20.0d0
1141 real(c_double) :: prior_s2 = 1.0d0
1142 integer(c_int) :: optim_alg = 0 ! GPR_OPT_SCG
1143 integer(c_int) :: max_iter = 400
1144 real(c_double) :: tol_func = 1.0d-3
1145 real(c_double) :: tol_sol = 1.0d-3
1146 integer(c_int) :: report_level = 0
1147 real(c_double) :: tp_hyperprior_a = 1.0d-20
1148 real(c_double) :: tp_hyperprior_b = 1.0d-20
1149 integer(c_int) :: use_zbl_prior_mean = 0
1150 integer(c_int) :: use_ff_prior_mean = 0
1151 integer(c_int) :: use_hssvd_backend = 1 ! GPR_HSSVD_BACKEND_HSSVD
1152 end type
1153
1154 !> Result of a prior-free negative log marginal-likelihood fit (ABI 1.13).
1155 type, public, bind(C) :: marginallikelihoodreport
1156 real(c_double) :: objective
1157 real(c_double) :: log_determinant
1158 real(c_double) :: quadratic
1159 real(c_double) :: signal_variance
1160 real(c_double) :: noise_variance
1161 integer(c_int) :: n_lengthscales
1162 integer(c_int) :: optimizer_iterations
1163 end type
1164
1165 !> Residual-calibration report shared by held-out force and LOO workflows.
1166 type, public, bind(C) :: calibrationreport
1167 integer(c_size_t) :: components
1168 real(c_double) :: nominal_probability
1169 real(c_double) :: empirical_coverage
1170 real(c_double) :: calibrated_coverage
1171 real(c_double) :: posterior_variance_scale
1172 real(c_double) :: calibration_scale
1173 real(c_double) :: mean_standardized_residual
1174 real(c_double) :: rms_standardized_residual
1175 real(c_double) :: mean_log_predictive_density
1176 end type
1177
1178 type, public, bind(C) :: bqlooreport
1179 type(calibrationreport) :: summary
1180 integer(c_size_t) :: z_score_count
1181 end type
1182
1183 !> Result of a Bayesian quadrature hyperparameter fit (ABI 1.17): the
1184 !> MarginalLikelihoodReport fields plus the number of failed trial points.
1185 type, public, bind(C) :: bqfitreport
1186 real(c_double) :: objective
1187 real(c_double) :: log_determinant
1188 real(c_double) :: quadratic
1189 real(c_double) :: signal_variance
1190 real(c_double) :: noise_variance
1191 integer(c_int) :: n_lengthscales
1192 integer(c_int) :: optimizer_iterations
1193 integer(c_int) :: failed_trials
1194 end type
1195
1196 !> NEB search configuration. Field order matches gpr_neb_config_t;
1197 !> the initializers are gpr_neb_config_defaults(), which NEBConfig()
1198 !> returns.
1199 type, public, bind(C) :: nebconfig
1200 integer(c_int) :: mode = 4 ! GPR_NEB_GP_OIE
1201 real(c_double) :: conv_tol = 0.05d0
1202 integer(c_int) :: max_outer_iter = 200
1203 integer(c_int) :: max_inner_iter = 100
1204 real(c_double) :: inner_step_size = 0.01d0
1205 real(c_double) :: spring_constant = 5.0d0
1206 integer(c_int) :: climbing_image = 1
1207 real(c_double) :: ci_activation_tol = 0.5d0
1208 integer(c_int) :: n_atoms = 0
1209 integer(c_int) :: use_idpp = 0
1210 integer(c_int) :: acquisition = 7 ! GPR_ACQ_TPE
1211 real(c_double) :: ucb_kappa = 1.0d0
1212 integer(c_int) :: evals_per_iter = 1
1213 integer(c_int) :: use_triplet = 0
1214 integer(c_int) :: seed = 42 ! unsigned in C, same width
1215 integer(c_int) :: verbose = 1
1216 integer(c_int) :: uncertainty_mode = 0 ! GPR_UQ_MAP
1217 integer(c_int) :: use_psis_laplace = 0
1218 integer(c_int) :: use_psis_deterministic = 1
1219 integer(c_int) :: use_delta_method = 0
1220 integer(c_int) :: use_zbl_prior_mean = 0
1221 integer(c_int) :: rff_features = 0
1222 integer(c_int) :: hyperparameter_mode = 0 ! GPR_HOPT_SCG
1223 integer(c_int) :: hyperparameter_objective = 0 ! GPR_HOBJ_NLML
1224 integer(c_int) :: max_inner_iter_gp = 0
1225 real(c_double) :: inner_conv_tol = 1.0d-3
1226 integer(c_int) :: trust_metric = 2 ! GPR_DIST_EMD
1227 integer(c_int) :: use_adaptive_trust = 0
1228 real(c_double) :: trust_radius = 0.5d0
1229 real(c_double) :: trust_adaptive_a = 1.3d0
1230 real(c_double) :: trust_adaptive_floor = 0.25d0
1231 real(c_double) :: trust_t_min = 0.15d0
1232 real(c_double) :: trust_delta_explore = 0.35d0
1233 integer(c_int) :: trust_half_life = 50
1234 real(c_double) :: trust_ratio_at_limit = 0.4d0
1235 integer(c_int) :: scalapack_block_size = 0
1236 integer(c_int) :: scalapack_nprow = 0
1237 real(c_double) :: lbfgs_max_move = 0.1d0
1238 integer(c_int) :: lbfgs_memory = 20
1239 real(c_double) :: lbfgs_inverse_curvature = 0.01d0
1240 real(c_double) :: lbfgs_finite_difference = 1.0d-6
1241 integer(c_int) :: lbfgs_auto_scale = 1
1242 integer(c_int) :: lbfgs_angle_reset = 1
1243 integer(c_int) :: lbfgs_distance_reset = 1
1244 integer(c_int) :: reparam_period = 0
1245 real(c_double) :: reparam_tol = -1.0d0
1246 integer(c_int) :: use_ff_prior_mean = 0
1247 end type
1248
1249 !> Minimizer configuration (gpr_minimize_config_t). The initializers
1250 !> are gpr_minimize_config_defaults(), which MinimizeConfig() returns.
1251 !> max_iter bounds outer surrogate-relaxation cycles (up to 200 inner
1252 !> surrogate steps by default; override via
1253 !> gpr_minimize_request_max_inner_steps).
1254 type, public, bind(C) :: minimizeconfig
1255 real(c_double) :: trust_radius = 0.1d0
1256 real(c_double) :: conv_tol = 5.0d-3
1257 integer(c_int) :: max_iter = 500
1258 integer(c_int) :: max_oracle_calls = 0
1259 integer(c_int) :: gp_train_iter = 300
1260 integer(c_int) :: n_initial_perturb = 4
1261 real(c_double) :: perturb_scale = 0.1d0
1262 real(c_double) :: max_move = 0.1d0
1263 integer(c_int) :: max_training_points = 0
1264 integer(c_int) :: fps_history = 0
1265 real(c_double) :: jitter_sigma2 = 1.0d-6
1266 integer(c_int) :: verbose = 1
1267 integer(c_int) :: seed = 42
1268 end type
1269
1270 !> Dimer search configuration. Field order matches gpr_dimer_config_t;
1271 !> the initializers are gpr_dimer_config_defaults().
1272 type, public, bind(C) :: dimerconfig
1273 real(c_double) :: dimer_sep = 0.01d0
1274 real(c_double) :: t_dimer = 0.1d0
1275 integer(c_int) :: conv_norm = 0 ! GPR_NORM_L2
1276 real(c_double) :: t_anglerot_init = 0.0873d0 ! radians
1277 integer(c_int) :: num_iter_initrot = 6
1278 real(c_double) :: t_anglerot_gp = 0.01d0
1279 integer(c_int) :: num_iter_rot_gp = 0
1280 integer(c_int) :: initrot_nogp = 0
1281 real(c_double) :: step_length = 0.1d0
1282 real(c_double) :: max_step_length = 0.05d0
1283 real(c_double) :: disp_max = 0.5d0
1284 real(c_double) :: ratio_at_limit = 2.0d0 / 3.0d0
1285 integer(c_int) :: num_bigiter = 300
1286 integer(c_int) :: num_iter = 200
1287 integer(c_int) :: num_bigiter_initloc = 0
1288 integer(c_int) :: num_bigiter_initparam = 0
1289 integer(c_int) :: islarge_num_iter = 2
1290 integer(c_int) :: eval_image1 = 0
1291 integer(c_int) :: divisor_t_dimer_gp = 10
1292 integer(c_int) :: use_prune = 0
1293 integer(c_int) :: start_prune_at = 10
1294 integer(c_int) :: nprune_vals = 4
1295 real(c_double) :: prune_threshold = 0.5d0
1296 real(c_double) :: cell(9) = 0.0d0
1297 real(c_double) :: gp_sigma2 = 1.0d-4
1298 real(c_double) :: gp_jitter = 1.0d-4
1299 integer(c_int) :: gp_max_iter = 400
1300 integer(c_int) :: uncertainty_mode = 0 ! GPR_UQ_MAP
1301 real(c_double) :: variance_accept_tau = 0.0d0
1302 real(c_double) :: variance_accept_tau_relative = 0.0d0
1303 integer(c_int) :: use_psis_laplace = 0
1304 integer(c_int) :: use_psis_deterministic = 1
1305 integer(c_int) :: use_delta_method = 0
1306 integer(c_int) :: use_zbl_prior_mean = 0
1307 integer(c_int) :: report_level = 2
1308 integer(c_int) :: es_use_adaptive_threshold = 0
1309 real(c_double) :: es_threshold = 1.2d0
1310 real(c_double) :: es_adaptive_a = 1.3d0
1311 real(c_double) :: es_adaptive_floor = 0.25d0
1312 real(c_double) :: es_t_min = 0.15d0
1313 real(c_double) :: es_delta_explore = 0.35d0
1314 integer(c_int) :: es_half_life = 50
1315 integer(c_int) :: use_ff_prior_mean = 0
1316 integer(c_int) :: vibrational_stencil = 0
1317 end type
1318
1319 !> Outcome of a dimer search (gpr_dimer_report_t). Two fields are
1320 !> inputs: max_oracle_calls, a budget of oracle calls that is never
1321 !> exceeded, with 0 for none, and certificate_step, the Cartesian
1322 !> displacement of the stencil that certifies the stopped midpoint, with
1323 !> 0 for the library step.
1324 type, public, bind(C) :: dimerreport
1325 integer(c_size_t) :: struct_size = 0
1326 integer(c_int) :: converged = 0
1327 integer(c_int) :: stop = gpr_dimer_stop_unspecified
1328 real(c_double) :: curvature = 0.0d0
1329 real(c_double) :: final_force_norm = 0.0d0
1330 integer(c_long) :: n_force_calls = 0
1331 integer(c_long) :: n_gp_calls = 0
1332 integer(c_long) :: n_iterations = 0
1333 integer(c_int) :: max_oracle_calls = 0
1334 !> E_saddle + energy_zero_level is the absolute saddle energy.
1335 real(c_double) :: energy_zero_level = 0.0d0
1336 !> Input: displacement of the certificate stencil; 0 selects the
1337 !> library step.
1338 real(c_double) :: certificate_step = 0.0d0
1339 !> Oracle evaluations the certificate spent; not part of
1340 !> n_force_calls.
1341 integer(c_long) :: n_certificate_calls = 0
1342 !> 1 when the certificate found one negative mode.
1343 integer(c_int) :: certified = 0
1344 end type
1345
1346 !> Outcome of a NEB run (gpr_neb_report_t), from NEBResult%report.
1347 type, public, bind(C) :: nebreport
1348 integer(c_size_t) :: struct_size = 0
1349 integer(c_int) :: converged = 0
1350 integer(c_int) :: convergence_status = gpr_neb_not_converged
1351 !> 1 when a GP surrogate relaxed the band.
1352 integer(c_int) :: gp_used = 0
1353 integer(c_int) :: max_energy_image = 0
1354 integer(c_long) :: oracle_calls = 0
1355 integer(c_long) :: oracle_calls_to_convergence = 0
1356 !> Every oracle evaluation, band and dimer bursts together.
1357 integer(c_long) :: callback_calls = 0
1358 integer(c_long) :: outer_iterations = 0
1359 integer(c_long) :: hyperparameter_refits = 0
1360 real(c_double) :: barrier = 0.0d0
1361 real(c_double) :: reverse_barrier = 0.0d0
1362 integer(c_int) :: dimer_ran = 0
1363 integer(c_int) :: dimer_converged = 0
1364 integer(c_long) :: dimer_oracle_calls = 0
1365 integer(c_long) :: mmf_bursts = 0
1366 !> 1 when the band index certificate holds.
1367 integer(c_int) :: certified = 0
1368 !> Negative-mode count of that certificate.
1369 integer(c_int) :: index = 0
1370 !> Oracle evaluations the certificate spent. Not part of the
1371 !> search count (oracle_calls_to_convergence).
1372 integer(c_long) :: n_certificate_calls = 0
1373 !> Rows loaded from a seed (ABI 1.25). Not part of oracle_calls.
1374 integer(c_int) :: prior_observations = 0
1375 end type
1376
1377 !> Options of the derivative primitives (gpr_derivative_options_t,
1378 !> ABI 1.20). The wrappers set struct_size.
1379 type, public, bind(C) :: derivativeoptions
1380 integer(c_size_t) :: struct_size = 0
1381 integer(c_int) :: energy_unit = gpr_energy_unit_native
1382 integer(c_int) :: length_unit = gpr_length_unit_native
1383 !> 1: project rigid translations and rotations.
1384 integer(c_int) :: project_rigid = 0
1385 !> Fail-closed posterior energy std; <= 0 disables the check.
1386 real(c_double) :: max_energy_std = 0.0d0
1387 !> Stencil step of the Hessian covariance; <= 0 means 1e-3.
1388 real(c_double) :: variance_step = 0.0d0
1389 end type
1390
1391 !> Report of one derivative call (gpr_derivative_report_t, ABI 1.20).
1392 !> Written on success and on GPR_ERR_OUT_OF_SUPPORT.
1393 type, public, bind(C) :: derivativereport
1394 integer(c_size_t) :: struct_size = 0
1395 integer(c_int) :: energy_unit = 0
1396 integer(c_int) :: length_unit = 0
1397 integer(c_int) :: n_points = 0
1398 integer(c_int) :: projected = 0
1399 real(c_double) :: max_energy_std = 0.0d0
1400 !> 0-based point index of max_energy_std.
1401 integer(c_int) :: max_energy_std_point = -1
1402 real(c_double) :: max_translation_residual = -1.0d0
1403 real(c_double) :: max_rotation_residual = -1.0d0
1404 !> condition_fixed: 1 bordered factor, 0 refactored, else -1.
1405 integer(c_int) :: factor_appended = -1
1406 end type
1407
1408 !> Prefactor options (gpr_htst_options_t, ABI 1.20); start from
1409 !> gpr_htst_options_defaults().
1410 type, public, bind(C) :: htstoptions
1411 integer(c_size_t) :: struct_size = 0
1412 integer(c_int) :: enabled = 1
1413 integer(c_int) :: mode = gpr_htst_refined
1414 integer(c_int) :: project_translation = 1
1415 integer(c_int) :: project_rotation = 1
1416 integer(c_int) :: max_measured = 0
1417 real(c_double) :: omega_scale = 1.0d0
1418 real(c_double) :: tolerance = 1.0d-3
1419 real(c_double) :: fd_step = 1.0d-3
1420 real(c_double) :: variance_step = 0.0d0
1421 end type
1422
1423 !> One half of the prefactor (gpr_htst_half_t, ABI 1.20).
1424 type, public, bind(C) :: htsthalf
1425 integer(c_size_t) :: struct_size = 0
1426 integer(c_int) :: status = gpr_htst_unavailable
1427 integer(c_int) :: kind = gpr_htst_minimum
1428 integer(c_int) :: source = gpr_htst_source_refined
1429 integer(c_int) :: n_coords = 0
1430 integer(c_int) :: n_projected = 0
1431 integer(c_int) :: n_modes = 0
1432 integer(c_int) :: n_negative = 0
1433 integer(c_int) :: oracle_calls = 0
1434 integer(c_int) :: n_measured = 0
1435 integer(c_int) :: converged = 0
1436 real(c_double) :: ln_sum = 0.0d0
1437 !> GP-variance estimate of the spread of ln_sum, never a certificate.
1438 real(c_double) :: ln_sum_std = 0.0d0
1439 real(c_double) :: imaginary_frequency = 0.0d0
1440 !> omega_scale of ln_sum and the frequencies.
1441 real(c_double) :: omega_scale = 0.0d0
1442 end type
1443
1444 !> Local-band knobs (gpr_local_band_config_t). The initializers are
1445 !> gpr_local_band_config_defaults(), which LocalBandConfig() returns.
1446 type, public, bind(C) :: localbandconfig
1447 real(c_double) :: fraction = 0.1d0
1448 real(c_double) :: radius = 0.0d0
1449 integer(c_int) :: window = 16
1450 real(c_double) :: trust = 0.3d0
1451 integer(c_int) :: inner_max = 20
1452 integer(c_int) :: refit_iters = 0
1453 real(c_double) :: inner_tol_factor = 0.5d0
1454 integer(c_int) :: phase = 1
1455 integer(c_int) :: refit_every = 4
1456 real(c_double) :: noise = 1.0d-3
1457 real(c_double) :: pair_cutoff = 9.5d0
1458 real(c_double) :: pair_spacing = 0.0d0
1459 real(c_double) :: far_trust = 0.5d0
1460 real(c_double) :: far_refresh = 0.05d0
1461 integer(c_int) :: initial_sweep = 1
1462 integer(c_int) :: batch = 1
1463 integer(c_int) :: batch_growth = 8
1464 integer(c_int) :: batch_max = 3
1465 integer(c_int) :: sweep_images = 0
1466 integer(c_int) :: jacobi = 0
1467 real(c_double) :: grow_radius = 3.0d0
1468 integer(c_int) :: safeguard = 1
1469 integer(c_int) :: keep_memory = 1
1470 integer(c_int) :: residual = 1
1471 real(c_double) :: pair_split = 7.0d0
1472 real(c_double) :: pair_tail_refresh = 0.0d0
1473 integer(c_int) :: cycles = 2
1474 integer(c_int) :: sweep = 0
1475 integer(c_int) :: force_stop_certificate = 0
1476 real(c_double) :: certificate_step = 0.0d0
1477 integer(c_int) :: vibrational_stencil = 0
1478 end type
1479
1480 !> Initial path of a periodic band (gpr_periodic_band_initial_t).
1481 integer(c_int), parameter, public :: gpr_periodic_band_linear = 0
1482 integer(c_int), parameter, public :: gpr_periodic_band_idpp = 1
1483 integer(c_int), parameter, public :: gpr_periodic_band_sidpp = 2
1484 !> convergence_norm value that keeps the mode's own norm.
1485 integer(c_int), parameter, public :: gpr_periodic_norm_unset = -1
1486
1487 !> Periodic local band (gpr_periodic_band_config_t). The initializers
1488 !> are gpr_periodic_band_config_defaults(), which PeriodicBandConfig()
1489 !> returns. The local knobs stay on LocalBandConfig.
1490 type, public, bind(C) :: periodicbandconfig
1491 real(c_double) :: fmax = 0.05d0
1492 real(c_double) :: spring_constant = 5.0d0
1493 real(c_double) :: max_move = 0.2d0
1494 integer(c_int) :: steps = 1000
1495 integer(c_int) :: climb = 1
1496 integer(c_int) :: initial = gpr_periodic_band_linear
1497 integer(c_int) :: seed = 42
1498 integer(c_int) :: verbose = 0
1499 integer(c_int) :: convergence_norm = gpr_periodic_norm_unset
1500 end type
1501
1502 !> OCINEB dimer-burst controls (gpr_ocineb_config_t). The initializers
1503 !> are gpr_ocineb_config_defaults(), which OCINEBConfig() returns.
1504 type, public, bind(C) :: ocinebconfig
1505 integer(c_int) :: use_mmf = 1
1506 real(c_double) :: trigger_force = 0.0d0
1507 real(c_double) :: trigger_factor = 0.31d0
1508 integer(c_long) :: max_steps = 0
1509 real(c_double) :: alignment_cos_tol = 0.85d0
1510 real(c_double) :: force_tolerance = 0.05d0
1511 integer(c_int) :: dimer_max_phases = 0
1512 integer(c_int) :: dimer_max_inner_iter = 0
1513 integer(c_int) :: dimer_max_rot_iter = 10
1514 integer(c_int) :: dimer_eval_image1 = 1
1515 real(c_double) :: perturb_along_tangent = 0.05d0
1516 real(c_double) :: max_burst_displacement = 0.0d0
1517 end type
1518
1519 !> The C atoms descriptor (gpr_atoms_config_t). AtomsConfig(n, ...) fills
1520 !> it; it is public so its layout can be checked against the header.
1521 type, public, bind(C) :: atomsdescriptor
1522 integer(c_int) :: n_atoms_total = 0
1523 type(c_ptr) :: is_frozen = c_null_ptr
1524 type(c_ptr) :: atom_types = c_null_ptr
1525 type(c_ptr) :: atomic_nrs = c_null_ptr
1526 type(c_ptr) :: positions = c_null_ptr
1527 real(c_double) :: actdist_fro = 0.0d0
1528 end type
1529
1530 !> Report of held-out random-feature selection (gpr_rff_selection_t).
1531 type, public, bind(C) :: rffselection
1532 integer(c_int) :: accepted = 0
1533 integer(c_int) :: deferred = 0
1534 integer(c_int) :: automatic = 0
1535 integer(c_int) :: features = 0
1536 integer(c_int) :: start_features = 0
1537 integer(c_int) :: limit_features = 0
1538 integer(c_int) :: fit_geometries = 0
1539 integer(c_int) :: holdout_geometries = 0
1540 integer(c_int) :: full_geometries = 0
1541 integer(c_int) :: cartesian_dimension = 0
1542 integer(c_int) :: joint_rows = 0
1543 real(c_double) :: force_tol_fraction = 0.0d0
1544 real(c_double) :: force_convergence_tolerance = 0.0d0
1545 real(c_double) :: energy_tolerance = 0.0d0
1546 real(c_double) :: force_tolerance = 0.0d0
1547 real(c_double) :: energy_noise = 0.0d0
1548 real(c_double) :: gradient_noise = 0.0d0
1549 real(c_double) :: max_energy_error = 0.0d0
1550 real(c_double) :: max_force_error = 0.0d0
1551 real(c_double) :: max_energy_oracle_error = 0.0d0
1552 real(c_double) :: max_force_oracle_error = 0.0d0
1553 real(c_double) :: exact_energy_oracle_error = 0.0d0
1554 real(c_double) :: exact_force_oracle_error = 0.0d0
1555 integer(c_long_long) :: exact_gram_bytes = 0
1556 integer(c_long_long) :: memory_cap_bytes = 0
1557 integer(c_long_long) :: full_gram_bytes = 0
1558 end type
1559
1560 !> Condition-floored noise and certificate gap of a trained model
1561 !> (gpr_noise_floor_report_t, ABI 1.14).
1562 type, public, bind(C) :: noisefloorreport
1563 real(c_double) :: sigma2_requested = 0.0d0
1564 real(c_double) :: sigma2_floored = 0.0d0
1565 real(c_double) :: certificate_gap = 0.0d0
1566 real(c_double) :: sigma2_interval = 0.0d0
1567 integer(c_int) :: floor_active = 0
1568 integer(c_int) :: certified = 0
1569 end type
1570
1571 !> Lennard-Jones oracle adapter parameters (gpr_lj_params_t).
1572 type, public, bind(C) :: ljparams
1573 integer(c_int) :: n_atoms = 0
1574 real(c_double) :: epsilon = 1.0d0
1575 real(c_double) :: sigma = 1.0d0
1576 end type
1577
1578 ! The configuration types also construct from the loaded library.
1579 interface atomsdescriptor
1580 module procedure gpr_atoms_config_defaults
1581 end interface
1582 interface modelconfig
1583 module procedure gpr_model_config_defaults
1584 end interface
1585 interface nebconfig
1586 module procedure gpr_neb_config_defaults
1587 end interface
1588 interface minimizeconfig
1589 module procedure gpr_minimize_config_defaults
1590 end interface
1591 interface ocinebconfig
1592 module procedure gpr_ocineb_config_defaults
1593 end interface
1594 interface localbandconfig
1595 module procedure gpr_local_band_config_defaults
1596 end interface
1597 interface periodicbandconfig
1598 module procedure gpr_periodic_band_config_defaults
1599 end interface
1600
1601 ! =====================================================================
1602 ! Callback interfaces (public: user procedures implement them)
1603 ! =====================================================================
1604
1605 abstract interface
1606 !> gpr_oracle_fn: energy and gradient at positions. A failed
1607 !> evaluation sets a non-finite energy.
1608 subroutine gpr_oracle_interface(n_coords, positions, energy, gradient, &
1609 user_data) bind(C)
1610 import :: c_int, c_double, c_ptr
1611 integer(c_int), value :: n_coords
1612 real(c_double), intent(in) :: positions(n_coords)
1613 real(c_double), intent(out) :: energy
1614 real(c_double), intent(out) :: gradient(n_coords)
1615 type(c_ptr), value :: user_data
1616 end subroutine
1617
1618 !> gpr_force_fn: energy and forces of n_atoms atoms. energy_noise_rms
1619 !> (a standard deviation in eV) and box may be C_NULL_PTR. A failed
1620 !> evaluation sets a non-finite energy.
1621 subroutine gpr_force_interface(n_atoms, positions, atomic_nrs, forces, &
1622 energy, energy_noise_rms, box, user_data) bind(C)
1623 import :: c_long, c_int, c_double, c_ptr
1624 integer(c_long), value :: n_atoms
1625 real(c_double), intent(in) :: positions(3 * n_atoms)
1626 integer(c_int), intent(in) :: atomic_nrs(n_atoms)
1627 real(c_double), intent(out) :: forces(3 * n_atoms)
1628 real(c_double), intent(out) :: energy
1629 type(c_ptr), value :: energy_noise_rms, box, user_data
1630 end subroutine
1631
1632 !> gpr_force_with_uncertainty_fn: energy, forces, energy_noise_rms and
1633 !> force_noise_rms of n_atoms atoms. Noise and box pointers may be
1634 !> C_NULL_PTR. A failed evaluation sets a non-finite energy.
1635 subroutine gpr_force_with_uncertainty_interface(n_atoms, positions, &
1636 atomic_nrs, forces, energy, energy_noise_rms, force_noise_rms, box, &
1637 user_data) bind(C)
1638 import :: c_long, c_int, c_double, c_ptr
1639 integer(c_long), value :: n_atoms
1640 real(c_double), intent(in) :: positions(3 * n_atoms)
1641 integer(c_int), intent(in) :: atomic_nrs(n_atoms)
1642 real(c_double), intent(out) :: forces(3 * n_atoms)
1643 real(c_double), intent(out) :: energy
1644 type(c_ptr), value :: energy_noise_rms, force_noise_rms, box, user_data
1645 end subroutine
1646
1647 !> gpr_hvp_fn: Hessian-vector-product callback at a fixed point (ABI 1.20).
1648 !> Writes H(positions) * vector into hv_out; non-finite entries signal failure.
1649 subroutine gpr_hvp_interface(n_coords, positions, vector, hv_out, &
1650 user_data) bind(C)
1651 import :: c_int, c_double, c_ptr
1652 integer(c_int), value :: n_coords
1653 real(c_double), intent(in) :: positions(n_coords), vector(n_coords)
1654 real(c_double), intent(out) :: hv_out(n_coords)
1655 type(c_ptr), value :: user_data
1656 end subroutine
1657 end interface
1658
1661
1662 ! =====================================================================
1663 ! C API bindings added in ABI 1.1 (private)
1664 ! =====================================================================
1665
1666 interface
1667 integer(c_size_t) function c_strlen(s) bind(C, name='strlen')
1668 import :: c_ptr, c_size_t
1669 type(c_ptr), value :: s
1670 end function
1671
1672 subroutine c_gpr_abi_version(major, minor) bind(C, name='gpr_abi_version')
1673 import :: c_int
1674 integer(c_int), intent(out) :: major, minor
1675 end subroutine
1676
1677 integer(c_int) function c_gpr_abi_check(major, minor) &
1678 bind(c, name='gpr_abi_check')
1679 import :: c_int
1680 integer(c_int), value :: major, minor
1681 end function
1682
1683 integer(c_size_t) function c_gpr_last_error_copy(buf, capacity) &
1684 bind(c, name='gpr_last_error_copy')
1685 import :: c_char, c_size_t
1686 character(kind=c_char), intent(out) :: buf(*)
1687 integer(c_size_t), value :: capacity
1688 end function
1689
1690 integer(c_int) function c_gpr_last_status() bind(C, name='gpr_last_status')
1691 import :: c_int
1692 end function
1693
1694 integer(c_int) function c_gpr_set_linalg_mode(mode) &
1695 bind(c, name='gpr_set_linalg_mode')
1696 import :: c_int, c_char
1697 character(kind=c_char), intent(in) :: mode(*)
1698 end function
1699
1700 type(c_ptr) function c_gpr_linalg_mode() bind(C, name='gpr_linalg_mode')
1701 import :: c_ptr
1702 end function
1703
1704 integer(c_int) function c_gpr_set_linalg_threads(n) &
1705 bind(c, name='gpr_set_linalg_threads')
1706 import :: c_int
1707 integer(c_int), value :: n
1708 end function
1709
1710 integer(c_int) function c_gpr_set_training_product(spec) &
1711 bind(c, name='gpr_set_training_product')
1712 import :: c_int, c_char
1713 character(kind=c_char), intent(in) :: spec(*)
1714 end function
1715
1716 integer(c_int) function c_gpr_training_product_configured() &
1717 bind(c, name='gpr_training_product_configured')
1718 import :: c_int
1719 end function
1720
1721 integer(c_int) function c_gpr_check_model_package(path) &
1722 bind(c, name='gpr_check_model_package')
1723 import :: c_int, c_char
1724 character(kind=c_char), intent(in) :: path(*)
1725 end function
1726
1727 type(dimerconfig) function c_gpr_dimer_config_defaults() &
1728 bind(C, name='gpr_dimer_config_defaults')
1729 import :: dimerconfig
1730 end function
1731
1732 type(c_ptr) function c_gpr_potential_from_force(fn, user_data) &
1733 bind(C, name='gpr_potential_from_force')
1734 import :: c_ptr, c_funptr
1735 type(c_funptr), value :: fn
1736 type(c_ptr), value :: user_data
1737 end function
1738
1739 subroutine c_gpr_potential_destroy(pot) &
1740 bind(c, name='gpr_potential_destroy')
1741 import :: c_ptr
1742 type(c_ptr), value :: pot
1743 end subroutine
1744
1745 ! No INTENT on the outputs: an early error leaves them unchanged.
1746 integer(c_int) function c_gpr_dimer_search_report(pot, atoms, R_init, &
1747 orient_init, config, R_obs, E_obs, G_obs, n_init_obs, R_saddle, &
1748 E_saddle, orient_out, report) bind(C, name='gpr_dimer_search_report')
1749 import :: c_ptr, c_int, c_double, dimerconfig, dimerreport
1750 type(c_ptr), value :: pot, atoms
1751 real(c_double), intent(in) :: R_init(*), orient_init(*)
1752 type(dimerconfig), intent(in) :: config
1753 type(c_ptr), value :: R_obs, E_obs, G_obs
1754 integer(c_int), value :: n_init_obs
1755 real(c_double) :: R_saddle(*), E_saddle
1756 type(c_ptr), value :: orient_out
1757 type(dimerreport) :: report
1758 end function
1759
1760 type(c_ptr) function c_gpr_neb_search(oracle, user_data, R_i, R_f, &
1761 n_coords, n_images, config) bind(C, name='gpr_neb_search')
1762 import :: c_ptr, c_int, c_double, c_funptr, nebconfig
1763 type(c_funptr), value :: oracle
1764 type(c_ptr), value :: user_data
1765 real(c_double), intent(in) :: R_i(*), R_f(*)
1766 integer(c_int), value :: n_coords, n_images
1767 type(nebconfig), intent(in) :: config
1768 end function
1769
1770 type(localbandconfig) function c_gpr_local_band_config_defaults() &
1771 bind(C, name='gpr_local_band_config_defaults')
1772 import :: localbandconfig
1773 end function
1774
1775 integer(c_int) function c_gpr_neb_request_index_certificate(enable, step) &
1776 bind(c, name='gpr_neb_request_index_certificate')
1777 import :: c_int, c_double
1778 integer(c_int), value :: enable
1779 real(c_double), value :: step
1780 end function
1781
1782 integer(c_int) function c_gpr_neb_request_sidpp(enable) &
1783 bind(c, name='gpr_neb_request_sidpp')
1784 import :: c_int
1785 integer(c_int), value :: enable
1786 end function
1787
1788 integer(c_int) function c_gpr_neb_request_vibrational_stencil(mode) &
1789 bind(c, name='gpr_neb_request_vibrational_stencil')
1790 import :: c_int
1791 integer(c_int), value :: mode
1792 end function
1793
1794 type(c_ptr) function c_gpr_neb_search_local(oracle, user_data, atoms, &
1795 box, R_i, R_f, n_coords, n_images, config, local) &
1796 bind(C, name='gpr_neb_search_local')
1797 import :: c_ptr, c_int, c_double, c_funptr, nebconfig, localbandconfig
1798 type(c_funptr), value :: oracle
1799 type(c_ptr), value :: user_data, atoms, box
1800 real(c_double), intent(in) :: R_i(*), R_f(*)
1801 integer(c_int), value :: n_coords, n_images
1802 type(c_ptr), value :: config, local
1803 end function
1804
1805 type(c_ptr) function c_gpr_neb_search_local_potential(pot, atomic_nrs, &
1806 box, atoms, R_i, R_f, n_coords, n_images, config, local) &
1807 bind(C, name='gpr_neb_search_local_potential')
1808 import :: c_ptr, c_int, c_double, nebconfig, localbandconfig
1809 type(c_ptr), value :: pot, atomic_nrs, box, atoms
1810 real(c_double), intent(in) :: R_i(*), R_f(*)
1811 integer(c_int), value :: n_coords, n_images
1812 type(c_ptr), value :: config, local
1813 end function
1814
1815 type(periodicbandconfig) function c_gpr_periodic_band_config_defaults() &
1816 bind(C, name='gpr_periodic_band_config_defaults')
1817 import :: periodicbandconfig
1818 end function
1819
1820 type(c_ptr) function c_gpr_neb_search_periodic(oracle, user_data, atoms, &
1821 box, R_i, R_f, n_coords, n_images, periodic, local) &
1822 bind(C, name='gpr_neb_search_periodic')
1823 import :: c_ptr, c_int, c_double, c_funptr, periodicbandconfig, &
1825 type(c_funptr), value :: oracle
1826 type(c_ptr), value :: user_data, atoms, box
1827 real(c_double), intent(in) :: R_i(*), R_f(*)
1828 integer(c_int), value :: n_coords, n_images
1829 type(c_ptr), value :: periodic, local
1830 end function
1831
1832 type(c_ptr) function c_gpr_neb_search_periodic_potential(pot, atomic_nrs, &
1833 box, atoms, R_i, R_f, n_coords, n_images, periodic, local) &
1834 bind(C, name='gpr_neb_search_periodic_potential')
1835 import :: c_ptr, c_int, c_double, periodicbandconfig, localbandconfig
1836 type(c_ptr), value :: pot, atomic_nrs, box, atoms
1837 real(c_double), intent(in) :: R_i(*), R_f(*)
1838 integer(c_int), value :: n_coords, n_images
1839 type(c_ptr), value :: periodic, local
1840 end function
1841
1842 integer(c_int) function c_gpr_neb_result_convergence_status(r) &
1843 bind(c, name='gpr_neb_result_convergence_status')
1844 import :: c_ptr, c_int
1845 type(c_ptr), value :: r
1846 end function
1847
1848 integer(c_int) function c_gpr_neb_result_outer_iterations(r) &
1849 bind(c, name='gpr_neb_result_outer_iterations')
1850 import :: c_ptr, c_int
1851 type(c_ptr), value :: r
1852 end function
1853
1854 integer(c_int) function c_gpr_neb_result_all_energies(r, out, n) &
1855 bind(c, name='gpr_neb_result_all_energies')
1856 import :: c_ptr, c_int, c_double
1857 type(c_ptr), value :: r
1858 real(c_double), intent(out) :: out(*)
1859 integer(c_int), value :: n
1860 end function
1861
1862 integer(c_int) function c_gpr_minimize_request_max_inner_steps( &
1863 max_inner_steps) &
1864 bind(c, name='gpr_minimize_request_max_inner_steps')
1865 import :: c_int
1866 integer(c_int), value :: max_inner_steps
1867 end function
1868
1869 integer(c_int) function c_gpr_minimize(oracle, user_data, R_init, &
1870 n_coords, atoms, config, R_final, E_final, G_final, conv, n_calls) &
1871 bind(c, name='gpr_minimize')
1872 import :: c_ptr, c_int, c_double, c_funptr, minimizeconfig
1873 type(c_funptr), value :: oracle
1874 type(c_ptr), value :: user_data, atoms
1875 real(c_double), intent(in) :: R_init(*)
1876 integer(c_int), value :: n_coords
1877 type(minimizeconfig), intent(in) :: config
1878 real(c_double) :: R_final(*), E_final, G_final(*)
1879 integer(c_int) :: conv, n_calls
1880 end function
1881 end interface
1882
1883 ! =====================================================================
1884 ! C API bindings: configuration defaults, atoms descriptors, the rest
1885 ! of the model and NEB surface, introspection, and ABI 1.2 (private)
1886 ! =====================================================================
1887
1888 interface
1889 type(modelconfig) function c_gpr_model_config_defaults() &
1890 bind(C, name='gpr_model_config_defaults')
1891 import :: modelconfig
1892 end function
1893
1894 type(nebconfig) function c_gpr_neb_config_defaults() &
1895 bind(C, name='gpr_neb_config_defaults')
1896 import :: nebconfig
1897 end function
1898
1899 type(minimizeconfig) function c_gpr_minimize_config_defaults() &
1900 bind(C, name='gpr_minimize_config_defaults')
1901 import :: minimizeconfig
1902 end function
1903
1904 type(ocinebconfig) function c_gpr_ocineb_config_defaults() &
1905 bind(C, name='gpr_ocineb_config_defaults')
1906 import :: ocinebconfig
1907 end function
1908
1909 type(c_ptr) function c_gpr_atoms_create(config) &
1910 bind(C, name='gpr_atoms_create')
1911 import :: c_ptr, atomsdescriptor
1912 type(atomsdescriptor), intent(in) :: config
1913 end function
1914
1915 integer(c_int) function c_gpr_model_type(model) &
1916 bind(c, name='gpr_model_type')
1917 import :: c_ptr, c_int
1918 type(c_ptr), value :: model
1919 end function
1920
1921 integer(c_int) function c_gpr_model_predict_full_checked(model, R_q, &
1922 R_len, E, G, G_len, vE, vG, vG_len, n_coords) &
1923 bind(c, name='gpr_model_predict_full_checked')
1924 import :: c_ptr, c_int, c_double, c_size_t
1925 type(c_ptr), value :: model
1926 real(c_double), intent(in) :: R_q(*)
1927 integer(c_size_t), value :: R_len
1928 real(c_double) :: E, G(*), vE, vG(*)
1929 integer(c_size_t), value :: G_len, vG_len
1930 integer(c_int), value :: n_coords
1931 end function
1932
1933 integer(c_int) function c_gpr_model_predict_batch_checked(model, R_q, &
1934 R_len, E, E_len, G, G_len, vE, vE_len, vG, vG_len, n_queries, &
1935 n_coords) bind(C, name='gpr_model_predict_batch_checked')
1936 import :: c_ptr, c_int, c_double, c_size_t
1937 type(c_ptr), value :: model
1938 real(c_double), intent(in) :: R_q(*)
1939 integer(c_size_t), value :: R_len
1940 real(c_double) :: E(*), G(*)
1941 integer(c_size_t), value :: E_len, G_len
1942 type(c_ptr), value :: vE, vG
1943 integer(c_size_t), value :: vE_len, vG_len
1944 integer(c_int), value :: n_queries, n_coords
1945 end function
1946
1947 integer(c_int) function c_gpr_model_predict_hessian_checked( &
1948 model, R_q, R_len, H, H_len, n_coords) &
1949 bind(c, name='gpr_model_predict_hessian_checked')
1950 import :: c_ptr, c_int, c_double, c_size_t
1951 type(c_ptr), value :: model
1952 real(c_double), intent(in) :: R_q(*)
1953 integer(c_size_t), value :: R_len
1954 real(c_double) :: H(*)
1955 integer(c_size_t), value :: H_len
1956 integer(c_int), value :: n_coords
1957 end function
1958
1959 integer(c_int) function c_gpr_model_predict_hessian_action_checked( &
1960 model, R_q, R_len, v, v_len, Hv, Hv_len, n_coords) &
1961 bind(c, name='gpr_model_predict_hessian_action_checked')
1962 import :: c_ptr, c_int, c_double, c_size_t
1963 type(c_ptr), value :: model
1964 real(c_double), intent(in) :: R_q(*), v(*)
1965 integer(c_size_t), value :: R_len, v_len
1966 real(c_double) :: Hv(*)
1967 integer(c_size_t), value :: Hv_len
1968 integer(c_int), value :: n_coords
1969 end function
1970
1971 integer(c_int) function c_gpr_model_prediction_supported_checked( &
1972 model, R_q, R_len, n_coords, supported) &
1973 bind(c, name='gpr_model_prediction_supported_checked')
1974 import :: c_ptr, c_int, c_double, c_size_t
1975 type(c_ptr), value :: model
1976 real(c_double), intent(in) :: R_q(*)
1977 integer(c_size_t), value :: R_len
1978 integer(c_int), value :: n_coords
1979 integer(c_int) :: supported
1980 end function
1981
1982 integer(c_int) function c_gpr_model_predict_energy_variance_interval( &
1983 model, R_q, n_queries, n_coords, lower, upper) &
1984 bind(c, name='gpr_model_predict_energy_variance_interval')
1985 import :: c_ptr, c_int, c_double
1986 type(c_ptr), value :: model
1987 real(c_double), intent(in) :: R_q(*)
1988 integer(c_int), value :: n_queries, n_coords
1989 real(c_double) :: lower(*), upper(*)
1990 end function
1991
1992 integer(c_int) function &
1993 c_gpr_model_predict_energy_variance_interval_checked( &
1994 model, r_q, r_len, n_queries, n_coords, lower, lower_len, upper, &
1995 upper_len) &
1996 bind(c, name='gpr_model_predict_energy_variance_interval_checked')
1997 import :: c_ptr, c_int, c_double, c_size_t
1998 type(c_ptr), value :: model
1999 real(c_double), intent(in) :: R_q(*)
2000 integer(c_size_t), value :: R_len
2001 integer(c_int), value :: n_queries, n_coords
2002 real(c_double) :: lower(*), upper(*)
2003 integer(c_size_t), value :: lower_len, upper_len
2004 end function
2005
2006 integer(c_int) function c_gpr_neb_result_max_energy_image(r) &
2007 bind(c, name='gpr_neb_result_max_energy_image')
2008 import :: c_ptr, c_int
2009 type(c_ptr), value :: r
2010 end function
2011
2012 integer(c_int) function c_gpr_neb_result_report(r, report) &
2013 bind(c, name='gpr_neb_result_report')
2014 import :: c_ptr, c_int, nebreport
2015 type(c_ptr), value :: r
2016 type(nebreport) :: report
2017 end function
2018
2019 type(c_ptr) function c_gpr_neb_search_potential(pot, atomic_nrs, box, &
2020 R_i, R_f, n_coords, n_images, config) &
2021 bind(C, name='gpr_neb_search_potential')
2022 import :: c_ptr, c_int, c_double, nebconfig
2023 type(c_ptr), value :: pot
2024 integer(c_int), intent(in) :: atomic_nrs(*)
2025 real(c_double), intent(in) :: box(9), R_i(*), R_f(*)
2026 integer(c_int), value :: n_coords, n_images
2027 type(nebconfig), intent(in) :: config
2028 end function
2029
2030 type(c_ptr) function c_gpr_neb_search_gp(oracle, user_data, atoms, &
2031 model, R_i, R_f, n_coords, n_images, config) &
2032 bind(C, name='gpr_neb_search_gp')
2033 import :: c_ptr, c_int, c_double, c_funptr, nebconfig
2034 type(c_funptr), value :: oracle
2035 type(c_ptr), value :: user_data, atoms, model
2036 real(c_double), intent(in) :: R_i(*), R_f(*)
2037 integer(c_int), value :: n_coords, n_images
2038 type(nebconfig), intent(in) :: config
2039 end function
2040
2041 type(c_ptr) function c_gpr_neb_search_gp_potential(pot, atoms, box, &
2042 model, R_i, R_f, n_coords, n_images, config) &
2043 bind(C, name='gpr_neb_search_gp_potential')
2044 import :: c_ptr, c_int, c_double, nebconfig
2045 type(c_ptr), value :: pot, atoms, box, model
2046 real(c_double), intent(in) :: R_i(*), R_f(*)
2047 integer(c_int), value :: n_coords, n_images
2048 type(nebconfig), intent(in) :: config
2049 end function
2050
2051 type(c_ptr) function c_gpr_ocineb_search(oracle, user_data, atoms, &
2052 model, R_i, R_f, n_coords, n_images, config, oci) &
2053 bind(C, name='gpr_ocineb_search')
2054 import :: c_ptr, c_int, c_double, c_funptr, nebconfig
2055 type(c_funptr), value :: oracle
2056 type(c_ptr), value :: user_data, atoms, model
2057 real(c_double), intent(in) :: R_i(*), R_f(*)
2058 integer(c_int), value :: n_coords, n_images
2059 type(nebconfig), intent(in) :: config
2060 type(c_ptr), value :: oci
2061 end function
2062
2063 type(c_ptr) function c_gpr_status_name(status) &
2064 bind(C, name='gpr_status_name')
2065 import :: c_ptr, c_int
2066 integer(c_int), value :: status
2067 end function
2068
2069 subroutine c_gpr_version_components(major, minor, patch) &
2070 bind(c, name='gpr_version_components')
2071 import :: c_int
2072 integer(c_int), intent(out) :: major, minor, patch
2073 end subroutine
2074
2075 type(c_ptr) function c_gpr_backend_name() bind(C, name='gpr_backend_name')
2076 import :: c_ptr
2077 end function
2078
2079 integer(c_int) function c_gpr_backend_requires_mpi() &
2080 bind(c, name='gpr_backend_requires_mpi')
2081 import :: c_int
2082 end function
2083
2084 integer(c_int) function c_gpr_mpi_initialized() &
2085 bind(c, name='gpr_mpi_initialized')
2086 import :: c_int
2087 end function
2088
2089 integer(c_int) function c_gpr_mpi_world_rank() &
2090 bind(c, name='gpr_mpi_world_rank')
2091 import :: c_int
2092 end function
2093
2094 integer(c_int) function c_gpr_mpi_world_size() &
2095 bind(c, name='gpr_mpi_world_size')
2096 import :: c_int
2097 end function
2098
2099 integer(c_int) function c_gpr_omp_max_threads() &
2100 bind(c, name='gpr_omp_max_threads')
2101 import :: c_int
2102 end function
2103
2104 type(c_ptr) function c_gpr_last_error_raw() bind(C, name='gpr_last_error')
2105 import :: c_ptr
2106 end function
2107
2108 type(atomsdescriptor) function c_gpr_atoms_config_defaults() &
2109 bind(C, name='gpr_atoms_config_defaults')
2110 import :: atomsdescriptor
2111 end function
2112
2113 type(atomsdescriptor) function c_gpr_atoms_simple(n_atoms) &
2114 bind(C, name='gpr_atoms_simple')
2115 import :: atomsdescriptor, c_int
2116 integer(c_int), value :: n_atoms
2117 end function
2118
2119 integer(c_int) function c_gpr_model_fit_iterations(model) &
2120 bind(c, name='gpr_model_fit_iterations')
2121 import :: c_ptr, c_int
2122 type(c_ptr), value :: model
2123 end function
2124
2125 integer(c_int) function c_gpr_model_fit_restarts(model, out) &
2126 bind(c, name='gpr_model_fit_restarts')
2127 import :: c_ptr, c_int
2128 type(c_ptr), value :: model
2129 integer(c_int) :: out
2130 end function
2131
2132 type(c_ptr) function c_gpr_model_fit_stop_reason(model) &
2133 bind(C, name='gpr_model_fit_stop_reason')
2134 import :: c_ptr
2135 type(c_ptr), value :: model
2136 end function
2137
2138 subroutine c_gpr_train_phase_reset() bind(C, name='gpr_train_phase_reset')
2139 end subroutine
2140
2141 subroutine c_gpr_train_phase_read(factor_s, solve_s, eigen_s, kernel_s, &
2142 hessian_s) bind(C, name='gpr_train_phase_read')
2143 import :: c_ptr
2144 type(c_ptr), value :: factor_s, solve_s, eigen_s, kernel_s, hessian_s
2145 end subroutine
2146
2147 subroutine c_gpr_train_phase_read_leaves(setup_s, descriptor_s, &
2148 posterior_s, subset_s, objective_s, condition_s, cache_s, &
2149 curvature_s, energy_s, schedule_s) &
2150 bind(c, name='gpr_train_phase_read_leaves')
2151 import :: c_ptr
2152 type(c_ptr), value :: setup_s, descriptor_s, posterior_s, subset_s
2153 type(c_ptr), value :: objective_s, condition_s, cache_s, curvature_s
2154 type(c_ptr), value :: energy_s, schedule_s
2155 end subroutine
2156
2157 integer(c_int) function c_gpr_set_library_serial(enabled) &
2158 bind(c, name='gpr_set_library_serial')
2159 import :: c_int
2160 integer(c_int), value :: enabled
2161 end function
2162
2163 integer(c_int) function c_gpr_model_predict_hessian(model, R_q, H_out, &
2164 n_coords) bind(C, name='gpr_model_predict_hessian')
2165 import :: c_ptr, c_int, c_double
2166 type(c_ptr), value :: model
2167 real(c_double), intent(in) :: R_q(*)
2168 real(c_double) :: H_out(*)
2169 integer(c_int), value :: n_coords
2170 end function
2171
2172 integer(c_int) function c_gpr_model_prediction_factors(model, R_q, &
2173 n_coords, energy, scale, mean, kstar, weights, capacity, order) &
2174 bind(c, name='gpr_model_prediction_factors')
2175 import :: c_ptr, c_int, c_double
2176 type(c_ptr), value :: model
2177 real(c_double), intent(in) :: R_q(*)
2178 integer(c_int), value :: n_coords, capacity
2179 real(c_double) :: energy, scale, mean, kstar(*), weights(*)
2180 integer(c_int) :: order
2181 end function
2182
2183 integer(c_int) function c_gpr_model_set_rff_features(model, n_features, &
2184 force_tol_fraction) bind(C, name='gpr_model_set_rff_features')
2185 import :: c_ptr, c_int, c_double
2186 type(c_ptr), value :: model
2187 integer(c_int), value :: n_features
2188 real(c_double), value :: force_tol_fraction
2189 end function
2190
2191 integer(c_int) function c_gpr_model_get_noise_floor_report(model, out) &
2192 bind(c, name='gpr_model_get_noise_floor_report')
2193 import :: c_ptr, c_int, noisefloorreport
2194 type(c_ptr), value :: model
2195 type(noisefloorreport) :: out
2196 end function
2197
2198 integer(c_int) function c_gpr_model_get_rff_selection(model, out) &
2199 bind(c, name='gpr_model_get_rff_selection')
2200 import :: c_ptr, c_int, rffselection
2201 type(c_ptr), value :: model
2202 type(rffselection) :: out
2203 end function
2204
2205 integer(c_int) function c_gpr_model_set_rigid_null_deflation(model, &
2206 enabled) bind(C, name='gpr_model_set_rigid_null_deflation')
2207 import :: c_ptr, c_int
2208 type(c_ptr), value :: model
2209 integer(c_int), value :: enabled
2210 end function
2211
2212 integer(c_int) function c_gpr_model_get_rigid_null_deflation(model, out) &
2213 bind(c, name='gpr_model_get_rigid_null_deflation')
2214 import :: c_ptr, c_int
2215 type(c_ptr), value :: model
2216 integer(c_int) :: out
2217 end function
2218
2219 type(c_ptr) function c_gpr_potential_from_force_with_uncertainty(fn, &
2220 user_data) bind(C, name='gpr_potential_from_force_with_uncertainty')
2221 import :: c_ptr, c_funptr
2222 type(c_funptr), value :: fn
2223 type(c_ptr), value :: user_data
2224 end function
2225
2226 integer(c_int) function c_gpr_potential_force(pot, n_atoms, R, &
2227 atomic_nrs, F, energy, energy_noise_rms, box) &
2228 bind(c, name='gpr_potential_force')
2229 import :: c_ptr, c_long, c_int, c_double
2230 type(c_ptr), value :: pot, energy_noise_rms, box
2231 integer(c_long), value :: n_atoms
2232 real(c_double), intent(in) :: R(*)
2233 integer(c_int), intent(in) :: atomic_nrs(*)
2234 real(c_double) :: F(*), energy
2235 end function
2236
2237 integer(c_int) function c_gpr_potential_force_with_uncertainty(pot, &
2238 n_atoms, R, atomic_nrs, F, energy, energy_noise_rms, &
2239 force_noise_rms, box) &
2240 bind(c, name='gpr_potential_force_with_uncertainty')
2241 import :: c_ptr, c_long, c_int, c_double
2242 type(c_ptr), value :: pot, energy_noise_rms, force_noise_rms, box
2243 integer(c_long), value :: n_atoms
2244 real(c_double), intent(in) :: R(*)
2245 integer(c_int), intent(in) :: atomic_nrs(*)
2246 real(c_double) :: F(*), energy
2247 end function
2248
2249 integer(c_int) function c_gpr_dimer_search(force_fn, user_data, atoms, &
2250 R_init, orient_init, config, R_obs, E_obs, G_obs, n_init_obs, &
2251 R_saddle, E_saddle, orient_out, curvature, n_force_calls, &
2252 n_gp_calls) bind(C, name='gpr_dimer_search')
2253 import :: c_ptr, c_funptr, c_int, c_double, dimerconfig
2254 type(c_funptr), value :: force_fn
2255 type(c_ptr), value :: user_data, atoms, R_obs, E_obs, G_obs
2256 type(c_ptr), value :: orient_out, curvature, n_force_calls, n_gp_calls
2257 real(c_double), intent(in) :: R_init(*), orient_init(*)
2258 type(dimerconfig), intent(in) :: config
2259 integer(c_int), value :: n_init_obs
2260 real(c_double) :: R_saddle(*), E_saddle
2261 end function
2262
2263 integer(c_int) function c_gpr_dimer_search_potential(pot, atoms, R_init, &
2264 orient_init, config, R_obs, E_obs, G_obs, n_init_obs, R_saddle, &
2265 E_saddle, orient_out, curvature, n_force_calls, n_gp_calls) &
2266 bind(c, name='gpr_dimer_search_potential')
2267 import :: c_ptr, c_int, c_double, dimerconfig
2268 type(c_ptr), value :: pot, atoms, R_obs, E_obs, G_obs
2269 type(c_ptr), value :: orient_out, curvature, n_force_calls, n_gp_calls
2270 real(c_double), intent(in) :: R_init(*), orient_init(*)
2271 type(dimerconfig), intent(in) :: config
2272 integer(c_int), value :: n_init_obs
2273 real(c_double) :: R_saddle(*), E_saddle
2274 end function
2275
2276 subroutine c_gpr_oracle_lj(nc, pos, E, G, ud) bind(C, name='gpr_oracle_lj')
2277 import :: c_int, c_double, c_ptr
2278 integer(c_int), value :: nc
2279 real(c_double), intent(in) :: pos(*)
2280 real(c_double), intent(out) :: E, G(*)
2281 type(c_ptr), value :: ud
2282 end subroutine
2283
2284 ! Unchecked C model entries declared for complete ABI coverage; GPModel
2285 ! delegates to the *_checked variants above.
2286 integer(c_int) function c_gpr_model_train(model, R, E, G, n_obs, &
2287 n_coords) bind(C, name='gpr_model_train')
2288 import :: c_ptr, c_int, c_double
2289 type(c_ptr), value :: model
2290 real(c_double), intent(in) :: R(*), E(*), G(*)
2291 integer(c_int), value :: n_obs, n_coords
2292 end function
2293
2294 integer(c_int) function c_gpr_model_update(model, R, E, G, n_new, &
2295 n_coords) bind(C, name='gpr_model_update')
2296 import :: c_ptr, c_int, c_double
2297 type(c_ptr), value :: model
2298 real(c_double), intent(in) :: R(*), E(*), G(*)
2299 integer(c_int), value :: n_new, n_coords
2300 end function
2301
2302 integer(c_int) function c_gpr_model_predict(model, R_q, E, G, n_coords) &
2303 bind(c, name='gpr_model_predict')
2304 import :: c_ptr, c_int, c_double
2305 type(c_ptr), value :: model
2306 real(c_double), intent(in) :: R_q(*)
2307 real(c_double), intent(out) :: E, G(*)
2308 integer(c_int), value :: n_coords
2309 end function
2310
2311 integer(c_int) function c_gpr_model_predict_variance(model, R_q, vE, &
2312 vG, n_coords) bind(C, name='gpr_model_predict_variance')
2313 import :: c_ptr, c_int, c_double
2314 type(c_ptr), value :: model
2315 real(c_double), intent(in) :: R_q(*)
2316 real(c_double), intent(out) :: vE, vG(*)
2317 integer(c_int), value :: n_coords
2318 end function
2319
2320 integer(c_int) function c_gpr_model_predict_full(model, R_q, E, G, vE, &
2321 vG, n_coords) bind(C, name='gpr_model_predict_full')
2322 import :: c_ptr, c_int, c_double
2323 type(c_ptr), value :: model
2324 real(c_double), intent(in) :: R_q(*)
2325 real(c_double) :: E, G(*), vE, vG(*)
2326 integer(c_int), value :: n_coords
2327 end function
2328
2329 integer(c_int) function c_gpr_model_predict_batch(model, R_q, E, G, vE, &
2330 vG, n_queries, n_coords) bind(C, name='gpr_model_predict_batch')
2331 import :: c_ptr, c_int, c_double
2332 type(c_ptr), value :: model
2333 real(c_double), intent(in) :: R_q(*)
2334 real(c_double) :: E(*), G(*)
2335 type(c_ptr), value :: vE, vG
2336 integer(c_int), value :: n_queries, n_coords
2337 end function
2338
2339 integer(c_int) function c_gpr_model_predict_hessian_action(model, R_q, &
2340 v, Hv, n_coords) bind(C, name='gpr_model_predict_hessian_action')
2341 import :: c_ptr, c_int, c_double
2342 type(c_ptr), value :: model
2343 real(c_double), intent(in) :: R_q(*), v(*)
2344 real(c_double) :: Hv(*)
2345 integer(c_int), value :: n_coords
2346 end function
2347
2348 integer(c_int) function c_gpr_model_prediction_supported(model, R_q, &
2349 n_coords, supported) bind(C, name='gpr_model_prediction_supported')
2350 import :: c_ptr, c_int, c_double
2351 type(c_ptr), value :: model
2352 real(c_double), intent(in) :: R_q(*)
2353 integer(c_int), value :: n_coords
2354 integer(c_int) :: supported
2355 end function
2356 end interface
2357
2358 ! =====================================================================
2359 ! Atoms configuration handle
2360 ! =====================================================================
2361
2362 !> Atomic configuration for GP kernel (wraps opaque C handle)
2363 type, public :: atomsconfig
2364 private
2365 type(c_ptr) :: handle = c_null_ptr
2366 integer, pointer :: references => null()
2367 contains
2368 procedure :: n_moving => atoms_n_moving
2369 procedure :: n_pairtypes => atoms_n_pairtypes
2370 procedure :: is_valid => atoms_is_valid
2371 procedure :: get_handle => atoms_get_handle
2372 procedure :: release => atoms_release
2373 procedure, private :: assign => atoms_assign
2374 generic, public :: assignment(=) => assign
2375 final :: atoms_finalize
2376 end type
2377
2378 interface atomsconfig
2379 module procedure atoms_constructor
2380 end interface
2381
2382 ! =====================================================================
2383 ! C API bindings: posterior-mean derivatives and prefactors (ABI 1.20)
2384 ! =====================================================================
2385
2386 interface
2387 function c_gpr_derivative_options_defaults() result(o) &
2388 bind(c, name='gpr_derivative_options_defaults')
2389 import :: derivativeoptions
2390 type(derivativeoptions) :: o
2391 end function
2392
2393 integer(c_int) function c_gpr_model_mean_hessian_batch(model, options, &
2394 R, n_points, n_coords, H, residuals, report) &
2395 bind(c, name='gpr_model_mean_hessian_batch')
2396 import :: c_ptr, c_int, c_double, derivativeoptions, derivativereport
2397 type(c_ptr), value :: model
2398 type(derivativeoptions), intent(in) :: options
2399 real(c_double), intent(in) :: r(*)
2400 integer(c_int), value :: n_points, n_coords
2401 real(c_double) :: h(*)
2402 type(c_ptr), value :: residuals
2403 type(derivativereport) :: report
2404 end function
2405
2406 integer(c_int) function c_gpr_model_mean_hessian_batch_checked(model, &
2407 options, R, R_len, n_points, n_coords, H, H_len, residuals, &
2408 residuals_len, report) &
2409 bind(c, name='gpr_model_mean_hessian_batch_checked')
2410 import :: c_ptr, c_int, c_double, c_size_t, derivativeoptions, &
2412 type(c_ptr), value :: model
2413 type(derivativeoptions), intent(in) :: options
2414 real(c_double), intent(in) :: r(*)
2415 integer(c_size_t), value :: r_len, h_len, residuals_len
2416 integer(c_int), value :: n_points, n_coords
2417 real(c_double) :: h(*)
2418 type(c_ptr), value :: residuals
2419 type(derivativereport) :: report
2420 end function
2421
2422 integer(c_int) function c_gpr_model_mean_hessian_action_batch(model, &
2423 options, R, n_points, n_coords, V, n_vectors, Hv, report) &
2424 bind(c, name='gpr_model_mean_hessian_action_batch')
2425 import :: c_ptr, c_int, c_double, derivativeoptions, derivativereport
2426 type(c_ptr), value :: model
2427 type(derivativeoptions), intent(in) :: options
2428 real(c_double), intent(in) :: r(*), v(*)
2429 integer(c_int), value :: n_points, n_coords, n_vectors
2430 real(c_double) :: hv(*)
2431 type(derivativereport) :: report
2432 end function
2433
2434 integer(c_int) function c_gpr_model_mean_hessian_action_batch_checked( &
2435 model, options, R, R_len, n_points, n_coords, V, V_len, n_vectors, &
2436 Hv, Hv_len, report) &
2437 bind(c, name='gpr_model_mean_hessian_action_batch_checked')
2438 import :: c_ptr, c_int, c_double, c_size_t, derivativeoptions, &
2440 type(c_ptr), value :: model
2441 type(derivativeoptions), intent(in) :: options
2442 real(c_double), intent(in) :: r(*), v(*)
2443 integer(c_size_t), value :: r_len, v_len, hv_len
2444 integer(c_int), value :: n_points, n_coords, n_vectors
2445 real(c_double) :: hv(*)
2446 type(derivativereport) :: report
2447 end function
2448
2449 integer(c_int) function c_gpr_model_hessian_bilinear_covariance(model, &
2450 options, R, n_points, n_coords, V, n_left, W, n_right, cov, report) &
2451 bind(c, name='gpr_model_hessian_bilinear_covariance')
2452 import :: c_ptr, c_int, c_double, derivativeoptions, derivativereport
2453 type(c_ptr), value :: model
2454 type(derivativeoptions), intent(in) :: options
2455 real(c_double), intent(in) :: r(*), v(*), w(*)
2456 integer(c_int), value :: n_points, n_coords, n_left, n_right
2457 real(c_double) :: cov(*)
2458 type(derivativereport) :: report
2459 end function
2460
2461 integer(c_int) function c_gpr_model_hessian_bilinear_covariance_checked( &
2462 model, options, R, R_len, n_points, n_coords, V, V_len, n_left, W, &
2463 W_len, n_right, cov, cov_len, report) &
2464 bind(c, name='gpr_model_hessian_bilinear_covariance_checked')
2465 import :: c_ptr, c_int, c_double, c_size_t, derivativeoptions, &
2467 type(c_ptr), value :: model
2468 type(derivativeoptions), intent(in) :: options
2469 real(c_double), intent(in) :: r(*), v(*), w(*)
2470 integer(c_size_t), value :: r_len, v_len, w_len, cov_len
2471 integer(c_int), value :: n_points, n_coords, n_left, n_right
2472 real(c_double) :: cov(*)
2473 type(derivativereport) :: report
2474 end function
2475
2476 integer(c_int) function c_gpr_model_hessian_trace_variance(model, &
2477 options, R, n_points, n_coords, A, var, report) &
2478 bind(c, name='gpr_model_hessian_trace_variance')
2479 import :: c_ptr, c_int, c_double, derivativeoptions, derivativereport
2480 type(c_ptr), value :: model
2481 type(derivativeoptions), intent(in) :: options
2482 real(c_double), intent(in) :: r(*), a(*)
2483 integer(c_int), value :: n_points, n_coords
2484 real(c_double) :: var(*)
2485 type(derivativereport) :: report
2486 end function
2487
2488 integer(c_int) function c_gpr_model_hessian_trace_variance_checked( &
2489 model, options, R, R_len, n_points, n_coords, A, A_len, var, &
2490 var_len, report) &
2491 bind(c, name='gpr_model_hessian_trace_variance_checked')
2492 import :: c_ptr, c_int, c_double, c_size_t, derivativeoptions, &
2494 type(c_ptr), value :: model
2495 type(derivativeoptions), intent(in) :: options
2496 real(c_double), intent(in) :: r(*), a(*)
2497 integer(c_size_t), value :: r_len, a_len, var_len
2498 integer(c_int), value :: n_points, n_coords
2499 real(c_double) :: var(*)
2500 type(derivativereport) :: report
2501 end function
2502
2503 integer(c_int) function c_gpr_model_posterior_variance_batch(model, &
2504 options, R, n_points, n_coords, var_E, var_G, report) &
2505 bind(c, name='gpr_model_posterior_variance_batch')
2506 import :: c_ptr, c_int, c_double, derivativeoptions, derivativereport
2507 type(c_ptr), value :: model
2508 type(derivativeoptions), intent(in) :: options
2509 real(c_double), intent(in) :: r(*)
2510 integer(c_int), value :: n_points, n_coords
2511 real(c_double) :: var_e(*), var_g(*)
2512 type(derivativereport) :: report
2513 end function
2514
2515 integer(c_int) function c_gpr_model_posterior_variance_batch_checked( &
2516 model, options, R, R_len, n_points, n_coords, var_E, var_E_len, &
2517 var_G, var_G_len, report) &
2518 bind(c, name='gpr_model_posterior_variance_batch_checked')
2519 import :: c_ptr, c_int, c_double, c_size_t, derivativeoptions, &
2521 type(c_ptr), value :: model
2522 type(derivativeoptions), intent(in) :: options
2523 real(c_double), intent(in) :: r(*)
2524 integer(c_size_t), value :: r_len, var_e_len, var_g_len
2525 integer(c_int), value :: n_points, n_coords
2526 real(c_double) :: var_e(*), var_g(*)
2527 type(derivativereport) :: report
2528 end function
2529
2530 integer(c_int) function c_gpr_model_condition_fixed(model, options, &
2531 R_new, E_new, G_new, n_new, R_query, n_query, n_coords, E, G, var_E, &
2532 var_G, report) bind(C, name='gpr_model_condition_fixed')
2533 import :: c_ptr, c_int, c_double, derivativeoptions, derivativereport
2534 type(c_ptr), value :: model
2535 type(derivativeoptions), intent(in) :: options
2536 real(c_double), intent(in) :: r_new(*), e_new(*), g_new(*), r_query(*)
2537 integer(c_int), value :: n_new, n_query, n_coords
2538 real(c_double) :: e(*), g(*), var_e(*), var_g(*)
2539 type(derivativereport) :: report
2540 end function
2541
2542 integer(c_int) function c_gpr_model_condition_fixed_checked(model, &
2543 options, R_new, R_new_len, E_new, E_new_len, G_new, G_new_len, &
2544 n_new, R_query, R_query_len, n_query, n_coords, E, E_len, G, G_len, &
2545 var_E, var_E_len, var_G, var_G_len, report) &
2546 bind(c, name='gpr_model_condition_fixed_checked')
2547 import :: c_ptr, c_int, c_double, c_size_t, derivativeoptions, &
2549 type(c_ptr), value :: model
2550 type(derivativeoptions), intent(in) :: options
2551 real(c_double), intent(in) :: r_new(*), e_new(*), g_new(*), r_query(*)
2552 integer(c_size_t), value :: r_new_len, e_new_len, g_new_len, &
2553 r_query_len, e_len, g_len, var_e_len, var_g_len
2554 integer(c_int), value :: n_new, n_query, n_coords
2555 real(c_double) :: e(*), g(*), var_e(*), var_g(*)
2556 type(derivativereport) :: report
2557 end function
2558
2559 integer(c_int) function c_gpr_model_condition_fixed_hessian(model, &
2560 options, R_new, E_new, G_new, n_new, H_new, hvp, user_data, R_query, &
2561 n_query, n_coords, E, G, var_E, var_G, report) &
2562 bind(c, name='gpr_model_condition_fixed_hessian')
2563 import :: c_ptr, c_funptr, c_int, c_double, derivativeoptions, &
2565 type(c_ptr), value :: model, h_new, user_data
2566 type(c_funptr), value :: hvp
2567 type(derivativeoptions), intent(in) :: options
2568 real(c_double), intent(in) :: r_new(*), e_new(*), g_new(*), r_query(*)
2569 integer(c_int), value :: n_new, n_query, n_coords
2570 real(c_double) :: e(*), g(*), var_e(*), var_g(*)
2571 type(derivativereport) :: report
2572 end function
2573
2574 integer(c_int) function c_gpr_model_condition_fixed_hessian_checked( &
2575 model, options, R_new, R_new_len, E_new, E_new_len, G_new, &
2576 G_new_len, n_new, H_new, H_new_len, hvp, user_data, R_query, &
2577 R_query_len, n_query, n_coords, E, E_len, G, G_len, var_E, &
2578 var_E_len, var_G, var_G_len, report) &
2579 bind(c, name='gpr_model_condition_fixed_hessian_checked')
2580 import :: c_ptr, c_funptr, c_int, c_double, c_size_t, &
2582 type(c_ptr), value :: model, h_new, user_data
2583 type(c_funptr), value :: hvp
2584 type(derivativeoptions), intent(in) :: options
2585 real(c_double), intent(in) :: r_new(*), e_new(*), g_new(*), r_query(*)
2586 integer(c_size_t), value :: r_new_len, e_new_len, g_new_len, &
2587 h_new_len, r_query_len, e_len, g_len, var_e_len, var_g_len
2588 integer(c_int), value :: n_new, n_query, n_coords
2589 real(c_double) :: e(*), g(*), var_e(*), var_g(*)
2590 type(derivativereport) :: report
2591 end function
2592
2593 function c_gpr_htst_options_defaults() result(o) &
2594 bind(c, name='gpr_htst_options_defaults')
2595 import :: htstoptions
2596 type(htstoptions) :: o
2597 end function
2598
2599 integer(c_int) function c_gpr_htst_half_from_hessian(options, masses, &
2600 n_masses, H, x, n_coords, kind, frequencies, half) &
2601 bind(c, name='gpr_htst_half_from_hessian')
2602 import :: c_ptr, c_int, c_double, htstoptions, htsthalf
2603 type(htstoptions), intent(in) :: options
2604 type(c_ptr), value :: masses, frequencies
2605 integer(c_int), value :: n_masses, n_coords, kind
2606 real(c_double), intent(in) :: h(*), x(*)
2607 type(htsthalf) :: half
2608 end function
2609
2610 integer(c_int) function c_gpr_htst_half_from_hessian_checked(options, &
2611 masses, masses_len, n_masses, H, H_len, x, x_len, n_coords, kind, &
2612 frequencies, frequencies_len, half) &
2613 bind(c, name='gpr_htst_half_from_hessian_checked')
2614 import :: c_ptr, c_int, c_double, c_size_t, htstoptions, htsthalf
2615 type(htstoptions), intent(in) :: options
2616 type(c_ptr), value :: masses, frequencies
2617 integer(c_size_t), value :: masses_len, h_len, x_len, frequencies_len
2618 integer(c_int), value :: n_masses, n_coords, kind
2619 real(c_double), intent(in) :: h(*), x(*)
2620 type(htsthalf) :: half
2621 end function
2622
2623 integer(c_int) function c_gpr_htst_half(model, oracle, user_data, &
2624 options, masses, n_masses, x, n_coords, kind, frequencies, measured, &
2625 half) bind(C, name='gpr_htst_half')
2626 import :: c_ptr, c_funptr, c_int, c_double, htstoptions, htsthalf
2627 type(c_ptr), value :: model, user_data, masses, frequencies, measured
2628 type(c_funptr), value :: oracle
2629 type(htstoptions), intent(in) :: options
2630 integer(c_int), value :: n_masses, n_coords, kind
2631 real(c_double), intent(in) :: x(*)
2632 type(htsthalf) :: half
2633 end function
2634
2635 integer(c_int) function c_gpr_htst_half_checked(model, oracle, &
2636 user_data, options, masses, masses_len, n_masses, x, x_len, &
2637 n_coords, kind, frequencies, frequencies_len, measured, &
2638 measured_len, half) bind(C, name='gpr_htst_half_checked')
2639 import :: c_ptr, c_funptr, c_int, c_double, c_size_t, htstoptions, &
2640 htsthalf
2641 type(c_ptr), value :: model, user_data, masses, frequencies, measured
2642 type(c_funptr), value :: oracle
2643 type(htstoptions), intent(in) :: options
2644 integer(c_size_t), value :: masses_len, x_len, frequencies_len, &
2645 measured_len
2646 integer(c_int), value :: n_masses, n_coords, kind
2647 real(c_double), intent(in) :: x(*)
2648 type(htsthalf) :: half
2649 end function
2650
2651 integer(c_int) function c_gpr_htst_ln_prefactor(minimum, saddle, ln_nu, &
2652 ln_nu_std) bind(C, name='gpr_htst_ln_prefactor')
2653 import :: c_int, c_double, htsthalf
2654 type(htsthalf), intent(in) :: minimum, saddle
2655 real(c_double) :: ln_nu, ln_nu_std
2656 end function
2657
2658 integer(c_int) function c_gpr_request_prefactor(options, masses, &
2659 n_masses) bind(C, name='gpr_request_prefactor')
2660 import :: c_ptr, c_int
2661 type(c_ptr), value :: options, masses
2662 integer(c_int), value :: n_masses
2663 end function
2664
2665 integer(c_int) function c_gpr_search_prefactor(point, half, &
2666 frequencies, measured, n_coords) bind(C, name='gpr_search_prefactor')
2667 import :: c_ptr, c_int, htsthalf
2668 integer(c_int), value :: point, n_coords
2669 type(htsthalf) :: half
2670 type(c_ptr), value :: frequencies, measured
2671 end function
2672
2673 integer(c_int) function c_gpr_search_prefactor_checked(point, half, &
2674 frequencies, frequencies_len, measured, measured_len, n_coords) &
2675 bind(c, name='gpr_search_prefactor_checked')
2676 import :: c_ptr, c_int, c_size_t, htsthalf
2677 integer(c_int), value :: point, n_coords
2678 type(htsthalf) :: half
2679 type(c_ptr), value :: frequencies, measured
2680 integer(c_size_t), value :: frequencies_len, measured_len
2681 end function
2682
2683 integer(c_int) function c_gpr_neb_result_prefactor(result, point, half, &
2684 frequencies, measured, n_coords) &
2685 bind(c, name='gpr_neb_result_prefactor')
2686 import :: c_ptr, c_int, htsthalf
2687 type(c_ptr), value :: result, frequencies, measured
2688 integer(c_int), value :: point, n_coords
2689 type(htsthalf) :: half
2690 end function
2691
2692 integer(c_int) function c_gpr_neb_result_prefactor_checked(result, &
2693 point, half, frequencies, frequencies_len, measured, measured_len, &
2694 n_coords) bind(C, name='gpr_neb_result_prefactor_checked')
2695 import :: c_ptr, c_int, c_size_t, htsthalf
2696 type(c_ptr), value :: result, frequencies, measured
2697 integer(c_int), value :: point, n_coords
2698 integer(c_size_t), value :: frequencies_len, measured_len
2699 type(htsthalf) :: half
2700 end function
2701 end interface
2702
2703 ! =====================================================================
2704 ! GP/TP model handle
2705 ! =====================================================================
2706
2707 !> Gaussian/Student-t process model (wraps opaque C handle)
2708 type, public :: gpmodel
2709 private
2710 type(c_ptr) :: handle = c_null_ptr
2711 integer, pointer :: references => null()
2712 contains
2713 procedure :: init => gpmodel_init
2714 procedure :: train => gpmodel_train
2715 procedure :: train_marginal_likelihood => gpmodel_train_marginal_likelihood
2716 procedure :: update => gpmodel_update
2717 procedure :: append_fixed => gpmodel_append_fixed
2718 procedure :: calibrate_forces => gpmodel_calibrate_forces
2719 procedure :: calibrate_loo => gpmodel_calibrate_loo
2720 procedure :: predict => gpmodel_predict
2721 procedure :: predict_variance => gpmodel_predict_variance
2722 procedure :: predict_full => gpmodel_predict_full
2723 procedure :: predict_batch => gpmodel_predict_batch
2724 procedure :: predict_hessian => gpmodel_predict_hessian
2725 procedure :: predict_hessian_action => gpmodel_predict_hessian_action
2726 procedure :: prediction_supported => gpmodel_prediction_supported
2727 procedure :: prediction_factors => gpmodel_prediction_factors
2728 procedure :: fit_iterations => gpmodel_fit_iterations
2729 procedure :: fit_restarts => gpmodel_fit_restarts
2730 procedure :: fit_stop_reason => gpmodel_fit_stop_reason
2731 procedure :: set_rff_features => gpmodel_set_rff_features
2732 procedure :: get_rff_selection => gpmodel_get_rff_selection
2733 procedure :: set_rigid_null_deflation => gpmodel_set_rigid_null_deflation
2734 procedure :: get_rigid_null_deflation => gpmodel_get_rigid_null_deflation
2735 procedure :: predict_energy_variance_interval => &
2736 gpmodel_predict_energy_variance_interval
2737 procedure :: noise_floor_report => gpmodel_noise_floor_report
2738 procedure :: mean_hessian_batch => gpmodel_mean_hessian_batch
2739 procedure :: mean_hessian_action_batch => gpmodel_mean_hessian_action_batch
2740 procedure :: hessian_bilinear_covariance => &
2741 gpmodel_hessian_bilinear_covariance
2742 procedure :: hessian_trace_variance => gpmodel_hessian_trace_variance
2743 procedure :: posterior_variance_batch => gpmodel_posterior_variance_batch
2744 procedure :: condition_fixed => gpmodel_condition_fixed
2745 procedure :: condition_fixed_hessian => gpmodel_condition_fixed_hessian
2746 procedure :: model_type => gpmodel_model_type
2747 procedure :: n_lengthscales => gpmodel_n_lengthscales
2748 procedure :: get_lengthscales => gpmodel_get_lengthscales
2749 procedure :: set_lengthscales => gpmodel_set_lengthscales
2750 procedure :: get_magn_sigma2 => gpmodel_get_magn_sigma2
2751 procedure :: set_magn_sigma2 => gpmodel_set_magn_sigma2
2752 procedure :: get_sigma2 => gpmodel_get_sigma2
2753 procedure :: set_sigma2 => gpmodel_set_sigma2
2754 procedure :: get_jitter => gpmodel_get_jitter
2755 procedure :: set_hssvd_backend => gpmodel_set_hssvd_backend
2756 procedure :: get_hssvd_backend => gpmodel_get_hssvd_backend
2757 procedure :: get_alpha => gpmodel_get_alpha
2758 procedure :: n_observations => gpmodel_n_observations
2759 procedure :: tp_prefactor => gpmodel_tp_prefactor
2760 procedure :: is_valid => gpmodel_is_valid
2761 procedure :: release => gpmodel_release
2762 procedure, private :: assign => gpmodel_assign
2763 generic, public :: assignment(=) => assign
2764 final :: gpmodel_finalize
2765 end type
2766
2767 interface gpmodel
2768 module procedure gpmodel_constructor
2769 end interface
2770
2771 ! =====================================================================
2772 ! NEB result handle
2773 ! =====================================================================
2774
2775 !> NEB result (wraps opaque C handle with path data)
2776 type, public :: nebresult
2777 private
2778 type(c_ptr) :: handle = c_null_ptr
2779 integer, pointer :: references => null()
2780 contains
2781 procedure :: converged => neb_converged
2782 procedure :: oracle_calls => neb_oracle_calls
2783 procedure :: barrier => neb_barrier
2784 procedure :: n_images => neb_n_images
2785 procedure :: image_energy => neb_image_energy
2786 procedure :: image_positions => neb_image_positions
2787 procedure :: convergence_status => neb_convergence_status
2788 procedure :: outer_iterations => neb_outer_iterations
2789 procedure :: energies => neb_energies
2790 procedure :: max_energy_image => neb_max_energy_image
2791 procedure :: report => neb_report
2792 procedure :: prefactor => neb_prefactor
2793 procedure :: is_valid => neb_is_valid
2794 procedure :: release => neb_release
2795 procedure, private :: assign => neb_assign
2796 generic, public :: assignment(=) => assign
2797 final :: neb_finalize
2798 end type
2799
2800 ! =====================================================================
2801 ! Potential handle
2802 ! =====================================================================
2803
2804 !> Force-evaluation wrapper handle (wraps opaque gpr_potential_t)
2805 type, public :: potentialhandle
2806 private
2807 type(c_ptr) :: handle = c_null_ptr
2808 integer, pointer :: references => null()
2809 contains
2810 procedure :: force => pot_force
2811 procedure :: force_with_uncertainty => pot_force_with_uncertainty
2812 procedure :: is_valid => pot_is_valid
2813 procedure :: get_handle => pot_get_handle
2814 procedure :: release => pot_release
2815 procedure, private :: assign => pot_assign
2816 generic, public :: assignment(=) => assign
2817 final :: pot_finalize
2818 end type
2819
2820 ! =====================================================================
2821 ! Free-energy surrogate handle (ABI 1.23)
2822 ! =====================================================================
2823
2824 !> Gaussian process over a free energy F(s) on collective variables.
2825 !> Point arrays are s(dimension, n): one column per point.
2826 type, public :: fessurrogate
2827 private
2828 type(c_ptr) :: handle = c_null_ptr
2829 integer, pointer :: references => null()
2830 contains
2831 procedure :: dimension => fes_dimension
2832 procedure :: n_observations => fes_n_observations
2833 procedure :: train => fes_train
2834 procedure :: predict => fes_predict
2835 procedure :: rate_path => fes_rate_path
2836 procedure :: is_valid => fes_is_valid
2837 procedure :: get_handle => fes_get_handle
2838 procedure :: release => fes_release
2839 procedure, private :: assign => fes_assign
2840 generic, public :: assignment(=) => assign
2841 final :: fes_finalize
2842 end type
2843
2844 interface fessurrogate
2845 module procedure fes_constructor
2846 end interface
2847
2848 interface
2849 type(c_ptr) function c_gpr_fes_create(dimension, model_config, fes_config, &
2850 grad_noise_var, grad_noise_var_len) bind(c, name='gpr_fes_create')
2851 import :: c_ptr, c_int, c_size_t, modelconfig, fesconfig
2852 integer(c_int), value :: dimension
2853 type(modelconfig), intent(in) :: model_config
2854 type(fesconfig), intent(in) :: fes_config
2855 type(c_ptr), value :: grad_noise_var
2856 integer(c_size_t), value :: grad_noise_var_len
2857 end function
2858 end interface
2859
2860 ! =====================================================================
2861 ! Public module procedures
2862 ! =====================================================================
2863
2864 public :: gpr_lj_energy
2865 public :: gpr_muller_brown_energy
2866 public :: gpr_leps_energy
2868
2869 ! Version, ABI and errors
2871 public :: gpr_last_error
2872 public :: gpr_check_abi
2875
2876 ! Build and runtime introspection
2879 public :: gpr_omp_max_threads
2880
2881 ! Runtime configuration and train-phase timers
2885 public :: gpr_check_model_package
2888
2889 ! Potential wrappers
2891
2892 ! Searches
2896 public :: gpr_neb_search_potential
2908 public :: fes_noise_from_weights
2909
2910 ! Posterior-mean derivatives and harmonic prefactors (ABI 1.20)
2915
2916contains
2917
2918 ! ===================================================================
2919 ! AtomsConfig implementation
2920 ! ===================================================================
2921
2922 !> Atoms configuration of n_atoms atoms. Without the optional arrays the
2923 !> atoms are identical and all move. is_frozen marks fixed atoms,
2924 !> atom_types gives dense type indices (0, 1, ...) for the kernel's pair
2925 !> types, atomic_nrs the atomic numbers, positions (3*n_atoms) the
2926 !> reference positions, and actdist_fro the radius within which frozen
2927 !> atoms enter the GP kernel of the GP NEB searches (0: 30.3 Angstrom).
2928 !> A failure returns an invalid handle, with stat and errmsg as in the
2929 !> intrinsic statements.
2930 function atoms_constructor(n_atoms, is_frozen, atom_types, atomic_nrs, &
2931 positions, actdist_fro, stat, errmsg) result(self)
2932 integer, intent(in) :: n_atoms
2933 logical, intent(in), optional :: is_frozen(:)
2934 integer, intent(in), optional :: atom_types(:), atomic_nrs(:)
2935 real(c_double), intent(in), optional :: positions(:)
2936 real(c_double), intent(in), optional :: actdist_fro
2937 integer, intent(out), optional :: stat
2938 character(len=*), intent(inout), optional :: errmsg
2939 type(atomsconfig) :: self
2940 type(atomsdescriptor) :: descriptor
2941 integer(c_int), allocatable, target :: frozen_c(:), types_c(:), z_c(:)
2942 real(c_double), allocatable, target :: positions_c(:)
2943 integer(c_int) :: rc
2944
2945 if (.not. (present(is_frozen) .or. present(atom_types) .or. &
2946 present(atomic_nrs) .or. present(positions) .or. &
2947 present(actdist_fro))) then
2948 self%handle = c_gpr_atoms_create_simple(int(n_atoms, c_int))
2949 else
2950 descriptor%n_atoms_total = int(n_atoms, c_int)
2951 if (present(is_frozen)) then
2952 if (size(is_frozen) /= n_atoms) then
2953 call report_status(gpr_err_invalid_arg, stat, errmsg, &
2954 'AtomsConfig: is_frozen needs n_atoms entries')
2955 return
2956 end if
2957 allocate(frozen_c(n_atoms))
2958 frozen_c = merge(1_c_int, 0_c_int, is_frozen)
2959 descriptor%is_frozen = c_loc(frozen_c)
2960 end if
2961 if (present(atom_types)) then
2962 if (size(atom_types) /= n_atoms) then
2963 call report_status(gpr_err_invalid_arg, stat, errmsg, &
2964 'AtomsConfig: atom_types needs n_atoms entries')
2965 return
2966 end if
2967 types_c = int(atom_types, c_int)
2968 descriptor%atom_types = c_loc(types_c)
2969 end if
2970 if (present(atomic_nrs)) then
2971 if (size(atomic_nrs) /= n_atoms) then
2972 call report_status(gpr_err_invalid_arg, stat, errmsg, &
2973 'AtomsConfig: atomic_nrs needs n_atoms entries')
2974 return
2975 end if
2976 z_c = int(atomic_nrs, c_int)
2977 descriptor%atomic_nrs = c_loc(z_c)
2978 end if
2979 if (present(positions)) then
2980 if (size(positions) /= 3 * n_atoms) then
2981 call report_status(gpr_err_invalid_arg, stat, errmsg, &
2982 'AtomsConfig: positions needs 3*n_atoms entries')
2983 return
2984 end if
2985 positions_c = positions
2986 descriptor%positions = c_loc(positions_c)
2987 end if
2988 if (present(actdist_fro)) descriptor%actdist_fro = actdist_fro
2989 self%handle = c_gpr_atoms_create(descriptor)
2990 end if
2991 if (c_associated(self%handle)) then
2992 allocate(self%references, source=1)
2993 rc = gpr_success
2994 else
2995 rc = failed_status()
2996 end if
2997 call report_status(rc, stat, errmsg)
2998 end function
2999
3000 function atoms_n_moving(self) result(n)
3001 class(atomsconfig), intent(in) :: self
3002 integer :: n
3003 n = int(c_gpr_atoms_n_moving(self%handle))
3004 end function
3005
3006 function atoms_n_pairtypes(self) result(n)
3007 class(atomsconfig), intent(in) :: self
3008 integer :: n
3009 n = int(c_gpr_atoms_n_pairtypes(self%handle))
3010 end function
3011
3012 function atoms_is_valid(self) result(valid)
3013 class(atomsconfig), intent(in) :: self
3014 logical :: valid
3015 valid = c_associated(self%handle)
3016 end function
3017
3018 function atoms_get_handle(self) result(h)
3019 class(atomsconfig), intent(in) :: self
3020 type(c_ptr) :: h
3021 h = self%handle
3022 end function
3023
3024 !> Assignment shares the handle; each wrapper releases its own reference.
3025 impure elemental subroutine atoms_assign(self, other)
3026 class(atomsconfig), intent(inout) :: self
3027 type(atomsconfig), intent(in) :: other
3028 type(c_ptr) :: handle
3029 integer, pointer :: references
3030
3031 if (associated(self%references, other%references)) return
3032 handle = other%handle
3033 references => other%references
3034 if (associated(references)) references = references + 1
3035 call self%release()
3036 self%handle = handle
3037 self%references => references
3038 end subroutine
3039
3040 subroutine atoms_release(self)
3041 class(atomsconfig), intent(inout) :: self
3042 if (associated(self%references)) then
3043 self%references = self%references - 1
3044 if (self%references == 0) then
3045 call c_gpr_atoms_destroy(self%handle)
3046 deallocate(self%references)
3047 end if
3048 end if
3049 self%handle = c_null_ptr
3050 nullify(self%references)
3051 end subroutine
3052
3053 impure elemental subroutine atoms_finalize(self)
3054 type(atomsconfig), intent(inout) :: self
3055 call self%release()
3056 end subroutine
3057
3058 ! ===================================================================
3059 ! GPModel implementation
3060 ! ===================================================================
3061
3062 !> Create a GP or TP model
3063 function gpmodel_constructor(model_type) result(self)
3064 integer(c_int), intent(in) :: model_type
3065 type(gpmodel) :: self
3066
3067 self%handle = c_gpr_model_create(model_type)
3068 if (c_associated(self%handle)) allocate(self%references, source=1)
3069 end function
3070
3071 !> Initialize model with configuration and atom setup
3072 subroutine gpmodel_init(self, config, atoms, ierr)
3073 class(gpmodel), intent(inout) :: self
3074 type(modelconfig), intent(in) :: config
3075 type(atomsconfig), intent(in) :: atoms
3076 integer, intent(out), optional :: ierr
3077 integer(c_int) :: rc
3078
3079 rc = c_gpr_model_init(self%handle, config, atoms%handle)
3080 if (present(ierr)) ierr = int(rc)
3081 end subroutine
3082
3083 !> Train model on observations. R and G hold n_obs * n_coords values, E
3084 !> holds n_obs; a shorter array is refused with GPR_ERR_INVALID_ARG.
3085 subroutine gpmodel_train(self, R, E, G, n_obs, n_coords, ierr)
3086 class(gpmodel), intent(inout) :: self
3087 real(c_double), intent(in), contiguous :: r(:), e(:), g(:)
3088 integer, intent(in) :: n_obs, n_coords
3089 integer, intent(out), optional :: ierr
3090 integer(c_int) :: rc
3091
3092 rc = c_gpr_model_train_checked(self%handle, &
3093 r, size(r, kind=c_size_t), e, size(e, kind=c_size_t), &
3094 g, size(g, kind=c_size_t), int(n_obs, c_int), int(n_coords, c_int))
3095 if (present(ierr)) ierr = int(rc)
3096 end subroutine
3097
3098 !> Fit all rows by prior-free Gaussian marginal likelihood. The report and
3099 !> lengthscales are unchanged when an extent check rejects the call.
3100 subroutine gpmodel_train_marginal_likelihood(self, R, E, G, n_obs, &
3101 n_coords, report, lengthscales, ierr)
3102 class(gpmodel), intent(inout) :: self
3103 real(c_double), intent(in), contiguous :: r(:), e(:), g(:)
3104 integer, intent(in) :: n_obs, n_coords
3105 type(marginallikelihoodreport) :: report
3106 real(c_double), contiguous :: lengthscales(:)
3107 integer, intent(out), optional :: ierr
3108 integer(c_int) :: rc
3109
3110 rc = c_gpr_model_train_marginal_likelihood_checked(self%handle, &
3111 r, size(r, kind=c_size_t), e, size(e, kind=c_size_t), &
3112 g, size(g, kind=c_size_t), int(n_obs, c_int), int(n_coords, c_int), &
3113 report, lengthscales, size(lengthscales, kind=c_size_t))
3114 if (present(ierr)) ierr = int(rc)
3115 end subroutine
3116
3117 !> Add observations and retrain. The array extents are checked as in train.
3118 subroutine gpmodel_update(self, R, E, G, n_new, n_coords, ierr)
3119 class(gpmodel), intent(inout) :: self
3120 real(c_double), intent(in), contiguous :: r(:), e(:), g(:)
3121 integer, intent(in) :: n_new, n_coords
3122 integer, intent(out), optional :: ierr
3123 integer(c_int) :: rc
3124
3125 rc = c_gpr_model_update_checked(self%handle, &
3126 r, size(r, kind=c_size_t), e, size(e, kind=c_size_t), &
3127 g, size(g, kind=c_size_t), int(n_new, c_int), int(n_coords, c_int))
3128 if (present(ierr)) ierr = int(rc)
3129 end subroutine
3130
3131 !> Append rows without changing fitted hyperparameters or refactorizing.
3132 subroutine gpmodel_append_fixed(self, R, E, G, n_new, n_coords, ierr)
3133 class(gpmodel), intent(inout) :: self
3134 real(c_double), intent(in), contiguous :: r(:), e(:), g(:)
3135 integer, intent(in) :: n_new, n_coords
3136 integer, intent(out), optional :: ierr
3137 integer(c_int) :: rc
3138
3139 rc = c_gpr_model_append_fixed_checked(self%handle, &
3140 r, size(r, kind=c_size_t), e, size(e, kind=c_size_t), &
3141 g, size(g, kind=c_size_t), int(n_new, c_int), int(n_coords, c_int))
3142 if (present(ierr)) ierr = int(rc)
3143 end subroutine
3144
3145 !> Calibrate latent force marginals against held-out true gradients.
3146 subroutine gpmodel_calibrate_forces(self, R, G_true, n_holdout, n_coords, &
3147 nominal_probability, report, ierr)
3148 class(gpmodel), intent(inout) :: self
3149 real(c_double), intent(in), contiguous :: r(:), g_true(:)
3150 integer, intent(in) :: n_holdout, n_coords
3151 real(c_double), intent(in) :: nominal_probability
3152 type(calibrationreport) :: report
3153 integer, intent(out), optional :: ierr
3154 integer(c_int) :: rc
3155
3156 rc = c_gpr_model_calibrate_forces_checked(self%handle, &
3157 r, size(r, kind=c_size_t), g_true, size(g_true, kind=c_size_t), &
3158 int(n_holdout, c_int), int(n_coords, c_int), nominal_probability, &
3159 report)
3160 if (present(ierr)) ierr = int(rc)
3161 end subroutine
3162
3163 !> Calibrate all fitted training channels by closed-form leave-one-out
3164 !> prediction without changing the model.
3165 subroutine gpmodel_calibrate_loo(self, nominal_probability, report, ierr)
3166 class(gpmodel), intent(inout) :: self
3167 real(c_double), intent(in) :: nominal_probability
3168 type(calibrationreport) :: report
3169 integer, intent(out), optional :: ierr
3170 integer(c_int) :: rc
3171
3172 rc = c_gpr_model_calibrate_loo_checked(self%handle, nominal_probability, &
3173 report)
3174 if (present(ierr)) ierr = int(rc)
3175 end subroutine
3176
3177 !> Predict energy and gradient at a query point. R_query and G_out hold
3178 !> n_coords values.
3179 subroutine gpmodel_predict(self, R_query, E_out, G_out, n_coords, ierr)
3180 class(gpmodel), intent(inout) :: self
3181 real(c_double), intent(in), contiguous :: r_query(:)
3182 real(c_double), intent(out) :: e_out
3183 real(c_double), intent(out), contiguous :: g_out(:)
3184 integer, intent(in) :: n_coords
3185 integer, intent(out), optional :: ierr
3186 integer(c_int) :: rc
3187
3188 rc = c_gpr_model_predict_checked(self%handle, &
3189 r_query, size(r_query, kind=c_size_t), e_out, &
3190 g_out, size(g_out, kind=c_size_t), int(n_coords, c_int))
3191 if (present(ierr)) ierr = int(rc)
3192 end subroutine
3193
3194 !> Predict variance at a query point. R_query and var_G hold n_coords
3195 !> values.
3196 subroutine gpmodel_predict_variance(self, R_query, var_E, var_G, n_coords, ierr)
3197 class(gpmodel), intent(inout) :: self
3198 real(c_double), intent(in), contiguous :: r_query(:)
3199 real(c_double), intent(out) :: var_e
3200 real(c_double), intent(out), contiguous :: var_g(:)
3201 integer, intent(in) :: n_coords
3202 integer, intent(out), optional :: ierr
3203 integer(c_int) :: rc
3204
3205 rc = c_gpr_model_predict_variance_checked(self%handle, &
3206 r_query, size(r_query, kind=c_size_t), var_e, &
3207 var_g, size(var_g, kind=c_size_t), int(n_coords, c_int))
3208 if (present(ierr)) ierr = int(rc)
3209 end subroutine
3210
3211 !> Predict energy, gradient and their variances at a query point
3212 ! No INTENT on the outputs: an error leaves them unchanged.
3213 subroutine gpmodel_predict_full(self, R_query, E_out, G_out, var_E, var_G, &
3214 n_coords, ierr)
3215 class(gpmodel), intent(inout) :: self
3216 real(c_double), intent(in), contiguous :: r_query(:)
3217 real(c_double) :: e_out, var_e
3218 real(c_double), contiguous :: g_out(:), var_g(:)
3219 integer, intent(in) :: n_coords
3220 integer, intent(out), optional :: ierr
3221 integer(c_int) :: rc
3222
3223 rc = c_gpr_model_predict_full_checked(self%handle, &
3224 r_query, size(r_query, kind=c_size_t), e_out, &
3225 g_out, size(g_out, kind=c_size_t), var_e, &
3226 var_g, size(var_g, kind=c_size_t), int(n_coords, c_int))
3227 if (present(ierr)) ierr = int(rc)
3228 end subroutine
3229
3230 !> Predict at n_queries points stored one after another in R_queries.
3231 !> var_E (n_queries) and var_G (n_queries*n_coords) are optional.
3232 subroutine gpmodel_predict_batch(self, R_queries, E_out, G_out, n_queries, &
3233 n_coords, ierr, var_E, var_G)
3234 class(gpmodel), intent(inout) :: self
3235 real(c_double), intent(in), contiguous :: r_queries(:)
3236 real(c_double), contiguous :: e_out(:), g_out(:)
3237 integer, intent(in) :: n_queries, n_coords
3238 integer, intent(out), optional :: ierr
3239 real(c_double), intent(inout), optional, target, contiguous :: var_e(:)
3240 real(c_double), intent(inout), optional, target, contiguous :: var_g(:)
3241 type(c_ptr) :: pve, pvg
3242 integer(c_size_t) :: nve, nvg
3243 integer(c_int) :: rc
3244
3245 pve = c_null_ptr
3246 pvg = c_null_ptr
3247 nve = 0_c_size_t
3248 nvg = 0_c_size_t
3249 if (present(var_e)) then
3250 pve = c_loc(var_e)
3251 nve = size(var_e, kind=c_size_t)
3252 end if
3253 if (present(var_g)) then
3254 pvg = c_loc(var_g)
3255 nvg = size(var_g, kind=c_size_t)
3256 end if
3257 rc = c_gpr_model_predict_batch_checked(self%handle, &
3258 r_queries, size(r_queries, kind=c_size_t), &
3259 e_out, size(e_out, kind=c_size_t), &
3260 g_out, size(g_out, kind=c_size_t), pve, nve, pvg, nvg, &
3261 int(n_queries, c_int), int(n_coords, c_int))
3262 if (present(ierr)) ierr = int(rc)
3263 end subroutine
3264
3265 !> Apply the posterior-mean Hessian to v. All arrays hold n_coords values.
3266 subroutine gpmodel_predict_hessian_action(self, R_query, v, Hv_out, &
3267 n_coords, ierr)
3268 class(gpmodel), intent(inout) :: self
3269 real(c_double), intent(in), contiguous :: r_query(:), v(:)
3270 real(c_double), contiguous :: hv_out(:)
3271 integer, intent(in) :: n_coords
3272 integer, intent(out), optional :: ierr
3273 integer(c_int) :: rc
3274
3275 rc = c_gpr_model_predict_hessian_action_checked(self%handle, &
3276 r_query, size(r_query, kind=c_size_t), &
3277 v, size(v, kind=c_size_t), hv_out, size(hv_out, kind=c_size_t), &
3278 int(n_coords, c_int))
3279 if (present(ierr)) ierr = int(rc)
3280 end subroutine
3281
3282 !> Certified energy-variance intervals for n_queries contiguous points (ABI 1.14).
3283 subroutine gpmodel_predict_energy_variance_interval(self, R_queries, &
3284 n_queries, n_coords, lower, upper, ierr)
3285 class(gpmodel), intent(inout) :: self
3286 real(c_double), intent(in), contiguous :: r_queries(:)
3287 integer, intent(in) :: n_queries, n_coords
3288 real(c_double), contiguous :: lower(:), upper(:)
3289 integer, intent(out), optional :: ierr
3290 integer(c_int) :: rc
3291
3292 rc = c_gpr_model_predict_energy_variance_interval_checked(self%handle, &
3293 r_queries, size(r_queries, kind=c_size_t), int(n_queries, c_int), &
3294 int(n_coords, c_int), lower, size(lower, kind=c_size_t), upper, &
3295 size(upper, kind=c_size_t))
3296 if (present(ierr)) ierr = int(rc)
3297 end subroutine
3298
3299 !> Condition-floored noise and certificate gap of the trained model (ABI 1.14).
3300 subroutine gpmodel_noise_floor_report(self, report, ierr)
3301 class(gpmodel), intent(in) :: self
3302 type(noisefloorreport), intent(out) :: report
3303 integer, intent(out), optional :: ierr
3304 integer(c_int) :: rc
3305
3306 rc = c_gpr_model_get_noise_floor_report(self%handle, report)
3307 if (present(ierr)) ierr = int(rc)
3308 end subroutine
3309
3310 !> Report whether the model's own kernel-support rule admits R_query.
3311 subroutine gpmodel_prediction_supported(self, R_query, n_coords, supported, &
3312 ierr)
3313 class(gpmodel), intent(inout) :: self
3314 real(c_double), intent(in), contiguous :: r_query(:)
3315 integer, intent(in) :: n_coords
3316 logical :: supported
3317 integer, intent(out), optional :: ierr
3318 integer(c_int) :: rc, value
3319
3320 value = 0_c_int
3321 rc = c_gpr_model_prediction_supported_checked(self%handle, &
3322 r_query, size(r_query, kind=c_size_t), int(n_coords, c_int), value)
3323 if (rc == gpr_success) then
3324 supported = value /= 0_c_int
3325 else if (.not. present(ierr)) then
3326 supported = .false.
3327 end if
3328 call report_status(rc, ierr)
3329 end subroutine
3330
3331 !> Posterior-mean Hessian (n_coords x n_coords, symmetric) at R_query.
3332 subroutine gpmodel_predict_hessian(self, R_query, H_out, n_coords, ierr)
3333 class(gpmodel), intent(inout) :: self
3334 real(c_double), intent(in), contiguous :: r_query(:)
3335 real(c_double), intent(out), contiguous :: h_out(:)
3336 integer, intent(in) :: n_coords
3337 integer, intent(out), optional :: ierr
3338 integer(c_int) :: rc
3339
3340 rc = c_gpr_model_predict_hessian_checked(self%handle, &
3341 r_query, size(r_query, kind=c_size_t), &
3342 h_out, size(h_out, kind=c_size_t), int(n_coords, c_int))
3343 if (rc /= gpr_success) h_out = 0.0_c_double
3344 call report_status(rc, ierr)
3345 end subroutine
3346
3347 !> Factors of one trained energy prediction.
3348 subroutine gpmodel_prediction_factors(self, R_query, n_coords, energy, &
3349 scale, mean, kstar, weights, order, ierr)
3350 class(gpmodel), intent(inout) :: self
3351 real(c_double), intent(in), contiguous :: r_query(:)
3352 integer, intent(in) :: n_coords
3353 real(c_double), intent(out) :: energy, scale, mean
3354 real(c_double), intent(out), contiguous :: kstar(:), weights(:)
3355 integer, intent(out) :: order
3356 integer, intent(out), optional :: ierr
3357 integer(c_int) :: rc, c_order, cap
3358
3359 energy = 0.0_c_double
3360 scale = 0.0_c_double
3361 mean = 0.0_c_double
3362 kstar = 0.0_c_double
3363 weights = 0.0_c_double
3364 order = 0
3365 cap = int(min(size(kstar), size(weights)), c_int)
3366 if (n_coords <= 0 .or. size(r_query) < n_coords .or. cap <= 0) then
3368 else
3369 c_order = 0_c_int
3370 rc = c_gpr_model_prediction_factors(self%handle, r_query, &
3371 int(n_coords, c_int), energy, scale, mean, kstar, weights, cap, &
3372 c_order)
3373 if (rc == gpr_success) order = int(c_order)
3374 end if
3375 call report_status(rc, ierr)
3376 end subroutine
3377
3378 !> Optimizer iterations the last train ran, or -1 if missing. The count is
3379 !> rgmin's SCG steps plus the L-BFGS fallback steps that finish a stalled
3380 !> rgmin SCG fit.
3381 function gpmodel_fit_iterations(self) result(iters)
3382 class(gpmodel), intent(in) :: self
3383 integer :: iters
3384 iters = int(c_gpr_model_fit_iterations(self%handle))
3385 end function
3386
3387 !> Restarts the last train needed: 1 after a restarted marginal-likelihood
3388 !> fit, otherwise 0.
3389 ! INTENT(INOUT) preserves the caller value when C rejects the handle.
3390 subroutine gpmodel_fit_restarts(self, restarts, ierr)
3391 class(gpmodel), intent(in) :: self
3392 integer, intent(inout) :: restarts
3393 integer, intent(out), optional :: ierr
3394 integer(c_int) :: rc, c_restarts
3395
3396 rc = c_gpr_model_fit_restarts(self%handle, c_restarts)
3397 if (rc == gpr_success) restarts = int(c_restarts)
3398 if (present(ierr)) ierr = int(rc)
3399 end subroutine
3400
3401 !> Why the last train stopped: "budget" when an rgmin fit exhausts its
3402 !> iteration budget, "library" when it does not, "restored scg point" when
3403 !> a rejected L-BFGS fallback restores the SCG point, "wall-clock limit"
3404 !> when the wall is already spent, "non-finite marginal likelihood" when a
3405 !> failed fit keeps a non-finite input marginal likelihood, "unset" before
3406 !> any train, and "missing" for a NULL handle.
3407 function gpmodel_fit_stop_reason(self) result(reason)
3408 class(gpmodel), intent(in) :: self
3409 character(len=:), allocatable :: reason
3410 reason = from_c_string(c_gpr_model_fit_stop_reason(self%handle))
3411 end function
3412
3413 !> Configure the random-feature count or automatic held-out selection (-1).
3414 subroutine gpmodel_set_rff_features(self, n_features, force_tol_fraction, &
3415 ierr)
3416 class(gpmodel), intent(inout) :: self
3417 integer, intent(in) :: n_features
3418 real(c_double), intent(in), optional :: force_tol_fraction
3419 integer, intent(out), optional :: ierr
3420 real(c_double) :: frac
3421 integer(c_int) :: rc
3422
3423 frac = 0.0d0
3424 if (present(force_tol_fraction)) frac = force_tol_fraction
3425 rc = c_gpr_model_set_rff_features(self%handle, int(n_features, c_int), &
3426 frac)
3427 if (present(ierr)) ierr = int(rc)
3428 end subroutine
3429
3430 !> Copy the stored held-out random-feature selection report.
3431 subroutine gpmodel_get_rff_selection(self, selection, ierr)
3432 class(gpmodel), intent(in) :: self
3433 type(rffselection), intent(out) :: selection
3434 integer, intent(out), optional :: ierr
3435 integer(c_int) :: rc
3436
3437 selection = rffselection()
3438 rc = c_gpr_model_get_rff_selection(self%handle, selection)
3439 call report_status(rc, ierr)
3440 end subroutine
3441
3442 !> Enable or disable rigid-motion nullspace deflation on training
3443 !> factorizations.
3444 subroutine gpmodel_set_rigid_null_deflation(self, enabled, ierr)
3445 class(gpmodel), intent(inout) :: self
3446 logical, intent(in) :: enabled
3447 integer, intent(out), optional :: ierr
3448 integer(c_int) :: rc, flag
3449
3450 if (enabled) then
3451 flag = 1_c_int
3452 else
3453 flag = 0_c_int
3454 end if
3455 rc = c_gpr_model_set_rigid_null_deflation(self%handle, flag)
3456 call report_status(rc, ierr)
3457 end subroutine
3458
3459 !> Query whether rigid-motion nullspace deflation is enabled.
3460 function gpmodel_get_rigid_null_deflation(self, ierr) result(enabled)
3461 class(gpmodel), intent(in) :: self
3462 integer, intent(out), optional :: ierr
3463 logical :: enabled
3464 integer(c_int) :: rc, out_flag
3465
3466 out_flag = 0_c_int
3467 rc = c_gpr_model_get_rigid_null_deflation(self%handle, out_flag)
3468 enabled = (rc == gpr_success .and. out_flag /= 0_c_int)
3469 call report_status(rc, ierr)
3470 end function
3471
3472 !> GPR_MODEL_GP or GPR_MODEL_TP
3473 function gpmodel_model_type(self) result(model_type)
3474 class(gpmodel), intent(in) :: self
3475 integer :: model_type
3476 model_type = int(c_gpr_model_type(self%handle))
3477 end function
3478
3479 !> Number of kernel lengthscale parameters
3480 function gpmodel_n_lengthscales(self) result(n)
3481 class(gpmodel), intent(in) :: self
3482 integer :: n
3483 n = int(c_gpr_model_n_lengthscales(self%handle))
3484 end function
3485
3486 !> Get lengthscale values. out must hold n_lengthscales() values; a
3487 !> shorter array is refused with GPR_ERR_INVALID_ARG.
3488 subroutine gpmodel_get_lengthscales(self, out, ierr)
3489 class(gpmodel), intent(in) :: self
3490 real(c_double), intent(out), contiguous :: out(:)
3491 integer, intent(out), optional :: ierr
3492 integer(c_int) :: rc
3493
3494 if (size(out) < c_gpr_model_n_lengthscales(self%handle)) then
3496 else
3497 rc = c_gpr_model_get_lengthscales(self%handle, out)
3498 end if
3499 if (present(ierr)) ierr = int(rc)
3500 end subroutine
3501
3502 !> Set lengthscale values. values must hold n values.
3503 subroutine gpmodel_set_lengthscales(self, values, n, ierr)
3504 class(gpmodel), intent(inout) :: self
3505 real(c_double), intent(in), contiguous :: values(:)
3506 integer, intent(in) :: n
3507 integer, intent(out), optional :: ierr
3508 integer(c_int) :: rc
3509
3510 if (n < 0 .or. size(values) < n) then
3512 else
3513 rc = c_gpr_model_set_lengthscales(self%handle, values, int(n, c_int))
3514 end if
3515 if (present(ierr)) ierr = int(rc)
3516 end subroutine
3517
3518 !> Get signal variance
3519 subroutine gpmodel_get_magn_sigma2(self, val, ierr)
3520 class(gpmodel), intent(in) :: self
3521 real(c_double), intent(out) :: val
3522 integer, intent(out), optional :: ierr
3523 integer(c_int) :: rc
3524
3525 rc = c_gpr_model_get_magn_sigma2(self%handle, val)
3526 if (present(ierr)) ierr = int(rc)
3527 end subroutine
3528
3529 !> Set signal variance
3530 subroutine gpmodel_set_magn_sigma2(self, val, ierr)
3531 class(gpmodel), intent(inout) :: self
3532 real(c_double), intent(in) :: val
3533 integer, intent(out), optional :: ierr
3534 integer(c_int) :: rc
3535
3536 rc = c_gpr_model_set_magn_sigma2(self%handle, val)
3537 if (present(ierr)) ierr = int(rc)
3538 end subroutine
3539
3540 !> Get noise variance
3541 subroutine gpmodel_get_sigma2(self, val, ierr)
3542 class(gpmodel), intent(in) :: self
3543 real(c_double), intent(out) :: val
3544 integer, intent(out), optional :: ierr
3545 integer(c_int) :: rc
3546
3547 rc = c_gpr_model_get_sigma2(self%handle, val)
3548 if (present(ierr)) ierr = int(rc)
3549 end subroutine
3550
3551 !> Configured numerical diagonal jitter variance.
3552 ! INTENT(INOUT) preserves the caller value when C rejects the handle.
3553 subroutine gpmodel_get_jitter(self, val, ierr)
3554 class(gpmodel), intent(in) :: self
3555 real(c_double), intent(inout) :: val
3556 integer, intent(out), optional :: ierr
3557 integer(c_int) :: rc
3558
3559 rc = c_gpr_model_get_jitter(self%handle, val)
3560 if (present(ierr)) ierr = int(rc)
3561 end subroutine
3562
3563 !> Select the HS-SVD stable-basis backend for the next training call.
3564 subroutine gpmodel_set_hssvd_backend(self, enabled, ierr)
3565 class(gpmodel), intent(inout) :: self
3566 logical, intent(in) :: enabled
3567 integer, intent(out), optional :: ierr
3568 integer(c_int) :: rc
3569
3570 rc = c_gpr_model_set_hssvd_backend( &
3571 self%handle, merge(gpr_hssvd_backend_hssvd, &
3573 if (present(ierr)) ierr = int(rc)
3574 end subroutine
3575
3576 !> Return whether the HS-SVD stable-basis backend is selected.
3577 subroutine gpmodel_get_hssvd_backend(self, enabled, ierr)
3578 class(gpmodel), intent(in) :: self
3579 logical, intent(out) :: enabled
3580 integer, intent(out), optional :: ierr
3581 integer(c_int) :: rc, value
3582
3583 value = 0_c_int
3584 rc = c_gpr_model_get_hssvd_backend(self%handle, value)
3585 enabled = value /= gpr_hssvd_backend_cholesky
3586 if (present(ierr)) ierr = int(rc)
3587 end subroutine
3588
3589 !> Posterior mean weights. size(alpha) is the buffer capacity passed to C.
3590 ! A short or empty buffer returns GPR_ERR_INVALID_ARG and is not written.
3591 ! Capacity beyond the weight vector is left unchanged.
3592 subroutine gpmodel_get_alpha(self, alpha, ierr)
3593 class(gpmodel), intent(in) :: self
3594 real(c_double), intent(inout), contiguous :: alpha(:)
3595 integer, intent(out), optional :: ierr
3596 integer(c_int) :: rc
3597 integer(c_int) :: capacity
3598 real(c_double) :: unused(1)
3599
3600 if (size(alpha, kind=c_size_t) > int(huge(0_c_int), c_size_t)) then
3602 else if (size(alpha) == 0) then
3603 ! n <= 0 is rejected before C reads or writes the pointer.
3604 unused = 0.0_c_double
3605 rc = c_gpr_model_get_alpha(self%handle, unused, 0_c_int)
3606 else
3607 capacity = int(size(alpha), c_int)
3608 rc = c_gpr_model_get_alpha(self%handle, alpha, capacity)
3609 end if
3610 if (present(ierr)) ierr = int(rc)
3611 end subroutine
3612
3613 !> Set noise variance
3614 subroutine gpmodel_set_sigma2(self, val, ierr)
3615 class(gpmodel), intent(inout) :: self
3616 real(c_double), intent(in) :: val
3617 integer, intent(out), optional :: ierr
3618 integer(c_int) :: rc
3619
3620 rc = c_gpr_model_set_sigma2(self%handle, val)
3621 if (present(ierr)) ierr = int(rc)
3622 end subroutine
3623
3624 !> Number of training observations
3625 function gpmodel_n_observations(self) result(n)
3626 class(gpmodel), intent(in) :: self
3627 integer :: n
3628 n = int(c_gpr_model_n_observations(self%handle))
3629 end function
3630
3631 !> TP prefactor (valid after training, TP models only)
3632 subroutine gpmodel_tp_prefactor(self, val, ierr)
3633 class(gpmodel), intent(in) :: self
3634 real(c_double), intent(out) :: val
3635 integer, intent(out), optional :: ierr
3636 integer(c_int) :: rc
3637
3638 rc = c_gpr_model_tp_prefactor(self%handle, val)
3639 if (present(ierr)) ierr = int(rc)
3640 end subroutine
3641
3642 function gpmodel_is_valid(self) result(valid)
3643 class(gpmodel), intent(in) :: self
3644 logical :: valid
3645 valid = c_associated(self%handle)
3646 end function
3647
3648 !> Assignment shares the handle; each wrapper releases its own reference.
3649 impure elemental subroutine gpmodel_assign(self, other)
3650 class(gpmodel), intent(inout) :: self
3651 type(gpmodel), intent(in) :: other
3652 type(c_ptr) :: handle
3653 integer, pointer :: references
3654
3655 if (associated(self%references, other%references)) return
3656 handle = other%handle
3657 references => other%references
3658 if (associated(references)) references = references + 1
3659 call self%release()
3660 self%handle = handle
3661 self%references => references
3662 end subroutine
3663
3664 subroutine gpmodel_release(self)
3665 class(gpmodel), intent(inout) :: self
3666 if (associated(self%references)) then
3667 self%references = self%references - 1
3668 if (self%references == 0) then
3669 call c_gpr_model_destroy(self%handle)
3670 deallocate(self%references)
3671 end if
3672 end if
3673 self%handle = c_null_ptr
3674 nullify(self%references)
3675 end subroutine
3676
3677 impure elemental subroutine gpmodel_finalize(self)
3678 type(gpmodel), intent(inout) :: self
3679 call self%release()
3680 end subroutine
3681
3682 ! ===================================================================
3683 ! NEBResult implementation
3684 ! ===================================================================
3685
3686 function neb_converged(self) result(conv)
3687 class(nebresult), intent(in) :: self
3688 logical :: conv
3689 conv = (c_gpr_neb_result_converged(self%handle) /= 0)
3690 end function
3691
3692 function neb_oracle_calls(self) result(n)
3693 class(nebresult), intent(in) :: self
3694 integer :: n
3695 n = int(c_gpr_neb_result_oracle_calls(self%handle))
3696 end function
3697
3698 function neb_barrier(self) result(b)
3699 class(nebresult), intent(in) :: self
3700 real(c_double) :: b
3701 b = c_gpr_neb_result_barrier(self%handle)
3702 end function
3703
3704 function neb_n_images(self) result(n)
3705 class(nebresult), intent(in) :: self
3706 integer :: n
3707 n = int(c_gpr_neb_result_n_images(self%handle))
3708 end function
3709
3710 subroutine neb_image_energy(self, idx, energy, ierr)
3711 class(nebresult), intent(in) :: self
3712 integer, intent(in) :: idx
3713 real(c_double), intent(out) :: energy
3714 integer, intent(out), optional :: ierr
3715 integer(c_int) :: rc
3716
3717 rc = c_gpr_neb_result_image_energy(self%handle, int(idx, c_int), energy)
3718 if (present(ierr)) ierr = int(rc)
3719 end subroutine
3720
3721 subroutine neb_image_positions(self, idx, positions, n_coords, ierr)
3722 class(nebresult), intent(in) :: self
3723 integer, intent(in) :: idx, n_coords
3724 real(c_double), intent(out), contiguous :: positions(:)
3725 integer, intent(out), optional :: ierr
3726 integer(c_int) :: rc
3727
3728 if (n_coords < 0 .or. size(positions) < n_coords) then
3730 else
3731 rc = c_gpr_neb_result_image_positions(self%handle, int(idx, c_int), &
3732 positions, int(n_coords, c_int))
3733 end if
3734 if (present(ierr)) ierr = int(rc)
3735 end subroutine
3736
3737 !> GPR_NEB_NOT_CONVERGED, GPR_NEB_FORCE_TOLERANCE or
3738 !> GPR_NEB_MODEL_NOISE_FLOOR.
3739 function neb_convergence_status(self) result(status)
3740 class(nebresult), intent(in) :: self
3741 integer :: status
3742 status = int(c_gpr_neb_result_convergence_status(self%handle))
3743 end function
3744
3745 function neb_outer_iterations(self) result(n)
3746 class(nebresult), intent(in) :: self
3747 integer :: n
3748 n = int(c_gpr_neb_result_outer_iterations(self%handle))
3749 end function
3750
3751 !> Energies of every image, endpoints included.
3752 subroutine neb_energies(self, energies, stat, errmsg)
3753 class(nebresult), intent(in) :: self
3754 real(c_double), allocatable, intent(out) :: energies(:)
3755 integer, intent(out), optional :: stat
3756 character(len=*), intent(inout), optional :: errmsg
3757 integer(c_int) :: n
3758
3759 n = c_gpr_neb_result_n_images(self%handle)
3760 allocate(energies(max(n, 0)))
3761 if (n <= 0) then
3762 call report_status(gpr_err_null_handle, stat, errmsg, &
3763 'NEBResult%energies: the result holds no path')
3764 return
3765 end if
3766 call report_status(c_gpr_neb_result_all_energies(self%handle, energies, &
3767 n), stat, errmsg)
3768 end subroutine
3769
3770 !> 0-based index of the highest-energy image.
3771 function neb_max_energy_image(self) result(idx)
3772 class(nebresult), intent(in) :: self
3773 integer :: idx
3774 idx = int(c_gpr_neb_result_max_energy_image(self%handle))
3775 end function
3776
3777 !> Fill report (gpr_neb_report_t) from the result.
3778 subroutine neb_report(self, report, stat, errmsg)
3779 class(nebresult), intent(in) :: self
3780 type(nebreport), intent(inout) :: report
3781 integer, intent(out), optional :: stat
3782 character(len=*), intent(inout), optional :: errmsg
3783
3784 report%struct_size = c_sizeof(report)
3785 call report_status(c_gpr_neb_result_report(self%handle, report), stat, &
3786 errmsg)
3787 end subroutine
3788
3789 function neb_is_valid(self) result(valid)
3790 class(nebresult), intent(in) :: self
3791 logical :: valid
3792 valid = c_associated(self%handle)
3793 end function
3794
3795 !> Assignment shares the handle; each wrapper releases its own reference.
3796 impure elemental subroutine neb_assign(self, other)
3797 class(nebresult), intent(inout) :: self
3798 type(nebresult), intent(in) :: other
3799 type(c_ptr) :: handle
3800 integer, pointer :: references
3801
3802 if (associated(self%references, other%references)) return
3803 handle = other%handle
3804 references => other%references
3805 if (associated(references)) references = references + 1
3806 call self%release()
3807 self%handle = handle
3808 self%references => references
3809 end subroutine
3810
3811 subroutine neb_release(self)
3812 class(nebresult), intent(inout) :: self
3813 if (associated(self%references)) then
3814 self%references = self%references - 1
3815 if (self%references == 0) then
3816 call c_gpr_neb_result_destroy(self%handle)
3817 deallocate(self%references)
3818 end if
3819 end if
3820 self%handle = c_null_ptr
3821 nullify(self%references)
3822 end subroutine
3823
3824 impure elemental subroutine neb_finalize(self)
3825 type(nebresult), intent(inout) :: self
3826 call self%release()
3827 end subroutine
3828
3829 ! ===================================================================
3830 ! Analytical potentials (convenience wrappers)
3831 ! ===================================================================
3832
3833 !> Lennard-Jones energy and gradient
3834 subroutine gpr_lj_energy(x, n_atoms, epsilon, sigma, energy, gradient, ierr)
3835 real(c_double), intent(in), contiguous :: x(:)
3836 integer, intent(in) :: n_atoms
3837 real(c_double), intent(in) :: epsilon, sigma
3838 real(c_double), intent(out) :: energy
3839 real(c_double), intent(out), contiguous :: gradient(:)
3840 integer, intent(out), optional :: ierr
3841 integer(c_int) :: rc
3842
3843 if (n_atoms < 1 .or. size(x) < 3 * n_atoms .or. &
3844 size(gradient) < 3 * n_atoms) then
3846 else
3847 rc = c_gpr_potential_lj(x, int(n_atoms, c_int), epsilon, sigma, &
3848 energy, gradient)
3849 end if
3850 if (present(ierr)) ierr = int(rc)
3851 end subroutine
3852
3853 !> Muller-Brown 2D potential
3854 subroutine gpr_muller_brown_energy(xy, energy, gradient, ierr)
3855 real(c_double), intent(in) :: xy(2)
3856 real(c_double), intent(out) :: energy
3857 real(c_double), intent(out) :: gradient(2)
3858 integer, intent(out), optional :: ierr
3859 integer(c_int) :: rc
3860
3861 rc = c_gpr_potential_muller_brown(xy, energy, gradient)
3862 if (present(ierr)) ierr = int(rc)
3863 end subroutine
3864
3865 !> LEPS collinear potential
3866 subroutine gpr_leps_energy(r, energy, gradient, ierr)
3867 real(c_double), intent(in) :: r(2)
3868 real(c_double), intent(out) :: energy
3869 real(c_double), intent(out) :: gradient(2)
3870 integer, intent(out), optional :: ierr
3871 integer(c_int) :: rc
3872
3873 rc = c_gpr_potential_leps(r, energy, gradient)
3874 if (present(ierr)) ierr = int(rc)
3875 end subroutine
3876
3877 !> Oracle adapter for Lennard-Jones (user_data points to LJParams).
3878 subroutine gpr_oracle_lj(n_coords, positions, energy, gradient, user_data)
3879 integer, intent(in) :: n_coords
3880 real(c_double), intent(in) :: positions(:)
3881 real(c_double), intent(out) :: energy
3882 real(c_double), intent(out) :: gradient(:)
3883 type(c_ptr), intent(in) :: user_data
3884 call c_gpr_oracle_lj(int(n_coords, c_int), positions, energy, gradient, &
3885 user_data)
3886 end subroutine
3887
3888 !> Oracle adapter for Muller-Brown.
3889 subroutine gpr_oracle_muller_brown(n_coords, positions, energy, gradient, &
3890 user_data)
3891 integer, intent(in) :: n_coords
3892 real(c_double), intent(in) :: positions(:)
3893 real(c_double), intent(out) :: energy
3894 real(c_double), intent(out) :: gradient(:)
3895 type(c_ptr), intent(in), optional :: user_data
3896 type(c_ptr) :: ud
3897 ud = c_null_ptr
3898 if (present(user_data)) ud = user_data
3899 call c_gpr_oracle_muller_brown(int(n_coords, c_int), positions, energy, &
3900 gradient, ud)
3901 end subroutine
3902
3903 !> Oracle adapter for LEPS.
3904 subroutine gpr_oracle_leps(n_coords, positions, energy, gradient, user_data)
3905 integer, intent(in) :: n_coords
3906 real(c_double), intent(in) :: positions(:)
3907 real(c_double), intent(out) :: energy
3908 real(c_double), intent(out) :: gradient(:)
3909 type(c_ptr), intent(in), optional :: user_data
3910 type(c_ptr) :: ud
3911 ud = c_null_ptr
3912 if (present(user_data)) ud = user_data
3913 call c_gpr_oracle_leps(int(n_coords, c_int), positions, energy, &
3914 gradient, ud)
3915 end subroutine
3916
3917 ! ===================================================================
3918 ! PotentialHandle implementation
3919 ! ===================================================================
3920
3921 function gpr_potential_from_force(fn, user_data, stat, errmsg) result(self)
3922 procedure(gpr_force_interface) :: fn
3923 type(c_ptr), intent(in), optional :: user_data
3924 integer, intent(out), optional :: stat
3925 character(len=*), intent(inout), optional :: errmsg
3926 type(potentialhandle) :: self
3927 type(c_ptr) :: ud
3928 integer(c_int) :: rc
3929
3930 ud = c_null_ptr
3931 if (present(user_data)) ud = user_data
3932 self%handle = c_gpr_potential_from_force(c_funloc(fn), ud)
3933 if (c_associated(self%handle)) then
3934 allocate(self%references, source=1)
3935 rc = gpr_success
3936 else
3937 rc = failed_status()
3938 end if
3939 call report_status(rc, stat, errmsg)
3940 end function
3941
3942 function gpr_potential_from_force_with_uncertainty(fn, user_data, stat, &
3943 errmsg) result(self)
3945 type(c_ptr), intent(in), optional :: user_data
3946 integer, intent(out), optional :: stat
3947 character(len=*), intent(inout), optional :: errmsg
3948 type(potentialhandle) :: self
3949 type(c_ptr) :: ud
3950 integer(c_int) :: rc
3951
3952 ud = c_null_ptr
3953 if (present(user_data)) ud = user_data
3954 self%handle = c_gpr_potential_from_force_with_uncertainty(c_funloc(fn), ud)
3955 if (c_associated(self%handle)) then
3956 allocate(self%references, source=1)
3957 rc = gpr_success
3958 else
3959 rc = failed_status()
3960 end if
3961 call report_status(rc, stat, errmsg)
3962 end function
3963
3964 subroutine pot_force(self, n_atoms, R, atomic_nrs, F, energy, &
3965 energy_noise_rms, box, stat, errmsg)
3966 class(potentialhandle), intent(in) :: self
3967 integer, intent(in) :: n_atoms
3968 real(c_double), intent(in) :: r(:)
3969 integer, intent(in) :: atomic_nrs(:)
3970 real(c_double), intent(out) :: f(:)
3971 real(c_double), intent(out) :: energy
3972 real(c_double), intent(out), optional, target :: energy_noise_rms
3973 real(c_double), intent(in), optional, target :: box(9)
3974 integer, intent(out), optional :: stat
3975 character(len=*), intent(inout), optional :: errmsg
3976 integer(c_int), allocatable :: z(:)
3977 type(c_ptr) :: p_en, p_box
3978 real(c_double), target :: zero_box(9)
3979 integer(c_int) :: rc
3980
3981 if (n_atoms <= 0 .or. size(r) < 3 * n_atoms .or. &
3982 size(f) < 3 * n_atoms .or. size(atomic_nrs) < n_atoms) then
3983 call report_status(gpr_err_invalid_arg, stat, errmsg, &
3984 'PotentialHandle%force: array sizes do not match n_atoms')
3985 return
3986 end if
3987 z = int(atomic_nrs(1:n_atoms), c_int)
3988 p_en = c_null_ptr
3989 if (present(energy_noise_rms)) p_en = c_loc(energy_noise_rms)
3990 zero_box = 0.0d0
3991 if (present(box)) then
3992 p_box = c_loc(box)
3993 else
3994 p_box = c_loc(zero_box)
3995 end if
3996 rc = c_gpr_potential_force(self%handle, int(n_atoms, c_long), r, z, f, &
3997 energy, p_en, p_box)
3998 call report_status(rc, stat, errmsg)
3999 end subroutine
4000
4001 subroutine pot_force_with_uncertainty(self, n_atoms, R, atomic_nrs, F, &
4002 energy, energy_noise_rms, force_noise_rms, box, stat, errmsg)
4003 class(potentialhandle), intent(in) :: self
4004 integer, intent(in) :: n_atoms
4005 real(c_double), intent(in) :: r(:)
4006 integer, intent(in) :: atomic_nrs(:)
4007 real(c_double), intent(out) :: f(:)
4008 real(c_double), intent(out) :: energy
4009 real(c_double), intent(out), optional, target :: energy_noise_rms
4010 real(c_double), intent(out), optional, target :: force_noise_rms
4011 real(c_double), intent(in), optional, target :: box(9)
4012 integer, intent(out), optional :: stat
4013 character(len=*), intent(inout), optional :: errmsg
4014 integer(c_int), allocatable :: z(:)
4015 type(c_ptr) :: p_en, p_fn, p_box
4016 real(c_double), target :: zero_box(9)
4017 integer(c_int) :: rc
4018
4019 if (n_atoms <= 0 .or. size(r) < 3 * n_atoms .or. &
4020 size(f) < 3 * n_atoms .or. size(atomic_nrs) < n_atoms) then
4021 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4022 'PotentialHandle%force_with_uncertainty: array sizes do not match')
4023 return
4024 end if
4025 z = int(atomic_nrs(1:n_atoms), c_int)
4026 p_en = c_null_ptr
4027 if (present(energy_noise_rms)) p_en = c_loc(energy_noise_rms)
4028 p_fn = c_null_ptr
4029 if (present(force_noise_rms)) p_fn = c_loc(force_noise_rms)
4030 zero_box = 0.0d0
4031 if (present(box)) then
4032 p_box = c_loc(box)
4033 else
4034 p_box = c_loc(zero_box)
4035 end if
4036 rc = c_gpr_potential_force_with_uncertainty(self%handle, &
4037 int(n_atoms, c_long), r, z, f, energy, p_en, p_fn, p_box)
4038 call report_status(rc, stat, errmsg)
4039 end subroutine
4040
4041 function pot_is_valid(self) result(valid)
4042 class(potentialhandle), intent(in) :: self
4043 logical :: valid
4044 valid = c_associated(self%handle)
4045 end function
4046
4047 function pot_get_handle(self) result(h)
4048 class(potentialhandle), intent(in) :: self
4049 type(c_ptr) :: h
4050 h = self%handle
4051 end function
4052
4053 impure elemental subroutine pot_assign(self, other)
4054 class(potentialhandle), intent(inout) :: self
4055 type(potentialhandle), intent(in) :: other
4056 type(c_ptr) :: handle
4057 integer, pointer :: references
4058
4059 if (associated(self%references, other%references)) return
4060 handle = other%handle
4061 references => other%references
4062 if (associated(references)) references = references + 1
4063 call self%release()
4064 self%handle = handle
4065 self%references => references
4066 end subroutine
4067
4068 subroutine pot_release(self)
4069 class(potentialhandle), intent(inout) :: self
4070 if (associated(self%references)) then
4071 self%references = self%references - 1
4072 if (self%references == 0) then
4073 call c_gpr_potential_destroy(self%handle)
4074 deallocate(self%references)
4075 end if
4076 end if
4077 self%handle = c_null_ptr
4078 nullify(self%references)
4079 end subroutine
4080
4081 impure elemental subroutine pot_finalize(self)
4082 type(potentialhandle), intent(inout) :: self
4083 call self%release()
4084 end subroutine
4085
4086 ! ===================================================================
4087 ! Strings and status
4088 ! ===================================================================
4089
4090 !> Copy of a NUL-terminated C string; empty for C_NULL_PTR.
4091 function from_c_string(p) result(s)
4092 type(c_ptr), intent(in) :: p
4093 character(len=:), allocatable :: s
4094 character(kind=c_char), pointer :: chars(:)
4095 integer :: n, i
4096
4097 if (.not. c_associated(p)) then
4098 s = ''
4099 return
4100 end if
4101 n = int(c_strlen(p))
4102 call c_f_pointer(p, chars, [n])
4103 allocate(character(len=n) :: s)
4104 do i = 1, n
4105 s(i:i) = chars(i)
4106 end do
4107 end function
4108
4109 !> Fortran string as a C string (trailing blanks dropped).
4110 pure function to_c_string(s) result(c)
4111 character(len=*), intent(in) :: s
4112 character(kind=c_char, len=len_trim(s) + 1) :: c
4113 c = trim(s) // c_null_char
4114 end function
4115
4116 !> Return rc the way the intrinsic statements do: with stat present it
4117 !> receives the status and errmsg, if present, the message of a failure;
4118 !> without stat a failure stops the program with that message.
4119 subroutine report_status(rc, stat, errmsg, message)
4120 integer(c_int), intent(in) :: rc
4121 integer, intent(out), optional :: stat
4122 character(len=*), intent(inout), optional :: errmsg
4123 character(len=*), intent(in), optional :: message
4124 character(len=:), allocatable :: text
4125
4126 if (present(stat)) stat = int(rc)
4127 if (rc == gpr_success) return
4128 if (present(message)) then
4129 text = message
4130 else
4131 text = gpr_error_message()
4132 end if
4133 if (present(errmsg)) errmsg = text
4134 if (.not. present(stat)) error stop text
4135 end subroutine
4136
4137 !> gpr_atoms_config_defaults() of the loaded library.
4138 function gpr_atoms_config_defaults() result(config)
4139 type(atomsdescriptor) :: config
4140 config = c_gpr_atoms_config_defaults()
4141 end function
4142
4143 !> gpr_atoms_simple() of the loaded library.
4144 function gpr_atoms_simple(n_atoms) result(config)
4145 integer, intent(in) :: n_atoms
4146 type(atomsdescriptor) :: config
4147 config = c_gpr_atoms_simple(int(n_atoms, c_int))
4148 end function
4149
4150 !> gpr_dimer_config_defaults() of the loaded library; equal to a
4151 !> default-initialized DimerConfig.
4152 function gpr_dimer_config_defaults() result(config)
4153 type(dimerconfig) :: config
4154 config = c_gpr_dimer_config_defaults()
4155 end function
4156
4157 !> gpr_model_config_defaults() of the loaded library.
4158 function gpr_model_config_defaults() result(config)
4159 type(modelconfig) :: config
4160 config = c_gpr_model_config_defaults()
4161 end function
4162
4163 !> gpr_neb_config_defaults() of the loaded library.
4164 function gpr_neb_config_defaults() result(config)
4165 type(nebconfig) :: config
4166 config = c_gpr_neb_config_defaults()
4167 end function
4168
4169 !> gpr_minimize_config_defaults() of the loaded library.
4170 function gpr_minimize_config_defaults() result(config)
4171 type(minimizeconfig) :: config
4172 config = c_gpr_minimize_config_defaults()
4173 end function
4174
4175 !> gpr_ocineb_config_defaults() of the loaded library.
4176 function gpr_ocineb_config_defaults() result(config)
4177 type(ocinebconfig) :: config
4178 config = c_gpr_ocineb_config_defaults()
4179 end function
4180
4181 !> Version components of the loaded library.
4182 subroutine gpr_version_components(major, minor, patch)
4183 integer, intent(out) :: major, minor, patch
4184 integer(c_int) :: a, b, c
4185 call c_gpr_version_components(a, b, c)
4186 major = int(a)
4187 minor = int(b)
4188 patch = int(c)
4189 end subroutine
4190
4191 !> ABI version of the loaded library (GPR_C_ABI_MAJOR/MINOR give this
4192 !> module's).
4193 subroutine gpr_abi_version(major, minor)
4194 integer, intent(out) :: major, minor
4195 integer(c_int) :: a, b
4196 call c_gpr_abi_version(a, b)
4197 major = int(a)
4198 minor = int(b)
4199 end subroutine
4200
4201 !> Name of a status code, e.g. "GPR_ERR_ORACLE".
4202 function gpr_status_name(status) result(name)
4203 integer, intent(in) :: status
4204 character(len=:), allocatable :: name
4205 name = from_c_string(c_gpr_status_name(int(status, c_int)))
4206 end function
4207
4208 !> Status of the last failing call on this thread; GPR_SUCCESS after a
4209 !> call that succeeded.
4210 function gpr_last_status() result(status)
4211 integer :: status
4212 status = int(c_gpr_last_status())
4213 end function
4214
4215 !> Status of a constructor that returned no handle.
4216 function failed_status() result(rc)
4217 integer(c_int) :: rc
4218 rc = c_gpr_last_status()
4219 if (rc == gpr_success) rc = gpr_err_internal
4220 end function
4221
4222 !> "slate", "scalapack", "kokkos", "cusolver", "cholmod", "stdpar" or
4223 !> "eigen".
4224 function gpr_backend_name() result(name)
4225 character(len=:), allocatable :: name
4226 name = from_c_string(c_gpr_backend_name())
4227 end function
4228
4229 !> True when the linear-algebra backend needs MPI initialized first.
4230 function gpr_backend_requires_mpi() result(requires)
4231 logical :: requires
4232 requires = c_gpr_backend_requires_mpi() /= 0
4233 end function
4234
4235 function gpr_mpi_initialized() result(initialized)
4236 logical :: initialized
4237 initialized = c_gpr_mpi_initialized() /= 0
4238 end function
4239
4240 !> Rank in MPI_COMM_WORLD, 0 without MPI.
4241 function gpr_mpi_world_rank() result(rank)
4242 integer :: rank
4243 rank = int(c_gpr_mpi_world_rank())
4244 end function
4245
4246 !> Size of MPI_COMM_WORLD, 1 without MPI.
4247 function gpr_mpi_world_size() result(size_)
4248 integer :: size_
4249 size_ = int(c_gpr_mpi_world_size())
4250 end function
4251
4252 !> OpenMP thread budget, 1 without OpenMP.
4253 function gpr_omp_max_threads() result(threads)
4254 integer :: threads
4255 threads = int(c_gpr_omp_max_threads())
4256 end function
4257
4258 !> Library version string, "major.minor.patch".
4259 function gpr_version_string() result(version)
4260 character(len=:), allocatable :: version
4261 version = from_c_string(c_gpr_version())
4262 end function
4263
4264 !> Message of the last failing call on this thread.
4265 function gpr_error_message() result(message)
4266 character(len=:), allocatable :: message
4267 message = gpr_last_error_message()
4268 end function
4269
4270 !> Same string as gpr_error_message. This is the C name.
4271 function gpr_last_error_message() result(message)
4272 character(len=:), allocatable :: message
4273 message = from_c_string(c_gpr_last_error())
4274 end function
4275
4276 !> Alias of gpr_last_error_message matching gpr_last_error in gpridge_c.h.
4277 function gpr_last_error() result(message)
4278 character(len=:), allocatable :: message
4279 message = from_c_string(c_gpr_last_error_raw())
4280 end function
4281
4282 !> Check that the loaded library implements the ABI this module binds.
4283 subroutine gpr_check_abi(stat, errmsg)
4284 integer, intent(out), optional :: stat
4285 character(len=*), intent(inout), optional :: errmsg
4286 call report_status(c_gpr_abi_check(gpr_c_abi_major, gpr_c_abi_minor), &
4287 stat, errmsg)
4288 end subroutine
4289
4290 ! ===================================================================
4291 ! Runtime configuration
4292 ! ===================================================================
4293
4294 !> "reproducible" (the default) or "library"; see gpr_set_linalg_mode in
4295 !> gpridge_c.h.
4296 subroutine gpr_set_linalg_mode(mode, stat, errmsg)
4297 character(len=*), intent(in) :: mode
4298 integer, intent(out), optional :: stat
4299 character(len=*), intent(inout), optional :: errmsg
4300 call report_status(c_gpr_set_linalg_mode(to_c_string(mode)), stat, errmsg)
4301 end subroutine
4302
4303 function gpr_linalg_mode() result(mode)
4304 character(len=:), allocatable :: mode
4305 mode = from_c_string(c_gpr_linalg_mode())
4306 end function
4307
4308 subroutine gpr_set_linalg_threads(threads, stat, errmsg)
4309 integer, intent(in) :: threads
4310 integer, intent(out), optional :: stat
4311 character(len=*), intent(inout), optional :: errmsg
4312 call report_status(c_gpr_set_linalg_threads(int(threads, c_int)), &
4313 stat, errmsg)
4314 end subroutine
4315
4316 !> Select Eigen's serial factor/solve (true) or OpenMP panel kernels (false).
4317 subroutine gpr_set_library_serial(enabled, stat, errmsg)
4318 logical, intent(in) :: enabled
4319 integer, intent(out), optional :: stat
4320 character(len=*), intent(inout), optional :: errmsg
4321 integer(c_int) :: flag
4322 flag = 0_c_int
4323 if (enabled) flag = 1_c_int
4324 call report_status(c_gpr_set_library_serial(flag), stat, errmsg)
4325 end subroutine
4326
4327 !> Zero the train-phase wall-time accumulators.
4329 call c_gpr_train_phase_reset()
4330 end subroutine
4331
4332 !> Read the five train-phase wall-time accumulators.
4333 subroutine gpr_train_phase_read(factor_s, solve_s, eigen_s, kernel_s, &
4334 hessian_s)
4335 real(c_double), intent(out), optional, target :: factor_s, solve_s, &
4336 eigen_s, kernel_s, hessian_s
4337 type(c_ptr) :: p_fac, p_sol, p_eig, p_ker, p_hes
4338
4339 p_fac = c_null_ptr
4340 p_sol = c_null_ptr
4341 p_eig = c_null_ptr
4342 p_ker = c_null_ptr
4343 p_hes = c_null_ptr
4344 if (present(factor_s)) p_fac = c_loc(factor_s)
4345 if (present(solve_s)) p_sol = c_loc(solve_s)
4346 if (present(eigen_s)) p_eig = c_loc(eigen_s)
4347 if (present(kernel_s)) p_ker = c_loc(kernel_s)
4348 if (present(hessian_s)) p_hes = c_loc(hessian_s)
4349 call c_gpr_train_phase_read(p_fac, p_sol, p_eig, p_ker, p_hes)
4350 end subroutine
4351
4352 !> Read the train-phase leaf accumulators (setup, conditioning, etc.).
4353 subroutine gpr_train_phase_read_leaves(setup_s, descriptor_s, posterior_s, &
4354 subset_s, objective_s, condition_s, cache_s, curvature_s, energy_s, &
4355 schedule_s)
4356 real(c_double), intent(out), optional, target :: setup_s, descriptor_s, &
4357 posterior_s, subset_s, objective_s, condition_s, cache_s, curvature_s, &
4358 energy_s, schedule_s
4359 type(c_ptr) :: p1, p2, p3, p4, p5, p6, p7, p8, p9, p10
4360
4361 p1 = c_null_ptr; p2 = c_null_ptr; p3 = c_null_ptr; p4 = c_null_ptr
4362 p5 = c_null_ptr; p6 = c_null_ptr; p7 = c_null_ptr; p8 = c_null_ptr
4363 p9 = c_null_ptr; p10 = c_null_ptr
4364 if (present(setup_s)) p1 = c_loc(setup_s)
4365 if (present(descriptor_s)) p2 = c_loc(descriptor_s)
4366 if (present(posterior_s)) p3 = c_loc(posterior_s)
4367 if (present(subset_s)) p4 = c_loc(subset_s)
4368 if (present(objective_s)) p5 = c_loc(objective_s)
4369 if (present(condition_s)) p6 = c_loc(condition_s)
4370 if (present(cache_s)) p7 = c_loc(cache_s)
4371 if (present(curvature_s)) p8 = c_loc(curvature_s)
4372 if (present(energy_s)) p9 = c_loc(energy_s)
4373 if (present(schedule_s)) p10 = c_loc(schedule_s)
4374 call c_gpr_train_phase_read_leaves(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10)
4375 end subroutine
4376
4377 !> "" for the native product, "scheme2:fp64[...]" / "scheme2:int8[...]"
4378 !> for a Scheme II engine, or the path of a product library.
4379 subroutine gpr_set_training_product(spec, stat, errmsg)
4380 character(len=*), intent(in) :: spec
4381 integer, intent(out), optional :: stat
4382 character(len=*), intent(inout), optional :: errmsg
4383 call report_status(c_gpr_set_training_product(to_c_string(spec)), &
4384 stat, errmsg)
4385 end subroutine
4386
4387 function gpr_training_product_configured() result(configured)
4388 logical :: configured
4389 configured = c_gpr_training_product_configured() /= 0
4390 end function
4391
4392 !> Check that an AOTInductor model package runs on this CPU.
4393 subroutine gpr_check_model_package(path, stat, errmsg)
4394 character(len=*), intent(in) :: path
4395 integer, intent(out), optional :: stat
4396 character(len=*), intent(inout), optional :: errmsg
4397 call report_status(c_gpr_check_model_package(to_c_string(path)), &
4398 stat, errmsg)
4399 end subroutine
4400
4401 ! ===================================================================
4402 ! Searches
4403 ! ===================================================================
4404
4405 !> NEB between R_initial and R_final with n_images intermediate images.
4406 !> config%mode selects standard, AIE or OIE without a surrogate. A GP
4407 !> mode runs when the coordinate length is three times an atom count,
4408 !> with every atom moving and the library GP settings. Any other length
4409 !> is refused; use gpr_neb_search_gp to pass atoms and a model. On
4410 !> success result holds the path.
4411 subroutine gpr_neb_search(oracle, R_initial, R_final, n_images, config, &
4412 result, stat, errmsg, user_data)
4413 procedure(gpr_oracle_interface) :: oracle
4414 real(c_double), intent(in) :: r_initial(:), r_final(:)
4415 integer, intent(in) :: n_images
4416 type(nebconfig), intent(in) :: config
4417 type(nebresult), intent(inout) :: result
4418 integer, intent(out), optional :: stat
4419 character(len=*), intent(inout), optional :: errmsg
4420 type(c_ptr), intent(in), optional :: user_data
4421 type(c_ptr) :: ud, handle
4422
4423 call result%release()
4424 if (size(r_final) /= size(r_initial)) then
4425 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4426 'gpr_neb_search: R_initial and R_final differ in size')
4427 return
4428 end if
4429 ud = c_null_ptr
4430 if (present(user_data)) ud = user_data
4431 handle = c_gpr_neb_search(c_funloc(oracle), ud, r_initial, r_final, &
4432 int(size(r_initial), c_int), int(n_images, c_int), config)
4433 call adopt_neb_result(handle, result, stat, errmsg)
4434 end subroutine
4435
4436 !> Local band (gpr_neb_search_local). config and local default to the
4437 !> library defaults. atoms, when present, is the full system and frozen
4438 !> atoms stay at R_initial; without it every coordinate moves. box is
4439 !> absent for an isolated system. A failure leaves the reason in
4440 !> gpr_last_error_message().
4441 subroutine gpr_neb_search_local(oracle, R_initial, R_final, n_images, &
4442 result, stat, errmsg, config, local, atoms, box, user_data)
4443 procedure(gpr_oracle_interface) :: oracle
4444 real(c_double), intent(in) :: r_initial(:), r_final(:)
4445 integer, intent(in) :: n_images
4446 type(nebresult), intent(inout) :: result
4447 integer, intent(out), optional :: stat
4448 character(len=*), intent(inout), optional :: errmsg
4449 type(nebconfig), intent(in), optional, target :: config
4450 type(localbandconfig), intent(in), optional, target :: local
4451 type(atomsconfig), intent(in), optional :: atoms
4452 real(c_double), intent(in), optional, target :: box(9)
4453 type(c_ptr), intent(in), optional :: user_data
4454 type(c_ptr) :: ud, handle, patoms, pbox, pconfig, plocal
4455
4456 call result%release()
4457 if (size(r_final) /= size(r_initial)) then
4458 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4459 'gpr_neb_search_local: R_initial and R_final differ in size')
4460 return
4461 end if
4462 ud = c_null_ptr
4463 if (present(user_data)) ud = user_data
4464 patoms = c_null_ptr
4465 if (present(atoms)) patoms = atoms%get_handle()
4466 pbox = c_null_ptr
4467 if (present(box)) pbox = c_loc(box)
4468 pconfig = c_null_ptr
4469 if (present(config)) pconfig = c_loc(config)
4470 plocal = c_null_ptr
4471 if (present(local)) plocal = c_loc(local)
4472 handle = c_gpr_neb_search_local(c_funloc(oracle), ud, patoms, pbox, &
4473 r_initial, r_final, int(size(r_initial), c_int), &
4474 int(n_images, c_int), pconfig, plocal)
4475 call adopt_neb_result(handle, result, stat, errmsg)
4476 end subroutine
4477
4478 !> gpr_neb_search_local over a force callback. atomic_nrs names the
4479 !> atoms when atoms is absent.
4480 subroutine gpr_neb_search_local_potential(force, atomic_nrs, R_initial, &
4481 R_final, n_images, result, stat, errmsg, config, local, atoms, box, &
4482 user_data)
4483 procedure(gpr_force_interface) :: force
4484 integer, intent(in) :: atomic_nrs(:)
4485 real(c_double), intent(in) :: r_initial(:), r_final(:)
4486 integer, intent(in) :: n_images
4487 type(nebresult), intent(inout) :: result
4488 integer, intent(out), optional :: stat
4489 character(len=*), intent(inout), optional :: errmsg
4490 type(nebconfig), intent(in), optional, target :: config
4491 type(localbandconfig), intent(in), optional, target :: local
4492 type(atomsconfig), intent(in), optional :: atoms
4493 real(c_double), intent(in), optional, target :: box(9)
4494 type(c_ptr), intent(in), optional :: user_data
4495 type(c_ptr) :: ud, pot, handle, patoms, pbox, pconfig, plocal, pz
4496 integer(c_int), allocatable, target :: z(:)
4497
4498 call result%release()
4499 if (size(r_final) /= size(r_initial)) then
4500 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4501 'gpr_neb_search_local_potential: R_initial and R_final differ ' // &
4502 'in size')
4503 return
4504 end if
4505 if (.not. present(atoms) .or. size(atomic_nrs) > 0) then
4506 if (modulo(size(r_initial), 3) /= 0 .or. &
4507 size(atomic_nrs) /= size(r_initial) / 3) then
4508 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4509 'gpr_neb_search_local_potential: atomic_nrs must name every atom')
4510 return
4511 end if
4512 end if
4513 ud = c_null_ptr
4514 if (present(user_data)) ud = user_data
4515 pot = c_gpr_potential_from_force(c_funloc(force), ud)
4516 if (.not. c_associated(pot)) then
4517 call report_status(failed_status(), stat, errmsg)
4518 return
4519 end if
4520 allocate(z(size(atomic_nrs)))
4521 z = int(atomic_nrs, c_int)
4522 pz = c_null_ptr
4523 if (size(z) > 0) pz = c_loc(z)
4524 patoms = c_null_ptr
4525 if (present(atoms)) patoms = atoms%get_handle()
4526 pbox = c_null_ptr
4527 if (present(box)) pbox = c_loc(box)
4528 pconfig = c_null_ptr
4529 if (present(config)) pconfig = c_loc(config)
4530 plocal = c_null_ptr
4531 if (present(local)) plocal = c_loc(local)
4532 handle = c_gpr_neb_search_local_potential(pot, pz, pbox, patoms, &
4533 r_initial, r_final, int(size(r_initial), c_int), &
4534 int(n_images, c_int), pconfig, plocal)
4535 call c_gpr_potential_destroy(pot)
4536 call adopt_neb_result(handle, result, stat, errmsg)
4537 end subroutine
4538
4539 !> Ask the next band search on this thread for the index certificate.
4540 !> step 0 keeps the library stencil step. On the periodic band searches a
4541 !> nonzero step takes precedence over LocalBandConfig%certificate_step.
4542 subroutine gpr_neb_request_index_certificate(enable, step, stat, errmsg)
4543 logical, intent(in) :: enable
4544 real(c_double), intent(in) :: step
4545 integer, intent(out), optional :: stat
4546 character(len=*), intent(inout), optional :: errmsg
4547 integer(c_int) :: flag
4548 flag = 0
4549 if (enable) flag = 1
4550 call report_status(c_gpr_neb_request_index_certificate(flag, step), &
4551 stat, errmsg)
4552 end subroutine
4553
4554 !> Select SIDPP (true) or classic IDPP (false) for the next NEB search
4555 !> on this thread. SIDPP is the library default. The periodic band
4556 !> searches take PeriodicBandConfig%initial alone, so the request has no
4557 !> effect on them; they still consume it.
4558 subroutine gpr_neb_request_sidpp(enable, stat, errmsg)
4559 logical, intent(in) :: enable
4560 integer, intent(out), optional :: stat
4561 character(len=*), intent(inout), optional :: errmsg
4562 integer(c_int) :: flag
4563 flag = 0
4564 if (enable) flag = 1
4565 call report_status(c_gpr_neb_request_sidpp(flag), stat, errmsg)
4566 end subroutine
4567
4568 !> Stencil of the next non-local NEB search on this thread.
4569 !> mode 0 measures every coordinate; mode 1 measures the vibrational
4570 !> directions. A local or periodic band takes LocalBandConfig instead.
4571 subroutine gpr_neb_request_vibrational_stencil(mode, stat, errmsg)
4572 integer, intent(in) :: mode
4573 integer, intent(out), optional :: stat
4574 character(len=*), intent(inout), optional :: errmsg
4575 call report_status(c_gpr_neb_request_vibrational_stencil(int(mode, c_int)), &
4576 stat, errmsg)
4577 end subroutine
4578
4579 function gpr_local_band_config_defaults() result(config)
4580 type(localbandconfig) :: config
4581 config = c_gpr_local_band_config_defaults()
4582 end function
4583
4584 function gpr_periodic_band_config_defaults() result(config)
4585 type(periodicbandconfig) :: config
4586 config = c_gpr_periodic_band_config_defaults()
4587 end function
4588
4589 !> Periodic local band (gpr_neb_search_periodic), the binding of
4590 !> GPLocalBand. periodic and local default to the library defaults.
4591 !> atoms and box are as for gpr_neb_search_local. The search does not
4592 !> certify; gpr_neb_request_index_certificate, called first, does.
4593 subroutine gpr_neb_search_periodic(oracle, R_initial, R_final, n_images, &
4594 result, stat, errmsg, periodic, local, atoms, box, user_data)
4595 procedure(gpr_oracle_interface) :: oracle
4596 real(c_double), intent(in) :: r_initial(:), r_final(:)
4597 integer, intent(in) :: n_images
4598 type(nebresult), intent(inout) :: result
4599 integer, intent(out), optional :: stat
4600 character(len=*), intent(inout), optional :: errmsg
4601 type(periodicbandconfig), intent(in), optional, target :: periodic
4602 type(localbandconfig), intent(in), optional, target :: local
4603 type(atomsconfig), intent(in), optional :: atoms
4604 real(c_double), intent(in), optional, target :: box(9)
4605 type(c_ptr), intent(in), optional :: user_data
4606 type(c_ptr) :: ud, handle, patoms, pbox, pperiodic, plocal
4607
4608 call result%release()
4609 if (size(r_final) /= size(r_initial)) then
4610 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4611 'gpr_neb_search_periodic: R_initial and R_final differ in size')
4612 return
4613 end if
4614 ud = c_null_ptr
4615 if (present(user_data)) ud = user_data
4616 patoms = c_null_ptr
4617 if (present(atoms)) patoms = atoms%get_handle()
4618 pbox = c_null_ptr
4619 if (present(box)) pbox = c_loc(box)
4620 pperiodic = c_null_ptr
4621 if (present(periodic)) pperiodic = c_loc(periodic)
4622 plocal = c_null_ptr
4623 if (present(local)) plocal = c_loc(local)
4624 handle = c_gpr_neb_search_periodic(c_funloc(oracle), ud, patoms, pbox, &
4625 r_initial, r_final, int(size(r_initial), c_int), &
4626 int(n_images, c_int), pperiodic, plocal)
4627 call adopt_neb_result(handle, result, stat, errmsg)
4628 end subroutine
4629
4630 !> gpr_neb_search_periodic over a force callback.
4631 subroutine gpr_neb_search_periodic_potential(force, atomic_nrs, R_initial, &
4632 R_final, n_images, result, stat, errmsg, periodic, local, atoms, box, &
4633 user_data)
4634 procedure(gpr_force_interface) :: force
4635 integer, intent(in) :: atomic_nrs(:)
4636 real(c_double), intent(in) :: r_initial(:), r_final(:)
4637 integer, intent(in) :: n_images
4638 type(nebresult), intent(inout) :: result
4639 integer, intent(out), optional :: stat
4640 character(len=*), intent(inout), optional :: errmsg
4641 type(periodicbandconfig), intent(in), optional, target :: periodic
4642 type(localbandconfig), intent(in), optional, target :: local
4643 type(atomsconfig), intent(in), optional :: atoms
4644 real(c_double), intent(in), optional, target :: box(9)
4645 type(c_ptr), intent(in), optional :: user_data
4646 type(c_ptr) :: ud, pot, handle, patoms, pbox, pperiodic, plocal, pz
4647 integer(c_int), allocatable, target :: z(:)
4648
4649 call result%release()
4650 if (size(r_final) /= size(r_initial)) then
4651 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4652 'gpr_neb_search_periodic_potential: R_initial and R_final differ ' // &
4653 'in size')
4654 return
4655 end if
4656 if (.not. present(atoms) .or. size(atomic_nrs) > 0) then
4657 if (modulo(size(r_initial), 3) /= 0 .or. &
4658 size(atomic_nrs) /= size(r_initial) / 3) then
4659 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4660 'gpr_neb_search_periodic_potential: atomic_nrs must name every atom')
4661 return
4662 end if
4663 end if
4664 ud = c_null_ptr
4665 if (present(user_data)) ud = user_data
4666 pot = c_gpr_potential_from_force(c_funloc(force), ud)
4667 if (.not. c_associated(pot)) then
4668 call report_status(failed_status(), stat, errmsg)
4669 return
4670 end if
4671 allocate(z(size(atomic_nrs)))
4672 z = int(atomic_nrs, c_int)
4673 pz = c_null_ptr
4674 if (size(z) > 0) pz = c_loc(z)
4675 patoms = c_null_ptr
4676 if (present(atoms)) patoms = atoms%get_handle()
4677 pbox = c_null_ptr
4678 if (present(box)) pbox = c_loc(box)
4679 pperiodic = c_null_ptr
4680 if (present(periodic)) pperiodic = c_loc(periodic)
4681 plocal = c_null_ptr
4682 if (present(local)) plocal = c_loc(local)
4683 handle = c_gpr_neb_search_periodic_potential(pot, pz, pbox, patoms, &
4684 r_initial, r_final, int(size(r_initial), c_int), &
4685 int(n_images, c_int), pperiodic, plocal)
4686 call c_gpr_potential_destroy(pot)
4687 call adopt_neb_result(handle, result, stat, errmsg)
4688 end subroutine
4689
4690 !> Take ownership of a NEB result handle; a null handle reports the
4691 !> status of the failed call.
4692 subroutine adopt_neb_result(handle, result, stat, errmsg)
4693 type(c_ptr), intent(in) :: handle
4694 type(nebresult), intent(inout) :: result
4695 integer, intent(out), optional :: stat
4696 character(len=*), intent(inout), optional :: errmsg
4697 integer(c_int) :: rc
4698
4699 if (c_associated(handle)) then
4700 result%handle = handle
4701 allocate(result%references, source=1)
4702 rc = gpr_success
4703 else
4704 rc = failed_status()
4705 end if
4706 call report_status(rc, stat, errmsg)
4707 end subroutine
4708
4709 !> NEB without a GP over a force callback of n_atoms = size(atomic_nrs)
4710 !> atoms (R_initial and R_final have 3*n_atoms values). box (3x3,
4711 !> row-major) defaults to zeros, an isolated system.
4712 subroutine gpr_neb_search_potential(force, atomic_nrs, R_initial, R_final, &
4713 n_images, config, result, stat, errmsg, box, user_data)
4714 procedure(gpr_force_interface) :: force
4715 integer, intent(in) :: atomic_nrs(:)
4716 real(c_double), intent(in) :: r_initial(:), r_final(:)
4717 integer, intent(in) :: n_images
4718 type(nebconfig), intent(in) :: config
4719 type(nebresult), intent(inout) :: result
4720 integer, intent(out), optional :: stat
4721 character(len=*), intent(inout), optional :: errmsg
4722 real(c_double), intent(in), optional :: box(9)
4723 type(c_ptr), intent(in), optional :: user_data
4724 real(c_double) :: cell(9)
4725 type(c_ptr) :: ud, pot, handle
4726
4727 call result%release()
4728 if (size(r_final) /= size(r_initial) .or. &
4729 size(r_initial) /= 3 * size(atomic_nrs)) then
4730 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4731 'gpr_neb_search_potential: R_initial, R_final and atomic_nrs ' // &
4732 'differ in size')
4733 return
4734 end if
4735 cell = 0.0d0
4736 if (present(box)) cell = box
4737 ud = c_null_ptr
4738 if (present(user_data)) ud = user_data
4739 pot = c_gpr_potential_from_force(c_funloc(force), ud)
4740 if (.not. c_associated(pot)) then
4741 call report_status(failed_status(), stat, errmsg)
4742 return
4743 end if
4744 handle = c_gpr_neb_search_potential(pot, int(atomic_nrs, c_int), cell, &
4745 r_initial, r_final, int(size(r_initial), c_int), &
4746 int(n_images, c_int), config)
4747 call c_gpr_potential_destroy(pot)
4748 call adopt_neb_result(handle, result, stat, errmsg)
4749 end subroutine
4750
4751 !> GP-accelerated NEB (gpr_neb_search_gp): R_initial and R_final hold
4752 !> every atom of atoms (3*n_atoms values); frozen atoms stay put and the
4753 !> oracle sees full-length arrays. config%mode must be GPR_NEB_GP_OIE or
4754 !> GPR_NEB_GP_AIE. model defaults to the gprn NEB GP settings.
4755 subroutine gpr_neb_search_gp(oracle, atoms, R_initial, R_final, n_images, &
4756 config, result, stat, errmsg, model, user_data)
4757 procedure(gpr_oracle_interface) :: oracle
4758 type(atomsconfig), intent(in) :: atoms
4759 real(c_double), intent(in) :: r_initial(:), r_final(:)
4760 integer, intent(in) :: n_images
4761 type(nebconfig), intent(in) :: config
4762 type(nebresult), intent(inout) :: result
4763 integer, intent(out), optional :: stat
4764 character(len=*), intent(inout), optional :: errmsg
4765 type(modelconfig), intent(in), optional, target :: model
4766 type(c_ptr), intent(in), optional :: user_data
4767 type(c_ptr) :: ud, pmodel, handle
4768
4769 call result%release()
4770 if (size(r_final) /= size(r_initial)) then
4771 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4772 'gpr_neb_search_gp: R_initial and R_final differ in size')
4773 return
4774 end if
4775 ud = c_null_ptr
4776 if (present(user_data)) ud = user_data
4777 pmodel = c_null_ptr
4778 if (present(model)) pmodel = c_loc(model)
4779 handle = c_gpr_neb_search_gp(c_funloc(oracle), ud, atoms%get_handle(), &
4780 pmodel, r_initial, r_final, int(size(r_initial), c_int), &
4781 int(n_images, c_int), config)
4782 call adopt_neb_result(handle, result, stat, errmsg)
4783 end subroutine
4784
4785 !> gpr_neb_search_gp over a force callback. The callback receives the
4786 !> atomic numbers of atoms; box (3x3, row-major) is absent for an
4787 !> isolated system.
4788 subroutine gpr_neb_search_gp_potential(force, atoms, R_initial, R_final, &
4789 n_images, config, result, stat, errmsg, model, box, user_data)
4790 procedure(gpr_force_interface) :: force
4791 type(atomsconfig), intent(in) :: atoms
4792 real(c_double), intent(in) :: r_initial(:), r_final(:)
4793 integer, intent(in) :: n_images
4794 type(nebconfig), intent(in) :: config
4795 type(nebresult), intent(inout) :: result
4796 integer, intent(out), optional :: stat
4797 character(len=*), intent(inout), optional :: errmsg
4798 type(modelconfig), intent(in), optional, target :: model
4799 real(c_double), intent(in), optional, target :: box(9)
4800 type(c_ptr), intent(in), optional :: user_data
4801 type(c_ptr) :: ud, pmodel, pbox, pot, handle
4802
4803 call result%release()
4804 if (size(r_final) /= size(r_initial)) then
4805 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4806 'gpr_neb_search_gp_potential: R_initial and R_final differ in size')
4807 return
4808 end if
4809 ud = c_null_ptr
4810 if (present(user_data)) ud = user_data
4811 pmodel = c_null_ptr
4812 if (present(model)) pmodel = c_loc(model)
4813 pbox = c_null_ptr
4814 if (present(box)) pbox = c_loc(box)
4815 pot = c_gpr_potential_from_force(c_funloc(force), ud)
4816 if (.not. c_associated(pot)) then
4817 call report_status(failed_status(), stat, errmsg)
4818 return
4819 end if
4820 handle = c_gpr_neb_search_gp_potential(pot, atoms%get_handle(), pbox, &
4821 pmodel, r_initial, r_final, int(size(r_initial), c_int), &
4822 int(n_images, c_int), config)
4823 call c_gpr_potential_destroy(pot)
4824 call adopt_neb_result(handle, result, stat, errmsg)
4825 end subroutine
4826
4827 !> GP-NEB with dimer bursts on the climbing image (gpr_ocineb_search).
4828 !> Arguments as gpr_neb_search_gp; oci defaults to OCINEBConfig().
4829 subroutine gpr_ocineb_search(oracle, atoms, R_initial, R_final, n_images, &
4830 config, result, stat, errmsg, oci, model, user_data)
4831 procedure(gpr_oracle_interface) :: oracle
4832 type(atomsconfig), intent(in) :: atoms
4833 real(c_double), intent(in) :: r_initial(:), r_final(:)
4834 integer, intent(in) :: n_images
4835 type(nebconfig), intent(in) :: config
4836 type(nebresult), intent(inout) :: result
4837 integer, intent(out), optional :: stat
4838 character(len=*), intent(inout), optional :: errmsg
4839 type(ocinebconfig), intent(in), optional, target :: oci
4840 type(modelconfig), intent(in), optional, target :: model
4841 type(c_ptr), intent(in), optional :: user_data
4842 type(c_ptr) :: ud, pmodel, poci, handle
4843
4844 call result%release()
4845 if (size(r_final) /= size(r_initial)) then
4846 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4847 'gpr_ocineb_search: R_initial and R_final differ in size')
4848 return
4849 end if
4850 ud = c_null_ptr
4851 if (present(user_data)) ud = user_data
4852 pmodel = c_null_ptr
4853 if (present(model)) pmodel = c_loc(model)
4854 poci = c_null_ptr
4855 if (present(oci)) poci = c_loc(oci)
4856 handle = c_gpr_ocineb_search(c_funloc(oracle), ud, atoms%get_handle(), &
4857 pmodel, r_initial, r_final, int(size(r_initial), c_int), &
4858 int(n_images, c_int), config, poci)
4859 call adopt_neb_result(handle, result, stat, errmsg)
4860 end subroutine
4861
4862 !> GP-accelerated dimer search from R_init along orient_init (both
4863 !> 3*n_atoms). report%max_oracle_calls is read as a budget; the rest of
4864 !> report is filled. A search that stops unconverged succeeds with
4865 !> report%converged == 0.
4866 subroutine gpr_dimer_search(force, atoms, R_init, orient_init, config, &
4867 R_saddle, E_saddle, report, stat, errmsg, orient_out, user_data)
4868 procedure(gpr_force_interface) :: force
4869 type(atomsconfig), intent(in) :: atoms
4870 real(c_double), intent(in) :: r_init(:), orient_init(:)
4871 type(dimerconfig), intent(in) :: config
4872 real(c_double), intent(inout) :: r_saddle(:)
4873 real(c_double), intent(inout) :: e_saddle
4874 type(dimerreport), intent(inout) :: report
4875 integer, intent(out), optional :: stat
4876 character(len=*), intent(inout), optional :: errmsg
4877 real(c_double), intent(inout), optional, target, contiguous :: &
4878 orient_out(:)
4879 type(c_ptr), intent(in), optional :: user_data
4880 type(c_ptr) :: ud, pot, orient
4881 integer(c_int) :: rc
4882
4883 if (size(orient_init) /= size(r_init) .or. &
4884 size(r_saddle) /= size(r_init)) then
4885 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4886 'gpr_dimer_search: R_init, orient_init and R_saddle differ in size')
4887 return
4888 end if
4889 if (present(orient_out)) then
4890 if (size(orient_out) /= size(r_init)) then
4891 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4892 'gpr_dimer_search: orient_out differs in size from R_init')
4893 return
4894 end if
4895 orient = c_loc(orient_out)
4896 else
4897 orient = c_null_ptr
4898 end if
4899 ud = c_null_ptr
4900 if (present(user_data)) ud = user_data
4901 pot = c_gpr_potential_from_force(c_funloc(force), ud)
4902 if (.not. c_associated(pot)) then
4903 call report_status(gpr_err_internal, stat, errmsg)
4904 return
4905 end if
4906 report%struct_size = c_sizeof(report)
4907 rc = c_gpr_dimer_search_report(pot, atoms%get_handle(), r_init, &
4908 orient_init, config, c_null_ptr, c_null_ptr, c_null_ptr, 0_c_int, &
4909 r_saddle, e_saddle, orient, report)
4910 call c_gpr_potential_destroy(pot)
4911 call report_status(rc, stat, errmsg)
4912 end subroutine
4913
4914 !> GP-accelerated dimer search via gpr_dimer_search (without DimerReport).
4915 subroutine gpr_dimer_search_raw(force, atoms, R_init, orient_init, config, &
4916 R_saddle, E_saddle, stat, errmsg, orient_out, curvature, n_force_calls, &
4917 n_gp_calls, user_data)
4918 procedure(gpr_force_interface) :: force
4919 type(atomsconfig), intent(in) :: atoms
4920 real(c_double), intent(in) :: r_init(:), orient_init(:)
4921 type(dimerconfig), intent(in) :: config
4922 real(c_double), intent(inout) :: r_saddle(:)
4923 real(c_double), intent(inout) :: e_saddle
4924 integer, intent(out), optional :: stat
4925 character(len=*), intent(inout), optional :: errmsg
4926 real(c_double), intent(inout), optional, target, contiguous :: &
4927 orient_out(:)
4928 real(c_double), intent(out), optional, target :: curvature
4929 integer, intent(out), optional :: n_force_calls, n_gp_calls
4930 type(c_ptr), intent(in), optional :: user_data
4931 type(c_ptr) :: ud, porient, pcurv, pfc, pgc
4932 integer(c_int), target :: fc_c, gc_c
4933 integer(c_int) :: rc
4934
4935 if (size(orient_init) /= size(r_init) .or. &
4936 size(r_saddle) /= size(r_init)) then
4937 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4938 'gpr_dimer_search_raw: R_init, orient_init and R_saddle differ')
4939 return
4940 end if
4941 porient = c_null_ptr
4942 if (present(orient_out)) then
4943 if (size(orient_out) /= size(r_init)) then
4944 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4945 'gpr_dimer_search_raw: orient_out differs in size from R_init')
4946 return
4947 end if
4948 porient = c_loc(orient_out)
4949 end if
4950 ud = c_null_ptr
4951 if (present(user_data)) ud = user_data
4952 pcurv = c_null_ptr
4953 if (present(curvature)) pcurv = c_loc(curvature)
4954 pfc = c_null_ptr
4955 if (present(n_force_calls)) pfc = c_loc(fc_c)
4956 pgc = c_null_ptr
4957 if (present(n_gp_calls)) pgc = c_loc(gc_c)
4958 rc = c_gpr_dimer_search(c_funloc(force), ud, atoms%get_handle(), r_init, &
4959 orient_init, config, c_null_ptr, c_null_ptr, c_null_ptr, 0_c_int, &
4960 r_saddle, e_saddle, porient, pcurv, pfc, pgc)
4961 if (present(n_force_calls) .and. rc == gpr_success) &
4962 n_force_calls = int(fc_c)
4963 if (present(n_gp_calls) .and. rc == gpr_success) &
4964 n_gp_calls = int(gc_c)
4965 call report_status(rc, stat, errmsg)
4966 end subroutine
4967
4968 !> GP-accelerated dimer search over a PotentialHandle.
4969 subroutine gpr_dimer_search_potential(pot, atoms, R_init, orient_init, &
4970 config, R_saddle, E_saddle, report, stat, errmsg, orient_out)
4971 type(potentialhandle), intent(in) :: pot
4972 type(atomsconfig), intent(in) :: atoms
4973 real(c_double), intent(in) :: r_init(:), orient_init(:)
4974 type(dimerconfig), intent(in) :: config
4975 real(c_double), intent(inout) :: r_saddle(:)
4976 real(c_double), intent(inout) :: e_saddle
4977 type(dimerreport), intent(inout), optional :: report
4978 integer, intent(out), optional :: stat
4979 character(len=*), intent(inout), optional :: errmsg
4980 real(c_double), intent(inout), optional, target, contiguous :: &
4981 orient_out(:)
4982 type(c_ptr) :: porient
4983 integer(c_int) :: rc
4984
4985 if (size(orient_init) /= size(r_init) .or. &
4986 size(r_saddle) /= size(r_init)) then
4987 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4988 'gpr_dimer_search_potential: R_init, orient_init and R_saddle differ')
4989 return
4990 end if
4991 porient = c_null_ptr
4992 if (present(orient_out)) then
4993 if (size(orient_out) /= size(r_init)) then
4994 call report_status(gpr_err_invalid_arg, stat, errmsg, &
4995 'gpr_dimer_search_potential: orient_out differs in size')
4996 return
4997 end if
4998 porient = c_loc(orient_out)
4999 end if
5000 if (present(report)) then
5001 report%struct_size = c_sizeof(report)
5002 rc = c_gpr_dimer_search_report(pot%get_handle(), atoms%get_handle(), &
5003 r_init, orient_init, config, c_null_ptr, c_null_ptr, c_null_ptr, &
5004 0_c_int, r_saddle, e_saddle, porient, report)
5005 else
5006 rc = c_gpr_dimer_search_potential(pot%get_handle(), atoms%get_handle(), &
5007 r_init, orient_init, config, c_null_ptr, c_null_ptr, c_null_ptr, &
5008 0_c_int, r_saddle, e_saddle, porient, c_null_ptr, c_null_ptr, &
5009 c_null_ptr)
5010 end if
5011 call report_status(rc, stat, errmsg)
5012 end subroutine
5013
5014 !> Set the inner surrogate L-BFGS step cap (default 200, must be >= 1)
5015 !> for the next gpr_minimize call on this thread. The request is
5016 !> consumed by that call, including when validation rejects it.
5017 subroutine gpr_minimize_request_max_inner_steps(max_inner_steps, stat, &
5018 errmsg)
5019 integer, intent(in) :: max_inner_steps
5020 integer, intent(out), optional :: stat
5021 character(len=*), intent(inout), optional :: errmsg
5022 call report_status( &
5023 c_gpr_minimize_request_max_inner_steps(int(max_inner_steps, c_int)), &
5024 stat, errmsg)
5025 end subroutine
5026
5027 !> GP-accelerated minimization from R_init. R_final, E_final and G_final
5028 !> are always an exact oracle evaluation at R_final (never a surrogate
5029 !> prediction or an averaged near-coincident row); converged is true when
5030 !> its gradient norm is below conv_tol. config%max_iter bounds outer
5031 !> surrogate-relaxation cycles (up to 200 inner steps each by default,
5032 !> or the cap set by gpr_minimize_request_max_inner_steps). The first
5033 !> failed oracle evaluation ends the run with GPR_ERR_ORACLE.
5034 subroutine gpr_minimize(oracle, R_init, atoms, config, R_final, E_final, &
5035 converged, n_oracle_calls, stat, errmsg, G_final, user_data)
5036 procedure(gpr_oracle_interface) :: oracle
5037 real(c_double), intent(in) :: r_init(:)
5038 type(atomsconfig), intent(in) :: atoms
5039 type(minimizeconfig), intent(in) :: config
5040 real(c_double), intent(inout) :: r_final(:)
5041 real(c_double), intent(inout) :: e_final
5042 logical, intent(out) :: converged
5043 integer, intent(out) :: n_oracle_calls
5044 integer, intent(out), optional :: stat
5045 character(len=*), intent(inout), optional :: errmsg
5046 real(c_double), intent(inout), optional :: g_final(:)
5047 type(c_ptr), intent(in), optional :: user_data
5048 real(c_double), allocatable :: gradient(:)
5049 type(c_ptr) :: ud
5050 integer(c_int) :: rc, conv, calls
5051
5052 converged = .false.
5053 n_oracle_calls = 0
5054 if (size(r_final) /= size(r_init)) then
5055 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5056 'gpr_minimize: R_init and R_final differ in size')
5057 return
5058 end if
5059 allocate(gradient(size(r_init)))
5060 ud = c_null_ptr
5061 if (present(user_data)) ud = user_data
5062 conv = 0
5063 calls = 0
5064 rc = c_gpr_minimize(c_funloc(oracle), ud, r_init, &
5065 int(size(r_init), c_int), atoms%get_handle(), config, r_final, &
5066 e_final, gradient, conv, calls)
5067 converged = conv /= 0
5068 n_oracle_calls = int(calls)
5069 if (present(g_final) .and. rc == gpr_success) g_final = gradient
5070 call report_status(rc, stat, errmsg)
5071 end subroutine
5072
5073 ! =====================================================================
5074 ! Posterior-mean derivatives and harmonic prefactors (ABI 1.20)
5075 ! =====================================================================
5076
5077 !> gpr_derivative_options_defaults() with struct_size set.
5078 function gpr_derivative_options_defaults() result(options)
5079 type(derivativeoptions) :: options
5080 options = c_gpr_derivative_options_defaults()
5081 options%struct_size = c_sizeof(options)
5082 end function
5083
5084 !> gpr_htst_options_defaults() with struct_size set.
5085 function gpr_htst_options_defaults() result(options)
5086 type(htstoptions) :: options
5087 options = c_gpr_htst_options_defaults()
5088 options%struct_size = c_sizeof(options)
5089 end function
5090
5091 function derivative_options_or_defaults(options) result(o)
5092 type(derivativeoptions), intent(in), optional :: options
5093 type(derivativeoptions) :: o
5094 if (present(options)) then
5095 o = options
5096 else
5097 o = c_gpr_derivative_options_defaults()
5098 end if
5099 o%struct_size = c_sizeof(o)
5100 end function
5101
5102 function htst_options_or_defaults(options) result(o)
5103 type(htstoptions), intent(in), optional :: options
5104 type(htstoptions) :: o
5105 if (present(options)) then
5106 o = options
5107 else
5108 o = c_gpr_htst_options_defaults()
5109 end if
5110 o%struct_size = c_sizeof(o)
5111 end function
5112
5113 subroutine finish_derivative_report(local, rc, report, ierr)
5114 type(derivativereport), intent(in) :: local
5115 integer(c_int), intent(in) :: rc
5116 type(derivativereport), intent(inout), optional :: report
5117 integer, intent(out), optional :: ierr
5118 ! The C call writes the report only on success and out-of-support.
5119 if (present(report)) then
5120 if (rc == gpr_success .or. rc == gpr_err_out_of_support) report = local
5121 end if
5122 if (present(ierr)) ierr = int(rc)
5123 end subroutine
5124
5125 !> Posterior-mean Hessians at n_points contiguous points: H_out holds
5126 !> n_points row-major n_coords x n_coords blocks. residuals (6 per
5127 !> point) receives the rigid-generator norms ||H g_k|| of the raw
5128 !> Hessian.
5129 subroutine gpmodel_mean_hessian_batch(self, R, n_points, n_coords, H_out, &
5130 options, residuals, report, ierr)
5131 class(gpmodel), intent(inout) :: self
5132 real(c_double), intent(in), contiguous :: r(:)
5133 integer, intent(in) :: n_points, n_coords
5134 real(c_double), contiguous :: h_out(:)
5135 type(derivativeoptions), intent(in), optional :: options
5136 real(c_double), intent(inout), contiguous, optional, target :: &
5137 residuals(:)
5138 type(derivativereport), intent(inout), optional :: report
5139 integer, intent(out), optional :: ierr
5140 type(derivativereport) :: local
5141 type(c_ptr) :: rptr
5142 integer(c_size_t) :: rlen
5143 integer(c_int) :: rc
5144
5145 local%struct_size = c_sizeof(local)
5146 rptr = c_null_ptr
5147 rlen = 0
5148 if (present(residuals)) then
5149 rptr = c_loc(residuals)
5150 rlen = size(residuals, kind=c_size_t)
5151 end if
5152 rc = c_gpr_model_mean_hessian_batch_checked(self%handle, &
5153 derivative_options_or_defaults(options), r, &
5154 size(r, kind=c_size_t), int(n_points, c_int), &
5155 int(n_coords, c_int), h_out, size(h_out, kind=c_size_t), rptr, &
5156 rlen, local)
5157 call finish_derivative_report(local, rc, report, ierr)
5158 end subroutine
5159
5160 !> Posterior-mean Hessian actions: V holds n_vectors vectors per point
5161 !> (point-major); Hv_out the same layout.
5162 subroutine gpmodel_mean_hessian_action_batch(self, R, n_points, n_coords, &
5163 V, n_vectors, Hv_out, options, report, ierr)
5164 class(gpmodel), intent(inout) :: self
5165 real(c_double), intent(in), contiguous :: r(:), v(:)
5166 integer, intent(in) :: n_points, n_coords, n_vectors
5167 real(c_double), contiguous :: hv_out(:)
5168 type(derivativeoptions), intent(in), optional :: options
5169 type(derivativereport), intent(inout), optional :: report
5170 integer, intent(out), optional :: ierr
5171 type(derivativereport) :: local
5172 integer(c_int) :: rc
5173
5174 local%struct_size = c_sizeof(local)
5175 rc = c_gpr_model_mean_hessian_action_batch_checked(self%handle, &
5176 derivative_options_or_defaults(options), r, &
5177 size(r, kind=c_size_t), int(n_points, c_int), &
5178 int(n_coords, c_int), v, size(v, kind=c_size_t), &
5179 int(n_vectors, c_int), hv_out, size(hv_out, kind=c_size_t), local)
5180 call finish_derivative_report(local, rc, report, ierr)
5181 end subroutine
5182
5183 !> Posterior covariance of v_i^T H w_j, one (n_left*n_right)^2 block per
5184 !> point. A probabilistic estimate, not a bound.
5185 subroutine gpmodel_hessian_bilinear_covariance(self, R, n_points, &
5186 n_coords, V, n_left, W, n_right, cov_out, options, report, ierr)
5187 class(gpmodel), intent(inout) :: self
5188 real(c_double), intent(in), contiguous :: r(:), v(:), w(:)
5189 integer, intent(in) :: n_points, n_coords, n_left, n_right
5190 real(c_double), contiguous :: cov_out(:)
5191 type(derivativeoptions), intent(in), optional :: options
5192 type(derivativereport), intent(inout), optional :: report
5193 integer, intent(out), optional :: ierr
5194 type(derivativereport) :: local
5195 integer(c_int) :: rc
5196
5197 local%struct_size = c_sizeof(local)
5198 rc = c_gpr_model_hessian_bilinear_covariance_checked(self%handle, &
5199 derivative_options_or_defaults(options), r, &
5200 size(r, kind=c_size_t), int(n_points, c_int), &
5201 int(n_coords, c_int), v, size(v, kind=c_size_t), &
5202 int(n_left, c_int), w, size(w, kind=c_size_t), &
5203 int(n_right, c_int), cov_out, size(cov_out, kind=c_size_t), local)
5204 call finish_derivative_report(local, rc, report, ierr)
5205 end subroutine
5206
5207 !> Posterior variance of tr(A dH) for one symmetric A per point.
5208 subroutine gpmodel_hessian_trace_variance(self, R, n_points, n_coords, A, &
5209 var_out, options, report, ierr)
5210 class(gpmodel), intent(inout) :: self
5211 real(c_double), intent(in), contiguous :: r(:), a(:)
5212 integer, intent(in) :: n_points, n_coords
5213 real(c_double), contiguous :: var_out(:)
5214 type(derivativeoptions), intent(in), optional :: options
5215 type(derivativereport), intent(inout), optional :: report
5216 integer, intent(out), optional :: ierr
5217 type(derivativereport) :: local
5218 integer(c_int) :: rc
5219
5220 local%struct_size = c_sizeof(local)
5221 rc = c_gpr_model_hessian_trace_variance_checked(self%handle, &
5222 derivative_options_or_defaults(options), r, &
5223 size(r, kind=c_size_t), int(n_points, c_int), &
5224 int(n_coords, c_int), a, size(a, kind=c_size_t), var_out, &
5225 size(var_out, kind=c_size_t), local)
5226 call finish_derivative_report(local, rc, report, ierr)
5227 end subroutine
5228
5229 !> Posterior variance of the energy and of each gradient component.
5230 subroutine gpmodel_posterior_variance_batch(self, R, n_points, n_coords, &
5231 var_E, var_G, options, report, ierr)
5232 class(gpmodel), intent(inout) :: self
5233 real(c_double), intent(in), contiguous :: r(:)
5234 integer, intent(in) :: n_points, n_coords
5235 real(c_double), contiguous :: var_e(:), var_g(:)
5236 type(derivativeoptions), intent(in), optional :: options
5237 type(derivativereport), intent(inout), optional :: report
5238 integer, intent(out), optional :: ierr
5239 type(derivativereport) :: local
5240 integer(c_int) :: rc
5241
5242 local%struct_size = c_sizeof(local)
5243 rc = c_gpr_model_posterior_variance_batch_checked(self%handle, &
5244 derivative_options_or_defaults(options), r, &
5245 size(r, kind=c_size_t), int(n_points, c_int), &
5246 int(n_coords, c_int), var_e, size(var_e, kind=c_size_t), var_g, &
5247 size(var_g, kind=c_size_t), local)
5248 call finish_derivative_report(local, rc, report, ierr)
5249 end subroutine
5250
5251 !> Condition on n_new oracle rows at fixed hyperparameters, then predict
5252 !> energy, gradient and their variances at n_query points. When H_new or
5253 !> hvp is supplied, the fixed-point Hessian is validated and used in
5254 !> subsequent Vineyard prefactor calculations at R_new.
5255 subroutine gpmodel_condition_fixed(self, R_new, E_new, G_new, n_new, &
5256 R_query, n_query, n_coords, E_out, G_out, var_E, var_G, options, &
5257 report, ierr, H_new, hvp, user_data)
5258 class(gpmodel), intent(inout) :: self
5259 real(c_double), intent(in), contiguous :: r_new(:), e_new(:), g_new(:)
5260 real(c_double), intent(in), contiguous :: r_query(:)
5261 integer, intent(in) :: n_new, n_query, n_coords
5262 real(c_double), contiguous :: e_out(:), g_out(:), var_e(:), var_g(:)
5263 type(derivativeoptions), intent(in), optional :: options
5264 type(derivativereport), intent(inout), optional :: report
5265 integer, intent(out), optional :: ierr
5266 real(c_double), intent(in), contiguous, optional, target :: h_new(:)
5267 procedure(gpr_hvp_interface), optional :: hvp
5268 type(c_ptr), intent(in), optional :: user_data
5269 type(derivativereport) :: local
5270 integer(c_int) :: rc
5271
5272 if (present(h_new) .or. present(hvp)) then
5273 call gpmodel_condition_fixed_hessian(self, r_new, e_new, g_new, n_new, &
5274 r_query, n_query, n_coords, e_out, g_out, var_e, var_g, h_new, &
5275 hvp, user_data, options, report, ierr)
5276 return
5277 end if
5278 local%struct_size = c_sizeof(local)
5279 rc = c_gpr_model_condition_fixed_checked(self%handle, &
5280 derivative_options_or_defaults(options), r_new, &
5281 size(r_new, kind=c_size_t), e_new, size(e_new, kind=c_size_t), &
5282 g_new, size(g_new, kind=c_size_t), int(n_new, c_int), r_query, &
5283 size(r_query, kind=c_size_t), int(n_query, c_int), &
5284 int(n_coords, c_int), e_out, size(e_out, kind=c_size_t), g_out, &
5285 size(g_out, kind=c_size_t), var_e, size(var_e, kind=c_size_t), &
5286 var_g, size(var_g, kind=c_size_t), local)
5287 call finish_derivative_report(local, rc, report, ierr)
5288 end subroutine
5289
5290 !> Condition on a fixed point with an optional exact Hessian H_new or
5291 !> Hessian-vector-product callback hvp, then predict at n_query points.
5292 subroutine gpmodel_condition_fixed_hessian(self, R_new, E_new, G_new, &
5293 n_new, R_query, n_query, n_coords, E_out, G_out, var_E, var_G, H_new, &
5294 hvp, user_data, options, report, ierr)
5295 class(gpmodel), intent(inout) :: self
5296 real(c_double), intent(in), contiguous :: r_new(:), e_new(:), g_new(:)
5297 real(c_double), intent(in), contiguous :: r_query(:)
5298 integer, intent(in) :: n_new, n_query, n_coords
5299 real(c_double), contiguous :: e_out(:), g_out(:), var_e(:), var_g(:)
5300 real(c_double), intent(in), contiguous, optional, target :: h_new(:)
5301 procedure(gpr_hvp_interface), optional :: hvp
5302 type(c_ptr), intent(in), optional :: user_data
5303 type(derivativeoptions), intent(in), optional :: options
5304 type(derivativereport), intent(inout), optional :: report
5305 integer, intent(out), optional :: ierr
5306 type(derivativereport) :: local
5307 type(c_ptr) :: h_ptr, uptr
5308 type(c_funptr) :: fptr
5309 integer(c_size_t) :: h_len
5310 integer(c_int) :: rc
5311
5312 h_ptr = c_null_ptr
5313 h_len = 0
5314 if (present(h_new)) then
5315 h_ptr = c_loc(h_new)
5316 h_len = size(h_new, kind=c_size_t)
5317 end if
5318 fptr = c_null_funptr
5319 if (present(hvp)) fptr = c_funloc(hvp)
5320 uptr = c_null_ptr
5321 if (present(user_data)) uptr = user_data
5322 local%struct_size = c_sizeof(local)
5323 rc = c_gpr_model_condition_fixed_hessian_checked(self%handle, &
5324 derivative_options_or_defaults(options), r_new, &
5325 size(r_new, kind=c_size_t), e_new, size(e_new, kind=c_size_t), &
5326 g_new, size(g_new, kind=c_size_t), int(n_new, c_int), h_ptr, &
5327 h_len, fptr, uptr, r_query, size(r_query, kind=c_size_t), &
5328 int(n_query, c_int), int(n_coords, c_int), e_out, &
5329 size(e_out, kind=c_size_t), g_out, size(g_out, kind=c_size_t), &
5330 var_e, size(var_e, kind=c_size_t), var_g, &
5331 size(var_g, kind=c_size_t), local)
5332 call finish_derivative_report(local, rc, report, ierr)
5333 end subroutine
5334
5335 subroutine htst_output_pointers(frequencies, measured, fptr, flen, mptr, &
5336 mlen)
5337 real(c_double), intent(inout), contiguous, optional, target :: &
5338 frequencies(:)
5339 integer(c_int), intent(inout), contiguous, optional, target :: &
5340 measured(:)
5341 type(c_ptr), intent(out) :: fptr, mptr
5342 integer(c_size_t), intent(out) :: flen, mlen
5343 fptr = c_null_ptr
5344 mptr = c_null_ptr
5345 flen = 0
5346 mlen = 0
5347 if (present(frequencies)) then
5348 fptr = c_loc(frequencies)
5349 flen = size(frequencies, kind=c_size_t)
5350 end if
5351 if (present(measured)) then
5352 mptr = c_loc(measured)
5353 mlen = size(measured, kind=c_size_t)
5354 end if
5355 end subroutine
5356
5357 !> The half of a caller's row-major Hessian H at x. masses holds one
5358 !> value per moving atom; absent means unit masses.
5359 subroutine gpr_htst_half_from_hessian(H, x, kind, half, options, masses, &
5360 frequencies, stat, errmsg)
5361 real(c_double), intent(in), contiguous :: h(:), x(:)
5362 integer, intent(in) :: kind
5363 type(htsthalf), intent(inout) :: half
5364 type(htstoptions), intent(in), optional :: options
5365 real(c_double), intent(in), contiguous, optional, target :: masses(:)
5366 real(c_double), intent(inout), contiguous, optional, target :: &
5367 frequencies(:)
5368 integer, intent(out), optional :: stat
5369 character(len=*), intent(inout), optional :: errmsg
5370 type(c_ptr) :: mass_ptr, fptr, mptr
5371 integer(c_size_t) :: mass_len, flen, mlen
5372 integer(c_int) :: n_masses
5373
5374 mass_ptr = c_null_ptr
5375 mass_len = 0
5376 n_masses = 0
5377 if (present(masses)) then
5378 mass_ptr = c_loc(masses)
5379 mass_len = size(masses, kind=c_size_t)
5380 n_masses = int(size(masses), c_int)
5381 end if
5382 call htst_output_pointers(frequencies=frequencies, fptr=fptr, &
5383 flen=flen, mptr=mptr, mlen=mlen)
5384 half%struct_size = c_sizeof(half)
5385 call report_status(c_gpr_htst_half_from_hessian_checked( &
5386 htst_options_or_defaults(options), mass_ptr, mass_len, n_masses, &
5387 h, size(h, kind=c_size_t), x, size(x, kind=c_size_t), &
5388 int(size(x), c_int), int(kind, c_int), fptr, flen, half), stat, &
5389 errmsg)
5390 end subroutine
5391
5392 !> The half at x from a trained model and an oracle; the options' mode
5393 !> says which of the two it needs. measured receives one flag per
5394 !> frequency: 1 for an oracle-measured mode.
5395 subroutine gpr_htst_half(x, kind, half, model, oracle, options, masses, &
5396 frequencies, measured, stat, errmsg, user_data)
5397 real(c_double), intent(in), contiguous :: x(:)
5398 integer, intent(in) :: kind
5399 type(htsthalf), intent(inout) :: half
5400 class(gpmodel), intent(in), optional :: model
5401 procedure(gpr_oracle_interface), optional :: oracle
5402 type(htstoptions), intent(in), optional :: options
5403 real(c_double), intent(in), contiguous, optional, target :: masses(:)
5404 real(c_double), intent(inout), contiguous, optional, target :: &
5405 frequencies(:)
5406 integer(c_int), intent(inout), contiguous, optional, target :: &
5407 measured(:)
5408 integer, intent(out), optional :: stat
5409 character(len=*), intent(inout), optional :: errmsg
5410 type(c_ptr), intent(in), optional :: user_data
5411 type(c_ptr) :: handle, ud, mass_ptr, fptr, mptr
5412 type(c_funptr) :: fn
5413 integer(c_size_t) :: mass_len, flen, mlen
5414 integer(c_int) :: n_masses
5415
5416 handle = c_null_ptr
5417 if (present(model)) handle = model%handle
5418 fn = c_null_funptr
5419 if (present(oracle)) fn = c_funloc(oracle)
5420 ud = c_null_ptr
5421 if (present(user_data)) ud = user_data
5422 mass_ptr = c_null_ptr
5423 mass_len = 0
5424 n_masses = 0
5425 if (present(masses)) then
5426 mass_ptr = c_loc(masses)
5427 mass_len = size(masses, kind=c_size_t)
5428 n_masses = int(size(masses), c_int)
5429 end if
5430 call htst_output_pointers(frequencies, measured, fptr, flen, mptr, mlen)
5431 half%struct_size = c_sizeof(half)
5432 call report_status(c_gpr_htst_half_checked(handle, fn, ud, &
5433 htst_options_or_defaults(options), mass_ptr, mass_len, n_masses, &
5434 x, size(x, kind=c_size_t), int(size(x), c_int), int(kind, c_int), &
5435 fptr, flen, mptr, mlen, half), stat, errmsg)
5436 end subroutine
5437
5438 !> ln nu = minimum%ln_sum - saddle%ln_sum and its GP-variance spread.
5439 subroutine gpr_htst_ln_prefactor(minimum, saddle, ln_nu, ln_nu_std, stat, &
5440 errmsg)
5441 type(htsthalf), intent(in) :: minimum, saddle
5442 real(c_double), intent(out) :: ln_nu
5443 real(c_double), intent(out), optional :: ln_nu_std
5444 integer, intent(out), optional :: stat
5445 character(len=*), intent(inout), optional :: errmsg
5446 real(c_double) :: spread
5447
5448 ln_nu = 0.0d0
5449 spread = 0.0d0
5450 call report_status(c_gpr_htst_ln_prefactor(minimum, saddle, ln_nu, &
5451 spread), stat, errmsg)
5452 if (present(ln_nu_std)) ln_nu_std = spread
5453 end subroutine
5454
5455 !> Opt this thread's later searches into prefactor halves. Absent
5456 !> options set enabled and the surrogate. Searches stay off until this call.
5457 subroutine gpr_request_prefactor(options, masses, stat, errmsg)
5458 type(htstoptions), intent(in), optional, target :: options
5459 real(c_double), intent(in), contiguous, optional, target :: masses(:)
5460 integer, intent(out), optional :: stat
5461 character(len=*), intent(inout), optional :: errmsg
5462 type(htstoptions), target :: local
5463 type(c_ptr) :: optr, mass_ptr
5464 integer(c_int) :: n_masses
5465
5466 optr = c_null_ptr
5467 if (present(options)) then
5468 local = options
5469 local%struct_size = c_sizeof(local)
5470 optr = c_loc(local)
5471 end if
5472 mass_ptr = c_null_ptr
5473 n_masses = 0
5474 if (present(masses)) then
5475 mass_ptr = c_loc(masses)
5476 n_masses = int(size(masses), c_int)
5477 end if
5478 call report_status(c_gpr_request_prefactor(optr, mass_ptr, n_masses), &
5479 stat, errmsg)
5480 end subroutine
5481
5482 !> A half (GPR_HTST_REACTANT, TRANSITION or PRODUCT) of the last search
5483 !> on this thread. n_coords is required with frequencies or measured.
5484 subroutine gpr_search_prefactor(point, half, frequencies, measured, &
5485 n_coords, stat, errmsg)
5486 integer, intent(in) :: point
5487 type(htsthalf), intent(inout) :: half
5488 real(c_double), intent(inout), contiguous, optional, target :: &
5489 frequencies(:)
5490 integer(c_int), intent(inout), contiguous, optional, target :: &
5491 measured(:)
5492 integer, intent(in), optional :: n_coords
5493 integer, intent(out), optional :: stat
5494 character(len=*), intent(inout), optional :: errmsg
5495 type(c_ptr) :: fptr, mptr
5496 integer(c_size_t) :: flen, mlen
5497 integer(c_int) :: n
5498
5499 call htst_output_pointers(frequencies, measured, fptr, flen, mptr, mlen)
5500 n = 0
5501 if (present(n_coords)) n = int(n_coords, c_int)
5502 half%struct_size = c_sizeof(half)
5503 call report_status(c_gpr_search_prefactor_checked(int(point, c_int), &
5504 half, fptr, flen, mptr, mlen, n), stat, errmsg)
5505 end subroutine
5506
5507 !> A half of this GP NEB result, as gpr_search_prefactor.
5508 subroutine neb_prefactor(self, point, half, frequencies, measured, &
5509 n_coords, stat, errmsg)
5510 class(nebresult), intent(in) :: self
5511 integer, intent(in) :: point
5512 type(htsthalf), intent(inout) :: half
5513 real(c_double), intent(inout), contiguous, optional, target :: &
5514 frequencies(:)
5515 integer(c_int), intent(inout), contiguous, optional, target :: &
5516 measured(:)
5517 integer, intent(in), optional :: n_coords
5518 integer, intent(out), optional :: stat
5519 character(len=*), intent(inout), optional :: errmsg
5520 type(c_ptr) :: fptr, mptr
5521 integer(c_size_t) :: flen, mlen
5522 integer(c_int) :: n
5523
5524 call htst_output_pointers(frequencies, measured, fptr, flen, mptr, mlen)
5525 n = 0
5526 if (present(n_coords)) n = int(n_coords, c_int)
5527 half%struct_size = c_sizeof(half)
5528 call report_status(c_gpr_neb_result_prefactor_checked(self%handle, &
5529 int(point, c_int), half, fptr, flen, mptr, mlen, n), stat, errmsg)
5530 end subroutine
5531
5532 ! ===================================================================
5533 ! Free-energy surrogate (ABI 1.23)
5534 ! ===================================================================
5535
5536 !> gpr_fes_config_init() of the loaded library.
5537 function fes_config_defaults() result(config)
5538 type(fesconfig) :: config
5539 integer(c_int) :: rc
5540 rc = c_gpr_fes_config_init(config, c_sizeof(config))
5541 call report_status(rc)
5542 end function
5543
5544 !> gpr_fes_rate_config_init() of the loaded library.
5545 function fes_rate_config_defaults() result(config)
5546 type(fesrateconfig) :: config
5547 integer(c_int) :: rc
5548 rc = c_gpr_fes_rate_config_init(config, c_sizeof(config))
5549 call report_status(rc)
5550 end function
5551
5552 !> Noise variances from relative sample weights; an approximation that
5553 !> ignores correlation between samples (see the C reference). noise_var
5554 !> has one entry per weight.
5555 subroutine fes_noise_from_weights(weights, reference_variance, &
5556 min_relative_weight, noise_var, stat, errmsg)
5557 real(c_double), intent(in), contiguous :: weights(:)
5558 real(c_double), intent(in) :: reference_variance, min_relative_weight
5559 real(c_double), intent(inout) :: noise_var(:)
5560 integer, intent(out), optional :: stat
5561 character(len=*), intent(inout), optional :: errmsg
5562 integer(c_int) :: rc
5563 real(c_double), allocatable :: out(:)
5564
5565 if (size(noise_var) /= size(weights)) then
5566 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5567 'fes_noise_from_weights: noise_var needs one entry per weight')
5568 return
5569 end if
5570 allocate(out(size(noise_var)))
5572 int(size(weights), c_size_t), reference_variance, &
5573 min_relative_weight, out, int(size(out), c_size_t), &
5574 int(size(weights), c_int))
5575 if (rc == gpr_success) noise_var = out
5576 call report_status(rc, stat, errmsg)
5577 end subroutine
5578
5579 !> Create a surrogate; absent configurations take the library defaults.
5580 !> grad_noise_var(dimension) is added to each observed gradient component;
5581 !> absent, the library divides the value noise by the squared spread of
5582 !> the training points along each coordinate.
5583 function fes_constructor(dimension, model_config, fes_config, &
5584 grad_noise_var, stat, errmsg) result(self)
5585 integer, intent(in) :: dimension
5586 type(modelconfig), intent(in), optional :: model_config
5587 type(fesconfig), intent(in), optional :: fes_config
5588 real(c_double), intent(in), optional :: grad_noise_var(:)
5589 integer, intent(out), optional :: stat
5590 character(len=*), intent(inout), optional :: errmsg
5591 type(fessurrogate) :: self
5592 type(modelconfig) :: model
5593 type(fesconfig) :: fes
5594 real(c_double), allocatable, target :: noise(:)
5595 type(c_ptr) :: noise_ptr
5596 integer(c_size_t) :: noise_len
5597 integer(c_int) :: rc
5598
5599 if (present(model_config)) then
5600 model = model_config
5601 else
5602 model = c_gpr_model_config_defaults()
5603 end if
5604 if (present(fes_config)) then
5605 fes = fes_config
5606 else
5607 rc = c_gpr_fes_config_init(fes, c_sizeof(fes))
5608 end if
5609 noise_ptr = c_null_ptr
5610 noise_len = 0
5611 if (present(grad_noise_var)) then
5612 noise = grad_noise_var
5613 noise_ptr = c_loc(noise)
5614 noise_len = size(noise, kind=c_size_t)
5615 end if
5616 self%handle = c_gpr_fes_create(int(dimension, c_int), model, fes, &
5617 noise_ptr, noise_len)
5618 if (c_associated(self%handle)) then
5619 allocate(self%references, source=1)
5620 rc = gpr_success
5621 else
5622 rc = failed_status()
5623 end if
5624 call report_status(rc, stat, errmsg)
5625 end function
5626
5627 function fes_dimension(self) result(n)
5628 class(fessurrogate), intent(in) :: self
5629 integer :: n
5630 n = int(c_gpr_fes_dimension(self%handle))
5631 end function
5632
5633 function fes_n_observations(self) result(n)
5634 class(fessurrogate), intent(in) :: self
5635 integer :: n
5636 n = int(c_gpr_fes_n_observations(self%handle))
5637 end function
5638
5639 !> Train on F at the columns of s. grad_F and grad_noise_var must
5640 !> have the shape of s (dimension x n). grad_present (n) is with them,
5641 !> or all three are absent. Any other shape is rejected.
5642 subroutine fes_train(self, s, F, F_noise_var, grad_F, grad_noise_var, &
5643 grad_present, stat, errmsg)
5644 class(fessurrogate), intent(inout) :: self
5645 real(c_double), intent(in), contiguous :: s(:,:), f(:)
5646 real(c_double), intent(in), optional :: f_noise_var(:)
5647 real(c_double), intent(in), optional :: grad_f(:,:), grad_noise_var(:,:)
5648 logical, intent(in), optional :: grad_present(:)
5649 integer, intent(out), optional :: stat
5650 character(len=*), intent(inout), optional :: errmsg
5651 real(c_double), allocatable, target :: noise(:), grad(:,:), grad_noise(:,:)
5652 integer(c_int8_t), allocatable, target :: flags(:)
5653 type(c_ptr) :: noise_ptr, grad_ptr, grad_noise_ptr, flags_ptr
5654 integer(c_size_t) :: noise_len, grad_len, grad_noise_len, flags_len
5655 integer(c_int) :: rc
5656
5657 noise_ptr = c_null_ptr
5658 noise_len = 0
5659 if (present(f_noise_var)) then
5660 noise = f_noise_var
5661 noise_ptr = c_loc(noise)
5662 noise_len = size(noise, kind=c_size_t)
5663 end if
5664 grad_ptr = c_null_ptr
5665 grad_noise_ptr = c_null_ptr
5666 flags_ptr = c_null_ptr
5667 grad_len = 0
5668 grad_noise_len = 0
5669 flags_len = 0
5670 if (present(grad_f)) then
5671 grad = grad_f
5672 grad_ptr = c_loc(grad)
5673 grad_len = size(grad, kind=c_size_t)
5674 end if
5675 if (present(grad_noise_var)) then
5676 grad_noise = grad_noise_var
5677 grad_noise_ptr = c_loc(grad_noise)
5678 grad_noise_len = size(grad_noise, kind=c_size_t)
5679 end if
5680 if (present(grad_present)) then
5681 allocate(flags(size(grad_present)))
5682 flags = 0_c_int8_t
5683 where (grad_present) flags = 1_c_int8_t
5684 flags_ptr = c_loc(flags)
5685 flags_len = size(flags, kind=c_size_t)
5686 end if
5687 if (size(s, 2) /= size(f)) then
5688 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5689 'FESSurrogate%train: s needs one column per F')
5690 return
5691 end if
5692 if (present(grad_f)) then
5693 if (any(shape(grad_f) /= shape(s))) then
5694 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5695 'FESSurrogate%train: grad_F needs the shape of s')
5696 return
5697 end if
5698 end if
5699 if (present(grad_noise_var)) then
5700 if (any(shape(grad_noise_var) /= shape(s))) then
5701 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5702 'FESSurrogate%train: grad_noise_var needs the shape of s')
5703 return
5704 end if
5705 end if
5706 rc = c_gpr_fes_train_checked(self%handle, s, size(s, kind=c_size_t), f, &
5707 size(f, kind=c_size_t), noise_ptr, noise_len, grad_ptr, grad_len, &
5708 grad_noise_ptr, grad_noise_len, flags_ptr, flags_len, &
5709 int(size(f), c_int), int(size(s, 1), c_int))
5710 call report_status(rc, stat, errmsg)
5711 end subroutine
5712
5713 !> Posterior mean F(n) at the n columns of s, with the mean gradient
5714 !> grad_F(dimension, n) and the latent variance var_F(n) when present.
5715 !> Outputs of any other shape are rejected unwritten.
5716 subroutine fes_predict(self, s, F, grad_F, var_F, stat, errmsg)
5717 class(fessurrogate), intent(in) :: self
5718 real(c_double), intent(in), contiguous :: s(:,:)
5719 real(c_double), intent(inout) :: f(:)
5720 real(c_double), intent(inout), optional :: grad_f(:,:), var_f(:)
5721 integer, intent(out), optional :: stat
5722 character(len=*), intent(inout), optional :: errmsg
5723 real(c_double), allocatable :: mean(:)
5724 real(c_double), allocatable, target :: grad(:,:), var(:)
5725 type(c_ptr) :: grad_ptr, var_ptr
5726 integer(c_size_t) :: grad_len, var_len
5727 integer(c_int) :: rc
5728
5729 if (size(f) /= size(s, 2)) then
5730 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5731 'FESSurrogate%predict: F needs one entry per column of s')
5732 return
5733 end if
5734 if (present(grad_f)) then
5735 if (any(shape(grad_f) /= shape(s))) then
5736 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5737 'FESSurrogate%predict: grad_F needs the shape of s')
5738 return
5739 end if
5740 end if
5741 if (present(var_f)) then
5742 if (size(var_f) /= size(s, 2)) then
5743 call report_status(gpr_err_invalid_arg, stat, errmsg, &
5744 'FESSurrogate%predict: var_F needs one entry per column of s')
5745 return
5746 end if
5747 end if
5748 allocate(mean(size(f)))
5749 grad_ptr = c_null_ptr
5750 var_ptr = c_null_ptr
5751 grad_len = 0
5752 var_len = 0
5753 if (present(grad_f)) then
5754 allocate(grad(size(grad_f, 1), size(grad_f, 2)))
5755 grad_ptr = c_loc(grad)
5756 grad_len = size(grad, kind=c_size_t)
5757 end if
5758 if (present(var_f)) then
5759 allocate(var(size(var_f)))
5760 var_ptr = c_loc(var)
5761 var_len = size(var, kind=c_size_t)
5762 end if
5763 rc = c_gpr_fes_predict_batch_checked(self%handle, s, &
5764 size(s, kind=c_size_t), mean, size(mean, kind=c_size_t), grad_ptr, &
5765 grad_len, var_ptr, var_len, int(size(s, 2), c_int), &
5766 int(size(s, 1), c_int))
5767 if (rc == gpr_success) then
5768 f = mean
5769 if (present(grad_f)) grad_f = grad
5770 if (present(var_f)) var_f = var
5771 end if
5772 call report_status(rc, stat, errmsg)
5773 end subroutine
5774
5775 !> Posterior-sampled Kramers rate along the columns of path. The indices
5776 !> are 1-based; diffusion(dimension) is the diagonal of the diffusion
5777 !> tensor.
5778 subroutine fes_rate_path(self, path, reactant, product, diffusion, config, &
5779 report, stat, errmsg)
5780 class(fessurrogate), intent(in) :: self
5781 real(c_double), intent(in), contiguous :: path(:,:)
5782 integer, intent(in) :: reactant, product
5783 real(c_double), intent(in), contiguous :: diffusion(:)
5784 type(fesrateconfig), intent(in) :: config
5785 type(fesratereport), intent(inout) :: report
5786 integer, intent(out), optional :: stat
5787 character(len=*), intent(inout), optional :: errmsg
5788 type(fesratereport) :: result
5789 integer(c_int) :: rc
5790
5791 result%struct_size = c_sizeof(result)
5792 rc = c_gpr_fes_rate_path_checked(self%handle, path, &
5793 size(path, kind=c_size_t), int(size(path, 2), c_int), &
5794 int(size(path, 1), c_int), int(reactant - 1, c_int), &
5795 int(product - 1, c_int), diffusion, size(diffusion, kind=c_size_t), &
5796 config, result)
5797 if (rc == gpr_success) report = result
5798 call report_status(rc, stat, errmsg)
5799 end subroutine
5800
5801 function fes_is_valid(self) result(valid)
5802 class(fessurrogate), intent(in) :: self
5803 logical :: valid
5804 valid = c_associated(self%handle)
5805 end function
5806
5807 function fes_get_handle(self) result(h)
5808 class(fessurrogate), intent(in) :: self
5809 type(c_ptr) :: h
5810 h = self%handle
5811 end function
5812
5813 !> Assignment shares the handle; each wrapper releases its own reference.
5814 impure elemental subroutine fes_assign(self, other)
5815 class(fessurrogate), intent(inout) :: self
5816 type(fessurrogate), intent(in) :: other
5817 type(c_ptr) :: handle
5818 integer, pointer :: references
5819
5820 if (associated(self%references, other%references)) return
5821 handle = other%handle
5822 references => other%references
5823 if (associated(references)) references = references + 1
5824 call self%release()
5825 self%handle = handle
5826 self%references => references
5827 end subroutine
5828
5829 subroutine fes_release(self)
5830 class(fessurrogate), intent(inout) :: self
5831 if (associated(self%references)) then
5832 self%references = self%references - 1
5833 if (self%references == 0) then
5834 call c_gpr_fes_destroy(self%handle)
5835 deallocate(self%references)
5836 end if
5837 end if
5838 self%handle = c_null_ptr
5839 nullify(self%references)
5840 end subroutine
5841
5842 impure elemental subroutine fes_finalize(self)
5843 type(fessurrogate), intent(inout) :: self
5844 call self%release()
5845 end subroutine
5846
5847end module gpridge
@ z
Definition Enums.h:28
@ x
Definition Enums.h:28
@ y
Definition Enums.h:28
gpr_force_fn: energy and forces of n_atoms atoms. energy_noise_rms (a standard deviation in eV) and b...
Definition gpridge.f90:1621
gpr_force_with_uncertainty_fn: energy, forces, energy_noise_rms and force_noise_rms of n_atoms atoms....
Definition gpridge.f90:1635
gpr_hvp_fn: Hessian-vector-product callback at a fixed point (ABI 1.20). Writes H(positions) * vector...
Definition gpridge.f90:1649
gpr_oracle_fn: energy and gradient at positions. A failed evaluation sets a non-finite energy.
Definition gpridge.f90:1608
integer(c_int), parameter, public gpr_htst_surrogate
Definition gpridge.f90:70
subroutine, public gpr_neb_search_gp_potential(force, atoms, r_initial, r_final, n_images, config, result, stat, errmsg, model, box, user_data)
gpr_neb_search_gp over a force callback. The callback receives the atomic numbers of atoms; box (3x3,...
Definition gpridge.f90:4790
subroutine, public gpr_htst_half_from_hessian(h, x, kind, half, options, masses, frequencies, stat, errmsg)
The half of a caller's row-major Hessian H at x. masses holds one value per moving atom; absent means...
Definition gpridge.f90:5361
integer(c_int), parameter, public gpr_neb_not_converged
Definition gpridge.f90:51
logical function, public gpr_backend_requires_mpi()
True when the linear-algebra backend needs MPI initialized first.
Definition gpridge.f90:4231
integer(c_int), parameter, public gpr_neb_oie
Definition gpridge.f90:109
character(len=:) function, allocatable, public gpr_last_error_message()
Same string as gpr_error_message. This is the C name.
Definition gpridge.f90:4272
integer(c_int), parameter, public gpr_uq_laplace_slice
Definition gpridge.f90:136
integer(c_int), parameter, public gpr_neb_gp_aie
Definition gpridge.f90:110
integer(c_int), parameter, public gpr_hopt_scg
Definition gpridge.f90:139
character(len=:) function, allocatable, public gpr_last_error()
Alias of gpr_last_error_message matching gpr_last_error in gpridge_c.h.
Definition gpridge.f90:4278
integer(c_int), parameter, public gpr_bq_hyper_map
Definition gpridge.f90:157
integer(c_int), parameter, public gpr_htst_wrong_index
Definition gpridge.f90:75
subroutine, public gpr_request_prefactor(options, masses, stat, errmsg)
Opt this thread's later searches into prefactor halves. Absent options set enabled and the surrogate....
Definition gpridge.f90:5458
integer(c_int), parameter, public gpr_htst_product
Definition gpridge.f90:84
integer(c_int), parameter, public gpr_neb_gp_local
Definition gpridge.f90:112
integer(c_int), parameter, public gpr_neb_gp_oie
Definition gpridge.f90:111
integer(c_int), parameter, public gpr_dist_emd
Definition gpridge.f90:147
integer(c_int), parameter, public gpr_model_gp
Definition gpridge.f90:94
integer(c_int), parameter, public gpr_neb_model_noise_floor
Definition gpridge.f90:53
type(potentialhandle) function, public gpr_potential_from_force_with_uncertainty(fn, user_data, stat, errmsg)
Definition gpridge.f90:3944
type(fesrateconfig) function, public fes_rate_config_defaults()
gpr_fes_rate_config_init() of the loaded library.
Definition gpridge.f90:5546
character(len=:) function, allocatable, public gpr_linalg_mode()
Definition gpridge.f90:4304
integer(c_int), parameter, public gpr_opt_factorized
Definition gpridge.f90:99
type(localbandconfig) function, public gpr_local_band_config_defaults()
Definition gpridge.f90:4580
subroutine, public gpr_neb_search_periodic_potential(force, atomic_nrs, r_initial, r_final, n_images, result, stat, errmsg, periodic, local, atoms, box, user_data)
gpr_neb_search_periodic over a force callback.
Definition gpridge.f90:4634
subroutine, public gpr_oracle_lj(n_coords, positions, energy, gradient, user_data)
Oracle adapter for Lennard-Jones (user_data points to LJParams).
Definition gpridge.f90:3879
integer(c_int), parameter, public gpr_htst_source_stencil
Definition gpridge.f90:79
integer(c_int), parameter, public gpr_err_cholesky
Definition gpridge.f90:20
integer(c_int), parameter, public gpr_htst_source_surrogate
Definition gpridge.f90:80
integer(c_int), parameter, public gpr_acq_priority_cascade
Definition gpridge.f90:121
subroutine, public gpr_htst_ln_prefactor(minimum, saddle, ln_nu, ln_nu_std, stat, errmsg)
ln nu = minimumln_sum - saddleln_sum and its GP-variance spread.
Definition gpridge.f90:5441
integer(c_int), parameter, public gpr_dimer_stop_invalid_parameters
Definition gpridge.f90:46
integer(c_int), parameter, public gpr_htst_not_converged
Definition gpridge.f90:74
subroutine, public gpr_neb_search_gp(oracle, atoms, r_initial, r_final, n_images, config, result, stat, errmsg, model, user_data)
GP-accelerated NEB (gpr_neb_search_gp): R_initial and R_final hold every atom of atoms (3*n_atoms val...
Definition gpridge.f90:4757
integer(c_int), parameter, public gpr_bq_kernel_matern32_isotropic
Definition gpridge.f90:153
integer(c_int), parameter, public gpr_uq_bma
Definition gpridge.f90:132
integer(c_int), parameter, public gpr_bq_hyper_tp_marginal
Definition gpridge.f90:158
integer(c_int), parameter, public gpr_norm_l2
Definition gpridge.f90:126
subroutine, public fes_noise_from_weights(weights, reference_variance, min_relative_weight, noise_var, stat, errmsg)
Noise variances from relative sample weights; an approximation that ignores correlation between sampl...
Definition gpridge.f90:5557
integer(c_int), parameter, public gpr_htst_minimum
Definition gpridge.f90:71
subroutine, public gpr_check_abi(stat, errmsg)
Check that the loaded library implements the ABI this module binds.
Definition gpridge.f90:4284
integer(c_int), parameter, public gpr_htst_ok
Definition gpridge.f90:73
integer(c_int), parameter, public gpr_dimer_stop_force_converged
Definition gpridge.f90:37
integer(c_int), parameter, public gpr_bq_kernel_matern52_isotropic
Definition gpridge.f90:154
subroutine, public gpr_train_phase_read_leaves(setup_s, descriptor_s, posterior_s, subset_s, objective_s, condition_s, cache_s, curvature_s, energy_s, schedule_s)
Read the train-phase leaf accumulators (setup, conditioning, etc.).
Definition gpridge.f90:4356
integer function, public gpr_omp_max_threads()
OpenMP thread budget, 1 without OpenMP.
Definition gpridge.f90:4254
integer(c_int), parameter, public gpr_acq_psbax
Definition gpridge.f90:123
subroutine, public gpr_check_model_package(path, stat, errmsg)
Check that an AOTInductor model package runs on this CPU.
Definition gpridge.f90:4394
integer(c_int), parameter, public gpr_htst_refined
Definition gpridge.f90:68
integer(c_int), parameter, public gpr_energy_unit_kcal_per_mol
Definition gpridge.f90:60
subroutine, public gpr_dimer_search(force, atoms, r_init, orient_init, config, r_saddle, e_saddle, report, stat, errmsg, orient_out, user_data)
GP-accelerated dimer search from R_init along orient_init (both 3*n_atoms). reportmax_oracle_calls is...
Definition gpridge.f90:4868
integer(c_int), parameter, public gpr_dimer_stop_measured_non_descent
Definition gpridge.f90:38
integer(c_int), parameter, public gpr_bq_kernel_matern32_product
Definition gpridge.f90:151
integer(c_int), parameter, public gpr_acq_imspe
Definition gpridge.f90:119
integer(c_int), parameter, public gpr_dimer_stop_interatomic_collapse
Definition gpridge.f90:43
subroutine, public gpr_neb_search_periodic(oracle, r_initial, r_final, n_images, result, stat, errmsg, periodic, local, atoms, box, user_data)
Periodic local band (gpr_neb_search_periodic), the binding of GPLocalBand. periodic and local default...
Definition gpridge.f90:4595
integer(c_int), parameter, public gpr_acq_ucb
Definition gpridge.f90:117
type(potentialhandle) function, public gpr_potential_from_force(fn, user_data, stat, errmsg)
Definition gpridge.f90:3922
integer(c_int), parameter, public gpr_bq_measure_lebesgue_box
Definition gpridge.f90:160
integer(c_int), parameter, public gpr_htst_measured
Definition gpridge.f90:69
integer function, public gpr_last_status()
Status of the last failing call on this thread; GPR_SUCCESS after a call that succeeded.
Definition gpridge.f90:4211
integer(c_int), parameter, public gpr_err_invalid_arg
Definition gpridge.f90:17
integer(c_int), parameter, public gpr_psearch_axis_log
Definition gpridge.f90:168
integer(c_int), parameter, public gpr_energy_unit_hartree
Definition gpridge.f90:59
subroutine, public gpr_oracle_leps(n_coords, positions, energy, gradient, user_data)
Oracle adapter for LEPS.
Definition gpridge.f90:3905
logical function, public gpr_training_product_configured()
Definition gpridge.f90:4388
subroutine, public gpr_ocineb_search(oracle, atoms, r_initial, r_final, n_images, config, result, stat, errmsg, oci, model, user_data)
GP-NEB with dimer bursts on the climbing image (gpr_ocineb_search). Arguments as gpr_neb_search_gp; o...
Definition gpridge.f90:4831
integer(c_int), parameter, public gpr_energy_unit_ev
Definition gpridge.f90:58
integer(c_int), parameter, public gpr_energy_unit_native
Definition gpridge.f90:57
integer(c_int), parameter, public gpr_hssvd_backend_hssvd
Definition gpridge.f90:103
integer(c_int), parameter, public gpr_htst_unavailable
Definition gpridge.f90:76
type(fesconfig) function, public fes_config_defaults()
gpr_fes_config_init() of the loaded library.
Definition gpridge.f90:5538
subroutine, public gpr_search_prefactor(point, half, frequencies, measured, n_coords, stat, errmsg)
A half (GPR_HTST_REACTANT, TRANSITION or PRODUCT) of the last search on this thread....
Definition gpridge.f90:5486
integer(c_int), parameter, public gpr_dimer_stop_uninformative_rotation
Definition gpridge.f90:40
integer(c_int), parameter, public gpr_htst_source_measured
Definition gpridge.f90:78
integer(c_int), parameter, public gpr_energy_unit_kj_per_mol
Definition gpridge.f90:61
integer(c_int), parameter, public gpr_acq_thompson
Definition gpridge.f90:118
integer(c_int), parameter, public gpr_bq_kernel_se
Definition gpridge.f90:150
integer(c_int), parameter, public gpr_length_unit_bohr
Definition gpridge.f90:64
subroutine, public gpr_neb_search_local_potential(force, atomic_nrs, r_initial, r_final, n_images, result, stat, errmsg, config, local, atoms, box, user_data)
gpr_neb_search_local over a force callback. atomic_nrs names the atoms when atoms is absent.
Definition gpridge.f90:4483
integer(c_int), parameter, public gpr_hobj_nlml
Definition gpridge.f90:141
integer(c_int), parameter, public gpr_err_alloc
Definition gpridge.f90:19
integer(c_int), parameter, public gpr_hssvd_backend_cholesky
Definition gpridge.f90:104
integer(c_int), parameter, public gpr_length_unit_nanometer
Definition gpridge.f90:65
integer(c_int), parameter, public gpr_dimer_stop_uncertified_force_stop
Definition gpridge.f90:48
integer(c_int), parameter, public gpr_err_size_limit
Definition gpridge.f90:23
integer(c_int), parameter, public gpr_hobj_loo
Definition gpridge.f90:142
integer(c_int), parameter, public gpr_model_tp
Definition gpridge.f90:95
integer(c_int), parameter, public gpr_err_optimizer
Definition gpridge.f90:21
integer(c_int), parameter, public gpr_htst_reactant
Definition gpridge.f90:82
integer(c_int), parameter, public gpr_bq_measure_gaussian
Definition gpridge.f90:162
integer(c_int), parameter, public gpr_err_abi
Definition gpridge.f90:26
integer(c_int), parameter, public gpr_acq_tpe
Definition gpridge.f90:122
integer(c_int), parameter, public gpr_dimer_stop_invalid_atoms
Definition gpridge.f90:44
integer(c_int), parameter, public gpr_neb_standard
Definition gpridge.f90:107
integer(c_int), parameter, public gpr_periodic_band_idpp
Definition gpridge.f90:1482
integer(c_int), parameter, public gpr_err_oracle
Definition gpridge.f90:24
subroutine, public gpr_leps_energy(r, energy, gradient, ierr)
LEPS collinear potential.
Definition gpridge.f90:3867
integer(c_int), parameter, public gpr_htst_saddle
Definition gpridge.f90:72
integer(c_int), parameter, public gpr_dist_max_1d_log
Definition gpridge.f90:145
integer(c_int), parameter, public gpr_norm_linf
Definition gpridge.f90:127
subroutine, public gpr_muller_brown_energy(xy, energy, gradient, ierr)
Muller-Brown 2D potential.
Definition gpridge.f90:3855
subroutine, public gpr_neb_request_sidpp(enable, stat, errmsg)
Select SIDPP (true) or classic IDPP (false) for the next NEB search on this thread....
Definition gpridge.f90:4559
type(nebconfig) function, public gpr_neb_config_defaults()
gpr_neb_config_defaults() of the loaded library.
Definition gpridge.f90:4165
integer(c_int), parameter, public gpr_success
Definition gpridge.f90:15
integer(c_int), parameter, public gpr_acq_max_force
Definition gpridge.f90:116
integer(c_int), parameter, public gpr_err_internal
Definition gpridge.f90:29
integer(c_int), parameter, public gpr_bq_hyper_ml
Definition gpridge.f90:156
integer(c_int), parameter, public gpr_neb_force_tolerance
Definition gpridge.f90:52
type(minimizeconfig) function, public gpr_minimize_config_defaults()
gpr_minimize_config_defaults() of the loaded library.
Definition gpridge.f90:4171
integer(c_int), parameter, public gpr_dimer_stop_measured_index_zero
Definition gpridge.f90:47
integer(c_int), parameter, public gpr_bq_basis_none
Definition gpridge.f90:164
integer(c_int), parameter, public gpr_htst_source_refined
Definition gpridge.f90:77
subroutine, public gpr_minimize(oracle, r_init, atoms, config, r_final, e_final, converged, n_oracle_calls, stat, errmsg, g_final, user_data)
GP-accelerated minimization from R_init. R_final, E_final and G_final are always an exact oracle eval...
Definition gpridge.f90:5036
subroutine, public gpr_train_phase_read(factor_s, solve_s, eigen_s, kernel_s, hessian_s)
Read the five train-phase wall-time accumulators.
Definition gpridge.f90:4335
subroutine, public gpr_train_phase_reset()
Zero the train-phase wall-time accumulators.
Definition gpridge.f90:4329
integer(c_int), parameter, public gpr_bq_hyper_marginalized
Definition gpridge.f90:159
integer(c_int), parameter, public gpr_bq_basis_affine
Definition gpridge.f90:166
integer(c_int), parameter, public gpr_periodic_band_linear
Initial path of a periodic band (gpr_periodic_band_initial_t).
Definition gpridge.f90:1481
integer(c_int), parameter, public gpr_length_unit_native
Definition gpridge.f90:62
subroutine, public gpr_abi_version(major, minor)
ABI version of the loaded library (GPR_C_ABI_MAJOR/MINOR give this module's).
Definition gpridge.f90:4194
subroutine, public gpr_neb_search(oracle, r_initial, r_final, n_images, config, result, stat, errmsg, user_data)
NEB between R_initial and R_final with n_images intermediate images. configmode selects standard,...
Definition gpridge.f90:4413
integer(c_int), parameter, public gpr_c_abi_major
C ABI version this module was written against (gpridge_c.h).
Definition gpridge.f90:32
subroutine, public gpr_neb_search_local(oracle, r_initial, r_final, n_images, result, stat, errmsg, config, local, atoms, box, user_data)
Local band (gpr_neb_search_local). config and local default to the library defaults....
Definition gpridge.f90:4443
integer(c_int), parameter, public gpr_dimer_stop_oracle_budget
Definition gpridge.f90:45
type(htstoptions) function, public gpr_htst_options_defaults()
gpr_htst_options_defaults() with struct_size set.
Definition gpridge.f90:5086
subroutine, public gpr_oracle_muller_brown(n_coords, positions, energy, gradient, user_data)
Oracle adapter for Muller-Brown.
Definition gpridge.f90:3891
subroutine, public gpr_neb_request_vibrational_stencil(mode, stat, errmsg)
Stencil of the next non-local NEB search on this thread. mode 0 measures every coordinate; mode 1 mea...
Definition gpridge.f90:4572
integer(c_int), parameter, public gpr_bq_basis_follow_config
Definition gpridge.f90:163
subroutine, public gpr_set_linalg_mode(mode, stat, errmsg)
"reproducible" (the default) or "library"; see gpr_set_linalg_mode in gpridge_c.h.
Definition gpridge.f90:4297
integer(c_int), parameter, public gpr_dist_rmsd
Definition gpridge.f90:146
integer(c_int), parameter, public gpr_length_unit_angstrom
Definition gpridge.f90:63
integer(c_int), parameter, public gpr_uq_eb
Definition gpridge.f90:134
integer(c_int), parameter, public gpr_dimer_stop_unspecified
Definition gpridge.f90:36
subroutine, public gpr_neb_request_index_certificate(enable, step, stat, errmsg)
Ask the next band search on this thread for the index certificate. step 0 keeps the library stencil s...
Definition gpridge.f90:4543
integer(c_int), parameter, public gpr_bq_basis_constant
Definition gpridge.f90:165
subroutine, public gpr_minimize_request_max_inner_steps(max_inner_steps, stat, errmsg)
Set the inner surrogate L-BFGS step cap (default 200, must be >= 1) for the next gpr_minimize call on...
Definition gpridge.f90:5019
subroutine, public gpr_version_components(major, minor, patch)
Version components of the loaded library.
Definition gpridge.f90:4183
subroutine, public gpr_set_library_serial(enabled, stat, errmsg)
Select Eigen's serial factor/solve (true) or OpenMP panel kernels (false).
Definition gpridge.f90:4318
integer(c_int), parameter, public gpr_psearch_axis_linear
Definition gpridge.f90:167
integer(c_int), parameter, public gpr_periodic_norm_unset
convergence_norm value that keeps the mode's own norm.
Definition gpridge.f90:1485
type(modelconfig) function, public gpr_model_config_defaults()
gpr_model_config_defaults() of the loaded library.
Definition gpridge.f90:4159
integer function, public gpr_mpi_world_size()
Size of MPI_COMM_WORLD, 1 without MPI.
Definition gpridge.f90:4248
integer(c_int), parameter, public gpr_htst_transition
Definition gpridge.f90:83
integer(c_int), parameter, public gpr_dimer_stop_alignment_loss
Definition gpridge.f90:41
integer(c_int), parameter, public gpr_dimer_stop_iteration_budget
Definition gpridge.f90:42
integer(c_int), parameter, public gpr_neb_aie
Definition gpridge.f90:108
character(len=:) function, allocatable, public gpr_status_name(status)
Name of a status code, e.g. "GPR_ERR_ORACLE".
Definition gpridge.f90:4203
subroutine, public gpr_lj_energy(x, n_atoms, epsilon, sigma, energy, gradient, ierr)
Lennard-Jones energy and gradient.
Definition gpridge.f90:3835
logical function, public gpr_mpi_initialized()
Definition gpridge.f90:4236
type(dimerconfig) function, public gpr_dimer_config_defaults()
gpr_dimer_config_defaults() of the loaded library; equal to a default-initialized DimerConfig.
Definition gpridge.f90:4153
type(ocinebconfig) function, public gpr_ocineb_config_defaults()
gpr_ocineb_config_defaults() of the loaded library.
Definition gpridge.f90:4177
character(len=:) function, allocatable, public gpr_version_string()
Library version string, "major.minor.patch".
Definition gpridge.f90:4260
integer(c_int), parameter, public gpr_hssvd_backend_default
Definition gpridge.f90:102
subroutine, public gpr_neb_search_potential(force, atomic_nrs, r_initial, r_final, n_images, config, result, stat, errmsg, box, user_data)
NEB without a GP over a force callback of n_atoms = size(atomic_nrs) atoms (R_initial and R_final hav...
Definition gpridge.f90:4714
type(derivativeoptions) function, public gpr_derivative_options_defaults()
gpr_derivative_options_defaults() with struct_size set.
Definition gpridge.f90:5079
type(atomsdescriptor) function, public gpr_atoms_simple(n_atoms)
gpr_atoms_simple() of the loaded library.
Definition gpridge.f90:4145
integer(c_int), parameter, public gpr_htst_source_conditioned
Definition gpridge.f90:81
integer(c_int), parameter, public gpr_hopt_inla
Definition gpridge.f90:140
integer(c_int), parameter, public gpr_opt_scg
Definition gpridge.f90:98
integer(c_int), parameter, public gpr_psearch_axis_integer
Definition gpridge.f90:169
integer(c_int), parameter, public gpr_acq_ei
Definition gpridge.f90:120
integer(c_int), parameter, public gpr_uq_svgd
Definition gpridge.f90:135
integer(c_int), parameter, public gpr_err_out_of_support
Definition gpridge.f90:27
type(atomsdescriptor) function, public gpr_atoms_config_defaults()
gpr_atoms_config_defaults() of the loaded library.
Definition gpridge.f90:4139
type(periodicbandconfig) function, public gpr_periodic_band_config_defaults()
Definition gpridge.f90:4585
integer(c_int), parameter, public gpr_bq_hyper_fixed
Definition gpridge.f90:155
integer(c_int), parameter, public gpr_err_null_handle
Definition gpridge.f90:16
integer(c_int), parameter, public gpr_bq_measure_uniform_box
Definition gpridge.f90:161
integer(c_int), parameter, public gpr_bq_kernel_matern52_product
Definition gpridge.f90:152
integer(c_int), parameter, public gpr_err_not_converged
Definition gpridge.f90:22
character(len=:) function, allocatable, public gpr_backend_name()
"slate", "scalapack", "kokkos", "cusolver", "cholmod", "stdpar" or "eigen".
Definition gpridge.f90:4225
character(len=:) function, allocatable, public gpr_error_message()
Message of the last failing call on this thread.
Definition gpridge.f90:4266
integer(c_int), parameter, public gpr_norm_max_atom
Definition gpridge.f90:128
integer(c_int), parameter, public gpr_periodic_band_sidpp
Definition gpridge.f90:1483
subroutine, public gpr_dimer_search_raw(force, atoms, r_init, orient_init, config, r_saddle, e_saddle, stat, errmsg, orient_out, curvature, n_force_calls, n_gp_calls, user_data)
GP-accelerated dimer search via gpr_dimer_search (without DimerReport).
Definition gpridge.f90:4918
integer(c_int), parameter, public gpr_err_unsupported
Definition gpridge.f90:25
integer(c_int), parameter, public gpr_c_abi_minor
Definition gpridge.f90:33
integer(c_int), parameter, public gpr_acq_max_variance
Definition gpridge.f90:115
integer(c_int), parameter, public gpr_err_unit_mismatch
Definition gpridge.f90:28
integer(c_int), parameter, public gpr_err_not_trained
Definition gpridge.f90:18
subroutine, public gpr_set_linalg_threads(threads, stat, errmsg)
Definition gpridge.f90:4309
subroutine, public gpr_dimer_search_potential(pot, atoms, r_init, orient_init, config, r_saddle, e_saddle, report, stat, errmsg, orient_out)
GP-accelerated dimer search over a PotentialHandle.
Definition gpridge.f90:4971
integer function, public gpr_mpi_world_rank()
Rank in MPI_COMM_WORLD, 0 without MPI.
Definition gpridge.f90:4242
integer(c_int), parameter, public gpr_uq_map
Definition gpridge.f90:131
integer(c_int), parameter, public gpr_uq_laplace
Definition gpridge.f90:133
integer(c_int), parameter, public gpr_dimer_stop_degenerate_probe
Definition gpridge.f90:39
real(c_double), parameter, public gpr_htst_omega_ev_angstrom_amu
sqrt(eV / (Angstrom^2 amu)) in rad/s.
Definition gpridge.f90:86
subroutine, public gpr_set_training_product(spec, stat, errmsg)
"" for the native product, "scheme2:fp64[...]" / "scheme2:int8[...]" for a Scheme II engine,...
Definition gpridge.f90:4380
Potential wrappers and the batched oracle interface.
STL namespace.
One half of the prefactor (ABI 1.20).
Definition gpridge_c.h:2621
Atomic configuration for GP kernel (wraps opaque C handle).
Definition gpridge.f90:2363
The C atoms descriptor (gpr_atoms_config_t). AtomsConfig(n, ...) fills it; it is public so its layout...
Definition gpridge.f90:1521
Result of a Bayesian quadrature hyperparameter fit (ABI 1.17): the MarginalLikelihoodReport fields pl...
Definition gpridge.f90:1185
Residual-calibration report shared by held-out force and LOO workflows.
Definition gpridge.f90:1166
Options of the derivative primitives (gpr_derivative_options_t, ABI 1.20). The wrappers set struct_si...
Definition gpridge.f90:1379
Report of one derivative call (gpr_derivative_report_t, ABI 1.20). Written on success and on GPR_ERR_...
Definition gpridge.f90:1393
Dimer search configuration. Field order matches gpr_dimer_config_t; the initializers are gpr_dimer_co...
Definition gpridge.f90:1272
Outcome of a dimer search (gpr_dimer_report_t). Two fields are inputs: max_oracle_calls,...
Definition gpridge.f90:1324
gpr_fes_config_t (ABI 1.23). fes_config_defaults() fills it.
Definition gpridge.f90:228
gpr_fes_rate_config_t (ABI 1.23). fes_rate_config_defaults() fills it; beta must then be set.
Definition gpridge.f90:236
gpr_fes_rate_report_t (ABI 1.23).
Definition gpridge.f90:246
Gaussian process over a free energy F(s) on collective variables. Point arrays are s(dimension,...
Definition gpridge.f90:2826
Gaussian/Student-t process model (wraps opaque C handle).
Definition gpridge.f90:2708
One half of the prefactor (gpr_htst_half_t, ABI 1.20).
Definition gpridge.f90:1424
Prefactor options (gpr_htst_options_t, ABI 1.20); start from gpr_htst_options_defaults().
Definition gpridge.f90:1410
Lennard-Jones oracle adapter parameters (gpr_lj_params_t).
Definition gpridge.f90:1572
Local-band knobs (gpr_local_band_config_t). The initializers are gpr_local_band_config_defaults(),...
Definition gpridge.f90:1446
Result of a prior-free negative log marginal-likelihood fit (ABI 1.13).
Definition gpridge.f90:1155
Minimizer configuration (gpr_minimize_config_t). The initializers are gpr_minimize_config_defaults(),...
Definition gpridge.f90:1254
GP/TP model configuration (gpr_model_config_t). The initializers are gpr_model_config_defaults(),...
Definition gpridge.f90:1134
NEB search configuration. Field order matches gpr_neb_config_t; the initializers are gpr_neb_config_d...
Definition gpridge.f90:1199
Outcome of a NEB run (gpr_neb_report_t), from NEBResultreport.
Definition gpridge.f90:1347
NEB result (wraps opaque C handle with path data).
Definition gpridge.f90:2776
Condition-floored noise and certificate gap of a trained model (gpr_noise_floor_report_t,...
Definition gpridge.f90:1562
OCINEB dimer-burst controls (gpr_ocineb_config_t). The initializers are gpr_ocineb_config_defaults(),...
Definition gpridge.f90:1504
Periodic local band (gpr_periodic_band_config_t). The initializers are gpr_periodic_band_config_defau...
Definition gpridge.f90:1490
Force-evaluation wrapper handle (wraps opaque gpr_potential_t).
Definition gpridge.f90:2805
Report of held-out random-feature selection (gpr_rff_selection_t).
Definition gpridge.f90:1531