Loading...
Searching...
No Matches
metatomic_c_abi.h File Reference

C ABI between Metatomic frontend and libmetatomic_engine.so. More...

#include <stddef.h>

Go to the source code of this file.

Classes

struct  RgpotMtaConfig
 Flat config (subset of MetatomicConfig). More...

Macros

#define RGPOT_MTA_API   __attribute__((visibility("default")))
#define RGPOT_MTA_ABI_VERSION   1

Typedefs

typedef struct RgpotMtaPot RgpotMtaPot
typedef struct RgpotMtaConfig RgpotMtaConfig
 Flat config (subset of MetatomicConfig).

Functions

RGPOT_MTA_API int rgpot_mta_abi_version (void)
RGPOT_MTA_API RgpotMtaPotrgpot_mta_create (const RgpotMtaConfig *cfg, char *errbuf, size_t errlen)
RGPOT_MTA_API void rgpot_mta_destroy (RgpotMtaPot *pot)
RGPOT_MTA_API int rgpot_mta_force (RgpotMtaPot *pot, long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)
 Energy + forces.
RGPOT_MTA_API int rgpot_mta_available (void)

Detailed Description

C ABI between Metatomic frontend and libmetatomic_engine.so.

Units: positions Angstrom, energy eV, forces eV/Angstrom (eOn/rgpot host). Mirrors the NWChem engine split: thin consumer, optional heavy torch engine.

Definition in file metatomic_c_abi.h.

Macro Definition Documentation

◆ RGPOT_MTA_ABI_VERSION

#define RGPOT_MTA_ABI_VERSION   1

Definition at line 43 of file metatomic_c_abi.h.

◆ RGPOT_MTA_API

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

Definition at line 23 of file metatomic_c_abi.h.

Typedef Documentation

◆ RgpotMtaConfig

typedef struct RgpotMtaConfig RgpotMtaConfig

Flat config (subset of MetatomicConfig).

NULL strings => empty/default.

◆ RgpotMtaPot

typedef struct RgpotMtaPot RgpotMtaPot

Definition at line 26 of file metatomic_c_abi.h.

Function Documentation

◆ rgpot_mta_abi_version()

RGPOT_MTA_API int rgpot_mta_abi_version ( void )

Definition at line 29 of file MetatomicEngineAbi.cpp.

29{ return RGPOT_MTA_ABI_VERSION; }
#define RGPOT_MTA_ABI_VERSION

◆ rgpot_mta_available()

RGPOT_MTA_API int rgpot_mta_available ( void )

Definition at line 30 of file MetatomicEngineAbi.cpp.

30{ return 1; }

◆ rgpot_mta_create()

RGPOT_MTA_API RgpotMtaPot * rgpot_mta_create ( const RgpotMtaConfig * cfg,
char * errbuf,
size_t errlen )

Definition at line 32 of file MetatomicEngineAbi.cpp.

33 {
34 if (!cfg || !cfg->model_path || !cfg->model_path[0]) {
35 set_err(errbuf, errlen, "model_path required");
36 return nullptr;
37 }
38 try {
39 Parameters p;
40 p.potential_options.potential = PotType::METATOMIC;
41 auto &o = p.metatomic_options;
42 o.model_path = cfg->model_path;
43 o.device = nz(cfg->device)[0] ? cfg->device : "cpu";
44 o.length_unit = nz(cfg->length_unit)[0] ? cfg->length_unit : "angstrom";
45 o.extensions_directory = nz(cfg->extensions_directory);
46 o.check_consistency = cfg->check_consistency != 0;
47 o.uncertainty_threshold = cfg->uncertainty_threshold;
48 o.deterministic = !cfg->torch_determinism_strict; // map: strict => det
49 o.deterministic_strict = cfg->torch_determinism_strict != 0;
50 auto pot = std::make_unique<RgpotMtaPot>();
51 pot->impl = std::make_unique<MetatomicPotential>(p);
52 return pot.release();
53 } catch (const std::exception &e) {
54 set_err(errbuf, errlen, e.what());
55 return nullptr;
56 } catch (...) {
57 set_err(errbuf, errlen, "create failed");
58 return nullptr;
59 }
60}
static void set_err(char *b, size_t n, const char *m)
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 * extensions_directory
double uncertainty_threshold
const char * device
const char * model_path
const char * length_unit
int torch_determinism_strict
0=Fast, 1=Strict

◆ rgpot_mta_destroy()

RGPOT_MTA_API void rgpot_mta_destroy ( RgpotMtaPot * pot)

Definition at line 62 of file MetatomicEngineAbi.cpp.

62{ delete pot; }

◆ rgpot_mta_force()

RGPOT_MTA_API int rgpot_mta_force ( RgpotMtaPot * pot,
long nAtoms,
const double * positions,
const int * atomicNrs,
double * forces,
double * energy,
double * variance,
const double * box )

Energy + forces.

Returns 0 on success. variance may be NULL.

Definition at line 64 of file MetatomicEngineAbi.cpp.

66 {
67 if (!pot || !pot->impl || !positions || !atomicNrs || !forces || !energy ||
68 !box)
69 return 1;
70 try {
71 pot->impl->force(nAtoms, positions, atomicNrs, forces, energy, variance,
72 box);
73 return 0;
74 } catch (...) {
75 return 2;
76 }
77}
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