Loading...
Searching...
No Matches
gpr::geometry::ElementPairContactFloor Class Reference

#include <gpr/auxiliary/ElementPairContactFloor.h>

Public Member Functions

 ElementPairContactFloor ()=default
 ElementPairContactFloor (double scalar_floor, std::vector< int > atomic_numbers)
bool active () const noexcept
double scalar () const noexcept
 The legacy scalar bound (0 when disabled).
double cutoff () const noexcept
 The largest pair floor: no pair beyond it can violate the domain.
std::size_t atomCount () const noexcept
double floor (std::size_t i, std::size_t j) const noexcept
 Floor of the pair (i, j); the scalar bound when a Z is unknown.
double elementFloor (int Zi, int Zj) const noexcept
void calibrateToGeometries (const std::vector< Eigen::VectorXd > &references, const std::array< double, 9 > &cell, Eigen::Index moving_count=-1)
double minimumRatio (const Eigen::VectorXd &positions, const std::array< double, 9 > &cell, Eigen::Index moving_count=-1) const
bool violated (const Eigen::VectorXd &positions, const std::array< double, 9 > &cell, Eigen::Index moving_count=-1) const
 True when some moving pair sits below its floor.
Eigen::VectorXd limitStep (const Eigen::VectorXd &positions, const Eigen::VectorXd &proposed, const std::array< double, 9 > &cell, Eigen::Index moving_count=-1) const

Detailed Description

Contact floor of a molecular domain, one distance per atom pair.

The scalar floor is the legacy endpoint bound (r_limit times the shortest pair in the endpoints or the seed). It is one number for every pair, so a reaction that forms H2 (0.74 A) leaves every heavy-atom pair free down to 0.3 A: on H2CO, HCN+H2 and the formamide cation the band relaxed C-O and C-N to 0.54-0.67 A, the oracle answered with 100-130 eV/A, and the amplitude fit never recovered. With atomic numbers the floor of a pair is at least the radius at which the ZBL prior mean's repulsion switches on (0.75 of the Cordero covalent sum): the shortest distance real bonding reaches, and the edge of the domain in which the residual process is the whole model.

The covalent radii describe chemical bonding, not every potential: a Lennard-Jones solid labelled Ar with sigma = 1 A holds its atoms 1.12 A apart, inside the 1.59 A Ar-Ar onset. calibrateToGeometries checks the floor against geometries the potential itself treats as ordinary (the relaxed endpoints). A pair type whose shortest contact there sits below its onset takes that contact in place of the covalent sum, keeping the same onset fraction of it; pair types the endpoints respect keep their covalent floor.

Definition at line 40 of file ElementPairContactFloor.h.

Constructor & Destructor Documentation

◆ ElementPairContactFloor() [1/2]

gpr::geometry::ElementPairContactFloor::ElementPairContactFloor ( )
default

◆ ElementPairContactFloor() [2/2]

gpr::geometry::ElementPairContactFloor::ElementPairContactFloor ( double scalar_floor,
std::vector< int > atomic_numbers )
inline

Definition at line 43 of file ElementPairContactFloor.h.

45 : scalar_(scalar_floor > 0.0 ? scalar_floor : 0.0),
46 atomic_numbers_(std::move(atomic_numbers))
47 {
48 for (std::size_t i = 0; i < atomic_numbers_.size(); ++i)
49 for (std::size_t j = i + 1; j < atomic_numbers_.size(); ++j)
50 cutoff_ = std::max(cutoff_, floor(i, j));
51 cutoff_ = std::max(cutoff_, scalar_);
52 }
double floor(std::size_t i, std::size_t j) const noexcept
Floor of the pair (i, j); the scalar bound when a Z is unknown.

Member Function Documentation

◆ active()

bool gpr::geometry::ElementPairContactFloor::active ( ) const
inlinenodiscardnoexcept

Definition at line 54 of file ElementPairContactFloor.h.

55 {
56 return cutoff_ > 0.0;
57 }

◆ atomCount()

std::size_t gpr::geometry::ElementPairContactFloor::atomCount ( ) const
inlinenodiscardnoexcept

