113 int number_of_bands_at_kpoint,
114 WavefunctionAtKpoint wavefunction_at_kpoint,
115 const std::vector<int>& g_vector_indices_at_neighbor,
116 int number_of_bands_at_neighbor,
117 WavefunctionAtNeighbor wavefunction_at_neighbor,
119 const std::vector<GVector>& global_g_vectors = planewave_basis_.
g_vectors();
120 int number_of_plane_waves_at_kpoint =
static_cast<int>(g_vector_indices_at_kpoint.size());
121 int number_of_plane_waves_at_neighbor =
122 static_cast<int>(g_vector_indices_at_neighbor.size());
130 std::unordered_map<int, int> neighbor_local_position_by_global_index;
131 neighbor_local_position_by_global_index.reserve(number_of_plane_waves_at_neighbor);
132 for (
int local_index = 0; local_index < number_of_plane_waves_at_neighbor; local_index++) {
133 neighbor_local_position_by_global_index[g_vector_indices_at_neighbor[local_index]] =
142 std::vector<int> neighbor_local_position_for_kpoint_plane_wave(
143 number_of_plane_waves_at_kpoint, -1);
144 int missing_count = 0;
145 for (
int g_index = 0; g_index < number_of_plane_waves_at_kpoint; g_index++) {
147 global_g_vectors[g_vector_indices_at_kpoint[g_index]].miller;
149 miller.
y + periodic_image_shift.
y,
150 miller.
z + periodic_image_shift.
z);
151 int global_index_of_shifted = global_miller_lookup_.
find(shifted_miller);
152 if (global_index_of_shifted < 0) {
156 auto iterator = neighbor_local_position_by_global_index.find(global_index_of_shifted);
157 if (iterator == neighbor_local_position_by_global_index.end()) {
161 neighbor_local_position_for_kpoint_plane_wave[g_index] = iterator->second;
168 result.
values.assign(
static_cast<std::size_t
>(number_of_bands_at_kpoint) *
169 number_of_bands_at_neighbor,
172 std::vector<const Complex*> band_data_at_kpoint(number_of_bands_at_kpoint);
173 for (
int band_index = 0; band_index < number_of_bands_at_kpoint; band_index++) {
174 band_data_at_kpoint[band_index] = wavefunction_at_kpoint(band_index);
176 std::vector<const Complex*> band_data_at_neighbor(number_of_bands_at_neighbor);
177 for (
int band_index = 0; band_index < number_of_bands_at_neighbor; band_index++) {
178 band_data_at_neighbor[band_index] = wavefunction_at_neighbor(band_index);
181 for (
int band_index_at_neighbor = 0; band_index_at_neighbor < number_of_bands_at_neighbor;
182 band_index_at_neighbor++) {
183 for (
int band_index_at_kpoint = 0; band_index_at_kpoint < number_of_bands_at_kpoint;
184 band_index_at_kpoint++) {
186 for (
int g_index = 0; g_index < number_of_plane_waves_at_kpoint; g_index++) {
187 int neighbor_local_position =
188 neighbor_local_position_for_kpoint_plane_wave[g_index];
189 if (neighbor_local_position < 0) {
193 std::conj(band_data_at_kpoint[band_index_at_kpoint][g_index]) *
194 band_data_at_neighbor[band_index_at_neighbor][neighbor_local_position];
196 result.
values[
static_cast<std::size_t
>(band_index_at_neighbor) *
197 number_of_bands_at_kpoint +
198 band_index_at_kpoint] = overlap;
238 const Crystal& crystal_structure,
241 int number_of_plane_waves_at_kpoint,
242 int number_of_bands_at_kpoint,
243 WavefunctionAtKpoint wavefunction_at_kpoint,
245 int number_of_plane_waves_at_neighbor,
246 int number_of_bands_at_neighbor,
247 WavefunctionAtNeighbor wavefunction_at_neighbor,
248 const Vector3D& b_cartesian)
const {
250 throw std::invalid_argument(
251 "PlanewaveBlochOverlapCalculator::add_augmentation_contribution: |b_cartesian| "
252 "is below compute_q_g_single's zero-vector threshold, where it takes its b=0 "
253 "special branch. That branch is already correctly scaled and must not be "
254 "multiplied by cell_volume(), which this method does unconditionally for its "
255 "(always nonzero, in real use) general-branch case.");
257 int total_number_of_projectors = projectors_at_kpoint.
rows();
260 Matrix<Complex> amplitude_at_kpoint(
static_cast<std::size_t
>(total_number_of_projectors),
261 number_of_bands_at_kpoint);
262 for (
int band_index = 0; band_index < number_of_bands_at_kpoint; band_index++) {
263 const Complex* band_data = wavefunction_at_kpoint(band_index);
264 for (
int projector_index = 0; projector_index < total_number_of_projectors;
267 const Complex* projector_row = projectors_at_kpoint[projector_index];
268 for (
int g_index = 0; g_index < number_of_plane_waves_at_kpoint; g_index++) {
269 sum += std::conj(projector_row[g_index]) * band_data[g_index];
271 amplitude_at_kpoint[projector_index][band_index] = sum;
276 Matrix<Complex> amplitude_at_neighbor(
static_cast<std::size_t
>(total_number_of_projectors),
277 number_of_bands_at_neighbor);
278 for (
int band_index = 0; band_index < number_of_bands_at_neighbor; band_index++) {
279 const Complex* band_data = wavefunction_at_neighbor(band_index);
280 for (
int projector_index = 0; projector_index < total_number_of_projectors;
283 const Complex* projector_row = projectors_at_neighbor[projector_index];
284 for (
int g_index = 0; g_index < number_of_plane_waves_at_neighbor; g_index++) {
285 sum += std::conj(projector_row[g_index]) * band_data[g_index];
287 amplitude_at_neighbor[projector_index][band_index] = sum;
328 const Vector3D b_in_lattice_units = b_cartesian * (1.0 / two_pi_over_lattice_parameter);
330 int projector_offset = 0;
331 for (
int atom_index = 0; atom_index < crystal_structure.
number_of_atoms(); atom_index++) {
333 int number_of_channels =
335 if (number_of_channels == 0) {
352 Real translation_phase_angle =
356 for (
int channel_i = 0; channel_i < number_of_channels; channel_i++) {
357 int projector_i = projector_offset + channel_i;
358 for (
int channel_j = 0; channel_j < number_of_channels; channel_j++) {
359 int projector_j = projector_offset + channel_j;
367 two_pi_over_lattice_parameter) *
369 if (q_ij ==
Complex(0.0, 0.0)) {
373 for (
int band_index_at_neighbor = 0;
374 band_index_at_neighbor < number_of_bands_at_neighbor;
375 band_index_at_neighbor++) {
377 q_ij * amplitude_at_neighbor[projector_j][band_index_at_neighbor];
378 for (
int band_index_at_kpoint = 0;
379 band_index_at_kpoint < number_of_bands_at_kpoint;
380 band_index_at_kpoint++) {
385 result.
values[
static_cast<std::size_t
>(band_index_at_neighbor) *
386 number_of_bands_at_kpoint +
387 band_index_at_kpoint] +=
388 std::conj(amplitude_at_kpoint[projector_i][band_index_at_kpoint]) *
394 projector_offset += number_of_channels;