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

Go to the source code of this file.

Classes

struct  RgpotMtaPot

Macros

#define RGPOT_MTA_ENGINE_BUILD

Functions

static const char * nz (const char *s)
static void set_err (char *b, size_t n, const char *m)
int rgpot_mta_abi_version (void)
int rgpot_mta_available (void)
RgpotMtaPotrgpot_mta_create (const RgpotMtaConfig *cfg, char *errbuf, size_t errlen)
void rgpot_mta_destroy (RgpotMtaPot *pot)
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.

Macro Definition Documentation

◆ RGPOT_MTA_ENGINE_BUILD

#define RGPOT_MTA_ENGINE_BUILD

Definition at line 6 of file MetatomicEngineAbi.cpp.

Function Documentation

◆ nz()

const char * nz ( const char * s)
static

Definition at line 21 of file MetatomicEngineAbi.cpp.

21{ return s ? s : ""; }

◆ rgpot_mta_abi_version()

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()

int rgpot_mta_available ( void )

Definition at line 30 of file MetatomicEngineAbi.cpp.

30{ return 1; }

◆ rgpot_mta_create()

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()

void rgpot_mta_destroy ( RgpotMtaPot * pot)

Definition at line 62 of file MetatomicEngineAbi.cpp.

62{ delete pot; }

◆ rgpot_mta_force()

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

◆ set_err()

void set_err ( char * b,
size_t n,
const char * m )
static

Definition at line 22 of file MetatomicEngineAbi.cpp.

22 {
23 if (b && n)
24 std::snprintf(b, n, "%s", m ? m : "unknown");
25}