36{
38 const Eigen::Index n_mov = configuration.
atoms_mov.
type.size();
40 const Eigen::Index n_conf = positions.rows();
41 const Eigen::Index dof = 3 * n_mov;
42 if (n_conf <= 0 || n_mov <= 0 || positions.cols() < dof ||
43 configuration.
n_pt <= 0)
44 return false;
45 if (far_radius > 0.0) {
47 configuration, far_radius);
48 const Eigen::Index features = rows.front().size();
53 geometry.grad.resize(n_conf, 3 * features);
54 for (const auto& feature: rows.front())
55 geometry.pairs.push_back({feature.first,
56 feature.second < n_mov
57 ? feature.second
58 : -1 - (feature.second - n_mov),
59 feature.type});
60 for (Eigen::Index c = 0; c < n_conf; ++c) {
61 if (static_cast<Eigen::Index>(rows[c].size()) != features)
62 throw std::logic_error(
63 "far-field feature vocabulary changed across rows");
64 for (Eigen::Index f = 0; f < features; ++f) {
65 geometry.
q(c, f) = rows[c][f].value;
66 geometry.
grad.block(c, 3 * f, 1, 3) =
67 rows[c][f].gradient.transpose();
68 }
69 }
70 geometry.
valid =
true;
71 return true;
72 }
73 std::vector<Pair> pairs;
74 pairs.reserve(
75 static_cast<std::size_t>(n_mov * (n_mov - 1) / 2 + n_mov * n_fro));
76 for (Eigen::Index j = 0; j + 1 < n_mov; ++j) {
77 for (Eigen::Index i = j + 1; i < n_mov; ++i) {
81 if (!activePairtype(configuration, pt)) continue;
82 pairs.push_back(
Pair{i, j,
static_cast<Eigen::Index
>(pt)});
83 }
84 }
85 for (Eigen::Index j = 0; j < n_mov; ++j) {
86 for (Eigen::Index i = 0; i < n_fro; ++i) {
90 if (!activePairtype(configuration, pt)) continue;
91
92 pairs.push_back(
Pair{j, -1 - i,
static_cast<Eigen::Index
>(pt)});
93 }
94 }
95 const Eigen::Index n_pairs = static_cast<Eigen::Index>(pairs.size());
96 if (n_pairs == 0) return false;
97
98 const geometry::PairBox box(configuration.
cell);
101 geometry.
q.resize(n_conf, n_pairs);
102 geometry.
grad.resize(n_conf, 3 * n_pairs);
104 for (Eigen::Index c = 0; c < n_conf; ++c) {
105 for (Eigen::Index f = 0; f < n_pairs; ++f) {
106 const Pair& pair = pairs[
static_cast<std::size_t
>(f)];
107 const Eigen::Vector3d xa =
108 positions.block(c, 3 * pair.first, 1, 3).transpose();
109 Eigen::Vector3d xb;
110 if (pair.second >= 0) {
111 xb = positions.block(c, 3 * pair.second, 1, 3).transpose();
112 } else {
113 const Eigen::Index frozen_index = -1 - pair.second;
114 xb = Eigen::Vector3d(frozen.data() + 3 * frozen_index);
115 }
116
117
118
119 const Eigen::Vector3d delta = box.displacement(xb, xa);
120 const double r = delta.norm();
121 if (!(r > 0.0) || !std::isfinite(r)) return false;
123 const auto radial = cutoff(r);
124 geometry.
q(c, f) = radial.value;
125 geometry.
grad.block(c, 3 * f, 1, 3) =
126 (radial.first * (delta / r)).transpose();
127 } else {
128 const double inv_r = 1.0 / r;
129 geometry.
q(c, f) = inv_r;
130 geometry.
grad.block(c, 3 * f, 1, 3) =
131 (-delta * (inv_r * inv_r * inv_r)).transpose();
132 }
133 }
134 }
138 geometry.
pairs = std::move(pairs);
139 geometry.
valid =
true;
140 return true;
141}
std::vector< CutoffPairFeatures > radialPairFeatures(const Coord &positions, const AtomsConfiguration &configuration)
AtomsPositionAndType atoms_froz_active
Info on active frozen atoms.
AtomsPositionAndType atoms_mov
Info on moving atoms.
std::vector< Pair > pairs
Eigen::Index dof
3 x moving atoms
Eigen::MatrixXd q
n_conf x F
Eigen::MatrixXd grad
n_conf x 3F