Definition at line 71 of file ElementPairContactFloor.h.

72 {
73 return atomic_numbers_.size();
74 }

◆ calibrateToGeometries()

void gpr::geometry::ElementPairContactFloor::calibrateToGeometries ( const std::vector< Eigen::VectorXd > & references,
const std::array< double, 9 > & cell,
Eigen::Index moving_count = -1 )
inline

Recalibrate the element floors against reference geometries (each laid out like the positions minimumRatio takes) that the potential treats as ordinary. For each pair type with a moving pair below its onset, the shortest such contact replaces the covalent sum, so the floor becomes the same onset fraction of that contact. Floors the references respect are left alone, as is the scalar bound.

Definition at line 103 of file ElementPairContactFloor.h.

106 {
107 if (atomic_numbers_.empty()) return;
108 std::vector<std::pair<std::pair<int, int>, double>> shortest;
109 for (const Eigen::VectorXd& positions: references) {
110 if (positions.size() % 3 != 0 || !positions.allFinite() ||
111 positions.size() / 3 !=
112 static_cast<Eigen::Index>(atomic_numbers_.size()))
113 continue;
114 const Eigen::Index count = positions.size() / 3;
115 const Eigen::Index moving =
116 moving_count < 0 ? count : std::min(moving_count, count);
117 const PairBox box(cell);
118 for (const auto& pair:
119 cutoffNeighbors(positions.data(), count, cell,
120 box.periodicAxes(), 1.125 * cutoff_)) {
121 if (pair.first == pair.second ||
122 std::min(pair.first, pair.second) >=
123 static_cast<std::size_t>(moving))
124 continue;
125 const int zi = atomic_numbers_[pair.first];
126 const int zj = atomic_numbers_[pair.second];
127 const double onset =
129 if (!(onset > 0.0)) continue;
130 const double r =
131 std::sqrt(box.dist2(positions.segment<3>(3 * pair.first),
132 positions.segment<3>(3 * pair.second)));
133 if (!(r > 0.0) || r >= onset) continue;
134 const std::pair<int, int> key{std::min(zi, zj),
135 std::max(zi, zj)};
136 auto it = std::find_if(
137 shortest.begin(), shortest.end(),
138 [&](const auto& entry) { return entry.first == key; });
139 if (it == shortest.end())
140 shortest.emplace_back(key, r);
141 else
142 it->second = std::min(it->second, r);
143 }
144 }
145 for (const auto& shortest_entry: shortest) {
146 const std::pair<int, int>& key = shortest_entry.first;
147 const double contact = shortest_entry.second;
148 const double covalent_sum =
151 if (!(covalent_sum > 0.0)) continue;
153 key.first, key.second);
154 const double calibrated = onset * contact / covalent_sum;
155 auto it = std::find_if(
156 calibrated_.begin(), calibrated_.end(),
157 [&](const auto& entry) { return entry.first == key; });
158 if (it == calibrated_.end())
159 calibrated_.emplace_back(key, calibrated);
160 else
161 it->second = std::min(it->second, calibrated);
162 }
163 cutoff_ = scalar_;
164 for (std::size_t i = 0; i < atomic_numbers_.size(); ++i)
165 for (std::size_t j = i + 1; j < atomic_numbers_.size(); ++j)
166 cutoff_ = std::max(cutoff_, floor(i, j));
167 }
static double repulsionOnsetRadius(int Zi, int Zj) noexcept
static double covalentRadius(int Z) noexcept
Cordero single-bond covalent radius (Angstrom) of atomic number Z.
std::vector< CutoffPair > cutoffNeighbors(const double *positions, std::size_t count, const std::array< double, 9 > &cell, const std::array< bool, 3 > &periodic, double cutoff)

◆ cutoff()

double gpr::geometry::ElementPairContactFloor::cutoff ( ) const
inlinenodiscardnoexcept

The largest pair floor: no pair beyond it can violate the domain.

Definition at line 66 of file ElementPairContactFloor.h.

67 {
68 return cutoff_;
69 }

◆ elementFloor()

double gpr::geometry::ElementPairContactFloor::elementFloor ( int Zi,
int Zj ) const
inlinenodiscardnoexcept

