91 void virtual force(
long nAtoms,
const double *positions,
const int *atomicNrs,
92 double *forces,
double *energy,
double *variance,
93 const double *box) = 0;
96 void force(std::span<const double> positions, std::span<const int> atomicNrs,
97 std::span<double> forces,
double *energy,
double *variance,
98 std::span<const double> box) {
99 if (positions.size() % 3 != 0 || positions.size() / 3 != atomicNrs.size() ||
100 forces.size() != positions.size() || box.size() != 9) {
101 throw std::invalid_argument(
"Potential::force span size mismatch");
103 force(
static_cast<long>(atomicNrs.size()), positions.data(),
104 atomicNrs.data(), forces.data(), energy, variance, box.data());
115 std::tuple<double, AtomMatrix>
124 [[nodiscard]]
virtual unsigned long long surfaceEpoch() const noexcept {
133 [[deprecated(
"Override hessianRange() instead.")]]
134 [[nodiscard]]
virtual double finiteCutoff() const noexcept {
return 0.0; }
138 [[nodiscard]]
virtual bool isSurrogate() const noexcept {
return false; }
151 [[nodiscard]]
virtual bool isThreadSafe() const noexcept {
return true; }
197 virtual void bindBand(
const std::vector<std::shared_ptr<Matter>> &) {}
213 throw std::logic_error(
"Potential::cauchyStress is not implemented");
224 const double *
const *positions,
225 const int *
const *atomicNrs,
226 double *
const *forces,
double *energies,
227 double *variances,
const double *
const *boxes,
228 const long *owners) {
230 forceBatch(nSystems, nAtoms, positions, atomicNrs, forces, energies,
235 const double *
const *positions,
236 const int *
const *atomicNrs,
double *
const *forces,
237 double *energies,
double *variances,
238 const double *
const *boxes) {
239 for (
long i = 0; i < nSystems; i++) {
241 force(nAtoms, positions[i], atomicNrs[i], forces[i], &energies[i], &var,
260#if defined(__GNUC__) || defined(__clang__)
261#pragma GCC diagnostic push
262#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
266#pragma warning(disable : 4996)
272#if defined(__GNUC__) || defined(__clang__)
273#pragma GCC diagnostic pop
282[[nodiscard]] std::unique_ptr<Potential>
284[[nodiscard]] std::unique_ptr<Potential>
286[[nodiscard]] std::unique_ptr<Potential>
291[[nodiscard]]
inline std::shared_ptr<Potential>
293 return std::shared_ptr<Potential>(std::move(
pot));
301[[nodiscard]] std::shared_ptr<Potential>
Eigen::Matrix< double, 3, 3, eOnStorageOrder > Matrix3d
Eigen::Matrix< double, Eigen::Dynamic, 3, eOnStorageOrder > AtomMatrix
Clock::time_point TimePoint
~PotentialConstructionScope()
PotentialConstructionScope(IPotRegistry ®istry)
PotentialConstructionScope & operator=(const PotentialConstructionScope &)=delete
PotentialConstructionScope(const PotentialConstructionScope &)=delete
IPotRegistry & registry() const noexcept
The registry this potential charges its force calls to.
virtual bool computesStress() const noexcept
True when force() leaves a Cauchy stress that cauchyStress() can read until the next force() on this ...
std::atomic< size_t > forceCallCounter
virtual unsigned long long surfaceEpoch() const noexcept
Host-visible surface generation.
virtual bool supportsBatchEvaluation() const noexcept
Whether this potential supports batched evaluation of N systems in a single call.
virtual void forceBatchOwned(long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes, const long *owners)
Evaluate forces for N systems in a single call.
Potential(PotType a_ptype, IPotRegistry ®istry)
Test seam: injected registry, no process-default get() counters.
virtual void force(long nAtoms, const double *positions, const int *atomicNrs, double *forces, double *energy, double *variance, const double *box)=0
void force(std::span< const double > positions, std::span< const int > atomicNrs, std::span< double > forces, double *energy, double *variance, std::span< const double > box)
C++ call site: size-checked view over the raw FFI force().
virtual std::shared_ptr< Potential > clonePotential() const
Independent instance that does not reload from disk.
virtual bool forwardsStoredCell() const noexcept
A host that owns the cell reads the stored matrix.
PotLayout
How the pot is executed. Combine with bitwise or.
virtual double hessianRange() const noexcept
Distance beyond which every Hessian block between two atoms is exactly zero, in position length units...
virtual bool isSharedInstanceThreadSafe() const noexcept
Conservative gate for sharing one Potential instance across threads.
virtual bool isSurrogate() const noexcept
Whether this is a surrogate (GP) potential.
virtual bool needsPerImageInstance() const noexcept
Whether NEB should create separate Potential instances per image for true parallel force evaluation.
virtual double finiteCutoff() const noexcept
Finite interaction range in position length units.
virtual Matrix3d cauchyStress() const
Cauchy stress in eV/Angstrom^3.
std::tuple< double, AtomMatrix > get_ef(const AtomMatrix &pos, const VectorXi &atmnrs, const Matrix3d &box)
virtual void forceBatch(long nSystems, long nAtoms, const double *const *positions, const int *const *atomicNrs, double *const *forces, double *energies, double *variances, const double *const *boxes)
std::shared_ptr< RegistryLifetime > lifetime_
virtual unsigned layoutFlags() const noexcept
virtual bool requiresIsolatedMoleculeLayout() const noexcept
True for molecular QM / non-PBC backends (NWChem socket, ASE ORCA/NWChem, …).
virtual void bindBand(const std::vector< std::shared_ptr< Matter > > &)
NEB calls this with the finished band before the first force evaluation, so a host surface can name e...
IPotRegistry::TimePoint m_created_at
void recordForceCall() noexcept
Charge one evaluated geometry to this potential and its owning registry.
virtual void setFixedMask(long nAtoms, const double *isFixed)
Optional frozen-atom mask (nAtoms*3, 1.0 = fixed).
virtual bool isThreadSafe() const noexcept
Whether this potential's force() can be called from multiple threads on the SAME instance.
Potential(PotType a_ptype)
Production default: construction-scope registry, else PotRegistry::get().
Move-only composition root for process resources (dlopen loaders and the potential registry).
std::shared_ptr< Potential > makeImagePotential(const Potential &pot, const Parameters ¶ms)
A separate instance of pot for one image of a band, dimer or pair of minimizations: a clone when the ...
std::unique_ptr< Potential > makePotential(const Parameters ¶ms)
Exclusive ownership.
std::shared_ptr< Potential > sharePotential(std::unique_ptr< Potential > pot)
Multi-owner boundary: one instance observed by several Matters, images, or a binding.
RAII resource manager for the ARTn C library with global synchronization.