5
5
import copy
6
6
import json
7
7
import logging
8
- from collections .abc import Iterable
9
8
from dataclasses import dataclass , field
10
9
from typing import TYPE_CHECKING , Any
11
10
from warnings import warn
19
18
from pymatgen .io .core import InputFile , InputGenerator , InputSet
20
19
21
20
if TYPE_CHECKING :
22
- from collections .abc import Sequence
21
+ from collections .abc import Iterable , Sequence
23
22
24
23
from pymatgen .util .typing import PathLike
25
24
@@ -234,7 +233,7 @@ def _read_previous(
234
233
prev_dir (str or Path): The previous directory for the calculation
235
234
"""
236
235
prev_structure : Structure | Molecule | None = None
237
- prev_parameters = {}
236
+ prev_params = {}
238
237
prev_results : dict [str , Any ] = {}
239
238
240
239
if prev_dir :
@@ -243,7 +242,7 @@ def _read_previous(
243
242
# jobflow_remote)
244
243
split_prev_dir = str (prev_dir ).split (":" )[- 1 ]
245
244
with open (f"{ split_prev_dir } /parameters.json" ) as param_file :
246
- prev_parameters = json .load (param_file , cls = MontyDecoder )
245
+ prev_params = json .load (param_file , cls = MontyDecoder )
247
246
248
247
try :
249
248
aims_output : Sequence [Structure | Molecule ] = read_aims_output (
@@ -256,7 +255,7 @@ def _read_previous(
256
255
except (IndexError , AimsParseError ):
257
256
pass
258
257
259
- return prev_structure , prev_parameters , prev_results
258
+ return prev_structure , prev_params , prev_results
260
259
261
260
@staticmethod
262
261
def _get_properties (
@@ -308,12 +307,9 @@ def _get_input_parameters(
308
307
Returns:
309
308
dict: The input object
310
309
"""
311
- # Get the default configuration
312
- # FHI-aims recommends using their defaults so bare-bones default parameters
313
- parameters : dict [str , Any ] = {
314
- "xc" : "pbe" ,
315
- "relativistic" : "atomic_zora scalar" ,
316
- }
310
+ # Get the default config
311
+ # FHI-aims recommends using their defaults so bare-bones default params
312
+ params : dict [str , Any ] = {"xc" : "pbe" , "relativistic" : "atomic_zora scalar" }
317
313
318
314
# Override default parameters with previous parameters
319
315
prev_parameters = {} if prev_parameters is None else copy .deepcopy (prev_parameters )
@@ -327,25 +323,25 @@ def _get_input_parameters(
327
323
kpt_settings ["density" ] = density
328
324
329
325
parameter_updates = self .get_parameter_updates (structure , prev_parameters )
330
- parameters = recursive_update (parameters , parameter_updates )
326
+ params = recursive_update (params , parameter_updates )
331
327
332
328
# Override default parameters with user_params
333
- parameters = recursive_update (parameters , self .user_params )
334
- if ("k_grid" in parameters ) and ("density" in kpt_settings ):
329
+ params = recursive_update (params , self .user_params )
330
+ if ("k_grid" in params ) and ("density" in kpt_settings ):
335
331
warn (
336
332
"WARNING: the k_grid is set in user_params and in the kpt_settings,"
337
333
" using the one passed in user_params." ,
338
334
stacklevel = 1 ,
339
335
)
340
- elif isinstance (structure , Structure ) and ("k_grid" not in parameters ):
336
+ elif isinstance (structure , Structure ) and ("k_grid" not in params ):
341
337
density = kpt_settings .get ("density" , 5.0 )
342
338
even = kpt_settings .get ("even" , True )
343
- parameters ["k_grid" ] = self .d2k (structure , density , even )
344
- elif isinstance (structure , Molecule ) and "k_grid" in parameters :
339
+ params ["k_grid" ] = self .d2k (structure , density , even )
340
+ elif isinstance (structure , Molecule ) and "k_grid" in params :
345
341
warn ("WARNING: removing unnecessary k_grid information" , stacklevel = 1 )
346
- del parameters ["k_grid" ]
342
+ del params ["k_grid" ]
347
343
348
- return parameters
344
+ return params
349
345
350
346
def get_parameter_updates (
351
347
self ,
@@ -366,7 +362,7 @@ def get_parameter_updates(
366
362
def d2k (
367
363
self ,
368
364
structure : Structure ,
369
- kptdensity : float | list [ float ] = 5.0 ,
365
+ kpt_density : float | tuple [ float , float , float ] = 5.0 ,
370
366
even : bool = True ,
371
367
) -> Iterable [float ]:
372
368
"""Convert k-point density to Monkhorst-Pack grid size.
@@ -376,15 +372,15 @@ def d2k(
376
372
Args:
377
373
structure (Structure): Contains unit cell and
378
374
information about boundary conditions.
379
- kptdensity (float | list[float]): Required k-point
375
+ kpt_density (float | list[float]): Required k-point
380
376
density. Default value is 5.0 point per Ang^-1.
381
377
even (bool): Round up to even numbers.
382
378
383
379
Returns:
384
380
dict: Monkhorst-Pack grid size in all directions
385
381
"""
386
- recipcell = structure .lattice .inv_matrix
387
- return self .d2k_recipcell ( recipcell , structure .lattice .pbc , kptdensity , even )
382
+ recip_cell = structure .lattice .inv_matrix . transpose ()
383
+ return self .d2k_recip_cell ( recip_cell , structure .lattice .pbc , kpt_density , even )
388
384
389
385
def k2d (self , structure : Structure , k_grid : np .ndarray [int ]):
390
386
"""Generate the kpoint density in each direction from given k_grid.
@@ -398,36 +394,36 @@ def k2d(self, structure: Structure, k_grid: np.ndarray[int]):
398
394
Returns:
399
395
dict: Density of kpoints in each direction. result.mean() computes average density
400
396
"""
401
- recipcell = structure .lattice .inv_matrix
402
- densities = k_grid / (2 * np .pi * np .sqrt ((recipcell ** 2 ).sum (axis = 1 )))
397
+ recip_cell = structure .lattice .inv_matrix . transpose ()
398
+ densities = k_grid / (2 * np .pi * np .sqrt ((recip_cell ** 2 ).sum (axis = 1 )))
403
399
return np .array (densities )
404
400
405
401
@staticmethod
406
- def d2k_recipcell (
407
- recipcell : np .ndarray ,
402
+ def d2k_recip_cell (
403
+ recip_cell : np .ndarray ,
408
404
pbc : Sequence [bool ],
409
- kptdensity : float | Sequence [ float ] = 5.0 ,
405
+ kpt_density : float | tuple [ float , float , float ] = 5.0 ,
410
406
even : bool = True ,
411
407
) -> Sequence [int ]:
412
408
"""Convert k-point density to Monkhorst-Pack grid size.
413
409
414
410
Args:
415
- recipcell (Cell): The reciprocal cell
411
+ recip_cell (Cell): The reciprocal cell
416
412
pbc (Sequence[bool]): If element of pbc is True
417
413
then system is periodic in that direction
418
- kptdensity (float or list[floats]): Required k-point
419
- density. Default value is 3.5 point per Ang^-1.
414
+ kpt_density (float or list[floats]): Required k-point
415
+ density. Default value is 5 points per Ang^-1.
420
416
even(bool): Round up to even numbers.
421
417
422
418
Returns:
423
419
dict: Monkhorst-Pack grid size in all directions
424
420
"""
425
- if not isinstance (kptdensity , Iterable ):
426
- kptdensity = 3 * [ float ( kptdensity )]
421
+ if isinstance (kpt_density , float ):
422
+ kpt_density = ( kpt_density , kpt_density , kpt_density )
427
423
kpts : list [int ] = []
428
424
for i in range (3 ):
429
425
if pbc [i ]:
430
- k = 2 * np .pi * np .sqrt ((recipcell [i ] ** 2 ).sum ()) * float (kptdensity [i ])
426
+ k = 2 * np .pi * np .sqrt ((recip_cell [i ] ** 2 ).sum ()) * float (kpt_density [i ])
431
427
if even :
432
428
kpts .append (2 * int (np .ceil (k / 2 )))
433
429
else :
0 commit comments