@@ -173,9 +173,10 @@ def get_reduced_formula_and_factor(
173
173
el_amt_dict = {k : int (round (v )) for k , v in comp .get_el_amt_dict ().items ()}
174
174
formula , factor = reduce_formula (el_amt_dict , iupac_ordering = iupac_ordering )
175
175
176
- if (self .composition .get ("H" ) and self .composition .get ("O" )) is not None :
176
+ # This line checks specifically that the contains an equal amount of O and H. When that is the case,
177
+ # they should be displayed as "OH" rather than "HO".
178
+ if self .composition .get ("H" ) == self .composition .get ("O" ):
177
179
formula = formula .replace ("HO" , "OH" )
178
-
179
180
if nH2O > 0 :
180
181
formula += f".{ nH2O } H2O"
181
182
@@ -187,6 +188,13 @@ def get_reduced_formula_and_factor(
187
188
elif formula == "H2CO" :
188
189
formula = "CH3COOH"
189
190
factor /= 2
191
+ # phosphoric acid system
192
+ elif formula == "PH3O4" :
193
+ formula = "H3PO4"
194
+ elif formula == "PHO4" :
195
+ formula = "HPO4"
196
+ elif formula == "P(HO2)2" :
197
+ formula = "H2PO4"
190
198
# acetate
191
199
elif formula == "H3(CO)2" :
192
200
formula = "CH3COO"
@@ -205,6 +213,29 @@ def get_reduced_formula_and_factor(
205
213
elif formula == "O" and factor % 3 == 0 :
206
214
formula = "O3"
207
215
factor /= 3
216
+ # ammonia
217
+ elif formula == "H4N" :
218
+ formula = "NH4"
219
+ elif formula == "H3N" :
220
+ formula = "NH3"
221
+ # methane
222
+ elif formula == "H4C" :
223
+ formula = "CH4"
224
+ # thiocyanate
225
+ elif formula == "CSN" :
226
+ formula = "SCN"
227
+ # triiodide, nitride, an phosphide
228
+ elif formula in ["I" , "N" , "P" ] and self .charge == - 1 :
229
+ formula += "3"
230
+ factor /= 3
231
+ # formate # codespell:ignore
232
+ elif formula == "HCOO" :
233
+ formula = "HCO2"
234
+ # oxalate
235
+ elif formula == "CO2" :
236
+ formula = "C2O4"
237
+ factor *= 2
238
+ # diatomic gases
208
239
elif formula in {"O" , "N" , "F" , "Cl" , "H" } and factor % 2 == 0 :
209
240
formula += "2"
210
241
factor /= 2
0 commit comments