5#ifndef GPR_AUXILIARY_MINIMAGE_H_
6#define GPR_AUXILIARY_MINIMAGE_H_
22[[nodiscard]]
inline bool cellIsZero(
const double cell[9])
noexcept
24 for (
int i = 0; i < 9; ++i) {
25 if (cell[i] != 0.0)
return false;
30[[nodiscard]]
inline bool cellIsZero(
const std::array<double, 9>& cell)
noexcept
41 constexpr double L = 25.0;
42 constexpr double tol = 1.0e-12;
43 if (cell[0] != L || cell[4] != L || cell[8] != L)
return false;
44 return std::abs(cell[1]) <= tol && std::abs(cell[2]) <= tol &&
45 std::abs(cell[3]) <= tol && std::abs(cell[5]) <= tol &&
46 std::abs(cell[6]) <= tol && std::abs(cell[7]) <= tol;
50 const std::array<double, 9>& cell)
noexcept
62 const std::array<double, 9>& cell)
noexcept
71 for (
int i = 0; i < 9; ++i)
77 const double cell[9])
noexcept
79 std::array<double, 9>
out{};
85 const std::array<double, 9>& cell)
noexcept
94 const double cell[9])
noexcept
96 std::array<bool, 3> periodic{};
97 for (
int row = 0; row < 3; ++row)
98 periodic[row] = cell[3 * row] != 0.0 || cell[3 * row + 1] != 0.0 ||
99 cell[3 * row + 2] != 0.0;
116 for (
int row = 0; row < 3; ++row) {
117 const double* src = cell + 3 * row;
118 double* dst = row == 0 ? &box.ax : row == 1 ? &box.bx : &box.cx;
124 if (minimage_unique_image_radius(&box, &radius) != 0)
return 0.0;
129 const std::array<double, 9>& cell)
noexcept
137 const std::array<bool, 3>& periodic)
noexcept
139 for (
int row = 0; row < 3; ++row)
141 for (
int k = 0; k < 3; ++k)
142 cell[3 * row + k] = 0.0;
165 explicit PairBox(
const std::array<double, 9>& cell)
175 std::copy(cell, cell + 9, rows);
183 periodic_ = axes_[0] || axes_[1] || axes_[2];
184 partial_ = periodic_ && !(axes_[0] && axes_[1] && axes_[2]);
185 if (!periodic_)
return;
187 if (minimage_cell_from_ase(cell,
nullptr, &box_) != 0)
188 throwLastError(
"minimage: cell_from_ase failed");
191 const int mask[3] = {axes_[0] ? 1 : 0, axes_[1] ? 1 : 0,
193 if (minimage_pbc_cell_from_ase(cell, mask,
nullptr, &partial_box_) != 0)
194 throwLastError(
"minimage: pbc_cell_from_ase failed");
210 void displacement(
const double p[3],
const double q[3],
double dr[3])
const
219 if (minimage_displacement_euclidean(&box_, p, q, dr) != 0)
220 throwLastError(
"minimage: displacement failed");
223 if (minimage_displacement_euclidean_pbc(&partial_box_, p, q, dr) != 0)
224 throwLastError(
"minimage: displacement failed");
228 const Eigen::Vector3d& q)
const
235 [[nodiscard]]
double dist2(
const Eigen::Vector3d& p,
236 const Eigen::Vector3d& q)
const
238 if (!periodic_)
return (q - p).squaredNorm();
243 [[noreturn]]
static void throwLastError(
const char* fallback)
245 const char* msg = minimage_last_error();
246 throw std::invalid_argument(msg ? std::string(msg)
247 : std::string(fallback));
250 bool periodic_ =
false;
251 bool partial_ =
false;
252 std::array<bool, 3> axes_{};
254 mi_pbc_cell partial_box_{};
260 const PairBox* box,
const Eigen::VectorXd& from,
const Eigen::VectorXd& to)
262 if (from.size() != to.size())
263 throw std::invalid_argument(
"minimum-image displacement size mismatch");
264 if (box ==
nullptr || !box->
periodic())
return to - from;
265 if (from.size() % 3 != 0)
266 throw std::invalid_argument(
267 "minimum-image displacement needs 3N coordinates");
268 Eigen::VectorXd delta(from.size());
269 const int n_atoms =
static_cast<int>(from.size() / 3);
270 for (
int atom = 0; atom < n_atoms; ++atom) {
271 const Eigen::Vector3d p = from.segment<3>(3 * atom);
272 const Eigen::Vector3d q = to.segment<3>(3 * atom);
PairBox(const double cell[9], const std::array< bool, 3 > &periodic)
void reset(const double cell[9])
const std::array< bool, 3 > & periodicAxes() const noexcept
The periodic axes, a, b, c.
bool periodic() const noexcept
Some axis is periodic.
PairBox(const std::array< double, 9 > &cell)
PairBox(const double cell[9])
void displacement(const double p[3], const double q[3], double dr[3]) const
Displacement from p to q. Cartesian q - p when the cell is zero.
double dist2(const Eigen::Vector3d &p, const Eigen::Vector3d &q) const
Eigen::Vector3d displacement(const Eigen::Vector3d &p, const Eigen::Vector3d &q) const
eon_relax_band_t eon_relax_surface_fn void eon_relax_outcome_t * out
bool cellIsVacuumBox(const double cell[9]) noexcept
bool cellIsZero(const double cell[9]) noexcept
Isolated molecule: every entry of the ASE-style 3x3 cell is zero.
void zeroOpenAxes(double cell[9], const std::array< bool, 3 > &periodic) noexcept
double uniqueImageRadius(const double cell[9]) noexcept
bool cellIsMicLattice(const double cell[9]) noexcept
Nonzero ASE 3x3 that is not the 25 A vacuum convention.
bool copyMicLattice(double dest[9], const double src[9]) noexcept
Copy src onto dest only when src is a MIC lattice.
std::array< double, 9 > micLattice(const double cell[9]) noexcept
std::array< bool, 3 > cellPeriodicAxes(const double cell[9]) noexcept
Eigen::VectorXd flatMinimumImageDisplacement(const PairBox *box, const Eigen::VectorXd &from, const Eigen::VectorXd &to)
Gaussian-process regression, kernels, priors, and the searches that run on the surrogate.