@@ -371,16 +371,15 @@ def from_path(cls, path: str, suffix: str = "") -> BaderAnalysis:
371
371
to perform Bader analysis.
372
372
373
373
Args:
374
- path (str): Name of directory where VASP output files are
375
- stored.
374
+ path (str): Name of directory where VASP output files are stored.
376
375
suffix (str): specific suffix to look for (e.g. '.relax1' for 'CHGCAR.relax1.gz').
377
376
378
377
Returns:
379
378
BaderAnalysis
380
379
"""
381
380
382
381
def _get_filepath (filename ):
383
- name_pattern = filename + suffix + " *" if filename != "POTCAR" else filename + " *"
382
+ name_pattern = f" { filename } { suffix } *" if filename != "POTCAR" else f" { filename } *"
384
383
paths = glob (f"{ path } /{ name_pattern } " )
385
384
fpath = ""
386
385
if len (paths ) >= 1 :
@@ -394,10 +393,10 @@ def _get_filepath(filename):
394
393
fpath = paths [0 ]
395
394
else :
396
395
msg = f"Could not find { filename !r} "
397
- if filename in [ "AECCAR0" , "AECCAR2" ] :
398
- msg += ", cannot calculate charge transfer ."
396
+ if filename in ( "AECCAR0" , "AECCAR2" ) :
397
+ msg += ", interpret Bader results with severe caution ."
399
398
elif filename == "POTCAR" :
400
- msg += ", interpret Bader results with caution ."
399
+ msg += ", cannot calculate charge transfer ."
401
400
warnings .warn (msg )
402
401
return fpath
403
402
@@ -440,10 +439,9 @@ def bader_analysis_from_path(path, suffix=""):
440
439
summary dict
441
440
"""
442
441
443
- def _get_filepath (filename , warning , path = path , suffix = suffix ):
442
+ def _get_filepath (filename , path = path , suffix = suffix ):
444
443
paths = glob (f"{ path } /{ filename } { suffix } *" )
445
- if not paths :
446
- warnings .warn (warning )
444
+ if len (paths ) == 0 :
447
445
return None
448
446
if len (paths ) > 1 :
449
447
# using reverse=True because, if multiple files are present,
@@ -457,13 +455,19 @@ def _get_filepath(filename, warning, path=path, suffix=suffix):
457
455
chgcar_path = _get_filepath ("CHGCAR" , "Could not find CHGCAR!" )
458
456
chgcar = Chgcar .from_file (chgcar_path )
459
457
460
- aeccar0_path = _get_filepath ("AECCAR0" , "Could not find AECCAR0, interpret Bader results with caution." )
458
+ aeccar0_path = _get_filepath ("AECCAR0" )
459
+ if not aeccar0_path :
460
+ warnings .warn ("Could not find AECCAR0, interpret Bader results with severe caution!" )
461
461
aeccar0 = Chgcar .from_file (aeccar0_path ) if aeccar0_path else None
462
462
463
- aeccar2_path = _get_filepath ("AECCAR2" , "Could not find AECCAR2, interpret Bader results with caution." )
463
+ aeccar2_path = _get_filepath ("AECCAR2" )
464
+ if not aeccar2_path :
465
+ warnings .warn ("Could not find AECCAR2, interpret Bader results with severe caution!" )
464
466
aeccar2 = Chgcar .from_file (aeccar2_path ) if aeccar2_path else None
465
467
466
- potcar_path = _get_filepath ("POTCAR" , "Could not find POTCAR, cannot calculate charge transfer." )
468
+ potcar_path = _get_filepath ("POTCAR" )
469
+ if not potcar_path :
470
+ warnings .warn ("Could not find POTCAR, cannot calculate charge transfer." )
467
471
potcar = Potcar .from_file (potcar_path ) if potcar_path else None
468
472
469
473
return bader_analysis_from_objects (chgcar , potcar , aeccar0 , aeccar2 )
0 commit comments