From dc1b58b604936d527a59d5b63ed959de2d947986 Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Tue, 12 Mar 2024 15:20:27 +0100 Subject: [PATCH 1/2] fix poscar.lobster, cleanup cli, update tests --- lobsterpy/cli.py | 206 +++++++++++++--------------------- lobsterpy/featurize/batch.py | 34 +++--- lobsterpy/featurize/core.py | 4 +- lobsterpy/featurize/utils.py | 12 +- tests/cli/test_cli.py | 75 +++++-------- tests/featurize/test_utils.py | 2 +- 6 files changed, 135 insertions(+), 198 deletions(-) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index ab742fad..955a2e15 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -6,6 +6,7 @@ import argparse import json +import os from math import log, sqrt from pathlib import Path @@ -16,6 +17,7 @@ from lobsterpy.cohp.analyze import Analysis from lobsterpy.cohp.describe import Description +from lobsterpy.featurize.utils import get_file_paths from lobsterpy.plotting import ( IcohpDistancePlotter, PlainCohpPlotter, @@ -738,61 +740,28 @@ def run(args): "plot-automatic", "plot-automatic-ia", ]: - # Check for .gz files exist for default values and update accordingly - default_files = { - "structure": "POSCAR", - "charge": "CHARGE.lobster", - "icohplist": "ICOHPLIST.lobster", - "cohpcar": "COHPCAR.lobster", - } - - for arg_name in default_files: - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError( - "Files necessary for automatic analysis of LOBSTER outputs " - "not found in the current directory" - ) + req_files = get_file_paths( + path_to_lobster_calc=Path(os.getcwd()), requested_files=["structure", "charge", "icohplist", "cohpcar"] + ) if args.coops: - default_files_coops = { - "icohplist": "ICOOPLIST.lobster", - "cohpcar": "COOPCAR.lobster", - } - for arg_name, file_name in default_files_coops.items(): - setattr(args, arg_name, Path(file_name)) - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError( - "Files required for automatic analysis of COOPs (ICOOPLIST.lobster and" - " COOPCAR.lobster) not found in the directory" - ) + req_files_coops = get_file_paths( + path_to_lobster_calc=Path(os.getcwd()), requested_files=["icooplist", "coopcar"] + ) + + req_files["icohplist"] = req_files_coops["icooplist"] + req_files["cohpcar"] = req_files_coops["coopcar"] if args.cobis: - default_files_cobis = { - "icohplist": "ICOBILIST.lobster", - "cohpcar": "COBICAR.lobster", - } - for arg_name, file_name in default_files_cobis.items(): - setattr(args, arg_name, Path(file_name)) - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError( - "Files required for automatic analysis of COBIs (ICOBILIST.lobster and" - " COBICAR.lobster) not found in the directory" - ) + req_files_cobis = get_file_paths( + path_to_lobster_calc=Path(os.getcwd()), requested_files=["icobilist", "cobicar"] + ) + + req_files["icohplist"] = req_files_cobis["icobilist"] + req_files["cohpcar"] = req_files_cobis["cobicar"] + + for arg_name in req_files: + setattr(args, arg_name, req_files[arg_name]) if args.action in ["description", "plot-automatic", "plot-automatic-ia"]: which_bonds = "all" if args.allbonds else "cation-anion" @@ -871,24 +840,24 @@ def run(args): if args.action == "plot": if args.cobis: - filename = args.cohpcar.parent / "COBICAR.lobster" - if not filename.exists(): - filename = filename.with_name(zpath(filename.name)) + filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["cobicar"]).get( + "cobicar" + ) options = {"are_cobis": True, "are_coops": False} elif args.coops: - filename = args.cohpcar.parent / "COOPCAR.lobster" - if not filename.exists(): - filename = filename.with_name(zpath(filename.name)) + filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["coopcar"]).get( + "coopcar" + ) options = {"are_cobis": False, "are_coops": True} else: - filename = args.cohpcar.parent / "COHPCAR.lobster" - if not filename.exists(): - filename = filename.with_name(zpath(filename.name)) + filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["cohpcar"]).get( + "cohpcar" + ) options = {"are_cobis": False, "are_coops": False} - struture_filename = args.structure.parent / "POSCAR" - if not struture_filename.exists(): - struture_filename = struture_filename.with_name(zpath(struture_filename.name)) + struture_filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["structure"]).get( + "structure" + ) completecohp = CompleteCohp.from_file( fmt="LOBSTER", @@ -1051,29 +1020,18 @@ def run(args): if args.action in ["description-quality"]: # Check for .gz files exist for default values and update accordingly - mandatory_files = { - "structure": "POSCAR", - "lobsterin": "lobsterin", - "lobsterout": "lobsterout", - } - - for arg_name in mandatory_files: - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError( - "Mandatory files necessary for LOBSTER calc quality not found in the current directory." - ) + req_files = get_file_paths( + path_to_lobster_calc=Path(os.getcwd()), requested_files=["structure", "lobsterin", "lobsterout"] + ) + for arg_name in req_files: + setattr(args, arg_name, req_files[arg_name]) - optional_file = { + optional_files = { "bandoverlaps": "bandOverlaps.lobster", "potcar": "POTCAR", } - for arg_name in optional_file: + for arg_name in optional_files: file_path = getattr(args, arg_name) if not file_path.exists(): gz_file_path = file_path.with_name(zpath(file_path.name)) @@ -1083,34 +1041,26 @@ def run(args): bva_comp = args.bvacomp if bva_comp: - bva_files = { - "charge": "CHARGE.lobster", - } + bva_files = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["charge"]) for arg_name in bva_files: - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError("BVA charge requested but CHARGE.lobster file not found.") + setattr(args, arg_name, bva_files[arg_name]) dos_comparison = args.doscomp if dos_comparison: - dos_files = { - "doscar": "DOSCAR.lobster", - "vasprun": "vasprun.xml", - } - + dos_files = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["doscar", "vasprun"]) for arg_name in dos_files: - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError("DOS comparisons requested but DOSCAR.lobster, vasprun.xml file not found.") + if arg_name == "doscar": + file_path = getattr(args, arg_name) + if not file_path.exists(): + gz_file_path = file_path.with_name(zpath(file_path.name)) + if gz_file_path.exists(): + setattr(args, arg_name, gz_file_path) + else: + raise ValueError(f"{file_path} or {gz_file_path} not found in current directory") + else: + setattr(args, arg_name, dos_files[arg_name]) + potcar_file_path = args.potcar quality_dict = Analysis.get_lobster_calc_quality_summary( @@ -1137,19 +1087,19 @@ def run(args): json.dump(quality_dict, fd) if args.action in ["plot-dos", "plotdos"]: - mandatory_files = { - "doscar": "DOSCAR.lobster", - "structure": "POSCAR", - } + req_files = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["structure", "doscar"]) - for arg_name in mandatory_files: - file_path = getattr(args, arg_name) - if not file_path.exists(): - gz_file_path = file_path.with_name(zpath(file_path.name)) - if gz_file_path.exists(): - setattr(args, arg_name, gz_file_path) - else: - raise ValueError(f"{file_path.name} necessary for plotting DOS not found in the current directory.") + for arg_name in req_files: + if arg_name == "doscar": + file_path = getattr(args, arg_name) + if not file_path.exists(): + gz_file_path = file_path.with_name(zpath(file_path.name)) + if gz_file_path.exists(): + setattr(args, arg_name, gz_file_path) + else: + raise ValueError(f"{file_path} or {gz_file_path} not found in current directory") + else: + setattr(args, arg_name, req_files[arg_name]) from pymatgen.io.lobster import Doscar @@ -1218,22 +1168,28 @@ def run(args): if args.action in ["plot-icohp-distance", "ploticohpdistance"]: if args.cobis: - filename = args.icohplist.parent / "ICOBILIST.lobster" - if not filename.exists(): - filename = filename.with_name(zpath(filename.name)) + filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["icobilist"]).get( + "icobilist" + ) + args.icohplist = filename + # filename = args.icohplist.parent / "ICOBILIST.lobster" + # if not filename.exists(): + # filename = filename.with_name(zpath(filename.name)) options = {"are_cobis": True, "are_coops": False} elif args.coops: - filename = args.icohplist.parent / "ICOOPLIST.lobster" - if not filename.exists(): - filename = filename.with_name(zpath(filename.name)) + filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["icooplist"]).get( + "icooplist" + ) + args.icohplist = filename options = {"are_cobis": False, "are_coops": True} else: - filename = args.icohplist.parent / "ICOHPLIST.lobster" - if not filename.exists(): - filename = filename.with_name(zpath(filename.name)) + filename = get_file_paths(path_to_lobster_calc=Path(os.getcwd()), requested_files=["icohplist"]).get( + "icohplist" + ) + args.icohplist = filename options = {"are_cobis": False, "are_coops": False} - icohpcollection = Icohplist(filename=filename, **options).icohpcollection + icohpcollection = Icohplist(filename=args.icohplist, **options).icohpcollection icohp_plotter = IcohpDistancePlotter(**options) icohp_plotter.add_icohps(icohpcollection=icohpcollection, label="") diff --git a/lobsterpy/featurize/batch.py b/lobsterpy/featurize/batch.py index 079fb53d..3bbb8c46 100644 --- a/lobsterpy/featurize/batch.py +++ b/lobsterpy/featurize/batch.py @@ -140,9 +140,9 @@ def _featurizecoxx(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: """ file_paths = get_file_paths( - path_to_lobster_calc=path_to_lobster_calc, requested_files=["poscar", "cohpcar", "icohplist"] + path_to_lobster_calc=path_to_lobster_calc, requested_files=["structure", "cohpcar", "icohplist"] ) - structure_path = file_paths.get("poscar") + structure_path = file_paths.get("structure") coxx = FeaturizeCOXX( path_to_coxxcar=str(file_paths.get("cohpcar")), @@ -203,33 +203,33 @@ def _featurizecharges(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: A pandas dataframe with computed ionicity for the structure """ - file_paths = get_file_paths(path_to_lobster_calc=path_to_lobster_calc, requested_files=["poscar", "charge"]) + file_paths = get_file_paths(path_to_lobster_calc=path_to_lobster_calc, requested_files=["structure", "charge"]) if self.charge_type == "mulliken": charge_mull = FeaturizeCharges( path_to_charge=str(file_paths.get("charge")), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), charge_type="mulliken", ) df = charge_mull.get_df() elif self.charge_type == "loewdin": charge_loew = FeaturizeCharges( path_to_charge=str(file_paths.get("charge")), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), charge_type="loewdin", ) df = charge_loew.get_df() else: charge_mull = FeaturizeCharges( path_to_charge=str(file_paths.get("charge")), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), charge_type="mulliken", ) df_mull = charge_mull.get_df() charge_loew = FeaturizeCharges( path_to_charge=str(file_paths.get("charge")), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), charge_type="loewdin", ) df_loew = charge_loew.get_df() @@ -487,7 +487,7 @@ def _fingerprint_df(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: """ if self.fingerprint_for.upper() == "COBI": file_paths = get_file_paths( - path_to_lobster_calc=path_to_lobster_calc, requested_files=["poscar", "cobicar", "icobilist"] + path_to_lobster_calc=path_to_lobster_calc, requested_files=["structure", "cobicar", "icobilist"] ) coxxcar_path = file_paths.get("cobicar") @@ -497,7 +497,7 @@ def _fingerprint_df(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: elif self.fingerprint_for.upper() == "COOP": file_paths = get_file_paths( - path_to_lobster_calc=path_to_lobster_calc, requested_files=["poscar", "coopcar", "icooplist"] + path_to_lobster_calc=path_to_lobster_calc, requested_files=["structure", "coopcar", "icooplist"] ) coxxcar_path = file_paths.get("coopcar") @@ -507,7 +507,7 @@ def _fingerprint_df(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: else: file_paths = get_file_paths( - path_to_lobster_calc=path_to_lobster_calc, requested_files=["poscar", "cohpcar", "icohplist"] + path_to_lobster_calc=path_to_lobster_calc, requested_files=["structure", "cohpcar", "icohplist"] ) coxxcar_path = file_paths.get("cohpcar") @@ -518,7 +518,7 @@ def _fingerprint_df(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: coxx = FeaturizeCOXX( path_to_coxxcar=str(coxxcar_path), path_to_icoxxlist=str(icoxxlist_path), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), feature_type=self.feature_type, e_range=self.e_range, are_coops=are_coops, @@ -622,11 +622,11 @@ def _get_sg_df(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: dir_name = Path(path_to_lobster_calc) file_paths = get_file_paths( path_to_lobster_calc=path_to_lobster_calc, - requested_files=["charge", "cohpcar", "icohplist", "icooplist", "icobilist", "madelung", "poscar"], + requested_files=["charge", "cohpcar", "icohplist", "icooplist", "icobilist", "madelung", "structure"], ) graph = LobsterGraph( - path_to_poscar=str(file_paths.get("poscar")), + path_to_poscar=str(file_paths.get("structure")), path_to_charge=str(file_paths.get("charge")), path_to_cohpcar=str(file_paths.get("cohpcar")), path_to_icohplist=str(file_paths.get("icohplist")), @@ -738,13 +738,13 @@ def _get_dos_moments_df(self, path_to_lobster_calc: str | Path) -> pd.DataFrame: """ file_paths = get_file_paths( path_to_lobster_calc=path_to_lobster_calc, - requested_files=["poscar", "doscar"], + requested_files=["structure", "doscar"], use_lso_dos=self.use_lso_dos, ) featurize_dos = FeaturizeDoscar( path_to_doscar=str(file_paths.get("doscar")), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), add_element_dos_moments=self.add_element_dos_moments, e_range=self.e_range, ) @@ -762,13 +762,13 @@ def _get_dos_fingerprints_df(self, path_to_lobster_calc: str | Path) -> pd.DataF """ file_paths = get_file_paths( path_to_lobster_calc=path_to_lobster_calc, - requested_files=["poscar", "doscar"], + requested_files=["structure", "doscar"], use_lso_dos=self.use_lso_dos, ) featurize_dos = FeaturizeDoscar( path_to_doscar=str(file_paths.get("doscar")), - path_to_structure=str(file_paths.get("poscar")), + path_to_structure=str(file_paths.get("structure")), e_range=self.e_range, ) diff --git a/lobsterpy/featurize/core.py b/lobsterpy/featurize/core.py index cb00bd4a..205f3d57 100644 --- a/lobsterpy/featurize/core.py +++ b/lobsterpy/featurize/core.py @@ -270,7 +270,7 @@ def get_lobsterpy_cba_dict(path_to_lobster_calc: str | Path, bonds: str, orbital """ file_paths = get_file_paths( - path_to_lobster_calc=path_to_lobster_calc, requested_files=["poscar", "cohpcar", "icohplist", "charge"] + path_to_lobster_calc=path_to_lobster_calc, requested_files=["structure", "cohpcar", "icohplist", "charge"] ) which_bonds = bonds.replace("-", "_") @@ -278,7 +278,7 @@ def get_lobsterpy_cba_dict(path_to_lobster_calc: str | Path, bonds: str, orbital try: analyse = Analysis( - path_to_poscar=str(file_paths.get("poscar")), + path_to_poscar=str(file_paths.get("structure")), path_to_icohplist=str(file_paths.get("icohplist")), path_to_cohpcar=str(file_paths.get("cohpcar")), path_to_charge=str(file_paths.get("charge")), diff --git a/lobsterpy/featurize/utils.py b/lobsterpy/featurize/utils.py index acb57a7f..11ea76bb 100644 --- a/lobsterpy/featurize/utils.py +++ b/lobsterpy/featurize/utils.py @@ -24,7 +24,7 @@ def get_file_paths( """ default_values = { - "poscar": "POSCAR", + "structure": "POSCAR", "cohpcar": "COHPCAR.lobster", "icohplist": "ICOHPLIST.lobster", "cobicar": "COBICAR.lobster", @@ -34,6 +34,12 @@ def get_file_paths( "charge": "CHARGE.lobster", "madelung": "MadelungEnergies.lobster", "doscar": ("DOSCAR.LSO.lobster" if use_lso_dos else "DOSCAR.lobster"), + "lobsterin": "lobsterin", + "lobsterout": "lobsterout", + "bandoverlaps": "bandOverlaps.lobster", + "potcar": "POTCAR", + "vasprun": "vasprun.xml", + "incar": "INCAR", } lobster_path = Path(path_to_lobster_calc) @@ -43,11 +49,11 @@ def get_file_paths( for file in requested_files: file_str = default_values.get(file) file_str = file_str if isinstance(file_str, str) else file - if file == "poscar": + if file == "structure": try: file_paths[file] = get_structure_path(lobster_path=lobster_path) except Exception: - missing_files.append(default_values["poscar"]) + missing_files.append(default_values["structure"]) else: file_path = lobster_path / file_str if file_path.exists(): diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py index 2e5dd313..79a74375 100644 --- a/tests/cli/test_cli.py +++ b/tests/cli/test_cli.py @@ -286,7 +286,7 @@ def test_lobsterin_generation_error(self, tmp_path): assert str(err2.value) == 'please use "--overwrite" if you would like to overwrite existing lobster inputs' def test_cli_automatic_analysis_error(self): - with pytest.raises(ValueError) as err1: # noqa: PT012, PT011 + with pytest.raises(Exception) as err1: # noqa: PT012, PT011 os.chdir(TestDir / "test_data/NaCl") args1 = [ "description", @@ -295,12 +295,9 @@ def test_cli_automatic_analysis_error(self): test1 = get_parser().parse_args(args1) run(test1) - assert ( - str(err1.value) == "Files required for automatic analysis of COBIs (ICOBILIST.lobster and " - "COBICAR.lobster) not found in the directory" - ) + assert str(err1.value) == "Files ['ICOBILIST.lobster'] not found in ." - with pytest.raises(ValueError) as err2: # noqa: PT012, PT011 + with pytest.raises(Exception) as err2: # noqa: PT012, PT011 os.chdir(TestDir / "test_data/NaCl") args2 = [ "description", @@ -308,10 +305,7 @@ def test_cli_automatic_analysis_error(self): ] test2 = get_parser().parse_args(args2) run(test2) - assert ( - str(err2.value) == "Files required for automatic analysis of COOPs (ICOOPLIST.lobster and " - "COOPCAR.lobster) not found in the directory" - ) + assert str(err2.value) == "Files ['ICOOPLIST.lobster'] not found in ." def test_lobsterin_generation_error_userbasis(self, tmp_path): # This is a test for the user-defined basis set. @@ -554,7 +548,7 @@ def test_dos_plot(self, tmp_path, inject_mocks, clean_plot): def test_cli_exceptions(self): # Calc files missing exception test - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 + with pytest.raises(Exception) as err1: # noqa: PT012, PT011 os.chdir(TestDir) args = [ "description", @@ -562,13 +556,12 @@ def test_cli_exceptions(self): test = get_parser().parse_args(args) run(test) + assert ( + str(err1.value) + == "Files ['POSCAR', 'CHARGE.lobster', 'ICOHPLIST.lobster', 'COHPCAR.lobster'] not found in tests." + ) - assert ( - str(err.value) - == "Files necessary for automatic analysis of LOBSTER outputs not found in the current directory" - ) - - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 + with pytest.raises(Exception) as err2: # noqa: PT012, PT011 os.chdir(TestDir) args = [ "description-quality", @@ -577,13 +570,10 @@ def test_cli_exceptions(self): test = get_parser().parse_args(args) run(test) - assert ( - str(err.value) - == "Mandatory files necessary for LOBSTER calc quality not found in the current directory." - ) - + assert str(err2.value) == "Files ['POSCAR', 'lobsterin', 'lobsterout'] not found in tests." + # # doscar comparison exceptions test - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 + with pytest.raises(Exception) as err3: # noqa: PT012, PT011 os.chdir(TestDir / "test_data/NaCl") args = [ "description-quality", @@ -593,25 +583,21 @@ def test_cli_exceptions(self): test = get_parser().parse_args(args) run(test) - assert str(err.value) == "DOS comparisons requested but DOSCAR.lobster, vasprun.xml file not found." + assert str(err3.value) == "Files ['DOSCAR.LSO.lobster', 'vasprun.xml'] not found in NaCl." - # BVA comparison exceptions test - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 - os.chdir(TestDir / "test_data/NaCl") + with pytest.raises(Exception) as err4: # noqa: PT012, PT011 + os.chdir(TestDir / "test_data/CsH") args = [ - "description-quality", - "--bvacomp", - "--file-charge", - "../CHARGE.lobster", + "plot-dos", ] test = get_parser().parse_args(args) run(test) - assert str(err.value) == "BVA charge requested but CHARGE.lobster file not found." + assert str(err4.value) == "Files ['DOSCAR.LSO.lobster'] not found in CsH." # Create-inputs exceptions test - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 + with pytest.raises(ValueError) as err5: # noqa: PT012, PT011 os.chdir(TestDir / "test_data/CsH") args = [ "create-inputs", @@ -620,23 +606,12 @@ def test_cli_exceptions(self): test = get_parser().parse_args(args) run(test) - assert ( - str(err.value) - == "Files necessary for creating puts for LOBSTER calcs not found in the current directory." - ) - - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 - os.chdir(TestDir / "test_data/CsH") - args = [ - "plot-dos", - ] - - test = get_parser().parse_args(args) - run(test) - - assert str(err.value) == "DOSCAR.lobster necessary for plotting DOS not found in the current directory." + assert ( + str(err5.value) + == "Files necessary for creating inputs for LOBSTER calcs not found in the current directory." + ) - with pytest.raises(ValueError) as err: # noqa: PT012, PT011 + with pytest.raises(ValueError) as err6: # noqa: PT012, PT011 os.chdir(TestDir / "test_data/K3Sb") args = [ "plot-dos", @@ -649,7 +624,7 @@ def test_cli_exceptions(self): test = get_parser().parse_args(args) run(test) - assert str(err.value) == "Please set both args i.e site and orbital to generate the plot" + assert str(err6.value) == "Please set both args i.e site and orbital to generate the plot" def test_nongz_file_cli(self, tmp_path, inject_mocks, clean_plot): # test description from gz input files diff --git a/tests/featurize/test_utils.py b/tests/featurize/test_utils.py index 2c2ace25..2240be94 100644 --- a/tests/featurize/test_utils.py +++ b/tests/featurize/test_utils.py @@ -39,7 +39,7 @@ def test_get_file_paths(tmp_path): """ file_paths_zipped = get_file_paths( path_to_lobster_calc=TestDir / "test_data/BaTaO2N1", - requested_files=["poscar", "cohpcar", "charge", "icohplist"], + requested_files=["structure", "cohpcar", "charge", "icohplist"], ) for key, value in file_paths_zipped.items(): assert isinstance(key, str) From 275168dfd6f56822a0075b9bf4da55772c8d1b30 Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Tue, 12 Mar 2024 16:23:16 +0100 Subject: [PATCH 2/2] add summed spins arg to automatic anaylsis > cli --- lobsterpy/cli.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lobsterpy/cli.py b/lobsterpy/cli.py index 955a2e15..d1f75c08 100644 --- a/lobsterpy/cli.py +++ b/lobsterpy/cli.py @@ -429,6 +429,15 @@ def get_parser() -> argparse.ArgumentParser: "with orbital-resolved automatic analysis (--orbitalresolved).", ) + auto_group.add_argument( + "-sspins", + "--summedspins", + "--summed-spins", + action="store_true", + default=False, + help="Sum COHP `Spin.up` and `Spin.down` populations for automatic analysis", + ) + # Argument that will help to switch automatic analysis analysis_switch = argparse.ArgumentParser(add_help=False) analysis_group = analysis_switch.add_argument_group( @@ -778,6 +787,7 @@ def run(args): cutoff_icohp=args.cutofficohp, orbital_cutoff=args.orbitalcutoff, orbital_resolved=args.orbitalresolved, + summed_spins=args.summedspins, ) describe = Description(analysis_object=analyse)