Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing parenthesis to electronic_structure.boltztrap.BoltztrapAnalyzer.get_extreme.is_isotropic #4271

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 18 additions & 17 deletions src/pymatgen/electronic_structure/boltztrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,37 +1454,38 @@ def get_extreme(
{"value", "temperature", "doping", "isotropic"}
"""

def is_isotropic(x, isotropy_tolerance) -> bool:
"""Internal method to tell you if 3-vector "x" is isotropic.
def is_isotropic(x, isotropy_tolerance: float) -> bool:
"""Helper function to determine if 3D vector is isotropic.

Args:
x: the vector to determine isotropy for
isotropy_tolerance: tolerance, e.g. 0.05 is 5%
isotropy_tolerance (float): tolerance, e.g. 0.05 is 5%
"""
if len(x) != 3:
raise ValueError("Invalid input to is_isotropic!")
raise ValueError("Invalid vector length to is_isotropic!")

st = sorted(x)

return bool(
all([st[0], st[1], st[2]])
and (abs((st[1] - st[0]) / st[1]) <= isotropy_tolerance)
and (abs(st[2] - st[0]) / st[2] <= isotropy_tolerance)
and (abs((st[2] - st[0]) / st[2]) <= isotropy_tolerance)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mark in case hard to review: this is the only functional change (added missing parenthesis) in this PR, others should be type/comment cleanups.

and (abs((st[2] - st[1]) / st[2]) <= isotropy_tolerance)
)

if target_prop.lower() == "seebeck":
d = self.get_seebeck(output="eigs", doping_levels=True)
dct = self.get_seebeck(output="eigs", doping_levels=True)

elif target_prop.lower() == "power factor":
d = self.get_power_factor(output="eigs", doping_levels=True)
dct = self.get_power_factor(output="eigs", doping_levels=True)

elif target_prop.lower() == "conductivity":
d = self.get_conductivity(output="eigs", doping_levels=True)
dct = self.get_conductivity(output="eigs", doping_levels=True)

elif target_prop.lower() == "kappa":
d = self.get_thermal_conductivity(output="eigs", doping_levels=True)
dct = self.get_thermal_conductivity(output="eigs", doping_levels=True)
elif target_prop.lower() == "zt":
d = self.get_zt(output="eigs", doping_levels=True)
dct = self.get_zt(output="eigs", doping_levels=True)

else:
raise ValueError(f"Unrecognized {target_prop=}")
Expand All @@ -1499,23 +1500,23 @@ def is_isotropic(x, isotropy_tolerance) -> bool:
min_doping = min_doping or 0
max_doping = max_doping or float("inf")

for pn in ("p", "n"):
for t in d[pn]: # temperatures
if min_temp <= float(t) <= max_temp:
for didx, evs in enumerate(d[pn][t]):
doping_lvl = self.doping[pn][didx]
for pn_type in ("p", "n"):
for temperature in dct[pn_type]:
if min_temp <= float(temperature) <= max_temp:
for didx, evs in enumerate(dct[pn_type][temperature]):
doping_lvl = self.doping[pn_type][didx]
if min_doping <= doping_lvl <= max_doping:
isotropic = is_isotropic(evs, isotropy_tolerance)
if abs_val:
evs = [abs(x) for x in evs]
val = float(sum(evs)) / len(evs) if use_average else max(evs)
if x_val is None or (val > x_val and maximize) or (val < x_val and not maximize):
x_val = val
x_temp = t
x_temp = temperature
x_doping = doping_lvl
x_isotropic = isotropic

output[pn] = {
output[pn_type] = {
"value": x_val,
"temperature": x_temp,
"doping": x_doping,
Expand Down
2 changes: 1 addition & 1 deletion tests/electronic_structure/test_boltztrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ def test_extreme(self):
extreme = self.bz.get_extreme("seebeck")
assert extreme["best"]["carrier_type"] == "n"
assert extreme["p"]["value"] == approx(1255.365, abs=1e-2)
assert extreme["n"]["isotropic"]
assert extreme["n"]["isotropic"] is False
DanielYang59 marked this conversation as resolved.
Show resolved Hide resolved
assert extreme["n"]["temperature"] == 600

extreme = self.bz.get_extreme("kappa", maximize=False, min_temp=400, min_doping=1e20)
Expand Down