93{
94 if (
pot ==
nullptr ||
pot->impl ==
nullptr || positions ==
nullptr ||
95 atomicNrs == nullptr || forces == nullptr || energy == nullptr ||
96 box == nullptr || nAtoms <= 0) {
97 return 1;
98 }
99 try {
100 std::vector<double> R(positions, positions + 3 * nAtoms);
101 std::vector<double> cell(box, box + 9);
102 if (transform != nullptr) {
103 const int rc =
104 transform(transform_user, nAtoms, R.data(), cell.data());
105 if (rc != 0) return rc;
106 }
107 std::vector<double> Fbuf(static_cast<size_t>(nAtoms) * 3);
108 rgpot::ForceOut
out{Fbuf.data(), 0.0, 0.0};
109 const rgpot::ForceInput in{static_cast<size_t>(nAtoms), R.data(),
110 atomicNrs, cell.data()};
111 pot->impl->forceImpl(in, &
out);
112 *energy =
out.energy;
114 std::memcpy(forces, Fbuf.data(), Fbuf.size() * sizeof(double));
115 return 0;
116 } catch (const rgpot::CP2KScfError& e) {
117
118
119 std::fprintf(stderr, "rgpot_engine_force(cp2k): %s\n", e.what());
120 return 2;
121 } catch (const std::exception& e) {
122 std::fprintf(stderr, "rgpot_engine_force(cp2k): %s\n", e.what());
123 return -1;
124 } catch (...) {
125 std::fprintf(stderr, "rgpot_engine_force(cp2k): unknown exception\n");
126 return -1;
127 }
128}
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
double variance(const Weights &w, const Matrix &covariance)