Skip to content

Commit

Permalink
Formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Jun 19, 2024
1 parent edbed6d commit 1fd036f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
15 changes: 10 additions & 5 deletions doped/thermodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand Down
5 changes: 2 additions & 3 deletions tests/test_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_thermodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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")

Expand Down

0 comments on commit 1fd036f

Please sign in to comment.