269 :
impl_(std::make_unique<Impl>()) {
275 ::capnp::MallocMessageBuilder msg;
276 auto params = msg.initRoot<::NWChemParams>();
277 params.setBasis(opt.
basis);
278 params.setTheory(opt.
theory);
280 params.setCharge(opt.
charge);
288 if (!opt.
title.empty())
289 params.setTitle(opt.
title);
291 params.setMemoryMb(
static_cast<uint32_t
>(opt.
memory_mb));
294
296 if (block.empty()) {
297 if (const char *env = std::getenv("RGPOT_NWCHEM_INPUT_BLOCK"))
298 block = env;
299 }
300 if (block.empty()) {
302 block);
303 }
304 if (!block.empty()) {
305 auto blocks = params.initInputBlocks(1);
306 blocks.set(0, block);
307 }
308 impl_->nwchem = std::make_unique<rgpot::NWChemPot>(params.asReader());
309 if (!
impl_->nwchem->available())
310 throw std::runtime_error(
311 "RGPOT(nwchemc): engine not available (set NWCHEMC_LIBRARY / "
312 "RGPOT_NWCHEMC_ENGINE or [RgpotPot] engine_path)");
317 std::string local_error;
318 ::capnp::MallocMessageBuilder msg;
319 try {
321 } catch (const std::exception &ex) {
322 local_error = ex.what();
323 }
324
325
326 if (mpi_world_hint() <= 1 && !local_error.empty())
327 throw std::runtime_error(local_error);
328
329
330 if (mpi_world_hint() > 1 && !agree_construction(local_error)) {
332 throw std::runtime_error(
333 local_error.empty()
334 ? std::string(
335 "RGPOT(cpmdc): a rank failed before the calculator split")
336 : local_error);
337 }
338 if (!local_error.empty())
339 throw std::runtime_error(local_error);
340 if (::rgpot::calculatorsUseMpi()) {
341
342
343
344
345
346
347 const rgpot::CalculatorGroup g =
349 ::rgpot::finalizeMpiAtExit();
350 if (mpi_world_hint() > 1)
352 if (g.index < 0)
353 throw std::runtime_error(
354 "RGPOT(cpmdc): ranks_per_image=" +
356 " does not divide the MPI world into calculator groups");
357 impl_->groups = ::rgpot::calculatorCount();
358 impl_->group = g.index;
359 impl_->world = ::rgpot::calculatorWorldSize();
361 throw std::runtime_error(
362 "RGPOT(cpmdc): ranks_per_image needs rgpot built with MPI "
363 "(-Drgpot:with_mpi=enabled)");
364 }
365 try {
366 impl_->cpmd = std::make_unique<rgpot::CPMDPot>(
367 msg.getRoot<::CPMDParams>().asReader());
370 if (!
impl_->cpmd->available())
371 throw std::runtime_error(
372 "RGPOT(cpmdc): engine not available (set CPMDC_LIBRARY / "
373 "RGPOT_CPMDC_ENGINE or [RgpotPot] engine_path)");
374 } catch (const std::exception &ex) {
375 local_error = ex.what();
376 }
377
378
379 if (mpi_world_hint() > 1 && !agree_construction(local_error))
380 throw std::runtime_error(
381 local_error.empty()
382 ? std::string("RGPOT(cpmdc): a rank failed to load the engine")
383 : local_error);
384 if (!local_error.empty())
385 throw std::runtime_error(local_error);
390 MetatomicEngineOptions mopt;
400 impl_->metatomic = std::make_unique<MetatomicEngineLoader>(mopt);
401 if (!
impl_->metatomic->available())
402 throw std::runtime_error(
403 "RGPOT(metatomic): engine not available (set RGPOT_METATOMIC_ENGINE "
404 "or [RgpotPot] engine_path to librgpot_metatomic_engine.so)");
408 GenericEngineOptions gopt;
409 gopt.
library =
"libuma_engine.so";
410 gopt.
env_var =
"RGPOT_UMA_ENGINE";
414 {
415 ::capnp::MallocMessageBuilder msg;
416 auto params = msg.initRoot<::UmaParams>();
419 params.setDevice(opt.
device);
420 params.setCharge(opt.
charge);
422 const auto words = ::capnp::messageToFlatArray(msg);
423 const auto bytes = words.asBytes();
424 gopt.
config.assign(bytes.begin(), bytes.end());
425 }
426 impl_->uma = std::make_unique<GenericEngineLoader>(gopt);
427 if (!
impl_->uma->available())
428 throw std::runtime_error(
429 "RGPOT(uma): engine not available (set RGPOT_UMA_ENGINE or "
430 "[RgpotPot] engine_path to libuma_engine.so)");
435 XTBEngineOptions xopt;
444 impl_->xtb = std::make_unique<XTBEngineLoader>(xopt);
445 if (!
impl_->xtb->available())
446 throw std::runtime_error(
447 "RGPOT(xtb): engine not available (set RGPOT_XTB_ENGINE or "
448 "[RgpotPot] engine_path to librgpot_xtb_engine.so)");
449 } else {
450 throw std::runtime_error(
451 "RGPOT: unknown backend '" + opt.
backend +
452 "' (expected nwchemc, cpmdc, metatomic, uma, or xtb)");
453 }
454}
std::string nwchemDftInputBlock(const std::string &theory, const std::string &scfType, int multiplicity, const std::string &existing)
NWChem input block for a DFT theory.
void armGroupedExit() const
After MPI_Finalize, _Exit.
std::unique_ptr< Impl > impl_
::CPMDParams::Builder fillCpmdParams(::capnp::MallocMessageBuilder &msg, const RGPotEngineOptions &opt)
std::string tag
Backend tag for error messages ("uma", ...).
std::string env_var
Optional env var naming an explicit .so path (checked first).
std::vector< unsigned char > config
Cap'n Proto flat-array message (the engine's params struct on the shared Potentials....
std::string engine_path
Optional explicit .so path from config.
std::string library
Library basename to search for, e.g. "libuma_engine.so".
std::string extensions_directory
std::string engine_library
double xtb_electronic_temperature
bool torch_determinism_strict
double uncertainty_threshold
double electronic_temperature