Skip to content

Commit 668f1aa

Browse files
authored
Ion: bugfix for CO2(aq) reduced formula (materialsproject#4099)
1 parent 7e42635 commit 668f1aa

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/pymatgen/core/ion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ def get_reduced_formula_and_factor(
233233
elif formula == "HCOO":
234234
formula = "HCO2"
235235
# oxalate
236-
elif formula == "CO2":
236+
elif formula == "CO2" and self.charge == -2:
237237
formula = "C2O4"
238238
factor /= 2
239239
# diatomic gases

tests/core/test_ion.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ def test_charge_from_formula(self):
3939
assert Ion.from_formula("Ca++").charge == 2
4040
assert Ion.from_formula("Ca[++]").charge == 2
4141
assert Ion.from_formula("Ca2+").charge == 1
42+
assert Ion.from_formula("C2O4-2").charge == -2
43+
assert Ion.from_formula("CO2").charge == 0
4244

4345
assert Ion.from_formula("Cl-").charge == -1
4446
assert Ion.from_formula("Cl[-]").charge == -1
@@ -70,7 +72,9 @@ def test_special_formulas(self):
7072
("CH3COOH", "CH3COOH(aq)"),
7173
("CH3OH", "CH3OH(aq)"),
7274
("H4CO", "CH3OH(aq)"),
73-
("CO2-", "C2O4[-2]"),
75+
("C2O4--", "C2O4[-2]"),
76+
("CO2", "CO2(aq)"),
77+
("CO3--", "CO3[-2]"),
7478
("CH4", "CH4(aq)"),
7579
("NH4+", "NH4[+1]"),
7680
("NH3", "NH3(aq)"),

0 commit comments

Comments
 (0)