Skip to content

Commit

Permalink
Merge and formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Jul 11, 2024
1 parent 0d495d6 commit 974c23d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 52 deletions.
4 changes: 2 additions & 2 deletions doped/interface/fermi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,15 +803,15 @@ def pseudo_equilibrium_solve(
Returns:
pd.DataFrame: DataFrame containing defect and carrier concentrations
and the self consistent Fermi energy
and the self-consistent Fermi energy
"""
(
fermi_level,
electrons,
holes,
concentrations,
) = self.defect_thermodynamics.get_quenched_fermi_level_and_concentrations(
bulk_dos_vr=self.bulk_dos,
bulk_dos=self.bulk_dos,
chempots=chempots,
limit=None,
annealing_temperature=annealing_temperature,
Expand Down
104 changes: 57 additions & 47 deletions doped/thermodynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,13 +1179,13 @@ def get_equilibrium_concentrations(
dilute limit approximation.
Note that these are the `equilibrium` defect concentrations!
DefectThermodynamics.get_quenched_fermi_level_and_concentrations() can
instead be used to calculate the Fermi level and defect concentrations
for a material grown/annealed at higher temperatures and then cooled
(quenched) to room/operating temperature (where defect concentrations
are assumed to remain fixed) - this is known as the frozen defect
approach and is typically the most valid approximation (see its
docstring for more information).
``DefectThermodynamics.get_quenched_fermi_level_and_concentrations()``
can instead be used to calculate the Fermi level and defect
concentrations for a material grown/annealed at higher temperatures
and then cooled (quenched) to room/operating temperature (where defect
concentrations are assumed to remain fixed) - this is known as the
frozen defect approach and is typically the most valid approximation
(see its docstring for more information).
The degeneracy/multiplicity factor "g" is an important parameter in the defect
concentration equation (see discussion in https://doi.org/10.1039/D2FD00043A
Expand Down Expand Up @@ -1375,39 +1375,6 @@ def _parse_fermi_dos(
)
return fdos

def _add_effective_dopant_concentration(
self, conc_df: pd.DataFrame, effective_dopant_concentration: Optional[float] = None
):
"""
Add the effective dopant concentration to the concentration
``DataFrame``.
"""
if effective_dopant_concentration is not None:
eff_dopant_df = pd.DataFrame(
{
"Defect": "Effective Dopant",
"Charge": np.sign(effective_dopant_concentration),
"Formation Energy (eV)": "N/A",
"Concentration (cm^-3)": np.abs(effective_dopant_concentration),
"Charge State Population": "100.0%",
},
index=[0],
)
for col in conc_df.columns:
if col not in eff_dopant_df.columns:
eff_dopant_df[col] = "N/A" # e.g. concentration per site, if per_site=True

if "Charge" not in conc_df.columns:
eff_dopant_df = eff_dopant_df.drop(
columns=["Charge", "Formation Energy (eV)", "Charge State Population"]
)
eff_dopant_df = eff_dopant_df.set_index("Defect") # Defect is index with summed conc df
return pd.concat([conc_df, eff_dopant_df])

return pd.concat([conc_df, eff_dopant_df], ignore_index=True)

return conc_df

def get_equilibrium_fermi_level(
self,
bulk_dos: Optional[Union[FermiDos, Vasprun, PathLike]] = None,
Expand All @@ -1431,13 +1398,13 @@ def get_equilibrium_fermi_level(
default, unless ``bulk_band_gap_vr`` is set during defect parsing.
Note that this assumes `equilibrium` defect concentrations!
DefectThermodynamics.get_quenched_fermi_level_and_concentrations() can
instead be used to calculate the Fermi level and defect concentrations
for a material grown/annealed at higher temperatures and then cooled
(quenched) to room/operating temperature (where defect concentrations
are assumed to remain fixed) - this is known as the frozen defect
approach and is typically the most valid approximation (see its
docstring for more information).
``DefectThermodynamics.get_quenched_fermi_level_and_concentrations()``
can instead be used to calculate the Fermi level and defect
concentrations for a material grown/annealed at higher temperatures and
then cooled (quenched) to room/operating temperature (where defect
concentrations are assumed to remain fixed) - this is known as the
frozen defect approach and is typically the most valid approximation
(see its docstring for more information).
Note that the bulk DOS calculation should be well-converged with respect to
k-points for accurate Fermi level predictions!
Expand Down Expand Up @@ -3141,6 +3108,49 @@ def __repr__(self):
)


def _add_effective_dopant_concentration(
conc_df: pd.DataFrame, effective_dopant_concentration: Optional[float] = None
):
"""
Add the effective dopant concentration to the concentration ``DataFrame``.
Args:
conc_df (pd.DataFrame):
DataFrame of defect concentrations.
effective_dopant_concentration (float):
The effective dopant concentration to add to the DataFrame.
Returns:
pd.DataFrame: DataFrame of defect concentrations with the effective
dopant concentration
"""
if effective_dopant_concentration is None:
return conc_df

eff_dopant_df = pd.DataFrame(
{
"Defect": "Effective Dopant",
"Charge": np.sign(effective_dopant_concentration),
"Formation Energy (eV)": "N/A",
"Concentration (cm^-3)": np.abs(effective_dopant_concentration),
"Charge State Population": "100.0%",
},
index=[0],
)
for col in conc_df.columns:
if col not in eff_dopant_df.columns:
eff_dopant_df[col] = "N/A" # e.g. concentration per site, if per_site=True

if "Charge" not in conc_df.columns:
eff_dopant_df = eff_dopant_df.drop(
columns=["Charge", "Formation Energy (eV)", "Charge State Population"]
)
eff_dopant_df = eff_dopant_df.set_index("Defect") # Defect is index with summed conc df
return pd.concat([conc_df, eff_dopant_df])

return pd.concat([conc_df, eff_dopant_df], ignore_index=True)


def _group_defect_charge_state_concentrations(
conc_df: pd.DataFrame, per_site: bool = False, skip_formatting: bool = False
):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_interface_fermi_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def test_assert_scan_temperature_raises(self):
annealing_temperature_range=[1, 2, 3],
quenching_temperature_range=None,
)
print(exc.value) # for debugging
print(exc.value) # for debugging

with pytest.raises(ValueError) as exc:
self.fs.scan_temperature(
Expand All @@ -64,7 +64,7 @@ def test_assert_scan_temperature_raises(self):
annealing_temperature_range=None,
quenching_temperature_range=[1, 2, 3],
)
print(exc.value) # for debugging
print(exc.value) # for debugging

with pytest.raises(ValueError) as exc:
self.fs.scan_temperature(
Expand All @@ -73,7 +73,7 @@ def test_assert_scan_temperature_raises(self):
annealing_temperature_range=None,
quenching_temperature_range=None,
)
print(exc.value) # for debugging
print(exc.value) # for debugging

def test_get_interpolated_chempots(self):

Expand Down

0 comments on commit 974c23d

Please sign in to comment.