Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Feb 15, 2022
2 parents 18a4dcb + df44a54 commit f2caba9
Show file tree
Hide file tree
Showing 15 changed files with 100 additions and 183 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ default_language_version:

ci:
autoupdate_schedule: monthly
skip: [flake8, autoflake, mypy]
skip: [flake8, mypy]

repos:
- repo: https://github.com/psf/black
Expand Down
52 changes: 26 additions & 26 deletions pymatgen/analysis/pourbaix_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@
class PourbaixEntry(MSONable, Stringify):
"""
An object encompassing all data relevant to a solid or ion
in a pourbaix diagram. Each bulk solid/ion has an energy
in a Pourbaix diagram. Each bulk solid/ion has an energy
g of the form: e = e0 + 0.0591 log10(conc) - nO mu_H2O
+ (nH - 2nO) pH + phi (-nH + 2nO + q)
Note that the energies corresponding to the input entries
should be formation energies with respect to hydrogen and
oxygen gas in order for the pourbaix diagram formalism to
oxygen gas in order for the Pourbaix diagram formalism to
work. This may be changed to be more flexible in the future.
"""

Expand Down Expand Up @@ -134,7 +134,7 @@ def energy(self):
"""
returns energy
Returns (float): total energy of the pourbaix
Returns (float): total energy of the Pourbaix
entry (at pH, V = 0 vs. SHE)
"""
# Note: this implicitly depends on formation energies as input
Expand All @@ -143,7 +143,7 @@ def energy(self):
@property
def energy_per_atom(self):
"""
energy per atom of the pourbaix entry
energy per atom of the Pourbaix entry
Returns (float): energy per atom
"""
Expand Down Expand Up @@ -561,7 +561,7 @@ def __init__(
def _convert_entries_to_points(self, pourbaix_entries):
"""
Args:
pourbaix_entries ([PourbaixEntry]): list of pourbaix entries
pourbaix_entries ([PourbaixEntry]): list of Pourbaix entries
to process into vectors in nph-nphi-composition space
Returns:
Expand All @@ -580,7 +580,7 @@ def _convert_entries_to_points(self, pourbaix_entries):

def _get_hull_in_nph_nphi_space(self, entries):
"""
Generates convex hull of pourbaix diagram entries in composition,
Generates convex hull of Pourbaix diagram entries in composition,
npH, and nphi space. This enables filtering of multi-entries
such that only compositionally stable combinations of entries
are included.
Expand Down Expand Up @@ -623,7 +623,7 @@ def _get_hull_in_nph_nphi_space(self, entries):
facets = [facet for facet in hull.simplices if not len(points) - 1 in facet]

if self.dim > 1:
logger.debug("Filtering facets by pourbaix composition")
logger.debug("Filtering facets by Pourbaix composition")
valid_facets = []
for facet in facets:
comps = vecs[facet][:, 3:]
Expand All @@ -638,7 +638,7 @@ def _get_hull_in_nph_nphi_space(self, entries):

def _preprocess_pourbaix_entries(self, entries, nproc=None):
"""
Generates multi-entries for pourbaix diagram
Generates multi-entries for Pourbaix diagram
Args:
entries ([PourbaixEntry]): list of PourbaixEntries to preprocess
Expand Down Expand Up @@ -697,7 +697,7 @@ def _generate_multielement_entries(self, entries, nproc=None):
from the initialized comp_dict.
Args:
entries ([PourbaixEntries]): list of pourbaix entries
entries ([PourbaixEntries]): list of Pourbaix entries
to process into MultiEntries
nproc (int): number of processes to be used in parallel
treatment of entry combos
Expand All @@ -716,7 +716,7 @@ def _generate_multielement_entries(self, entries, nproc=None):
processed_entries = []
total = sum(comb(len(entries), j + 1) for j in range(N))
if total > 1e6:
warnings.warn(f"Your pourbaix diagram includes {total} entries and may take a long time to generate.")
warnings.warn(f"Your Pourbaix diagram includes {total} entries and may take a long time to generate.")

# Parallel processing of multi-entry generation
if nproc is not None:
Expand Down Expand Up @@ -763,7 +763,7 @@ def process_multientry(entry_list, prod_comp, coeff_threshold=1e-4):
react_coeffs = [-rxn.get_coeff(comp) for comp in entry_comps]
all_coeffs = react_coeffs + [rxn.get_coeff(prod_comp)]

# Check if reaction coeff threshold met for pourbaix compounds
# Check if reaction coeff threshold met for Pourbaix compounds
# All reactant/product coefficients must be positive nonzero
if all(coeff > coeff_threshold for coeff in all_coeffs):
return MultiEntry(entry_list, weights=react_coeffs)
Expand All @@ -775,7 +775,7 @@ def process_multientry(entry_list, prod_comp, coeff_threshold=1e-4):
@staticmethod
def get_pourbaix_domains(pourbaix_entries, limits=None):
"""
Returns a set of pourbaix stable domains (i. e. polygons) in
Returns a set of Pourbaix stable domains (i. e. polygons) in
pH-V space from a list of pourbaix_entries
This function works by using scipy's HalfspaceIntersection
Expand All @@ -784,12 +784,12 @@ def get_pourbaix_domains(pourbaix_entries, limits=None):
gibbs free energies as a function of pH and V. Hyperplanes
of the form a*pH + b*V + 1 - g(0, 0) are constructed and
supplied to HalfspaceIntersection, which then finds the
boundaries of each pourbaix region using the intersection
boundaries of each Pourbaix region using the intersection
points.
Args:
pourbaix_entries ([PourbaixEntry]): Pourbaix entries
with which to construct stable pourbaix domains
with which to construct stable Pourbaix domains
limits ([[float]]): limits in which to do the pourbaix
analysis
Expand Down Expand Up @@ -832,7 +832,7 @@ def get_pourbaix_domains(pourbaix_entries, limits=None):
this_entry = pourbaix_entries[v]
pourbaix_domains[this_entry].append(intersection)

# Remove entries with no pourbaix region
# Remove entries with no Pourbaix region
pourbaix_domains = {k: v for k, v in pourbaix_domains.items() if v}
pourbaix_domain_vertices = {}

Expand All @@ -848,7 +848,7 @@ def get_pourbaix_domains(pourbaix_entries, limits=None):
points_centered = sorted(points_centered, key=cmp_to_key(lambda x, y: x[0] * y[1] - x[1] * y[0]))
points = points_centered + center

# Create simplices corresponding to pourbaix boundary
# Create simplices corresponding to Pourbaix boundary
simplices = [Simplex(points[indices]) for indices in ConvexHull(points).simplices]
pourbaix_domains[entry] = simplices
pourbaix_domain_vertices[entry] = points
Expand Down Expand Up @@ -881,7 +881,7 @@ def get_decomposition_energy(self, entry, pH, V):
Returns:
Decomposition energy for the entry, i. e. the energy above
the "pourbaix hull" in eV/atom at the given conditions
the "Pourbaix hull" in eV/atom at the given conditions
"""

# Check composition consistency between entry and Pourbaix diagram:
Expand All @@ -902,15 +902,15 @@ def get_decomposition_energy(self, entry, pH, V):

def get_hull_energy(self, pH, V):
"""
Gets the minimum energy of the pourbaix "basin" that is formed
from the stable pourbaix planes. Vectorized.
Gets the minimum energy of the Pourbaix "basin" that is formed
from the stable Pourbaix planes. Vectorized.
Args:
pH (float or [float]): pH at which to find the hull energy
V (float or [float]): V at which to find the hull energy
Returns:
(float or [float]) minimum pourbaix energy at conditions
(float or [float]) minimum Pourbaix energy at conditions
"""
all_gs = np.array([e.normalized_energy_at_conditions(pH, V) for e in self.stable_entries])
Expand All @@ -926,7 +926,7 @@ def get_stable_entry(self, pH, V):
V (float): V at a given condition
Returns:
(PourbaixEntry or MultiEntry): pourbaix or multi-entry
(PourbaixEntry or MultiEntry): Pourbaix or multi-entry
corresponding ot the minimum energy entry at a given
pH, V condition
Expand All @@ -951,7 +951,7 @@ def unstable_entries(self):
@property
def all_entries(self):
"""
Return all entries used to generate the pourbaix diagram
Return all entries used to generate the Pourbaix diagram
"""
return self._processed_entries

Expand Down Expand Up @@ -1017,7 +1017,7 @@ def __init__(self, pourbaix_diagram):

def show(self, *args, **kwargs):
"""
Shows the pourbaix plot
Shows the Pourbaix plot
Args:
*args: args to get_pourbaix_plot
Expand Down Expand Up @@ -1046,7 +1046,7 @@ def get_pourbaix_plot(
limits: 2D list containing limits of the Pourbaix diagram
of the form [[xlo, xhi], [ylo, yhi]]
title (str): Title to display on plot
label_domains (bool): whether to label pourbaix domains
label_domains (bool): whether to label Pourbaix domains
label_fontsize: font size for domain labels
show_water_lines: whether to show dashed lines indicating the region
of water stability.
Expand All @@ -1055,7 +1055,7 @@ def get_pourbaix_plot(
plt (pyplot): Pyplot instance for plotting
Returns:
plt (pyplot) - matplotlib plot object with pourbaix diagram
plt (pyplot) - matplotlib plot object with Pourbaix diagram
"""
if limits is None:
limits = [[-2, 16], [-3, 3]]
Expand Down Expand Up @@ -1168,7 +1168,7 @@ def domain_vertices(self, entry):

def generate_entry_label(entry):
"""
Generates a label for the pourbaix plotter
Generates a label for the Pourbaix plotter
Args:
entry (PourbaixEntry or MultiEntry): entry to get a label for
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/analysis/tests/test_pourbaix_diagram.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def test_multicomponent(self):
self.assertAlmostEqual(pd_ternary.get_decomposition_energy(ag_te_n, 10, -2), 3.756840056890625)
self.assertAlmostEqual(pd_ternary.get_decomposition_energy(ground_state_ag_with_ions, 2, -1), 0)

# Test invocation of pourbaix diagram from ternary data
# Test invocation of Pourbaix diagram from ternary data
new_ternary = PourbaixDiagram(pd_ternary.all_entries)
self.assertEqual(len(new_ternary.stable_entries), 49)
self.assertAlmostEqual(new_ternary.get_decomposition_energy(ag_te_n, 2, -1), 2.767822855765)
Expand Down
2 changes: 1 addition & 1 deletion pymatgen/apps/battery/battery_abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AbstractElectrode(Sequence, MSONable):
framework_formula: The compositions of one formula unit of the host material
"""

voltage_pairs: Tuple[AbstractVoltagePair]
voltage_pairs: Tuple[AbstractVoltagePair, ...]
working_ion_entry: ComputedEntry
framework_formula: str # should be made into Composition whenever the as_dict and from dict are fixed

Expand Down
2 changes: 1 addition & 1 deletion pymatgen/apps/battery/insertion_battery.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def lifrac(e):
_unstable_entries = tuple(sorted((e for e in pd.unstable_entries if e in entries), key=lifrac))

# create voltage pairs
_vpairs: Tuple[AbstractVoltagePair] = tuple( # type: ignore
_vpairs: Tuple[AbstractVoltagePair, ...] = tuple(
InsertionVoltagePair.from_entries(
_stable_entries[i],
_stable_entries[i + 1],
Expand Down
1 change: 0 additions & 1 deletion pymatgen/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def _load_pmg_settings():
# If there are any errors, default to using environment variables
# if present.
warnings.warn(f"Error loading .pmgrc.yaml: {ex}. You may need to reconfigure your yaml file.")
pass

return d

Expand Down
2 changes: 1 addition & 1 deletion pymatgen/core/composition.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def __truediv__(self, other):

__div__ = __truediv__

def __hash__(self):
def __hash__(self) -> int:
"""
hash based on the chemical system
"""
Expand Down

0 comments on commit f2caba9

Please sign in to comment.