83{
84 if (
pot ==
nullptr ||
pot->impl ==
nullptr || positions ==
nullptr ||
85 atomicNrs == nullptr || forces == nullptr || energy == nullptr ||
86 box == nullptr || nAtoms <= 0) {
87 return 1;
88 }
89 try {
90 std::vector<double> R(positions, positions + 3 * nAtoms);
91 std::vector<double> cell(box, box + 9);
92 if (transform != nullptr) {
93 const int rc =
94 transform(transform_user, nAtoms, R.data(), cell.data());
95 if (rc != 0) return rc;
96 }
97 std::vector<double> Fbuf(static_cast<size_t>(nAtoms) * 3);
98 rgpot::ForceOut
out{Fbuf.data(), 0.0, 0.0};
99 const rgpot::ForceInput in{static_cast<size_t>(nAtoms), R.data(),
100 atomicNrs, cell.data()};
101 pot->impl->forceImpl(in, &
out);
102 *energy =
out.energy;
104 std::memcpy(forces, Fbuf.data(), Fbuf.size() * sizeof(double));
105 return 0;
106 } catch (const std::exception& e) {
107 std::fprintf(stderr, "rgpot_engine_force(cpmd): %s\n", e.what());
108 return 2;
109 } catch (...) {
110 std::fprintf(stderr, "rgpot_engine_force(cpmd): unknown exception\n");
111 return 2;
112 }
113}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
double variance(const Weights &w, const Matrix &covariance)