Coverage for gpaw/kpoint.py: 97%
35 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-19 00:19 +0000
1# Copyright (C) 2003 CAMP
2# Please see the accompanying LICENSE file for further information.
4"""This module defines a ``KPoint`` class."""
5from typing import Optional
6from gpaw.projections import Projections
9class KPoint:
10 """Class for a single k-point.
12 The KPoint class takes care of all wave functions for a
13 certain k-point and a certain spin.
15 Attributes:
17 eps_n: float ndarray
18 Eigenvalues.
19 f_n: float ndarray
20 Occupation numbers. The occupation numbers already include the
21 k-point weight in supercell calculations.
22 """
24 def __init__(self,
25 weightk: float,
26 weight: float,
27 s: int,
28 k: int,
29 q: int,
30 phase_cd=None):
31 """Construct k-point object.
33 Parameters:
35 weightk:
36 Weight of this k-point.
37 weight:
38 Old confusing weight.
39 s: int
40 Spin index: up or down (0 or 1).
41 k: int
42 k-point IBZ-index.
43 q: int
44 local k-point index.
45 phase_cd: complex ndarray
46 Bloch phase-factors for translations - axis c=0,1,2
47 and direction d=0,1.
48 """
50 self.weightk = weightk # pure k-point weight
51 self.weight = weight # old confusing weight
52 self.s = s # spin index
53 self.k = k # k-point index
54 self.q = q # local k-point index
55 self.phase_cd = phase_cd
57 self.eps_n = None
58 self.f_n = None
59 self._projections: Optional[Projections] = None
61 # Only one of these two will be used:
62 self.psit = None # UniformGridMatrix/PWExpansionMatrix
63 self.C_nM = None # LCAO coefficients for wave functions
65 # LCAO stuff:
66 self.rho_MM = None
67 self.S_MM = None
68 self.T_MM = None
70 def __repr__(self):
71 return (f'KPoint(weight={self.weight}, weightk={self.weightk}, '
72 f's={self.s}, k={self.k}, q={self.q})')
74 @property
75 def projections(self) -> Projections:
76 assert self._projections is not None
77 return self._projections
79 @projections.setter
80 def projections(self, value):
81 self._projections = value
83 @property
84 def P_ani(self):
85 if self._projections is not None:
86 return {a: P_ni for a, P_ni in self.projections.items()}
88 @property
89 def psit_nG(self):
90 if self.psit is not None:
91 return self.psit.array