Skip to content

Commit

Permalink
more group(x) changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielYang59 committed Jun 9, 2024
1 parent f4d3ec5 commit e0e0fe3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions dev_scripts/update_pt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ def parse_oxi_state():
oxi_data = re.sub("[\n\r]", "", oxi_data)
patt = re.compile("<tr>(.*?)</tr>", re.MULTILINE)

for m in patt.finditer(oxi_data):
line = m.group(1)
for match in patt.finditer(oxi_data):
line = match[1]
line = re.sub("</td>", "", line)
line = re.sub("(<td>)+", "<td>", line)
line = re.sub("</*a[^>]*>", "", line)
el = None
oxi_states = []
common_oxi = []
for tok in re.split("<td>", line.strip()):
m2 = re.match(r"<b>([A-Z][a-z]*)</b>", tok)
if m2:
el = m2.group(1)
match2 = re.match(r"<b>([A-Z][a-z]*)</b>", tok)
if match2:
el = match2[1]
else:
m3 = re.match(r"(<b>)*([\+\-]\d)(</b>)*", tok)
if m3:
oxi_states += [int(m3.group(2))]
if m3.group(1):
common_oxi += [int(m3.group(2))]
match3 = re.match(r"(<b>)*([\+\-]\d)(</b>)*", tok)
if match3:
oxi_states += [int(match3[2])]
if match3[1]:
common_oxi += [int(match3[2])]
if el in data:
del data[el]["Max oxidation state"]
del data[el]["Min oxidation state"]
Expand Down
4 changes: 2 additions & 2 deletions pymatgen/analysis/reaction_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def from_str(cls, rxn_str: str) -> Self:

def get_comp_amt(comp_str):
return {
Composition(m.group(2)): float(m.group(1) or 1)
for m in re.finditer(r"([\d\.]*(?:[eE]-?[\d\.]+)?)\s*([A-Z][\w\.\(\)]*)", comp_str)
Composition(match[2]): float(match[1] or 1)
for match in re.finditer(r"([\d\.]*(?:[eE]-?[\d\.]+)?)\s*([A-Z][\w\.\(\)]*)", comp_str)
}

return BalancedReaction(get_comp_amt(rct_str), get_comp_amt(prod_str))
Expand Down
12 changes: 6 additions & 6 deletions pymatgen/util/string.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ def to_unicode_string(self):
with systems where the sub and superscripts are pure integers.
"""
str_ = self.to_latex_string()
for m in re.finditer(r"\$_\{(\d+)\}\$", str_):
s1 = m.group()
s2 = [SUBSCRIPT_UNICODE[s] for s in m.group(1)]
for match in re.finditer(r"\$_\{(\d+)\}\$", str_):
s1 = match.group()
s2 = [SUBSCRIPT_UNICODE[s] for s in match[1]]
str_ = str_.replace(s1, "".join(s2))
for m in re.finditer(r"\$\^\{([\d\+\-]+)\}\$", str_):
s1 = m.group()
s2 = [SUPERSCRIPT_UNICODE[s] for s in m.group(1)]
for match in re.finditer(r"\$\^\{([\d\+\-]+)\}\$", str_):
s1 = match.group()
s2 = [SUPERSCRIPT_UNICODE[s] for s in match[1]]
str_ = str_.replace(s1, "".join(s2))
return str_

Expand Down

0 comments on commit e0e0fe3

Please sign in to comment.