Element floor of the pair type (Zi, Zj) without the scalar bound: the ZBL repulsion onset, or the calibrated value for a pair type the reference geometries showed closer than its onset.

Definition at line 89 of file ElementPairContactFloor.h.

90 {
91 const std::pair<int, int> key{std::min(Zi, Zj), std::max(Zi, Zj)};
92 for (const auto& entry: calibrated_)
93 if (entry.first == key) return entry.second;
95 }

◆ floor()

double gpr::geometry::ElementPairContactFloor::floor ( std::size_t i,
std::size_t j ) const
inlinenodiscardnoexcept

Floor of the pair (i, j); the scalar bound when a Z is unknown.

Definition at line 77 of file ElementPairContactFloor.h.

78 {
79 double bound = scalar_;
80 if (i < atomic_numbers_.size() && j < atomic_numbers_.size())
81 bound = std::max(
82 bound, elementFloor(atomic_numbers_[i], atomic_numbers_[j]));
83 return bound;
84 }
double elementFloor(int Zi, int Zj) const noexcept

◆ limitStep()

Eigen::VectorXd gpr::geometry::ElementPairContactFloor::limitStep ( const Eigen::VectorXd & positions,
const Eigen::VectorXd & proposed,
const std::array< double, 9 > & cell,
Eigen::Index moving_count = -1 ) const
inlinenodiscard

Keep the full Cartesian step inside the contact domain. Checking only the endpoint permits a long step to pass through a contact and emerge on the other side with a feasible pair distance.

Definition at line 217 of file ElementPairContactFloor.h.

220 {
221 if (!active()) return proposed;
222 if (positions.size() != proposed.size() || positions.size() % 3 != 0 ||
223 !positions.allFinite() || !proposed.allFinite())
224 return positions;
225
226 const Eigen::Index count = positions.size() / 3;
227 if (moving_count < 0) moving_count = count;
228 moving_count = std::min(moving_count, count);
229 const double start_ratio = minimumRatio(positions, cell, moving_count);
230 const Eigen::VectorXd displacement = proposed - positions;
231 double maximum_atom_step = 0.0;
232 for (Eigen::Index atom = 0; atom < count; ++atom)
233 maximum_atom_step = std::max(
234 maximum_atom_step, displacement.segment<3>(3 * atom).norm());
235
236 Eigen::VectorXd path_endpoint = proposed;
237 const double candidate_cutoff = cutoff_ + 2.0 * maximum_atom_step;
238 if (std::isfinite(candidate_cutoff) && candidate_cutoff > 0.0) {
239 const std::array<bool, 3> periodic = PairBox(cell).periodicAxes();
240 double first_contact = 1.0;
241 for (const auto& pair: cutoffNeighbors(
242 positions.data(), static_cast<std::size_t>(count), cell,
243 periodic, candidate_cutoff)) {
244 if (pair.first == pair.second ||
245 std::min(pair.first, pair.second) >=
246 static_cast<std::size_t>(moving_count))
247 continue;
248 const double pair_floor = floor(pair.first, pair.second);
249 if (!(pair_floor > 0.0)) continue;
250
251 const Eigen::Index first =
252 static_cast<Eigen::Index>(pair.first);
253 const Eigen::Index second =
254 static_cast<Eigen::Index>(pair.second);
255 const Eigen::Vector3d relative =
256 positions.segment<3>(3 * second) -
257 positions.segment<3>(3 * first) +
258 pair.shift[0] * Eigen::Vector3d(cell[0], cell[1], cell[2]) +
259 pair.shift[1] * Eigen::Vector3d(cell[3], cell[4], cell[5]) +
260 pair.shift[2] * Eigen::Vector3d(cell[6], cell[7], cell[8]);
261 const double relative_distance = relative.norm();
262 const double bound =
263 std::min(pair_floor * start_ratio, relative_distance);
264 if (!(bound > 0.0)) continue;
265 const Eigen::Vector3d relative_step =
266 displacement.segment<3>(3 * second) -
267 displacement.segment<3>(3 * first);
268 const double quadratic = relative_step.squaredNorm();
269 if (!(quadratic > 0.0) || !std::isfinite(quadratic)) continue;
270 const double linear = 2.0 * relative.dot(relative_step);
271 const double constant =
272 std::max(0.0, relative.squaredNorm() - bound * bound);
273 const double discriminant =
274 linear * linear - 4.0 * quadratic * constant;
275 if (!(discriminant >= 0.0) || !std::isfinite(discriminant))
276 continue;
277 double entry = std::numeric_limits<double>::infinity();
278 if (constant == 0.0) {
279 if (linear < 0.0) entry = 0.0;
280 } else {
281 const double denominator =
282 -linear + std::sqrt(discriminant);
283 if (denominator > 0.0) entry = 2.0 * constant / denominator;
284 }
285 if (entry >= 0.0 && entry < first_contact)
286 first_contact = std::nextafter(entry, 0.0);
287 }
288 if (first_contact < 1.0)
289 path_endpoint = positions + first_contact * displacement;
290 }
291
293 positions, path_endpoint, 1.0, [&](const Eigen::VectorXd& point) {
294 return minimumRatio(point, cell, moving_count);
295 });
296 }
double minimumRatio(const Eigen::VectorXd &positions, const std::array< double, 9 > &cell, Eigen::Index moving_count=-1) const
Eigen::VectorXd limitPairDistanceStep(const Eigen::VectorXd &positions, const Eigen::VectorXd &proposed, double floor, Distance &&distance)

