@@ -15,7 +15,7 @@ class CheckKpointsKspacing(BaseValidator):
1515 """Check that k-point density is sufficiently high and is compatible with lattice symmetry."""
1616
1717 name : str = "Check k-point density"
18- kpts_tolerance : float | None = Field (
18+ kpts_tolerance : float = Field (
1919 SETTINGS .VASP_KPTS_TOLERANCE ,
2020 description = "Tolerance for evaluating k-point density, to accommodate different the k-point generation schemes across VASP versions." ,
2121 )
@@ -46,16 +46,18 @@ def _get_valid_num_kpts(
4646 int, the minimum permitted number of k-points, consistent with self.kpts_tolerance
4747 """
4848 # If MP input set specifies KSPACING in the INCAR
49- if ("KSPACING" in vasp_files .valid_input_set .incar .keys ()) and (vasp_files .valid_input_set .kpoints is None ):
50- valid_kspacing = vasp_files .valid_input_set .incar .get ("KSPACING" , self .vasp_defaults ["KSPACING" ].value )
49+ if (kspacing := vasp_files .valid_input_set .incar .get ("KSPACING" )) and (
50+ vasp_files .valid_input_set .kpoints is None
51+ ):
52+ valid_kspacing = kspacing
5153 # number of kpoints along each of the three lattice vectors
5254 nk = [
5355 max (1 , np .ceil (vasp_files .user_input .structure .lattice .reciprocal_lattice .abc [ik ] / valid_kspacing ))
5456 for ik in range (3 )
5557 ]
5658 valid_num_kpts = np .prod (nk )
5759 # If MP input set specifies a KPOINTS file
58- else :
60+ elif vasp_files . valid_input_set . kpoints :
5961 valid_num_kpts = vasp_files .valid_input_set .kpoints .num_kpts or np .prod (
6062 vasp_files .valid_input_set .kpoints .kpts [0 ]
6163 )
@@ -64,7 +66,7 @@ def _get_valid_num_kpts(
6466
6567 def _check_user_shifted_mesh (self , vasp_files : VaspFiles , reasons : list [str ], warnings : list [str ]) -> None :
6668 # Check for user shifts
67- if (not self .allow_kpoint_shifts ) and any (shift_val != 0 for shift_val in vasp_files .actual_kpoints .kpts_shift ):
69+ if (not self .allow_kpoint_shifts ) and any (shift_val != 0 for shift_val in vasp_files .actual_kpoints .kpts_shift ): # type: ignore[union-attr]
6870 reasons .append ("INPUT SETTINGS --> KPOINTS: shifting the kpoint mesh is not currently allowed." )
6971
7072 def _check_explicit_mesh_permitted (self , vasp_files : VaspFiles , reasons : list [str ], warnings : list [str ]) -> None :
@@ -77,7 +79,7 @@ def _check_explicit_mesh_permitted(self, vasp_files: VaspFiles, reasons: list[st
7779 else :
7880 allow_explicit = False
7981
80- if (not allow_explicit ) and len (vasp_files .actual_kpoints .kpts ) > 1 :
82+ if (not allow_explicit ) and len (vasp_files .actual_kpoints .kpts ) > 1 : # type: ignore[union-attr]
8183 reasons .append (
8284 "INPUT SETTINGS --> KPOINTS: explicitly defining "
8385 "the k-point mesh is not currently allowed. "
@@ -92,10 +94,10 @@ def _check_kpoint_density(self, vasp_files: VaspFiles, reasons: list[str], warni
9294 # Check number of kpoints used
9395 valid_num_kpts = self ._get_valid_num_kpts (vasp_files )
9496
95- cur_num_kpts = max (
96- vasp_files .actual_kpoints .num_kpts ,
97- np .prod (vasp_files .actual_kpoints .kpts ),
98- len (vasp_files .actual_kpoints .kpts ),
97+ cur_num_kpts : int = max ( # type: ignore[assignment]
98+ vasp_files .actual_kpoints .num_kpts , # type: ignore[union-attr]
99+ np .prod (vasp_files .actual_kpoints .kpts ), # type: ignore[union-attr]
100+ len (vasp_files .actual_kpoints .kpts ), # type: ignore[union-attr]
99101 )
100102 if cur_num_kpts < valid_num_kpts :
101103 reasons .append (
@@ -106,19 +108,19 @@ def _check_kpoint_density(self, vasp_files: VaspFiles, reasons: list[str], warni
106108 def _check_kpoint_mesh_symmetry (self , vasp_files : VaspFiles , reasons : list [str ], warnings : list [str ]) -> None :
107109 # check for valid kpoint mesh (which depends on symmetry of the structure)
108110
109- cur_kpoint_style = vasp_files .actual_kpoints .style .name .lower ()
111+ cur_kpoint_style = vasp_files .actual_kpoints .style .name .lower () # type: ignore[union-attr]
110112 is_hexagonal = vasp_files .user_input .structure .lattice .is_hexagonal ()
111113 is_face_centered = vasp_files .user_input .structure .get_space_group_info ()[0 ][0 ] == "F"
112114 monkhorst_mesh_is_invalid = is_hexagonal or is_face_centered
113115 if (
114116 cur_kpoint_style == "monkhorst"
115117 and monkhorst_mesh_is_invalid
116- and any (x % 2 == 0 for x in vasp_files .actual_kpoints .kpts [0 ])
118+ and any (x % 2 == 0 for x in vasp_files .actual_kpoints .kpts [0 ]) # type: ignore[union-attr]
117119 ):
118120 # only allow Monkhorst with all odd number of subdivisions per axis.
119- kx , ky , kz = vasp_files .actual_kpoints .kpts [0 ]
121+ kv = vasp_files .actual_kpoints .kpts [0 ] # type: ignore[union-attr ]
120122 reasons .append (
121- f"INPUT SETTINGS --> KPOINTS or KGAMMA: ({ kx } x { ky } x { kz } ) "
123+ f"INPUT SETTINGS --> KPOINTS or KGAMMA: ({ '×' . join ([ f' { _k } ' for _k in kv ]) } ) "
122124 "Monkhorst-Pack kpoint mesh was used."
123125 "To be compatible with the symmetry of the lattice, "
124126 "a Monkhorst-Pack mesh should have only odd number of "
0 commit comments