Skip to content

Commit

Permalink
Merge branch 'materialsproject:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo authored Jul 31, 2024
2 parents 35260ee + 660ba7a commit 1d315a5
Show file tree
Hide file tree
Showing 17 changed files with 21,055 additions and 6 deletions.
35 changes: 33 additions & 2 deletions src/pymatgen/core/ion.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,9 +173,10 @@ def get_reduced_formula_and_factor(
el_amt_dict = {k: int(round(v)) for k, v in comp.get_el_amt_dict().items()}
formula, factor = reduce_formula(el_amt_dict, iupac_ordering=iupac_ordering)

if (self.composition.get("H") and self.composition.get("O")) is not None:
# This line checks specifically that the contains an equal amount of O and H. When that is the case,
# they should be displayed as "OH" rather than "HO".
if self.composition.get("H") == self.composition.get("O"):
formula = formula.replace("HO", "OH")

if nH2O > 0:
formula += f".{nH2O}H2O"

Expand All @@ -187,6 +188,13 @@ def get_reduced_formula_and_factor(
elif formula == "H2CO":
formula = "CH3COOH"
factor /= 2
# phosphoric acid system
elif formula == "PH3O4":
formula = "H3PO4"
elif formula == "PHO4":
formula = "HPO4"
elif formula == "P(HO2)2":
formula = "H2PO4"
# acetate
elif formula == "H3(CO)2":
formula = "CH3COO"
Expand All @@ -205,6 +213,29 @@ def get_reduced_formula_and_factor(
elif formula == "O" and factor % 3 == 0:
formula = "O3"
factor /= 3
# ammonia
elif formula == "H4N":
formula = "NH4"
elif formula == "H3N":
formula = "NH3"
# methane
elif formula == "H4C":
formula = "CH4"
# thiocyanate
elif formula == "CSN":
formula = "SCN"
# triiodide, nitride, an phosphide
elif formula in ["I", "N", "P"] and self.charge == -1:
formula += "3"
factor /= 3
# formate # codespell:ignore
elif formula == "HCOO":
formula = "HCO2"
# oxalate
elif formula == "CO2":
formula = "C2O4"
factor *= 2
# diatomic gases
elif formula in {"O", "N", "F", "Cl", "H"} and factor % 2 == 0:
formula += "2"
factor /= 2
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/core/structure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1874,7 +1874,7 @@ def get_symmetric_neighbor_list(
redundant.append(jdx)

# Delete the redundant neighbors
m = ~np.in1d(np.arange(len(bonds[0])), redundant)
m = ~np.isin(np.arange(len(bonds[0])), redundant)
idcs_dist = np.argsort(bonds[3][m])
bonds = (bonds[0][m][idcs_dist], bonds[1][m][idcs_dist], bonds[2][m][idcs_dist], bonds[3][m][idcs_dist])

Expand Down
Loading

0 comments on commit 1d315a5

Please sign in to comment.