diff --git a/doped/thermodynamics.py b/doped/thermodynamics.py index a4172574..fe64683c 100644 --- a/doped/thermodynamics.py +++ b/doped/thermodynamics.py @@ -2526,11 +2526,11 @@ def get_transition_levels( self, all: bool = False, format_charges: bool = True, - ) -> pd.DataFrame: + ) -> Union[pd.DataFrame, None]: """ - Return a DataFrame of the charge transition levels for the defects in - the DefectThermodynamics object (stored in the transition_level_map - attribute). + Return a ``DataFrame`` of the charge transition levels for the defects + in the ``DefectThermodynamics`` object (stored in the + ``transition_level_map`` attribute). Note that the transition level (and Fermi level) positions are given relative to ``self.vbm``, which is the VBM eigenvalue of the bulk @@ -2547,7 +2547,7 @@ def get_transition_levels( If instead all single-electron transition levels are desired, set ``all = True``. - Returns a DataFrame with columns: + Returns a ``DataFrame`` with columns: - "Defect": Defect name - "Charges": Defect charge states which make up the transition level @@ -2627,6 +2627,9 @@ def _TL_naming_func(TL_charges, i_meta=False, j_meta=False): } ) + if not transition_level_map_list: + warnings.warn("No transition levels found for chosen parameters!") + return None tl_df = pd.DataFrame(transition_level_map_list) # sort df by Defect appearance order in defect_entries, Defect, then by TL position: tl_df["Defect Appearance Order"] = tl_df["Defect"].map(self._name_wout_charge_appearance_order) @@ -2669,6 +2672,8 @@ def print_transition_levels(self, all: bool = False): else: all_TLs_df = self.get_transition_levels(all=True) + if all_TLs_df is None: + return for defect_name, tl_df in all_TLs_df.groupby("Defect", sort=False): bold_print(f"Defect: {defect_name}") for _, row in tl_df.iterrows(): diff --git a/tests/test_generation.py b/tests/test_generation.py index 5bb643ca..73285fbf 100644 --- a/tests/test_generation.py +++ b/tests/test_generation.py @@ -3373,9 +3373,8 @@ def test_unrecognised_gen_kwargs(self): with pytest.raises(TypeError) as exc: DefectsGenerator(self.prim_cdte, interstitial_gen_kwargs={"unrecognised_kwarg": 1}) - assert ( - "TopographyAnalyzer.__init__() got an unexpected keyword argument 'unrecognised_kwarg'" - in str(exc.value) + assert ( # TopographyAnalyzer.__init__() but only __init__() shown in python 3.9 + "__init__() got an unexpected keyword argument 'unrecognised_kwarg'" in str(exc.value) ) with pytest.raises(TypeError) as exc: diff --git a/tests/test_thermodynamics.py b/tests/test_thermodynamics.py index 1838a462..81ede77f 100644 --- a/tests/test_thermodynamics.py +++ b/tests/test_thermodynamics.py @@ -1382,7 +1382,7 @@ def _check_formation_energy_methods(form_en_df_row, thermo_obj, fermi_level): assert list(row)[7] == list(te_rich_df.iloc[i])[7] assert list(row)[8] != list(te_rich_df.iloc[i])[8] assert list(row)[9] == list(te_rich_df.iloc[i])[9] - _check_formation_energy_methods(row, manual_thermo, 3) + _check_formation_energy_methods(list(row), manual_thermo, 3) assert list(manual_form_en_df.iloc[2])[:-1] == [ "v_Cd", @@ -1923,8 +1923,8 @@ def test_Sb2O5_formation_energies(self): df_row = formation_energy_table_df.iloc[i] reloaded_df_row = formation_energy_table_df_wout_charge_formatting.iloc[i] for j, val in enumerate(df_row): - print(val, reloaded_df_row[j]) - assert val == reloaded_df_row[j] + print(val, reloaded_df_row.iloc[j]) + assert val == reloaded_df_row.iloc[j] os.remove("test.csv")