◆ minimumRatio()

double gpr::geometry::ElementPairContactFloor::minimumRatio ( const Eigen::VectorXd & positions,
const std::array< double, 9 > & cell,
Eigen::Index moving_count = -1 ) const
inlinenodiscard

Smallest ratio of a pair distance to its floor over the moving pairs, capped at one. Below one the geometry is outside the domain; the ratio is the metric limitPairDistanceStep bisects against a floor of one. Frozen-frozen pairs (indices at or beyond moving_count) do not constrain the moving coordinates.

Definition at line 174 of file ElementPairContactFloor.h.

177 {
178 if (!active()) return 1.0;
179 if (positions.size() % 3 != 0 || !positions.allFinite()) return 0.0;
180 const Eigen::Index count = positions.size() / 3;
181 if (moving_count < 0) moving_count = count;
182 const PairBox box(cell);
183 const std::array<bool, 3> periodic = box.periodicAxes();
184 double minimum = 1.0;
185 // Candidates come from the neighbour list's own distance; a pair
186 // sitting within rounding of its floor must still be ranked by
187 // the minimum-image distance below, so the list reaches past the
188 // largest floor. A pair beyond its floor leaves the minimum at one.
189 const double candidate_cutoff = 1.125 * cutoff_;
190 for (const auto& pair: cutoffNeighbors(positions.data(), count, cell,
191 periodic, candidate_cutoff)) {
192 if (pair.first == pair.second ||
193 std::min(pair.first, pair.second) >=
194 static_cast<std::size_t>(moving_count))
195 continue;
196 const double bound = floor(pair.first, pair.second);
197 if (!(bound > 0.0)) continue;
198 const double r =
199 std::sqrt(box.dist2(positions.segment<3>(3 * pair.first),
200 positions.segment<3>(3 * pair.second)));
201 minimum = std::min(minimum, r / bound);
202 }
203 return minimum;
204 }

◆ scalar()

double gpr::geometry::ElementPairContactFloor::scalar ( ) const
inlinenodiscardnoexcept

The legacy scalar bound (0 when disabled).

Definition at line 60 of file ElementPairContactFloor.h.

61 {
62 return scalar_;
63 }

◆ violated()

bool gpr::geometry::ElementPairContactFloor::violated ( const Eigen::VectorXd & positions,
const std::array< double, 9 > & cell,
Eigen::Index moving_count = -1 ) const
inlinenodiscard

True when some moving pair sits below its floor.

Definition at line 207 of file ElementPairContactFloor.h.

210 {
211 return active() && minimumRatio(positions, cell, moving_count) < 1.0;
212 }

The documentation for this class was generated from the following file: