Loading...
Searching...
No Matches
metatomic_c_abi.h File Reference
#include <stddef.h>

Go to the source code of this file.

Classes

struct  EonMtaConfig
 Flat config for create (mirrors Parameters::metatomic_options_t). More...

Macros

#define EON_MTA_API   __attribute__((visibility("default")))
#define EON_MTA_ABI_VERSION   1

Typedefs

typedef struct EonMtaPot EonMtaPot
 Opaque pot handle.
typedef struct EonMtaConfig EonMtaConfig
 Flat config for create (mirrors Parameters::metatomic_options_t).

Functions

EON_MTA_API EonMtaPoteon_mta_pot_create (const EonMtaConfig *cfg, char *errbuf, size_t errlen)
 Create pot.
EON_MTA_API void eon_mta_pot_destroy (EonMtaPot *pot)
EON_MTA_API int eon_mta_pot_force (EonMtaPot *pot, long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)
 Evaluate energy + forces.
EON_MTA_API int eon_mta_abi_version (void)
 ABI version for loader checks.

Macro Definition Documentation

◆ EON_MTA_ABI_VERSION

#define EON_MTA_ABI_VERSION   1

Definition at line 79 of file metatomic_c_abi.h.

◆ EON_MTA_API

#define EON_MTA_API   __attribute__((visibility("default")))

Definition at line 27 of file metatomic_c_abi.h.

Typedef Documentation

◆ EonMtaConfig

typedef struct EonMtaConfig EonMtaConfig

Flat config for create (mirrors Parameters::metatomic_options_t).

All string pointers may be NULL (treated as empty / defaults).

◆ EonMtaPot

typedef struct EonMtaPot EonMtaPot

Opaque pot handle.

Definition at line 31 of file metatomic_c_abi.h.

Function Documentation

◆ eon_mta_abi_version()

EON_MTA_API int eon_mta_abi_version ( void )

ABI version for loader checks.

Definition at line 33 of file MetatomicCAbi.cpp.

33{ return EON_MTA_ABI_VERSION; }
#define EON_MTA_ABI_VERSION

◆ eon_mta_pot_create()

EON_MTA_API EonMtaPot * eon_mta_pot_create ( const EonMtaConfig * cfg,
char * errbuf,
size_t errlen )

Create pot.

On failure returns NULL and writes a message into errbuf (if non-NULL and errlen > 0).

Definition at line 35 of file MetatomicCAbi.cpp.

36 {
37 if (!cfg || !cfg->model_path || cfg->model_path[0] == '\0') {
38 set_err(errbuf, errlen, "eon_mta_pot_create: model_path is required");
39 return nullptr;
40 }
41 try {
42 Parameters params;
43 params.potential_options.potential = PotType::METATOMIC;
44 auto &o = params.metatomic_options;
45 o.model_path = cfg->model_path;
46 o.device = nz(cfg->device)[0] ? cfg->device : "cpu";
47 o.length_unit = nz(cfg->length_unit)[0] ? cfg->length_unit : "angstrom";
48 o.extensions_directory = nz(cfg->extensions_directory);
49 o.check_consistency = cfg->check_consistency != 0;
50 o.uncertainty_threshold = cfg->uncertainty_threshold;
51 o.energy_output = nz(cfg->energy_output);
52 o.energy_uncertainty_output = nz(cfg->energy_uncertainty_output);
53 o.force_output = nz(cfg->force_output);
54 o.non_conservative = cfg->non_conservative != 0;
55 o.random_rotation = cfg->random_rotation != 0;
56 o.n_symmetry_rotations = cfg->n_symmetry_rotations;
57 o.deterministic = cfg->deterministic != 0;
58 o.deterministic_strict = cfg->deterministic_strict != 0;
59 o.variant.base = nz(cfg->variant_base);
60 o.variant.energy = nz(cfg->variant_energy);
61 o.variant.energy_uncertainty = nz(cfg->variant_energy_uncertainty);
62 o.variant.force = nz(cfg->variant_force);
63
64 auto pot = std::make_unique<EonMtaPot>();
65 pot->impl = std::make_unique<MetatomicPotential>(params);
66 return pot.release();
67 } catch (const std::exception &e) {
68 set_err(errbuf, errlen, e.what());
69 return nullptr;
70 } catch (...) {
71 set_err(errbuf, errlen, "eon_mta_pot_create: unknown exception");
72 return nullptr;
73 }
74}
static void set_err(char *errbuf, size_t errlen, const char *msg)
static const char * nz(const char *s)
struct eonc::Parameters::potential_options_t potential_options
struct eonc::Parameters::metatomic_options_t metatomic_options
const char * device
const char * extensions_directory
const char * variant_force
const char * model_path
const char * length_unit
long n_symmetry_rotations
const char * energy_output
const char * force_output
const char * variant_base
const char * energy_uncertainty_output
const char * variant_energy
const char * variant_energy_uncertainty
double uncertainty_threshold

◆ eon_mta_pot_destroy()

EON_MTA_API void eon_mta_pot_destroy ( EonMtaPot * pot)

Definition at line 76 of file MetatomicCAbi.cpp.

76{ delete pot; }

◆ eon_mta_pot_force()

EON_MTA_API int eon_mta_pot_force ( EonMtaPot * pot,
long nAtoms,
const double * positions,
const int * atomicNrs,
double * forces,
double * energy,
double * variance,
const double * box )

Evaluate energy + forces.

Returns 0 on success, nonzero on failure. variance may be NULL.

Definition at line 78 of file MetatomicCAbi.cpp.

80 {
81 if (!pot || !pot->impl || !positions || !atomicNrs || !forces || !energy ||
82 !box) {
83 return 1;
84 }
85 try {
86 pot->impl->force(nAtoms, positions, atomicNrs, forces, energy, variance,
87 box);
88 return 0;
89 } catch (...) {
90 return 2;
91 }
92}
void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box) override
Calculates the energy and forces for a given atomic configuration.
std::unique_ptr< MetatomicPotential > impl