|
| 1 | +#ifndef MI_TOOLS_H |
| 2 | +#define MI_TOOLS_H |
| 3 | + |
| 4 | +#include <complex> |
| 5 | +#include <vector> |
| 6 | + |
| 7 | +#include "source_base/vector3.h" |
| 8 | + |
| 9 | +/** |
| 10 | + * @file mi_tools.h |
| 11 | + * @brief Free-function utilities for computing atomic magnetic moments (Mi) |
| 12 | + * from intermediate quantities (e.g. becp projector coefficients) |
| 13 | + * in the DeltaSpin module. |
| 14 | + * |
| 15 | + * @par Rationale |
| 16 | + * These functions do not depend on the SpinConstrain<TK> template state and |
| 17 | + * are factored out as free functions to: |
| 18 | + * - Reduce coupling to the singleton class members |
| 19 | + * - Allow reuse by both LCAO and PW basis paths |
| 20 | + * - Be independently unit-testable |
| 21 | + */ |
| 22 | + |
| 23 | +namespace spinconstrain |
| 24 | +{ |
| 25 | + |
| 26 | +/** |
| 27 | + * @brief Convert spinor occupation matrix to magnetic moment vector using Pauli matrices. |
| 28 | + * |
| 29 | + * @details For a two-component spinor wavefunction, the spin density matrix is: |
| 30 | + * rho = |a|^2 a*b | = | (1+Mz)/2 (Mx-iMy)/2 | |
| 31 | + * |b*a |b|^2 | | (Mx+iMy)/2 (1-Mz)/2 | |
| 32 | + * The magnetic moment components are extracted via Pauli matrix traces: |
| 33 | + * Mx = Tr(rho * sigma_x) = occ[1] + occ[2] (real part) |
| 34 | + * My = Tr(rho * sigma_y) = -Im(occ[1] - occ[2]) (from sigma_y = [[0,-i],[i,0]]) |
| 35 | + * Mz = Tr(rho * sigma_z) = occ[0] - occ[3] (real part) |
| 36 | + * where occ = {|a|^2, a*b, b*a, |b|^2} from becp coefficients. |
| 37 | + * |
| 38 | + * @param occ 4-element array of occupation matrix elements (complex) |
| 39 | + * @param weight k-point weight for integration |
| 40 | + * @return 3D magnetic moment vector (Mx, My, Mz) in Bohr magnetons |
| 41 | + */ |
| 42 | +inline ModuleBase::Vector3<double> pauli_to_moment(const std::complex<double> occ[4], double weight) |
| 43 | +{ |
| 44 | + return ModuleBase::Vector3<double>( |
| 45 | + weight * (occ[1] + occ[2]).real(), |
| 46 | + weight * (occ[1] - occ[2]).imag(), |
| 47 | + weight * (occ[0] - occ[3]).real() |
| 48 | + ); |
| 49 | +} |
| 50 | + |
| 51 | +/** |
| 52 | + * @brief Accumulate atomic magnetic moments from becp coefficients for one k-point. |
| 53 | + * |
| 54 | + * @details For npol=2 (nspin=4), computes full Pauli decomposition: |
| 55 | + * occ[0] = sum(becp_up^* * becp_up), occ[1] = sum(becp_up^* * becp_dn), |
| 56 | + * occ[2] = sum(becp_dn^* * becp_up), occ[3] = sum(becp_dn^* * becp_dn) |
| 57 | + * Mi = pauli_to_moment(occ, weight) |
| 58 | + * For npol=1 (nspin=2), only z-component: |
| 59 | + * occ = sum(|becp|^2), Mi.z += weight * occ * spin_sign |
| 60 | + * |
| 61 | + * @param becp Projector coefficients <alpha_{l,m}|psi_{k,i}> |
| 62 | + * @param nkb Total number of projectors |
| 63 | + * @param nbands Number of bands |
| 64 | + * @param npol Number of spinor components (1 for collinear, 2 for non-collinear) |
| 65 | + * @param spin_sign +1 for spin-up, -1 for spin-down (nspin=2 only); unused for npol=2 |
| 66 | + * @param wg_ik Band occupation weights for this k-point (from Fermi-Dirac) |
| 67 | + * @param nh_iat Array of projector counts per atom: nh_iat[iat] = nproj for atom iat |
| 68 | + * @param mi [in,out] Magnetic moments vector to accumulate into (size = nat) |
| 69 | + */ |
| 70 | +void accumulate_Mi_from_becp(const std::complex<double>* becp, |
| 71 | + int nkb, |
| 72 | + int nbands, |
| 73 | + int npol, |
| 74 | + int spin_sign, |
| 75 | + const double* wg_ik, |
| 76 | + const int* nh_iat, |
| 77 | + std::vector<ModuleBase::Vector3<double>>& mi); |
| 78 | + |
| 79 | +} // namespace spinconstrain |
| 80 | + |
| 81 | +#endif // MI_TOOLS_H |
0 commit comments