37 const Crystal& crystal_structure,
41 const std::vector<int>& g_vector_indices,
42 int number_of_plane_waves,
43 int total_number_of_projectors,
46 kleinman_bylander_potential.
resize(
47 total_number_of_projectors, number_of_plane_waves,
Complex(0.0, 0.0));
51 for (
int dimension = 0; dimension < 3; dimension++) {
52 kpoint_cartesian[dimension] = k_crystal.
x * reciprocal_lattice_vectors[0][dimension] +
53 k_crystal.
y * reciprocal_lattice_vectors[1][dimension] +
54 k_crystal.
z * reciprocal_lattice_vectors[2][dimension];
59 Real inverse_sqrt_cell_volume = 1.0 / std::sqrt(cell_volume);
64 std::vector<std::array<Real, 3>> k_plus_g_cartesian_array(number_of_plane_waves);
65 std::vector<Real> k_plus_g_magnitude_squared(number_of_plane_waves);
66 std::vector<Real> k_plus_g_magnitude(number_of_plane_waves);
68 for (
int g_index = 0; g_index < number_of_plane_waves; g_index++) {
70 kpoint_cartesian + planewave_basis.
g_vectors()[g_vector_indices[g_index]].g_cart;
71 k_plus_g_cartesian_array[g_index] = {k_plus_g.
x, k_plus_g.
y, k_plus_g.
z};
72 Real magnitude_squared =
73 k_plus_g.
x * k_plus_g.
x + k_plus_g.
y * k_plus_g.
y + k_plus_g.
z * k_plus_g.
z;
74 k_plus_g_magnitude_squared[g_index] = magnitude_squared;
75 k_plus_g_magnitude[g_index] = std::sqrt(magnitude_squared) * two_pi_over_lattice_parameter;
85 std::vector<std::vector<Complex>> structure_factors(number_of_atoms);
87 for (
int atom_index = 0; atom_index < number_of_atoms; atom_index++) {
89 Real k_dot_r = kpoint_cartesian.
dot(atomic_position);
90 structure_factors[atom_index].resize(number_of_plane_waves);
92 for (
int g_index = 0; g_index < number_of_plane_waves; g_index++) {
94 (planewave_basis.
g_vectors()[g_vector_indices[g_index]].g_cart.dot(
102 int maximum_angular_momentum = 0;
103 for (
int species_index = 0; species_index < static_cast<int>(pseudopotential_set.
size());
105 for (
const auto& projector : pseudopotential_set[species_index].projectors) {
106 maximum_angular_momentum =
107 std::max(maximum_angular_momentum, projector.angular_momentum);
110 int number_of_lm_components = (maximum_angular_momentum + 1) * (maximum_angular_momentum + 1);
113 std::vector<std::vector<Real>> spherical_harmonics_values;
115 number_of_plane_waves,
116 k_plus_g_cartesian_array,
117 k_plus_g_magnitude_squared,
118 spherical_harmonics_values);
122 int combined_projector_index = 0;
123 for (
int atom_index = 0; atom_index < number_of_atoms; atom_index++) {
125 const auto& atom_structure_factors = structure_factors[atom_index];
127 for (
int beta_index = 0;
129 static_cast<int>(pseudopotential_set[species_type_index].projectors.
size());
131 int angular_momentum =
132 pseudopotential_set[species_type_index].projectors[beta_index].angular_momentum;
134 Complex combined_prefactor = inverse_sqrt_cell_volume * angular_phase_factor;
140 for (
int g_index = 0; g_index < number_of_plane_waves; g_index++) {
142 species_type_index, beta_index, k_plus_g_magnitude[g_index]);
144 kleinman_bylander_potential[combined_projector_index][g_index] =
145 beta_value_at_q * spherical_harmonics_values[g_index][lm_index] *
146 atom_structure_factors[g_index] * combined_prefactor;
148 combined_projector_index++;
void compute_kleinman_bylander_projectors(const Vector3D &k_crystal, const Crystal &crystal_structure, const PlanewaveBasis &planewave_basis, const PseudopotentialSet &pseudopotential_set, const BetaFunctionTable &beta_function_table, const std::vector< int > &g_vector_indices, int number_of_plane_waves, int total_number_of_projectors, Matrix< Complex > &kleinman_bylander_potential)