Loading...
Searching...
No Matches
MetatomicCAbi.cpp File Reference
#include "eon/potentials/Metatomic/metatomic_c_abi.h"
#include "eon/potentials/Metatomic/MetatomicPotential.h"
#include <cstdio>
#include <exception>
#include <memory>
#include <string>

Go to the source code of this file.

Classes

struct  EonMtaPot

Macros

#define EON_MTA_BUILD

Functions

static const char * nz (const char *s)
static void set_err (char *errbuf, size_t errlen, const char *msg)
int eon_mta_abi_version (void)
 ABI version for loader checks.
EonMtaPot * eon_mta_pot_create (const EonMtaConfig *cfg, char *errbuf, size_t errlen)
 Create pot.
void eon_mta_pot_destroy (EonMtaPot *pot)
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.

Macro Definition Documentation

◆ EON_MTA_BUILD

#define EON_MTA_BUILD

Definition at line 8 of file MetatomicCAbi.cpp.

Function Documentation

◆ eon_mta_abi_version()

int eon_mta_abi_version ( void )

ABI version for loader checks.

Definition at line 32 of file MetatomicCAbi.cpp.

32{ return EON_MTA_ABI_VERSION; }
#define EON_MTA_ABI_VERSION

◆ eon_mta_pot_create()

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 34 of file MetatomicCAbi.cpp.

35 {
36 if (!cfg || !cfg->model_path || cfg->model_path[0] == '\0') {
37 set_err(errbuf, errlen, "eon_mta_pot_create: model_path is required");
38 return nullptr;
39 }
40 try {
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";
52 o.random_rotation = cfg->random_rotation != 0;
54 o.deterministic = cfg->deterministic != 0;
56 o.variant.base = nz(cfg->variant_base);
59 o.variant.force = nz(cfg->variant_force);
60
61 auto pot = std::make_unique<EonMtaPot>();
62 pot->impl = std::make_unique<MetatomicPotential>(o);
63 return pot.release();
64 } catch (const std::exception &e) {
65 set_err(errbuf, errlen, e.what());
66 return nullptr;
67 } catch (...) {
68 set_err(errbuf, errlen, "eon_mta_pot_create: unknown exception");
69 return nullptr;
70 }
71}
static void set_err(char *errbuf, size_t errlen, const char *msg)
static const char * nz(const char *s)
eonc::metatomic_options_t metatomic_options_t
Definition Parameters.h:77
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
struct eonc::metatomic_options_t::variants_t variant

◆ eon_mta_pot_destroy()

void eon_mta_pot_destroy ( EonMtaPot * pot)

Definition at line 73 of file MetatomicCAbi.cpp.

73 {
74 std::unique_ptr<EonMtaPot> owned(pot);
75}

◆ eon_mta_pot_force()

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 77 of file MetatomicCAbi.cpp.

79 {
80 if (!pot || !pot->impl || !positions || !atomicNrs || !forces || !energy ||
81 !box) {
82 return 1;
83 }
84 try {
85 pot->impl->force(nAtoms, positions, atomicNrs, forces, energy, variance,
86 box);
87 return 0;
88 } catch (...) {
89 return 2;
90 }
91}
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

◆ nz()

const char * nz ( const char * s)
static

Definition at line 22 of file MetatomicCAbi.cpp.

22{ return s ? s : ""; }

◆ set_err()

void set_err ( char * errbuf,
size_t errlen,
const char * msg )
static

Definition at line 24 of file MetatomicCAbi.cpp.

24 {
25 if (!errbuf || errlen == 0)
26 return;
27 std::snprintf(errbuf, errlen, "%s", msg ? msg : "unknown error");
28}